#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)
/* Widget structure.
+--- frame (form) -------------------------+
| +--- command_area (box) ---------------+ |
- | | quit charmap ... | |
+ | | quit dump charmap ... | |
| +--------------------------------------+ |
| +---- navi_area (box) -----------------+ |
| | FIRST PREV prev label next NEXT LAST | |
| +--------------------------------------+ |
+------------------------------------------+ */
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;
}
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;
}
void
-create_widgets ()
+create_widgets (int pixel_size)
{
String quit_action = "<KeyPress>q: set() notify() unset()";
String FIRST_action = "~Shift<KeyPress>f: set() notify() unset()";
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,
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;
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);
* 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)
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 ();