- string_metrics measure_string(const std::wstring& str)
- {
- string_metrics result;
-
- bool use_kerning = (face_->face_flags & FT_FACE_FLAG_KERNING) == FT_FACE_FLAG_KERNING;
- int index = 0;
- FT_UInt previous = 0;
- double pos_x = 0;
-// float pos_y = 0;
-
- auto end = str.end();
- for(auto it = str.begin(); it != end; ++it, ++index)
- {
- auto glyph_it = glyphs_.find(*it);
- if(glyph_it != glyphs_.end())
- {
- const glyph_info& coords = glyph_it->second;
-
- FT_UInt glyph_index = FT_Get_Char_Index(face_.get(), (*it));
-
- if(use_kerning && previous && glyph_index)
- {
- FT_Vector delta;
- FT_Get_Kerning(face_.get(), previous, glyph_index, FT_KERNING_DEFAULT, &delta);
-
- pos_x += delta.x / 64.0;
- }
-
- FT_Load_Glyph(face_.get(), glyph_index, FT_LOAD_NO_BITMAP | FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_NORMAL);
-
- int bearingY = face_->glyph->metrics.horiBearingY >> 6;
- if(bearingY > result.bearingY)
- result.bearingY = bearingY;
-
- int protrudeUnderY = coords.height - bearingY;
-
- if (protrudeUnderY > result.protrudeUnderY)
- result.protrudeUnderY = protrudeUnderY;
-
- if (result.bearingY + result.protrudeUnderY > result.height)
- result.height = result.bearingY + result.protrudeUnderY;
-
- pos_x += face_->glyph->advance.x / 64.0;
- previous = glyph_index;
- }
- }
-
- result.width = (int)(pos_x+.5f);
- return result;
- }
-