From: Mikko Rasa Date: Thu, 3 May 2018 17:19:10 +0000 (+0300) Subject: Allocate slightly larger image when creating packed texture X-Git-Url: http://git.tdb.fi/?p=ttf2png.git;a=commitdiff_plain;h=2894ee8a8f6d5852f3cbda1e5b6f64e03d2356e9 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. --- 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