Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/CoreGraphics PDF/PDF Text
Required plugins for this example: MBS MacCG Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/CoreGraphics PDF/PDF Text
This example is the version from Sun, 23th Sep 2017.
Project "PDF Text.rbp"
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class Window1 Inherits Window
EventHandler Sub Open() // Original example can be found on Apple's Website. // Translation from C is quite easy ;-) dim c as CGContextMBS dim f as FolderItem dim r as CGRectMBS const size=500.0 f=SpecialFolder.Desktop.Child("RB Text Demo.pdf") r=CGMakeRectMBS(0,0,size,size) // Create the context c=CGNewPDFDocumentMBS(f,r,"PDF from Xojo","Christian Schmitz","MBS Plugin 2.7") if c<>nil then // We must begin a new page before drawing to a PDF context c.BeginPage(r) c.SetRGBFillColor 0,0,0, 1.0 c.SelectFont "Times New Roman", 18.0, 1 c.ShowTextAtPoint "Hello World in Times New Roman",10,100 c.SetRGBFillColor 0.4, 0.7, 0.9, 1.0 c.SelectFont "Helvetica", 36.0, 1 c.SetTextDrawingMode 5 c.ShowTextAtPoint "revenge of the razorback frogs",0,r.height/2 c.SetRGBFillColor 0.4, 0.7, 0.9, 1.0 c.FillRect r c.SetLineWidth 2 DrawStarburst c,size // We've finished rendering the page c.EndPage c.Flush c=nil // to force the file to be written as we want to launch it f.Launch else MsgBox "Failed to creator file!" end if quit End EventHandler
Sub DrawStarburst(c as cgcontextmbs, size as single) dim kFullCircleInRadians as single dim rotation as single kFullCircleInRadians = 3.14159265358979323846 * 2.0 // Draw 50 lines as a starburst c.SetLineWidth 2 rotation = 0.0 while rotation<kFullCircleInRadians // Start a new path c.BeginPath // Save the graphics state so we can start with a // fresh rotation each time c.SaveGState // // Translate the CTM to the center of the page, then // rotate the CTM by our current translation. Note // that order is important -- if you rotate the CTM // before the translation, the translation coordinates // will be rotated. In this example, we want to draw // in the center of the page, so we translate before // we rotate. // c.TranslateCTM size * 0.5, size * 0.5 c.RotateCTM rotation // // Draw a simple horizontal line // - First, set the current point to 0,0 // - Second, add the horizontal line // (We now have a path consisting of a horizontal line) // - Third, stroke the line to paint it onto the page // c.MoveToPoint 0.0, 0.0 c.AddLineToPoint size * 0.5, 0.0 c.StrokePath // Restore the graphics state c.RestoreGState rotation = rotation+ (kFullCircleInRadians/200.0) wend End Sub
End Class
Class App Inherits Application
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCG Plugin.

MBS Xojo Plugins