Skip to content

Commit 56caf7d

Browse files
committed
imgui_freetype: Minor tweaks and comments.
1 parent 7ed8e55 commit 56caf7d

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

misc/freetype/imgui_freetype.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Wrapper to use Freetype (instead of stb_truetype) for Dear ImGui
1+
// Wrapper to use FreeType (instead of stb_truetype) for Dear ImGui
22
// Get latest version at https://github.com/ocornut/imgui/tree/master/misc/freetype
33
// Original code by @Vuhdo (Aleksei Skriabin). Improvements by @mikesart. Maintained by @ocornut
44

@@ -20,15 +20,15 @@
2020
// TODO:
2121
// - Output texture has excessive resolution (lots of vertical waste).
2222
// - FreeType's memory allocator is not overridden.
23-
// - cfg.OversampleH, OversampleV are ignored (but perhaps not so necessary with this rasterizer).
23+
// - cfg.OversampleH, OversampleV are not supported (but perhaps not so necessary with this rasterizer).
2424

2525
#include "imgui_freetype.h"
2626
#include "imgui_internal.h" // ImMin,ImMax,ImFontAtlasBuild*,
2727
#include <stdint.h>
2828
#include <ft2build.h>
29-
#include FT_FREETYPE_H
30-
#include FT_GLYPH_H
31-
#include FT_SYNTHESIS_H
29+
#include FT_FREETYPE_H // <freetype/freetype.h>
30+
#include FT_GLYPH_H // <freetype/ftglyph.h>
31+
#include FT_SYNTHESIS_H // <freetype/ftsynth.h>
3232

3333
#ifdef _MSC_VER
3434
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
@@ -96,8 +96,8 @@ namespace
9696
// NB: No ctor/dtor, explicitly call Init()/Shutdown()
9797
struct FreeTypeFont
9898
{
99-
bool Init(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.
100-
void Shutdown();
99+
bool Create(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.
100+
void Destroy();
101101
void SetPixelHeight(int pixel_height); // Change font pixel size. All following calls to RasterizeGlyph() will use this size
102102

103103
bool CalcGlyphInfo(uint32_t codepoint, GlyphInfo& glyph_info, FT_Glyph& ft_glyph, FT_BitmapGlyph& ft_bitmap);
@@ -114,7 +114,7 @@ namespace
114114
// From SDL_ttf: Handy routines for converting from fixed point
115115
#define FT_CEIL(X) (((X + 63) & -64) / 64)
116116

117-
bool FreeTypeFont::Init(const ImFontConfig& cfg, unsigned int extra_user_flags)
117+
bool FreeTypeFont::Create(const ImFontConfig& cfg, unsigned int extra_user_flags)
118118
{
119119
// FIXME: substitute allocator
120120
FT_Error error = FT_Init_FreeType(&FreetypeLibrary);
@@ -130,7 +130,7 @@ namespace
130130
memset(&Info, 0, sizeof(Info));
131131
SetPixelHeight((uint32_t)cfg.SizePixels);
132132

133-
// Convert to freetype flags (nb: Bold and Oblique are processed separately)
133+
// Convert to FreeType flags (NB: Bold and Oblique are processed separately)
134134
UserFlags = cfg.RasterizerFlags | extra_user_flags;
135135
FreetypeLoadFlags = FT_LOAD_NO_BITMAP;
136136
if (UserFlags & ImGuiFreeType::NoHinting) FreetypeLoadFlags |= FT_LOAD_NO_HINTING;
@@ -146,7 +146,7 @@ namespace
146146
return true;
147147
}
148148

149-
void FreeTypeFont::Shutdown()
149+
void FreeTypeFont::Destroy()
150150
{
151151
if (FreetypeFace)
152152
{
@@ -162,6 +162,7 @@ namespace
162162
// I'm not sure how to deal with font sizes properly.
163163
// As far as I understand, currently ImGui assumes that the 'pixel_height' is a maximum height of an any given glyph,
164164
// i.e. it's the sum of font's ascender and descender. Seems strange to me.
165+
// FT_Set_Pixel_Sizes() doesn't seem to get us the same result.
165166
FT_Size_RequestRec req;
166167
req.type = FT_SIZE_REQUEST_TYPE_REAL_DIM;
167168
req.width = 0;
@@ -180,7 +181,7 @@ namespace
180181
Info.MaxAdvanceWidth = (float)FT_CEIL(metrics.max_advance);
181182
}
182183

183-
bool FreeTypeFont::CalcGlyphInfo(uint32_t codepoint, GlyphInfo &glyph_info, FT_Glyph& ft_glyph, FT_BitmapGlyph& ft_bitmap)
184+
bool FreeTypeFont::CalcGlyphInfo(uint32_t codepoint, GlyphInfo& glyph_info, FT_Glyph& ft_glyph, FT_BitmapGlyph& ft_bitmap)
184185
{
185186
uint32_t glyph_index = FT_Get_Char_Index(FreetypeFace, codepoint);
186187
if (glyph_index == 0)
@@ -253,7 +254,8 @@ bool ImGuiFreeType::BuildFontAtlas(ImFontAtlas* atlas, unsigned int extra_flags)
253254

254255
ImFontAtlasBuildRegisterDefaultCustomRects(atlas);
255256

256-
atlas->TexID = NULL;
257+
// Clear atlas
258+
atlas->TexID = (ImTextureID)NULL;
257259
atlas->TexWidth = atlas->TexHeight = 0;
258260
atlas->TexUvScale = ImVec2(0.0f, 0.0f);
259261
atlas->TexUvWhitePixel = ImVec2(0.0f, 0.0f);
@@ -273,7 +275,7 @@ bool ImGuiFreeType::BuildFontAtlas(ImFontAtlas* atlas, unsigned int extra_flags)
273275
FreeTypeFont& font_face = fonts[input_i];
274276
IM_ASSERT(cfg.DstFont && (!cfg.DstFont->IsLoaded() || cfg.DstFont->ContainerAtlas == atlas));
275277

276-
if (!font_face.Init(cfg, extra_flags))
278+
if (!font_face.Create(cfg, extra_flags))
277279
return false;
278280

279281
max_glyph_size.x = ImMax(max_glyph_size.x, font_face.Info.MaxAdvanceWidth);
@@ -380,7 +382,7 @@ bool ImGuiFreeType::BuildFontAtlas(ImFontAtlas* atlas, unsigned int extra_flags)
380382

381383
// Cleanup
382384
for (int n = 0; n < fonts.Size; n++)
383-
fonts[n].Shutdown();
385+
fonts[n].Destroy();
384386

385387
ImFontAtlasBuildFinish(atlas);
386388

misc/freetype/imgui_freetype.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Wrapper to use Freetype (instead of stb_truetype) for Dear ImGui
1+
// Wrapper to use FreeType (instead of stb_truetype) for Dear ImGui
22
// Get latest version at https://github.com/ocornut/imgui/tree/master/misc/freetype
33
// Original code by @Vuhdo (Aleksei Skriabin), maintained by @ocornut
44

0 commit comments

Comments
 (0)