Changeset 762
- Timestamp:
- Apr 13, 2006, 5:36:09 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/tools/makefont.c
r755 r762 23 23 #include <pango/pango.h> 24 24 #include <pango/pangoft2.h> 25 26 #define FONT "Monospace 9"27 #define DPI 9628 #define BPP 429 25 30 26 static int const blocklist[] = … … 51 47 static int printf_u16(char const *, uint16_t); 52 48 53 int main( void)49 int main(int argc, char *argv[]) 54 50 { 55 51 PangoContext *cx; … … 60 56 61 57 FT_Bitmap img; 62 int width, height, b, i, n, blocks, glyphs, data_bytes; 58 int width, height, b, i, n, blocks, glyphs; 59 unsigned int glyph_size, control_size, data_size; 63 60 uint8_t *glyph_data; 64 61 65 int bpp = BPP; 66 int dpi = DPI; 67 char const *font = FONT; 62 unsigned int bpp, dpi; 63 char const *prefix, *font; 64 65 if(argc != 5) 66 { 67 fprintf(stderr, "%s: wrong argument count\n", argv[0]); 68 fprintf(stderr, "usage: %s <prefix> <font> <dpi> <bpp>\n", argv[0]); 69 fprintf(stderr, "eg: %s monospace9 \"Monospace 9\" 96 4\n", argv[0]); 70 return -1; 71 } 72 73 prefix = argv[1]; 74 font = argv[2]; 75 dpi = atoi(argv[3]); 76 bpp = atoi(argv[4]); 77 78 if(dpi == 0 || (bpp != 1 && bpp != 2 && bpp != 4 && bpp != 8)) 79 { 80 fprintf(stderr, "%s: invalid argument\n", argv[0]); 81 return -1; 82 } 68 83 69 84 fprintf(stderr, "Font \"%s\", %i dpi, %i bpp\n", font, dpi, bpp); … … 77 92 if(!l) 78 93 { 94 fprintf(stderr, "%s: unable to initialise pango\n", argv[0]); 79 95 g_object_unref(cx); 80 96 return -1; … … 98 114 width = PANGO_PIXELS(r.width); 99 115 height = PANGO_PIXELS(r.height); 100 data_bytes= ((width * height) + (8 / bpp) - 1) / (8 / bpp);101 glyph_data = malloc( data_bytes);116 glyph_size = ((width * height) + (8 / bpp) - 1) / (8 / bpp); 117 glyph_data = malloc(glyph_size); 102 118 103 119 /* Compute blocks and glyphs count */ … … 110 126 } 111 127 128 control_size = 24 + 12 * blocks + 8 * glyphs; 129 data_size = glyph_size * glyphs; 130 112 131 /* Let's go! */ 113 132 printf("/* libcucul font file\n"); 114 133 printf(" * \"%s\": %i dpi, %i bpp, %ix%i glyphs\n", 115 134 font, dpi, bpp, width, height); 116 printf(" * Automatically generated by tools/makefont.c */\n"); 117 printf("\n"); 135 printf(" * Automatically generated by tools/makefont.c:\n"); 136 printf(" * tools/makefont %s \"%s\" %i %i\n", prefix, font, dpi, bpp); 137 printf(" */\n"); 138 printf("\n"); 139 140 printf("static unsigned int const %s_size = %i;\n", 141 prefix, 8 + control_size + data_size); 142 printf("static unsigned char const %s_data[] =\n", prefix); 118 143 119 144 printf("/* file: */\n"); … … 123 148 124 149 printf("/* font_header: */\n"); 125 printf_u32("\"%s\" /* header_size */\n", 24 + 12 * blocks + 8 * glyphs);126 printf_u32("\"%s\" /* data_size */\n", data_ bytes * glyphs);150 printf_u32("\"%s\" /* control_size */\n", control_size); 151 printf_u32("\"%s\" /* data_size */\n", data_size); 127 152 printf_u16("\"%s\" /* version */\n", 1); 128 153 printf_u16("\"%s\" /* blocks */\n", blocks); … … 153 178 printf_u16("\"%s", width); 154 179 printf_u16("%s", height); 155 printf_u32("%s\"\n", n * data_bytes);180 printf_u32("%s\"\n", n * glyph_size); 156 181 n++; 157 182 } … … 205 230 /* Render glyph on a bitmap */ 206 231 pango_layout_set_text(l, buf, -1); 207 memset(glyph_data, 0, data_bytes);232 memset(glyph_data, 0, glyph_size); 208 233 memset(img.buffer, 0, img.pitch * height); 209 234 pango_ft2_render_layout(&img, l, 0, 0); … … 222 247 } 223 248 } 224 printf_hex("\"%s\"\n", glyph_data, data_bytes); 225 } 226 } 249 printf_hex("\"%s\"\n", glyph_data, glyph_size); 250 } 251 } 252 253 printf(";\n"); 227 254 228 255 free(img.buffer);
Note: See TracChangeset
for help on using the changeset viewer.