Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for Kerning Support or Improved Text Positioning Documentation #15

Open
ZeunO8 opened this issue Jul 21, 2023 · 2 comments
Open

Comments

@ZeunO8
Copy link
Contributor

ZeunO8 commented Jul 21, 2023

Hello,

I have been using ttf2mesh for rendering text in my application, and I have encountered a challenge with the text positioning due to the lack of kerning support. Kerning is crucial for high-quality text rendering as it adjusts the space between individual character pairs to improve the visual appearance and perceived uniformity of the type.

While it is possible to render text without kerning by using glyph advances and bearings, the result is often less visually pleasing, particularly for certain character combinations that would typically have a kerning adjustment in professional typesetting.

As of now, the library does not seem to expose a way to access the kerning information from the original TrueType or OpenType font file. It would be extremely beneficial if ttf2mesh could parse and expose the kerning information from the font's "kern" table, allowing users to adjust the positioning of their text more accurately.

If this feature is not feasible, could you provide more detailed documentation or examples on how to best position text when using ttf2mesh? This would be incredibly helpful for users to get the best possible results with your library.

Thank you for your time and for the work you've put into ttf2mesh.

Best regards,
Zeun

@fetisov
Copy link
Owner

fetisov commented Jul 30, 2023

Hello.
You are right, currently kerning is not supported by the library. This function may be added in a future version of the library.
Thanks for the good feedback and constructive suggestion!
In this thread, I'll let you know when kerning will be added.

@ZeunO8
Copy link
Contributor Author

ZeunO8 commented Sep 22, 2023

After some testing I got text aligning correctly. Here is my code:

const vector<TTFGlyph> stringToGlyphs(const string &string, const vec3 &startPosition, const float &fontSize)
{
 int stringIndex(0);
 const int stringSize = string.size();
 vec3 currentPosition = startPosition;
 vec4 currentForegroundColor(1, 1, 1, 1);
 TTFGlyph *currentTTFGlyph = 0;
 vector<TTFGlyph> ttfGlyphs;
 float advanceX = 0;
 for (; stringIndex < stringSize; stringIndex++)
 {
  advanceX = 0;
  int codepoint = string[stringIndex];
  Integer32 glyphIndex = ttf_find_glyph(fontPointer.pointer, codepoint);
  if (glyphIndex < 0)
  {
   continue;
  }
  ttf_glyph_t *glyph = &fontPointer->glyphs[glyphIndex];
  advanceX = glyph->advance * fontSize;
  ttf_mesh3d_t *mesh;
  if (ttf_glyph2mesh3d(glyph, &mesh, TTF_QUALITY_NORMAL, TTF_FEATURES_DFLT, 0.1f) != TTF_DONE)
  {
   goto _advance;
  }
  currentTTFGlyph = new TTFGlyph(glyph, mesh, currentPosition, currentForegroundColor, vec3(fontSize));
  ttfGlyphs.push_back(currentTTFGlyph);
  ttf_free_mesh3d(mesh);
 _advance:
  currentPosition.x += advanceX;
 }
 return ttfGlyphs;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants