From: handa Date: Sun, 19 Jan 2003 23:17:50 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: REL-0-9-1~113 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=4b0b5f8fd187b6f9edfde8ad43becf5384593b97;p=m17n%2Flibotf.git *** empty log message *** --- diff --git a/AUTHORS b/AUTHORS index e69de29..3c7acff 100644 --- a/AUTHORS +++ b/AUTHORS @@ -0,0 +1,3 @@ +Author of libotf. + +Kenichi HANDA , National Institute of AIST, JAPAN. diff --git a/README b/README index e69de29..3c23e48 100644 --- a/README +++ b/README @@ -0,0 +1,74 @@ + + libotf -- A Library for handling OpenType Font (OTF) + + Ver.0.9 (2003.1.10) + + +(1) What is libotf? + +The library "libotf" provides the following facilites. + + o Read Open Type Layout Tables from OTF file. Currently these + tables are supported; head, name, cmap, GDEF, GSUB, and GPOS. + + o Convert a Unicode character sequence to a glyph code sequence by + using the above tables. + +The combination of libotf and the FreeType library (Ver.2) realizes +CTL (complex text layout) by OpenType fonts. + + +(2) Installation + +(2-1) Installation from libotf-X.Y.tar.gz. + +% tar xfz libotf-X.Y.tar.gz +% cd libotf-X.Y +% ./configure +% make +% make install + +(2-2) Installation from CVS repository. + +% cvs -d :pserver:anonymous@cvs.m17n.org:/cvs/root login +CVS Password: <- type Enter (or RET) +% cvs -d :pserver:anonymous@cvs.m17n.org:/cvs/root co libotf +% cd libotf +% ./autogen.sh +% ./configure +% make +% make install + +(3) Documents + +o REAMDE -- this file +o COPYING -- GPL document +o INSTALL -- the generic installation instructions +o NEWS -- the recent changes to libm17n + +(4) Bug report + +Please send bug reports to bugs . + + +----- + +Copyright (C) 2003 +National Institute of Advanced Industrial Science and Technology (AIST) + +This file is part of libotf. + +Libotf is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Libotf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with autoconf; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. diff --git a/autogen.sh b/autogen.sh index a539740..79cbc6a 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,6 +1,11 @@ #!/bin/sh +echo "Running libtoolize..." libtoolize --automake +echo "Running aclocal..." aclocal +echo "Running automake..." automake -a +echo "Running autoheader..." +autoheader +echo "Running autoconf..." autoconf - diff --git a/configure.ac b/configure.ac index c4bfce6..263e9ed 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. -AC_INIT(libotf, 1.0, libotf@m17n.org) -AM_INIT_AUTOMAKE(libotf, 1.0) +AC_INIT(libotf, 0.9, libotf@m17n.org) +AM_INIT_AUTOMAKE(libotf, 0.9) AM_CONFIG_HEADER(src/config.h) # Checks for programs. diff --git a/example/otfview.c b/example/otfview.c index 0a4dabe..2680d73 100644 --- a/example/otfview.c +++ b/example/otfview.c @@ -1,8 +1,10 @@ #include #include #include +#include +#include -#include "otf.h" +#include #include #include FT_FREETYPE_H @@ -11,9 +13,15 @@ FT_Library library; FT_Face face; #include +#include +#include -#define FONT_NAME "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1" +#define PIXEL_SIZE 20 + +//#define FONT_NAME "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1" +#define FONT_NAME "6x13" #define FONT_HEIGHT 14 +int font_height, font_width; Display *display; int screen; @@ -30,31 +38,25 @@ typedef struct int rows; int width; int pitch; + int unicode; unsigned char* buf; } Bitmap; Bitmap bitmap[0x10000]; +/* Unicode to glyph index mapping table. */ +int utog[0x10000]; + void draw_bitmap (int index, int x, int xoff, int width, - int y, int yoff, int height, int rev) + int y, int yoff, int height, int clear) { Bitmap *bmp = bitmap + index; unsigned char *buf = bmp->buf; int i, j; - char str[256]; - int w; - - if (rev) - XFillRectangle (display, win, gc_norm, x, y, width, height); - XFillRectangle (display, win, gc_xor, x, y + height - FONT_HEIGHT, - width, FONT_HEIGHT); - XDrawLine (display, win, gc_xor, x, y, x, y + height - 1); - sprintf (str, "%04X", index); - w = XTextWidth (font, str, 4); - XDrawString (display, win, gc_xor, x + (width - w) / 2, y + height - 2, - str, 4); + if (clear) + XClearArea (display, win, x, y, width, height, False); if (buf) { x += xoff + bmp->left; @@ -62,7 +64,7 @@ draw_bitmap (int index, int x, int xoff, int width, for (i = 0; i < bmp->rows; i++, buf += bmp->pitch) for (j = 0; j < bmp->width; j++) if (buf[j / 8] & (1 << (7 - (j % 8)))) - XDrawPoint (display, win, gc_xor, x + j, y + i); + XDrawPoint (display, win, gc_norm, x + j, y + i); } } @@ -75,7 +77,7 @@ draw_big_bitmat (int index, unsigned char *buf; int i, j; - FT_Set_Pixel_Sizes (face, 0, 120); + FT_Set_Pixel_Sizes (face, 0, PIXEL_SIZE * 4); if (FT_Load_Glyph (face, index, FT_LOAD_RENDER | FT_LOAD_MONOCHROME)) return; @@ -100,25 +102,70 @@ quit (char *msg) int +read_unicode_seq (char *filename, int *code) +{ + FILE *fp = fopen (filename, "r"); + int i = 0; + + if (! fp) + { + fprintf (stderr, "File \"%s\" can't be opened.\n", filename); + exit (1); + } + while (i < 256 + && fscanf (fp, "%x", code + i) == 1) + i++; + fclose (fp); + return i; +} + + +int main (int argc, char **argv) { OTF *otf; int err; - int i, max_i, j; - int width, height, max_width, max_height; - int cols = 16, rows = 8; - int x0, y0, x1, y1; - int big_height; + int i, j, max_glyph_idx; int first_idx; int left_idx = -1, right_idx = -1; int update_mask; -#define UPDATE_LEFT 1 -#define UPDATE_RIGHT 2 -#define UPDATE_MAIN 4 +#define UPDATE_RENDERING 1 +#define UPDATE_BITMAP 2 + OTF_GlyphString gstring; + OTF_Glyph *g; + int unicode_seq[256]; + int n_codes = 0; + /* Window structure. + + +-------------------------+ + | +--- rendering area --+ | + | |Unicode: ... | | + | | cmap: ... | | + | | GSUB: ... | | + | | GPOS: ... | | + | +---------------------+ | + | +--- bitmap area -----+ | + | | | | + | | | | + | | | | + | +---------------------+ | + +-------------------------+ + */ + int margin = 2; + int win_width, win_height; + int cols = 16, rows = 8; + int max_glyph_width, max_glyph_height; + int inner_width, rendering_area_height, bitmap_area_height; + int x, y, x0, y0, x1, y1; + char buf[1024]; - if (argc != 2) + gstring.size = gstring.used = 256; + g = calloc (256, sizeof (OTF_Glyph)); + gstring.glyphs = g; + + if (argc != 2 && argc != 3) { - fprintf (stderr, "Usage, otfview OTF-FILE"); + fprintf (stderr, "Usage, otfview OTF-FILE [CODE-FILE]\n"); exit (1); } @@ -137,10 +184,11 @@ main (int argc, char **argv) quit ("FT_New_Face: unknown file format"); else if (err) quit ("FT_New_Face: unknown error"); - err = FT_Set_Pixel_Sizes (face, 0, 24); + err = FT_Set_Pixel_Sizes (face, 0, PIXEL_SIZE); if (err) quit ("FT_Set_Char_Size"); + memset (utog, 0, sizeof (utog)); x0 = x1 = y0 = y1 = 0; for (i = 0; i < 0x10000; i++) { @@ -152,7 +200,7 @@ main (int argc, char **argv) Bitmap *bmp = bitmap + i; int bmpsize; - max_i = i; + max_glyph_idx = i; bmp->left = face->glyph->bitmap_left; bmp->top = face->glyph->bitmap_top; bmp->rows = face->glyph->bitmap.rows; @@ -172,25 +220,46 @@ main (int argc, char **argv) } } - max_height = y1 - y0; - max_width = x1 - x0; + max_glyph_height = y1 - y0; + max_glyph_width = x1 - x0; + + for (i = 0; i < 0x10000; i++) + { + gstring.glyphs[i & 0xFF].c = i; + if ((i & 0xFF) == 0xFF) + { + OTF_drive_cmap (otf, &gstring); + for (j = 0; j < 0x100; j++) + { + utog[(i & 0xFF00) + j] = gstring.glyphs[j].glyph_id; + if (gstring.glyphs[j].glyph_id > 0) + bitmap[gstring.glyphs[j].glyph_id].unicode = (i & 0xFF00) + j; + } + } + } + + if (argc == 3) + n_codes = read_unicode_seq (argv[2], unicode_seq); display = XOpenDisplay (NULL); screen = DefaultScreen (display); + font = XLoadQueryFont (display, FONT_NAME); + if (! font) + font = XLoadQueryFont (display, "fixed"); + font_height = font->ascent + font->descent; + font_width = font->max_bounds.width; - big_height = max_height * 5 + 10; - - width = max_width * cols; - height = big_height + (max_height + FONT_HEIGHT) * rows; + inner_width = (max_glyph_width + 1) * cols + font_width * 4 + 2; + rendering_area_height= (max_glyph_height + 1) * 3 + font_height; + bitmap_area_height = (max_glyph_height + 1) * rows + font_height + 2; + win_width = inner_width + margin * 2; + win_height = rendering_area_height + bitmap_area_height + margin * 3; win = XCreateSimpleWindow (display, RootWindow (display, screen), - 0, 0, width, height, 1, + 0, 0, win_width, win_height, 1, BlackPixel (display, screen), WhitePixel (display, screen)); - font = XLoadQueryFont (display, FONT_NAME); - if (! font) - font = XLoadQueryFont (display, "fixed"); valuemask = GCForeground | GCBackground | GCFunction | GCFont; values.foreground = BlackPixel (display, screen); @@ -227,88 +296,146 @@ main (int argc, char **argv) int x = event.xbutton.x; int y = event.xbutton.y; - if (y < big_height) + if (margin <= x && x < margin + inner_width + && margin + 1 <= y && y < margin + 1 + font_height) { - if (x < width / 2) - { - if (first_idx > 0) - { - first_idx -= cols * rows; - update_mask |= UPDATE_MAIN; - goto redraw; - } - } - else - { - if (first_idx + cols * rows <= max_i) - { - first_idx += cols * rows; - update_mask |= UPDATE_MAIN; - goto redraw; - } - } + n_codes = read_unicode_seq (argv[2], unicode_seq); + update_mask = UPDATE_RENDERING; + goto redraw; } - else + } + break; + + case KeyPress: + { + char buf[512]; + KeySym keysym; + int n; + + n = XLookupString ((XKeyEvent *) &event, buf, 512, &keysym, NULL); + if (! n) + break; + if (buf[0] == 'q') + goto finish; + if (buf[0] == 'n' || buf[0] == ' ') { - if (event.xbutton.button == Button1) + if (first_idx + cols * rows <= max_glyph_idx) { - left_idx = (first_idx - + ((y - big_height) - / (max_height + FONT_HEIGHT) - * cols) - + x / max_width); - update_mask |= UPDATE_LEFT; + first_idx += cols * rows; + update_mask |= UPDATE_BITMAP; + goto redraw; } - else + } + else if (buf[0] == 'p' + || keysym == XK_BackSpace || keysym == XK_Delete) + { + if (first_idx > 0) { - right_idx = (first_idx - + ((y - big_height) - / (max_height + FONT_HEIGHT) - * cols) - + x / max_width); - update_mask |= UPDATE_RIGHT; + first_idx -= cols * rows; + update_mask |= UPDATE_BITMAP; + goto redraw; } - goto redraw; } } break; - case KeyPress: - break; - default: - update_mask = UPDATE_LEFT | UPDATE_RIGHT | UPDATE_MAIN; + update_mask = UPDATE_RENDERING | UPDATE_BITMAP; goto redraw; } continue; redraw: - if (update_mask == (UPDATE_LEFT | UPDATE_RIGHT | UPDATE_MAIN)) + if (update_mask == (UPDATE_RENDERING | UPDATE_BITMAP)) { XClearWindow (display, win); - XDrawLine (display, win, gc_norm, 0, big_height - 1, - width, big_height - 1); + x = margin; + y = margin + font->ascent; + XDrawImageString (display, win, gc_norm, x, y, "Unicode: ", 9); + y += font_height + (max_glyph_height - font_height) / 2; + XDrawImageString (display, win, gc_norm, x, y, " cmap: ", 9); + y += max_glyph_height + 1; + XDrawImageString (display, win, gc_norm, x, y, " GSUB: ", 9); + y += max_glyph_height + 1; + XDrawImageString (display, win, gc_norm, x, y, " GPOS: ", 9); + + y = margin * 2 + rendering_area_height; + XDrawLine (display, win, gc_norm, x, y, x + inner_width - 1, y); + y += font_height + 1; + for (i = 0; i <= rows; i++, y += max_glyph_height + 1) + XDrawLine (display, win, gc_norm, x, y, x + inner_width - 1, y); + y = margin * 2 + rendering_area_height; + XDrawLine (display, win, gc_norm, x, y, + x, y + bitmap_area_height - 1); + x += font_width * 4 + 1; + for (i = 0; i <= cols; i++, x += max_glyph_width + 1) + XDrawLine (display, win, gc_norm, x, y, + x, y + bitmap_area_height - 1); + y += font->ascent + 1; + x = (margin + font_width * 4 + 2 + + (max_glyph_width - font_width * 4) / 2); + for (i = 0; i < cols; i++, x += max_glyph_width + 1) + { + sprintf (buf, "xxx%X", i); + XDrawImageString (display, win, gc_norm, x, y, buf, 4); + } + } + + if (update_mask & UPDATE_RENDERING) + { + x = margin + font_width * 9; + y = margin + font->ascent; + for (i = 0; i < n_codes; i++) + { + sprintf (buf + i * 5, "%04X ", unicode_seq[i]); + gstring.glyphs[i].c = unicode_seq[i]; + } + gstring.used = n_codes; + XDrawImageString (display, win, gc_norm, x, y, buf, n_codes * 5); + + OTF_drive_cmap (otf, &gstring); + y = margin + font_height + 1; + for (i = 0; i < n_codes; i++, x+= max_glyph_width) + draw_bitmap (gstring.glyphs[i].glyph_id, x, -x0, max_glyph_width, + y, -y0, max_glyph_height, 1); + + OTF_drive_gsub (otf, &gstring, "deva", NULL, NULL); + x = margin + font_width * 9; + y += max_glyph_height; + for (i = 0; i < gstring.used; i++) + { + draw_bitmap (gstring.glyphs[i].glyph_id, x, -x0, max_glyph_width, + y, -y0, max_glyph_height, 0); + x += bitmap[gstring.glyphs[i].glyph_id].width; + } + + draw_big_bitmat (left_idx, max_glyph_width * 2, -x0 * 5, max_glyph_width * 5, + 5, -y0 * 5, max_glyph_height * 5); } - if (update_mask & UPDATE_MAIN) + if (update_mask & UPDATE_BITMAP) { - XFillRectangle (display, win, gc_rev, 0, big_height, width, height); + x = margin + 1; + y = (margin * 2 + rendering_area_height + font_height + 2 + + (max_glyph_height - font_height) / 2 + font->ascent); + for (i = 0; i < rows; i++, y += max_glyph_height + 1) + { + sprintf (buf, "%03Xx", (first_idx + i * cols) / 16); + XDrawImageString (display, win, gc_norm, x, y, buf, 4); + } + x += font_width * 4 + 1; + y = margin * 2 + rendering_area_height + font_height + 2; for (i = 0; i < rows; i++) for (j = 0; j < cols; j++) draw_bitmap (first_idx + i * cols + j, - max_width * j, -x0, max_width, - big_height + (max_height + FONT_HEIGHT) * i, - -y0, max_height + FONT_HEIGHT, 0); + x + (max_glyph_width + 1) * j, -x0, max_glyph_width, + y + (max_glyph_height + 1) * i, + -y0, max_glyph_height, 1); } - if (update_mask & UPDATE_LEFT) - draw_big_bitmat (left_idx, max_width * 2, -x0 * 5, max_width * 5, - 5, -y0 * 5, max_height * 5); - if (update_mask & UPDATE_RIGHT) - draw_big_bitmat (right_idx, max_width * 9, -x0 * 5, max_width * 5, - 5, -y0 * 5, max_height * 5); update_mask = 0; } + finish: OTF_close (otf); exit (0); }