freetype
[Top][All Lists]
Advanced

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

Re: Initial pen position in freetype?


From: Werner LEMBERG
Subject: Re: Initial pen position in freetype?
Date: Fri, 31 Jul 2020 07:20:49 +0200 (CEST)

> For the record I ended up using as initial pen position:
> 
>   pen.x = 0;
>   pen.y = -face->size->metrics.ascender;
> 
> This seems to be the appropriate minimal border to the topleft of the
> origin of the first glyph.

This is a good start for many cases, but it won't work in general.
Let's assume that the upper left corner of your canvas is (x,y) =
(0,0).  If I understand you correctly you want a solution that ensures
that no ink is spilled in the range y < 0.  Derek gave the right
answer in

  https://lists.nongnu.org/archive/html/freetype/2020-07/msg00016.html

  [...]

  2) Spin through the text, collecting a list of glyphs and glyph
     metrics - you can do any fancy layout you want here

  3) Spin through the glyphs, get their bounding boxes, and calculate
     the bounds of the whole text, and thus the size of the necessary
     image

  4) Spin through the glyphs again and raster them to the image.

As mentioned in the docs and repeated again and again on this list,
the *only* reliable way to get the exact bounding box of a glyph
string is doing what Derek suggests.

In case this restriction is of no concern, the vertical distance of
the first baseline from the upper left corner might then be indeed
`-face->size->metrics.ascender`.

Could you provide a patch to the tutorial that clarifies this issue?


    Werner



reply via email to

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