• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Fixed Font.TextHeight

Rich

Well-known member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
3rd Party Tool Dev
Joined
Sep 9, 2017
Messages
451
While looking at my font editor I noticed the following in graphics.cxs
Cerberus:
    Method TextHeight:Float( text:String )
        Return _height
    End
text:string looks redundant or it not actually returning the max height (including offsets) for the individual letters
 
I wonder why in javascript, its easy to get width of individual alphabet but not for height.
A lot of people do a work around by returning the height of a letter 'M'. Its like an average height !@!$#
 
Cerberus V2020-05-29 throws an error:

"Unable to find overload for TextHeight(String)"

Is there a way to calculate text height for a given font?

Code:
Import mojo

Class MyApp Extends App
  
    Method OnRender()
        Cls()

        DrawText("Height: " + TextHeight("Testing"), DeviceWidth()/2, DeviceHeight()/2)
    End
End

Function Main()
    New MyApp
End
 
@SimonVD : TextHeight( "testing") doesn't work like that. It only works with a font object and is a bit pointless passing a string of text as the font glyph's would all be the same height. Not sure what that function parameter was going to be used for, but it doesn't actually do anything.
Code:
Import mojo

Class MyApp Extends App
    Field myFont1:Font
    Field myFont2:Font
    
    Method OnCreate()
        myFont1 = Font.Load( "myfont1.png", 32, 96, True )
        myFont2 = Font.Load( "mojo_font.png", 32, 96, True )   
      End
      
    Method OnUpDate()
    End
    
    Method OnRender()
        Cls()
        SetFont(myFont1)
        DrawText("Font 1 height: "+myFont1.TextHeight("Testing"), 0, 0)
        SetFont(myFont2)
        DrawText("Font 2 height: "+myFont2.TextHeight(""), 0, myFont1.TextHeight("") )
    End
End

Function Main()
    New MyApp
End
See https://www.cerberus-x.com/cxDocs/Modules_mojo.graphics_Font.html
 

Attachments

  • myfont1.png
    myfont1.png
    12.1 KB · Views: 137
Replace the TextHeight method of the Font class with this code, that should do the trick.

Cerberus:
    Method TextHeight:Float( text:String = "" )
        If text = ""
            Return _height
        Else
            Local h:=0.0
            For Local char:=Eachin text
                Local glyph:=GetGlyph( char )
                If Not glyph Continue
                If h < glyph.height Then h = glyph.height
            Next   
            Return h
        Endif
    End
 
Back
Top Bottom