[futurebasic] Re: [FB] Help on Pasteboard.h

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2009 : Group Archive : Group : All Groups

From: Deep <Info@...>
Date: Wed, 07 Jan 2009 00:42:06 +0000
Hi Robert,

Thanks for that, inserting the CGContextBeginPage() and CGContextEndPage()
statements has fixed it.

Working version below for those interested. After running the application, a
small graphic image will be on the clipboard. Pasting into a vector editing
application like Intaglio, Illustrator, etc, will let you separate the
elements and see the transparency when moving the objects around.

Kind regards,

Deep


*** Sample Follows ***

include "Rntm Appearance.incl"
include "Tlbx CoreGraphics.incl"
include "Tlbx HIObject.incl"


#if ndef _DEFINEDINCARBON
#define PasteboardRef as CFTypeRef
#define PasteboardItemID as ptr
#define PasteboardFlavorFlags as UInt32
#define CGDataConsumerRef as pointer
#endif

toolbox fn PasteboardCreate( CFStringRef inName, PasteboardRef
*outPasteboard ) = OSStatus
toolbox fn PasteboardClear( PasteboardRef inPasteboard ) = OSStatus
toolbox fn PasteboardPutItemFlavor( PasteboardRef inPasteboard,
PasteboardItemID inItem, CFStringRef inFlavorType, CFDataRef inData,
PasteboardFlavorFlags inFlags ) = OSStatus

toolbox fn CGDataConsumerCreateWithCFData ( CFMutableDataRef data ) =
CGDataConsumerRef
toolbox fn CGPDFContextCreate( CGDataConsumerRef consumer, const CGRect
*mediaBox, CFDictionaryRef auxiliaryInfo ) = CGContextRef
toolbox CGDataConsumerRelease( CGDataConsumerRef consumer )
toolbox CGContextBeginPage( CGContextRef c, const CGRect *mediaBox )
toolbox CGContextEndPage( CGContextRef c )

_kPasteboardFlavorNoFlags = 0
_kPasteboardFlavorSenderOnly = 1 << 0
_kPasteboardFlavorSenderTranslated = 1 << 1
_kPasteboardFlavorNotSaved = 1 << 2
_kPasteboardFlavorRequestOnly = 1 << 3
_kPasteboardFlavorSystemTranslated = 1 << 8
_kPasteboardFlavorPromised = 1 << 9



local fn AddImageToPasteboardAsPDF
dim osErr as OSStatus
dim @ MyPasteBoard as PasteBoardRef
dim @ MyPDFData as CFMutableDataRef
dim PDFContext as CGContextRef
dim MyConsumer as CGDataConsumerRef



dim CTMAdjX as single
dim CTMAdjY as single
dim CTMAdjS as single

CTMAdjX = 200
CTMAdjY = 125
CTMAdjS = 10

dim myRect as CGRect
dim myX as double
dim myY as double
dim myH as double
dim myW as double

myX = 0.0
myY = 0.0
myH = 200.0
myW = 400.0

fn CGRectMake( @myRect, myX, myY, myH, myW )


MyPDFData = fn CFDataCreateMutable( _kCFAllocatorDefault, 0 )
MyConsumer = fn CGDataConsumerCreateWithCFData( MyPDFData )

PDFContext = fn CGPDFContextCreate( MyConsumer, @myRect, 0 )

fn CGContextBeginPage( PDFContext, @myRect)

fn CGContextSaveGState( PDFContext )

fn CGContextStrokeRectWithWidth( PDFContext, myRect, 3.75 )
fn CGContextSetRGBFillColor( PDFContext, 0.0, 1.0, 0.0, 0.5 )
fn CGContextFillRect( PDFContext, myRect )

fn CGContextTranslateCTM( PDFContext, CTMAdjX, CTMAdjY )
fn CGContextScaleCTM( PDFContext, CTMAdjS, CTMAdjS )

fn CGContextSetLineWidth( PDFContext, 2.0 )
fn CGContextSetRGBStrokeColor( PDFContext, 1, 0, 0, 1 )
fn CGContextAddArc( PDFContext, 0, 0, 2 , 0, ( 2 * 3.1415926535 ) , 0 )
fn CGContextStrokePath( PDFContext )

fn CGContextRestoreGState( PDFContext )

fn CGContextEndPage( PDFContext )

fn CGContextRelease (PDFContext)

osErr = fn PasteboardCreate( fn CFSTR( "com.apple.pasteboard.clipboard" ),
@MyPasteBoard )
long if ( osErr == _noErr )
osErr = fn PasteboardClear( MyPasteBoard )
long if ( osErr == _noErr )
osErr = fn PasteboardPutItemFlavor( MyPasteBoard, 1, fn CFSTR(
"com.adobe.pdf" ), MyPDFData, _kPasteboardFlavorNoFlags )
end if
fn CFRelease( MyPasteBoard )
end if
fn CGDataConsumerRelease( MyConsumer )
fn CFRelease( MyPDFData )
end fn = osErr

// main
dim osErr as OSStatus

osErr = fn AddImageToPasteboardAsPDF

long if ( osErr )
shutdown "PutPDFOnClipboard error " + str$( osErr )
xelse
fn StandardAlert( _kAlertNoteAlert, "PDF Image is on clipboard", "", 0, #0 )
end if

RunApplicationEventLoop()