Skip to content

Commit 8df8482

Browse files
committed
imgui_freetype: Fixed redundant FT_Load_Glyph() calls, unused parameters, and compilation warning/error. (#2270)
1 parent 6511300 commit 8df8482

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

misc/freetype/imgui_freetype.cpp

+8-28
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ namespace
9898
bool InitFont(FT_Library ft_library, const ImFontConfig& cfg, unsigned int extra_user_flags); // Initialize from an external data buffer. Doesn't copy data, and you must ensure it stays valid up to this object lifetime.
9999
void CloseFont();
100100
void SetPixelHeight(int pixel_height); // Change font pixel size. All following calls to RasterizeGlyph() will use this size
101-
const FT_Glyph_Metrics* LoadGlyph(uint32_t in_codepoint, uint32_t* out_glyph_index);
102-
const FT_Bitmap* RenderGlyphAndGetInfo(uint32_t in_glyph_index, GlyphInfo* out_glyph_info);
101+
const FT_Glyph_Metrics* LoadGlyph(uint32_t in_codepoint);
102+
const FT_Bitmap* RenderGlyphAndGetInfo(GlyphInfo* out_glyph_info);
103103
void BlitGlyph(const FT_Bitmap* ft_bitmap, uint8_t* dst, uint32_t dst_pitch, unsigned char* multiply_table = NULL);
104104
~FreeTypeFont() { CloseFont(); }
105105

@@ -177,21 +177,15 @@ namespace
177177
Info.MaxAdvanceWidth = (float)FT_CEIL(metrics.max_advance);
178178
}
179179

180-
const FT_Glyph_Metrics* FreeTypeFont::LoadGlyph(uint32_t codepoint, uint32_t* out_glyph_index)
180+
const FT_Glyph_Metrics* FreeTypeFont::LoadGlyph(uint32_t codepoint)
181181
{
182-
if (out_glyph_index)
183-
*out_glyph_index = 0;
184-
185182
uint32_t glyph_index = FT_Get_Char_Index(Face, codepoint);
186183
if (glyph_index == 0)
187184
return NULL;
188185
FT_Error error = FT_Load_Glyph(Face, glyph_index, LoadFlags);
189186
if (error)
190187
return NULL;
191188

192-
if (out_glyph_index)
193-
*out_glyph_index = glyph_index;
194-
195189
// Need an outline for this to work
196190
FT_GlyphSlot slot = Face->glyph;
197191
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE);
@@ -211,25 +205,12 @@ namespace
211205
return &slot->metrics;
212206
}
213207

214-
const FT_Bitmap* FreeTypeFont::RenderGlyphAndGetInfo(uint32_t in_glyph_index, GlyphInfo* out_glyph_info)
208+
const FT_Bitmap* FreeTypeFont::RenderGlyphAndGetInfo(GlyphInfo* out_glyph_info)
215209
{
216-
IM_ASSERT(in_glyph_index != 0);
217-
FT_Error error = FT_Load_Glyph(Face, in_glyph_index, LoadFlags);
218-
if (error)
219-
return NULL;
220-
221-
// Need an outline for this to work
222210
FT_GlyphSlot slot = Face->glyph;
223-
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE);
224-
225-
if (UserFlags & ImGuiFreeType::Bold)
226-
FT_GlyphSlot_Embolden(slot);
227-
if (UserFlags & ImGuiFreeType::Oblique)
228-
FT_GlyphSlot_Oblique(slot);
229-
230-
error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
211+
FT_Error error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
231212
if (error != 0)
232-
return false;
213+
return NULL;
233214

234215
FT_Bitmap* ft_bitmap = &Face->glyph->bitmap;
235216
out_glyph_info->Width = (int)ft_bitmap->width;
@@ -272,7 +253,6 @@ struct ImFontBuildSrcGlyphFT
272253
{
273254
GlyphInfo Info;
274255
uint32_t Codepoint;
275-
uint32_t GlyphIndex; // Index in font (to avoid calling FT_Get_Char_Index multiple times)
276256
unsigned char* BitmapData; // Point within one of the dst_tmp_bitmap_buffers[] array
277257
};
278258

@@ -446,13 +426,13 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns
446426
{
447427
ImFontBuildSrcGlyphFT& src_glyph = src_tmp.GlyphsList[glyph_i];
448428

449-
const FT_Glyph_Metrics* metrics = src_tmp.Font.LoadGlyph(src_glyph.Codepoint, &src_glyph.GlyphIndex);
429+
const FT_Glyph_Metrics* metrics = src_tmp.Font.LoadGlyph(src_glyph.Codepoint);
450430
IM_ASSERT(metrics != NULL);
451431
if (metrics == NULL)
452432
continue;
453433

454434
// Render glyph into a bitmap (currently held by FreeType)
455-
const FT_Bitmap* ft_bitmap = src_tmp.Font.RenderGlyphAndGetInfo(src_glyph.GlyphIndex, &src_glyph.Info);
435+
const FT_Bitmap* ft_bitmap = src_tmp.Font.RenderGlyphAndGetInfo(&src_glyph.Info);
456436
IM_ASSERT(ft_bitmap);
457437

458438
// Allocate new temporary chunk if needed

0 commit comments

Comments
 (0)