-bin_PROGRAMS = otfdump otfdraw otfview otflist
+bin_PROGRAMS = otfdump otfdraw otfview otflist otfimage
INCLUDES = `freetype-config --cflags`
CommonLDADD = ${top_builddir}/src/libotf.la
otfview_SOURCE = otfview.c
otfview_LDADD = ${CommonLDADD}
otfview_LDFLAGS = `freetype-config --libs` ${X_LIBS} ${X_PRE_LIBS} -lX11 -lXt -lXaw -lXmu -ldl -static
+
+otfimage_SOURCE = otfimage.c
+otfimage_LDADD = ${CommonLDADD}
+otfimage_LDFLAGS = `freetype-config --libs` -static
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <libgen.h>
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#define DEFAULT_PIXEL_SIZE 16
+
+FT_Face face;
+
+void
+dump_image (int pixel_size, int index)
+{
+ int err = FT_Load_Glyph (face, index, FT_LOAD_RENDER | FT_LOAD_MONOCHROME);
+ int i,j, size;
+ unsigned char *buf;
+
+ if (err)
+ return;
+ size = face->glyph->bitmap.rows * face->glyph->bitmap.width;
+ if (! size)
+ return;
+ buf = (unsigned char *) face->glyph->bitmap.buffer;
+ printf ("(#x%02X \"P4 %d %d ",
+ index, face->glyph->bitmap.width, face->glyph->bitmap.rows);
+ for (i = 0; i < face->glyph->bitmap.rows; i++)
+ for (j = 0; j < (face->glyph->bitmap.width + 7) / 8; j++)
+ {
+ printf("\\%o", buf[i * face->glyph->bitmap.pitch + j]);
+ }
+ printf ("\")\n");
+}
+
+/* Format MSG by FMT and print the result to the stderr, and exit. */
+
+#define FATAL_ERROR(fmt, arg) \
+ do { \
+ fprintf (stderr, fmt, arg); \
+ exit (1); \
+ } while (0)
+
+int
+main (int argc, char **argv)
+{
+ FT_Library library;
+ int err;
+ int i;
+ int pixel_size = DEFAULT_PIXEL_SIZE;
+
+ if (argc != 2)
+ FATAL_ERROR ("%s\n", "Usage: otfimage [ X-OPTION ... ] OTF-FILE");
+
+ if ((err = FT_Init_FreeType (&library)))
+ FATAL_ERROR ("%s\n", "FT_Init_FreeType: error");
+ err = FT_New_Face (library, argv[1], 0, &face);
+ if (err == FT_Err_Unknown_File_Format)
+ FATAL_ERROR ("%s\n", "FT_New_Face: unknown file format");
+ else if (err)
+ FATAL_ERROR ("%s\n", "FT_New_Face: unknown error");
+ if ((err = FT_Set_Pixel_Sizes (face, 0, pixel_size)))
+ FATAL_ERROR ("%s\n", "FT_Set_Pixel_Sizes: error");
+
+ {
+ char *str = getenv ("PIXEL_SIZE");
+
+ if (str && (i = atoi (str)) > 0)
+ pixel_size = i;
+ }
+
+ for (i = 0; i < 0x10000; i++)
+ dump_image (pixel_size, i);
+
+ exit (0);
+}