freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft] Fitting text to a limited display area


From: Werner LEMBERG
Subject: Re: [ft] Fitting text to a limited display area
Date: Thu, 16 Mar 2006 00:01:45 +0100 (CET)

> Hello, I'm hoping to get some advice on the problem I'm working
> on. In my application, I am given a limited display area for a
> single row of text. The text box is sized based on the number of
> characters it can hold, say one row of 20 characters. For any
> selected font, I need to chose the correct scale to fit any text
> string of the maximum length inside the box, with no character
> extending beyond the edge.

AFAIK, you have to use FT_Outline_Get_BBox also.

> Using FT_Set_Pixel_Sizes() gets me close, but often
> this will scale certain characters beyond the allowed
> bounds (many characters may be too tall to fit in the
> allowed height). The current idea is to reduce the
> scale until all characters fit. Can this be done
> reliably by using the data generated in
> face->size->metrics to calculate the maximum
> dimensions for the font?

No.  From the docs for FT_Size_Metrics:

      The scales, if relevant, are determined first during a size
      changing operation.  The remaining fields are then set by the
      driver.  For scalable formats, they are usually set to scaled
      values of the corresponding fields in @FT_FaceRec.

      Note that due to glyph hinting, these values might not be exact
      for certain fonts.  Thus they must be treated as unreliable with
      an error margin of at least one pixel!

      Indeed, the only way to get the exact metrics is to render _all_
      glyphs.  As this would be a definite performance hit, it is up
      to client applications to perform such computations.


   Werner




reply via email to

[Prev in Thread] Current Thread [Next in Thread]