freetype-devel
[Top][All Lists]
Advanced

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

RE: [Devel] compute bounding box


From: Thierry Frey
Subject: RE: [Devel] compute bounding box
Date: Mon, 23 Apr 2001 11:45:29 +0200

Tom,

Is this piece of code correct?

void Test()
{
  FT_ULong         charcode;
  FT_Error         error;
  FT_Face          face;
  FT_UInt          glyphIndex;
  FT_GlyphSlot     glyphSlot;
  FT_Glyph_Metrics glyphMetrics;

  // load arial font description
  error = FT_New_Face(_library,"C:/WINNT/Fonts/arial.ttf",0,&face);
  if (error) return;

  // set 10 point size
  error = FT_Set_Char_Size(face,0,10*64,72,72);
  if (error) return;

  // calculate width of sample text
  const char * text = "whiskey";

  int textWidth = 0;
  int i, I = strlen(text);
  for (i=0; i<I; i++)
  {
    charcode   = text[i];
    glyphIndex = FT_Get_Char_Index(face,charcode);
    error      = FT_Load_Glyph(face,glyphIndex,
                               FT_LOAD_DEFAULT       |
                               //FT_LOAD_LINEAR_DESIGN |
                               FT_LOAD_NO_SCALE      |
                               FT_LOAD_NO_BITMAP);
    glyphSlot    = face->glyph;
    glyphMetrics = glyphSlot->metrics;

    cout << text[i] << "   "  << glyphMetrics.horiAdvance << endl;
    textWidth += glyphMetrics.horiAdvance;
  }

  cout << " width of text: " << textWidth << endl;
}

What is the unit of glyphMetrics.horiAdvance? Does it depend on the flags given to FT_Load_Glyph? I find the documentation not really clear on this.

Thanks,
Thierry

> -----Original Message-----
> From: Tom Kacvinsky [mailto:address@hidden]
> Sent: Tuesday, April 17, 2001 10:35 PM
> To: FreeType Development
> Subject: Re: [Devel] compute bounding box
>
>
> Well, it is in the TODO list that computing the bbox of a
> glyph that uses cubic
> Bezier curves is broken.  Given the fact that you may want to
> use the bbox of
> each glyph shown in a string to compute the glocabl bbox of
> the string, I'd have
> to say that you are going to have problems with Type 1 fonts. :(
>
> But, supposing the glyph bbox code for each font format
> FreeType supports works and
> assuming a left to right (or right to left) language script:
>
> The height of the global bbox should be the maximum of
>
>    {y: y is the "height" of the bbox of a glyphs shown in the string}
>
> Similarly for the depth of the global bbox.  The left (right,
> resp.) edge is a
> rather simple case:  the left (right) edge of the first glyph
> shown (if kerning
> isn't wacked out).
>
> The right (or left) edge poses a problem, because the
> advanced width, kerning,
> and left side bearing tricks that can come into play.  I
> leave that up to the
> interested reader. :)
>
> Tom
>
> P.S.  Thierry, did the ASCI85 code I pointed out to you (on
> comp.text.pdf) work
> out?
>
>
>
> On Tue, 17 Apr 2001, Thierry Frey wrote:
>
> >
> > I was interested in using freetype to compute the bounding
> box of a given
> > string. Unfortunately, the FAQ only hints at this at the
> moment. Does
> > anybody have a more thorough answer? I'd be happy to write
> up something for
> > the FAQ afterwards.
> >
>
>
> _______________________________________________
> Devel mailing list
> address@hidden
> http://www.freetype.org/mailman/listinfo/devel
>


reply via email to

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