Well, I am not entirely sure what you want to do. Using horiBearingY as the ascender seems weird - do you really want to use glyph metrics for line metrics? Or do you really need the ascender/descender info for every glyph? In any case, you shouldn't be calling FT_Load_Glyph when using the cache system. Instead, you let the cache subsytem make that call using the load flags you supply to FTC_ImageCache_LookupScaler(). That gives you an FT_Glyph which you can use for basic glyph metrics. Specifically the "advance" vector of that struct tells you how far to move to account for this glyph. In a more interesting case, you would pass FT_LOAD_RENDER to the cache subsystem, which should make the returned glyph be an FT_BitmapGlyph. That in turn gives you the left/top coordinates for the actual bitmap, plus an FT_Bitmap struct you can use for more information. Once you have the top and left values, you can essentially calculate the horibearingX/Y, though you may not need to bother. The nice thing about using the cache is, in most cases rendering is fast (already cached). It's only a problem if you plan to measure a *lot* of glyphs that you don't plan to render. Of course, in that case there isn't much point in using the cache at all.
You might also want to consider caching the char map using FTC_CMapCache_Lookup instead of FT_Get_Char_Index.
--Brady
On Sep 28, 2010, at 11:30 PM, Werner LEMBERG wrote: Please help this guy.
Werner
Date: September 28, 2010 9:50:48 PM PDT
Subject: freetype cache and glyph metrics
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
_______________________________________________ Freetype mailing list address@hidden http://lists.nongnu.org/mailman/listinfo/freetype
|