VectorTextHeight differences on macOS/Linux and Windows

Just starting out? Need help? Post your questions and find answers here.
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

VectorTextHeight differences on macOS/Linux and Windows

Post by wombats »

On Windows, VectorTextHeight returns the height of the entire block of text, while on macOS and Linux, it returns the height of one line. I'm not sure which is right, so I was hesitant to post this in one of the bug forums. The difference in return values makes it difficult to rely on across platforms.

Code: Select all

If OpenWindow(0, 0, 0, 630, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 300, 133)
CanvasGadget(1, 320, 8, 300, 133)
For a = 0 To 5
AddGadgetItem(0, a, "Line "+Str(a))
Next
LoadFont(0, "Arial", 20)
Repeat

Event = WaitWindowEvent()

If Event = #PB_Event_Gadget

If StartVectorDrawing(CanvasVectorOutput(1))

VectorFont(FontID(0), 18)

VectorSourceColor(RGBA(255, 255, 255, 255))
FillVectorOutput()

MovePathCursor(5, 5)

VectorSourceColor(RGBA(0, 0, 0, 255))

DrawVectorParagraph(GetGadgetText(0), VectorOutputWidth() - 10, VectorOutputHeight() - 10)

MovePathCursor(VectorOutputWidth() - VectorTextWidth("Height: ###"), 5)

DrawVectorText("Height: " + Str(VectorTextHeight(GetGadgetText(0))))

StopVectorDrawing()

EndIf

EndIf

Until Event = #PB_Event_CloseWindow
EndIf
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: VectorTextHeight differences on macOS/Linux and Windows

Post by #NULL »

I get "Height: 21" with subsystem qt, and "..126" otherwise (gtk2/3). It should be the same I think. In all cases the lines are separated with linefeed characters (LF / 10).
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: VectorTextHeight differences on macOS/Linux and Windows

Post by RASHAD »

I am not sure but maybe because of MovePathCursor()
Try next snippet
If you still get the wrong result with Mac & Linux you can post a bug report

Code: Select all

If OpenWindow(0, 0, 0, 630, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 300, 133)
CanvasGadget(1, 320, 8, 300, 133)
For a = 0 To 5
AddGadgetItem(0, a, "Line "+Str(a))
Next
LoadFont(0, "Arial", 20)
Repeat

Event = WaitWindowEvent()

If Event = #PB_Event_Gadget

If StartVectorDrawing(CanvasVectorOutput(1))

VectorFont(FontID(0), 18)

VectorSourceColor(RGBA(255, 255, 255, 255))
FillVectorOutput()

MovePathCursor(5, 5)

VectorSourceColor(RGBA(0, 0, 0, 255))

DrawVectorParagraph(GetGadgetText(0), VectorOutputWidth() - 10, VectorOutputHeight() - 10)
hh = VectorTextHeight(GetGadgetText(0))
MovePathCursor(VectorOutputWidth() - VectorTextWidth("Height: ###"), 5)

DrawVectorText("Height: " + Str(hh) )

StopVectorDrawing()

EndIf

EndIf

Until Event = #PB_Event_CloseWindow
EndIf
Egypt my love
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: VectorTextHeight differences on macOS/Linux and Windows

Post by #NULL »

nope :) , doesn't change anything (on Linux).
But doc for VectorTextHeight() says
Text$
The text (single-line) to measure.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: VectorTextHeight differences on macOS/Linux and Windows

Post by RASHAD »

Yes you are right
Then no bug
Try

Code: Select all

If OpenWindow(0, 0, 0, 630, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 300, 133)
CanvasGadget(1, 320, 8, 300, 133)
For a = 0 To 5
AddGadgetItem(0, a, "Line "+Str(a))
Next
LoadFont(0, "Arial", 20)
Repeat

Event = WaitWindowEvent()

If Event = #PB_Event_Gadget

If StartVectorDrawing(CanvasVectorOutput(1))

VectorFont(FontID(0), 18)

VectorSourceColor(RGBA(255, 255, 255, 255))
FillVectorOutput()

MovePathCursor(5, 5)

VectorSourceColor(RGBA(0, 0, 0, 255))

DrawVectorParagraph(GetGadgetText(0), VectorOutputWidth() - 10, VectorOutputHeight() - 10)
hh = VectorParagraphHeight(GetGadgetText(0),300, 300)
MovePathCursor(VectorOutputWidth() - VectorTextWidth("Height: ###"), 5)

DrawVectorText("Height: " + Str(hh) )

StopVectorDrawing()

EndIf

EndIf

Until Event = #PB_Event_CloseWindow
EndIf
Egypt my love
Post Reply