Page 1 of 1

Need help with DrawVectorText()

Posted: Mon Sep 07, 2015 1:26 pm
by akj

Code: Select all

; DrawVectorText() failure
EnableExplicit
Enumeration
  #win
  #cnv
EndEnumeration
OpenWindow(#win, 0, 0, 638, 560, "Test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(#cnv, 418, 162, 60, 60)
StartVectorDrawing(CanvasVectorOutput(#cnv))
  DrawVectorText("Hi")
StopVectorDrawing()
Repeat: Until WaitWindowEvent()=#PB_Event_CloseWindow
End
I am trying to get the vector text "Hi" to display on the canvas gadget, but the canvas remains empty.
What is the least change I must make to the program to get it to work correctly?

Re: Need help with DrawVectorText()

Posted: Mon Sep 07, 2015 1:36 pm
by User_Russian

Code: Select all

; DrawVectorText() failure
EnableExplicit
Enumeration
  #win
  #cnv
EndEnumeration
LoadFont(0, "Arial", 20, #PB_Font_Bold)
OpenWindow(#win, 0, 0, 638, 560, "Test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(#cnv, 418, 162, 60, 60)
StartVectorDrawing(CanvasVectorOutput(#cnv))
VectorFont(FontID(0), 20)
DrawVectorText("Hi")
StopVectorDrawing()
Repeat: Until WaitWindowEvent()=#PB_Event_CloseWindow
End

Re: Need help with DrawVectorText()

Posted: Mon Sep 07, 2015 2:05 pm
by akj
Thank you User_Russian for your working code.

However, I have a query:
Why does

Code: Select all

VectorFont(FontID(0), 20)
result in a different text size from

Code: Select all

VectorFont(FontID(0))
even though the default text height is 20 as set by

Code: Select all

LoadFont(0, "Arial", 20)
?

Re: Need help with DrawVectorText()

Posted: Mon Sep 07, 2015 3:37 pm
by freak
akj wrote:Why does

Code: Select all

VectorFont(FontID(0), 20)
result in a different text size from

Code: Select all

VectorFont(FontID(0))
even though the default text height is 20 as set by

Code: Select all

LoadFont(0, "Arial", 20)
?
Because LoadFont() measures the height in Points, while VectorFont() measures the height in the unit of the drawing output (for the CanvasGadget, the default is pixels). So VectorFont(FontID(0), 20) sets the height to 20 pixels in this case.

Re: Need help with DrawVectorText()

Posted: Mon Oct 12, 2015 9:29 am
by collectordave
Tried this and freak is quite correct i found.

I solved the issue by using vectordrawing in mm on the canvas gadget and then when using the font I took the font size in points and converted to mm.

As an example using VectorFont(FontID(0), 20) will print text 20mm high/width on the canvas gadget with #PB_Unit_Millimeter used on the canvas so as the font is measured in points convert the '20 points' to mm each point is 1/72 of an inch so a simple conversion is possible. Then use VectorFont(FontID(0), (20 * conversion factor)) which will display and print at the normalish 20 point size.

You can use #PB_Unit_Point but then all measurements from that point on are in points. The #PB_Unit_Pixel one can give strange results as it is in DPI of the screen etc or the printer if using these functions for printing so become device dependent.

Check out the print and print preview post to see an example.

Hope this helps a bit.