Need help with DrawVectorText()

Just starting out? Need help? Post your questions and find answers here.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Need help with DrawVectorText()

Post 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?
Anthony Jordan
User_Russian
Addict
Addict
Posts: 1582
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Need help with DrawVectorText()

Post 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
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Re: Need help with DrawVectorText()

Post 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)
?
Anthony Jordan
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Need help with DrawVectorText()

Post 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.
quidquid Latine dictum sit altum videtur
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Need help with DrawVectorText()

Post 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.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply