Recent

Author Topic: Font properties internal/external leading and others  (Read 9576 times)

Martin V

  • Full Member
  • ***
  • Posts: 139
Font properties internal/external leading and others
« on: August 13, 2010, 11:26:51 am »
Hello,

I did not managed yet to exactly place fonts. I realized that
- assigning a negative value to tFont.Width assigns a font width value in pixels which does not include the external leading (external leading means the space between lines which is not printed)
- assigning a positive value to tFont.Width assigns a font width value which represents the height of a font character in pixels without the non-printed space between the lines.

But if I query the font width property, I get a negative value, so I have no idea how to query the full width with external leading. If I get a positive value, I do not know the font width without external leading. This information can be necessary if you select a background color of the font where the height of the colored rectangle relates to the font width with external leading. (The background color of the font Canvas.Brush.Color only works in Windows at the moment.)

I also miss to query the position of the base line (the bottom line of most characters besides g, p...).

Any idea how to query all these font properties?

Martin

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9909
  • Debugger - SynEdit - and more
    • wiki
Re: Font properties internal/external leading and others
« Reply #1 on: August 13, 2010, 11:53:44 am »
have a look at GetTextMetrics

uses LCLType, LCLIntf;
var   TM: TTextMetric;

BoolIsOk = GetTextMetrics(DC, TM);

DC is a drawing context, eg canvas.handle

TM is
  tagTextMetricA = record
    tmHeight: Longint;
    tmAscent: Longint;
    tmDescent: Longint;
    tmInternalLeading: Longint;
    tmExternalLeading: Longint;
    tmAveCharWidth: Longint;
    tmMaxCharWidth: Longint;
    tmWeight: Longint;
    tmOverhang: Longint;
    tmDigitizedAspectX: Longint;
    tmDigitizedAspectY: Longint;
    tmFirstChar: AnsiChar;
    tmLastChar: AnsiChar;
    tmDefaultChar: AnsiChar;
    tmBreakChar: AnsiChar;
    tmItalic: Byte;
    tmUnderlined: Byte;
    tmStruckOut: Byte;
    tmPitchAndFamily: Byte;
    tmCharSet: Byte;
  end;



Note: afaik there is not yet support to get the half pixels on Carbon


In addition, some people reported that for some fonts (may be that the font was broken, but it worked in many other apps) the results were unusable.

SynEdit has some additional tests (for char width):
components\synedit\syntextdrawer.pp  line 572
C:\lazarus_latest\components\synedit\syntextdrawer.pp
This is expecting a monospaced font.

For the background:
SetBkColor(dc, ColorToRGB(colEditorBG));
« Last Edit: August 13, 2010, 12:06:06 pm by Martin_fr »

Martin V

  • Full Member
  • ***
  • Posts: 139
Re: Font properties internal/external leading and others
« Reply #2 on: August 14, 2010, 12:39:46 am »
Thank you, TextMetrics seems to work an all OS for the vertical dimensions (Height, InternalLeading, ExternalLeading, Ascent, Descent). For the horizontal dimensions, there still seems to be problems. One week ago, I've posted a sample program with monospaced font problems to the bugtracker which is already assigned.

Martin

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9909
  • Debugger - SynEdit - and more
    • wiki
Re: Font properties internal/external leading and others
« Reply #3 on: August 14, 2010, 01:44:49 am »
TextMetric also contains avg and max width; as well as PitchandFamily

Which could help as a workaround.

Interesting that Canvas.TextWidth fails, not that I tested it lately, but I remember it served well when I implemented the checks in SynEdit (probably a year back at least). (SynEdit uses GetTextExtentPoint, but so does TextWidth).

I run your program, and actually it seems that changing the fontname does not set the font under gtk2 (label1 doesn't change). So that is probably where the problem is.

---
Something else, that might be of interest to you, if you play with those things. Many such tests use "M" and "W" for finding the widest char. Surprisingly I found that in quite a few fonts the "@" is by far wider.

That excludes of course so called "full width" chars (Japanese, Chinese, Arabic), which even in a monospaced font have twice the width of the latin based chars

 

TinyPortal © 2005-2018