From 1fed7ba0a636aa9d29f931f1de33f4be6e04ccd9 Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Mon, 11 Apr 2022 13:25:38 +0200 Subject: [PATCH] libcupsfilters: Do actual commit for the previous commit message Normally, GIT does not accept the command "git commit" without specifying files or "-a" for all modified files. Strangely enough, it accepts it when files got deleted and then it only commits the deletions. So the previous commit (f89c3136cb8) only contains the deletions of the cupsfilters/image-sgi.h and cupsfilters/image-sgilib.c and not the actual changes. Now here we go with the changes. --- Makefile.am | 2 - cupsfilters/bannertopdf.c | 12 +- cupsfilters/colord.c | 2 +- cupsfilters/colormanager.c | 34 +- cupsfilters/filter.c | 10 +- cupsfilters/ghostscript.c | 10 +- cupsfilters/ieee1284.c | 30 +- cupsfilters/image-colorspace.c | 90 ++-- cupsfilters/image-sgi.c | 354 +++++++++++++- cupsfilters/image.c | 66 +-- cupsfilters/imagetopdf.c | 327 ++++++------- cupsfilters/imagetops-pstops.c | 4 +- cupsfilters/imagetoraster.c | 84 ++-- cupsfilters/ipp.c | 2 +- cupsfilters/mupdftopwg.c | 2 +- cupsfilters/pclmtoraster.cxx | 102 ++-- cupsfilters/pdf.cxx | 8 +- cupsfilters/pdftopdf/intervalset.cc | 18 +- cupsfilters/pdftopdf/intervalset.h | 16 +- cupsfilters/pdftopdf/nup.cc | 54 +-- cupsfilters/pdftopdf/nup.h | 81 ++-- cupsfilters/pdftopdf/pdftopdf.cc | 180 +++---- cupsfilters/pdftopdf/pdftopdf.h | 18 +- cupsfilters/pdftopdf/pdftopdf_jcl.cc | 46 +- cupsfilters/pdftopdf/pdftopdf_jcl.h | 17 +- cupsfilters/pdftopdf/pdftopdf_processor.cc | 148 +++--- cupsfilters/pdftopdf/pdftopdf_processor.h | 150 +++--- cupsfilters/pdftopdf/pptypes.cc | 36 +- cupsfilters/pdftopdf/pptypes.h | 38 +- cupsfilters/pdftopdf/qpdf_cm.cc | 8 +- cupsfilters/pdftopdf/qpdf_cm.h | 12 +- cupsfilters/pdftopdf/qpdf_pdftopdf.cc | 38 +- cupsfilters/pdftopdf/qpdf_pdftopdf.h | 36 +- .../pdftopdf/qpdf_pdftopdf_processor.cc | 232 ++++----- .../pdftopdf/qpdf_pdftopdf_processor.h | 60 +-- cupsfilters/pdftopdf/qpdf_tools.cc | 20 +- cupsfilters/pdftopdf/qpdf_tools.h | 18 +- cupsfilters/pdftopdf/qpdf_xobject.cc | 10 +- cupsfilters/pdftopdf/qpdf_xobject.h | 6 +- cupsfilters/pdftops.c | 9 +- cupsfilters/pdftoraster.cxx | 270 +++++------ cupsfilters/pdfutils.c | 18 - cupsfilters/pwgtoraster.c | 250 +++++----- cupsfilters/raster.c | 2 +- cupsfilters/rastertopdf.cpp | 261 +++++----- cupsfilters/rastertops.c | 56 +-- cupsfilters/rastertopwg.c | 3 +- cupsfilters/texttopdf.c | 445 +++++++++--------- 48 files changed, 1973 insertions(+), 1722 deletions(-) diff --git a/Makefile.am b/Makefile.am index 35f8cc7fb..e9f54856b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -459,8 +459,6 @@ libcupsfilters_la_SOURCES = \ cupsfilters/image-pnm.c \ cupsfilters/image-private.h \ cupsfilters/image-sgi.c \ - cupsfilters/image-sgi.h \ - cupsfilters/image-sgilib.c \ cupsfilters/image-sun.c \ cupsfilters/image-tiff.c \ cupsfilters/image-zoom.c \ diff --git a/cupsfilters/bannertopdf.c b/cupsfilters/bannertopdf.c index ae7b7e1ae..e8ebde2fa 100644 --- a/cupsfilters/bannertopdf.c +++ b/cupsfilters/bannertopdf.c @@ -43,7 +43,7 @@ #include "filter.h" #include "pdf.h" -enum banner_info +typedef enum banner_info_e { INFO_IMAGEABLE_AREA = 1, INFO_JOB_BILLING = 1 << 1, @@ -63,16 +63,16 @@ enum banner_info INFO_PRINTER_NAME = 1 << 15, INFO_TIME_AT_CREATION = 1 << 16, INFO_TIME_AT_PROCESSING = 1 << 17 -}; +} banner_info_t; -typedef struct +typedef struct banner_s { char *template_file; char *header, *footer; unsigned infos; } banner_t; -void banner_free(banner_t *banner) +static void banner_free(banner_t *banner) { if (banner) { @@ -180,7 +180,7 @@ static char *template_path(const char *name, const char *datadir) return result; } -banner_t *banner_new_from_file(const char *filename, int *num_options, +static banner_t *banner_new_from_file(const char *filename, int *num_options, cups_option_t **options, const char *datadir, cf_logfunc_t log, void *ld) { @@ -561,7 +561,7 @@ static cf_opt_t *add_opt(cf_opt_t *in_opt, const char *key, const char *val) * * Create PDF form's field names according above. */ -cf_opt_t *get_known_opts( +static cf_opt_t *get_known_opts( cf_filter_data_t *data, const char *jobid, const char *user, diff --git a/cupsfilters/colord.c b/cupsfilters/colord.c index c370bb40b..1cb2ad85b 100644 --- a/cupsfilters/colord.c +++ b/cupsfilters/colord.c @@ -374,7 +374,7 @@ out: return filename; } -int +static int get_profile_inhibitors ( cf_filter_data_t *data, DBusConnection *con, const char *object_path) { diff --git a/cupsfilters/colormanager.c b/cupsfilters/colormanager.c index 29a5b0cfa..f59926315 100644 --- a/cupsfilters/colormanager.c +++ b/cupsfilters/colormanager.c @@ -35,12 +35,12 @@ MIT Open Source License - http://www.opensource.org/ /* Private function prototypes */ -static int _get_colord_printer_cm_status (cf_filter_data_t *data); -static char *_get_colord_printer_id (cf_filter_data_t *data); -static int _get_colord_profile (cf_filter_data_t *data, +static int get_colord_printer_cm_status (cf_filter_data_t *data); +static char *get_colord_printer_id (cf_filter_data_t *data); +static int get_colord_profile (cf_filter_data_t *data, char **profile, ppd_file_t *ppd); -static char *_get_ppd_icc_fallback (cf_filter_data_t *data, +static char *get_ppd_icc_fallback (cf_filter_data_t *data, ppd_file_t *ppd, char **qualifier); @@ -75,7 +75,7 @@ cfCmIsPrinterCmDisabled(cf_filter_data_t *data) /* Request color management status from colord */ - is_cm_off = _get_colord_printer_cm_status(data); + is_cm_off = get_colord_printer_cm_status(data); if (is_cm_off) if(log) log(ld, CF_LOGLEVEL_DEBUG, @@ -98,7 +98,7 @@ cfCmGetPrinterIccProfile(cf_filter_data_t *data, /* Request a profile from colord */ - profile_set = _get_colord_profile(data, icc_profile, ppd); + profile_set = get_colord_profile(data, icc_profile, ppd); if(log) log(ld, CF_LOGLEVEL_DEBUG, "Color Manager: ICC Profile: %s", *icc_profile ? *icc_profile : "None"); @@ -185,8 +185,8 @@ double *cfCmBlackPointDefault(void) */ -char * -_get_colord_printer_id( cf_filter_data_t *data) +static char * +get_colord_printer_id( cf_filter_data_t *data) { cf_logfunc_t log = data->logfunc; @@ -206,8 +206,8 @@ _get_colord_printer_id( cf_filter_data_t *data) } -int -_get_colord_printer_cm_status( cf_filter_data_t *data) +static int +get_colord_printer_cm_status( cf_filter_data_t *data) { cf_logfunc_t log = data->logfunc; @@ -226,7 +226,7 @@ _get_colord_printer_cm_status( cf_filter_data_t *data) /* Check if device is inhibited/disabled in colord */ - printer_id = _get_colord_printer_id(data); + printer_id = get_colord_printer_id(data); is_printer_cm_disabled = cfColordGetInhibitForDeviceID (data, printer_id); if (printer_id != NULL) @@ -236,8 +236,8 @@ _get_colord_printer_cm_status( cf_filter_data_t *data) } -int -_get_colord_profile(cf_filter_data_t *data, +static int +get_colord_profile(cf_filter_data_t *data, char **profile, /* Requested icc profile path */ ppd_file_t *ppd) /* PPD file */ { @@ -261,7 +261,7 @@ _get_colord_profile(cf_filter_data_t *data, qualifier = cfColordGetQualifierForPPD(ppd); if (qualifier != NULL) { - printer_id = _get_colord_printer_id(data); + printer_id = get_colord_printer_id(data); /* Get profile from colord using qualifiers */ icc_profile = cfColordGetProfileForDeviceID (data, (const char *)printer_id, @@ -272,7 +272,7 @@ _get_colord_profile(cf_filter_data_t *data, is_profile_set = 1; else if (ppd) { /* Get optional fallback PPD profile */ - icc_profile = _get_ppd_icc_fallback(data, ppd, qualifier); + icc_profile = get_ppd_icc_fallback(data, ppd, qualifier); if (icc_profile) is_profile_set = 1; } @@ -305,8 +305,8 @@ _get_colord_profile(cf_filter_data_t *data, #endif /* From gstoraster */ -char * -_get_ppd_icc_fallback (cf_filter_data_t *data, ppd_file_t *ppd, char **qualifier) +static char * +get_ppd_icc_fallback (cf_filter_data_t *data, ppd_file_t *ppd, char **qualifier) { cf_logfunc_t log = data->logfunc; diff --git a/cupsfilters/filter.c b/cupsfilters/filter.c index 5882fcf91..f51f4bd3a 100644 --- a/cupsfilters/filter.c +++ b/cupsfilters/filter.c @@ -40,7 +40,7 @@ typedef struct filter_function_pid_s /* Filter in filter chain */ * of a given file descriptor. */ -int /* Return value of fcntl() */ +static int /* Return value of fcntl() */ fcntl_add_cloexec(int fd) /* File descriptor to add FD_CLOEXEC to */ { return fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); @@ -52,7 +52,7 @@ fcntl_add_cloexec(int fd) /* File descriptor to add FD_CLOEXEC to */ * of a given file descriptor. */ -int /* Return value of fcntl() */ +static int /* Return value of fcntl() */ fcntl_add_nonblock(int fd) /* File descriptor to add O_NONBLOCK to */ { return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); @@ -837,7 +837,7 @@ cfFilterChain(int inputfd, /* I - File descriptor input stream */ * as used by the execve() function */ -char * /* O - The value, NULL if variable is not in list */ +static char * /* O - The value, NULL if variable is not in list */ get_env_var(char *name, /* I - Name of environment variable to read */ char **env) /* I - List of environment variable serttings */ { @@ -861,7 +861,7 @@ get_env_var(char *name, /* I - Name of environment variable to read */ * as used by the execve() function */ -int /* O - Index of where the new value got inserted in +static int /* O - Index of where the new value got inserted in the list */ add_env_var(char *name, /* I - Name of environment variable to set */ char *value, /* I - Value of environment variable to set */ @@ -916,7 +916,7 @@ add_env_var(char *name, /* I - Name of environment variable to set */ * 'sanitize_device_uri()' - Remove authentication info from a device URI */ -char * /* O - Sanitized URI */ +static char * /* O - Sanitized URI */ sanitize_device_uri(const char *uri, /* I - Device URI */ char *buf, /* I - Buffer for output */ size_t bufsize) /* I - Size of buffer */ diff --git a/cupsfilters/ghostscript.c b/cupsfilters/ghostscript.c index e7b176ad8..6fa6d8f52 100644 --- a/cupsfilters/ghostscript.c +++ b/cupsfilters/ghostscript.c @@ -32,12 +32,12 @@ #define PDF_MAX_CHECK_COMMENT_LINES 20 -typedef enum { +typedef enum gs_doc_e { GS_DOC_TYPE_PDF, GS_DOC_TYPE_PS, GS_DOC_TYPE_EMPTY, GS_DOC_TYPE_UNKNOWN -} GsDocType; +} gs_doc_t; #ifdef CUPS_RASTER_SYNCv1 typedef cups_page_header2_t gs_page_header; @@ -45,12 +45,12 @@ typedef cups_page_header2_t gs_page_header; typedef cups_page_header_t gs_page_header; #endif /* CUPS_RASTER_SYNCv1 */ -static GsDocType +static gs_doc_t parse_doc_type(FILE *fp) { char buf[5]; int is_empty = 1; - GsDocType type = GS_DOC_TYPE_UNKNOWN; + gs_doc_t type = GS_DOC_TYPE_UNKNOWN; /* get the first few bytes of the file */ rewind(fp); @@ -696,7 +696,7 @@ cfFilterGhostscript(int inputfd, /* I - File descriptor input cups_array_t *gs_args = NULL; cups_option_t *options = NULL; FILE *fp = NULL; - GsDocType doc_type; + gs_doc_t doc_type; gs_page_header h; cups_cspace_t cspace = -1; int bytes; diff --git a/cupsfilters/ieee1284.c b/cupsfilters/ieee1284.c index 9cc92767f..26e084dda 100644 --- a/cupsfilters/ieee1284.c +++ b/cupsfilters/ieee1284.c @@ -581,7 +581,7 @@ cfIEEE1284GetValues( } /* - * 'moverightpart()' - Mark a start position in a string buffer and + * 'move_right_part()' - Mark a start position in a string buffer and * move all characters beginning from there by * a given amount of characters. Characters will * get lost when moving to the left, there will @@ -589,8 +589,8 @@ cfIEEE1284GetValues( * to the right. */ -void -moverightpart( +static void +move_right_part( char *buffer, /* I/O - String buffer */ size_t bufsize, /* I - Size of string buffer */ char *start_pos, /* I - Start of part to be moved */ @@ -1026,7 +1026,7 @@ cfIEEE1284NormalizeMakeModel( bufptr[0] = 'H'; bufptr[1] = 'P'; - moverightpart(buffer, bufsize, bufptr + 2, -13); + move_right_part(buffer, bufsize, bufptr + 2, -13); if (modelptr >= bufptr + 15) modelptr -= 13; bufptr += 2; @@ -1046,7 +1046,7 @@ cfIEEE1284NormalizeMakeModel( bufptr[2] = 'd'; bufptr[3] = 'a'; bufptr[4] = 'k'; - moverightpart(buffer, bufsize, bufptr + 5, -16); + move_right_part(buffer, bufsize, bufptr + 5, -16); if (modelptr >= bufptr + 21) modelptr -= 16; bufptr += 5; @@ -1059,7 +1059,7 @@ cfIEEE1284NormalizeMakeModel( * Strip "International"... */ - moverightpart(buffer, bufsize, bufptr + 7, -14); + move_right_part(buffer, bufsize, bufptr + 7, -14); if (modelptr >= bufptr + 21) modelptr -= 14; bufptr += 7; @@ -1094,7 +1094,7 @@ cfIEEE1284NormalizeMakeModel( bufptr[1] = 'H'; bufptr[2] = 'A'; bufptr[3] = 'G'; - moverightpart(buffer, bufsize, bufptr + 4, -4); + move_right_part(buffer, bufsize, bufptr + 4, -4); if (modelptr >= bufptr + 8) modelptr -= 4; bufptr += 4; @@ -1107,7 +1107,7 @@ cfIEEE1284NormalizeMakeModel( * Strip "TEC Corp."... */ - moverightpart(buffer, bufsize, bufptr + 7, -10); + move_right_part(buffer, bufsize, bufptr + 7, -10); if (modelptr >= bufptr + 17) modelptr -= 10; bufptr += 7; @@ -1118,7 +1118,7 @@ cfIEEE1284NormalizeMakeModel( */ while (strncasecmp(buffer, modelptr, modelptr - buffer) == 0) - moverightpart(buffer, bufsize, modelptr, buffer - modelptr); + move_right_part(buffer, bufsize, modelptr, buffer - modelptr); /* * Clean up the model name... @@ -1131,7 +1131,7 @@ cfIEEE1284NormalizeMakeModel( * Strip "series"... */ - moverightpart(buffer, bufsize, bufptr, -7); + move_right_part(buffer, bufsize, bufptr, -7); } /* @@ -1237,14 +1237,14 @@ cfIEEE1284NormalizeMakeModel( isalnum(*(bufptr - 2)) && !isalnum(*(bufptr - 1))))) { /* Insert single separator */ - moverightpart(buffer, bufsize, bufptr, 1); + move_right_part(buffer, bufsize, bufptr, 1); *bufptr = sepchr; rightsidemoved += 1; } else if (*bufptr == '+') /* Model names sometimes differ only by a '+' */ { /* Replace with the word "plus" */ - moverightpart(buffer, bufsize, bufptr, 3); + move_right_part(buffer, bufsize, bufptr, 3); *bufptr = 'p'; *(bufptr + 1) = 'l'; *(bufptr + 2) = 'u'; @@ -1256,7 +1256,7 @@ cfIEEE1284NormalizeMakeModel( if (bufptr == buffer || !isalnum(*(bufptr - 1))) { /* The previous is already a separator, remove this one */ - moverightpart(buffer, bufsize, bufptr, -1); + move_right_part(buffer, bufsize, bufptr, -1); rightsidemoved -= 1; } else @@ -1274,7 +1274,7 @@ cfIEEE1284NormalizeMakeModel( { if (numdigits < 6) { - moverightpart(buffer, bufsize, + move_right_part(buffer, bufsize, bufptr - numdigits, 6 - numdigits); memset(bufptr - numdigits, '0', 6 - numdigits); rightsidemoved += 6 - numdigits; @@ -1290,7 +1290,7 @@ cfIEEE1284NormalizeMakeModel( if (bufptr == buffer || isspace(*(bufptr - 1))) { /* The previous is already white space, remove this one */ - moverightpart(buffer, bufsize, bufptr, -1); + move_right_part(buffer, bufsize, bufptr, -1); rightsidemoved -= 1; } else diff --git a/cupsfilters/image-colorspace.c b/cupsfilters/image-colorspace.c index 4761611d4..c4e6f0339 100644 --- a/cupsfilters/image-colorspace.c +++ b/cupsfilters/image-colorspace.c @@ -37,19 +37,19 @@ * cfImageWhiteToCMYK() - Convert luminance colors to CMYK. * cfImageWhiteToRGB() - Convert luminance data to RGB. * cfImageWhiteToWhite() - Convert luminance colors to device- - * dependent luminance. - * cielab() - Map CIE Lab transformation... - * huerotate() - Rotate the hue, maintaining luminance. - * ident() - Make an identity matrix. - * mult() - Multiply two matrices. - * rgb_to_lab() - Convert an RGB color to CIE Lab. - * rgb_to_xyz() - Convert an RGB color to CIE XYZ. - * saturate() - Make a saturation matrix. - * xform() - Transform a 3D point using a matrix... - * xrotate() - Rotate about the x (red) axis... - * yrotate() - Rotate about the y (green) axis... - * zrotate() - Rotate about the z (blue) axis... - * zshear() - Shear z using x and y... + * dependent luminance. + * cie_lab() - Map CIE Lab transformation... + * hue_rotate() - Rotate the hue, maintaining luminance. + * ident() - Make an identity matrix. + * mult() - Multiply two matrices. + * rgb_to_lab() - Convert an RGB color to CIE Lab. + * rgb_to_xyz() - Convert an RGB color to CIE XYZ. + * saturate() - Make a saturation matrix. + * x_form() - Transform a 3D point using a matrix... + * x_rotate() - Rotate about the x (red) axis... + * y_rotate() - Rotate about the y (green) axis... + * z_rotate() - Rotate about the z (blue) axis... + * z_shear() - Shear z using x and y... */ /* @@ -109,18 +109,18 @@ static cups_cspace_t cfImageColorSpace = CUPS_CSPACE_RGB; * Local functions... */ -static float cielab(float x, float xn); -static void huerotate(float [3][3], float); +static float cie_lab(float x, float xn); +static void hue_rotate(float [3][3], float); static void ident(float [3][3]); static void mult(float [3][3], float [3][3], float [3][3]); static void rgb_to_lab(cf_ib_t *val); static void rgb_to_xyz(cf_ib_t *val); static void saturate(float [3][3], float); -static void xform(float [3][3], float, float, float, float *, float *, float *); -static void xrotate(float [3][3], float, float); -static void yrotate(float [3][3], float, float); -static void zrotate(float [3][3], float, float); -static void zshear(float [3][3], float, float); +static void x_form(float [3][3], float, float, float, float *, float *, float *); +static void x_rotate(float [3][3], float, float); +static void y_rotate(float [3][3], float, float); +static void z_rotate(float [3][3], float, float); +static void z_shear(float [3][3], float, float); /* @@ -510,7 +510,7 @@ cfImageRGBAdjust(cf_ib_t *pixels, /* IO - Input/output pixels */ ident(mat); saturate(mat, saturation * 0.01); - huerotate(mat, (float)hue); + hue_rotate(mat, (float)hue); /* * Allocate memory for the lookup table... @@ -1115,11 +1115,11 @@ cfImageWhiteToWhite( /* - * 'cielab()' - Map CIE Lab transformation... + * 'cie_lab()' - Map CIE Lab transformation... */ static float /* O - Adjusted color value */ -cielab(float x, /* I - Raw color value */ +cie_lab(float x, /* I - Raw color value */ float xn) /* I - Whitepoint color value */ { float x_xn; /* Fraction of whitepoint */ @@ -1135,11 +1135,11 @@ cielab(float x, /* I - Raw color value */ /* - * 'huerotate()' - Rotate the hue, maintaining luminance. + * 'hue_rotate()' - Rotate the hue, maintaining luminance. */ static void -huerotate(float mat[3][3], /* I - Matrix to append to */ +hue_rotate(float mat[3][3], /* I - Matrix to append to */ float rot) /* I - Hue rotation in degrees */ { float hmat[3][3]; /* Hue matrix */ @@ -1162,20 +1162,20 @@ huerotate(float mat[3][3], /* I - Matrix to append to */ xrs = M_SQRT1_2; xrc = M_SQRT1_2; - xrotate(hmat,xrs,xrc); + x_rotate(hmat,xrs,xrc); yrs = -1.0 / sqrt(3.0); yrc = -M_SQRT2 * yrs; - yrotate(hmat,yrs,yrc); + y_rotate(hmat,yrs,yrc); /* * Shear the space to make the luminance plane horizontal... */ - xform(hmat, 0.3086, 0.6094, 0.0820, &lx, &ly, &lz); + x_form(hmat, 0.3086, 0.6094, 0.0820, &lx, &ly, &lz); zsx = lx / lz; zsy = ly / lz; - zshear(hmat, zsx, zsy); + z_shear(hmat, zsx, zsy); /* * Rotate the hue... @@ -1184,20 +1184,20 @@ huerotate(float mat[3][3], /* I - Matrix to append to */ zrs = sin(rot * M_PI / 180.0); zrc = cos(rot * M_PI / 180.0); - zrotate(hmat, zrs, zrc); + z_rotate(hmat, zrs, zrc); /* * Unshear the space to put the luminance plane back... */ - zshear(hmat, -zsx, -zsy); + z_shear(hmat, -zsx, -zsy); /* * Rotate the grey vector back into place... */ - yrotate(hmat, -yrs, yrc); - xrotate(hmat, -xrs, xrc); + y_rotate(hmat, -yrs, yrc); + x_rotate(hmat, -xrs, xrc); /* * Append it to the current matrix... @@ -1304,8 +1304,8 @@ rgb_to_lab(cf_ib_t *val) /* IO - Color value */ ciel = 903.3 * ciey_yn; /*ciel = ciel;*/ - ciea = 500 * (cielab(ciex, D65_X) - cielab(ciey, D65_Y)); - cieb = 200 * (cielab(ciey, D65_Y) - cielab(ciez, D65_Z)); + ciea = 500 * (cie_lab(ciex, D65_X) - cie_lab(ciey, D65_Y)); + cieb = 200 * (cie_lab(ciey, D65_Y) - cie_lab(ciez, D65_Z)); /* * Scale the L value and bias the a and b values by 128 so that all @@ -1427,11 +1427,11 @@ saturate(float mat[3][3], /* I - Matrix to append to */ /* - * 'xform()' - Transform a 3D point using a matrix... + * 'x_form()' - Transform a 3D point using a matrix... */ static void -xform(float mat[3][3], /* I - Matrix */ +x_form(float mat[3][3], /* I - Matrix */ float x, /* I - Input X coordinate */ float y, /* I - Input Y coordinate */ float z, /* I - Input Z coordinate */ @@ -1446,11 +1446,11 @@ xform(float mat[3][3], /* I - Matrix */ /* - * 'xrotate()' - Rotate about the x (red) axis... + * 'x_rotate()' - Rotate about the x (red) axis... */ static void -xrotate(float mat[3][3], /* I - Matrix */ +x_rotate(float mat[3][3], /* I - Matrix */ float rs, /* I - Rotation angle sine */ float rc) /* I - Rotation angle cosine */ { @@ -1474,11 +1474,11 @@ xrotate(float mat[3][3], /* I - Matrix */ /* - * 'yrotate()' - Rotate about the y (green) axis... + * 'y_rotate()' - Rotate about the y (green) axis... */ static void -yrotate(float mat[3][3], /* I - Matrix */ +y_rotate(float mat[3][3], /* I - Matrix */ float rs, /* I - Rotation angle sine */ float rc) /* I - Rotation angle cosine */ { @@ -1502,11 +1502,11 @@ yrotate(float mat[3][3], /* I - Matrix */ /* - * 'zrotate()' - Rotate about the z (blue) axis... + * 'z_rotate()' - Rotate about the z (blue) axis... */ static void -zrotate(float mat[3][3], /* I - Matrix */ +z_rotate(float mat[3][3], /* I - Matrix */ float rs, /* I - Rotation angle sine */ float rc) /* I - Rotation angle cosine */ { @@ -1530,11 +1530,11 @@ zrotate(float mat[3][3], /* I - Matrix */ /* - * 'zshear()' - Shear z using x and y... + * 'z_shear()' - Shear z using x and y... */ static void -zshear(float mat[3][3], /* I - Matrix */ +z_shear(float mat[3][3], /* I - Matrix */ float dx, /* I - X shear */ float dy) /* I - Y shear */ { diff --git a/cupsfilters/image-sgi.c b/cupsfilters/image-sgi.c index 9cf3f94a6..baf9829a8 100644 --- a/cupsfilters/image-sgi.c +++ b/cupsfilters/image-sgi.c @@ -19,7 +19,56 @@ */ #include "image-private.h" -#include "image-sgi.h" +#include +#include +#include + + +/* + * Constants... + */ + +# define CF_SGI_MAGIC 474 /* Magic number in image file */ + +# define CF_SGI_COMP_NONE 0 /* No compression */ +# define CF_SGI_COMP_RLE 1 /* Run-length encoding */ +# define CF_SGI_COMP_ARLE 2 /* Agressive run-length encoding */ + + +/* + * Image structure... + */ + +typedef struct +{ + FILE *file; /* Image file */ + int bpp, /* Bytes per pixel/channel */ + comp; /* Compression */ + unsigned short xsize, /* Width in pixels */ + ysize, /* Height in pixels */ + zsize; /* Number of channels */ + long firstrow, /* File offset for first row */ + nextrow, /* File offset for next row */ + **table, /* Offset table for compression */ + **length; /* Length table for compression */ + unsigned short *arle_row; /* Advanced RLE compression buffer */ + long arle_offset, /* Advanced RLE buffer offset */ + arle_length; /* Advanced RLE buffer length */ +} cf_sgi_t; + + +/* + * Local functions... + */ + +static int sgi_close(cf_sgi_t *sgip); +static int sgi_get_row(cf_sgi_t *sgip, unsigned short *row, int y, int z); +static cf_sgi_t *sgi_open_file(FILE *file, int comp, int bpp, + int xsize, int ysize, int zsize); +static int get_long(FILE *); +static int get_short(FILE *); +static int read_rle8(FILE *, unsigned short *, int); +static int read_rle16(FILE *, unsigned short *, int); /* @@ -54,7 +103,7 @@ _cfImageReadSGI( * Setup the SGI file... */ - sgip = cfSGIOpenFile(fp, CF_SGI_READ, 0, 0, 0, 0, 0); + sgip = sgi_open_file(fp, 0, 0, 0, 0, 0); /* * Get the image dimensions and load the output image... @@ -71,7 +120,7 @@ _cfImageReadSGI( { DEBUG_printf(("DEBUG: Bad SGI image dimensions %ux%ux%u!\n", sgip->xsize, sgip->ysize, sgip->zsize)); - cfSGIClose(sgip); + sgi_close(sgip); return (1); } @@ -90,14 +139,14 @@ _cfImageReadSGI( if ((in = malloc(img->xsize * sgip->zsize)) == NULL) { DEBUG_puts("DEBUG: Unable to allocate memory!\n"); - cfSGIClose(sgip); + sgi_close(sgip); return (1); } if ((out = malloc(img->xsize * bpp)) == NULL) { DEBUG_puts("DEBUG: Unable to allocate memory!\n"); - cfSGIClose(sgip); + sgi_close(sgip); free(in); return (1); } @@ -106,7 +155,7 @@ _cfImageReadSGI( sizeof(unsigned short))) == NULL) { DEBUG_puts("DEBUG: Unable to allocate memory!\n"); - cfSGIClose(sgip); + sgi_close(sgip); free(in); free(out); return (1); @@ -122,7 +171,7 @@ _cfImageReadSGI( for (y = 0; y < img->ysize; y ++) { for (i = 0; i < sgip->zsize; i ++) - cfSGIGetRow(sgip, rows[i], img->ysize - 1 - y, i); + sgi_get_row(sgip, rows[i], img->ysize - 1 - y, i); switch (sgip->zsize) { @@ -279,8 +328,297 @@ _cfImageReadSGI( free(out); free(rows[0]); - cfSGIClose(sgip); + sgi_close(sgip); return (0); } + +/* + * 'sgi_close()' - Close an SGI image file. + */ + +static int /* O - 0 on success, -1 on error */ +sgi_close(cf_sgi_t *sgip) /* I - SGI image */ +{ + int i; /* Return status */ + + + if (sgip == NULL) + return (-1); + + if (sgip->table != NULL) + { + free(sgip->table[0]); + free(sgip->table); + } + + if (sgip->length != NULL) + { + free(sgip->length[0]); + free(sgip->length); + } + + if (sgip->comp == CF_SGI_COMP_ARLE) + free(sgip->arle_row); + + i = fclose(sgip->file); + free(sgip); + + return (i); +} + + +/* + * 'sgi_get_row()' - Get a row of image data from a file. + */ + +static int /* O - 0 on success, -1 on error */ +sgi_get_row(cf_sgi_t *sgip, /* I - SGI image */ + unsigned short *row, /* O - Row to read */ + int y, /* I - Line to read */ + int z) /* I - Channel to read */ +{ + int x; /* X coordinate */ + long offset; /* File offset */ + + + if (sgip == NULL || + row == NULL || + y < 0 || y >= sgip->ysize || + z < 0 || z >= sgip->zsize) + return (-1); + + switch (sgip->comp) + { + case CF_SGI_COMP_NONE : + /* + * Seek to the image row - optimize buffering by only seeking if + * necessary... + */ + + offset = 512 + (y + z * sgip->ysize) * sgip->xsize * sgip->bpp; + if (offset != ftell(sgip->file)) + fseek(sgip->file, offset, SEEK_SET); + + if (sgip->bpp == 1) + { + for (x = sgip->xsize; x > 0; x --, row ++) + *row = getc(sgip->file); + } + else + { + for (x = sgip->xsize; x > 0; x --, row ++) + *row = get_short(sgip->file); + } + break; + + case CF_SGI_COMP_RLE : + offset = sgip->table[z][y]; + if (offset != ftell(sgip->file)) + fseek(sgip->file, offset, SEEK_SET); + + if (sgip->bpp == 1) + return (read_rle8(sgip->file, row, sgip->xsize)); + else + return (read_rle16(sgip->file, row, sgip->xsize)); + } + + return (0); +} + + +/* + * 'sgi_open_file()' - Open an SGI image file for reading or writing. + */ + +static cf_sgi_t * /* O - New image */ +sgi_open_file(FILE *file, /* I - File to open */ + int comp, /* I - Type of compression */ + int bpp, /* I - Bytes per pixel */ + int xsize, /* I - Width of image in pixels */ + int ysize, /* I - Height of image in pixels */ + int zsize) /* I - Number of channels */ +{ + int i, j; /* Looping var */ + short magic; /* Magic number */ + cf_sgi_t *sgip; /* New image pointer */ + + + if ((sgip = calloc(sizeof(cf_sgi_t), 1)) == NULL) + return (NULL); + + sgip->file = file; + + magic = get_short(sgip->file); + if (magic != CF_SGI_MAGIC) + { + free(sgip); + return (NULL); + } + + sgip->comp = getc(sgip->file); + sgip->bpp = getc(sgip->file); + get_short(sgip->file); /* Dimensions */ + sgip->xsize = get_short(sgip->file); + sgip->ysize = get_short(sgip->file); + sgip->zsize = get_short(sgip->file); + get_long(sgip->file); /* Minimum pixel */ + get_long(sgip->file); /* Maximum pixel */ + + if (sgip->comp) + { + /* + * This file is compressed; read the scanline tables... + */ + + fseek(sgip->file, 512, SEEK_SET); + + if ((sgip->table = calloc(sgip->zsize, sizeof(long *))) == NULL) + { + free(sgip); + return (NULL); + } + + if ((sgip->table[0] = calloc(sgip->ysize * sgip->zsize, + sizeof(long))) == NULL) + { + free(sgip->table); + free(sgip); + return (NULL); + } + + for (i = 1; i < sgip->zsize; i ++) + sgip->table[i] = sgip->table[0] + i * sgip->ysize; + + for (i = 0; i < sgip->zsize; i ++) + for (j = 0; j < sgip->ysize; j ++) + sgip->table[i][j] = get_long(sgip->file); + } + + return (sgip); +} + + +/* + * 'get_long()' - Get a 32-bit big-endian integer. + */ + +static int /* O - Long value */ +get_long(FILE *fp) /* I - File to read from */ +{ + unsigned char b[4]; /* Bytes from file */ + + + if (fread(b, 4, 1, fp) == 0 && ferror(fp)) + DEBUG_printf(("Error reading file!")); + return ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]); +} + + +/* + * 'get_short()' - Get a 16-bit big-endian integer. + */ + +static int /* O - Short value */ +get_short(FILE *fp) /* I - File to read from */ +{ + unsigned char b[2]; /* Bytes from file */ + + + if (fread(b, 2, 1, fp) == 0 && ferror(fp)) + DEBUG_printf(("Error reading file!")); + return ((b[0] << 8) | b[1]); +} + + +/* + * 'read_rle8()' - Read 8-bit RLE data. + */ + +static int /* O - Value on success, -1 on error */ +read_rle8(FILE *fp, /* I - File to read from */ + unsigned short *row, /* O - Data */ + int xsize) /* I - Width of data in pixels */ +{ + int i, /* Looping var */ + ch, /* Current character */ + count, /* RLE count */ + length; /* Number of bytes read... */ + + + length = 0; + + while (xsize > 0) + { + if ((ch = getc(fp)) == EOF) + return (-1); + length ++; + + count = ch & 127; + if (count == 0) + break; + + if (ch & 128) + { + for (i = 0; i < count; i ++, row ++, xsize --, length ++) + if (xsize > 0) + *row = getc(fp); + } + else + { + ch = getc(fp); + length ++; + for (i = 0; i < count && xsize > 0; i ++, row ++, xsize --) + *row = ch; + } + } + + return (xsize > 0 ? -1 : length); +} + + +/* + * 'read_rle16()' - Read 16-bit RLE data. + */ + +static int /* O - Value on success, -1 on error */ +read_rle16(FILE *fp, /* I - File to read from */ + unsigned short *row, /* O - Data */ + int xsize) /* I - Width of data in pixels */ +{ + int i, /* Looping var */ + ch, /* Current character */ + count, /* RLE count */ + length; /* Number of bytes read... */ + + + length = 0; + + while (xsize > 0) + { + if ((ch = get_short(fp)) == EOF) + return (-1); + length ++; + + count = ch & 127; + if (count == 0) + break; + + if (ch & 128) + { + for (i = 0; i < count; i ++, row ++, xsize --, length ++) + if (xsize > 0) + *row = get_short(fp); + } + else + { + ch = get_short(fp); + length ++; + for (i = 0; i < count && xsize > 0; i ++, row ++, xsize --) + *row = ch; + } + } + + return (xsize > 0 ? -1 : length * 2); +} diff --git a/cupsfilters/image.c b/cupsfilters/image.c index 0931b6544..900009015 100644 --- a/cupsfilters/image.c +++ b/cupsfilters/image.c @@ -24,8 +24,9 @@ * _cfImagePutCol() - Put a column of pixels to an image. * _cfImagePutRow() - Put a row of pixels to an image. * cfImageSetMaxTiles() - Set the maximum number of tiles to cache. - * flush_tile() - Flush the least-recently-used tile in the cache. - * get_tile() - Get a cached tile. + * cfImageCrop() - Crop an image. + * flush_tile() - Flush the least-recently-used tile in the cache. + * get_tile() - Get a cached tile. */ /* @@ -39,7 +40,7 @@ * Local functions... */ -static int flush_tile(cf_image_t *img); +static int flush_tile(cf_image_t *img); static cf_ib_t *get_tile(cf_image_t *img, int x, int y); @@ -634,6 +635,37 @@ cfImageSetMaxTiles( } + +/* + * 'cfImageCrop()' - Crop an image. + * (posw, posh): Position of left corner + * (width, height): Width and height of required image. + */ + +cf_image_t* cfImageCrop(cf_image_t* img,int posw,int posh,int width,int height) +{ + int image_width = cfImageGetWidth(img); + cf_image_t* temp=calloc(sizeof(cf_image_t),1); + cf_ib_t *pixels=(cf_ib_t*)malloc(img->xsize*cfImageGetDepth(img)); + temp->cachefile = -1; + temp->max_ics = CF_TILE_MINIMUM; + temp->colorspace=img->colorspace; + temp->xppi = img->xppi; + temp->yppi = img->yppi; + temp->num_ics = 0; + temp->first =temp->last = NULL; + temp->tiles = NULL; + temp->xsize = width; + temp->ysize = height; + for(int i=posh;ipixels + bpp * (y * CF_TILE_SIZE + x)); } - -/* - * Crop a image. - * (posw,posh): Position of left corner - * (width,height): width and height of required image. - */ -cf_image_t* cfImageCrop(cf_image_t* img,int posw,int posh,int width,int height) -{ - int image_width = cfImageGetWidth(img); - cf_image_t* temp=calloc(sizeof(cf_image_t),1); - cf_ib_t *pixels=(cf_ib_t*)malloc(img->xsize*cfImageGetDepth(img)); - temp->cachefile = -1; - temp->max_ics = CF_TILE_MINIMUM; - temp->colorspace=img->colorspace; - temp->xppi = img->xppi; - temp->yppi = img->yppi; - temp->num_ics = 0; - temp->first =temp->last = NULL; - temp->tiles = NULL; - temp->xsize = width; - temp->ysize = height; - for(int i=posh;i #include -#if CUPS_VERSION_MAJOR < 1 \ - || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 2) -#ifndef CUPS_1_1 -#error Installed libs and specified source Version mismatch \ - Libs >= 1.2 && Source < 1.2 -#define CUPS_1_1 -#endif -#else -#ifdef CUPS_1_1 -#error Installed libs and specified source Version mismatch \ - Libs < 1.2 && Source >= 1.2 -#undef CUPS_1_1 -#endif -#endif - -//#define OUT_AS_HEX -//#define OUT_AS_ASCII85 - #define N_OBJECT_ALLOC 100 #define LINEBUFSIZE 1024 -#ifdef CUPS_1_1 -#define cf_ib_t ib_t -#define cf_image_t image_t -#define CF_IMAGE_CMYK IMAGE_CMYK -#define CF_IMAGE_WHITE IMAGE_WHITE -#define CF_IMAGE_RGB IMAGE_RGB -#define CF_IMAGE_RGB_CMYK IMAGE_RGB_CMYK -#define cfImageOpen ImageOpen -#define cfImageClose ImageClose -#define cfImageGetColorSpace(img) (img->colorspace) -#define cfImageGetXPPI(img) (img->xppi) -#define cfImageGetYPPI(img) (img->yppi) -#define cfImageGetWidth(img) (img->xsize) -#define cfImageGetHeight(img) (img->ysize) -#define cfImageGetRow ImageGetRow -#endif - /* * Types... */ @@ -74,7 +39,7 @@ struct pdfObject { int offset; }; -typedef struct { /**** Document information ****/ +typedef struct imagetopdf_doc_s { /**** Document information ****/ int Flip, /* Flip/mirror pages */ XPosition, /* Horizontal position on page */ YPosition, /* Vertical position on page */ @@ -132,6 +97,7 @@ typedef struct { /**** Document information ****/ * Local functions... */ +static void emit_jcl_options(imagetopdf_doc_t *doc, FILE *fp, int copies); #ifdef OUT_AS_HEX static void out_hex(imagetopdf_doc_t *doc, cf_ib_t *, int, int); #else @@ -141,22 +107,22 @@ static void out_ascii85(imagetopdf_doc_t *doc, cf_ib_t *, int, int); static void out_bin(imagetopdf_doc_t *doc, cf_ib_t *, int, int); #endif #endif -static void outPdf(imagetopdf_doc_t *doc, const char *str); -static void putcPdf(imagetopdf_doc_t *doc, char c); -static int newObj(imagetopdf_doc_t *doc); -static void freeAllObj(imagetopdf_doc_t *doc); -static void outXref(imagetopdf_doc_t *doc); -static void outTrailer(imagetopdf_doc_t *doc); -static void outString(imagetopdf_doc_t *doc, const char *s); -static int outPrologue(imagetopdf_doc_t *doc, int nPages); -static int allocPageObjects(imagetopdf_doc_t *doc, int noPages); -static void setOffset(imagetopdf_doc_t *doc, int obj); -static int outPageObject(imagetopdf_doc_t *doc, int pageObj, +static void out_pdf(imagetopdf_doc_t *doc, const char *str); +static void putc_pdf(imagetopdf_doc_t *doc, char c); +static int new_obj(imagetopdf_doc_t *doc); +static void free_all_obj(imagetopdf_doc_t *doc); +static void out_xref(imagetopdf_doc_t *doc); +static void out_trailer(imagetopdf_doc_t *doc); +static void out_string(imagetopdf_doc_t *doc, const char *s); +static int out_prologue(imagetopdf_doc_t *doc, int nPages); +static int alloc_page_objects(imagetopdf_doc_t *doc, int noPages); +static void set_offset(imagetopdf_doc_t *doc, int obj); +static int out_page_object(imagetopdf_doc_t *doc, int pageObj, int contentsObj, int imgObj); -static int outPageContents(imagetopdf_doc_t *doc, int contentsObj); -static int outImage(imagetopdf_doc_t *doc, int imgObj); +static int out_page_contents(imagetopdf_doc_t *doc, int contentsObj); +static int out_image(imagetopdf_doc_t *doc, int imgObj); -void emitJCLOptions(imagetopdf_doc_t *doc, FILE *fp, int copies) +static void emit_jcl_options(imagetopdf_doc_t *doc, FILE *fp, int copies) { int section; ppd_choice_t **choices; @@ -214,13 +180,12 @@ void emitJCLOptions(imagetopdf_doc_t *doc, FILE *fp, int copies) if (datawritten) fputc('\n',fp); } - -static void setOffset(imagetopdf_doc_t *doc, int obj) +static void set_offset(imagetopdf_doc_t *doc, int obj) { doc->objects[obj].offset = doc->currentOffset; } -static int allocPageObjects(imagetopdf_doc_t *doc, int nPages) +static int alloc_page_objects(imagetopdf_doc_t *doc, int nPages) { int i, n; @@ -228,7 +193,7 @@ static int allocPageObjects(imagetopdf_doc_t *doc, int nPages) return (-1); for (i = 0;i < nPages;i++) { - if ((n = newObj(doc)) >= 0) + if ((n = new_obj(doc)) >= 0) doc->pageObjects[i] = n; else return (-1); @@ -236,7 +201,7 @@ static int allocPageObjects(imagetopdf_doc_t *doc, int nPages) return (0); } -static int newObj(imagetopdf_doc_t *doc) +static int new_obj(imagetopdf_doc_t *doc) { if (doc->objects == NULL) { @@ -257,7 +222,7 @@ static int newObj(imagetopdf_doc_t *doc) return doc->currentObjectNo++; } -static void freeAllObj(imagetopdf_doc_t *doc) +static void free_all_obj(imagetopdf_doc_t *doc) { if (doc->objects != NULL) { @@ -266,13 +231,13 @@ static void freeAllObj(imagetopdf_doc_t *doc) } } -static void putcPdf(imagetopdf_doc_t *doc, char c) +static void putc_pdf(imagetopdf_doc_t *doc, char c) { fputc(c, doc->outputfp); doc->currentOffset++; } -static void outPdf(imagetopdf_doc_t *doc, const char *str) +static void out_pdf(imagetopdf_doc_t *doc, const char *str) { unsigned long len = strlen(str); @@ -280,38 +245,38 @@ static void outPdf(imagetopdf_doc_t *doc, const char *str) doc->currentOffset += len; } -static void outXref(imagetopdf_doc_t *doc) +static void out_xref(imagetopdf_doc_t *doc) { char buf[21]; int i; doc->xrefOffset = doc->currentOffset; - outPdf(doc, "xref\n"); + out_pdf(doc, "xref\n"); snprintf(buf,21,"0 %d\n",doc->currentObjectNo); - outPdf(doc, buf); - outPdf(doc, "0000000000 65535 f \n"); + out_pdf(doc, buf); + out_pdf(doc, "0000000000 65535 f \n"); for (i = 1;i < doc->currentObjectNo;i++) { snprintf(buf,21,"%010d 00000 n \n",doc->objects[i].offset); - outPdf(doc, buf); + out_pdf(doc, buf); } } -static void outString(imagetopdf_doc_t *doc, const char *s) +static void out_string(imagetopdf_doc_t *doc, const char *s) { char c; - putcPdf(doc, '('); + putc_pdf(doc, '('); for (;(c = *s) != '\0';s++) { if (c == '\\' || c == '(' || c == ')') { - putcPdf(doc, '\\'); + putc_pdf(doc, '\\'); } - putcPdf(doc, c); + putc_pdf(doc, c); } - putcPdf(doc, ')'); + putc_pdf(doc, ')'); } -static void outTrailer(imagetopdf_doc_t *doc) +static void out_trailer(imagetopdf_doc_t *doc) { time_t curtime; struct tm *curtm; @@ -321,34 +286,34 @@ static void outTrailer(imagetopdf_doc_t *doc) curtm = localtime(&curtime); strftime(curdate, sizeof(curdate),"D:%Y%m%d%H%M%S%z", curtm); - outPdf(doc, "trailer\n"); + out_pdf(doc, "trailer\n"); snprintf(doc->linebuf, LINEBUFSIZE,"<currentObjectNo); - outPdf(doc, doc->linebuf); - outPdf(doc, "/Root 1 0 R\n"); - outPdf(doc, "/Info << /Title "); - outString(doc, doc->title); - putcPdf(doc, ' '); + out_pdf(doc, doc->linebuf); + out_pdf(doc, "/Root 1 0 R\n"); + out_pdf(doc, "/Info << /Title "); + out_string(doc, doc->title); + putc_pdf(doc, ' '); snprintf(doc->linebuf,LINEBUFSIZE,"/CreationDate (%s) ",curdate); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); snprintf(doc->linebuf,LINEBUFSIZE,"/ModDate (%s) ",curdate); - outPdf(doc, doc->linebuf); - outPdf(doc, "/Producer (imagetopdf) "); - outPdf(doc, "/Trapped /False >>\n"); - outPdf(doc, ">>\n"); - outPdf(doc, "startxref\n"); + out_pdf(doc, doc->linebuf); + out_pdf(doc, "/Producer (imagetopdf) "); + out_pdf(doc, "/Trapped /False >>\n"); + out_pdf(doc, ">>\n"); + out_pdf(doc, "startxref\n"); snprintf(doc->linebuf,LINEBUFSIZE,"%d\n",doc->xrefOffset); - outPdf(doc, doc->linebuf); - outPdf(doc, "%%EOF\n"); + out_pdf(doc, doc->linebuf); + out_pdf(doc, "%%EOF\n"); } -static int outPrologue(imagetopdf_doc_t *doc, int nPages) +static int out_prologue(imagetopdf_doc_t *doc, int nPages) { int i; /* out header */ - if (newObj(doc) < 0) /* dummy for no 0 object */ + if (new_obj(doc) < 0) /* dummy for no 0 object */ return (-1); - outPdf(doc, "%PDF-1.3\n"); + out_pdf(doc, "%PDF-1.3\n"); /* out binary for transfer program */ doc->linebuf[0] = '%'; doc->linebuf[1] = (char)129; @@ -357,47 +322,47 @@ static int outPrologue(imagetopdf_doc_t *doc, int nPages) doc->linebuf[4] = (char)132; doc->linebuf[5] = '\n'; doc->linebuf[6] = (char)0; - outPdf(doc, doc->linebuf); - outPdf(doc, "% This file was generated by imagetopdf\n"); + out_pdf(doc, doc->linebuf); + out_pdf(doc, "% This file was generated by imagetopdf\n"); - if ((doc->catalogObj = newObj(doc)) < 0) + if ((doc->catalogObj = new_obj(doc)) < 0) return (-1); - if ((doc->pagesObj = newObj(doc)) < 0) + if ((doc->pagesObj = new_obj(doc)) < 0) return (-1); - if (allocPageObjects(doc, nPages) < 0) + if (alloc_page_objects(doc, nPages) < 0) return (-1); /* out catalog */ snprintf(doc->linebuf,LINEBUFSIZE, "%d 0 obj <catalogObj,doc->pagesObj); - outPdf(doc, doc->linebuf); - outPdf(doc, ">> endobj\n"); + out_pdf(doc, doc->linebuf); + out_pdf(doc, ">> endobj\n"); /* out Pages */ - setOffset(doc, doc->pagesObj); + set_offset(doc, doc->pagesObj); snprintf(doc->linebuf,LINEBUFSIZE, "%d 0 obj <pagesObj); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); if (doc->Reverse) { for (i = nPages-1;i >= 0;i--) { snprintf(doc->linebuf,LINEBUFSIZE,"%d 0 R ",doc->pageObjects[i]); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); } } else { for (i = 0;i < nPages;i++) { snprintf(doc->linebuf,LINEBUFSIZE,"%d 0 R ",doc->pageObjects[i]); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); } } - outPdf(doc, "] "); + out_pdf(doc, "] "); snprintf(doc->linebuf,LINEBUFSIZE,"/Count %d >> endobj\n",nPages); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); return (0); } -static int outPageObject(imagetopdf_doc_t *doc, int pageObj, int contentsObj, +static int out_page_object(imagetopdf_doc_t *doc, int pageObj, int contentsObj, int imgObj) { int trfuncObj; @@ -407,94 +372,94 @@ static int outPageObject(imagetopdf_doc_t *doc, int pageObj, int contentsObj, int outTrfunc = (doc->gammaval != 1.0 || doc->brightness != 1.0); /* out Page Object */ - setOffset(doc, pageObj); + set_offset(doc, pageObj); snprintf(doc->linebuf,LINEBUFSIZE, "%d 0 obj <pagesObj); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); snprintf(doc->linebuf,LINEBUFSIZE, "/MediaBox [ 0 0 %f %f ] ",doc->PageWidth,doc->PageLength); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); snprintf(doc->linebuf,LINEBUFSIZE, "/TrimBox [ 0 0 %f %f ] ",doc->PageWidth,doc->PageLength); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); snprintf(doc->linebuf,LINEBUFSIZE, "/CropBox [ 0 0 %f %f ] ",doc->PageWidth,doc->PageLength); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); if (contentsObj >= 0) { snprintf(doc->linebuf,LINEBUFSIZE, "/Contents %d 0 R ",contentsObj); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); snprintf(doc->linebuf,LINEBUFSIZE, "/Resources <>\n",imgObj); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); } else { /* empty page */ snprintf(doc->linebuf,LINEBUFSIZE, "/Resources <linebuf); + out_pdf(doc, doc->linebuf); } if (outTrfunc) { - if ((trfuncObj = newObj(doc)) < 0) + if ((trfuncObj = new_obj(doc)) < 0) return (-1); - if ((lengthObj = newObj(doc)) < 0) + if ((lengthObj = new_obj(doc)) < 0) return (-1); snprintf(doc->linebuf,LINEBUFSIZE, "/ExtGState << /GS1 << /TR %d 0 R >> >>\n",trfuncObj); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); } - outPdf(doc, " >>\n>>\nendobj\n"); + out_pdf(doc, " >>\n>>\nendobj\n"); if (outTrfunc) { /* out translate function */ - setOffset(doc, trfuncObj); + set_offset(doc, trfuncObj); snprintf(doc->linebuf,LINEBUFSIZE, "%d 0 obj <>\n", trfuncObj,lengthObj); - outPdf(doc, doc->linebuf); - outPdf(doc, "stream\n"); + out_pdf(doc, doc->linebuf); + out_pdf(doc, "stream\n"); startOffset = doc->currentOffset; snprintf(doc->linebuf,LINEBUFSIZE, "{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } " "ifelse %.3f mul }\n", doc->gammaval, doc->brightness); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); length = doc->currentOffset - startOffset; snprintf(doc->linebuf,LINEBUFSIZE, "endstream\nendobj\n"); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); /* out length object */ - setOffset(doc, lengthObj); + set_offset(doc, lengthObj); snprintf(doc->linebuf,LINEBUFSIZE, "%d 0 obj %d endobj\n",lengthObj,length); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); } return (0); } -static int outPageContents(imagetopdf_doc_t *doc, int contentsObj) +static int out_page_contents(imagetopdf_doc_t *doc, int contentsObj) { int startOffset; int lengthObj; int length; - setOffset(doc, contentsObj); - if ((lengthObj = newObj(doc)) < 0) + set_offset(doc, contentsObj); + if ((lengthObj = new_obj(doc)) < 0) return (-1); snprintf(doc->linebuf,LINEBUFSIZE, "%d 0 obj <> stream\n",contentsObj,lengthObj); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); startOffset = doc->currentOffset; if (doc->gammaval != 1.0 || doc->brightness != 1.0) - outPdf(doc, "/GS1 gs\n"); + out_pdf(doc, "/GS1 gs\n"); if (doc->Flip) { snprintf(doc->linebuf,LINEBUFSIZE, "-1 0 0 1 %.0f 0 cm\n",doc->PageWidth); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); } switch (doc->Orientation) @@ -502,17 +467,17 @@ static int outPageContents(imagetopdf_doc_t *doc, int contentsObj) case 1: snprintf(doc->linebuf,LINEBUFSIZE, "0 1 -1 0 %.0f 0 cm\n",doc->PageWidth); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); break; case 2: snprintf(doc->linebuf,LINEBUFSIZE, "-1 0 0 -1 %.0f %.0f cm\n",doc->PageWidth, doc->PageLength); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); break; case 3: snprintf(doc->linebuf,LINEBUFSIZE, "0 -1 1 0 0 %.0f cm\n",doc->PageLength); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); break; } @@ -523,25 +488,25 @@ static int outPageContents(imagetopdf_doc_t *doc, int contentsObj) snprintf(doc->linebuf,LINEBUFSIZE, "1 0 0 1 %.1f %.1f cm\n",doc->left,doc->top); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); snprintf(doc->linebuf,LINEBUFSIZE, "%.3f 0 0 %.3f 0 0 cm\n", doc->xprint * 72.0, doc->yprint * 72.0); - outPdf(doc, doc->linebuf); - outPdf(doc, "/Im Do\n"); + out_pdf(doc, doc->linebuf); + out_pdf(doc, "/Im Do\n"); length = doc->currentOffset - startOffset - 1; - outPdf(doc, "endstream\nendobj\n"); + out_pdf(doc, "endstream\nendobj\n"); /* out length object */ - setOffset(doc, lengthObj); + set_offset(doc, lengthObj); snprintf(doc->linebuf,LINEBUFSIZE, "%d 0 obj %d endobj\n",lengthObj,length); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); return (0); } -static int outImage(imagetopdf_doc_t *doc, int imgObj) +static int out_image(imagetopdf_doc_t *doc, int imgObj) { int y; /* Current Y coordinate in image */ #ifdef OUT_AS_ASCII85 @@ -552,8 +517,8 @@ static int outImage(imagetopdf_doc_t *doc, int imgObj) int lengthObj; int length; - setOffset(doc, imgObj); - if ((lengthObj = newObj(doc)) < 0) + set_offset(doc, imgObj); + if ((lengthObj = new_obj(doc)) < 0) return (-1); snprintf(doc->linebuf,LINEBUFSIZE, "%d 0 obj << /Length %d 0 R /Type /XObject " @@ -566,32 +531,32 @@ static int outImage(imagetopdf_doc_t *doc, int imgObj) #endif #endif ,imgObj,lengthObj); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); snprintf(doc->linebuf,LINEBUFSIZE, "/Width %d /Height %d /BitsPerComponent 8 ", doc->xc1 - doc->xc0 + 1, doc->yc1 - doc->yc0 + 1); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); switch (doc->colorspace) { case CF_IMAGE_WHITE : - outPdf(doc, "/ColorSpace /DeviceGray "); - outPdf(doc, "/Decode[0 1] "); + out_pdf(doc, "/ColorSpace /DeviceGray "); + out_pdf(doc, "/Decode[0 1] "); break; case CF_IMAGE_RGB : - outPdf(doc, "/ColorSpace /DeviceRGB "); - outPdf(doc, "/Decode[0 1 0 1 0 1] "); + out_pdf(doc, "/ColorSpace /DeviceRGB "); + out_pdf(doc, "/Decode[0 1 0 1 0 1] "); break; case CF_IMAGE_CMYK : - outPdf(doc, "/ColorSpace /DeviceCMYK "); - outPdf(doc, "/Decode[0 1 0 1 0 1 0 1] "); + out_pdf(doc, "/ColorSpace /DeviceCMYK "); + out_pdf(doc, "/Decode[0 1 0 1 0 1 0 1] "); break; } if (((doc->xc1 - doc->xc0 + 1) / doc->xprint) < 100.0) - outPdf(doc, "/Interpolate true "); + out_pdf(doc, "/Interpolate true "); - outPdf(doc, ">>\n"); - outPdf(doc, "stream\n"); + out_pdf(doc, ">>\n"); + out_pdf(doc, "stream\n"); startOffset = doc->currentOffset; #ifdef OUT_AS_ASCII85 @@ -624,13 +589,13 @@ static int outImage(imagetopdf_doc_t *doc, int imgObj) } #endif length = doc->currentOffset - startOffset; - outPdf(doc, "\nendstream\nendobj\n"); + out_pdf(doc, "\nendstream\nendobj\n"); /* out length object */ - setOffset(doc, lengthObj); + set_offset(doc, lengthObj); snprintf(doc->linebuf,LINEBUFSIZE, "%d 0 obj %d endobj\n",lengthObj,length); - outPdf(doc, doc->linebuf); + out_pdf(doc, doc->linebuf); return (0); } @@ -1857,7 +1822,7 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ } ppdEmitJCL(doc.ppd, doc.outputfp, data->job_id, data->job_user, data->job_title); - emitJCLOptions(&doc, doc.outputfp, deviceCopies); + emit_jcl_options(&doc, doc.outputfp, deviceCopies); free(doc.ppd->jcl_ps); doc.ppd->jcl_ps = old_jcl_ps; /* cups uses pool allocator, not free() */ } @@ -1866,7 +1831,7 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ * Start sending the document with any commands needed... */ - if (outPrologue(&doc, doc.Copies * doc.xpages * doc.ypages + + if (out_prologue(&doc, doc.Copies * doc.xpages * doc.ypages + (doc.EvenDuplex ? 1 : 0)) < 0) goto out_of_memory; @@ -2047,18 +2012,18 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ } if ((contentsObj = contentsObjs[doc.ypages*doc.xpage+doc.ypage] = - newObj(&doc)) < 0) + new_obj(&doc)) < 0) goto out_of_memory; if ((imgObj = imgObjs[doc.ypages*doc.xpage+doc.ypage] = - newObj(&doc)) < 0) + new_obj(&doc)) < 0) goto out_of_memory; /* out contents object */ - if (outPageContents(&doc, contentsObj) < 0) + if (out_page_contents(&doc, contentsObj) < 0) goto out_of_memory; /* out image object */ - if (outImage(&doc, imgObj) < 0) + if (out_image(&doc, imgObj) < 0) goto out_of_memory; } for (doc.page = 0; doc.Copies > 0 ; doc.Copies --) { @@ -2073,7 +2038,7 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ } /* out Page Object */ - if (outPageObject(&doc, doc.pageObjects[doc.page], + if (out_page_object(&doc, doc.pageObjects[doc.page], contentsObjs[doc.ypages * doc.xpage + doc.ypage], imgObjs[doc.ypages * doc.xpage + doc.ypage]) < 0) goto out_of_memory; @@ -2083,7 +2048,7 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ } if (doc.EvenDuplex) { /* out empty page */ - if (outPageObject(&doc, doc.pageObjects[doc.page], -1, -1) < 0) + if (out_page_object(&doc, doc.pageObjects[doc.page], -1, -1) < 0) goto out_of_memory; if (pdf_printer && log) log(ld, CF_LOGLEVEL_CONTROL, @@ -2109,17 +2074,17 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ goto canceled; } - if ((imgObj = newObj(&doc)) < 0) + if ((imgObj = new_obj(&doc)) < 0) goto out_of_memory; - if ((contentsObj = newObj(&doc)) < 0) + if ((contentsObj = new_obj(&doc)) < 0) goto out_of_memory; /* out contents object */ - if (outPageContents(&doc, contentsObj) < 0) + if (out_page_contents(&doc, contentsObj) < 0) goto out_of_memory; /* out image object */ - if (outImage(&doc, imgObj) < 0) + if (out_image(&doc, imgObj) < 0) goto out_of_memory; for (p = 0;p < doc.Copies;p++, doc.page++) @@ -2132,7 +2097,7 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ } /* out Page Object */ - if (outPageObject(&doc, doc.pageObjects[doc.page], contentsObj, + if (out_page_object(&doc, doc.pageObjects[doc.page], contentsObj, imgObj) < 0) goto out_of_memory; if (pdf_printer && log) @@ -2153,7 +2118,7 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ goto canceled; } - if (outPageObject(&doc, doc.pageObjects[doc.page], -1, -1) < 0) + if (out_page_object(&doc, doc.pageObjects[doc.page], -1, -1) < 0) goto out_of_memory; if (pdf_printer && log) log(ld, CF_LOGLEVEL_CONTROL, @@ -2163,20 +2128,18 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ } canceled: - outXref(&doc); - outTrailer(&doc); - freeAllObj(&doc); + out_xref(&doc); + out_trailer(&doc); + free_all_obj(&doc); /* * Close files... */ -#ifndef CUPS_1_1 if (emit_jcl) { if (doc.ppd && doc.ppd->jcl_end) ppdEmitJCLEnd(doc.ppd, doc.outputfp); } -#endif cfImageClose(doc.img); fclose(doc.outputfp); @@ -2187,7 +2150,7 @@ cfFilterImageToPDF(int inputfd, /* I - File descriptor input stream */ if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterImageToPDF: Cannot allocate any more memory."); - freeAllObj(&doc); + free_all_obj(&doc); cfImageClose(doc.img); fclose(doc.outputfp); close(outputfd); @@ -2217,8 +2180,8 @@ out_hex(imagetopdf_doc_t *doc, * for speed reasons... */ - putcPdf(doc, hex[*data >> 4]); - putcPdf(doc, hex[*data & 15]); + putc_pdf(doc, hex[*data >> 4]); + putc_pdf(doc, hex[*data & 15]); data ++; length --; @@ -2226,14 +2189,14 @@ out_hex(imagetopdf_doc_t *doc, col += 2; if (col > 78) { - putcPdf(doc, '\n'); + putc_pdf(doc, '\n'); col = 0; } } if (last_line && col) { - putcPdf(doc, '\n'); + putc_pdf(doc, '\n'); col = 0; } } @@ -2262,7 +2225,7 @@ out_ascii85(imagetopdf_doc_t *doc, if (b == 0) { - putcPdf(doc, 'z'); + putc_pdf(doc, 'z'); col ++; } else @@ -2277,7 +2240,7 @@ out_ascii85(imagetopdf_doc_t *doc, b /= 85; c[0] = b + '!'; - outPdf(doc, c); + out_pdf(doc, c); col += 5; } @@ -2286,7 +2249,7 @@ out_ascii85(imagetopdf_doc_t *doc, if (col >= 75) { - putcPdf(doc, '\n'); + putc_pdf(doc, '\n'); col = 0; } } @@ -2309,10 +2272,10 @@ out_ascii85(imagetopdf_doc_t *doc, c[0] = b + '!'; c[length+1] = '\0'; - outPdf(doc, c); + out_pdf(doc, c); } - outPdf(doc, "~>"); + out_pdf(doc, "~>"); col = 0; } } @@ -2329,14 +2292,14 @@ out_bin(imagetopdf_doc_t *doc, { while (length > 0) { - putcPdf(doc, *data); + putc_pdf(doc, *data); data ++; length --; } if (last_line) { - putcPdf(doc, '\n'); + putc_pdf(doc, '\n'); } } #endif diff --git a/cupsfilters/imagetops-pstops.c b/cupsfilters/imagetops-pstops.c index b587a13e8..fbc0ac890 100644 --- a/cupsfilters/imagetops-pstops.c +++ b/cupsfilters/imagetops-pstops.c @@ -4879,7 +4879,7 @@ start_nup(pstops_doc_t *doc, /* I - Document information */ * 'write_common()' - Write common procedures... */ -void +static void write_common(pstops_doc_t *doc) { doc_puts(doc, @@ -5193,7 +5193,7 @@ write_options( * 'write_text_comment()' - Write a DSC text comment. */ -void +static void write_text_comment(pstops_doc_t *doc, /* I - Document */ const char *name, /* I - Comment name ("Title", etc.) */ const char *value) /* I - Comment value */ diff --git a/cupsfilters/imagetoraster.c b/cupsfilters/imagetoraster.c index 2c7ceab96..0d2109a0f 100644 --- a/cupsfilters/imagetoraster.c +++ b/cupsfilters/imagetoraster.c @@ -13,15 +13,15 @@ * * cfFilterImageToRaster() - The image conversion filter function * blank_line() - Clear a line buffer to the blank value... - * format_CMY() - Convert image data to CMY. - * format_CMYK() - Convert image data to CMYK. - * format_K() - Convert image data to black. - * format_KCMY() - Convert image data to KCMY. - * format_KCMYcm() - Convert image data to KCMYcm. - * format_RGBA() - Convert image data to RGBA/RGBW. - * format_W() - Convert image data to luminance. - * format_YMC() - Convert image data to YMC. - * format_YMCK() - Convert image data to YMCK. + * format_cmy() - Convert image data to CMY. + * format_cmyk() - Convert image data to CMYK. + * format_k() - Convert image data to black. + * format_kcmy() - Convert image data to KCMY. + * format_kcmycm() - Convert image data to KCMYcm. + * format_rgba() - Convert image data to RGBA/RGBW. + * format_w() - Convert image data to luminance. + * format_ymc() - Convert image data to YMC. + * format_ymck() - Convert image data to YMCK. * make_lut() - Make a lookup table given gamma and brightness values. * raster_cb() - Validate the page header. */ @@ -134,11 +134,11 @@ int Floyd4x4[4][4] = */ static void blank_line(cups_page_header2_t *header, unsigned char *row); -static void format_CMY(imagetoraster_doc_t *doc, +static void format_cmy(imagetoraster_doc_t *doc, cups_page_header2_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); -static void format_CMYK(imagetoraster_doc_t *doc, +static void format_cmyk(imagetoraster_doc_t *doc, cups_page_header2_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); @@ -146,28 +146,28 @@ static void format_K(imagetoraster_doc_t *doc, cups_page_header2_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); -static void format_KCMYcm(imagetoraster_doc_t *doc, +static void format_kcmycm(imagetoraster_doc_t *doc, cups_page_header2_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); -static void format_KCMY(imagetoraster_doc_t *doc, +static void format_kcmy(imagetoraster_doc_t *doc, cups_page_header2_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); -#define format_RGB format_CMY -static void format_RGBA(imagetoraster_doc_t *doc, +#define format_RGB format_cmy +static void format_rgba(imagetoraster_doc_t *doc, cups_page_header2_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); -static void format_W(imagetoraster_doc_t *doc, +static void format_w(imagetoraster_doc_t *doc, cups_page_header2_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); -static void format_YMC(imagetoraster_doc_t *doc, +static void format_ymc(imagetoraster_doc_t *doc, cups_page_header2_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); -static void format_YMCK(imagetoraster_doc_t *doc, +static void format_ymck(imagetoraster_doc_t *doc, cups_page_header2_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); @@ -1880,7 +1880,7 @@ cfFilterImageToRaster(int inputfd, /* I - File descriptor input stream * { case CUPS_CSPACE_W : case CUPS_CSPACE_SW : - format_W(&doc, &header, row, y, plane, z->xsize, z->ysize, + format_w(&doc, &header, row, y, plane, z->xsize, z->ysize, yerr0, yerr1, r0, r1); break; default : @@ -1892,7 +1892,7 @@ cfFilterImageToRaster(int inputfd, /* I - File descriptor input stream * break; case CUPS_CSPACE_RGBA : case CUPS_CSPACE_RGBW : - format_RGBA(&doc, &header, row, y, plane, z->xsize, z->ysize, + format_rgba(&doc, &header, row, y, plane, z->xsize, z->ysize, yerr0, yerr1, r0, r1); break; case CUPS_CSPACE_K : @@ -1903,32 +1903,32 @@ cfFilterImageToRaster(int inputfd, /* I - File descriptor input stream * yerr0, yerr1, r0, r1); break; case CUPS_CSPACE_CMY : - format_CMY(&doc, &header, row, y, plane, z->xsize, z->ysize, + format_cmy(&doc, &header, row, y, plane, z->xsize, z->ysize, yerr0, yerr1, r0, r1); break; case CUPS_CSPACE_YMC : - format_YMC(&doc, &header, row, y, plane, z->xsize, z->ysize, + format_ymc(&doc, &header, row, y, plane, z->xsize, z->ysize, yerr0, yerr1, r0, r1); break; case CUPS_CSPACE_CMYK : - format_CMYK(&doc, &header, row, y, plane, z->xsize, z->ysize, + format_cmyk(&doc, &header, row, y, plane, z->xsize, z->ysize, yerr0, yerr1, r0, r1); break; case CUPS_CSPACE_YMCK : case CUPS_CSPACE_GMCK : case CUPS_CSPACE_GMCS : - format_YMCK(&doc, &header, row, y, plane, z->xsize, z->ysize, + format_ymck(&doc, &header, row, y, plane, z->xsize, z->ysize, yerr0, yerr1, r0, r1); break; case CUPS_CSPACE_KCMYcm : if (header.cupsBitsPerColor == 1) { - format_KCMYcm(&doc, &header, row, y, plane, z->xsize, + format_kcmycm(&doc, &header, row, y, plane, z->xsize, z->ysize, yerr0, yerr1, r0, r1); break; } case CUPS_CSPACE_KCMY : - format_KCMY(&doc, &header, row, y, plane, z->xsize, z->ysize, + format_kcmy(&doc, &header, row, y, plane, z->xsize, z->ysize, yerr0, yerr1, r0, r1); break; } @@ -2085,11 +2085,11 @@ blank_line(cups_page_header2_t *header, /* I - Page header */ /* - * 'format_CMY()' - Convert image data to CMY. + * 'format_cmy()' - Convert image data to CMY. */ static void -format_CMY(imagetoraster_doc_t *doc, +format_cmy(imagetoraster_doc_t *doc, cups_page_header2_t *header, /* I - Page header */ unsigned char *row, /* IO - Bitmap data for device */ int y, /* I - Current row */ @@ -2461,11 +2461,11 @@ format_CMY(imagetoraster_doc_t *doc, /* - * 'format_CMYK()' - Convert image data to CMYK. + * 'format_cmyk()' - Convert image data to CMYK. */ static void -format_CMYK(imagetoraster_doc_t *doc, +format_cmyk(imagetoraster_doc_t *doc, cups_page_header2_t *header,/* I - Page header */ unsigned char *row, /* IO - Bitmap data for device */ int y, /* I - Current row */ @@ -2978,11 +2978,11 @@ format_K(imagetoraster_doc_t *doc, /* - * 'format_KCMY()' - Convert image data to KCMY. + * 'format_kcmy()' - Convert image data to KCMY. */ static void -format_KCMY(imagetoraster_doc_t *doc, +format_kcmy(imagetoraster_doc_t *doc, cups_page_header2_t *header,/* I - Page header */ unsigned char *row, /* IO - Bitmap data for device */ int y, /* I - Current row */ @@ -3406,11 +3406,11 @@ format_KCMY(imagetoraster_doc_t *doc, /* - * 'format_KCMYcm()' - Convert image data to KCMYcm. + * 'format_kcmycm()' - Convert image data to KCMYcm. */ static void -format_KCMYcm( +format_kcmycm( imagetoraster_doc_t *doc, cups_page_header2_t *header, /* I - Page header */ unsigned char *row, /* IO - Bitmap data for device */ @@ -3584,11 +3584,11 @@ format_KCMYcm( /* - * 'format_RGBA()' - Convert image data to RGBA/RGBW. + * 'format_rgba()' - Convert image data to RGBA/RGBW. */ static void -format_RGBA(imagetoraster_doc_t *doc, +format_rgba(imagetoraster_doc_t *doc, cups_page_header2_t *header,/* I - Page header */ unsigned char *row, /* IO - Bitmap data for device */ int y, /* I - Current row */ @@ -3986,11 +3986,11 @@ format_RGBA(imagetoraster_doc_t *doc, /* - * 'format_W()' - Convert image data to luminance. + * 'format_w()' - Convert image data to luminance. */ static void -format_W(imagetoraster_doc_t *doc, +format_w(imagetoraster_doc_t *doc, cups_page_header2_t *header, /* I - Page header */ unsigned char *row, /* IO - Bitmap data for device */ int y, /* I - Current row */ @@ -4106,11 +4106,11 @@ format_W(imagetoraster_doc_t *doc, /* - * 'format_YMC()' - Convert image data to YMC. + * 'format_ymc()' - Convert image data to YMC. */ static void -format_YMC(imagetoraster_doc_t *doc, +format_ymc(imagetoraster_doc_t *doc, cups_page_header2_t *header, /* I - Page header */ unsigned char *row, /* IO - Bitmap data for device */ int y, /* I - Current row */ @@ -4497,11 +4497,11 @@ format_YMC(imagetoraster_doc_t *doc, /* - * 'format_YMCK()' - Convert image data to YMCK. + * 'format_ymck()' - Convert image data to YMCK. */ static void -format_YMCK(imagetoraster_doc_t *doc, +format_ymck(imagetoraster_doc_t *doc, cups_page_header2_t *header,/* I - Page header */ unsigned char *row, /* IO - Bitmap data for device */ int y, /* I - Current row */ diff --git a/cupsfilters/ipp.c b/cupsfilters/ipp.c index f3cffdc5f..68465ca47 100644 --- a/cupsfilters/ipp.c +++ b/cupsfilters/ipp.c @@ -56,7 +56,7 @@ convert_to_port(char *a) return (port); } -void +static void log_printf(char *log, const char *format, ...) { diff --git a/cupsfilters/mupdftopwg.c b/cupsfilters/mupdftopwg.c index 1e6846471..fcfe86ce1 100644 --- a/cupsfilters/mupdftopwg.c +++ b/cupsfilters/mupdftopwg.c @@ -62,7 +62,7 @@ typedef cups_page_header_t mupdf_page_header; #endif /* CUPS_RASTER_SYNCv1 */ -int +static int parse_doc_type(FILE *fp, cf_logfunc_t log, void *ld) { char buf[5]; diff --git a/cupsfilters/pclmtoraster.cxx b/cupsfilters/pclmtoraster.cxx index 7bf0b6789..06fd216b5 100644 --- a/cupsfilters/pclmtoraster.cxx +++ b/cupsfilters/pclmtoraster.cxx @@ -62,24 +62,24 @@ typedef struct pclmtoraster_data_s std::string colorspace; /* Colorspace of raster data */ } pclmtoraster_data_t; -typedef unsigned char *(*ConvertCSpace)(unsigned char *src, unsigned char *dst, +typedef unsigned char *(*convert_cspace_func)(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, pclmtoraster_data_t *data); -typedef unsigned char *(*ConvertLine) (unsigned char *src, unsigned char *dst, +typedef unsigned char *(*convert_line_func) (unsigned char *src, unsigned char *dst, unsigned char *buf, unsigned int row, unsigned int plane, pclmtoraster_data_t *data, - ConvertCSpace convertcspace); + convert_cspace_func convertcspace); typedef struct conversion_function_s { - ConvertCSpace convertcspace; /* Function for conversion of colorspaces */ - ConvertLine convertline; /* Function tom modify raster data of a line */ + convert_cspace_func convertcspace; /* Function for conversion of colorspaces */ + convert_line_func convertline; /* Function tom modify raster data of a line */ } conversion_function_t; static int -parseOpts(cf_filter_data_t *data, cf_filter_out_format_t outformat, +parse_opts(cf_filter_data_t *data, cf_filter_out_format_t outformat, pclmtoraster_data_t *pclmtoraster_data) { int num_options = 0; @@ -266,7 +266,7 @@ parseOpts(cf_filter_data_t *data, cf_filter_out_format_t outformat, } static bool -mediaboxlookup(QPDFObjectHandle object, +media_box_lookup(QPDFObjectHandle object, float rect[4]) { // preliminary checks @@ -285,12 +285,12 @@ mediaboxlookup(QPDFObjectHandle object, } /* - * 'rotatebitmap()' - Function to rotate a bitmap + * 'rotate_bitmap()' - Function to rotate a bitmap * (assumed that bits-per-component of the bitmap is 8). */ static unsigned char * /* O - Output Bitmap */ -rotatebitmap(unsigned char *src, /* I - Input string */ +rotate_bitmap(unsigned char *src, /* I - Input string */ unsigned char *dst, /* O - Destination string */ unsigned int rotate, /* I - Rotate value (0, 90, 180, 270) */ unsigned int height, /* I - Height of raster image in pixels */ @@ -450,7 +450,7 @@ rotatebitmap(unsigned char *src, /* I - Input string */ } static unsigned char * -RGBtoCMYKLine(unsigned char *src, +rgb_to_cmyk_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -461,7 +461,7 @@ RGBtoCMYKLine(unsigned char *src, } static unsigned char * -RGBtoCMYLine(unsigned char *src, +rgb_to_cmy_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -472,7 +472,7 @@ RGBtoCMYLine(unsigned char *src, } static unsigned char * -RGBtoWhiteLine(unsigned char *src, +rgb_to_white_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -489,7 +489,7 @@ RGBtoWhiteLine(unsigned char *src, } static unsigned char * -RGBtoBlackLine(unsigned char *src, +rgb_to_black_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -505,7 +505,7 @@ RGBtoBlackLine(unsigned char *src, } static unsigned char * -CMYKtoRGBLine(unsigned char *src, +cmyk_to_rgb_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -516,7 +516,7 @@ CMYKtoRGBLine(unsigned char *src, } static unsigned char * -CMYKtoCMYLine(unsigned char *src, +cmyk_to_cmy_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -529,7 +529,7 @@ CMYKtoCMYLine(unsigned char *src, } static unsigned char * -CMYKtoWhiteLine(unsigned char *src, +cmyk_to_white_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -545,7 +545,7 @@ CMYKtoWhiteLine(unsigned char *src, } static unsigned char * -CMYKtoBlackLine(unsigned char *src, +cmyk_to_black_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -561,7 +561,7 @@ CMYKtoBlackLine(unsigned char *src, } static unsigned char * -GraytoRGBLine(unsigned char *src, +gray_to_rgb_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -572,7 +572,7 @@ GraytoRGBLine(unsigned char *src, } static unsigned char * -GraytoCMYKLine(unsigned char *src, +gray_to_cmyk_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -583,7 +583,7 @@ GraytoCMYKLine(unsigned char *src, } static unsigned char * -GraytoCMYLine(unsigned char *src, +gray_to_cmy_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -594,7 +594,7 @@ GraytoCMYLine(unsigned char *src, } static unsigned char * -GraytoBlackLine(unsigned char *src, +gray_to_black_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -610,7 +610,7 @@ GraytoBlackLine(unsigned char *src, } static unsigned char * -convertcspaceNoop(unsigned char *src, +convert_cspace_no_op(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int pixels, @@ -620,18 +620,18 @@ convertcspaceNoop(unsigned char *src, } /* - * 'convertLine()' - Function to convert colorspace and bits-per-pixel + * 'convert_line()' - Function to convert colorspace and bits-per-pixel * of a single line of raster data. */ static unsigned char * /* O - Output string */ -convertLine(unsigned char *src, /* I - Input line */ +convert_line(unsigned char *src, /* I - Input line */ unsigned char *dst, /* O - Destination string */ unsigned char *buf, /* I - Buffer string */ unsigned int row, /* I - Current Row */ unsigned int plane, /* I - Plane/Band */ pclmtoraster_data_t *data, - ConvertCSpace convertcspace) + convert_cspace_func convertcspace) { /* Use only convertcspace if conversion of bits and conversion of color order @@ -664,13 +664,13 @@ convertLine(unsigned char *src, /* I - Input line */ } /* - * 'convertReverseLine()' - Function to convert colorspace and bits-per-pixel + * 'convert_reverse_line()' - Function to convert colorspace and bits-per-pixel * of a single line of raster data and reverse the * line. */ static unsigned char * /* O - Output string */ -convertReverseLine(unsigned char *src, /* I - Input line */ +convert_reverse_line(unsigned char *src, /* I - Input line */ unsigned char *dst, /* O - Destination string */ unsigned char *buf, /* I - Buffer string */ @@ -678,7 +678,7 @@ convertReverseLine(unsigned char *src, /* I - Input line */ unsigned int plane, /* I - Plane/Band */ pclmtoraster_data_t *data, /* I - pclmtoraster filter data */ - ConvertCSpace convertcspace) /* I - Function for + convert_cspace_func convertcspace) /* I - Function for conversion of colorspace */ { @@ -728,7 +728,7 @@ convertReverseLine(unsigned char *src, /* I - Input line */ } static void /* O - Exit status */ -selectConvertFunc(int pgno, /* I - Page number */ +select_convert_func(int pgno, /* I - Page number */ cf_logfunc_t log, /* I - Log function */ void *ld, /* I - Aux. data for log function */ @@ -765,64 +765,64 @@ selectConvertFunc(int pgno, /* I - Page number */ data->numcolors = 3; } - convert->convertcspace = convertcspaceNoop; //Default function + convert->convertcspace = convert_cspace_no_op; //Default function /* Select convertcspace function */ switch (header.cupsColorSpace) { case CUPS_CSPACE_K: - if (colorspace == "/DeviceRGB") convert->convertcspace = RGBtoBlackLine; + if (colorspace == "/DeviceRGB") convert->convertcspace = rgb_to_black_line; else if (colorspace == "/DeviceCMYK") convert->convertcspace = - CMYKtoBlackLine; + cmyk_to_black_line; else if (colorspace == "/DeviceGray") convert->convertcspace = - GraytoBlackLine; + gray_to_black_line; break; case CUPS_CSPACE_W: case CUPS_CSPACE_SW: - if (colorspace == "/DeviceRGB") convert->convertcspace = RGBtoWhiteLine; + if (colorspace == "/DeviceRGB") convert->convertcspace = rgb_to_white_line; else if (colorspace == "/DeviceCMYK") convert->convertcspace = - CMYKtoWhiteLine; + cmyk_to_white_line; break; case CUPS_CSPACE_CMY: - if (colorspace == "/DeviceRGB") convert->convertcspace = RGBtoCMYLine; + if (colorspace == "/DeviceRGB") convert->convertcspace = rgb_to_cmy_line; else if (colorspace == "/DeviceCMYK") convert->convertcspace = - CMYKtoCMYLine; + cmyk_to_cmy_line; else if (colorspace == "/DeviceGray") convert->convertcspace = - GraytoCMYLine; + gray_to_cmy_line; break; case CUPS_CSPACE_CMYK: - if (colorspace == "/DeviceRGB") convert->convertcspace = RGBtoCMYKLine; + if (colorspace == "/DeviceRGB") convert->convertcspace = rgb_to_cmyk_line; else if (colorspace == "/DeviceGray") convert->convertcspace = - GraytoCMYKLine; + gray_to_cmyk_line; break; case CUPS_CSPACE_RGB: case CUPS_CSPACE_ADOBERGB: case CUPS_CSPACE_SRGB: default: - if (colorspace == "/DeviceCMYK") convert->convertcspace = CMYKtoRGBLine; + if (colorspace == "/DeviceCMYK") convert->convertcspace = cmyk_to_rgb_line; else if (colorspace == "/DeviceGray") convert->convertcspace = - GraytoRGBLine; + gray_to_rgb_line; break; } /* Select convertline function */ if (header.Duplex && (pgno & 1) && data->swap_image_x) { - convert->convertline = convertReverseLine; + convert->convertline = convert_reverse_line; } else { - convert->convertline = convertLine; + convert->convertline = convert_line; } } /* - * 'outPage()' - Function to convert a single page of raster-only PDF/PCLm + * 'out_page()' - Function to convert a single page of raster-only PDF/PCLm * input to CUPS/PWG Raster. */ static int /* O - Exit status */ -outPage(cups_raster_t* raster, /* I - Raster stream */ +out_page(cups_raster_t* raster, /* I - Raster stream */ QPDFObjectHandle page, /* I - QPDF Page Object */ int pgno, /* I - Page number */ cf_logfunc_t log, /* I - Log function */ @@ -853,7 +853,7 @@ outPage(cups_raster_t* raster, /* I - Raster stream */ rotate = page.getKey("/Rotate").getIntValueAsInt(); // Get pagesize by the mediabox key of the page. - if (!mediaboxlookup(page, mediaBox)) + if (!media_box_lookup(page, mediaBox)) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterPCLmToRaster: PDF page %d doesn't contain a valid mediaBox", @@ -1015,7 +1015,7 @@ outPage(cups_raster_t* raster, /* I - Raster stream */ // Default for pclm files in DeviceRGB /* Select convertline and convertscpace function */ - selectConvertFunc(pgno, log, ld, data, convert); + select_convert_func(pgno, log, ld, data, convert); // If page is to be swapped in both x and y, rotate it by 180 degress if (data->header.Duplex && (pgno & 1) && data->swap_image_y && @@ -1030,7 +1030,7 @@ outPage(cups_raster_t* raster, /* I - Raster stream */ if (rotate) { unsigned char *bitmap2 = (unsigned char *) malloc(pixel_count); - bitmap2 = rotatebitmap(bitmap, bitmap2, rotate, data->header.cupsHeight, + bitmap2 = rotate_bitmap(bitmap, bitmap2, rotate, data->header.cupsHeight, data->header.cupsWidth, data->rowsize, data->colorspace, log, ld); free(bitmap); @@ -1165,7 +1165,7 @@ cfFilterPCLmToRaster(int inputfd, /* I - File descriptor input stream */ filename = tempfile; pdf->processFile(filename); - if (parseOpts(data, outformat, &pclmtoraster_data) != 0) + if (parse_opts(data, outformat, &pclmtoraster_data) != 0) { delete(pdf); unlink(tempfile); @@ -1234,7 +1234,7 @@ cfFilterPCLmToRaster(int inputfd, /* I - File descriptor input stream */ if (log) log(ld, CF_LOGLEVEL_INFO, "cfFilterPCLmToRaster: Starting page %d.", i+1); - if (outPage(raster, pages[i], i, log, ld, &pclmtoraster_data,data, + if (out_page(raster, pages[i], i, log, ld, &pclmtoraster_data,data, &convert) != 0) break; } diff --git a/cupsfilters/pdf.cxx b/cupsfilters/pdf.cxx index 2102161d8..d768f4547 100644 --- a/cupsfilters/pdf.cxx +++ b/cupsfilters/pdf.cxx @@ -39,11 +39,11 @@ /** - * 'makeRealBox()' - Return a QPDF array object of real values for a box. + * 'make_real_box()' - Return a QPDF array object of real values for a box. * O - QPDFObjectHandle for an array * I - Dimensions of the box in a float array */ -static QPDFObjectHandle makeRealBox(float values[4]) +static QPDFObjectHandle make_real_box(float values[4]) { QPDFObjectHandle ret = QPDFObjectHandle::newArray(); for (int i = 0; i < 4; ++i) { @@ -320,7 +320,7 @@ extern "C" int cfPDFResizePage (cf_pdf_t *pdf, return (1); fit_rect(old_mediabox, new_mediabox, scale); - media_box = makeRealBox(new_mediabox); + media_box = make_real_box(new_mediabox); page.replaceKey("/ArtBox", media_box); page.replaceKey("/BleedBox", media_box); @@ -377,7 +377,7 @@ extern "C" void cfPDFWrite(cf_pdf_t *pdf, FILE *file) * O - character string which corresponds to the value of the key or * NULL if key is not found in the list. */ -std::string lookup_opt(cf_opt_t *opt, std::string const& key) { +static std::string lookup_opt(cf_opt_t *opt, std::string const& key) { if ( ! opt || key.empty() ) { return ""; } diff --git a/cupsfilters/pdftopdf/intervalset.cc b/cupsfilters/pdftopdf/intervalset.cc index efff5e04b..ab5ae776f 100644 --- a/cupsfilters/pdftopdf/intervalset.cc +++ b/cupsfilters/pdftopdf/intervalset.cc @@ -4,15 +4,15 @@ #include #include -const IntervalSet::key_t IntervalSet::npos=std::numeric_limits::max(); +const _cfPDFToPDFIntervalSet::key_t _cfPDFToPDFIntervalSet::npos=std::numeric_limits<_cfPDFToPDFIntervalSet::key_t>::max(); -void IntervalSet::clear() // {{{ +void _cfPDFToPDFIntervalSet::clear() // {{{ { data.clear(); } // }}} -void IntervalSet::add(key_t start,key_t end) // {{{ +void _cfPDFToPDFIntervalSet::add(key_t start,key_t end) // {{{ { if (start=b.first) && (a.first=a.first) && (b.first #include -class IntervalSet { +class _cfPDFToPDFIntervalSet { typedef int key_t; // TODO?! template - typedef std::pair value_t; + typedef std::pair value_t; typedef std::vector data_t; public: static const key_t npos; void clear(); - // [start;end) ! - void add(key_t start,key_t end=npos); + // [start; end) ! + void add(key_t start, key_t end = npos); void finish(); size_t size() const { return data.size(); } @@ -26,8 +26,8 @@ class IntervalSet { void dump(pdftopdf_doc_t *doc) const; private: // currently not used - bool intersect(const value_t &a,const value_t &b) const; - void unite(value_t &aret,const value_t &b) const; + bool intersect(const value_t &a, const value_t &b) const; + void unite(value_t &aret, const value_t &b) const; private: data_t data; }; diff --git a/cupsfilters/pdftopdf/nup.cc b/cupsfilters/pdftopdf/nup.cc index 64ac29149..c218a85ec 100644 --- a/cupsfilters/pdftopdf/nup.cc +++ b/cupsfilters/pdftopdf/nup.cc @@ -4,7 +4,7 @@ #include #include -void NupParameters::dump(pdftopdf_doc_t *doc) const // {{{ +void _cfPDFToPDFNupParameters::dump(pdftopdf_doc_t *doc) const // {{{ { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: NupX: %d, NupY: %d, " @@ -13,21 +13,21 @@ void NupParameters::dump(pdftopdf_doc_t *doc) const // {{{ width,height); int opos=-1,fpos=-1,spos=-1; - if (xstart==Position::LEFT) { // or Bottom + if (xstart==pdftopdf_position_e::LEFT) { // or Bottom fpos=0; - } else if (xstart==Position::RIGHT) { // or Top + } else if (xstart==pdftopdf_position_e::RIGHT) { // or Top fpos=1; } - if (ystart==Position::LEFT) { // or Bottom + if (ystart==pdftopdf_position_e::LEFT) { // or Bottom spos=0; - } else if (ystart==Position::RIGHT) { // or Top + } else if (ystart==pdftopdf_position_e::RIGHT) { // or Top spos=1; } - if (first==Axis::X) { + if (first==pdftopdf_axis_e::X) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: First Axis: X"); opos=0; - } else if (first==Axis::Y) { + } else if (first==pdftopdf_axis_e::Y) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: First Axis: Y"); opos=2; @@ -47,12 +47,12 @@ void NupParameters::dump(pdftopdf_doc_t *doc) const // {{{ if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: Alignment:"); - Position_dump(xalign,Axis::X,doc); - Position_dump(yalign,Axis::Y,doc); + _cfPDFToPDFPositionDump(xalign,pdftopdf_axis_e::X,doc); + _cfPDFToPDFPositionDump(yalign,pdftopdf_axis_e::Y,doc); } // }}} -bool NupParameters::possible(int nup) // {{{ +bool _cfPDFToPDFNupParameters::possible(int nup) // {{{ { // 1 2 3 4 6 8 9 10 12 15 16 return (nup>=1)&&(nup<=16)&& @@ -60,7 +60,7 @@ bool NupParameters::possible(int nup) // {{{ } // }}} -void NupParameters::preset(int nup,NupParameters &ret) // {{{ +void _cfPDFToPDFNupParameters::preset(int nup,_cfPDFToPDFNupParameters &ret) // {{{ { switch (nup) { case 1: @@ -118,7 +118,7 @@ void NupParameters::preset(int nup,NupParameters &ret) // {{{ // }}} -NupState::NupState(const NupParameters ¶m) // {{{ +_cfPDFToPDFNupState::_cfPDFToPDFNupState(const _cfPDFToPDFNupParameters ¶m) // {{{ : param(param), in_pages(0),out_pages(0), nup(param.nupX*param.nupY), @@ -128,7 +128,7 @@ NupState::NupState(const NupParameters ¶m) // {{{ } // }}} -void NupState::reset() // {{{ +void _cfPDFToPDFNupState::reset() // {{{ { in_pages=0; out_pages=0; @@ -137,7 +137,7 @@ void NupState::reset() // {{{ } // }}} -void NupPageEdit::dump(pdftopdf_doc_t *doc) const // {{{ +void _cfPDFToPDFNupPageEdit::dump(pdftopdf_doc_t *doc) const // {{{ { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: xpos: %f, ypos: %f, scale: %f", @@ -146,10 +146,10 @@ void NupPageEdit::dump(pdftopdf_doc_t *doc) const // {{{ } // }}} -std::pair NupState::convert_order(int subpage) const // {{{ +std::pair _cfPDFToPDFNupState::convert_order(int subpage) const // {{{ { int subx,suby; - if (param.first==Axis::X) { + if (param.first==pdftopdf_axis_e::X) { subx=subpage%param.nupX; suby=subpage/param.nupX; } else { @@ -164,7 +164,7 @@ std::pair NupState::convert_order(int subpage) const // {{{ } // }}} -static inline float lin(Position pos,float size) // {{{ +static inline float lin(pdftopdf_position_e pos,float size) // {{{ { if (pos==-1) return 0; else if (pos==0) return size/2; @@ -173,7 +173,7 @@ static inline float lin(Position pos,float size) // {{{ } // }}} -void NupState::calculate_edit(int subx,int suby,NupPageEdit &ret) const // {{{ +void _cfPDFToPDFNupState::calculate_edit(int subx,int suby,_cfPDFToPDFNupPageEdit &ret) const // {{{ { // dimensions of a "nup cell" const float width=param.width/param.nupX, @@ -206,7 +206,7 @@ void NupState::calculate_edit(int subx,int suby,NupPageEdit &ret) const // {{{ } // }}} -bool NupState::nextPage(float in_width,float in_height,NupPageEdit &ret) // {{{ +bool _cfPDFToPDFNupState::mext_page(float in_width,float in_height,_cfPDFToPDFNupPageEdit &ret) // {{{ { in_pages++; subpage++; @@ -226,24 +226,24 @@ bool NupState::nextPage(float in_width,float in_height,NupPageEdit &ret) // {{{ // }}} -static std::pair parsePosition(char a,char b) // {{{ returns ,CENTER(0) on invalid +static std::pair parsePosition(char a,char b) // {{{ returns ,CENTER(0) on invalid { a|=0x20; // make lowercase b|=0x20; if ( (a=='l')&&(b=='r') ) { - return std::make_pair(Axis::X,Position::LEFT); + return std::make_pair(pdftopdf_axis_e::X,pdftopdf_position_e::LEFT); } else if ( (a=='r')&&(b=='l') ) { - return std::make_pair(Axis::X,Position::RIGHT); + return std::make_pair(pdftopdf_axis_e::X,pdftopdf_position_e::RIGHT); } else if ( (a=='t')&&(b=='b') ) { - return std::make_pair(Axis::Y,Position::TOP); + return std::make_pair(pdftopdf_axis_e::Y,pdftopdf_position_e::TOP); } else if ( (a=='b')&&(b=='t') ) { - return std::make_pair(Axis::Y,Position::BOTTOM); + return std::make_pair(pdftopdf_axis_e::Y,pdftopdf_position_e::BOTTOM); } - return std::make_pair(Axis::X,Position::CENTER); + return std::make_pair(pdftopdf_axis_e::X,pdftopdf_position_e::CENTER); } // }}} -bool parseNupLayout(const char *val,NupParameters &ret) // {{{ +bool _cfPDFToPDFParseNupLayout(const char *val,_cfPDFToPDFNupParameters &ret) // {{{ { assert(val); auto pos0=parsePosition(val[0],val[1]); @@ -256,7 +256,7 @@ bool parseNupLayout(const char *val,NupParameters &ret) // {{{ } ret.first=pos0.first; - if (ret.first==Axis::X) { + if (ret.first==pdftopdf_axis_e::X) { ret.xstart=pos0.second; ret.ystart=pos1.second; } else { diff --git a/cupsfilters/pdftopdf/nup.h b/cupsfilters/pdftopdf/nup.h index 3fa443cca..ce55ad7ac 100644 --- a/cupsfilters/pdftopdf/nup.h +++ b/cupsfilters/pdftopdf/nup.h @@ -1,91 +1,96 @@ -#ifndef NUP_H_ -#define NUP_H_ +#ifndef _CUPS_FILTERS_PDFTOPDF_NUP_H_ +#define _CUPS_FILTERS_PDFTOPDF_NUP_H_ #include "pptypes.h" #include // you have to provide this -struct NupParameters { - NupParameters() - : nupX(1),nupY(1), - width(NAN),height(NAN), +struct _cfPDFToPDFNupParameters { + _cfPDFToPDFNupParameters() + : nupX(1), nupY(1), + width(NAN), height(NAN), landscape(false), first(X), - xstart(LEFT),ystart(TOP), - xalign(CENTER),yalign(CENTER) + xstart(LEFT), ystart(TOP), + xalign(CENTER), yalign(CENTER) {} // --- "calculated" parameters --- - int nupX,nupY; - float width,height; + int nupX, nupY; + float width, height; bool landscape; // post-rotate! // --- other settings --- // ordering - Axis first; - Position xstart,ystart; + pdftopdf_axis_e first; + pdftopdf_position_e xstart, ystart; - Position xalign,yalign; + pdftopdf_position_e xalign, yalign; - static bool possible(int nup); // TODO? float in_ratio,float out_ratio - static void preset(int nup,NupParameters &ret); - static float calculate(int nup, float in_ratio, float out_ratio,NupParameters &ret); // returns "quality", 1 is best + static bool possible(int nup); // TODO? float in_ratio, float out_ratio + static void preset(int nup, _cfPDFToPDFNupParameters &ret); + static float calculate(int nup, float in_ratio, float out_ratio, + _cfPDFToPDFNupParameters &ret); // returns "quality", 1 is best void dump(pdftopdf_doc_t *doc) const; }; // you get this -struct NupPageEdit { +struct _cfPDFToPDFNupPageEdit { // required transformation: first translate, then scale - float xpos,ypos; // TODO: already given by sub.left,sub.bottom [but for rotation?] - float scale; // uniform + float xpos, ypos; // TODO: already given by sub.left, sub.bottom + // [but for rotation?] + float scale; // uniform -// ? "landscape" e.g. to rotate labels + // ? "landscape" e.g. to rotate labels // for border, clip, ... // also stores in_width/in_height, unscaled! // everything in "outer"-page coordinates - PageRect sub; + _cfPDFToPDFPageRect sub; void dump(pdftopdf_doc_t *doc) const; }; /* - This class does the number-up calculation. Example: + This class does the number-up calculation. Example: - NupParameters param; - param.xyz=...; // fill it with your data! + _cfPDFToPDFNupParameters param; + param.xyz = ...; // fill it with your data! - NupState nup(param); - NupPageEdit edit; - for (auto page : your_pages) { - bool newPage=nup.nextPage(page.w,page.h,edit); // w,h from input page + _cfPDFToPDFNupState nup(param); + _cfPDFToPDFNupPageEdit edit; + for (auto page : your_pages) + { + bool newPage = nup.mext_page(page.w, page.h, edit); // w, h from input page // create newPage, if required; then place current page as specified in edit } */ -class NupState { + +class _cfPDFToPDFNupState { public: - NupState(const NupParameters ¶m); + _cfPDFToPDFNupState(const _cfPDFToPDFNupParameters ¶m); void reset(); // will overwrite ret with the new parameters // returns true, if a new output page should be started first - bool nextPage(float in_width,float in_height,NupPageEdit &ret); + bool mext_page(float in_width, float in_height, _cfPDFToPDFNupPageEdit &ret); private: - std::pair convert_order(int subpage) const; - void calculate_edit(int subx,int suby,NupPageEdit &ret) const; + std::pair convert_order(int subpage) const; + void calculate_edit(int subx, int suby, _cfPDFToPDFNupPageEdit &ret) const; + private: - NupParameters param; + _cfPDFToPDFNupParameters param; - int in_pages,out_pages; - int nup; // max. per page (==nupX*nupY) + int in_pages, out_pages; + int nup; // max. per page (== nupX * nupY) int subpage; // on the current output-page }; // TODO? elsewhere -// parsing functions for cups parameters (will not calculate nupX,nupY!) -bool parseNupLayout(const char *val,NupParameters &ret); // lrtb, btlr, ... +// parsing functions for cups parameters (will not calculate nupX, nupY!) +bool _cfPDFToPDFParseNupLayout(const char *val, _cfPDFToPDFNupParameters &ret); // lrtb, btlr, ... #endif diff --git a/cupsfilters/pdftopdf/pdftopdf.cc b/cupsfilters/pdftopdf/pdftopdf.cc index 3bbe3eb46..eddd1f7e3 100644 --- a/cupsfilters/pdftopdf/pdftopdf.cc +++ b/cupsfilters/pdftopdf/pdftopdf.cc @@ -32,16 +32,16 @@ // namespace {} -void setFinalPPD(ppd_file_t *ppd,const ProcessingParameters ¶m) +void setFinalPPD(ppd_file_t *ppd,const _cfPDFToPDFProcessingParameters ¶m) { - if ((param.booklet==BOOKLET_ON)&&(ppdFindOption(ppd,"Duplex"))) { + if ((param.booklet==CF_PDFTOPDF_BOOKLET_ON)&&(ppdFindOption(ppd,"Duplex"))) { // TODO: elsewhere, better ppdMarkOption(ppd,"Duplex","DuplexTumble"); // TODO? sides=two-sided-short-edge } // for compatibility - if ((param.setDuplex)&&(ppdFindOption(ppd,"Duplex")!=NULL)) { + if ((param.set_duplex)&&(ppdFindOption(ppd,"Duplex")!=NULL)) { ppdMarkOption(ppd,"Duplex","True"); ppdMarkOption(ppd,"Duplex","On"); } @@ -194,19 +194,19 @@ static bool optGetCollate(int num_options,cups_option_t *options) // {{{ } // }}} -static bool parsePosition(const char *value,Position &xpos,Position &ypos) // {{{ +static bool parsePosition(const char *value,pdftopdf_position_e &xpos,pdftopdf_position_e &ypos) // {{{ { // ['center','top','left','right','top-left','top-right','bottom','bottom-left','bottom-right'] - xpos=Position::CENTER; - ypos=Position::CENTER; + xpos=pdftopdf_position_e::CENTER; + ypos=pdftopdf_position_e::CENTER; int next=0; if (strcasecmp(value,"center")==0) { return true; } else if (strncasecmp(value,"top",3)==0) { - ypos=Position::TOP; + ypos=pdftopdf_position_e::TOP; next=3; } else if (strncasecmp(value,"bottom",6)==0) { - ypos=Position::BOTTOM; + ypos=pdftopdf_position_e::BOTTOM; next=6; } if (next) { @@ -218,9 +218,9 @@ static bool parsePosition(const char *value,Position &xpos,Position &ypos) // {{ value+=next+1; } if (strcasecmp(value,"left")==0) { - xpos=Position::LEFT; + xpos=pdftopdf_position_e::LEFT; } else if (strcasecmp(value,"right")==0) { - xpos=Position::RIGHT; + xpos=pdftopdf_position_e::RIGHT; } else { return false; } @@ -229,7 +229,7 @@ static bool parsePosition(const char *value,Position &xpos,Position &ypos) // {{ // }}} #include -static void parseRanges(const char *range,IntervalSet &ret) // {{{ +static void parseRanges(const char *range,_cfPDFToPDFIntervalSet &ret) // {{{ { ret.clear(); if (!range) { @@ -276,19 +276,19 @@ static void parseRanges(const char *range,IntervalSet &ret) // {{{ } // }}} -static bool parseBorder(const char *val,BorderType &ret) // {{{ +static bool _cfPDFToPDFParseBorder(const char *val,pdftopdf_border_type_e &ret) // {{{ { assert(val); if (strcasecmp(val,"none")==0) { - ret=BorderType::NONE; + ret=pdftopdf_border_type_e::NONE; } else if (strcasecmp(val,"single")==0) { - ret=BorderType::ONE_THIN; + ret=pdftopdf_border_type_e::ONE_THIN; } else if (strcasecmp(val,"single-thick")==0) { - ret=BorderType::ONE_THICK; + ret=pdftopdf_border_type_e::ONE_THICK; } else if (strcasecmp(val,"double")==0) { - ret=BorderType::TWO_THIN; + ret=pdftopdf_border_type_e::TWO_THIN; } else if (strcasecmp(val,"double-thick")==0) { - ret=BorderType::TWO_THICK; + ret=pdftopdf_border_type_e::TWO_THICK; } else { return false; } @@ -296,7 +296,7 @@ static bool parseBorder(const char *val,BorderType &ret) // {{{ } // }}} -void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options,ProcessingParameters ¶m,char *final_content_type,pdftopdf_doc_t *doc) // {{{ +void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options,_cfPDFToPDFProcessingParameters ¶m,char *final_content_type,pdftopdf_doc_t *doc) // {{{ { ppd_file_t *ppd = data->ppd; @@ -310,14 +310,14 @@ void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options (val = cupsGetOption("NumCopies", num_options, options))!=NULL) { int copies = atoi(val); if (copies > 0) - param.numCopies = copies; + param.num_copies = copies; } - // param.numCopies initially from commandline - if (param.numCopies==1) { - ppdGetInt(ppd,"Copies",¶m.numCopies); + // param.num_copies initially from commandline + if (param.num_copies==1) { + ppdGetInt(ppd,"Copies",¶m.num_copies); } - if (param.numCopies==0) { - param.numCopies=1; + if (param.num_copies==0) { + param.num_copies=1; } if((val = cupsGetOption("ipp-attribute-fidelity",num_options,options))!=NULL) { @@ -386,13 +386,13 @@ void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options "cfFilterPDFToPDF: Bad value (%d) for " "orientation-requested, using 0 degrees", ipprot); - param.noOrientation = true; + param.no_orientation = true; } else { - static const Rotation ipp2rot[4]={ROT_0, ROT_90, ROT_270, ROT_180}; + static const pdftopdf_rotation_e ipp2rot[4]={ROT_0, ROT_90, ROT_270, ROT_180}; param.orientation=ipp2rot[ipprot-3]; } } else { - param.noOrientation = true; + param.no_orientation = true; } ppd_size_t *pagesize; @@ -458,7 +458,7 @@ void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options } param.paper_is_landscape=(param.page.width>param.page.height); - PageRect tmp; // borders (before rotation) + _cfPDFToPDFPageRect tmp; // borders (before rotation) optGetFloat("page-top",num_options,options,&tmp.top); optGetFloat("page-left",num_options,options,&tmp.left); @@ -495,12 +495,12 @@ void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options param.duplex=true; } else if (is_true(cupsGetOption("Duplex",num_options,options))) { param.duplex=true; - param.setDuplex=true; + param.set_duplex=true; } else if ((val=cupsGetOption("sides",num_options,options)) != NULL) { if ((strcasecmp(val,"two-sided-long-edge")==0)|| (strcasecmp(val,"two-sided-short-edge")==0)) { param.duplex=true; - param.setDuplex=true; + param.set_duplex=true; } else if (strcasecmp(val,"one-sided")!=0) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: Unsupported sides value %s, " @@ -511,34 +511,34 @@ void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options // default nup is 1 int nup=1; if (optGetInt("number-up",num_options,options,&nup)) { - if (!NupParameters::possible(nup)) { + if (!_cfPDFToPDFNupParameters::possible(nup)) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: Unsupported number-up value " "%d, using number-up=1!", nup); nup=1; } // TODO ; TODO? nup enabled? ... fitplot -// NupParameters::calculate(nup,param.nup); - NupParameters::preset(nup,param.nup); +// _cfPDFToPDFNupParameters::calculate(nup,param.nup); + _cfPDFToPDFNupParameters::preset(nup,param.nup); } if ((val=cupsGetOption("number-up-layout",num_options,options)) != NULL) { - if (!parseNupLayout(val,param.nup)) { + if (!_cfPDFToPDFParseNupLayout(val,param.nup)) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: Unsupported number-up-layout " "%s, using number-up-layout=lrtb!" ,val); - param.nup.first=Axis::X; - param.nup.xstart=Position::LEFT; - param.nup.ystart=Position::TOP; + param.nup.first=pdftopdf_axis_e::X; + param.nup.xstart=pdftopdf_position_e::LEFT; + param.nup.ystart=pdftopdf_position_e::TOP; } } if ((val=cupsGetOption("page-border",num_options,options)) != NULL) { - if (!parseBorder(val,param.border)) { + if (!_cfPDFToPDFParseBorder(val,param.border)) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: Unsupported page-border value " "%s, using page-border=none!", val); - param.border=BorderType::NONE; + param.border=pdftopdf_border_type_e::NONE; } } @@ -571,13 +571,13 @@ void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options else cookedlabel.put (*it); } - param.pageLabel = cookedlabel.str (); + param.page_label = cookedlabel.str (); if ((val=cupsGetOption("page-set",num_options,options)) != NULL) { if (strcasecmp(val,"even")==0) { - param.oddPages=false; + param.odd_pages=false; } else if (strcasecmp(val,"odd")==0) { - param.evenPages=false; + param.even_pages=false; } else if (strcasecmp(val,"all")!=0) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: Unsupported page-set value %s, " @@ -586,11 +586,11 @@ void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options } if ((val=cupsGetOption("page-ranges",num_options,options)) != NULL) { - parseRanges(val,param.pageRange); + parseRanges(val,param.page_ranges); } if ((val=cupsGetOption("input-page-ranges",num_options,options)) !=NULL){ - parseRanges(val,param.inputPageRange); + parseRanges(val,param.input_page_ranges); } ppd_choice_t *choice; @@ -605,29 +605,29 @@ void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options if ((val=cupsGetOption("emit-jcl",num_options,options)) != NULL) { - param.emitJCL=!is_false(val)&&(strcmp(val,"0")!=0); + param.emit_jcl=!is_false(val)&&(strcmp(val,"0")!=0); } - param.booklet=BookletMode::BOOKLET_OFF; + param.booklet=pdftopdf_booklet_mode_e::CF_PDFTOPDF_BOOKLET_OFF; if ((val=cupsGetOption("booklet",num_options,options)) != NULL) { if (strcasecmp(val,"shuffle-only")==0) { - param.booklet=BookletMode::BOOKLET_JUSTSHUFFLE; + param.booklet=pdftopdf_booklet_mode_e::CF_PDFTOPDF_BOOKLET_JUST_SHUFFLE; } else if (is_true(val)) { - param.booklet=BookletMode::BOOKLET_ON; + param.booklet=pdftopdf_booklet_mode_e::CF_PDFTOPDF_BOOKLET_ON; } else if (!is_false(val)) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: Unsupported booklet value %s, " "using booklet=off!", val); } } - param.bookSignature=-1; - if (optGetInt("booklet-signature",num_options,options,¶m.bookSignature)) { - if (param.bookSignature==0) { + param.book_signature=-1; + if (optGetInt("booklet-signature",num_options,options,¶m.book_signature)) { + if (param.book_signature==0) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: Unsupported booklet-signature " "value, using booklet-signature=-1 " "(all)!", val); - param.bookSignature=-1; + param.book_signature=-1; } } @@ -636,8 +636,8 @@ void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: Unrecognized position value " "%s, using position=center!", val); - param.xpos=Position::CENTER; - param.ypos=Position::CENTER; + param.xpos=pdftopdf_position_e::CENTER; + param.ypos=pdftopdf_position_e::CENTER; } } @@ -677,14 +677,14 @@ bool checkFeature(const char *feature, int num_options, cups_option_t *options) // FIXME? pdftopdf also supports it as cmdline option (via checkFeature()) ppd_attr_t *attr; if ((attr=ppdFindAttr(ppd,"cupsEvenDuplex",0)) != NULL) { - param.evenDuplex=is_true(attr->value); + param.even_duplex=is_true(attr->value); } // TODO? pdftopdf* ? // TODO?! pdftopdfAutoRotate // TODO?! choose default by whether pdfautoratate filter has already been run (e.g. by mimetype) - param.autoRotate=(!is_false(cupsGetOption("pdfAutoRotate",num_options,options)) && + param.auto_rotate=(!is_false(cupsGetOption("pdfAutoRotate",num_options,options)) && !is_false(cupsGetOption("pdftopdfAutoRotate",num_options,options))); // Do we have to do the page logging in page_log? @@ -896,24 +896,24 @@ static bool printerWillCollate(ppd_file_t *ppd) // {{{ } // }}} -void calculate(cf_filter_data_t *data,ProcessingParameters ¶m,char *final_content_type) // {{{ +void calculate(cf_filter_data_t *data,_cfPDFToPDFProcessingParameters ¶m,char *final_content_type) // {{{ { ppd_file_t *ppd = data->ppd; int num_options = 0; cups_option_t *options = NULL; num_options = cfJoinJobOptionsAndAttrs(data, num_options, &options); if (param.reverse) - // Enable evenDuplex or the first page may be empty. - param.evenDuplex=true; // disabled later, if non-duplex + // Enable even_duplex or the first page may be empty. + param.even_duplex=true; // disabled later, if non-duplex setFinalPPD(ppd,param); - if (param.numCopies==1) { - param.deviceCopies=1; + if (param.num_copies==1) { + param.device_copies=1; // collate is never needed for a single copy param.collate=false; // (does not make a big difference for us) } else if ((ppd)&&(!ppd->manual_copies)) { // hw copy generation available - param.deviceCopies=param.numCopies; + param.device_copies=param.num_copies; if (param.collate) { // collate requested by user // Check output format (FINAL_CONTENT_TYPE env variable) whether it is // of a driverless IPP printer (PDF, Apple Raster, PWG Raster, PCLm). @@ -925,50 +925,50 @@ void calculate(cf_filter_data_t *data,ProcessingParameters ¶m,char *final_co strcasestr(final_content_type, "/pwg-raster") || strcasestr(final_content_type, "/urf") || strcasestr(final_content_type, "/PCLm"))) { - param.deviceCollate = true; + param.device_collate = true; } else { // check collate device, with current/final(!) ppd settings - param.deviceCollate=printerWillCollate(ppd); - if (!param.deviceCollate) { + param.device_collate=printerWillCollate(ppd); + if (!param.device_collate) { // printer can't hw collate -> we must copy collated in sw - param.deviceCopies=1; + param.device_copies=1; } } - } // else: printer copies w/o collate and takes care of duplex/evenDuplex + } // else: printer copies w/o collate and takes care of duplex/even_duplex } else if(final_content_type && ((strcasestr(final_content_type, "/pdf")) || (strcasestr(final_content_type, "/vnd.cups-pdf")))){ - param.deviceCopies = param.numCopies; + param.device_copies = param.num_copies; if(param.collate){ - param.deviceCollate = true; + param.device_collate = true; } } else { // sw copies - param.deviceCopies=1; - if (param.duplex) { // &&(numCopies>1) - // sw collate + evenDuplex must be forced to prevent copies on the backsides + param.device_copies=1; + if (param.duplex) { // &&(num_copies>1) + // sw collate + even_duplex must be forced to prevent copies on the backsides param.collate=true; - param.deviceCollate=false; + param.device_collate=false; } } // TODO? FIXME: unify code with emitJCLOptions, which does this "by-hand" now (and makes this code superfluous) - if (param.deviceCopies==1) { + if (param.device_copies==1) { // make sure any hardware copying is disabled ppdMarkOption(ppd,"Copies","1"); ppdMarkOption(ppd,"JCLCopies","1"); } else { // hw copy - param.numCopies=1; // disable sw copy + param.num_copies=1; // disable sw copy } - if ((param.collate)&&(!param.deviceCollate)) { // software collate + if ((param.collate)&&(!param.device_collate)) { // software collate ppdMarkOption(ppd,"Collate","False"); // disable any hardware-collate (in JCL) - param.evenDuplex=true; // fillers always needed + param.even_duplex=true; // fillers always needed } if (!param.duplex) { - param.evenDuplex=false; + param.even_duplex=false; } } // }}} @@ -1060,12 +1060,12 @@ cfFilterPDFToPDF(int inputfd, /* I - File descriptor input stream */ final_content_type = (char *)parameters; try { - ProcessingParameters param; + _cfPDFToPDFProcessingParameters param; - param.jobId=data->job_id; + param.job_id=data->job_id; param.user=data->job_user; param.title=data->job_title; - param.numCopies=data->copies; + param.num_copies=data->copies; param.copies_to_be_logged=data->copies; // TODO?! sanity checks @@ -1096,7 +1096,7 @@ cfFilterPDFToPDF(int inputfd, /* I - File descriptor input stream */ "cfFilterPDFToPDF: Streaming mode: No PDF processing, only adding of JCL"); } - std::unique_ptr proc(PDFTOPDF_Factory::processor()); + std::unique_ptr<_cfPDFToPDFProcessor> proc(_cfPDFToPDFFactory::processor()); if ((inputseekable && inputfd > 0) || streaming) { if ((inputfp = fdopen(inputfd, "rb")) == NULL) @@ -1118,17 +1118,17 @@ cfFilterPDFToPDF(int inputfd, /* I - File descriptor input stream */ "cfFilterPDFToPDF: Processing PDF input with QPDF: Page-ranges, page-set, number-up, booklet, size adjustment, ..."); // Load the PDF input data into QPDF - if (!proc->loadFile(inputfp, &doc, WillStayAlive, 1)) { + if (!proc->load_file(inputfp, &doc, CF_PDFTOPDF_WILL_STAY_ALIVE, 1)) { fclose(inputfp); return 1; } // Process the PDF input data - if (!processPDFTOPDF(*proc, param, &doc)) + if (!_cfProcessPDFToPDF(*proc, param, &doc)) return 2; // Pass information to subsequent filters via PDF comments - emitComment(*proc, param); + _cfPDFToPDFEmitComment(*proc, param); } /* TODO @@ -1140,7 +1140,7 @@ cfFilterPDFToPDF(int inputfd, /* I - File descriptor input stream */ copyPPDLine_(fp_dest, fp_src, "*ColorDevice:"); copyPPDLine_(fp_dest, fp_src, "*DefaultColorSpace:"); if (cupsICCProfile) { - proc.addCM(...,...); + proc.add_cm(...,...); } */ @@ -1148,12 +1148,12 @@ cfFilterPDFToPDF(int inputfd, /* I - File descriptor input stream */ if (outputfp == NULL) return 1; - emitPreamble(outputfp, data->ppd, param); // ppdEmit, JCL stuff + _cfPDFToPDFEmitPreamble(outputfp, data->ppd, param); // ppdEmit, JCL stuff if (!streaming) { // Pass on the processed input data - proc->emitFile(outputfp, &doc, WillStayAlive); - // proc->emitFilename(NULL); + proc->emit_file(outputfp, &doc, CF_PDFTOPDF_WILL_STAY_ALIVE); + // proc->emit_filename(NULL); } else { // Pass through the input data if (log) log(ld, CF_LOGLEVEL_DEBUG, @@ -1164,7 +1164,7 @@ cfFilterPDFToPDF(int inputfd, /* I - File descriptor input stream */ fclose(inputfp); } - emitPostamble(outputfp, data->ppd,param); + _cfPDFToPDFEmitPostamble(outputfp, data->ppd,param); fclose(outputfp); } catch (std::exception &e) { // TODO? exception type diff --git a/cupsfilters/pdftopdf/pdftopdf.h b/cupsfilters/pdftopdf/pdftopdf.h index 4c77d956b..ae3e10671 100644 --- a/cupsfilters/pdftopdf/pdftopdf.h +++ b/cupsfilters/pdftopdf/pdftopdf.h @@ -2,20 +2,20 @@ // Copyright 2020 by Jai Luthra. // -#ifndef PDFTOPDF_H -#define PDFTOPDF_H +#ifndef _CUPS_FILTERS_PDFTOPDF_PDFTOPDF_H +#define _CUPS_FILTERS_PDFTOPDF_PDFTOPDF_H #include -typedef struct /***** Document information *****/ +typedef struct /***** Document information *****/ { - cf_logfunc_t logfunc; /* Log function */ - void *logdata; /* Log data */ + cf_logfunc_t logfunc; /* Log function */ + void *logdata; /* Log data */ cf_filter_iscanceledfunc_t iscanceledfunc; /* Function returning 1 when - job is canceled, NULL for not - supporting stop on cancel */ - void *iscanceleddata; /* User data for is-canceled function, can be - NULL */ + job is canceled, NULL for not + supporting stop on cancel */ + void *iscanceleddata; /* User data for is-canceled + function, can be NULL */ } pdftopdf_doc_t; #endif diff --git a/cupsfilters/pdftopdf/pdftopdf_jcl.cc b/cupsfilters/pdftopdf/pdftopdf_jcl.cc index 5545744f4..6e7f3d504 100644 --- a/cupsfilters/pdftopdf/pdftopdf_jcl.cc +++ b/cupsfilters/pdftopdf/pdftopdf_jcl.cc @@ -6,7 +6,7 @@ // TODO: -currently changes ppd. (Copies) // -static void emitJCLOptions(FILE *fp, ppd_file_t *ppd, int deviceCopies) // {{{ +static void emitJCLOptions(FILE *fp, ppd_file_t *ppd, int device_copies) // {{{ { int section; ppd_choice_t **choices; @@ -31,7 +31,7 @@ static void emitJCLOptions(FILE *fp, ppd_file_t *ppd, int deviceCopies) // {{{ } } - snprintf(buf,sizeof(buf),"%d",deviceCopies); + snprintf(buf,sizeof(buf),"%d",device_copies); if (ppdFindOption(ppd,"Copies") != NULL) { ppdMarkOption(ppd,"Copies",buf); } else { @@ -39,7 +39,7 @@ static void emitJCLOptions(FILE *fp, ppd_file_t *ppd, int deviceCopies) // {{{ fputs(attr->value,fp); datawritten=true; } else if (withJCL) { - fprintf(fp,"Copies=%d;",deviceCopies); + fprintf(fp,"Copies=%d;",device_copies); datawritten=true; } } @@ -66,7 +66,7 @@ static void emitJCLOptions(FILE *fp, ppd_file_t *ppd, int deviceCopies) // {{{ } // }}} -/* Copied ppd_decode() from CUPS which is not exported to the API; needed in emitPreamble() */ +/* Copied ppd_decode() from CUPS which is not exported to the API; needed in _cfPDFToPDFEmitPreamble() */ // {{{ static int ppd_decode(char *string) static int /* O - Length of decoded string */ ppd_decode(char *string) /* I - String to decode */ @@ -117,14 +117,14 @@ ppd_decode(char *string) /* I - String to decode */ } // }}} -void emitPreamble(FILE *fp, ppd_file_t *ppd, - const ProcessingParameters ¶m) // {{{ +void _cfPDFToPDFEmitPreamble(FILE *fp, ppd_file_t *ppd, + const _cfPDFToPDFProcessingParameters ¶m) // {{{ { if (ppd == 0) return; ppdEmit(ppd, fp, PPD_ORDER_EXIT); - if (param.emitJCL) { + if (param.emit_jcl) { /* pdftopdf only adds JCL to the job if the printer is a native PDF printer and the PPD is for this mode, having the "*JCLToPDFInterpreter:" keyword. We need to read this keyword manually from the PPD and replace @@ -138,23 +138,23 @@ void emitPreamble(FILE *fp, ppd_file_t *ppd, /* If there is a "Copies" option in the PPD file, assure that hardware copies are implemented as described by this option */ if (ppdFindOption(ppd,"Copies") != NULL && - param.deviceCopies > 1) { - snprintf(buf,sizeof(buf),"%d",param.deviceCopies); + param.device_copies > 1) { + snprintf(buf,sizeof(buf),"%d",param.device_copies); ppdMarkOption(ppd,"Copies",buf); devicecopies_done = 1; } if ((attr=ppdFindAttr(ppd,"JCLToPDFInterpreter",NULL)) != NULL) { - if (param.deviceCopies > 1 && devicecopies_done == 0 && // HW copies + if (param.device_copies > 1 && devicecopies_done == 0 && // HW copies strncmp(ppd->jcl_begin, "\033%-12345X@", 10) == 0) { // PJL /* Add a PJL command to implement the hardware copies */ const size_t size=strlen(attr->value)+1+30; ppd->jcl_ps=(char *)malloc(size*sizeof(char)); - if (param.deviceCollate) { + if (param.device_collate) { snprintf(ppd->jcl_ps, size, "@PJL SET QTY=%d\n%s", - param.deviceCopies, attr->value); + param.device_copies, attr->value); } else { snprintf(ppd->jcl_ps, size, "@PJL SET COPIES=%d\n%s", - param.deviceCopies, attr->value); + param.device_copies, attr->value); } } else ppd->jcl_ps=strdup(attr->value); @@ -162,43 +162,43 @@ void emitPreamble(FILE *fp, ppd_file_t *ppd, } else { ppd->jcl_ps=NULL; } - ppdEmitJCL(ppd, fp, param.jobId, param.user, param.title); - emitJCLOptions(fp, ppd, param.deviceCopies); + ppdEmitJCL(ppd, fp, param.job_id, param.user, param.title); + emitJCLOptions(fp, ppd, param.device_copies); free(ppd->jcl_ps); ppd->jcl_ps = old_jcl_ps; // cups uses pool allocator, not free() } } // }}} -void emitPostamble(FILE *fp, ppd_file_t *ppd, - const ProcessingParameters ¶m) // {{{ +void _cfPDFToPDFEmitPostamble(FILE *fp, ppd_file_t *ppd, + const _cfPDFToPDFProcessingParameters ¶m) // {{{ { - if (param.emitJCL) { + if (param.emit_jcl) { ppdEmitJCLEnd(ppd, fp); } } // }}} // pass information to subsequent filters via PDF comments -void emitComment(PDFTOPDF_Processor &proc,const ProcessingParameters ¶m) // {{{ +void _cfPDFToPDFEmitComment(_cfPDFToPDFProcessor &proc,const _cfPDFToPDFProcessingParameters ¶m) // {{{ { std::vector output; output.push_back("% This file was generated by pdftopdf"); // This is not standard, but like PostScript. - if (param.deviceCopies>0) { + if (param.device_copies>0) { char buf[256]; - snprintf(buf,sizeof(buf),"%d",param.deviceCopies); + snprintf(buf,sizeof(buf),"%d",param.device_copies); output.push_back(std::string("%%PDFTOPDFNumCopies : ")+buf); - if (param.deviceCollate) { + if (param.device_collate) { output.push_back("%%PDFTOPDFCollate : true"); } else { output.push_back("%%PDFTOPDFCollate : false"); } } - proc.setComments(output); + proc.set_comments(output); } // }}} diff --git a/cupsfilters/pdftopdf/pdftopdf_jcl.h b/cupsfilters/pdftopdf/pdftopdf_jcl.h index 1289278b5..373d3c559 100644 --- a/cupsfilters/pdftopdf/pdftopdf_jcl.h +++ b/cupsfilters/pdftopdf/pdftopdf_jcl.h @@ -1,12 +1,15 @@ -#ifndef PDFTOPDF_JCL_H -#define PDFTOPDF_JCL_H +#ifndef _CUPS_FILTERS_PDFTOPDF_PDFTOPDF_JCL_H +#define _CUPS_FILTERS_PDFTOPDF_PDFTOPDF_JCL_H -struct ProcessingParameters; -class PDFTOPDF_Processor; +struct _cfPDFToPDFProcessingParameters; +class _cfPDFToPDFProcessor; -void emitPreamble(FILE *fp, ppd_file_t *ppd,const ProcessingParameters ¶m); -void emitPostamble(FILE *fp, ppd_file_t *ppd,const ProcessingParameters ¶m); +void _cfPDFToPDFEmitPreamble(FILE *fp, ppd_file_t *ppd, + const _cfPDFToPDFProcessingParameters ¶m); +void _cfPDFToPDFEmitPostamble(FILE *fp, ppd_file_t *ppd, + const _cfPDFToPDFProcessingParameters ¶m); -void emitComment(PDFTOPDF_Processor &proc,const ProcessingParameters ¶m); +void _cfPDFToPDFEmitComment(_cfPDFToPDFProcessor &proc, + const _cfPDFToPDFProcessingParameters ¶m); #endif diff --git a/cupsfilters/pdftopdf/pdftopdf_processor.cc b/cupsfilters/pdftopdf/pdftopdf_processor.cc index e3c7f7713..1fa4f6027 100644 --- a/cupsfilters/pdftopdf/pdftopdf_processor.cc +++ b/cupsfilters/pdftopdf/pdftopdf_processor.cc @@ -4,10 +4,10 @@ #include #include -void BookletMode_dump(BookletMode bkm,pdftopdf_doc_t *doc) // {{{ +void BookletMode_dump(pdftopdf_booklet_mode_e bkm,pdftopdf_doc_t *doc) // {{{ { static const char *bstr[3]={"Off","On","Shuffle-Only"}; - if ((bkmBOOKLET_JUSTSHUFFLE)) { + if ((bkmCF_PDFTOPDF_BOOKLET_JUST_SHUFFLE)) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: bookletMode: (bad booklet mode: " "%d)", bkm); @@ -18,28 +18,28 @@ void BookletMode_dump(BookletMode bkm,pdftopdf_doc_t *doc) // {{{ } // }}} -bool ProcessingParameters::withPage(int outno) const // {{{ +bool _cfPDFToPDFProcessingParameters::with_page(int outno) const // {{{ { if (outno%2 == 0) { // 1-based - if (!evenPages) { + if (!even_pages) { return false; } - } else if (!oddPages) { + } else if (!odd_pages) { return false; } - return pageRange.contains(outno); + return page_ranges.contains(outno); } // }}} -bool ProcessingParameters::havePage(int pageno) const +bool _cfPDFToPDFProcessingParameters::have_page(int pageno) const { - return inputPageRange.contains(pageno); + return input_page_ranges.contains(pageno); } -void ProcessingParameters::dump(pdftopdf_doc_t *doc) const // {{{ +void _cfPDFToPDFProcessingParameters::dump(pdftopdf_doc_t *doc) const // {{{ { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, - "cfFilterPDFToPDF: jobId: %d, numCopies: %d", - jobId,numCopies); + "cfFilterPDFToPDF: job_id: %d, num_copies: %d", + job_id,num_copies); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: user: %s, title: %s", (user)?user:"(null)",(title)?title:"(null)"); @@ -49,7 +49,7 @@ void ProcessingParameters::dump(pdftopdf_doc_t *doc) const // {{{ page.dump(doc); - Rotation_dump(orientation,doc); + _cfPDFToPDFRotationDump(orientation,doc); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: paper_is_landscape: %s", @@ -59,7 +59,7 @@ void ProcessingParameters::dump(pdftopdf_doc_t *doc) const // {{{ "cfFilterPDFToPDF: duplex: %s", (duplex)?"true":"false"); - BorderType_dump(border,doc); + _cfPDFToPDFBorderTypeDump(border,doc); nup.dump(doc); @@ -68,17 +68,17 @@ void ProcessingParameters::dump(pdftopdf_doc_t *doc) const // {{{ (reverse)?"true":"false"); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, - "cfFilterPDFToPDF: evenPages: %s, oddPages: %s", - (evenPages)?"true":"false", - (oddPages)?"true":"false"); + "cfFilterPDFToPDF: even_pages: %s, odd_pages: %s", + (even_pages)?"true":"false", + (odd_pages)?"true":"false"); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: input page range:"); - inputPageRange.dump(doc); + input_page_ranges.dump(doc); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: page range:"); - pageRange.dump(doc); + page_ranges.dump(doc); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: mirror: %s", @@ -86,50 +86,50 @@ void ProcessingParameters::dump(pdftopdf_doc_t *doc) const // {{{ if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: Position:"); - Position_dump(xpos,Axis::X,doc); - Position_dump(ypos,Axis::Y,doc); + _cfPDFToPDFPositionDump(xpos,pdftopdf_axis_e::X,doc); + _cfPDFToPDFPositionDump(ypos,pdftopdf_axis_e::Y,doc); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: collate: %s", (collate)?"true":"false"); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, - "cfFilterPDFToPDF: evenDuplex: %s", - (evenDuplex)?"true":"false"); + "cfFilterPDFToPDF: even_duplex: %s", + (even_duplex)?"true":"false"); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, - "cfFilterPDFToPDF: pageLabel: %s", - pageLabel.empty () ? "(none)" : - pageLabel.c_str()); + "cfFilterPDFToPDF: page_label: %s", + page_label.empty () ? "(none)" : + page_label.c_str()); BookletMode_dump(booklet,doc); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: booklet signature: %d", - bookSignature); + book_signature); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, - "cfFilterPDFToPDF: autoRotate: %s", - (autoRotate)?"true":"false"); + "cfFilterPDFToPDF: auto_rotate: %s", + (auto_rotate)?"true":"false"); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, - "cfFilterPDFToPDF: emitJCL: %s", - (emitJCL)?"true":"false"); + "cfFilterPDFToPDF: emit_jcl: %s", + (emit_jcl)?"true":"false"); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, - "cfFilterPDFToPDF: deviceCopies: %d", - deviceCopies); + "cfFilterPDFToPDF: device_copies: %d", + device_copies); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, - "cfFilterPDFToPDF: deviceCollate: %s", - (deviceCollate)?"true":"false"); + "cfFilterPDFToPDF: device_collate: %s", + (device_collate)?"true":"false"); if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, - "cfFilterPDFToPDF: setDuplex: %s", - (setDuplex)?"true":"false"); + "cfFilterPDFToPDF: set_duplex: %s", + (set_duplex)?"true":"false"); } // }}} -PDFTOPDF_Processor *PDFTOPDF_Factory::processor() +_cfPDFToPDFProcessor *_cfPDFToPDFFactory::processor() { - return new QPDF_PDFTOPDF_Processor(); + return new _cfPDFToPDFQPDFProcessor(); } // (1-based) @@ -138,7 +138,7 @@ PDFTOPDF_Processor *PDFTOPDF_Factory::processor() // NOTE: psbook always fills the sig completely (results in completely white pages (4-set), depending on the input) // empty pages must be added for output values >=numPages -std::vector bookletShuffle(int numPages,int signature) // {{{ +std::vector _cfPDFToPDFBookletShuffle(int numPages,int signature) // {{{ { if (signature<0) { signature=(numPages+3)&~0x3; @@ -166,7 +166,7 @@ std::vector bookletShuffle(int numPages,int signature) // {{{ } // }}} -bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftopdf_doc_t *doc) // {{{ +bool _cfProcessPDFToPDF(_cfPDFToPDFProcessor &proc,_cfPDFToPDFProcessingParameters ¶m,pdftopdf_doc_t *doc) // {{{ { if (!proc.check_print_permissions(doc)) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, @@ -181,28 +181,28 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftop if (param.paper_is_landscape) std::swap(param.nup.nupX, param.nup.nupY); - if (param.autoRotate) - proc.autoRotateAll(dst_lscape,param.normal_landscape); + if (param.auto_rotate) + proc.auto_rotate_all(dst_lscape,param.normal_landscape); - std::vector> pages=proc.get_pages(doc); + std::vector> pages=proc.get_pages(doc); - std::vector> input_page_range_list; + std::vector> input_page_range_list; for(int i=1;i<=(int)pages.size();i++) - if(param.havePage(i)) + if(param.have_page(i)) input_page_range_list.push_back(pages[i-1]); const int numOrigPages=input_page_range_list.size(); // TODO FIXME? elsewhere std::vector shuffle; - if (param.booklet!=BOOKLET_OFF) { - shuffle=bookletShuffle(numOrigPages,param.bookSignature); - if (param.booklet==BOOKLET_ON) { // override options + if (param.booklet!=CF_PDFTOPDF_BOOKLET_OFF) { + shuffle=_cfPDFToPDFBookletShuffle(numOrigPages,param.book_signature); + if (param.booklet==CF_PDFTOPDF_BOOKLET_ON) { // override options // TODO? specifically "sides=two-sided-short-edge" / DuplexTumble // param.duplex=true; - // param.setDuplex=true; ? currently done in setFinalPPD() - NupParameters::preset(2,param.nup); // TODO?! better + // param.set_duplex=true; ? currently done in setFinalPPD() + _cfPDFToPDFNupParameters::preset(2,param.nup); // TODO?! better } } else { // 0 1 2 3 ... shuffle.resize(numOrigPages); @@ -230,7 +230,7 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftop for (int i = 0; i < (int)input_page_range_list.size(); i ++) { - PageRect r = input_page_range_list[i]->getRect(); + _cfPDFToPDFPageRect r = input_page_range_list[i]->get_rect(); int w = r.width * 100 / 102; // 2% of tolerance int h = r.height * 100 / 102; if ((w > param.page.width || h > param.page.height) && @@ -295,20 +295,20 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftop { for (int i = 0; i < (int)input_page_range_list.size(); i ++) { - std::shared_ptr page = input_page_range_list[i]; - Rotation orientation; + std::shared_ptr<_cfPDFToPDFPageHandle> page = input_page_range_list[i]; + pdftopdf_rotation_e orientation; if (page->is_landscape(param.orientation)) orientation = param.normal_landscape; else orientation = ROT_0; page->crop(param.page, orientation, param.orientation, param.xpos, param.ypos, - !param.cropfit, param.autoRotate, doc); + !param.cropfit, param.auto_rotate, doc); } if (param.fillprint) param.fitplot = true; } - std::shared_ptr curpage; + std::shared_ptr<_cfPDFToPDFPageHandle> curpage; int outputpage=0; int outputno=0; @@ -353,25 +353,25 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftop } } - NupState nupstate(param.nup); - NupPageEdit pgedit; + _cfPDFToPDFNupState nupstate(param.nup); + _cfPDFToPDFNupPageEdit pgedit; for (int iA = 0; iA < numPages; iA ++) { - std::shared_ptr page; + std::shared_ptr<_cfPDFToPDFPageHandle> page; if (shuffle[iA] >= numOrigPages) // add empty page as filler page = proc.new_page(param.page.width, param.page.height, doc); else page = input_page_range_list[shuffle[iA]]; - PageRect rect; - rect = page->getRect(); + _cfPDFToPDFPageRect rect; + rect = page->get_rect(); //rect.dump(doc); - bool newPage = nupstate.nextPage(rect.width, rect.height, pgedit); + bool newPage = nupstate.mext_page(rect.width, rect.height, pgedit); if (newPage) { - if ((curpage) && (param.withPage(outputpage))) + if ((curpage) && (param.with_page(outputpage))) { curpage->rotate(param.orientation); if (param.mirror) @@ -393,14 +393,14 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftop if (shuffle[iA] >= numOrigPages) continue; - if (param.border != BorderType::NONE) + if (param.border != pdftopdf_border_type_e::NONE) // TODO FIXME... border gets cutted away, if orignal page had wrong size // page->"uncrop"(rect); // page->setMedia() // Note: currently "fixed" in add_subpage(...&rect); page->add_border_rect(rect, param.border, 1.0 / pgedit.scale); - if (!param.pageLabel.empty()) - page->add_label(param.page, param.pageLabel); + if (!param.page_label.empty()) + page->add_label(param.page, param.page_label); if (param.cropfit) { @@ -408,16 +408,16 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftop { double xpos2, ypos2; if ((param.page.height - param.page.width) * - (page->getRect().height - page->getRect().width) < 0) + (page->get_rect().height - page->get_rect().width) < 0) { - xpos2 = (param.page.width - (page->getRect().height)) / 2; - ypos2 = (param.page.height - (page->getRect().width)) / 2; + xpos2 = (param.page.width - (page->get_rect().height)) / 2; + ypos2 = (param.page.height - (page->get_rect().width)) / 2; curpage->add_subpage(page, ypos2 + xpos, xpos2 + ypos, 1); } else { - xpos2 = (param.page.width - (page->getRect().width)) / 2; - ypos2 = (param.page.height - (page->getRect().height)) / 2; + xpos2 = (param.page.width - (page->get_rect().width)) / 2; + ypos2 = (param.page.height - (page->get_rect().height)) / 2; curpage->add_subpage(page, xpos2 + xpos, ypos2 + ypos, 1); } } @@ -430,13 +430,13 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftop pgedit.scale); #ifdef DEBUG - if (auto dbg=dynamic_cast(curpage.get())) + if (auto dbg=dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(curpage.get())) dbg->debug(pgedit.sub, xpos, ypos); #endif //pgedit.dump(doc); } - if ((curpage) && (param.withPage(outputpage))) + if ((curpage) && (param.with_page(outputpage))) { curpage->rotate(param.orientation); if (param.mirror) @@ -450,7 +450,7 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftop param.copies_to_be_logged); } - if ((param.evenDuplex || !param.oddPages) && (outputno & 1)) { + if ((param.even_duplex || !param.odd_pages) && (outputno & 1)) { // need to output empty page to not confuse duplex proc.add_page(proc.new_page(param.page.width,param.page.height,doc),param.reverse); // Log page in /var/log/cups/page_log @@ -460,7 +460,7 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftop param.copies_to_be_logged); } - proc.multiply(param.numCopies,param.collate); + proc.multiply(param.num_copies,param.collate); return true; } diff --git a/cupsfilters/pdftopdf/pdftopdf_processor.h b/cupsfilters/pdftopdf/pdftopdf_processor.h index 0b2c70bec..18dd58fa0 100644 --- a/cupsfilters/pdftopdf/pdftopdf_processor.h +++ b/cupsfilters/pdftopdf/pdftopdf_processor.h @@ -1,5 +1,5 @@ -#ifndef PDFTOPDF_PROCESSOR_H -#define PDFTOPDF_PROCESSOR_H +#ifndef _CUPS_FILTERS_PDFTOPDF_PDFTOPDF_PROCESSOR_H +#define _CUPS_FILTERS_PDFTOPDF_PDFTOPDF_PROCESSOR_H #include "pptypes.h" #include "nup.h" @@ -7,12 +7,18 @@ #include "intervalset.h" #include #include +#include +#include -enum BookletMode { BOOKLET_OFF, BOOKLET_ON, BOOKLET_JUSTSHUFFLE }; +enum pdftopdf_booklet_mode_e { + CF_PDFTOPDF_BOOKLET_OFF, + CF_PDFTOPDF_BOOKLET_ON, + CF_PDFTOPDF_BOOKLET_JUST_SHUFFLE +}; -struct ProcessingParameters { -ProcessingParameters() -: jobId(0),numCopies(1), +struct _cfPDFToPDFProcessingParameters { +_cfPDFToPDFProcessingParameters() +: job_id(0),num_copies(1), user(0),title(0), fitplot(false), fillprint(false), //print-scaling = fill @@ -20,29 +26,29 @@ ProcessingParameters() autoprint(false), autofit(false), fidelity(false), - noOrientation(false), + no_orientation(false), orientation(ROT_0),normal_landscape(ROT_270), paper_is_landscape(false), duplex(false), border(NONE), reverse(false), - pageLabel(), - evenPages(true),oddPages(true), + page_label(), + even_pages(true),odd_pages(true), mirror(false), xpos(CENTER),ypos(CENTER), collate(false), - evenDuplex(false), + even_duplex(false), - booklet(BOOKLET_OFF),bookSignature(-1), + booklet(CF_PDFTOPDF_BOOKLET_OFF),book_signature(-1), - autoRotate(false), + auto_rotate(false), - emitJCL(true),deviceCopies(1), - deviceCollate(false),setDuplex(false), + emit_jcl(true),device_copies(1), + device_collate(false),set_duplex(false), page_logging(-1) { @@ -54,13 +60,13 @@ ProcessingParameters() page.right=page.width-18.0; // everything - inputPageRange.add(1); - inputPageRange.finish(); - pageRange.add(1); - pageRange.finish(); + input_page_ranges.add(1); + input_page_ranges.finish(); + page_ranges.add(1); + page_ranges.finish(); } - int jobId, numCopies; + int job_id, num_copies; const char *user, *title; // will stay around bool fitplot; bool fillprint; //print-scaling = fill @@ -68,112 +74,112 @@ ProcessingParameters() bool autoprint; // print-scaling = auto bool autofit; // print-scaling = auto-fit bool fidelity; - bool noOrientation; - PageRect page; - Rotation orientation,normal_landscape; // normal_landscape (i.e. default direction) is e.g. needed for number-up=2 + bool no_orientation; + _cfPDFToPDFPageRect page; + pdftopdf_rotation_e orientation,normal_landscape; // normal_landscape (i.e. default direction) is e.g. needed for number-up=2 bool paper_is_landscape; bool duplex; - BorderType border; - NupParameters nup; + pdftopdf_border_type_e border; + _cfPDFToPDFNupParameters nup; bool reverse; - std::string pageLabel; - bool evenPages,oddPages; - IntervalSet pageRange; - IntervalSet inputPageRange; + std::string page_label; + bool even_pages,odd_pages; + _cfPDFToPDFIntervalSet page_ranges; + _cfPDFToPDFIntervalSet input_page_ranges; bool mirror; - Position xpos,ypos; + pdftopdf_position_e xpos,ypos; bool collate; - bool evenDuplex; // make number of pages a multiple of 2 + bool even_duplex; // make number of pages a multiple of 2 - BookletMode booklet; - int bookSignature; + pdftopdf_booklet_mode_e booklet; + int book_signature; - bool autoRotate; + bool auto_rotate; // ppd/jcl changes - bool emitJCL; - int deviceCopies; - bool deviceCollate; - bool setDuplex; - // unsetMirror (always) + bool emit_jcl; + int device_copies; + bool device_collate; + bool set_duplex; int page_logging; int copies_to_be_logged; // helper functions - bool withPage(int outno) const; // 1 based - bool havePage(int pageno) const; //1 based + bool with_page(int outno) const; // 1 based + bool have_page(int pageno) const; //1 based void dump(pdftopdf_doc_t *doc) const; }; -#include -#include - -enum ArgOwnership { WillStayAlive,MustDuplicate,TakeOwnership }; +enum pdftopdf_arg_ownership_e { + CF_PDFTOPDF_WILL_STAY_ALIVE, + CF_PDFTOPDF_MUST_DUPLICATE, + CF_PDFTOPDF_TAKE_OWNERSHIP +}; -class PDFTOPDF_PageHandle { +class _cfPDFToPDFPageHandle { public: - virtual ~PDFTOPDF_PageHandle() {} - virtual PageRect getRect() const =0; + virtual ~_cfPDFToPDFPageHandle() {} + virtual _cfPDFToPDFPageRect get_rect() const =0; // fscale: inverse_scale (from nup, fitplot) - virtual void add_border_rect(const PageRect &rect,BorderType border,float fscale) =0; + virtual void add_border_rect(const _cfPDFToPDFPageRect &rect,pdftopdf_border_type_e border,float fscale) =0; // TODO?! add standalone crop(...) method (not only for subpages) - virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc) =0; - virtual bool is_landscape(Rotation orientation) =0 ; - virtual void add_subpage(const std::shared_ptr &sub,float xpos,float ypos,float scale,const PageRect *crop=NULL) =0; + virtual pdftopdf_rotation_e crop(const _cfPDFToPDFPageRect &cropRect,pdftopdf_rotation_e orientation,pdftopdf_rotation_e param_orientation,pdftopdf_position_e xpos,pdftopdf_position_e ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc) =0; + virtual bool is_landscape(pdftopdf_rotation_e orientation) =0 ; + virtual void add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,float xpos,float ypos,float scale,const _cfPDFToPDFPageRect *crop=NULL) =0; virtual void mirror() =0; - virtual void rotate(Rotation rot) =0; - virtual void add_label(const PageRect &rect, const std::string label) =0; + virtual void rotate(pdftopdf_rotation_e rot) =0; + virtual void add_label(const _cfPDFToPDFPageRect &rect, const std::string label) =0; }; // TODO: ... error output? -class PDFTOPDF_Processor { // abstract interface +class _cfPDFToPDFProcessor { // abstract interface public: - virtual ~PDFTOPDF_Processor() {} + virtual ~_cfPDFToPDFProcessor() {} // TODO: ... qpdf wants password at load time - virtual bool loadFile(FILE *f,pdftopdf_doc_t *doc,ArgOwnership take=WillStayAlive,int flatten_forms=1) =0; - virtual bool loadFilename(const char *name,pdftopdf_doc_t *doc,int flatten_forms=1) =0; + virtual bool load_file(FILE *f,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take=CF_PDFTOPDF_WILL_STAY_ALIVE,int flatten_forms=1) =0; + virtual bool load_filename(const char *name,pdftopdf_doc_t *doc,int flatten_forms=1) =0; // TODO? virtual bool may_modify/may_print/? virtual bool check_print_permissions(pdftopdf_doc_t *doc) =0; - virtual std::vector> get_pages(pdftopdf_doc_t *doc) =0; // shared_ptr because of type erasure (deleter) + virtual std::vector> get_pages(pdftopdf_doc_t *doc) =0; // shared_ptr because of type erasure (deleter) - virtual std::shared_ptr new_page(float width,float height,pdftopdf_doc_t *doc) =0; + virtual std::shared_ptr<_cfPDFToPDFPageHandle> new_page(float width,float height,pdftopdf_doc_t *doc) =0; - virtual void add_page(std::shared_ptr page,bool front) =0; // at back/front -- either from get_pages() or new_page()+add_subpage()-calls (or [also allowed]: empty) + virtual void add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,bool front) =0; // at back/front -- either from get_pages() or new_page()+add_subpage()-calls (or [also allowed]: empty) - // void remove_page(std::shared_ptr ph); // not needed: we construct from scratch, at least conceptually. + // void remove_page(std::shared_ptr<_cfPDFToPDFPageHandle> ph); // not needed: we construct from scratch, at least conceptually. virtual void multiply(int copies,bool collate) =0; - virtual void autoRotateAll(bool dst_lscape,Rotation normal_landscape) =0; // TODO elsewhere?! - virtual void addCM(const char *defaulticc,const char *outputicc) =0; + virtual void auto_rotate_all(bool dst_lscape,pdftopdf_rotation_e normal_landscape) =0; // TODO elsewhere?! + virtual void add_cm(const char *defaulticc,const char *outputicc) =0; - virtual void setComments(const std::vector &comments) =0; + virtual void set_comments(const std::vector &comments) =0; - virtual void emitFile(FILE *dst,pdftopdf_doc_t *doc,ArgOwnership take=WillStayAlive) =0; - virtual void emitFilename(const char *name,pdftopdf_doc_t *doc) =0; // NULL -> stdout + virtual void emit_file(FILE *dst,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take=CF_PDFTOPDF_WILL_STAY_ALIVE) =0; + virtual void emit_filename(const char *name,pdftopdf_doc_t *doc) =0; // NULL -> stdout - virtual bool hasAcroForm() =0; + virtual bool has_acro_form() =0; }; -class PDFTOPDF_Factory { +class _cfPDFToPDFFactory { public: // never NULL, but may throw. - static PDFTOPDF_Processor *processor(); + static _cfPDFToPDFProcessor *processor(); }; -//bool checkBookletSignature(int signature) { return (signature%4==0); } -std::vector bookletShuffle(int numPages,int signature=-1); +//bool _cfPDFToPDFCheckBookletSignature(int signature) { return (signature%4==0); } +std::vector _cfPDFToPDFBookletShuffle(int numPages,int signature=-1); // This is all we want: -bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,pdftopdf_doc_t *doc); +bool _cfProcessPDFToPDF(_cfPDFToPDFProcessor &proc,_cfPDFToPDFProcessingParameters ¶m,pdftopdf_doc_t *doc); #endif diff --git a/cupsfilters/pdftopdf/pptypes.cc b/cupsfilters/pdftopdf/pptypes.cc index 97cd05f4e..126dbc10f 100644 --- a/cupsfilters/pdftopdf/pptypes.cc +++ b/cupsfilters/pdftopdf/pptypes.cc @@ -3,7 +3,7 @@ #include #include -void Position_dump(Position pos,pdftopdf_doc_t *doc) // {{{ +void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_doc_t *doc) // {{{ { static const char *pstr[3]={"Left/Bottom","Center","Right/Top"}; if ((pos < LEFT) || (pos > RIGHT)) { @@ -16,16 +16,16 @@ void Position_dump(Position pos,pdftopdf_doc_t *doc) // {{{ } // }}} -void Position_dump(Position pos,Axis axis,pdftopdf_doc_t *doc) // {{{ +void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_axis_e axis,pdftopdf_doc_t *doc) // {{{ { - assert((axis == Axis::X) || (axis == Axis::Y)); + assert((axis == pdftopdf_axis_e::X) || (axis == pdftopdf_axis_e::Y)); if ((pos < LEFT) || (pos > RIGHT)) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: Position %s: (bad position: %d)", - (axis == Axis::X) ? "X" : "Y", pos); + (axis == pdftopdf_axis_e::X) ? "X" : "Y", pos); return; } - if (axis==Axis::X) { + if (axis==pdftopdf_axis_e::X) { static const char *pxstr[3]={"Left","Center","Right"}; if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: Position X: %s", pxstr[pos+1]); @@ -37,7 +37,7 @@ void Position_dump(Position pos,Axis axis,pdftopdf_doc_t *doc) // {{{ } // }}} -void Rotation_dump(Rotation rot,pdftopdf_doc_t *doc) // {{{ +void _cfPDFToPDFRotationDump(pdftopdf_rotation_e rot,pdftopdf_doc_t *doc) // {{{ { static const char *rstr[4]={"0 deg","90 deg","180 deg","270 deg"}; // CCW if ((rot < ROT_0) || (rot > ROT_270)) { @@ -50,25 +50,25 @@ void Rotation_dump(Rotation rot,pdftopdf_doc_t *doc) // {{{ } // }}} -Rotation operator+(Rotation lhs,Rotation rhs) // {{{ +pdftopdf_rotation_e operator+(pdftopdf_rotation_e lhs,pdftopdf_rotation_e rhs) // {{{ { - return (Rotation)(((int)lhs+(int)rhs)%4); + return (pdftopdf_rotation_e)(((int)lhs+(int)rhs)%4); } // }}} -Rotation operator-(Rotation lhs,Rotation rhs) // {{{ +pdftopdf_rotation_e operator-(pdftopdf_rotation_e lhs,pdftopdf_rotation_e rhs) // {{{ { - return (Rotation)((((int)lhs-(int)rhs)%4+4)%4); + return (pdftopdf_rotation_e)((((int)lhs-(int)rhs)%4+4)%4); } // }}} -Rotation operator-(Rotation rhs) // {{{ +pdftopdf_rotation_e operator-(pdftopdf_rotation_e rhs) // {{{ { - return (Rotation)((4-(int)rhs)%4); + return (pdftopdf_rotation_e)((4-(int)rhs)%4); } // }}} -void BorderType_dump(BorderType border,pdftopdf_doc_t *doc) // {{{ +void _cfPDFToPDFBorderTypeDump(pdftopdf_border_type_e border,pdftopdf_doc_t *doc) // {{{ { if ((border < NONE) || (border == 1) || (border > TWO_THICK)) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, @@ -81,7 +81,7 @@ void BorderType_dump(BorderType border,pdftopdf_doc_t *doc) // {{{ } // }}} -void PageRect::rotate_move(Rotation r,float pwidth,float pheight) // {{{ +void _cfPDFToPDFPageRect::rotate_move(pdftopdf_rotation_e r,float pwidth,float pheight) // {{{ { #if 1 if (r>=ROT_180) { @@ -142,7 +142,7 @@ void PageRect::rotate_move(Rotation r,float pwidth,float pheight) // {{{ } // }}} -void PageRect::scale(float mult) // {{{ +void _cfPDFToPDFPageRect::scale(float mult) // {{{ { if (mult==1.0) { return; @@ -159,7 +159,7 @@ void PageRect::scale(float mult) // {{{ } // }}} -void PageRect::translate(float tx,float ty) // {{{ +void _cfPDFToPDFPageRect::translate(float tx,float ty) // {{{ { left+=tx; bottom+=ty; @@ -168,7 +168,7 @@ void PageRect::translate(float tx,float ty) // {{{ } // }}} -void PageRect::set(const PageRect &rhs) // {{{ +void _cfPDFToPDFPageRect::set(const _cfPDFToPDFPageRect &rhs) // {{{ { if (!std::isnan(rhs.top)) top=rhs.top; if (!std::isnan(rhs.left)) left=rhs.left; @@ -177,7 +177,7 @@ void PageRect::set(const PageRect &rhs) // {{{ } // }}} -void PageRect::dump(pdftopdf_doc_t *doc) const // {{{ +void _cfPDFToPDFPageRect::dump(pdftopdf_doc_t *doc) const // {{{ { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPDF: top: %f, left: %f, right: %f, bottom: %f, " diff --git a/cupsfilters/pdftopdf/pptypes.h b/cupsfilters/pdftopdf/pptypes.h index bff54f8a4..dc1225fcf 100644 --- a/cupsfilters/pdftopdf/pptypes.h +++ b/cupsfilters/pdftopdf/pptypes.h @@ -1,40 +1,40 @@ -#ifndef PPTYPES_H_ -#define PPTYPES_H_ +#ifndef _CUPS_FILTERS_PDFTOPDF_PPTYPES_H_ +#define _CUPS_FILTERS_PDFTOPDF_PPTYPES_H_ #include "pdftopdf.h" #include // NAN // namespace PPTypes {} TODO? -enum Axis { X, Y }; -enum Position { CENTER=0, LEFT=-1, RIGHT=1, TOP=1, BOTTOM=-1 }; // PS order -void Position_dump(Position pos,pdftopdf_doc_t *doc); -void Position_dump(Position pos,Axis axis,pdftopdf_doc_t *doc); +enum pdftopdf_axis_e { X, Y }; +enum pdftopdf_position_e { CENTER=0, LEFT=-1, RIGHT=1, TOP=1, BOTTOM=-1 }; // PS order +void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_doc_t *doc); +void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_axis_e axis,pdftopdf_doc_t *doc); -enum Rotation { ROT_0, ROT_90, ROT_180, ROT_270 }; // CCW -void Rotation_dump(Rotation rot,pdftopdf_doc_t *doc); -Rotation operator+(Rotation lhs,Rotation rhs); -Rotation operator-(Rotation lhs,Rotation rhs); -Rotation operator-(Rotation rhs); -//Rotation operator+=(Rotation &lhs,Rotation rhs); +enum pdftopdf_rotation_e { ROT_0, ROT_90, ROT_180, ROT_270 }; // CCW +void _cfPDFToPDFRotationDump(pdftopdf_rotation_e rot,pdftopdf_doc_t *doc); +pdftopdf_rotation_e operator+(pdftopdf_rotation_e lhs,pdftopdf_rotation_e rhs); +pdftopdf_rotation_e operator-(pdftopdf_rotation_e lhs,pdftopdf_rotation_e rhs); +pdftopdf_rotation_e operator-(pdftopdf_rotation_e rhs); +//pdftopdf_rotation_e operator+=(pdftopdf_rotation_e &lhs,pdftopdf_rotation_e rhs); -enum BorderType { NONE=0, ONE_THIN=2, ONE_THICK=3, TWO_THIN=4, TWO_THICK=5, +enum pdftopdf_border_type_e { NONE=0, ONE_THIN=2, ONE_THICK=3, TWO_THIN=4, TWO_THICK=5, ONE=0x02, TWO=0x04, THICK=0x01}; -void BorderType_dump(BorderType border,pdftopdf_doc_t *doc); +void _cfPDFToPDFBorderTypeDump(pdftopdf_border_type_e border,pdftopdf_doc_t *doc); -struct PageRect { -PageRect() : top(NAN),left(NAN),right(NAN),bottom(NAN),width(NAN),height(NAN) {} +struct _cfPDFToPDFPageRect { +_cfPDFToPDFPageRect() : top(NAN),left(NAN),right(NAN),bottom(NAN),width(NAN),height(NAN) {} float top,left,right,bottom; // i.e. margins float width,height; - void rotate_move(Rotation r,float pwidth,float pheight); // pwidth original "page size" (i.e. before rotation) + void rotate_move(pdftopdf_rotation_e r,float pwidth,float pheight); // pwidth original "page size" (i.e. before rotation) void scale(float mult); void translate(float tx,float ty); - void set(const PageRect &rhs); // only for rhs.* != NAN + void set(const _cfPDFToPDFPageRect &rhs); // only for rhs.* != NAN void dump(pdftopdf_doc_t *doc) const; }; -// bool parseBorder(const char *val,BorderType &ret); // none,single,...,double-thick +// bool _cfPDFToPDFParseBorder(const char *val,pdftopdf_border_type_e &ret); // none,single,...,double-thick #endif diff --git a/cupsfilters/pdftopdf/qpdf_cm.cc b/cupsfilters/pdftopdf/qpdf_cm.cc index f5ee6ab37..9a6a2c7a0 100644 --- a/cupsfilters/pdftopdf/qpdf_cm.cc +++ b/cupsfilters/pdftopdf/qpdf_cm.cc @@ -38,7 +38,7 @@ static std::string load_file(const char *filename) // {{{ // TODO? // TODO? test -bool hasOutputIntent(QPDF &pdf) // {{{ +bool _cfPDFToPDFHasOutputIntent(QPDF &pdf) // {{{ { auto catalog=pdf.getRoot(); if (!catalog.hasKey("/OutputIntents")) { @@ -50,7 +50,7 @@ bool hasOutputIntent(QPDF &pdf) // {{{ // TODO: test // TODO? find existing , replace and return (?) -void addOutputIntent(QPDF &pdf,const char *filename) // {{{ +void _cfPDFToPDFAddOutputIntent(QPDF &pdf,const char *filename) // {{{ { std::string icc=load_file(filename); // TODO: check icc fitness @@ -103,7 +103,7 @@ void addOutputIntent(QPDF &pdf,const char *filename) // {{{ */ // TODO? test -void addDefaultRGB(QPDF &pdf,QPDFObjectHandle srcicc) // {{{ +void _cfPDFToPDFAddDefaultRGB(QPDF &pdf,QPDFObjectHandle srcicc) // {{{ { srcicc.assertStream(); @@ -130,7 +130,7 @@ void addDefaultRGB(QPDF &pdf,QPDFObjectHandle srcicc) // {{{ // TODO? test // TODO: find existing , replace and return (?) // TODO: check icc fitness -QPDFObjectHandle setDefaultICC(QPDF &pdf,const char *filename) // {{{ +QPDFObjectHandle _cfPDFToPDFSetDefaultICC(QPDF &pdf,const char *filename) // {{{ { // TODO: find existing , replace and return (?) diff --git a/cupsfilters/pdftopdf/qpdf_cm.h b/cupsfilters/pdftopdf/qpdf_cm.h index 5eb27596f..e871bd1db 100644 --- a/cupsfilters/pdftopdf/qpdf_cm.h +++ b/cupsfilters/pdftopdf/qpdf_cm.h @@ -1,12 +1,12 @@ -#ifndef QPDF_CM_H_ -#define QPDF_CM_H_ +#ifndef _CUPS_FILTERS_PDFTOPDF_QPDF_CM_H_ +#define _CUPS_FILTERS_PDFTOPDF_QPDF_CM_H_ #include -bool hasOutputIntent(QPDF &pdf); -void addOutputIntent(QPDF &pdf,const char *filename); +bool _cfPDFToPDFHasOutputIntent(QPDF &pdf); +void _cfPDFToPDFAddOutputIntent(QPDF &pdf,const char *filename); -void addDefaultRGB(QPDF &pdf,QPDFObjectHandle srcicc); -QPDFObjectHandle setDefaultICC(QPDF &pdf,const char *filename); +void _cfPDFToPDFAddDefaultRGB(QPDF &pdf,QPDFObjectHandle srcicc); +QPDFObjectHandle _cfPDFToPDFSetDefaultICC(QPDF &pdf,const char *filename); #endif diff --git a/cupsfilters/pdftopdf/qpdf_pdftopdf.cc b/cupsfilters/pdftopdf/qpdf_pdftopdf.cc index 68cd8ef41..869eee46f 100644 --- a/cupsfilters/pdftopdf/qpdf_pdftopdf.cc +++ b/cupsfilters/pdftopdf/qpdf_pdftopdf.cc @@ -3,9 +3,9 @@ #include #include -PageRect getBoxAsRect(QPDFObjectHandle box) // {{{ +_cfPDFToPDFPageRect _cfPDFToPDFGetBoxAsRect(QPDFObjectHandle box) // {{{ { - PageRect ret; + _cfPDFToPDFPageRect ret; ret.left=box.getArrayItem(0).getNumericValue(); ret.bottom=box.getArrayItem(1).getNumericValue(); @@ -19,7 +19,7 @@ PageRect getBoxAsRect(QPDFObjectHandle box) // {{{ } // }}} -Rotation getRotate(QPDFObjectHandle page) // {{{ +pdftopdf_rotation_e _cfPDFToPDFGetRotate(QPDFObjectHandle page) // {{{ { if (!page.hasKey("/Rotate")) { return ROT_0; @@ -36,13 +36,13 @@ Rotation getRotate(QPDFObjectHandle page) // {{{ } else if (rot==270.0) { return ROT_90; } else if (rot!=0.0) { - throw std::runtime_error("Unexpected /Rotation value: "+QUtil::double_to_string(rot)); + throw std::runtime_error("Unexpected /Rotate value: "+QUtil::double_to_string(rot)); } return ROT_0; } // }}} -double getUserUnit(QPDFObjectHandle page) // {{{ +double _cfPDFToPDFGetUserUnit(QPDFObjectHandle page) // {{{ { if (!page.hasKey("/UserUnit")) { return 1.0; @@ -51,7 +51,7 @@ double getUserUnit(QPDFObjectHandle page) // {{{ } // }}} -QPDFObjectHandle makeRotate(Rotation rot) // {{{ +QPDFObjectHandle _cfPDFToPDFMakeRotate(pdftopdf_rotation_e rot) // {{{ { switch (rot) { case ROT_0: @@ -70,21 +70,21 @@ QPDFObjectHandle makeRotate(Rotation rot) // {{{ #include "qpdf_tools.h" -QPDFObjectHandle getRectAsBox(const PageRect &rect) // {{{ +QPDFObjectHandle _cfPDFToPDFGetRectAsBox(const _cfPDFToPDFPageRect &rect) // {{{ { - return makeBox(rect.left,rect.bottom,rect.right,rect.top); + return _cfPDFToPDFMakeBox(rect.left,rect.bottom,rect.right,rect.top); } // }}} #include -Matrix::Matrix() // {{{ +_cfPDFToPDFMatrix::_cfPDFToPDFMatrix() // {{{ : ctm{1,0,0,1,0,0} { } // }}} -Matrix::Matrix(QPDFObjectHandle ar) // {{{ +_cfPDFToPDFMatrix::_cfPDFToPDFMatrix(QPDFObjectHandle ar) // {{{ { if (ar.getArrayNItems()!=6) { throw std::runtime_error("Not a ctm matrix"); @@ -95,7 +95,7 @@ Matrix::Matrix(QPDFObjectHandle ar) // {{{ } // }}} -Matrix &Matrix::rotate(Rotation rot) // {{{ +_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::rotate(pdftopdf_rotation_e rot) // {{{ { switch (rot) { case ROT_0: @@ -124,7 +124,7 @@ Matrix &Matrix::rotate(Rotation rot) // {{{ // }}} // TODO: test -Matrix &Matrix::rotate_move(Rotation rot,double width,double height) // {{{ +_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::rotate_move(pdftopdf_rotation_e rot,double width,double height) // {{{ { rotate(rot); switch (rot) { @@ -144,9 +144,9 @@ Matrix &Matrix::rotate_move(Rotation rot,double width,double height) // {{{ } // }}} -Matrix &Matrix::rotate(double rad) // {{{ +_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::rotate(double rad) // {{{ { - Matrix tmp; + _cfPDFToPDFMatrix tmp; tmp.ctm[0]=cos(rad); tmp.ctm[1]=sin(rad); @@ -157,7 +157,7 @@ Matrix &Matrix::rotate(double rad) // {{{ } // }}} -Matrix &Matrix::translate(double tx,double ty) // {{{ +_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::translate(double tx,double ty) // {{{ { ctm[4]+=ctm[0]*tx+ctm[2]*ty; ctm[5]+=ctm[1]*tx+ctm[3]*ty; @@ -165,7 +165,7 @@ Matrix &Matrix::translate(double tx,double ty) // {{{ } // }}} -Matrix &Matrix::scale(double sx,double sy) // {{{ +_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::scale(double sx,double sy) // {{{ { ctm[0]*=sx; ctm[1]*=sx; @@ -175,7 +175,7 @@ Matrix &Matrix::scale(double sx,double sy) // {{{ } // }}} -Matrix &Matrix::operator*=(const Matrix &rhs) // {{{ +_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::operator*=(const _cfPDFToPDFMatrix &rhs) // {{{ { double tmp[6]; std::copy(ctm,ctm+6,tmp); @@ -193,7 +193,7 @@ Matrix &Matrix::operator*=(const Matrix &rhs) // {{{ } // }}} -QPDFObjectHandle Matrix::get() const // {{{ +QPDFObjectHandle _cfPDFToPDFMatrix::get() const // {{{ { QPDFObjectHandle ret=QPDFObjectHandle::newArray(); ret.appendItem(QPDFObjectHandle::newReal(ctm[0])); @@ -206,7 +206,7 @@ QPDFObjectHandle Matrix::get() const // {{{ } // }}} -std::string Matrix::get_string() const // {{{ +std::string _cfPDFToPDFMatrix::get_string() const // {{{ { std::string ret; ret.append(QUtil::double_to_string(ctm[0])); diff --git a/cupsfilters/pdftopdf/qpdf_pdftopdf.h b/cupsfilters/pdftopdf/qpdf_pdftopdf.h index 9cb1536bc..27bb357b8 100644 --- a/cupsfilters/pdftopdf/qpdf_pdftopdf.h +++ b/cupsfilters/pdftopdf/qpdf_pdftopdf.h @@ -1,36 +1,36 @@ -#ifndef QPDF_PDFTOPDF_H -#define QPDF_PDFTOPDF_H +#ifndef _CUPS_FILTERS_PDFTOPDF_QPDF_PDFTOPDF_H +#define _CUPS_FILTERS_PDFTOPDF_QPDF_PDFTOPDF_H #include #include "pptypes.h" // helper functions -PageRect getBoxAsRect(QPDFObjectHandle box); -QPDFObjectHandle getRectAsBox(const PageRect &rect); +_cfPDFToPDFPageRect _cfPDFToPDFGetBoxAsRect(QPDFObjectHandle box); +QPDFObjectHandle _cfPDFToPDFGetRectAsBox(const _cfPDFToPDFPageRect &rect); // Note that PDF specification is CW, but our Rotation is CCW -Rotation getRotate(QPDFObjectHandle page); -QPDFObjectHandle makeRotate(Rotation rot); // Integer +pdftopdf_rotation_e _cfPDFToPDFGetRotate(QPDFObjectHandle page); +QPDFObjectHandle _cfPDFToPDFMakeRotate(pdftopdf_rotation_e rot); // Integer -double getUserUnit(QPDFObjectHandle page); +double _cfPDFToPDFGetUserUnit(QPDFObjectHandle page); // PDF CTM -class Matrix { +class _cfPDFToPDFMatrix { public: - Matrix(); // identity - Matrix(QPDFObjectHandle ar); + _cfPDFToPDFMatrix(); // identity + _cfPDFToPDFMatrix(QPDFObjectHandle ar); - Matrix &rotate(Rotation rot); - Matrix &rotate_move(Rotation rot,double width,double height); - Matrix &rotate(double rad); - // Matrix &rotate_deg(double deg); + _cfPDFToPDFMatrix &rotate(pdftopdf_rotation_e rot); + _cfPDFToPDFMatrix &rotate_move(pdftopdf_rotation_e rot,double width,double height); + _cfPDFToPDFMatrix &rotate(double rad); + // _cfPDFToPDFMatrix &rotate_deg(double deg); - Matrix &translate(double tx,double ty); - Matrix &scale(double sx,double sy); - Matrix &scale(double s) { return scale(s,s); } + _cfPDFToPDFMatrix &translate(double tx,double ty); + _cfPDFToPDFMatrix &scale(double sx,double sy); + _cfPDFToPDFMatrix &scale(double s) { return scale(s,s); } - Matrix &operator*=(const Matrix &rhs); + _cfPDFToPDFMatrix &operator*=(const _cfPDFToPDFMatrix &rhs); QPDFObjectHandle get() const; std::string get_string() const; diff --git a/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc b/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc index e9282836a..981fd7756 100644 --- a/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc +++ b/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc @@ -13,7 +13,7 @@ #include "pdftopdf.h" // Use: content.append(debug_box(pe.sub,xpos,ypos)); -static std::string debug_box(const PageRect &box,float xshift,float yshift) // {{{ +static std::string debug_box(const _cfPDFToPDFPageRect &box,float xshift,float yshift) // {{{ { return std::string("q 1 w 0.1 G\n ")+ QUtil::double_to_string(box.left+xshift)+" "+QUtil::double_to_string(box.bottom+yshift)+" m "+ @@ -27,7 +27,7 @@ static std::string debug_box(const PageRect &box,float xshift,float yshift) // { } // }}} -QPDF_PDFTOPDF_PageHandle::QPDF_PDFTOPDF_PageHandle(QPDFObjectHandle page,int orig_no) // {{{ +_cfPDFToPDFQPDFPageHandle::_cfPDFToPDFQPDFPageHandle(QPDFObjectHandle page,int orig_no) // {{{ : page(page), no(orig_no), rotation(ROT_0) @@ -35,7 +35,7 @@ QPDF_PDFTOPDF_PageHandle::QPDF_PDFTOPDF_PageHandle(QPDFObjectHandle page,int ori } // }}} -QPDF_PDFTOPDF_PageHandle::QPDF_PDFTOPDF_PageHandle(QPDF *pdf,float width,float height) // {{{ +_cfPDFToPDFQPDFPageHandle::_cfPDFToPDFQPDFPageHandle(QPDF *pdf,float width,float height) // {{{ : no(0), rotation(ROT_0) { @@ -49,7 +49,7 @@ QPDF_PDFTOPDF_PageHandle::QPDF_PDFTOPDF_PageHandle(QPDF *pdf,float width,float h " /MediaBox null " " /Contents null " ">>"); - page.replaceKey("/MediaBox",makeBox(0,0,width,height)); + page.replaceKey("/MediaBox",_cfPDFToPDFMakeBox(0,0,width,height)); page.replaceKey("/Contents",QPDFObjectHandle::newStream(pdf)); // xobjects: later (in get()) content.assign("q\n"); // TODO? different/not needed @@ -58,36 +58,36 @@ QPDF_PDFTOPDF_PageHandle::QPDF_PDFTOPDF_PageHandle(QPDF *pdf,float width,float h } // }}} -// Note: PDFTOPDF_Processor always works with "/Rotate"d and "/UserUnit"-scaled pages/coordinates/..., having 0,0 at left,bottom of the TrimBox -PageRect QPDF_PDFTOPDF_PageHandle::getRect() const // {{{ +// Note: _cfPDFToPDFProcessor always works with "/Rotate"d and "/UserUnit"-scaled pages/coordinates/..., having 0,0 at left,bottom of the TrimBox +_cfPDFToPDFPageRect _cfPDFToPDFQPDFPageHandle::get_rect() const // {{{ { page.assertInitialized(); - PageRect ret=getBoxAsRect(getTrimBox(page)); + _cfPDFToPDFPageRect ret=_cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page)); ret.translate(-ret.left,-ret.bottom); - ret.rotate_move(getRotate(page),ret.width,ret.height); - ret.scale(getUserUnit(page)); + ret.rotate_move(_cfPDFToPDFGetRotate(page),ret.width,ret.height); + ret.scale(_cfPDFToPDFGetUserUnit(page)); return ret; } // }}} -bool QPDF_PDFTOPDF_PageHandle::isExisting() const // {{{ +bool _cfPDFToPDFQPDFPageHandle::is_existing() const // {{{ { page.assertInitialized(); return content.empty(); } // }}} -QPDFObjectHandle QPDF_PDFTOPDF_PageHandle::get() // {{{ +QPDFObjectHandle _cfPDFToPDFQPDFPageHandle::get() // {{{ { QPDFObjectHandle ret=page; - if (!isExisting()) { // finish up page + if (!is_existing()) { // finish up page page.getKey("/Resources").replaceKey("/XObject",QPDFObjectHandle::newDictionary(xobjs)); content.append("Q\n"); page.getKey("/Contents").replaceStreamData(content,QPDFObjectHandle::newNull(),QPDFObjectHandle::newNull()); - page.replaceOrRemoveKey("/Rotate",makeRotate(rotation)); + page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(rotation)); } else { - Rotation rot=getRotate(page)+rotation; - page.replaceOrRemoveKey("/Rotate",makeRotate(rot)); + pdftopdf_rotation_e rot=_cfPDFToPDFGetRotate(page)+rotation; + page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(rot)); } page=QPDFObjectHandle(); // i.e. uninitialized return ret; @@ -96,23 +96,23 @@ QPDFObjectHandle QPDF_PDFTOPDF_PageHandle::get() // {{{ // TODO: we probably need a function "ungetRect()" to transform to page/form space // TODO: as member -static PageRect ungetRect(PageRect rect,const QPDF_PDFTOPDF_PageHandle &ph,Rotation rotation,QPDFObjectHandle page) +static _cfPDFToPDFPageRect ungetRect(_cfPDFToPDFPageRect rect,const _cfPDFToPDFQPDFPageHandle &ph,pdftopdf_rotation_e rotation,QPDFObjectHandle page) { - PageRect pg1=ph.getRect(); - PageRect pg2=getBoxAsRect(getTrimBox(page)); + _cfPDFToPDFPageRect pg1=ph.get_rect(); + _cfPDFToPDFPageRect pg2=_cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page)); // we have to invert /Rotate, /UserUnit and the left,bottom (TrimBox) translation - //Rotation_dump(rotation); - //Rotation_dump(getRotate(page)); + //_cfPDFToPDFRotationDump(rotation); + //_cfPDFToPDFRotationDump(_cfPDFToPDFGetRotate(page)); rect.width=pg1.width; rect.height=pg1.height; //std::swap(rect.width,rect.height); //rect.rotate_move(-rotation,rect.width,rect.height); - rect.rotate_move(-getRotate(page),pg1.width,pg1.height); - rect.scale(1.0/getUserUnit(page)); + rect.rotate_move(-_cfPDFToPDFGetRotate(page),pg1.width,pg1.height); + rect.scale(1.0/_cfPDFToPDFGetUserUnit(page)); - // PageRect pg2=getBoxAsRect(getTrimBox(page)); + // _cfPDFToPDFPageRect pg2=_cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page)); rect.translate(pg2.left,pg2.bottom); //rect.dump(); @@ -121,10 +121,10 @@ static PageRect ungetRect(PageRect rect,const QPDF_PDFTOPDF_PageHandle &ph,Rotat // TODO FIXME rotations are strange ... (via ungetRect) // TODO? for non-existing (either drop comment or facility to create split streams needed) -void QPDF_PDFTOPDF_PageHandle::add_border_rect(const PageRect &_rect,BorderType border,float fscale) // {{{ +void _cfPDFToPDFQPDFPageHandle::add_border_rect(const _cfPDFToPDFPageRect &_rect,pdftopdf_border_type_e border,float fscale) // {{{ { - assert(isExisting()); - assert(border!=BorderType::NONE); + assert(is_existing()); + assert(border!=pdftopdf_border_type_e::NONE); // straight from pstops const double lw=(border&THICK)?0.5:0.24; @@ -133,7 +133,7 @@ void QPDF_PDFTOPDF_PageHandle::add_border_rect(const PageRect &_rect,BorderType // (PageLeft+margin,PageBottom+margin) rect (PageRight-PageLeft-2*margin,...) ... for nup>1: PageLeft=0,etc. // if (double) margin+=2*fscale ...rect... - PageRect rect=ungetRect(_rect,*this,rotation,page); + _cfPDFToPDFPageRect rect=ungetRect(_rect,*this,rotation,page); assert(rect.left<=rect.right); assert(rect.bottom<=rect.top); @@ -149,7 +149,7 @@ void QPDF_PDFTOPDF_PageHandle::add_border_rect(const PageRect &_rect,BorderType } boxcmd+="Q\n"; - // if (!isExisting()) { + // if (!is_existing()) { // // TODO: only after // return; // } @@ -177,23 +177,23 @@ void QPDF_PDFTOPDF_PageHandle::add_border_rect(const PageRect &_rect,BorderType * Trim Box is used for trimming the page in required size. * scale tells if we need to scale input file. */ -Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc) +pdftopdf_rotation_e _cfPDFToPDFQPDFPageHandle::crop(const _cfPDFToPDFPageRect &cropRect,pdftopdf_rotation_e orientation,pdftopdf_rotation_e param_orientation,pdftopdf_position_e xpos,pdftopdf_position_e ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc) { page.assertInitialized(); - Rotation save_rotate = getRotate(page); + pdftopdf_rotation_e save_rotate = _cfPDFToPDFGetRotate(page); if(orientation==ROT_0||orientation==ROT_180) - page.replaceOrRemoveKey("/Rotate",makeRotate(ROT_90)); + page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(ROT_90)); else - page.replaceOrRemoveKey("/Rotate",makeRotate(ROT_0)); + page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(ROT_0)); - PageRect currpage= getBoxAsRect(getTrimBox(page)); + _cfPDFToPDFPageRect currpage= _cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page)); double width = currpage.right-currpage.left; double height = currpage.top-currpage.bottom; double pageWidth = cropRect.right-cropRect.left; double pageHeight = cropRect.top-cropRect.bottom; double final_w,final_h; //Width and height of cropped image. - Rotation pageRot = getRotate(page); + pdftopdf_rotation_e pageRot = _cfPDFToPDFGetRotate(page); if ((autorotate && (((pageRot == ROT_0 || pageRot == ROT_180) && pageWidth <= pageHeight) || @@ -226,43 +226,43 @@ Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orient width,height,final_w,final_h); double posw = (width-final_w)/2, posh = (height-final_h)/2; - // posw, posh : Position along width and height respectively. + // posw, posh : pdftopdf_position_e along width and height respectively. // Calculating required position. - if(xpos==Position::LEFT) + if(xpos==pdftopdf_position_e::LEFT) posw =0; - else if(xpos==Position::RIGHT) + else if(xpos==pdftopdf_position_e::RIGHT) posw*=2; - if(ypos==Position::TOP) + if(ypos==pdftopdf_position_e::TOP) posh*=2; - else if(ypos==Position::BOTTOM) + else if(ypos==pdftopdf_position_e::BOTTOM) posh=0; - // making PageRect for cropping. + // making _cfPDFToPDFPageRect for cropping. currpage.left += posw; currpage.bottom += posh; currpage.top =currpage.bottom+final_h; currpage.right=currpage.left+final_w; //Cropping. // TODO: Borders are covered by the image. buffer space? - page.replaceKey("/TrimBox",makeBox(currpage.left,currpage.bottom,currpage.right,currpage.top)); - page.replaceOrRemoveKey("/Rotate",makeRotate(save_rotate)); - return getRotate(page); + page.replaceKey("/TrimBox",_cfPDFToPDFMakeBox(currpage.left,currpage.bottom,currpage.right,currpage.top)); + page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(save_rotate)); + return _cfPDFToPDFGetRotate(page); } -bool QPDF_PDFTOPDF_PageHandle::is_landscape(Rotation orientation) +bool _cfPDFToPDFQPDFPageHandle::is_landscape(pdftopdf_rotation_e orientation) { page.assertInitialized(); - Rotation save_rotate = getRotate(page); + pdftopdf_rotation_e save_rotate = _cfPDFToPDFGetRotate(page); if(orientation==ROT_0||orientation==ROT_180) - page.replaceOrRemoveKey("/Rotate",makeRotate(ROT_90)); + page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(ROT_90)); else - page.replaceOrRemoveKey("/Rotate",makeRotate(ROT_0)); + page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(ROT_0)); - PageRect currpage= getBoxAsRect(getTrimBox(page)); + _cfPDFToPDFPageRect currpage= _cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page)); double width = currpage.right-currpage.left; double height = currpage.top-currpage.bottom; - page.replaceOrRemoveKey("/Rotate",makeRotate(save_rotate)); + page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(save_rotate)); if(width>height) return true; return false; @@ -270,18 +270,18 @@ bool QPDF_PDFTOPDF_PageHandle::is_landscape(Rotation orientation) // TODO: better cropping // TODO: test/fix with qsub rotation -void QPDF_PDFTOPDF_PageHandle::add_subpage(const std::shared_ptr &sub,float xpos,float ypos,float scale,const PageRect *crop) // {{{ +void _cfPDFToPDFQPDFPageHandle::add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,float xpos,float ypos,float scale,const _cfPDFToPDFPageRect *crop) // {{{ { - auto qsub=dynamic_cast(sub.get()); + auto qsub=dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(sub.get()); assert(qsub); std::string xoname="/X"+QUtil::int_to_string((qsub->no!=-1)?qsub->no:++no); if (crop) { - PageRect pg=qsub->getRect(),tmp=*crop; + _cfPDFToPDFPageRect pg=qsub->get_rect(),tmp=*crop; // we need to fix a too small cropbox. tmp.width=tmp.right-tmp.left; tmp.height=tmp.top-tmp.bottom; - tmp.rotate_move(-getRotate(qsub->page),tmp.width,tmp.height); // TODO TODO (pg.width? / unneeded?) + tmp.rotate_move(-_cfPDFToPDFGetRotate(qsub->page),tmp.width,tmp.height); // TODO TODO (pg.width? / unneeded?) // TODO: better // TODO: we need to obey page./Rotate if (pg.widthpage); + _cfPDFToPDFPageRect rect=ungetRect(pg,*qsub,ROT_0,qsub->page); - qsub->page.replaceKey("/TrimBox",makeBox(rect.left,rect.bottom,rect.right,rect.top)); + qsub->page.replaceKey("/TrimBox",_cfPDFToPDFMakeBox(rect.left,rect.bottom,rect.right,rect.top)); // TODO? do everything for cropping here? } - xobjs[xoname]=makeXObject(qsub->page.getOwningQPDF(),qsub->page); // trick: should be the same as page->getOwningQPDF() [only after it's made indirect] + xobjs[xoname]=_cfPDFToPDFMakeXObject(qsub->page.getOwningQPDF(),qsub->page); // trick: should be the same as page->getOwningQPDF() [only after it's made indirect] - Matrix mtx; + _cfPDFToPDFMatrix mtx; mtx.translate(xpos,ypos); mtx.scale(scale); mtx.rotate(qsub->rotation); // TODO? -sub.rotation ? // TODO FIXME: this might need another translation!? - if (crop) { // TODO? other technique: set trim-box before makeXObject (but this modifies original page) + if (crop) { // TODO? other technique: set trim-box before _cfPDFToPDFMakeXObject (but this modifies original page) mtx.translate(crop->left,crop->bottom); // crop->dump(); } @@ -318,11 +318,11 @@ void QPDF_PDFTOPDF_PageHandle::add_subpage(const std::shared_ptrpage, with rotation // replace all our data - *this=QPDF_PDFTOPDF_PageHandle(subpage.getOwningQPDF(),orig.width,orig.height); + *this=_cfPDFToPDFQPDFPageHandle(subpage.getOwningQPDF(),orig.width,orig.height); - xobjs[xoname]=makeXObject(subpage.getOwningQPDF(),subpage); // we can only now set this->xobjs + xobjs[xoname]=_cfPDFToPDFMakeXObject(subpage.getOwningQPDF(),subpage); // we can only now set this->xobjs // content.append(std::string("1 0 0 1 0 0 cm\n "); content.append(xoname+" Do\n"); - assert(!isExisting()); + assert(!is_existing()); } static const char *pre="%pdftopdf cm\n"; @@ -349,17 +349,17 @@ void QPDF_PDFTOPDF_PageHandle::mirror() // {{{ } // }}} -void QPDF_PDFTOPDF_PageHandle::rotate(Rotation rot) // {{{ +void _cfPDFToPDFQPDFPageHandle::rotate(pdftopdf_rotation_e rot) // {{{ { rotation=rot; // "rotation += rot;" ? } // }}} -void QPDF_PDFTOPDF_PageHandle::add_label(const PageRect &_rect, const std::string label) // {{{ +void _cfPDFToPDFQPDFPageHandle::add_label(const _cfPDFToPDFPageRect &_rect, const std::string label) // {{{ { - assert(isExisting()); + assert(is_existing()); - PageRect rect = ungetRect (_rect, *this, rotation, page); + _cfPDFToPDFPageRect rect = ungetRect (_rect, *this, rotation, page); assert (rect.left <= rect.right); assert (rect.bottom <= rect.top); @@ -449,14 +449,14 @@ void QPDF_PDFTOPDF_PageHandle::add_label(const PageRect &_rect, const std::strin } // }}} -void QPDF_PDFTOPDF_PageHandle::debug(const PageRect &rect,float xpos,float ypos) // {{{ +void _cfPDFToPDFQPDFPageHandle::debug(const _cfPDFToPDFPageRect &rect,float xpos,float ypos) // {{{ { - assert(!isExisting()); + assert(!is_existing()); content.append(debug_box(rect,xpos,ypos)); } // }}} -void QPDF_PDFTOPDF_Processor::closeFile() // {{{ +void _cfPDFToPDFQPDFProcessor::close_file() // {{{ { pdf.reset(); hasCM=false; @@ -465,42 +465,42 @@ void QPDF_PDFTOPDF_Processor::closeFile() // {{{ // TODO? try/catch for PDF parsing errors? -bool QPDF_PDFTOPDF_Processor::loadFile(FILE *f,pdftopdf_doc_t *doc,ArgOwnership take,int flatten_forms) // {{{ +bool _cfPDFToPDFQPDFProcessor::load_file(FILE *f,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take,int flatten_forms) // {{{ { - closeFile(); + close_file(); if (!f) { - throw std::invalid_argument("loadFile(NULL,...) not allowed"); + throw std::invalid_argument("load_file(NULL,...) not allowed"); } try { pdf.reset(new QPDF); } catch (...) { - if (take==TakeOwnership) { + if (take==CF_PDFTOPDF_TAKE_OWNERSHIP) { fclose(f); } throw; } switch (take) { - case WillStayAlive: + case CF_PDFTOPDF_WILL_STAY_ALIVE: try { pdf->processFile("temp file",f,false); } catch (const std::exception &e) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, - "cfFilterPDFToPDF: loadFile failed: %s", e.what()); + "cfFilterPDFToPDF: load_file failed: %s", e.what()); return false; } break; - case TakeOwnership: + case CF_PDFTOPDF_TAKE_OWNERSHIP: try { pdf->processFile("temp file",f,true); } catch (const std::exception &e) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, - "cfFilterPDFToPDF: loadFile failed: %s", e.what()); + "cfFilterPDFToPDF: load_file failed: %s", e.what()); return false; } break; - case MustDuplicate: + case CF_PDFTOPDF_MUST_DUPLICATE: if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, - "cfFilterPDFToPDF: loadFile with MustDuplicate is not supported"); + "cfFilterPDFToPDF: load_file with CF_PDFTOPDF_MUST_DUPLICATE is not supported"); return false; } start(flatten_forms); @@ -508,15 +508,15 @@ bool QPDF_PDFTOPDF_Processor::loadFile(FILE *f,pdftopdf_doc_t *doc,ArgOwnership } // }}} -bool QPDF_PDFTOPDF_Processor::loadFilename(const char *name,pdftopdf_doc_t *doc,int flatten_forms) // {{{ +bool _cfPDFToPDFQPDFProcessor::load_filename(const char *name,pdftopdf_doc_t *doc,int flatten_forms) // {{{ { - closeFile(); + close_file(); try { pdf.reset(new QPDF); pdf->processFile(name); } catch (const std::exception &e) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, - "cfFilterPDFToPDF: loadFilename failed: %s",e.what()); + "cfFilterPDFToPDF: load_filename failed: %s",e.what()); return false; } start(flatten_forms); @@ -524,7 +524,7 @@ bool QPDF_PDFTOPDF_Processor::loadFilename(const char *name,pdftopdf_doc_t *doc, } // }}} -void QPDF_PDFTOPDF_Processor::start(int flatten_forms) // {{{ +void _cfPDFToPDFQPDFProcessor::start(int flatten_forms) // {{{ { assert(pdf); @@ -553,7 +553,7 @@ void QPDF_PDFTOPDF_Processor::start(int flatten_forms) // {{{ } // }}} -bool QPDF_PDFTOPDF_Processor::check_print_permissions(pdftopdf_doc_t *doc) // {{{ +bool _cfPDFToPDFQPDFProcessor::check_print_permissions(pdftopdf_doc_t *doc) // {{{ { if (!pdf) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, @@ -564,9 +564,9 @@ bool QPDF_PDFTOPDF_Processor::check_print_permissions(pdftopdf_doc_t *doc) // {{ } // }}} -std::vector> QPDF_PDFTOPDF_Processor::get_pages(pdftopdf_doc_t *doc) // {{{ +std::vector> _cfPDFToPDFQPDFProcessor::get_pages(pdftopdf_doc_t *doc) // {{{ { - std::vector> ret; + std::vector> ret; if (!pdf) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: No PDF loaded"); @@ -576,30 +576,30 @@ std::vector> QPDF_PDFTOPDF_Processor::get_p const int len=orig_pages.size(); ret.reserve(len); for (int iA=0;iA(new QPDF_PDFTOPDF_PageHandle(orig_pages[iA],iA+1))); + ret.push_back(std::shared_ptr<_cfPDFToPDFPageHandle>(new _cfPDFToPDFQPDFPageHandle(orig_pages[iA],iA+1))); } return ret; } // }}} -std::shared_ptr QPDF_PDFTOPDF_Processor::new_page(float width,float height,pdftopdf_doc_t *doc) // {{{ +std::shared_ptr<_cfPDFToPDFPageHandle> _cfPDFToPDFQPDFProcessor::new_page(float width,float height,pdftopdf_doc_t *doc) // {{{ { if (!pdf) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, "cfFilterPDFToPDF: No PDF loaded"); assert(0); - return std::shared_ptr(); + return std::shared_ptr<_cfPDFToPDFPageHandle>(); } - return std::shared_ptr(new QPDF_PDFTOPDF_PageHandle(pdf.get(),width,height)); - // return std::make_shared(pdf.get(),width,height); + return std::shared_ptr<_cfPDFToPDFQPDFPageHandle>(new _cfPDFToPDFQPDFPageHandle(pdf.get(),width,height)); + // return std::make_shared<_cfPDFToPDFQPDFPageHandle>(pdf.get(),width,height); // problem: make_shared not friend } // }}} -void QPDF_PDFTOPDF_Processor::add_page(std::shared_ptr page,bool front) // {{{ +void _cfPDFToPDFQPDFProcessor::add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,bool front) // {{{ { assert(pdf); - auto qpage=dynamic_cast(page.get()); + auto qpage=dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(page.get()); if (qpage) { pdf->addPage(qpage->get(),front); } @@ -614,7 +614,7 @@ pdf->getRoot().removeKey("/OpenAction"); pdf->getRoot().removeKey("/PageLabels"); #endif -void QPDF_PDFTOPDF_Processor::multiply(int copies,bool collate) // {{{ +void _cfPDFToPDFQPDFProcessor::multiply(int copies,bool collate) // {{{ { assert(pdf); assert(copies>0); @@ -639,7 +639,7 @@ void QPDF_PDFTOPDF_Processor::multiply(int copies,bool collate) // {{{ // }}} // TODO? elsewhere? -void QPDF_PDFTOPDF_Processor::autoRotateAll(bool dst_lscape,Rotation normal_landscape) // {{{ +void _cfPDFToPDFQPDFProcessor::auto_rotate_all(bool dst_lscape,pdftopdf_rotation_e normal_landscape) // {{{ { assert(pdf); @@ -647,21 +647,21 @@ void QPDF_PDFTOPDF_Processor::autoRotateAll(bool dst_lscape,Rotation normal_land for (int iA=0;iAret.height); if (src_lscape!=dst_lscape) { - Rotation rotation=normal_landscape; + pdftopdf_rotation_e rotation=normal_landscape; // TODO? other rotation direction, e.g. if (src_rot==ROT_0)&&(param.orientation==ROT_270) ... etc. // rotation=ROT_270; - page.replaceOrRemoveKey("/Rotate",makeRotate(src_rot+rotation)); + page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(src_rot+rotation)); } } } @@ -670,24 +670,24 @@ void QPDF_PDFTOPDF_Processor::autoRotateAll(bool dst_lscape,Rotation normal_land #include "qpdf_cm.h" // TODO -void QPDF_PDFTOPDF_Processor::addCM(const char *defaulticc,const char *outputicc) // {{{ +void _cfPDFToPDFQPDFProcessor::add_cm(const char *defaulticc,const char *outputicc) // {{{ { assert(pdf); - if (hasOutputIntent(*pdf)) { + if (_cfPDFToPDFHasOutputIntent(*pdf)) { return; // nothing to do } - QPDFObjectHandle srcicc=setDefaultICC(*pdf,defaulticc); // TODO? rename to putDefaultICC? - addDefaultRGB(*pdf,srcicc); + QPDFObjectHandle srcicc=_cfPDFToPDFSetDefaultICC(*pdf,defaulticc); // TODO? rename to putDefaultICC? + _cfPDFToPDFAddDefaultRGB(*pdf,srcicc); - addOutputIntent(*pdf,outputicc); + _cfPDFToPDFAddOutputIntent(*pdf,outputicc); hasCM=true; } // }}} -void QPDF_PDFTOPDF_Processor::setComments(const std::vector &comments) // {{{ +void _cfPDFToPDFQPDFProcessor::set_comments(const std::vector &comments) // {{{ { extraheader.clear(); const int len=comments.size(); @@ -699,22 +699,22 @@ void QPDF_PDFTOPDF_Processor::setComments(const std::vector &commen } // }}} -void QPDF_PDFTOPDF_Processor::emitFile(FILE *f,pdftopdf_doc_t *doc,ArgOwnership take) // {{{ +void _cfPDFToPDFQPDFProcessor::emit_file(FILE *f,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take) // {{{ { if (!pdf) { return; } QPDFWriter out(*pdf); switch (take) { - case WillStayAlive: + case CF_PDFTOPDF_WILL_STAY_ALIVE: out.setOutputFile("temp file",f,false); break; - case TakeOwnership: + case CF_PDFTOPDF_TAKE_OWNERSHIP: out.setOutputFile("temp file",f,true); break; - case MustDuplicate: + case CF_PDFTOPDF_MUST_DUPLICATE: if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, - "cfFilterPDFToPDF: emitFile with MustDuplicate is not supported"); + "cfFilterPDFToPDF: emit_file with CF_PDFTOPDF_MUST_DUPLICATE is not supported"); return; } if (hasCM) { @@ -730,7 +730,7 @@ void QPDF_PDFTOPDF_Processor::emitFile(FILE *f,pdftopdf_doc_t *doc,ArgOwnership } // }}} -void QPDF_PDFTOPDF_Processor::emitFilename(const char *name,pdftopdf_doc_t *doc) // {{{ +void _cfPDFToPDFQPDFProcessor::emit_filename(const char *name,pdftopdf_doc_t *doc) // {{{ { if (!pdf) { return; @@ -759,7 +759,7 @@ void QPDF_PDFTOPDF_Processor::emitFilename(const char *name,pdftopdf_doc_t *doc) // TODO: // loadPDF(); success? -bool QPDF_PDFTOPDF_Processor::hasAcroForm() // {{{ +bool _cfPDFToPDFQPDFProcessor::has_acro_form() // {{{ { if (!pdf) { return false; diff --git a/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.h b/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.h index 732e7cbff..18b84e9ce 100644 --- a/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.h +++ b/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.h @@ -1,66 +1,66 @@ -#ifndef QPDF_PDFTOPDF_PROCESSOR_H -#define QPDF_PDFTOPDF_PROCESSOR_H +#ifndef _CUPS_FILTERS_PDFTOPDF_QPDF_PDFTOPDF_PROCESSOR_H +#define _CUPS_FILTERS_PDFTOPDF_QPDF_PDFTOPDF_PROCESSOR_H #include "pdftopdf_processor.h" #include -class QPDF_PDFTOPDF_PageHandle : public PDFTOPDF_PageHandle { +class _cfPDFToPDFQPDFPageHandle : public _cfPDFToPDFPageHandle { public: - virtual PageRect getRect() const; - virtual void add_border_rect(const PageRect &rect,BorderType border,float fscale); - virtual void add_subpage(const std::shared_ptr &sub,float xpos,float ypos,float scale,const PageRect *crop=NULL); + virtual _cfPDFToPDFPageRect get_rect() const; + virtual void add_border_rect(const _cfPDFToPDFPageRect &rect,pdftopdf_border_type_e border,float fscale); + virtual void add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,float xpos,float ypos,float scale,const _cfPDFToPDFPageRect *crop=NULL); virtual void mirror(); - virtual void rotate(Rotation rot); - virtual void add_label(const PageRect &rect, const std::string label); - virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc); - virtual bool is_landscape(Rotation orientation); - void debug(const PageRect &rect,float xpos,float ypos); + virtual void rotate(pdftopdf_rotation_e rot); + virtual void add_label(const _cfPDFToPDFPageRect &rect, const std::string label); + virtual pdftopdf_rotation_e crop(const _cfPDFToPDFPageRect &cropRect,pdftopdf_rotation_e orientation,pdftopdf_rotation_e param_orientation,pdftopdf_position_e xpos,pdftopdf_position_e ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc); + virtual bool is_landscape(pdftopdf_rotation_e orientation); + void debug(const _cfPDFToPDFPageRect &rect,float xpos,float ypos); private: - bool isExisting() const; + bool is_existing() const; QPDFObjectHandle get(); // only once! private: - friend class QPDF_PDFTOPDF_Processor; + friend class _cfPDFToPDFQPDFProcessor; // 1st mode: existing - QPDF_PDFTOPDF_PageHandle(QPDFObjectHandle page,int orig_no=-1); + _cfPDFToPDFQPDFPageHandle(QPDFObjectHandle page,int orig_no=-1); QPDFObjectHandle page; int no; // 2nd mode: create new - QPDF_PDFTOPDF_PageHandle(QPDF *pdf,float width,float height); + _cfPDFToPDFQPDFPageHandle(QPDF *pdf,float width,float height); std::map xobjs; std::string content; - Rotation rotation; + pdftopdf_rotation_e rotation; }; -class QPDF_PDFTOPDF_Processor : public PDFTOPDF_Processor { +class _cfPDFToPDFQPDFProcessor : public _cfPDFToPDFProcessor { public: - virtual bool loadFile(FILE *f,pdftopdf_doc_t *doc,ArgOwnership take=WillStayAlive,int flatten_forms=1); - virtual bool loadFilename(const char *name,pdftopdf_doc_t *doc,int flatten_forms=1); + virtual bool load_file(FILE *f,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take=CF_PDFTOPDF_WILL_STAY_ALIVE,int flatten_forms=1); + virtual bool load_filename(const char *name,pdftopdf_doc_t *doc,int flatten_forms=1); // TODO: virtual bool may_modify/may_print/? virtual bool check_print_permissions(pdftopdf_doc_t *doc); - // virtual bool setProcess(const ProcessingParameters ¶m) =0; + // virtual bool set_process(const _cfPDFToPDFProcessingParameters ¶m) =0; - virtual std::vector> get_pages(pdftopdf_doc_t *doc); - virtual std::shared_ptr new_page(float width,float height,pdftopdf_doc_t *doc); + virtual std::vector> get_pages(pdftopdf_doc_t *doc); + virtual std::shared_ptr<_cfPDFToPDFPageHandle> new_page(float width,float height,pdftopdf_doc_t *doc); - virtual void add_page(std::shared_ptr page,bool front); + virtual void add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,bool front); virtual void multiply(int copies,bool collate); - virtual void autoRotateAll(bool dst_lscape,Rotation normal_landscape); - virtual void addCM(const char *defaulticc,const char *outputicc); + virtual void auto_rotate_all(bool dst_lscape,pdftopdf_rotation_e normal_landscape); + virtual void add_cm(const char *defaulticc,const char *outputicc); - virtual void setComments(const std::vector &comments); + virtual void set_comments(const std::vector &comments); - virtual void emitFile(FILE *dst,pdftopdf_doc_t *doc,ArgOwnership take=WillStayAlive); - virtual void emitFilename(const char *name,pdftopdf_doc_t *doc); + virtual void emit_file(FILE *dst,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take=CF_PDFTOPDF_WILL_STAY_ALIVE); + virtual void emit_filename(const char *name,pdftopdf_doc_t *doc); - virtual bool hasAcroForm(); + virtual bool has_acro_form(); private: - void closeFile(); + void close_file(); void start(int flatten_forms); private: std::unique_ptr pdf; diff --git a/cupsfilters/pdftopdf/qpdf_tools.cc b/cupsfilters/pdftopdf/qpdf_tools.cc index 44cb98189..5be6b6f42 100644 --- a/cupsfilters/pdftopdf/qpdf_tools.cc +++ b/cupsfilters/pdftopdf/qpdf_tools.cc @@ -1,12 +1,12 @@ #include "qpdf_tools.h" -QPDFObjectHandle getMediaBox(QPDFObjectHandle page) // {{{ +QPDFObjectHandle _cfPDFToPDFGetMediaBox(QPDFObjectHandle page) // {{{ { return page.getKey("/MediaBox"); } // }}} -QPDFObjectHandle getCropBox(QPDFObjectHandle page) // {{{ +QPDFObjectHandle _cfPDFToPDFGetCropBox(QPDFObjectHandle page) // {{{ { if (page.hasKey("/CropBox")) { return page.getKey("/CropBox"); @@ -15,34 +15,34 @@ QPDFObjectHandle getCropBox(QPDFObjectHandle page) // {{{ } // }}} -QPDFObjectHandle getBleedBox(QPDFObjectHandle page) // {{{ +QPDFObjectHandle _cfPDFToPDFGetBleedBox(QPDFObjectHandle page) // {{{ { if (page.hasKey("/BleedBox")) { return page.getKey("/BleedBox"); } - return getCropBox(page); + return _cfPDFToPDFGetCropBox(page); } // }}} -QPDFObjectHandle getTrimBox(QPDFObjectHandle page) // {{{ +QPDFObjectHandle _cfPDFToPDFGetTrimBox(QPDFObjectHandle page) // {{{ { if (page.hasKey("/TrimBox")) { return page.getKey("/TrimBox"); } - return getCropBox(page); + return _cfPDFToPDFGetCropBox(page); } // }}} -QPDFObjectHandle getArtBox(QPDFObjectHandle page) // {{{ +QPDFObjectHandle _cfPDFToPDFGetArtBox(QPDFObjectHandle page) // {{{ { if (page.hasKey("/ArtBox")) { return page.getKey("/ArtBox"); } - return getCropBox(page); + return _cfPDFToPDFGetCropBox(page); } // }}} -QPDFObjectHandle makePage(QPDF &pdf,const std::map &xobjs,QPDFObjectHandle mediabox,const std::string &content) // {{{ +QPDFObjectHandle _cfPDFToPDFMakePage(QPDF &pdf,const std::map &xobjs,QPDFObjectHandle mediabox,const std::string &content) // {{{ { QPDFObjectHandle ret=QPDFObjectHandle::newDictionary(); ret.replaceKey("/Type",QPDFObjectHandle::newName("/Page")); @@ -57,7 +57,7 @@ QPDFObjectHandle makePage(QPDF &pdf,const std::map } // }}} -QPDFObjectHandle makeBox(double x1,double y1,double x2,double y2) // {{{ +QPDFObjectHandle _cfPDFToPDFMakeBox(double x1,double y1,double x2,double y2) // {{{ { QPDFObjectHandle ret=QPDFObjectHandle::newArray(); ret.appendItem(QPDFObjectHandle::newReal(x1)); diff --git a/cupsfilters/pdftopdf/qpdf_tools.h b/cupsfilters/pdftopdf/qpdf_tools.h index 20a19fb2a..5a39479e6 100644 --- a/cupsfilters/pdftopdf/qpdf_tools.h +++ b/cupsfilters/pdftopdf/qpdf_tools.h @@ -1,18 +1,18 @@ -#ifndef QPDF_TOOLS_H_ -#define QPDF_TOOLS_H_ +#ifndef _CUPS_FILTERS_PDFTOPDF_QPDF_TOOLS_H_ +#define _CUPS_FILTERS_PDFTOPDF_QPDF_TOOLS_H_ #include #include #include -QPDFObjectHandle getMediaBox(QPDFObjectHandle page); -QPDFObjectHandle getCropBox(QPDFObjectHandle page); -QPDFObjectHandle getBleedBox(QPDFObjectHandle page); -QPDFObjectHandle getTrimBox(QPDFObjectHandle page); -QPDFObjectHandle getArtBox(QPDFObjectHandle page); +QPDFObjectHandle _cfPDFToPDFGetMediaBox(QPDFObjectHandle page); +QPDFObjectHandle _cfPDFToPDFGetCropBox(QPDFObjectHandle page); +QPDFObjectHandle _cfPDFToPDFGetBleedBox(QPDFObjectHandle page); +QPDFObjectHandle _cfPDFToPDFGetTrimBox(QPDFObjectHandle page); +QPDFObjectHandle _cfPDFToPDFGetArtBox(QPDFObjectHandle page); -QPDFObjectHandle makePage(QPDF &pdf,const std::map &xobjs,QPDFObjectHandle mediabox,const std::string &content); +QPDFObjectHandle _cfPDFToPDFMakePage(QPDF &pdf,const std::map &xobjs,QPDFObjectHandle mediabox,const std::string &content); -QPDFObjectHandle makeBox(double x1,double y1,double x2,double y2); +QPDFObjectHandle _cfPDFToPDFMakeBox(double x1,double y1,double x2,double y2); #endif diff --git a/cupsfilters/pdftopdf/qpdf_xobject.cc b/cupsfilters/pdftopdf/qpdf_xobject.cc index cc33f43a5..5914c2bae 100644 --- a/cupsfilters/pdftopdf/qpdf_xobject.cc +++ b/cupsfilters/pdftopdf/qpdf_xobject.cc @@ -79,7 +79,7 @@ void CombineFromContents_Provider::provideStreamData(int objid, int generation, [/VP] viewport rects -- ignore/drop or recalculate into new page */ -QPDFObjectHandle makeXObject(QPDF *pdf,QPDFObjectHandle page) +QPDFObjectHandle _cfPDFToPDFMakeXObject(QPDF *pdf,QPDFObjectHandle page) { page.assertPageObject(); @@ -90,20 +90,20 @@ QPDFObjectHandle makeXObject(QPDF *pdf,QPDFObjectHandle page) dict.replaceKey("/Subtype",QPDFObjectHandle::newName("/Form")); // required // dict.replaceKey("/FormType",QPDFObjectHandle::newInteger(1)); // optional - QPDFObjectHandle box=getTrimBox(page); // already in "form space" + QPDFObjectHandle box=_cfPDFToPDFGetTrimBox(page); // already in "form space" dict.replaceKey("/BBox",box); // reqd // [/Matrix .] ... default is [1 0 0 1 0 0]; we incorporate /UserUnit and /Rotate here - Matrix mtx; + _cfPDFToPDFMatrix mtx; if (page.hasKey("/UserUnit")) { mtx.scale(page.getKey("/UserUnit").getNumericValue()); } // transform, so that bbox is [0 0 w h] (in outer space, but after UserUnit) - Rotation rot=getRotate(page); + pdftopdf_rotation_e rot=_cfPDFToPDFGetRotate(page); // calculate rotation effect on [0 0 w h] - PageRect bbox=getBoxAsRect(box),tmp; + _cfPDFToPDFPageRect bbox=_cfPDFToPDFGetBoxAsRect(box),tmp; tmp.left=0; tmp.bottom=0; tmp.right=0; diff --git a/cupsfilters/pdftopdf/qpdf_xobject.h b/cupsfilters/pdftopdf/qpdf_xobject.h index 096b56d8b..a95f6bdf2 100644 --- a/cupsfilters/pdftopdf/qpdf_xobject.h +++ b/cupsfilters/pdftopdf/qpdf_xobject.h @@ -1,8 +1,8 @@ -#ifndef QPDF_XOBJECT_H_ -#define QPDF_XOBJECT_H_ +#ifndef _CUPS_FILTERS_PDFTOPDF_QPDF_XOBJECT_H_ +#define _CUPS_FILTERS_PDFTOPDF_QPDF_XOBJECT_H_ #include -QPDFObjectHandle makeXObject(QPDF *pdf,QPDFObjectHandle page); +QPDFObjectHandle _cfPDFToPDFMakeXObject(QPDF *pdf, QPDFObjectHandle page); #endif diff --git a/cupsfilters/pdftops.c b/cupsfilters/pdftops.c index 0a68339a9..55497be63 100644 --- a/cupsfilters/pdftops.c +++ b/cupsfilters/pdftops.c @@ -100,7 +100,8 @@ const char *pstops_exclude_page_management[] = { * file */ -static void parsePDFTOPDFComment(char *filename, /* I - Input file */ +static void +parse_pdftopdf_comment(char *filename, /* I - Input file */ int *pdftopdfapplied, /* O - Does the input data come from pdftopdf filter?*/ @@ -165,7 +166,7 @@ static void parsePDFTOPDFComment(char *filename, /* I - Input file */ * Check whether given file is empty */ -int /* O - Result: 1: Empty; 0: Contains pages */ +static int /* O - Result: 1: Empty; 0: Contains pages */ is_empty(char *filename, /* I - Input file */ cf_logfunc_t log, /* I - Log function */ void *ld) /* I - Auxiliary data for log function */ @@ -378,8 +379,8 @@ cfFilterPDFToPS(int inputfd, /* I - File descriptor input stream */ * Read out copy counts and collate setting passed over by pdftopdf */ - parsePDFTOPDFComment(filename, &pdftopdfapplied, deviceCopies, - &deviceCollate, log, ld); + parse_pdftopdf_comment(filename, &pdftopdfapplied, deviceCopies, + &deviceCollate, log, ld); /* * CUPS option list diff --git a/cupsfilters/pdftoraster.cxx b/cupsfilters/pdftoraster.cxx index 1fc9d1d88..089d8e1db 100644 --- a/cupsfilters/pdftoraster.cxx +++ b/cupsfilters/pdftoraster.cxx @@ -140,28 +140,28 @@ typedef struct pdftoraster_doc_s cms_profile_t colour_profile; } pdftoraster_doc_t; -typedef unsigned char *(*ConvertCSpaceFunc)(unsigned char *src, +typedef unsigned char *(*convert_cspace_func)(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t* doc); -typedef unsigned char *(*ConvertLineFunc)(unsigned char *src, +typedef unsigned char *(*convert_line_func)(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, unsigned int size, pdftoraster_doc_t* doc, - ConvertCSpaceFunc convertCSpace); + convert_cspace_func convertCSpace); typedef struct conversion_function_s { - ConvertCSpaceFunc convertCSpace; /* Function for conversion of colorspaces */ - ConvertLineFunc convertLineOdd;/* Function tom modify raster data of a line */ - ConvertLineFunc convertLineEven; + convert_cspace_func convertCSpace; /* Function for conversion of colorspaces */ + convert_line_func convertLineOdd;/* Function tom modify raster data of a line */ + convert_line_func convertLineEven; } conversion_function_t; -cmsCIExyY adobergb_wp() +static cmsCIExyY adobergb_wp() { double * xyY = cfCmWhitePointAdobeRGB(); cmsCIExyY wp; @@ -173,7 +173,7 @@ cmsCIExyY adobergb_wp() return wp; } -cmsCIExyY sgray_wp() +static cmsCIExyY sgray_wp() { double * xyY = cfCmWhitePointSGray(); cmsCIExyY wp; @@ -185,7 +185,7 @@ cmsCIExyY sgray_wp() return wp; } -cmsCIExyYTRIPLE adobergb_matrix() +static cmsCIExyYTRIPLE adobergb_matrix() { cmsCIExyYTRIPLE m; @@ -204,7 +204,7 @@ cmsCIExyYTRIPLE adobergb_matrix() return m; } -cmsHPROFILE adobergb_profile() +static cmsHPROFILE adobergb_profile() { cmsHPROFILE adobergb; @@ -228,7 +228,7 @@ cmsHPROFILE adobergb_profile() return adobergb; } -cmsHPROFILE sgray_profile() +static cmsHPROFILE sgray_profile() { cmsHPROFILE sgray; @@ -248,19 +248,19 @@ cmsHPROFILE sgray_profile() #ifdef USE_LCMS1 -static int lcmsErrorHandler(int ErrorCode, const char *ErrorText) +static int lcms_error_handler(int ErrorCode, const char *ErrorText) { return 1; } #else -static void lcmsErrorHandler(cmsContext contextId, cmsUInt32Number ErrorCode, +static void lcms_error_handler(cmsContext contextId, cmsUInt32Number ErrorCode, const char *ErrorText) { return; } #endif -static void handleRqeuiresPageRegion(pdftoraster_doc_t*doc) { +static void handle_requires_page_region(pdftoraster_doc_t*doc) { ppd_choice_t *mf; ppd_choice_t *is; ppd_attr_t *rregions = NULL; @@ -296,7 +296,7 @@ static void handleRqeuiresPageRegion(pdftoraster_doc_t*doc) { } } -static int parseOpts(cf_filter_data_t *data, +static int parse_opts(cf_filter_data_t *data, cf_filter_out_format_t outformat, pdftoraster_doc_t *doc) { @@ -320,7 +320,7 @@ static int parseOpts(cf_filter_data_t *data, doc->ppd = data->ppd; if (doc->ppd) - handleRqeuiresPageRegion(doc); + handle_requires_page_region(doc); else if (log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterPDFToRaster: PPD file is not specified."); @@ -500,7 +500,7 @@ static int parseOpts(cf_filter_data_t *data, return (0); } -static void parsePDFTOPDFComment(FILE *fp, int* deviceCopies, bool* deviceCollate) +static void parse_pdftopdf_comment(FILE *fp, int* deviceCopies, bool* deviceCollate) { char buf[4096]; int i; @@ -532,9 +532,9 @@ static void parsePDFTOPDFComment(FILE *fp, int* deviceCopies, bool* deviceCollat } } -static unsigned char *reverseLine(unsigned char *src, unsigned char *dst, +static unsigned char *reverse_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *p = src; @@ -544,9 +544,9 @@ static unsigned char *reverseLine(unsigned char *src, unsigned char *dst, return src; } -static unsigned char *reverseLineSwapByte(unsigned char *src, +static unsigned char *reverse_line_swap_byte(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, - unsigned int pixels, unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int pixels, unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+size-1; unsigned char *dp = dst; @@ -558,25 +558,25 @@ static unsigned char *reverseLineSwapByte(unsigned char *src, } -static unsigned char *reverseLineSwapBit(unsigned char *src, +static unsigned char *reverse_line_swap_bit(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, - unsigned int pixels, unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int pixels, unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { dst = cfReverseOneBitLineSwap(src, dst, pixels, size); return dst; } -static unsigned char *rgbToCMYKLine(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_cmyk_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { cfImageRGBToCMYK(src,dst,pixels); return dst; } -static unsigned char *rgbToCMYKLineSwap(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_cmyk_line_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+(pixels-1)*3; unsigned char *dp = dst; @@ -587,17 +587,17 @@ static unsigned char *rgbToCMYKLineSwap(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *rgbToCMYLine(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_cmy_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { cfImageRGBToCMY(src,dst,pixels); return dst; } -static unsigned char *rgbToCMYLineSwap(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_cmy_line_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+size-3; unsigned char *dp = dst; @@ -608,9 +608,9 @@ static unsigned char *rgbToCMYLineSwap(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *rgbToKCMYLine(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_kcmy_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src; unsigned char *dp = dst; @@ -628,9 +628,9 @@ static unsigned char *rgbToKCMYLine(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *rgbToKCMYLineSwap(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_kcmy_line_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+(pixels-1)*3; unsigned char *dp = dst; @@ -648,17 +648,17 @@ static unsigned char *rgbToKCMYLineSwap(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *lineNoop(unsigned char *src, unsigned char *dst, +static unsigned char *line_no_op(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { /* do nothing */ return src; } -static unsigned char *lineSwap24(unsigned char *src, unsigned char *dst, +static unsigned char *line_swap_24(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+size-3; unsigned char *dp = dst; @@ -671,9 +671,9 @@ static unsigned char *lineSwap24(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *lineSwapByte(unsigned char *src, unsigned char *dst, +static unsigned char *line_swap_byte(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t *doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t *doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+size-1; unsigned char *dp = dst; @@ -684,60 +684,60 @@ static unsigned char *lineSwapByte(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *lineSwapBit(unsigned char *src, unsigned char *dst, +static unsigned char *line_swap_bit(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { dst = cfReverseOneBitLine(src, dst, pixels, size); return dst; } -typedef struct _funcTable { +typedef struct func_table_s { enum cups_cspace_e cspace; unsigned int bitsPerPixel; unsigned int bitsPerColor; - ConvertLineFunc convertLine; + convert_line_func convertLine; bool allocLineBuf; - ConvertLineFunc convertLineSwap; + convert_line_func convertLineSwap; bool allocLineBufSwap; -} FuncTable; - -static FuncTable specialCaseFuncs[] = { - {CUPS_CSPACE_K,8,8,reverseLine,false,reverseLineSwapByte,true}, - {CUPS_CSPACE_K,1,1,reverseLine,false,reverseLineSwapBit,true}, - {CUPS_CSPACE_GOLD,8,8,reverseLine,false,reverseLineSwapByte,true}, - {CUPS_CSPACE_GOLD,1,1,reverseLine,false,reverseLineSwapBit,true}, - {CUPS_CSPACE_SILVER,8,8,reverseLine,false,reverseLineSwapByte,true}, - {CUPS_CSPACE_SILVER,1,1,reverseLine,false,reverseLineSwapBit,true}, - {CUPS_CSPACE_CMYK,32,8,rgbToCMYKLine,true,rgbToCMYKLineSwap,true}, - {CUPS_CSPACE_KCMY,32,8,rgbToKCMYLine,true,rgbToKCMYLineSwap,true}, - {CUPS_CSPACE_CMY,24,8,rgbToCMYLine,true,rgbToCMYLineSwap,true}, - {CUPS_CSPACE_RGB,24,8,lineNoop,false,lineSwap24,true}, - {CUPS_CSPACE_SRGB,24,8,lineNoop,false,lineSwap24,true}, - {CUPS_CSPACE_ADOBERGB,24,8,lineNoop,false,lineSwap24,true}, - {CUPS_CSPACE_W,8,8,lineNoop,false,lineSwapByte,true}, - {CUPS_CSPACE_W,1,1,lineNoop,false,lineSwapBit,true}, - {CUPS_CSPACE_SW,8,8,lineNoop,false,lineSwapByte,true}, - {CUPS_CSPACE_SW,1,1,lineNoop,false,lineSwapBit,true}, - {CUPS_CSPACE_WHITE,8,8,lineNoop,false,lineSwapByte,true}, - {CUPS_CSPACE_WHITE,1,1,lineNoop,false,lineSwapBit,true}, +} func_table_t; + +static func_table_t specialCaseFuncs[] = { + {CUPS_CSPACE_K,8,8,reverse_line,false,reverse_line_swap_byte,true}, + {CUPS_CSPACE_K,1,1,reverse_line,false,reverse_line_swap_bit,true}, + {CUPS_CSPACE_GOLD,8,8,reverse_line,false,reverse_line_swap_byte,true}, + {CUPS_CSPACE_GOLD,1,1,reverse_line,false,reverse_line_swap_bit,true}, + {CUPS_CSPACE_SILVER,8,8,reverse_line,false,reverse_line_swap_byte,true}, + {CUPS_CSPACE_SILVER,1,1,reverse_line,false,reverse_line_swap_bit,true}, + {CUPS_CSPACE_CMYK,32,8,rgb_to_cmyk_line,true,rgb_to_cmyk_line_swap,true}, + {CUPS_CSPACE_KCMY,32,8,rgb_to_kcmy_line,true,rgb_to_kcmy_line_swap,true}, + {CUPS_CSPACE_CMY,24,8,rgb_to_cmy_line,true,rgb_to_cmy_line_swap,true}, + {CUPS_CSPACE_RGB,24,8,line_no_op,false,line_swap_24,true}, + {CUPS_CSPACE_SRGB,24,8,line_no_op,false,line_swap_24,true}, + {CUPS_CSPACE_ADOBERGB,24,8,line_no_op,false,line_swap_24,true}, + {CUPS_CSPACE_W,8,8,line_no_op,false,line_swap_byte,true}, + {CUPS_CSPACE_W,1,1,line_no_op,false,line_swap_bit,true}, + {CUPS_CSPACE_SW,8,8,line_no_op,false,line_swap_byte,true}, + {CUPS_CSPACE_SW,1,1,line_no_op,false,line_swap_bit,true}, + {CUPS_CSPACE_WHITE,8,8,line_no_op,false,line_swap_byte,true}, + {CUPS_CSPACE_WHITE,1,1,line_no_op,false,line_swap_bit,true}, {CUPS_CSPACE_RGB,0,0,NULL,false,NULL,false} /* end mark */ }; -static unsigned char *convertCSpaceNone(unsigned char *src, +static unsigned char *convert_cspace_none(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc) { return src; } -static unsigned char *convertCSpaceWithProfiles(unsigned char *src, +static unsigned char *convert_cspace_with_profiles(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc) { cmsDoTransform(doc->colour_profile.colorTransform,src,pixelBuf,1); return pixelBuf; } -static unsigned char *convertCSpaceXYZ8(unsigned char *src, +static unsigned char *convert_cspace_xyz_8(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc) { double alab[3]; @@ -757,7 +757,7 @@ static unsigned char *convertCSpaceXYZ8(unsigned char *src, return pixelBuf; } -static unsigned char *convertCSpaceXYZ16(unsigned char *src, +static unsigned char *convert_cspace_xyz_16(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc) { double alab[3]; @@ -778,7 +778,7 @@ static unsigned char *convertCSpaceXYZ16(unsigned char *src, return pixelBuf; } -static unsigned char *convertCSpaceLab8(unsigned char *src, +static unsigned char *convert_cspace_lab_8(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc) { double lab[3]; @@ -789,7 +789,7 @@ static unsigned char *convertCSpaceLab8(unsigned char *src, return pixelBuf; } -static unsigned char *convertCSpaceLab16(unsigned char *src, +static unsigned char *convert_cspace_lab_16(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc) { double lab[3]; @@ -801,7 +801,7 @@ static unsigned char *convertCSpaceLab16(unsigned char *src, return pixelBuf; } -static unsigned char *RGB8toRGBA(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_rgba(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t* doc) { unsigned char *dp = pixelBuf; @@ -813,7 +813,7 @@ static unsigned char *RGB8toRGBA(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *RGB8toRGBW(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_rgbw(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t* doc) { unsigned char cmyk[4]; @@ -826,21 +826,21 @@ static unsigned char *RGB8toRGBW(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *RGB8toCMYK(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_cmyk(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t* doc) { cfImageRGBToCMYK(src,pixelBuf,1); return pixelBuf; } -static unsigned char *RGB8toCMY(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_cmy(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t* doc) { cfImageRGBToCMY(src,pixelBuf,1); return pixelBuf; } -static unsigned char *RGB8toYMC(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_ymc(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t* doc) { cfImageRGBToCMY(src,pixelBuf,1); @@ -851,7 +851,7 @@ static unsigned char *RGB8toYMC(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *RGB8toKCMY(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_kcmy(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t* doc) { cfImageRGBToCMYK(src,pixelBuf,1); @@ -863,13 +863,13 @@ static unsigned char *RGB8toKCMY(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *RGB8toKCMYcmTemp(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_kcmycm_temp(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t* doc) { return cfRGB8toKCMYcm(src, pixelBuf, x, y); } -static unsigned char *RGB8toYMCK(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_ymck(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t* doc) { cfImageRGBToCMYK(src,pixelBuf,1); @@ -880,16 +880,16 @@ static unsigned char *RGB8toYMCK(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *W8toK8(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *w_8_to_k_8(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc) { *pixelBuf = ~(*src); return pixelBuf; } -static unsigned char *convertLineChunked(unsigned char *src, unsigned char *dst, +static unsigned char *convert_line_chunked(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t *doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t *doc, convert_cspace_func convertCSpace) { /* Assumed that BitsPerColor is 8 */ for (unsigned int i = 0;i < pixels;i++) { @@ -904,9 +904,9 @@ static unsigned char *convertLineChunked(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *convertLineChunkedSwap(unsigned char *src, +static unsigned char *convert_line_chunked_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, - unsigned int pixels, unsigned int size, pdftoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int pixels, unsigned int size, pdftoraster_doc_t* doc, convert_cspace_func convertCSpace) { /* Assumed that BitsPerColor is 8 */ for (unsigned int i = 0;i < pixels;i++) { @@ -921,9 +921,9 @@ static unsigned char *convertLineChunkedSwap(unsigned char *src, return dst; } -static unsigned char *convertLinePlane(unsigned char *src, unsigned char *dst, +static unsigned char *convert_line_plane(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pdftoraster_doc_t *doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pdftoraster_doc_t *doc, convert_cspace_func convertCSpace) { /* Assumed that BitsPerColor is 8 */ for (unsigned int i = 0;i < pixels;i++) { @@ -938,9 +938,9 @@ static unsigned char *convertLinePlane(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *convertLinePlaneSwap(unsigned char *src, +static unsigned char *convert_line_plane_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, - unsigned int pixels, unsigned int size, pdftoraster_doc_t *doc, ConvertCSpaceFunc convertCSpace) + unsigned int pixels, unsigned int size, pdftoraster_doc_t *doc, convert_cspace_func convertCSpace) { for (unsigned int i = 0;i < pixels;i++) { unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL]; @@ -954,8 +954,8 @@ static unsigned char *convertLinePlaneSwap(unsigned char *src, return dst; } -/* handle special cases which are appear in gutenprint's PPDs. */ -static bool selectSpecialCase(pdftoraster_doc_t* doc, conversion_function_t* convert) +/* Handle special cases which appear in Gutenprint's PPDs */ +static bool select_special_case(pdftoraster_doc_t* doc, conversion_function_t* convert) { int i; @@ -977,7 +977,7 @@ static bool selectSpecialCase(pdftoraster_doc_t* doc, conversion_function_t* con return false; } -static unsigned int getCMSColorSpaceType(cmsColorSpaceSignature cs) +static unsigned int get_cms_color_space_type(cmsColorSpaceSignature cs) { switch (cs) { case cmsSigXYZData: @@ -1034,13 +1034,13 @@ static unsigned int getCMSColorSpaceType(cmsColorSpaceSignature cs) } /* select convertLine function */ -static int selectConvertFunc(cups_raster_t *raster, pdftoraster_doc_t* doc, conversion_function_t *convert, cf_logfunc_t log, void* ld) +static int select_convert_func(cups_raster_t *raster, pdftoraster_doc_t* doc, conversion_function_t *convert, cf_logfunc_t log, void* ld) { doc->bitspercolor = doc->header.cupsBitsPerColor; if ((doc->colour_profile.colorProfile == NULL || doc->colour_profile.popplerColorProfile == doc->colour_profile.colorProfile) && (doc->header.cupsColorOrder == CUPS_ORDER_CHUNKED || doc->header.cupsNumColors == 1)) { - if (selectSpecialCase(doc, convert)) + if (select_special_case(doc, convert)) return (0); } @@ -1048,14 +1048,14 @@ static int selectConvertFunc(cups_raster_t *raster, pdftoraster_doc_t* doc, conv case CUPS_ORDER_BANDED: case CUPS_ORDER_PLANAR: if (doc->header.cupsNumColors > 1) { - convert->convertLineEven = convertLinePlaneSwap; - convert->convertLineOdd = convertLinePlane; + convert->convertLineEven = convert_line_plane_swap; + convert->convertLineOdd = convert_line_plane; break; } default: case CUPS_ORDER_CHUNKED: - convert->convertLineEven = convertLineChunkedSwap; - convert->convertLineOdd = convertLineChunked; + convert->convertLineEven = convert_line_chunked_swap; + convert->convertLineOdd = convert_line_chunked; break; } if (!doc->header.Duplex || !doc->swap_image_x) { @@ -1084,24 +1084,24 @@ static int selectConvertFunc(cups_raster_t *raster, pdftoraster_doc_t* doc, conv case CUPS_CSPACE_ICCE: case CUPS_CSPACE_ICCF: if (doc->header.cupsBitsPerColor == 8) { - convert->convertCSpace = convertCSpaceLab8; + convert->convertCSpace = convert_cspace_lab_8; } else { /* 16 bits */ - convert->convertCSpace = convertCSpaceLab16; + convert->convertCSpace = convert_cspace_lab_16; } bytes = 0; /* double */ break; case CUPS_CSPACE_CIEXYZ: if (doc->header.cupsBitsPerColor == 8) { - convert->convertCSpace = convertCSpaceXYZ8; + convert->convertCSpace = convert_cspace_xyz_8; } else { /* 16 bits */ - convert->convertCSpace = convertCSpaceXYZ16; + convert->convertCSpace = convert_cspace_xyz_16; } bytes = 0; /* double */ break; default: - convert->convertCSpace = convertCSpaceWithProfiles; + convert->convertCSpace = convert_cspace_with_profiles; bytes = doc->header.cupsBitsPerColor/8; break; } @@ -1110,7 +1110,7 @@ static int selectConvertFunc(cups_raster_t *raster, pdftoraster_doc_t* doc, conv doc->colour_profile.popplerColorProfile = cmsCreate_sRGBProfile(); } unsigned int dcst = - getCMSColorSpaceType(cmsGetColorSpace(doc->colour_profile.colorProfile)); + get_cms_color_space_type(cmsGetColorSpace(doc->colour_profile.colorProfile)); if ((doc->colour_profile.colorTransform = cmsCreateTransform(doc->colour_profile.popplerColorProfile, COLORSPACE_SH(PT_RGB) |CHANNELS_SH(3) | BYTES_SH(1), @@ -1143,52 +1143,52 @@ static int selectConvertFunc(cups_raster_t *raster, pdftoraster_doc_t* doc, conv case CUPS_CSPACE_ICCE: case CUPS_CSPACE_ICCF: case CUPS_CSPACE_CIEXYZ: - convert->convertCSpace = convertCSpaceNone; + convert->convertCSpace = convert_cspace_none; break; case CUPS_CSPACE_CMY: - convert->convertCSpace = RGB8toCMY; + convert->convertCSpace = rgb_8_to_cmy; break; case CUPS_CSPACE_YMC: - convert->convertCSpace = RGB8toYMC; + convert->convertCSpace = rgb_8_to_ymc; break; case CUPS_CSPACE_CMYK: - convert->convertCSpace = RGB8toCMYK; + convert->convertCSpace = rgb_8_to_cmyk; break; case CUPS_CSPACE_KCMY: - convert->convertCSpace = RGB8toKCMY; + convert->convertCSpace = rgb_8_to_kcmy; break; case CUPS_CSPACE_KCMYcm: if (doc->header.cupsBitsPerColor > 1) { - convert->convertCSpace = RGB8toKCMY; + convert->convertCSpace = rgb_8_to_kcmy; } else { - convert->convertCSpace = RGB8toKCMYcmTemp; + convert->convertCSpace = rgb_8_to_kcmycm_temp; } break; case CUPS_CSPACE_GMCS: case CUPS_CSPACE_GMCK: case CUPS_CSPACE_YMCK: - convert->convertCSpace = RGB8toYMCK; + convert->convertCSpace = rgb_8_to_ymck; break; case CUPS_CSPACE_RGBW: - convert->convertCSpace = RGB8toRGBW; + convert->convertCSpace = rgb_8_to_rgbw; break; case CUPS_CSPACE_RGBA: - convert->convertCSpace = RGB8toRGBA; + convert->convertCSpace = rgb_8_to_rgba; break; case CUPS_CSPACE_RGB: case CUPS_CSPACE_SRGB: case CUPS_CSPACE_ADOBERGB: - convert->convertCSpace = convertCSpaceNone; + convert->convertCSpace = convert_cspace_none; break; case CUPS_CSPACE_W: case CUPS_CSPACE_SW: case CUPS_CSPACE_WHITE: - convert->convertCSpace = convertCSpaceNone; + convert->convertCSpace = convert_cspace_none; break; case CUPS_CSPACE_K: case CUPS_CSPACE_GOLD: case CUPS_CSPACE_SILVER: - convert->convertCSpace = W8toK8; + convert->convertCSpace = w_8_to_k_8; break; default: if (log) log(ld, CF_LOGLEVEL_ERROR, @@ -1205,7 +1205,7 @@ static int selectConvertFunc(cups_raster_t *raster, pdftoraster_doc_t* doc, conv return (0); } -static unsigned char *onebitpixel(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height, pdftoraster_doc_t* doc){ +static unsigned char *one_bit_pixel(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height, pdftoraster_doc_t* doc){ unsigned char *temp; temp=dst; for(unsigned int i=0;iheader.cupsBitsPerColor==1){ // Special case for 1-bit colorspaces im = pr.render_page(current_page,doc->header.HWResolution[0],doc->header.HWResolution[1],doc->bitmapoffset[0],doc->bitmapoffset[1],(doc->bytesPerLine)*8,doc->header.cupsHeight); newdata = (unsigned char *)malloc(sizeof(char)*3*im.width()*im.height()); - newdata = removeAlpha((unsigned char *)im.const_data(),newdata,im.width(),im.height()); + newdata = remove_alpha((unsigned char *)im.const_data(),newdata,im.width(),im.height()); graydata=(unsigned char *)malloc(sizeof(char)*im.width()*im.height()); cfImageRGBToWhite(newdata,graydata,im.width()*im.height()); onebitdata=(unsigned char *)malloc(sizeof(char)*(doc->bytesPerLine)*im.height()); - onebitpixel(graydata,onebitdata,im.width(),im.height(), doc); + one_bit_pixel(graydata,onebitdata,im.width(),im.height(), doc); colordata=onebitdata; rowsize=doc->bytesPerLine; } else{ im = pr.render_page(current_page,doc->header.HWResolution[0],doc->header.HWResolution[1],doc->bitmapoffset[0],doc->bitmapoffset[1],doc->header.cupsWidth,doc->header.cupsHeight); newdata = (unsigned char *)malloc(sizeof(char)*3*im.width()*im.height()); - newdata = removeAlpha((unsigned char *)im.const_data(),newdata,im.width(),im.height()); + newdata = remove_alpha((unsigned char *)im.const_data(),newdata,im.width(),im.height()); pixel_count=im.width()*im.height(); graydata=(unsigned char *)malloc(sizeof(char)*im.width()*im.height()); cfImageRGBToWhite(newdata,graydata,pixel_count); @@ -1286,7 +1286,7 @@ static void writePageImage(cups_raster_t *raster, pdftoraster_doc_t *doc, default: im = pr.render_page(current_page,doc->header.HWResolution[0],doc->header.HWResolution[1],doc->bitmapoffset[0],doc->bitmapoffset[1],doc->header.cupsWidth,doc->header.cupsHeight); newdata = (unsigned char *)malloc(sizeof(char)*3*im.width()*im.height()); - newdata = removeAlpha((unsigned char *)im.const_data(),newdata,im.width(),im.height()); + newdata = remove_alpha((unsigned char *)im.const_data(),newdata,im.width(),im.height()); pixel_count=im.width()*im.height(); rowsize=doc->header.cupsWidth*3; colordata=newdata; @@ -1331,7 +1331,7 @@ static void writePageImage(cups_raster_t *raster, pdftoraster_doc_t *doc, if (doc->allocLineBuf) delete[] lineBuf; } -static int outPage(pdftoraster_doc_t *doc, int pageNo, cf_filter_data_t *data, +static int out_page(pdftoraster_doc_t *doc, int pageNo, cf_filter_data_t *data, cups_raster_t *raster, conversion_function_t *convert, cf_logfunc_t log, void* ld, cf_filter_iscanceledfunc_t iscanceled, void *icd) { int rotate = 0; @@ -1470,11 +1470,11 @@ static int outPage(pdftoraster_doc_t *doc, int pageNo, cf_filter_data_t *data, } /* write page image */ - writePageImage(raster,doc,pageNo, convert, iscanceled, icd); + write_page_image(raster,doc,pageNo, convert, iscanceled, icd); return (0); } -static int setPopplerColorProfile(pdftoraster_doc_t *doc, cf_logfunc_t log, void *ld) +static int set_poppler_color_profile(pdftoraster_doc_t *doc, cf_logfunc_t log, void *ld) { if (doc->header.cupsBitsPerColor != 8 && doc->header.cupsBitsPerColor != 16) { /* color Profile is not supported */ @@ -1583,7 +1583,7 @@ int cfFilterPDFToRaster(int inputfd, /* I - File descriptor input stream int ret = 0; (void)inputseekable; - cmsSetLogErrorHandler(lcmsErrorHandler); + cmsSetLogErrorHandler(lcms_error_handler); /* Note: With the CF_FILTER_OUT_FORMAT_PCLM selection the output is actually CUPS Raster but color spaces and depth are always @@ -1652,7 +1652,7 @@ int cfFilterPDFToRaster(int inputfd, /* I - File descriptor input stream } close(fd); - if (parseOpts(data, outformat, &doc) == 1) + if (parse_opts(data, outformat, &doc) == 1) { unlink(name); return (1); @@ -1669,7 +1669,7 @@ int cfFilterPDFToRaster(int inputfd, /* I - File descriptor input stream goto out; } - parsePDFTOPDFComment(fp, &deviceCopies, &deviceCollate); + parse_pdftopdf_comment(fp, &deviceCopies, &deviceCollate); fclose(fp); if(doc.poppler_doc != NULL) @@ -1761,7 +1761,7 @@ int cfFilterPDFToRaster(int inputfd, /* I - File descriptor input stream goto out; } if (!(doc.colour_profile.cm_disabled)) { - if (setPopplerColorProfile(&doc, log, ld) != 0) { + if (set_poppler_color_profile(&doc, log, ld) != 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterPDFToRaster: Cannot set color profile."); ret = 1; @@ -1786,7 +1786,7 @@ int cfFilterPDFToRaster(int inputfd, /* I - File descriptor input stream goto out; } memset(&convert, 0, sizeof(conversion_function_t)); - if (selectConvertFunc(raster, &doc, &convert, log, ld) == 1) + if (select_convert_func(raster, &doc, &convert, log, ld) == 1) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterPDFToRaster: Unable to select color conversion function."); @@ -1795,7 +1795,7 @@ int cfFilterPDFToRaster(int inputfd, /* I - File descriptor input stream } if (doc.poppler_doc != NULL) { for (i = 1;i <= npages;i++) { - if (outPage(&doc,i,data,raster, &convert, log, ld, iscanceled, icd) == 1) + if (out_page(&doc,i,data,raster, &convert, log, ld, iscanceled, icd) == 1) { if (log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterPDFToRaster: Unable to output page %d.", i); diff --git a/cupsfilters/pdfutils.c b/cupsfilters/pdfutils.c index 1b138b464..ab9358a16 100644 --- a/cupsfilters/pdfutils.c +++ b/cupsfilters/pdfutils.c @@ -411,21 +411,3 @@ int cfPDFOutWriteFont(cf_pdf_out_t *pdf,EMB_PARAMS *emb) // {{{ return f_obj; } // }}} - -#if 0 -one_page(...parent,resources,mediabox,contents); -{ -// " /Resources %d 0 R\n" - cfPDFOutPrintF(pdf,"%d 0 obj\n" - "<>\n" - "endobj\n" - ,,,PageWidth,PageLength // TODO: into pdf-> - ... -} - -... pfb_embedder ... pfa? -#endif diff --git a/cupsfilters/pwgtoraster.c b/cupsfilters/pwgtoraster.c index da1666d38..e7a4d2b08 100644 --- a/cupsfilters/pwgtoraster.c +++ b/cupsfilters/pwgtoraster.c @@ -130,28 +130,28 @@ typedef struct pwgtoraster_doc_s cms_profile_t color_profile; } pwgtoraster_doc_t; -typedef unsigned char *(*ConvertCSpaceFunc)(unsigned char *src, +typedef unsigned char *(*convert_cspace_func)(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t* doc); -typedef unsigned char *(*ConvertLineFunc)(unsigned char *src, +typedef unsigned char *(*convert_line_func)(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, unsigned int size, pwgtoraster_doc_t* doc, - ConvertCSpaceFunc convertCSpace); + convert_cspace_func convertCSpace); typedef struct conversion_function_s { - ConvertCSpaceFunc convertCSpace; /* Function for conversion of colorspaces */ - ConvertLineFunc convertLineOdd;/* Function tom modify raster data of a line */ - ConvertLineFunc convertLineEven; + convert_cspace_func convertCSpace; /* Function for conversion of colorspaces */ + convert_line_func convertLineOdd;/* Function to modify raster data of a line */ + convert_line_func convertLineEven; } conversion_function_t; -cmsCIExyY adobergb_wp_cms() +static cmsCIExyY adobergb_wp_cms() { double * xyY = cfCmWhitePointAdobeRGB(); cmsCIExyY wp; @@ -163,7 +163,7 @@ cmsCIExyY adobergb_wp_cms() return wp; } -cmsCIExyY sgray_wp_cms() +static cmsCIExyY sgray_wp_cms() { double * xyY = cfCmWhitePointSGray(); cmsCIExyY wp; @@ -175,7 +175,7 @@ cmsCIExyY sgray_wp_cms() return wp; } -cmsCIExyYTRIPLE adobergb_matrix_cms() +static cmsCIExyYTRIPLE adobergb_matrix_cms() { cmsCIExyYTRIPLE m; @@ -194,7 +194,7 @@ cmsCIExyYTRIPLE adobergb_matrix_cms() return m; } -cmsHPROFILE adobergb_profile() +static cmsHPROFILE adobergb_profile() { cmsHPROFILE adobergb; @@ -218,7 +218,7 @@ cmsHPROFILE adobergb_profile() return adobergb; } -cmsHPROFILE sgray_profile() +static cmsHPROFILE sgray_profile() { cmsHPROFILE sgray; @@ -238,19 +238,19 @@ cmsHPROFILE sgray_profile() #ifdef USE_LCMS1 -static int lcmsErrorHandler(int ErrorCode, const char *ErrorText) +static int lcms_error_handler(int ErrorCode, const char *ErrorText) { return 1; } #else -static void lcmsErrorHandler(cmsContext contextId, cmsUInt32Number ErrorCode, +static void lcms_error_handler(cmsContext contextId, cmsUInt32Number ErrorCode, const char *ErrorText) { return; } #endif -static void handleRequiresPageRegion(pwgtoraster_doc_t*doc) { +static void handle_requires_page_region(pwgtoraster_doc_t*doc) { ppd_choice_t *mf; ppd_choice_t *is; ppd_attr_t *rregions = NULL; @@ -286,7 +286,7 @@ static void handleRequiresPageRegion(pwgtoraster_doc_t*doc) { } } -static int parseOpts(cf_filter_data_t *data, +static int parse_opts(cf_filter_data_t *data, cf_filter_out_format_t outformat, pwgtoraster_doc_t *doc) { @@ -321,7 +321,7 @@ static int parseOpts(cf_filter_data_t *data, if (log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterPWGToRaster: Using PPD file: %s", doc->ppd->nickname); ppdMarkOptions(doc->ppd,num_options,options); - handleRequiresPageRegion(doc); + handle_requires_page_region(doc); attr = ppdFindAttr(doc->ppd,"pwgtorasterRenderingIntent",NULL); if (attr != NULL && attr->value != NULL) { if (strcasecmp(attr->value,"PERCEPTUAL") == 0) { @@ -421,9 +421,9 @@ static int parseOpts(cf_filter_data_t *data, return (0); } -static unsigned char *reverseLine(unsigned char *src, unsigned char *dst, +static unsigned char *reverse_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *p = src; @@ -433,9 +433,9 @@ static unsigned char *reverseLine(unsigned char *src, unsigned char *dst, return src; } -static unsigned char *reverseLineSwapByte(unsigned char *src, +static unsigned char *reverse_line_swap_byte(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, - unsigned int pixels, unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int pixels, unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+size-1; unsigned char *dp = dst; @@ -447,25 +447,25 @@ static unsigned char *reverseLineSwapByte(unsigned char *src, } -static unsigned char *reverseLineSwapBit(unsigned char *src, +static unsigned char *reverse_line_swap_bit(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, - unsigned int pixels, unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int pixels, unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { dst = cfReverseOneBitLineSwap(src, dst, pixels, size); return dst; } -static unsigned char *rgbToCMYKLine(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_cmyk_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { cfImageRGBToCMYK(src,dst,pixels); return dst; } -static unsigned char *rgbToCMYKLineSwap(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_cmyk_line_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+(pixels-1)*3; unsigned char *dp = dst; @@ -476,17 +476,17 @@ static unsigned char *rgbToCMYKLineSwap(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *rgbToCMYLine(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_cmy_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { cfImageRGBToCMY(src,dst,pixels); return dst; } -static unsigned char *rgbToCMYLineSwap(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_cmy_line_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+size-3; unsigned char *dp = dst; @@ -497,9 +497,9 @@ static unsigned char *rgbToCMYLineSwap(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *rgbToKCMYLine(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_kcmy_line(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src; unsigned char *dp = dst; @@ -517,9 +517,9 @@ static unsigned char *rgbToKCMYLine(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *rgbToKCMYLineSwap(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_kcmy_line_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+(pixels-1)*3; unsigned char *dp = dst; @@ -537,17 +537,17 @@ static unsigned char *rgbToKCMYLineSwap(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *lineNoop(unsigned char *src, unsigned char *dst, +static unsigned char *line_no_op(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { /* do nothing */ return src; } -static unsigned char *lineSwap24(unsigned char *src, unsigned char *dst, +static unsigned char *line_swap_24(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+size-3; unsigned char *dp = dst; @@ -560,9 +560,9 @@ static unsigned char *lineSwap24(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *lineSwapByte(unsigned char *src, unsigned char *dst, +static unsigned char *line_swap_byte(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t *doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t *doc, convert_cspace_func convertCSpace) { unsigned char *bp = src+size-1; unsigned char *dp = dst; @@ -573,60 +573,60 @@ static unsigned char *lineSwapByte(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *lineSwapBit(unsigned char *src, unsigned char *dst, +static unsigned char *line_swap_bit(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { dst = cfReverseOneBitLine(src, dst, pixels, size); return dst; } -typedef struct _funcTable { +typedef struct func_table_s { enum cups_cspace_e cspace; unsigned int bitsPerPixel; unsigned int bitsPerColor; - ConvertLineFunc convertLine; + convert_line_func convertLine; bool allocLineBuf; - ConvertLineFunc convertLineSwap; + convert_line_func convertLineSwap; bool allocLineBufSwap; -} FuncTable; - -static FuncTable specialCaseFuncs[] = { - {CUPS_CSPACE_K,8,8,reverseLine,false,reverseLineSwapByte,true}, - {CUPS_CSPACE_K,1,1,reverseLine,false,reverseLineSwapBit,true}, - {CUPS_CSPACE_GOLD,8,8,reverseLine,false,reverseLineSwapByte,true}, - {CUPS_CSPACE_GOLD,1,1,reverseLine,false,reverseLineSwapBit,true}, - {CUPS_CSPACE_SILVER,8,8,reverseLine,false,reverseLineSwapByte,true}, - {CUPS_CSPACE_SILVER,1,1,reverseLine,false,reverseLineSwapBit,true}, - {CUPS_CSPACE_CMYK,32,8,rgbToCMYKLine,true,rgbToCMYKLineSwap,true}, - {CUPS_CSPACE_KCMY,32,8,rgbToKCMYLine,true,rgbToKCMYLineSwap,true}, - {CUPS_CSPACE_CMY,24,8,rgbToCMYLine,true,rgbToCMYLineSwap,true}, - {CUPS_CSPACE_RGB,24,8,lineNoop,false,lineSwap24,true}, - {CUPS_CSPACE_SRGB,24,8,lineNoop,false,lineSwap24,true}, - {CUPS_CSPACE_ADOBERGB,24,8,lineNoop,false,lineSwap24,true}, - {CUPS_CSPACE_W,8,8,lineNoop,false,lineSwapByte,true}, - {CUPS_CSPACE_W,1,1,lineNoop,false,lineSwapBit,true}, - {CUPS_CSPACE_SW,8,8,lineNoop,false,lineSwapByte,true}, - {CUPS_CSPACE_SW,1,1,lineNoop,false,lineSwapBit,true}, - {CUPS_CSPACE_WHITE,8,8,lineNoop,false,lineSwapByte,true}, - {CUPS_CSPACE_WHITE,1,1,lineNoop,false,lineSwapBit,true}, +} func_table_t; + +static func_table_t specialCaseFuncs[] = { + {CUPS_CSPACE_K,8,8,reverse_line,false,reverse_line_swap_byte,true}, + {CUPS_CSPACE_K,1,1,reverse_line,false,reverse_line_swap_bit,true}, + {CUPS_CSPACE_GOLD,8,8,reverse_line,false,reverse_line_swap_byte,true}, + {CUPS_CSPACE_GOLD,1,1,reverse_line,false,reverse_line_swap_bit,true}, + {CUPS_CSPACE_SILVER,8,8,reverse_line,false,reverse_line_swap_byte,true}, + {CUPS_CSPACE_SILVER,1,1,reverse_line,false,reverse_line_swap_bit,true}, + {CUPS_CSPACE_CMYK,32,8,rgb_to_cmyk_line,true,rgb_to_cmyk_line_swap,true}, + {CUPS_CSPACE_KCMY,32,8,rgb_to_kcmy_line,true,rgb_to_kcmy_line_swap,true}, + {CUPS_CSPACE_CMY,24,8,rgb_to_cmy_line,true,rgb_to_cmy_line_swap,true}, + {CUPS_CSPACE_RGB,24,8,line_no_op,false,line_swap_24,true}, + {CUPS_CSPACE_SRGB,24,8,line_no_op,false,line_swap_24,true}, + {CUPS_CSPACE_ADOBERGB,24,8,line_no_op,false,line_swap_24,true}, + {CUPS_CSPACE_W,8,8,line_no_op,false,line_swap_byte,true}, + {CUPS_CSPACE_W,1,1,line_no_op,false,line_swap_bit,true}, + {CUPS_CSPACE_SW,8,8,line_no_op,false,line_swap_byte,true}, + {CUPS_CSPACE_SW,1,1,line_no_op,false,line_swap_bit,true}, + {CUPS_CSPACE_WHITE,8,8,line_no_op,false,line_swap_byte,true}, + {CUPS_CSPACE_WHITE,1,1,line_no_op,false,line_swap_bit,true}, {CUPS_CSPACE_RGB,0,0,NULL,false,NULL,false} /* end mark */ }; -static unsigned char *convertCSpaceNone(unsigned char *src, +static unsigned char *convert_cspace_none(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc) { return src; } -static unsigned char *convertCSpaceWithProfiles(unsigned char *src, +static unsigned char *convert_cspace_with_profiles(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc) { cmsDoTransform(doc->color_profile.colorTransform,src,pixelBuf,1); return pixelBuf; } -static unsigned char *convertCSpaceXYZ8(unsigned char *src, +static unsigned char *convert_cspace_xyz_8(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc) { double alab[3]; @@ -646,7 +646,7 @@ static unsigned char *convertCSpaceXYZ8(unsigned char *src, return pixelBuf; } -static unsigned char *convertCSpaceXYZ16(unsigned char *src, +static unsigned char *convert_cspace_xyz_16(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc) { double alab[3]; @@ -667,7 +667,7 @@ static unsigned char *convertCSpaceXYZ16(unsigned char *src, return pixelBuf; } -static unsigned char *convertCSpaceLab8(unsigned char *src, +static unsigned char *convert_cspace_lab_8(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc) { double lab[3]; @@ -678,7 +678,7 @@ static unsigned char *convertCSpaceLab8(unsigned char *src, return pixelBuf; } -static unsigned char *convertCSpaceLab16(unsigned char *src, +static unsigned char *convert_cspace_lab_16(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc) { double lab[3]; @@ -690,7 +690,7 @@ static unsigned char *convertCSpaceLab16(unsigned char *src, return pixelBuf; } -static unsigned char *RGB8toRGBA(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_rgba(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t* doc) { unsigned char *dp = pixelBuf; @@ -702,7 +702,7 @@ static unsigned char *RGB8toRGBA(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *RGB8toRGBW(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_rgbw(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t* doc) { unsigned char cmyk[4]; @@ -715,21 +715,21 @@ static unsigned char *RGB8toRGBW(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *RGB8toCMYK(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_cmyk(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t* doc) { cfImageRGBToCMYK(src,pixelBuf,1); return pixelBuf; } -static unsigned char *RGB8toCMY(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_cmy(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t* doc) { cfImageRGBToCMY(src,pixelBuf,1); return pixelBuf; } -static unsigned char *RGB8toYMC(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_ymc(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t* doc) { cfImageRGBToCMY(src,pixelBuf,1); @@ -740,7 +740,7 @@ static unsigned char *RGB8toYMC(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *RGB8toKCMY(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_kcmy(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t* doc) { cfImageRGBToCMYK(src,pixelBuf,1); @@ -752,13 +752,13 @@ static unsigned char *RGB8toKCMY(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *RGB8toKCMYcmTemp(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_kcmycm_temp(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t* doc) { return cfRGB8toKCMYcm(src, pixelBuf, x, y); } -static unsigned char *RGB8toYMCK(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *rgb_8_to_ymck(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t* doc) { cfImageRGBToCMYK(src,pixelBuf,1); @@ -769,16 +769,16 @@ static unsigned char *RGB8toYMCK(unsigned char *src, unsigned char *pixelBuf, return pixelBuf; } -static unsigned char *W8toK8(unsigned char *src, unsigned char *pixelBuf, +static unsigned char *w_8_to_k_8(unsigned char *src, unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc) { *pixelBuf = ~(*src); return pixelBuf; } -static unsigned char *convertLineChunked(unsigned char *src, unsigned char *dst, +static unsigned char *convert_line_chunked(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t *doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t *doc, convert_cspace_func convertCSpace) { /* Assumed that BitsPerColor is 8 */ for (unsigned int i = 0;i < pixels;i++) { @@ -793,9 +793,9 @@ static unsigned char *convertLineChunked(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *convertLineChunkedSwap(unsigned char *src, +static unsigned char *convert_line_chunked_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, - unsigned int pixels, unsigned int size, pwgtoraster_doc_t* doc, ConvertCSpaceFunc convertCSpace) + unsigned int pixels, unsigned int size, pwgtoraster_doc_t* doc, convert_cspace_func convertCSpace) { /* Assumed that BitsPerColor is 8 */ for (unsigned int i = 0;i < pixels;i++) { @@ -810,9 +810,9 @@ static unsigned char *convertLineChunkedSwap(unsigned char *src, return dst; } -static unsigned char *convertLinePlane(unsigned char *src, unsigned char *dst, +static unsigned char *convert_line_plane(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, unsigned int pixels, - unsigned int size, pwgtoraster_doc_t *doc, ConvertCSpaceFunc convertCSpace) + unsigned int size, pwgtoraster_doc_t *doc, convert_cspace_func convertCSpace) { /* Assumed that BitsPerColor is 8 */ for (unsigned int i = 0;i < pixels;i++) { @@ -827,9 +827,9 @@ static unsigned char *convertLinePlane(unsigned char *src, unsigned char *dst, return dst; } -static unsigned char *convertLinePlaneSwap(unsigned char *src, +static unsigned char *convert_line_plane_swap(unsigned char *src, unsigned char *dst, unsigned int row, unsigned int plane, - unsigned int pixels, unsigned int size, pwgtoraster_doc_t *doc, ConvertCSpaceFunc convertCSpace) + unsigned int pixels, unsigned int size, pwgtoraster_doc_t *doc, convert_cspace_func convertCSpace) { for (unsigned int i = 0;i < pixels;i++) { unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL]; @@ -843,8 +843,8 @@ static unsigned char *convertLinePlaneSwap(unsigned char *src, return dst; } -/* handle special cases which are appear in gutenprint's PPDs. */ -static bool selectSpecialCase(pwgtoraster_doc_t* doc, conversion_function_t* convert) +/* Handle special cases which appear in Gutenprint's PPDs */ +static bool select_special_case(pwgtoraster_doc_t* doc, conversion_function_t* convert) { int i; @@ -861,7 +861,7 @@ static bool selectSpecialCase(pwgtoraster_doc_t* doc, conversion_function_t* con return false; } -static unsigned int getCMSColorSpaceType(cmsColorSpaceSignature cs) +static unsigned int get_cms_color_space_type(cmsColorSpaceSignature cs) { switch (cs) { case cmsSigXYZData: @@ -918,7 +918,7 @@ static unsigned int getCMSColorSpaceType(cmsColorSpaceSignature cs) } /* select convertLine function */ -static int selectConvertFunc(cups_raster_t *raster, +static int select_convert_func(cups_raster_t *raster, pwgtoraster_doc_t* doc, conversion_function_t *convert, cf_logfunc_t log, @@ -929,7 +929,7 @@ static int selectConvertFunc(cups_raster_t *raster, if ((doc->color_profile.colorProfile == NULL || doc->color_profile.outputColorProfile == doc->color_profile.colorProfile) && (doc->outheader.cupsColorOrder == CUPS_ORDER_CHUNKED || doc->outheader.cupsNumColors == 1)) { - if (selectSpecialCase(doc, convert)) + if (select_special_case(doc, convert)) return (0); } @@ -937,14 +937,14 @@ static int selectConvertFunc(cups_raster_t *raster, case CUPS_ORDER_BANDED: case CUPS_ORDER_PLANAR: if (doc->outheader.cupsNumColors > 1) { - convert->convertLineEven = convertLinePlaneSwap; - convert->convertLineOdd = convertLinePlane; + convert->convertLineEven = convert_line_plane_swap; + convert->convertLineOdd = convert_line_plane; break; } default: case CUPS_ORDER_CHUNKED: - convert->convertLineEven = convertLineChunkedSwap; - convert->convertLineOdd = convertLineChunked; + convert->convertLineEven = convert_line_chunked_swap; + convert->convertLineOdd = convert_line_chunked; break; } convert->convertLineEven = convert->convertLineOdd; @@ -971,24 +971,24 @@ static int selectConvertFunc(cups_raster_t *raster, case CUPS_CSPACE_ICCE: case CUPS_CSPACE_ICCF: if (doc->outheader.cupsBitsPerColor == 8) { - convert->convertCSpace = convertCSpaceLab8; + convert->convertCSpace = convert_cspace_lab_8; } else { /* 16 bits */ - convert->convertCSpace = convertCSpaceLab16; + convert->convertCSpace = convert_cspace_lab_16; } bytes = 0; /* double */ break; case CUPS_CSPACE_CIEXYZ: if (doc->outheader.cupsBitsPerColor == 8) { - convert->convertCSpace = convertCSpaceXYZ8; + convert->convertCSpace = convert_cspace_xyz_8; } else { /* 16 bits */ - convert->convertCSpace = convertCSpaceXYZ16; + convert->convertCSpace = convert_cspace_xyz_16; } bytes = 0; /* double */ break; default: - convert->convertCSpace = convertCSpaceWithProfiles; + convert->convertCSpace = convert_cspace_with_profiles; bytes = doc->outheader.cupsBitsPerColor/8; break; } @@ -997,7 +997,7 @@ static int selectConvertFunc(cups_raster_t *raster, doc->color_profile.outputColorProfile = cmsCreate_sRGBProfile(); } unsigned int dcst = - getCMSColorSpaceType(cmsGetColorSpace(doc->color_profile.colorProfile)); + get_cms_color_space_type(cmsGetColorSpace(doc->color_profile.colorProfile)); if ((doc->color_profile.colorTransform = cmsCreateTransform(doc->color_profile.outputColorProfile, COLORSPACE_SH(PT_RGB) |CHANNELS_SH(3) | BYTES_SH(1), @@ -1030,52 +1030,52 @@ static int selectConvertFunc(cups_raster_t *raster, case CUPS_CSPACE_ICCE: case CUPS_CSPACE_ICCF: case CUPS_CSPACE_CIEXYZ: - convert->convertCSpace = convertCSpaceNone; + convert->convertCSpace = convert_cspace_none; break; case CUPS_CSPACE_CMY: - convert->convertCSpace = RGB8toCMY; + convert->convertCSpace = rgb_8_to_cmy; break; case CUPS_CSPACE_YMC: - convert->convertCSpace = RGB8toYMC; + convert->convertCSpace = rgb_8_to_ymc; break; case CUPS_CSPACE_CMYK: - convert->convertCSpace = RGB8toCMYK; + convert->convertCSpace = rgb_8_to_cmyk; break; case CUPS_CSPACE_KCMY: - convert->convertCSpace = RGB8toKCMY; + convert->convertCSpace = rgb_8_to_kcmy; break; case CUPS_CSPACE_KCMYcm: if (doc->outheader.cupsBitsPerColor > 1) { - convert->convertCSpace = RGB8toKCMY; + convert->convertCSpace = rgb_8_to_kcmy; } else { - convert->convertCSpace = RGB8toKCMYcmTemp; + convert->convertCSpace = rgb_8_to_kcmycm_temp; } break; case CUPS_CSPACE_GMCS: case CUPS_CSPACE_GMCK: case CUPS_CSPACE_YMCK: - convert->convertCSpace = RGB8toYMCK; + convert->convertCSpace = rgb_8_to_ymck; break; case CUPS_CSPACE_RGBW: - convert->convertCSpace = RGB8toRGBW; + convert->convertCSpace = rgb_8_to_rgbw; break; case CUPS_CSPACE_RGBA: - convert->convertCSpace = RGB8toRGBA; + convert->convertCSpace = rgb_8_to_rgba; break; case CUPS_CSPACE_RGB: case CUPS_CSPACE_SRGB: case CUPS_CSPACE_ADOBERGB: - convert->convertCSpace = convertCSpaceNone; + convert->convertCSpace = convert_cspace_none; break; case CUPS_CSPACE_W: case CUPS_CSPACE_SW: case CUPS_CSPACE_WHITE: - convert->convertCSpace = convertCSpaceNone; + convert->convertCSpace = convert_cspace_none; break; case CUPS_CSPACE_K: case CUPS_CSPACE_GOLD: case CUPS_CSPACE_SILVER: - convert->convertCSpace = W8toK8; + convert->convertCSpace = w_8_to_k_8; break; default: if (log) log(ld, CF_LOGLEVEL_ERROR, @@ -1093,7 +1093,7 @@ static int selectConvertFunc(cups_raster_t *raster, return (0); } -static bool outPage(pwgtoraster_doc_t *doc, +static bool out_page(pwgtoraster_doc_t *doc, int pageNo, cups_raster_t *inras, cups_raster_t *outras, @@ -1114,7 +1114,7 @@ static bool outPage(pwgtoraster_doc_t *doc, int next_line_read = 0; unsigned int y = 0, yin = 0; unsigned char *bp = NULL; - ConvertLineFunc convertLine; + convert_line_func convertLine; unsigned char *lineBuf = NULL; unsigned char *dp; unsigned int inlineoffset, // Offset where to start in input line (bytes) @@ -2002,7 +2002,7 @@ static bool outPage(pwgtoraster_doc_t *doc, return (ret); } -static int setColorProfile(pwgtoraster_doc_t *doc, cf_logfunc_t log, void *ld) +static int set_color_profile(pwgtoraster_doc_t *doc, cf_logfunc_t log, void *ld) { if (doc->outheader.cupsBitsPerColor != 8 && doc->outheader.cupsBitsPerColor != 16) { /* color Profile is not supported */ @@ -2127,7 +2127,7 @@ int cfFilterPWGToRaster(int inputfd, /* I - File descriptor input stream (outformat == CF_FILTER_OUT_FORMAT_APPLE_RASTER ? "Apple Raster" : "PCLM")))); - cmsSetLogErrorHandler(lcmsErrorHandler); + cmsSetLogErrorHandler(lcms_error_handler); /* * Open the input data stream specified by inputfd ... @@ -2153,7 +2153,7 @@ int cfFilterPWGToRaster(int inputfd, /* I - File descriptor input stream doc.color_profile.renderingIntent = INTENT_PERCEPTUAL; // Parse the options - if (parseOpts(data, outformat, &doc) == 1) + if (parse_opts(data, outformat, &doc) == 1) return (1); doc.outheader.NumCopies = data->copies; @@ -2243,7 +2243,7 @@ int cfFilterPWGToRaster(int inputfd, /* I - File descriptor input stream goto out; } if (!(doc.color_profile.cm_disabled)) { - if (setColorProfile(&doc, log, ld) == 1) { + if (set_color_profile(&doc, log, ld) == 1) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterPWGToRaster: Cannot set color profile."); ret = 1; @@ -2277,7 +2277,7 @@ int cfFilterPWGToRaster(int inputfd, /* I - File descriptor input stream */ memset(&convert, 0, sizeof(conversion_function_t)); - if (selectConvertFunc(outras, &doc, &convert, log, ld) == 1) + if (select_convert_func(outras, &doc, &convert, log, ld) == 1) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterPWGToRaster: Unable to select color conversion function."); @@ -2348,7 +2348,7 @@ int cfFilterPWGToRaster(int inputfd, /* I - File descriptor input stream */ i = 0; - while (outPage(&doc, i + 1, inras, outras, &convert, log, ld, iscanceled, + while (out_page(&doc, i + 1, inras, outras, &convert, log, ld, iscanceled, icd)) i ++; if (i == 0) diff --git a/cupsfilters/raster.c b/cupsfilters/raster.c index 7ad6f20f4..e6442771d 100644 --- a/cupsfilters/raster.c +++ b/cupsfilters/raster.c @@ -37,7 +37,7 @@ * '_strlcpy()' - Safely copy two strings. */ -size_t /* O - Length of string */ +static size_t /* O - Length of string */ _strlcpy(char *dst, /* O - Destination string */ const char *src, /* I - Source string */ size_t size) /* I - Size of destination string buffer */ diff --git a/cupsfilters/rastertopdf.cpp b/cupsfilters/rastertopdf.cpp index eab56ea60..9c32599b2 100644 --- a/cupsfilters/rastertopdf.cpp +++ b/cupsfilters/rastertopdf.cpp @@ -88,29 +88,29 @@ #define PROGRAM "rastertopdf" // Compression method for providing data to PCLm Streams. -typedef enum { +typedef enum compression_method_e { DCT_DECODE = 0, FLATE_DECODE, RLE_DECODE -} CompressionMethod; +} compression_method_t; // Color conversion function -typedef unsigned char *(*convertFunction)(unsigned char *src, +typedef unsigned char *(*convert_function)(unsigned char *src, unsigned char *dst, unsigned int pixels); // Bit conversion function -typedef unsigned char *(*bitFunction)(unsigned char *src, +typedef unsigned char *(*bit_convert_function)(unsigned char *src, unsigned char *dst, unsigned int pixels); -typedef struct /**** Document information ****/ +typedef struct rastertopdf_doc_s /**** Document information ****/ { cmsHPROFILE colorProfile = NULL; /* ICC Profile to be applied to PDF */ int cm_disabled = 0; /* Flag raised if color management is disabled */ - convertFunction conversion_function; /* Raster color conversion + convert_function conversion_function; /* Raster color conversion function */ - bitFunction bit_function; /* Raster bit function */ + bit_convert_function bit_function; /* Raster bit function */ FILE *outputfp; /* Temporary file, if any */ cf_logfunc_t logfunc; /* Logging function, NULL for no logging */ @@ -124,13 +124,13 @@ typedef struct /**** Document information ****/ } rastertopdf_doc_t; // PDF color conversion function -typedef void (*pdfConvertFunction)(struct pdf_info * info, +typedef void (*pdf_convert_function)(struct pdf_info * info, rastertopdf_doc_t *doc); // Bit conversion functions -unsigned char *invertBits(unsigned char *src, unsigned char *dst, - unsigned int pixels) +static unsigned char *invert_bits(unsigned char *src, unsigned char *dst, + unsigned int pixels) { unsigned int i; @@ -141,56 +141,56 @@ unsigned char *invertBits(unsigned char *src, unsigned char *dst, return dst; } -unsigned char *noBitConversion(unsigned char *src, unsigned char *dst, +static unsigned char *no_bit_conversion(unsigned char *src, unsigned char *dst, unsigned int pixels) { return src; } // Color conversion functions -unsigned char *rgbToCmyk(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_cmyk(unsigned char *src, unsigned char *dst, unsigned int pixels) { cfImageRGBToCMYK(src,dst,pixels); return dst; } -unsigned char *whiteToCmyk(unsigned char *src, unsigned char *dst, +static unsigned char *white_to_cmyk(unsigned char *src, unsigned char *dst, unsigned int pixels) { cfImageWhiteToCMYK(src,dst,pixels); return dst; } -unsigned char *cmykToRgb(unsigned char *src, unsigned char *dst, +static unsigned char *cmyk_to_rgb(unsigned char *src, unsigned char *dst, unsigned int pixels) { cfImageCMYKToRGB(src,dst,pixels); return dst; } -unsigned char *whiteToRgb(unsigned char *src, unsigned char *dst, +static unsigned char *white_to_rgb(unsigned char *src, unsigned char *dst, unsigned int pixels) { cfImageWhiteToRGB(src,dst,pixels); return dst; } -unsigned char *rgbToWhite(unsigned char *src, unsigned char *dst, +static unsigned char *rgb_to_white(unsigned char *src, unsigned char *dst, unsigned int pixels) { cfImageRGBToWhite(src,dst,pixels); return dst; } -unsigned char *cmykToWhite(unsigned char *src, unsigned char *dst, +static unsigned char *cmyk_to_white(unsigned char *src, unsigned char *dst, unsigned int pixels) { cfImageCMYKToWhite(src,dst,pixels); return dst; } -unsigned char *noColorConversion(unsigned char *src, +static unsigned char *no_color_conversion(unsigned char *src, unsigned char *dst, unsigned int pixels) { return src; @@ -234,7 +234,7 @@ split_strings(std::string const &str, std::string delimiters = ",") * O - number of digits in the input integer * I - the integer whose digits needs to be calculated */ -int num_digits(int n) +static int num_digits(int n) { if (n == 0) return 1; int digits = 0; @@ -253,7 +253,7 @@ int num_digits(int n) * I - the integee which needs to be converted to string * I - width of string required */ -std::string int_to_fwstring(int n, int width) +static std::string int_to_fwstring(int n, int width) { int num_zeroes = width - num_digits(n); if (num_zeroes < 0) @@ -299,7 +299,7 @@ struct pdf_info unsigned pclm_strip_height_preferred; std::vector pclm_strip_height; std::vector pclm_strip_height_supported; - std::vector pclm_compression_method_preferred; + std::vector pclm_compression_method_preferred; std::vector pclm_source_resolution_supported; std::string pclm_source_resolution_default; std::string pclm_raster_back_side; @@ -311,7 +311,7 @@ struct pdf_info cf_filter_out_format_t outformat; }; -int create_pdf_file(struct pdf_info * info, +static int create_pdf_file(struct pdf_info * info, const cf_filter_out_format_t &outformat) { try { @@ -323,7 +323,7 @@ int create_pdf_file(struct pdf_info * info, return 0; } -QPDFObjectHandle makeRealBox(double x1, double y1, double x2, double y2) +static QPDFObjectHandle make_real_box(double x1, double y1, double x2, double y2) { QPDFObjectHandle ret=QPDFObjectHandle::newArray(); ret.appendItem(QPDFObjectHandle::newReal(x1)); @@ -333,7 +333,7 @@ QPDFObjectHandle makeRealBox(double x1, double y1, double x2, double y2) return ret; } -QPDFObjectHandle makeIntegerBox(int x1, int y1, int x2, int y2) +static QPDFObjectHandle make_integer_box(int x1, int y1, int x2, int y2) { QPDFObjectHandle ret = QPDFObjectHandle::newArray(); ret.appendItem(QPDFObjectHandle::newInteger(x1)); @@ -348,8 +348,8 @@ QPDFObjectHandle makeIntegerBox(int x1, int y1, int x2, int y2) // PDF color conversion functons... -void modify_pdf_color(struct pdf_info * info, int bpp, int bpc, - convertFunction fn, rastertopdf_doc_t *doc) +static void modify_pdf_color(struct pdf_info * info, int bpp, int bpc, + convert_function fn, rastertopdf_doc_t *doc) { unsigned old_bpp = info->bpp; unsigned old_bpc = info->bpc; @@ -367,52 +367,52 @@ void modify_pdf_color(struct pdf_info * info, int bpp, int bpc, return; } -void convertPdf_NoConversion(struct pdf_info * info, rastertopdf_doc_t *doc) +static void convert_pdf_no_conversion(struct pdf_info * info, rastertopdf_doc_t *doc) { - doc->conversion_function = noColorConversion; - doc->bit_function = noBitConversion; + doc->conversion_function = no_color_conversion; + doc->bit_function = no_bit_conversion; } -void convertPdf_Cmyk8ToWhite8(struct pdf_info * info, rastertopdf_doc_t *doc) +static void convert_pdf_cmyk_8_to_white_8(struct pdf_info * info, rastertopdf_doc_t *doc) { - modify_pdf_color(info, 8, 8, cmykToWhite, doc); - doc->bit_function = noBitConversion; + modify_pdf_color(info, 8, 8, cmyk_to_white, doc); + doc->bit_function = no_bit_conversion; } -void convertPdf_Rgb8ToWhite8(struct pdf_info * info, rastertopdf_doc_t *doc) +static void convert_pdf_rgb_8_to_white_8(struct pdf_info * info, rastertopdf_doc_t *doc) { - modify_pdf_color(info, 8, 8, rgbToWhite, doc); - doc->bit_function = noBitConversion; + modify_pdf_color(info, 8, 8, rgb_to_white, doc); + doc->bit_function = no_bit_conversion; } -void convertPdf_Cmyk8ToRgb8(struct pdf_info * info, rastertopdf_doc_t *doc) +static void convert_pdf_cmyk_8_to_rgb_8(struct pdf_info * info, rastertopdf_doc_t *doc) { - modify_pdf_color(info, 24, 8, cmykToRgb, doc); - doc->bit_function = noBitConversion; + modify_pdf_color(info, 24, 8, cmyk_to_rgb, doc); + doc->bit_function = no_bit_conversion; } -void convertPdf_White8ToRgb8(struct pdf_info * info, rastertopdf_doc_t *doc) +static void convert_pdf_white_8_to_rgb_8(struct pdf_info * info, rastertopdf_doc_t *doc) { - modify_pdf_color(info, 24, 8, whiteToRgb, doc); - doc->bit_function = invertBits; + modify_pdf_color(info, 24, 8, white_to_rgb, doc); + doc->bit_function = invert_bits; } -void convertPdf_Rgb8ToCmyk8(struct pdf_info * info, rastertopdf_doc_t *doc) +static void convert_pdf_rgb_8_to_cmyk_8(struct pdf_info * info, rastertopdf_doc_t *doc) { - modify_pdf_color(info, 32, 8, rgbToCmyk, doc); - doc->bit_function = noBitConversion; + modify_pdf_color(info, 32, 8, rgb_to_cmyk, doc); + doc->bit_function = no_bit_conversion; } -void convertPdf_White8ToCmyk8(struct pdf_info * info, rastertopdf_doc_t *doc) +static void convert_pdf_white_8_to_cmyk_8(struct pdf_info * info, rastertopdf_doc_t *doc) { - modify_pdf_color(info, 32, 8, whiteToCmyk, doc); - doc->bit_function = invertBits; + modify_pdf_color(info, 32, 8, white_to_cmyk, doc); + doc->bit_function = invert_bits; } -void convertPdf_InvertColors(struct pdf_info * info, rastertopdf_doc_t *doc) +static void convert_pdf_invert_colors(struct pdf_info * info, rastertopdf_doc_t *doc) { - doc->conversion_function = noColorConversion; - doc->bit_function = invertBits; + doc->conversion_function = no_color_conversion; + doc->bit_function = invert_bits; } @@ -420,7 +420,7 @@ void convertPdf_InvertColors(struct pdf_info * info, rastertopdf_doc_t *doc) // Create an '/ICCBased' array and embed a previously // set ICC Profile in the PDF -QPDFObjectHandle embedIccProfile(QPDF &pdf, rastertopdf_doc_t *doc) +static QPDFObjectHandle embed_icc_profile(QPDF &pdf, rastertopdf_doc_t *doc) { if (doc->colorProfile == NULL) { return QPDFObjectHandle::newNull(); @@ -494,14 +494,14 @@ QPDFObjectHandle embedIccProfile(QPDF &pdf, rastertopdf_doc_t *doc) return ret; } -QPDFObjectHandle embedSrgbProfile(QPDF &pdf, rastertopdf_doc_t *doc) +static QPDFObjectHandle embed_srgb_profile(QPDF &pdf, rastertopdf_doc_t *doc) { QPDFObjectHandle iccbased_reference; // Create an sRGB profile from lcms doc->colorProfile = cmsCreate_sRGBProfile(); // Embed it into the profile - iccbased_reference = embedIccProfile(pdf, doc); + iccbased_reference = embed_icc_profile(pdf, doc); return iccbased_reference; } @@ -518,7 +518,7 @@ Output: >> ] */ -QPDFObjectHandle getCalibrationArray(const char * color_space, double wp[], +static QPDFObjectHandle get_calibration_array(const char * color_space, double wp[], double gamma[], double matrix[], double bp[]) { @@ -584,22 +584,22 @@ QPDFObjectHandle getCalibrationArray(const char * color_space, double wp[], return ret; } -QPDFObjectHandle getCalRGBArray(double wp[3], double gamma[3], +static QPDFObjectHandle get_cal_rgb_array(double wp[3], double gamma[3], double matrix[9], double bp[3]) { - QPDFObjectHandle ret = getCalibrationArray("/CalRGB", wp, gamma, matrix, + QPDFObjectHandle ret = get_calibration_array("/CalRGB", wp, gamma, matrix, bp); return ret; } -QPDFObjectHandle getCalGrayArray(double wp[3], double gamma[1], double bp[3]) +static QPDFObjectHandle get_cal_gray_array(double wp[3], double gamma[1], double bp[3]) { - QPDFObjectHandle ret = getCalibrationArray("/CalGray", wp, gamma, 0, bp); + QPDFObjectHandle ret = get_calibration_array("/CalGray", wp, gamma, 0, bp); return ret; } /** - * 'makePclmStrips()' - return an std::vector of QPDFObjectHandle, each + * 'make_pclm_strips()' - return an std::vector of QPDFObjectHandle, each * containing the stream data of the various strips * which make up a PCLm page. * O - std::vector of QPDFObjectHandle @@ -612,10 +612,10 @@ QPDFObjectHandle getCalGrayArray(double wp[3], double gamma[1], double bp[3]) * I - bits per component * I - document information */ -std::vector -makePclmStrips(QPDF &pdf, unsigned num_strips, +static std::vector +make_pclm_strips(QPDF &pdf, unsigned num_strips, std::vector< PointerHolder > &strip_data, - std::vector &compression_methods, + std::vector &compression_methods, unsigned width, std::vector& strip_height, cups_cspace_t cs, unsigned bpc, rastertopdf_doc_t *doc) { @@ -666,8 +666,8 @@ makePclmStrips(QPDF &pdf, unsigned num_strips, // 1 | FLATE // 2 | RLE // ------------------ - CompressionMethod compression = compression_methods.front(); - for (std::vector::iterator it = + compression_method_t compression = compression_methods.front(); + for (std::vector::iterator it = compression_methods.begin(); it != compression_methods.end(); ++it) compression = compression > *it ? compression : *it; @@ -709,7 +709,7 @@ makePclmStrips(QPDF &pdf, unsigned num_strips, return ret; } -QPDFObjectHandle makeImage(QPDF &pdf, PointerHolder page_data, +static QPDFObjectHandle make_image(QPDF &pdf, PointerHolder page_data, unsigned width, unsigned height, std::string render_intent, cups_cspace_t cs, unsigned bpc, rastertopdf_doc_t *doc) @@ -746,7 +746,7 @@ QPDFObjectHandle makeImage(QPDF &pdf, PointerHolder page_data, /* Write "/ColorSpace" dictionary based on raster input */ if (doc->colorProfile != NULL && !doc->cm_disabled) { - icc_ref = embedIccProfile(pdf, doc); + icc_ref = embed_icc_profile(pdf, doc); if (!icc_ref.isNull()) dict["/ColorSpace"]=icc_ref; @@ -775,11 +775,11 @@ QPDFObjectHandle makeImage(QPDF &pdf, PointerHolder page_data, break; case CUPS_CSPACE_SW: if (use_blackpoint) - dict["/ColorSpace"]=getCalGrayArray(cfCmWhitePointSGray(), + dict["/ColorSpace"]=get_cal_gray_array(cfCmWhitePointSGray(), cfCmGammaSGray(), cfCmBlackPointDefault()); else - dict["/ColorSpace"]=getCalGrayArray(cfCmWhitePointSGray(), + dict["/ColorSpace"]=get_cal_gray_array(cfCmWhitePointSGray(), cfCmGammaSGray(), 0); break; case CUPS_CSPACE_CMYK: @@ -789,7 +789,7 @@ QPDFObjectHandle makeImage(QPDF &pdf, PointerHolder page_data, dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceRGB"); break; case CUPS_CSPACE_SRGB: - icc_ref = embedSrgbProfile(pdf, doc); + icc_ref = embed_srgb_profile(pdf, doc); if (!icc_ref.isNull()) dict["/ColorSpace"]=icc_ref; else @@ -797,12 +797,12 @@ QPDFObjectHandle makeImage(QPDF &pdf, PointerHolder page_data, break; case CUPS_CSPACE_ADOBERGB: if (use_blackpoint) - dict["/ColorSpace"]=getCalRGBArray(cfCmWhitePointAdobeRGB(), + dict["/ColorSpace"]=get_cal_rgb_array(cfCmWhitePointAdobeRGB(), cfCmGammaAdobeRGB(), cfCmMatrixAdobeRGB(), cfCmBlackPointDefault()); else - dict["/ColorSpace"]=getCalRGBArray(cfCmWhitePointAdobeRGB(), + dict["/ColorSpace"]=get_cal_rgb_array(cfCmWhitePointAdobeRGB(), cfCmGammaAdobeRGB(), cfCmMatrixAdobeRGB(), 0); break; @@ -872,7 +872,7 @@ QPDFObjectHandle makeImage(QPDF &pdf, PointerHolder page_data, return ret; } -int finish_page(struct pdf_info * info, rastertopdf_doc_t *doc) +static int finish_page(struct pdf_info * info, rastertopdf_doc_t *doc) { if (info->outformat == CF_FILTER_OUT_FORMAT_PDF) { @@ -880,7 +880,7 @@ int finish_page(struct pdf_info * info, rastertopdf_doc_t *doc) if(!info->page_data.getPointer()) return 0; - QPDFObjectHandle image = makeImage(info->pdf, info->page_data, + QPDFObjectHandle image = make_image(info->pdf, info->page_data, info->width, info->height, info->render_intent, info->color_space, info->bpc, doc); @@ -906,7 +906,7 @@ int finish_page(struct pdf_info * info, rastertopdf_doc_t *doc) return 0; std::vector strips = - makePclmStrips(info->pdf, info->pclm_num_strips, info->pclm_strip_data, + make_pclm_strips(info->pdf, info->pclm_num_strips, info->pclm_strip_data, info->pclm_compression_method_preferred, info->width, info->pclm_strip_height, info->color_space, info->bpc, doc); @@ -978,7 +978,7 @@ int finish_page(struct pdf_info * info, rastertopdf_doc_t *doc) /* Perform modifications to PDF if color space conversions are needed */ -int prepare_pdf_page(struct pdf_info * info, unsigned width, unsigned height, +static int prepare_pdf_page(struct pdf_info * info, unsigned width, unsigned height, unsigned bpl, unsigned bpp, unsigned bpc, std::string render_intent, cups_cspace_t color_space, rastertopdf_doc_t *doc) @@ -992,7 +992,7 @@ int prepare_pdf_page(struct pdf_info * info, unsigned width, unsigned height, #define IMAGE_WHITE_16 (bpp == 16 && bpc == 16) int error = 0; - pdfConvertFunction fn = convertPdf_NoConversion; + pdf_convert_function fn = convert_pdf_no_conversion; cmsColorSpaceSignature css; /* Register available raster information into the PDF */ @@ -1021,7 +1021,7 @@ int prepare_pdf_page(struct pdf_info * info, unsigned width, unsigned height, /* Invert grayscale by default */ if (color_space == CUPS_CSPACE_K) - fn = convertPdf_InvertColors; + fn = convert_pdf_invert_colors; if (doc->colorProfile != NULL) { css = cmsGetColorSpace(doc->colorProfile); @@ -1032,27 +1032,27 @@ int prepare_pdf_page(struct pdf_info * info, unsigned width, unsigned height, // Convert PDF to Grayscale when using a gray profile case cmsSigGrayData: if (color_space == CUPS_CSPACE_CMYK) - fn = convertPdf_Cmyk8ToWhite8; + fn = convert_pdf_cmyk_8_to_white_8; else if (color_space == CUPS_CSPACE_RGB) - fn = convertPdf_Rgb8ToWhite8; + fn = convert_pdf_rgb_8_to_white_8; else - fn = convertPdf_InvertColors; + fn = convert_pdf_invert_colors; info->color_space = CUPS_CSPACE_K; break; // Convert PDF to RGB when using an RGB profile case cmsSigRgbData: if (color_space == CUPS_CSPACE_CMYK) - fn = convertPdf_Cmyk8ToRgb8; + fn = convert_pdf_cmyk_8_to_rgb_8; else if (color_space == CUPS_CSPACE_K) - fn = convertPdf_White8ToRgb8; + fn = convert_pdf_white_8_to_rgb_8; info->color_space = CUPS_CSPACE_RGB; break; // Convert PDF to CMYK when using an RGB profile case cmsSigCmykData: if (color_space == CUPS_CSPACE_RGB) - fn = convertPdf_Rgb8ToCmyk8; + fn = convert_pdf_rgb_8_to_cmyk_8; else if (color_space == CUPS_CSPACE_K) - fn = convertPdf_White8ToCmyk8; + fn = convert_pdf_white_8_to_cmyk_8; info->color_space = CUPS_CSPACE_CMYK; break; default: @@ -1068,38 +1068,38 @@ int prepare_pdf_page(struct pdf_info * info, unsigned width, unsigned height, // Convert image to CMYK case CUPS_CSPACE_CMYK: if (IMAGE_RGB_8) - fn = convertPdf_Rgb8ToCmyk8; + fn = convert_pdf_rgb_8_to_cmyk_8; else if (IMAGE_RGB_16) - fn = convertPdf_NoConversion; + fn = convert_pdf_no_conversion; else if (IMAGE_WHITE_8) - fn = convertPdf_White8ToCmyk8; + fn = convert_pdf_white_8_to_cmyk_8; else if (IMAGE_WHITE_16) - fn = convertPdf_NoConversion; + fn = convert_pdf_no_conversion; break; // Convert image to RGB case CUPS_CSPACE_ADOBERGB: case CUPS_CSPACE_RGB: case CUPS_CSPACE_SRGB: if (IMAGE_CMYK_8) - fn = convertPdf_Cmyk8ToRgb8; + fn = convert_pdf_cmyk_8_to_rgb_8; else if (IMAGE_CMYK_16) - fn = convertPdf_NoConversion; + fn = convert_pdf_no_conversion; else if (IMAGE_WHITE_8) - fn = convertPdf_White8ToRgb8; + fn = convert_pdf_white_8_to_rgb_8; else if (IMAGE_WHITE_16) - fn = convertPdf_NoConversion; + fn = convert_pdf_no_conversion; break; // Convert image to Grayscale case CUPS_CSPACE_SW: case CUPS_CSPACE_K: if (IMAGE_CMYK_8) - fn = convertPdf_Cmyk8ToWhite8; + fn = convert_pdf_cmyk_8_to_white_8; else if (IMAGE_CMYK_16) - fn = convertPdf_NoConversion; + fn = convert_pdf_no_conversion; else if (IMAGE_RGB_8) - fn = convertPdf_Rgb8ToWhite8; + fn = convert_pdf_rgb_8_to_white_8; else if (IMAGE_RGB_16) - fn = convertPdf_NoConversion; + fn = convert_pdf_no_conversion; break; case CUPS_CSPACE_DEVICE1: case CUPS_CSPACE_DEVICE2: @@ -1117,7 +1117,7 @@ int prepare_pdf_page(struct pdf_info * info, unsigned width, unsigned height, case CUPS_CSPACE_DEVICEE: case CUPS_CSPACE_DEVICEF: // No conversion for right now - fn = convertPdf_NoConversion; + fn = convert_pdf_no_conversion; break; default: if (doc->logfunc) @@ -1134,7 +1134,7 @@ int prepare_pdf_page(struct pdf_info * info, unsigned width, unsigned height, return error; } -int add_pdf_page(struct pdf_info * info, int pagen, unsigned width, +static int add_pdf_page(struct pdf_info * info, int pagen, unsigned width, unsigned height, int bpp, int bpc, int bpl, std::string render_intent, cups_cspace_t color_space, unsigned xdpi, unsigned ydpi, rastertopdf_doc_t *doc) @@ -1182,7 +1182,7 @@ int add_pdf_page(struct pdf_info * info, int pagen, unsigned width, { page.replaceKey("/Contents",QPDFObjectHandle::newStream(&info->pdf)); // data will be provided later - page.replaceKey("/MediaBox",makeRealBox(0,0,info->page_width, + page.replaceKey("/MediaBox",make_real_box(0,0,info->page_width, info->page_height)); } else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM) @@ -1194,7 +1194,7 @@ int add_pdf_page(struct pdf_info * info, int pagen, unsigned width, // box with dimensions rounded off to the nearest integer page.replaceKey("/MediaBox", - makeIntegerBox(0,0,info->page_width + 0.5, + make_integer_box(0,0,info->page_width + 0.5, info->page_height + 0.5)); } @@ -1213,7 +1213,7 @@ int add_pdf_page(struct pdf_info * info, int pagen, unsigned width, return 0; } -int close_pdf_file(struct pdf_info * info, rastertopdf_doc_t *doc) +static int close_pdf_file(struct pdf_info * info, rastertopdf_doc_t *doc) { try { if (finish_page(info, doc)) // any active @@ -1231,7 +1231,7 @@ int close_pdf_file(struct pdf_info * info, rastertopdf_doc_t *doc) return 0; } -void pdf_set_line(struct pdf_info * info, unsigned line_n, +static void pdf_set_line(struct pdf_info * info, unsigned line_n, unsigned char *line, rastertopdf_doc_t *doc) { if(line_n > info->height) @@ -1255,7 +1255,7 @@ void pdf_set_line(struct pdf_info * info, unsigned line_n, } } -int convert_raster(cups_raster_t *ras, unsigned width, unsigned height, +static int convert_raster(cups_raster_t *ras, unsigned width, unsigned height, int bpp, int bpl, struct pdf_info * info, rastertopdf_doc_t *doc) { @@ -1304,7 +1304,7 @@ int convert_raster(cups_raster_t *ras, unsigned width, unsigned height, return 0; } -int setProfile(const char * path, rastertopdf_doc_t *doc) +static int set_profile(const char * path, rastertopdf_doc_t *doc) { if (path != NULL) doc->colorProfile = cmsOpenProfileFromFile(path,"r"); @@ -1323,57 +1323,6 @@ int setProfile(const char * path, rastertopdf_doc_t *doc) } } -/* Obtain a source profile name using color qualifiers from raster file */ -const char * getIPPColorProfileName(const char * media_type, cups_cspace_t cs, - unsigned dpi) -{ - std::string mediaType = ""; - std::string resolution = ""; - std::string colorModel = ""; - - std::string iccProfile = ""; - - // ColorModel - switch (cs) { - case CUPS_CSPACE_RGB: - colorModel = "rgb"; - break; - case CUPS_CSPACE_SRGB: - colorModel = "srgb"; - break; - case CUPS_CSPACE_ADOBERGB: - colorModel = "adobergb"; - break; - case CUPS_CSPACE_K: - colorModel = "gray"; - break; - case CUPS_CSPACE_CMYK: - colorModel = "cmyk"; - break; - default: - colorModel = ""; - break; - } - - if (media_type != NULL) - mediaType = media_type; - if (dpi > 0) - resolution = dpi; - - // Requires color space and media type qualifiers - if (resolution != "" || colorModel != "") - return 0; - - // profile-uri reference: - // http://www.server.com/colorModel-Resolution-mediaType.icc - if (mediaType != "") - iccProfile = colorModel + "-" + resolution + ".icc"; - else - iccProfile = colorModel + "-" + resolution + "-" + mediaType + ".icc"; - - return strdup(iccProfile.c_str()); -} - int /* O - Error status */ cfFilterRasterToPDF(int inputfd, /* I - File descriptor input stream */ int outputfd, /* I - File descriptor output stream */ @@ -1722,7 +1671,7 @@ cfFilterRasterToPDF(int inputfd, /* I - File descriptor input stream */ if (outformat == CF_FILTER_OUT_FORMAT_PDF && (profile_name = cupsGetOption("profile", data->num_options, data->options)) != NULL) { - setProfile(profile_name, &doc); + set_profile(profile_name, &doc); doc.cm_disabled = 0; } if (doc.colorProfile != NULL) diff --git a/cupsfilters/rastertops.c b/cupsfilters/rastertops.c index 2cf332202..03c86bb87 100644 --- a/cupsfilters/rastertops.c +++ b/cupsfilters/rastertops.c @@ -18,7 +18,7 @@ /* * Types... */ -typedef struct { /**** Document information ****/ +typedef struct rastertops_doc_s { /**** Document information ****/ cups_file_t *inputfp; /* Temporary file, if any */ FILE *outputfp; /* Temporary file, if any */ cf_logfunc_t logfunc; /* Logging function, NULL for no @@ -37,8 +37,8 @@ typedef struct { /**** Document information ****/ * 'write_prolog()' - Writing the PostScript prolog for the file */ -void -writeProlog(int width, /* I - width of the image in points */ +static void +write_prolog(int width, /* I - width of the image in points */ int height, /* I - height of the image in points */ rastertops_doc_t *doc) /* I - Document information */ { @@ -55,11 +55,11 @@ writeProlog(int width, /* I - width of the image in points */ } /* - * 'writeStartPage()' - Write the basic page setup + * 'write_start_page()' - Write the basic page setup */ -void -writeStartPage(int page, /* I - Page to write */ +static void +write_start_page(int page, /* I - Page to write */ int width, /* I - Page width in points */ int length, /* I - Page length in points */ rastertops_doc_t *doc) /* I - Document information */ @@ -77,7 +77,7 @@ writeStartPage(int page, /* I - Page to write */ * 'find_bits()' - Finding the number of bits per color */ -int /* O - Exit status */ +static int /* O - Exit status */ find_bits(cups_cspace_t mode, /* I - Color space of data */ int bpc) /* I - Original bits per color of data */ { @@ -95,11 +95,11 @@ find_bits(cups_cspace_t mode, /* I - Color space of data */ } /* - * 'writeImage()' - Write the information regarding the image + * 'write_image()' - Write the information regarding the image */ -void /* O - Exit status */ -writeImage(int pagewidth, /* I - width of page in points */ +static void +write_image(int pagewidth, /* I - width of page in points */ int pageheight, /* I - height of page in points */ int bpc, /* I - bits per color */ int pixwidth, /* I - width of image in pixels */ @@ -179,7 +179,7 @@ writeImage(int pagewidth, /* I - width of page in points */ * 'convert_pixels()'- Convert 1 bpc to 8 bpc */ -void +static void convert_pixels(unsigned char *pixdata, /* I - Original pixel data */ unsigned char *convertedpix, /* I - Buffer for converted data */ int width) /* I - Width of data */ @@ -206,10 +206,10 @@ convert_pixels(unsigned char *pixdata, /* I - Original pixel data */ } /* - * 'write_flate()' - Write the image data in flate encoded format + * 'write_flate()' - Write the image data in flate encoded format */ -int /* O - Error value */ +static int /* O - Error value */ write_flate(cups_raster_t *ras, /* I - Image data */ cups_page_header2_t header, /* I - Bytes Per Line */ rastertops_doc_t *doc) /* I - Document information */ @@ -309,11 +309,11 @@ write_flate(cups_raster_t *ras, /* I - Image data */ } /* - * Report a zlib or i/o error + * 'z_error()' - Report a zlib or i/o error */ -void -zerr(int ret, /* I - Return status of deflate */ +static void +z_error(int ret, /* I - Return status of deflate */ rastertops_doc_t *doc) /* I - Document information */ { switch (ret) { @@ -340,11 +340,11 @@ zerr(int ret, /* I - Return status of deflate */ } /* - * 'writeEndPage()' - Show the current page. + * 'write_end_page()' - Show the current page. */ -void -writeEndPage(rastertops_doc_t *doc) /* I - Document information */ +static void +write_end_page(rastertops_doc_t *doc) /* I - Document information */ { fprintf(doc->outputfp, "\ngrestore\n"); fprintf(doc->outputfp, "showpage\n"); @@ -352,11 +352,11 @@ writeEndPage(rastertops_doc_t *doc) /* I - Document information */ } /* - * 'writeTrailer()' - Write the PostScript trailer. + * 'write_trailer()' - Write the PostScript trailer. */ -void -writeTrailer(int pages, /* I - Number of pages */ +static void +write_trailer(int pages, /* I - Number of pages */ rastertops_doc_t *doc) /* I - Document information */ { fprintf(doc->outputfp, "%%%%Trailer\n"); @@ -458,7 +458,7 @@ cfFilterRasterToPS(int inputfd, /* I - File descriptor input stream */ if (empty) { empty = 0; - writeProlog(header.PageSize[0], header.PageSize[1], &doc); + write_prolog(header.PageSize[0], header.PageSize[1], &doc); } /* @@ -473,12 +473,12 @@ cfFilterRasterToPS(int inputfd, /* I - File descriptor input stream */ /* * Write the starting of the page */ - writeStartPage(Page, header.PageSize[0], header.PageSize[1], &doc); + write_start_page(Page, header.PageSize[0], header.PageSize[1], &doc); /* * write the information regarding the image */ - writeImage(header.PageSize[0], header.PageSize[1], + write_image(header.PageSize[0], header.PageSize[1], header.cupsBitsPerColor, header.cupsWidth, header.cupsHeight, header.cupsColorSpace, &doc); @@ -486,8 +486,8 @@ cfFilterRasterToPS(int inputfd, /* I - File descriptor input stream */ /* Write the compressed image data*/ ret = write_flate(ras, header, &doc); if (ret != Z_OK) - zerr(ret, &doc); - writeEndPage(&doc); + z_error(ret, &doc); + write_end_page(&doc); } if (empty) @@ -498,7 +498,7 @@ cfFilterRasterToPS(int inputfd, /* I - File descriptor input stream */ return 0; } - writeTrailer(Page, &doc); + write_trailer(Page, &doc); cupsRasterClose(ras); diff --git a/cupsfilters/rastertopwg.c b/cupsfilters/rastertopwg.c index ccb400938..a92cdfa0b 100644 --- a/cupsfilters/rastertopwg.c +++ b/cupsfilters/rastertopwg.c @@ -20,7 +20,8 @@ /* - * 'main()' - Main entry for filter. + * 'cfFilterRasterToPWG()' - Filter function to convert CUPS Raster + * into PWG or Apple Raster */ int /* O - Exit status */ diff --git a/cupsfilters/texttopdf.c b/cupsfilters/texttopdf.c index 869cfad01..f5416cffc 100644 --- a/cupsfilters/texttopdf.c +++ b/cupsfilters/texttopdf.c @@ -9,15 +9,6 @@ * property of Apple Inc. and are protected by Federal copyright * law. Distribution and use rights are outlined in the file "COPYING" * which should have been included with this file. - * - * Contents: - * - * cfFilterTextToPDF() - Main entry for text to PDF filter. - * WriteEpilogue() - Write the PDF file epilogue. - * WritePage() - Write a page of text. - * WriteProlog() - Write the PDF file prolog with options. - * write_line() - Write a row of text. - * write_string() - Write a string of text. */ /* @@ -63,6 +54,7 @@ /* * Globals... */ + static char *code_keywords[] = /* List of known C/C++ keywords... */ { "and", @@ -475,6 +467,10 @@ static char *code_keywords[] = /* List of known C/C++ keywords... */ "write" }; +/* + * Types... + */ + typedef struct /**** Character/attribute structure... ****/ { unsigned short ch, /* Character */ @@ -527,198 +523,15 @@ typedef struct texttopdf_doc_s } texttopdf_doc_t; -EMB_PARAMS *font_load(const char *font, int fontwidth, cf_logfunc_t log, - void *ld) -{ - OTF_FILE *otf; - - FcPattern *pattern; - FcFontSet *candidates; - FcChar8 *fontname = NULL; - FcResult result; - int i; - - if ((font[0] == '/') || (font[0] == '.')) - { - candidates = NULL; - fontname = (FcChar8 *)strdup(font); - } - else - { - FcInit(); - pattern = FcNameParse ((const FcChar8 *)font); - FcPatternAddInteger(pattern, FC_SPACING, FC_MONO); - // guide fc, in case substitution becomes necessary - FcConfigSubstitute (0, pattern, FcMatchPattern); - FcDefaultSubstitute (pattern); - - /* Receive a sorted list of fonts matching our pattern */ - candidates = FcFontSort (0, pattern, FcFalse, 0, &result); - FcPatternDestroy (pattern); - - if (candidates) - { - /* In the list of fonts returned by FcFontSort() - find the first one that is both in TrueType format and monospaced */ - for (i = 0; i < candidates->nfont; i ++) - { - FcChar8 *fontformat = NULL; // TODO? or just try? - int spacing = 0; // sane default, as FC_MONO == 100 - FcPatternGetString(candidates->fonts[i], FC_FONTFORMAT, 0, &fontformat); - FcPatternGetInteger(candidates->fonts[i], FC_SPACING, 0, &spacing); - - if ((fontformat) && ((spacing == FC_MONO) || (fontwidth == 2))) - { - // check for monospace or double width fonts - if (strcmp((const char *)fontformat, "TrueType") == 0) - { - fontname = - FcPatternFormat(candidates->fonts[i], - (const FcChar8 *)"%{file|cescape}/%{index}"); - break; - } - else if (strcmp((const char *)fontformat, "CFF") == 0) - { - fontname = - FcPatternFormat (candidates->fonts[i], - (const FcChar8 *)"%{file|cescape}"); - // TTC only possible with non-cff glyphs! - break; - } - } - } - FcFontSetDestroy (candidates); - } - } - - if (!fontname) - { - // TODO: try /usr/share/fonts/*/*/%s.ttf - if(log) log(ld, CF_LOGLEVEL_ERROR,"cfFilterTextToPDF: No viable font found."); - return NULL; - } - - otf = otf_load((const char *)fontname); - free(fontname); - if (!otf) - { - return NULL; - } - - FONTFILE *ff = fontfile_open_sfnt(otf); - assert(ff); - EMB_PARAMS *emb = emb_new(ff, - EMB_DEST_PDF16, - EMB_C_FORCE_MULTIBYTE| - EMB_C_TAKE_FONTFILE); - assert(emb); - assert(emb->plan&EMB_A_MULTIBYTE); - return emb; -} - -EMB_PARAMS *font_std(const char *name) -{ - FONTFILE *ff = fontfile_open_std(name); - assert(ff); - EMB_PARAMS *emb = emb_new(ff, - EMB_DEST_PDF16, - EMB_C_TAKE_FONTFILE); - assert(emb); - return emb; -} - - -/* - * 'compare_keywords()' - Compare two C/C++ keywords. - */ - -static int /* O - Result of strcmp */ -compare_keywords(const void *k1, /* I - First keyword */ - const void *k2) /* I - Second keyword */ -{ - return (strcmp(*((const char **)k1), *((const char **)k2))); -} - - -/* - * 'getutf8()' - Get a UTF-8 encoded wide character... - */ - -static int /* O - Character or -1 on error */ -getutf8(FILE *fp) /* I - File to read from */ -{ - int ch; /* Current character value */ - int next; /* Next character from file */ - - - /* - * Read the first character and process things accordingly... - * - * UTF-8 maps 16-bit characters to: - * - * 0 to 127 = 0xxxxxxx - * 128 to 2047 = 110xxxxx 10yyyyyy (xxxxxyyyyyy) - * 2048 to 65535 = 1110xxxx 10yyyyyy 10zzzzzz (xxxxyyyyyyzzzzzz) - * - * We also accept: - * - * 128 to 191 = 10xxxxxx - * - * since this range of values is otherwise undefined unless you are - * in the middle of a multi-byte character... - * - * This code currently does not support anything beyond 16-bit - * characters, in part because PostScript doesn't support more than - * 16-bit characters... - */ - - if ((ch = getc(fp)) == EOF) - return (EOF); - - if (ch < 0xc0) /* One byte character? */ - return (ch); - else if ((ch & 0xe0) == 0xc0) - { - /* - * Two byte character... - */ - - if ((next = getc(fp)) == EOF) - return (EOF); - else - return (((ch & 0x1f) << 6) | (next & 0x3f)); - } - else if ((ch & 0xf0) == 0xe0) - { - /* - * Three byte character... - */ - - if ((next = getc(fp)) == EOF) - return (EOF); - - ch = ((ch & 0x0f) << 6) | (next & 0x3f); - - if ((next = getc(fp)) == EOF) - return (EOF); - else - return ((ch << 6) | (next & 0x3f)); - } - else - { - /* - * More than three bytes... We don't support that... - */ - - return (EOF); - } -} - - /* * Local functions... */ +static EMB_PARAMS *font_load(const char *font, int fontwidth, cf_logfunc_t log, + void *ld); +static EMB_PARAMS *font_std(const char *name); +static int compare_keywords(const void *k1, const void *k2); +static int get_utf8(FILE *fp); static void write_line(int row, lchar_t *line, texttopdf_doc_t *doc); static void write_string(int col, int row, int len, lchar_t *s, texttopdf_doc_t *doc); @@ -726,12 +539,12 @@ static lchar_t *make_wide(const char *buf, texttopdf_doc_t *doc); static void write_font_str(float x,float y,int fontid, lchar_t *str, int len, texttopdf_doc_t *doc); static void write_pretty_header(); -int WriteProlog(const char *title, const char *user, +static int write_prolog(const char *title, const char *user, const char *classification, const char *label, ppd_file_t *ppd, texttopdf_doc_t *doc, cf_logfunc_t log, void *ld); -void WritePage(texttopdf_doc_t *doc); -void WriteEpilogue(texttopdf_doc_t *doc); +static void write_page(texttopdf_doc_t *doc); +static void write_epilogue(texttopdf_doc_t *doc); /* @@ -1040,13 +853,13 @@ cfFilterTextToPDF(int inputfd, /* I - File descriptor input stream */ cmntState = NoCmnt; strState = NoStr; - while ((ch = getutf8(fp)) >= 0) + while ((ch = get_utf8(fp)) >= 0) { if (empty) { /* Found the first valid character, write file header */ empty = 0; - ret = WriteProlog(data->job_title, data->job_user, + ret = write_prolog(data->job_title, data->job_user, doc.env_vars.classification, cupsGetOption("page-label", data->num_options, data->options), @@ -1116,7 +929,7 @@ cfFilterTextToPDF(int inputfd, /* I - File descriptor input stream */ if (page_column >= doc.PageColumns) { - WritePage(&doc); + write_page(&doc); page_column = 0; } } @@ -1192,7 +1005,7 @@ cfFilterTextToPDF(int inputfd, /* I - File descriptor input stream */ if (page_column >= doc.PageColumns) { - WritePage(&doc); + write_page(&doc); page_column = 0; } } @@ -1250,13 +1063,13 @@ cfFilterTextToPDF(int inputfd, /* I - File descriptor input stream */ if (page_column >= doc.PageColumns) { - WritePage(&doc); + write_page(&doc); page_column = 0; } break; case 0x1b : /* Escape sequence */ - ch = getutf8(fp); + ch = get_utf8(fp); if (ch == '7') { /* @@ -1424,7 +1237,7 @@ cfFilterTextToPDF(int inputfd, /* I - File descriptor input stream */ if (page_column >= doc.PageColumns) { - WritePage(&doc); + write_page(&doc); page_column = 0; } } @@ -1529,13 +1342,13 @@ cfFilterTextToPDF(int inputfd, /* I - File descriptor input stream */ */ if (line > 0 || page_column > 0 || column > 0) - WritePage(&doc); + write_page(&doc); /* * Write the epilog and return... */ - WriteEpilogue(&doc); + write_epilogue(&doc); out: @@ -1577,12 +1390,200 @@ cfFilterTextToPDF(int inputfd, /* I - File descriptor input stream */ } +static EMB_PARAMS *font_load(const char *font, int fontwidth, cf_logfunc_t log, + void *ld) +{ + OTF_FILE *otf; + + FcPattern *pattern; + FcFontSet *candidates; + FcChar8 *fontname = NULL; + FcResult result; + int i; + + if ((font[0] == '/') || (font[0] == '.')) + { + candidates = NULL; + fontname = (FcChar8 *)strdup(font); + } + else + { + FcInit(); + pattern = FcNameParse ((const FcChar8 *)font); + FcPatternAddInteger(pattern, FC_SPACING, FC_MONO); + // guide fc, in case substitution becomes necessary + FcConfigSubstitute (0, pattern, FcMatchPattern); + FcDefaultSubstitute (pattern); + + /* Receive a sorted list of fonts matching our pattern */ + candidates = FcFontSort (0, pattern, FcFalse, 0, &result); + FcPatternDestroy (pattern); + + if (candidates) + { + /* In the list of fonts returned by FcFontSort() + find the first one that is both in TrueType format and monospaced */ + for (i = 0; i < candidates->nfont; i ++) + { + FcChar8 *fontformat = NULL; // TODO? or just try? + int spacing = 0; // sane default, as FC_MONO == 100 + FcPatternGetString(candidates->fonts[i], FC_FONTFORMAT, 0, &fontformat); + FcPatternGetInteger(candidates->fonts[i], FC_SPACING, 0, &spacing); + + if ((fontformat) && ((spacing == FC_MONO) || (fontwidth == 2))) + { + // check for monospace or double width fonts + if (strcmp((const char *)fontformat, "TrueType") == 0) + { + fontname = + FcPatternFormat(candidates->fonts[i], + (const FcChar8 *)"%{file|cescape}/%{index}"); + break; + } + else if (strcmp((const char *)fontformat, "CFF") == 0) + { + fontname = + FcPatternFormat (candidates->fonts[i], + (const FcChar8 *)"%{file|cescape}"); + // TTC only possible with non-cff glyphs! + break; + } + } + } + FcFontSetDestroy (candidates); + } + } + + if (!fontname) + { + // TODO: try /usr/share/fonts/*/*/%s.ttf + if(log) log(ld, CF_LOGLEVEL_ERROR,"cfFilterTextToPDF: No viable font found."); + return NULL; + } + + otf = otf_load((const char *)fontname); + free(fontname); + if (!otf) + { + return NULL; + } + + FONTFILE *ff = fontfile_open_sfnt(otf); + assert(ff); + EMB_PARAMS *emb = emb_new(ff, + EMB_DEST_PDF16, + EMB_C_FORCE_MULTIBYTE| + EMB_C_TAKE_FONTFILE); + assert(emb); + assert(emb->plan&EMB_A_MULTIBYTE); + return emb; +} + +static EMB_PARAMS *font_std(const char *name) +{ + FONTFILE *ff = fontfile_open_std(name); + assert(ff); + EMB_PARAMS *emb = emb_new(ff, + EMB_DEST_PDF16, + EMB_C_TAKE_FONTFILE); + assert(emb); + return emb; +} + + +/* + * 'compare_keywords()' - Compare two C/C++ keywords. + */ + +static int /* O - Result of strcmp */ +compare_keywords(const void *k1, /* I - First keyword */ + const void *k2) /* I - Second keyword */ +{ + return (strcmp(*((const char **)k1), *((const char **)k2))); +} + + +/* + * 'get_utf8()' - Get a UTF-8 encoded wide character... + */ + +static int /* O - Character or -1 on error */ +get_utf8(FILE *fp) /* I - File to read from */ +{ + int ch; /* Current character value */ + int next; /* Next character from file */ + + + /* + * Read the first character and process things accordingly... + * + * UTF-8 maps 16-bit characters to: + * + * 0 to 127 = 0xxxxxxx + * 128 to 2047 = 110xxxxx 10yyyyyy (xxxxxyyyyyy) + * 2048 to 65535 = 1110xxxx 10yyyyyy 10zzzzzz (xxxxyyyyyyzzzzzz) + * + * We also accept: + * + * 128 to 191 = 10xxxxxx + * + * since this range of values is otherwise undefined unless you are + * in the middle of a multi-byte character... + * + * This code currently does not support anything beyond 16-bit + * characters, in part because PostScript doesn't support more than + * 16-bit characters... + */ + + if ((ch = getc(fp)) == EOF) + return (EOF); + + if (ch < 0xc0) /* One byte character? */ + return (ch); + else if ((ch & 0xe0) == 0xc0) + { + /* + * Two byte character... + */ + + if ((next = getc(fp)) == EOF) + return (EOF); + else + return (((ch & 0x1f) << 6) | (next & 0x3f)); + } + else if ((ch & 0xf0) == 0xe0) + { + /* + * Three byte character... + */ + + if ((next = getc(fp)) == EOF) + return (EOF); + + ch = ((ch & 0x0f) << 6) | (next & 0x3f); + + if ((next = getc(fp)) == EOF) + return (EOF); + else + return ((ch << 6) | (next & 0x3f)); + } + else + { + /* + * More than three bytes... We don't support that... + */ + + return (EOF); + } +} + + /* - * 'WriteEpilogue()' - Write the PDF file epilogue. + * 'write_epilogue()' - Write the PDF file epilogue. */ -void -WriteEpilogue(texttopdf_doc_t *doc) +static void +write_epilogue(texttopdf_doc_t *doc) { static char *names[] = /* Font names */ { "FN","FB","FI","FBI" }; @@ -1638,11 +1639,11 @@ WriteEpilogue(texttopdf_doc_t *doc) } /* - * {{{ 'WritePage()' - Write a page of text. + * {{{ 'write_page()' - Write a page of text. */ -void -WritePage(texttopdf_doc_t *doc) +static void +write_page(texttopdf_doc_t *doc) { int line; /* Current line */ @@ -1693,11 +1694,11 @@ WritePage(texttopdf_doc_t *doc) // }}} /* - * {{{'WriteProlog()' - Write the PDF file prolog with options. + * {{{'write_prolog()' - Write the PDF file prolog with options. */ -int -WriteProlog(const char *title, /* I - Title of job */ +static int +write_prolog(const char *title, /* I - Title of job */ const char *user, /* I - Username */ const char *classification, /* I - Classification */ const char *label, /* I - Page label */ @@ -2636,7 +2637,7 @@ static void write_font_str(float x,float y,int fontid, lchar_t *str, } // }}} -static float stringwidth_x(lchar_t *str, texttopdf_doc_t * doc) +static float string_width_x(lchar_t *str, texttopdf_doc_t * doc) { int len; @@ -2670,7 +2671,7 @@ static void write_pretty_header(texttopdf_doc_t *doc) // {{{ if (doc->Duplex && (doc->NumPages & 1) == 0) { x = doc->PageRight - doc->PageLeft - 36.0f / - doc->LinesPerInch - stringwidth_x(doc->Title, doc); + doc->LinesPerInch - string_width_x(doc->Title, doc); y = (0.5f + 0.157f) * 72.0f / doc->LinesPerInch; } else @@ -2680,7 +2681,7 @@ static void write_pretty_header(texttopdf_doc_t *doc) // {{{ } write_font_str(x, y, ATTR_BOLD, doc->Title, -1, doc); - x = (-stringwidth_x(doc->Date, doc) + doc->PageRight - doc->PageLeft) * 0.5; + x = (-string_width_x(doc->Date, doc) + doc->PageRight - doc->PageLeft) * 0.5; write_font_str(x, y, ATTR_BOLD, doc->Date, -1, doc); // convert pagenumber to string @@ -2696,7 +2697,7 @@ static void write_pretty_header(texttopdf_doc_t *doc) // {{{ else { x = doc->PageRight - doc->PageLeft - - 36.0f / doc->LinesPerInch - stringwidth_x(pagestr, doc); + 36.0f / doc->LinesPerInch - string_width_x(pagestr, doc); } write_font_str(x, y, ATTR_BOLD, pagestr, -1, doc); free(pagestr); -- 2.47.3