|
From: | Bart De Lathouwer |
Subject: | calculating bounding box of a string |
Date: | Fri, 15 Sep 2000 23:40:08 +0200 |
Hi all,
I'm trying to calculate the bounding box of a
string using the method described further down.
Somehow this method is not quite exact. When i draw
the string, it's seems to be shorter that calculated.
(I did an example using the gara.ttf file on Win Nt
4 SP 4)
Am i using the correct procedure to calculate the
bounding box?
Thanks
Bart De Lathouwer
FT_BBox
ftText::getBoundingRect() { assert(m_face.face); FT_Error ftErr =
0;
FT_Pos origin_x = 0; FT_UInt previous_index = 0; m_bbox.xMin = 0;
m_bbox.yMin = 0; m_bbox.xMax = 0; m_bbox.yMax = 0; string::iterator i;
for (i = m_sText.begin(); i < m_sText.end(); i++) { //------------------------------------------------------------
FT_UInt glyph_index = FT_Get_Char_Index(m_face.face, *i); //------------------------------------------------------------
if (m_bKerning && previous_index && glyph_index) { FT_Vector delta = {0,0}; FT_Get_Kerning(m_face.face, previous_index, glyph_index, ft_kerning_default, &delta); m_bbox.xMax += delta.x; } //------------------------------------------------------------ ftErr = FT_Load_Glyph(m_face.face, glyph_index, FT_LOAD_DEFAULT); assert(ftErr == 0); //------------------------------------------------------------
FT_Glyph glyph; ftErr = FT_Get_Glyph(m_face.face->glyph, &glyph); FT_BBox box; FT_Glyph_Get_CBox(glyph, 0, &box); // grow bounding
box
m_bbox.xMax += m_face.face->glyph->advance.x; if (box.yMin < m_bbox.yMin) m_bbox.yMin = box.yMin; if (box.yMax > m_bbox.yMax) m_bbox.yMax = box.yMax; previous_index =
glyph_index;
} return
m_bbox;
} |
[Prev in Thread] | Current Thread | [Next in Thread] |