]> git.tdb.fi Git - ttf2png.git/blobdiff - ttf2png.c
Avoid warning about signed/unsigend mismatch
[ttf2png.git] / ttf2png.c
index 7ef19e14860d9590e8e748dfccde291c0779c1f1..f8f465ffd6bf80209032a66475069fe5728c9f44 100644 (file)
--- a/ttf2png.c
+++ b/ttf2png.c
@@ -61,8 +61,8 @@ typedef struct sFont
        Image    image;
 } Font;
 
-unsigned round_to_pot(unsigned);
 void usage();
+unsigned round_to_pot(unsigned);
 void *alloc_image_data(size_t, size_t);
 int init_font(Font *, FT_Face, unsigned, unsigned, int);
 int render_grid(Font *, unsigned, unsigned, unsigned, int);
@@ -271,21 +271,9 @@ int main(int argc, char **argv)
        return 0;
 }
 
-unsigned round_to_pot(unsigned n)
-{
-       n -= 1;
-       n |= n>>1;
-       n |= n>>2;
-       n |= n>>4;
-       n |= n>>8;
-       n |= n>>16;
-
-       return n+1;
-}
-
 void usage()
 {
-       printf("ttf2png - True Type Font to PNG converter\n"
+       printf("ttf2png 1.0 - True Type Font to PNG converter\n"
                "Copyright (c) 2004-2008  Mikko Rasa, Mikkosoft Productions\n"
                "Distributed under the GNU General Public License\n\n");
 
@@ -307,6 +295,18 @@ void usage()
                "  -h  Print this message\n");
 }
 
+unsigned round_to_pot(unsigned n)
+{
+       n -= 1;
+       n |= n>>1;
+       n |= n>>2;
+       n |= n>>4;
+       n |= n>>8;
+       n |= n>>16;
+
+       return n+1;
+}
+
 void *alloc_image_data(size_t a, size_t b)
 {
        void *ptr;
@@ -320,14 +320,14 @@ void *alloc_image_data(size_t a, size_t b)
                        a += c;
                if(a<c)
                {
-                       fprintf(stderr, "Cannot allocate %d kbytes of memory for image\n", c/1024*b);
+                       fprintf(stderr, "Cannot allocate %lu kbytes of memory for image\n", (unsigned long)(c/1024*b));
                        return NULL;
                }
                b /= 2;
        }
        ptr = malloc(a);
        if(!ptr)
-               fprintf(stderr, "Cannot allocate %d kbytes of memory for image\n", a/1024*b);
+               fprintf(stderr, "Cannot allocate %lu kbytes of memory for image\n", (unsigned long)(a/1024*b));
        return ptr;
 }
 
@@ -351,7 +351,7 @@ int init_font(Font *font, FT_Face face, unsigned first, unsigned last, int autoh
        {
                unsigned  n;
                FT_Bitmap *bmp = &face->glyph->bitmap;
-               int       x, y;
+               unsigned  x, y;
                int       flags = 0;
                Glyph     *glyph;
 
@@ -396,7 +396,7 @@ int init_font(Font *font, FT_Face face, unsigned first, unsigned last, int autoh
 
                /* Copy the glyph image since FreeType uses a global buffer, which would
                be overwritten by the next glyph.  Negative pitch means the scanlines
-               start from the bottom */
+               start from the bottom. */
                if(bmp->pitch<0)
                {
                        for(y=0; y<bmp->rows; ++y) for(x=0; x<bmp->width; ++x)
@@ -511,7 +511,10 @@ int render_grid(Font *font, unsigned cellw, unsigned cellh, unsigned cpl, int se
        last = font->glyphs[font->n_glyphs-1].code;
 
        font->image.w = round_to_pot(cpl*cellw);
-       font->image.h = round_to_pot((last-first+cpl)/cpl*cellh);
+       if(seq)
+               font->image.h = round_to_pot((font->n_glyphs+cpl-1)/cpl*cellh);
+       else
+               font->image.h = round_to_pot((last-first+cpl)/cpl*cellh);
 
        font->image.data = (char *)alloc_image_data(font->image.w, font->image.h);
        if(!font->image.data)
@@ -727,7 +730,7 @@ int save_png(const char *fn, const Image *image, char alpha)
        png_info   *pngi;
        png_byte   **rows;
        unsigned   i;
-       png_byte   *data2;
+       png_byte   *data2 = 0;
        int        color;
 
        if(!strcmp(fn, "-"))