Vertical text height?

Share your advanced PureBasic knowledge/code with the community.
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Vertical text height?

Post 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.
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Vertical text height?

Post 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.
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 :D
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Re: Vertical text height?

Post 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
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Vertical text height?

Post by Shield »

For 90° just use TextWidth()?
Image
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
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Re: Vertical text height?

Post by Justin »

TextWidth() seems to work, thanks!
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Vertical text height?

Post 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
Post Reply