|
|
@@ -1053,8 +1053,10 @@ ImFontConfig::ImFontConfig()
|
|
|
GlyphOffset = ImVec2(0.0f, 0.0f);
|
|
|
GlyphRanges = NULL;
|
|
|
MergeMode = false;
|
|
|
- DstFont = NULL;
|
|
|
+ RasterizerFlags = 0x00;
|
|
|
+ RasterizerMultiply = 1.0f;
|
|
|
memset(Name, 0, sizeof(Name));
|
|
|
+ DstFont = NULL;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
@@ -1342,6 +1344,23 @@ bool ImFontAtlas::Build()
|
|
|
return ImFontAtlasBuildWithStbTruetype(this);
|
|
|
}
|
|
|
|
|
|
+void ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], float in_brighten_factor)
|
|
|
+{
|
|
|
+ for (unsigned int i = 0; i < 256; i++)
|
|
|
+ {
|
|
|
+ unsigned int value = (unsigned int)(i * in_brighten_factor);
|
|
|
+ out_table[i] = value > 255 ? 255 : (value & 0xFF);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride)
|
|
|
+{
|
|
|
+ unsigned char* data = pixels + x + y * stride;
|
|
|
+ for (int j = h; j > 0; j--, data += stride)
|
|
|
+ for (int i = 0; i < w; i++)
|
|
|
+ data[i] = table[data[i]];
|
|
|
+}
|
|
|
+
|
|
|
bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|
|
{
|
|
|
IM_ASSERT(atlas->ConfigData.Size > 0);
|
|
|
@@ -1384,6 +1403,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|
|
{
|
|
|
stbtt_fontinfo FontInfo;
|
|
|
stbrp_rect* Rects;
|
|
|
+ int RectsCount;
|
|
|
stbtt_pack_range* Ranges;
|
|
|
int RangesCount;
|
|
|
};
|
|
|
@@ -1436,6 +1456,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|
|
|
|
|
// Pack
|
|
|
tmp.Rects = buf_rects + buf_rects_n;
|
|
|
+ tmp.RectsCount = font_glyphs_count;
|
|
|
buf_rects_n += font_glyphs_count;
|
|
|
stbtt_PackSetOversampling(&spc, cfg.OversampleH, cfg.OversampleV);
|
|
|
int n = stbtt_PackFontRangesGatherRects(&spc, &tmp.FontInfo, tmp.Ranges, tmp.RangesCount, tmp.Rects);
|
|
|
@@ -1465,6 +1486,14 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|
|
ImFontTempBuildData& tmp = tmp_array[input_i];
|
|
|
stbtt_PackSetOversampling(&spc, cfg.OversampleH, cfg.OversampleV);
|
|
|
stbtt_PackFontRangesRenderIntoRects(&spc, &tmp.FontInfo, tmp.Ranges, tmp.RangesCount, tmp.Rects);
|
|
|
+ if (cfg.RasterizerMultiply != 1.0f)
|
|
|
+ {
|
|
|
+ unsigned char multiply_table[256];
|
|
|
+ ImFontAtlasBuildMultiplyCalcLookupTable(multiply_table, cfg.RasterizerMultiply);
|
|
|
+ for (const stbrp_rect* r = tmp.Rects; r != tmp.Rects + tmp.RectsCount; r++)
|
|
|
+ if (r->was_packed)
|
|
|
+ ImFontAtlasBuildMultiplyRectAlpha8(multiply_table, spc.pixels, r->x, r->y, r->w, r->h, spc.stride_in_bytes);
|
|
|
+ }
|
|
|
tmp.Rects = NULL;
|
|
|
}
|
|
|
|
|
|
@@ -1480,15 +1509,15 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|
|
ImFontTempBuildData& tmp = tmp_array[input_i];
|
|
|
ImFont* dst_font = cfg.DstFont; // We can have multiple input fonts writing into a same destination font (when using MergeMode=true)
|
|
|
|
|
|
- float font_scale = stbtt_ScaleForPixelHeight(&tmp.FontInfo, cfg.SizePixels);
|
|
|
+ const float font_scale = stbtt_ScaleForPixelHeight(&tmp.FontInfo, cfg.SizePixels);
|
|
|
int unscaled_ascent, unscaled_descent, unscaled_line_gap;
|
|
|
stbtt_GetFontVMetrics(&tmp.FontInfo, &unscaled_ascent, &unscaled_descent, &unscaled_line_gap);
|
|
|
|
|
|
- float ascent = unscaled_ascent * font_scale;
|
|
|
- float descent = unscaled_descent * font_scale;
|
|
|
+ const float ascent = unscaled_ascent * font_scale;
|
|
|
+ const float descent = unscaled_descent * font_scale;
|
|
|
ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent);
|
|
|
- float off_x = cfg.GlyphOffset.x;
|
|
|
- float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f);
|
|
|
+ const float off_x = cfg.GlyphOffset.x;
|
|
|
+ const float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f);
|
|
|
|
|
|
dst_font->FallbackGlyph = NULL; // Always clear fallback so FindGlyph can return NULL. It will be set again in BuildLookupTable()
|
|
|
for (int i = 0; i < tmp.RangesCount; i++)
|