Replies: 1 comment 1 reply
-
Hope this helps. #include <codecvt>
std::string textInput;
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
auto textU32 = converter.from_bytes(textInput);
float scale = stbtt_ScaleForPixelHeight(&stbttInfo, pointSize);
int unscaledAscent;
int unscaledDescent;
int unscaledLineGap;
stbtt_GetFontVMetrics(&stbttInfo, &unscaledAscent, &unscaledDescent, &unscaledLineGap);
float ascent = roundf(float(unscaledAscent) * scale);
float descent = roundf(float(unscaledDescent) * scale);
for (char32_t codepoint : textU32) {
uint16_t glyphIndex = stbtt_FindGlyphIndex(&stbttInfo, (int)codepoint);
// Get advance.
int advanceWidth;
int leftSideBearing;
stbtt_GetGlyphHMetrics(&stbttInfo, glyphIndex, &advanceWidth, &leftSideBearing);
float advance = advanceWidth * scale;
// If you want a rasterized glyph, call stbtt_GetGlyphBitmap.
// If you want to render the glyph yourself, call stbtt_GetGlyphShape to get the glyph shapes.
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Anyone can give an example on how to render unicode font characters like CJK?
I'm using Microsoft YaHei to load font, but no clue where to start.
Beta Was this translation helpful? Give feedback.
All reactions