Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,22 @@ pkgfilter_PROGRAMS += \
endif

check_PROGRAMS = \
test-external
test-external \
test-rastertopclx-format-string \
test-rastertoescpx-page-size

TESTS = \
test-rastertopclx-format-string \
test-rastertoescpx-page-size

# Not reliable bash script
#TESTS += filter/test.sh

EXTRA_DIST += \
$(genfilterscripts) \
filter/test.sh
filter/test.sh \
filter/test-rastertopclx-format-string.c \
filter/test-rastertoescpx-page-size.c

bannertopdf_SOURCES = \
filter/bannertopdf.c
Expand Down Expand Up @@ -561,6 +569,31 @@ test_external_LDADD = \
$(LIBPPD_LIBS) \
$(CUPS_LIBS)

test_rastertopclx_format_string_SOURCES = \
filter/test-rastertopclx-format-string.c \
filter/pcl-common.c
test_rastertopclx_format_string_CFLAGS = \
$(CUPS_CFLAGS) \
$(LIBPNG_CFLAGS) \
$(LIBCUPSFILTERS_CFLAGS) \
$(LIBPPD_CFLAGS)
test_rastertopclx_format_string_LDADD = \
$(CUPS_LIBS) \
$(LIBPNG_LIBS) \
$(LIBCUPSFILTERS_LIBS) \
$(LIBPPD_LIBS)

test_rastertoescpx_page_size_SOURCES = \
filter/test-rastertoescpx-page-size.c
test_rastertoescpx_page_size_CFLAGS = \
$(CUPS_CFLAGS) \
$(LIBCUPSFILTERS_CFLAGS) \
$(LIBPPD_CFLAGS)
test_rastertoescpx_page_size_LDADD = \
$(CUPS_LIBS) \
$(LIBCUPSFILTERS_LIBS) \
$(LIBPPD_LIBS)

# =========
# Man pages
# =========
Expand Down
89 changes: 89 additions & 0 deletions filter/pcl-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// Contents:
//
// pcl_set_media_size() - Set media size using the page size command.
// pcl_write() - Write a PCL command string, performing safe
// page-count substitutions as needed.
// pjl_write() - Write a PJL command string, performing
// substitutions as needed.
//
Expand All @@ -22,6 +24,7 @@
#include <ppd/ppd.h>
#include <ppd/ppd-filter.h>
#include "pcl-common.h"
#include <ctype.h>
#include <math.h>


Expand Down Expand Up @@ -192,6 +195,92 @@ pcl_set_media_size(ppd_file_t *ppd, // I - PPD file
}


//
// 'pcl_write()' - Write a PCL command string, performing safe page-count
// substitutions as needed.
//

void
pcl_write(const char *format, // I - Format string
int page_count) // I - Page count
{
const char *spec; // Start of format specifier
int width; // Field width
int zero_pad; // Zero-pad output?
int have_width; // Width was specified?


if (!format)
return;

while (*format)
{
if (*format != '%')
{
putchar(*format++);
continue;
}

format ++;

if (!*format)
{
putchar('%');
break;
}

if (*format == '%')
{
putchar('%');
format ++;
continue;
}

spec = format;
width = 0;
zero_pad = 0;
have_width = 0;

if (*format == '0')
{
zero_pad = 1;
format ++;
}

while (isdigit((unsigned char)*format))
{
have_width = 1;
width = width * 10 + (*format - '0');
format ++;
}

// Only integer page-count substitutions are supported here. Emit any
// other format sequence literally instead of interpreting PPD data as a
// general printf format string.
if (*format == 'd' || *format == 'i' || *format == 'u')
{
if (zero_pad && have_width)
printf("%0*d", width, page_count);
else if (have_width)
printf("%*d", width, page_count);
else
printf("%d", page_count);

format ++;
continue;
}

putchar('%');

while (spec < format)
putchar(*spec++);

if (*format)
putchar(*format++);
}
}


//
// 'pjl_write()' - Write a PJL command string, performing substitutions as
// needed.
Expand Down
2 changes: 1 addition & 1 deletion filter/pcl-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
printf("@PJL ENTER LANGUAGE=%s\r\n", (lang))

extern void pcl_set_media_size(ppd_file_t *ppd, float width, float length);
extern void pcl_write(const char *format, int page_count);
extern void pjl_write(const char *format,
const char *value, int job_id,
const char *user, const char *title,
int num_options, cups_option_t *options);

28 changes: 26 additions & 2 deletions filter/rastertoescpx.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void Setup(ppd_file_t *);
void StartPage(ppd_file_t *, cups_page_header2_t *);
void EndPage(ppd_file_t *, cups_page_header2_t *);
void Shutdown(ppd_file_t *);
static int GetPrinterTop(ppd_file_t *, cups_page_header2_t *);

void AddBand(cups_weave_t *band);
void CancelJob(int sig);
Expand Down Expand Up @@ -123,6 +124,30 @@ Setup(ppd_file_t *ppd) // I - PPD file
}


//
// 'GetPrinterTop()' - Get the selected page size's top margin in device
// units.
//

static int
GetPrinterTop(ppd_file_t *ppd, // I - PPD file
cups_page_header2_t *header) // I - Page header
{
ppd_size_t *size; // Selected page size


if (!ppd || !header)
return (0);

// Use the currently selected/default PageSize instead of assuming a
// particular entry exists in ppd->sizes[].
if ((size = ppdPageSize(ppd, NULL)) == NULL)
return (0);

return ((int)((size->length - size->top) * header->HWResolution[1] / 72.0));
}


//
// 'StartPage()' - Start a page of graphics.
//
Expand Down Expand Up @@ -729,8 +754,7 @@ StartPage(ppd_file_t *ppd, // I - PPD file
// Set the top and bottom margins...
//

PrinterTop = (int)((ppd->sizes[1].length - ppd->sizes[1].top) *
header->HWResolution[1] / 72.0);
PrinterTop = GetPrinterTop(ppd, header);

if (ppd->model_number & ESCP_EXT_MARGINS)
{
Expand Down
4 changes: 3 additions & 1 deletion filter/rastertopclx.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,9 @@ Shutdown(ppd_file_t *ppd, // I - PPD file
//

putchar(0x1b);
printf(attr->value, Page);
// EndJob comes from the PPD, so only restricted page-count formatting
// is allowed here.
pcl_write(attr->value, Page);
}
else
{
Expand Down
Loading