Amiga.org
Amiga computer related discussion => Amiga/MorphOS/AROS Programmers Forum => Topic started by: nyteschayde on January 31, 2017, 01:36:31 AM
-
So I am trying to figure out the best way to determine the actual size of rendered text given a particular font so that I can size and position things easily in Intuition with C. Rather than the trial and error approach of compiling, looking, modifying, recompiling and so forth.
Also, how does one get the information about the default fonts specified with the Font preferences in WB2+. There's the WB icon font, the system font and the title (?) font. When creating a new app, or gadget, I'd like to take the default font and size the UI correctly around that information.
Any sample code or pointers anyone can share?
-
With intuition.library you can use IntuiText->ITextFont->ta_YSize to get the height and IntuiTextLength() to get the width of the text.
With graphics.library cou'd get the height from RastPort->TxHeight and the width with TextLength(rp,text,length). Or use TextExtent() to get more detailed information.
The screen font can be read from Screen->Font (struct TextAttr) or Screen->RastPort.Font (struct TextFont).
The system font is available in GfxBase->DefaultFont or in RastPort->Font after a call to InitRastPort().
-
Seriously, Thomas, you're a true guru. Thanks for your help. I'll continue to pick your brain in public so others can learn from my own learnings; if you do not mind. <3
-
With graphics.library cou'd get the height from RastPort->TxHeight and the width with TextLength(rp,text,length). Or use TextExtent() to get more detailed information.
Be a bit careful with TextLength() because it might not do *quite* what you want. If the text is italic, it will actually extend to the left of the anchor position, namely the part below the base line, and it will also extend to the right of the end position computed with TextLength(), namely the part of the text above the base line.
IOWs, TextExtent() is the recommended method to get an idea how much room a given text will occupy in a window. TextLength() is just the number of pixels occupied by the base line of a given text.
-
Again, thanks. I'll try to write an example for you to pick at and post it here later.