]> git.tdb.fi Git - ttf2png.git/blobdiff - ttf2png.c
Round kerning values to nearest integer rather than down
[ttf2png.git] / ttf2png.c
index d7079d53794f5e7091ff029e4949744a9d92df1d..e890e33643084f7784c8d23e280555c425e8fec4 100644 (file)
--- a/ttf2png.c
+++ b/ttf2png.c
@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 typedef struct sImage
 {
        unsigned w, h;
-       char *data;
+       unsigned char *data;
 } Image;
 
 typedef struct sGlyph
@@ -265,6 +265,7 @@ int main(int argc, char **argv)
        free(font.glyphs);
        free(font.kerning);
        free(font.image.data);
+       free(ranges);
 
        FT_Done_Face(face);
        FT_Done_FreeType(freetype);
@@ -542,7 +543,7 @@ int init_font(Font *font, FT_Face face, const Range *ranges, unsigned n_ranges,
                                kern = &font->kerning[font->n_kerning++];
                                kern->left_code = font->glyphs[i].code;
                                kern->right_code = font->glyphs[j].code;
-                               kern->distance = kerning.x/64;
+                               kern->distance = (kerning.x+32)/64;
                        }
                }
 
@@ -627,7 +628,7 @@ int copy_bitmap(const FT_Bitmap *bmp, Image *image)
 {
        unsigned x, y;
        unsigned char *src;
-       char *dst;
+       unsigned char *dst;
 
        image->w = bmp->width;
        image->h = bmp->rows;
@@ -637,7 +638,7 @@ int copy_bitmap(const FT_Bitmap *bmp, Image *image)
                return 0;
        }
 
-       image->data = (char *)malloc(image->w*image->h);
+       image->data = (unsigned char *)malloc(image->w*image->h);
        if(!image->data)
        {
                fprintf(stderr, "Cannot allocate %d bytes of memory for glyph\n", image->w*image->h);
@@ -744,7 +745,7 @@ int render_grid(Font *font, unsigned cellw, unsigned cellh, unsigned cpl, bool s
        if(!npot)
                font->image.h = round_to_pot(font->image.h);
 
-       font->image.data = (char *)alloc_image_data(font->image.w, font->image.h);
+       font->image.data = (unsigned char *)alloc_image_data(font->image.w, font->image.h);
        if(!font->image.data)
                return -1;
        memset(font->image.data, 255, font->image.w*font->image.h);
@@ -821,7 +822,7 @@ int render_packed(Font *font, unsigned margin, unsigned padding, bool npot)
        glyphs.  Since glyphs are rectangular and the image is filled starting from
        the top, it's enough to track the number of used pixels at the top of each
        column. */
-       font->image.data = (char *)alloc_image_data(font->image.w, font->image.h);
+       font->image.data = (unsigned char *)alloc_image_data(font->image.w, font->image.h);
        if(!font->image.data)
                return -1;
        memset(font->image.data, 255, font->image.w*font->image.h);