• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Small footprint UI library for hardware accelerated games & applications


Commit MetaInfo

修订版8a55432524e095dd7d457a3418c57ac0dc319861 (tree)
时间2016-12-22 05:29:38
作者Emil Segerås <emilsegers@gmai...>
CommiterEmil Segerås

Log Message

Fix for STB glyph positioning, font sizes, and optimization.

tbtt_GetGlyphBitmapBoxSubpixel scale_x was 0, resulting in incorrect x
offset for glyphs.

Use calls taking glyph index instead of cp to reduce glyph lookups.

Removed magic constant since it only worked for Vera in 14px. The real
issue is that FT remaps font height (depending on table in font) while
STB don't.

更改概述

差异

--- a/Demo/demo01/Demo01.cpp
+++ b/Demo/demo01/Demo01.cpp
@@ -878,13 +878,20 @@ void DemoApplication::OnBackendAttached(AppBackend *backend, int width, int heig
878878 #endif
879879
880880 // Set the default font description for widgets to one of the fonts we just added
881+ // STB renders Lato smaller than FreeType since it ignores the size table in fonts.
882+ // To make demo look similar with all font engines, we use slightly different sizes.
883+ // This should match when running in 96dp, but will likely diverge for other DPIs (and fonts).
881884 TBFontDescription fd;
882-#if defined(TB_FONT_RENDERER_STB) || defined(TB_FONT_RENDERER_FREETYPE)
885+#if defined(TB_FONT_RENDERER_FREETYPE)
886+ fd.SetID(TBIDC("Lato"));
887+ fd.SetSize(g_tb_skin->GetDimensionConverter()->DpToPx(15));
888+#elif defined(TB_FONT_RENDERER_STB)
883889 fd.SetID(TBIDC("Lato"));
890+ fd.SetSize(g_tb_skin->GetDimensionConverter()->DpToPx(18));
884891 #else
885892 fd.SetID(TBIDC("Segoe"));
886-#endif
887893 fd.SetSize(g_tb_skin->GetDimensionConverter()->DpToPx(14));
894+#endif
888895 g_font_manager->SetDefaultFontDescription(fd);
889896
890897 // Create the font now.
--- a/src/tb/tb_font_renderer_stb.cpp
+++ b/src/tb/tb_font_renderer_stb.cpp
@@ -36,7 +36,6 @@ private:
3636 stbtt_fontinfo font;
3737 TBTempBuffer ttf_buffer;
3838 unsigned char *render_data;
39- int font_size;
4039 float scale;
4140 };
4241
@@ -74,10 +73,12 @@ bool STBFontRenderer::RenderGlyph(TBFontGlyphData *data, UCS4 cp)
7473 void STBFontRenderer::GetGlyphMetrics(TBGlyphMetrics *metrics, UCS4 cp)
7574 {
7675 int advance, leftSideBearing;
77- stbtt_GetCodepointHMetrics(&font, cp, &advance, &leftSideBearing);
76+ const int gi = stbtt_FindGlyphIndex(&font, cp);
77+ stbtt_GetGlyphHMetrics(&font, gi, &advance, &leftSideBearing);
7878 metrics->advance = (int) roundf(advance * scale);
79- int ix0, iy0, ix1, iy1;
80- stbtt_GetCodepointBitmapBox(&font, cp, 0, scale, &ix0, &iy0, &ix1, &iy1);
79+
80+ int ix0, iy0;
81+ stbtt_GetGlyphBitmapBoxSubpixel(&font, gi, scale, scale, 0.f, 0.f, &ix0, &iy0, 0, 0);
8182 metrics->x = ix0;
8283 metrics->y = iy0;
8384 }
@@ -100,8 +101,7 @@ bool STBFontRenderer::Load(const char *filename, int size)
100101 const unsigned char *ttf_ptr = (const unsigned char *) ttf_buffer.GetData();
101102 stbtt_InitFont(&font, ttf_ptr, stbtt_GetFontOffsetForIndex(ttf_ptr, 0));
102103
103- font_size = (int) (size * 1.3f); // FIX: Constant taken out of thin air because fonts get too small.
104- scale = stbtt_ScaleForPixelHeight(&font, (float)font_size);
104+ scale = stbtt_ScaleForPixelHeight(&font, (float) size);
105105 return true;
106106 }
107107