]> git.tdb.fi Git - ttf2png.git/commitdiff
Allocate slightly larger image when creating packed texture
authorMikko Rasa <tdb@tdb.fi>
Thu, 3 May 2018 17:19:10 +0000 (20:19 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 3 May 2018 17:19:10 +0000 (20:19 +0300)
When rendering a very small number of glyphs the packing imperfections
become more pronounced, overflowing the allocated area more easily.

ttf2png.c

index a634b2b9def92998add21bd3e7ecfebf077db243..13e5a80489b0e5eb64976c9d595969931c24af65 100644 (file)
--- 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