File include/fg2/fg2.h changed (mode: 100755) (index 3b04ebc..acfc2b3) |
... |
... |
Font loadFont( std::string fileName, float fontSize, int oversampleX, int oversa |
2398 |
2398 |
float getTextWidthUtf32( std::u32string codepoints, Font &font ){ |
float getTextWidthUtf32( std::u32string codepoints, Font &font ){ |
2399 |
2399 |
Texture &tex = font.texture; |
Texture &tex = font.texture; |
2400 |
2400 |
if( !tex.success ) return 0.0f; |
if( !tex.success ) return 0.0f; |
|
2401 |
|
float kernScale = stbtt_ScaleForPixelHeight( &font.info, font.height ); |
2401 |
2402 |
// for stb_truetype's automatic positioning |
// for stb_truetype's automatic positioning |
2402 |
2403 |
float charX = 0.0f, charY = 0.0f; |
float charX = 0.0f, charY = 0.0f; |
2403 |
2404 |
for( size_t i = 0; i < codepoints.length(); i++ ){ |
for( size_t i = 0; i < codepoints.length(); i++ ){ |
|
... |
... |
float getTextWidthUtf32( std::u32string codepoints, Font &font ){ |
2408 |
2409 |
stbtt_GetPackedQuad( font.packedChars.data(), tex.width, tex.height, ci, &charX, &charY, &q, 0 ); |
stbtt_GetPackedQuad( font.packedChars.data(), tex.width, tex.height, ci, &charX, &charY, &q, 0 ); |
2409 |
2410 |
// set the kern offset for the next character |
// set the kern offset for the next character |
2410 |
2411 |
if( codepoints.length() - i > 1 ) |
if( codepoints.length() - i > 1 ) |
2411 |
|
charX += ( q.s1 - q.s0 ) * stbtt_GetCodepointKernAdvance( &font.info, cp, codepoints[ i + 1 ] ); |
|
|
2412 |
|
charX += stbtt_GetCodepointKernAdvance( &font.info, cp, codepoints[ i + 1 ] ) * kernScale; |
2412 |
2413 |
} |
} |
2413 |
2414 |
return charX; |
return charX; |
2414 |
2415 |
} |
} |
|
... |
... |
void drawTextUtf32( std::u32string codepoints, Font &font, float posX, float pos |
2427 |
2428 |
float leading = font.size * 1.2f; |
float leading = font.size * 1.2f; |
2428 |
2429 |
size_t wordStart = 0; |
size_t wordStart = 0; |
2429 |
2430 |
float wordStartX = 0.0f; |
float wordStartX = 0.0f; |
|
2431 |
|
float kernScale = stbtt_ScaleForPixelHeight( &font.info, font.height ); |
2430 |
2432 |
|
|
2431 |
2433 |
// for stb_truetype's automatic positioning |
// for stb_truetype's automatic positioning |
2432 |
2434 |
float charX = 0.0f, charY = 0.0f; |
float charX = 0.0f, charY = 0.0f; |
|
... |
... |
void drawTextUtf32( std::u32string codepoints, Font &font, float posX, float pos |
2447 |
2449 |
|
|
2448 |
2450 |
// set the kern offset for the next character |
// set the kern offset for the next character |
2449 |
2451 |
if( codepoints.length() - i > 1 ) |
if( codepoints.length() - i > 1 ) |
2450 |
|
charX += ( q.s1 - q.s0 ) * stbtt_GetCodepointKernAdvance( &font.info, cp, codepoints[ i + 1 ] ); |
|
|
2452 |
|
charX += stbtt_GetCodepointKernAdvance( &font.info, cp, codepoints[ i + 1 ] ) * kernScale; |
2451 |
2453 |
|
|
2452 |
2454 |
// handle newlines and word wrapping |
// handle newlines and word wrapping |
2453 |
2455 |
if( cp == ' ' ){ |
if( cp == ' ' ){ |
File include/fg3/fg3.h changed (mode: 100644) (index 07f2399..c8101da) |
... |
... |
Font loadFont( std::string fileName, float fontSize, int oversampleX, int oversa |
2631 |
2631 |
float getTextWidthUtf32( std::u32string codepoints, Font &font ){ |
float getTextWidthUtf32( std::u32string codepoints, Font &font ){ |
2632 |
2632 |
Texture &tex = font.texture; |
Texture &tex = font.texture; |
2633 |
2633 |
if( !tex.success ) return 0.0f; |
if( !tex.success ) return 0.0f; |
|
2634 |
|
float kernScale = stbtt_ScaleForPixelHeight( &font.info, font.height ); |
2634 |
2635 |
// for stb_truetype's automatic positioning |
// for stb_truetype's automatic positioning |
2635 |
2636 |
float charX = 0.0f, charY = 0.0f; |
float charX = 0.0f, charY = 0.0f; |
2636 |
2637 |
for( size_t i = 0; i < codepoints.length(); i++ ){ |
for( size_t i = 0; i < codepoints.length(); i++ ){ |
|
... |
... |
float getTextWidthUtf32( std::u32string codepoints, Font &font ){ |
2641 |
2642 |
stbtt_GetPackedQuad( font.packedChars.data(), tex.width, tex.height, ci, &charX, &charY, &q, 0 ); |
stbtt_GetPackedQuad( font.packedChars.data(), tex.width, tex.height, ci, &charX, &charY, &q, 0 ); |
2642 |
2643 |
// set the kern offset for the next character |
// set the kern offset for the next character |
2643 |
2644 |
if( codepoints.length() - i > 1 ) |
if( codepoints.length() - i > 1 ) |
2644 |
|
charX += ( q.s1 - q.s0 ) * stbtt_GetCodepointKernAdvance( &font.info, cp, codepoints[ i + 1 ] ); |
|
|
2645 |
|
charX += stbtt_GetCodepointKernAdvance( &font.info, cp, codepoints[ i + 1 ] ) * kernScale; |
2645 |
2646 |
} |
} |
2646 |
2647 |
return charX; |
return charX; |
2647 |
2648 |
} |
} |
|
... |
... |
void drawTextUtf32( std::u32string codepoints, Font &font, float posX, float pos |
2660 |
2661 |
float leading = font.size * 1.2f; |
float leading = font.size * 1.2f; |
2661 |
2662 |
size_t wordStart = 0; |
size_t wordStart = 0; |
2662 |
2663 |
float wordStartX = 0.0f; |
float wordStartX = 0.0f; |
|
2664 |
|
float kernScale = stbtt_ScaleForPixelHeight( &font.info, font.height ); |
2663 |
2665 |
|
|
2664 |
2666 |
// for stb_truetype's automatic positioning |
// for stb_truetype's automatic positioning |
2665 |
2667 |
float charX = 0.0f, charY = 0.0f; |
float charX = 0.0f, charY = 0.0f; |
|
... |
... |
void drawTextUtf32( std::u32string codepoints, Font &font, float posX, float pos |
2680 |
2682 |
|
|
2681 |
2683 |
// set the kern offset for the next character |
// set the kern offset for the next character |
2682 |
2684 |
if( codepoints.length() - i > 1 ) |
if( codepoints.length() - i > 1 ) |
2683 |
|
charX += ( q.s1 - q.s0 ) * stbtt_GetCodepointKernAdvance( &font.info, cp, codepoints[ i + 1 ] ); |
|
|
2685 |
|
charX += stbtt_GetCodepointKernAdvance( &font.info, cp, codepoints[ i + 1 ] ) * kernScale; |
2684 |
2686 |
|
|
2685 |
2687 |
// handle newlines and word wrapping |
// handle newlines and word wrapping |
2686 |
2688 |
if( cp == ' ' ){ |
if( cp == ' ' ){ |