17 #include <cups/cups.h> 20 #include <cups/raster.h> 21 #include <cups/backend.h> 38 #define VERSION "<unknown>" 45 fputs(
"DEBUG: cab - Job cancelled ... \n", stderr);
55 const char* sFilename = (
char*) getenv(
"PPD");
59 return CUPS_BACKEND_FAILED;
61 if(!(ppd = ppdOpenFile(sFilename)))
62 return CUPS_BACKEND_FAILED;
68 conflicts = cupsMarkOptions(ppd, cups_opts, cups_opt);
72 fprintf(stderr,
"ERROR: Driver conflicts occurred: %d conflicts ...\n", conflicts);
73 fprintf(stderr,
"ERROR: Report this, please. Thank you!\n");
76 return CUPS_BACKEND_FAILED;
82 return CUPS_BACKEND_OK;
91 static void print_page(cups_page_header2_t *header,
int image_offset_pix,
int page)
100 image_offset_mm = (int)(25.4 / (
double)header->HWResolution[0] * (double)image_offset_pix);
103 printf(
"end-of-data\r\n");
105 if(page <= 1 || !replace)
150 printf(
"I:Field1; 0,%d,0;cups\r\n", image_offset_mm);
176 printf(
"R Field1;cups\r\n");
180 if (header->NumCopies >= 1)
181 printf(
"A%u\r\n", header->NumCopies);
195 for(i = 0; i < size; i++)
204 static void print_raster_image(cups_raster_t *ras, cups_page_header2_t *header,
int *image_offset_pix)
209 int wwidth, y, front, height;
210 int image_opimization;
216 image_opimization=
TRUE;
218 *image_offset_pix = 0;
220 image->
breite = (short) header->cupsWidth;
221 image->
hoehe = (
short) header->cupsHeight;
222 wwidth = (int) ((header->cupsBytesPerLine + 1) >> 1);
223 img_buffer = malloc(header->cupsHeight * wwidth * 2);
224 ptr = image->
inh = img_buffer;
228 for (y = 0; y < header->cupsHeight && !
cancelled; y++)
231 if (cupsRasterReadPixels(ras, (
unsigned char *) ptr, header->cupsBytesPerLine) < 1)
234 if(front < 0 && image_opimization)
245 height = y - front + 1;
253 printf(
"d IMG;cups\r");
259 image->
hoehe = height;
260 image->
inh += front * wwidth;
263 *image_offset_pix = front;
279 int main(
int argc,
char *argv[])
282 cups_page_header2_t header;
283 cups_option_t *options;
284 int rv, fd, num_options, page;
285 int image_offset_pix;
287 signal(SIGPIPE, SIG_IGN);
293 rv = CUPS_BACKEND_OK;
296 fputs(
"DEBUG: cab - Starting rastertocab ...\n", stderr);
301 setbuf(stderr, NULL);
303 if(argc == 2 && (strcmp(argv[1],
"--version") == 0 ))
305 fprintf(stderr,
"%s - version %s\n", argv[0],
VERSION);
310 if ((fd = open(argv[6], O_RDONLY)) < 0)
312 perror(
"ERROR: rastertocab - Unable to open raster file - ");
313 return CUPS_BACKEND_FAILED;
318 fprintf(stderr,
"Usage: %s job-id user title copies options [file]\n", argv[0]);
319 return CUPS_BACKEND_FAILED;
324 num_options = cupsParseOptions(argv[5], 0, &options);
327 dump_cups_options(num_options, options);
331 ras = cupsRasterOpen(fd, CUPS_RASTER_READ);
334 if((rv =
setup_printer(num_options, options)) != CUPS_BACKEND_OK)
338 while (cupsRasterReadHeader2(ras, &header))
348 rv = CUPS_BACKEND_CANCEL;
354 fprintf(stderr,
"INFO: rastertocab - PAGE: %d\n", ++page);
362 cupsRasterClose(ras);
370 fputs(
"ERROR: rastertocab - No pages found!\n", stderr);
371 return CUPS_BACKEND_FAILED;
373 fputs(
"DEBUG: rastertocab - Ready to print.\n", stderr);
static void print_raster_image(cups_raster_t *ras, cups_page_header2_t *header, int *image_offset_pix)
void sigterm_callback(int sig)
int get_p_option_cmd(char *command)
int get_preprint_opt(char *command)
Assembles the command for the per-print option (C-Command)
void write_img_header(FILE *oFile, unsigned int xdim, unsigned int ydim)
Creates and writes the image header.
int get_o_option_cmd(char *command)
int isPrePrintPerforate()
Return, wether the pre-print option is set to 'Perforate'.
void get_s_option_cmd(char *command, cups_page_header2_t *header, double printwidth)
double get_printing_width(int modelnumber)
#define OPT_CAB_FORMFEED_MODE
static int setup_printer(int cups_opts, cups_option_t *cups_opt)
void dump_pg_header(cups_page_header2_t *header)
Dumps the CUPS page header structure.
void get_perfo_depth(char *command)
Assembles the command for the perforation depth (C-Command)
static int line_is_empty(short *ptr, int size)
int isPerfoCutterInstalled()
Return, wether a perforation cutter is installed.
int get_immediate_cmd(char *command, const char *type, const char value)
int get_d_option_cmd(char *command)
int isRibbonSaveSelected()
Return, wether the RibbonSave is active.
#define CUSTOM_JSCRIPT_PARAM_MAX
short * inh
pointer to bitmap
int get_option_image_optimization()
int get_custom_jscript1_cmd(char *command, int page)
void handleMarkedPPDOptions(ppd_file_t *ppd)
int get_custom_jscript3_cmd(char *command)
#define OPT_CAB_PAUSE_MODE
short breite
width in pixels (16 pixel steps!)
Internal struct to store informations for images.
void get_perfo_offset(char *command)
Assembles the command for the perforation offset (C-Command)
void write_img(pictogram_t *pp, FILE *fp)
int get_c_option_cmd(char *command)
int main(int argc, char *argv[])
short hoehe
height in pixels
static void print_page(cups_page_header2_t *header, int image_offset_pix, int page)
void get_h_option_cmd(char *command)