6 #define DEFAULT_PIXEL_SIZE 16
10 /* Format MSG by FMT and print the result to the stderr, and exit. */
12 #define FATAL_ERROR(fmt, arg) \
14 fprintf (stderr, fmt, arg); \
19 dump_header (FT_Face face, char *foundry, int nchars, int pixel_size)
21 int width = ((face->bbox.xMax - face->bbox.xMin)
22 * pixel_size / face->units_per_EM);
23 int height = ((face->bbox.yMax - face->bbox.yMin)
24 * pixel_size / face->units_per_EM);
25 int x = face->bbox.xMin * pixel_size / face->units_per_EM;
26 int y = face->bbox.yMin * pixel_size / face->units_per_EM;
28 printf ("STARTFONT 2.1\n");
29 printf ("FONT -%s-%s-%s-R-Normal--%d-%d-72-72-C-%d-ISO10646-1\n",
30 foundry, face->family_name, face->style_name,
31 pixel_size, pixel_size * 10, pixel_size * 10);
32 printf ("SIZE %d 72 72\n", pixel_size);
33 printf ("FONTBOUNDINGBOX %d %d %d %d\n", width, height, x, y);
34 printf ("STARTPROPERTIES 2\n");
35 printf ("FONT_ASCENT %d\n", y + height);
36 printf ("FONT_DESCENT %d\n", -y);
37 printf ("ENDPROPERTIES 0\n");
38 printf ("CHARS %d\n", nchars);
48 dump_image (int pixel_size, int index, int code, int full)
50 int err = FT_Load_Glyph (face, index, FT_LOAD_RENDER | FT_LOAD_MONOCHROME);
59 if (glyph->bitmap.rows * glyph->bitmap.width == 0)
61 printf ("STARTCHAR U+%04X\n", code);
62 printf ("ENCODING %d\n", code);
63 printf ("SWIDTH %d 0\n",
64 (int) (glyph->metrics.horiAdvance >> 6) * 1000 / pixel_size);
67 dwidth = glyph->bitmap.width;
72 dwidth = glyph->metrics.horiAdvance >> 6;
73 x = glyph->metrics.horiBearingX >> 6;
75 y = (glyph->metrics.horiBearingY - glyph->metrics.height) >> 6;
76 printf ("DWIDTH %d 0\n", dwidth);
77 printf ("BBX %d %d %d %d\n", glyph->bitmap.width, glyph->bitmap.rows, x, y);
79 buf = (unsigned char *) glyph->bitmap.buffer;
80 for (i = 0; i < glyph->bitmap.rows; i++)
82 for (j = 0; j < (glyph->bitmap.width + 7) / 8; j++)
83 printf ("%02X", buf[i * glyph->bitmap.pitch + j]);
90 main (int argc, char **argv)
95 int pixel_size = DEFAULT_PIXEL_SIZE;
96 FT_UInt unicode_table[0x10000];
100 FATAL_ERROR ("%s\n", "Usage: otfimage [ X-OPTION ... ] OTF-FILE");
102 if ((err = FT_Init_FreeType (&library)))
103 FATAL_ERROR ("%s\n", "FT_Init_FreeType: error");
104 err = FT_New_Face (library, argv[1], 0, &face);
105 if (err == FT_Err_Unknown_File_Format)
106 FATAL_ERROR ("%s\n", "FT_New_Face: unknown file format");
108 FATAL_ERROR ("%s\n", "FT_New_Face: unknown error");
110 char *str = getenv ("PIXEL_SIZE");
112 if (str && (i = atoi (str)) > 0)
116 if ((err = FT_Set_Pixel_Sizes (face, 0, pixel_size)))
117 FATAL_ERROR ("%s\n", "FT_Set_Pixel_Sizes: error");
119 for (i = nchars = 0; i < 0x10000; i++)
120 if (! FT_Load_Glyph (face, i, FT_LOAD_RENDER | FT_LOAD_MONOCHROME)
121 && face->glyph->bitmap.rows * face->glyph->bitmap.width)
123 for (i = 0; i < 0x10000; i++)
124 if ((unicode_table[i] = FT_Get_Char_Index (face, (FT_ULong) i)))
126 if (! FT_Load_Glyph (face, unicode_table[i],
127 FT_LOAD_RENDER | FT_LOAD_MONOCHROME)
128 && face->glyph->bitmap.rows * face->glyph->bitmap.width)
131 unicode_table[i] = 0;
134 dump_header (face, "SuperSoft", nchars, pixel_size);
135 for (i = 0; i < 0x10000; i++)
136 if (unicode_table[i])
137 dump_image (pixel_size, unicode_table[i], i, 1);
138 for (i = 0; i < 0x10000; i++)
139 dump_image (pixel_size, i, 0xE000 + i, 0);