@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.
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.
<li> -m MARGIN
<li> -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.
<li> -w
<li> -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.
<li> -q
@section mdump-description DESCRIPTION
- ¥Æ¥¥¹¥È¤ò Netpbm ²èÁü¤È¤·¤Æ¥À¥ó¥×¤¹¤ë¡£
+ ¥Æ¥¥¹¥È¤ò PNG ²èÁü¤È¤·¤Æ¥À¥ó¥×¤¹¤ë¡£
- Netpbm ²èÁü¤Ï¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ëºî¤é¤ì¤¿ "BASE.pbm" ¤È¤¤¤¦Ì¾Á°¤Î
+ PNG ²èÁü¤Ï¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ëºî¤é¤ì¤¿ "BASE.png" ¤È¤¤¤¦Ì¾Á°¤Î
¥Õ¥¡¥¤¥ë¤Ë½ñ¤¹þ¤Þ¤ì¤ë¡£¤³¤³¤Ç BASE ¤ÏFILE ¤Î basename ¤Ç¤¢¤ë¡£
FILE ¤¬¾Êά¤µ¤ì¤ì¤Ð¡¢¥Æ¥¥¹¥È¤Ïɸ½àÆþÎϤ«¤éÆɤޤ졢²èÁü¤Ï
- "output.pbm" ¤Ë¥À¥ó¥×¤µ¤ì¤ë¡£
+ "output.png" ¤Ë¥À¥ó¥×¤µ¤ì¤ë¡£
°Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤¬ÍøÍѤǤ¤ë¡£
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" Åù¤Î̾Á°¤Î¤Ä¤¤¤¿Ê£¿ô¤Î¥Õ¥¡¥¤¥ë¤¬ºî¤é¤ì¤ë¡£
<li> -m MARGIN
<li> -f FILTER
FILTER ¤Ï¥·¥§¥ë¥³¥Þ¥ó¥É¹Ô¤ò´Þ¤àʸ»úÎó¤Ç¤¢¤ë¡£¤³¤Î¥ª¥×¥·¥ç¥ó¤¬»ØÄê
- ¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢Netpbm ²èÁü¤Ï¥Õ¥¡¥¤¥ë¤Ë½ñ¤«¤ì¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢FILTER ¤Ë
+ ¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢PNG ²èÁü¤Ï¥Õ¥¡¥¤¥ë¤Ë½ñ¤«¤ì¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢FILTER ¤Ë
ɸ½àÆþÎϤȤ·¤ÆÅϤµ¤ì¤ë¡£ FILTER ¤¬ "s" ¤ò´Þ¤ó¤Ç¤¤¤ì¤Ð¡¢¤½¤ì¤Ï FILE
¤Î¥Ù¡¼¥¹¥Í¡¼¥à¤ËÃÖ¤´¹¤¨¤é¤ì¤ë¡£¤³¤Î¥×¥í¥°¥é¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¶Éñ¤¤
- ¤È¡¢FILTER ¤Ë "cat > s.pbm" ¤ò»ØÄꤷ¤¿¾ì¹ç¤Î¿¶Éñ¤ÏƱ°ì¤Ç¤¢¤ë¡£
+ ¤È¡¢FILTER ¤Ë "cat > s.png" ¤ò»ØÄꤷ¤¿¾ì¹ç¤Î¿¶Éñ¤ÏƱ°ì¤Ç¤¢¤ë¡£
<li> -q
#include <string.h>
#include <libgen.h>
-#include <X11/Xlib.h>
+#include <gd.h>
#include <m17n-gui.h>
#include <m17n-misc.h>
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");
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)
{
{
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);
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);
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;
int i;
int paper_width, paper_height;
int page_index;
+ gdImagePtr image;
+ int white;
MFrame *frame;
MText *mt;
margin = margin * dpi / 25.4;
}
- display = XOpenDisplay (NULL);
- screen = DefaultScreen (display);
-
{
MPlist *plist = mplist (), *p;
MFontset *fontset = mfontset ("truetype");
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);
control.as_image = 1;
control.two_dimensional = 1;
control.enable_bidi = 1;
+ control.anti_alias = 1;
if (cursor_pos >= 0)
{
control.with_cursor = 1;
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;
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);
m17n_object_unref (frame);
m17n_object_unref (mt);
M17N_FINI ();
- XCloseDisplay (display);
+ gdImageDestroy (image);
exit (0);
}
#endif /* not FOR_DOXYGEN */