Fonts: Added ImFontAtlasBakedSetFontGlyphBitmap().
This commit is contained in:
+24
-19
@@ -4370,9 +4370,10 @@ static bool ImGui_ImplStbTrueType_FontBakedAddGlyph(ImFontAtlas* atlas, ImFontBa
|
|||||||
const bool is_visible = (x0 != x1 && y0 != y1);
|
const bool is_visible = (x0 != x1 && y0 != y1);
|
||||||
|
|
||||||
// Prepare glyph
|
// Prepare glyph
|
||||||
ImFontGlyph glyph;
|
ImFontGlyph glyph_in = {};
|
||||||
glyph.Codepoint = codepoint;
|
ImFontGlyph* glyph = &glyph_in;
|
||||||
glyph.AdvanceX = advance * scale_for_layout;
|
glyph->Codepoint = codepoint;
|
||||||
|
glyph->AdvanceX = advance * scale_for_layout;
|
||||||
|
|
||||||
// Pack and retrieve position inside texture atlas
|
// Pack and retrieve position inside texture atlas
|
||||||
// (generally based on stbtt_PackFontRangesRenderIntoRects)
|
// (generally based on stbtt_PackFontRangesRenderIntoRects)
|
||||||
@@ -4420,25 +4421,18 @@ static bool ImGui_ImplStbTrueType_FontBakedAddGlyph(ImFontAtlas* atlas, ImFontBa
|
|||||||
// Register glyph
|
// Register glyph
|
||||||
// r->x r->y are coordinates inside texture (in pixels)
|
// r->x r->y are coordinates inside texture (in pixels)
|
||||||
// glyph.X0, glyph.Y0 are drawing coordinates from base text position, and accounting for oversampling.
|
// glyph.X0, glyph.Y0 are drawing coordinates from base text position, and accounting for oversampling.
|
||||||
glyph.X0 = x0 * recip_h + font_off_x;
|
glyph->X0 = x0 * recip_h + font_off_x;
|
||||||
glyph.Y0 = y0 * recip_v + font_off_y;
|
glyph->Y0 = y0 * recip_v + font_off_y;
|
||||||
glyph.X1 = (x0 + (int)r->w) * recip_h + font_off_x;
|
glyph->X1 = (x0 + (int)r->w) * recip_h + font_off_x;
|
||||||
glyph.Y1 = (y0 + (int)r->h) * recip_v + font_off_y;
|
glyph->Y1 = (y0 + (int)r->h) * recip_v + font_off_y;
|
||||||
glyph.Visible = true;
|
glyph->Visible = true;
|
||||||
glyph.PackId = pack_id;
|
glyph->PackId = pack_id;
|
||||||
ImFontAtlasBakedAddFontGlyph(atlas, baked, src, &glyph);
|
glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, src, glyph);
|
||||||
|
ImFontAtlasBakedSetFontGlyphBitmap(atlas, baked, src, glyph, r, bitmap_pixels, ImTextureFormat_Alpha8, w);
|
||||||
// Copy to texture, post-process and queue update for backend
|
|
||||||
ImTextureData* tex = atlas->TexData;
|
|
||||||
IM_ASSERT(r->x + r->w <= tex->Width && r->y + r->h <= tex->Height);
|
|
||||||
ImFontAtlasTextureBlockConvert(bitmap_pixels, ImTextureFormat_Alpha8, w, tex->GetPixelsAt(r->x, r->y), tex->Format, tex->GetPitch(), w, h);
|
|
||||||
ImFontAtlasPostProcessData pp_data = { atlas, baked->ContainerFont, src, baked, &baked->Glyphs.back(), tex->GetPixelsAt(r->x, r->y), tex->Format, tex->GetPitch(), w, h };
|
|
||||||
ImFontAtlasTextureBlockPostProcess(&pp_data);
|
|
||||||
ImFontAtlasTextureBlockQueueUpload(atlas, tex, r->x, r->y, r->w, r->h);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImFontAtlasBakedAddFontGlyph(atlas, baked, src, &glyph);
|
glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, src, glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -4891,6 +4885,17 @@ ImFontGlyph* ImFontAtlasBakedAddFontGlyph(ImFontAtlas* atlas, ImFontBaked* baked
|
|||||||
return &glyph;
|
return &glyph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy to texture, post-process and queue update for backend
|
||||||
|
void ImFontAtlasBakedSetFontGlyphBitmap(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, ImFontGlyph* glyph, ImFontAtlasRect* r, const unsigned char* src_pixels, ImTextureFormat src_fmt, int src_pitch)
|
||||||
|
{
|
||||||
|
ImTextureData* tex = atlas->TexData;
|
||||||
|
IM_ASSERT(r->x + r->w <= tex->Width && r->y + r->h <= tex->Height);
|
||||||
|
ImFontAtlasTextureBlockConvert(src_pixels, src_fmt, src_pitch, tex->GetPixelsAt(r->x, r->y), tex->Format, tex->GetPitch(), r->w, r->h);
|
||||||
|
ImFontAtlasPostProcessData pp_data = { atlas, baked->ContainerFont, src, baked, glyph, tex->GetPixelsAt(r->x, r->y), tex->Format, tex->GetPitch(), r->w, r->h };
|
||||||
|
ImFontAtlasTextureBlockPostProcess(&pp_data);
|
||||||
|
ImFontAtlasTextureBlockQueueUpload(atlas, tex, r->x, r->y, r->w, r->h);
|
||||||
|
}
|
||||||
|
|
||||||
void ImFont::AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint, bool overwrite_dst)
|
void ImFont::AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint, bool overwrite_dst)
|
||||||
{
|
{
|
||||||
// FIXME-BAKED: Implement AddRemapChar()
|
// FIXME-BAKED: Implement AddRemapChar()
|
||||||
|
|||||||
@@ -3777,6 +3777,7 @@ IMGUI_API void ImFontAtlasBuildGetOversampleFactors(ImFontConfig* s
|
|||||||
IMGUI_API bool ImFontAtlasBuildAcceptCodepointForSource(ImFontConfig* src, ImWchar codepoint);
|
IMGUI_API bool ImFontAtlasBuildAcceptCodepointForSource(ImFontConfig* src, ImWchar codepoint);
|
||||||
|
|
||||||
IMGUI_API ImFontGlyph* ImFontAtlasBakedAddFontGlyph(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, const ImFontGlyph* in_glyph);
|
IMGUI_API ImFontGlyph* ImFontAtlasBakedAddFontGlyph(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, const ImFontGlyph* in_glyph);
|
||||||
|
IMGUI_API void ImFontAtlasBakedSetFontGlyphBitmap(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, ImFontGlyph* glyph, ImFontAtlasRect* r, const unsigned char* src_pixels, ImTextureFormat src_fmt, int src_pitch);
|
||||||
IMGUI_API ImGuiID ImFontAtlasBakedGetId(ImGuiID font_id, float baked_size);
|
IMGUI_API ImGuiID ImFontAtlasBakedGetId(ImGuiID font_id, float baked_size);
|
||||||
|
|
||||||
IMGUI_API void ImFontAtlasPackInit(ImFontAtlas* atlas);
|
IMGUI_API void ImFontAtlasPackInit(ImFontAtlas* atlas);
|
||||||
|
|||||||
@@ -546,9 +546,10 @@ bool ImGui_ImplFreeType_FontBakedAddGlyph(ImFontAtlas* atlas, ImFontBaked* baked
|
|||||||
const bool is_visible = (w != 0 && h != 0);
|
const bool is_visible = (w != 0 && h != 0);
|
||||||
|
|
||||||
// Prepare glyph
|
// Prepare glyph
|
||||||
ImFontGlyph glyph = {};
|
ImFontGlyph glyph_in = {};
|
||||||
glyph.Codepoint = codepoint;
|
ImFontGlyph* glyph = &glyph_in;
|
||||||
glyph.AdvanceX = (slot->advance.x / FT_SCALEFACTOR) * bd_font_data->InvRasterizationDensity;
|
glyph->Codepoint = codepoint;
|
||||||
|
glyph->AdvanceX = (slot->advance.x / FT_SCALEFACTOR) * bd_font_data->InvRasterizationDensity;
|
||||||
|
|
||||||
// Pack and retrieve position inside texture atlas
|
// Pack and retrieve position inside texture atlas
|
||||||
if (is_visible)
|
if (is_visible)
|
||||||
@@ -580,26 +581,19 @@ bool ImGui_ImplFreeType_FontBakedAddGlyph(ImFontAtlas* atlas, ImFontBaked* baked
|
|||||||
// Register glyph
|
// Register glyph
|
||||||
float glyph_off_x = (float)face->glyph->bitmap_left;
|
float glyph_off_x = (float)face->glyph->bitmap_left;
|
||||||
float glyph_off_y = (float)-face->glyph->bitmap_top;
|
float glyph_off_y = (float)-face->glyph->bitmap_top;
|
||||||
glyph.X0 = glyph_off_x * recip_h + font_off_x;
|
glyph->X0 = glyph_off_x * recip_h + font_off_x;
|
||||||
glyph.Y0 = glyph_off_y * recip_v + font_off_y;
|
glyph->Y0 = glyph_off_y * recip_v + font_off_y;
|
||||||
glyph.X1 = (glyph_off_x + w) * recip_h + font_off_x;
|
glyph->X1 = (glyph_off_x + w) * recip_h + font_off_x;
|
||||||
glyph.Y1 = (glyph_off_y + h) * recip_v + font_off_y;
|
glyph->Y1 = (glyph_off_y + h) * recip_v + font_off_y;
|
||||||
glyph.Visible = true;
|
glyph->Visible = true;
|
||||||
glyph.Colored = (ft_bitmap->pixel_mode == FT_PIXEL_MODE_BGRA);
|
glyph->Colored = (ft_bitmap->pixel_mode == FT_PIXEL_MODE_BGRA);
|
||||||
glyph.PackId = pack_id;
|
glyph->PackId = pack_id;
|
||||||
ImFontAtlasBakedAddFontGlyph(atlas, baked, src, &glyph);
|
glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, src, glyph);
|
||||||
|
ImFontAtlasBakedSetFontGlyphBitmap(atlas, baked, src, glyph, r, (const unsigned char*)temp_buffer, ImTextureFormat_RGBA32, w * 4);
|
||||||
// Copy to texture, post-process and queue update for backend
|
|
||||||
ImTextureData* tex = atlas->TexData;
|
|
||||||
IM_ASSERT(r->x + r->w <= tex->Width && r->y + r->h <= tex->Height);
|
|
||||||
ImFontAtlasTextureBlockConvert(temp_buffer, ImTextureFormat_RGBA32, w * 4, tex->GetPixelsAt(r->x, r->y), tex->Format, tex->GetPitch(), w, h);
|
|
||||||
ImFontAtlasPostProcessData pp_data = { atlas, baked->ContainerFont, src, baked, &baked->Glyphs.back(), tex->GetPixelsAt(r->x, r->y), tex->Format, tex->GetPitch(), w, h };
|
|
||||||
ImFontAtlasTextureBlockPostProcess(&pp_data);
|
|
||||||
ImFontAtlasTextureBlockQueueUpload(atlas, tex, r->x, r->y, r->w, r->h);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImFontAtlasBakedAddFontGlyph(atlas, baked, src, &glyph);
|
glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, src, glyph);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user