mirror of
https://github.com/ocornut/imgui.git
synced 2025-04-04 21:15:09 +00:00
WIP - Added ImFontAtlasBakedSetFontGlyphBitmap().
This commit is contained in:
parent
4f8f7ff999
commit
8c7fbbc6ad
3 changed files with 39 additions and 39 deletions
|
@ -4373,9 +4373,10 @@ static bool ImGui_ImplStbTrueType_FontBakedAddGlyph(ImFontAtlas* atlas, ImFontBa
|
|||
const bool is_visible = (x0 != x1 && y0 != y1);
|
||||
|
||||
// Prepare glyph
|
||||
ImFontGlyph glyph;
|
||||
glyph.Codepoint = codepoint;
|
||||
glyph.AdvanceX = advance * scale_for_layout;
|
||||
ImFontGlyph glyph_in = {};
|
||||
ImFontGlyph* glyph = &glyph_in;
|
||||
glyph->Codepoint = codepoint;
|
||||
glyph->AdvanceX = advance * scale_for_layout;
|
||||
|
||||
// Pack and retrieve position inside texture atlas
|
||||
// (generally based on stbtt_PackFontRangesRenderIntoRects)
|
||||
|
@ -4423,25 +4424,18 @@ static bool ImGui_ImplStbTrueType_FontBakedAddGlyph(ImFontAtlas* atlas, ImFontBa
|
|||
// Register glyph
|
||||
// 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 = x0 * recip_h + font_off_x;
|
||||
glyph.Y0 = y0 * recip_v + font_off_y;
|
||||
glyph.X1 = (x0 + (int)r->w) * recip_h + font_off_x;
|
||||
glyph.Y1 = (y0 + (int)r->h) * recip_v + font_off_y;
|
||||
glyph.Visible = true;
|
||||
glyph.PackId = pack_id;
|
||||
ImFontAtlasBakedAddFontGlyph(atlas, baked, src, &glyph);
|
||||
|
||||
// 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);
|
||||
glyph->X0 = x0 * recip_h + font_off_x;
|
||||
glyph->Y0 = y0 * recip_v + font_off_y;
|
||||
glyph->X1 = (x0 + (int)r->w) * recip_h + font_off_x;
|
||||
glyph->Y1 = (y0 + (int)r->h) * recip_v + font_off_y;
|
||||
glyph->Visible = true;
|
||||
glyph->PackId = pack_id;
|
||||
glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, src, glyph);
|
||||
ImFontAtlasBakedSetFontGlyphBitmap(atlas, baked, src, glyph, r, bitmap_pixels, ImTextureFormat_Alpha8, w);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImFontAtlasBakedAddFontGlyph(atlas, baked, src, &glyph);
|
||||
glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, src, glyph);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -4894,6 +4888,17 @@ ImFontGlyph* ImFontAtlasBakedAddFontGlyph(ImFontAtlas* atlas, ImFontBaked* baked
|
|||
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 dst, ImWchar src, bool overwrite_dst)
|
||||
{
|
||||
// FIXME-BAKED: Implement AddRemapChar()
|
||||
|
|
|
@ -4063,6 +4063,7 @@ IMGUI_API void ImFontAtlasBuildGetOversampleFactors(ImFontConfig* s
|
|||
IMGUI_API bool ImFontAtlasBuildAcceptCodepointForSource(ImFontConfig* src, ImWchar codepoint);
|
||||
|
||||
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 void ImFontAtlasPackInit(ImFontAtlas* atlas);
|
||||
|
|
|
@ -546,9 +546,10 @@ bool ImGui_ImplFreeType_FontBakedAddGlyph(ImFontAtlas* atlas, ImFontBaked* baked
|
|||
const bool is_visible = (w != 0 && h != 0);
|
||||
|
||||
// Prepare glyph
|
||||
ImFontGlyph glyph = {};
|
||||
glyph.Codepoint = codepoint;
|
||||
glyph.AdvanceX = (slot->advance.x / FT_SCALEFACTOR) * bd_font_data->InvRasterizationDensity;
|
||||
ImFontGlyph glyph_in = {};
|
||||
ImFontGlyph* glyph = &glyph_in;
|
||||
glyph->Codepoint = codepoint;
|
||||
glyph->AdvanceX = (slot->advance.x / FT_SCALEFACTOR) * bd_font_data->InvRasterizationDensity;
|
||||
|
||||
// Pack and retrieve position inside texture atlas
|
||||
if (is_visible)
|
||||
|
@ -580,26 +581,19 @@ bool ImGui_ImplFreeType_FontBakedAddGlyph(ImFontAtlas* atlas, ImFontBaked* baked
|
|||
// Register glyph
|
||||
float glyph_off_x = (float)face->glyph->bitmap_left;
|
||||
float glyph_off_y = (float)-face->glyph->bitmap_top;
|
||||
glyph.X0 = glyph_off_x * recip_h + font_off_x;
|
||||
glyph.Y0 = glyph_off_y * recip_v + font_off_y;
|
||||
glyph.X1 = (glyph_off_x + w) * recip_h + font_off_x;
|
||||
glyph.Y1 = (glyph_off_y + h) * recip_v + font_off_y;
|
||||
glyph.Visible = true;
|
||||
glyph.Colored = (ft_bitmap->pixel_mode == FT_PIXEL_MODE_BGRA);
|
||||
glyph.PackId = pack_id;
|
||||
ImFontAtlasBakedAddFontGlyph(atlas, baked, src, &glyph);
|
||||
|
||||
// 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);
|
||||
glyph->X0 = glyph_off_x * recip_h + font_off_x;
|
||||
glyph->Y0 = glyph_off_y * recip_v + font_off_y;
|
||||
glyph->X1 = (glyph_off_x + w) * recip_h + font_off_x;
|
||||
glyph->Y1 = (glyph_off_y + h) * recip_v + font_off_y;
|
||||
glyph->Visible = true;
|
||||
glyph->Colored = (ft_bitmap->pixel_mode == FT_PIXEL_MODE_BGRA);
|
||||
glyph->PackId = pack_id;
|
||||
glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, src, glyph);
|
||||
ImFontAtlasBakedSetFontGlyphBitmap(atlas, baked, src, glyph, r, (const unsigned char*)temp_buffer, ImTextureFormat_RGBA32, w * 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImFontAtlasBakedAddFontGlyph(atlas, baked, src, &glyph);
|
||||
glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, src, glyph);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue