It is currently Sun Dec 16, 2018 7:08 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: VectorTextHeight differences on macOS/Linux and Windows
PostPosted: Tue Nov 06, 2018 8:24 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 296
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: VectorTextHeight differences on macOS/Linux and Windows
PostPosted: Tue Nov 06, 2018 9:14 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 870
Location: right here
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).


Top
 Profile  
Reply with quote  
 Post subject: Re: VectorTextHeight differences on macOS/Linux and Windows
PostPosted: Tue Nov 06, 2018 9:19 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3147
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: VectorTextHeight differences on macOS/Linux and Windows
PostPosted: Tue Nov 06, 2018 9:36 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 870
Location: right here
nope :) , doesn't change anything (on Linux).
But doc for VectorTextHeight() says
Quote:
Text$
The text (single-line) to measure.


Top
 Profile  
Reply with quote  
 Post subject: Re: VectorTextHeight differences on macOS/Linux and Windows
PostPosted: Tue Nov 06, 2018 9:47 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3147
Yes you are right
Then no bug
Try
Code:
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye