Changeset 755 for libcaca/trunk/tools/makefont.c
- Timestamp:
- Apr 13, 2006, 2:44:55 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/tools/makefont.c
r754 r755 47 47 }; 48 48 49 static int printf_hex(char const *fmt, uint8_t *data, int bytes) 50 { 51 char buf[BUFSIZ]; 52 char *parser = buf; 53 int rewind = 0; /* we use this variable to rewind 2 bytes after \000 54 * was printed when the next char starts with "\", too. */ 55 56 while(bytes--) 57 { 58 uint8_t c = *data++; 59 if(c == '\\' || c == '"') 60 { 61 parser -= rewind; 62 parser += sprintf(parser, "\\%c", c); 63 rewind = 0; 64 } 65 else if(c >= 0x20 && c < 0x7f) 66 { 67 parser += sprintf(parser, "%c", c); 68 rewind = 0; 69 } 70 else 71 { 72 parser -= rewind; 73 parser += sprintf(parser, "\\%.03o", c); 74 rewind = c ? 0 : 2; 75 } 76 } 77 78 parser -= rewind; 79 parser[0] = '\0'; 80 81 return printf(fmt, buf); 82 } 83 84 static int printf_u32(char const *fmt, uint32_t i) 85 { 86 uint32_t ni = htonl(i); 87 return printf_hex(fmt, (uint8_t *)&ni, 4); 88 } 89 90 static int printf_u16(char const *fmt, uint16_t i) 91 { 92 uint16_t ni = htons(i); 93 return printf_hex(fmt, (uint8_t *)&ni, 2); 94 } 49 static int printf_hex(char const *, uint8_t *, int); 50 static int printf_u32(char const *, uint32_t); 51 static int printf_u16(char const *, uint16_t); 95 52 96 53 int main(void) … … 106 63 uint8_t *glyph_data; 107 64 65 int bpp = BPP; 66 int dpi = DPI; 67 char const *font = FONT; 68 69 fprintf(stderr, "Font \"%s\", %i dpi, %i bpp\n", font, dpi, bpp); 70 108 71 /* Initialise Pango */ 109 72 fm = pango_ft2_font_map_new(); 110 pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(fm), DPI, DPI);73 pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(fm), dpi, dpi); 111 74 cx = pango_ft2_font_map_create_context(PANGO_FT2_FONT_MAP(fm)); 112 75 … … 118 81 } 119 82 120 fd = pango_font_description_from_string( FONT);83 fd = pango_font_description_from_string(font); 121 84 pango_layout_set_font_description(l, fd); 122 85 pango_font_description_free(fd); … … 135 98 width = PANGO_PIXELS(r.width); 136 99 height = PANGO_PIXELS(r.height); 137 data_bytes = ((width * height) + (8 / BPP) - 1) / (8 / BPP);100 data_bytes = ((width * height) + (8 / bpp) - 1) / (8 / bpp); 138 101 glyph_data = malloc(data_bytes); 139 102 … … 150 113 printf("/* libcucul font file\n"); 151 114 printf(" * \"%s\": %i dpi, %i bpp, %ix%i glyphs\n", 152 FONT, DPI, BPP, width, height);115 font, dpi, bpp, width, height); 153 116 printf(" * Automatically generated by tools/makefont.c */\n"); 154 117 printf("\n"); … … 165 128 printf_u16("\"%s\" /* blocks */\n", blocks); 166 129 printf_u32("\"%s\" /* glyphs */\n", glyphs); 167 printf_u16("\"%s\" /* bpp */\n", BPP);130 printf_u16("\"%s\" /* bpp */\n", bpp); 168 131 printf_u16("\"%s\" /* width */\n", width); 169 132 printf_u16("\"%s\" /* height */\n", height); … … 236 199 237 200 if(i < 0x20 || (i >= 0x80 && i <= 0xa0)) 238 printf("\\x%.02x\" (", i);201 printf("\\x%.02x\" */", i); 239 202 else 240 printf("%s\" (", buf); 241 242 for(x = 0; x < bytes; x++) 243 printf("%s0x%.02X", x ? " " : "", (unsigned char)buf[x]); 244 245 printf(") */\n"); 203 printf("%s\" */ ", buf); 246 204 247 205 /* Render glyph on a bitmap */ … … 259 217 uint8_t pixel = img.buffer[y * img.pitch + x]; 260 218 261 pixel >>= (8 - BPP);262 glyph_data[n / 8] |= pixel << (8 - BPP- (n % 8));263 n += BPP;219 pixel >>= (8 - bpp); 220 glyph_data[n / 8] |= pixel << (8 - bpp - (n % 8)); 221 n += bpp; 264 222 } 265 223 } … … 275 233 } 276 234 235 /* 236 * XXX: the following functions are local 237 */ 238 239 static int printf_u32(char const *fmt, uint32_t i) 240 { 241 uint32_t ni = htonl(i); 242 return printf_hex(fmt, (uint8_t *)&ni, 4); 243 } 244 245 static int printf_u16(char const *fmt, uint16_t i) 246 { 247 uint16_t ni = htons(i); 248 return printf_hex(fmt, (uint8_t *)&ni, 2); 249 } 250 251 static int printf_hex(char const *fmt, uint8_t *data, int bytes) 252 { 253 char buf[BUFSIZ]; 254 char *parser = buf; 255 int rewind = 0; /* we use this variable to rewind 2 bytes after \000 256 * was printed when the next char starts with "\", too. */ 257 258 while(bytes--) 259 { 260 uint8_t c = *data++; 261 if(c == '\\' || c == '"') 262 { 263 parser -= rewind; 264 parser += sprintf(parser, "\\%c", c); 265 rewind = 0; 266 } 267 else if(c >= 0x20 && c < 0x7f) 268 { 269 parser += sprintf(parser, "%c", c); 270 rewind = 0; 271 } 272 else 273 { 274 parser -= rewind; 275 parser += sprintf(parser, "\\%.03o", c); 276 rewind = c ? 0 : 2; 277 } 278 } 279 280 parser -= rewind; 281 parser[0] = '\0'; 282 283 return printf(fmt, buf); 284 } 285
Note: See TracChangeset
for help on using the changeset viewer.