Jump to content


Photo

Is there a way to obtain the font width in an e2 plugin?


  • Please log in to reply
No replies to this topic

#1 awx

  • Senior Member
  • 297 posts

+17
Neutral

Posted 7 December 2011 - 10:52

Does anyone know if there is a way to get the width of a font in an e2plugin?
As far as I can tell fontRender only has a function getLineHeight, if this is really the case would someone be willing to try out adding a function to get the width?
I will also try this but I have never built an e2 image so this may take a while.

The following code would need to be added to lib/gdi/font.cpp
float fontRenderClass::getFontWidth(const gFont& font)
{
if (!instance)
  return 0;
ePtr<Font> fnt;
getFont(fnt, font.family.c_str(), font.pointSize);
if (!fnt)
  return 0;
singleLock s(ftlock);
FT_Face current_face;
if ((FTC_Manager_LookupFace(cacheManager, fnt->scaler.face_id, &current_face) < 0) ||
	 (FTC_Manager_LookupSize(cacheManager, &fnt->scaler, &fnt->size) < 0))
{
  eDebug("FTC_Manager_Lookup_Size failed!");
  return 0;
}
int width = current_face->size->metrics.width;
if (!width)
{
  /* some fonts don't have width filled in. Estimate it based on the bbox dimensions. */
  /* Usually, 'width' is less than the complete boundingbox width, so we use only xMax, to avoid getting a much too large line spacing */
  width = FT_MulFix(current_face->bbox.xMax, current_face->size->metrics.x_scale);
}
return (width>>6);
}

The following function definition would need to be added to the fontRenderClass in font.h
float getLineHeight(const gFont& font);


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users