Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/DynaPDF Graphics/DynaPDF GraphicsPath


Required plugins for this example: MBS DynaPDF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/DynaPDF Graphics/DynaPDF GraphicsPath

This example is the version from Mon, 17th Jan 2021.

Project "DynaPDF GraphicsPath.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() // add license key here End EventHandler
End Class
Class MainWindow Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Dim g As Graphics=OpenPrinterDialog if g=nil then Return end if draw g End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() Dim pdf As New MyDynapdfMBS Dim f1 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics.pdf") Dim f2 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics.png") Dim f3 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics Rendered.png") 'pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License If Not pdf.CreateNewPDF(f1) Then Return end if Call pdf.Append dim g as Graphics = pdf.PageGraphics draw g, pdf // for debugging, show temp picture Dim p As Picture = pdf.PageGraphicsPicture p.Save(f2, p.SaveAsPNG) Call pdf.EndPage If pdf.HasPro Then Call pdf.RenderPageToImage(1, f3, 150, 0, 0, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfFlate, pdf.kifmPNG) End If Call pdf.CloseFile f1.Launch True End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) draw g End EventHandler
End Control
Sub draw(g as graphics, pdf as DynaPDFMBS = nil) Const Pi = 3.14159 Dim pi2 As Double = pi * 2.0 Var gp As DynapdfGraphicsPathMBS g.DrawingColor = &cFF0000 g.PenSize = 5 g.PenHeight = 5 g.PenWidth = 5 Title = Str(g.PenWidth)+"x"+Str(g.PenHeight) 'g.DrawLine 0, 0, 100, 100 g.PenSize = 1 // arc g.AntiAlias = True g.PenSize = 3 Dim r As Integer = 40 Dim n As Integer = 0 For w As Integer = 0 To 350 Step 10 Select Case n Mod 4 Case 0 g.DrawingColor = &cFF0000 Case 1 g.DrawingColor = &c00FF00 Case 2 g.DrawingColor = &c0000FF Case 3 g.DrawingColor = &cFF00FF End Select n = n + 1 Dim w0 As Double = w Dim w1 As Double = w0 / 180.0 * pi Dim w2 As Double = (w0+10.0) / 180.0 * pi Dim clockwise As Boolean = False If pdf <> Nil Then 'w1 = Convrt(w1) 'w2 = Convrt(w2) 'w1 = pi2 - w1 'w2 = pi2 - w2 'clockwise = True End If gp = New DynapdfGraphicsPathMBS gp.AddArc(200, 200, r, w1, w2, clockwise) g.DrawPath gp r = r + 1 Next g.DrawingColor = &c00FFFF Dim w1 As Double = 0 Dim w2 As Double = pi/2 Dim clockwise As Boolean = False gp = New DynapdfGraphicsPathMBS gp.AddArc(200, 200, 80, w1, w2, clockwise) g.DrawPath gp Var curve As New DynapdfGraphicsPathMBS curve.MoveToPoint(320, 200+20) curve.AddCurveToPoint(320, 200+100, 500, 200+100, 500, 200+20) g.DrawingColor = &c00FF00 g.DrawPath(curve) // Draw a fluffy white cloud Var cloud As New DynapdfGraphicsPathMBS cloud.MoveToPoint(270, 80) cloud.AddCurveToPoint(230, 100, 230, 150, 330, 150) cloud.AddCurveToPoint(350, 180, 420, 180, 440, 150) cloud.AddCurveToPoint(520, 150, 520, 120, 490, 100) cloud.AddCurveToPoint(530, 40, 470, 30, 440, 50) cloud.AddCurveToPoint(420, 5, 350, 20, 350, 50) cloud.AddCurveToPoint(300, 5, 250, 20, 270, 80) g.DrawingColor = &c0000FF g.PenSize = 5 g.DrawPath(cloud) Var p As New DynapdfGraphicsPathMBS p.MoveToPoint(10, 5) // Start location p.AddLineToPoint(40, 40) p.AddLineToPoint(5, 60) g.DrawingColor = &c0000FF g.DrawPath(p, True) Var qCurve As New DynapdfGraphicsPathMBS qCurve.MoveToPoint(38, 100) qCurve.AddQuadraticCurveToPoint(138, 0, 238, 100) g.DrawingColor = &c00FF00 g.PenSize = 10 g.DrawPath(qCurve) Var rect As New DynapdfGraphicsPathMBS rect.AddRectangle(300+10, 300+10, 100, 150) g.DrawingColor = &cFF0000 g.DrawPath(rect) rect = New DynapdfGraphicsPathMBS rect.AddRoundRectangle(10, 300+10, 100, 150, 10, 10) g.DrawPath(rect) End Sub
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer // output all messages on the console: System.DebugLog str(ErrorCode)+": "+ErrorMessage // and display dialog: Dim d as New MessageDialog //declare the MessageDialog object Dim b as MessageDialogButton //for handling the result d.icon=MessageDialog.GraphicCaution //display warning icon d.ActionButton.Caption="Continue" d.CancelButton.Visible=True //show the Cancel button // a warning or an error? if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then // if user decided to ignore, we'll ignore if IgnoreWarnings then Return 0 d.Message="A warning occurred while processing your PDF code." // we add a third button to display all warnings d.AlternateActionButton.Caption = "Ignore warnings" d.AlternateActionButton.Visible = true else d.Message="An error occurred while processing your PDF code." end if d.Explanation = str(ErrorCode)+": "+ErrorMessage b=d.ShowModal //display the dialog Select Case b //determine which button was pressed. Case d.ActionButton Return 0 // ignore Case d.AlternateActionButton IgnoreWarnings = true Return 0 // ignore Case d.CancelButton Return -1 // stop End select End EventHandler
EventHandler Function PageBreak(LastPosX as double, LastPosY as double, PageBreak as boolean) As integer PageBreak = true Return -1 // stop End EventHandler
Property IgnoreWarnings As Boolean
Property PageBreak As Boolean
End Class
End Project

See also:

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


The biggest plugin in space...