Updated print plug-in to version 2.0

--Sven
This commit is contained in:
Sven Neumann 1998-05-11 19:53:31 +00:00
parent 695c0970cc
commit bea57c14aa
7 changed files with 2455 additions and 959 deletions

View File

@ -1,3 +1,7 @@
Mon May 11 21:40:25 MEST 1998 Sven Neumann <sven@gimp.org>
* updated print plug-in
Fri May 8 20:51:24 PDT 1998 Manish Singh <yosh@gimp.org>
* plug-ins/script-fu/script-fu-console.c: workaround for text

View File

@ -21,46 +21,28 @@
*
* Contents:
*
* escp2_print() - Print an image to an EPSON printer.
* escp2_write() - Send ESC/P2 graphics using TIFF packbits compression.
* escp2_parameters() - Return the parameter values for the given
* parameter.
* escp2_imageable_area() - Return the imageable area of the page.
* escp2_print() - Print an image to an EPSON printer.
* escp2_write() - Send ESC/P2 graphics using TIFF packbits compression.
*
* Revision History:
*
* $Log$
* Revision 1.6 1998/04/13 05:43:12 yosh
* Have fun recompiling gimp everyone. It's the great FSF address change!
*
* -Yosh
*
* Revision 1.5 1998/04/07 03:41:11 yosh
* configure.in: fix for $srcdir != $builddir for data. Tightened check for
* random() and add -lucb on systems that need it. Fix for xdelta.h check. Find
* xemacs as well as emacs. Properly define settings for print plugin.
*
* app/Makefile.am: ditch -DNDEBUG, since nothing uses it
*
* flame: properly handle random() and friends
*
* pnm: workaround for systems with old sprintfs
*
* print, sgi: fold back in portability fixes
*
* threshold_alpha: properly get params in non-interactive mode
*
* bmp: updated and merged in
*
* -Yosh
*
* Revision 1.4 1998/04/01 22:14:44 neo
* Added checks for print spoolers to configure.in as suggested by Michael
* Sweet. The print plug-in still needs some changes to Makefile.am to make
* make use of this.
*
* Updated print and sgi plug-ins to version on the registry.
* Revision 1.7 1998/05/11 19:49:56 neo
* Updated print plug-in to version 2.0
*
*
* --Sven
*
* Revision 1.10 1998/05/08 21:18:34 mike
* Now enable microweaving in 720 DPI mode.
*
* Revision 1.9 1998/05/08 20:49:43 mike
* Updated to support media size, imageable area, and parameter functions.
* Added support for scaling modes - scale by percent or scale by PPI.
*
* Revision 1.8 1998/01/21 21:33:47 mike
* Updated copyright.
*
@ -109,26 +91,131 @@
static void escp2_write(FILE *, unsigned char *, int, int, int, int, int, int);
/*
* 'escp2_parameters()' - Return the parameter values for the given parameter.
*/
char ** /* O - Parameter values */
escp2_parameters(int model, /* I - Printer model */
char *ppd_file, /* I - PPD file (not used) */
char *name, /* I - Name of parameter */
int *count) /* O - Number of values */
{
int i;
char **p,
**valptrs;
static char *media_sizes[] =
{
"Letter",
"Legal",
"A4",
"Tabloid",
"A3",
"12x18"
};
static char *resolutions[] =
{
"360 DPI",
"720 DPI"
};
if (count == NULL)
return (NULL);
*count = 0;
if (name == NULL)
return (NULL);
if (strcmp(name, "PageSize") == 0)
{
if (model == 5 || model == 2)
*count = 6;
else
*count = 3;
p = media_sizes;
}
else if (strcmp(name, "Resolution") == 0)
{
*count = 2;
p = resolutions;
}
else
return (NULL);
valptrs = g_new(char *, *count);
for (i = 0; i < *count; i ++)
valptrs[i] = strdup(p[i]);
return (valptrs);
}
/*
* 'escp2_imageable_area()' - Return the imageable area of the page.
*/
void
escp2_imageable_area(int model, /* I - Printer model */
char *ppd_file, /* I - PPD file (not used) */
char *media_size, /* I - Media size */
int *left, /* O - Left position in points */
int *right, /* O - Right position in points */
int *bottom, /* O - Bottom position in points */
int *top) /* O - Top position in points */
{
int width, length; /* Size of page */
default_media_size(model, ppd_file, media_size, &width, &length);
switch (model)
{
default :
*left = 14;
*right = width - 14;
*top = length - 14;
*bottom = 40;
break;
case 3 :
case 4 :
case 5 :
*left = 8;
*right = width - 9;
*top = length - 32;
*bottom = 40;
break;
};
}
/*
* 'escp2_print()' - Print an image to an EPSON printer.
*/
void
escp2_print(FILE *prn, /* I - Print file or command */
GDrawable *drawable, /* I - Image to print */
int media_size, /* I - Output size */
int xdpi, /* I - Horizontal resolution */
int ydpi, /* I - Vertical resolution */
int output_type, /* I - Color or grayscale? */
int model, /* I - Model of printer */
guchar *lut, /* I - Brightness lookup table */
guchar *cmap, /* I - Colormap (for indexed images) */
escp2_print(int model, /* I - Model */
char *ppd_file, /* I - PPD file (not used) */
char *resolution, /* I - Resolution */
char *media_size, /* I - Media size */
char *media_type, /* I - Media type */
char *media_source, /* I - Media source */
int output_type, /* I - Output type (color/grayscale) */
int orientation, /* I - Orientation of image */
int scaling, /* I - Scaling of image */
int left, /* I - Left offset of image (10ths) */
int top) /* I - Top offset of image (10ths) */
float scaling, /* I - Scaling of image */
int left, /* I - Left offset of image (points) */
int top, /* I - Top offset of image (points) */
int copies, /* I - Number of copies */
FILE *prn, /* I - File to print to */
GDrawable *drawable, /* I - Image to print */
guchar *lut, /* I - Brightness lookup table */
guchar *cmap) /* I - Colormap (for indexed images) */
{
int x, y; /* Looping vars */
int xdpi, ydpi; /* Resolution */
int n; /* Output number */
GPixelRgn rgn; /* Image region */
unsigned char *in, /* Input pixels */
@ -137,8 +224,13 @@ escp2_print(FILE *prn, /* I - Print file or command */
*cyan, /* Cyan bitmap data */
*magenta, /* Magenta bitmap data */
*yellow; /* Yellow bitmap data */
int page_width, /* Width of page */
int page_left, /* Left margin of page */
page_right, /* Right margin of page */
page_top, /* Top of page */
page_bottom, /* Bottom of page */
page_width, /* Width of page */
page_height, /* Height of page */
page_length, /* True length of page */
out_width, /* Width of image on page */
out_height, /* Height of image on page */
out_bpp, /* Output bytes per pixel */
@ -189,44 +281,106 @@ escp2_print(FILE *prn, /* I - Print file or command */
colorfunc = indexed_to_gray;
};
/*
* Figure out the output resolution...
*/
xdpi = ydpi = atoi(resolution);
/*
* Compute the output size...
*/
landscape = 0;
page_width = media_width(media_size, xdpi);
page_height = media_height(media_size, ydpi);
escp2_imageable_area(model, ppd_file, media_size, &page_left, &page_right,
&page_bottom, &page_top);
page_width = page_right - page_left;
page_height = page_top - page_bottom;
default_media_size(model, ppd_file, media_size, &n, &page_length);
/*
* Portrait width/height...
*/
out_width = page_width * scaling / 100;
out_height = out_width * ydpi / xdpi * drawable->height / drawable->width;
if (out_height > page_height)
if (scaling < 0.0)
{
out_height = page_height;
out_width = out_height * xdpi / ydpi * drawable->width / drawable->height;
/*
* Scale to pixels per inch...
*/
out_width = drawable->width * -72.0 / scaling;
out_height = drawable->height * -72.0 / scaling;
}
else
{
/*
* Scale by percent...
*/
out_width = page_width * scaling / 100.0;
out_height = out_width * drawable->height / drawable->width;
if (out_height > page_height)
{
out_height = page_height * scaling / 100.0;
out_width = out_height * drawable->width / drawable->height;
};
};
/*
* Landscape width/height...
*/
temp_width = page_width * scaling / 100;
temp_height = temp_width * ydpi / xdpi * drawable->width / drawable->height;
if (temp_height > page_height)
if (scaling < 0.0)
{
temp_height = page_height;
temp_width = temp_height * xdpi / ydpi * drawable->height / drawable->width;
/*
* Scale to pixels per inch...
*/
temp_width = drawable->height * -72.0 / scaling;
temp_height = drawable->width * -72.0 / scaling;
}
else
{
/*
* Scale by percent...
*/
temp_width = page_width * scaling / 100.0;
temp_height = temp_width * drawable->width / drawable->height;
if (temp_height > page_height)
{
temp_height = page_height;
temp_width = temp_height * drawable->height / drawable->width;
};
};
/*
* See which orientation has the greatest area...
* See which orientation has the greatest area (or if we need to rotate the
* image to fit it on the page...)
*/
if ((temp_width * temp_height) > (out_width * out_height) &&
orientation != ORIENT_PORTRAIT)
if (orientation == ORIENT_AUTO)
{
if (scaling < 0.0)
{
if ((out_width > page_width && out_height < page_width) ||
(out_height > page_height && out_width < page_height))
orientation = ORIENT_LANDSCAPE;
else
orientation = ORIENT_PORTRAIT;
}
else
{
if ((temp_width * temp_height) > (out_width * out_height))
orientation = ORIENT_LANDSCAPE;
else
orientation = ORIENT_PORTRAIT;
};
};
if (orientation == ORIENT_LANDSCAPE)
{
out_width = temp_width;
out_height = temp_height;
@ -241,6 +395,12 @@ escp2_print(FILE *prn, /* I - Print file or command */
left = x;
};
if (top < 0 || left < 0)
{
left = (page_width - out_width) / 2;
top = (page_height + out_height) / 2;
};
/*
* Let the user know what we're doing...
*/
@ -270,60 +430,68 @@ escp2_print(FILE *prn, /* I - Print file or command */
};
fwrite("\033(C\002\000", 5, 1, prn); /* Page length */
n = page_height + ydpi;
n = ydpi * page_length / 72;
putc(n & 255, prn);
putc(n >> 8, prn);
if (left < 0 || top < 0)
{
left = (page_width - out_width) / 2;
top = (page_height - out_height + ydpi) / 2;
}
else
{
left *= xdpi / 10;
top = top * ydpi / 10 + ydpi / 2;
};
fwrite("\033(c\004\000", 5, 1, prn); /* Top/bottom margins */
putc(top & 255, prn);
putc(top >> 8, prn);
n = page_height + ydpi / 2;
n = ydpi * (page_length - page_top) / 72;
putc(n & 255, prn);
putc(n >> 8, prn);
n = ydpi * (page_length - page_bottom) / 72;
putc(n & 255, prn);
putc(n >> 8, prn);
fwrite("\033(V\002\000", 5, 1, prn); /* Absolute vertical position */
n = ydpi * (page_length - top) / 72;
putc(n & 255, prn);
putc(n >> 8, prn);
switch (model) /* Printer specific initialization */
{
case 0 : /* ESC */
if (output_type == OUTPUT_COLOR && ydpi > 360)
fwrite("\033(i\001\000\001", 6, 1, prn); /* Microweave mode on */
break;
case 1 : /* ESC Pro, Pro XL, 400, 500 */
fwrite("\033(e\002\000\000\001", 7, 1, prn); /* Small dots */
if (ydpi > 360)
fwrite("\033(i\001\000\001", 6, 1, prn); /* Microweave mode on */
break;
case 2 : /* ESC 1500 */
fwrite("\033(e\002\000\000\001", 7, 1, prn); /* Small dots */
if (ydpi > 360)
fwrite("\033(i\001\000\001", 6, 1, prn); /* Microweave mode on */
break;
case 3 : /* ESC 600 */
if (output_type == OUTPUT_GRAY)
fwrite("\033(K\002\000\000\001", 7, 1, prn); /* Fast black printing */
else
fwrite("\033(K\002\000\000\002", 7, 1, prn); /* Color printing */
fwrite("\033(e\002\000\000\003", 7, 1, prn); /* Small dots */
break;
case 4 : /* ESC 800, 1520, 3000 */
case 4 : /* ESC 800 */
case 5 : /* 1520, 3000 */
if (output_type == OUTPUT_GRAY)
fwrite("\033(K\002\000\000\001", 7, 1, prn); /* Fast black printing */
else
fwrite("\033(K\002\000\000\002", 7, 1, prn); /* Color printing */
fwrite("\033(e\002\000\000\002", 7, 1, prn); /* Small dots */
if (ydpi > 360)
fwrite("\033(i\001\000\001", 6, 1, prn); /* Microweave mode on */
break;
};
/*
* Convert image size to printer resolution...
*/
out_width = xdpi * out_width / 72;
out_height = ydpi * out_height / 72;
left = ydpi * left / 72;
/*
* Allocate memory for the raster data...
*/
@ -493,7 +661,7 @@ escp2_print(FILE *prn, /* I - Print file or command */
* 'escp2_write()' - Send ESC/P2 graphics using TIFF packbits compression.
*/
static void
void
escp2_write(FILE *prn, /* I - Print file or command */
unsigned char *line, /* I - Output bitmap data */
int length, /* I - Length of bitmap data */

View File

@ -21,47 +21,30 @@
*
* Contents:
*
* pcl_print() - Print an image to an HP printer.
* pcl_mode0() - Send PCL graphics using mode 0 (no) compression.
* pcl_mode2() - Send PCL graphics using mode 2 (TIFF) compression.
* pcl_parameters() - Return the parameter values for the given
* parameter.
* pcl_imageable_area() - Return the imageable area of the page.
* pcl_print() - Print an image to an HP printer.
* pcl_mode0() - Send PCL graphics using mode 0 (no) compression.
* pcl_mode2() - Send PCL graphics using mode 2 (TIFF) compression.
*
* Revision History:
*
* $Log$
* Revision 1.6 1998/04/13 05:43:13 yosh
* Have fun recompiling gimp everyone. It's the great FSF address change!
*
* -Yosh
*
* Revision 1.5 1998/04/07 03:41:12 yosh
* configure.in: fix for $srcdir != $builddir for data. Tightened check for
* random() and add -lucb on systems that need it. Fix for xdelta.h check. Find
* xemacs as well as emacs. Properly define settings for print plugin.
*
* app/Makefile.am: ditch -DNDEBUG, since nothing uses it
*
* flame: properly handle random() and friends
*
* pnm: workaround for systems with old sprintfs
*
* print, sgi: fold back in portability fixes
*
* threshold_alpha: properly get params in non-interactive mode
*
* bmp: updated and merged in
*
* -Yosh
*
* Revision 1.4 1998/04/01 22:14:45 neo
* Added checks for print spoolers to configure.in as suggested by Michael
* Sweet. The print plug-in still needs some changes to Makefile.am to make
* make use of this.
*
* Updated print and sgi plug-ins to version on the registry.
* Revision 1.7 1998/05/11 19:50:36 neo
* Updated print plug-in to version 2.0
*
*
* --Sven
*
* Revision 1.10 1998/05/08 21:22:00 mike
* Added quality mode command for DeskJet printers (high quality for 300
* DPI or higher).
*
* Revision 1.9 1998/05/08 19:20:50 mike
* Updated to support media size, imageable area, and parameter functions.
* Added support for scaling modes - scale by percent or scale by PPI.
*
* Revision 1.8 1998/01/21 21:33:47 mike
* Updated copyright.
*
@ -108,26 +91,198 @@ static void pcl_mode0(FILE *, unsigned char *, int, int);
static void pcl_mode2(FILE *, unsigned char *, int, int);
/*
* 'pcl_parameters()' - Return the parameter values for the given parameter.
*/
char ** /* O - Parameter values */
pcl_parameters(int model, /* I - Printer model */
char *ppd_file, /* I - PPD file (not used) */
char *name, /* I - Name of parameter */
int *count) /* O - Number of values */
{
int i;
char **p,
**valptrs;
static char *media_sizes[] =
{
"Letter",
"Legal",
"A4",
"Tabloid",
"A3",
"12x18"
};
static char *media_types[] =
{
"Plain",
"Premium",
"Glossy",
"Transparency"
};
static char *media_sources[] =
{
"Manual",
"Tray 1",
"Tray 2",
"Tray 3",
"Tray 4",
};
static char *resolutions[] =
{
"150 DPI",
"300 DPI",
"600 DPI"
};
if (count == NULL)
return (NULL);
*count = 0;
if (name == NULL)
return (NULL);
if (strcmp(name, "PageSize") == 0)
{
if (model == 5 || model == 1100)
*count = 6;
else
*count = 3;
p = media_sizes;
}
else if (strcmp(name, "MediaType") == 0)
{
if (model < 500)
{
*count = 0;
return (NULL);
}
else
{
*count = 4;
p = media_types;
};
}
else if (strcmp(name, "InputSlot") == 0)
{
if (model < 500)
{
*count = 5;
p = media_sources;
}
else
{
*count = 0;
return (NULL);
};
}
else if (strcmp(name, "Resolution") == 0)
{
if (model == 4 || model == 5 || model == 800 || model == 600)
*count = 3;
else
*count = 2;
p = resolutions;
}
else
return (NULL);
valptrs = g_new(char *, *count);
for (i = 0; i < *count; i ++)
valptrs[i] = strdup(p[i]);
return (valptrs);
}
/*
* 'pcl_imageable_area()' - Return the imageable area of the page.
*/
void
pcl_imageable_area(int model, /* I - Printer model */
char *ppd_file, /* I - PPD file (not used) */
char *media_size, /* I - Media size */
int *left, /* O - Left position in points */
int *right, /* O - Right position in points */
int *bottom, /* O - Bottom position in points */
int *top) /* O - Top position in points */
{
int width, length; /* Size of page */
default_media_size(model, ppd_file, media_size, &width, &length);
switch (model)
{
default :
*left = 18;
*right = width - 18;
*top = length - 12;
*bottom = 12;
break;
case 500 :
*left = 18;
*right = width - 18;
*top = length - 7;
*bottom = 41;
break;
case 501 :
*left = 18;
*right = width - 18;
*top = length - 7;
*bottom = 33;
break;
case 550 :
case 800 :
case 1100 :
*left = 18;
*right = width - 18;
*top = length - 3;
*bottom = 33;
break;
case 600 :
*left = 18;
*right = width - 18;
*top = length - 0;
*bottom = 33;
break;
};
}
/*
* 'pcl_print()' - Print an image to an HP printer.
*/
void
pcl_print(FILE *prn, /* I - Print file or command */
GDrawable *drawable, /* I - Image to print */
int media_size, /* I - Output size */
int xdpi, /* I - Horizontal resolution */
int ydpi, /* I - Vertical resolution */
int output_type, /* I - Color or grayscale? */
int model, /* I - Model of printer */
guchar *lut, /* I - Brightness lookup table */
guchar *cmap, /* I - Colormap (for indexed images) */
pcl_print(int model, /* I - Model */
char *ppd_file, /* I - PPD file (not used) */
char *resolution, /* I - Resolution */
char *media_size, /* I - Media size */
char *media_type, /* I - Media type */
char *media_source, /* I - Media source */
int output_type, /* I - Output type (color/grayscale) */
int orientation, /* I - Orientation of image */
int scaling, /* I - Scaling of image */
int left, /* I - Left offset of image (10ths) */
int top) /* I - Top offset of image (10ths) */
float scaling, /* I - Scaling of image */
int left, /* I - Left offset of image (points) */
int top, /* I - Top offset of image (points) */
int copies, /* I - Number of copies */
FILE *prn, /* I - File to print to */
GDrawable *drawable, /* I - Image to print */
guchar *lut, /* I - Brightness lookup table */
guchar *cmap) /* I - Colormap (for indexed images) */
{
int x, y; /* Looping vars */
int xdpi, ydpi; /* Resolution */
GPixelRgn rgn; /* Image region */
unsigned char *in, /* Input pixels */
*out, /* Output pixels */
@ -135,7 +290,11 @@ pcl_print(FILE *prn, /* I - Print file or command */
*cyan, /* Cyan bitmap data */
*magenta, /* Magenta bitmap data */
*yellow; /* Yellow bitmap data */
int page_width, /* Width of page */
int page_left, /* Left margin of page */
page_right, /* Right margin of page */
page_top, /* Top of page */
page_bottom, /* Bottom of page */
page_width, /* Width of page */
page_height, /* Height of page */
out_width, /* Width of image on page */
out_height, /* Height of image on page */
@ -192,44 +351,113 @@ pcl_print(FILE *prn, /* I - Print file or command */
colorfunc = indexed_to_gray;
};
/*
* Figure out the output resolution...
*/
xdpi = atoi(resolution);
if ((model == 800 || model == 1100) &&
output_type == OUTPUT_COLOR && xdpi == 600)
xdpi = 300;
if (model == 600 && xdpi == 600)
ydpi = 300;
else
ydpi = xdpi;
/*
* Compute the output size...
*/
landscape = 0;
page_width = media_width(media_size, xdpi);
page_height = media_height(media_size, ydpi);
landscape = 0;
pcl_imageable_area(model, ppd_file, media_size, &page_left, &page_right,
&page_bottom, &page_top);
page_width = page_right - page_left;
page_height = page_top - page_bottom;
/*
* Portrait width/height...
*/
out_width = page_width * scaling / 100;
out_height = out_width * ydpi / xdpi * drawable->height / drawable->width;
if (out_height > page_height)
if (scaling < 0.0)
{
out_height = page_height;
out_width = out_height * xdpi / ydpi * drawable->width / drawable->height;
/*
* Scale to pixels per inch...
*/
out_width = drawable->width * -72.0 / scaling;
out_height = drawable->height * -72.0 / scaling;
}
else
{
/*
* Scale by percent...
*/
out_width = page_width * scaling / 100.0;
out_height = out_width * drawable->height / drawable->width;
if (out_height > page_height)
{
out_height = page_height * scaling / 100.0;
out_width = out_height * drawable->width / drawable->height;
};
};
/*
* Landscape width/height...
*/
temp_width = page_width * scaling / 100;
temp_height = temp_width * ydpi / xdpi * drawable->width / drawable->height;
if (temp_height > page_height)
if (scaling < 0.0)
{
temp_height = page_height;
temp_width = temp_height * xdpi / ydpi * drawable->height / drawable->width;
/*
* Scale to pixels per inch...
*/
temp_width = drawable->height * -72.0 / scaling;
temp_height = drawable->width * -72.0 / scaling;
}
else
{
/*
* Scale by percent...
*/
temp_width = page_width * scaling / 100.0;
temp_height = temp_width * drawable->width / drawable->height;
if (temp_height > page_height)
{
temp_height = page_height;
temp_width = temp_height * drawable->height / drawable->width;
};
};
/*
* See which orientation has the greatest area...
* See which orientation has the greatest area (or if we need to rotate the
* image to fit it on the page...)
*/
if ((temp_width * temp_height) > (out_width * out_height) &&
orientation != ORIENT_PORTRAIT)
if (orientation == ORIENT_AUTO)
{
if (scaling < 0.0)
{
if ((out_width > page_width && out_height < page_width) ||
(out_height > page_height && out_width < page_height))
orientation = ORIENT_LANDSCAPE;
else
orientation = ORIENT_PORTRAIT;
}
else
{
if ((temp_width * temp_height) > (out_width * out_height))
orientation = ORIENT_LANDSCAPE;
else
orientation = ORIENT_PORTRAIT;
};
};
if (orientation == ORIENT_LANDSCAPE)
{
out_width = temp_width;
out_height = temp_height;
@ -244,6 +472,18 @@ pcl_print(FILE *prn, /* I - Print file or command */
left = x;
};
if (top < 0 || left < 0)
{
left = (page_width - out_width) / 2;
top = (page_height + out_height) / 2;
};
#ifdef DEBUG
printf("page_width = %d, page_height = %d\n", page_width, page_height);
printf("out_width = %d, out_height = %d\n", out_width, out_height);
printf("xdpi = %d, ydpi = %d, landscape = %d\n", xdpi, ydpi, landscape);
#endif /* DEBUG */
/*
* Let the user know what we're doing...
*/
@ -254,28 +494,63 @@ pcl_print(FILE *prn, /* I - Print file or command */
* Send PCL initialization commands...
*/
fputs("\033E", prn); /* PCL reset */
fputs("\033E", prn); /* PCL reset */
switch (media_size) /* Set media size... */
if (strcmp(media_size, "Letter") == 0) /* Set media size */
{
case MEDIA_LETTER :
fputs("\033&l2A", prn);
break;
case MEDIA_LEGAL :
fputs("\033&l3A", prn);
break;
case MEDIA_TABLOID :
fputs("\033&l6A", prn);
break;
case MEDIA_A4 :
fputs("\033&l26A", prn);
break;
case MEDIA_A3 :
fputs("\033&l27A", prn);
break;
fputs("\033&l2A", prn);
top = 792 - top;
}
else if (strcmp(media_size, "Legal") == 0)
{
fputs("\033&l3A", prn);
top = 1008 - top;
}
else if (strcmp(media_size, "Tabloid") == 0)
{
fputs("\033&l6A", prn);
top = 1214 - top;
}
else if (strcmp(media_size, "A4") == 0)
{
fputs("\033&l26A", prn);
top = 842 - top;
}
else if (strcmp(media_size, "A3") == 0)
{
fputs("\033&l27A", prn);
top = 1191 - top;
};
if (xdpi != ydpi) /* Set resolution */
fputs("\033&l0L", prn); /* Turn off perforation skip */
fputs("\033&l0E", prn); /* Reset top margin to 0 */
if (strcmp(media_type, "Plain") == 0) /* Set media type */
fputs("\033&l0M", prn);
else if (strcmp(media_type, "Premium") == 0)
fputs("\033&l2M", prn);
else if (strcmp(media_type, "Glossy") == 0)
fputs("\033&l3M", prn);
else if (strcmp(media_type, "Transparency") == 0)
fputs("\033&l4M", prn);
if (strcmp(media_type, "Manual") == 0) /* Set media source */
fputs("\033&l2H", prn);
else if (strcmp(media_type, "Tray 1") == 0)
fputs("\033&l8H", prn);
else if (strcmp(media_type, "Tray 2") == 0)
fputs("\033&l1H", prn);
else if (strcmp(media_type, "Tray 3") == 0)
fputs("\033&l4H", prn);
else if (strcmp(media_type, "Tray 4") == 0)
fputs("\033&l5H", prn);
if (model >= 500 && model < 1200 && xdpi >= 300)
fputs("\033*r2Q", prn);
else if (model == 1200 && xdpi >= 300)
fputs("\033*o1Q", prn);
if (xdpi != ydpi) /* Set resolution */
{
/*
* Send 26-byte configure image data command with horizontal and
@ -283,74 +558,70 @@ pcl_print(FILE *prn, /* I - Print file or command */
*/
fputs("\033*g26W", prn);
putc(2, prn); /* Format 2 */
putc(2, prn); /* Format 2 */
if (output_type == OUTPUT_COLOR)
putc(4, prn); /* # output planes */
putc(4, prn); /* # output planes */
else
putc(1, prn); /* # output planes */
putc(1, prn); /* # output planes */
putc(xdpi >> 8, prn); /* Black resolution */
putc(xdpi >> 8, prn); /* Black resolution */
putc(xdpi, prn);
putc(ydpi >> 8, prn);
putc(ydpi, prn);
putc(0, prn);
putc(2, prn); /* # of black levels */
putc(2, prn); /* # of black levels */
putc(xdpi >> 8, prn); /* Cyan resolution */
putc(xdpi >> 8, prn); /* Cyan resolution */
putc(xdpi, prn);
putc(ydpi >> 8, prn);
putc(ydpi, prn);
putc(0, prn);
putc(2, prn); /* # of cyan levels */
putc(2, prn); /* # of cyan levels */
putc(xdpi >> 8, prn); /* Magenta resolution */
putc(xdpi >> 8, prn); /* Magenta resolution */
putc(xdpi, prn);
putc(ydpi >> 8, prn);
putc(ydpi, prn);
putc(0, prn);
putc(2, prn); /* # of magenta levels */
putc(2, prn); /* # of magenta levels */
putc(xdpi >> 8, prn); /* Yellow resolution */
putc(xdpi >> 8, prn); /* Yellow resolution */
putc(xdpi, prn);
putc(ydpi >> 8, prn);
putc(ydpi, prn);
putc(0, prn);
putc(2, prn); /* # of yellow levels */
putc(2, prn); /* # of yellow levels */
}
else
{
fprintf(prn, "\033*t%dR", xdpi); /* Simple resolution */
fprintf(prn, "\033*t%dR", xdpi); /* Simple resolution */
if (output_type == OUTPUT_COLOR)
{
if (model == 501 || model == 1200)
fputs("\033*r-3U", prn); /* Simple CMY color */
fputs("\033*r-3U", prn); /* Simple CMY color */
else
fputs("\033*r-4U", prn); /* Simple KCMY color */
fputs("\033*r-4U", prn); /* Simple KCMY color */
};
};
if (model < 3 || model == 500)
fputs("\033*b0M", prn); /* Mode 0 (no compression) */
fputs("\033*b0M", prn); /* Mode 0 (no compression) */
else
fputs("\033*b2M", prn); /* Mode 2 (TIFF) */
fputs("\033*b2M", prn); /* Mode 2 (TIFF) */
if (left < 0 || top < 0)
{
left = (page_width - out_width) / 2;
top = (page_height - out_height) / 2;
}
else
{
left *= 30;
top *= 30;
};
/*
* Convert image size to printer resolution and setup the page for printing...
*/
fprintf(prn, "\033&a%dH", 720 * left / xdpi); /* Set left raster position */
fprintf(prn, "\033&a%dV", 720 * top / ydpi); /* Set top raster position */
out_width = xdpi * out_width / 72;
out_height = ydpi * out_height / 72;
fprintf(prn, "\033&a%dH", 10 * left); /* Set left raster position */
fprintf(prn, "\033&a%dV", 10 * top); /* Set top raster position */
fprintf(prn, "\033*r%dS", out_width); /* Set raster width */
fprintf(prn, "\033*r%dT", out_height); /* Set raster height */
fputs("\033*r1A", prn); /* Start GFX */
fputs("\033*r1A", prn); /* Start GFX */
/*
* Allocate memory for the raster data...
@ -535,7 +806,7 @@ pcl_print(FILE *prn, /* I - Print file or command */
* 'pcl_mode0()' - Send PCL graphics using mode 0 (no) compression.
*/
static void
void
pcl_mode0(FILE *prn, /* I - Print file or command */
unsigned char *line, /* I - Output bitmap data */
int length, /* I - Length of bitmap data */
@ -550,7 +821,7 @@ pcl_mode0(FILE *prn, /* I - Print file or command */
* 'pcl_mode2()' - Send PCL graphics using mode 2 (TIFF) compression.
*/
static void
void
pcl_mode2(FILE *prn, /* I - Print file or command */
unsigned char *line, /* I - Output bitmap data */
int length, /* I - Length of bitmap data */

View File

@ -21,47 +21,32 @@
*
* Contents:
*
* ps_print() - Print an image to a PostScript printer.
* ps_hex() - Print binary data as a series of hexadecimal numbers.
* ps_ascii85() - Print binary data as a series of base-85 numbers.
* ps_parameters() - Return the parameter values for the given
* parameter.
* ps_media_size() - Return the size of the page.
* ps_imageable_area() - Return the imageable area of the page.
* ps_print() - Print an image to a PostScript printer.
* ps_hex() - Print binary data as a series of hexadecimal numbers.
* ps_ascii85() - Print binary data as a series of base-85 numbers.
*
* Revision History:
*
* $Log$
* Revision 1.6 1998/04/13 05:43:14 yosh
* Have fun recompiling gimp everyone. It's the great FSF address change!
*
* -Yosh
*
* Revision 1.5 1998/04/07 03:41:14 yosh
* configure.in: fix for $srcdir != $builddir for data. Tightened check for
* random() and add -lucb on systems that need it. Fix for xdelta.h check. Find
* xemacs as well as emacs. Properly define settings for print plugin.
*
* app/Makefile.am: ditch -DNDEBUG, since nothing uses it
*
* flame: properly handle random() and friends
*
* pnm: workaround for systems with old sprintfs
*
* print, sgi: fold back in portability fixes
*
* threshold_alpha: properly get params in non-interactive mode
*
* bmp: updated and merged in
*
* -Yosh
*
* Revision 1.4 1998/04/01 22:14:46 neo
* Added checks for print spoolers to configure.in as suggested by Michael
* Sweet. The print plug-in still needs some changes to Makefile.am to make
* make use of this.
*
* Updated print and sgi plug-ins to version on the registry.
* Revision 1.7 1998/05/11 19:51:06 neo
* Updated print plug-in to version 2.0
*
*
* --Sven
*
* Revision 1.11 1998/05/08 19:20:50 mike
* Updated to support PPD files, media size, imageable area, and parameter
* functions.
* Added support for scaling modes - scale by percent or scale by PPI.
* Updated Ascii85 output - some Level 2 printers are buggy and won't accept
* whitespace in the data stream.
* Now use image dictionaries with Level 2 printers - allows interpolation
* flag to be sent (not all printers use this flag).
*
* Revision 1.10 1998/01/22 15:38:46 mike
* Updated copyright notice.
* Whoops - wasn't encoding correctly for portrait output to level 2 printers!
@ -106,6 +91,15 @@
#include "print.h"
#include <time.h>
/*#define DEBUG*/
/*
* Local variables...
*/
static FILE *ps_ppd = NULL;
static char *ps_ppd_file = NULL;
/*
@ -114,6 +108,166 @@
static void ps_hex(FILE *, guchar *, int);
static void ps_ascii85(FILE *, guchar *, int, int);
static char *ppd_find(char *, char *, char *, int *);
/*
* 'ps_parameters()' - Return the parameter values for the given parameter.
*/
char ** /* O - Parameter values */
ps_parameters(int model, /* I - Printer model */
char *ppd_file, /* I - PPD file (not used) */
char *name, /* I - Name of parameter */
int *count) /* O - Number of values */
{
int i;
char line[1024],
lname[255],
loption[255];
char **valptrs;
static char *media_sizes[] =
{
"Letter",
"Legal",
"A4",
"Tabloid",
"A3",
"12x18"
};
if (count == NULL)
return (NULL);
*count = 0;
if (ppd_file == NULL || name == NULL)
return (NULL);
if (ps_ppd_file == NULL || strcmp(ps_ppd_file, ppd_file) != 0)
{
if (ps_ppd != NULL)
fclose(ps_ppd);
ps_ppd = fopen(ppd_file, "r");
if (ps_ppd == NULL)
ps_ppd_file = NULL;
else
ps_ppd_file = ppd_file;
};
if (ps_ppd == NULL)
{
if (strcmp(name, "PageSize") == 0)
{
*count = 6;
valptrs = g_new(char *, 6);
for (i = 0; i < 6; i ++)
valptrs[i] = strdup(media_sizes[i]);
return (valptrs);
}
else
return (NULL);
};
rewind(ps_ppd);
*count = 0;
valptrs = g_new(char *, 100);
while (fgets(line, sizeof(line), ps_ppd) != NULL)
{
if (line[0] != '*')
continue;
if (sscanf(line, "*%s %[^/:]", lname, loption) != 2)
continue;
if (strcasecmp(lname, name) == 0)
{
valptrs[*count] = strdup(loption);
(*count) ++;
};
};
if (*count == 0)
{
g_free(valptrs);
return (NULL);
}
else
return (valptrs);
}
/*
* 'ps_media_size()' - Return the size of the page.
*/
void
ps_media_size(int model, /* I - Printer model */
char *ppd_file, /* I - PPD file (not used) */
char *media_size, /* I - Media size */
int *width, /* O - Width in points */
int *length) /* O - Length in points */
{
char *dimensions; /* Dimensions of media size */
#ifdef DEBUG
printf("ps_media_size(%d, \'%s\', \'%s\', %08x, %08x)\n", model, ppd_file,
media_size, width, length);
#endif /* DEBUG */
if ((dimensions = ppd_find(ppd_file, "PaperDimension", media_size, NULL)) != NULL)
sscanf(dimensions, "%d%d", width, length);
else
default_media_size(model, ppd_file, media_size, width, length);
}
/*
* 'ps_imageable_area()' - Return the imageable area of the page.
*/
void
ps_imageable_area(int model, /* I - Printer model */
char *ppd_file, /* I - PPD file (not used) */
char *media_size, /* I - Media size */
int *left, /* O - Left position in points */
int *right, /* O - Right position in points */
int *bottom, /* O - Bottom position in points */
int *top) /* O - Top position in points */
{
char *area; /* Imageable area of media */
float fleft, /* Floating point versions */
fright,
fbottom,
ftop;
if ((area = ppd_find(ppd_file, "ImageableArea", media_size, NULL)) != NULL)
{
#ifdef DEBUG
printf("area = \'%s\'\n", area);
#endif /* DEBUG */
if (sscanf(area, "%f%f%f%f", &fleft, &fbottom, &fright, &ftop) == 4)
{
*left = (int)fleft;
*right = (int)fright;
*bottom = (int)fbottom;
*top = (int)ftop;
}
else
*left = *right = *bottom = *top = 0;
}
else
*left = *right = *bottom = *top = 0;
}
/*
@ -121,25 +275,34 @@ static void ps_ascii85(FILE *, guchar *, int, int);
*/
void
ps_print(FILE *prn, /* I - File to print to */
GDrawable *drawable, /* I - Image to print */
int media_size, /* I - Size of output */
int xdpi, /* I - Horizontal resolution (always 72) */
int ydpi, /* I - Vertical resolution (always 72) */
int output_type, /* I - Output type (color/grayscale) */
int model, /* I - Model (ignored) */
guchar *lut, /* I - Brightness lookup table */
guchar *cmap, /* I - Colormap (for indexed images) */
int orientation, /* I - Orientation of image */
int scaling, /* I - Scaling of image */
int left, /* I - Left offset of image (10ths) */
int top) /* I - Top offset of image (10ths) */
ps_print(int model, /* I - Model (Level 1 or 2) */
char *ppd_file, /* I - PPD file */
char *resolution, /* I - Resolution */
char *media_size, /* I - Media size */
char *media_type, /* I - Media type */
char *media_source, /* I - Media source */
int output_type, /* I - Output type (color/grayscale) */
int orientation, /* I - Orientation of image */
float scaling, /* I - Scaling of image */
int left, /* I - Left offset of image (points) */
int top, /* I - Top offset of image (points) */
int copies, /* I - Number of copies */
FILE *prn, /* I - File to print to */
GDrawable *drawable, /* I - Image to print */
guchar *lut, /* I - Brightness lookup table */
guchar *cmap) /* I - Colormap (for indexed images) */
{
int i, j; /* Looping vars */
int x, y; /* Looping vars */
GPixelRgn rgn; /* Image region */
guchar *in, /* Input pixels from image */
*out; /* Output pixels for printer */
int page_width, /* Width of page */
*out, /* Output pixels for printer */
*outptr; /* Current output pixel */
int page_left, /* Left margin of page */
page_right, /* Right margin of page */
page_top, /* Top of page */
page_bottom, /* Bottom of page */
page_width, /* Width of page */
page_height, /* Height of page */
out_width, /* Width of image on page */
out_height, /* Height of image on page */
@ -151,11 +314,14 @@ ps_print(FILE *prn, /* I - File to print to */
landscape; /* True if we rotate the output 90 degrees */
time_t curtime; /* Current time of day */
convert_t colorfunc; /* Color conversion function... */
static char *filters[2] = /* PostScript image filters... */
{
"{currentfile picture readhexstring pop}", /* Level 1 */
"currentfile /ASCII85Decode filter" /* Level 2 */
};
char *command; /* PostScript command */
int order, /* Order of command */
num_commands; /* Number of commands */
struct /* PostScript commands... */
{
char *command;
int order;
} commands[4];
/*
@ -197,40 +363,100 @@ ps_print(FILE *prn, /* I - File to print to */
* Compute the output size...
*/
landscape = 0;
page_width = media_width(media_size, xdpi);
page_height = media_height(media_size, ydpi);
landscape = 0;
ps_imageable_area(model, ppd_file, media_size, &page_left, &page_right,
&page_bottom, &page_top);
page_width = page_right - page_left;
page_height = page_top - page_bottom;
#ifdef DEBUG
printf("page_width = %d, page_height = %d\n", page_width, page_height);
printf("drawable->width = %d, drawable->height = %d\n", drawable->width, drawable->height);
printf("scaling = %.1f\n", scaling);
#endif /* DEBUG */
/*
* Portrait width/height...
*/
out_width = page_width * scaling / 100;
out_height = out_width * ydpi / xdpi * drawable->height / drawable->width;
if (out_height > page_height)
if (scaling < 0.0)
{
out_height = page_height;
out_width = out_height * xdpi / ydpi * drawable->width / drawable->height;
/*
* Scale to pixels per inch...
*/
out_width = drawable->width * -72.0 / scaling;
out_height = drawable->height * -72.0 / scaling;
}
else
{
/*
* Scale by percent...
*/
out_width = page_width * scaling / 100.0;
out_height = out_width * drawable->height / drawable->width;
if (out_height > page_height)
{
out_height = page_height * scaling / 100.0;
out_width = out_height * drawable->width / drawable->height;
};
};
/*
* Landscape width/height...
*/
temp_width = page_width * scaling / 100;
temp_height = temp_width * ydpi / xdpi * drawable->width / drawable->height;
if (temp_height > page_height)
if (scaling < 0.0)
{
temp_height = page_height;
temp_width = temp_height * xdpi / ydpi * drawable->height / drawable->width;
/*
* Scale to pixels per inch...
*/
temp_width = drawable->height * -72.0 / scaling;
temp_height = drawable->width * -72.0 / scaling;
}
else
{
/*
* Scale by percent...
*/
temp_width = page_width * scaling / 100.0;
temp_height = temp_width * drawable->width / drawable->height;
if (temp_height > page_height)
{
temp_height = page_height;
temp_width = temp_height * drawable->height / drawable->width;
};
};
/*
* See which orientation has the greatest area...
* See which orientation has the greatest area (or if we need to rotate the
* image to fit it on the page...)
*/
if ((temp_width * temp_height) > (out_width * out_height) &&
orientation != ORIENT_PORTRAIT)
if (orientation == ORIENT_AUTO)
{
if (scaling < 0.0)
{
if ((out_width > page_width && out_height < page_width) ||
(out_height > page_height && out_width < page_height))
orientation = ORIENT_LANDSCAPE;
else
orientation = ORIENT_PORTRAIT;
}
else
{
if ((temp_width * temp_height) > (out_width * out_height))
orientation = ORIENT_LANDSCAPE;
else
orientation = ORIENT_PORTRAIT;
};
};
if (orientation == ORIENT_LANDSCAPE)
{
out_width = temp_width;
out_height = temp_height;
@ -257,19 +483,98 @@ ps_print(FILE *prn, /* I - File to print to */
curtime = time(NULL);
if (top < 0 || left < 0)
{
left = (page_width - out_width) / 2 + page_left;
top = (page_height + out_height) / 2 + page_bottom;
};
#ifdef DEBUG
printf("out_width = %d, out_height = %d\n", out_width, out_height);
printf("page_left = %d, page_right = %d, page_bottom = %d, page_top = %d\n",
page_left, page_right, page_bottom, page_top);
printf("left = %d, top = %d\n", left, top);
#endif /* DEBUG */
fputs("%!PS-Adobe-3.0\n", prn);
fputs("%%Creator: " PLUG_IN_NAME " plug-in V" PLUG_IN_VERSION " for GIMP.\n", prn);
fprintf(prn, "%%%%CreationDate: %s", ctime(&curtime));
fputs("%%Copyright: 1997-1998 by Michael Sweet (mike@easysw.com)\n", prn);
fprintf(prn, "%%%%BoundingBox: %d %d %d %d\n",
(page_width - out_width) / 2 + 18, (page_height - out_height) / 2 + 36,
(page_width + out_width) / 2 + 18, (page_height + out_height) / 2 + 36);
left, top - out_height, left + out_width, top);
fputs("%%DocumentData: Clean7Bit\n", prn);
fprintf(prn, "%%%%LanguageLevel: %d\n", model + 1);
fputs("%%Pages: 1\n", prn);
fputs("%%Orientation: Portrait\n", prn);
fputs("%%EndComments\n", prn);
/*
* Find any printer-specific commands...
*/
num_commands = 0;
if ((command = ppd_find(ppd_file, "PageSize", media_size, &order)) != NULL)
{
commands[num_commands].command = strdup(command);
commands[num_commands].order = order;
num_commands ++;
};
if ((command = ppd_find(ppd_file, "InputSlot", media_source, &order)) != NULL)
{
commands[num_commands].command = strdup(command);
commands[num_commands].order = order;
num_commands ++;
};
if ((command = ppd_find(ppd_file, "MediaType", media_type, &order)) != NULL)
{
commands[num_commands].command = strdup(command);
commands[num_commands].order = order;
num_commands ++;
};
if ((command = ppd_find(ppd_file, "Resolution", resolution, &order)) != NULL)
{
commands[num_commands].command = strdup(command);
commands[num_commands].order = order;
num_commands ++;
};
/*
* Sort the commands using the OrderDependency value...
*/
for (i = 0; i < (num_commands - 1); i ++)
for (j = i + 1; j < num_commands; j ++)
if (commands[j].order < commands[i].order)
{
order = commands[i].order;
command = commands[i].command;
commands[i].command = commands[j].command;
commands[i].order = commands[j].order;
commands[j].command = command;
commands[j].order = order;
};
/*
* Send the commands...
*/
if (num_commands > 0)
{
fputs("%%BeginProlog\n", prn);
for (i = 0; i < num_commands; i ++)
{
fputs(commands[i].command, prn);
free(commands[i].command);
};
fputs("%%EndProlog\n", prn);
};
/*
* Output the page, rotating as necessary...
*/
@ -277,87 +582,82 @@ ps_print(FILE *prn, /* I - File to print to */
fputs("%%Page: 1\n", prn);
fputs("gsave\n", prn);
if (top < 0 || left < 0)
if (landscape)
{
left = (page_width - out_width) / 2 + 18;
top = (page_height - out_height) / 2 + 36;
fprintf(prn, "%d %d translate\n", left, top - out_height);
fprintf(prn, "%.3f %.3f scale\n",
(float)out_width / ((float)drawable->height),
(float)out_height / ((float)drawable->width));
}
else
{
left = 72 * left / 10 + 18;
top = page_height - out_height - 72 * top / 10 + 36;
fprintf(prn, "%d %d translate\n", left, top);
fprintf(prn, "%.3f %.3f scale\n",
(float)out_width / ((float)drawable->width),
(float)out_height / ((float)drawable->height));
};
fprintf(prn, "%d %d translate\n", left, top);
fprintf(prn, "%d %d scale\n", out_width, out_height);
in = g_malloc(drawable->width * drawable->bpp);
out = g_malloc(drawable->width * out_bpp + 3);
if (landscape)
if (model == 0)
{
in = g_malloc(drawable->height * drawable->bpp);
out = g_malloc(drawable->height * out_bpp + 3);
fprintf(prn, "/picture %d string def\n", drawable->width * out_bpp);
if (model == 0)
fprintf(prn, "/picture %d string def\n", drawable->height * out_bpp);
fprintf(prn, "%d %d 8\n", drawable->width, drawable->height);
if (landscape)
fputs("[ 0 1 1 0 0 0 ]\n", prn);
else
fputs("[ 1 0 0 -1 0 1 ]\n", prn);
if (output_type == OUTPUT_GRAY)
fprintf(prn, "%d %d 8 [%d 0 0 %d 0 %d] %s image\n",
drawable->height, drawable->width,
drawable->height, drawable->width, 0,
filters[model]);
fputs("{currentfile picture readhexstring pop} image\n", prn);
else
fprintf(prn, "%d %d 8 [%d 0 0 %d 0 %d] %s false 3 colorimage\n",
drawable->height, drawable->width,
drawable->height, drawable->width, 0,
filters[model]);
fputs("{currentfile picture readhexstring pop} false 3 colorimage\n", prn);
for (x = 0, out_offset = 0; x < drawable->width; x ++)
for (y = 0; y < drawable->height; y ++)
{
if ((x & 15) == 0)
gimp_progress_update((double)x / (double)drawable->width);
if ((y & 15) == 0)
gimp_progress_update((double)y / (double)drawable->height);
gimp_pixel_rgn_get_col(&rgn, in, x, 0, drawable->height);
(*colorfunc)(in, out + out_offset, drawable->height, drawable->bpp, lut, cmap);
gimp_pixel_rgn_get_row(&rgn, in, 0, y, drawable->width);
(*colorfunc)(in, out, drawable->width, drawable->bpp, lut, cmap);
if (model)
{
out_length = out_offset + drawable->height * out_bpp;
if (x < (drawable->width - 1))
{
ps_ascii85(prn, out, out_length & ~3, 0);
out_offset = out_length & 3;
}
else
{
ps_ascii85(prn, out, out_length, 1);
out_offset = 0;
};
if (out_offset > 0)
memcpy(out, out + out_length - out_offset, out_offset);
}
else
ps_hex(prn, out, drawable->height * out_bpp);
ps_hex(prn, out, drawable->width * out_bpp);
};
}
else
{
in = g_malloc(drawable->width * drawable->bpp);
out = g_malloc(drawable->width * out_bpp + 3);
if (output_type == OUTPUT_GRAY)
fputs("/DeviceGray setcolorspace\n", prn);
else
fputs("/DeviceRGB setcolorspace\n", prn);
if (model == 0)
fprintf(prn, "/picture %d string def\n", drawable->width * out_bpp);
fputs("<<\n", prn);
fputs("\t/ImageType 1\n", prn);
fprintf(prn, "\t/Width %d\n", drawable->width);
fprintf(prn, "\t/Height %d\n", drawable->height);
fputs("\t/BitsPerComponent 8\n", prn);
if (output_type == OUTPUT_GRAY)
fprintf(prn, "%d %d 8 [%d 0 0 %d 0 %d] %s image\n",
drawable->width, drawable->height,
drawable->width, -drawable->height, drawable->height,
filters[model]);
fputs("\t/Decode [ 0 1 ]\n", prn);
else
fprintf(prn, "%d %d 8 [%d 0 0 %d 0 %d] %s false 3 colorimage\n",
drawable->width, drawable->height,
drawable->width, -drawable->height, drawable->height,
filters[model]);
fputs("\t/Decode [ 0 1 0 1 0 1 ]\n", prn);
fputs("\t/DataSource currentfile /ASCII85Decode filter\n", prn);
if ((drawable->width * 72 / out_width) < 100)
fputs("\t/Interpolate true\n", prn);
if (landscape)
fputs("\t/ImageMatrix [ 0 1 1 0 0 0 ]\n", prn);
else
fputs("\t/ImageMatrix [ 1 0 0 -1 0 1 ]\n", prn);
fputs(">>\n", prn);
fputs("image\n", prn);
for (y = 0, out_offset = 0; y < drawable->height; y ++)
{
@ -367,26 +667,21 @@ ps_print(FILE *prn, /* I - File to print to */
gimp_pixel_rgn_get_row(&rgn, in, 0, y, drawable->width);
(*colorfunc)(in, out + out_offset, drawable->width, drawable->bpp, lut, cmap);
if (model)
out_length = out_offset + drawable->width * out_bpp;
if (y < (drawable->height - 1))
{
out_length = out_offset + drawable->width * out_bpp;
if (y < (drawable->height - 1))
{
ps_ascii85(prn, out, out_length & ~3, 0);
out_offset = out_length & 3;
}
else
{
ps_ascii85(prn, out, out_length, 1);
out_offset = 0;
};
if (out_offset > 0)
memcpy(out, out + out_length - out_offset, out_offset);
ps_ascii85(prn, out, out_length & ~3, 0);
out_offset = out_length & 3;
}
else
ps_hex(prn, out, drawable->width * out_bpp);
{
ps_ascii85(prn, out, out_length, 1);
out_offset = 0;
};
if (out_offset > 0)
memcpy(out, out + out_length - out_offset, out_offset);
};
};
@ -409,9 +704,11 @@ ps_hex(FILE *prn, /* I - File to print to */
guchar *data, /* I - Data to print */
int length) /* I - Number of bytes to print */
{
int col; /* Current column */
static char *hex = "0123456789ABCDEF";
col = 0;
while (length > 0)
{
/*
@ -424,9 +721,14 @@ ps_hex(FILE *prn, /* I - File to print to */
data ++;
length --;
col = (col + 1) & 31;
if (col == 0)
putc('\n', prn);
};
putc('\n', prn);
if (col > 0)
putc('\n', prn);
}
@ -440,12 +742,11 @@ ps_ascii85(FILE *prn, /* I - File to print to */
int length, /* I - Number of bytes to print */
int last_line) /* I - Last line of raster data? */
{
int i; /* Looping var */
unsigned b; /* Binary data word */
unsigned char c[5]; /* ASCII85 encoded chars */
int col; /* Current column */
col = 0;
while (length > 3)
{
b = (((((data[0] << 8) | data[1]) << 8) | data[2]) << 8) | data[3];
@ -469,17 +770,13 @@ ps_ascii85(FILE *prn, /* I - File to print to */
data += 4;
length -= 4;
col = (col + 1) & 15;
if (col == 0 && length > 0)
putc('\n', prn);
};
if (last_line)
{
if (length > 0)
{
for (b = 0, col = length; col > 0; b = (b << 8) | data[0], data ++, col --);
for (b = 0, i = length; i > 0; b = (b << 8) | data[0], data ++, i --);
c[4] = (b % 85) + '!';
b /= 85;
@ -495,9 +792,93 @@ ps_ascii85(FILE *prn, /* I - File to print to */
};
fputs("~>\n", prn);
}
else
putc('\n', prn);
};
}
/*
* 'ppd_find()' - Find a control string with the specified name & parameters.
*/
static char * /* O - Control string */
ppd_find(char *ppd_file, /* I - Name of PPD file */
char *name, /* I - Name of parameter */
char *option, /* I - Value of parameter */
int *order) /* O - Order of the control string */
{
char line[1024], /* Line from file */
lname[255], /* Name from line */
loption[255], /* Value from line */
*opt; /* Current control string pointer */
static char value[32768]; /* Current control string value */
if (ppd_file == NULL || name == NULL || option == NULL)
return (NULL);
if (ps_ppd_file == NULL || strcmp(ps_ppd_file, ppd_file) != 0)
{
if (ps_ppd != NULL)
fclose(ps_ppd);
ps_ppd = fopen(ppd_file, "r");
if (ps_ppd == NULL)
ps_ppd_file = NULL;
else
ps_ppd_file = ppd_file;
};
if (ps_ppd == NULL)
return (NULL);
if (order != NULL)
*order = 1000;
rewind(ps_ppd);
while (fgets(line, sizeof(line), ps_ppd) != NULL)
{
if (line[0] != '*')
continue;
if (strncasecmp(line, "*OrderDependency:", 17) == 0 && order != NULL)
{
sscanf(line, "%*s%d", order);
continue;
}
else if (sscanf(line, "*%s %[^/:]", lname, loption) != 2)
continue;
if (strcasecmp(lname, name) == 0 &&
strcasecmp(loption, option) == 0)
{
opt = strchr(line, ':') + 1;
while (*opt == ' ' || *opt == '\t')
opt ++;
if (*opt != '\"')
continue;
strcpy(value, opt + 1);
if ((opt = strchr(value, '\"')) == NULL)
{
while (fgets(line, sizeof(line), ps_ppd) != NULL)
{
strcat(value, line);
if (strchr(line, '\"') != NULL)
{
strcpy(strchr(value, '\"'), "\n");
break;
};
};
}
else
*opt = '\0';
return (value);
};
};
return (NULL);
}

View File

@ -21,73 +21,30 @@
*
* Contents:
*
* dither_black() - Dither grayscale pixels to black.
* dither_cmyk() - Dither RGB pixels to cyan, magenta, yellow, and black.
* gray_to_gray() - Convert grayscale image data to grayscale.
* indexed_to_gray() - Convert indexed image data to grayscale.
* indexed_to_rgb() - Convert indexed image data to RGB.
* media_width() - Get the addressable width of the page.
* media_height() - Get the addressable height of the page.
* rgb_to_gray() - Convert RGB image data to grayscale.
* rgb_to_rgb() - Convert RGB image data to RGB.
* dither_black() - Dither grayscale pixels to black.
* dither_cmyk() - Dither RGB pixels to cyan, magenta, yellow, and
* black.
* gray_to_gray() - Convert grayscale image data to grayscale.
* indexed_to_gray() - Convert indexed image data to grayscale.
* indexed_to_rgb() - Convert indexed image data to RGB.
* rgb_to_gray() - Convert RGB image data to grayscale.
* rgb_to_rgb() - Convert RGB image data to RGB.
* default_media_size() - Return the size of a default page size.
*
* Revision History:
*
* $Log$
* Revision 1.7 1998/04/13 05:43:15 yosh
* Have fun recompiling gimp everyone. It's the great FSF address change!
*
* -Yosh
*
* Revision 1.6 1998/04/11 05:07:46 yosh
* * app/app_procs.c: fixed up idle handler for file open (look like testgtk
* idle demo)
*
* * app/colomaps.c: fixup for visual test and use of gdk_color_alloc for some
* fixed colors (from Owen Taylor)
*
* * app/errors.h
* * app/errors.c
* * app/main.c
* * libgimp/gimp.c: redid the signal handlers so we only get a debug prompt on
* SIGSEGV, SIGBUS, and SIGFPE.
*
* * applied gimp-jbuhler-980408-0 and gimp-joke-980409-0 (warning fixups)
*
* * applied gimp-monnaux-980409-0 for configurable plugin path for multiarch
* setups
*
* -Yosh
*
* Revision 1.5 1998/04/07 03:41:15 yosh
* configure.in: fix for $srcdir != $builddir for data. Tightened check for
* random() and add -lucb on systems that need it. Fix for xdelta.h check. Find
* xemacs as well as emacs. Properly define settings for print plugin.
*
* app/Makefile.am: ditch -DNDEBUG, since nothing uses it
*
* flame: properly handle random() and friends
*
* pnm: workaround for systems with old sprintfs
*
* print, sgi: fold back in portability fixes
*
* threshold_alpha: properly get params in non-interactive mode
*
* bmp: updated and merged in
*
* -Yosh
*
* Revision 1.4 1998/04/01 22:14:47 neo
* Added checks for print spoolers to configure.in as suggested by Michael
* Sweet. The print plug-in still needs some changes to Makefile.am to make
* make use of this.
*
* Updated print and sgi plug-ins to version on the registry.
* Revision 1.8 1998/05/11 19:51:25 neo
* Updated print plug-in to version 2.0
*
*
* --Sven
*
* Revision 1.12 1998/05/08 19:20:50 mike
* Updated CMYK generation code to use new method.
* Updated dithering algorithm (slightly more uniform now, less speckling)
* Added default media size function.
*
* Revision 1.11 1998/03/01 18:03:27 mike
* Whoops - need to add 255 - alpha to the output values (transparent to white
* and not transparent to black...)
@ -152,15 +109,16 @@
/*
* Error buffer for dither functions. This needs to be at least 11xMAXDPI
* Error buffer for dither functions. This needs to be at least 14xMAXDPI
* (currently 720) to avoid problems...
*/
int error[2][4][11*720+4] =
int error[2][4][14*720+4] =
{
{ { 0 }, { 0 }, { 0 } , { 0 } },
{ { 0 }, { 0 }, { 0 } , { 0 } }
};
};
/*
* 'dither_black()' - Dither grayscale pixels to black.
@ -203,7 +161,7 @@ dither_black(guchar *gray, /* I - Grayscale pixels */
x < dst_width;
x ++, kerror0 ++, kerror1 ++)
{
k = 255 - *gray + ditherk / 4;
k = 255 - *gray + ditherk / 8;
if (k > 127)
{
*kptr |= bit;
@ -212,13 +170,13 @@ dither_black(guchar *gray, /* I - Grayscale pixels */
if (ditherbit & bit)
{
kerror1[0] = 3 * k;
ditherk = kerror0[1] + k;
kerror1[0] = 5 * k;
ditherk = kerror0[1] + 3 * k;
}
else
{
kerror1[0] = k;
ditherk = kerror0[1] + 3 * k;
kerror1[0] = 3 * k;
ditherk = kerror0[1] + 5 * k;
};
if (bit == 1)
@ -349,12 +307,12 @@ dither_cmyk(guchar *rgb, /* I - RGB pixels */
* CMY as necessary to give better blues, greens, and reds... :)
*/
c = (255 - (rgb[1] + rgb[2]) / 8) * (c - k) / divk;
m = (255 - (rgb[0] + rgb[2]) / 8) * (m - k) / divk;
y = (255 - (rgb[0] + rgb[1]) / 8) * (y - k) / divk;
c = (255 - rgb[1] / 4) * (c - k) / divk;
m = (255 - rgb[2] / 4) * (m - k) / divk;
y = (255 - rgb[0] / 4) * (y - k) / divk;
};
k += ditherk / 4;
k += ditherk / 8;
if (k > 127)
{
*kptr |= bit;
@ -363,13 +321,13 @@ dither_cmyk(guchar *rgb, /* I - RGB pixels */
if (ditherbit & bit)
{
kerror1[0] = 3 * k;
ditherk = kerror0[1] + k;
kerror1[0] = 5 * k;
ditherk = kerror0[1] + 3 * k;
}
else
{
kerror1[0] = k;
ditherk = kerror0[1] + 3 * k;
kerror1[0] = 3 * k;
ditherk = kerror0[1] + 5 * k;
};
if (bit == 1)
@ -382,12 +340,12 @@ dither_cmyk(guchar *rgb, /* I - RGB pixels */
* better reds, greens, and blues...
*/
c = (255 - (rgb[1] + rgb[2]) / 8) * (c - k) / 255 + k;
m = (255 - (rgb[0] + rgb[2]) / 8) * (m - k) / 255 + k;
y = (255 - (rgb[0] + rgb[1]) / 8) * (y - k) / 255 + k;
c = (255 - rgb[1] / 4) * (c - k) / 255 + k;
m = (255 - rgb[2] / 4) * (m - k) / 255 + k;
y = (255 - rgb[0] / 4) * (y - k) / 255 + k;
};
c += ditherc / 4;
c += ditherc / 8;
if (c > 127)
{
*cptr |= bit;
@ -396,16 +354,16 @@ dither_cmyk(guchar *rgb, /* I - RGB pixels */
if (ditherbit & bit)
{
cerror1[0] = 3 * c;
ditherc = cerror0[1] + c;
cerror1[0] = 5 * c;
ditherc = cerror0[1] + 3 * c;
}
else
{
cerror1[0] = c;
ditherc = cerror0[1] + 3 * c;
cerror1[0] = 3 * c;
ditherc = cerror0[1] + 5 * c;
};
m += ditherm / 4;
m += ditherm / 8;
if (m > 127)
{
*mptr |= bit;
@ -414,16 +372,16 @@ dither_cmyk(guchar *rgb, /* I - RGB pixels */
if (ditherbit & bit)
{
merror1[0] = 3 * m;
ditherm = merror0[1] + m;
merror1[0] = 5 * m;
ditherm = merror0[1] + 3 * m;
}
else
{
merror1[0] = m;
ditherm = merror0[1] + 3 * m;
merror1[0] = 3 * m;
ditherm = merror0[1] + 5 * m;
};
y += dithery / 4;
y += dithery / 8;
if (y > 127)
{
*yptr |= bit;
@ -432,13 +390,13 @@ dither_cmyk(guchar *rgb, /* I - RGB pixels */
if (ditherbit & bit)
{
yerror1[0] = 3 * y;
dithery = yerror0[1] + y;
yerror1[0] = 5 * y;
dithery = yerror0[1] + 3 * y;
}
else
{
yerror1[0] = y;
dithery = yerror0[1] + 3 * y;
yerror1[0] = 3 * y;
dithery = yerror0[1] + 5 * y;
};
if (bit == 1)
@ -606,70 +564,6 @@ indexed_to_rgb(guchar *indexed, /* I - Indexed pixels */
}
/*
* 'media_width()' - Get the addressable width of the page.
*
* This function assumes a standard left/right margin of 0.25".
*/
int
media_width(int media_size, /* I - Media size code */
int dpi) /* I - Resolution in dots-per-inch */
{
switch (media_size)
{
case MEDIA_LETTER :
case MEDIA_LEGAL :
return (8 * dpi);
case MEDIA_TABLOID :
return ((int)(10.5 * dpi + 0.5));
case MEDIA_A4 :
return ((int)(7.77 * dpi + 0.5));
case MEDIA_A3 :
return ((int)(11.09 * dpi + 0.5));
default :
return (0);
};
}
/*
* 'media_height()' - Get the addressable height of the page.
*
* This function assumes a standard top/bottom margin of 0.5".
*/
int
media_height(int media_size, /* I - Media size code */
int dpi) /* I - Resolution in dots-per-inch */
{
switch (media_size)
{
case MEDIA_LETTER :
return (10 * dpi);
case MEDIA_LEGAL :
return (13 * dpi);
case MEDIA_TABLOID :
return (16 * dpi);
case MEDIA_A4 :
return ((int)(10.69 * dpi + 0.5));
case MEDIA_A3 :
return ((int)(15.54 * dpi + 0.5));
default :
return (0);
};
}
/*
* 'rgb_to_gray()' - Convert RGB image data to grayscale.
*/
@ -761,6 +655,55 @@ rgb_to_rgb(guchar *rgbin, /* I - RGB pixels */
}
/*
* 'default_media_size()' - Return the size of a default page size.
*/
void
default_media_size(int model, /* I - Printer model */
char *ppd_file, /* I - PPD file (not used) */
char *media_size, /* I - Media size */
int *width, /* O - Width in points */
int *length) /* O - Length in points */
{
if (strcmp(media_size, "Letter") == 0)
{
*width = 612;
*length = 792;
}
else if (strcmp(media_size, "Legal") == 0)
{
*width = 612;
*length = 1008;
}
else if (strcmp(media_size, "Tabloid") == 0)
{
*width = 792;
*length = 1214;
}
else if (strcmp(media_size, "12x18") == 0)
{
*width = 864;
*length = 1296;
}
else if (strcmp(media_size, "A4") == 0)
{
*width = 595;
*length = 842;
}
else if (strcmp(media_size, "A3") == 0)
{
*width = 842;
*length = 1191;
}
else
{
*width = 0;
*length = 0;
};
}
/*
* End of "$Id$".
*/

File diff suppressed because it is too large Load Diff

View File

@ -22,21 +22,16 @@
* Revision History:
*
* $Log$
* Revision 1.4 1998/04/13 05:43:17 yosh
* Have fun recompiling gimp everyone. It's the great FSF address change!
*
* -Yosh
*
* Revision 1.3 1998/04/01 22:14:49 neo
* Added checks for print spoolers to configure.in as suggested by Michael
* Sweet. The print plug-in still needs some changes to Makefile.am to make
* make use of this.
*
* Updated print and sgi plug-ins to version on the registry.
* Revision 1.5 1998/05/11 19:53:31 neo
* Updated print plug-in to version 2.0
*
*
* --Sven
*
* Revision 1.11 1998/05/08 19:20:50 mike
* Updated for new driver interface.
* Added media size, imageable area, and parameter functions.
*
* Revision 1.10 1998/03/01 17:20:48 mike
* Updated version number & date.
*
@ -96,7 +91,7 @@
* Constants...
*/
#define PLUG_IN_VERSION "1.4 - 1 March 1998"
#define PLUG_IN_VERSION "2.0 - 8 May 1998"
#define PLUG_IN_NAME "Print"
#define MEDIA_LETTER 0 /* 8.5x11" a.k.a. "A" size */
@ -126,21 +121,25 @@ typedef struct
{
char *long_name, /* Long name for UI */
*short_name; /* Short name for printrc file */
int xdpi, /* X resolution */
ydpi, /* Y resolution */
large_sizes, /* TRUE if supports large sizes */
color, /* TRUE if supports color */
int color, /* TRUE if supports color */
model; /* Model number */
float gamma, /* Gamma correction */
density; /* Ink "density" or black level */
void (*print)(FILE *prn, GDrawable *drawable, int media_size,
int xdpi, int ydpi, int output_type, int model,
guchar *lut, guchar *cmap, int orientation,
int scaling, int left, int top);
/* Print function */
char **(*parameters)(int model, char *ppd_file, char *name, int *count);
/* Parameter names */
void (*media_size)(int model, char *ppd_file, char *media_size,
int *width, int *length);
void (*imageable_area)(int model, char *ppd_file, char *media_size,
int *left, int *right, int *bottom, int *top);
void (*print)(int model, char *ppd_file, char *resolution,
char *media_size, char *media_type, char *media_source,
int output_type, int orientation, float scaling, int left,
int top, int copies, FILE *prn, GDrawable *drawable,
guchar *lut, guchar *cmap); /* Print function */
} printer_t;
typedef void (*convert_t)(guchar *in, guchar *out, int width, int bpp, guchar *lut, guchar *cmap);
typedef void (*convert_t)(guchar *in, guchar *out, int width, int bpp,
guchar *lut, guchar *cmap);
/*
@ -153,14 +152,43 @@ extern void dither_cmyk(guchar *, int, int, int, unsigned char *,
extern void gray_to_gray(guchar *, guchar *, int, int, guchar *, guchar *);
extern void indexed_to_gray(guchar *, guchar *, int, int, guchar *, guchar *);
extern void indexed_to_rgb(guchar *, guchar *, int, int, guchar *, guchar *);
extern int media_width(int, int);
extern int media_height(int, int);
extern void rgb_to_gray(guchar *, guchar *, int, int, guchar *, guchar *);
extern void rgb_to_rgb(guchar *, guchar *, int, int, guchar *, guchar *);
extern void escp2_print(FILE *, GDrawable *, int, int, int, int, int, guchar *, guchar *, int, int, int, int);
extern void pcl_print(FILE *, GDrawable *, int, int, int, int, int, guchar *, guchar *, int, int, int, int);
extern void ps_print(FILE *, GDrawable *, int, int, int, int, int, guchar *, guchar *, int, int, int, int);
extern void default_media_size(int model, char *ppd_file, char *media_size,
int *width, int *length);
extern char **escp2_parameters(int model, char *ppd_file, char *name,
int *count);
extern void escp2_imageable_area(int model, char *ppd_file, char *media_size,
int *left, int *right, int *bottom, int *top);
extern void escp2_print(int model, char *ppd_file, char *resolution,
char *media_size, char *media_type, char *media_source,
int output_type, int orientation, float scaling,
int left, int top, int copies, FILE *prn,
GDrawable *drawable, guchar *lut, guchar *cmap);
extern char **pcl_parameters(int model, char *ppd_file, char *name,
int *count);
extern void pcl_imageable_area(int model, char *ppd_file, char *media_size,
int *left, int *right, int *bottom, int *top);
extern void pcl_print(int model, char *ppd_file, char *resolution,
char *media_size, char *media_type, char *media_source,
int output_type, int orientation, float scaling,
int left, int top, int copies, FILE *prn,
GDrawable *drawable, guchar *lut, guchar *cmap);
extern char **ps_parameters(int model, char *ppd_file, char *name,
int *count);
extern void ps_media_size(int model, char *ppd_file, char *media_size,
int *width, int *length);
extern void ps_imageable_area(int model, char *ppd_file, char *media_size,
int *left, int *right, int *bottom, int *top);
extern void ps_print(int model, char *ppd_file, char *resolution,
char *media_size, char *media_type, char *media_source,
int output_type, int orientation, float scaling,
int left, int top, int copies, FILE *prn,
GDrawable *drawable, guchar *lut, guchar *cmap);
/*