freetype
[Top][All Lists]
Advanced

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

Re: Initial pen position in freetype?


From: Andrew Tomazos
Subject: Re: Initial pen position in freetype?
Date: Wed, 22 Jul 2020 20:55:33 +1000

On Wed, Jul 22, 2020 at 12:36 AM Werner LEMBERG <wl@gnu.org> wrote:

>
> > After drawing a glyph with freetype the pen is advanced as follows:
> >
> > pen.x += face->glyph->advance.x;
> > pen.y += face->glyph->advance.y;
> >
> > (possibly plus a kerning delta)
> >
> > But my question is, how do you set the initial pen position of the
> > first character, relative to the upper left bound of the drawing
> > surface?
>
> Please have a look into the example programs, for example
>
>   https://www.freetype.org/freetype2/docs/tutorial/example1.c
>
> If this doesn't answer your question please go into more detail.
>

Hi Werner,

Thanks for responding.  In example1.c the initial pen position is set as
follows:

  /* the pen position in 26.6 cartesian space coordinates; */
  /* start at (300,200) relative to the upper left corner  */
  pen.x = 300 * 64;
  pen.y = ( target_height - 200 ) * 64;

which is just picking an arbitrary point (300,200) within the image to
place the origin of the first glyph.

My question is: rather than (300,200), is there some
"typographically-correct" point if we want the text to appear at the upper
left of the image?  Or, put another way, what is the minimal margin to the
left and above the origin of the first glyph?

Here is a list of the metrics I am collecting when the face size is set:

  ascender = FT_MulFix( face->ascender, face->size->metrics.y_scale );
  descender = FT_MulFix( face->descender, face->size->metrics.y_scale );
  height = FT_MulFix( face->height, face->size->metrics.y_scale );
  max_advance_width = FT_MulFix(face->max_advance_width,
face->size->metrics.x_scale);
  max_advance_height = FT_MulFix(face->max_advance_height,
face->size->metrics.y_scale);
  bbox_xMin = FT_MulFix(face->bbox.xMin, face->size->metrics.x_scale);
  bbox_xMax = FT_MulFix(face->bbox.xMax, face->size->metrics.x_scale);
  bbox_yMin = FT_MulFix(face->bbox.yMin, face->size->metrics.y_scale);
  bbox_yMax = FT_MulFix(face->bbox.yMax, face->size->metrics.y_scale);
  em_width = FT_MulFix(face->units_per_EM, face->size->metrics.x_scale);
  em_height = FT_MulFix(face->units_per_EM, face->size->metrics.y_scale);

(`height` for example is how far to advance downward to the next line on
newline)

My current wild-ass guess is something like `ascender` down and `em_width`
across ?  Is it clear what I am asking?

Thanks,
Andrew.


reply via email to

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