Welcome, Guest. Please login or register.

Author Topic: Fonts, fonts, fonts  (Read 2218 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show only replies by nyteschayde
    • http://www.nyteshade.com
Fonts, fonts, fonts
« 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?
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Offline Thomas

Re: Fonts, fonts, fonts
« Reply #1 on: January 31, 2017, 09:58:42 AM »
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().

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show only replies by nyteschayde
    • http://www.nyteshade.com
Re: Fonts, fonts, fonts
« Reply #2 on: January 31, 2017, 05:39:34 PM »
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
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

guest11527

  • Guest
Re: Fonts, fonts, fonts
« Reply #3 on: January 31, 2017, 06:51:14 PM »
Quote from: Thomas;821151
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.
 

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show only replies by nyteschayde
    • http://www.nyteshade.com
Re: Fonts, fonts, fonts
« Reply #4 on: January 31, 2017, 11:34:51 PM »
Again, thanks. I'll try to write an example for you to pick at and post it here later.
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500