From 855fa1e9d6d1b6f69549753202f1c7a9de47cf2b Mon Sep 17 00:00:00 2001 From: handa Date: Fri, 17 Oct 2003 08:46:56 +0000 Subject: [PATCH] *** empty log message *** --- example/Makefile.am | 6 +++- example/otfimage.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 example/otfimage.c diff --git a/example/Makefile.am b/example/Makefile.am index 6497be1..2a47702 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = otfdump otfdraw otfview otflist +bin_PROGRAMS = otfdump otfdraw otfview otflist otfimage INCLUDES = `freetype-config --cflags` CommonLDADD = ${top_builddir}/src/libotf.la @@ -19,3 +19,7 @@ otfdraw_LDFLAGS = `freetype-config --libs` ${X_LIBS} ${X_PRE_LIBS} -lX11 -lXt -l 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 diff --git a/example/otfimage.c b/example/otfimage.c new file mode 100644 index 0000000..0a23a7a --- /dev/null +++ b/example/otfimage.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include + +#include +#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); +} -- 1.7.10.4