Page 1 of 1

Vertical text height?

Posted: Mon Jul 15, 2013 11:27 am
by Justin
Is there some way to get the vertical text height before drawing it?
Something like TextHeight(text, angle)
It has to be crossplatform.

Re: Vertical text height?

Posted: Mon Jul 15, 2013 1:08 pm
by TI-994A
Justin wrote:Is there some way to get the vertical text height before drawing it?
Something like TextHeight(text, angle)
Hi Justin. PureBasic has the TextHeight() function that returns the height of the currently selected drawing font in pixels, fully cross-platform:

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()
Hope that's what you're looking for.

Re: Vertical text height?

Posted: Mon Jul 15, 2013 2:11 pm
by Justin
Thanks, but this is for horizontal text. I need to draw vertical text like this:

Code: Select all

DrawRotatedText(x, y, "Some text", -90)
And later draw another vertical text just at the bottom of the previous text.
t
e
x
t
<--- here

Re: Vertical text height?

Posted: Mon Jul 15, 2013 2:51 pm
by Shield
For 90° just use TextWidth()?

Re: Vertical text height?

Posted: Mon Jul 15, 2013 3:34 pm
by Justin
TextWidth() seems to work, thanks!

Re: Vertical text height?

Posted: Mon Jul 15, 2013 3:40 pm
by Danilo
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