From 952ad7a7df2c4342238c813d2d6c8b1724c5b487 Mon Sep 17 00:00:00 2001 From: handa Date: Tue, 18 Jul 2006 02:32:57 +0000 Subject: [PATCH] (bitmap): Array increated to cover full Unicode. (fontindex): New variable. (update_glyph_area): Adjusted for the change of `bitmap'. (GlyphProc): Likewise. (help): New function. (main): Accept a new 2nd arg INDEX. --- example/otfview.c | 72 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/example/otfview.c b/example/otfview.c index c528737..1dcc1df 100644 --- a/example/otfview.c +++ b/example/otfview.c @@ -126,7 +126,7 @@ typedef struct { int advance; } BitmapRec; -BitmapRec bitmap[0x10000]; +BitmapRec bitmap[0x110000]; int render_width, render_height; Pixmap raw_pixmap, seq_pixmap, gsub_pixmap, gpos_pixmap; @@ -156,6 +156,7 @@ struct { OTF *otf; char *filename; +int fontindex; void create_pixmap (int index) @@ -233,7 +234,10 @@ update_glyph_area () XtSetValues (index_label[i], arg, 2); } - sprintf (buf, " %04X-%04X ", glyph_index, glyph_index + 0x7F); + if (glyph_index < 0x10000) + sprintf (buf, " %04X-%04X ", glyph_index, glyph_index + 0x7F); + else + sprintf (buf, "%06X-%06X", glyph_index, glyph_index + 0x7F); XtSetArg (arg[0], XtNlabel, buf); XtSetValues (range, arg, 1); } @@ -639,15 +643,15 @@ GlyphProc (Widget w, XtPointer client_data, XtPointer call_data) if ((int) client_data == -3 && glyph_index > 0) glyph_index = 0; else if ((int) client_data == -2 && glyph_index > 0) - glyph_index = (glyph_index - 1) & 0xF000; + glyph_index = (glyph_index - 1) & 0x1FF000; else if ((int) client_data == -1 && glyph_index > 0) glyph_index -= 0x80; - else if ((int) client_data == 1 && glyph_index < 0xFF80) + else if ((int) client_data == 1 && glyph_index < 0x10FF80) glyph_index += 0x80; - else if ((int) client_data == 2 && glyph_index < 0xF000) - glyph_index = (glyph_index + 0x1000) & 0xF000; - else if ((int) client_data == 3 && glyph_index < 0xF000) - glyph_index = 0xFF80; + else if ((int) client_data == 2 && glyph_index < 0x10F000) + glyph_index = (glyph_index + 0x1000) & 0x1FF000; + else if ((int) client_data == 3 && glyph_index < 0x10F000) + glyph_index = 0x10FF80; if (glyph_index != old_glyph_index) update_glyph_area (); } @@ -1339,6 +1343,19 @@ x_error_handler (Display *display, XErrorEvent *error) return 0; } +void +help (char **argv, int err) +{ + FILE *fp = err ? stderr : stdout; + + fprintf (fp, "Usage: %s [ X-OPTION ... ] OTF-FILE [INDEX]\n", + basename (argv[0])); + fprintf (fp, " Environment variable PIXEL_SIZE specifies the pixel size.\n"); + fprintf (fp, " The default pixel size is %d, but is reduced\n", + DEFAULT_PIXEL_SIZE); + fprintf (fp, " if your screen is not that wide.\n"); + exit (err); +} int main (int argc, char **argv) @@ -1381,21 +1398,34 @@ main (int argc, char **argv) if (! font) font = XLoadQueryFont (display, "fixed"); - if (argc != 2 || !strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) + if (argc < 2) + help (argv, 1); + if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) + help (argv, 0); + filename = argv[1]; + if (argc > 2) { - fprintf (stderr, "Usage: %s [ X-OPTION ... ] OTF-FILE\n", - basename (argv[0])); - fprintf (stderr, - " Pixel size is decided by the environment variable PIXEL_SIZE ((default %d).\n", DEFAULT_PIXEL_SIZE); - exit (argc != 2); + fontindex = atoi (argv[2]); + if (fontindex < 0) + FATAL_ERROR ("Invalid font index: %d\n", fontindex); } - filename = argv[1]; + + if ((err = FT_Init_FreeType (&library))) + FATAL_ERROR ("%s\n", "FT_Init_FreeType: error"); + err = FT_New_Face (library, filename, fontindex, &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 (invalid face index?)"); + if ((err = FT_Set_Pixel_Sizes (face, 0, pixel_size))) + FATAL_ERROR ("%s\n", "FT_Set_Pixel_Sizes: error"); + if (strstr (filename, ".ttf") || strstr (filename, ".TTF") || strstr (filename, ".otf") || strstr (filename, ".OTF")) { - otf = OTF_open (filename); + otf = OTF_open_ft_face (face); if (! otf || OTF_get_table (otf, "head") < 0 || OTF_get_table (otf, "cmap") < 0 @@ -1404,16 +1434,6 @@ main (int argc, char **argv) otf = NULL; } - if ((err = FT_Init_FreeType (&library))) - FATAL_ERROR ("%s\n", "FT_Init_FreeType: error"); - err = FT_New_Face (library, filename, 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 title[256]; Arg arg[1]; -- 1.7.10.4