Is there some way to get the vertical text height before drawing it?
Something like TextHeight(text, angle)
It has to be crossplatform.
Vertical text height?
Re: Vertical text height?
Hi Justin. PureBasic has the TextHeight() function that returns the height of the currently selected drawing font in pixels, fully cross-platform:Justin wrote:Is there some way to get the vertical text height before drawing it?
Something like TextHeight(text, angle)
Code: Select all
OpenWindow(0, 50, 50, 100, 100, "Get Text Height")
LoadFont(1, "Arial", 10)
LoadFont(2, "Arial", 12)
LoadFont(3, "Arial", 14)
StartDrawing(WindowOutput(0))
Debug "Font heights in pixels:"
DrawingFont(FontID(1))
Debug TextHeight("ABC")
DrawingFont(FontID(2))
Debug TextHeight("ABC")
DrawingFont(FontID(3))
Debug TextHeight("ABC")
StopDrawing()
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: Vertical text height?
Thanks, but this is for horizontal text. I need to draw vertical text like this:
And later draw another vertical text just at the bottom of the previous text.
t
e
x
t
<--- here
Code: Select all
DrawRotatedText(x, y, "Some text", -90)
t
e
x
t
<--- here
Re: Vertical text height?
For 90° just use TextWidth()?
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Re: Vertical text height?
TextWidth() seems to work, thanks!
Re: Vertical text height?
For angles in between 0 and 90 degrees: hc = a * sin(ß) - triangle calculation
Code: Select all
Procedure DrawTheImage(degree)
text$ = "Hello World!"
If StartDrawing(ImageOutput(0))
Box(0, 0, 200, 200, RGB(255, 255, 255))
DrawingMode(#PB_2DDrawing_Transparent)
DrawRotatedText(10, 10, text$, -degree, RGB(0, 0, 0))
hc = TextWidth(text$) * Sin(Radian(degree)) ; hc = a * sin(ß)
hc + TextHeight(text$) ; add text height
DrawText(10,10+hc,"Next line.",0)
StopDrawing()
EndIf
SetGadgetState(0,ImageID(0))
EndProcedure
If OpenWindow(0, 0, 0, 300, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SpinGadget(1,210,10,80,25,0,90)
SetGadgetState(1,45)
If CreateImage(0, 200, 200)
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
DrawTheImage(45)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 1
deg = GetGadgetState(1)
SetGadgetText(1,Str(deg))
DrawTheImage(deg)
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
EndIf