Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/DynaPDF Graphics
Feedback.

Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /DynaPDF/DynaPDF Graphics
This example is the version from Thu, 10th Mar 2010.
Notes: Last modified: Thu, 10th Mar 2010
Class App
Inherits Application
// Constants
Const kFileQuitShortcut = Ctrl+Q
Const kFileQuit = E&xit
Const kEditClear = &Delete
End Class

Class Window1
Inherits Window
// Controls
ControlInstance
Sub Action() Handles Event
dim g as Graphics=OpenPrinterDialog

if g=nil then
Return
end if

g.ForeColor=&c777777
g.DrawRect 0,0,g.Width-1,g.Height-1

g.ForeColor=&cFF0000
g.FillRect 100,100,200,200

g.DrawLine 0,0,100,100

g.ForeColor=&c000000
g.DrawString "Hello",150,150

g.DrawLine 100,100,200,200

g.ForeColor=&c00FF00
g.FillOval 100,0,100,100

g.ForeColor=&c0000FF
g.DrawOval 100,0,100,100

g.ForeColor=&cFFFF00
g.FillRect 0,100,100,100
g.ForeColor=&c000000
g.DrawRect 0,100,100,100

g.ForeColor=&c00FF00
g.FillRoundRect 0,250,100,100,20,20
g.ForeColor=&c000000
g.DrawRoundRect 0,250,100,100,20,20

g.Pixel(400,400)=&cFFFF00

Dim Points(6) as Integer
Points(1)=10 //X of Point 1
Points(2)=10 //Y of Point 1
Points(3)=75 //X of Point 2
Points(4)=30 //Y of Point 2
Points(5)=10 //X of Point 3
Points(6)=125 //Y of Point 3
g.ForeColor= RGB(100,200,255)
g.FillPolygon Points
g.ForeColor=&c000000
g.DrawPolygon Points

End Sub
End ControlInstance
ControlInstance
Sub Action() Handles Event
dim g as DynaPDFGraphics
dim pdf as DynapdfMBS
dim f as FolderItem

f=SpecialFolder.Desktop.Child("DynaPDF Graphics.pdf")
pdf=new DynaPDF

pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License

if not pdf.CreateNewPDF(f) then
Return
end if

g=new DynaPDFGraphics(pdf,20.0,20.0)

g.ForeColor=&c777777
g.DrawRect 0,0,g.Width-1,g.Height-1

g.ForeColor=&cFF0000
g.FillRect 100,100,200,200

g.DrawLine 0,0,100,100

g.ForeColor=&c000000
g.DrawString "Hello",150,150

g.DrawLine 100,100,200,200

g.ForeColor=&c00FF00
g.FillOval 100,0,100,100

g.ForeColor=&c0000FF
g.DrawOval 100,0,100,100

g.ForeColor=&cFFFF00
g.FillRect 0,100,100,100
g.ForeColor=&c000000
g.DrawRect 0,100,100,100

g.ForeColor=&c00FF00
g.FillRoundRect 0,250,100,100,20,20
g.ForeColor=&c000000
g.DrawRoundRect 0,250,100,100,20,20

g.Pixel(400,400)=&cFFFF00

Dim Points(6) as Integer
Points(1)=10 //X of Point 1
Points(2)=10 //Y of Point 1
Points(3)=75 //X of Point 2
Points(4)=30 //Y of Point 2
Points(5)=10 //X of Point 3
Points(6)=125 //Y of Point 3
g.ForeColor= RGB(100,200,255)
g.FillPolygon Points
g.ForeColor=&c000000
g.DrawPolygon Points

g=nil

f.Launch true

End Sub
End ControlInstance
ControlInstance
Sub Action() Handles Event
dim g as Graphics=Graphics

g.ForeColor=&c777777
g.DrawRect 0,0,g.Width-1,g.Height-1

g.ForeColor=&cFF0000
g.FillRect 100,100,200,200

g.DrawLine 0,0,100,100

g.ForeColor=&c000000
g.DrawString "Hello",150,150

g.DrawLine 100,100,200,200

g.ForeColor=&c00FF00
g.FillOval 100,0,100,100

g.ForeColor=&c0000FF
g.DrawOval 100,0,100,100

g.ForeColor=&cFFFF00
g.FillRect 0,100,100,100
g.ForeColor=&c000000
g.DrawRect 0,100,100,100

g.ForeColor=&c00FF00
g.FillRoundRect 0,250,100,100,20,20
g.ForeColor=&c000000
g.DrawRoundRect 0,250,100,100,20,20

g.Pixel(400,400)=&cFFFF00

Dim Points(6) as Integer
Points(1)=10 //X of Point 1
Points(2)=10 //Y of Point 1
Points(3)=75 //X of Point 2
Points(4)=30 //Y of Point 2
Points(5)=10 //X of Point 3
Points(6)=125 //Y of Point 3
g.ForeColor= RGB(100,200,255)
g.FillPolygon Points
g.ForeColor=&c000000
g.DrawPolygon Points

End Sub
End ControlInstance

// Event implementations
Sub Open()



End Sub
End Class

Class DynaPDFGraphics
// Properties
Dim pdf As dynaPDFmbs
Private Dim myPageOpen As boolean
Private Dim myItalic As boolean
Private Dim myUnderline As boolean
Private Dim myBold As boolean
Private Dim myFontname As string
Private Dim myTextSize As double
Private Dim myForeColor As color
Private Dim myOffsetX As double
Private Dim myOffsetY As double

// Methods
Sub Bold(assigns b as boolean)
myBold=b
setFont

