From: handa Date: Tue, 8 Jul 2003 23:16:55 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: REL-0-9-1~105 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a43f53017aedecf4555ddf718161836c4c875576;p=m17n%2Flibotf.git *** empty log message *** --- diff --git a/example/otfview.c b/example/otfview.c index 626bce8..6b2e416 100644 --- a/example/otfview.c +++ b/example/otfview.c @@ -51,14 +51,9 @@ int utog[0x10000]; void draw_bitmap (int index, int x, int y) { - Bitmap *bmp; - unsigned char *buf; + Bitmap *bmp = bitmap + index; + unsigned char *buf = bmp->buf; int i, j; - unsigned code = FT_Get_Char_Index (face, (FT_ULong) index); - //unsigned code = index; - - bmp = bitmap + code; - buf = bmp->buf; if (buf) { @@ -98,6 +93,14 @@ read_unicode_seq (char *filename, int *code) } +typedef struct +{ + int platform_id; + int encoding_id; + int index; + char name[256]; +} CharmapRec; + int main (int argc, char **argv) { @@ -107,13 +110,16 @@ main (int argc, char **argv) int first_idx; int update_mask; #define UPDATE_RENDERING 1 -#define UPDATE_BITMAP 2 +#define UPDATE_CHARMAP 2 +#define UPDATE_BITMAP 3 OTF_GlyphString gstring; OTF_Glyph *g; int unicode_seq[256]; int n_codes = 0; int pixel_size = PIXEL_SIZE; - int raw_mode = 0; + CharmapRec *charmap_rec; + int charmap_index = -1; + char charmap_line[256]; /* Window structure. @@ -124,6 +130,9 @@ main (int argc, char **argv) | | GSUB: ... | | | | GPOS: ... | | | +---------------------+ | + | +--- charmap area ----+ | + | | | | + | +---------------------+ | | +--- bitmap area -----+ | | | | | | | | | @@ -135,7 +144,8 @@ main (int argc, char **argv) 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 inner_width, rendering_area_height; + int charmap_area_height, bitmap_area_height; int x, y, x0, y0, x1, y1; char buf[1024]; @@ -170,10 +180,6 @@ main (int argc, char **argv) if (p && sscanf (p, "%d", &n) == 1) pixel_size = n; - - p = getenv ("RAW_MODE"); - if (p) - raw_mode = 1; } err = FT_Init_FreeType (&library); @@ -187,7 +193,27 @@ main (int argc, char **argv) err = FT_Set_Pixel_Sizes (face, 0, pixel_size); if (err) quit ("FT_Set_Char_Size"); - err = FT_Select_Charmap (face, FT_ENCODING_APPLE_ROMAN); + charmap_rec = alloca (sizeof (CharmapRec) * face->num_charmaps); + strcpy (charmap_line, "raw"); + for (i = 0; i < face->num_charmaps; i++) + { + strcat (charmap_line, " "); + charmap_rec[i].index = strlen (charmap_line); + charmap_rec[i].platform_id = face->charmaps[i]->platform_id; + charmap_rec[i].encoding_id = face->charmaps[i]->encoding_id; + sprintf (charmap_rec[i].name, "%d-%d", + charmap_rec[i].platform_id, charmap_rec[i].encoding_id); + if (face->charmaps[i]->platform_id == 0 + || (face->charmaps[i]->platform_id == 3 + && face->charmaps[i]->encoding_id == 1)) + strcat (charmap_rec[i].name, " (unicode)"); + else if (face->charmaps[i]->platform_id == 1 + && face->charmaps[i]->encoding_id == 0) + strcat (charmap_rec[i].name, " (apple-roman)"); + strcat (charmap_line, charmap_rec[i].name); + } + strcat (charmap_line, " "); + memset (utog, 0, sizeof (utog)); x0 = x1 = y0 = y1 = 0; for (i = 0; i < 0x10000; i++) @@ -254,10 +280,13 @@ main (int argc, char **argv) inner_width = (max_glyph_width + 1) * cols + font_width * 4 + 2; rendering_area_height= (max_glyph_height + 1) * 3 + font_height; + charmap_area_height = font_height + 2; 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_height = (rendering_area_height + + charmap_area_height + + bitmap_area_height + + margin * 4); win = XCreateSimpleWindow (display, RootWindow (display, screen), 0, 0, win_width, win_height, 1, BlackPixel (display, screen), @@ -299,11 +328,21 @@ main (int argc, char **argv) int x = event.xbutton.x; int y = event.xbutton.y; - if (margin <= x && x < margin + inner_width - && margin + 1 <= y && y < margin + 1 + font_height) + if (x < margin || x >= margin + inner_width) + break; + if (margin + rendering_area_height + 3 <= y + && y < margin + rendering_area_height + 3 + font_height) + { + charmap_index++; + if (charmap_index >= face->num_charmaps) + charmap_index = -1; + update_mask = UPDATE_CHARMAP | UPDATE_BITMAP; + goto redraw; + } + if (margin + 1 <= y && y < margin + 1 + font_height) { n_codes = read_unicode_seq (argv[2], unicode_seq); - update_mask = UPDATE_RENDERING; + goto redraw; } } @@ -349,7 +388,7 @@ main (int argc, char **argv) continue; redraw: - if (update_mask == (UPDATE_RENDERING | UPDATE_BITMAP)) + if (update_mask == (UPDATE_RENDERING | UPDATE_CHARMAP | UPDATE_BITMAP)) { XClearWindow (display, win); x = margin; @@ -362,12 +401,12 @@ main (int argc, char **argv) y += max_glyph_height + 1; XDrawImageString (display, win, gc_norm, x, y, " GPOS: ", 9); - y = margin * 2 + rendering_area_height; + y = margin * 3 + rendering_area_height + charmap_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; + y = margin * 3 + rendering_area_height + charmap_area_height; XDrawLine (display, win, gc_norm, x, y, x, y + bitmap_area_height - 1); x += font_width * 4 + 1; @@ -443,6 +482,28 @@ main (int argc, char **argv) } } + if (update_mask & UPDATE_CHARMAP) + { + char *p = charmap_line, *pend; + + x = margin + 1; + y = margin * 3 + rendering_area_height + font->ascent + 1; + XDrawImageString (display, win, gc_norm, x, y, charmap_line, + strlen (charmap_line)); + if (charmap_index == -1) + pend = p + 3; + else + { + p += charmap_rec[charmap_index].index; + pend = p + strlen (charmap_rec[charmap_index].name); + FT_Set_Charmap (face, face->charmaps[charmap_index]); + } + x += font_width * (p - charmap_line); + *pend = '\0'; + XDrawImageString (display, win, gc_rev, x, y, p, strlen (p)); + *pend = ' '; + } + if (update_mask & UPDATE_BITMAP) { x = margin + 1; @@ -454,7 +515,8 @@ main (int argc, char **argv) XDrawImageString (display, win, gc_norm, x, y, buf, 4); } x += font_width * 4 + 1; - y = margin * 2 + rendering_area_height + font_height + 2; + y = (margin * 3 + rendering_area_height + charmap_area_height + + font_height + 2); for (i = 0; i < rows; i++) for (j = 0; j < cols; j++) { @@ -463,7 +525,7 @@ main (int argc, char **argv) XClearArea (display, win, x + (max_glyph_width + 1) * j, y + (max_glyph_height + 1) * i, max_glyph_width, max_glyph_height, False); - if (! raw_mode) + if (charmap_index >= 0) index = FT_Get_Char_Index (face, (FT_ULong) index); draw_bitmap (index,