From: handa Date: Thu, 27 May 2004 08:23:27 +0000 (+0000) Subject: Include instead of . X-Git-Tag: withdl~183 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80fa3fa9a3c85c67d6f1633bb62ca88c53839d87;p=m17n%2Fm17n-lib.git Include instead of . (help_exit): Adjusted for the change of spec. (dump_image): Argument changed. Dump PNG image instead of PBM. (main): Adjusted for the change of spec. --- diff --git a/example/mdump.c b/example/mdump.c index 724959f..67a2b12 100644 --- a/example/mdump.c +++ b/example/mdump.c @@ -29,12 +29,12 @@ @section mdump-description DESCRIPTION - Dump a text as a Netpbm image. + Dump a text as PNG image file. - The Netpbm image is written to a file created in the current - directory with the name "BASE.pbm" where BASE is the basename of - FILE. If FILE is omitted, text is read from standard input, and - the image is dumped into the file "output.pbm". + The PNG file is written to a file created in the current directory + with the name "BASE.png" where BASE is the basename of FILE. If + FILE is omitted, text is read from standard input, and the image + is dumped into the file "output.png". The following OPTIONs are available. @@ -55,7 +55,7 @@ WxH. In the last case, W and H are the width and height in millimeter. If this option is specified, PAPER limits the image size. If FILE is too large for a single page, multiple files with - the names "BASE.01.pbm", "BASE.02.pbm", etc. are created. + the names "BASE.01.png", "BASE.02.png", etc. are created.
  • -m MARGIN @@ -71,7 +71,7 @@
  • -x FILE is assumed to be an XML file generated by the serialize - facility of the m17n library, and FILE is deserialized before the + facility of the m17n library, and FILE is deserialized before an image is created.
  • -w @@ -81,11 +81,11 @@
  • -f FILTER FILTER is a string containing a shell command line. If this - option is specified, the Netpbm image is not written info a + option is specified, the PNG image is not written info a file but is given to FILTER as standard input. If FILTER contains "%s", that part is replaced by a basename of FILE. So, the default behaviour is the same as specifying "cat > - %s.pbm" as FILTER. + %s.png" as FILTER.
  • -q @@ -110,12 +110,12 @@ @section mdump-description DESCRIPTION - ¥Æ¥­¥¹¥È¤ò Netpbm ²èÁü¤È¤·¤Æ¥À¥ó¥×¤¹¤ë¡£ + ¥Æ¥­¥¹¥È¤ò PNG ²èÁü¤È¤·¤Æ¥À¥ó¥×¤¹¤ë¡£ - Netpbm ²èÁü¤Ï¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ëºî¤é¤ì¤¿ "BASE.pbm" ¤È¤¤¤¦Ì¾Á°¤Î + PNG ²èÁü¤Ï¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ëºî¤é¤ì¤¿ "BASE.png" ¤È¤¤¤¦Ì¾Á°¤Î ¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤Þ¤ì¤ë¡£¤³¤³¤Ç BASE ¤ÏFILE ¤Î basename ¤Ç¤¢¤ë¡£ FILE ¤¬¾Êά¤µ¤ì¤ì¤Ð¡¢¥Æ¥­¥¹¥È¤Ïɸ½àÆþÎϤ«¤éÆɤޤ졢²èÁü¤Ï - "output.pbm" ¤Ë¥À¥ó¥×¤µ¤ì¤ë¡£ + "output.png" ¤Ë¥À¥ó¥×¤µ¤ì¤ë¡£ °Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤¬ÍøÍѤǤ­¤ë¡£ @@ -136,8 +136,8 @@ PAPER ¤Ï¤Ú¡¼¥Ñ¥µ¥¤¥º : a4, a4r, a5, a5r, b5, b5r, letter, ¤Þ¤¿¤Ï WxH. WxH ¤Î¾ì¹ç¡¢ W ¤È H ¤ÏÉý¤È¹â¤µ¤ò¥ß¥ê¥á¡¼¥¿Ã±°Ì¤Ç¼¨¤·¤¿¤â¤Î¡£ ¤³¤Î¥ª¥×¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢ PAPER ¤¬²èÁü¥µ¥¤¥º¤òÀ©¸Â¤¹ - ¤ë¡£FILE ¤¬ 1 ¥Ú¡¼¥¸¤ËǼ¤Þ¤é¤Ê¤¤¤Û¤ÉÂ礭¤¤¾ì¹ç¤Ï¡¢"BASE.01.pbm", - "BASE.02.pbm" Åù¤Î̾Á°¤Î¤Ä¤¤¤¿Ê£¿ô¤Î¥Õ¥¡¥¤¥ë¤¬ºî¤é¤ì¤ë¡£ + ¤ë¡£FILE ¤¬ 1 ¥Ú¡¼¥¸¤ËǼ¤Þ¤é¤Ê¤¤¤Û¤ÉÂ礭¤¤¾ì¹ç¤Ï¡¢"BASE.01.png", + "BASE.02.png" Åù¤Î̾Á°¤Î¤Ä¤¤¤¿Ê£¿ô¤Î¥Õ¥¡¥¤¥ë¤¬ºî¤é¤ì¤ë¡£
  • -m MARGIN @@ -160,10 +160,10 @@
  • -f FILTER FILTER ¤Ï¥·¥§¥ë¥³¥Þ¥ó¥É¹Ô¤ò´Þ¤àʸ»úÎó¤Ç¤¢¤ë¡£¤³¤Î¥ª¥×¥·¥ç¥ó¤¬»ØÄê - ¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢Netpbm ²èÁü¤Ï¥Õ¥¡¥¤¥ë¤Ë½ñ¤«¤ì¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢FILTER ¤Ë + ¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢PNG ²èÁü¤Ï¥Õ¥¡¥¤¥ë¤Ë½ñ¤«¤ì¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢FILTER ¤Ë ɸ½àÆþÎϤȤ·¤ÆÅϤµ¤ì¤ë¡£ FILTER ¤¬ "s" ¤ò´Þ¤ó¤Ç¤¤¤ì¤Ð¡¢¤½¤ì¤Ï FILE ¤Î¥Ù¡¼¥¹¥Í¡¼¥à¤ËÃÖ¤­´¹¤¨¤é¤ì¤ë¡£¤³¤Î¥×¥í¥°¥é¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¶Éñ¤¤ - ¤È¡¢FILTER ¤Ë "cat > s.pbm" ¤ò»ØÄꤷ¤¿¾ì¹ç¤Î¿¶Éñ¤ÏƱ°ì¤Ç¤¢¤ë¡£ + ¤È¡¢FILTER ¤Ë "cat > s.png" ¤ò»ØÄꤷ¤¿¾ì¹ç¤Î¿¶Éñ¤ÏƱ°ì¤Ç¤¢¤ë¡£
  • -q @@ -187,7 +187,7 @@ #include #include -#include +#include #include #include @@ -236,11 +236,11 @@ help_exit (char *prog, int exit_code) prog = p; printf ("Usage: %s [ OPTION ...] [ FILE ]\n", prog); - printf ("Dump a text as a Netpbm image into a PBM file.\n"); - printf (" The PBM file is created in the current directory\n"); - printf (" with the name \"BASE.pbm\" where BASE is the basename of FILE.\n"); + printf ("Dump a text as a PNG image into a file.\n"); + printf (" The PNG file is created in the current directory\n"); + printf (" with the name \"BASE.png\" where BASE is the basename of FILE.\n"); printf (" If FILE is omitted, text is read from standard input, and\n"); - printf (" dumped into the file \"output.pbm\".\n"); + printf (" dumped into the file \"output.png\".\n"); printf ("The following OPTIONs are available.\n"); printf (" %-13s %s", "-s SIZE", "Font size in point (default 12).\n"); @@ -351,13 +351,10 @@ init_reverse_bit_order () FILENAME and PAGE_INDEX (if it is not zero). */ void -dump_image (XImage *image, char *filename, char *filter, - int white_is_zero, int page_index, int quiet_mode) +dump_image (gdImagePtr image, char *filename, char *filter, + int page_index, int quiet_mode) { FILE *fp; - int pbm_bytes_per_line; - char *data = image->data; - int x, y; if (page_index) { @@ -382,7 +379,7 @@ dump_image (XImage *image, char *filename, char *filter, { char *fullname = alloca (strlen (filename) + 5); - sprintf (fullname, "%s.pbm", filename); + sprintf (fullname, "%s.png", filename); fp = fopen (fullname, "w"); if (! fp) FATAL_ERROR ("Can't write to \"%s\"\n", fullname); @@ -390,53 +387,11 @@ dump_image (XImage *image, char *filename, char *filter, printf ("Writing %s ... ", fullname); } - if (image->bitmap_bit_order != MSBFirst - || (image->byte_order != MSBFirst - && image->bitmap_unit != 8)) - { - /* We must adjust image->data for PBM. */ - int bytes_per_unit = image->bitmap_unit / 8; - - for (y = 0; y < image->height; y++, data += image->bytes_per_line) - { - char b; - - if (image->byte_order != MSBFirst) - { - if (reverse_bit_order[0] == 0) - init_reverse_bit_order (); - if (bytes_per_unit == 2) - for (x = 0; x < image->bytes_per_line; x += 2) - b = data[x], data[x] = data[x + 1], data[x + 1] = b; - else if (bytes_per_unit == 6) - for (x = 0; x < image->bytes_per_line; x += 3) - { - b = data[x], data[x] = data[x + 3], data[x + 3] = b; - x++; - b = data[x], data[x] = data[x + 1], data[x + 1] = b; - } - } - - if (image->bitmap_bit_order != MSBFirst) - for (x = 0; x < image->bytes_per_line; x++) - data[x] = reverse_bit_order[(unsigned char) data[x]]; - if (! white_is_zero) - for (x = 0; x < image->bytes_per_line; x++) - data[x] = ~data[x]; - } - /* Reset DATA. */ - data = image->data; - } - - /* Generate PBM (Portable Bitmap File Format) of P4 format. */ - fprintf (fp, "P4\n%d %d\n", image->width, image->height); - pbm_bytes_per_line = (image->width + 7) / 8; - for (y = 0; y < image->height; y++, data += image->bytes_per_line) - fwrite (data, 1, pbm_bytes_per_line, fp); - + /* Generate PNG. */ + gdImagePng (image, fp); fclose (fp); if (! quiet_mode) - printf (" done (%dx%d)\n", image->width, image->height); + printf (" done (%dx%d)\n", image->sx, image->sy); } extern int line_break (MText *mt, int pos, int from, int to, int line, int y); @@ -444,11 +399,6 @@ extern int line_break (MText *mt, int pos, int from, int to, int line, int y); int main (int argc, char **argv) { - Display *display; - int screen; - GC gc; - Pixmap pixmap; - XImage *image; int fontsize = 120; int paper = PAPER_NOLIMIT; int dpi = 300; @@ -462,6 +412,8 @@ main (int argc, char **argv) int i; int paper_width, paper_height; int page_index; + gdImagePtr image; + int white; MFrame *frame; MText *mt; @@ -589,9 +541,6 @@ main (int argc, char **argv) margin = margin * dpi / 25.4; } - display = XOpenDisplay (NULL); - screen = DefaultScreen (display); - { MPlist *plist = mplist (), *p; MFontset *fontset = mfontset ("truetype"); @@ -599,8 +548,7 @@ main (int argc, char **argv) mface_put_prop (face, Mfontset, fontset); mface_put_prop (face, Msize, (void *) (fontsize * dpi / 100)); - p = mplist_add (plist, msymbol ("display"), display); - p = mplist_add (p, msymbol ("depth"), (void *) 1); + p = mplist_add (plist, Mdevice, msymbol ("gd")); p = mplist_add (p, Mface, face); m17n_object_unref (face); frame = mframe (plist); @@ -613,6 +561,7 @@ main (int argc, char **argv) control.as_image = 1; control.two_dimensional = 1; control.enable_bidi = 1; + control.anti_alias = 1; if (cursor_pos >= 0) { control.with_cursor = 1; @@ -636,12 +585,10 @@ main (int argc, char **argv) else control.max_line_width = paper_width - margin * 2; - pixmap = XCreatePixmap (display, RootWindow (display, screen), - paper_width, paper_height, 1); - gc = XCreateGC (display, pixmap, 0L, NULL); - + image = gdImageCreate (paper_width, paper_height); from = 0; page_index = 1; + white = gdImageColorAllocate (image, 255, 255, 255); while (from < len) { int to; @@ -652,21 +599,12 @@ main (int argc, char **argv) to = find_page_end (frame, paper_height - margin * 2, mt, from, &control, &rect); - XSetForeground (display, gc, WhitePixel (display, screen)); - XFillRectangle (display, pixmap, gc, 0, 0, paper_width, paper_height); - mdraw_text_with_control (frame, (MDrawWindow) pixmap, + gdImageFilledRectangle (image, 0, 0, paper_width - 1, paper_height - 1, + white); + mdraw_text_with_control (frame, image, margin, margin - rect.y, mt, from, to, &control); - XSetForeground (display, gc, BlackPixel (display, screen)); -#if 0 - XDrawRectangle (display, pixmap, gc, margin, margin, - paper_width - margin * 2 - 1, - paper_height - margin * 2 - 1); -#endif - image = XGetImage (display, pixmap, 0, 0, paper_width, paper_height, - AllPlanes, XYPixmap); - XInitImage (image); - dump_image (image, filename, filter, !WhitePixel (display, screen), + dump_image (image, filename, filter, ((from > 0 || to < len) ? page_index : 0), quiet_mode); @@ -677,7 +615,7 @@ main (int argc, char **argv) m17n_object_unref (frame); m17n_object_unref (mt); M17N_FINI (); - XCloseDisplay (display); + gdImageDestroy (image); exit (0); } #endif /* not FOR_DOXYGEN */