X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=example%2Fmdump.c;h=a53cd7e5ce7f758214aa32de326e026d6f026998;hb=f585b4727a65159d539c8921b0c354c501cdb043;hp=76c8416b685ce7fb95acaec3a4c9b957750f1542;hpb=4867144910a33314aa080037b228a3805299d051;p=m17n%2Fm17n-lib.git diff --git a/example/mdump.c b/example/mdump.c index 76c8416..a53cd7e 100644 --- a/example/mdump.c +++ b/example/mdump.c @@ -1,5 +1,5 @@ /* mdump.c -- Dump text image -*- coding: euc-jp; -*- - Copyright (C) 2003, 2004, 2005 + Copyright (C) 2003, 2004, 2005, 2006, 2007 National Institute of Advanced Industrial Science and Technology (AIST) Registration Number H15PRO112 @@ -17,7 +17,7 @@ You should have received a copy of the GNU Lesser General Public License along with the m17n library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 02111-1307, USA. */ /***en @@ -103,6 +103,17 @@ Prefer a font specified for the language LANG. LANG must be a 2-letter code of ISO 630 (e.g. "en" for English). +
  • -fg FOREGROUND + + Specify the text color. The supported color names are those of + HTML 4.0 and "#RRGGBB" notation. + +
  • -bg BACKGROUND + + Specify the background color. The supported color names are the + same as FOREGROUND, except that if "transparent" is specified, + make the background transparent. +
  • -r Specify that the orientation of the text is right-to-left. @@ -201,6 +212,20 @@ ¸À¸ì LANG ÍѤ˻ØÄꤵ¤ì¤¿¥Õ¥©¥ó¥È¤òÍ¥ÀèŪ¤Ë»È¤¦¡£LANG ¤Ï ISO 630 ¤Î £²Ê¸»ú¥³¡¼¥É¡ÊÎ㡧±Ñ¸ì¤Ï "en" ¡Ë¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£ +
  • -fg FOREGROUND + + ¥Æ¥­¥¹¥È¤Î¿§¤ò»ØÄꤹ¤ë¡£HTML 4.0 ¤Î¿§¤Î̾Á°¤ª¤è¤Ó "#RRGGBB" µ­Ë¡¤ò + ¥µ¥Ý¡¼¥È¡£ + +
  • -bg BACKGROUND + + Çطʤ理ò»ØÄꤹ¤ë¡£¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¿§¤Î̾Á°¤Ï FOREGROUND Ʊ¤¸¡£ + ¤¿¤À¤·¡¢¤â¤· "transparent" ¤¬»ØÄꤵ¤ì¤¿¤éÇطʤòÆ©ÌÀ¤Ë¤¹¤ë¡£ + +
  • -r + + Specify that the orientation of the text is right-to-left. +
  • -q °ìÀڤΥá¥Ã¥»¡¼¥¸¤òɽ¼¨¤·¤Ê¤¤¡£ @@ -230,8 +255,6 @@ #include #include -#define PROGRAM_VERSION "1.1" - /* Enumuration of the supported paper types. */ enum paper_type { @@ -302,6 +325,10 @@ help_exit (char *prog, int exit_code) "Prefer a font specified for the langauge LANG.\n"); printf (" %-13s %s", "-r", "Specify that the orientation of the text is right-to-left.\n"); + printf (" %-13s %s", "-fg FOREGROUND", + "Specify the text color (HTML 4.0 color names or \"#RRGGBB\").\n"); + printf (" %-13s %s", "-bg BACKGROUND", + "Specify the background color (\"transparent\" for transparent)\n"); printf (" %-13s %s", "-q", "Quiet mode. Don't print any messages.\n"); printf (" %-13s %s", "--version", "Print the version number.\n"); printf (" %-13s %s", "-h, --help", "Print this message.\n"); @@ -445,11 +472,13 @@ main (int argc, char **argv) int anti_alias = 0; char *family_name = NULL; char *lang_name = NULL; + char *fg_color = NULL, *bg_color = NULL; + int transparent = 0; int r2l = 0; int i; int page_index; gdImagePtr image; - int white; + int bg_rgb; MFrame *frame; MText *mt; @@ -457,7 +486,7 @@ main (int argc, char **argv) MDrawMetric rect; char *filename = "output"; int len, from; - char *fontset_name = "truetype"; + char *fontset_name = "generic"; /* Parse the command line arguments. */ @@ -469,8 +498,8 @@ main (int argc, char **argv) help_exit (argv[0], 0); else if (! strcmp (argv[i], "--version")) { - printf ("m17n-dump (m17n library) %s\n", PROGRAM_VERSION); - printf ("Copyright (C) 2003, 2004 AIST, JAPAN\n"); + printf ("m17n-dump (m17n library) %s\n", M17NLIB_VERSION_NAME); + printf ("Copyright (C) 2007 AIST, JAPAN\n"); exit (0); } else if (! strcmp (argv[i], "-s") && i + 1< argc) @@ -576,7 +605,28 @@ main (int argc, char **argv) { fontset_name = argv[++i]; } - + else if (! strcmp (argv[i], "-fg")) + { + if (i + 1 == argc) + { + fprintf (stderr, "Foreground color not specified\n"); + help_exit (argv[0], 1); + } + fg_color = argv[++i]; + } + else if (! strcmp (argv[i], "-bg")) + { + if (i + 1 == argc) + { + fprintf (stderr, "Background color not specified\n"); + help_exit (argv[0], 1); + } + i++; + if (! strcmp (argv[i], "transparent")) + transparent = 1; + else + bg_color = argv[i]; + } else { fprintf (stderr, "Unknown or invalid option: %s\n", argv[i]); @@ -624,7 +674,10 @@ main (int argc, char **argv) if (isupper (*p)) *p = tolower (*p); mface_put_prop (face, Mfamily, msymbol (family_name)); } - + if (fg_color) + mface_put_prop (face, Mforeground, msymbol (fg_color)); + if (bg_color) + mface_put_prop (face, Mbackground, msymbol (bg_color)); p = mplist_add (plist, Mdevice, msymbol ("gd")); p = mplist_add (p, Mface, face); m17n_object_unref (face); @@ -669,10 +722,46 @@ main (int argc, char **argv) } } +#if HAVE_GD > 1 + image = gdImageCreateTrueColor (paper_width, paper_height); +#else image = gdImageCreate (paper_width, paper_height); +#endif from = 0; page_index = 1; - white = gdImageColorAllocate (image, 255, 255, 255); + + if (transparent) + { + MFace *face = mframe_get_prop (frame, Mface); + MSymbol fg = mface_get_prop (face, Mforeground); + int rgb_value = 0; + + if (fg) + rgb_value = (int) msymbol_get (fg, msymbol (" rgb")); + if (rgb_value == 0xFFFFFF) + bg_rgb = gdImageColorAllocate (image, 0, 0, 0); + else + bg_rgb = gdImageColorAllocate (image, 255, 255, 255); + gdImageColorTransparent (image, bg_rgb); +#if HAVE_GD > 1 + gdImageAlphaBlending (image, 0); +#endif + } + else + { + MFace *face = mframe_get_prop (frame, Mface); + MSymbol bg = mface_get_prop (face, Mbackground); + if (bg) + { + int rgb_value = (int) msymbol_get (bg, msymbol (" rgb")); + bg_rgb = gdImageColorAllocate (image, rgb_value >> 16, + (rgb_value >> 8) & 255, + rgb_value & 255); + } + else + bg_rgb = gdImageColorAllocate (image, 255, 255, 255); + } + while (from < len) { int to; @@ -684,7 +773,7 @@ main (int argc, char **argv) &control, &rect); gdImageFilledRectangle (image, 0, 0, paper_width - 1, paper_height - 1, - white); + bg_rgb); if (! r2l) mdraw_text_with_control (frame, image, margin, margin - rect.y,