Printing with Carbon's Print Manager
Posted: Sun Jul 03, 2011 5:18 pm
Can anyone please help me. This code works perfectly in FutureBASIC, and prints out a yellow circle with a red border in the middle of a page. However, in PB, nothing. The print dialog pops up, but the printer "prints out" a blank page. Besides CGRectMake, the code compiles without any errors, and OSStat returns no errors for any of the Print Manager calls. What did I do wrong?
Would truly appreciate some direction. Thanks in advance!
Code: Select all
EnableExplicit
Structure CGPoint
x.f
y.f
EndStructure
Structure CGSize
width.f
height.f
EndStructure
Structure CGRect
origin.CGPoint
size.CGSize
EndStructure
ImportC ""
PMSessionBeginCGDocument(printSession.l, printSettings.l, pageFormat.l)
PMSessionGetCGGraphicsContext (printSession.l, context.l)
PMCreateSession(printSession.l)
PMCreatePageFormat(pageFormat.l)
PMCreatePrintSettings(printSettings.l)
PMSessionDefaultPageFormat(printSession.l, pageFormat.l)
PMSessionDefaultPrintSettings(printSession.l, printSettings.l)
PMSessionPrintDialog(printSession.l, printSettings.l, constPageFormat.l, accepted.l)
PMSessionBeginPage(printSession.l, pageFormat.l, *pageFrame.RECT)
PMSessionEndDocument(printSession.l)
PMSessionEndPage(printSession.l)
PMRelease(object.l)
CGContextSetAlpha(context.l, alpha.f)
CGContextSetRGBFillColor(context.l, r.f, g.f, b.f, a.f)
CGRectMake(x.f, y.f, width.f, height.f)
CGContextFillRect(context.l, *pageFrame.RECT)
CGContextStrokeRect(context.l, *pageFrame.RECT)
CGContextSetRGBStrokeColor(context.l, r.f, g.f, b.f, a.f)
CGContextFillEllipseInRect(context.l, *pageFrame.RECT)
CGContextStrokeEllipseInRect(context.l, *pageFrame.RECT)
CGContextFlush(context.l)
EndImport
Define session.l, pageFormat.l, printSettings.l, OSStat.l
Define cg.l, PageRect.CGRect, accepted.l, pbVoid.l
OSStat = PMCreateSession(@session)
OSStat = PMCreatePageFormat(@pageFormat)
OSStat = PMSessionDefaultPageFormat(session, pageFormat)
OSStat = PMCreatePrintSettings(@printSettings)
OSStat = PMSessionDefaultPrintSettings(session, printSettings)
OSStat = PMSessionPrintDialog(session, printSettings, pageFormat, @accepted)
If accepted = 1
OSStat = PMSessionBeginCGDocument(session, printSettings, pageFormat)
OSStat = PMSessionBeginPage(session, pageFormat, pbVoid)
OSStat = PMSessionGetCGGraphicsContext(session, @cg)
CGContextSetAlpha(cg, 1.0)
CGContextSetRGBFillColor(cg, 1.0, 1.0, 1.0, 1.0)
With PageRect
\origin\x = 16
\origin\y = 15
\size\height = 765
\size\width = 584
EndWith
; PageRect = CGRectMake(16, 15, 584, 765)
CGContextFillRect(cg, PageRect)
CGContextSetRGBFillColor(cg, 0.0, 0.0, 0.0, 1.0)
CGContextStrokeRect(cg, PageRect)
CGContextSetRGBFillColor(cg, 1.0, 1.0, 0.0, 1.0)
CGContextSetRGBStrokeColor(cg, 1.0, 0.0, 0.0, 1.0)
With PageRect
\origin\x = 200
\origin\y = 200
\size\height = 300
\size\width = 300
EndWith
; CGContextFillEllipseInRect(cg, CGRectMake(200,200,300,300))
CGContextFillEllipseInRect(cg, PageRect)
; CGContextStrokeEllipseInRect(cg, CGRectMake(200,200,300,300))
CGContextStrokeEllipseInRect(cg, PageRect)
CGContextFlush(cg)
OSStat = PMSessionEndPage(session)
OSStat = PMSessionEndDocument(session)
OSStat = PMRelease(printSettings)
OSStat = PMRelease(pageFormat)
OSStat = PMRelease(session)
EndIf
End