End Sub
Function Bold() As boolean
Return myBold
End Function
Function ForeColor() As color
Return myForeColor
End Function
Sub ForeColor(assigns c as color)
if pdf.SetColors(pdf.RGB(c.red,c.Green,c.Blue)) then
myForeColor=c
end if


End Sub
Function Height() As double
Return pdf.GetPageHeight-myOffsety-myOffsety
End Function
Function Italic() As boolean
Return myItalic
End Function
Sub Italic(assigns v as boolean)
myItalic=v
setFont

End Sub
Function PenHeight() As double
Return pdf.GetLineWidth
End Function
Sub PenHeight(assigns v as double)
call pdf.SetLineWidth v
End Sub
Function PenWidth() As double
Return pdf.GetLineWidth
End Function
Sub PenWidth(assigns v as double)
call pdf.SetLineWidth v
End Sub
Sub Pixel(x as integer, y as integer, assigns c as color)
if pdf.SetColors(pdf.RGB(c.red,c.Green,c.Blue)) then
DrawLine x,y,x,y
call pdf.SetColors(pdf.RGB(myForeColor.red,myForeColor.Green,myForeColor.Blue))
end if

End Sub
Function TextAscent() As double
Return pdf.GetAscent

End Function
Sub TextFont(assigns name as string)
myFontname=name
SetFont

End Sub
Function TextFont() As string
Return myFontname
End Function
Function TextHeight() As double
Return pdf.GetCapHeight
End Function
Function TextSize() As double
Return myTextSize
End Function
Sub TextSize(assigns v as double)
myTextSize=v
setfont

End Sub
Function Underline() As boolean
Return myUnderline
End Function
Sub Underline(assigns v as boolean)
myUnderline=v
setFont

End Sub
Function Width() As integer
Return pdf.GetPageWidth-myOffsetx-myOffsetx
End Function
Sub NextPage()
if pdf.EndPage then
myPageOpen=false


if pdf.Append then
myPageOpen=true
SetFont

end if

end if

End Sub
Sub FillOval(x as double, y as double, width as double, height as double)
call pdf.Ellipse(myOffsetX+x,myOffsety+y,Width,Height,pdf.kfmFill)


End Sub
Sub DrawOval(x as double, y as double, width as double, height as double)
call pdf.Ellipse(myOffsetX+x,myOffsety+y,Width,Height,pdf.kfmStroke)


End Sub
Sub FillRect(x as double, y as double, width as double, height as double)
call pdf.Rectangle(myOffsetX+x,myOffsety+y,Width,Height,pdf.kfmFill)

End Sub
Sub DrawRect(x as double, y as double, width as double, height as double)
call pdf.Rectangle(myOffsetX+x,myOffsety+y,Width,Height,pdf.kfmStroke)

End Sub
Sub DrawLine(x1 as double, y1 as double, x2 as double, y2 as double)

call pdf.MoveTo(myOffsetX+x1,myOffsety+y1)
call pdf.LineTo(myOffsetX+x2,myOffsety+y2)

call pdf.StrokePath


End Sub
Sub Constructor(d as dynaPDFmbs, OffsetX as double, OffsetY as double)
pdf=d

call pdf.SetPageCoords(pdf.kpcTopDown)

if pdf.Append then
myPageOpen=true
end if

myTextSize=12
myFontname="Arial"
myOffsetX=OffsetX
myOffsetY=OffsetY

SetFont

End Sub
Sub Destructor()
call pdf.EndPage
call pdf.CloseFile


End Sub
Sub DrawString(text as string, x as double, y as double)

call pdf.WriteText(myOffsetX+x,myOffsety+y-myTextSize,text)

End Sub
Private Sub SetFont()
dim style as integer

if mybold then
Style=style+pdf.kfsBold
end if

if myUnderline then
Style=style+pdf.kfsUnderlined
end if

if myitalic then
Style=style+pdf.kfsItalic
end if

call pdf.SetFont(myFontname, Style, myTextSize, true, pdf.kcp1252)

End Sub
Sub DrawRoundRect(x as double, y as double, width as double, height as double, ArcWidth as double, ArcHeight as double)
call pdf.RoundRectex(myOffsetX+x,myOffsety+y,Width,Height,arcwidth/2.0, archeight/2.0, pdf.kfmStroke)

End Sub
Sub FillRoundRect(x as double, y as double, width as double, height as double, arcwidth as double, archeight as double)
call pdf.RoundRectex(myOffsetX+x,myOffsety+y,Width,Height,arcwidth/2.0, archeight/2.0, pdf.kfmFill)

End Sub
Sub FillPolygon(points() as integer)
dim x,y as integer
dim i,c as integer

c=UBound(points)

if c>=2 then
x=points(1)
y=points(2)

call pdf.MoveTo(myOffsetX+x,myOffsety+y)

for i=3 to c step 2
x=points(i)
y=points(i+1)
call pdf.LineTo(myOffsetX+x,myOffsety+y)
next

call pdf.ClosePath(pdf.kfmFill)

end if

End Sub
Sub DrawPolygon(points() as integer)
dim x,y as integer
dim i,c as integer

c=UBound(points)

if c>=2 then
x=points(1)
y=points(2)

call pdf.MoveTo(myOffsetX+x,myOffsety+y)

for i=3 to c step 2
x=points(i)
y=points(i+1)
call pdf.LineTo(myOffsetX+x,myOffsety+y)
next

x=points(1)
y=points(2)

call pdf.LineTo(myOffsetX+x,myOffsety+y)

call pdf.StrokePath

end if

End Sub
End Class

Class DynaPDF
Inherits DynapdfMBS
// Event implementations
Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer
MsgBox str(ErrorCode)+" "+ErrorMessage
End Function
End Class


See also:




Links
MBS Realbasic Chart Plugins - Nachhilfe in Kruft