Skip to content

Commit d5d2383

Browse files
committed
always rescale when bitmap != glyph size
1 parent 9530ad5 commit d5d2383

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

misc/freetype/imgui_freetype.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,8 @@ static void ImGui_ImplFreeType_FontBakedDestroy(ImFontAtlas* atlas, ImFontConfig
514514
bd_baked_data->~ImGui_ImplFreeType_FontSrcBakedData(); // ~IM_PLACEMENT_DELETE()
515515
}
516516

517-
static void DownscaleBitmap(uint32_t* dst, const int dst_w, const int dst_h, uint32_t* src, const int src_w, const int src_h) {
518-
IM_ASSERT(dst_w <= src_w && dst_h <= src_h); // TODO: check if this is required
519-
517+
static void RescaleBitmap(uint32_t* dst, const int dst_w, const int dst_h, uint32_t* src, const int src_w, const int src_h)
518+
{
520519
#if 0
521520
// Point Sampling / Nearest Neighbor
522521
for (int y = 0; y < dst_h; y++)
@@ -644,8 +643,7 @@ static bool ImGui_ImplFreeType_FontBakedLoadGlyph(ImFontAtlas* atlas, ImFontConf
644643
{
645644
const int w = (int)ImCeil(bitmap_w * bitmap_x_scale);
646645
const int h = (int)ImCeil(bitmap_h * bitmap_y_scale);
647-
IM_ASSERT(!((h < bitmap_h && w > bitmap_w) || (h > bitmap_h && w < bitmap_w))); // Can't up AND downscale at the same time // TODO: or can we?
648-
const bool down_scaling = h < bitmap_h || w < bitmap_w;
646+
const bool rescaling = h != bitmap_h || w != bitmap_w;
649647

650648
ImFontAtlasRectId pack_id = ImFontAtlasPackAddRect(atlas, w, h);
651649
if (pack_id == ImFontAtlasRectId_Invalid)
@@ -656,20 +654,20 @@ static bool ImGui_ImplFreeType_FontBakedLoadGlyph(ImFontAtlas* atlas, ImFontConf
656654
}
657655
ImTextureRect* r = ImFontAtlasPackGetRect(atlas, pack_id);
658656

659-
// Render pixels to our temporary buffer, while making sure we have space for an extra copy used during downscaling.
660-
atlas->Builder->TempBuffer.resize(((down_scaling ? bitmap_w * bitmap_h : 0) + w * h) * 4);
657+
// Render pixels to our temporary buffer, while making sure we have space for an extra copy used during rescaling.
658+
atlas->Builder->TempBuffer.resize(((rescaling ? bitmap_w * bitmap_h : 0) + w * h) * 4);
661659
uint32_t* temp_buffer = (uint32_t*)atlas->Builder->TempBuffer.Data;
662-
// Blit (and convert) into the first bm_w * bm_h * 4 bytes.
660+
// Blit (and convert) into the first bitmap_w * bitmap_h * 4 bytes.
663661
ImGui_ImplFreeType_BlitGlyph(ft_bitmap, temp_buffer, bitmap_w);
664662

665-
if (down_scaling)
663+
if (rescaling)
666664
{
667665
uint32_t* dst_buffer = temp_buffer + bitmap_w * bitmap_h;
668666

669-
// Perform downscale, from temp_buffer (bitmap_w * bitmap_h) to dst_buffer (w * h)
670-
DownscaleBitmap(dst_buffer, w, h, temp_buffer, bitmap_w, bitmap_h);
667+
// Perform rescale, from temp_buffer (bitmap_w * bitmap_h) to dst_buffer (w * h)
668+
RescaleBitmap(dst_buffer, w, h, temp_buffer, bitmap_w, bitmap_h);
671669

672-
// Redirect to downscaled part of the buffer
670+
// Redirect to rescaled part of the buffer
673671
temp_buffer = dst_buffer;
674672
}
675673

0 commit comments

Comments
 (0)