From: handa Date: Mon, 2 Feb 2004 08:17:27 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: REL-0-9-1~77 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=c246addfb42a88ec0590379420a9e705b0ebace8;p=m17n%2Flibotf.git *** empty log message *** --- diff --git a/Makefile.am b/Makefile.am index 9a1d702..93b44d6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,6 @@ SUBDIRS = src example -bin_SCRIPTS = otflib-config +bin_SCRIPTS = libotf-config EXTRA_DIST = autogen.sh diff --git a/configure.ac b/configure.ac index 189a20e..c90af0e 100644 --- a/configure.ac +++ b/configure.ac @@ -44,5 +44,25 @@ AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h]) AC_FUNC_ALLOCA AC_FUNC_MALLOC +# Check for Freetype2 usability. +AC_CHECK_PROG(HAVE_FREETYPE_CONFIG, freetype-config, yes) +if test "x$HAVE_FREETYPE_CONFIG" = "xyes"; then + FREETYPE_INC=`freetype-config --cflags` + CPPFLAGS="$CPPFLAGS $FREETYPE_INC" + AC_CHECK_HEADER(ft2build.h, HAVE_FREETYPE=yes, + HAVE_FREETYPE=no CPPFLAGS=$save_CPPFLAGS) + if test "x$HAVE_FREETYPE" = "xyes" ; then + FREETYPE_LD_FLAGS=`freetype-config --libs`; + LIBS="$LIBS $FREETYPE_LD_FLAGS" + AC_CHECK_LIB(freetype, FT_Init_FreeType, HAVE_FREETYPE=yes, + HAVE_FREETYPE=no) + fi +fi + +if test "x$HAVE_FREETYPE" != "xyes" ; then + echo "Freetype library wan't found in your system!" + exit 1 +fi + AC_CONFIG_FILES([Makefile src/Makefile example/Makefile libotf-config]) AC_OUTPUT diff --git a/example/Makefile.am b/example/Makefile.am index 18ca42b..6cdbaf4 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -24,22 +24,18 @@ bin_PROGRAMS = otfdump otfview otflist otftobdf -INCLUDES = `freetype-config --cflags` CommonLDADD = ${top_builddir}/src/libotf.la -CommonLDFLAGS = -all-static otflist_SOURCE = otflist.c otflist_LDADD = ${CommonLDADD} -otflist_LDFLAGS = `freetype-config --libs` ${CommonLDFLAGS} otfdump_SOURCE = otfdump.c otfdump_LDADD = ${CommonLDADD} -otfdump_LDFLAGS = ${CommonLDFLAGS} otfview_SOURCE = otfview.c otfview_LDADD = ${CommonLDADD} -otfview_LDFLAGS = `freetype-config --libs` ${X_LIBS} ${X_PRE_LIBS} -lX11 -lXt -lXaw -lXmu -ldl -static +otfview_LDFLAGS = ${X_LIBS} ${X_PRE_LIBS} \ + -lX11 -lXt -lXaw -lXmu ${X_EXTRA_LIBS} otftobdf_SOURCE = otftobdf.c otftobdf_LDADD = ${CommonLDADD} -otftobdf_LDFLAGS = `freetype-config --libs` -static diff --git a/example/otfview.c b/example/otfview.c index b662d99..696bbd3 100644 --- a/example/otfview.c +++ b/example/otfview.c @@ -46,6 +46,7 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite #define DEFAULT_FONT_NAME "6x13" XFontStruct *font; #define FONT_HEIGHT (font->ascent + font->descent) +#define FONT_ASCENT (font->ascent) #define FONT_DESCENT (font->descent) #define FONT_WIDTH (font->max_bounds.width) @@ -53,7 +54,7 @@ XtAppContext context; /* Widget structure. +--- frame (form) -------------------------+ | +--- command_area (box) ---------------+ | - | | quit charmap ... | | + | | quit dump charmap ... | | | +--------------------------------------+ | | +---- navi_area (box) -----------------+ | | | FIRST PREV prev label next NEXT LAST | | @@ -77,7 +78,7 @@ XtAppContext context; | +--------------------------------------+ | +------------------------------------------+ */ Widget shell, frame; -Widget command_area, quit, *charmap; +Widget command_area, quit, dump, *charmap; Widget navi_area, FIRST, PREV, prev, label, next, NEXT, LAST; Widget glyph_area, glyph[128]; Widget render_area, clear, raw, seq, gsub, gpos; @@ -256,6 +257,119 @@ QuitProc (Widget w, XtPointer client_data, XtPointer call_data) } void +DumpProc (Widget w, XtPointer client_data, XtPointer pixel_size) +{ + int g_width, g_height, g_x, g_y, pix_width, pix_height; + int margin = 20 * 300 / 25.4; + int a4_width = 210 * 300 / 25.4 - margin * 2; + int a4_height = 297 * 300 / 25.4 - margin * 2; + int size = 100; + Pixmap pixmap; + XImage ximage, *image; + int i, x, y; + FILE *fp; + char *data; + int bytes_per_line; + + FT_Set_Pixel_Sizes (face, 0, size); + g_width = ((face->bbox.xMax - face->bbox.xMin) * size / face->units_per_EM); + g_height = ((face->bbox.yMax - face->bbox.yMin) * size / face->units_per_EM); + pix_width = (g_width + 1) * 16 + margin + 1; + pix_height = (g_height + 1 + FONT_HEIGHT) * 16 + margin + 1; + while (pix_width > a4_width || pix_height > a4_height) + { + size--; + FT_Set_Pixel_Sizes (face, 0, size); + g_width = ((face->bbox.xMax - face->bbox.xMin) + * size / face->units_per_EM); + g_height = ((face->bbox.yMax - face->bbox.yMin) + * size / face->units_per_EM); + pix_width = (g_width + 1) * 16 + margin + 1; + pix_height = (g_height + 1 + FONT_HEIGHT) * 16 + margin + 1; + } + + g_x = - (face->bbox.xMin * size / face->units_per_EM); + g_y = face->bbox.yMax * size / face->units_per_EM; + for (i = 0; i < 0x10000; i++) + if (FT_Load_Glyph (face, i, FT_LOAD_RENDER | FT_LOAD_MONOCHROME) == 0) + { + if (g_x < - face->glyph->bitmap_left) + g_x = - face->glyph->bitmap_left; + if (g_y < face->glyph->bitmap_top) + g_y = face->glyph->bitmap_top; + if (g_width + < g_x + face->glyph->bitmap_left + face->glyph->bitmap.width) + g_width + = g_x + face->glyph->bitmap_left + face->glyph->bitmap.width; + if (g_height + < g_y - face->glyph->bitmap_top + face->glyph->bitmap.rows) + g_height + = g_y - face->glyph->bitmap_top + face->glyph->bitmap.rows; + } + pix_width = (g_width + 1) * 16 + margin + 1; + pix_height = (g_height + FONT_HEIGHT + 1) * 16 + margin + 1; + pixmap = XCreatePixmap (display, + RootWindow (display, DefaultScreen (display)), + pix_width, pix_height, 1); + + for (i = 0, x = margin; i <= 16; i++, x += g_width + 1) + XDrawLine (display, pixmap, gc_set, x, margin, + x, margin + (g_height + FONT_HEIGHT + 1) * 16); + for (i = 0, y = margin; i <= 16; i++, y += g_height + FONT_HEIGHT + 1) + XDrawLine (display, pixmap, gc_set, margin, y, + margin + (g_width + 1) * 16, y); + for (i = 0; i < 256; i++) + { + char str[5]; + int idx; + + if (charmap_index >= 0) + idx = FT_Get_Char_Index (face, (FT_ULong) i); + else + idx = i; + x = margin + (g_width + 1) * (i % 16); + y = margin + (g_height + FONT_HEIGHT + 1) * (i / 16); + if (FT_Load_Glyph (face, idx, FT_LOAD_RENDER | FT_LOAD_MONOCHROME) == 0) + { + ximage.height = face->glyph->bitmap.rows; + ximage.width = face->glyph->bitmap.width; + ximage.depth = 1; + ximage.bits_per_pixel = 1; + ximage.xoffset = 0; + ximage.format = XYPixmap; + ximage.data = (char *) face->glyph->bitmap.buffer; + ximage.byte_order = MSBFirst; + ximage.bitmap_unit = 8; + ximage.bitmap_bit_order = MSBFirst; + ximage.bitmap_pad = 8; + ximage.bytes_per_line = face->glyph->bitmap.pitch; + XInitImage (&ximage); + XPutImage (display, pixmap, gc, &ximage, 0, 0, + x + g_x + face->glyph->bitmap_left, + y + g_y - face->glyph->bitmap_top, + ximage.width, ximage.height); + } + sprintf (str, "0x%02X", i); + XDrawString (display, pixmap, gc_inv, + x + (g_width - XTextWidth (font, str, 4))/ 2, + y + g_height + FONT_ASCENT, str, 4); + } + + image = XGetImage (display, pixmap, 0, 0, pix_width, pix_height, + AllPlanes, XYPixmap); + XInitImage (image); + fp = fopen ("temp", "w"); + fprintf (fp, "P4\n%d %d\n", image->width, image->height); + bytes_per_line = (image->width + 7) / 8; + data = image->data; + for (y = 0; y < image->height; y++, data += image->bytes_per_line) + fwrite (data, 1, bytes_per_line, fp); + fclose (fp); + FT_Set_Pixel_Sizes (face, 0, (int) pixel_size); +} + + +void GlyphProc (Widget w, XtPointer client_data, XtPointer call_data) { int old_glyph_index = glyph_index; @@ -311,7 +425,7 @@ RenderProc (Widget w, XtPointer client_data, XtPointer call_data) } void -create_widgets () +create_widgets (int pixel_size) { String quit_action = "q: set() notify() unset()"; String FIRST_action = "~Shiftf: set() notify() unset()"; @@ -351,6 +465,10 @@ create_widgets () command_area, arg, 1); XtAddCallback (quit, XtNcallback, QuitProc, NULL); + dump = XtCreateManagedWidget ("dump", commandWidgetClass, + command_area, arg, 1); + XtAddCallback (dump, XtNcallback, DumpProc, (XtPointer) pixel_size); + charmap = alloca (sizeof (Widget) * (face->num_charmaps + 1)); XtSetArg (arg[0], XtNstate, True); charmap[0] = XtCreateManagedWidget (charmap_rec[0].name, toggleWidgetClass, @@ -496,13 +614,17 @@ main (int argc, char **argv) int err; int i; int pixel_size = DEFAULT_PIXEL_SIZE; + int fixed_pixel_size = 0; int display_width; { char *str = getenv ("PIXEL_SIZE"); if (str && (i = atoi (str)) > 0) - pixel_size = i; + { + pixel_size = i; + fixed_pixel_size = 1; + } } gstring.size = gstring.used = 256; @@ -557,7 +679,7 @@ main (int argc, char **argv) glyph_width = ((face->bbox.xMax - face->bbox.xMin) * pixel_size / face->units_per_EM); - if (glyph_width * 16 > display_width * 0.8) + if (! fixed_pixel_size && glyph_width * 16 > display_width * 0.8) { pixel_size = (pixel_size * display_width * 0.8 / 16 / glyph_width); FT_Set_Pixel_Sizes (face, 0, pixel_size); @@ -571,7 +693,7 @@ main (int argc, char **argv) * pixel_size / face->units_per_EM); glyph_x = - (face->bbox.xMin * pixel_size / face->units_per_EM); - glyph_y = face->ascender * pixel_size / face->units_per_EM; + glyph_y = face->bbox.yMax * pixel_size / face->units_per_EM; for (i = 0; i < 0x10000; i++) if (FT_Load_Glyph (face, i, FT_LOAD_RENDER | FT_LOAD_MONOCHROME) == 0) @@ -646,7 +768,7 @@ main (int argc, char **argv) for (i = 0; i < 0x10000; i++) create_pixmap (pixel_size, i); - create_widgets (); + create_widgets (pixel_size); glyph_index = 0; charmap_index = -1; update_glyph_area (); diff --git a/src/config.h.in b/src/config.h.in index f3d67e9..f78e200 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -24,8 +24,8 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H -/* Define to 1 if your system has a GNU libc compatible `malloc' function, and - to 0 otherwise. */ +/* Define to 1 if your system has a working `malloc' function, and to 0 + otherwise. */ #undef HAVE_MALLOC /* Define to 1 if you have the header file. */ diff --git a/src/otfdrive.c b/src/otfdrive.c index 6d0baed..fdb7b36 100644 --- a/src/otfdrive.c +++ b/src/otfdrive.c @@ -24,6 +24,7 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite #include #include #include +#include #include "otf.h" #include "otferror.h" diff --git a/src/otferror.c b/src/otferror.c index 28dd5fe..a631c9b 100644 --- a/src/otferror.c +++ b/src/otferror.c @@ -24,6 +24,7 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite #include #include #include +#include #include "otf.h" diff --git a/src/otfopen.c b/src/otfopen.c index 0aa2bc9..94429ec 100644 --- a/src/otfopen.c +++ b/src/otfopen.c @@ -24,6 +24,7 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite #include #include #include +#include #include "otf.h" #include "otferror.h"