--- Begin Message ---
Subject: |
freetype cache and glyph metrics |
Date: |
Tue, 28 Sep 2010 21:50:48 -0700 |
Hello Werner,
I have been using freetype for some time and have come to my first
stumbling block: When using the image and font face caches, how can I
get the the full metrics of a glyph (metrics.horiBearingY, etc.)? It
seems that information is only available from the FT_GlyphSlotRec in
the face itself. When using the cache APIs all of my attempts to get
at the FT_Glyph_Metrics have yielded inconsistent results. Here is one
of my latest attempts:
void nlGfxContext :: GetGlyphMetrics(nlULONG aHeight, char aGlyph,
nlFontMetrics *aOutMetrics)
{
if ((mFont != NULL) && (aOutMetrics != NULL))
{
FT_Face font;
FTC_ScalerRec scaler;
scaler.face_id = mFont;
scaler.width = 0;
scaler.height = aHeight;
scaler.pixel = 1;
scaler.x_res = 0;
scaler.y_res = 0;
font = mGlobals->LookupFontID(mFont);
if (font != NULL)
{
FTC_ImageCache icache = mGlobals->GetFontImageCache();
FT_Glyph glyph;
FTC_Node node;
FT_UInt charidx = FT_Get_Char_Index(font, aGlyph);
FT_Error err;
err = FTC_ImageCache_LookupScaler(icache, &scaler,
FT_LOAD_DEFAULT, charidx, &glyph, &node);
FT_Load_Glyph(font, charidx, FT_LOAD_DEFAULT);
if (err == FT_Err_Ok)
{
aOutMetrics->mHeight = font->glyph->metrics.height >> 6;
aOutMetrics->mAscender = font->glyph->metrics.horiBearingY >> 6;
aOutMetrics->mDescender = -(aOutMetrics->mHeight -
aOutMetrics->mAscender);
aOutMetrics->mMaxAdvance =
font->glyph->metrics.horiAdvance >> 6;
FTC_Node_Unref(node, mGlobals->GetFontCacheManager());
}
}
}
}
This is my horrible attempt to use the image cache scaler to get the
glyph that i want at the size that i want and somehow get the glyph
metrics to be set as i want as part of the FT_Load_Glyph(). It seems
like it shouldn't work and it doesn't.
How does one get the metrics for an individual glyph and use the
caching subsystems at the same time?
I apologize in advance if this has been answered somewhere out on the
internet, but I was unable to find it.
Many thanks.
Michael Plitkins
--- End Message ---