From 2894ee8a8f6d5852f3cbda1e5b6f64e03d2356e9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 3 May 2018 20:19:10 +0300 Subject: [PATCH] Allocate slightly larger image when creating packed texture When rendering a very small number of glyphs the packing imperfections become more pronounced, overflowing the allocated area more easily. --- ttf2png.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ttf2png.c b/ttf2png.c index a634b2b..13e5a80 100644 --- a/ttf2png.c +++ b/ttf2png.c @@ -919,18 +919,18 @@ int render_packed(Font *font, unsigned margin, unsigned padding, bool npot) area = a; } - /* Find an image size that's no higher than wide, allowing for some - imperfections in the packing. */ + /* Find an image size that's approximately square. */ for(font->image.w=1;; font->image.w<<=1) { if(font->image.w<=margin*2) continue; - font->image.h = (area*5/4)/(font->image.w-margin*2)+margin*2; + font->image.h = area/(font->image.w-margin*2)+margin*2; if(font->image.h<=font->image.w) break; } - if(!npot) - font->image.h = round_to_pot(font->image.h); + + /* Add some extra space to accommodate packing imperfections. */ + font->image.h = font->image.h*3/2; /* Allocate arrays for storing the image and keeping track of used pixels and glyphs. Since glyphs are rectangular and the image is filled starting from -- 2.45.2