i = 2;
if (c1[i] == '_') {
i ++;
- if (c1[i] < 'A' || c1[i] > 'Z' || c1[i+1] < 'A' || c1[i+1] > 'Z')
+ if (c1[i] < 'A' || c1[i] > 'Z' || c1[i + 1] < 'A' || c1[i + 1] > 'Z')
continue;
i += 2;
if (c1[i] >= 'A' && c1[i] <= 'Z')
DBUS_TYPE_ARRAY,
"s",
&entry);
- for (i=0; key[i] != NULL; i++)
+ for (i = 0; key[i] != NULL; i ++)
{
dbus_message_iter_append_basic(&entry,
DBUS_TYPE_STRING,
if (reply != NULL)
dbus_message_unref(reply);
if (key != NULL) {
- for (i=0; i < max_keys; i++)
+ for (i = 0; i < max_keys; i ++)
free(key[i]);
free(key);
}
h->cupsBorderlessScalingFactor);
cupsArrayAdd(gs_args, strdup(tmpstr));
}
- for (i=0; i <= 15; i ++)
+ for (i = 0; i <= 15; i ++)
if (h->cupsInteger[i])
{
snprintf(tmpstr, sizeof(tmpstr), "-dcupsInteger%d=%d",
i, (unsigned)(h->cupsInteger[i]));
cupsArrayAdd(gs_args, strdup(tmpstr));
}
- for (i=0; i <= 15; i ++)
+ for (i = 0; i <= 15; i ++)
if (h->cupsReal[i])
{
snprintf(tmpstr, sizeof(tmpstr), "-dcupsReal%d=%.4f",
i, h->cupsReal[i]);
cupsArrayAdd(gs_args, strdup(tmpstr));
}
- for (i=0; i <= 15; i ++)
+ for (i = 0; i <= 15; i ++)
if (h->cupsString[i][0] != '\0')
{
snprintf(tmpstr, sizeof(tmpstr), "-scupsString%d=%s",
goto out_of_memory;
if (pdf_printer && log)
log(ld, CF_LOGLEVEL_CONTROL,
- "PAGE: %d %d\n", doc.page+1, 1);
+ "PAGE: %d %d\n", doc.page + 1, 1);
}
}
}
b /= 85;
c[0] = b + '!';
- c[length+1] = '\0';
+ c[length + 1] = '\0';
out_pdf(doc, c);
}
else if(!strcasecmp(val, "fit"))
zoom = 1.0; // fitplot = 1 or fit method
else
- cropfit=1; // none or crop-to-fit
+ cropfit = 1; // none or crop-to-fit
}
else // print-scaling is not defined, look for alternate options.
{
- /***
- This file is part of cups-filters.
-
- This file is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- This file is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
- USA.
-***/
-
-/*
- * Include necessary headers.
- */
+//
+// IPP-related functions for libcupsfilters.
+//
+// This file is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of the
+// License, or (at your option) any later version.
+//
+// This file is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+// Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with avahi; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+// USA.
+//
+
+//
+// Include necessary headers.
+//
#include <config.h>
#include <cups/pwg.h>
#include <cupsfilters/ipp.h>
-enum resolve_uri_converter_type /**** Resolving DNS-SD based URI ****/
+
+enum resolve_uri_converter_type // **** Resolving DNS-SD based URI ****
{
CUPS_BACKEND_URI_CONVERTER = -1,
IPPFIND_BASED_CONVERTER_FOR_PRINT_URI = 0,
convert_to_port(char *a)
{
int port = 0;
- for (int i = 0; i<strlen(a); i++)
+ for (int i = 0; i < strlen(a); i ++)
port = port*10 + (a[i] - '0');
return (port);
int fd1, fd2;
char *save_device_uri_var;
- /* Eliminate any output to stderr, to get rid of the CUPS-backend-specific
- output of the cupsBackendDeviceURI() function */
+ // Eliminate any output to stderr, to get rid of the CUPS-backend-specific
+ // output of the cupsBackendDeviceURI() function
fd1 = dup(2);
fd2 = open("/dev/null", O_WRONLY);
dup2(fd2, 2);
close(fd2);
- /* If set, save the DEVICE_URI environment and then unset it, so that
- if we are running under CUPS (as filter or backend) our raw_uri gets
- resolved and not whatever URI is set in DEVICE_URI */
+ // If set, save the DEVICE_URI environment and then unset it, so that
+ // if we are running under CUPS (as filter or backend) our raw_uri gets
+ // resolved and not whatever URI is set in DEVICE_URI
if ((save_device_uri_var = getenv("DEVICE_URI")) != NULL)
{
save_device_uri_var = strdup(save_device_uri_var);
unsetenv("DEVICE_URI");
}
- /* Use the URI resolver of libcups to support DNS-SD-service-name-based
- URIs. The function returns the corresponding host-name-based URI */
+ // Use the URI resolver of libcups to support DNS-SD-service-name-based
+ // URIs. The function returns the corresponding host-name-based URI
pseudo_argv[0] = (char *)raw_uri;
pseudo_argv[1] = NULL;
uri = cupsBackendDeviceURI(pseudo_argv);
- /* Restore DEVICE_URI envidonment variable if we had unset it */
+ // Restore DEVICE_URI environment variable if we had unset it
if (save_device_uri_var)
{
setenv("DEVICE_URI", save_device_uri_var, 1);
free(save_device_uri_var);
}
- /* Re-activate stderr output */
+ // Re-activate stderr output
dup2(fd1, 2);
close(fd1);
return (uri ? strdup(uri) : NULL);
}
-/* Check how the driverless support is provided */
+// Check how the driverless support is provided
int
cfCheckDriverlessSupport(const char* uri)
{
if (response != NULL)
ippDelete(response);
- return support_status;
+ return (support_status);
}
-/* Get attributes of a printer specified only by URI */
+// Get attributes of a printer specified only by URI
ipp_t *
cfGetPrinterAttributes(const char* raw_uri,
const char* const pattrs[],
int req_attrs_size,
int debug)
{
- return cfGetPrinterAttributes2(NULL, raw_uri, pattrs, pattrs_size,
- req_attrs, req_attrs_size, debug);
+ return (cfGetPrinterAttributes2(NULL, raw_uri, pattrs, pattrs_size,
+ req_attrs, req_attrs_size, debug));
}
-/* Get attributes of a printer specified by URI and under a given HTTP
- connection, for example via a domain socket */
+// Get attributes of a printer specified by URI and under a given HTTP
+// connection, for example via a domain socket
ipp_t *
cfGetPrinterAttributes2(http_t *http_printer,
const char* raw_uri,
int req_attrs_size,
int debug)
{
- return cfGetPrinterAttributes3(http_printer, raw_uri, pattrs, pattrs_size,
- req_attrs, req_attrs_size, debug, NULL);
+ return (cfGetPrinterAttributes3(http_printer, raw_uri, pattrs, pattrs_size,
+ req_attrs, req_attrs_size, debug, NULL));
}
-/* Get attributes of a printer specified by URI and under a given HTTP
- connection, for example via a domain socket, and give info about used
- fallbacks */
+// Get attributes of a printer specified by URI and under a given HTTP
+// connection, for example via a domain socket, and give info about used
+// fallbacks
ipp_t *
cfGetPrinterAttributes3(http_t *http_printer,
const char* raw_uri,
int debug,
int* driverless_info)
{
- return cfGetPrinterAttributes5(http_printer, raw_uri, pattrs, pattrs_size,
- req_attrs, req_attrs_size, debug,
- driverless_info, CUPS_BACKEND_URI_CONVERTER);
+ return (cfGetPrinterAttributes5(http_printer, raw_uri, pattrs, pattrs_size,
+ req_attrs, req_attrs_size, debug,
+ driverless_info, CUPS_BACKEND_URI_CONVERTER));
}
-/* Get attributes of a printer specified only by URI and given info about fax-support*/
+// Get attributes of a printer specified only by URI and given info about
+// fax-support
ipp_t *cfGetPrinterAttributes4(const char* raw_uri,
const char* const pattrs[],
int pattrs_size,
int debug,
int is_fax)
{
- if(is_fax)
- return cfGetPrinterAttributes5(NULL, raw_uri, pattrs, pattrs_size,
- req_attrs, req_attrs_size, debug, NULL,
- IPPFIND_BASED_CONVERTER_FOR_FAX_URI);
+ if (is_fax)
+ return (cfGetPrinterAttributes5(NULL, raw_uri, pattrs, pattrs_size,
+ req_attrs, req_attrs_size, debug, NULL,
+ IPPFIND_BASED_CONVERTER_FOR_FAX_URI));
else
- return cfGetPrinterAttributes5(NULL, raw_uri, pattrs, pattrs_size,
- req_attrs, req_attrs_size, debug, NULL,
- IPPFIND_BASED_CONVERTER_FOR_PRINT_URI);
+ return (cfGetPrinterAttributes5(NULL, raw_uri, pattrs, pattrs_size,
+ req_attrs, req_attrs_size, debug, NULL,
+ IPPFIND_BASED_CONVERTER_FOR_PRINT_URI));
}
-/* Get attributes of a printer specified by URI and under a given HTTP
- connection, for example via a domain socket, and give info about used
- fallbacks */
+// Get attributes of a printer specified by URI and under a given HTTP
+// connection, for example via a domain socket, and give info about used
+// fallbacks
ipp_t *
cfGetPrinterAttributes5(http_t *http_printer,
const char* raw_uri,
char valuebuffer[65536];
const char *kw;
ipp_status_t ipp_status;
- /* Default attributes for get-printer-attributes requests to
- obtain complete capability lists of a printer */
- const char * const pattrs_cap_standard[] = {
+ // Default attributes for get-printer-attributes requests to
+ // obtain complete capability lists of a printer
+ const char * const pattrs_cap_standard[] =
+ {
"all",
"media-col-database",
};
- const char * const pattrs_cap_fallback[] = {
+ const char * const pattrs_cap_fallback[] =
+ {
"all",
};
- /* Attributes required in the IPP response of a complete printer
- capability list */
- const char * const req_attrs_cap[] = {
+ // Attributes required in the IPP response of a complete printer
+ // capability list
+ const char * const req_attrs_cap[] =
+ {
"attributes-charset",
"attributes-natural-language",
"charset-configured",
"uri-security-supported"
};
- /* Expect a device capable of standard IPP Everywhere */
+ // Expect a device capable of standard IPP Everywhere
if (driverless_info != NULL)
*driverless_info = CF_DRVLESS_FULL;
- /* Request printer properties via IPP, for example to
- - Find capabilities, options, and default settings
- - Printer's status: Accepting jobs? Busy? With how many jobs?
- - Generate a PPD file for the printer
- (mainly driverless-capable printers with CUPS 2.x) */
+ //
+ // Request printer properties via IPP, for example to
+ // - Find capabilities, options, and default settings
+ // - Printer's status: Accepting jobs? Busy? With how many jobs?
+ // - Generate a PPD file for the printer
+ // (mainly driverless-capable printers with CUPS 2.x)
+ //
cf_get_printer_attributes_log[0] = '\0';
- /* Convert DNS-SD-service-name-based URIs to host-name-based URIs */
- if(resolve_uri_type == CUPS_BACKEND_URI_CONVERTER)
+ // Convert DNS-SD-service-name-based URIs to host-name-based URIs
+ if (resolve_uri_type == CUPS_BACKEND_URI_CONVERTER)
uri = cfResolveURI(raw_uri);
else
uri = cfippfindBasedURIConverter(raw_uri, resolve_uri_type);
return NULL;
}
- /* Extract URI componants needed for the IPP request */
+ // Extract URI componants needed for the IPP request
uri_status = httpSeparateURI(HTTP_URI_CODING_ALL, uri,
scheme, sizeof(scheme),
userpass, sizeof(userpass),
host_name, sizeof(host_name),
&(host_port),
resource, sizeof(resource));
- if (uri_status != HTTP_URI_OK) {
- /* Invalid URI */
+ if (uri_status != HTTP_URI_OK)
+ {
+ // Invalid URI
log_printf(cf_get_printer_attributes_log,
"get-printer-attributes: Cannot parse the printer URI: %s\n",
uri);
else
encryption = HTTP_ENCRYPTION_IF_REQUESTED;
- /* Connect to the server if not already done */
- if (http_printer == NULL) {
+ // Connect to the server if not already done
+ if (http_printer == NULL)
+ {
have_http = 0;
if ((http_printer =
httpConnect2 (host_name, host_port, NULL, AF_UNSPEC,
- encryption, 1, 3000, NULL)) == NULL) {
+ encryption, 1, 3000, NULL)) == NULL)
+ {
log_printf(cf_get_printer_attributes_log,
"get-printer-attributes: Cannot connect to printer with URI %s.\n",
uri);
if (uri) free(uri);
return NULL;
}
- } else
+ }
+ else
have_http = 1;
- /* If we got called without attribute list, use the attributes for polling
- a complete list of capabilities of the printer.
- If also no list of required attributes in the response is supplied, use
- the default list */
- if (pattrs == NULL || pattrs_size == 0) {
+ // If we got called without attribute list, use the attributes for polling
+ // a complete list of capabilities of the printer.
+ // If also no list of required attributes in the response is supplied, use
+ // the default list
+ if (pattrs == NULL || pattrs_size == 0)
+ {
cap = 1;
pattrs = pattrs_cap_standard;
pattrs_size = sizeof(pattrs_cap_standard) / sizeof(pattrs_cap_standard[0]);
- if (req_attrs == NULL || req_attrs_size == 0) {
+ if (req_attrs == NULL || req_attrs_size == 0)
+ {
req_attrs = req_attrs_cap;
req_attrs_size = sizeof(req_attrs_cap) / sizeof(req_attrs_cap[0]);
}
}
- /* Loop through all fallbacks until getting a successful result */
- for (fallback = 0; fallback < 2 + cap; fallback ++) {
+ // Loop through all fallbacks until getting a successful result
+ for (fallback = 0; fallback < 2 + cap; fallback ++)
+ {
request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
if (fallback == 1)
- /* Fallback 1: Try IPP 1.1 instead of 2.0 */
+ // Fallback 1: Try IPP 1.1 instead of 2.0
ippSetVersion(request, 1, 1);
- if (fallback == 2 && cap) {
- /* Fallback 2: (Only for full capability list) Try only "all",
- without "media-col-database */
+ if (fallback == 2 && cap)
+ {
+ // Fallback 2: (Only for full capability list) Try only "all",
+ // without "media-col-database"
pattrs = pattrs_cap_fallback;
pattrs_size = sizeof(pattrs_cap_fallback) /
sizeof(pattrs_cap_fallback[0]);
response = cupsDoRequest(http_printer, request, resource);
ipp_status = cupsLastError();
- if (response) {
+ if (response)
+ {
log_printf(cf_get_printer_attributes_log,
"Requested IPP attributes (get-printer-attributes) for printer with URI %s\n",
uri);
- /* Log all printer attributes for debugging and count them */
+ // Log all printer attributes for debugging and count them
if (debug)
log_printf(cf_get_printer_attributes_log,
"Full list of all IPP attributes:\n");
attr = ippFirstAttribute(response);
- while (attr) {
+ while (attr)
+ {
total_attrs ++;
- if (debug) {
+ if (debug)
+ {
ippAttributeString(attr, valuebuffer, sizeof(valuebuffer));
log_printf(cf_get_printer_attributes_log,
" Attr: %s\n",ippGetName(attr));
log_printf(cf_get_printer_attributes_log,
" Value: %s\n", valuebuffer);
- for (i = 0; i < ippGetCount(attr); i ++) {
- if ((kw = ippGetString(attr, i, NULL)) != NULL) {
+ for (i = 0; i < ippGetCount(attr); i ++)
+ if ((kw = ippGetString(attr, i, NULL)) != NULL)
log_printf(cf_get_printer_attributes_log, " Keyword: %s\n", kw);
- }
- }
}
attr = ippNextAttribute(response);
}
- /* Check whether the IPP response contains the required attributes
- and is not incomplete */
+ // Check whether the IPP response contains the required attributes
+ // and is not incomplete
if (req_attrs)
for (i = req_attrs_size; i > 0; i --)
if (ippFindAttribute(response, req_attrs[i - 1], IPP_TAG_ZERO) ==
break;
if (ipp_status == IPP_STATUS_ERROR_BAD_REQUEST ||
ipp_status == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED ||
- (req_attrs && i > 0) || (cap && total_attrs < 20)) {
+ (req_attrs && i > 0) || (cap && total_attrs < 20))
+ {
log_printf(cf_get_printer_attributes_log,
"get-printer-attributes IPP request failed:\n");
if (ipp_status == IPP_STATUS_ERROR_BAD_REQUEST)
" - Too few IPP attributes: %d (30 or more expected)\n",
total_attrs);
ippDelete(response);
- } else {
- /* Suitable response, we are done */
+ }
+ else
+ {
+ // Suitable response, we are done
if (have_http == 0) httpClose(http_printer);
if (uri) free(uri);
return response;
}
- } else {
+ }
+ else
+ {
log_printf(cf_get_printer_attributes_log,
"Request for IPP attributes (get-printer-attributes) for printer with URI %s failed: %s\n",
uri, cupsLastErrorString());
log_printf(cf_get_printer_attributes_log, "get-printer-attributes IPP request failed:\n");
log_printf(cf_get_printer_attributes_log, " - No response\n");
}
- if (fallback == 1 + cap) {
+ if (fallback == 1 + cap)
+ {
log_printf(cf_get_printer_attributes_log,
"No further fallback available, giving up\n");
if (driverless_info != NULL)
*driverless_info = CF_DRVLESS_CHECKERR;
- } else if (cap && fallback == 1) {
+ }
+ else if (cap && fallback == 1)
+ {
log_printf(cf_get_printer_attributes_log,
"The server doesn't support the standard IPP request, trying request without media-col\n");
if (driverless_info != NULL)
*driverless_info = CF_DRVLESS_INCOMPLETEIPP;
- } else if (fallback == 0) {
+ }
+ else if (fallback == 0)
+ {
log_printf(cf_get_printer_attributes_log,
"The server doesn't support IPP2.0 request, trying IPP1.1 request\n");
if (driverless_info != NULL)
if (have_http == 0) httpClose(http_printer);
if (uri) free(uri);
- return NULL;
+ return (NULL);
}
char*
cfippfindBasedURIConverter (const char *uri, int is_fax)
{
- int ippfind_pid = 0, /* Process ID of ippfind for IPP */
- post_proc_pipe[2], /* Pipe to post-processing for IPP */
- wait_children, /* Number of child processes left */
- wait_pid, /* Process ID from wait() */
- wait_status, /* Status from child */
- exit_status = 0, /* Exit status */
+ int ippfind_pid = 0, // Process ID of ippfind for IPP
+ post_proc_pipe[2], // Pipe to post-processing for IPP
+ wait_children, // Number of child processes left
+ wait_pid, // Process ID from wait()
+ wait_status, // Status from child
+ exit_status = 0, // Exit status
bytes,
port,
i,
output_of_fax_uri = 0,
is_local;
- char *ippfind_argv[100], /* Arguments for ippfind */
+ char *ippfind_argv[100], // Arguments for ippfind
*ptr_to_port = NULL,
*reg_type,
- *resolved_uri = NULL, /* Buffer for resolved URI */
+ *resolved_uri = NULL, // Buffer for resolved URI
*resource_field = NULL,
*service_hostname = NULL,
- /* URI components... */
+ // URI components...
scheme[32],
userpass[256],
hostname[1024],
resource[1024],
- *buffer = NULL, /* Copy buffer */
- *ptr; /* Pointer into string */;
- cups_file_t *fp; /* Post-processing input file */
- int status; /* Status of GET request */
+ *buffer = NULL, // Copy buffer
+ *ptr; // Pointer into string;
+ cups_file_t *fp; // Post-processing input file
+ int status; // Status of GET request
status = httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
userpass, sizeof(userpass),
hostname, sizeof(hostname), &port, resource,
sizeof(resource));
if (status < HTTP_URI_OK)
- /* Invalid URI */
+ // Invalid URI
goto error;
- /* URI is not DNS-SD-based, so do not resolve */
- if ((reg_type = strstr(hostname, "._tcp")) == NULL) {
- return strdup(uri);
- }
+ // URI is not DNS-SD-based, so do not resolve
+ if ((reg_type = strstr(hostname, "._tcp")) == NULL)
+ return (strdup(uri));
- resolved_uri = (char *)malloc(CF_GET_PRINTER_ATTRIBUTES_MAX_URI_LEN * (sizeof(char)));
+ resolved_uri =
+ (char *)malloc(CF_GET_PRINTER_ATTRIBUTES_MAX_URI_LEN * (sizeof(char)));
if (resolved_uri == NULL)
goto error;
memset(resolved_uri, 0, CF_GET_PRINTER_ATTRIBUTES_MAX_URI_LEN);
i = 0;
ippfind_argv[i++] = "ippfind";
- ippfind_argv[i++] = reg_type; /* list IPP(S) entries */
- ippfind_argv[i++] = "-T"; /* DNS-SD poll timeout */
- ippfind_argv[i++] = "0"; /* Minimum time required */
- if (is_fax) {
+ ippfind_argv[i++] = reg_type; // list IPP(S) entries
+ ippfind_argv[i++] = "-T"; // DNS-SD poll timeout
+ ippfind_argv[i++] = "0"; // Minimum time required
+ if (is_fax)
+ {
ippfind_argv[i++] = "--txt";
ippfind_argv[i++] = "rfo";
}
ippfind_argv[i++] = "-N";
ippfind_argv[i++] = hostname;
ippfind_argv[i++] = "-x";
- ippfind_argv[i++] = "echo"; /* Output the needed data fields */
- ippfind_argv[i++] = "-en"; /* separated by tab characters */
+ ippfind_argv[i++] = "echo"; // Output the needed data fields
+ ippfind_argv[i++] = "-en"; // separated by tab characters
if(is_fax)
ippfind_argv[i++] = "\n{service_hostname}\t{txt_rfo}\t{service_port}\t";
else
ippfind_argv[i++] = "\n{service_hostname}\t{txt_rp}\t{service_port}\t";
ippfind_argv[i++] = ";";
- ippfind_argv[i++] = "--local"; /* Rest only if local service */
+ ippfind_argv[i++] = "--local"; // Rest only if local service
ippfind_argv[i++] = "-x";
- ippfind_argv[i++] = "echo"; /* Output an 'L' at the end of the */
- ippfind_argv[i++] = "-en"; /* line */
+ ippfind_argv[i++] = "echo"; // Output an 'L' at the end of the
+ ippfind_argv[i++] = "-en"; // line
ippfind_argv[i++] = "L";
ippfind_argv[i++] = ";";
ippfind_argv[i++] = NULL;
- /*
- * Create a pipe for passing the ippfind output to post-processing
- */
+ //
+ // Create a pipe for passing the ippfind output to post-processing
+ //
if (pipe(post_proc_pipe))
goto error;
- if ((ippfind_pid = fork()) == 0) {
- /*
- * Child comes here...
- */
+ if ((ippfind_pid = fork()) == 0)
+ {
+ //
+ // Child comes here...
+ //
dup2(post_proc_pipe[1], 1);
close(post_proc_pipe[0]);
exit(1);
}
- else if (ippfind_pid < 0) {
- /*
- * Unable to fork!
- */
+ else if (ippfind_pid < 0)
+ {
+ //
+ // Unable to fork!
+ //
goto error;
}
fp = cupsFileOpenFd(post_proc_pipe[0], "r");
- buffer = (char*)malloc(CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN * sizeof(char));
+ buffer =
+ (char*)malloc(CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN * sizeof(char));
if (buffer == NULL)
goto error;
memset(buffer, 0, CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN);
- while ((bytes = cupsFileGetLine(fp, buffer, CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN)) > 0) {
- /* Mark all the fields of the output of ippfind */
+ while ((bytes =
+ cupsFileGetLine(fp, buffer,
+ CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN)) > 0)
+ {
+ // Mark all the fields of the output of ippfind
ptr = buffer;
- /* ignore new lines */
+ // ignore new lines
if (bytes < 3)
goto read_error;
- /* First, build the DNS-SD-service-name-based URI ... */
+ // First, build the DNS-SD-service-name-based URI ...
while (ptr && !isalnum(*ptr & 255)) ptr ++;
service_hostname = ptr;
- ptr = memchr(ptr, '\t', CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer));
+ ptr = memchr(ptr, '\t',
+ CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer));
if (!ptr) goto read_error;
*ptr = '\0';
ptr ++;
resource_field = ptr;
- ptr = memchr(ptr, '\t', CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer));
+ ptr = memchr(ptr, '\t',
+ CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer));
if (!ptr) goto read_error;
*ptr = '\0';
ptr ++;
ptr_to_port = ptr;
- ptr = memchr(ptr, '\t', CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer));
+ ptr = memchr(ptr, '\t',
+ CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer));
if (!ptr) goto read_error;
*ptr = '\0';
ptr ++;
- /* Do we have a local service so that we have to set the host name to
- "localhost"? */
+ // Do we have a local service so that we have to set the host name to
+ // "localhost"?
is_local = (*ptr == 'L');
ptr = strchr(reg_type, '.');
resource_field);
if (is_fax)
- output_of_fax_uri = 1; /* fax-uri requested from fax-capable device */
+ output_of_fax_uri = 1; // fax-uri requested from fax-capable device
read_error:
memset(buffer, 0, CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN);
if (buffer != NULL)
free(buffer);
- /*
- * Wait for the child processes to exit...
- */
+ //
+ // Wait for the child processes to exit...
+ //
wait_children = 1;
- while (wait_children > 0) {
- /*
- * Wait until we get a valid process ID or the job is canceled...
- */
+ while (wait_children > 0)
+ {
+ //
+ // Wait until we get a valid process ID or the job is canceled...
+ //
- while ((wait_pid = wait(&wait_status)) < 0 && errno == EINTR) {
- }
+ while ((wait_pid = wait(&wait_status)) < 0 && errno == EINTR) {};
if (wait_pid < 0)
break;
wait_children --;
- /*
- * Report child status...
- */
+ //
+ // Report child status...
+ //
- if (wait_status) {
- if (WIFEXITED(wait_status)) {
+ if (wait_status)
+ {
+ if (WIFEXITED(wait_status))
+ {
exit_status = WEXITSTATUS(wait_status);
if (wait_pid == ippfind_pid && exit_status <= 2)
exit_status = 0;
- } else if (WTERMSIG(wait_status) == SIGTERM) {
- } else {
+ }
+ else if (WTERMSIG(wait_status) == SIGTERM)
+ {
+ // All OK, no error
+ }
+ else
+ {
exit_status = WTERMSIG(wait_status);
}
}
return (resolved_uri);
- /*
- * Exit...
- */
+ //
+ // Exit...
+ //
error:
if (resolved_uri != NULL)
}
-const char* /* O - Attribute value as string */
-cfIPPAttrEnumValForPrinter(ipp_t *printer_attrs, /* I - Printer attributes, same
- as to respond
- get-printer-attributes,
- or NULL to not consider */
- ipp_t *job_attrs, /* I - Job attributes */
- const char *attr_name)/* I - Attribute name */
+const char* // O - Attribute value as string
+cfIPPAttrEnumValForPrinter(ipp_t *printer_attrs, // I - Printer attributes, same
+ // as to respond
+ // get-printer-attributes,
+ // or NULL to not consider
+ ipp_t *job_attrs, // I - Job attributes
+ const char *attr_name)// I - Attribute name
{
ipp_attribute_t *attr;
char printer_attr_name[256];
if ((printer_attrs == NULL && job_attrs == NULL) || attr_name == NULL)
return NULL;
- /* Check whether job got supplied the named attribute and read out its value
- as string */
+ // Check whether job got supplied the named attribute and read out its value
+ // as string
if (job_attrs == NULL ||
(attr = ippFindAttribute(job_attrs, attr_name, IPP_TAG_ZERO)) == NULL)
res = NULL;
else
res = ippGetString(attr, 0, NULL);
- /* Check the printer properties if supplied to see whether the job attribute
- value is valid or if the job attribute was not supplied. Use printer
- default value of job attribute is invalid or not supplied
- If no printer attributes are supplied (NULL), simply accept the job
- attribute value */
+ // Check the printer properties if supplied to see whether the job attribute
+ // value is valid or if the job attribute was not supplied. Use printer
+ // default value of job attribute is invalid or not supplied
+ // If no printer attributes are supplied (NULL), simply accept the job
+ // attribute value
if (printer_attrs)
{
if (res && res[0])
{
- /* Check whether value is valid according to printer attributes */
+ // Check whether value is valid according to printer attributes
snprintf(printer_attr_name, sizeof(printer_attr_name) - 1,
"%s-supported", attr_name);
if ((attr = ippFindAttribute(printer_attrs, printer_attr_name,
- IPP_TAG_ZERO)) != NULL) {
+ IPP_TAG_ZERO)) != NULL)
+ {
for (i = 0; i < ippGetCount(attr); i ++)
if (strcasecmp(res, ippGetString(attr, i, NULL)) == 0)
- break; /* Job attribute value is valid */
+ break; // Job attribute value is valid
if (i == ippGetCount(attr))
- res = NULL; /* Job attribute value is not valid */
+ res = NULL; // Job attribute value is not valid
}
}
if (!res || !res[0])
{
- /* Use default value from printer attributes */
+ // Use default value from printer attributes
snprintf(printer_attr_name, sizeof(printer_attr_name) - 1,
"%s-default", attr_name);
if ((attr = ippFindAttribute(printer_attrs, printer_attr_name,
}
-int /* O - 1: Success; 0: Error */
-cfIPPAttrIntValForPrinter(ipp_t *printer_attrs, /* I - Printer attributes, same
- as to respond
- get-printer-attributes,
- or NULL to not consider */
- ipp_t *job_attrs, /* I - Job attributes */
- const char *attr_name,/* I - Attribute name */
- int *value) /* O - Attribute value as
- integer */
+int // O - 1: Success; 0: Error
+cfIPPAttrIntValForPrinter(ipp_t *printer_attrs, // I - Printer attributes, same
+ // as to respond
+ // get-printer-attributes,
+ // or NULL to not consider
+ ipp_t *job_attrs, // I - Job attributes
+ const char *attr_name,// I - Attribute name
+ int *value) // O - Attribute value as
+ // integer
{
ipp_attribute_t *attr;
char printer_attr_name[256];
int retval, val, min, max;
if ((printer_attrs == NULL && job_attrs == NULL) || attr_name == NULL)
- return 0;
+ return (0);
- /* Check whether job got supplied the named attribute and read out its value
- as integer */
+ // Check whether job got supplied the named attribute and read out its value
+ // as integer
if (job_attrs == NULL ||
(attr = ippFindAttribute(job_attrs, attr_name, IPP_TAG_ZERO)) == NULL)
retval = 0;
- else {
+ else
+ {
retval = 1;
val = ippGetInteger(attr, 0);
}
- /* Check the printer properties if supplied to see whether the job attribute
- value is valid or if the job attribute was not supplied. Use printer
- default value of job attribute is invalid or not supplied
- If no printer attributes are supplied (NULL), simply accept the job
- attribute value */
- if (printer_attrs) {
- if (retval == 1) {
- /* Check whether value is valid according to printer attributes */
+ // Check the printer properties if supplied to see whether the job attribute
+ // value is valid or if the job attribute was not supplied. Use printer
+ // default value of job attribute is invalid or not supplied
+ // If no printer attributes are supplied (NULL), simply accept the job
+ // attribute value
+ if (printer_attrs)
+ {
+ if (retval == 1)
+ {
+ // Check whether value is valid according to printer attributes
snprintf(printer_attr_name, sizeof(printer_attr_name) - 1,
"%s-supported", attr_name);
if ((attr = ippFindAttribute(printer_attrs, printer_attr_name,
- IPP_TAG_RANGE)) != NULL) {
+ IPP_TAG_RANGE)) != NULL)
+ {
min = ippGetRange(attr, 0, &max);
if (val < min || val > max)
- retval = 0; /* Job attribute value out of range */
+ retval = 0; // Job attribute value out of range
}
}
if (retval == 0) {
- /* Use default value from printer attributes */
+ // Use default value from printer attributes
snprintf(printer_attr_name, sizeof(printer_attr_name) - 1,
"%s-default", attr_name);
if ((attr = ippFindAttribute(printer_attrs, printer_attr_name,
if (retval == 1)
*value = val;
- return retval;
+ return (retval);
}
-int /* O - 1: Success; 0: Error */
-cfIPPAttrResolutionForPrinter(ipp_t *printer_attrs,/* I - Printer attributes */
- ipp_t *job_attrs, /* I - Job attributes */
- const char *attr_name,/* I - Attribute name */
- int *xres, /* O - X resolution (dpi) */
- int *yres) /* O - Y resolution (dpi) */
-
+int // O - 1: Success; 0: Error
+cfIPPAttrResolutionForPrinter(ipp_t *printer_attrs,// I - Printer attributes
+ ipp_t *job_attrs, // I - Job attributes
+ const char *attr_name,// I - Attribute name
+ int *xres, // O - X resolution (dpi)
+ int *yres) // O - Y resolution (dpi)
{
int i;
ipp_attribute_t *attr;
ipp_res_t units;
if ((printer_attrs == NULL && job_attrs == NULL))
- return 0;
+ return (0);
if (attr_name == NULL)
attr_name = "printer-resolution";
- /* Check whether job got supplied the named attribute and read out its value
- as integer */
+ // Check whether job got supplied the named attribute and read out its value
+ // as integer
if (job_attrs == NULL ||
(attr = ippFindAttribute(job_attrs, attr_name, IPP_TAG_ZERO)) == NULL)
retval = 0;
x = ippGetResolution(attr, 0, &y, &units);
if (units == IPP_RES_PER_CM)
{
- /* Get resolutions in dpi */
+ // Get resolutions in dpi
x = (int)((float)x * 2.54);
y = (int)((float)y * 2.54);
}
}
- /* Check the printer properties if supplied to see whether the job attribute
- value is valid or if the job attribute was not supplied. Use printer
- default value of job attribute is invalid or not supplied
- If no printer attributes are supplied (NULL), simply accept the job
- attribute value */
- if (printer_attrs) {
- if (retval == 1) {
- /* Check whether value is valid according to printer attributes */
+ // Check the printer properties if supplied to see whether the job attribute
+ // value is valid or if the job attribute was not supplied. Use printer
+ // default value of job attribute is invalid or not supplied
+ // If no printer attributes are supplied (NULL), simply accept the job
+ // attribute value
+ if (printer_attrs)
+ {
+ if (retval == 1)
+ {
+ // Check whether value is valid according to printer attributes
snprintf(printer_attr_name, sizeof(printer_attr_name) - 1,
"%s-supported", attr_name);
if ((attr = ippFindAttribute(printer_attrs, printer_attr_name,
sx = ippGetResolution(attr, i, &sy, &su);
if (su == IPP_RES_PER_CM)
{
- /* Get resolutions in dpi */
+ // Get resolutions in dpi
sx = (int)((float)sx * 2.54);
sy = (int)((float)sy * 2.54);
}
if ((x - sx) * (x - sx) < 10 &&
(y - sy) * (y - sy) < 10)
- break; /* Job attribute value is valid */
+ break; // Job attribute value is valid
}
if (i == ippGetCount(attr))
- retval = 0; /* Job attribute value is not valid */
+ retval = 0; // Job attribute value is not valid
}
}
- if (retval == 0) {
- /* Use default value from printer attributes */
+ if (retval == 0)
+ {
+ // Use default value from printer attributes
snprintf(printer_attr_name, sizeof(printer_attr_name) - 1,
"%s-default", attr_name);
if ((attr = ippFindAttribute(printer_attrs, printer_attr_name,
- IPP_TAG_ZERO)) != NULL) {
+ IPP_TAG_ZERO)) != NULL)
+ {
retval = 1;
x = ippGetResolution(attr, 0, &y, &units);
if (units == IPP_RES_PER_CM)
{
- /* Get resolutions in dpi */
+ // Get resolutions in dpi
x = (int)((float)x * 2.54);
y = (int)((float)y * 2.54);
}
#ifndef HAVE_STRLCPY
-/*
- * 'strlcpy()' - Safely copy two strings.
- */
-
-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 */
+//
+// 'strlcpy()' - Safely copy two strings.
+//
+
+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
{
- size_t srclen; /* Length of source string */
+ size_t srclen; // Length of source string
- /*
- * Figure out how much room is needed...
- */
+ //
+ // Figure out how much room is needed...
+ //
size --;
srclen = strlen(src);
- /*
- * Copy the appropriate amount...
- */
+ //
+ // Copy the appropriate amount...
+ //
if (srclen > size)
srclen = size;
return (srclen);
}
-#endif /* !HAVE_STRLCPY */
+#endif // !HAVE_STRLCPY
-/*
- * 'cfStrFormatd()' - Format a floating-point number.
- */
+//
+// 'cfStrFormatd()' - Format a floating-point number.
+//
-char * /* O - Pointer to end of string */
-cfStrFormatd(char *buf, /* I - String */
- char *bufend, /* I - End of string buffer */
- double number, /* I - Number to format */
- struct lconv *loc) /* I - Locale data */
+char * // O - Pointer to end of string
+cfStrFormatd(char *buf, // I - String
+ char *bufend, // I - End of string buffer
+ double number, // I - Number to format
+ struct lconv *loc) // I - Locale data
{
- char *bufptr, /* Pointer into buffer */
- temp[1024], /* Temporary string */
- *tempdec, /* Pointer to decimal point */
- *tempptr; /* Pointer into temporary string */
- const char *dec; /* Decimal point */
- int declen; /* Length of decimal point */
+ char *bufptr, // Pointer into buffer
+ temp[1024], // Temporary string
+ *tempdec, // Pointer to decimal point
+ *tempptr; // Pointer into temporary string
+ const char *dec; // Decimal point
+ int declen; // Length of decimal point
- /*
- * Format the number using the "%.12f" format and then eliminate
- * unnecessary trailing 0's.
- */
+ //
+ // Format the number using the "%.12f" format and then eliminate
+ // unnecessary trailing 0's.
+ //
snprintf(temp, sizeof(temp), "%.12f", number);
for (tempptr = temp + strlen(temp) - 1;
tempptr > temp && *tempptr == '0';
*tempptr-- = '\0');
- /*
- * Next, find the decimal point...
- */
+ //
+ // Next, find the decimal point...
+ //
if (loc && loc->decimal_point) {
dec = loc->decimal_point;
else
tempdec = strstr(temp, dec);
- /*
- * Copy everything up to the decimal point...
- */
+ //
+ // Copy everything up to the decimal point...
+ //
if (tempdec) {
for (tempptr = temp, bufptr = buf;
cf_res_t *res_b = (cf_res_t *)resolution_b;
int i, a, b;
- /* Compare the pixels per square inch */
+ // Compare the pixels per square inch
a = res_a->x * res_a->y;
b = res_b->x * res_b->y;
i = (a > b) - (a < b);
- if (i) return i;
+ if (i) return (i);
- /* Compare how much the pixel shape deviates from a square, the
- more, the worse */
+ // Compare how much the pixel shape deviates from a square, the
+ // more, the worse
a = 100 * res_a->y / res_a->x;
if (a > 100) a = 10000 / a;
b = 100 * res_b->y / res_b->x;
if (b > 100) b = 10000 / b;
- return (a > b) - (a < b);
+ return ((a > b) - (a < b));
}
void *
cfCopyResolution(void *resolution,
- void *user_data)
+ void *user_data)
{
cf_res_t *res = (cf_res_t *)resolution;
cf_res_t *copy;
copy = (cf_res_t *)calloc(1, sizeof(cf_res_t));
- if (copy) {
+ if (copy)
+ {
copy->x = res->x;
copy->y = res->y;
}
void
cfFreeResolution(void *resolution,
- void *user_data)
+ void *user_data)
{
cf_res_t *res = (cf_res_t *)resolution;
cups_array_t *
cfNewResolutionArray()
{
- return cupsArrayNew3(cfCompareResolutions, NULL, NULL, 0,
- cfCopyResolution, cfFreeResolution);
+ return (cupsArrayNew3(cfCompareResolutions, NULL, NULL, 0,
+ cfCopyResolution, cfFreeResolution));
}
cf_res_t *
int y)
{
cf_res_t *res = (cf_res_t *)calloc(1, sizeof(cf_res_t));
- if (res) {
+ if (res)
+ {
res->x = x;
res->y = y;
}
- return res;
+ return (res);
}
-/* Read a single resolution from an IPP attribute, take care of
- obviously wrong entries (printer firmware bugs), ignoring
- resolutions of less than 60 dpi in at least one dimension and
- fixing Brother's "600x2dpi" resolutions. */
+// Read a single resolution from an IPP attribute, take care of
+// obviously wrong entries (printer firmware bugs), ignoring
+// resolutions of less than 60 dpi in at least one dimension and
+// fixing Brother's "600x2dpi" resolutions.
cf_res_t *
cfIPPResToResolution(ipp_attribute_t *attr,
int index)
int x = 0, y = 0;
ipp_res_t units;
- if (attr) {
+ if (attr)
+ {
ipp_tag_t tag = ippGetValueTag(attr);
int count = ippGetCount(attr);
- if (tag == IPP_TAG_RESOLUTION && index < count) {
+ if (tag == IPP_TAG_RESOLUTION && index < count)
+ {
x = ippGetResolution(attr, index, &y, &units);
if (units == IPP_RES_PER_CM)
{
x = (int)(x * 2.54);
y = (int)(y * 2.54);
}
- if (y == 2) y = x; /* Brother quirk ("600x2dpi") */
+ if (y == 2) y = x; // Brother quirk ("600x2dpi")
if (x >= 60 && y >= 60)
res = cfNewResolution(x, y);
}
}
- return res;
+ return (res);
}
cups_array_t *
cf_res_t *res;
int i;
- if (attr) {
+ if (attr)
+ {
ipp_tag_t tag = ippGetValueTag(attr);
int count = ippGetCount(attr);
- if (tag == IPP_TAG_RESOLUTION && count > 0) {
+ if (tag == IPP_TAG_RESOLUTION && count > 0)
+ {
res_array = cfNewResolutionArray();
- if (res_array) {
+ if (res_array)
+ {
for (i = 0; i < count; i ++)
- if ((res = cfIPPResToResolution(attr, i)) != NULL) {
+ if ((res = cfIPPResToResolution(attr, i)) != NULL)
+ {
if (cupsArrayFind(res_array, res) == NULL)
cupsArrayAdd(res_array, res);
cfFreeResolution(res, NULL);
}
}
- if (cupsArrayCount(res_array) == 0) {
+ if (cupsArrayCount(res_array) == 0)
+ {
cupsArrayDelete(res_array);
res_array = NULL;
}
}
}
- return res_array;
+ return (res_array);
}
-/* Build up an array of common resolutions and most desirable default
- resolution from multiple arrays of resolutions with an optional
- default resolution.
- Call this function with each resolution array you find as "new", and
- in "current" an array of the common resolutions will be built up.
- You do not need to create an empty array for "current" before
- starting. Initialize it with NULL.
- "current_default" holds the default resolution of the array "current".
- It will get replaced by "new_default" if "current_default" is either
- NULL or a resolution which is not in "current" any more.
- "new" and "new_default" will be deleted/freed and set to NULL after
- each, successful or unsuccssful operation.
- Note that when calling this function the addresses of the pointers
- to the resolution arrays and default resolutions have to be given
- (call by reference) as all will get modified by the function. */
-
-int /* 1 on success, 0 on failure */
+// Build up an array of common resolutions and most desirable default
+// resolution from multiple arrays of resolutions with an optional
+// default resolution.
+// Call this function with each resolution array you find as "new", and
+// in "current" an array of the common resolutions will be built up.
+// You do not need to create an empty array for "current" before
+// starting. Initialize it with NULL.
+// "current_default" holds the default resolution of the array "current".
+// It will get replaced by "new_default" if "current_default" is either
+// NULL or a resolution which is not in "current" any more.
+// "new" and "new_default" will be deleted/freed and set to NULL after
+// each, successful or unsuccssful operation.
+// Note that when calling this function the addresses of the pointers
+// to the resolution arrays and default resolutions have to be given
+// (call by reference) as all will get modified by the function.
+
+int // 1 on success, 0 on failure
cfJoinResolutionArrays(cups_array_t **current,
cups_array_t **new_arr,
cf_res_t **current_default,
int retval;
if (current == NULL || new_arr == NULL || *new_arr == NULL ||
- cupsArrayCount(*new_arr) == 0) {
+ cupsArrayCount(*new_arr) == 0)
+ {
retval = 0;
goto finish;
}
- if (*current == NULL) {
- /* We are adding the very first resolution array, simply make it
- our common resolutions array */
+ if (*current == NULL)
+ {
+ // We are adding the very first resolution array, simply make it
+ // our common resolutions array
*current = *new_arr;
- if (current_default) {
+ if (current_default)
+ {
if (*current_default)
free(*current_default);
*current_default = (new_default ? *new_default : NULL);
}
return 1;
- } else if (cupsArrayCount(*current) == 0) {
+ }
+ else if (cupsArrayCount(*current) == 0)
+ {
retval = 1;
goto finish;
}
- /* Dry run: Check whether the two arrays have at least one resolution
- in common, if not, do not touch the original array */
+ // Dry run: Check whether the two arrays have at least one resolution
+ // in common, if not, do not touch the original array
for (res = cupsArrayFirst(*current);
res; res = cupsArrayNext(*current))
if (cupsArrayFind(*new_arr, res))
break;
- if (res) {
- /* Reduce the original array to the resolutions which are in both
- the original and the new array, at least one resolution will
- remain. */
+ if (res)
+ {
+ // Reduce the original array to the resolutions which are in both
+ // the original and the new array, at least one resolution will
+ // remain.
for (res = cupsArrayFirst(*current);
res; res = cupsArrayNext(*current))
if (!cupsArrayFind(*new_arr, res))
cupsArrayRemove(*current, res);
- if (current_default) {
- /* Replace the current default by the new one if the current default
- is not in the array any more or if it is NULL. If the new default
- is not in the list or NULL in such a case, set the current default
- to NULL */
- if (*current_default && !cupsArrayFind(*current, *current_default)) {
+ if (current_default)
+ {
+ // Replace the current default by the new one if the current default
+ // is not in the array any more or if it is NULL. If the new default
+ // is not in the list or NULL in such a case, set the current default
+ // to NULL
+ if (*current_default && !cupsArrayFind(*current, *current_default))
+ {
free(*current_default);
*current_default = NULL;
}
retval = 0;
finish:
- if (new_arr && *new_arr) {
+ if (new_arr && *new_arr)
+ {
cupsArrayDelete(*new_arr);
*new_arr = NULL;
}
- if (new_default && *new_default) {
+ if (new_default && *new_default)
+ {
free(*new_default);
*new_default = NULL;
}
- return retval;
+
+ return (retval);
}
-/*
- * 'pwg_compare_sizes()' - Compare two media sizes...
- */
+//
+// 'pwg_compare_sizes()' - Compare two media sizes...
+//
-static int /* O - Result of comparison */
-pwg_compare_sizes(cups_size_t *a, /* I - First media size */
- cups_size_t *b) /* I - Second media size */
+static int // O - Result of comparison
+pwg_compare_sizes(cups_size_t *a, // I - First media size
+ cups_size_t *b) // I - Second media size
{
return (strcmp(a->media, b->media));
}
-/*
- * 'pwg_copy_size()' - Copy a media size.
- */
+//
+// 'pwg_copy_size()' - Copy a media size.
+//
-static cups_size_t * /* O - New media size */
-pwg_copy_size(cups_size_t *size) /* I - Media size to copy */
+static cups_size_t * // O - New media size
+pwg_copy_size(cups_size_t *size) // I - Media size to copy
{
cups_size_t *newsize = (cups_size_t *)calloc(1, sizeof(cups_size_t));
- /* New media size */
+ // New media size
if (newsize)
memcpy(newsize, size, sizeof(cups_size_t));
}
-int /* O - 1: Requested page size supported
- 2: Requested page size supported
- when rotated by 90 degrees
- 0: No page size requested
- -1: Requested size unsupported */
-cfGetPageDimensions(ipp_t *printer_attrs, /* I - Printer attributes */
- ipp_t *job_attrs, /* I - Job attributes */
- int num_options, /* I - Number of options */
- cups_option_t *options, /* I - Options */
- cups_page_header2_t *header, /* I - Raster page header */
- int transverse_fit, /* I - Accept transverse fit? */
- float *width, /* O - Width (in pt, 1/72 inches) */
- float *height, /* O - Height */
- float *left, /* O - Left margin */
- float *bottom, /* O - Bottom margin */
- float *right, /* O - Right margin */
- float *top, /* O - Top margin */
- char *name, /* O - Page size name */
- ipp_t **media_col_entry)/* O - media-col-database record of
- match */
+int // O - 1: Requested page size supported
+ // 2: Requested page size supported
+ // when rotated by 90 degrees
+ // 0: No page size requested
+ // -1: Requested size unsupported
+cfGetPageDimensions(ipp_t *printer_attrs, // I - Printer attributes
+ ipp_t *job_attrs, // I - Job attributes
+ int num_options, // I - Number of options
+ cups_option_t *options, // I - Options
+ cups_page_header2_t *header, // I - Raster page header
+ int transverse_fit, // I - Accept transverse fit?
+ float *width, // O - Width (in pt, 1/72 inches)
+ float *height, // O - Height
+ float *left, // O - Left margin
+ float *bottom, // O - Bottom margin
+ float *right, // O - Right margin
+ float *top, // O - Top margin
+ char *name, // O - Page size name
+ ipp_t **media_col_entry)// O - media-col-database record of
+ // match
{
int i;
const char *attr_name;
char size_name_buf[IPP_MAX_NAME + 1];
int size_requested = 0;
- const char * const media_size_attr_names[] = {
+ const char * const media_size_attr_names[] =
+ {
"Jmedia-col",
"Jmedia-size",
"Jmedia",
"JPageSize",
"JMediaSize",
- "J", /* A raster header with media dimensions */
+ "J", // A raster header with media dimensions
"jmedia-col",
"jmedia-size",
"jmedia",
"jPageSize",
"jMediaSize",
- "j", /* A raster header with media dimensions */
+ "j", // A raster header with media dimensions
"Dmedia-col-default",
"Dmedia-default",
};
if (media_col_entry)
*media_col_entry = NULL;
- /*
- * Media from job_attrs and options, defaults from printer_attrs...
- */
+ //
+ // Media from job_attrs and options, defaults from printer_attrs...
+ //
- /* Go through all job attributes and options which could contain the
- page size, afterwards go through the page size defaults in the
- printer attributes */
+ // Go through all job attributes and options which could contain the
+ // page size, afterwards go through the page size defaults in the
+ // printer attributes
for (i = 0;
i < sizeof(media_size_attr_names) / sizeof(media_size_attr_names[0]);
i ++)
{
- ipp_attribute_t *attr = NULL; /* Job attribute */
- char valstr[8192]; /* Attribute value string */
- const char *value = NULL; /* Option value */
- const char *name_ptr = NULL; /* Pointer to page size name */
- int num_media_col = 0; /* Number of media-col values */
- cups_option_t *media_col = NULL; /* media-col values */
+ ipp_attribute_t *attr = NULL; // Job attribute
+ char valstr[8192]; // Attribute value string
+ const char *value = NULL; // Option value
+ const char *name_ptr = NULL; // Pointer to page size name
+ int num_media_col = 0; // Number of media-col values
+ cups_option_t *media_col = NULL; // media-col values
int ipp_width = 0,
ipp_height = 0,
ipp_left = -1,
attr_name = media_size_attr_names[i];
if (*attr_name == 'J' ||
- (transverse_fit && *attr_name == 'j')) /* Job attribute/option */
+ (transverse_fit && *attr_name == 'j')) // Job attribute/option
{
if (*(attr_name + 1) == '\0')
{
if (header)
{
- /* Raster header */
+ // Raster header
if (header->cupsPageSize[0] > 0.0)
ipp_width = (int)(header->cupsPageSize[0] * 2540.0 / 72.0);
else if (header->PageSize[0] > 0)
else if ((attr = ippFindAttribute(job_attrs, attr_name + 1,
IPP_TAG_ZERO)) != NULL)
{
- /* String from IPP attribute */
+ // String from IPP attribute
ippAttributeString(attr, valstr, sizeof(valstr));
value = valstr;
}
options)) == NULL)
continue;
}
- else if (*attr_name == 'D') /* Printer default */
+ else if (*attr_name == 'D') // Printer default
{
if (*(attr_name + 1))
{
if ((attr = ippFindAttribute(printer_attrs, attr_name + 1,
IPP_TAG_ZERO)) != NULL)
{
- /* String from IPP attribute */
+ // String from IPP attribute
ippAttributeString(attr, valstr, sizeof(valstr));
value = valstr;
}
{
if (*value == '{')
{
- /*
- * String is a dictionary -> "media-col" value...
- */
+ //
+ // String is a dictionary -> "media-col" value...
+ //
num_media_col = cupsParseOptions(value, 0, &media_col);
- /* Actual size in dictionary? */
+ // Actual size in dictionary?
if ((value = cupsGetOption("media-size", num_media_col, media_col))
!= NULL)
{
- int num_media_size; /* Number of media-size values */
- cups_option_t *media_size; /* media-size values */
- const char *x_dimension, /* x-dimension value */
- *y_dimension; /* y-dimension value */
+ int num_media_size; // Number of media-size values
+ cups_option_t *media_size; // media-size values
+ const char *x_dimension, // x-dimension value
+ *y_dimension; // y-dimension value
num_media_size = cupsParseOptions(value, 0, &media_size);
cupsFreeOptions(num_media_size, media_size);
}
- /* Name in dictionary? Use only if actual dimensions are not supplied */
+ // Name in dictionary? Use only if actual dimensions are not supplied
if ((ipp_width <= 0 || ipp_height <= 0) &&
(name_ptr = cupsGetOption("media-size-name",
num_media_col, media_col)) == NULL)
continue;
}
- /* Grab margins from media-col */
+ // Grab margins from media-col
if ((value = cupsGetOption("media-left-margin",
num_media_col, media_col))
!= NULL)
}
else
{
- /*
- * String is not dictionary, check also if it contains commas (list
- * of media properties supplied via "media" CUPS option
- */
+ //
+ // String is not dictionary, check also if it contains commas (list
+ // of media properties supplied via "media" CUPS option
+ //
char *ptr;
name_ptr = value;
if (strchr(value, ','))
{
- /* Comma-separated list of media properties, supplied with "media"
- CUPS option */
+ // Comma-separated list of media properties, supplied with "media"
+ // CUPS option
if (value != valstr)
{
- /* Copy string for further manipulation */
+ // Copy string for further manipulation
strlcpy(valstr, value, sizeof(valstr));
value = valstr;
name_ptr = value;
ptr ++;
if (*ptr == ',' || *ptr == '\0')
{
- /* End of item name */
+ // End of item name
if (*ptr == ',')
{
*ptr = '\0';
ptr ++;
}
- /* Find PWG media entry for the name, if we find one, the name
- is actually a page size name */
+ // Find PWG media entry for the name, if we find one, the name
+ // is actually a page size name
if (pwgMediaForPWG(name_ptr) ||
pwgMediaForPPD(name_ptr) ||
pwgMediaForLegacy(name_ptr))
- /* This is a page size name */
+ // This is a page size name
break;
else if (*ptr)
- /* Next item */
+ // Next item
name_ptr = ptr;
else
- /* No further item */
+ // No further item
name_ptr = NULL;
}
}
}
}
- /* Get name from media */
+ // Get name from media
if (name_ptr)
{
if (ipp_left == 0 && ipp_bottom == 0 &&
strlcpy(name, name_ptr, IPP_MAX_NAME);
}
- /* Landscape/Transverse fit */
- if (*attr_name == 'j') /* Only job attributes/options */
+ // Landscape/Transverse fit
+ if (*attr_name == 'j') // Only job attributes/options
{
int swap;
cupsFreeOptions(num_media_col, media_col);
- /* We have a valid request for a page size */
+ // We have a valid request for a page size
if (*attr_name == 'J' || *attr_name == 'j')
size_requested = 1;
- /* Validate collected information */
- /* If we have a size, we use the size as search term (name = "" then),
- if we have no size but a name, use the name, always pass in margins
- if available */
+ // Validate collected information
+ // If we have a size, we use the size as search term (name = "" then),
+ // if we have no size but a name, use the name, always pass in margins
+ // if available
cfGenerateSizes(printer_attrs, CF_GEN_SIZES_SEARCH, NULL, NULL,
&ipp_width, &ipp_height,
&ipp_left, &ipp_bottom, &ipp_right, &ipp_top,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, name,
media_col_entry);
- /* Return resulting numbers */
+ // Return resulting numbers
if (ipp_width > 0 && ipp_height > 0 &&
ipp_left >= 0 && ipp_bottom >= 0 &&
ipp_right >= 0 && ipp_top >= 0)
ipp_t **media_col_entry)
{
ipp_attribute_t *default_attr,
- *attr, /* xxx-supported */
- *x_dim, *y_dim, /* Media dimensions */
- *name; /* Media size name */
- ipp_t *media_col, /* Media collection */
- *media_size; /* Media size collection */
+ *attr, // xxx-supported
+ *x_dim, *y_dim, // Media dimensions
+ *name; // Media size name
+ ipp_t *media_col, // Media collection
+ *media_size; // Media size collection
int i, x = 0, y = 0, count = 0;
- pwg_media_t *pwg, *pwg_by_name; /* PWG media size */
+ pwg_media_t *pwg, *pwg_by_name; // PWG media size
int local_min_width, local_min_length,
local_max_width, local_max_length;
int local_left, local_right, local_bottom, local_top;
- ipp_attribute_t *margin; /* media-xxx-margin attribute */
+ ipp_attribute_t *margin; // media-xxx-margin attribute
const char *psname;
const char *entry_name;
char size_name_buf[IPP_MAX_NAME + 1] = "";
if (custom_left == NULL)
custom_left = &local_left;
if ((attr = ippFindAttribute(response, "media-left-margin-supported",
- IPP_TAG_INTEGER)) != NULL) {
- for (i = 1, *custom_left = ippGetInteger(attr, 0), count = ippGetCount(attr);
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ for (i = 1, *custom_left = ippGetInteger(attr, 0),
+ count = ippGetCount(attr);
i < count; i ++)
if (ippGetInteger(attr, i) < *custom_left)
*custom_left = ippGetInteger(attr, i);
if (custom_bottom == NULL)
custom_bottom = &local_bottom;
if ((attr = ippFindAttribute(response, "media-bottom-margin-supported",
- IPP_TAG_INTEGER)) != NULL) {
- for (i = 1, *custom_bottom = ippGetInteger(attr, 0), count = ippGetCount(attr);
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ for (i = 1, *custom_bottom = ippGetInteger(attr, 0),
+ count = ippGetCount(attr);
i < count; i ++)
if (ippGetInteger(attr, i) < *custom_bottom)
*custom_bottom = ippGetInteger(attr, i);
if (custom_right == NULL)
custom_right = &local_right;
if ((attr = ippFindAttribute(response, "media-right-margin-supported",
- IPP_TAG_INTEGER)) != NULL) {
- for (i = 1, *custom_right = ippGetInteger(attr, 0), count = ippGetCount(attr);
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ for (i = 1, *custom_right = ippGetInteger(attr, 0),
+ count = ippGetCount(attr);
i < count; i ++)
if (ippGetInteger(attr, i) < *custom_right)
*custom_right = ippGetInteger(attr, i);
if (custom_top == NULL)
custom_top = &local_top;
if ((attr = ippFindAttribute(response, "media-top-margin-supported",
- IPP_TAG_INTEGER)) != NULL) {
- for (i = 1, *custom_top = ippGetInteger(attr, 0), count = ippGetCount(attr);
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ for (i = 1, *custom_top = ippGetInteger(attr, 0),
+ count = ippGetCount(attr);
i < count; i ++)
if (ippGetInteger(attr, i) < *custom_top)
*custom_top = ippGetInteger(attr, i);
defattr = &default_attr;
if (defattr &&
(*defattr = ippFindAttribute(response, "media-col-default",
- IPP_TAG_BEGIN_COLLECTION)) != NULL) {
+ IPP_TAG_BEGIN_COLLECTION)) != NULL)
+ {
if (mode == CF_GEN_SIZES_DEFAULT &&
(attr = ippFindAttribute(ippGetCollection(*defattr, 0), "media-size",
- IPP_TAG_BEGIN_COLLECTION)) != NULL) {
+ IPP_TAG_BEGIN_COLLECTION)) != NULL)
+ {
media_size = ippGetCollection(attr, 0);
x_dim = ippFindAttribute(media_size, "x-dimension", IPP_TAG_INTEGER);
y_dim = ippFindAttribute(media_size, "y-dimension", IPP_TAG_INTEGER);
if (top)
*top = local_top;
- if (x_dim && y_dim) {
+ if (x_dim && y_dim)
+ {
x = ippGetInteger(x_dim, 0);
y = ippGetInteger(y_dim, 0);
if (x > 0 && y > 0 &&
pwgMediaForPWG(ippGetString(ippFindAttribute(response,
"media-default",
IPP_TAG_ZERO), 0,
- NULL))) != NULL) {
+ NULL))) != NULL)
+ {
psname = (pwg->ppd != NULL ? pwg->ppd : pwg->pwg);
strlcpy(size_name, psname, IPP_MAX_NAME);
- if (x <= 0 || y <= 0) {
+ if (x <= 0 || y <= 0)
+ {
x = pwg->width;
y = pwg->length;
}
if (mode == CF_GEN_SIZES_DEFAULT)
{
- /* Output the default page size dimensions, 0 if no valid size found */
+ // Output the default page size dimensions, 0 if no valid size found
if (!size_name[0])
strlcpy(size_name, "Unknown", IPP_MAX_NAME);
if (width)
}
else
{
- /* Find the dimensions for the page size name we got as search term */
+ // Find the dimensions for the page size name we got as search term
char *ptr;
int is_transverse = (strcasestr(size_name, ".Transverse") ? 1 : 0);
if (strcasestr(size_name, ".Fullbleed") ||
if ((search = pwgMediaForPWG(size_name_buf)) == NULL)
if ((search = pwgMediaForPPD(size_name_buf)) == NULL)
search = pwgMediaForLegacy(size_name_buf);
- if (search != NULL) {
- /* Set the appropriate dimensions */
+ if (search != NULL)
+ {
+ // Set the appropriate dimensions
if (is_transverse)
{
search_width = search->length;
}
else
{
- /* Set the dimensions if we search by dimensions */
+ // Set the dimensions if we search by dimensions
if (width)
search_width = *width;
if (length)
}
if (search_width <= 0 || search_length <= 0)
{
- /* No valid search dimensions, de-activate searching and set 0 as
- result */
+ // No valid search dimensions, de-activate searching and set 0 as
+ // result
mode = CF_GEN_SIZES_DEFAULT;
if (width)
*width = 0;
}
else
{
- /* Check whether we have margin info so that we can search for a
- size with similar/the same margins, otherwise set the margins
- -1 to pick the first entry from the list which fits the size
- dimensions (if there are variants of a size, the first entry
- is usually the standard size) */
+ // Check whether we have margin info so that we can search for a
+ // size with similar/the same margins, otherwise set the margins
+ // -1 to pick the first entry from the list which fits the size
+ // dimensions (if there are variants of a size, the first entry
+ // is usually the standard size)
if (left && *left >= 0)
search_left = *left;
else
(cups_afree_func_t)free);
if ((attr = ippFindAttribute(response, "media-col-database",
- IPP_TAG_BEGIN_COLLECTION)) != NULL) {
- for (i = 0, count = ippGetCount(attr); i < count; i ++) {
- cups_size_t temp, temp_by_name; /* Current size */
+ IPP_TAG_BEGIN_COLLECTION)) != NULL)
+ {
+ for (i = 0, count = ippGetCount(attr); i < count; i ++)
+ {
+ cups_size_t temp, temp_by_name; // Current size
media_col = ippGetCollection(attr, i);
media_size =
ippGetCollection(ippFindAttribute(media_col, "media-size",
IPP_TAG_BEGIN_COLLECTION), 0);
- /* These are the numeric paper dimensions explicitly mentioned
- in this media entry. if we were called in a retro-fitting
- setup via a ppdFilter...() wrapper filter function of libppd,
- these dimensions can deviate from the paper dimensions which
- the PWG-style page size name in the same entry suggests. In
- this case we match both sizes against the size requested for
- the job and consider the entry as matching if one of the two
- sizes matches. In this case the entry gets included in all
- entries which are selected by the closest fit of the margins.
-
- We do this as some PPD files (especially of HPLIP) contain
- page size entries which are variants of a standard size with
- the base name of a standard size (like "A4.Borderless", base
- name "A4") but different dimensions.
-
- Especially there are larger dimensions for borderless, for
- overspraying over the borders of the sheet so that there will
- be no faint white borders if the sheet is a little
- mis-aligned.
-
- So if such overspraying borderless size entry is present and
- has zero margins while the standard size entry has regular
- margins, this entry will get automatically selected if
- borderless printing (standard size name or dimensions plus
- zero margins) is selected.
- */
+
+ // These are the numeric paper dimensions explicitly mentioned
+ // in this media entry. if we were called in a retro-fitting
+ // setup via a ppdFilter...() wrapper filter function of libppd,
+ // these dimensions can deviate from the paper dimensions which
+ // the PWG-style page size name in the same entry suggests. In
+ // this case we match both sizes against the size requested for
+ // the job and consider the entry as matching if one of the two
+ // sizes matches. In this case the entry gets included in all
+ // entries which are selected by the closest fit of the margins.
+ //
+ // We do this as some PPD files (especially of HPLIP) contain
+ // page size entries which are variants of a standard size with
+ // the base name of a standard size (like "A4.Borderless", base
+ // name "A4") but different dimensions.
+ //
+ // Especially there are larger dimensions for borderless, for
+ // overspraying over the borders of the sheet so that there will
+ // be no faint white borders if the sheet is a little
+ // mis-aligned.
+ //
+ // So if such overspraying borderless size entry is present and
+ // has zero margins while the standard size entry has regular
+ // margins, this entry will get automatically selected if
+ // borderless printing (standard size name or dimensions plus
+ // zero margins) is selected.
+
x_dim = ippFindAttribute(media_size, "x-dimension", IPP_TAG_ZERO);
y_dim = ippFindAttribute(media_size, "y-dimension", IPP_TAG_ZERO);
// Move "if" for custom size parameters here
pwg_by_name = pwgMediaForPWG(entry_name);
}
- if (pwg || pwg_by_name) {
+ if (pwg || pwg_by_name)
+ {
if (!sizes && mode == CF_GEN_SIZES_DEFAULT)
continue;
borderless = 0;
}
- /* Check whether this size matches our search criteria */
+ // Check whether this size matches our search criteria
if (mode != CF_GEN_SIZES_DEFAULT &&
min_border_mismatch > 0 &&
search_width > 0 && search_length > 0 &&
- ((abs(search_width - temp_by_name.width) < 70 /* 2pt */ &&
- abs(search_length - temp_by_name.length) < 70) /* 2pt */ ||
- (abs(search_width - temp.width) < 70 /* 2pt */ &&
- abs(search_length - temp.length) < 70) /* 2pt */))
+ ((abs(search_width - temp_by_name.width) < 70 && // 2pt
+ abs(search_length - temp_by_name.length) < 70) || // 2pt
+ (abs(search_width - temp.width) < 70 && // 2pt
+ abs(search_length - temp.length) < 70))) // 2pt
{
- /* Found size with the correct dimensions */
+ // Found size with the correct dimensions
int match = 0;
if (mode == CF_GEN_SIZES_SEARCH_BORDERLESS_ONLY &&
borderless == 1)
{
- /* We search only for borderless sizes and have found a match */
+ // We search only for borderless sizes and have found a match
border_mismatch = 0;
min_border_mismatch = 0;
if (media_col_entry)
}
else if (mode == CF_GEN_SIZES_SEARCH)
{
- /* We search a size in general, borders are accepted. find the
- best match in terms of border size */
+ // We search a size in general, borders are accepted. find the
+ // best match in terms of border size
border_mismatch =
(long long)(search_left < 0 ? 1 :
(abs(search_left - temp.left) + 1)) *
}
}
- /* Add size to list */
+ // Add size to list
if (sizes && !cupsArrayFind(*sizes, &temp))
cupsArrayAdd(*sizes, &temp);
- } else if (ippGetValueTag(x_dim) == IPP_TAG_RANGE ||
- ippGetValueTag(y_dim) == IPP_TAG_RANGE) {
- /*
- * Custom size - record the min/max values...
- */
+ }
+ else if (ippGetValueTag(x_dim) == IPP_TAG_RANGE ||
+ ippGetValueTag(y_dim) == IPP_TAG_RANGE)
+ {
+ //
+ // Custom size - record the min/max values...
+ //
- int lower, upper; /* Range values */
+ int lower, upper; // Range values
if (ippGetValueTag(x_dim) == IPP_TAG_RANGE)
lower = ippGetRange(x_dim, 0, &upper);
}
if (min_border_mismatch < LLONG_MAX)
{
- /* If we have found a matching page size in the media-col-database
- we stop searching */
+ // If we have found a matching page size in the media-col-database
+ // we stop searching
min_border_mismatch = 0;
}
}
if ((attr = ippFindAttribute(response, "media-size-supported",
- IPP_TAG_BEGIN_COLLECTION)) != NULL) {
- for (i = 0, count = ippGetCount(attr); i < count; i ++) {
- cups_size_t temp; /* Current size */
+ IPP_TAG_BEGIN_COLLECTION)) != NULL)
+ {
+ for (i = 0, count = ippGetCount(attr); i < count; i ++)
+ {
+ cups_size_t temp; // Current size
media_size = ippGetCollection(attr, i);
x_dim = ippFindAttribute(media_size, "x-dimension", IPP_TAG_ZERO);
borderless = 0;
}
- /* Check whether this size matches our search criteria */
+ // Check whether this size matches our search criteria
if (mode != CF_GEN_SIZES_DEFAULT &&
min_border_mismatch > 0 &&
search_width > 0 && search_length > 0 &&
- abs(search_width - temp.width) < 70 /* 2pt */ &&
- abs(search_length - temp.length) < 70 /* 2pt */)
+ abs(search_width - temp.width) < 70 && // 2pt
+ abs(search_length - temp.length) < 70 ) // 2pt
{
- /* Found size with the correct dimensions */
+ // Found size with the correct dimensions
if (mode != CF_GEN_SIZES_SEARCH_BORDERLESS_ONLY ||
borderless == 1)
{
- /* We accept the entry just by the size dimensions as
- "media-size-supported" has no per-size margin info */
+ // We accept the entry just by the size dimensions as
+ // "media-size-supported" has no per-size margin info
if (width)
*width = temp.width;
if (length)
if (top)
*top = temp.top;
strlcpy(size_name, temp.media, IPP_MAX_NAME);
- /* Found it, stop searching */
+ // Found it, stop searching
min_border_mismatch = 0;
}
}
if (sizes && !cupsArrayFind(*sizes, &temp))
cupsArrayAdd(*sizes, &temp);
- } else if (ippGetValueTag(x_dim) == IPP_TAG_RANGE ||
- ippGetValueTag(y_dim) == IPP_TAG_RANGE) {
- /*
- * Custom size - record the min/max values...
- */
+ }
+ else if (ippGetValueTag(x_dim) == IPP_TAG_RANGE ||
+ ippGetValueTag(y_dim) == IPP_TAG_RANGE)
+ {
+ //
+ // Custom size - record the min/max values...
+ //
- int lower, upper; /* Range values */
+ int lower, upper; // Range values
if (ippGetValueTag(x_dim) == IPP_TAG_RANGE)
lower = ippGetRange(x_dim, 0, &upper);
}
}
if ((attr = ippFindAttribute(response, "media-supported", IPP_TAG_ZERO))
- != NULL) {
- for (i = 0, count = ippGetCount(attr); i < count; i ++) {
+ != NULL)
+ {
+ for (i = 0, count = ippGetCount(attr); i < count; i ++)
+ {
const char *pwg_size = ippGetString(attr, i, NULL);
- /* PWG size name */
- cups_size_t temp, *temp2; /* Current size, found size */
+ // PWG size name
+ cups_size_t temp, *temp2; // Current size, found size
- if ((pwg = pwgMediaForPWG(pwg_size)) != NULL) {
- if (strstr(pwg_size, "_max_") || strstr(pwg_size, "_max.")) {
+ if ((pwg = pwgMediaForPWG(pwg_size)) != NULL)
+ {
+ if (strstr(pwg_size, "_max_") || strstr(pwg_size, "_max."))
+ {
if (max_width && pwg->width > *max_width)
*max_width = pwg->width;
if (max_length && pwg->length > *max_length)
*max_length = pwg->length;
- } else if (strstr(pwg_size, "_min_") || strstr(pwg_size, "_min.")) {
+ }
+ else if (strstr(pwg_size, "_min_") || strstr(pwg_size, "_min."))
+ {
if (min_width && pwg->width < *min_width)
*min_width = pwg->width;
if (min_length && pwg->length < *min_length)
*min_length = pwg->length;
- } else {
+ }
+ else
+ {
if (!sizes && mode == CF_GEN_SIZES_DEFAULT)
continue;
else
strlcpy(temp.media, psname, sizeof(temp.media));
- /* Add the printer's original IPP name to an already found size */
+ // Add the printer's original IPP name to an already found size
if (sizes)
{
- if ((temp2 = cupsArrayFind(*sizes, &temp)) != NULL) {
+ if ((temp2 = cupsArrayFind(*sizes, &temp)) != NULL)
+ {
snprintf(temp2->media + strlen(temp2->media),
sizeof(temp2->media) - strlen(temp2->media),
" %s", pwg_size);
- /* Check if we have also a borderless version of the size and add
- the original IPP name also there */
+ // Check if we have also a borderless version of the size and add
+ // the original IPP name also there
snprintf(temp.media, sizeof(temp.media), "%s.Borderless", psname);
if ((temp2 = cupsArrayFind(*sizes, &temp)) != NULL)
snprintf(temp2->media + strlen(temp2->media),
*custom_left >= 0 && *custom_bottom >= 0 &&
*custom_right >= 0 && *custom_top >= 0)
{
- /* Do we have support for a custom page size and have valid size ranges for
- it? Check whether the size we are searching for can go as custom size */
- if (search_width >= *min_width - 70 /* 2pt */ &&
- search_width <= *max_width + 70 /* 2pt */ &&
- search_length >= *min_length - 70 /* 2pt */ &&
- search_length <= *max_length + 70 /* 2pt */)
+ // Do we have support for a custom page size and have valid size ranges for
+ // it? Check whether the size we are searching for can go as custom size
+ if (search_width >= *min_width - 70 && // 2pt
+ search_width <= *max_width + 70 && // 2pt
+ search_length >= *min_length - 70 && // 2pt
+ search_length <= *max_length + 70) // 2pt
{
if (width)
*width = (search_width < *min_width ? *min_width :
}
if (mode != CF_GEN_SIZES_DEFAULT && min_border_mismatch > 0)
{
- /* Size not found */
+ // Size not found
if (width) *width = 0;
if (length) *length = 0;
if (left) *left = -1;
- /***
- This file is part of cups-filters.
-
- This file is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- This file is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
- USA.
-***/
+//
+// IPP-related functions for libcupsfilters.
+//
+// This file is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of the
+// License, or (at your option) any later version.
+//
+// This file is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+// Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with avahi; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+// USA.
+//
#ifndef _CUPS_FILTERS_IPP_H_
# define _CUPS_FILTERS_IPP_H_
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
-/*
- * Include necessary headers...
- */
+//
+// Include necessary headers...
+//
#include <config.h>
#else
# include <unistd.h>
# include <fcntl.h>
-#endif /* WIN32 || __EMX__ */
+#endif // WIN32 || __EMX__
#include <cups/cups.h>
#include <cups/backend.h>
extern char cf_get_printer_attributes_log[CF_GET_PRINTER_ATTRIBUTES_LOGSIZE];
-/*
- * Types...
- */
+//
+// Types...
+//
-/* Enum of possible driverless options */
-enum cf_driverless_support_modes_e {
- CF_DRVLESS_CHECKERR, /* Unable to get get-printer-attributes response*/
- CF_DRVLESS_FULL, /* Standard IPP Everywhere support, works with
- 'everywhere' model */
- CF_DRVLESS_IPP11, /* Driverless support via IPP 1.1 request */
- CF_DRVLESS_INCOMPLETEIPP /* Driverless support without media-col-database
- attribute */
+// Enum of possible driverless options
+enum cf_driverless_support_modes_e
+{
+ CF_DRVLESS_CHECKERR, // Unable to get get-printer-attributes response*/
+ CF_DRVLESS_FULL, // Standard IPP Everywhere support, works with
+ // 'everywhere' model
+ CF_DRVLESS_IPP11, // Driverless support via IPP 1.1 request
+ CF_DRVLESS_INCOMPLETEIPP // Driverless support without media-col-database
+ // attribute
};
-/* Data structure for resolution (X x Y dpi) */
-typedef struct cf_res_s {
+// Data structure for resolution (X x Y dpi)
+typedef struct cf_res_s
+{
int x, y;
} cf_res_t;
-typedef enum cf_gen_sizes_mode_e {
+typedef enum cf_gen_sizes_mode_e
+{
CF_GEN_SIZES_DEFAULT = 0,
CF_GEN_SIZES_SEARCH,
CF_GEN_SIZES_SEARCH_BORDERLESS_ONLY
} cf_gen_sizes_mode_t;
-/*
- * Prototypes...
- */
+//
+// Prototypes...
+//
char *cfResolveURI(const char *raw_uri);
char *cfippfindBasedURIConverter(const char *uri ,int is_fax);
cups_array_t **new_arr,
cf_res_t **current_default,
cf_res_t **new_default);
+
int cfGetPageDimensions(ipp_t *printer_attrs,
ipp_t *job_attrs,
int num_options,
# ifdef __cplusplus
}
-# endif /* __cplusplus */
+# endif // __cplusplus
-#endif /* !_CUPS_FILTERS_IPP_H_ */
+#endif // !_CUPS_FILTERS_IPP_H_
-/*
- * Log functions header file for cups-filters.
- *
- * Copyright 2020 by Till Kamppeter.
- *
- * Distribution and use rights are outlined in the file "COPYING"
- * which should have been included with this file.
- */
+//
+// Log functions header file for cups-filters.
+//
+// Copyright 2020 by Till Kamppeter.
+//
+// Distribution and use rights are outlined in the file "COPYING"
+// which should have been included with this file.
+//
#ifndef _CUPS_FILTERS_LOG_H_
# define _CUPS_FILTERS_LOG_H_
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
-
-
-/*
- * Types...
- */
-
-typedef enum cf_loglevel_e { /* Log levels, same as PAPPL, similar
- to CUPS */
- CF_LOGLEVEL_UNSPEC = -1, /* Not specified */
- CF_LOGLEVEL_DEBUG, /* Debug message */
- CF_LOGLEVEL_INFO, /* Informational message */
- CF_LOGLEVEL_WARN, /* Warning message */
- CF_LOGLEVEL_ERROR, /* Error message */
- CF_LOGLEVEL_FATAL, /* Fatal message */
- CF_LOGLEVEL_CONTROL /* Control message */
+# endif // __cplusplus
+
+
+//
+// Types...
+//
+
+typedef enum cf_loglevel_e // Log levels, same as PAPPL, similar
+{ // to CUPS
+ CF_LOGLEVEL_UNSPEC = -1, // Not specified
+ CF_LOGLEVEL_DEBUG, // Debug message
+ CF_LOGLEVEL_INFO, // Informational message
+ CF_LOGLEVEL_WARN, // Warning message
+ CF_LOGLEVEL_ERROR, // Error message
+ CF_LOGLEVEL_FATAL, // Fatal message
+ CF_LOGLEVEL_CONTROL // Control message
} cf_loglevel_t;
typedef void (*cf_logfunc_t)(void *data, cf_loglevel_t level,
# ifdef __cplusplus
}
-# endif /* __cplusplus */
+# endif // __cplusplus
-#endif /* !_CUPS_FILTERS_LOG_H_ */
-
-/*
- * End
- */
+#endif // !_CUPS_FILTERS_LOG_H_
-/*
- * Lookup table routines for CUPS.
- *
- * Copyright 2007 by Apple Inc.
- * Copyright 1993-2005 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * 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:
- *
- * cfLutDelete() - Free the memory used by a lookup table.
- * cfLutNew() - Make a lookup table from a list of pixel values.
- */
-
-/*
- * Include necessary headers.
- */
+//
+// Lookup table routines for libcupsfilters.
+//
+// Copyright 2007 by Apple Inc.
+// Copyright 1993-2005 by Easy Software Products.
+//
+// These coded instructions, statements, and computer programs are the
+// 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:
+//
+// cfLutDelete() - Free the memory used by a lookup table.
+// cfLutNew() - Make a lookup table from a list of pixel values.
+//
+
+//
+// Include necessary headers.
+//
#include "driver.h"
#include <math.h>
-/*
- * 'cfLutDelete()' - Free the memory used by a lookup table.
- */
+//
+// 'cfLutDelete()' - Free the memory used by a lookup table.
+//
void
-cfLutDelete(cf_lut_t *lut) /* I - Lookup table to free */
+cfLutDelete(cf_lut_t *lut) // I - Lookup table to free
{
if (lut != NULL)
free(lut);
}
-/*
- * 'cfLutNew()' - Make a lookup table from a list of pixel values.
- *
- * Returns a pointer to the lookup table on success, NULL on failure.
- */
+//
+// 'cfLutNew()' - Make a lookup table from a list of pixel values.
+//
+// Returns a pointer to the lookup table on success, NULL on failure.
+//
-cf_lut_t * /* O - New lookup table */
-cfLutNew(int num_values, /* I - Number of values */
- const float *values, /* I - Lookup table values */
- cf_logfunc_t log, /* I - Log function */
- void *ld) /* I - Log function data */
+cf_lut_t * // O - New lookup table
+cfLutNew(int num_values, // I - Number of values
+ const float *values, // I - Lookup table values
+ cf_logfunc_t log, // I - Log function
+ void *ld) // I - Log function data
{
- int pixel; /* Pixel value */
- cf_lut_t *lut; /* Lookup table */
- int start, /* Start value */
- end, /* End value */
- maxval; /* Maximum value */
+ int pixel; // Pixel value
+ cf_lut_t *lut; // Lookup table
+ int start, // Start value
+ end, // End value
+ maxval; // Maximum value
- /*
- * Range check...
- */
+ //
+ // Range check...
+ //
if (!num_values || !values)
return (NULL);
- /*
- * Allocate memory for the lookup table...
- */
+ //
+ // Allocate memory for the lookup table...
+ //
if ((lut = (cf_lut_t *)calloc((CF_MAX_LUT + 1),
sizeof(cf_lut_t))) == NULL)
return (NULL);
- /*
- * Generate the dither lookup table. The pixel values are roughly
- * defined by a piecewise linear curve that has an intensity value
- * at each output pixel. This isn't perfectly accurate, but it's
- * close enough for jazz.
- */
+ //
+ // Generate the dither lookup table. The pixel values are roughly
+ // defined by a piecewise linear curve that has an intensity value
+ // at each output pixel. This isn't perfectly accurate, but it's
+ // close enough for jazz.
+ //
maxval = CF_MAX_LUT / values[num_values - 1];
for (pixel = 0; pixel < num_values; pixel ++)
{
- /*
- * Select start and end values for this pixel...
- */
+ //
+ // Select start and end values for this pixel...
+ //
if (pixel == 0)
start = 0;
if (start == end)
break;
- /*
- * Generate lookup values and errors for each pixel.
- */
+ //
+ // Generate lookup values and errors for each pixel.
+ //
while (start <= end)
{
}
}
- /*
- * Show the lookup table...
- */
+ //
+ // Show the lookup table...
+ //
if (log)
for (start = 0; start <= CF_MAX_LUT; start += CF_MAX_LUT / 15)
"%d = %d/%d/%d", start, lut[start].intensity,
lut[start].pixel, lut[start].error);
- /*
- * Return the lookup table...
- */
+ //
+ // Return the lookup table...
+ //
return (lut);
}
-
-/*
-
-Copyright (c) 2016, Pranjal Bhor
-Copyright (c) 2008-2016, Till Kamppeter
-Copyright (c) 2011, Tim Waugh
-Copyright (c) 2011-2013, Richard Hughes
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-MIT Open Source License - http://www.opensource.org/
-
-*/
-
-
-/* PS/PDF to CUPS Raster filter based on mutool */
+//
+// Copyright (c) 2016, Pranjal Bhor
+// Copyright (c) 2008-2016, Till Kamppeter
+// Copyright (c) 2011, Tim Waugh
+// Copyright (c) 2011-2013, Richard Hughes
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// MIT Open Source License - http://www.opensource.org/
+//
+
+
+// PS/PDF to PWG Raster filter based on mutool
#include <config.h>
#include <cups/cups.h>
typedef cups_page_header2_t mupdf_page_header;
#else
typedef cups_page_header_t mupdf_page_header;
-#endif /* CUPS_RASTER_SYNCv1 */
+#endif // CUPS_RASTER_SYNCv1
static int
-parse_doc_type(FILE *fp, cf_logfunc_t log, void *ld)
+parse_doc_type(FILE *fp,
+ cf_logfunc_t log,
+ void *ld)
{
char buf[5];
char *rc;
- /* get the first few bytes of the file */
+ // get the first few bytes of the file
rewind(fp);
- rc = fgets(buf,sizeof(buf),fp);
- /* empty input */
+ rc = fgets(buf, sizeof(buf), fp);
+
+ // empty input
if (rc == NULL)
- return 1;
+ return (1);
- /* is PDF */
- if (strncmp(buf,"%PDF",4) == 0)
- return 0;
+ // is PDF
+ if (strncmp(buf, "%PDF", 4) == 0)
+ return (0);
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterMuPDFToPWG: input file cannot be identified");
- return -1;
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterMuPDFToPWG: input file cannot be identified");
+
+ return (-1);
}
static void
-parse_pdf_header_options(FILE *fp, mupdf_page_header *h)
+parse_pdf_header_options(FILE *fp,
+ mupdf_page_header *h)
{
char buf[4096];
int i;
rewind(fp);
- /* skip until PDF start header */
- while (fgets(buf,sizeof(buf),fp) != 0) {
- if (strncmp(buf,"%PDF",4) == 0) {
+
+ // skip until PDF start header
+ while (fgets(buf, sizeof(buf), fp) != 0)
+ if (strncmp(buf, "%PDF", 4) == 0)
break;
- }
- }
- for (i = 0;i < PDF_MAX_CHECK_COMMENT_LINES;i++) {
- if (fgets(buf,sizeof(buf),fp) == 0) break;
- if (strncmp(buf,"%%PDFTOPDFNumCopies",19) == 0) {
+ for (i = 0; i < PDF_MAX_CHECK_COMMENT_LINES; i++)
+ {
+ if (fgets(buf, sizeof(buf), fp) == 0)
+ break;
+ if (strncmp(buf, "%%PDFTOPDFNumCopies", 19) == 0)
+ {
char *p;
- p = strchr(buf+19,':');
- h->NumCopies = atoi(p+1);
- } else if (strncmp(buf,"%%PDFTOPDFCollate",17) == 0) {
+ p = strchr(buf + 19, ':');
+ h->NumCopies = atoi(p + 1);
+ }
+ else if (strncmp(buf, "%%PDFTOPDFCollate", 17) == 0)
+ {
char *p;
- p = strchr(buf+17,':');
- while (*p == ' ' || *p == '\t') p++;
- if (strncasecmp(p,"true",4) == 0) {
+ p = strchr(buf + 17, ':');
+ while (*p == ' ' || *p == '\t')
+ p ++;
+ if (strncasecmp(p, "true", 4) == 0)
h->Collate = CUPS_TRUE;
- } else {
+ else
h->Collate = CUPS_FALSE;
- }
}
}
}
{
char tmpstr[1024];
- if ((h->HWResolution[0] != 100) || (h->HWResolution[1] != 100)) {
+ if ((h->HWResolution[0] != 100) || (h->HWResolution[1] != 100))
+ {
snprintf(tmpstr, sizeof(tmpstr), "-r%dx%d", h->HWResolution[0],
h->HWResolution[1]);
cupsArrayAdd(mupdf_args, strdup(tmpstr));
- } else {
+ }
+ else
+ {
snprintf(tmpstr, sizeof(tmpstr), "-r100x100");
cupsArrayAdd(mupdf_args, strdup(tmpstr));
}
snprintf(tmpstr, sizeof(tmpstr), "-h%d", h->cupsHeight);
cupsArrayAdd(mupdf_args, strdup(tmpstr));
- switch (h->cupsColorSpace) {
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_CMY:
- case CUPS_CSPACE_RGBW:
- case CUPS_CSPACE_SRGB:
- case CUPS_CSPACE_ADOBERGB:
- default:
- snprintf(tmpstr, sizeof(tmpstr), "-crgb");
- break;
-
- case CUPS_CSPACE_CMYK:
- if (outformat == CF_FILTER_OUT_FORMAT_PWG_RASTER) /* No post-filtering needed */
- snprintf(tmpstr, sizeof(tmpstr), "-ccmyk");
- else
- snprintf(tmpstr, sizeof(tmpstr), "-crgb"); /* Post-filtering needed, only
- 3-color modes supported as
- input for the post filters*/
- break;
-
- case CUPS_CSPACE_SW:
- snprintf(tmpstr, sizeof(tmpstr), "-cgray");
- break;
-
- case CUPS_CSPACE_K:
- case CUPS_CSPACE_W:
- snprintf(tmpstr, sizeof(tmpstr), "-cmono");
- break;
+ switch (h->cupsColorSpace)
+ {
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_CMY:
+ case CUPS_CSPACE_RGBW:
+ case CUPS_CSPACE_SRGB:
+ case CUPS_CSPACE_ADOBERGB:
+ default:
+ snprintf(tmpstr, sizeof(tmpstr), "-crgb");
+ break;
+
+ case CUPS_CSPACE_CMYK:
+ if (outformat == CF_FILTER_OUT_FORMAT_PWG_RASTER)
+ // No post-filtering needed
+ snprintf(tmpstr, sizeof(tmpstr), "-ccmyk");
+ else
+ snprintf(tmpstr, sizeof(tmpstr), "-crgb");
+ // Post-filtering needed, only
+ // 3-color modes supported as
+ // input for the post filters*/
+ break;
+
+ case CUPS_CSPACE_SW:
+ snprintf(tmpstr, sizeof(tmpstr), "-cgray");
+ break;
+
+ case CUPS_CSPACE_K:
+ case CUPS_CSPACE_W:
+ snprintf(tmpstr, sizeof(tmpstr), "-cmono");
+ break;
}
cupsArrayAdd(mupdf_args, strdup(tmpstr));
}
static int
-mutool_spawn (const char *filename,
- cups_array_t *mutool_args,
- int outputfd,
- cf_logfunc_t log,
- void *ld,
- cf_filter_iscanceledfunc_t iscanceled,
- void *icd)
+mutool_spawn(const char *filename,
+ cups_array_t *mutool_args,
+ int outputfd,
+ cf_logfunc_t log,
+ void *ld,
+ cf_filter_iscanceledfunc_t iscanceled,
+ void *icd)
{
char *argument;
char buf[BUFSIZ];
int status = 65536;
int wstatus;
- /* Put mutool command line argument into an array for the "exec()"
- call */
+ // Put mutool command line argument into an array for the "exec()"
+ // call
numargs = cupsArrayCount(mutool_args);
mutoolargv = calloc(numargs + 1, sizeof(char *));
for (argument = (char *)cupsArrayFirst(mutool_args), i = 0; argument;
- argument = (char *)cupsArrayNext(mutool_args), i++) {
+ argument = (char *)cupsArrayNext(mutool_args), i++)
mutoolargv[i] = argument;
- }
mutoolargv[i] = NULL;
- if (log) {
- /* Debug output: Full mutool command line and environment variables */
+ if (log)
+ {
+ // Debug output: Full mutool command line and environment variables
snprintf(buf, sizeof(buf), "cfFilterMuPDFToPWG: mutool command line:");
- for (i = 0; mutoolargv[i]; i ++) {
+ for (i = 0; mutoolargv[i]; i ++)
+ {
if ((strchr(mutoolargv[i],' ')) || (strchr(mutoolargv[i],'\t')))
apos = "'";
else
log(ld, CF_LOGLEVEL_DEBUG, "%s", buf);
}
- /* Create a pipe for stderr output of mutool */
+ // Create a pipe for stderr output of mutool
if (pipe(errfds))
{
errfds[0] = -1;
errfds[1] = -1;
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterMuPDFToPWG: Unable to establish stderr pipe for mutool "
- "call");
+ "cfFilterMuPDFToPWG: Unable to establish stderr pipe for mutool call");
goto out;
}
- /* Set the "close on exec" flag on each end of the pipes... */
+ // Set the "close on exec" flag on each end of the pipes...
if (fcntl(errfds[0], F_SETFD, fcntl(errfds[0], F_GETFD) | FD_CLOEXEC))
{
close(errfds[0]);
errfds[0] = -1;
errfds[1] = -1;
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterMuPDFToPWG: Unable to set \"close on exec\" flag on read "
- "end of the stderr pipe for mutool call");
+ "cfFilterMuPDFToPWG: Unable to set \"close on exec\" flag on read end of the stderr pipe for mutool call");
goto out;
}
if (fcntl(errfds[1], F_SETFD, fcntl(errfds[1], F_GETFD) | FD_CLOEXEC))
close(errfds[0]);
close(errfds[1]);
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterMuPDFToPWG: Unable to set \"close on exec\" flag on write "
- "end of the stderr pipe for mutool call");
+ "cfFilterMuPDFToPWG: Unable to set \"close on exec\" flag on write end of the stderr pipe for mutool call");
goto out;
}
if ((mutoolpid = fork()) == 0)
{
- /* Couple errfds pipe with stdin of mutool process */
- if (errfds[1] >= 2) {
- if (errfds[1] != 2) {
- if (dup2(errfds[1], 2) < 0) {
+ // Couple errfds pipe with stdin of mutool process
+ if (errfds[1] >= 2)
+ {
+ if (errfds[1] != 2)
+ {
+ if (dup2(errfds[1], 2) < 0)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterMuPDFToPWG: Unable to couple pipe with stderr of "
- "mutool process");
+ "cfFilterMuPDFToPWG: Unable to couple pipe with stderr of mutool process");
exit(1);
}
close(errfds[1]);
}
close(errfds[0]);
- } else {
+ }
+ else
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterMuPDFToPWG: invalid pipe file descriptor to couple with "
- "stderr of mutool process");
+ "cfFilterMuPDFToPWG: invalid pipe file descriptor to couple with stderr of mutool process");
exit(1);
}
- /* Couple stdout of mutool process */
- if (outputfd >= 1) {
- if (outputfd != 1) {
- if (dup2(outputfd, 1) < 0) {
+ // Couple stdout of mutool process
+ if (outputfd >= 1)
+ {
+ if (outputfd != 1)
+ {
+ if (dup2(outputfd, 1) < 0)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterMuPDFToPWG: Unable to couple stdout of mutool "
- "process");
+ "cfFilterMuPDFToPWG: Unable to couple stdout of mutool process");
exit(1);
}
close(outputfd);
}
- } else {
+ }
+ else
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterMuPDFToPWG: Invalid file descriptor to couple with "
- "stdout of mutool process");
+ "cfFilterMuPDFToPWG: Invalid file descriptor to couple with stdout of mutool process");
exit(1);
}
- /* Execute mutool command line ... */
+ // Execute mutool command line ...
execvp(filename, mutoolargv);
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterMuPDFToPWG: Unable to launch mutool: %s: %s", filename,
- strerror(errno));
+ "cfFilterMuPDFToPWG: Unable to launch mutool: %s: %s",
+ filename, strerror(errno));
exit(1);
}
if (log) log(ld, CF_LOGLEVEL_DEBUG,
{
logfp = cupsFileOpenFd(errfds[0], "r");
while (cupsFileGets(logfp, buf, sizeof(buf)))
- if (log) {
- if (strncmp(buf, "DEBUG: ", 7) == 0) {
+ if (log)
+ {
+ if (strncmp(buf, "DEBUG: ", 7) == 0)
+ {
log_level = CF_LOGLEVEL_DEBUG;
msg = buf + 7;
- } else if (strncmp(buf, "DEBUG2: ", 8) == 0) {
+ }
+ else if (strncmp(buf, "DEBUG2: ", 8) == 0)
+ {
log_level = CF_LOGLEVEL_DEBUG;
msg = buf + 8;
- } else if (strncmp(buf, "INFO: ", 6) == 0) {
+ }
+ else if (strncmp(buf, "INFO: ", 6) == 0)
+ {
log_level = CF_LOGLEVEL_INFO;
msg = buf + 6;
- } else if (strncmp(buf, "WARNING: ", 9) == 0) {
+ }
+ else if (strncmp(buf, "WARNING: ", 9) == 0)
+ {
log_level = CF_LOGLEVEL_WARN;
msg = buf + 9;
- } else if (strncmp(buf, "ERROR: ", 7) == 0) {
+ }
+ else if (strncmp(buf, "ERROR: ", 7) == 0)
+ {
log_level = CF_LOGLEVEL_ERROR;
msg = buf + 7;
- } else {
+ }
+ else
+ {
log_level = CF_LOGLEVEL_DEBUG;
msg = buf;
}
log(ld, log_level, "cfFilterMuPDFToPWG: %s", msg);
}
cupsFileClose(logfp);
- /* No need to close the fd errfds[0], as cupsFileClose(fp) does this
- already */
- /* Ignore errors of the logging process */
+ // No need to close the fd errfds[0], as cupsFileClose(fp) does this
+ // already
+ // Ignore errors of the logging process
exit(0);
}
if (log) log(ld, CF_LOGLEVEL_DEBUG,
close(errfds[0]);
- while (mutoolpid > 0 || errpid > 0) {
- if ((pid = wait(&wstatus)) < 0) {
- if (errno == EINTR && iscanceled && iscanceled(icd)) {
+ while (mutoolpid > 0 || errpid > 0)
+ {
+ if ((pid = wait(&wstatus)) < 0)
+ {
+ if (errno == EINTR && iscanceled && iscanceled(icd))
+ {
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterMuPDFToPWG: Job canceled, killing mutool ...");
kill(mutoolpid, SIGTERM);
continue;
}
- /* How did the filter terminate */
- if (wstatus) {
- if (WIFEXITED(wstatus)) {
- /* Via exit() anywhere or return() in the main() function */
+ // How did the filter terminate
+ if (wstatus)
+ {
+ if (WIFEXITED(wstatus))
+ {
+ // Via exit() anywhere or return() in the main() function
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterMuPDFToPWG: %s (PID %d) stopped with status %d",
(pid == mutoolpid ? "mutool" : "Logging"), pid,
WEXITSTATUS(wstatus));
status = WEXITSTATUS(wstatus);
- } else {
- /* Via signal */
+ }
+ else
+ {
+ // Via signal
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterMuPDFToPWG: %s (PID %d) crashed on signal %d",
(pid == mutoolpid ? "mutool" : "Logging"), pid,
WTERMSIG(wstatus));
status = 256 * WTERMSIG(wstatus);
}
- } else {
+ }
+ else
+ {
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterMuPDFToPWG: %s (PID %d) exited with no errors.",
(pid == mutoolpid ? "mutool" : "Logging"), pid);
out:
free(mutoolargv);
- return status;
+ return (status);
}
int
-cfFilterMuPDFToPWG(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable?
- (unused) */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters
- (unused) */
+cfFilterMuPDFToPWG(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ // (unused)
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
+ // (unused)
{
cf_filter_out_format_t outformat;
char *val;
"PCLM"))));
memset(&sa, 0, sizeof(sa));
- /* Ignore SIGPIPE and have write return an error instead */
+ // Ignore SIGPIPE and have write return an error instead
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, NULL);
fd = cupsTempFd(infilename, 1024);
- if (fd < 0) {
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterMuPDFToPWG: Can't create temporary file");
- goto out;
- }
+ if (fd < 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterMuPDFToPWG: Can't create temporary file");
+ goto out;
+ }
- /* copy input file to the tmp file */
- while ((n = read(inputfd, buf, BUFSIZ)) > 0) {
- if (write(fd,buf,n) != n) {
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterMuPDFToPWG: Can't copy input to temporary file");
- close(fd);
- goto out;
- }
+ // copy input file to the tmp file
+ while ((n = read(inputfd, buf, BUFSIZ)) > 0)
+ {
+ if (write(fd, buf, n) != n)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterMuPDFToPWG: Can't copy input to temporary file");
+ close(fd);
+ goto out;
}
+ }
- if (!inputfd) {
-
- if (lseek(fd,0,SEEK_SET) < 0) {
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterMuPDFToPWG: Can't rewind temporary file");
+ if (!inputfd)
+ {
+ if (lseek(fd, 0, SEEK_SET) < 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterMuPDFToPWG: Can't rewind temporary file");
close(fd);
goto out;
}
- if ((fp = fdopen(fd,"rb")) == 0) {
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterMuPDFToPWG: Can't open temporary file");
+ if ((fp = fdopen(fd, "rb")) == 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterMuPDFToPWG: Can't open temporary file");
close(fd);
goto out;
}
- } else {
- /* filename is specified */
+ }
+ else
+ {
+ // filename is specified
- if ((fp = fdopen(fd,"rb")) == 0) {
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterMuPDFToPWG: Can't open temporary file");
+ if ((fp = fdopen(fd, "rb")) == 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterMuPDFToPWG: Can't open temporary file");
goto out;
}
}
- /* If doc type is not PDF exit */
+ // If doc type is not PDF exit
empty = parse_doc_type(fp, log, ld);
if (empty == -1)
goto out;
- /* mutool parameters */
+ // mutool parameters
mupdf_args = cupsArrayNew(NULL, NULL);
- if (!mupdf_args) {
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterMuPDFToPWG: Unable to allocate memory for mutool arguments array");
+ if (!mupdf_args)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterMuPDFToPWG: Unable to allocate memory for mutool arguments array");
goto out;
}
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterMuPDFToPWG: command: %s",
- CUPS_MUTOOL);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterMuPDFToPWG: command: %s",
+ CUPS_MUTOOL);
snprintf(tmpstr, sizeof(tmpstr), "%s", CUPS_MUTOOL);
cupsArrayAdd(mupdf_args, strdup(tmpstr));
cupsArrayAdd(mupdf_args, strdup("draw"));
cupsArrayAdd(mupdf_args, strdup("-o-"));
cupsArrayAdd(mupdf_args, strdup("-smtf"));
- /* mutool output parameters */
+ // mutool output parameters
cupsArrayAdd(mupdf_args, strdup("-Fpwg"));
- /* Note that MuPDF only creates PWG Raster so we select this as header format,
- We also supply the final output format (to which will be converted with
- further filters) to determine the correct color space and depth.
- From the header h only cupsWidth/cupsHeight (dimensions in pixels),
- resolution, and color space are used here. */
+ // Note that MuPDF only creates PWG Raster so we select this as header format,
+ // We also supply the final output format (to which will be converted with
+ // further filters) to determine the correct color space and depth.
+ // From the header h only cupsWidth/cupsHeight (dimensions in pixels),
+ // resolution, and color space are used here.
cfRasterPrepareHeader(&h, data, outformat,
CF_FILTER_OUT_FORMAT_PWG_RASTER, 1, &cspace);
- /* set PDF-specific options */
+ // set PDF-specific options
parse_pdf_header_options(fp, &h);
- /* fixed other values that pdftopdf handles */
+ // fixed other values that pdftopdf handles
h.MirrorPrint = CUPS_FALSE;
h.Orientation = CUPS_ORIENT_0;
- /* Check status of color management in CUPS */
+ // Check status of color management in CUPS
cm_calibrate = cfCmGetCupsColorCalibrateMode(data);
if (cm_calibrate == CF_CM_CALIBRATION_ENABLED)
h.MediaType, h.HWResolution[0], h.HWResolution[1],
&icc_profile);
- /* Note: No ICC profile support in mutool! */
+ // Note: No ICC profile support in mutool!
- /* Find print-rendering-intent */
+ // Find print-rendering-intent
h.cupsRenderingIntent[0] = '\0';
cfGetPrintRenderIntent(data, h.cupsRenderingIntent,
sizeof(h.cupsRenderingIntent));
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Print rendering intent = %s", h.cupsRenderingIntent);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Print rendering intent = %s", h.cupsRenderingIntent);
- /* get all the data from the header and pass it to mutool */
+ // get all the data from the header and pass it to mutool
header_to_gs_args(&h, outformat, mupdf_args);
snprintf(tmpstr, sizeof(tmpstr), "%s", infilename);
cupsArrayAdd(mupdf_args, strdup(tmpstr));
- /* Execute mutool command line ... */
+ // Execute mutool command line ...
snprintf(tmpstr, sizeof(tmpstr), "%s", CUPS_MUTOOL);
- /* call mutool */
+ // call mutool
status = mutool_spawn (tmpstr, mupdf_args, outputfd, log, ld,
iscanceled, icd);
- if (status != 0) status = 1;
+ if (status != 0)
+ status = 1;
- if(empty)
+ if (empty)
{
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterMuPDFToPWG: Input is empty, outputting empty file.");
- status = 0;
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterMuPDFToPWG: Input is empty, outputting empty file.");
+ status = 0;
}
+
out:
close(outputfd);
if (fp)
if (fd >= 0)
unlink(infilename);
- return status;
+
+ return (status);
}
-/*
- * Bit packing routines for CUPS.
- *
- * Copyright 2007 by Apple Inc.
- * Copyright 1993-2005 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * 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:
- *
- * cfPackHorizontal() - Pack pixels horizontally...
- * cfPackHorizontal2() - Pack 2-bit pixels horizontally...
- * cfPackHorizontalBit() - Pack pixels horizontally by bit...
- * cfPackVertical() - Pack pixels vertically...
- */
-
-/*
- * Include necessary headers...
- */
+//
+// Bit packing routines for libcupsfilters.
+//
+// Copyright 2007 by Apple Inc.
+// Copyright 1993-2005 by Easy Software Products.
+//
+// These coded instructions, statements, and computer programs are the
+// 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:
+//
+// cfPackHorizontal() - Pack pixels horizontally...
+// cfPackHorizontal2() - Pack 2-bit pixels horizontally...
+// cfPackHorizontalBit() - Pack pixels horizontally by bit...
+// cfPackVertical() - Pack pixels vertically...
+//
+
+//
+// Include necessary headers...
+//
#include "driver.h"
-/*
- * 'cfPackHorizontal()' - Pack pixels horizontally...
- */
+//
+// 'cfPackHorizontal()' - Pack pixels horizontally...
+//
void
-cfPackHorizontal(const unsigned char *ipixels,/* I - Input pixels */
- unsigned char *obytes, /* O - Output bytes */
- int width, /* I - Number of pixels */
- const unsigned char clearto, /* I - Initial value of bytes */
- const int step) /* I - Step value between pixels */
+cfPackHorizontal(const unsigned char *ipixels, // I - Input pixels
+ unsigned char *obytes, // O - Output bytes
+ int width, // I - Number of pixels
+ const unsigned char clearto, // I - Initial value of bytes
+ const int step) // I - Step value between pixels
{
- register unsigned char b; /* Current byte */
+ register unsigned char b; // Current byte
- /*
- * Do whole bytes first...
- */
+ //
+ // Do whole bytes first...
+ //
while (width > 7)
{
width -= 8;
}
- /*
- * Then do the last N bytes (N < 8)...
- */
+ //
+ // Then do the last N bytes (N < 8)...
+ //
b = clearto;
}
-/*
- * 'cfPackHorizontal2()' - Pack 2-bit pixels horizontally...
- */
+//
+// 'cfPackHorizontal2()' - Pack 2-bit pixels horizontally...
+//
void
-cfPackHorizontal2(const unsigned char *ipixels, /* I - Input pixels */
- unsigned char *obytes, /* O - Output bytes */
- int width, /* I - Number of pixels */
- const int step) /* I - Stepping value */
+cfPackHorizontal2(const unsigned char *ipixels, // I - Input pixels
+ unsigned char *obytes, // O - Output bytes
+ int width, // I - Number of pixels
+ const int step) // I - Stepping value
{
- register unsigned char b; /* Current byte */
+ register unsigned char b; // Current byte
- /*
- * Do whole bytes first...
- */
+ //
+ // Do whole bytes first...
+ //
while (width > 3)
{
width -= 4;
}
- /*
- * Then do the last N bytes (N < 4)...
- */
+ //
+ // Then do the last N bytes (N < 4)...
+ //
b = 0;
}
-/*
- * 'cfPackHorizontalBit()' - Pack pixels horizontally by bit...
- */
+//
+// 'cfPackHorizontalBit()' - Pack pixels horizontally by bit...
+//
void
-cfPackHorizontalBit(const unsigned char *ipixels, /* I - Input pixels */
- unsigned char *obytes, /* O - Output bytes */
- int width, /* I - Number of pixels */
- const unsigned char clearto, /* I - Initial value of bytes */
- const unsigned char bit) /* I - Bit to check */
+cfPackHorizontalBit(const unsigned char *ipixels, // I - Input pixels
+ unsigned char *obytes, // O - Output bytes
+ int width, // I - Number of pixels
+ const unsigned char clearto, // I - Initial value of
+ // bytes
+ const unsigned char bit) // I - Bit to check
{
- register unsigned char b; /* Current byte */
+ register unsigned char b; // Current byte
- /*
- * Do whole bytes first...
- */
+ //
+ // Do whole bytes first...
+ //
while (width > 7)
{
width -= 8;
}
- /*
- * Then do the last N bytes (N < 8)...
- */
+ //
+ // Then do the last N bytes (N < 8)...
+ //
b = clearto;
}
-/*
- * 'cfPackVertical()' - Pack pixels vertically...
- */
+//
+// 'cfPackVertical()' - Pack pixels vertically...
+//
void
-cfPackVertical(const unsigned char *ipixels, /* I - Input pixels */
- unsigned char *obytes, /* O - Output bytes */
- int width, /* I - Number of input pixels */
- const unsigned char bit, /* I - Output bit */
- const int step) /* I - Number of bytes between columns */
+cfPackVertical(const unsigned char *ipixels, // I - Input pixels
+ unsigned char *obytes, // O - Output bytes
+ int width, // I - Number of input pixels
+ const unsigned char bit, // I - Output bit
+ const int step) // I - Number of bytes between
+ // columns
{
- /*
- * Loop through the entire array...
- */
+ //
+ // Loop through the entire array...
+ //
while (width > 7)
{
width --;
}
}
-
-/**
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * @brief pclmtoraster filter function
- * @file pclmtoraster.cxx
- * @author Vikrant Malik <vikrantmalik051@gmail.com> (c) 2020
- */
-
-/*
- * Include necessary headers...
- */
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// @brief pclmtoraster filter function
+// @file pclmtoraster.cxx
+// @author Vikrant Malik <vikrantmalik051@gmail.com> (c) 2020
+//
+
+//
+// Include necessary headers...
+//
#include "filter.h"
#include <cups/raster.h>
#include "ipp.h"
-
-#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 6)
-#define HAVE_CUPS_1_7 1
-#endif
#define MAX_BYTES_PER_PIXEL 32
+
typedef struct pclmtoraster_data_s
{
cf_filter_out_format_t outformat = CF_FILTER_OUT_FORMAT_PWG_RASTER;
cups_page_header2_t header;
char pageSizeRequested[64];
int bi_level = 0;
- /* image swapping */
+ // image swapping
bool swap_image_x = false;
bool swap_image_y = false;
- /* margin swapping */
+ // margin swapping
bool swap_margin_x = false;
bool swap_margin_y = false;
unsigned int nplanes;
unsigned int nbands;
- unsigned int bytesPerLine; /* number of bytes per line */
- /* Note: When CUPS_ORDER_BANDED,
- cupsBytesPerLine = bytesPerLine*cupsNumColors */
- std::string colorspace; /* Colorspace of raster data */
+ unsigned int bytesPerLine; // number of bytes per line
+ // Note: When CUPS_ORDER_BANDED,
+ // cupsBytesPerLine = bytesPerLine * cupsNumColors
+ std::string colorspace; // Colorspace of raster data
} pclmtoraster_data_t;
-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 *(*convert_line_func) (unsigned char *src, unsigned char *dst,
- unsigned char *buf,
- unsigned int row, unsigned int plane,
- pclmtoraster_data_t *data,
- convert_cspace_func convertcspace);
+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 *(*convert_line_func)(unsigned char *src,
+ unsigned char *dst,
+ unsigned char *buf,
+ unsigned int row,
+ unsigned int plane,
+ pclmtoraster_data_t *data,
+ convert_cspace_func convertcspace);
typedef struct conversion_function_s
{
- convert_cspace_func convertcspace; /* Function for conversion of colorspaces */
- convert_line_func 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
-parse_opts(cf_filter_data_t *data, cf_filter_out_format_t outformat,
- pclmtoraster_data_t *pclmtoraster_data)
+parse_opts(cf_filter_data_t *data,
+ cf_filter_out_format_t outformat,
+ pclmtoraster_data_t *pclmtoraster_data)
{
int num_options = 0;
cups_option_t* options = NULL;
const char* t = NULL;
const char *val;
- cf_logfunc_t log = data->logfunc;
+ cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
cups_page_header2_t *header = &(pclmtoraster_data->header);
cups_cspace_t cspace = (cups_cspace_t)(-1);
pclmtoraster_data->outformat = outformat;
- /*
- * CUPS option list
- */
+ //
+ // CUPS option list
+ //
num_options = cfJoinJobOptionsAndAttrs(data, num_options, &options);
if (header->Duplex)
{
int backside;
- /* analyze options relevant to Duplex */
- /* APDuplexRequiresFlippedMargin */
- enum {
+ // analyze options relevant to Duplex
+ // APDuplexRequiresFlippedMargin
+ enum
+ {
FM_NO,
FM_FALSE,
FM_TRUE
FM_NO));
backside &= 7;
- if (backside==CF_BACKSIDE_MANUAL_TUMBLE && header->Tumble)
+ if (backside == CF_BACKSIDE_MANUAL_TUMBLE && header->Tumble)
{
pclmtoraster_data->swap_image_x = pclmtoraster_data->swap_image_y =
true;
if (flippedMargin == FM_TRUE)
pclmtoraster_data->swap_margin_y = false;
}
- else if (backside==CF_BACKSIDE_ROTATED && !header->Tumble)
+ else if (backside == CF_BACKSIDE_ROTATED && !header->Tumble)
{
pclmtoraster_data->swap_image_x = pclmtoraster_data->swap_image_y =
true;
if (flippedMargin == FM_TRUE)
pclmtoraster_data->swap_margin_y = false;
}
- else if (backside==CF_BACKSIDE_FLIPPED)
+ else if (backside == CF_BACKSIDE_FLIPPED)
{
if (header->Tumble)
{
}
}
- if ((val = cupsGetOption("print-color-mode", num_options, options)) != NULL
- && !strncasecmp(val, "bi-level", 8))
+ if ((val = cupsGetOption("print-color-mode", num_options, options)) != NULL &&
+ !strncasecmp(val, "bi-level", 8))
pclmtoraster_data->bi_level = 1;
strncpy(pclmtoraster_data->pageSizeRequested, header->cupsPageSizeName, 64);
return(0);
}
+
static bool
media_box_lookup(QPDFObjectHandle object,
- float rect[4])
+ float rect[4])
{
// preliminary checks
if (!object.isDictionary() || !object.hasKey("/MediaBox"))
- return false;
+ return (false);
// assign mediabox values to rect
std::vector<QPDFObjectHandle> mediabox =
object.getKey("/MediaBox").getArrayAsVector();
for (int i = 0; i < 4; ++i)
- {
rect[i] = mediabox[i].getNumericValue();
- }
- return mediabox.size() == 4;
+ return (mediabox.size() == 4);
}
-/*
- * 'rotate_bitmap()' - Function to rotate a bitmap
- * (assumed that bits-per-component of the bitmap is 8).
- */
-
-static unsigned char * /* O - Output Bitmap */
-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 */
- unsigned int width, /* I - Width of raster image in pixels */
- int rowsize, /* I - Length of one row of pixels */
- std::string colorspace,/* I - Colorspace of input bitmap */
- cf_logfunc_t log, /* I - Log function */
- void *ld) /* I - Aux. data for log function */
+
+//
+// 'rotate_bitmap()' - Function to rotate a bitmap
+// (assumed that bits-per-component of the bitmap is 8).
+//
+
+static unsigned char * // O - Output Bitmap
+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
+ unsigned int width, // I - Width of raster image in pixels
+ int rowsize, // I - Length of one row of pixels
+ std::string colorspace,// I - Colorspace of input bitmap
+ cf_logfunc_t log, // I - Log function
+ void *ld) // I - Aux. data for log function
{
unsigned char *bp = src;
unsigned char *dp = dst;
unsigned char *temp = dst;
if (rotate == 0)
- {
return (src);
- }
else if (rotate == 180)
{
if (colorspace == "/DeviceGray")
{
bp = src + height * rowsize - 1;
dp = dst;
- for (unsigned int h = 0; h < height; h++)
- {
- for (unsigned int w = 0; w < width; w++, bp --, dp ++)
- {
+ for (unsigned int h = 0; h < height; h ++)
+ for (unsigned int w = 0; w < width; w ++, bp --, dp ++)
*dp = *bp;
- }
- }
}
else if (colorspace == "/DeviceCMYK")
{
bp = src + height * rowsize - 4;
dp = dst;
- for (unsigned int h = 0; h < height; h++)
+ for (unsigned int h = 0; h < height; h ++)
{
- for (unsigned int w = 0; w < width; w++, bp -= 4, dp += 4)
+ for (unsigned int w = 0; w < width; w ++, bp -= 4, dp += 4)
{
dp[0] = bp[0];
dp[1] = bp[1];
{
bp = src + height * rowsize - 3;
dp = dst;
- for (unsigned int h = 0; h < height; h++)
+ for (unsigned int h = 0; h < height; h ++)
{
- for (unsigned int w = 0; w < width; w++, bp -= 3, dp += 3)
+ for (unsigned int w = 0; w < width; w ++, bp -= 3, dp += 3)
{
dp[0] = bp[0];
dp[1] = bp[1];
{
bp = src;
dp = dst;
- for (unsigned int h = 0; h < height; h++)
+ for (unsigned int h = 0; h < height; h ++)
{
bp = src + (height - h) - 1;
- for (unsigned int w = 0; w < width; w++, bp += height , dp ++)
- {
+ for (unsigned int w = 0; w < width; w ++, bp += height , dp ++)
*dp = *bp;
- }
}
}
else if (colorspace == "/DeviceCMYK")
{
for (unsigned int h = 0; h < height; h++)
{
- bp = src + (height - h)*4 - 4;
- for (unsigned int i = 0; i < width; i++, bp += height*4 , dp += 4)
+ bp = src + (height - h) * 4 - 4;
+ for (unsigned int i = 0; i < width; i ++, bp += height * 4 , dp += 4)
{
dp[0] = bp[0];
dp[1] = bp[1];
{
bp = src;
dp = dst;
- for (unsigned int h = 0; h < height; h++)
+ for (unsigned int h = 0; h < height; h ++)
{
- bp = src + (height - h)*3 - 3;
- for (unsigned int i = 0; i < width; i++, bp += height*3 , dp += 3)
+ bp = src + (height - h) * 3 - 3;
+ for (unsigned int i = 0; i < width; i ++, bp += height * 3 , dp += 3)
{
dp[0] = bp[0];
dp[1] = bp[1];
{
if (colorspace == "/DeviceGray")
{
- for (unsigned int h = 0; h < height; h++)
+ for (unsigned int h = 0; h < height; h ++)
{
bp = src + (width - 1) * height + h;
- for (unsigned int i = 0; i < width; i++, bp -= height , dp ++)
- {
+ for (unsigned int i = 0; i < width; i ++, bp -= height , dp ++)
*dp = *bp;
- }
}
}
else if (colorspace == "/DeviceCMYK")
{
- for (unsigned int h = 0; h < height; h++)
+ for (unsigned int h = 0; h < height; h ++)
{
- bp = src + (width - 1) * height * 4 + 4*h;
- for (unsigned int i = 0; i < width; i++, bp -= height*4 , dp += 4)
+ bp = src + (width - 1) * height * 4 + 4 * h;
+ for (unsigned int i = 0; i < width; i ++, bp -= height * 4 , dp += 4)
{
dp[0] = bp[0];
dp[1] = bp[1];
}
else if (colorspace == "/DeviceRGB")
{
- for (unsigned int h = 0; h < height; h++)
+ for (unsigned int h = 0; h < height; h ++)
{
- bp = src + (width - 1) * height * 3 + 3*h;
- for (unsigned int i = 0; i < width; i++, bp -= height*3 , dp += 3)
+ bp = src + (width - 1) * height * 3 + 3 * h;
+ for (unsigned int i = 0; i < width; i ++, bp -= height * 3 , dp += 3)
{
dp[0] = bp[0];
dp[1] = bp[1];
return (temp);
}
+
static unsigned char *
rgb_to_cmyk_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- cfImageRGBToCMYK(src,dst,pixels);
- return dst;
+ cfImageRGBToCMYK(src, dst, pixels);
+ return (dst);
}
+
static unsigned char *
rgb_to_cmy_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- cfImageRGBToCMY(src,dst,pixels);
- return dst;
+ cfImageRGBToCMY(src, dst, pixels);
+ return (dst);
}
+
static unsigned char *
rgb_to_white_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- if (data->header.cupsBitsPerColor != 1) {
- cfImageRGBToWhite(src,dst,pixels);
- } else {
- cfImageRGBToWhite(src,src,pixels);
+ if (data->header.cupsBitsPerColor != 1)
+ cfImageRGBToWhite(src, dst, pixels);
+ else
+ {
+ cfImageRGBToWhite(src, src, pixels);
cfOneBitLine(src, dst, data->header.cupsWidth, row, data->bi_level);
}
-
- return dst;
+ return (dst);
}
+
static unsigned char *
rgb_to_black_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- if (data->header.cupsBitsPerColor != 1) {
- cfImageRGBToBlack(src,dst,pixels);
- } else {
- cfImageRGBToBlack(src,src,pixels);
+ if (data->header.cupsBitsPerColor != 1)
+ cfImageRGBToBlack(src, dst, pixels);
+ else
+ {
+ cfImageRGBToBlack(src, src, pixels);
cfOneBitLine(src, dst, data->header.cupsWidth, row, data->bi_level);
}
- return dst;
+ return (dst);
}
+
static unsigned char *
cmyk_to_rgb_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- cfImageCMYKToRGB(src,dst,pixels);
- return dst;
+ cfImageCMYKToRGB(src, dst, pixels);
+ return (dst);
}
+
static unsigned char *
cmyk_to_cmy_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- // Converted first to rgb and then to cmy for better outputs.
- cfImageCMYKToRGB(src,src,pixels);
- cfImageRGBToCMY(src,dst,pixels);
- return dst;
+ // Converted first to RGB and then to cmy for better outputs.
+ cfImageCMYKToRGB(src, src, pixels);
+ cfImageRGBToCMY(src, dst, pixels);
+ return (dst);
}
+
static unsigned char *
cmyk_to_white_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- if (data->header.cupsBitsPerColor != 1) {
- cfImageCMYKToWhite(src,dst,pixels);
- } else {
- cfImageCMYKToWhite(src,src,pixels);
+ if (data->header.cupsBitsPerColor != 1)
+ cfImageCMYKToWhite(src, dst, pixels);
+ else
+ {
+ cfImageCMYKToWhite(src, src, pixels);
cfOneBitLine(src, dst, data->header.cupsWidth, row, data->bi_level);
}
- return dst;
+ return (dst);
}
+
static unsigned char *
cmyk_to_black_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- if (data->header.cupsBitsPerColor != 1) {
- cfImageCMYKToBlack(src,dst,pixels);
- } else {
- cfImageCMYKToBlack(src,src,pixels);
+ if (data->header.cupsBitsPerColor != 1)
+ cfImageCMYKToBlack(src, dst, pixels);
+ else
+ {
+ cfImageCMYKToBlack(src, src, pixels);
cfOneBitLine(src, dst, data->header.cupsWidth, row, data->bi_level);
}
- return dst;
+ return (dst);
}
+
static unsigned char *
gray_to_rgb_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- cfImageWhiteToRGB(src,dst,pixels);
- return dst;
+ cfImageWhiteToRGB(src, dst, pixels);
+ return (dst);
}
+
static unsigned char *
gray_to_cmyk_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- cfImageWhiteToCMYK(src,dst,pixels);
- return dst;
+ cfImageWhiteToCMYK(src, dst, pixels);
+ return (dst);
}
+
static unsigned char *
gray_to_cmy_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- cfImageWhiteToCMY(src,dst,pixels);
- return dst;
+ cfImageWhiteToCMY(src, dst, pixels);
+ return (dst);
}
+
static unsigned char *
gray_to_black_line(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- if (data->header.cupsBitsPerColor != 1) {
+ if (data->header.cupsBitsPerColor != 1)
cfImageWhiteToBlack(src, dst, pixels);
- } else {
+ else
+ {
cfImageWhiteToBlack(src, src, pixels);
cfOneBitLine(src, dst, data->header.cupsWidth, row, data->bi_level);
}
- return dst;
+ return (dst);
}
+
static unsigned char *
convert_cspace_no_op(unsigned char *src,
- unsigned char *dst,
- unsigned int row,
- unsigned int pixels,
- pclmtoraster_data_t *data)
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int pixels,
+ pclmtoraster_data_t *data)
{
- return src;
+ return (src);
}
-/*
- * 'convert_line()' - Function to convert colorspace and bits-per-pixel
- * of a single line of raster data.
- */
-
-static unsigned char * /* O - Output string */
-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,
- convert_cspace_func convertcspace)
+
+//
+// 'convert_line()' - Function to convert colorspace and bits-per-pixel
+// of a single line of raster data.
+//
+
+static unsigned char * // O - Output string
+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,
+ convert_cspace_func convertcspace)
{
- /*
- Use only convertcspace if conversion of bits and conversion of color order
- is not required, or if dithering is required, for faster processing of
- raster output.
- */
+ //
+ // Use only convertcspace if conversion of bits and conversion of color order
+ // is not required, or if dithering is required, for faster processing of
+ // raster output.
+ //
+
unsigned int pixels = data->header.cupsWidth;
- if ((data->header.cupsBitsPerColor == 1
- && data->header.cupsNumColors == 1)
- || (data->header.cupsBitsPerColor == 8
- && data->header.cupsColorOrder == CUPS_ORDER_CHUNKED))
- {
+ if ((data->header.cupsBitsPerColor == 1 &&
+ data->header.cupsNumColors == 1) ||
+ (data->header.cupsBitsPerColor == 8 &&
+ data->header.cupsColorOrder == CUPS_ORDER_CHUNKED))
dst = convertcspace(src, dst, row, pixels, data);
- }
else
{
- for (unsigned int i = 0;i < pixels;i++)
+ for (unsigned int i = 0; i < pixels; i ++)
{
unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
unsigned char *pb;
- pb = convertcspace(src + i*(data->numcolors), pixelBuf1, row, 1, data);
+ pb = convertcspace(src + i * data->numcolors, pixelBuf1, row, 1, data);
pb = cfConvertBits(pb, pixelBuf2, i, row, data->header.cupsNumColors,
- data->header.cupsBitsPerColor);
+ data->header.cupsBitsPerColor);
cfWritePixel(dst, plane, i, pb, data->header.cupsNumColors,
- data->header.cupsBitsPerColor, data->header.cupsColorOrder);
+ data->header.cupsBitsPerColor, data->header.cupsColorOrder);
}
}
- return dst;
+ return (dst);
}
-/*
- * '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 */
-convert_reverse_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, /* I - pclmtoraster
- filter data */
- convert_cspace_func convertcspace) /* I - Function for
- conversion of
- colorspace */
+
+//
+// '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
+convert_reverse_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, // I - pclmtoraster
+ // filter data
+ convert_cspace_func convertcspace) // I - Function for
+ // conversion of
+ // colorspace
{
- /*
- Use only convertcspace if conversion of bits and conversion of color order
- is not required, or if dithering is required, for faster processing of
- raster output.
- */
+ //
+ // Use only convertcspace if conversion of bits and conversion of color order
+ // is not required, or if dithering is required, for faster processing of
+ // raster output.
+ //
+
unsigned int pixels = data->header.cupsWidth;
if (data->header.cupsBitsPerColor == 1 && data->header.cupsNumColors == 1)
{
unsigned char *dp = dst;
// Assign each pixel of buf to dst in the reverse order.
buf = convertcspace(src, buf, row, pixels, data) +
- (data->header.cupsWidth - 1)*data->header.cupsNumColors;
- for (unsigned int i = 0; i < pixels; i++, buf-=data->header.cupsNumColors,
- dp+=data->header.cupsNumColors)
- {
- for (unsigned int j = 0; j < data->header.cupsNumColors; j++)
- {
+ (data->header.cupsWidth - 1) * data->header.cupsNumColors;
+ for (unsigned int i = 0; i < pixels;
+ i ++, buf-=data->header.cupsNumColors, dp+=data->header.cupsNumColors)
+ for (unsigned int j = 0; j < data->header.cupsNumColors; j ++)
dp[j] = buf[j];
- }
- }
}
else
{
- for (unsigned int i = 0;i < pixels;i++)
+ for (unsigned int i = 0; i < pixels; i ++)
{
unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
unsigned char *pb;
- pb = convertcspace(src + (pixels - i - 1)*(data->numcolors), pixelBuf1,
+ pb = convertcspace(src + (pixels - i - 1) * (data->numcolors), pixelBuf1,
row, 1, data);
pb = cfConvertBits(pb, pixelBuf2, i, row, data->header.cupsNumColors,
- data->header.cupsBitsPerColor);
+ data->header.cupsBitsPerColor);
cfWritePixel(dst, plane, i, pb, data->header.cupsNumColors,
- data->header.cupsBitsPerColor, data->header.cupsColorOrder);
+ data->header.cupsBitsPerColor, data->header.cupsColorOrder);
}
}
- return dst;
+ return (dst);
}
-static void /* O - Exit status */
-select_convert_func(int pgno, /* I - Page number */
- cf_logfunc_t log, /* I - Log function */
- void *ld, /* I - Aux. data for log
- function */
- pclmtoraster_data_t *data, /* I - pclmtoraster filter
- data */
- conversion_function_t *convert)/* I - Conversion functions */
+
+static void // O - Exit status
+select_convert_func(int pgno, // I - Page number
+ cf_logfunc_t log, // I - Log function
+ void *ld, // I - Aux. data for log
+ // function
+ pclmtoraster_data_t *data, // I - pclmtoraster filter
+ // data
+ conversion_function_t *convert)// I - Conversion function
{
- /* Set rowsize and numcolors based on colorspace of raster data */
+ // Set rowsize and numcolors based on colorspace of raster data
cups_page_header2_t header = data->header;
std::string colorspace = data->colorspace;
if (colorspace == "/DeviceRGB")
{
- data->rowsize = header.cupsWidth*3;
+ data->rowsize = header.cupsWidth * 3;
data->numcolors = 3;
}
else if (colorspace == "/DeviceCMYK")
{
- data->rowsize = header.cupsWidth*4;
+ data->rowsize = header.cupsWidth * 4;
data->numcolors = 4;
}
else if (colorspace == "/DeviceGray")
"defaulting to /deviceRGB",
colorspace.c_str());
data->colorspace = "/DeviceRGB";
- data->rowsize = header.cupsWidth*3;
+ data->rowsize = header.cupsWidth * 3;
data->numcolors = 3;
}
convert->convertcspace = convert_cspace_no_op; //Default function
- /* Select convertcspace function */
+ // Select convertcspace function
switch (header.cupsColorSpace)
{
case CUPS_CSPACE_K:
- if (colorspace == "/DeviceRGB") convert->convertcspace = rgb_to_black_line;
- else if (colorspace == "/DeviceCMYK") convert->convertcspace =
- cmyk_to_black_line;
- else if (colorspace == "/DeviceGray") convert->convertcspace =
- gray_to_black_line;
- break;
+ if (colorspace == "/DeviceRGB")
+ convert->convertcspace = rgb_to_black_line;
+ else if (colorspace == "/DeviceCMYK")
+ convert->convertcspace = cmyk_to_black_line;
+ else if (colorspace == "/DeviceGray")
+ convert->convertcspace = gray_to_black_line;
+ break;
case CUPS_CSPACE_W:
case CUPS_CSPACE_SW:
- if (colorspace == "/DeviceRGB") convert->convertcspace = rgb_to_white_line;
- else if (colorspace == "/DeviceCMYK") convert->convertcspace =
- cmyk_to_white_line;
- break;
+ if (colorspace == "/DeviceRGB")
+ convert->convertcspace = rgb_to_white_line;
+ else if (colorspace == "/DeviceCMYK")
+ convert->convertcspace = cmyk_to_white_line;
+ break;
case CUPS_CSPACE_CMY:
- if (colorspace == "/DeviceRGB") convert->convertcspace = rgb_to_cmy_line;
- else if (colorspace == "/DeviceCMYK") convert->convertcspace =
- cmyk_to_cmy_line;
- else if (colorspace == "/DeviceGray") convert->convertcspace =
- gray_to_cmy_line;
- break;
+ if (colorspace == "/DeviceRGB")
+ convert->convertcspace = rgb_to_cmy_line;
+ else if (colorspace == "/DeviceCMYK")
+ convert->convertcspace = cmyk_to_cmy_line;
+ else if (colorspace == "/DeviceGray")
+ convert->convertcspace = gray_to_cmy_line;
+ break;
case CUPS_CSPACE_CMYK:
- if (colorspace == "/DeviceRGB") convert->convertcspace = rgb_to_cmyk_line;
- else if (colorspace == "/DeviceGray") convert->convertcspace =
- gray_to_cmyk_line;
- break;
+ if (colorspace == "/DeviceRGB")
+ convert->convertcspace = rgb_to_cmyk_line;
+ else if (colorspace == "/DeviceGray")
+ convert->convertcspace = gray_to_cmyk_line;
+ break;
case CUPS_CSPACE_RGB:
case CUPS_CSPACE_ADOBERGB:
case CUPS_CSPACE_SRGB:
default:
- if (colorspace == "/DeviceCMYK") convert->convertcspace = cmyk_to_rgb_line;
- else if (colorspace == "/DeviceGray") convert->convertcspace =
- gray_to_rgb_line;
- break;
- }
+ if (colorspace == "/DeviceCMYK")
+ convert->convertcspace = cmyk_to_rgb_line;
+ else if (colorspace == "/DeviceGray")
+ convert->convertcspace = gray_to_rgb_line;
+ break;
+ }
- /* Select convertline function */
+ // Select convertline function
if (header.Duplex && (pgno & 1) && data->swap_image_x)
- {
convert->convertline = convert_reverse_line;
- }
else
- {
convert->convertline = convert_line;
- }
-
}
-/*
- * 'out_page()' - Function to convert a single page of raster-only PDF/PCLm
- * input to CUPS/PWG Raster.
- */
-
-static int /* O - Exit status */
-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 */
- void* ld, /* I - Aux. data for log function */
- pclmtoraster_data_t *data, /* I - pclmtoraster filter data */
- cf_filter_data_t *filter_data, /* I - filter data */
- conversion_function_t *convert) /* I - Conversion functions */
+
+//
+// 'out_page()' - Function to convert a single page of raster-only PDF/PCLm
+// input to CUPS/PWG Raster.
+//
+
+static int // O - Exit status
+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
+ void* ld, // I - Aux. data for log function
+ pclmtoraster_data_t *data, // I - pclmtoraster filter data
+ cf_filter_data_t *filter_data, // I - filter data
+ conversion_function_t *convert)// I - Conversion functions
{
long long rotate = 0,
height,
QPDFObjectHandle imgdict;
QPDFObjectHandle colorspace_obj;
+
// Check if page is rotated.
if (page.getKey("/Rotate").isInteger())
rotate = page.getKey("/Rotate").getIntValueAsInt();
"cfFilterPCLmToRaster: mediaBox = [%f %f %f %f]: ",
mediaBox[0], mediaBox[1], mediaBox[2], mediaBox[3]);
l = mediaBox[2] - mediaBox[0];
- if (l < 0) l = -l;
+ if (l < 0)
+ l = -l;
if (rotate == 90 || rotate == 270)
data->header.PageSize[1] = (unsigned)l;
else
data->header.PageSize[0] = (unsigned)l;
l = mediaBox[3] - mediaBox[1];
- if (l < 0) l = -l;
+ if (l < 0)
+ l = -l;
if (rotate == 90 || rotate == 270)
data->header.PageSize[0] = (unsigned)l;
else
paperdimensions[i] = data->header.PageSize[i];
if (data->header.cupsImagingBBox[3] > 0.0)
{
- /* Set margins if we have a bounding box defined ... */
+ // Set margins if we have a bounding box defined ...
if (data->outformat == CF_FILTER_OUT_FORMAT_CUPS_RASTER)
{
margins[0] = data->header.cupsImagingBBox[0];
}
}
else
- /* ... otherwise use zero margins */
+ // ... otherwise use zero margins
for (int i = 0; i < 4; i ++)
margins[i] = 0.0;
}
-
if (data->header.Duplex && (pgno & 1))
{
- /* backside: change margin if needed */
+ // backside: change margin if needed
if (data->swap_margin_x)
{
swap = margins[2]; margins[2] = margins[0]; margins[0] = swap;
}
}
- /* write page header */
+ // write page header
for (int i = 0; i < 2; i ++)
{
data->header.cupsPageSize[i] = paperdimensions[i];
data->header.cupsWidth = 0;
data->header.cupsHeight = 0;
- /* Loop over all raster images in a page and store them in bitmap. */
+ // Loop over all raster images in a page and store them in bitmap.
std::map<std::string, QPDFObjectHandle> images = page.getPageImages();
for (auto const& iter: images)
{
image = iter.second;
- imgdict = image.getDict(); //XObject dictionary
+ imgdict = image.getDict(); // XObject dictionary
PointerHolder<Buffer> actual_data = image.getStreamData(qpdf_dl_all);
width = imgdict.getKey("/Width").getIntValue();
data->header.cupsHeight += height;
bufsize = actual_data->getSize();
- if(!pixel_count)
- {
+ if (!pixel_count)
bitmap = (unsigned char *) malloc(bufsize);
- }
else
- {
bitmap = (unsigned char *) realloc(bitmap, pixel_count + bufsize);
- }
memcpy(bitmap + pixel_count, actual_data->getBuffer(), bufsize);
pixel_count += bufsize;
if (data->header.cupsColorOrder == CUPS_ORDER_BANDED)
data->header.cupsBytesPerLine *= data->header.cupsNumColors;
- if (!cupsRasterWriteHeader2(raster,&(data->header)))
+ if (!cupsRasterWriteHeader2(raster, &(data->header)))
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPCLmToRaster: Can't write page %d header", pgno + 1);
colorspace_obj.getName() : "/DeviceRGB");
// Default for pclm files in DeviceRGB
- /* Select convertline and convertscpace function */
+ // Select convertline and convertscpace function
select_convert_func(pgno, log, ld, data, convert);
// If page is to be swapped in both x and y, rotate it by 180 degress
data->swap_image_x = false;
}
- /* Rotate Bitmap */
+ // Rotate Bitmap
if (rotate)
{
unsigned char *bitmap2 = (unsigned char *) malloc(pixel_count);
bitmap2 = rotate_bitmap(bitmap, bitmap2, rotate, data->header.cupsHeight,
- data->header.cupsWidth, data->rowsize,
- data->colorspace, log, ld);
+ data->header.cupsWidth, data->rowsize,
+ data->colorspace, log, ld);
free(bitmap);
bitmap = bitmap2;
}
colordata = bitmap;
- /* Write page image */
+ // Write page image
lineBuf = new unsigned char [data->bytesPerLine];
line = new unsigned char [data->bytesPerLine];
if (data->header.Duplex && (pgno & 1) && data->swap_image_y)
{
- for (unsigned int plane = 0; plane < data->nplanes ; plane++)
+ for (unsigned int plane = 0; plane < data->nplanes; plane ++)
{
unsigned char *bp = colordata +
(data->header.cupsHeight - 1) * (data->rowsize);
for (unsigned int h = data->header.cupsHeight; h > 0; h--)
{
- for (unsigned int band = 0; band < data->nbands; band++)
+ for (unsigned int band = 0; band < data->nbands; band ++)
{
dp = convert->convertline(bp, line, lineBuf, h - 1, plane + band,
data, convert->convertcspace);
}
else
{
- for (unsigned int plane = 0; plane < data->nplanes ; plane++)
+ for (unsigned int plane = 0; plane < data->nplanes; plane ++)
{
unsigned char *bp = colordata;
- for (unsigned int h = 0; h < data->header.cupsHeight; h++)
+ for (unsigned int h = 0; h < data->header.cupsHeight; h ++)
{
- for (unsigned int band = 0; band < data->nbands; band++)
+ for (unsigned int band = 0; band < data->nbands; band ++)
{
dp = convert->convertline(bp, line, lineBuf, h, plane + band,
data, convert->convertcspace);
return (0);
}
-/*
- * 'cfFilterPCLmToRaster()' - Filter function to convert raster-only PDF/PCLm input to
- * CUPS/PWG Raster output.
- */
-
-int /* O - Error status */
-cfFilterPCLmToRaster(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? (unused) */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters (unused) */
+
+//
+// 'cfFilterPCLmToRaster()' - Filter function to convert raster-only PDF/PCLm
+// input to CUPS/PWG Raster output.
+//
+
+int // O - Error status
+cfFilterPCLmToRaster(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ // (unused)
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
+ // (unused)
{
- cf_filter_out_format_t outformat;
- FILE *inputfp; /* Input file pointer */
- int fd = 0; /* Copy file descriptor */
- char *filename, /* PDF file to convert */
- tempfile[1024]; /* Temporary file */
- char buffer[8192]; /* Copy buffer */
- int bytes; /* Bytes copied */
+ cf_filter_out_format_t outformat;
+ FILE *inputfp; // Input file pointer
+ int fd = 0; // Copy file descriptor
+ char *filename, // PDF file to convert
+ tempfile[1024]; // Temporary file
+ char buffer[8192]; // Copy buffer
+ int bytes; // Bytes copied
int npages = 0;
QPDF *pdf = new QPDF();
cups_raster_t *raster;
pclmtoraster_data_t pclmtoraster_data;
conversion_function_t convert;
- cf_logfunc_t log = data->logfunc;
+ cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
- void *icd = data->iscanceleddata;
+ void *icd = data->iscanceleddata;
- if (parameters) {
+ if (parameters)
+ {
outformat = *(cf_filter_out_format_t *)parameters;
if (outformat != CF_FILTER_OUT_FORMAT_CUPS_RASTER &&
outformat != CF_FILTER_OUT_FORMAT_PWG_RASTER &&
outformat != CF_FILTER_OUT_FORMAT_APPLE_RASTER)
outformat = CF_FILTER_OUT_FORMAT_PWG_RASTER;
- } else
+ }
+ else
outformat = CF_FILTER_OUT_FORMAT_PWG_RASTER;
if (log) log(ld, CF_LOGLEVEL_DEBUG,
(outformat == CF_FILTER_OUT_FORMAT_PWG_RASTER ? "PWG Raster" :
"Apple Raster")));
- /*
- * Open the input data stream specified by the inputfd...
- */
+ //
+ // Open the input data stream specified by the inputfd...
+ //
if ((inputfp = fdopen(inputfd, "r")) == NULL)
{
}
if (pclmtoraster_data.header.cupsColorOrder == CUPS_ORDER_PLANAR)
- {
pclmtoraster_data.nplanes = pclmtoraster_data.header.cupsNumColors;
- }
else
- {
pclmtoraster_data.nplanes = 1;
- }
if (pclmtoraster_data.header.cupsColorOrder == CUPS_ORDER_BANDED)
- {
pclmtoraster_data.nbands = pclmtoraster_data.header.cupsNumColors;
- }
else
- {
pclmtoraster_data.nbands = 1;
- }
if ((raster = cupsRasterOpen(outputfd,
(pclmtoraster_data.outformat ==
}
if (log) log(ld, CF_LOGLEVEL_INFO,
- "cfFilterPCLmToRaster: Starting page %d.", i+1);
+ "cfFilterPCLmToRaster: Starting page %d.", i + 1);
if (out_page(raster, pages[i], i, log, ld, &pclmtoraster_data,data,
- &convert) != 0)
+ &convert) != 0)
break;
}
cupsRasterClose(raster);
delete pdf;
unlink(tempfile);
- return 0;
+ return (0);
}
void operator delete[](void *p) throw ()
-/*
- * Copyright 2012 Canonical Ltd.
- * Copyright 2013 ALT Linux, Andrew V. Stepanov <stanv@altlinux.com>
- * Copyright 2018 Sahil Arora <sahilarora.535@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+//
+// Copyright 2012 Canonical Ltd.
+// Copyright 2013 ALT Linux, Andrew V. Stepanov <stanv@altlinux.com>
+// Copyright 2018 Sahil Arora <sahilarora.535@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License version 3, as published
+// by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranties of
+// MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>.
+//
#include <config.h>
#include "pdf.h"
#include <qpdf/QPDFAcroFormDocumentHelper.hh>
#include <qpdf/QPDFPageDocumentHelper.hh>
-/*
- * Useful reference:
- *
- * http://www.gnupdf.org/Indirect_Object
- * http://www.gnupdf.org/Introduction_to_PDF
- * http://blog.idrsolutions.com/2011/05/understanding-the-pdf-file-format-%E2%80%93-pdf-xref-tables-explained
- * http://labs.appligent.com/pdfblog/pdf-hello-world/
- * https://github.com/OpenPrinting/cups-filters/pull/25
-*/
-
-
-/**
- * '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 make_real_box(float values[4])
+//
+// Useful reference:
+//
+// http://www.gnupdf.org/Indirect_Object
+// http://www.gnupdf.org/Introduction_to_PDF
+// http://blog.idrsolutions.com/2011/05/understanding-the-pdf-file-format-%E2%80%93-pdf-xref-tables-explained
+// http://labs.appligent.com/pdfblog/pdf-hello-world/
+// https://github.com/OpenPrinting/cups-filters/pull/25
+//
+
+
+//
+// 'make_real_box()' - Return a QPDF array object of real values for a box.
+//
+
+static QPDFObjectHandle // O - QPDFObjectHandle for an array
+make_real_box(float values[4]) // I - Dimensions of the box in a float array
{
QPDFObjectHandle ret = QPDFObjectHandle::newArray();
- for (int i = 0; i < 4; ++i) {
+ for (int i = 0; i < 4; ++i)
ret.appendItem(QPDFObjectHandle::newReal(values[i]));
- }
- return ret;
+ return (ret);
}
-/**
- * 'cfPDFLoadTemplate()' - Load an existing PDF file and do initial parsing
- * using QPDF.
- * I - Filename to open
- */
-extern "C" cf_pdf_t * cfPDFLoadTemplate(const char *filename)
+//
+// 'cfPDFLoadTemplate()' - Load an existing PDF file and do initial parsing
+// using QPDF.
+//
+
+extern "C" cf_pdf_t *
+cfPDFLoadTemplate(const char *filename) // I - Filename to open
{
QPDF *pdf = new QPDF();
- try {
+
+ try
+ {
pdf->processFile(filename);
- } catch(...) {
+ }
+ catch(...)
+ {
delete pdf;
- return NULL;
+ return (NULL);
}
unsigned pages = (pdf->getAllPages()).size();
- if (pages != 1) {
+ if (pages != 1)
+ {
delete pdf;
- return NULL;
+ return (NULL);
}
- return pdf;
+ return (pdf);
}
-/**
- * 'cfPDFFree()' - Free pointer used by PDF object
- * I - Pointer to PDF object
- */
-extern "C" void cfPDFFree(cf_pdf_t *pdf)
+//
+// 'cfPDFFree()' - Free pointer used by PDF object
+//
+
+extern "C" void
+cfPDFFree(cf_pdf_t *pdf) // I - Pointer to PDF object
{
delete pdf;
}
-/*
- * 'cfPDFPages()' - Count number of pages in file
- * using QPDF.
- * I - Filename to open
- * O - Number of pages or -1 on error
- */
-int cfPDFPages(const char *filename)
+
+//
+// 'cfPDFPages()' - Count number of pages in file using QPDF.
+//
+
+int // O - Number of pages or -1 on error
+cfPDFPages(const char *filename) // I - Filename to open
{
QPDF *pdf = new QPDF();
- if (pdf) {
- try{
+
+ if (pdf)
+ {
+ try
+ {
pdf->processFile(filename);
- } catch(...) {
+ }
+ catch(...)
+ {
cfPDFFree(pdf);
- return -1;
+ return (-1);
}
int pages = (pdf->getAllPages()).size();
cfPDFFree(pdf);
- return pages;
+ return (pages);
} else
- return -1;
+ return (-1);
}
-/*
- * 'cfPDFPagesFP()' - Count number of pages in file
- * using QPDF.
- * I - Pointer to opened PDF file (stdio FILE*)
- * O - Number of pages or -1 on error
- */
-int cfPDFPagesFP(FILE *file)
+
+//
+// 'cfPDFPagesFP()' - Count number of pages in file
+// using QPDF.
+//
+
+int // O - Number of pages or -1 on error
+cfPDFPagesFP(FILE *file) // I - Pointer to opened PDF file (stdio FILE*)
{
QPDF *pdf = new QPDF();
- if (pdf) {
- try{
+
+ if (pdf)
+ {
+ try
+ {
pdf->processFile("", file, false);
- } catch(...) {
+ }
+ catch(...)
+ {
cfPDFFree(pdf);
- return -1;
+ return (-1);
}
int pages = (pdf->getAllPages()).size();
cfPDFFree(pdf);
- return pages;
+ return (pages);
} else
- return -1;
+ return (-1);
}
-/**
- * 'cfPDFPrependStream' - Prepend a stream to the contents of a specified
- * page in PDF file.
- * I - Pointer to QPDF object
- * I - page number of page to prepend stream to
- * I - buffer containing data to be prepended
- * I - length of buffer
- */
-extern "C" int cfPDFPrependStream(cf_pdf_t *pdf,
- unsigned page_num,
- char const *buf,
- size_t len)
+//
+// 'cfPDFPrependStream' - Prepend a stream to the contents of a specified
+// page in PDF file.
+//
+
+extern "C" int
+cfPDFPrependStream(cf_pdf_t *pdf, // I - Pointer to QPDF object
+ unsigned page_num, // I - page number of page to prepend
+ // stream to
+ char const *buf, // I - buffer containing data to be
+ // prepended
+ size_t len) // I - length of buffer
{
std::vector<QPDFObjectHandle> pages = pdf->getAllPages();
+
if (pages.empty() || page_num > pages.size())
return (1);
}
-/**
- * 'cfPDFAddType1Font()' - Add the specified type1 fontface to the specified
- * page in a PDF document.
- * I - QPDF object
- * I - page number of the page to which the font is to be added
- * I - name of the font to be added
- */
-extern "C" int cfPDFAddType1Font(cf_pdf_t *pdf,
- unsigned page_num,
- const char *name)
+//
+// 'cfPDFAddType1Font()' - Add the specified type1 fontface to the specified
+// page in a PDF document.
+//
+
+extern "C" int
+cfPDFAddType1Font(cf_pdf_t *pdf, // I - QPDF object
+ unsigned page_num, // I - Page number of the page to which
+ // the font is to be added
+ const char *name) // I - name of the font to be added
{
std::vector<QPDFObjectHandle> pages = pdf->getAllPages();
+
if (pages.empty() || page_num > pages.size())
return (1);
font.replaceKey("/Type", QPDFObjectHandle::newName("/Font"));
font.replaceKey("/Subtype", QPDFObjectHandle::newName("/Type1"));
font.replaceKey("/BaseFont",
- QPDFObjectHandle::newName(std::string("/") + std::string(name)));
+ QPDFObjectHandle::newName(std::string("/") +
+ std::string(name)));
QPDFObjectHandle fonts = resources.getKey("/Font");
if (fonts.isNull())
- {
fonts = QPDFObjectHandle::newDictionary();
- }
else if (!fonts.isDictionary())
return (1);
}
-/**
- * 'dict_lookup_rect()' - Lookup for an array of rectangle dimensions in a QPDF
- * dictionary object. If it is found, store the values in
- * an array and return true, else return false.
- * O - True / False, depending on whether the key is found in the dictionary
- * I - PDF dictionary object
- * I - Key to lookup for
- * I - array to store values if key is found
- */
-static bool dict_lookup_rect(QPDFObjectHandle object,
- std::string const& key,
- float rect[4],
- bool inheritable)
+//
+// 'dict_lookup_rect()' - Lookup for an array of rectangle dimensions in a QPDF
+// dictionary object. If it is found, store the values in
+// an array and return true, else return false.
+//
+
+static bool
+dict_lookup_rect(QPDFObjectHandle object, // O - Key is found in the dictionary?
+ std::string const& key, // I - PDF dictionary object
+ float rect[4], // I - Key to lookup
+ bool inheritable) // I - Array to store values if key
+ // is found
{
// preliminary checks
if (!object.isDictionary())
- return false;
+ return (false);
QPDFObjectHandle value;
- if (!object.hasKey(key) && inheritable){
+ if (!object.hasKey(key) && inheritable)
+ {
QPDFFormFieldObjectHelper helper(object);
value = helper.getInheritableFieldValue(key);
- if (value.isNull()) {
- return false;
- }
- } else {
- value = object.getKey(key);
+ if (value.isNull())
+ return (false);
}
+ else
+ value = object.getKey(key);
// check if the key is array or some other type
if (!value.isArray())
- return false;
+ return (false);
// get values in a vector and assign it to rect
std::vector<QPDFObjectHandle> array = value.getArrayAsVector();
- for (int i = 0; i < 4; ++i) {
+ for (int i = 0; i < 4; ++i)
+ {
// if the value in the array is not real, we have an invalid array
if (!array[i].isReal() && !array[i].isInteger())
- return false;
+ return (false);
rect[i] = array[i].getNumericValue();
}
- return array.size() == 4;
+ return (array.size() == 4);
}
-/**
- * 'fit_rect()' - Update the scale of the page using old media box dimensions
- * and new media box dimensions.
- * I - Old media box
- * I - New media box
- * I - Pointer to scale which needs to be updated
- */
-static void fit_rect(float oldrect[4],
- float newrect[4],
- float *scale)
+//
+// 'fit_rect()' - Update the scale of the page using old media box dimensions
+// and new media box dimensions.
+//
+
+static void
+fit_rect(float oldrect[4], // I - Old media box
+ float newrect[4], // I - New media box
+ float *scale) // I - Pointer to scale which needs to be updated
{
float oldwidth = oldrect[2] - oldrect[0];
float oldheight = oldrect[3] - oldrect[1];
}
-/**
- * 'cfPDFResizePage()' - Resize page in a PDF with the given dimensions.
- * I - Pointer to QPDF object
- * I - Page number
- * I - Width of page to set
- * I - Length of page to set
- * I - Scale of page to set
- */
-extern "C" int cfPDFResizePage (cf_pdf_t *pdf,
- unsigned page_num,
- float width,
- float length,
- float *scale)
+//
+// 'cfPDFResizePage()' - Resize page in a PDF with the given dimensions.
+//
+
+extern "C" int
+cfPDFResizePage(cf_pdf_t *pdf, // I - Pointer to QPDF object
+ unsigned page_num, // I - Page number
+ float width, // I - Width of page to set
+ float length, // I - Length of page to set
+ float *scale) // I - Scale of page to set
{
std::vector<QPDFObjectHandle> pages = pdf->getAllPages();
+
if (pages.empty() || page_num > pages.size())
return (1);
}
-/**
- * 'cfPDFDuplicatePage()' - Duplicate a specified pdf page in a PDF
- * I - Pointer to QPDF object
- * I - page number of the page to be duplicated
- * I - number of copies to be duplicated
- */
-extern "C" int cfPDFDuplicatePage (cf_pdf_t *pdf,
- unsigned page_num,
- unsigned count)
+//
+// 'cfPDFDuplicatePage()' - Duplicate a specified pdf page in a PDF
+//
+
+extern "C" int
+cfPDFDuplicatePage (cf_pdf_t *pdf, // I - Pointer to QPDF object
+ unsigned page_num, // I - Page number of the page to be
+ // duplicated
+ unsigned count) // I - Number of copies to be duplicated
{
std::vector<QPDFObjectHandle> pages = pdf->getAllPages();
+
if (pages.empty() || page_num > pages.size())
return (1);
}
-/**
- * 'cfPDFWrite()' - Write the contents of PDF object to an already open FILE*.
- * I - pointer to QPDF structure
- * I - File pointer to write to
- */
-extern "C" void cfPDFWrite(cf_pdf_t *pdf, FILE *file)
+//
+// 'cfPDFWrite()' - Write the contents of PDF object to an already open FILE*.
+//
+
+extern "C" void
+cfPDFWrite(cf_pdf_t *pdf, // I - Pointer to QPDF structure
+ FILE *file) // I - File pointer to write to
{
QPDFWriter output(*pdf, "cfPDFWrite", file, false);
output.write();
}
+//
+// 'lookup_opt()' - Get value according to key in the options list.
+//
-/*
- * 'lookup_opt()' - Get value according to key in the options list.
- * I - pointer to the cf_opt_t type list
- * I - key to be found in the list
- * O - character string which corresponds to the value of the key or
- * NULL if key is not found in the list.
- */
-static std::string lookup_opt(cf_opt_t *opt, std::string const& key) {
- if ( ! opt || key.empty() ) {
- return "";
- }
+static std::string // O - character string which corresponds
+ // to the value of the key or NULL if
+ // key is not found in the list.
+lookup_opt(cf_opt_t *opt, // I - pointer to the cf_opt_t type list
+ std::string const& key) // I - key to be found in the list
+{
+ if (!opt || key.empty())
+ return ("");
- while (opt) {
- if (opt->key && opt->val) {
- if ( strcmp(opt->key, key.c_str()) == 0 ) {
- return std::string(opt->val);
- }
- }
- opt = opt->next;
+ while (opt)
+ {
+ if (opt->key && opt->val)
+ {
+ if (strcmp(opt->key, key.c_str()) == 0)
+ return (std::string(opt->val));
}
+ opt = opt->next;
+ }
- return "";
+ return ("");
}
-/*
- * 'cfPDFFillForm()' - 1. Lookup in PDF template file for form.
- * 2. Lookup for form fields' names.
- * 3. Fill recognized fields with information.
- * I - Pointer to the QPDF structure
- * I - Pointer to the cf_opt_t type list
- * O - status of form fill - 0 for success, 1 for failure
- */
-extern "C" int cfPDFFillForm(cf_pdf_t *doc, cf_opt_t *opt)
+//
+// 'cfPDFFillForm()' - 1. Look for form in PDF template file
+// 2. Look for form fields' names
+// 3. Fill recognized fields with information
+//
+
+extern "C" int // O - Status of form fill - 0 for success,
+ // 1 for failure
+cfPDFFillForm(cf_pdf_t *doc, // I - Pointer to the QPDF structure
+ cf_opt_t *opt) // I - Pointer to the cf_opt_t type list
{
- // initialize AcroFormDocumentHelper and PageDocumentHelper objects
- // to work with forms in the PDF
- QPDFAcroFormDocumentHelper afdh(*doc);
- QPDFPageDocumentHelper pdh(*doc);
-
- // check if the PDF has a form or not
- if (!afdh.hasAcroForm())
- return 1;
-
- // get the first page from the PDF to fill the form. Since this
- // is a banner file,it must contain only a single page, and that
- // check has already been performed in the `cfPDFLoadTemplate()` function
- std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
- if (pages.empty())
- return 1;
- QPDFPageObjectHelper page = pages.front();
-
- // get the annotations in the page
- std::vector<QPDFAnnotationObjectHelper> annotations =
- afdh.getWidgetAnnotationsForPage(page);
-
- for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter =
- annotations.begin();
- annot_iter != annotations.end(); ++annot_iter) {
- // For each annotation, find its associated field. If it's a
- // text field, we try to set its value. This will automatically
- // update the document to indicate that appearance streams need
- // to be regenerated. At the time of this writing, qpdf doesn't
- // have any helper code to assist with appearance stream generation,
- // though there's nothing that prevents it from being possible.
- QPDFFormFieldObjectHelper ffh =
- afdh.getFieldForAnnotation(*annot_iter);
- if (ffh.getFieldType() == "/Tx") {
- // Lookup the options setting for value of this field and fill the
- // value accordingly. This will automatically set
- // /NeedAppearances to true.
- std::string const name = ffh.getFullyQualifiedName();
- std::string fill_with = lookup_opt(opt, name);
- if (fill_with.empty()) {
- std::cerr << "DEBUG: Lack information for widget: " << name << ".\n";
- fill_with = "N/A";
- }
-
- // convert the 'fill_with' string to UTF16 before filling to the widget
- QPDFObjectHandle fill_with_utf_16 = QPDFObjectHandle::newUnicodeString(fill_with);
- ffh.setV(fill_with_utf_16);
- std::cerr << "DEBUG: Fill widget name " << name << " with value "
- << fill_with_utf_16.getUTF8Value() << ".\n";
- }
+ // Initialize AcroFormDocumentHelper and PageDocumentHelper objects
+ // to work with forms in the PDF
+ QPDFAcroFormDocumentHelper afdh(*doc);
+ QPDFPageDocumentHelper pdh(*doc);
+
+ // Check if the PDF has a form or not
+ if (!afdh.hasAcroForm())
+ return 1;
+
+ // Get the first page from the PDF to fill the form. Since this
+ // is a banner file, it must contain only a single page, and that
+ // check has already been performed in the `cfPDFLoadTemplate()` function
+ std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
+ if (pages.empty())
+ return 1;
+ QPDFPageObjectHelper page = pages.front();
+
+ // Get the annotations in the page
+ std::vector<QPDFAnnotationObjectHelper> annotations =
+ afdh.getWidgetAnnotationsForPage(page);
+
+ for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter =
+ annotations.begin();
+ annot_iter != annotations.end();
+ ++annot_iter)
+ {
+ // For each annotation, find its associated field. If it's a
+ // text field, we try to set its value. This will automatically
+ // update the document to indicate that appearance streams need
+ // to be regenerated. At the time of this writing, QPDF doesn't
+ // have any helper code to assist with appearance stream generation,
+ // though there's nothing that prevents it from being possible.
+ QPDFFormFieldObjectHelper ffh =
+ afdh.getFieldForAnnotation(*annot_iter);
+ if (ffh.getFieldType() == "/Tx")
+ {
+ // Look in the options setting for the value of this field and fill the
+ // value accordingly. This will automatically set /NeedAppearances to
+ // true.
+ std::string const name = ffh.getFullyQualifiedName();
+ std::string fill_with = lookup_opt(opt, name);
+ if (fill_with.empty())
+ {
+ std::cerr << "DEBUG: Lack information for widget: " << name << ".\n";
+ fill_with = "N/A";
+ }
+
+ // Convert the 'fill_with' string to UTF16 before filling to the widget
+ QPDFObjectHandle fill_with_utf_16 =
+ QPDFObjectHandle::newUnicodeString(fill_with);
+ ffh.setV(fill_with_utf_16);
+ std::cerr << "DEBUG: Fill widget name " << name << " with value "
+ << fill_with_utf_16.getUTF8Value() << ".\n";
}
+ }
- // status 0 notifies that the function successfully filled all the
- // identifiable fields in the form
- return 0;
+ // Status 0 notifies that the function successfully filled all the
+ // identifiable fields in the form
+ return (0);
}
-/*
- * Copyright 2012 Canonical Ltd.
- * Copyright 2018 Sahil Arora <sahilarora.535@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+//
+// Copyright 2012 Canonical Ltd.
+// Copyright 2018 Sahil Arora <sahilarora.535@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License version 3, as published
+// by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranties of
+// MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>.
+//
#ifndef _CUPS_FILTERS_PDF_H_
#define _CUPS_FILTERS_PDF_H_
typedef struct _cf_opt cf_opt_t;
-/*
- * Type to bunch PDF form field name and its value.
- */
-struct _cf_opt {
+//
+// Type to bunch PDF form field name and its value.
+//
+
+struct _cf_opt
+{
const char* key;
const char* val;
cf_opt_t *next;
}
#endif
-#endif /* !_CUPS_FILTERS_PDF_H_ */
+#endif // !_CUPS_FILTERS_PDF_H_
-/*
-Copyright (c) 2008-2011 BBR Inc. All rights reserved.
-Copyright (c) 2012-2019 by Till Kamppeter
-Copyright (c) 2019 by Tanmay Anand.
-Modified 2021 by Pratyush Ranjan.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-*/
-/*
- pdftoraster.cxx
- pdf to raster filter function
-*/
+//
+// Copyright (c) 2008-2011 BBR Inc. All rights reserved.
+// Copyright (c) 2012-2019 by Till Kamppeter
+// Copyright (c) 2019 by Tanmay Anand.
+// Modified 2021 by Pratyush Ranjan.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+//
+// pdftoraster.cxx
+// pdf to raster filter function
+//
#include "colormanager.h"
#include "image.h"
typedef struct cms_profile_s
{
- /* for color profiles */
+ // for color profiles
cmsHPROFILE colorProfile = NULL;
cmsHPROFILE popplerColorProfile = NULL;
cmsHTRANSFORM colorTransform = NULL;
} cms_profile_t;
typedef struct pdftoraster_doc_s
-{ /**** Document information ****/
+{ // **** Document information ****
int pwgraster = 0;
int bi_level = 0;
bool allocLineBuf = false;
unsigned int bitmapoffset[2];
poppler::document *poppler_doc;
cups_page_header2_t header;
- cf_logfunc_t logfunc; /* Logging function, NULL for no
- logging */
- void *logdata; /* User data for logging function, can
- be NULL */
- cups_file_t *inputfp; /* Temporary file, if any */
- FILE *outputfp; /* Temporary file, if any */
+ cf_logfunc_t logfunc; // Logging function, NULL for no
+ // logging
+ void *logdata; // User data for logging function, can
+ // be NULL
+ cups_file_t *inputfp; // Temporary file, if any
+ FILE *outputfp; // Temporary file, if any
bool swap_image_x = false;
bool swap_image_y = false;
- /* margin swapping */
+ // margin swapping
bool swap_margin_x = false;
bool swap_margin_y = false;
unsigned int nplanes;
unsigned int nbands;
- unsigned int bytesPerLine; /* number of bytes per line */
- /* Note: When CUPS_ORDER_BANDED,
- cupsBytesPerLine = bytesPerLine*cupsNumColors */
+ unsigned int bytesPerLine; // number of bytes per line
+ // Note: When CUPS_ORDER_BANDED,
+ // cupsBytesPerLine = bytesPerLine * cupsNumColors
cms_profile_t colour_profile;
} pdftoraster_doc_t;
typedef unsigned char *(*convert_cspace_func)(unsigned char *src,
- unsigned char *pixelBuf,
- unsigned int x,
- unsigned int y,
- pdftoraster_doc_t* doc);
+ unsigned char *pixelBuf,
+ unsigned int x,
+ unsigned int y,
+ pdftoraster_doc_t* doc);
+
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,
- convert_cspace_func convertCSpace);
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int plane,
+ unsigned int pixels,
+ unsigned int size,
+ pdftoraster_doc_t* doc,
+ convert_cspace_func convertCSpace);
typedef struct conversion_function_s
{
- convert_cspace_func convertCSpace; /* Function for conversion of colorspaces */
- convert_line_func convertLineOdd;/* Function tom modify raster data of a line */
+ 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;
+
static cmsCIExyY adobergb_wp()
{
- double * xyY = cfCmWhitePointAdobeRGB();
- cmsCIExyY wp;
+ double * xyY = cfCmWhitePointAdobeRGB();
+ cmsCIExyY wp;
- wp.x = xyY[0];
- wp.y = xyY[1];
- wp.Y = xyY[2];
+ wp.x = xyY[0];
+ wp.y = xyY[1];
+ wp.Y = xyY[2];
- return wp;
+ return (wp);
}
+
static cmsCIExyY sgray_wp()
{
- double * xyY = cfCmWhitePointSGray();
- cmsCIExyY wp;
+ double * xyY = cfCmWhitePointSGray();
+ cmsCIExyY wp;
- wp.x = xyY[0];
- wp.y = xyY[1];
- wp.Y = xyY[2];
+ wp.x = xyY[0];
+ wp.y = xyY[1];
+ wp.Y = xyY[2];
- return wp;
+ return (wp);
}
+
static cmsCIExyYTRIPLE adobergb_matrix()
{
- cmsCIExyYTRIPLE m;
+ cmsCIExyYTRIPLE m;
- double * matrix = cfCmMatrixAdobeRGB();
+ double * matrix = cfCmMatrixAdobeRGB();
- m.Red.x = matrix[0];
- m.Red.y = matrix[1];
- m.Red.Y = matrix[2];
- m.Green.x = matrix[3];
- m.Green.y = matrix[4];
- m.Green.Y = matrix[5];
- m.Blue.x = matrix[6];
- m.Blue.y = matrix[7];
- m.Blue.Y = matrix[8];
+ m.Red.x = matrix[0];
+ m.Red.y = matrix[1];
+ m.Red.Y = matrix[2];
+ m.Green.x = matrix[3];
+ m.Green.y = matrix[4];
+ m.Green.Y = matrix[5];
+ m.Blue.x = matrix[6];
+ m.Blue.y = matrix[7];
+ m.Blue.Y = matrix[8];
- return m;
+ return (m);
}
-static cmsHPROFILE adobergb_profile()
+
+static cmsHPROFILE
+adobergb_profile()
{
- cmsHPROFILE adobergb;
+ cmsHPROFILE adobergb;
- cmsCIExyY wp;
- cmsCIExyYTRIPLE primaries;
+ cmsCIExyY wp;
+ cmsCIExyYTRIPLE primaries;
#if USE_LCMS1
- cmsToneCurve Gamma = cmsBuildGamma(256, 2.2);
- cmsToneCurve Gamma3[3];
+ cmsToneCurve Gamma = cmsBuildGamma(256, 2.2);
+ cmsToneCurve Gamma3[3];
#else
- cmsToneCurve * Gamma = cmsBuildGamma(NULL, 2.2);
- cmsToneCurve * Gamma3[3];
+ cmsToneCurve * Gamma = cmsBuildGamma(NULL, 2.2);
+ cmsToneCurve * Gamma3[3];
#endif
- Gamma3[0] = Gamma3[1] = Gamma3[2] = Gamma;
+ Gamma3[0] = Gamma3[1] = Gamma3[2] = Gamma;
- // Build AdobeRGB profile
- primaries = adobergb_matrix();
- wp = adobergb_wp();
- adobergb = cmsCreateRGBProfile(&wp, &primaries, Gamma3);
+ // Build AdobeRGB profile
+ primaries = adobergb_matrix();
+ wp = adobergb_wp();
+ adobergb = cmsCreateRGBProfile(&wp, &primaries, Gamma3);
- return adobergb;
+ return (adobergb);
}
-static cmsHPROFILE sgray_profile()
+
+static cmsHPROFILE
+sgray_profile()
{
cmsHPROFILE sgray;
wp = sgray_wp();
sgray = cmsCreateGrayProfile(&wp, Gamma);
- return sgray;
+ return (sgray);
}
#ifdef USE_LCMS1
-static int lcms_error_handler(int ErrorCode, const char *ErrorText)
+static int
+lcms_error_handler(int ErrorCode,
+ const char *ErrorText)
{
return 1;
}
#else
-static void lcms_error_handler(cmsContext contextId, cmsUInt32Number ErrorCode,
- const char *ErrorText)
+static void
+lcms_error_handler(cmsContext contextId,
+ cmsUInt32Number ErrorCode,
+ const char *ErrorText)
{
return;
}
#endif
-static int parse_opts(cf_filter_data_t *data,
- cf_filter_out_format_t *outformat,
- pdftoraster_doc_t *doc)
+
+static int
+parse_opts(cf_filter_data_t *data,
+ cf_filter_out_format_t *outformat,
+ pdftoraster_doc_t *doc)
{
int num_options = 0;
cups_option_t *options = NULL;
memset(&(doc->header), 0, sizeof(doc->header));
cfRasterPrepareHeader(&(doc->header), data, *outformat,
- (*outformat == CF_FILTER_OUT_FORMAT_PWG_RASTER ||
- *outformat == CF_FILTER_OUT_FORMAT_APPLE_RASTER ?
- *outformat :
- (*outformat == CF_FILTER_OUT_FORMAT_PCLM ?
- CF_FILTER_OUT_FORMAT_PWG_RASTER :
- CF_FILTER_OUT_FORMAT_CUPS_RASTER)), 0,
- &cspace);
+ (*outformat == CF_FILTER_OUT_FORMAT_PWG_RASTER ||
+ *outformat == CF_FILTER_OUT_FORMAT_APPLE_RASTER ?
+ *outformat :
+ (*outformat == CF_FILTER_OUT_FORMAT_PCLM ?
+ CF_FILTER_OUT_FORMAT_PWG_RASTER :
+ CF_FILTER_OUT_FORMAT_CUPS_RASTER)), 0,
+ &cspace);
doc->header.cupsRenderingIntent[0] = '\0';
cfGetPrintRenderIntent(data, doc->header.cupsRenderingIntent,
if (doc->header.Duplex)
{
int backside;
- /* analyze options relevant to Duplex */
- /* APDuplexRequiresFlippedMargin */
- enum {
+ // analyze options relevant to Duplex
+ // APDuplexRequiresFlippedMargin
+ enum
+ {
FM_NO,
FM_FALSE,
FM_TRUE
if (flippedMargin == FM_TRUE)
doc->swap_margin_y = false;
}
- else if (backside==CF_BACKSIDE_ROTATED && !doc->header.Tumble)
+ else if (backside == CF_BACKSIDE_ROTATED && !doc->header.Tumble)
{
doc->swap_image_x = doc->swap_image_y = true;
doc->swap_margin_x = doc->swap_margin_y = true;
if (flippedMargin == FM_TRUE)
doc->swap_margin_y = false;
}
- else if (backside==CF_BACKSIDE_FLIPPED)
+ else if (backside == CF_BACKSIDE_FLIPPED)
{
if (doc->header.Tumble)
{
}
}
- /* support the CUPS "cm-calibration" option */
+ // support the CUPS "cm-calibration" option
doc->colour_profile.cm_calibrate = cfCmGetCupsColorCalibrateMode(data);
if (doc->colour_profile.cm_calibrate == CF_CM_CALIBRATION_ENABLED)
return (0);
}
-static void parse_pdftopdf_comment(FILE *fp, int* deviceCopies, bool* deviceCollate)
+
+static void
+parse_pdftopdf_comment(FILE *fp,
+ int* deviceCopies,
+ bool* deviceCollate)
{
char buf[4096];
int i;
- /* skip until PDF start header */
- while (fgets(buf,sizeof(buf),fp) != 0) {
- if (strncmp(buf,"%PDF",4) == 0) {
+ // skip until PDF start header
+ while (fgets(buf, sizeof(buf), fp) != 0)
+ if (strncmp(buf, "%PDF", 4) == 0)
break;
- }
- }
- for (i = 0;i < MAX_CHECK_COMMENT_LINES;i++) {
- if (fgets(buf,sizeof(buf),fp) == 0) break;
- if (strncmp(buf,"%%PDFTOPDFNumCopies",19) == 0) {
+
+ for (i = 0; i < MAX_CHECK_COMMENT_LINES; i ++)
+ {
+ if (fgets(buf, sizeof(buf), fp) == 0)
+ break;
+ if (strncmp(buf, "%%PDFTOPDFNumCopies", 19) == 0)
+ {
char *p;
- p = strchr(buf+19,':');
- (*deviceCopies) = atoi(p+1);
- } else if (strncmp(buf,"%%PDFTOPDFCollate",17) == 0) {
+ p = strchr(buf + 19, ':');
+ (*deviceCopies) = atoi(p + 1);
+ }
+ else if (strncmp(buf, "%%PDFTOPDFCollate", 17) == 0)
+ {
char *p;
- p = strchr(buf+17,':');
- while (*p == ' ' || *p == '\t') p++;
- if (strncasecmp(p,"true",4) == 0) {
+ p = strchr(buf + 17, ':');
+ while (*p == ' ' || *p == '\t') p ++;
+ if (strncasecmp(p, "true", 4) == 0)
*deviceCollate = true;
- } else {
+ else
*deviceCollate = false;
- }
}
}
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
unsigned char *p = src;
- for (unsigned int j = 0;j < size;j++,p++) {
+ for (unsigned int j = 0; j < size; j ++, p ++)
*p = ~*p;
- }
- return src;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+size-1;
+ unsigned char *bp = src + size - 1;
unsigned char *dp = dst;
- for (unsigned int j = 0;j < size;j++,bp--,dp++) {
+ for (unsigned int j = 0; j < size; j ++, bp --, dp ++)
*dp = ~*bp;
- }
- return dst;
+ return (dst);
}
-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, convert_cspace_func convertCSpace)
+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,
+ convert_cspace_func convertCSpace)
{
dst = cfReverseOneBitLineSwap(src, dst, pixels, size);
- return dst;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- cfImageRGBToCMYK(src,dst,pixels);
- return dst;
+ cfImageRGBToCMYK(src, dst, pixels);
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+(pixels-1)*3;
+ unsigned char *bp = src + (pixels - 1) * 3;
unsigned char *dp = dst;
- for (unsigned int i = 0;i < pixels;i++, bp -= 3, dp += 4) {
- cfImageRGBToCMYK(bp,dp,1);
- }
- return dst;
+ for (unsigned int i = 0; i < pixels; i++, bp -= 3, dp += 4)
+ cfImageRGBToCMYK(bp, dp, 1);
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- cfImageRGBToCMY(src,dst,pixels);
- return dst;
+ cfImageRGBToCMY(src, dst, pixels);
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+size-3;
+ unsigned char *bp = src + size - 3;
unsigned char *dp = dst;
- for (unsigned int i = 0;i < pixels;i++, bp -= 3, dp += 3) {
- cfImageRGBToCMY(bp,dp,1);
- }
- return dst;
+ for (unsigned int i = 0; i < pixels; i++, bp -= 3, dp += 3)
+ cfImageRGBToCMY(bp, dp, 1);
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
unsigned char *bp = src;
unsigned char *dp = dst;
unsigned char d;
- cfImageRGBToCMYK(src,dst,pixels);
- /* CMYK to KCMY */
- for (unsigned int i = 0;i < pixels;i++, bp += 3, dp += 4) {
+ cfImageRGBToCMYK(src, dst, pixels);
+ // CMYK to KCMY
+ for (unsigned int i = 0; i < pixels; i++, bp += 3, dp += 4)
+ {
d = dp[3];
dp[3] = dp[2];
dp[2] = dp[1];
dp[1] = dp[0];
dp[0] = d;
}
- return dst;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+(pixels-1)*3;
+ unsigned char *bp = src + (pixels - 1) * 3;
unsigned char *dp = dst;
unsigned char d;
- for (unsigned int i = 0;i < pixels;i++, bp -= 3, dp += 4) {
- cfImageRGBToCMYK(bp,dp,1);
- /* CMYK to KCMY */
+ for (unsigned int i = 0; i < pixels; i++, bp -= 3, dp += 4)
+ {
+ cfImageRGBToCMYK(bp, dp, 1);
+ // CMYK to KCMY
d = dp[3];
dp[3] = dp[2];
dp[2] = dp[1];
dp[1] = dp[0];
dp[0] = d;
}
- return dst;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- /* do nothing */
- return src;
+ // do nothing
+ return (src);
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+size-3;
+ unsigned char *bp = src + size - 3;
unsigned char *dp = dst;
- for (unsigned int i = 0;i < pixels;i++, bp -= 3, dp += 3) {
+ for (unsigned int i = 0; i < pixels; i++, bp -= 3, dp += 3)
+ {
dp[0] = bp[0];
dp[1] = bp[1];
dp[2] = bp[2];
}
- return dst;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+size-1;
+ unsigned char *bp = src + size - 1;
unsigned char *dp = dst;
- for (unsigned int j = 0;j < size;j++,bp--,dp++) {
+ for (unsigned int j = 0; j < size; j++, bp --, dp ++)
*dp = *bp;
- }
- return dst;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
dst = cfReverseOneBitLine(src, dst, pixels, size);
- return dst;
+ return (dst);
}
-typedef struct func_table_s {
+
+typedef struct func_table_s
+{
enum cups_cspace_e cspace;
unsigned int bitsPerPixel;
unsigned int bitsPerColor;
bool allocLineBufSwap;
} 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 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 *convert_cspace_none(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc)
+
+static unsigned char *
+convert_cspace_none(unsigned char *src,
+ unsigned char *pixelBuf,
+ unsigned int x,
+ unsigned int y,
+ pdftoraster_doc_t *doc)
{
- return src;
+ return (src);
}
-static unsigned char *convert_cspace_with_profiles(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc)
+
+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;
+ cmsDoTransform(doc->colour_profile.colorTransform, src, pixelBuf, 1);
+ return (pixelBuf);
}
-static unsigned char *convert_cspace_xyz_8(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc)
+
+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];
- cmsDoTransform(doc->colour_profile.colorTransform,src,alab,1);
+ cmsDoTransform(doc->colour_profile.colorTransform, src, alab, 1);
cmsCIELab lab;
cmsCIEXYZ xyz;
lab.a = alab[1];
lab.b = alab[2];
- cmsLab2XYZ(&(doc->colour_profile.D65WhitePoint),&xyz,&lab);
- pixelBuf[0] = 231.8181*xyz.X+0.5;
- pixelBuf[1] = 231.8181*xyz.Y+0.5;
- pixelBuf[2] = 231.8181*xyz.Z+0.5;
- return pixelBuf;
+ cmsLab2XYZ(&(doc->colour_profile.D65WhitePoint), &xyz, &lab);
+ pixelBuf[0] = 231.8181 * xyz.X + 0.5;
+ pixelBuf[1] = 231.8181 * xyz.Y + 0.5;
+ pixelBuf[2] = 231.8181 * xyz.Z + 0.5;
+ return (pixelBuf);
}
-static unsigned char *convert_cspace_xyz_16(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc)
+
+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];
unsigned short *sd = (unsigned short *)pixelBuf;
- cmsDoTransform(doc->colour_profile.colorTransform,src,alab,1);
+ cmsDoTransform(doc->colour_profile.colorTransform, src, alab, 1);
cmsCIELab lab;
cmsCIEXYZ xyz;
lab.a = alab[1];
lab.b = alab[2];
- cmsLab2XYZ(&(doc->colour_profile.D65WhitePoint),&xyz,&lab);
- sd[0] = 59577.2727*xyz.X+0.5;
- sd[1] = 59577.2727*xyz.Y+0.5;
- sd[2] = 59577.2727*xyz.Z+0.5;
- return pixelBuf;
+ cmsLab2XYZ(&(doc->colour_profile.D65WhitePoint), &xyz, &lab);
+ sd[0] = 59577.2727 * xyz.X + 0.5;
+ sd[1] = 59577.2727 * xyz.Y + 0.5;
+ sd[2] = 59577.2727 * xyz.Z + 0.5;
+ return (pixelBuf);
}
-static unsigned char *convert_cspace_lab_8(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc)
+
+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];
- cmsDoTransform(doc->colour_profile.colorTransform ,src,lab,1);
- pixelBuf[0] = 2.55*lab[0]+0.5;
- pixelBuf[1] = lab[1]+128.5;
- pixelBuf[2] = lab[2]+128.5;
- return pixelBuf;
+
+ cmsDoTransform(doc->colour_profile.colorTransform , src, lab, 1);
+ pixelBuf[0] = 2.55 * lab[0] + 0.5;
+ pixelBuf[1] = lab[1] + 128.5;
+ pixelBuf[2] = lab[2] + 128.5;
+ return (pixelBuf);
}
-static unsigned char *convert_cspace_lab_16(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pdftoraster_doc_t *doc)
+
+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];
- cmsDoTransform(doc->colour_profile.colorTransform,src,lab,1);
+
+ cmsDoTransform(doc->colour_profile.colorTransform, src, lab, 1);
unsigned short *sd = (unsigned short *)pixelBuf;
- sd[0] = 655.35*lab[0]+0.5;
- sd[1] = 256*(lab[1]+128)+0.5;
- sd[2] = 256*(lab[2]+128)+0.5;
- return pixelBuf;
+ sd[0] = 655.35 * lab[0] + 0.5;
+ sd[1] = 256 * (lab[1] + 128) + 0.5;
+ sd[2] = 256 * (lab[2] + 128) + 0.5;
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_rgba(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pdftoraster_doc_t* doc)
+
+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;
- for (int i = 0;i < 3;i++) {
+ for (int i = 0; i < 3; i ++)
*dp++ = *src++;
- }
*dp = 255;
- return pixelBuf;
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_rgbw(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pdftoraster_doc_t* doc)
+
+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];
unsigned char *dp = pixelBuf;
- cfImageRGBToCMYK(src,cmyk,1);
- for (int i = 0;i < 4;i++) {
+ cfImageRGBToCMYK(src, cmyk, 1);
+ for (int i = 0; i < 4; i ++)
*dp++ = ~cmyk[i];
- }
- return pixelBuf;
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_cmyk(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pdftoraster_doc_t* doc)
+
+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;
+ cfImageRGBToCMYK(src, pixelBuf, 1);
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_cmy(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pdftoraster_doc_t* doc)
+
+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;
+ cfImageRGBToCMY(src, pixelBuf, 1);
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_ymc(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pdftoraster_doc_t* doc)
+
+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);
- /* swap C and Y */
+ cfImageRGBToCMY(src, pixelBuf, 1);
+ // swap C and Y
unsigned char d = pixelBuf[0];
pixelBuf[0] = pixelBuf[2];
pixelBuf[2] = d;
- return pixelBuf;
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_kcmy(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pdftoraster_doc_t* doc)
+
+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);
+ cfImageRGBToCMYK(src, pixelBuf, 1);
unsigned char d = pixelBuf[3];
pixelBuf[3] = pixelBuf[2];
pixelBuf[2] = pixelBuf[1];
pixelBuf[1] = pixelBuf[0];
pixelBuf[0] = d;
- return pixelBuf;
+ return (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)
+
+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);
+ return (cfRGB8toKCMYcm(src, pixelBuf, x, y));
}
-static unsigned char *rgb_8_to_ymck(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pdftoraster_doc_t* doc)
+
+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);
- /* swap C and Y */
+ cfImageRGBToCMYK(src, pixelBuf, 1);
+ // swap C and Y
unsigned char d = pixelBuf[0];
pixelBuf[0] = pixelBuf[2];
pixelBuf[2] = d;
- return pixelBuf;
+ return (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)
+
+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;
+ return (pixelBuf);
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- /* Assumed that BitsPerColor is 8 */
- for (unsigned int i = 0;i < pixels;i++) {
- unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
- unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
- unsigned char *pb;
-
- pb = convertCSpace(src+i*(doc->popplerNumColors),pixelBuf1,i,row, doc);
- pb = cfConvertBits(pb,pixelBuf2,i,row, doc->header.cupsNumColors, doc->bitspercolor);
- cfWritePixel(dst,0,i,pb, doc->header.cupsNumColors, doc->header.cupsBitsPerColor, doc->header.cupsColorOrder);
+ // Assumed that BitsPerColor is 8
+ for (unsigned int i = 0; i < pixels; i ++)
+ {
+ unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
+ unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
+ unsigned char *pb;
+
+ pb = convertCSpace(src + i * (doc->popplerNumColors), pixelBuf1, i,
+ row, doc);
+ pb = cfConvertBits(pb, pixelBuf2, i, row, doc->header.cupsNumColors,
+ doc->bitspercolor);
+ cfWritePixel(dst, 0, i, pb, doc->header.cupsNumColors,
+ doc->header.cupsBitsPerColor, doc->header.cupsColorOrder);
}
- return dst;
+ return (dst);
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- /* Assumed that BitsPerColor is 8 */
- for (unsigned int i = 0;i < pixels;i++) {
- unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
- unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
- unsigned char *pb;
-
- pb = convertCSpace(src+(pixels-i-1)*(doc->popplerNumColors),pixelBuf1,i,row, doc);
- pb = cfConvertBits(pb,pixelBuf2,i,row, doc->header.cupsNumColors, doc->bitspercolor);
- cfWritePixel(dst,0,i,pb, doc->header.cupsNumColors, doc->header.cupsBitsPerColor, doc->header.cupsColorOrder);
+ // Assumed that BitsPerColor is 8
+ for (unsigned int i = 0; i < pixels; i++)
+ {
+ unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
+ unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
+ unsigned char *pb;
+
+ pb = convertCSpace(src + (pixels - i - 1) * doc->popplerNumColors,
+ pixelBuf1, i, row, doc);
+ pb = cfConvertBits(pb, pixelBuf2, i, row, doc->header.cupsNumColors,
+ doc->bitspercolor);
+ cfWritePixel(dst, 0, i, pb, doc->header.cupsNumColors,
+ doc->header.cupsBitsPerColor, doc->header.cupsColorOrder);
}
- return dst;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- /* Assumed that BitsPerColor is 8 */
- for (unsigned int i = 0;i < pixels;i++) {
- unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
- unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
- unsigned char *pb;
-
- pb = convertCSpace(src+i*(doc->popplerNumColors),pixelBuf1,i,row, doc);
- pb = cfConvertBits(pb,pixelBuf2,i,row, doc->header.cupsNumColors, doc->bitspercolor);
- cfWritePixel(dst,plane,i,pb, doc->header.cupsNumColors, doc->header.cupsBitsPerColor, doc->header.cupsColorOrder);
+ // Assumed that BitsPerColor is 8
+ for (unsigned int i = 0; i < pixels; i ++)
+ {
+ unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
+ unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
+ unsigned char *pb;
+
+ pb = convertCSpace(src + i * doc->popplerNumColors,
+ pixelBuf1, i, row, doc);
+ pb = cfConvertBits(pb, pixelBuf2, i, row, doc->header.cupsNumColors,
+ doc->bitspercolor);
+ cfWritePixel(dst, plane, i, pb, doc->header.cupsNumColors,
+ doc->header.cupsBitsPerColor, doc->header.cupsColorOrder);
}
- return dst;
+ return (dst);
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- for (unsigned int i = 0;i < pixels;i++) {
- unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
- unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
- unsigned char *pb;
-
- pb = convertCSpace(src+(pixels-i-1)*(doc->popplerNumColors),pixelBuf1,i,row, doc);
- pb = cfConvertBits(pb,pixelBuf2,i,row, doc->header.cupsNumColors, doc->bitspercolor);
- cfWritePixel(dst,plane,i,pb, doc->header.cupsNumColors, doc->header.cupsBitsPerColor, doc->header.cupsColorOrder);
+ for (unsigned int i = 0; i < pixels; i ++)
+ {
+ unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
+ unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
+ unsigned char *pb;
+
+ pb = convertCSpace(src + (pixels - i - 1) * doc->popplerNumColors,
+ pixelBuf1, i, row, doc);
+ pb = cfConvertBits(pb, pixelBuf2, i, row, doc->header.cupsNumColors,
+ doc->bitspercolor);
+ cfWritePixel(dst, plane, i, pb, doc->header.cupsNumColors,
+ doc->header.cupsBitsPerColor, doc->header.cupsColorOrder);
}
- return dst;
+ return (dst);
}
-/* Handle special cases which appear in the Gutenprint driver */
-static bool select_special_case(pdftoraster_doc_t* doc, conversion_function_t* convert)
+
+// Handle special cases which appear in the Gutenprint driver
+static bool
+select_special_case(pdftoraster_doc_t* doc,
+ conversion_function_t* convert)
{
int i;
- for (i = 0;specialCaseFuncs[i].bitsPerPixel > 0;i++) {
- if (doc->header.cupsColorSpace == specialCaseFuncs[i].cspace
- && doc->header.cupsBitsPerPixel == specialCaseFuncs[i].bitsPerPixel
- && doc->header.cupsBitsPerColor == specialCaseFuncs[i].bitsPerColor) {
+ for (i = 0; specialCaseFuncs[i].bitsPerPixel > 0; i ++)
+ {
+ if (doc->header.cupsColorSpace == specialCaseFuncs[i].cspace &&
+ doc->header.cupsBitsPerPixel == specialCaseFuncs[i].bitsPerPixel &&
+ doc->header.cupsBitsPerColor == specialCaseFuncs[i].bitsPerColor)
+ {
convert->convertLineOdd = specialCaseFuncs[i].convertLine;
- if (doc->header.Duplex && doc->swap_image_x) {
+ if (doc->header.Duplex && doc->swap_image_x)
+ {
convert->convertLineEven = specialCaseFuncs[i].convertLineSwap;
doc->allocLineBuf = specialCaseFuncs[i].allocLineBufSwap;
- } else {
+ }
+ else
+ {
convert->convertLineEven = specialCaseFuncs[i].convertLine;
doc->allocLineBuf = specialCaseFuncs[i].allocLineBuf;
}
- return true; /* found */
+ return (true); // found
}
}
- return false;
+ return (false);
}
-static unsigned int get_cms_color_space_type(cmsColorSpaceSignature cs)
+
+static unsigned int
+get_cms_color_space_type(cmsColorSpaceSignature cs)
{
- switch (cs) {
+ switch (cs)
+ {
case cmsSigXYZData:
- return PT_XYZ;
- break;
+ return (PT_XYZ);
+ break;
case cmsSigLabData:
- return PT_Lab;
- break;
+ return (PT_Lab);
+ break;
case cmsSigLuvData:
- return PT_YUV;
- break;
+ return (PT_YUV);
+ break;
case cmsSigYCbCrData:
- return PT_YCbCr;
- break;
+ return (PT_YCbCr);
+ break;
case cmsSigYxyData:
- return PT_Yxy;
- break;
+ return (PT_Yxy);
+ break;
case cmsSigRgbData:
- return PT_RGB;
- break;
+ return (PT_RGB);
+ break;
case cmsSigGrayData:
- return PT_GRAY;
- break;
+ return (PT_GRAY);
+ break;
case cmsSigHsvData:
- return PT_HSV;
- break;
+ return (PT_HSV);
+ break;
case cmsSigHlsData:
- return PT_HLS;
- break;
+ return (PT_HLS);
+ break;
case cmsSigCmykData:
- return PT_CMYK;
- break;
+ return (PT_CMYK);
+ break;
case cmsSigCmyData:
- return PT_CMY;
- break;
+ return (PT_CMY);
+ break;
case cmsSig2colorData:
case cmsSig3colorData:
case cmsSig4colorData:
case cmsSig14colorData:
case cmsSig15colorData:
default:
- break;
- }
- return PT_RGB;
+ break;
+ }
+ return (PT_RGB);
}
-/* select convertLine function */
-static int select_convert_func(cups_raster_t *raster, pdftoraster_doc_t* doc, conversion_function_t *convert, cf_logfunc_t log, void* ld)
+
+// select convertLine function
+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 ((doc->colour_profile.colorProfile == NULL ||
+ doc->colour_profile.popplerColorProfile ==
+ doc->colour_profile.colorProfile) &&
+ (doc->header.cupsColorOrder == CUPS_ORDER_CHUNKED ||
+ doc->header.cupsNumColors == 1))
+ {
if (select_special_case(doc, convert))
return (0);
}
- switch (doc->header.cupsColorOrder) {
- case CUPS_ORDER_BANDED:
- case CUPS_ORDER_PLANAR:
- if (doc->header.cupsNumColors > 1) {
- convert->convertLineEven = convert_line_plane_swap;
- convert->convertLineOdd = convert_line_plane;
- break;
- }
- default:
- case CUPS_ORDER_CHUNKED:
- convert->convertLineEven = convert_line_chunked_swap;
- convert->convertLineOdd = convert_line_chunked;
- break;
+ switch (doc->header.cupsColorOrder)
+ {
+ case CUPS_ORDER_BANDED:
+ case CUPS_ORDER_PLANAR:
+ if (doc->header.cupsNumColors > 1)
+ {
+ convert->convertLineEven = convert_line_plane_swap;
+ convert->convertLineOdd = convert_line_plane;
+ break;
+ }
+ default:
+ case CUPS_ORDER_CHUNKED:
+ convert->convertLineEven = convert_line_chunked_swap;
+ convert->convertLineOdd = convert_line_chunked;
+ break;
}
- if (!doc->header.Duplex || !doc->swap_image_x) {
+ if (!doc->header.Duplex || !doc->swap_image_x)
convert->convertLineEven = convert->convertLineOdd;
- }
doc->allocLineBuf = true;
- if (doc->colour_profile.colorProfile != NULL && doc->colour_profile.popplerColorProfile != doc->colour_profile.colorProfile) {
+ if (doc->colour_profile.colorProfile != NULL &&
+ doc->colour_profile.popplerColorProfile !=
+ doc->colour_profile.colorProfile)
+ {
unsigned int bytes;
- switch (doc->header.cupsColorSpace) {
- case CUPS_CSPACE_CIELab:
- case CUPS_CSPACE_ICC1:
- case CUPS_CSPACE_ICC2:
- case CUPS_CSPACE_ICC3:
- case CUPS_CSPACE_ICC4:
- case CUPS_CSPACE_ICC5:
- case CUPS_CSPACE_ICC6:
- case CUPS_CSPACE_ICC7:
- case CUPS_CSPACE_ICC8:
- case CUPS_CSPACE_ICC9:
- case CUPS_CSPACE_ICCA:
- case CUPS_CSPACE_ICCB:
- case CUPS_CSPACE_ICCC:
- case CUPS_CSPACE_ICCD:
- case CUPS_CSPACE_ICCE:
- case CUPS_CSPACE_ICCF:
- if (doc->header.cupsBitsPerColor == 8) {
- convert->convertCSpace = convert_cspace_lab_8;
- } else {
- /* 16 bits */
- convert->convertCSpace = convert_cspace_lab_16;
- }
- bytes = 0; /* double */
- break;
- case CUPS_CSPACE_CIEXYZ:
- if (doc->header.cupsBitsPerColor == 8) {
- convert->convertCSpace = convert_cspace_xyz_8;
- } else {
- /* 16 bits */
- convert->convertCSpace = convert_cspace_xyz_16;
- }
- bytes = 0; /* double */
- break;
- default:
- convert->convertCSpace = convert_cspace_with_profiles;
- bytes = doc->header.cupsBitsPerColor/8;
- break;
+ switch (doc->header.cupsColorSpace)
+ {
+ case CUPS_CSPACE_CIELab:
+ case CUPS_CSPACE_ICC1:
+ case CUPS_CSPACE_ICC2:
+ case CUPS_CSPACE_ICC3:
+ case CUPS_CSPACE_ICC4:
+ case CUPS_CSPACE_ICC5:
+ case CUPS_CSPACE_ICC6:
+ case CUPS_CSPACE_ICC7:
+ case CUPS_CSPACE_ICC8:
+ case CUPS_CSPACE_ICC9:
+ case CUPS_CSPACE_ICCA:
+ case CUPS_CSPACE_ICCB:
+ case CUPS_CSPACE_ICCC:
+ case CUPS_CSPACE_ICCD:
+ case CUPS_CSPACE_ICCE:
+ case CUPS_CSPACE_ICCF:
+ if (doc->header.cupsBitsPerColor == 8)
+ convert->convertCSpace = convert_cspace_lab_8;
+ else
+ // 16 bits
+ convert->convertCSpace = convert_cspace_lab_16;
+ bytes = 0; // double
+ break;
+ case CUPS_CSPACE_CIEXYZ:
+ if (doc->header.cupsBitsPerColor == 8)
+ convert->convertCSpace = convert_cspace_xyz_8;
+ else
+ // 16 bits
+ convert->convertCSpace = convert_cspace_xyz_16;
+ bytes = 0; // double
+ break;
+ default:
+ convert->convertCSpace = convert_cspace_with_profiles;
+ bytes = doc->header.cupsBitsPerColor / 8;
+ break;
}
- doc->bitspercolor = 0; /* convert bits in convertCSpace */
- if (doc->colour_profile.popplerColorProfile == NULL) {
+ doc->bitspercolor = 0; // convert bits in convertCSpace
+ if (doc->colour_profile.popplerColorProfile == NULL)
doc->colour_profile.popplerColorProfile = cmsCreate_sRGBProfile();
- }
unsigned int dcst =
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),
+ COLORSPACE_SH(PT_RGB) | CHANNELS_SH(3) |
+ BYTES_SH(1),
doc->colour_profile.colorProfile,
COLORSPACE_SH(dcst) |
CHANNELS_SH(doc->header.cupsNumColors) |
BYTES_SH(bytes),
- doc->colour_profile.renderingIntent,0)) == 0) {
+ doc->colour_profile.renderingIntent, 0)) == 0)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPDFToRaster: Can't create color transform.");
return (1);
}
- } else {
- /* select convertCSpace function */
- switch (doc->header.cupsColorSpace) {
- case CUPS_CSPACE_CIELab:
- case CUPS_CSPACE_ICC1:
- case CUPS_CSPACE_ICC2:
- case CUPS_CSPACE_ICC3:
- case CUPS_CSPACE_ICC4:
- case CUPS_CSPACE_ICC5:
- case CUPS_CSPACE_ICC6:
- case CUPS_CSPACE_ICC7:
- case CUPS_CSPACE_ICC8:
- case CUPS_CSPACE_ICC9:
- case CUPS_CSPACE_ICCA:
- case CUPS_CSPACE_ICCB:
- case CUPS_CSPACE_ICCC:
- case CUPS_CSPACE_ICCD:
- case CUPS_CSPACE_ICCE:
- case CUPS_CSPACE_ICCF:
- case CUPS_CSPACE_CIEXYZ:
- convert->convertCSpace = convert_cspace_none;
- break;
- case CUPS_CSPACE_CMY:
- convert->convertCSpace = rgb_8_to_cmy;
- break;
- case CUPS_CSPACE_YMC:
- convert->convertCSpace = rgb_8_to_ymc;
- break;
- case CUPS_CSPACE_CMYK:
- convert->convertCSpace = rgb_8_to_cmyk;
- break;
- case CUPS_CSPACE_KCMY:
- convert->convertCSpace = rgb_8_to_kcmy;
- break;
- case CUPS_CSPACE_KCMYcm:
- if (doc->header.cupsBitsPerColor > 1) {
- convert->convertCSpace = rgb_8_to_kcmy;
- } else {
- convert->convertCSpace = rgb_8_to_kcmycm_temp;
- }
- break;
- case CUPS_CSPACE_GMCS:
- case CUPS_CSPACE_GMCK:
- case CUPS_CSPACE_YMCK:
- convert->convertCSpace = rgb_8_to_ymck;
- break;
- case CUPS_CSPACE_RGBW:
- convert->convertCSpace = rgb_8_to_rgbw;
- break;
- case CUPS_CSPACE_RGBA:
- convert->convertCSpace = rgb_8_to_rgba;
- break;
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_SRGB:
- case CUPS_CSPACE_ADOBERGB:
- convert->convertCSpace = convert_cspace_none;
- break;
- case CUPS_CSPACE_W:
- case CUPS_CSPACE_SW:
- case CUPS_CSPACE_WHITE:
- convert->convertCSpace = convert_cspace_none;
- break;
- case CUPS_CSPACE_K:
- case CUPS_CSPACE_GOLD:
- case CUPS_CSPACE_SILVER:
- convert->convertCSpace = w_8_to_k_8;
- break;
- default:
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToRaster: Specified ColorSpace is not supported");
- return (1);
+ }
+ else
+ {
+ // select convertCSpace function
+ switch (doc->header.cupsColorSpace)
+ {
+ case CUPS_CSPACE_CIELab:
+ case CUPS_CSPACE_ICC1:
+ case CUPS_CSPACE_ICC2:
+ case CUPS_CSPACE_ICC3:
+ case CUPS_CSPACE_ICC4:
+ case CUPS_CSPACE_ICC5:
+ case CUPS_CSPACE_ICC6:
+ case CUPS_CSPACE_ICC7:
+ case CUPS_CSPACE_ICC8:
+ case CUPS_CSPACE_ICC9:
+ case CUPS_CSPACE_ICCA:
+ case CUPS_CSPACE_ICCB:
+ case CUPS_CSPACE_ICCC:
+ case CUPS_CSPACE_ICCD:
+ case CUPS_CSPACE_ICCE:
+ case CUPS_CSPACE_ICCF:
+ case CUPS_CSPACE_CIEXYZ:
+ convert->convertCSpace = convert_cspace_none;
+ break;
+ case CUPS_CSPACE_CMY:
+ convert->convertCSpace = rgb_8_to_cmy;
+ break;
+ case CUPS_CSPACE_YMC:
+ convert->convertCSpace = rgb_8_to_ymc;
+ break;
+ case CUPS_CSPACE_CMYK:
+ convert->convertCSpace = rgb_8_to_cmyk;
+ break;
+ case CUPS_CSPACE_KCMY:
+ convert->convertCSpace = rgb_8_to_kcmy;
+ break;
+ case CUPS_CSPACE_KCMYcm:
+ if (doc->header.cupsBitsPerColor > 1)
+ convert->convertCSpace = rgb_8_to_kcmy;
+ else
+ convert->convertCSpace = rgb_8_to_kcmycm_temp;
+ break;
+ case CUPS_CSPACE_GMCS:
+ case CUPS_CSPACE_GMCK:
+ case CUPS_CSPACE_YMCK:
+ convert->convertCSpace = rgb_8_to_ymck;
+ break;
+ case CUPS_CSPACE_RGBW:
+ convert->convertCSpace = rgb_8_to_rgbw;
+ break;
+ case CUPS_CSPACE_RGBA:
+ convert->convertCSpace = rgb_8_to_rgba;
+ break;
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_SRGB:
+ case CUPS_CSPACE_ADOBERGB:
+ convert->convertCSpace = convert_cspace_none;
+ break;
+ case CUPS_CSPACE_W:
+ case CUPS_CSPACE_SW:
+ case CUPS_CSPACE_WHITE:
+ convert->convertCSpace = convert_cspace_none;
+ break;
+ case CUPS_CSPACE_K:
+ case CUPS_CSPACE_GOLD:
+ case CUPS_CSPACE_SILVER:
+ convert->convertCSpace = w_8_to_k_8;
+ break;
+ default:
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterPDFToRaster: Specified ColorSpace is not supported");
+ return (1);
}
}
if (doc->header.cupsBitsPerColor == 1 &&
(doc->header.cupsNumColors == 1 ||
doc->header.cupsColorSpace == CUPS_CSPACE_KCMYcm ))
- doc->bitspercolor = 0; /* Do not convert the bits */
+ doc->bitspercolor = 0; // Do not convert the bits
return (0);
}
-static unsigned char *one_bit_pixel(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;i<height;i++){
- cfOneBitLine(src + (doc->bytesPerLine)*8*i, dst + (doc->bytesPerLine)*i, doc->header.cupsWidth, i, doc->bi_level);
- }
- return temp;
+
+ temp = dst;
+ for (unsigned int i = 0; i < height; i ++)
+ cfOneBitLine(src + doc->bytesPerLine * 8 * i,
+ dst + doc->bytesPerLine * i,
+ doc->header.cupsWidth, i, doc->bi_level);
+ return (temp);
}
-static unsigned char *remove_alpha(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height){
+static unsigned char *
+remove_alpha(unsigned char *src,
+ unsigned char *dst,
+ unsigned int width,
+ unsigned int height)
+{
unsigned char *temp;
- temp=dst;
- for(unsigned int i=0;i<height;i++){
- for(unsigned int j=0;j<width;j++){
- dst[0]=src[2];
- dst[1]=src[1];
- dst[2]=src[0];
- src+=4;
- dst+=3;
+
+ temp = dst;
+ for (unsigned int i = 0; i < height; i ++)
+ {
+ for (unsigned int j = 0; j < width; j ++)
+ {
+ dst[0] = src[2];
+ dst[1] = src[1];
+ dst[2] = src[0];
+ src += 4;
+ dst += 3;
}
}
- return temp;
+ return (temp);
}
-static void write_page_image(cups_raster_t *raster, pdftoraster_doc_t *doc,
- int pageNo, conversion_function_t* convert, float overspray_factor, cf_filter_iscanceledfunc_t iscanceled, void *icd)
+
+static void
+write_page_image(cups_raster_t *raster,
+ pdftoraster_doc_t *doc,
+ int pageNo,
+ conversion_function_t* convert,
+ float overspray_factor,
+ cf_filter_iscanceledfunc_t iscanceled,
+ void *icd)
{
int i;
convert_line_func convertLine;
if (iscanceled && iscanceled(icd))
return;
- poppler::page *current_page =doc->poppler_doc->create_page(pageNo-1);
+ poppler::page *current_page = doc->poppler_doc->create_page(pageNo - 1);
poppler::page_renderer pr;
pr.set_render_hint(poppler::page_renderer::antialiasing, true);
pr.set_render_hint(poppler::page_renderer::text_antialiasing, true);
for (i = 0; i < 2; i ++)
fakeres[i] = (int)(fakeres[i] * overspray_factor);
- unsigned char *colordata,*newdata,*graydata,*onebitdata;
+ unsigned char *colordata, *newdata, *graydata, *onebitdata;
unsigned int pixel_count;
poppler::image im;
// Render the page according to the colourspace and generate the requried data
- switch (doc->header.cupsColorSpace) {
- case CUPS_CSPACE_W: // Gray
- case CUPS_CSPACE_K: // Black
- case CUPS_CSPACE_SW: // sGray
- if(doc->header.cupsBitsPerColor==1){ // Special case for 1-bit colorspaces
- im = pr.render_page(current_page,fakeres[0],fakeres[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 = 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());
- one_bit_pixel(graydata,onebitdata,im.width(),im.height(), doc);
- colordata=onebitdata;
- rowsize=doc->bytesPerLine;
- }
- else{
-
- im = pr.render_page(current_page,fakeres[0],fakeres[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 = 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);
- colordata=graydata;
- rowsize=doc->header.cupsWidth;
- }
+ switch (doc->header.cupsColorSpace)
+ {
+ case CUPS_CSPACE_W: // Gray
+ case CUPS_CSPACE_K: // Black
+ case CUPS_CSPACE_SW: // sGray
+ if (doc->header.cupsBitsPerColor == 1) // Special case for 1-bit
+ // colorspaces
+ {
+ im = pr.render_page(current_page, fakeres[0], fakeres[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 = 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());
+ one_bit_pixel(graydata, onebitdata, im.width(), im.height(), doc);
+ colordata = onebitdata;
+ rowsize = doc->bytesPerLine;
+ }
+ else
+ {
+ im = pr.render_page(current_page, fakeres[0], fakeres[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 = 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);
+ colordata = graydata;
+ rowsize = doc->header.cupsWidth;
+ }
- break;
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_ADOBERGB:
- case CUPS_CSPACE_CMYK:
- case CUPS_CSPACE_SRGB:
- case CUPS_CSPACE_CMY:
- case CUPS_CSPACE_RGBW:
- default:
- im = pr.render_page(current_page,fakeres[0],fakeres[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 = 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;
- break;
+ break;
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_ADOBERGB:
+ case CUPS_CSPACE_CMYK:
+ case CUPS_CSPACE_SRGB:
+ case CUPS_CSPACE_CMY:
+ case CUPS_CSPACE_RGBW:
+ default:
+ im = pr.render_page(current_page, fakeres[0], fakeres[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 = 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;
+ break;
}
-
- if (doc->allocLineBuf) lineBuf = new unsigned char [doc->bytesPerLine];
- if ((pageNo & 1) == 0) {
+ if (doc->allocLineBuf)
+ lineBuf = new unsigned char [doc->bytesPerLine];
+ if ((pageNo & 1) == 0)
convertLine = convert->convertLineEven;
- } else {
+ else
convertLine = convert->convertLineOdd;
- }
- if (doc->header.Duplex && (pageNo & 1) == 0 && doc->swap_image_y) {
- for (unsigned int plane = 0;plane < doc->nplanes;plane++) {
+ if (doc->header.Duplex && (pageNo & 1) == 0 && doc->swap_image_y)
+ {
+ for (unsigned int plane = 0; plane < doc->nplanes; plane ++)
+ {
unsigned char *bp = colordata + (doc->header.cupsHeight - 1) * rowsize;
-
- for (unsigned int h = doc->header.cupsHeight;h > 0;h--) {
- for (unsigned int band = 0;band < doc->nbands;band++) {
- dp = convertLine(bp,lineBuf,h - 1,plane+band,doc->header.cupsWidth,
- doc->bytesPerLine, doc, convert->convertCSpace);
- cupsRasterWritePixels(raster,dp,doc->bytesPerLine);
+ for (unsigned int h = doc->header.cupsHeight; h > 0; h--)
+ {
+ for (unsigned int band = 0; band < doc->nbands; band ++)
+ {
+ dp = convertLine(bp, lineBuf, h - 1, plane + band,
+ doc->header.cupsWidth,
+ doc->bytesPerLine, doc, convert->convertCSpace);
+ cupsRasterWritePixels(raster, dp, doc->bytesPerLine);
}
bp -= rowsize;
}
}
- } else {
- for (unsigned int plane = 0;plane < doc->nplanes;plane++) {
+ }
+ else
+ {
+ for (unsigned int plane = 0; plane < doc->nplanes; plane ++)
+ {
unsigned char *bp = colordata;
-
- for (unsigned int h = 0;h < doc->header.cupsHeight;h++) {
- for (unsigned int band = 0;band < doc->nbands;band++) {
- dp = convertLine(bp,lineBuf,h,plane+band,doc->header.cupsWidth,
- doc->bytesPerLine, doc, convert->convertCSpace);
- cupsRasterWritePixels(raster,dp,doc->bytesPerLine);
+ for (unsigned int h = 0; h < doc->header.cupsHeight; h ++)
+ {
+ for (unsigned int band = 0; band < doc->nbands; band ++)
+ {
+ dp = convertLine(bp, lineBuf, h, plane + band, doc->header.cupsWidth,
+ doc->bytesPerLine, doc, convert->convertCSpace);
+ cupsRasterWritePixels(raster, dp, doc->bytesPerLine);
}
bp += rowsize;
}
}
}
free(colordata);
- if (doc->allocLineBuf) delete[] lineBuf;
+ if (doc->allocLineBuf)
+ delete[] lineBuf;
}
-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)
+
+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;
- float paperdimensions[2], /* Physical size of the paper */
- margins[4]; /* Physical margins of print */
+ float paperdimensions[2], // Physical size of the paper
+ margins[4]; // Physical margins of print
double l, swap;
int imageable_area_fit = 0;
float overspray_factor = 1.0;
if (iscanceled && iscanceled(icd))
return (0);
- poppler::page *current_page =doc->poppler_doc->create_page(pageNo-1);
+ poppler::page *current_page =doc->poppler_doc->create_page(pageNo - 1);
poppler::page_box_enum box = poppler::page_box_enum::crop_box;
poppler::rectf inputPageBox = current_page->page_rect(box);
poppler::page::orientation_enum orient = current_page->orientation();
- switch (orient) {
- case poppler::page::landscape: rotate=90;
- break;
- case poppler::page::upside_down: rotate=180;
- break;
- case poppler::page::seascape: rotate=270;
- break;
- default:rotate=0;
+ switch (orient)
+ {
+ case poppler::page::landscape:
+ rotate = 90;
+ break;
+ case poppler::page::upside_down:
+ rotate = 180;
+ break;
+ case poppler::page::seascape:
+ rotate = 270;
+ break;
+ default:
+ rotate = 0;
}
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToRaster: cropbox = [ %f %f %f %f ]; rotate = %d",
// Enter input page dimensions in header, so that if no page size got
// specified for the job, the input size gets used via the header
l = inputPageBox.width();
- if (l < 0) l = -l;
+ if (l < 0)
+ l = -l;
if (rotate == 90 || rotate == 270)
doc->header.cupsPageSize[1] = l;
else
doc->header.cupsPageSize[0] = l;
l = inputPageBox.height();
- if (l < 0) l = -l;
+ if (l < 0)
+ l = -l;
if (rotate == 90 || rotate == 270)
doc->header.cupsPageSize[0] = l;
else
{
for (i = 0; i < 2; i ++)
paperdimensions[i] = doc->header.PageSize[i];
- if (doc->header.cupsImagingBBox[3] > 0.0) {
- /* Set margins if we have a bounding box defined ... */
- if (doc->pwgraster == 0) {
+ if (doc->header.cupsImagingBBox[3] > 0.0)
+ {
+ // Set margins if we have a bounding box defined ...
+ if (doc->pwgraster == 0)
+ {
margins[0] = doc->header.cupsImagingBBox[0];
margins[1] = doc->header.cupsImagingBBox[1];
margins[2] = paperdimensions[0] - doc->header.cupsImagingBBox[2];
margins[3] = paperdimensions[1] - doc->header.cupsImagingBBox[3];
}
} else
- /* ... otherwise use zero margins */
+ // ... otherwise use zero margins
for (i = 0; i < 4; i ++)
margins[i] = 0.0;
- /*margins[0] = 0.0;
- margins[1] = 0.0;
- margins[2] = header.PageSize[0];
- margins[3] = header.PageSize[1];*/
+ //margins[0] = 0.0;
+ //margins[1] = 0.0;
+ //margins[2] = header.PageSize[0];
+ //margins[3] = header.PageSize[1];
}
- if (doc->header.Duplex && (pageNo & 1) == 0) {
- /* backside: change margin if needed */
- if (doc->swap_margin_x) {
+ if (doc->header.Duplex && (pageNo & 1) == 0)
+ {
+ // backside: change margin if needed
+ if (doc->swap_margin_x)
+ {
swap = margins[2]; margins[2] = margins[0]; margins[0] = swap;
}
- if (doc->swap_margin_y) {
+ if (doc->swap_margin_y)
+ {
swap = margins[3]; margins[3] = margins[1]; margins[1] = swap;
}
}
- if (imageable_area_fit == 0) {
+ if (imageable_area_fit == 0)
+ {
doc->bitmapoffset[0] = margins[0] / 72.0 * doc->header.HWResolution[0];
doc->bitmapoffset[1] = margins[3] / 72.0 * doc->header.HWResolution[1];
- } else {
+ }
+ else
+ {
doc->bitmapoffset[0] = 0;
doc->bitmapoffset[1] = 0;
}
- /* write page header */
- if (doc->pwgraster == 0) {
+ // write page header
+ if (doc->pwgraster == 0)
+ {
doc->header.cupsWidth = ((paperdimensions[0] - margins[0] - margins[2]) /
- 72.0 * doc->header.HWResolution[0]) + 0.5;
+ 72.0 * doc->header.HWResolution[0]) + 0.5;
doc->header.cupsHeight = ((paperdimensions[1] - margins[1] - margins[3]) /
- 72.0 * doc->header.HWResolution[1]) + 0.5;
- } else {
+ 72.0 * doc->header.HWResolution[1]) + 0.5;
+ }
+ else
+ {
doc->header.cupsWidth = (paperdimensions[0] /
- 72.0 * doc->header.HWResolution[0]) + 0.5;
+ 72.0 * doc->header.HWResolution[0]) + 0.5;
doc->header.cupsHeight = (paperdimensions[1] /
- 72.0 * doc->header.HWResolution[1]) + 0.5;
+ 72.0 * doc->header.HWResolution[1]) + 0.5;
}
- for (i = 0; i < 2; i ++) {
+ for (i = 0; i < 2; i ++)
+ {
doc->header.cupsPageSize[i] = paperdimensions[i];
doc->header.PageSize[i] = (unsigned int)(doc->header.cupsPageSize[i] + 0.5);
if (doc->pwgraster == 0)
else
doc->header.Margins[i] = 0;
}
- if (doc->pwgraster == 0) {
+ if (doc->pwgraster == 0)
+ {
doc->header.cupsImagingBBox[0] = margins[0];
doc->header.cupsImagingBBox[1] = margins[1];
doc->header.cupsImagingBBox[2] = paperdimensions[0] - margins[2];
doc->header.ImagingBoundingBox[i] =
(unsigned int)(doc->header.cupsImagingBBox[i] + 0.5);
} else
- for (i = 0; i < 4; i ++) {
+ for (i = 0; i < 4; i ++)
+ {
doc->header.cupsImagingBBox[i] = 0.0;
doc->header.ImagingBoundingBox[i] = 0;
}
- doc->bytesPerLine = doc->header.cupsBytesPerLine = (doc->header.cupsBitsPerPixel *
- doc->header.cupsWidth + 7) / 8;
- if (doc->header.cupsColorOrder == CUPS_ORDER_BANDED) {
+ doc->bytesPerLine =
+ doc->header.cupsBytesPerLine = (doc->header.cupsBitsPerPixel *
+ doc->header.cupsWidth + 7) / 8;
+ if (doc->header.cupsColorOrder == CUPS_ORDER_BANDED)
doc->header.cupsBytesPerLine *= doc->header.cupsNumColors;
- }
if (log) log(ld,CF_LOGLEVEL_DEBUG,
"cfFilterPDFToRaster: Page %d: Dimensions: %fx%f; Bounding box: %f %f %f %f",
pageNo, doc->header.cupsWidth, doc->header.cupsHeight,
doc->bitmapoffset[0], doc->bitmapoffset[1]);
- if (!cupsRasterWriteHeader2(raster,&(doc->header))) {
+ if (!cupsRasterWriteHeader2(raster, &(doc->header)))
+ {
if (log) log(ld,CF_LOGLEVEL_ERROR,
"cfFilterPDFToRaster: Cannot write page %d header", pageNo);
return (1);
}
- /* write page image */
- write_page_image(raster,doc,pageNo, convert, overspray_factor, iscanceled, icd);
+ // write page image
+ write_page_image(raster, doc, pageNo, convert, overspray_factor,
+ iscanceled, icd);
return (0);
}
-static int set_poppler_color_profile(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 */
+ if (doc->header.cupsBitsPerColor != 8 && doc->header.cupsBitsPerColor != 16)
+ // color Profile is not supported
return (0);
- }
- /* set poppler color profile */
- switch (doc->header.cupsColorSpace) {
- case CUPS_CSPACE_CIELab:
- case CUPS_CSPACE_ICC1:
- case CUPS_CSPACE_ICC2:
- case CUPS_CSPACE_ICC3:
- case CUPS_CSPACE_ICC4:
- case CUPS_CSPACE_ICC5:
- case CUPS_CSPACE_ICC6:
- case CUPS_CSPACE_ICC7:
- case CUPS_CSPACE_ICC8:
- case CUPS_CSPACE_ICC9:
- case CUPS_CSPACE_ICCA:
- case CUPS_CSPACE_ICCB:
- case CUPS_CSPACE_ICCC:
- case CUPS_CSPACE_ICCD:
- case CUPS_CSPACE_ICCE:
- case CUPS_CSPACE_ICCF:
- if (doc->colour_profile.colorProfile == NULL) {
- cmsCIExyY wp;
+
+ // set poppler color profile
+ switch (doc->header.cupsColorSpace)
+ {
+ case CUPS_CSPACE_CIELab:
+ case CUPS_CSPACE_ICC1:
+ case CUPS_CSPACE_ICC2:
+ case CUPS_CSPACE_ICC3:
+ case CUPS_CSPACE_ICC4:
+ case CUPS_CSPACE_ICC5:
+ case CUPS_CSPACE_ICC6:
+ case CUPS_CSPACE_ICC7:
+ case CUPS_CSPACE_ICC8:
+ case CUPS_CSPACE_ICC9:
+ case CUPS_CSPACE_ICCA:
+ case CUPS_CSPACE_ICCB:
+ case CUPS_CSPACE_ICCC:
+ case CUPS_CSPACE_ICCD:
+ case CUPS_CSPACE_ICCE:
+ case CUPS_CSPACE_ICCF:
+ if (doc->colour_profile.colorProfile == NULL)
+ {
+ cmsCIExyY wp;
#ifdef USE_LCMS1
- cmsWhitePointFromTemp(6504,&wp); /* D65 White point */
+ cmsWhitePointFromTemp(6504, &wp); // D65 White point
#else
- cmsWhitePointFromTemp(&wp,6504); /* D65 White point */
+ cmsWhitePointFromTemp(&wp, 6504); // D65 White point
#endif
- doc->colour_profile.colorProfile = cmsCreateLab4Profile(&wp);
- }
- break;
- case CUPS_CSPACE_CIEXYZ:
- if (doc->colour_profile.colorProfile == NULL) {
- /* transform color space via CIELab */
- cmsCIExyY wp;
+ doc->colour_profile.colorProfile = cmsCreateLab4Profile(&wp);
+ }
+ break;
+ case CUPS_CSPACE_CIEXYZ:
+ if (doc->colour_profile.colorProfile == NULL)
+ {
+ // transform color space via CIELab
+ cmsCIExyY wp;
#ifdef USE_LCMS1
- cmsWhitePointFromTemp(6504,&wp); /* D65 White point */
+ cmsWhitePointFromTemp(6504, &wp); // D65 White point
#else
- cmsWhitePointFromTemp(&wp,6504); /* D65 White point */
+ cmsWhitePointFromTemp(&wp, 6504); // D65 White point
#endif
- cmsxyY2XYZ(&(doc->colour_profile.D65WhitePoint),&wp);
- doc->colour_profile.colorProfile = cmsCreateLab4Profile(&wp);
- }
- break;
- case CUPS_CSPACE_SRGB:
- doc->colour_profile.colorProfile = cmsCreate_sRGBProfile();
- break;
- case CUPS_CSPACE_ADOBERGB:
- doc->colour_profile.colorProfile = adobergb_profile();
- break;
- case CUPS_CSPACE_SW:
- doc->colour_profile.colorProfile = sgray_profile();
- break;
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_K:
- case CUPS_CSPACE_W:
- case CUPS_CSPACE_WHITE:
- case CUPS_CSPACE_GOLD:
- case CUPS_CSPACE_SILVER:
- /* We can set specified profile to poppler profile */
- doc->colour_profile.popplerColorProfile = doc->colour_profile.colorProfile ;
- break;
- case CUPS_CSPACE_CMYK:
- case CUPS_CSPACE_KCMY:
- case CUPS_CSPACE_KCMYcm:
- case CUPS_CSPACE_YMCK:
- case CUPS_CSPACE_RGBA:
- case CUPS_CSPACE_RGBW:
- case CUPS_CSPACE_GMCK:
- case CUPS_CSPACE_GMCS:
- case CUPS_CSPACE_CMY:
- case CUPS_CSPACE_YMC:
- /* use standard RGB */
- doc->colour_profile.popplerColorProfile = NULL;
- break;
- default:
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToRaster: Specified ColorSpace is not supported");
- return (1);
- break;
+ cmsxyY2XYZ(&(doc->colour_profile.D65WhitePoint), &wp);
+ doc->colour_profile.colorProfile = cmsCreateLab4Profile(&wp);
+ }
+ break;
+ case CUPS_CSPACE_SRGB:
+ doc->colour_profile.colorProfile = cmsCreate_sRGBProfile();
+ break;
+ case CUPS_CSPACE_ADOBERGB:
+ doc->colour_profile.colorProfile = adobergb_profile();
+ break;
+ case CUPS_CSPACE_SW:
+ doc->colour_profile.colorProfile = sgray_profile();
+ break;
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_K:
+ case CUPS_CSPACE_W:
+ case CUPS_CSPACE_WHITE:
+ case CUPS_CSPACE_GOLD:
+ case CUPS_CSPACE_SILVER:
+ // We can set specified profile to poppler profile
+ doc->colour_profile.popplerColorProfile =
+ doc->colour_profile.colorProfile ;
+ break;
+ case CUPS_CSPACE_CMYK:
+ case CUPS_CSPACE_KCMY:
+ case CUPS_CSPACE_KCMYcm:
+ case CUPS_CSPACE_YMCK:
+ case CUPS_CSPACE_RGBA:
+ case CUPS_CSPACE_RGBW:
+ case CUPS_CSPACE_GMCK:
+ case CUPS_CSPACE_GMCS:
+ case CUPS_CSPACE_CMY:
+ case CUPS_CSPACE_YMC:
+ // use standard RGB
+ doc->colour_profile.popplerColorProfile = NULL;
+ break;
+ default:
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterPDFToRaster: Specified ColorSpace is not supported");
+ return (1);
+ break;
}
return (0);
}
-int cfFilterPDFToRaster(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? (unused)*/
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters(unused)*/
+
+int
+cfFilterPDFToRaster(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ // (unused)
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
+ // (unused)
{
- const char *val;
- cf_filter_out_format_t outformat;
- pdftoraster_doc_t doc;
- int i;
- int npages = 0;
- cups_raster_t *raster = NULL;
- cups_file_t *inputfp; /* Print file */
- cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
- int deviceCopies = 1;
- bool deviceCollate = false;
- conversion_function_t convert;
+ const char *val;
+ cf_filter_out_format_t outformat;
+ pdftoraster_doc_t doc;
+ int i;
+ int npages = 0;
+ cups_raster_t *raster = NULL;
+ cups_file_t *inputfp; // Print file
+ cf_logfunc_t log = data->logfunc;
+ void *ld = data->logdata;
+ int deviceCopies = 1;
+ bool deviceCollate = false;
+ conversion_function_t convert;
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
- void *icd = data->iscanceleddata;
- int ret = 0;
+ void *icd = data->iscanceleddata;
+ int ret = 0;
(void)inputseekable;
(void)parameters;
else
outformat = CF_FILTER_OUT_FORMAT_CUPS_RASTER;
- /* Note: With the CF_FILTER_OUT_FORMAT_PCLM selection the output is
- actually PWG Raster but color spaces and depth are always
- assumed to be 8-bit sRGB or sGray, the only color spaces in
- PCLm. This mode is for further processing with pwgtopclm. */
+ // Note: With the CF_FILTER_OUT_FORMAT_PCLM selection the output is
+ // actually PWG Raster but color spaces and depth are always
+ // assumed to be 8-bit sRGB or sGray, the only color spaces in
+ // PCLm. This mode is for further processing with pwgtopclm.
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToRaster: Final output format: %s",
"Apple Raster" :
"PCLm"))));
- /*
- * Open the input data stream specified by inputfd ...
- */
-
+ //
+ // Open the input data stream specified by inputfd ...
+ //
+
if ((inputfp = cupsFileOpenFd(inputfd, "r")) == NULL)
{
if (!iscanceled || !iscanceled(icd))
return (1);
}
- /*
- * Make a temporary file if input is stdin...
- */
+ //
+ // Make a temporary file if input is stdin...
+ //
// Make a temporary file and save input data in it...
int fd;
char buf[BUFSIZ];
int n;
- fd = cupsTempFd(name,sizeof(name));
- if (fd < 0) {
+ fd = cupsTempFd(name, sizeof(name));
+ if (fd < 0)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPDFToRaster: Can't create temporary file.");
return (1);
}
- /* copy input data to the tmp file */
- while ((n = read(inputfd, buf, BUFSIZ)) > 0) {
- if (write(fd, buf, n) != n) {
+ // copy input data to the tmp file
+ while ((n = read(inputfd, buf, BUFSIZ)) > 0)
+ {
+ if (write(fd, buf, n) != n)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPDFToRaster: Can't copy input data to temporary file.");
close(fd);
unlink(name);
FILE *fp;
- if ((fp = fdopen(inputfd,"rb")) == 0) {
+ if ((fp = fdopen(inputfd, "rb")) == 0)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPDFToRaster: Can't open input file.");
ret = 1;
if(doc.poppler_doc != NULL)
npages = doc.poppler_doc->pages();
- /* fix NumCopies, Collate ccording to PDFTOPDFComments */
+ // fix NumCopies, Collate ccording to PDFTOPDFComments
doc.header.NumCopies = deviceCopies;
doc.header.Collate = deviceCollate ? CUPS_TRUE : CUPS_FALSE;
- /* fixed other values that pdftopdf handles */
+ // fixed other values that pdftopdf handles
doc.header.MirrorPrint = CUPS_FALSE;
doc.header.Orientation = CUPS_ORIENT_0;
- if (doc.header.cupsBitsPerColor != 1
- && doc.header.cupsBitsPerColor != 2
- && doc.header.cupsBitsPerColor != 4
- && doc.header.cupsBitsPerColor != 8
- && doc.header.cupsBitsPerColor != 16) {
+ if (doc.header.cupsBitsPerColor != 1 &&
+ doc.header.cupsBitsPerColor != 2 &&
+ doc.header.cupsBitsPerColor != 4 &&
+ doc.header.cupsBitsPerColor != 8 &&
+ doc.header.cupsBitsPerColor != 16)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToRaster: Specified color format is not supported.");
+ "cfFilterPDFToRaster: Specified color format is not supported.");
ret = 1;
goto out;
}
- if (doc.header.cupsColorOrder == CUPS_ORDER_PLANAR) {
+ if (doc.header.cupsColorOrder == CUPS_ORDER_PLANAR)
doc.nplanes = doc.header.cupsNumColors;
- } else {
+ else
doc.nplanes = 1;
- }
- if (doc.header.cupsColorOrder == CUPS_ORDER_BANDED) {
+ if (doc.header.cupsColorOrder == CUPS_ORDER_BANDED)
doc.nbands = doc.header.cupsNumColors;
- } else {
+ else
doc.nbands = 1;
+ // set image's values
+ switch (doc.header.cupsColorSpace)
+ {
+ case CUPS_CSPACE_CIELab:
+ case CUPS_CSPACE_ICC1:
+ case CUPS_CSPACE_ICC2:
+ case CUPS_CSPACE_ICC3:
+ case CUPS_CSPACE_ICC4:
+ case CUPS_CSPACE_ICC5:
+ case CUPS_CSPACE_ICC6:
+ case CUPS_CSPACE_ICC7:
+ case CUPS_CSPACE_ICC8:
+ case CUPS_CSPACE_ICC9:
+ case CUPS_CSPACE_ICCA:
+ case CUPS_CSPACE_ICCB:
+ case CUPS_CSPACE_ICCC:
+ case CUPS_CSPACE_ICCD:
+ case CUPS_CSPACE_ICCE:
+ case CUPS_CSPACE_ICCF:
+ case CUPS_CSPACE_CIEXYZ:
+ if (doc.header.cupsColorOrder != CUPS_ORDER_CHUNKED ||
+ (doc.header.cupsBitsPerColor != 8 &&
+ doc.header.cupsBitsPerColor != 16))
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterPDFToRaster: Specified color format is not supported.");
+ ret = 1;
+ goto out;
+ }
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_SRGB:
+ case CUPS_CSPACE_ADOBERGB:
+ case CUPS_CSPACE_CMY:
+ case CUPS_CSPACE_YMC:
+ case CUPS_CSPACE_CMYK:
+ case CUPS_CSPACE_KCMY:
+ case CUPS_CSPACE_KCMYcm:
+ case CUPS_CSPACE_YMCK:
+ case CUPS_CSPACE_RGBA:
+ case CUPS_CSPACE_RGBW:
+ case CUPS_CSPACE_GMCK:
+ case CUPS_CSPACE_GMCS:
+ doc.popplerNumColors = 3;
+ break;
+ case CUPS_CSPACE_K:
+ case CUPS_CSPACE_W:
+ case CUPS_CSPACE_SW:
+ case CUPS_CSPACE_WHITE:
+ case CUPS_CSPACE_GOLD:
+ case CUPS_CSPACE_SILVER:
+ // set paper color white
+ doc.popplerNumColors = 1;
+ break;
+ default:
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterPDFToRaster: Specified ColorSpace is not supported.");
+ ret = 1;
+ goto out;
}
- /* set image's values */
- switch (doc.header.cupsColorSpace) {
- case CUPS_CSPACE_CIELab:
- case CUPS_CSPACE_ICC1:
- case CUPS_CSPACE_ICC2:
- case CUPS_CSPACE_ICC3:
- case CUPS_CSPACE_ICC4:
- case CUPS_CSPACE_ICC5:
- case CUPS_CSPACE_ICC6:
- case CUPS_CSPACE_ICC7:
- case CUPS_CSPACE_ICC8:
- case CUPS_CSPACE_ICC9:
- case CUPS_CSPACE_ICCA:
- case CUPS_CSPACE_ICCB:
- case CUPS_CSPACE_ICCC:
- case CUPS_CSPACE_ICCD:
- case CUPS_CSPACE_ICCE:
- case CUPS_CSPACE_ICCF:
- case CUPS_CSPACE_CIEXYZ:
- if (doc.header.cupsColorOrder != CUPS_ORDER_CHUNKED
- || (doc.header.cupsBitsPerColor != 8
- && doc.header.cupsBitsPerColor != 16)) {
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToRaster: Specified color format is not supported.");
- ret = 1;
- goto out;
- }
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_SRGB:
- case CUPS_CSPACE_ADOBERGB:
- case CUPS_CSPACE_CMY:
- case CUPS_CSPACE_YMC:
- case CUPS_CSPACE_CMYK:
- case CUPS_CSPACE_KCMY:
- case CUPS_CSPACE_KCMYcm:
- case CUPS_CSPACE_YMCK:
- case CUPS_CSPACE_RGBA:
- case CUPS_CSPACE_RGBW:
- case CUPS_CSPACE_GMCK:
- case CUPS_CSPACE_GMCS:
- doc.popplerNumColors = 3;
- break;
- case CUPS_CSPACE_K:
- case CUPS_CSPACE_W:
- case CUPS_CSPACE_SW:
- case CUPS_CSPACE_WHITE:
- case CUPS_CSPACE_GOLD:
- case CUPS_CSPACE_SILVER:
- /* set paper color white */
- doc.popplerNumColors = 1;
- break;
- default:
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToRaster: Specified ColorSpace is not supported.");
- ret = 1;
- goto out;
- }
- if (!(doc.colour_profile.cm_disabled)) {
- if (set_poppler_color_profile(&doc, log, ld) != 0) {
+ if (!(doc.colour_profile.cm_disabled))
+ {
+ if (set_poppler_color_profile(&doc, log, ld) != 0)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPDFToRaster: Cannot set color profile.");
ret = 1;
ret = 1;
goto out;
}
- if (doc.poppler_doc != NULL) {
- for (i = 1;i <= npages;i++) {
- if (out_page(&doc,i,data,raster, &convert, log, ld, iscanceled, icd) == 1)
+ if (doc.poppler_doc != NULL)
+ {
+ for (i = 1; i <= npages; i ++)
+ {
+ 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);
close(outputfd);
// Delete doc
- if (doc.colour_profile.colorProfile != NULL) {
+ if (doc.colour_profile.colorProfile != NULL)
cmsCloseProfile(doc.colour_profile.colorProfile);
- }
- if (doc.colour_profile.popplerColorProfile != NULL && doc.colour_profile.popplerColorProfile != doc.colour_profile.colorProfile) {
+ if (doc.colour_profile.popplerColorProfile != NULL &&
+ doc.colour_profile.popplerColorProfile !=
+ doc.colour_profile.colorProfile)
cmsCloseProfile(doc.colour_profile.popplerColorProfile);
- }
- if (doc.colour_profile.colorTransform != NULL) {
+ if (doc.colour_profile.colorTransform != NULL)
cmsDeleteTransform(doc.colour_profile.colorTransform);
- }
return (ret);
}
-/* replace memory allocation methods for memory check */
-/* For compatibility with g++ >= 4.7 compilers _GLIBCXX_THROW
- * should be used as a guard, otherwise use traditional definition */
+// Replace memory allocation methods for memory check
+// For compatibility with g++ >= 4.7 compilers _GLIBCXX_THROW
+// should be used as a guard, otherwise use traditional definition
#ifndef _GLIBCXX_THROW
#define _GLIBCXX_THROW throw
#endif
{
return malloc(size);
}
-/*
+
+#if 0
void operator delete[](void *p) throw ()
{
free(p);
}
-*/
+#endif // 0
-/*
- * PDF file output routines.
- *
- * Copyright 2008 by Tobias Hoffmann.
- *
- * This file is licensed as noted in "COPYING"
- * which should have been included with this file.
- *
- */
+//
+// PDF file output routines.
+//
+// Copyright 2008 by Tobias Hoffmann.
+//
+// This file is licensed as noted in "COPYING"
+// which should have been included with this file.
+//
+
#include <stdio.h>
#include "debug-internal.h"
#include <stdarg.h>
#include "pdfutils.h"
#include "fontembed/embed.h"
-void cfPDFOutPrintF(cf_pdf_out_t *pdf,const char *fmt,...) // {{{
+
+//
+// 'cfPDFOutPrintF()' - General output routine for our PDF
+//
+// Keeps track of characters actually written out
+//
+
+void
+cfPDFOutPrintF(cf_pdf_out_t *pdf,
+ const char *fmt,...) // {{{
{
- DEBUG_assert(pdf);
int len;
va_list ap;
- va_start(ap,fmt);
- len=vprintf(fmt,ap);
+
+ DEBUG_assert(pdf);
+
+ va_start(ap, fmt);
+ len = vprintf(fmt, ap);
va_end(ap);
- pdf->filepos+=len;
+ pdf->filepos += len;
}
// }}}
-void cfPDFOutputString(cf_pdf_out_t *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
+
+//
+// 'cfPDFOutputString()' - Write out an escaped PDF string: e.g.
+// "(Text \(Test\)\n)"
+//
+
+void
+cfPDFOutputString(cf_pdf_out_t *pdf,
+ const char *str,
+ int len) // {{{ -> len == -1: strlen()
{
DEBUG_assert(pdf);
DEBUG_assert(str);
- if (len==-1) {
- len=strlen(str);
- }
- putc('(',stdout);
+
+ if (len == -1)
+ len = strlen(str);
+ putc('(', stdout);
// escape special chars: \0 \\ \( \) -- don't bother about balanced parens
- int iA=0;
- for (;len>0;iA++,len--) {
- if ( (str[iA]<32)||(str[iA]>126) ) {
- fwrite(str,1,iA,stdout);
- fprintf(stdout,"\\%03o",(unsigned char)str[iA]);
- pdf->filepos+=iA+4;
- str+=iA+1;
- iA=-1;
- } else if ( (str[iA]=='(')||(str[iA]==')')||(str[iA]=='\\') ) {
- fwrite(str,1,iA,stdout);
- fprintf(stdout,"\\%c",str[iA]);
- pdf->filepos+=iA+2;
- str+=iA+1;
- iA=-1;
+ int iA = 0;
+ for (; len > 0; iA ++, len --)
+ {
+ if ((str[iA] < 32) || (str[iA] > 126))
+ {
+ fwrite(str, 1, iA, stdout);
+ fprintf(stdout, "\\%03o", (unsigned char)str[iA]);
+ pdf->filepos += iA + 4;
+ str += iA + 1;
+ iA = -1;
+ }
+ else if ((str[iA] == '(') || (str[iA] == ')') || (str[iA] == '\\'))
+ {
+ fwrite(str, 1, iA, stdout);
+ fprintf(stdout, "\\%c" ,str[iA]);
+ pdf->filepos += iA + 2;
+ str += iA + 1;
+ iA = -1;
}
}
- pdf->filepos+=iA+2;
- fwrite(str,1,iA,stdout);
- putc(')',stdout);
+ pdf->filepos += iA + 2;
+ fwrite(str, 1, iA, stdout);
+ putc(')', stdout);
}
// }}}
-void cfPDFOutputHexString(cf_pdf_out_t *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
+
+//
+// 'cfPDFOutputHexString()' - Write ot a string in hex, 2 digits per byte
+//
+
+void
+cfPDFOutputHexString(cf_pdf_out_t *pdf,
+ const char *str,
+ int len) // {{{ -> len == -1: strlen()
{
DEBUG_assert(pdf);
DEBUG_assert(str);
- if (len==-1) {
- len=strlen(str);
- }
- pdf->filepos+=2*len+2;
- putc('<',stdout);
- for (;len>0;str++,len--) {
- fprintf(stdout,"%02x",(unsigned char)*str);
- }
- putc('>',stdout);
+
+ if (len == -1)
+ len = strlen(str);
+ pdf->filepos += 2 * len + 2;
+ putc('<', stdout);
+ for (; len > 0; str++, len--)
+ fprintf(stdout, "%02x", (unsigned char)*str);
+ putc('>', stdout);
}
// }}}
-cf_pdf_out_t *cfPDFOutNew() // {{{ - NULL on error
+
+//
+// 'cfPDFOutNew()' - Allocates a new cf_pdf_out_t structure
+//
+
+cf_pdf_out_t * // O - NULL on error
+cfPDFOutNew() // {{{
{
- cf_pdf_out_t *ret=malloc(sizeof(cf_pdf_out_t));
- if (ret) {
- memset(ret,0,sizeof(cf_pdf_out_t));
- }
+ cf_pdf_out_t *ret = malloc(sizeof(cf_pdf_out_t));
+
+ if (ret)
+ memset(ret, 0, sizeof(cf_pdf_out_t));
- return ret;
+ return (ret);
}
// }}}
+
+//
+// 'cfPDFOutToPDFDate()' - Format the broken up timestamp according to
+// PDF requirements for /CreationDate
+//
// NOTE: uses statically allocated buffer
-const char *cfPDFOutToPDFDate(struct tm *curtm) // {{{
+//
+
+const char *
+cfPDFOutToPDFDate(struct tm *curtm) // {{{
{
static char curdate[250];
- if (!curtm) {
+
+
+ if (!curtm)
+ {
time_t curtime;
curtime = time(NULL);
curtm = localtime(&curtime);
}
strftime(curdate, sizeof(curdate), "D:%Y%m%d%H%M%S%z", curtm);
- curdate[23]=0;
- curdate[22]='\'';
- curdate[21]=curdate[18];
- curdate[20]=curdate[17];
- curdate[19]='\'';
- return curdate;
+ curdate[23] = 0;
+ curdate[22] = '\'';
+ curdate[21] = curdate[18];
+ curdate[20] = curdate[17];
+ curdate[19] = '\'';
+ return (curdate);
}
// }}}
-int cfPDFOutAddXRef(cf_pdf_out_t *pdf) // {{{ - returns obj_no
+
+//
+// 'cfPDFOutAddXRef()' - Begin a new object at current point of the
+// output stream and add it to the xref table.
+//
+
+int // O - Object number
+cfPDFOutAddXRef(cf_pdf_out_t *pdf) // {{{
{
DEBUG_assert(pdf);
- DEBUG_assert(pdf->xrefsize<=pdf->xrefalloc);
+ DEBUG_assert(pdf->xrefsize <= pdf->xrefalloc);
- if (pdf->xrefsize==pdf->xrefalloc) {
+ if (pdf->xrefsize == pdf->xrefalloc)
+ {
long *tmp;
- pdf->xrefalloc+=50;
- tmp=realloc(pdf->xref,sizeof(long)*pdf->xrefalloc);
- if (!tmp) {
+ pdf->xrefalloc += 50;
+ tmp = realloc(pdf->xref, sizeof(long) * pdf->xrefalloc);
+ if (!tmp)
+ {
pdf->xrefalloc=-1;
return -1;
}
- pdf->xref=tmp;
+ pdf->xref = tmp;
}
- pdf->xref[pdf->xrefsize++]=pdf->filepos;
- return pdf->xrefsize; // xrefsize+1
+ pdf->xref[pdf->xrefsize++] = pdf->filepos;
+ return (pdf->xrefsize); // xrefsize + 1
}
// }}}
-int cfPDFOutAddPage(cf_pdf_out_t *pdf,int obj) // {{{ - returns false on error
+
+//
+// 'cfPDFOutAddPage()' - Adds page dictionary Object to the global pages tree
+//
+
+int // O - Return 0 on error
+cfPDFOutAddPage(cf_pdf_out_t *pdf,
+ int obj) // {{{
{
DEBUG_assert(pdf);
- DEBUG_assert(obj>0);
- DEBUG_assert(pdf->pagessize<=pdf->pagesalloc);
+ DEBUG_assert(obj > 0);
+ DEBUG_assert(pdf->pagessize <= pdf->pagesalloc);
- if (pdf->pagessize==pdf->pagesalloc) {
+ if (pdf->pagessize == pdf->pagesalloc)
+ {
int *tmp;
- pdf->pagesalloc+=10;
- tmp=realloc(pdf->pages,sizeof(int)*pdf->pagesalloc);
- if (!tmp) {
- pdf->pagesalloc=-1;
- return 0;
+ pdf->pagesalloc += 10;
+ tmp = realloc(pdf->pages, sizeof(int) * pdf->pagesalloc);
+ if (!tmp)
+ {
+ pdf->pagesalloc = -1;
+ return (0);
}
- pdf->pages=tmp;
+ pdf->pages = tmp;
}
- pdf->pages[pdf->pagessize++]=obj;
- return 1;
+ pdf->pages[pdf->pagessize++] = obj;
+ return (1);
}
// }}}
-int cfPDFOutAddKeyValue(cf_pdf_out_t *pdf,const char *key,const char *val) // {{{ - returns false on error
+
+//
+// 'cfPDFOutAddKeyValue()' - Add a key/value pair to the document's info
+// dictionary
+//
+
+int // O - Return 0 on error
+cfPDFOutAddKeyValue(cf_pdf_out_t *pdf,
+ const char *key,
+ const char *val) // {{{
{
DEBUG_assert(pdf);
- DEBUG_assert(pdf->kvsize<=pdf->kvalloc);
+ DEBUG_assert(pdf->kvsize <= pdf->kvalloc);
- if (pdf->kvsize==pdf->kvalloc) {
+ if (pdf->kvsize == pdf->kvalloc)
+ {
struct cf_keyval_t *tmp;
- pdf->kvalloc+=10;
- tmp=realloc(pdf->kv,sizeof(struct cf_keyval_t)*pdf->kvalloc);
- if (!tmp) {
- pdf->kvalloc=-1;
- return 0;
+ pdf->kvalloc += 10;
+ tmp = realloc(pdf->kv, sizeof(struct cf_keyval_t) * pdf->kvalloc);
+ if (!tmp)
+ {
+ pdf->kvalloc = -1;
+ return (0);
}
- pdf->kv=tmp;
+ pdf->kv = tmp;
}
- pdf->kv[pdf->kvsize].key=strdup(key);
- pdf->kv[pdf->kvsize].value=strdup(val);
- if ( (!pdf->kv[pdf->kvsize].key)||(!pdf->kv[pdf->kvsize].value) ) {
- return 0;
- }
- pdf->kvsize++;
- return 1;
+ pdf->kv[pdf->kvsize].key = strdup(key);
+ pdf->kv[pdf->kvsize].value = strdup(val);
+ if ((!pdf->kv[pdf->kvsize].key) || (!pdf->kv[pdf->kvsize].value))
+ return (0);
+ pdf->kvsize ++;
+ return (1);
}
// }}}
-int cfPDFOutBeginPDF(cf_pdf_out_t *pdf) // ,...output_device?...) // {{{ - false on error
+
+//
+// 'cfPDFOutBeginPDF()' - Start outputting a PDF
+//
+
+int // O - Return 0 on error
+cfPDFOutBeginPDF(cf_pdf_out_t *pdf) // ,...output_device?...) // {{{
{
- DEBUG_assert(pdf);
- DEBUG_assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
int pages_obj;
- pdf->xrefsize=pdf->pagessize=0;
- pdf->filepos=0;
- pages_obj=cfPDFOutAddXRef(pdf); // fixed later
- if (pages_obj!=1) {
- return 0;
- }
- cfPDFOutPrintF(pdf,"%%PDF-1.3\n");
- return 1;
+
+ DEBUG_assert(pdf);
+ DEBUG_assert(pdf->kvsize == 0); // otherwise: finish_pdf has not been called
+
+ pdf->xrefsize = pdf->pagessize = 0;
+ pdf->filepos = 0;
+ pages_obj = cfPDFOutAddXRef(pdf); // fixed later
+ if (pages_obj != 1)
+ return (0);
+ cfPDFOutPrintF(pdf, "%%PDF-1.3\n");
+ return (1);
}
// }}}
-void cfPDFOutFinishPDF(cf_pdf_out_t *pdf) // {{{
+
+//
+// 'cfPDFOutFinishPDF()' - Finish outputting the PDF
+//
+
+void
+cfPDFOutFinishPDF(cf_pdf_out_t *pdf) // {{{
{
int iA;
- int root_obj,info_obj=0,xref_start;
- DEBUG_assert( (pdf)&&(pdf->filepos!=-1) );
+ int root_obj,
+ info_obj = 0,
+ xref_start;
+
+
+ DEBUG_assert(pdf && (pdf->filepos != -1));
// pages
- const int pages_obj=1;
- pdf->xref[0]=pdf->filepos; // now fix it
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "<</Type/Pages\n"
- " /Count %d\n"
- " /Kids [",
- pages_obj,pdf->pagessize);
- for (iA=0;iA<pdf->pagessize;iA++) {
- cfPDFOutPrintF(pdf,"%d 0 R ",pdf->pages[iA]);
- }
- cfPDFOutPrintF(pdf,"]\n"
- ">>\n"
- "endobj\n");
+ const int pages_obj = 1;
+ pdf->xref[0] = pdf->filepos; // now fix it
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "<</Type/Pages\n"
+ " /Count %d\n"
+ " /Kids [",
+ pages_obj, pdf->pagessize);
+ for (iA = 0; iA < pdf->pagessize; iA ++)
+ cfPDFOutPrintF(pdf, "%d 0 R ", pdf->pages[iA]);
+ cfPDFOutPrintF(pdf,
+ "]\n"
+ ">>\n"
+ "endobj\n");
// rootdict
- root_obj=cfPDFOutAddXRef(pdf);
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "<</Type/Catalog\n"
- " /Pages %d 0 R\n"
- ">>\n"
- "endobj\n",
- root_obj,pages_obj);
+ root_obj = cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "<</Type/Catalog\n"
+ " /Pages %d 0 R\n"
+ ">>\n"
+ "endobj\n",
+ root_obj, pages_obj);
// info
- if (pdf->kvsize) {
- info_obj=cfPDFOutAddXRef(pdf);
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "<<\n",
- info_obj);
- for (iA=0;iA<pdf->kvsize;iA++) {
- cfPDFOutPrintF(pdf," /%s ",pdf->kv[iA].key);
- cfPDFOutputString(pdf,pdf->kv[iA].value,-1);
- cfPDFOutPrintF(pdf,"\n");
+ if (pdf->kvsize)
+ {
+ info_obj = cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "<<\n",
+ info_obj);
+ for (iA = 0; iA < pdf->kvsize; iA++)
+ {
+ cfPDFOutPrintF(pdf, " /%s ", pdf->kv[iA].key);
+ cfPDFOutputString(pdf, pdf->kv[iA].value, -1);
+ cfPDFOutPrintF(pdf, "\n");
}
- cfPDFOutPrintF(pdf,">>\n"
- "endobj\n");
+ cfPDFOutPrintF(pdf,
+ ">>\n"
+ "endobj\n");
}
// TODO: some return-value checking (??)
// write xref
- xref_start=pdf->filepos;
- cfPDFOutPrintF(pdf,"xref\n"
- "%d %d\n"
- "%010d 65535 f \n",
- 0,pdf->xrefsize+1,0);
- for (iA=0;iA<pdf->xrefsize;iA++) {
- cfPDFOutPrintF(pdf,"%010ld 00000 n \n",
- pdf->xref[iA]);
- }
- cfPDFOutPrintF(pdf,"trailer\n"
- "<<\n"
- " /Size %d\n"
- " /Root %d 0 R\n",
- pdf->xrefsize+1,
- root_obj);
- if (info_obj) {
- cfPDFOutPrintF(pdf," /Info %d 0 R\n",info_obj);
- }
- cfPDFOutPrintF(pdf,">>\n"
- "startxref\n"
- "%d\n"
- "%%%%EOF\n",
- xref_start);
+ xref_start = pdf->filepos;
+ cfPDFOutPrintF(pdf,
+ "xref\n"
+ "%d %d\n"
+ "%010d 65535 f \n",
+ 0, pdf->xrefsize + 1, 0);
+ for (iA = 0; iA < pdf->xrefsize; iA ++)
+ cfPDFOutPrintF(pdf, "%010ld 00000 n \n",
+ pdf->xref[iA]);
+ cfPDFOutPrintF(pdf,
+ "trailer\n"
+ "<<\n"
+ " /Size %d\n"
+ " /Root %d 0 R\n",
+ pdf->xrefsize + 1,
+ root_obj);
+ if (info_obj)
+ cfPDFOutPrintF(pdf, " /Info %d 0 R\n", info_obj);
+ cfPDFOutPrintF(pdf,
+ ">>\n"
+ "startxref\n"
+ "%d\n"
+ "%%%%EOF\n",
+ xref_start);
// set to done
- pdf->filepos=-1;
- for (iA=0;iA<pdf->kvsize;iA++) {
+ pdf->filepos = -1;
+ for (iA = 0; iA < pdf->kvsize; iA ++)
+ {
free(pdf->kv[iA].key);
free(pdf->kv[iA].value);
}
- pdf->kvsize=0;
+ pdf->kvsize = 0;
}
// }}}
-void cfPDFOutFree(cf_pdf_out_t *pdf) // {{{
+
+//
+// 'cfPDFOutFree()' - Free memory of a cf_pdf_out_t structure
+//
+
+void
+cfPDFOutFree(cf_pdf_out_t *pdf) // {{{
{
- if (pdf) {
- DEBUG_assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
+ if (pdf)
+ {
+ DEBUG_assert(pdf->kvsize == 0); // otherwise: finish_pdf has not been called
+
free(pdf->kv);
free(pdf->pages);
free(pdf->xref);
}
// }}}
-static void pdfOut_outfn(const char *buf,int len,void *context) // {{{
+
+static void
+pdf_out_outfn(const char *buf,
+ int len,
+ void *context) // {{{
{
- cf_pdf_out_t *pdf=(cf_pdf_out_t *)context;
+ cf_pdf_out_t *pdf = (cf_pdf_out_t *)context;
- if (fwrite(buf,1,len,stdout)!=len) {
+ if (fwrite(buf, 1, len, stdout) != len)
+ {
perror("Short write");
DEBUG_assert(0);
return;
}
- pdf->filepos+=len;
+ pdf->filepos += len;
}
// }}}
-int cfPDFOutWriteFont(cf_pdf_out_t *pdf,EMB_PARAMS *emb) // {{{
+
+//
+// 'cfPDFOutWriteFont()' - Writes the font emb including descriptor to the PDF
+// and returns the object number.
+//
+
+int
+cfPDFOutWriteFont(cf_pdf_out_t *pdf,
+ EMB_PARAMS *emb) // {{{
{
DEBUG_assert(pdf);
DEBUG_assert(emb);
- EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
- if (!fdes) {
- if (emb->outtype==EMB_FMT_STDFONT) { // std-14 font
- const int f_obj=cfPDFOutAddXRef(pdf);
- char *res=emb_pdf_simple_stdfont(emb);
- if (!res) {
- return 0;
- }
-
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "%s"
- "endobj\n"
- ,f_obj,res);
+ EMB_PDF_FONTDESCR *fdes = emb_pdf_fontdescr(emb);
+ if (!fdes)
+ {
+ if (emb->outtype == EMB_FMT_STDFONT)
+ { // std-14 font
+ const int f_obj = cfPDFOutAddXRef(pdf);
+ char *res = emb_pdf_simple_stdfont(emb);
+ if (!res)
+ return (0);
+
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "%s"
+ "endobj\n",
+ f_obj,
+ res);
free(res);
- return f_obj;
+ return (f_obj);
}
- return 0;
+ return (0);
}
- const int ff_obj=cfPDFOutAddXRef(pdf);
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "<</Length %d 0 R\n"
- ,ff_obj,ff_obj+1);
- if (emb_pdf_get_fontfile_subtype(emb)) {
- cfPDFOutPrintF(pdf," /Subtype /%s\n",
- emb_pdf_get_fontfile_subtype(emb));
- }
- if (emb->outtype==EMB_FMT_TTF) {
- cfPDFOutPrintF(pdf," /Length1 %d 0 R\n"
- ,ff_obj+2);
- } else if (emb->outtype==EMB_FMT_T1) { // TODO
- cfPDFOutPrintF(pdf," /Length1 ?\n"
- " /Length2 ?\n"
- " /Length3 ?\n"
- );
- }
- cfPDFOutPrintF(pdf,">>\n"
- "stream\n");
- long streamsize=-pdf->filepos;
- const int outlen=emb_embed(emb,pdfOut_outfn,pdf);
- streamsize+=pdf->filepos;
+ const int ff_obj = cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "<</Length %d 0 R\n",
+ ff_obj,
+ ff_obj + 1);
+ if (emb_pdf_get_fontfile_subtype(emb))
+ cfPDFOutPrintF(pdf, " /Subtype /%s\n",
+ emb_pdf_get_fontfile_subtype(emb));
+ if (emb->outtype == EMB_FMT_TTF)
+ cfPDFOutPrintF(pdf, " /Length1 %d 0 R\n",
+ ff_obj + 2);
+ else if (emb->outtype == EMB_FMT_T1) // TODO
+ cfPDFOutPrintF(pdf,
+ " /Length1 ?\n"
+ " /Length2 ?\n"
+ " /Length3 ?\n");
+ cfPDFOutPrintF(pdf,
+ ">>\n"
+ "stream\n");
+ long streamsize = -pdf->filepos;
+ const int outlen = emb_embed(emb, pdf_out_outfn, pdf);
+ streamsize += pdf->filepos;
cfPDFOutPrintF(pdf,"\nendstream\n"
"endobj\n");
- const int l0_obj=cfPDFOutAddXRef(pdf);
- DEBUG_assert(l0_obj==ff_obj+1);
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "%ld\n"
- "endobj\n"
- ,l0_obj,streamsize);
-
- if (emb->outtype==EMB_FMT_TTF) {
- const int l1_obj=cfPDFOutAddXRef(pdf);
- DEBUG_assert(l1_obj==ff_obj+2);
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "%d\n"
- "endobj\n"
- ,l1_obj,outlen);
+ const int l0_obj = cfPDFOutAddXRef(pdf);
+ DEBUG_assert(l0_obj == ff_obj + 1);
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "%ld\n"
+ "endobj\n",
+ l0_obj, streamsize);
+
+ if (emb->outtype == EMB_FMT_TTF)
+ {
+ const int l1_obj = cfPDFOutAddXRef(pdf);
+ DEBUG_assert(l1_obj == ff_obj + 2);
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "%d\n"
+ "endobj\n",
+ l1_obj, outlen);
}
- const int fd_obj=cfPDFOutAddXRef(pdf);
- char *res=emb_pdf_simple_fontdescr(emb,fdes,ff_obj);
- if (!res) {
+ const int fd_obj = cfPDFOutAddXRef(pdf);
+ char *res = emb_pdf_simple_fontdescr(emb, fdes, ff_obj);
+ if (!res)
+ {
free(fdes);
- return 0;
+ return (0);
}
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "%s"
- "endobj\n"
- ,fd_obj,res);
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "%s"
+ "endobj\n",
+ fd_obj, res);
free(res);
- EMB_PDF_FONTWIDTHS *fwid=emb_pdf_fontwidths(emb);
- if (!fwid) {
+ EMB_PDF_FONTWIDTHS *fwid = emb_pdf_fontwidths(emb);
+ if (!fwid)
+ {
free(fdes);
- return 0;
+ return (0);
}
- const int f_obj=cfPDFOutAddXRef(pdf);
- res=emb_pdf_simple_font(emb,fdes,fwid,fd_obj);
- if (!res) {
+ const int f_obj = cfPDFOutAddXRef(pdf);
+ res = emb_pdf_simple_font(emb, fdes, fwid, fd_obj);
+ if (!res)
+ {
free(fwid);
free(fdes);
- return 0;
+ return (0);
}
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "%s"
- "endobj\n"
- ,f_obj,res);
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "%s"
+ "endobj\n",
+ f_obj,res);
free(res);
free(fwid);
- if (emb->plan&EMB_A_MULTIBYTE) {
- res=emb_pdf_simple_cidfont(emb,fdes->fontname,f_obj);
- if (!res) {
+ if (emb->plan & EMB_A_MULTIBYTE)
+ {
+ res = emb_pdf_simple_cidfont(emb, fdes->fontname, f_obj);
+ if (!res)
+ {
free(fdes);
- return 0;
+ return (0);
}
- const int cf_obj=cfPDFOutAddXRef(pdf);
- cfPDFOutPrintF(pdf,"%d 0 obj\n"
- "%s"
- "endobj\n"
- ,cf_obj,res);
+ const int cf_obj = cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,
+ "%d 0 obj\n"
+ "%s"
+ "endobj\n",
+ cf_obj, res);
free(res);
free(fdes);
- return cf_obj;
+ return (cf_obj);
}
free(fdes);
- return f_obj;
+ return (f_obj);
}
// }}}
-/*
- * PDF file output routines.
- *
- * Copyright 2008 by Tobias Hoffmann.
- *
- * This file is licensed as noted in "COPYING"
- * which should have been included with this file.
- *
- */
+//
+// PDF file output routines.
+//
+// Copyright 2008 by Tobias Hoffmann.
+//
+// This file is licensed as noted in "COPYING"
+// which should have been included with this file.
+//
+
+#ifndef _CUPS_FILTERS_PDFUTILS_H_
+# define _CUPS_FILTERS_PDFUTILS_H_
+
+# ifdef __cplusplus
+extern "C" {
+# endif // __cplusplus
+
+
+//
+// Include necessary headers...
+//
+
#include <time.h>
#include <fontembed/embed.h>
-struct cf_keyval_t {
- char *key,*value;
+
+//
+// Types and structures...
+//
+
+struct cf_keyval_t
+{
+ char *key, *value;
};
-typedef struct {
+typedef struct
+{
long filepos;
- int pagessize,pagesalloc;
+ int pagessize, pagesalloc;
int *pages;
- int xrefsize,xrefalloc;
+ int xrefsize, xrefalloc;
long *xref;
- int kvsize,kvalloc;
+ int kvsize, kvalloc;
struct cf_keyval_t *kv;
} cf_pdf_out_t;
-/* allocates a new cf_pdf_out_t structure
- * returns NULL on error
- */
+
+//
+// Prototypes...
+//
+
+// allocates a new cf_pdf_out_t structure
+// returns NULL on error
+
cf_pdf_out_t *cfPDFOutNew();
void cfPDFOutFree(cf_pdf_out_t *pdf);
-/* start outputting a pdf
- * returns false on error
- */
+// start outputting a pdf
+// returns false on error
+
int cfPDFOutBeginPDF(cf_pdf_out_t *pdf);
void cfPDFOutFinishPDF(cf_pdf_out_t *pdf);
-/* General output routine for our pdf.
- * Keeps track of characters actually written out
- */
-void cfPDFOutPrintF(cf_pdf_out_t *pdf,const char *fmt,...)
+// General output routine for our pdf.
+// Keeps track of characters actually written out
+
+void cfPDFOutPrintF(cf_pdf_out_t *pdf, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
-/* write out an escaped pdf string: e.g. (Text \(Test\)\n)
- * >len==-1: use strlen(str)
- */
-void cfPDFOutputString(cf_pdf_out_t *pdf,const char *str,int len);
-void cfPDFOutputHexString(cf_pdf_out_t *pdf,const char *str,int len);
+// write out an escaped pdf string: e.g. (Text \(Test\)\n)
+// > len == -1: use strlen(str)
+
+void cfPDFOutputString(cf_pdf_out_t *pdf, const char *str, int len);
+void cfPDFOutputHexString(cf_pdf_out_t *pdf, const char *str, int len);
+
+// Format the broken up timestamp according to
+// pdf requirements for /CreationDate
+// NOTE: uses statically allocated buffer
-/* Format the broken up timestamp according to
- * pdf requirements for /CreationDate
- * NOTE: uses statically allocated buffer
- */
const char *cfPDFOutToPDFDate(struct tm *curtm);
-/* begin a new object at current point of the
- * output stream and add it to the xref table.
- * returns the obj number.
- */
+// begin a new object at current point of the
+// output stream and add it to the xref table.
+// returns the obj number.
+
int cfPDFOutAddXRef(cf_pdf_out_t *pdf);
-/* adds page dictionary >obj to the global Pages tree
- * returns false on error
- */
-int cfPDFOutAddPage(cf_pdf_out_t *pdf,int obj);
-
-/* add a >key,>val pair to the document's Info dictionary
- * returns false on error
- */
-int cfPDFOutAddKeyValue(cf_pdf_out_t *pdf,const char *key,const char *val);
-
-/* Writes the font >emb including descriptor to the pdf
- * and returns the object number.
- * On error 0 is returned.
- */
-int cfPDFOutWriteFont(cf_pdf_out_t *pdf,struct _EMB_PARAMS *emb);
+// adds page dictionary >obj to the global Pages tree
+// returns false on error
+
+int cfPDFOutAddPage(cf_pdf_out_t *pdf, int obj);
+
+// add a >key,>val pair to the document's Info dictionary
+// returns false on error
+
+int cfPDFOutAddKeyValue(cf_pdf_out_t *pdf, const char *key, const char *val);
+
+// Writes the font >emb including descriptor to the pdf
+// and returns the object number.
+// On error 0 is returned.
+
+int cfPDFOutWriteFont(cf_pdf_out_t *pdf, struct _EMB_PARAMS *emb);
+
+# ifdef __cplusplus
+}
+# endif // __cplusplus
+
+#endif // !_CUPS_FILTERS_PDFUTILS_H_
-/**
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * @brief Convert PWG Raster to a PDF/PCLm file
- * @file pwgtopdf.cpp
- * @author Neil 'Superna' Armstrong <superna9999@gmail.com> (C) 2010
- * @author Tobias Hoffmann <smilingthax@gmail.com> (c) 2012
- * @author Till Kamppeter <till.kamppeter@gmail.com> (c) 2014
- * @author Sahil Arora <sahilarora.535@gmail.com> (c) 2017
- */
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// @brief Convert PWG Raster to a PDF/PCLm file
+// @file pwgtopdf.cxx
+// @author Neil 'Superna' Armstrong <superna9999@gmail.com> (C) 2010
+// @author Tobias Hoffmann <smilingthax@gmail.com> (c) 2012
+// @author Till Kamppeter <till.kamppeter@gmail.com> (c) 2014
+// @author Sahil Arora <sahilarora.535@gmail.com> (c) 2017
+//
#include "filter.h"
#include <config.h>
#define DEFAULT_PDF_UNIT 72 // 1/72 inch
-#define PROGRAM "pwgtopdf"
+#define PRE_COMPRESS
+
// Compression method for providing data to PCLm Streams.
-typedef enum compression_method_e {
+typedef enum compression_method_e
+{
DCT_DECODE = 0,
FLATE_DECODE,
RLE_DECODE
// Color conversion function
typedef unsigned char *(*convert_function)(unsigned char *src,
- unsigned char *dst, unsigned int pixels);
+ unsigned char *dst,
+ unsigned int pixels);
// Bit conversion function
typedef unsigned char *(*bit_convert_function)(unsigned char *src,
- unsigned char *dst, unsigned int pixels);
+ unsigned char *dst,
+ unsigned int pixels);
-typedef struct pwgtopdf_doc_s /**** Document information ****/
+typedef struct pwgtopdf_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 */
- convert_function conversion_function; /* Raster color conversion
- 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 */
- void *logdata; /* User data for logging
- function, can be NULL */
- 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 */
+ cmsHPROFILE colorProfile = NULL; // ICC Profile to be applied to
+ // PDF
+ int cm_disabled = 0; // Flag raised if color
+ // management is disabled
+ convert_function conversion_function; // Raster color conversion
+ // 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
+ void *logdata; // User data for logging
+ // function, can be NULL
+ 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
} pwgtopdf_doc_t;
// PDF color conversion function
typedef void (*pdf_convert_function)(struct pdf_info * info,
- pwgtopdf_doc_t *doc);
+ pwgtopdf_doc_t *doc);
+
+
+struct pdf_info // **** PDF ****
+{
+ pdf_info()
+ : pagecount(0),
+ width(0), height(0),
+ line_bytes(0),
+ bpp(0), bpc(0),
+ pclm_num_strips(0),
+ pclm_strip_height_preferred(16), // default strip height
+ pclm_strip_height(0),
+ pclm_strip_height_supported(1, 16),
+ pclm_compression_method_preferred(0),
+ pclm_source_resolution_supported(0),
+ pclm_source_resolution_default(""),
+ pclm_raster_back_side(""),
+ pclm_strip_data(0),
+ render_intent(""),
+ color_space(CUPS_CSPACE_K),
+ page_width(0), page_height(0),
+ outformat(CF_FILTER_OUT_FORMAT_PDF)
+ {
+ }
+
+ QPDF pdf;
+ QPDFObjectHandle page;
+ unsigned pagecount;
+ unsigned width;
+ unsigned height;
+ unsigned line_bytes;
+ unsigned bpp;
+ unsigned bpc;
+ unsigned pclm_num_strips;
+ unsigned pclm_strip_height_preferred;
+ std::vector<unsigned> pclm_strip_height;
+ std::vector<unsigned> pclm_strip_height_supported;
+ std::vector<compression_method_t> pclm_compression_method_preferred;
+ std::vector<std::string> pclm_source_resolution_supported;
+ std::string pclm_source_resolution_default;
+ std::string pclm_raster_back_side;
+ std::vector< PointerHolder<Buffer> > pclm_strip_data;
+ std::string render_intent;
+ cups_cspace_t color_space;
+ PointerHolder<Buffer> page_data;
+ double page_width,page_height;
+ cf_filter_out_format_t outformat;
+};
+//
// Bit conversion functions
-static unsigned char *invert_bits(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;
+ unsigned int i;
- // Invert black to grayscale...
- for (i = pixels, dst = src; i > 0; i --, dst ++)
- *dst = ~*dst;
+ // Invert black to grayscale...
+ for (i = pixels, dst = src; i > 0; i --, dst ++)
+ *dst = ~*dst;
- return dst;
+ return (dst);
}
-static unsigned char *no_bit_conversion(unsigned char *src, unsigned char *dst,
- unsigned int pixels)
+
+static unsigned char *
+no_bit_conversion(unsigned char *src,
+ unsigned char *dst,
+ unsigned int pixels)
{
- return src;
+ return (src);
}
+
+//
// Color conversion functions
-static unsigned char *rgb_to_cmyk(unsigned char *src, unsigned char *dst,
- unsigned int pixels)
+//
+
+static unsigned char *
+rgb_to_cmyk(unsigned char *src,
+ unsigned char *dst,
+ unsigned int pixels)
{
- cfImageRGBToCMYK(src,dst,pixels);
- return dst;
+ cfImageRGBToCMYK(src, dst, pixels);
+ return (dst);
}
-static unsigned char *white_to_cmyk(unsigned char *src, unsigned char *dst,
- unsigned int pixels)
+
+static unsigned char *
+white_to_cmyk(unsigned char *src,
+ unsigned char *dst,
+ unsigned int pixels)
{
- cfImageWhiteToCMYK(src,dst,pixels);
- return dst;
+ cfImageWhiteToCMYK(src, dst, pixels);
+ return (dst);
}
-static unsigned char *cmyk_to_rgb(unsigned char *src, unsigned char *dst,
- unsigned int pixels)
+
+static unsigned char *
+cmyk_to_rgb(unsigned char *src,
+ unsigned char *dst,
+ unsigned int pixels)
{
- cfImageCMYKToRGB(src,dst,pixels);
- return dst;
+ cfImageCMYKToRGB(src, dst, pixels);
+ return (dst);
}
-static unsigned char *white_to_rgb(unsigned char *src, unsigned char *dst,
- unsigned int pixels)
+
+static unsigned char *
+white_to_rgb(unsigned char *src,
+ unsigned char *dst,
+ unsigned int pixels)
{
- cfImageWhiteToRGB(src,dst,pixels);
- return dst;
+ cfImageWhiteToRGB(src, dst, pixels);
+ return (dst);
}
-static unsigned char *rgb_to_white(unsigned char *src, unsigned char *dst,
- unsigned int pixels)
+
+static unsigned char *
+rgb_to_white(unsigned char *src,
+ unsigned char *dst,
+ unsigned int pixels)
{
- cfImageRGBToWhite(src,dst,pixels);
- return dst;
+ cfImageRGBToWhite(src, dst, pixels);
+ return (dst);
}
-static unsigned char *cmyk_to_white(unsigned char *src, unsigned char *dst,
- unsigned int pixels)
+
+static unsigned char *
+cmyk_to_white(unsigned char *src,
+ unsigned char *dst,
+ unsigned int pixels)
{
- cfImageCMYKToWhite(src,dst,pixels);
- return dst;
+ cfImageCMYKToWhite(src, dst, pixels);
+ return (dst);
}
-static unsigned char *no_color_conversion(unsigned char *src,
- unsigned char *dst, unsigned int pixels)
+
+static unsigned char *
+no_color_conversion(unsigned char *src,
+ unsigned char *dst,
+ unsigned int pixels)
{
- return src;
+ return (src);
}
-/**
- * 'split_strings()' - Split a string to a vector of strings given some
- * delimiters
- * O - std::vector of std::string after splitting
- * I - input string to be split
- * I - string containing delimiters
- */
+
+//
+// 'split_strings()' - Split a string to a vector of strings given some
+// delimiters
+//
+// O - std::vector of std::string after splitting
+// I - input string to be split
+// I - string containing delimiters
+//
+
static std::vector<std::string>
-split_strings(std::string const &str, std::string delimiters = ",")
+split_strings(std::string const &str,
+ std::string delimiters = ",")
{
std::vector<std::string> vec(0);
std::string value = "";
}
if (!value.empty())
vec.push_back(value);
- return vec;
+ return (vec);
}
-/**
- * 'num_digits()' - Calculates the number of digits in an integer
- * O - number of digits in the input integer
- * I - the integer whose digits needs to be calculated
- */
-static int num_digits(int n)
+
+//
+// 'num_digits()' - Calculates the number of digits in an integer
+//
+// O - number of digits in the input integer
+// I - the integer whose digits needs to be calculated
+//
+
+static int
+num_digits(int n)
{
- if (n == 0) return 1;
+ if (n == 0)
+ return (1);
int digits = 0;
while (n)
{
++digits;
n /= 10;
}
- return digits;
+ return (digits);
}
-/**
- * 'int_to_fwstring()' - Convert a number to fixed width string by padding
- * with zeroes
- * O - converted string
- * I - the integee which needs to be converted to string
- * I - width of string required
- */
-static std::string int_to_fwstring(int n, int width)
+
+//
+// 'int_to_fwstring()' - Convert a number to fixed width string by padding
+// with zeroes
+// O - converted string
+// I - the integee which needs to be converted to string
+// I - width of string required
+//
+
+static std::string
+int_to_fwstring(int n,
+ int width)
{
int num_zeroes = width - num_digits(n);
if (num_zeroes < 0)
num_zeroes = 0;
- return std::string(num_zeroes, '0') + QUtil::int_to_string(n);
+ return (std::string(num_zeroes, '0') + QUtil::int_to_string(n));
}
-//------------- PDF ---------------
-
-struct pdf_info
+static int
+create_pdf_file(struct pdf_info * info,
+ const cf_filter_out_format_t &outformat)
{
- pdf_info()
- : pagecount(0),
- width(0),height(0),
- line_bytes(0),
- bpp(0), bpc(0),
- pclm_num_strips(0),
- pclm_strip_height_preferred(16), /* default strip height */
- pclm_strip_height(0),
- pclm_strip_height_supported(1, 16),
- pclm_compression_method_preferred(0),
- pclm_source_resolution_supported(0),
- pclm_source_resolution_default(""),
- pclm_raster_back_side(""),
- pclm_strip_data(0),
- render_intent(""),
- color_space(CUPS_CSPACE_K),
- page_width(0),page_height(0),
- outformat(CF_FILTER_OUT_FORMAT_PDF)
- {
- }
+ try {
+ info->pdf.emptyPDF();
+ info->outformat = outformat;
+ } catch (...) {
+ return (1);
+ }
+ return (0);
+}
- QPDF pdf;
- QPDFObjectHandle page;
- unsigned pagecount;
- unsigned width;
- unsigned height;
- unsigned line_bytes;
- unsigned bpp;
- unsigned bpc;
- unsigned pclm_num_strips;
- unsigned pclm_strip_height_preferred;
- std::vector<unsigned> pclm_strip_height;
- std::vector<unsigned> pclm_strip_height_supported;
- std::vector<compression_method_t> pclm_compression_method_preferred;
- std::vector<std::string> pclm_source_resolution_supported;
- std::string pclm_source_resolution_default;
- std::string pclm_raster_back_side;
- std::vector< PointerHolder<Buffer> > pclm_strip_data;
- std::string render_intent;
- cups_cspace_t color_space;
- PointerHolder<Buffer> page_data;
- double page_width,page_height;
- cf_filter_out_format_t outformat;
-};
-static int create_pdf_file(struct pdf_info * info,
- const cf_filter_out_format_t &outformat)
+static QPDFObjectHandle
+make_real_box(double x1,
+ double y1,
+ double x2,
+ double y2)
{
- try {
- info->pdf.emptyPDF();
- info->outformat = outformat;
- } catch (...) {
- return 1;
- }
- return 0;
+ QPDFObjectHandle ret = QPDFObjectHandle::newArray();
+ ret.appendItem(QPDFObjectHandle::newReal(x1));
+ ret.appendItem(QPDFObjectHandle::newReal(y1));
+ ret.appendItem(QPDFObjectHandle::newReal(x2));
+ ret.appendItem(QPDFObjectHandle::newReal(y2));
+ return (ret);
}
-static QPDFObjectHandle make_real_box(double x1, double y1, double x2, double y2)
-{
- QPDFObjectHandle ret=QPDFObjectHandle::newArray();
- ret.appendItem(QPDFObjectHandle::newReal(x1));
- ret.appendItem(QPDFObjectHandle::newReal(y1));
- ret.appendItem(QPDFObjectHandle::newReal(x2));
- ret.appendItem(QPDFObjectHandle::newReal(y2));
- return ret;
-}
-static QPDFObjectHandle make_integer_box(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));
- ret.appendItem(QPDFObjectHandle::newInteger(y1));
- ret.appendItem(QPDFObjectHandle::newInteger(x2));
- ret.appendItem(QPDFObjectHandle::newInteger(y2));
- return ret;
+ QPDFObjectHandle ret = QPDFObjectHandle::newArray();
+ ret.appendItem(QPDFObjectHandle::newInteger(x1));
+ ret.appendItem(QPDFObjectHandle::newInteger(y1));
+ ret.appendItem(QPDFObjectHandle::newInteger(x2));
+ ret.appendItem(QPDFObjectHandle::newInteger(y2));
+ return (ret);
}
-
-
+//
// PDF color conversion functons...
-
-static void modify_pdf_color(struct pdf_info * info, int bpp, int bpc,
- convert_function fn, pwgtopdf_doc_t *doc)
+//
+
+static void
+modify_pdf_color(struct pdf_info *info,
+ int bpp,
+ int bpc,
+ convert_function fn,
+ pwgtopdf_doc_t *doc)
{
- unsigned old_bpp = info->bpp;
- unsigned old_bpc = info->bpc;
- double old_ncolor = old_bpp/old_bpc;
-
- unsigned old_line_bytes = info->line_bytes;
+ unsigned old_bpp = info->bpp;
+ unsigned old_bpc = info->bpc;
+ double old_ncolor = old_bpp / old_bpc;
- double new_ncolor = (bpp/bpc);
+ unsigned old_line_bytes = info->line_bytes;
- info->line_bytes = (unsigned)old_line_bytes*(new_ncolor/old_ncolor);
- info->bpp = bpp;
- info->bpc = bpc;
- doc->conversion_function = fn;
+ double new_ncolor = bpp / bpc;
- return;
+ info->line_bytes = (unsigned)old_line_bytes * (new_ncolor / old_ncolor);
+ info->bpp = bpp;
+ info->bpc = bpc;
+ doc->conversion_function = fn;
}
-static void convert_pdf_no_conversion(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static void
+convert_pdf_no_conversion(struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- doc->conversion_function = no_color_conversion;
- doc->bit_function = no_bit_conversion;
+ doc->conversion_function = no_color_conversion;
+ doc->bit_function = no_bit_conversion;
}
-static void convert_pdf_cmyk_8_to_white_8(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static void
+convert_pdf_cmyk_8_to_white_8(struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- modify_pdf_color(info, 8, 8, cmyk_to_white, doc);
- doc->bit_function = no_bit_conversion;
+ modify_pdf_color(info, 8, 8, cmyk_to_white, doc);
+ doc->bit_function = no_bit_conversion;
}
-static void convert_pdf_rgb_8_to_white_8(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static void
+convert_pdf_rgb_8_to_white_8(struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- modify_pdf_color(info, 8, 8, rgb_to_white, doc);
- doc->bit_function = no_bit_conversion;
+ modify_pdf_color(info, 8, 8, rgb_to_white, doc);
+ doc->bit_function = no_bit_conversion;
}
-static void convert_pdf_cmyk_8_to_rgb_8(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static void
+convert_pdf_cmyk_8_to_rgb_8(struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- modify_pdf_color(info, 24, 8, cmyk_to_rgb, doc);
- doc->bit_function = no_bit_conversion;
+ modify_pdf_color(info, 24, 8, cmyk_to_rgb, doc);
+ doc->bit_function = no_bit_conversion;
}
-static void convert_pdf_white_8_to_rgb_8(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static void
+convert_pdf_white_8_to_rgb_8(struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- modify_pdf_color(info, 24, 8, white_to_rgb, doc);
- doc->bit_function = invert_bits;
+ modify_pdf_color(info, 24, 8, white_to_rgb, doc);
+ doc->bit_function = invert_bits;
}
-static void convert_pdf_rgb_8_to_cmyk_8(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static void
+convert_pdf_rgb_8_to_cmyk_8(struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- modify_pdf_color(info, 32, 8, rgb_to_cmyk, doc);
- doc->bit_function = no_bit_conversion;
+ modify_pdf_color(info, 32, 8, rgb_to_cmyk, doc);
+ doc->bit_function = no_bit_conversion;
}
-static void convert_pdf_white_8_to_cmyk_8(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static void
+convert_pdf_white_8_to_cmyk_8(struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- modify_pdf_color(info, 32, 8, white_to_cmyk, doc);
- doc->bit_function = invert_bits;
+ modify_pdf_color(info, 32, 8, white_to_cmyk, doc);
+ doc->bit_function = invert_bits;
}
-static void convert_pdf_invert_colors(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static void
+convert_pdf_invert_colors(struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- doc->conversion_function = no_color_conversion;
- doc->bit_function = invert_bits;
+ doc->conversion_function = no_color_conversion;
+ doc->bit_function = invert_bits;
}
-#define PRE_COMPRESS
-
+//
// Create an '/ICCBased' array and embed a previously
// set ICC Profile in the PDF
-static QPDFObjectHandle embed_icc_profile(QPDF &pdf, pwgtopdf_doc_t *doc)
+//
+
+static QPDFObjectHandle
+embed_icc_profile(QPDF &pdf,
+ pwgtopdf_doc_t *doc)
{
- if (doc->colorProfile == NULL) {
- return QPDFObjectHandle::newNull();
- }
-
- // Return handler
- QPDFObjectHandle ret;
- // ICCBased array
- QPDFObjectHandle array = QPDFObjectHandle::newArray();
- // Profile stream dictionary
- QPDFObjectHandle iccstream;
-
- std::map<std::string,QPDFObjectHandle> dict;
- std::map<std::string,QPDFObjectHandle> streamdict;
- std::string n_value = "";
- std::string alternate_cs = "";
- PointerHolder<Buffer>ph;
+ if (doc->colorProfile == NULL)
+ return (QPDFObjectHandle::newNull());
+
+ // Return handler
+ QPDFObjectHandle ret;
+ // ICCBased array
+ QPDFObjectHandle array = QPDFObjectHandle::newArray();
+ // Profile stream dictionary
+ QPDFObjectHandle iccstream;
+
+ std::map<std::string,QPDFObjectHandle> dict;
+ std::map<std::string,QPDFObjectHandle> streamdict;
+ std::string n_value = "";
+ std::string alternate_cs = "";
+ PointerHolder<Buffer>ph;
#ifdef USE_LCMS1
- size_t profile_size;
+ size_t profile_size;
#else
- unsigned int profile_size;
+ unsigned int profile_size;
#endif
- cmsColorSpaceSignature css = cmsGetColorSpace(doc->colorProfile);
+ cmsColorSpaceSignature css = cmsGetColorSpace(doc->colorProfile);
- // Write color component # for /ICCBased array in stream dictionary
- switch(css){
- case cmsSigGrayData:
+ // Write color component # for /ICCBased array in stream dictionary
+ switch (css)
+ {
+ case cmsSigGrayData:
n_value = "1";
alternate_cs = "/DeviceGray";
break;
- case cmsSigRgbData:
+ case cmsSigRgbData:
n_value = "3";
alternate_cs = "/DeviceRGB";
break;
- case cmsSigCmykData:
+ case cmsSigCmykData:
n_value = "4";
alternate_cs = "/DeviceCMYK";
break;
- default:
- if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Failed to embed ICC Profile.");
- return QPDFObjectHandle::newNull();
- }
+ default:
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Failed to embed ICC Profile.");
+ return (QPDFObjectHandle::newNull());
+ }
- streamdict["/Alternate"]=QPDFObjectHandle::newName(alternate_cs);
- streamdict["/N"]=QPDFObjectHandle::newName(n_value);
+ streamdict["/Alternate"] = QPDFObjectHandle::newName(alternate_cs);
+ streamdict["/N"] = QPDFObjectHandle::newName(n_value);
- // Read profile into memory
- cmsSaveProfileToMem(doc->colorProfile, NULL, &profile_size);
- unsigned char *buff =
- (unsigned char *)calloc(profile_size, sizeof(unsigned char));
- cmsSaveProfileToMem(doc->colorProfile, buff, &profile_size);
+ // Read profile into memory
+ cmsSaveProfileToMem(doc->colorProfile, NULL, &profile_size);
+ unsigned char *buff =
+ (unsigned char *)calloc(profile_size, sizeof(unsigned char));
+ cmsSaveProfileToMem(doc->colorProfile, buff, &profile_size);
- // Write ICC profile buffer into PDF
- ph = new Buffer(buff, profile_size);
- iccstream = QPDFObjectHandle::newStream(&pdf, ph);
- iccstream.replaceDict(QPDFObjectHandle::newDictionary(streamdict));
+ // Write ICC profile buffer into PDF
+ ph = new Buffer(buff, profile_size);
+ iccstream = QPDFObjectHandle::newStream(&pdf, ph);
+ iccstream.replaceDict(QPDFObjectHandle::newDictionary(streamdict));
- array.appendItem(QPDFObjectHandle::newName("/ICCBased"));
- array.appendItem(iccstream);
+ array.appendItem(QPDFObjectHandle::newName("/ICCBased"));
+ array.appendItem(iccstream);
- // Return a PDF object reference to an '/ICCBased' array
- ret = pdf.makeIndirectObject(array);
+ // Return a PDF object reference to an '/ICCBased' array
+ ret = pdf.makeIndirectObject(array);
- free(buff);
- if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: ICC Profile embedded in PDF.");
+ free(buff);
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: ICC Profile embedded in PDF.");
- return ret;
+ return (ret);
}
-static QPDFObjectHandle embed_srgb_profile(QPDF &pdf, pwgtopdf_doc_t *doc)
+
+static QPDFObjectHandle
+embed_srgb_profile(QPDF &pdf,
+ pwgtopdf_doc_t *doc)
{
- QPDFObjectHandle iccbased_reference;
+ QPDFObjectHandle iccbased_reference;
- // Create an sRGB profile from lcms
- doc->colorProfile = cmsCreate_sRGBProfile();
- // Embed it into the profile
- iccbased_reference = embed_icc_profile(pdf, doc);
+ // Create an sRGB profile from lcms
+ doc->colorProfile = cmsCreate_sRGBProfile();
+ // Embed it into the profile
+ iccbased_reference = embed_icc_profile(pdf, doc);
- return iccbased_reference;
+ return (iccbased_reference);
}
-/*
-Calibration function for non-Lab PDF color spaces
-Requires white point data, and if available, gamma or matrix numbers.
-
-Output:
- [/'color_space'
- << /Gamma ['gamma[0]'...'gamma[n]']
- /WhitePoint ['wp[0]' 'wp[1]' 'wp[2]']
- /Matrix ['matrix[0]'...'matrix[n*n]']
- >>
- ]
-*/
-static QPDFObjectHandle get_calibration_array(const char * color_space, double wp[],
- double gamma[], double matrix[],
- double bp[])
+
+//
+// Calibration function for non-Lab PDF color spaces
+// Requires white point data, and if available, gamma or matrix numbers.
+//
+// Output:
+// [/'color_space'
+// << /Gamma ['gamma[0]'...'gamma[n]']
+// /WhitePoint ['wp[0]' 'wp[1]' 'wp[2]']
+// /Matrix ['matrix[0]'...'matrix[n*n]']
+// >>
+// ]
+//
+
+static QPDFObjectHandle
+get_calibration_array(const char *color_space,
+ double wp[],
+ double gamma[],
+ double matrix[],
+ double bp[])
{
- // Check for invalid input
- if ((!strcmp("/CalGray", color_space) && matrix != NULL) ||
- wp == NULL)
- return QPDFObjectHandle();
+ // Check for invalid input
+ if ((!strcmp("/CalGray", color_space) && matrix != NULL) ||
+ wp == NULL)
+ return (QPDFObjectHandle());
+
+ QPDFObjectHandle ret;
+ std::string csString = color_space;
+ std::string colorSpaceArrayString = "";
+
+ char gamma_str[128];
+ char bp_str[256];
+ char wp_str[256];
+ char matrix_str[512];
+
+ // Convert numbers into string data for /Gamma, /WhitePoint, and/or /Matrix
+
+ // WhitePoint
+ snprintf(wp_str, sizeof(wp_str), "/WhitePoint [%g %g %g]",
+ wp[0], wp[1], wp[2]);
+
+ // Gamma
+ if (!strcmp("/CalGray", color_space) && gamma != NULL)
+ snprintf(gamma_str, sizeof(gamma_str), "/Gamma %g",
+ gamma[0]);
+ else if (!strcmp("/CalRGB", color_space) && gamma != NULL)
+ snprintf(gamma_str, sizeof(gamma_str), "/Gamma [%g %g %g]",
+ gamma[0], gamma[1], gamma[2]);
+ else
+ gamma_str[0] = '\0';
- QPDFObjectHandle ret;
- std::string csString = color_space;
- std::string colorSpaceArrayString = "";
+ // BlackPoint
+ if (bp != NULL)
+ snprintf(bp_str, sizeof(bp_str), "/BlackPoint [%g %g %g]",
+ bp[0], bp[1], bp[2]);
+ else
+ bp_str[0] = '\0';
+
+ // Matrix
+ if (!strcmp("/CalRGB", color_space) && matrix != NULL) {
+ snprintf(matrix_str, sizeof(matrix_str),
+ "/Matrix [%g %g %g %g %g %g %g %g %g]",
+ matrix[0], matrix[1], matrix[2],
+ matrix[3], matrix[4], matrix[5],
+ matrix[6], matrix[7], matrix[8]);
+ } else
+ matrix_str[0] = '\0';
+
+ // Write array string...
+ colorSpaceArrayString = "[" + csString + " <<" + gamma_str + " " + wp_str +
+ " " + matrix_str + " " + bp_str + " >>]";
+
+ ret = QPDFObjectHandle::parse(colorSpaceArrayString);
+
+ return (ret);
+}
- char gamma_str[128];
- char bp_str[256];
- char wp_str[256];
- char matrix_str[512];
+static QPDFObjectHandle
+get_cal_rgb_array(double wp[3],
+ double gamma[3],
+ double matrix[9],
+ double bp[3])
+{
+ QPDFObjectHandle ret = get_calibration_array("/CalRGB", wp, gamma, matrix,
+ bp);
+ return (ret);
+}
- // Convert numbers into string data for /Gamma, /WhitePoint, and/or /Matrix
+static QPDFObjectHandle
+get_cal_gray_array(double wp[3],
+ double gamma[1],
+ double bp[3])
+{
+ QPDFObjectHandle ret = get_calibration_array("/CalGray", wp, gamma, 0, bp);
+ return (ret);
+}
- // WhitePoint
- snprintf(wp_str, sizeof(wp_str), "/WhitePoint [%g %g %g]",
- wp[0], wp[1], wp[2]);
+//
+// '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
+// I - QPDF object
+// I - number of strips per page
+// I - std::vector of PointerHolder<Buffer> containing data for each strip
+// I - strip width
+// I - strip height
+// I - color space
+// I - bits per component
+// I - document information
+//
- // Gamma
- if (!strcmp("/CalGray", color_space) && gamma != NULL)
- snprintf(gamma_str, sizeof(gamma_str), "/Gamma %g",
- gamma[0]);
- else if (!strcmp("/CalRGB", color_space) && gamma != NULL)
- snprintf(gamma_str, sizeof(gamma_str), "/Gamma [%g %g %g]",
- gamma[0], gamma[1], gamma[2]);
- else
- gamma_str[0] = '\0';
-
+static std::vector<QPDFObjectHandle>
+make_pclm_strips(QPDF &pdf,
+ unsigned num_strips,
+ std::vector< PointerHolder<Buffer> > &strip_data,
+ std::vector<compression_method_t> &compression_methods,
+ unsigned width, std::vector<unsigned>& strip_height,
+ cups_cspace_t cs,
+ unsigned bpc,
+ pwgtopdf_doc_t *doc)
+{
+ std::vector<QPDFObjectHandle> ret(num_strips);
+ for (size_t i = 0; i < num_strips; i ++)
+ ret[i] = QPDFObjectHandle::newStream(&pdf);
+
+ // Strip stream dictionary
+ std::map<std::string,QPDFObjectHandle> dict;
+
+ dict["/Type"] = QPDFObjectHandle::newName("/XObject");
+ dict["/Subtype"] = QPDFObjectHandle::newName("/Image");
+ dict["/Width"] = QPDFObjectHandle::newInteger(width);
+ dict["/BitsPerComponent"] = QPDFObjectHandle::newInteger(bpc);
+
+ J_COLOR_SPACE color_space;
+ unsigned components;
+ // Write "/ColorSpace" dictionary based on raster input
+ switch(cs)
+ {
+ case CUPS_CSPACE_K:
+ case CUPS_CSPACE_SW:
+ dict["/ColorSpace"] = QPDFObjectHandle::newName("/DeviceGray");
+ color_space = JCS_GRAYSCALE;
+ components = 1;
+ break;
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_SRGB:
+ case CUPS_CSPACE_ADOBERGB:
+ dict["/ColorSpace"] = QPDFObjectHandle::newName("/DeviceRGB");
+ color_space = JCS_RGB;
+ components = 3;
+ break;
+ default:
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Color space not supported.");
+ return (std::vector<QPDFObjectHandle>(num_strips, QPDFObjectHandle()));
+ }
- // BlackPoint
- if (bp != NULL)
- snprintf(bp_str, sizeof(bp_str), "/BlackPoint [%g %g %g]",
- bp[0], bp[1], bp[2]);
- else
- bp_str[0] = '\0';
+ //
+ // We deliver already compressed content (instead of letting QPDFWriter
+ // do it) to avoid using excessive memory. For that we first get preferred
+ // compression method to pre-compress content for strip streams.
+ //
+ // Use the compression method with highest priority of the available methods
+ // __________________
+ // Priority | Method
+ // ------------------
+ // 0 | DCT
+ // 1 | FLATE
+ // 2 | RLE
+ // ------------------
+ //
+
+ compression_method_t compression = compression_methods.front();
+ for (std::vector<compression_method_t>::iterator it =
+ compression_methods.begin();
+ it != compression_methods.end(); ++it)
+ compression = compression > *it ? compression : *it;
+
+ // write compressed stream data
+ for (size_t i = 0; i < num_strips; i ++)
+ {
+ dict["/Height"] = QPDFObjectHandle::newInteger(strip_height[i]);
+ ret[i].replaceDict(QPDFObjectHandle::newDictionary(dict));
+ Pl_Buffer psink("psink");
+ if (compression == FLATE_DECODE)
+ {
+ Pl_Flate pflate("pflate", &psink, Pl_Flate::a_deflate);
+ pflate.write(strip_data[i]->getBuffer(), strip_data[i]->getSize());
+ pflate.finish();
+ ret[i].replaceStreamData(PointerHolder<Buffer>(psink.getBuffer()),
+ QPDFObjectHandle::newName("/FlateDecode"),
+ QPDFObjectHandle::newNull());
+ }
+ else if (compression == RLE_DECODE)
+ {
+ Pl_RunLength prle("prle", &psink, Pl_RunLength::a_encode);
+ prle.write(strip_data[i]->getBuffer(), strip_data[i]->getSize());
+ prle.finish();
+ ret[i].replaceStreamData(PointerHolder<Buffer>(psink.getBuffer()),
+ QPDFObjectHandle::newName("/RunLengthDecode"),
+ QPDFObjectHandle::newNull());
+ }
+ else if (compression == DCT_DECODE)
+ {
+ Pl_DCT pdct("pdct", &psink, width, strip_height[i], components,
+ color_space);
+ pdct.write(strip_data[i]->getBuffer(), strip_data[i]->getSize());
+ pdct.finish();
+ ret[i].replaceStreamData(PointerHolder<Buffer>(psink.getBuffer()),
+ QPDFObjectHandle::newName("/DCTDecode"),
+ QPDFObjectHandle::newNull());
+ }
+ }
+ return (ret);
+}
- // Matrix
- if (!strcmp("/CalRGB", color_space) && matrix != NULL) {
- snprintf(matrix_str, sizeof(matrix_str),
- "/Matrix [%g %g %g %g %g %g %g %g %g]",
- matrix[0], matrix[1], matrix[2],
- matrix[3], matrix[4], matrix[5],
- matrix[6], matrix[7], matrix[8]);
- } else
- matrix_str[0] = '\0';
+static QPDFObjectHandle
+make_image(QPDF &pdf,
+ PointerHolder<Buffer> page_data,
+ unsigned width,
+ unsigned height,
+ std::string render_intent,
+ cups_cspace_t cs,
+ unsigned bpc,
+ pwgtopdf_doc_t *doc)
+{
+ QPDFObjectHandle ret = QPDFObjectHandle::newStream(&pdf);
+ QPDFObjectHandle icc_ref;
- // Write array string...
- colorSpaceArrayString = "[" + csString + " <<" + gamma_str + " " + wp_str +
- " " + matrix_str + " " + bp_str + " >>]";
-
- ret = QPDFObjectHandle::parse(colorSpaceArrayString);
+ int use_blackpoint = 0;
+ std::map<std::string,QPDFObjectHandle> dict;
- return ret;
-}
+ dict["/Type"] = QPDFObjectHandle::newName("/XObject");
+ dict["/Subtype"] = QPDFObjectHandle::newName("/Image");
+ dict["/Width"] = QPDFObjectHandle::newInteger(width);
+ dict["/Height"] = QPDFObjectHandle::newInteger(height);
+ dict["/BitsPerComponent"] = QPDFObjectHandle::newInteger(bpc);
-static QPDFObjectHandle get_cal_rgb_array(double wp[3], double gamma[3],
- double matrix[9], double bp[3])
-{
- QPDFObjectHandle ret = get_calibration_array("/CalRGB", wp, gamma, matrix,
- bp);
- return ret;
-}
+ if (!doc->cm_disabled)
+ {
+ // Write rendering intent into the PDF based on raster settings
+ if (render_intent == "Perceptual")
+ dict["/Intent"] = QPDFObjectHandle::newName("/Perceptual");
+ else if (render_intent == "Absolute")
+ dict["/Intent"] = QPDFObjectHandle::newName("/AbsoluteColorimetric");
+ else if (render_intent == "Relative")
+ dict["/Intent"] = QPDFObjectHandle::newName("/RelativeColorimetric");
+ else if (render_intent == "Saturation")
+ dict["/Intent"] = QPDFObjectHandle::newName("/Saturation");
+ else if (render_intent == "RelativeBpc")
+ {
+ // Enable blackpoint compensation
+ dict["/Intent"] = QPDFObjectHandle::newName("/RelativeColorimetric");
+ use_blackpoint = 1;
+ }
+ }
-static QPDFObjectHandle get_cal_gray_array(double wp[3], double gamma[1], double bp[3])
-{
- QPDFObjectHandle ret = get_calibration_array("/CalGray", wp, gamma, 0, bp);
- return ret;
-}
+ // Write "/ColorSpace" dictionary based on raster input
+ if (doc->colorProfile != NULL && !doc->cm_disabled)
+ {
+ icc_ref = embed_icc_profile(pdf, doc);
-/**
- * '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
- * I - QPDF object
- * I - number of strips per page
- * I - std::vector of PointerHolder<Buffer> containing data for each strip
- * I - strip width
- * I - strip height
- * I - color space
- * I - bits per component
- * I - document information
- */
-static std::vector<QPDFObjectHandle>
-make_pclm_strips(QPDF &pdf, unsigned num_strips,
- std::vector< PointerHolder<Buffer> > &strip_data,
- std::vector<compression_method_t> &compression_methods,
- unsigned width, std::vector<unsigned>& strip_height,
- cups_cspace_t cs, unsigned bpc, pwgtopdf_doc_t *doc)
-{
- std::vector<QPDFObjectHandle> ret(num_strips);
- for (size_t i = 0; i < num_strips; i ++)
- ret[i] = QPDFObjectHandle::newStream(&pdf);
-
- // Strip stream dictionary
- std::map<std::string,QPDFObjectHandle> dict;
-
- dict["/Type"]=QPDFObjectHandle::newName("/XObject");
- dict["/Subtype"]=QPDFObjectHandle::newName("/Image");
- dict["/Width"]=QPDFObjectHandle::newInteger(width);
- dict["/BitsPerComponent"]=QPDFObjectHandle::newInteger(bpc);
-
- J_COLOR_SPACE color_space;
- unsigned components;
- /* Write "/ColorSpace" dictionary based on raster input */
- switch(cs) {
+ if (!icc_ref.isNull())
+ dict["/ColorSpace"] = icc_ref;
+ }
+ else if (!doc->cm_disabled)
+ {
+ switch (cs)
+ {
+ case CUPS_CSPACE_DEVICE1:
+ case CUPS_CSPACE_DEVICE2:
+ case CUPS_CSPACE_DEVICE3:
+ case CUPS_CSPACE_DEVICE4:
+ case CUPS_CSPACE_DEVICE5:
+ case CUPS_CSPACE_DEVICE6:
+ case CUPS_CSPACE_DEVICE7:
+ case CUPS_CSPACE_DEVICE8:
+ case CUPS_CSPACE_DEVICE9:
+ case CUPS_CSPACE_DEVICEA:
+ case CUPS_CSPACE_DEVICEB:
+ case CUPS_CSPACE_DEVICEC:
+ case CUPS_CSPACE_DEVICED:
+ case CUPS_CSPACE_DEVICEE:
+ case CUPS_CSPACE_DEVICEF:
+ // For right now, DeviceN will use /DeviceCMYK in the PDF
+ dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceCMYK");
+ break;
case CUPS_CSPACE_K:
+ dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceGray");
+ break;
case CUPS_CSPACE_SW:
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceGray");
- color_space = JCS_GRAYSCALE;
- components = 1;
- break;
+ if (use_blackpoint)
+ dict["/ColorSpace"]=get_cal_gray_array(cfCmWhitePointSGray(),
+ cfCmGammaSGray(),
+ cfCmBlackPointDefault());
+ else
+ dict["/ColorSpace"]=get_cal_gray_array(cfCmWhitePointSGray(),
+ cfCmGammaSGray(), 0);
+ break;
+ case CUPS_CSPACE_CMYK:
+ dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceCMYK");
+ break;
case CUPS_CSPACE_RGB:
+ dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceRGB");
+ break;
case CUPS_CSPACE_SRGB:
+ icc_ref = embed_srgb_profile(pdf, doc);
+ if (!icc_ref.isNull())
+ dict["/ColorSpace"]=icc_ref;
+ else
+ dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceRGB");
+ break;
case CUPS_CSPACE_ADOBERGB:
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceRGB");
- color_space = JCS_RGB;
- components = 3;
- break;
+ if (use_blackpoint)
+ dict["/ColorSpace"]=get_cal_rgb_array(cfCmWhitePointAdobeRGB(),
+ cfCmGammaAdobeRGB(),
+ cfCmMatrixAdobeRGB(),
+ cfCmBlackPointDefault());
+ else
+ dict["/ColorSpace"]=get_cal_rgb_array(cfCmWhitePointAdobeRGB(),
+ cfCmGammaAdobeRGB(),
+ cfCmMatrixAdobeRGB(), 0);
+ break;
default:
- if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Color space not supported.");
- return std::vector<QPDFObjectHandle>(num_strips, QPDFObjectHandle());
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Color space not supported.");
+ return (QPDFObjectHandle());
}
-
- // We deliver already compressed content (instead of letting QPDFWriter
- // do it) to avoid using excessive memory. For that we first get preferred
- // compression method to pre-compress content for strip streams.
-
- // Use the compression method with highest priority of the available methods
- // __________________
- // Priority | Method
- // ------------------
- // 0 | DCT
- // 1 | FLATE
- // 2 | RLE
- // ------------------
- compression_method_t compression = compression_methods.front();
- for (std::vector<compression_method_t>::iterator it =
- compression_methods.begin();
- it != compression_methods.end(); ++it)
- compression = compression > *it ? compression : *it;
-
- // write compressed stream data
- for (size_t i = 0; i < num_strips; i ++)
+ }
+ else if (doc->cm_disabled)
+ {
+ switch(cs)
{
- dict["/Height"]=QPDFObjectHandle::newInteger(strip_height[i]);
- ret[i].replaceDict(QPDFObjectHandle::newDictionary(dict));
- Pl_Buffer psink("psink");
- if (compression == FLATE_DECODE)
- {
- Pl_Flate pflate("pflate", &psink, Pl_Flate::a_deflate);
- pflate.write(strip_data[i]->getBuffer(), strip_data[i]->getSize());
- pflate.finish();
- ret[i].replaceStreamData(PointerHolder<Buffer>(psink.getBuffer()),
- QPDFObjectHandle::newName("/FlateDecode"),
- QPDFObjectHandle::newNull());
- }
- else if (compression == RLE_DECODE)
- {
- Pl_RunLength prle("prle", &psink, Pl_RunLength::a_encode);
- prle.write(strip_data[i]->getBuffer(),strip_data[i]->getSize());
- prle.finish();
- ret[i].replaceStreamData(PointerHolder<Buffer>(psink.getBuffer()),
- QPDFObjectHandle::newName("/RunLengthDecode"),
- QPDFObjectHandle::newNull());
- }
- else if (compression == DCT_DECODE)
- {
- Pl_DCT pdct("pdct", &psink, width, strip_height[i], components, color_space);
- pdct.write(strip_data[i]->getBuffer(),strip_data[i]->getSize());
- pdct.finish();
- ret[i].replaceStreamData(PointerHolder<Buffer>(psink.getBuffer()),
- QPDFObjectHandle::newName("/DCTDecode"),
- QPDFObjectHandle::newNull());
- }
- }
- return ret;
-}
-
-static QPDFObjectHandle make_image(QPDF &pdf, PointerHolder<Buffer> page_data,
- unsigned width, unsigned height,
- std::string render_intent, cups_cspace_t cs,
- unsigned bpc, pwgtopdf_doc_t *doc)
-{
- QPDFObjectHandle ret = QPDFObjectHandle::newStream(&pdf);
-
- QPDFObjectHandle icc_ref;
-
- int use_blackpoint = 0;
- std::map<std::string,QPDFObjectHandle> dict;
-
- dict["/Type"]=QPDFObjectHandle::newName("/XObject");
- dict["/Subtype"]=QPDFObjectHandle::newName("/Image");
- dict["/Width"]=QPDFObjectHandle::newInteger(width);
- dict["/Height"]=QPDFObjectHandle::newInteger(height);
- dict["/BitsPerComponent"]=QPDFObjectHandle::newInteger(bpc);
-
- if (!doc->cm_disabled) {
- // Write rendering intent into the PDF based on raster settings
- if (render_intent == "Perceptual") {
- dict["/Intent"]=QPDFObjectHandle::newName("/Perceptual");
- } else if (render_intent == "Absolute") {
- dict["/Intent"]=QPDFObjectHandle::newName("/AbsoluteColorimetric");
- } else if (render_intent == "Relative") {
- dict["/Intent"]=QPDFObjectHandle::newName("/RelativeColorimetric");
- } else if (render_intent == "Saturation") {
- dict["/Intent"]=QPDFObjectHandle::newName("/Saturation");
- } else if (render_intent == "RelativeBpc") {
- /* Enable blackpoint compensation */
- dict["/Intent"]=QPDFObjectHandle::newName("/RelativeColorimetric");
- use_blackpoint = 1;
- }
+ case CUPS_CSPACE_K:
+ case CUPS_CSPACE_SW:
+ dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceGray");
+ break;
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_SRGB:
+ case CUPS_CSPACE_ADOBERGB:
+ dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceRGB");
+ break;
+ case CUPS_CSPACE_DEVICE1:
+ case CUPS_CSPACE_DEVICE2:
+ case CUPS_CSPACE_DEVICE3:
+ case CUPS_CSPACE_DEVICE4:
+ case CUPS_CSPACE_DEVICE5:
+ case CUPS_CSPACE_DEVICE6:
+ case CUPS_CSPACE_DEVICE7:
+ case CUPS_CSPACE_DEVICE8:
+ case CUPS_CSPACE_DEVICE9:
+ case CUPS_CSPACE_DEVICEA:
+ case CUPS_CSPACE_DEVICEB:
+ case CUPS_CSPACE_DEVICEC:
+ case CUPS_CSPACE_DEVICED:
+ case CUPS_CSPACE_DEVICEE:
+ case CUPS_CSPACE_DEVICEF:
+ case CUPS_CSPACE_CMYK:
+ dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceCMYK");
+ break;
+ default:
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Color space not supported.");
+ return (QPDFObjectHandle());
}
+ }
+ else
+ return (QPDFObjectHandle());
- /* Write "/ColorSpace" dictionary based on raster input */
- if (doc->colorProfile != NULL && !doc->cm_disabled) {
- icc_ref = embed_icc_profile(pdf, doc);
-
- if (!icc_ref.isNull())
- dict["/ColorSpace"]=icc_ref;
- } else if (!doc->cm_disabled) {
- switch (cs) {
- case CUPS_CSPACE_DEVICE1:
- case CUPS_CSPACE_DEVICE2:
- case CUPS_CSPACE_DEVICE3:
- case CUPS_CSPACE_DEVICE4:
- case CUPS_CSPACE_DEVICE5:
- case CUPS_CSPACE_DEVICE6:
- case CUPS_CSPACE_DEVICE7:
- case CUPS_CSPACE_DEVICE8:
- case CUPS_CSPACE_DEVICE9:
- case CUPS_CSPACE_DEVICEA:
- case CUPS_CSPACE_DEVICEB:
- case CUPS_CSPACE_DEVICEC:
- case CUPS_CSPACE_DEVICED:
- case CUPS_CSPACE_DEVICEE:
- case CUPS_CSPACE_DEVICEF:
- // For right now, DeviceN will use /DeviceCMYK in the PDF
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceCMYK");
- break;
- case CUPS_CSPACE_K:
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceGray");
- break;
- case CUPS_CSPACE_SW:
- if (use_blackpoint)
- dict["/ColorSpace"]=get_cal_gray_array(cfCmWhitePointSGray(),
- cfCmGammaSGray(),
- cfCmBlackPointDefault());
- else
- dict["/ColorSpace"]=get_cal_gray_array(cfCmWhitePointSGray(),
- cfCmGammaSGray(), 0);
- break;
- case CUPS_CSPACE_CMYK:
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceCMYK");
- break;
- case CUPS_CSPACE_RGB:
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceRGB");
- break;
- case CUPS_CSPACE_SRGB:
- icc_ref = embed_srgb_profile(pdf, doc);
- if (!icc_ref.isNull())
- dict["/ColorSpace"]=icc_ref;
- else
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceRGB");
- break;
- case CUPS_CSPACE_ADOBERGB:
- if (use_blackpoint)
- dict["/ColorSpace"]=get_cal_rgb_array(cfCmWhitePointAdobeRGB(),
- cfCmGammaAdobeRGB(),
- cfCmMatrixAdobeRGB(),
- cfCmBlackPointDefault());
- else
- dict["/ColorSpace"]=get_cal_rgb_array(cfCmWhitePointAdobeRGB(),
- cfCmGammaAdobeRGB(),
- cfCmMatrixAdobeRGB(), 0);
- break;
- default:
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Color space not supported.");
- return QPDFObjectHandle();
- }
- } else if (doc->cm_disabled) {
- switch(cs) {
- case CUPS_CSPACE_K:
- case CUPS_CSPACE_SW:
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceGray");
- break;
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_SRGB:
- case CUPS_CSPACE_ADOBERGB:
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceRGB");
- break;
- case CUPS_CSPACE_DEVICE1:
- case CUPS_CSPACE_DEVICE2:
- case CUPS_CSPACE_DEVICE3:
- case CUPS_CSPACE_DEVICE4:
- case CUPS_CSPACE_DEVICE5:
- case CUPS_CSPACE_DEVICE6:
- case CUPS_CSPACE_DEVICE7:
- case CUPS_CSPACE_DEVICE8:
- case CUPS_CSPACE_DEVICE9:
- case CUPS_CSPACE_DEVICEA:
- case CUPS_CSPACE_DEVICEB:
- case CUPS_CSPACE_DEVICEC:
- case CUPS_CSPACE_DEVICED:
- case CUPS_CSPACE_DEVICEE:
- case CUPS_CSPACE_DEVICEF:
- case CUPS_CSPACE_CMYK:
- dict["/ColorSpace"]=QPDFObjectHandle::newName("/DeviceCMYK");
- break;
- default:
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Color space not supported.");
- return QPDFObjectHandle();
- }
- } else
- return QPDFObjectHandle();
-
- ret.replaceDict(QPDFObjectHandle::newDictionary(dict));
+ ret.replaceDict(QPDFObjectHandle::newDictionary(dict));
#ifdef PRE_COMPRESS
- // we deliver already compressed content (instead of letting QPDFWriter
- // do it), to avoid using excessive memory
- Pl_Buffer psink("psink");
- Pl_Flate pflate("pflate",&psink,Pl_Flate::a_deflate);
-
- pflate.write(page_data->getBuffer(),page_data->getSize());
- pflate.finish();
-
- ret.replaceStreamData(PointerHolder<Buffer>(psink.getBuffer()),
- QPDFObjectHandle::newName("/FlateDecode"),
- QPDFObjectHandle::newNull());
+ // we deliver already compressed content (instead of letting QPDFWriter
+ // do it), to avoid using excessive memory
+ Pl_Buffer psink("psink");
+ Pl_Flate pflate("pflate", &psink, Pl_Flate::a_deflate);
+
+ pflate.write(page_data->getBuffer(), page_data->getSize());
+ pflate.finish();
+
+ ret.replaceStreamData(PointerHolder<Buffer>(psink.getBuffer()),
+ QPDFObjectHandle::newName("/FlateDecode"),
+ QPDFObjectHandle::newNull());
#else
- ret.replaceStreamData(page_data,QPDFObjectHandle::newNull(),
- QPDFObjectHandle::newNull());
+ ret.replaceStreamData(page_data, QPDFObjectHandle::newNull(),
+ QPDFObjectHandle::newNull());
#endif
- return ret;
+ return (ret);
}
-static int finish_page(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static int
+finish_page(struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
+ if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
+ {
+ // Finish previous PDF Page
+ if (!info->page_data.getPointer())
+ return (0);
+
+ QPDFObjectHandle image = make_image(info->pdf, info->page_data,
+ info->width, info->height,
+ info->render_intent,
+ info->color_space, info->bpc, doc);
+ if (!image.isInitialized())
{
- // Finish previous PDF Page
- if(!info->page_data.getPointer())
- return 0;
-
- QPDFObjectHandle image = make_image(info->pdf, info->page_data,
- info->width, info->height,
- info->render_intent,
- info->color_space, info->bpc, doc);
- if(!image.isInitialized())
- {
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Unable to load image data");
- return 1;
- }
-
- // add it
- info->page.getKey("/Resources").getKey("/XObject").replaceKey("/I",image);
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Unable to load image data");
+ return (1);
}
- else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
- {
- // Finish previous PCLm page
- if (info->pclm_num_strips == 0)
- return 0;
- for (size_t i = 0; i < info->pclm_strip_data.size(); i ++)
- if(!info->pclm_strip_data[i].getPointer())
- return 0;
+ // add it
+ info->page.getKey("/Resources").getKey("/XObject").replaceKey("/I",image);
+ }
+ else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ {
+ // Finish previous PCLm page
+ if (info->pclm_num_strips == 0)
+ return (0);
- std::vector<QPDFObjectHandle> strips =
- make_pclm_strips(info->pdf, info->pclm_num_strips, info->pclm_strip_data,
+ for (size_t i = 0; i < info->pclm_strip_data.size(); i ++)
+ if (!info->pclm_strip_data[i].getPointer())
+ return (0);
+
+ std::vector<QPDFObjectHandle> strips =
+ 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);
- for (size_t i = 0; i < info->pclm_num_strips; i ++)
- if(!strips[i].isInitialized())
- {
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Unable to load strip data");
- return 1;
- }
+ for (size_t i = 0; i < info->pclm_num_strips; i ++)
+ if (!strips[i].isInitialized())
+ {
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Unable to load strip data");
+ return (1);
+ }
- // add it
- for (size_t i = 0; i < info->pclm_num_strips; i ++)
- info->page.getKey("/Resources").getKey("/XObject")
- .replaceKey("/Image" +
- int_to_fwstring(i, num_digits(info->pclm_num_strips - 1)),
- strips[i]);
- }
+ // Add it
+ for (size_t i = 0; i < info->pclm_num_strips; i ++)
+ info->page.getKey("/Resources").getKey("/XObject")
+ .replaceKey("/Image" +
+ int_to_fwstring(i, num_digits(info->pclm_num_strips - 1)),
+ strips[i]);
+ }
- // draw it
- std::string content;
- if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
- {
- content.append(QUtil::double_to_string(info->page_width) + " 0 0 " +
- QUtil::double_to_string(info->page_height) + " 0 0 cm\n");
- content.append("/I Do\n");
- }
- else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ // Draw it
+ std::string content;
+ if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
+ {
+ content.append(QUtil::double_to_string(info->page_width) + " 0 0 " +
+ QUtil::double_to_string(info->page_height) + " 0 0 cm\n");
+ content.append("/I Do\n");
+ }
+ else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ {
+ std::string res = info->pclm_source_resolution_default;
+
+ // resolution is in dpi, so remove the last three characters from
+ // resolution string to get resolution integer
+ unsigned resolution_integer = std::stoi(res.substr(0, res.size() - 3));
+ double d = (double)DEFAULT_PDF_UNIT / resolution_integer;
+ content.append(QUtil::double_to_string(d) + " 0 0 " +
+ QUtil::double_to_string(d) + " 0 0 cm\n");
+ unsigned yAnchor = info->height;
+ for (unsigned i = 0; i < info->pclm_num_strips; i ++)
{
- std::string res = info->pclm_source_resolution_default;
-
- // resolution is in dpi, so remove the last three characters from
- // resolution string to get resolution integer
- unsigned resolution_integer = std::stoi(res.substr(0, res.size() - 3));
- double d = (double)DEFAULT_PDF_UNIT / resolution_integer;
- content.append(QUtil::double_to_string(d) + " 0 0 " +
- QUtil::double_to_string(d) + " 0 0 cm\n");
- unsigned yAnchor = info->height;
- for (unsigned i = 0; i < info->pclm_num_strips; i ++)
- {
- yAnchor -= info->pclm_strip_height[i];
- content.append("/P <</MCID 0>> BDC q\n");
- content.append(QUtil::int_to_string(info->width) + " 0 0 " +
- QUtil::int_to_string(info->pclm_strip_height[i]) +
- " 0 " + QUtil::int_to_string(yAnchor) + " cm\n");
- content.append("/Image" +
- int_to_fwstring(i,
- num_digits(info->pclm_num_strips - 1)) +
- " Do Q\n");
- }
+ yAnchor -= info->pclm_strip_height[i];
+ content.append("/P <</MCID 0>> BDC q\n");
+ content.append(QUtil::int_to_string(info->width) + " 0 0 " +
+ QUtil::int_to_string(info->pclm_strip_height[i]) +
+ " 0 " + QUtil::int_to_string(yAnchor) + " cm\n");
+ content.append("/Image" +
+ int_to_fwstring(i,
+ num_digits(info->pclm_num_strips - 1)) +
+ " Do Q\n");
}
+ }
- QPDFObjectHandle page_contents = info->page.getKey("/Contents");
- if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
- page_contents.replaceStreamData(content, QPDFObjectHandle::newNull(),
- QPDFObjectHandle::newNull());
- else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
- page_contents.getArrayItem(0).replaceStreamData(content,
- QPDFObjectHandle::newNull(),
- QPDFObjectHandle::newNull());
+ QPDFObjectHandle page_contents = info->page.getKey("/Contents");
+ if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
+ page_contents.replaceStreamData(content, QPDFObjectHandle::newNull(),
+ QPDFObjectHandle::newNull());
+ else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ page_contents.getArrayItem(0).replaceStreamData(content,
+ QPDFObjectHandle::newNull(),
+ QPDFObjectHandle::newNull());
- // bookkeeping
- info->page_data = PointerHolder<Buffer>();
- info->pclm_strip_data.clear();
+ // bookkeeping
+ info->page_data = PointerHolder<Buffer>();
+ info->pclm_strip_data.clear();
- return 0;
+ return (0);
}
-/* Perform modifications to PDF if color space conversions are needed */
-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,
- pwgtopdf_doc_t *doc)
+//
+// Perform modifications to PDF if color space conversions are needed
+//
+
+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,
+ pwgtopdf_doc_t *doc)
{
+
#define IMAGE_CMYK_8 (bpp == 32 && bpc == 8)
#define IMAGE_CMYK_16 (bpp == 64 && bpc == 16)
#define IMAGE_RGB_8 (bpp == 24 && bpc == 8)
#define IMAGE_WHITE_8 (bpp == 8 && bpc == 8)
#define IMAGE_WHITE_16 (bpp == 16 && bpc == 16)
- int error = 0;
- pdf_convert_function fn = convert_pdf_no_conversion;
- cmsColorSpaceSignature css;
-
- /* Register available raster information into the PDF */
- info->width = width;
- info->height = height;
- info->line_bytes = bpl;
- info->bpp = bpp;
- info->bpc = bpc;
- info->render_intent = render_intent;
- info->color_space = color_space;
- if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ int error = 0;
+ pdf_convert_function fn = convert_pdf_no_conversion;
+ cmsColorSpaceSignature css;
+
+ // Register available raster information into the PDF
+ info->width = width;
+ info->height = height;
+ info->line_bytes = bpl;
+ info->bpp = bpp;
+ info->bpc = bpc;
+ info->render_intent = render_intent;
+ info->color_space = color_space;
+ if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ {
+ info->pclm_num_strips =
+ (height / info->pclm_strip_height_preferred) +
+ (height % info->pclm_strip_height_preferred ? 1 : 0);
+ info->pclm_strip_height.resize(info->pclm_num_strips);
+ info->pclm_strip_data.resize(info->pclm_num_strips);
+ for (size_t i = 0; i < info->pclm_num_strips; i ++)
{
- info->pclm_num_strips =
- (height / info->pclm_strip_height_preferred) +
- (height % info->pclm_strip_height_preferred ? 1 : 0);
- info->pclm_strip_height.resize(info->pclm_num_strips);
- info->pclm_strip_data.resize(info->pclm_num_strips);
- for (size_t i = 0; i < info->pclm_num_strips; i ++)
- {
- info->pclm_strip_height[i] =
- info->pclm_strip_height_preferred < height ?
- info->pclm_strip_height_preferred : height;
- height -= info->pclm_strip_height[i];
- }
+ info->pclm_strip_height[i] =
+ info->pclm_strip_height_preferred < height ?
+ info->pclm_strip_height_preferred : height;
+ height -= info->pclm_strip_height[i];
}
+ }
- /* Invert grayscale by default */
- if (color_space == CUPS_CSPACE_K)
- fn = convert_pdf_invert_colors;
+ // Invert grayscale by default
+ if (color_space == CUPS_CSPACE_K)
+ fn = convert_pdf_invert_colors;
- if (doc->colorProfile != NULL) {
- css = cmsGetColorSpace(doc->colorProfile);
+ if (doc->colorProfile != NULL)
+ {
+ css = cmsGetColorSpace(doc->colorProfile);
- // Convert image and PDF color space to an embedded ICC Profile color
- // space
- switch(css) {
- // Convert PDF to Grayscale when using a gray profile
- case cmsSigGrayData:
+ // Convert image and PDF color space to an embedded ICC Profile color
+ // space
+ switch (css)
+ {
+ // Convert PDF to Grayscale when using a gray profile
+ case cmsSigGrayData:
if (color_space == CUPS_CSPACE_CMYK)
- fn = convert_pdf_cmyk_8_to_white_8;
- else if (color_space == CUPS_CSPACE_RGB)
- fn = convert_pdf_rgb_8_to_white_8;
- else
- fn = convert_pdf_invert_colors;
- info->color_space = CUPS_CSPACE_K;
- break;
- // Convert PDF to RGB when using an RGB profile
- case cmsSigRgbData:
+ fn = convert_pdf_cmyk_8_to_white_8;
+ else if (color_space == CUPS_CSPACE_RGB)
+ fn = convert_pdf_rgb_8_to_white_8;
+ else
+ 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 = convert_pdf_cmyk_8_to_rgb_8;
- else if (color_space == CUPS_CSPACE_K)
- 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:
+ fn = convert_pdf_cmyk_8_to_rgb_8;
+ else if (color_space == CUPS_CSPACE_K)
+ 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 = convert_pdf_rgb_8_to_cmyk_8;
else if (color_space == CUPS_CSPACE_K)
fn = convert_pdf_white_8_to_cmyk_8;
info->color_space = CUPS_CSPACE_CMYK;
break;
- default:
- if (doc->logfunc)
+ default:
+ if (doc->logfunc)
doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToPDF: Unable to convert PDF from profile.");
doc->colorProfile = NULL;
error = 1;
- }
- // Perform conversion of an image color space
- } else if (!doc->cm_disabled) {
- switch (color_space) {
- // Convert image to CMYK
- case CUPS_CSPACE_CMYK:
- if (IMAGE_RGB_8)
- fn = convert_pdf_rgb_8_to_cmyk_8;
- else if (IMAGE_RGB_16)
- fn = convert_pdf_no_conversion;
- else if (IMAGE_WHITE_8)
- fn = convert_pdf_white_8_to_cmyk_8;
- else if (IMAGE_WHITE_16)
- fn = convert_pdf_no_conversion;
- break;
- // Convert image to RGB
- case CUPS_CSPACE_ADOBERGB:
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_SRGB:
+ }
+ }
+ else if (!doc->cm_disabled)
+ {
+ // Perform conversion of an image color space
+ switch (color_space)
+ {
+ // Convert image to CMYK
+ case CUPS_CSPACE_CMYK:
+ if (IMAGE_RGB_8)
+ fn = convert_pdf_rgb_8_to_cmyk_8;
+ else if (IMAGE_RGB_16)
+ fn = convert_pdf_no_conversion;
+ else if (IMAGE_WHITE_8)
+ fn = convert_pdf_white_8_to_cmyk_8;
+ else if (IMAGE_WHITE_16)
+ 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 = convert_pdf_cmyk_8_to_rgb_8;
else if (IMAGE_CMYK_16)
else if (IMAGE_WHITE_16)
fn = convert_pdf_no_conversion;
break;
- // Convert image to Grayscale
- case CUPS_CSPACE_SW:
- case CUPS_CSPACE_K:
- if (IMAGE_CMYK_8)
- fn = convert_pdf_cmyk_8_to_white_8;
- else if (IMAGE_CMYK_16)
- fn = convert_pdf_no_conversion;
- else if (IMAGE_RGB_8)
- fn = convert_pdf_rgb_8_to_white_8;
- else if (IMAGE_RGB_16)
- fn = convert_pdf_no_conversion;
- break;
- case CUPS_CSPACE_DEVICE1:
- case CUPS_CSPACE_DEVICE2:
- case CUPS_CSPACE_DEVICE3:
- case CUPS_CSPACE_DEVICE4:
- case CUPS_CSPACE_DEVICE5:
- case CUPS_CSPACE_DEVICE6:
- case CUPS_CSPACE_DEVICE7:
- case CUPS_CSPACE_DEVICE8:
- case CUPS_CSPACE_DEVICE9:
- case CUPS_CSPACE_DEVICEA:
- case CUPS_CSPACE_DEVICEB:
- case CUPS_CSPACE_DEVICEC:
- case CUPS_CSPACE_DEVICED:
- case CUPS_CSPACE_DEVICEE:
- case CUPS_CSPACE_DEVICEF:
- // No conversion for right now
- fn = convert_pdf_no_conversion;
- break;
- default:
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Color space not supported.");
- error = 1;
- break;
- }
- }
+ // Convert image to Grayscale
+ case CUPS_CSPACE_SW:
+ case CUPS_CSPACE_K:
+ if (IMAGE_CMYK_8)
+ fn = convert_pdf_cmyk_8_to_white_8;
+ else if (IMAGE_CMYK_16)
+ fn = convert_pdf_no_conversion;
+ else if (IMAGE_RGB_8)
+ fn = convert_pdf_rgb_8_to_white_8;
+ else if (IMAGE_RGB_16)
+ fn = convert_pdf_no_conversion;
+ break;
+ case CUPS_CSPACE_DEVICE1:
+ case CUPS_CSPACE_DEVICE2:
+ case CUPS_CSPACE_DEVICE3:
+ case CUPS_CSPACE_DEVICE4:
+ case CUPS_CSPACE_DEVICE5:
+ case CUPS_CSPACE_DEVICE6:
+ case CUPS_CSPACE_DEVICE7:
+ case CUPS_CSPACE_DEVICE8:
+ case CUPS_CSPACE_DEVICE9:
+ case CUPS_CSPACE_DEVICEA:
+ case CUPS_CSPACE_DEVICEB:
+ case CUPS_CSPACE_DEVICEC:
+ case CUPS_CSPACE_DEVICED:
+ case CUPS_CSPACE_DEVICEE:
+ case CUPS_CSPACE_DEVICEF:
+ // No conversion for right now
+ fn = convert_pdf_no_conversion;
+ break;
+ default:
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Color space not supported.");
+ error = 1;
+ break;
+ }
+ }
- if (!error)
- fn(info, doc);
+ if (!error)
+ fn(info, doc);
- return error;
+ return (error);
}
-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, pwgtopdf_doc_t *doc)
+
+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,
+ pwgtopdf_doc_t *doc)
{
- try {
- if (finish_page(info, doc)) // any active
- return 1;
-
- prepare_pdf_page(info, width, height, bpl, bpp,
- bpc, render_intent, color_space, doc);
-
- if (info->height > (std::numeric_limits<unsigned>::max() /
- info->line_bytes)) {
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Page too big");
- return 1;
- }
- if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
- info->page_data =
- PointerHolder<Buffer>(new Buffer(info->line_bytes * info->height));
- else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
- {
- // reserve space for PCLm strips
- for (size_t i = 0; i < info->pclm_num_strips; i ++)
- info->pclm_strip_data[i] =
- PointerHolder<Buffer>(new Buffer(info->line_bytes *
- info->pclm_strip_height[i]));
- }
-
- QPDFObjectHandle page = QPDFObjectHandle::parse(
- "<<"
+ try
+ {
+ if (finish_page(info, doc)) // any active
+ return (1);
+
+ prepare_pdf_page(info, width, height, bpl, bpp,
+ bpc, render_intent, color_space, doc);
+
+ if (info->height > (std::numeric_limits<unsigned>::max() /
+ info->line_bytes))
+ {
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Page too big");
+ return (1);
+ }
+ if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
+ info->page_data =
+ PointerHolder<Buffer>(new Buffer(info->line_bytes * info->height));
+ else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ {
+ // reserve space for PCLm strips
+ for (size_t i = 0; i < info->pclm_num_strips; i ++)
+ info->pclm_strip_data[i] =
+ PointerHolder<Buffer>(new Buffer(info->line_bytes *
+ info->pclm_strip_height[i]));
+ }
+
+ QPDFObjectHandle page = QPDFObjectHandle::parse(
+ "<<"
" /Type /Page"
" /Resources <<"
" /XObject << >> "
" /Contents null "
">>");
- // Convert to pdf units
- info->page_width=((double)info->width/xdpi)*DEFAULT_PDF_UNIT;
- info->page_height=((double)info->height/ydpi)*DEFAULT_PDF_UNIT;
- if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
- {
- page.replaceKey("/Contents",QPDFObjectHandle::newStream(&info->pdf));
- // data will be provided later
- page.replaceKey("/MediaBox",make_real_box(0,0,info->page_width,
- info->page_height));
- }
- else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
- {
- page.replaceKey("/Contents",
- QPDFObjectHandle::newArray(std::vector<QPDFObjectHandle>
- (1,QPDFObjectHandle::newStream
- (&info->pdf))));
-
- // box with dimensions rounded off to the nearest integer
- page.replaceKey("/MediaBox",
- make_integer_box(0,0,info->page_width + 0.5,
- info->page_height + 0.5));
- }
-
- info->page = info->pdf.makeIndirectObject(page); // we want to keep a
- // reference
- info->pdf.addPage(info->page, false);
- } catch (std::bad_alloc &ex) {
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Unable to allocate page data");
- return 1;
- } catch (...) {
- return 1;
+ // Convert to pdf units
+ info->page_width = ((double)info->width / xdpi) * DEFAULT_PDF_UNIT;
+ info->page_height = ((double)info->height / ydpi) * DEFAULT_PDF_UNIT;
+ if (info->outformat == CF_FILTER_OUT_FORMAT_PDF)
+ {
+ page.replaceKey("/Contents", QPDFObjectHandle::newStream(&info->pdf));
+ // data will be provided later
+ page.replaceKey("/MediaBox", make_real_box(0, 0, info->page_width,
+ info->page_height));
+ }
+ else if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ {
+ page.replaceKey("/Contents",
+ QPDFObjectHandle::newArray(std::vector<QPDFObjectHandle>
+ (1, QPDFObjectHandle::newStream
+ (&info->pdf))));
+
+ // box with dimensions rounded off to the nearest integer
+ page.replaceKey("/MediaBox",
+ make_integer_box(0, 0, info->page_width + 0.5,
+ info->page_height + 0.5));
}
- return 0;
+ info->page = info->pdf.makeIndirectObject(page); // we want to keep a
+ // reference
+ info->pdf.addPage(info->page, false);
+ }
+ catch (std::bad_alloc &ex)
+ {
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Unable to allocate page data");
+ return (1);
+ }
+ catch (...)
+ {
+ return (1);
+ }
+
+ return (0);
}
-static int close_pdf_file(struct pdf_info * info, pwgtopdf_doc_t *doc)
+
+static int
+close_pdf_file(struct pdf_info * info,
+ pwgtopdf_doc_t *doc)
{
- try {
- if (finish_page(info, doc)) // any active
- return 1;
- QPDFWriter output(info->pdf,NULL);
- output.setOutputFile("pdf", doc->outputfp, false);
-// output.setMinimumPDFVersion("1.4");
- if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
- output.setPCLm(true);
- output.write();
- } catch (...) {
- return 1;
- }
+ try
+ {
+ if (finish_page(info, doc)) // any active
+ return (1);
+ QPDFWriter output(info->pdf, NULL);
+ output.setOutputFile("pdf", doc->outputfp, false);
+ //output.setMinimumPDFVersion("1.4");
+ if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ output.setPCLm(true);
+ output.write();
+ }
+ catch (...)
+ {
+ return (1);
+ }
- return 0;
+ return (0);
}
-static void pdf_set_line(struct pdf_info * info, unsigned line_n,
- unsigned char *line, pwgtopdf_doc_t *doc)
+
+static void
+pdf_set_line(struct pdf_info * info,
+ unsigned line_n,
+ unsigned char *line,
+ pwgtopdf_doc_t *doc)
{
- if(line_n > info->height)
- {
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Bad line %d", line_n);
- return;
- }
+ if (line_n > info->height)
+ {
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Bad line %d", line_n);
+ return;
+ }
- if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM) {
- // copy line data into appropriate pclm strip
- size_t strip_num = line_n / info->pclm_strip_height_preferred;
- unsigned line_strip = line_n -
- strip_num * info->pclm_strip_height_preferred;
- memcpy(((info->pclm_strip_data[strip_num])->getBuffer() +
- (line_strip*info->line_bytes)), line, info->line_bytes);
- } else {
- memcpy((info->page_data->getBuffer() + (line_n * info->line_bytes)),
- line, info->line_bytes);
- }
+ if (info->outformat == CF_FILTER_OUT_FORMAT_PCLM)
+ {
+ // copy line data into appropriate pclm strip
+ size_t strip_num = line_n / info->pclm_strip_height_preferred;
+ unsigned line_strip = line_n -
+ strip_num * info->pclm_strip_height_preferred;
+ memcpy(((info->pclm_strip_data[strip_num])->getBuffer() +
+ (line_strip*info->line_bytes)), line, info->line_bytes);
+ }
+ else
+ memcpy((info->page_data->getBuffer() + (line_n * info->line_bytes)),
+ line, info->line_bytes);
}
-static int convert_raster(cups_raster_t *ras, unsigned width, unsigned height,
- int bpp, int bpl, struct pdf_info * info,
- pwgtopdf_doc_t *doc)
+
+static int
+convert_raster(cups_raster_t *ras,
+ unsigned width,
+ unsigned height,
+ int bpp,
+ int bpl,
+ struct pdf_info *info,
+ pwgtopdf_doc_t *doc)
{
- // We should be at raster start
- int i;
- unsigned cur_line = 0;
- unsigned char *PixelBuffer, *ptr = NULL, *buff;
+ // We should be at raster start
+ int i;
+ unsigned cur_line = 0;
+ unsigned char *PixelBuffer, *ptr = NULL, *buff;
- PixelBuffer = (unsigned char *)malloc(bpl);
- buff = (unsigned char *)malloc(info->line_bytes);
+ PixelBuffer = (unsigned char *)malloc(bpl);
+ buff = (unsigned char *)malloc(info->line_bytes);
- do
- {
- // Read raster data...
- cupsRasterReadPixels(ras, PixelBuffer, bpl);
+ do
+ {
+ // Read raster data...
+ cupsRasterReadPixels(ras, PixelBuffer, bpl);
#if !ARCH_IS_BIG_ENDIAN
+ if (info->bpc == 16)
+ {
+ // Swap byte pairs for endianess (cupsRasterReadPixels() switches
+ // from Big Endian back to the system's Endian)
+ for (i = bpl, ptr = PixelBuffer; i > 0; i -= 2, ptr += 2)
+ {
+ unsigned char swap = *ptr;
+ *ptr = *(ptr + 1);
+ *(ptr + 1) = swap;
+ }
+ }
+#endif // !ARCH_IS_BIG_ENDIAN
- if (info->bpc == 16)
- {
- // Swap byte pairs for endianess (cupsRasterReadPixels() switches
- // from Big Endian back to the system's Endian)
- for (i = bpl, ptr = PixelBuffer; i > 0; i -= 2, ptr += 2)
- {
- unsigned char swap = *ptr;
- *ptr = *(ptr + 1);
- *(ptr + 1) = swap;
- }
- }
-#endif /* !ARCH_IS_BIG_ENDIAN */
-
- // perform bit operations if necessary
- doc->bit_function(PixelBuffer, ptr, bpl);
+ // perform bit operations if necessary
+ doc->bit_function(PixelBuffer, ptr, bpl);
- // write lines and color convert when necessary
- pdf_set_line(info, cur_line, doc->conversion_function(PixelBuffer,
- buff, width),
- doc);
- ++cur_line;
- }
- while(cur_line < height);
+ // write lines and color convert when necessary
+ pdf_set_line(info, cur_line, doc->conversion_function(PixelBuffer,
+ buff, width),
+ doc);
+ ++cur_line;
+ }
+ while (cur_line < height);
- free(buff);
- free(PixelBuffer);
+ free(buff);
+ free(PixelBuffer);
- return 0;
+ return (0);
}
-static int set_profile(const char * path, pwgtopdf_doc_t *doc)
+
+static int
+set_profile(const char *path,
+ pwgtopdf_doc_t *doc)
{
- if (path != NULL)
- doc->colorProfile = cmsOpenProfileFromFile(path,"r");
+ if (path != NULL)
+ doc->colorProfile = cmsOpenProfileFromFile(path, "r");
- if (doc->colorProfile != NULL) {
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Load profile successful.");
- return 0;
- }
- else {
- if (doc->logfunc)
- doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Unable to load profile.");
- return 1;
- }
+ if (doc->colorProfile != NULL)
+ {
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Load profile successful.");
+ return (0);
+ }
+ else
+ {
+ if (doc->logfunc)
+ doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPWGToPDF: Unable to load profile.");
+ return (1);
+ }
}
-int /* O - Error status */
-cfFilterPWGToPDF(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? (unused) */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters (outformat) */
+
+int // O - Error status
+cfFilterPWGToPDF(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable? (unused)
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters (outformat)
{
int i;
char *t;
- pwgtopdf_doc_t doc; /* Document information */
- FILE *outputfp; /* Output data stream */
- cf_filter_out_format_t outformat; /* Output format */
- int Page, empty = 1;
- cf_cm_calibration_t cm_calibrate; /* Status of CUPS color management
- ("on" or "off") */
+ pwgtopdf_doc_t doc; // Document information
+ FILE *outputfp; // Output data stream
+ cf_filter_out_format_t outformat; // Output format
+ int Page, empty = 1;
+ cf_cm_calibration_t cm_calibrate; // Status of CUPS color management
+ // ("on" or "off")
struct pdf_info pdf;
- cups_raster_t *ras; /* Raster stream for printing */
- cups_page_header2_t header; /* Page header from file */
- ipp_t *printer_attrs = data->printer_attrs; /* Printer attributes from printer data*/
- ipp_attribute_t *ipp_attr; /* Printer attribute*/
- const char* profile_name = NULL; /* IPP Profile Name */
- cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
+ cups_raster_t *ras; // Raster stream for printing
+ cups_page_header2_t header; // Page header from file
+ ipp_t *printer_attrs = data->printer_attrs; // Printer attributes from
+ // printer data
+ ipp_attribute_t *ipp_attr; // Printer attribute
+ const char *profile_name = NULL; // IPP Profile Name
+ cf_logfunc_t log = data->logfunc;
+ void *ld = data->logdata;
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
- void *icd = data->iscanceleddata;
- int total_attrs;
- char buf[1024];
- const char *kw;
+ void *icd = data->iscanceleddata;
+ int total_attrs;
+ char buf[1024];
+ const char *kw;
(void)inputseekable;
"cfFilterPWGToPDF: OUTFORMAT=\"%s\"",
outformat == CF_FILTER_OUT_FORMAT_PDF ? "PDF" : "PCLM");
- /*
- * Open the output data stream specified by the outputfd...
- */
+ //
+ // Open the output data stream specified by the outputfd...
+ //
if ((outputfp = fdopen(outputfd, "w")) == NULL)
{
}
doc.outputfp = outputfp;
- /* Logging function */
+ // Logging function
doc.logfunc = log;
doc.logdata = ld;
- /* Job-is-canceled function */
+ // Job-is-canceled function
doc.iscanceledfunc = iscanceled;
doc.iscanceleddata = icd;
- /* support the CUPS "cm-calibration" option */
+ // support the CUPS "cm-calibration" option
cm_calibrate = cfCmGetCupsColorCalibrateMode(data);
if (outformat == CF_FILTER_OUT_FORMAT_PCLM ||
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPWGToPDF: PCLm output: No printer IPP attributes are supplied, PCLm output not possible.");
- return 1;
+ return (1);
}
// Transform
// Process pages as needed...
Page = 0;
- /* Get PCLm parameters from printer IPP attributes */
+ // Get PCLm parameters from printer IPP attributes
if (outformat == CF_FILTER_OUT_FORMAT_PCLM)
{
if (log)
log(ld, CF_LOGLEVEL_DEBUG, " Value: %s", buf);
for (i = 0; i < ippGetCount(ipp_attr); i ++)
if ((kw = ippGetString(ipp_attr, i, NULL)) != NULL)
- log(ld, CF_LOGLEVEL_DEBUG, " Keyword: %s", kw);
- }
- ipp_attr = ippNextAttribute(printer_attrs);
+ log(ld, CF_LOGLEVEL_DEBUG, " Keyword: %s", kw);
+ }
+ ipp_attr = ippNextAttribute(printer_attrs);
}
log(ld, CF_LOGLEVEL_DEBUG, " %d attributes", total_attrs);
}
char *attr_name = (char *)"pclm-strip-height-preferred";
- if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name, IPP_TAG_ZERO)) != NULL)
+ if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name,
+ IPP_TAG_ZERO)) != NULL)
{
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToPDF: Printer PCLm attribute \"%s\" with value %d",
pdf.pclm_strip_height_preferred = ippGetInteger(ipp_attr, 0);
}
else
- pdf.pclm_strip_height_preferred = 16; /* default strip height */
+ pdf.pclm_strip_height_preferred = 16; // default strip height
attr_name = (char *)"pclm-strip-height-supported";
- if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name, IPP_TAG_ZERO)) != NULL)
+ if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name,
+ IPP_TAG_ZERO)) != NULL)
{
if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Printer PCLm attribute \"%s\"",
- attr_name);
+ "cfFilterPWGToPDF: Printer PCLm attribute \"%s\"",
+ attr_name);
pdf.pclm_strip_height_supported.clear(); // remove default value = 16
for (int i = 0; i < ippGetCount(ipp_attr); i ++)
pdf.pclm_strip_height_supported.push_back(ippGetInteger(ipp_attr, i));
}
attr_name = (char *)"pclm-raster-back-side";
- if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name, IPP_TAG_ZERO)) != NULL)
+ if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name,
+ IPP_TAG_ZERO)) != NULL)
{
if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToPDF: Printer PCLm attribute \"%s\" with value \"%s\"",
- attr_name, ippGetString(ipp_attr, 0, NULL));
+ "cfFilterPWGToPDF: Printer PCLm attribute \"%s\" with value \"%s\"",
+ attr_name, ippGetString(ipp_attr, 0, NULL));
pdf.pclm_raster_back_side = ippGetString(ipp_attr, 0, NULL);
}
attr_name = (char *)"pclm-source-resolution-supported";
- if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name, IPP_TAG_ZERO)) != NULL)
+ if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name,
+ IPP_TAG_ZERO)) != NULL)
{
ippAttributeString(ipp_attr, buf, sizeof(buf));
if (log) log(ld, CF_LOGLEVEL_DEBUG,
}
attr_name = (char *)"pclm-source-resolution-default";
- if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name, IPP_TAG_ZERO)) != NULL)
+ if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name,
+ IPP_TAG_ZERO)) != NULL)
{
ippAttributeString(ipp_attr, buf, sizeof(buf));
if (log) log(ld, CF_LOGLEVEL_DEBUG,
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPWGToPDF: PCLm output: Printer IPP attributes do not contain printer resolution information for PCLm.");
- return 1;
+ return (1);
}
attr_name = (char *)"pclm-compression-method-preferred";
- if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name, IPP_TAG_ZERO)) != NULL)
+ if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name,
+ IPP_TAG_ZERO)) != NULL)
{
ippAttributeString(ipp_attr, buf, sizeof(buf));
if (log) log(ld, CF_LOGLEVEL_DEBUG,
// get all compression methods supported by the printer
for (std::vector<std::string>::iterator it = vec.begin();
- it != vec.end(); ++it)
+ it != vec.end(); ++it)
{
std::string compression_method = *it;
for (char& x: compression_method)
else if (compression_method == "jpeg")
pdf.pclm_compression_method_preferred.push_back(DCT_DECODE);
}
-
}
// If the compression methods is none of the above or is erreneous
// use FLATE as compression method and show a warning.
"(pwgtopclm) Unable parse Printer attribute \"%s\". "
"Using FLATE for encoding image streams.", attr_name);
pdf.pclm_compression_method_preferred.push_back(FLATE_DECODE);
- }
+ }
}
while (cupsRasterReadHeader2(ras, &header))
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPWGToPDF: Unable to create PDF file");
- return 1;
+ return (1);
}
}
// Add a new page to PDF file
if (add_pdf_page(&pdf, Page, header.cupsWidth, header.cupsHeight,
- header.cupsBitsPerPixel, header.cupsBitsPerColor,
- header.cupsBytesPerLine, header.cupsRenderingIntent,
- header.cupsColorSpace, header.HWResolution[0],
- header.HWResolution[1], &doc) != 0)
+ header.cupsBitsPerPixel, header.cupsBitsPerColor,
+ header.cupsBytesPerLine, header.cupsRenderingIntent,
+ header.cupsColorSpace, header.HWResolution[0],
+ header.HWResolution[1], &doc) != 0)
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPWGToPDF: Unable to start new PDF page");
- return 1;
+ return (1);
}
// Write the bit map into the PDF file
if (convert_raster(ras, header.cupsWidth, header.cupsHeight,
- header.cupsBitsPerPixel, header.cupsBytesPerLine,
- &pdf, &doc) != 0)
+ header.cupsBitsPerPixel, header.cupsBytesPerLine,
+ &pdf, &doc) != 0)
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPWGToPDF: Failed to convert page bitmap");
- return 1;
+ return (1);
}
}
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToPDF: Input is empty, outputting empty file.");
cupsRasterClose(ras);
- return 0;
+ return (0);
}
close_pdf_file(&pdf, &doc); // output to outputfp
- if (doc.colorProfile != NULL) {
+ if (doc.colorProfile != NULL)
cmsCloseProfile(doc.colorProfile);
- }
cupsRasterClose(ras);
fclose(outputfp);
-/*
-Copyright (c) 2008-2011 BBR Inc. All rights reserved.
-Copyright (c) 2012-2021 by Till Kamppeter
-Copyright (c) 2019 by Tanmay Anand.
-Modified 2021 by Pratyush Ranjan.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-*/
-/*
- pwgtoraster.c
- PWG/Apple Raster to CUPS/PWG/Apple Raster filter function
-*/
+//
+// Copyright (c) 2008-2011 BBR Inc. All rights reserved.
+// Copyright (c) 2012-2021 by Till Kamppeter
+// Copyright (c) 2019 by Tanmay Anand.
+// Modified 2021 by Pratyush Ranjan.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+//
+// pwgtoraster.c
+// PWG/Apple Raster to CUPS/PWG/Apple Raster filter function
+//
#include "colormanager.h"
#include "image.h"
#include "ipp.h"
#include <config.h>
#include <cups/cups.h>
-#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 6)
-#define HAVE_CUPS_1_7 1
-#endif
#define USE_CMS
typedef struct cms_profile_s
{
- /* for color profiles */
+ // for color profiles
cmsHPROFILE colorProfile;
cmsHPROFILE outputColorProfile;
cmsHTRANSFORM colorTransform;
} cms_profile_t;
typedef struct pwgtoraster_doc_s
-{ /**** Document information ****/
+{ // **** Document information ****
cf_filter_data_t *data;
bool page_size_requested;
int bi_level;
unsigned int bitmapoffset[2];
cups_page_header2_t inheader;
cups_page_header2_t outheader;
- cups_file_t *inputfp; /* Temporary file, if any */
- FILE *outputfp; /* Temporary file, if any */
- /* margin swapping */
+ cups_file_t *inputfp; // Temporary file, if any
+ FILE *outputfp; // Temporary file, if any
+ // margin swapping
bool swap_margin_x;
bool swap_margin_y;
unsigned int nplanes;
unsigned int nbands;
- unsigned int bytesPerLine; /* number of bytes per line */
- /* Note: When CUPS_ORDER_BANDED,
- cupsBytesPerLine = bytesPerLine*cupsNumColors */
+ unsigned int bytesPerLine; // number of bytes per line
+ // Note: When CUPS_ORDER_BANDED,
+ // cupsBytesPerLine = bytesPerLine * cupsNumColors
cms_profile_t color_profile;
} pwgtoraster_doc_t;
typedef unsigned char *(*convert_cspace_func)(unsigned char *src,
- unsigned char *pixelBuf,
- unsigned int x,
- unsigned int y,
- pwgtoraster_doc_t* doc);
+ unsigned char *pixelBuf,
+ unsigned int x,
+ unsigned int y,
+ pwgtoraster_doc_t* doc);
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,
- convert_cspace_func convertCSpace);
+ unsigned char *dst,
+ unsigned int row,
+ unsigned int plane,
+ unsigned int pixels,
+ unsigned int size,
+ pwgtoraster_doc_t* doc,
+ convert_cspace_func convertCSpace);
typedef struct conversion_function_s
{
- convert_cspace_func convertCSpace; /* Function for conversion of colorspaces */
- convert_line_func convertLineOdd;/* Function to modify raster data of a line */
+ 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;
-static cmsCIExyY adobergb_wp_cms()
+
+static cmsCIExyY
+adobergb_wp_cms()
{
- double * xyY = cfCmWhitePointAdobeRGB();
- cmsCIExyY wp;
+ double *xyY = cfCmWhitePointAdobeRGB();
+ cmsCIExyY wp;
- wp.x = xyY[0];
- wp.y = xyY[1];
- wp.Y = xyY[2];
+ wp.x = xyY[0];
+ wp.y = xyY[1];
+ wp.Y = xyY[2];
- return wp;
+ return (wp);
}
-static cmsCIExyY sgray_wp_cms()
+
+static cmsCIExyY
+sgray_wp_cms()
{
- double * xyY = cfCmWhitePointSGray();
- cmsCIExyY wp;
+ double *xyY = cfCmWhitePointSGray();
+ cmsCIExyY wp;
- wp.x = xyY[0];
- wp.y = xyY[1];
- wp.Y = xyY[2];
+ wp.x = xyY[0];
+ wp.y = xyY[1];
+ wp.Y = xyY[2];
- return wp;
+ return (wp);
}
-static cmsCIExyYTRIPLE adobergb_matrix_cms()
+
+static cmsCIExyYTRIPLE
+adobergb_matrix_cms()
{
- cmsCIExyYTRIPLE m;
+ cmsCIExyYTRIPLE m;
- double * matrix = cfCmMatrixAdobeRGB();
+ double *matrix = cfCmMatrixAdobeRGB();
- m.Red.x = matrix[0];
- m.Red.y = matrix[1];
- m.Red.Y = matrix[2];
- m.Green.x = matrix[3];
- m.Green.y = matrix[4];
- m.Green.Y = matrix[5];
- m.Blue.x = matrix[6];
- m.Blue.y = matrix[7];
- m.Blue.Y = matrix[8];
+ m.Red.x = matrix[0];
+ m.Red.y = matrix[1];
+ m.Red.Y = matrix[2];
+ m.Green.x = matrix[3];
+ m.Green.y = matrix[4];
+ m.Green.Y = matrix[5];
+ m.Blue.x = matrix[6];
+ m.Blue.y = matrix[7];
+ m.Blue.Y = matrix[8];
- return m;
+ return (m);
}
-static cmsHPROFILE adobergb_profile()
+
+static cmsHPROFILE
+adobergb_profile()
{
- cmsHPROFILE adobergb;
+ cmsHPROFILE adobergb;
- cmsCIExyY wp;
- cmsCIExyYTRIPLE primaries;
+ cmsCIExyY wp;
+ cmsCIExyYTRIPLE primaries;
#if USE_LCMS1
- cmsToneCurve Gamma = cmsBuildGamma(256, 2.2);
- cmsToneCurve Gamma3[3];
+ cmsToneCurve Gamma = cmsBuildGamma(256, 2.2);
+ cmsToneCurve Gamma3[3];
#else
- cmsToneCurve * Gamma = cmsBuildGamma(NULL, 2.2);
- cmsToneCurve * Gamma3[3];
+ cmsToneCurve *Gamma = cmsBuildGamma(NULL, 2.2);
+ cmsToneCurve *Gamma3[3];
#endif
- Gamma3[0] = Gamma3[1] = Gamma3[2] = Gamma;
+ Gamma3[0] = Gamma3[1] = Gamma3[2] = Gamma;
- // Build AdobeRGB profile
- primaries = adobergb_matrix_cms();
- wp = adobergb_wp_cms();
- adobergb = cmsCreateRGBProfile(&wp, &primaries, Gamma3);
+ // Build AdobeRGB profile
+ primaries = adobergb_matrix_cms();
+ wp = adobergb_wp_cms();
+ adobergb = cmsCreateRGBProfile(&wp, &primaries, Gamma3);
- return adobergb;
+ return (adobergb);
}
-static cmsHPROFILE sgray_profile()
+static cmsHPROFILE
+sgray_profile()
{
- cmsHPROFILE sgray;
+ cmsHPROFILE sgray;
- cmsCIExyY wp;
+ cmsCIExyY wp;
#if USE_LCMS1
- cmsToneCurve Gamma = cmsBuildGamma(256, 2.2);
+ cmsToneCurve Gamma = cmsBuildGamma(256, 2.2);
#else
- cmsToneCurve * Gamma = cmsBuildGamma(NULL, 2.2);
+ cmsToneCurve *Gamma = cmsBuildGamma(NULL, 2.2);
#endif
- // Build sGray profile
- wp = sgray_wp_cms();
- sgray = cmsCreateGrayProfile(&wp, Gamma);
+ // Build sGray profile
+ wp = sgray_wp_cms();
+ sgray = cmsCreateGrayProfile(&wp, Gamma);
- return sgray;
+ return (sgray);
}
#ifdef USE_LCMS1
-static int lcms_error_handler(int ErrorCode, const char *ErrorText)
+static int
+lcms_error_handler(int ErrorCode,
+ const char *ErrorText)
{
- return 1;
+ return (1);
}
#else
-static void lcms_error_handler(cmsContext contextId, cmsUInt32Number ErrorCode,
- const char *ErrorText)
+static void
+lcms_error_handler(cmsContext contextId,
+ cmsUInt32Number ErrorCode,
+ const char *ErrorText)
{
return;
}
#endif
-static int parse_opts(cf_filter_out_format_t outformat,
- pwgtoraster_doc_t *doc)
+
+static int
+parse_opts(cf_filter_out_format_t outformat,
+ pwgtoraster_doc_t *doc)
{
int num_options = 0;
cups_option_t *options = NULL;
cf_filter_data_t *data = doc->data;
cf_logfunc_t log = data->logfunc;
void *ld = data ->logdata;
- cups_cspace_t cspace = (cups_cspace_t)(-1);
+ cups_cspace_t cspace = (cups_cspace_t)(-1);
num_options = cfJoinJobOptionsAndAttrs(data, num_options, &options);
// We can directly create CUPS Raster, PWG Raster, and Apple Raster
cfRasterPrepareHeader(&(doc->outheader), data, outformat,
- outformat, 0, &cspace);
+ outformat, 0, &cspace);
if (doc->outheader.Duplex)
{
int backside;
- /* analyze options relevant to Duplex */
- /* APDuplexRequiresFlippedMargin */
- enum {
+
+ // analyze options relevant to Duplex
+ // APDuplexRequiresFlippedMargin
+ enum
+ {
FM_NO,
FM_FALSE,
FM_TRUE
if (flippedMargin == FM_TRUE)
doc->swap_margin_y = false;
}
- else if (backside==CF_BACKSIDE_ROTATED && !doc->outheader.Tumble)
+ else if (backside == CF_BACKSIDE_ROTATED && !doc->outheader.Tumble)
{
doc->swap_margin_x = doc->swap_margin_y = true;
if (flippedMargin == FM_TRUE)
doc->swap_margin_y = false;
}
- else if (backside==CF_BACKSIDE_FLIPPED)
+ else if (backside == CF_BACKSIDE_FLIPPED)
{
if (doc->outheader.Tumble)
doc->swap_margin_x = doc->swap_margin_y = true;
}
}
- /* support the CUPS "cm-calibration" option */
+ // support the CUPS "cm-calibration" option
doc->color_profile.cm_calibrate = cfCmGetCupsColorCalibrateMode(data);
if (doc->color_profile.cm_calibrate == CF_CM_CALIBRATION_ENABLED)
if (profile != NULL)
{
- doc->color_profile.colorProfile = cmsOpenProfileFromFile(profile,"r");
+ doc->color_profile.colorProfile = cmsOpenProfileFromFile(profile, "r");
free(profile);
}
doc->outheader.cupsRenderingIntent[0] = '\0';
cfGetPrintRenderIntent(data, doc->outheader.cupsRenderingIntent,
sizeof(doc->outheader.cupsRenderingIntent));
- if (strcasecmp(doc->outheader.cupsRenderingIntent, "Perceptual") == 0) {
+ if (strcasecmp(doc->outheader.cupsRenderingIntent, "Perceptual") == 0)
doc->color_profile.renderingIntent = INTENT_PERCEPTUAL;
- } else if (strcasecmp(doc->outheader.cupsRenderingIntent, "Relative") == 0) {
+ else if (strcasecmp(doc->outheader.cupsRenderingIntent, "Relative") == 0)
doc->color_profile.renderingIntent = INTENT_RELATIVE_COLORIMETRIC;
- } else if (strcasecmp(doc->outheader.cupsRenderingIntent, "Saturation") == 0) {
+ else if (strcasecmp(doc->outheader.cupsRenderingIntent, "Saturation") == 0)
doc->color_profile.renderingIntent = INTENT_SATURATION;
- } else if (strcasecmp(doc->outheader.cupsRenderingIntent, "Absolute") == 0) {
+ else if (strcasecmp(doc->outheader.cupsRenderingIntent, "Absolute") == 0)
doc->color_profile.renderingIntent = INTENT_ABSOLUTE_COLORIMETRIC;
- }
- if ((val = cupsGetOption("print-color-mode", num_options, options)) != NULL
- && !strncasecmp(val, "bi-level", 8))
+ if ((val = cupsGetOption("print-color-mode", num_options, options)) != NULL &&
+ !strncasecmp(val, "bi-level", 8))
doc->bi_level = 1;
if (log) log(ld, CF_LOGLEVEL_DEBUG,
return (0);
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
unsigned char *p = src;
- for (unsigned int j = 0;j < size;j++,p++) {
+ for (unsigned int j = 0; j < size; j ++, p ++)
*p = ~*p;
- }
- return src;
+
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+size-1;
+ unsigned char *bp = src + size - 1;
unsigned char *dp = dst;
- for (unsigned int j = 0;j < size;j++,bp--,dp++) {
+ for (unsigned int j = 0; j < size; j ++, bp --, dp ++)
*dp = ~*bp;
- }
- return dst;
+
+ return (dst);
}
-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, convert_cspace_func convertCSpace)
+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,
+ convert_cspace_func convertCSpace)
{
dst = cfReverseOneBitLineSwap(src, dst, pixels, size);
- return dst;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- cfImageRGBToCMYK(src,dst,pixels);
- return dst;
+ cfImageRGBToCMYK(src, dst, pixels);
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+(pixels-1)*3;
+ unsigned char *bp = src + (pixels - 1) * 3;
unsigned char *dp = dst;
- for (unsigned int i = 0;i < pixels;i++, bp -= 3, dp += 4) {
- cfImageRGBToCMYK(bp,dp,1);
- }
- return dst;
+ for (unsigned int i = 0; i < pixels; i++, bp -= 3, dp += 4)
+ cfImageRGBToCMYK(bp, dp, 1);
+
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- cfImageRGBToCMY(src,dst,pixels);
- return dst;
+ cfImageRGBToCMY(src, dst, pixels);
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+size-3;
+ unsigned char *bp = src + size - 3;
unsigned char *dp = dst;
- for (unsigned int i = 0;i < pixels;i++, bp -= 3, dp += 3) {
- cfImageRGBToCMY(bp,dp,1);
- }
- return dst;
+ for (unsigned int i = 0; i < pixels; i++, bp -= 3, dp += 3)
+ cfImageRGBToCMY(bp, dp, 1);
+
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
unsigned char *bp = src;
unsigned char *dp = dst;
unsigned char d;
- cfImageRGBToCMYK(src,dst,pixels);
- /* CMYK to KCMY */
- for (unsigned int i = 0;i < pixels;i++, bp += 3, dp += 4) {
+ cfImageRGBToCMYK(src, dst, pixels);
+ // CMYK to KCMY
+ for (unsigned int i = 0; i < pixels; i ++, bp += 3, dp += 4) {
d = dp[3];
dp[3] = dp[2];
dp[2] = dp[1];
dp[1] = dp[0];
dp[0] = d;
}
- return dst;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+(pixels-1)*3;
+ unsigned char *bp = src + (pixels - 1) * 3;
unsigned char *dp = dst;
unsigned char d;
- for (unsigned int i = 0;i < pixels;i++, bp -= 3, dp += 4) {
- cfImageRGBToCMYK(bp,dp,1);
- /* CMYK to KCMY */
+ for (unsigned int i = 0; i < pixels; i++, bp -= 3, dp += 4)
+ {
+ cfImageRGBToCMYK(bp, dp, 1);
+ // CMYK to KCMY
d = dp[3];
dp[3] = dp[2];
dp[2] = dp[1];
dp[1] = dp[0];
dp[0] = d;
}
- return dst;
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- /* do nothing */
- return src;
+ // do nothing
+ return (src);
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+size-3;
+ unsigned char *bp = src + size - 3;
unsigned char *dp = dst;
- for (unsigned int i = 0;i < pixels;i++, bp -= 3, dp += 3) {
+ for (unsigned int i = 0; i < pixels; i++, bp -= 3, dp += 3)
+ {
dp[0] = bp[0];
dp[1] = bp[1];
dp[2] = bp[2];
}
- return dst;
+
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- unsigned char *bp = src+size-1;
+ unsigned char *bp = src + size - 1;
unsigned char *dp = dst;
- for (unsigned int j = 0;j < size;j++,bp--,dp++) {
+ for (unsigned int j = 0; j < size; j++, bp --, dp ++)
*dp = *bp;
- }
- return dst;
+
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
dst = cfReverseOneBitLine(src, dst, pixels, size);
- return dst;
+ return (dst);
}
-typedef struct func_table_s {
+
+typedef struct func_table_s
+{
enum cups_cspace_e cspace;
unsigned int bitsPerPixel;
unsigned int bitsPerColor;
bool allocLineBufSwap;
} 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 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 *convert_cspace_none(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc)
+
+static unsigned char *
+convert_cspace_none(unsigned char *src,
+ unsigned char *pixelBuf,
+ unsigned int x,
+ unsigned int y,
+ pwgtoraster_doc_t *doc)
{
- return src;
+ return (src);
}
-static unsigned char *convert_cspace_with_profiles(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc)
+
+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;
+ cmsDoTransform(doc->color_profile.colorTransform, src, pixelBuf, 1);
+ return (pixelBuf);
}
-static unsigned char *convert_cspace_xyz_8(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc)
+
+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];
- cmsDoTransform(doc->color_profile.colorTransform,src,alab,1);
+ cmsDoTransform(doc->color_profile.colorTransform, src, alab, 1);
+
cmsCIELab lab;
cmsCIEXYZ xyz;
lab.a = alab[1];
lab.b = alab[2];
- cmsLab2XYZ(&(doc->color_profile.D65WhitePoint),&xyz,&lab);
- pixelBuf[0] = 231.8181*xyz.X+0.5;
- pixelBuf[1] = 231.8181*xyz.Y+0.5;
- pixelBuf[2] = 231.8181*xyz.Z+0.5;
- return pixelBuf;
+ cmsLab2XYZ(&(doc->color_profile.D65WhitePoint), &xyz, &lab);
+ pixelBuf[0] = 231.8181 * xyz.X + 0.5;
+ pixelBuf[1] = 231.8181 * xyz.Y + 0.5;
+ pixelBuf[2] = 231.8181 * xyz.Z + 0.5;
+
+ return (pixelBuf);
}
-static unsigned char *convert_cspace_xyz_16(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc)
+
+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];
unsigned short *sd = (unsigned short *)pixelBuf;
- cmsDoTransform(doc->color_profile.colorTransform,src,alab,1);
+ cmsDoTransform(doc->color_profile.colorTransform, src, alab, 1);
+
cmsCIELab lab;
cmsCIEXYZ xyz;
lab.b = alab[2];
cmsLab2XYZ(&(doc->color_profile.D65WhitePoint),&xyz,&lab);
- sd[0] = 59577.2727*xyz.X+0.5;
- sd[1] = 59577.2727*xyz.Y+0.5;
- sd[2] = 59577.2727*xyz.Z+0.5;
- return pixelBuf;
+ sd[0] = 59577.2727 * xyz.X + 0.5;
+ sd[1] = 59577.2727 * xyz.Y + 0.5;
+ sd[2] = 59577.2727 * xyz.Z + 0.5;
+
+ return (pixelBuf);
}
-static unsigned char *convert_cspace_lab_8(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc)
+
+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];
- cmsDoTransform(doc->color_profile.colorTransform ,src,lab,1);
- pixelBuf[0] = 2.55*lab[0]+0.5;
- pixelBuf[1] = lab[1]+128.5;
- pixelBuf[2] = lab[2]+128.5;
- return pixelBuf;
+
+ cmsDoTransform(doc->color_profile.colorTransform, src, lab, 1);
+ pixelBuf[0] = 2.55 * lab[0] + 0.5;
+ pixelBuf[1] = lab[1] + 128.5;
+ pixelBuf[2] = lab[2] + 128.5;
+
+ return (pixelBuf);
}
-static unsigned char *convert_cspace_lab_16(unsigned char *src,
- unsigned char *pixelBuf, unsigned int x, unsigned int y, pwgtoraster_doc_t *doc)
+
+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];
- cmsDoTransform(doc->color_profile.colorTransform,src,lab,1);
+
+ cmsDoTransform(doc->color_profile.colorTransform, src, lab, 1);
+
unsigned short *sd = (unsigned short *)pixelBuf;
- sd[0] = 655.35*lab[0]+0.5;
- sd[1] = 256*(lab[1]+128)+0.5;
- sd[2] = 256*(lab[2]+128)+0.5;
- return pixelBuf;
+ sd[0] = 655.35 * lab[0] + 0.5;
+ sd[1] = 256 * (lab[1] + 128) + 0.5;
+ sd[2] = 256 * (lab[2] + 128) + 0.5;
+
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_rgba(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pwgtoraster_doc_t* doc)
+
+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;
- for (int i = 0;i < 3;i++) {
+ for (int i = 0; i < 3; i ++)
*dp++ = *src++;
- }
+
*dp = 255;
- return pixelBuf;
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_rgbw(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pwgtoraster_doc_t* doc)
+
+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];
unsigned char *dp = pixelBuf;
- cfImageRGBToCMYK(src,cmyk,1);
- for (int i = 0;i < 4;i++) {
+ cfImageRGBToCMYK(src, cmyk, 1);
+ for (int i = 0; i < 4; i++)
*dp++ = ~cmyk[i];
- }
- return pixelBuf;
+
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_cmyk(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pwgtoraster_doc_t* doc)
+
+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;
+ cfImageRGBToCMYK(src, pixelBuf, 1);
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_cmy(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pwgtoraster_doc_t* doc)
+
+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;
+ cfImageRGBToCMY(src, pixelBuf, 1);
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_ymc(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pwgtoraster_doc_t* doc)
+
+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);
- /* swap C and Y */
+ cfImageRGBToCMY(src, pixelBuf, 1);
+ // swap C and Y
unsigned char d = pixelBuf[0];
pixelBuf[0] = pixelBuf[2];
pixelBuf[2] = d;
- return pixelBuf;
+
+ return (pixelBuf);
}
-static unsigned char *rgb_8_to_kcmy(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pwgtoraster_doc_t* doc)
+
+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);
+ cfImageRGBToCMYK(src, pixelBuf, 1);
unsigned char d = pixelBuf[3];
pixelBuf[3] = pixelBuf[2];
pixelBuf[2] = pixelBuf[1];
pixelBuf[1] = pixelBuf[0];
pixelBuf[0] = d;
- return pixelBuf;
+
+ return (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)
+
+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);
+ return (cfRGB8toKCMYcm(src, pixelBuf, x, y));
}
-static unsigned char *rgb_8_to_ymck(unsigned char *src, unsigned char *pixelBuf,
- unsigned int x, unsigned int y, pwgtoraster_doc_t* doc)
+
+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);
- /* swap C and Y */
+ cfImageRGBToCMYK(src, pixelBuf, 1);
+ // swap C and Y
unsigned char d = pixelBuf[0];
pixelBuf[0] = pixelBuf[2];
pixelBuf[2] = d;
- return pixelBuf;
+
+ return (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)
+
+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;
+ return (pixelBuf);
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- /* Assumed that BitsPerColor is 8 */
- for (unsigned int i = 0;i < pixels;i++) {
- unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
- unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
- unsigned char *pb;
-
- pb = convertCSpace(src+i*(doc->outputNumColors),pixelBuf1,i,row, doc);
- pb = cfConvertBits(pb,pixelBuf2,i,row, doc->outheader.cupsNumColors, doc->bitspercolor);
- cfWritePixel(dst,0,i,pb, doc->outheader.cupsNumColors, doc->outheader.cupsBitsPerColor, doc->outheader.cupsColorOrder);
+ // Assumed that BitsPerColor is 8
+ for (unsigned int i = 0; i < pixels; i ++)
+ {
+ unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
+ unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
+ unsigned char *pb;
+
+ pb = convertCSpace(src + i * (doc->outputNumColors), pixelBuf1, i, row,
+ doc);
+ pb = cfConvertBits(pb, pixelBuf2, i, row, doc->outheader.cupsNumColors,
+ doc->bitspercolor);
+ cfWritePixel(dst, 0, i, pb, doc->outheader.cupsNumColors,
+ doc->outheader.cupsBitsPerColor,
+ doc->outheader.cupsColorOrder);
}
- return dst;
+
+ return (dst);
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- /* Assumed that BitsPerColor is 8 */
- for (unsigned int i = 0;i < pixels;i++) {
- unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
- unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
- unsigned char *pb;
-
- pb = convertCSpace(src+(pixels-i-1)*(doc->outputNumColors),pixelBuf1,i,row, doc);
- pb = cfConvertBits(pb,pixelBuf2,i,row, doc->outheader.cupsNumColors, doc->bitspercolor);
- cfWritePixel(dst,0,i,pb, doc->outheader.cupsNumColors, doc->outheader.cupsBitsPerColor, doc->outheader.cupsColorOrder);
+ // Assumed that BitsPerColor is 8
+ for (unsigned int i = 0; i < pixels; i++)
+ {
+ unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
+ unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
+ unsigned char *pb;
+
+ pb = convertCSpace(src + (pixels - i - 1) * doc->outputNumColors,
+ pixelBuf1, i, row, doc);
+ pb = cfConvertBits(pb, pixelBuf2, i, row, doc->outheader.cupsNumColors,
+ doc->bitspercolor);
+ cfWritePixel(dst, 0, i, pb, doc->outheader.cupsNumColors,
+ doc->outheader.cupsBitsPerColor,
+ doc->outheader.cupsColorOrder);
}
- return dst;
+
+ return (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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- /* Assumed that BitsPerColor is 8 */
- for (unsigned int i = 0;i < pixels;i++) {
- unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
- unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
- unsigned char *pb;
-
- pb = convertCSpace(src+i*(doc->outputNumColors),pixelBuf1,i,row, doc);
- pb = cfConvertBits(pb,pixelBuf2,i,row, doc->outheader.cupsNumColors, doc->bitspercolor);
- cfWritePixel(dst,plane,i,pb, doc->outheader.cupsNumColors, doc->outheader.cupsBitsPerColor, doc->outheader.cupsColorOrder);
+ // Assumed that BitsPerColor is 8
+ for (unsigned int i = 0; i < pixels; i ++)
+ {
+ unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
+ unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
+ unsigned char *pb;
+
+ pb = convertCSpace(src + i * doc->outputNumColors, pixelBuf1, i, row, doc);
+ pb = cfConvertBits(pb, pixelBuf2, i, row, doc->outheader.cupsNumColors,
+ doc->bitspercolor);
+ cfWritePixel(dst, plane, i, pb, doc->outheader.cupsNumColors,
+ doc->outheader.cupsBitsPerColor,
+ doc->outheader.cupsColorOrder);
}
- return dst;
+
+ return (dst);
}
-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, convert_cspace_func convertCSpace)
+
+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,
+ convert_cspace_func convertCSpace)
{
- for (unsigned int i = 0;i < pixels;i++) {
- unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
- unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
- unsigned char *pb;
-
- pb = convertCSpace(src+(pixels-i-1)*(doc->outputNumColors),pixelBuf1,i,row, doc);
- pb = cfConvertBits(pb,pixelBuf2,i,row, doc->outheader.cupsNumColors, doc->bitspercolor);
- cfWritePixel(dst,plane,i,pb, doc->outheader.cupsNumColors, doc->outheader.cupsBitsPerColor, doc->outheader.cupsColorOrder);
+ for (unsigned int i = 0; i < pixels; i ++)
+ {
+ unsigned char pixelBuf1[MAX_BYTES_PER_PIXEL];
+ unsigned char pixelBuf2[MAX_BYTES_PER_PIXEL];
+ unsigned char *pb;
+
+ pb = convertCSpace(src + (pixels - i - 1) * doc->outputNumColors,
+ pixelBuf1, i, row, doc);
+ pb = cfConvertBits(pb, pixelBuf2, i, row, doc->outheader.cupsNumColors,
+ doc->bitspercolor);
+ cfWritePixel(dst, plane, i, pb, doc->outheader.cupsNumColors,
+ doc->outheader.cupsBitsPerColor,
+ doc->outheader.cupsColorOrder);
}
- return dst;
+
+ return (dst);
}
-/* Handle special cases which appear in the Gutenprint driver */
-static bool select_special_case(pwgtoraster_doc_t* doc, conversion_function_t* convert)
+
+// Handle special cases which appear in the Gutenprint driver
+static bool
+select_special_case(pwgtoraster_doc_t* doc,
+ conversion_function_t* convert)
{
int i;
- for (i = 0;specialCaseFuncs[i].bitsPerPixel > 0;i++) {
- if (doc->outheader.cupsColorSpace == specialCaseFuncs[i].cspace
- && doc->outheader.cupsBitsPerPixel == specialCaseFuncs[i].bitsPerPixel
- && doc->outheader.cupsBitsPerColor == specialCaseFuncs[i].bitsPerColor) {
+ for (i = 0; specialCaseFuncs[i].bitsPerPixel > 0; i ++)
+ {
+ if (doc->outheader.cupsColorSpace == specialCaseFuncs[i].cspace &&
+ doc->outheader.cupsBitsPerPixel == specialCaseFuncs[i].bitsPerPixel &&
+ doc->outheader.cupsBitsPerColor == specialCaseFuncs[i].bitsPerColor)
+ {
convert->convertLineOdd = specialCaseFuncs[i].convertLine;
convert->convertLineEven = specialCaseFuncs[i].convertLine;
doc->allocLineBuf = specialCaseFuncs[i].allocLineBuf;
- return true; /* found */
+ return (true); // found
}
}
- return false;
+
+ return (false);
}
-static unsigned int get_cms_color_space_type(cmsColorSpaceSignature cs)
+
+static unsigned int
+get_cms_color_space_type(cmsColorSpaceSignature cs)
{
- switch (cs) {
+ switch (cs)
+ {
case cmsSigXYZData:
- return PT_XYZ;
- break;
+ return (PT_XYZ);
+ break;
case cmsSigLabData:
- return PT_Lab;
- break;
+ return (PT_Lab);
+ break;
case cmsSigLuvData:
- return PT_YUV;
- break;
+ return (PT_YUV);
+ break;
case cmsSigYCbCrData:
- return PT_YCbCr;
- break;
+ return (PT_YCbCr);
+ break;
case cmsSigYxyData:
- return PT_Yxy;
- break;
+ return (PT_Yxy);
+ break;
case cmsSigRgbData:
- return PT_RGB;
- break;
+ return (PT_RGB);
+ break;
case cmsSigGrayData:
- return PT_GRAY;
- break;
+ return (PT_GRAY);
+ break;
case cmsSigHsvData:
- return PT_HSV;
- break;
+ return (PT_HSV);
+ break;
case cmsSigHlsData:
- return PT_HLS;
- break;
+ return (PT_HLS);
+ break;
case cmsSigCmykData:
- return PT_CMYK;
- break;
+ return (PT_CMYK);
+ break;
case cmsSigCmyData:
- return PT_CMY;
- break;
+ return (PT_CMY);
+ break;
case cmsSig2colorData:
case cmsSig3colorData:
case cmsSig4colorData:
case cmsSig14colorData:
case cmsSig15colorData:
default:
- break;
- }
- return PT_RGB;
+ break;
+ }
+
+ return (PT_RGB);
}
-/* select convertLine function */
+
+// select convertLine function
static int select_convert_func(cups_raster_t *raster,
pwgtoraster_doc_t* doc,
conversion_function_t *convert)
{
cf_logfunc_t log = doc->data->logfunc;
- void* ld = doc->data->logdata;
+ void *ld = doc->data->logdata;
doc->bitspercolor = doc->outheader.cupsBitsPerColor;
- 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 ((doc->color_profile.colorProfile == NULL ||
+ doc->color_profile.outputColorProfile ==
+ doc->color_profile.colorProfile) &&
+ (doc->outheader.cupsColorOrder == CUPS_ORDER_CHUNKED ||
+ doc->outheader.cupsNumColors == 1))
+ {
if (select_special_case(doc, convert))
return (0);
}
- switch (doc->outheader.cupsColorOrder) {
- case CUPS_ORDER_BANDED:
- case CUPS_ORDER_PLANAR:
- if (doc->outheader.cupsNumColors > 1) {
- convert->convertLineEven = convert_line_plane_swap;
- convert->convertLineOdd = convert_line_plane;
- break;
- }
- default:
- case CUPS_ORDER_CHUNKED:
- convert->convertLineEven = convert_line_chunked_swap;
- convert->convertLineOdd = convert_line_chunked;
- break;
+ switch (doc->outheader.cupsColorOrder)
+ {
+ case CUPS_ORDER_BANDED:
+ case CUPS_ORDER_PLANAR:
+ if (doc->outheader.cupsNumColors > 1)
+ {
+ convert->convertLineEven = convert_line_plane_swap;
+ convert->convertLineOdd = convert_line_plane;
+ break;
+ }
+ default:
+ case CUPS_ORDER_CHUNKED:
+ convert->convertLineEven = convert_line_chunked_swap;
+ convert->convertLineOdd = convert_line_chunked;
+ break;
}
convert->convertLineEven = convert->convertLineOdd;
doc->allocLineBuf = true;
- if (doc->color_profile.colorProfile != NULL && doc->color_profile.outputColorProfile != doc->color_profile.colorProfile) {
+ if (doc->color_profile.colorProfile != NULL &&
+ doc->color_profile.outputColorProfile !=
+ doc->color_profile.colorProfile)
+ {
unsigned int bytes;
- switch (doc->outheader.cupsColorSpace) {
- case CUPS_CSPACE_CIELab:
- case CUPS_CSPACE_ICC1:
- case CUPS_CSPACE_ICC2:
- case CUPS_CSPACE_ICC3:
- case CUPS_CSPACE_ICC4:
- case CUPS_CSPACE_ICC5:
- case CUPS_CSPACE_ICC6:
- case CUPS_CSPACE_ICC7:
- case CUPS_CSPACE_ICC8:
- case CUPS_CSPACE_ICC9:
- case CUPS_CSPACE_ICCA:
- case CUPS_CSPACE_ICCB:
- case CUPS_CSPACE_ICCC:
- case CUPS_CSPACE_ICCD:
- case CUPS_CSPACE_ICCE:
- case CUPS_CSPACE_ICCF:
- if (doc->outheader.cupsBitsPerColor == 8) {
- convert->convertCSpace = convert_cspace_lab_8;
- } else {
- /* 16 bits */
- convert->convertCSpace = convert_cspace_lab_16;
- }
- bytes = 0; /* double */
- break;
- case CUPS_CSPACE_CIEXYZ:
- if (doc->outheader.cupsBitsPerColor == 8) {
- convert->convertCSpace = convert_cspace_xyz_8;
- } else {
- /* 16 bits */
- convert->convertCSpace = convert_cspace_xyz_16;
- }
- bytes = 0; /* double */
- break;
- default:
- convert->convertCSpace = convert_cspace_with_profiles;
- bytes = doc->outheader.cupsBitsPerColor/8;
- break;
+ switch (doc->outheader.cupsColorSpace)
+ {
+ case CUPS_CSPACE_CIELab:
+ case CUPS_CSPACE_ICC1:
+ case CUPS_CSPACE_ICC2:
+ case CUPS_CSPACE_ICC3:
+ case CUPS_CSPACE_ICC4:
+ case CUPS_CSPACE_ICC5:
+ case CUPS_CSPACE_ICC6:
+ case CUPS_CSPACE_ICC7:
+ case CUPS_CSPACE_ICC8:
+ case CUPS_CSPACE_ICC9:
+ case CUPS_CSPACE_ICCA:
+ case CUPS_CSPACE_ICCB:
+ case CUPS_CSPACE_ICCC:
+ case CUPS_CSPACE_ICCD:
+ case CUPS_CSPACE_ICCE:
+ case CUPS_CSPACE_ICCF:
+ if (doc->outheader.cupsBitsPerColor == 8)
+ convert->convertCSpace = convert_cspace_lab_8;
+ else
+ // 16 bits
+ convert->convertCSpace = convert_cspace_lab_16;
+ bytes = 0; // double
+ break;
+ case CUPS_CSPACE_CIEXYZ:
+ if (doc->outheader.cupsBitsPerColor == 8)
+ convert->convertCSpace = convert_cspace_xyz_8;
+ else
+ // 16 bits
+ convert->convertCSpace = convert_cspace_xyz_16;
+ bytes = 0; // double
+ break;
+ default:
+ convert->convertCSpace = convert_cspace_with_profiles;
+ bytes = doc->outheader.cupsBitsPerColor / 8;
+ break;
}
- doc->bitspercolor = 0; /* convert bits in convertCSpace */
- if (doc->color_profile.outputColorProfile == NULL) {
+ doc->bitspercolor = 0; // convert bits in convertCSpace
+ if (doc->color_profile.outputColorProfile == NULL)
doc->color_profile.outputColorProfile = cmsCreate_sRGBProfile();
- }
unsigned int dcst =
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),
+ COLORSPACE_SH(PT_RGB) | CHANNELS_SH(3) |
+ BYTES_SH(1),
doc->color_profile.colorProfile,
COLORSPACE_SH(dcst) |
CHANNELS_SH(doc->outheader.cupsNumColors) |
BYTES_SH(bytes),
- doc->color_profile.renderingIntent,0)) == 0) {
+ doc->color_profile.renderingIntent,0)) == 0)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPWGToRaster: Can't create color transform.");
return (1);
}
- } else {
- /* select convertCSpace function */
- switch (doc->outheader.cupsColorSpace) {
- case CUPS_CSPACE_CIELab:
- case CUPS_CSPACE_ICC1:
- case CUPS_CSPACE_ICC2:
- case CUPS_CSPACE_ICC3:
- case CUPS_CSPACE_ICC4:
- case CUPS_CSPACE_ICC5:
- case CUPS_CSPACE_ICC6:
- case CUPS_CSPACE_ICC7:
- case CUPS_CSPACE_ICC8:
- case CUPS_CSPACE_ICC9:
- case CUPS_CSPACE_ICCA:
- case CUPS_CSPACE_ICCB:
- case CUPS_CSPACE_ICCC:
- case CUPS_CSPACE_ICCD:
- case CUPS_CSPACE_ICCE:
- case CUPS_CSPACE_ICCF:
- case CUPS_CSPACE_CIEXYZ:
- convert->convertCSpace = convert_cspace_none;
- break;
- case CUPS_CSPACE_CMY:
- convert->convertCSpace = rgb_8_to_cmy;
- break;
- case CUPS_CSPACE_YMC:
- convert->convertCSpace = rgb_8_to_ymc;
- break;
- case CUPS_CSPACE_CMYK:
- convert->convertCSpace = rgb_8_to_cmyk;
- break;
- case CUPS_CSPACE_KCMY:
- convert->convertCSpace = rgb_8_to_kcmy;
- break;
- case CUPS_CSPACE_KCMYcm:
- if (doc->outheader.cupsBitsPerColor > 1) {
- convert->convertCSpace = rgb_8_to_kcmy;
- } else {
- convert->convertCSpace = rgb_8_to_kcmycm_temp;
- }
- break;
- case CUPS_CSPACE_GMCS:
- case CUPS_CSPACE_GMCK:
- case CUPS_CSPACE_YMCK:
- convert->convertCSpace = rgb_8_to_ymck;
- break;
- case CUPS_CSPACE_RGBW:
- convert->convertCSpace = rgb_8_to_rgbw;
- break;
- case CUPS_CSPACE_RGBA:
- convert->convertCSpace = rgb_8_to_rgba;
- break;
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_SRGB:
- case CUPS_CSPACE_ADOBERGB:
- convert->convertCSpace = convert_cspace_none;
- break;
- case CUPS_CSPACE_W:
- case CUPS_CSPACE_SW:
- case CUPS_CSPACE_WHITE:
- convert->convertCSpace = convert_cspace_none;
- break;
- case CUPS_CSPACE_K:
- case CUPS_CSPACE_GOLD:
- case CUPS_CSPACE_SILVER:
- convert->convertCSpace = w_8_to_k_8;
- break;
- default:
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPWGToRaster: Specified ColorSpace is not supported");
- return (1);
- break;
+ }
+ else
+ {
+ // select convertCSpace function
+ switch (doc->outheader.cupsColorSpace)
+ {
+ case CUPS_CSPACE_CIELab:
+ case CUPS_CSPACE_ICC1:
+ case CUPS_CSPACE_ICC2:
+ case CUPS_CSPACE_ICC3:
+ case CUPS_CSPACE_ICC4:
+ case CUPS_CSPACE_ICC5:
+ case CUPS_CSPACE_ICC6:
+ case CUPS_CSPACE_ICC7:
+ case CUPS_CSPACE_ICC8:
+ case CUPS_CSPACE_ICC9:
+ case CUPS_CSPACE_ICCA:
+ case CUPS_CSPACE_ICCB:
+ case CUPS_CSPACE_ICCC:
+ case CUPS_CSPACE_ICCD:
+ case CUPS_CSPACE_ICCE:
+ case CUPS_CSPACE_ICCF:
+ case CUPS_CSPACE_CIEXYZ:
+ convert->convertCSpace = convert_cspace_none;
+ break;
+ case CUPS_CSPACE_CMY:
+ convert->convertCSpace = rgb_8_to_cmy;
+ break;
+ case CUPS_CSPACE_YMC:
+ convert->convertCSpace = rgb_8_to_ymc;
+ break;
+ case CUPS_CSPACE_CMYK:
+ convert->convertCSpace = rgb_8_to_cmyk;
+ break;
+ case CUPS_CSPACE_KCMY:
+ convert->convertCSpace = rgb_8_to_kcmy;
+ break;
+ case CUPS_CSPACE_KCMYcm:
+ if (doc->outheader.cupsBitsPerColor > 1)
+ convert->convertCSpace = rgb_8_to_kcmy;
+ else
+ convert->convertCSpace = rgb_8_to_kcmycm_temp;
+ break;
+ case CUPS_CSPACE_GMCS:
+ case CUPS_CSPACE_GMCK:
+ case CUPS_CSPACE_YMCK:
+ convert->convertCSpace = rgb_8_to_ymck;
+ break;
+ case CUPS_CSPACE_RGBW:
+ convert->convertCSpace = rgb_8_to_rgbw;
+ break;
+ case CUPS_CSPACE_RGBA:
+ convert->convertCSpace = rgb_8_to_rgba;
+ break;
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_SRGB:
+ case CUPS_CSPACE_ADOBERGB:
+ convert->convertCSpace = convert_cspace_none;
+ break;
+ case CUPS_CSPACE_W:
+ case CUPS_CSPACE_SW:
+ case CUPS_CSPACE_WHITE:
+ convert->convertCSpace = convert_cspace_none;
+ break;
+ case CUPS_CSPACE_K:
+ case CUPS_CSPACE_GOLD:
+ case CUPS_CSPACE_SILVER:
+ convert->convertCSpace = w_8_to_k_8;
+ break;
+ default:
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterPWGToRaster: Specified ColorSpace is not supported");
+ return (1);
+ break;
}
}
if (doc->outheader.cupsBitsPerColor == 1 &&
(doc->outheader.cupsNumColors == 1 ||
doc->outheader.cupsColorSpace == CUPS_CSPACE_KCMYcm ))
- doc->bitspercolor = 0; /* Do not convert the bits */
+ doc->bitspercolor = 0; // Do not convert the bits
return (0);
}
-static bool out_page(pwgtoraster_doc_t *doc,
- int pageNo,
- cups_raster_t *inras,
- cups_raster_t *outras,
- conversion_function_t *convert)
+
+static bool
+out_page(pwgtoraster_doc_t *doc,
+ int pageNo,
+ cups_raster_t *inras,
+ cups_raster_t *outras,
+ conversion_function_t *convert)
{
int i, j;
cf_filter_data_t *data = doc->data;
- float paperdimensions[2], /* Physical size of the paper */
- margins[4]; /* Physical margins of print */
+ float paperdimensions[2], // Physical size of the paper
+ margins[4]; // Physical margins of print
float swap;
int imageable_area_fit = 0;
int overspray_duplicate_after_pixels = INT_MAX;
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
void *icd = data->iscanceleddata;
+
if (iscanceled && iscanceled(icd))
{
// Canceled
return (false);
}
- if (log) {
+ if (log)
+ {
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToRaster: Input page %d", pageNo);
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToRaster: PageSize = [ %d %d ]",
doc->inheader.PageSize[0], doc->inheader.PageSize[1]);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsWidth = %d", doc->inheader.cupsWidth);
+ "cfFilterPWGToRaster: cupsWidth = %d",
+ doc->inheader.cupsWidth);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsHeight = %d", doc->inheader.cupsHeight);
+ "cfFilterPWGToRaster: cupsHeight = %d",
+ doc->inheader.cupsHeight);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsBitsPerColor = %d", doc->inheader.cupsBitsPerColor);
+ "cfFilterPWGToRaster: cupsBitsPerColor = %d",
+ doc->inheader.cupsBitsPerColor);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsBitsPerPixel = %d", doc->inheader.cupsBitsPerPixel);
+ "cfFilterPWGToRaster: cupsBitsPerPixel = %d",
+ doc->inheader.cupsBitsPerPixel);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsBytesPerLine = %d", doc->inheader.cupsBytesPerLine);
+ "cfFilterPWGToRaster: cupsBytesPerLine = %d",
+ doc->inheader.cupsBytesPerLine);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsColorOrder = %d", doc->inheader.cupsColorOrder);
+ "cfFilterPWGToRaster: cupsColorOrder = %d",
+ doc->inheader.cupsColorOrder);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsColorSpace = %d", doc->inheader.cupsColorSpace);
+ "cfFilterPWGToRaster: cupsColorSpace = %d",
+ doc->inheader.cupsColorSpace);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsCompression = %d", doc->inheader.cupsCompression);
+ "cfFilterPWGToRaster: cupsCompression = %d",
+ doc->inheader.cupsCompression);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsPageSizeName = %s", doc->inheader.cupsPageSizeName);
+ "cfFilterPWGToRaster: cupsPageSizeName = %s",
+ doc->inheader.cupsPageSizeName);
}
if (!doc->page_size_requested)
memset(margins, 0, sizeof(margins));
if (data->printer_attrs)
{
- /* Find dimensions/margins of requested page size */
+ // Find dimensions/margins of requested page size
if (cfGetPageDimensions(data->printer_attrs, data->job_attrs,
data->num_options, data->options,
&(doc->outheader), 0,
&(margins[0]), &(margins[1]),
&(margins[2]), &(margins[3]), NULL, NULL) == 0)
{
- /* Find dimensions/margins for input page size */
+ // Find dimensions/margins for input page size
cfGetPageDimensions(data->printer_attrs, NULL, 0, NULL,
&(doc->inheader), 0,
&(paperdimensions[0]), &(paperdimensions[1]),
margins[i] = 0.0;
}
- if (doc->outheader.Duplex && (pageNo & 1) == 0) {
- /* backside: change margin if needed */
- if (doc->swap_margin_x) {
+ if (doc->outheader.Duplex && (pageNo & 1) == 0)
+ {
+ // backside: change margin if needed
+ if (doc->swap_margin_x)
+ {
swap = margins[2]; margins[2] = margins[0]; margins[0] = swap;
}
- if (doc->swap_margin_y) {
+ if (doc->swap_margin_y)
+ {
swap = margins[3]; margins[3] = margins[1]; margins[1] = swap;
}
}
- if (imageable_area_fit == 0) {
+ if (imageable_area_fit == 0)
+ {
doc->bitmapoffset[0] = margins[0] / 72.0 * doc->outheader.HWResolution[0];
doc->bitmapoffset[1] = margins[3] / 72.0 * doc->outheader.HWResolution[1];
- } else {
+ }
+ else
+ {
doc->bitmapoffset[0] = 0;
doc->bitmapoffset[1] = 0;
}
doc->outheader.cupsHeight = ((paperdimensions[1] - margins[1] - margins[3]) /
72.0 * doc->outheader.HWResolution[1]) + 0.5;
- for (i = 0; i < 2; i ++) {
+ for (i = 0; i < 2; i ++)
+ {
doc->outheader.cupsPageSize[i] = paperdimensions[i];
doc->outheader.PageSize[i] =
(unsigned int)(doc->outheader.cupsPageSize[i] + 0.5);
if (doc->outheader.cupsColorOrder == CUPS_ORDER_BANDED)
doc->outheader.cupsBytesPerLine *= doc->outheader.cupsNumColors;
- if (!cupsRasterWriteHeader2(outras, &(doc->outheader))) {
+ if (!cupsRasterWriteHeader2(outras, &(doc->outheader)))
+ {
if (log) log(ld,CF_LOGLEVEL_ERROR,
"cfFilterPWGToRaster: Can't write page %d header", pageNo);
return (false);
}
- if (log) {
+ if (log)
+ {
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToRaster: Output page %d", pageNo);
if (doc->outheader.ImagingBoundingBox[3] > 0)
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToRaster: ManualFeed = %d", doc->outheader.ManualFeed);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: MediaPosition = %d", doc->outheader.MediaPosition);
+ "cfFilterPWGToRaster: MediaPosition = %d",
+ doc->outheader.MediaPosition);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: NumCopies = %d", doc->outheader.NumCopies);
+ "cfFilterPWGToRaster: NumCopies = %d",
+ doc->outheader.NumCopies);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: Orientation = %d", doc->outheader.Orientation);
+ "cfFilterPWGToRaster: Orientation = %d",
+ doc->outheader.Orientation);
}
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToRaster: PageSize = [ %d %d ]",
"cfFilterPWGToRaster: cupsHeight = %d", doc->outheader.cupsHeight);
if (doc->outheader.ImagingBoundingBox[3] > 0)
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsMediaType = %d", doc->outheader.cupsMediaType);
+ "cfFilterPWGToRaster: cupsMediaType = %d",
+ doc->outheader.cupsMediaType);
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToRaster: cupsBitsPerColor = %d",
doc->outheader.cupsBitsPerColor);
"cfFilterPWGToRaster: cupsBytesPerLine = %d",
doc->outheader.cupsBytesPerLine);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsColorOrder = %d", doc->outheader.cupsColorOrder);
+ "cfFilterPWGToRaster: cupsColorOrder = %d",
+ doc->outheader.cupsColorOrder);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsColorSpace = %d", doc->outheader.cupsColorSpace);
+ "cfFilterPWGToRaster: cupsColorSpace = %d",
+ doc->outheader.cupsColorSpace);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsCompression = %d", doc->outheader.cupsCompression);
+ "cfFilterPWGToRaster: cupsCompression = %d",
+ doc->outheader.cupsCompression);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsPageSizeName = %s", doc->outheader.cupsPageSizeName);
+ "cfFilterPWGToRaster: cupsPageSizeName = %s",
+ doc->outheader.cupsPageSizeName);
}
-
+
+ //
// write page image
+ //
if (iscanceled && iscanceled(icd))
// Canceled
- return false;
+ return (false);
+ //
// Pre-conversion of resolution and color space
//
// This is needed if we work with a driver (especially Gutenprint)
// Application has from the PPD often does not reflect the driver’s
// actual requirements, this filter function pre-converts
// resolutions and color spaces as needed.
+ //
// Check for needed resolution pre-conversions
for (i = 0; i < 2; i ++)
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPWGToRaster: Unsupported input color space: Number of colors: %d; Bits per color: %d.",
doc->inheader.cupsNumColors, doc->inheader.cupsBitsPerColor);
- return false;
+ return (false);
}
// Determine which input color space we need to obtain the output color
// space
- switch (doc->outheader.cupsColorSpace) {
- case CUPS_CSPACE_W: // Gray
- case CUPS_CSPACE_K: // Black
- case CUPS_CSPACE_SW: // sGray
- if (doc->outheader.cupsBitsPerColor == 1)
- color_mode_needed = 0;
- else
- color_mode_needed = 1;
- break;
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_ADOBERGB:
- case CUPS_CSPACE_CMYK:
- case CUPS_CSPACE_SRGB:
- case CUPS_CSPACE_CMY:
- case CUPS_CSPACE_RGBW:
- default:
- color_mode_needed = 2;
- break;
+ switch (doc->outheader.cupsColorSpace)
+ {
+ case CUPS_CSPACE_W: // Gray
+ case CUPS_CSPACE_K: // Black
+ case CUPS_CSPACE_SW: // sGray
+ if (doc->outheader.cupsBitsPerColor == 1)
+ color_mode_needed = 0;
+ else
+ color_mode_needed = 1;
+ break;
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_ADOBERGB:
+ case CUPS_CSPACE_CMYK:
+ case CUPS_CSPACE_SRGB:
+ case CUPS_CSPACE_CMY:
+ case CUPS_CSPACE_RGBW:
+ default:
+ color_mode_needed = 2;
+ break;
}
if (input_color_mode != color_mode_needed)
lineBuf = (unsigned char *)calloc(doc->bytesPerLine, sizeof(unsigned char));
// Switch conversion functions for even and odd pages
- if ((pageNo & 1) == 0) {
+ if ((pageNo & 1) == 0)
convertLine = convert->convertLineEven;
- } else {
+ else
convertLine = convert->convertLineOdd;
- }
+ //
// Input line buffer (with space for raising horizontal resolution
// and overspray stretch if needed)
//
// maximum of the input line size (multiplied by a resolution
// multiplier) and inlineoffset + inlinesize, to be sure to have
// enough space.
+ //
+
i = doc->inheader.cupsBytesPerLine * res_up_factor[0];
j = inlineoffset + inlinesize;
- if (j > i) i = j;
+ if (j > i)
+ i = j;
line =
(unsigned char *)calloc(i, sizeof(unsigned char));
pagebuf = (unsigned char *)calloc(doc->outheader.cupsHeight * inlinesize,
sizeof(unsigned char));
+ //
// Overspray stretch of the input image If the output page
// dimensions are larger than the input page dimensions we have most
// probably a page size from the driver where the page dimensions are
//
// This facility also fixes rounding errors which lead to the input
// raster to be a few pixels too small for the output.
+ //
if (doc->outheader.PageSize[0] > doc->inheader.PageSize[0] ||
doc->outheader.PageSize[1] > doc->inheader.PageSize[1])
// arranged in planes
next_line_read = 0;
next_overspray_duplicate = overspray_duplicate_after_pixels;
- for (unsigned int plane = 0; plane < doc->nplanes; plane ++) {
+ for (unsigned int plane = 0; plane < doc->nplanes; plane ++)
+ {
for (y = doc->bitmapoffset[1];
y < doc->bitmapoffset[1] + doc->outheader.cupsHeight; y ++)
{
i --;
}
}
- } else if (input_color_mode == 2) {
+ }
+ else if (input_color_mode == 2)
+ {
i = overspray_duplicate_after_pixels;
while (dst < buf + inlinesize - 2)
{
return (ret);
}
-static int set_color_profile(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 */
+ if (doc->outheader.cupsBitsPerColor != 8 &&
+ doc->outheader.cupsBitsPerColor != 16)
+ {
+ // color Profile is not supported
return (0);
}
- /* set output color profile */
- switch (doc->outheader.cupsColorSpace) {
- case CUPS_CSPACE_CIELab:
- case CUPS_CSPACE_ICC1:
- case CUPS_CSPACE_ICC2:
- case CUPS_CSPACE_ICC3:
- case CUPS_CSPACE_ICC4:
- case CUPS_CSPACE_ICC5:
- case CUPS_CSPACE_ICC6:
- case CUPS_CSPACE_ICC7:
- case CUPS_CSPACE_ICC8:
- case CUPS_CSPACE_ICC9:
- case CUPS_CSPACE_ICCA:
- case CUPS_CSPACE_ICCB:
- case CUPS_CSPACE_ICCC:
- case CUPS_CSPACE_ICCD:
- case CUPS_CSPACE_ICCE:
- case CUPS_CSPACE_ICCF:
- if (doc->color_profile.colorProfile == NULL) {
- cmsCIExyY wp;
+
+ // set output color profile
+ switch (doc->outheader.cupsColorSpace)
+ {
+ case CUPS_CSPACE_CIELab:
+ case CUPS_CSPACE_ICC1:
+ case CUPS_CSPACE_ICC2:
+ case CUPS_CSPACE_ICC3:
+ case CUPS_CSPACE_ICC4:
+ case CUPS_CSPACE_ICC5:
+ case CUPS_CSPACE_ICC6:
+ case CUPS_CSPACE_ICC7:
+ case CUPS_CSPACE_ICC8:
+ case CUPS_CSPACE_ICC9:
+ case CUPS_CSPACE_ICCA:
+ case CUPS_CSPACE_ICCB:
+ case CUPS_CSPACE_ICCC:
+ case CUPS_CSPACE_ICCD:
+ case CUPS_CSPACE_ICCE:
+ case CUPS_CSPACE_ICCF:
+ if (doc->color_profile.colorProfile == NULL)
+ {
+ cmsCIExyY wp;
#ifdef USE_LCMS1
- cmsWhitePointFromTemp(6504,&wp); /* D65 White point */
+ cmsWhitePointFromTemp(6504, &wp); // D65 White point
#else
- cmsWhitePointFromTemp(&wp,6504); /* D65 White point */
+ cmsWhitePointFromTemp(&wp, 6504); // D65 White point
#endif
- doc->color_profile.colorProfile = cmsCreateLab4Profile(&wp);
- }
- break;
- case CUPS_CSPACE_CIEXYZ:
- if (doc->color_profile.colorProfile == NULL) {
- /* transform color space via CIELab */
- cmsCIExyY wp;
+ doc->color_profile.colorProfile = cmsCreateLab4Profile(&wp);
+ }
+ break;
+ case CUPS_CSPACE_CIEXYZ:
+ if (doc->color_profile.colorProfile == NULL)
+ {
+ // transform color space via CIELab
+ cmsCIExyY wp;
#ifdef USE_LCMS1
- cmsWhitePointFromTemp(6504,&wp); /* D65 White point */
+ cmsWhitePointFromTemp(6504, &wp); // D65 White point
#else
- cmsWhitePointFromTemp(&wp,6504); /* D65 White point */
+ cmsWhitePointFromTemp(&wp, 6504); // D65 White point
#endif
- cmsxyY2XYZ(&(doc->color_profile.D65WhitePoint),&wp);
- doc->color_profile.colorProfile = cmsCreateLab4Profile(&wp);
- }
- break;
- case CUPS_CSPACE_SRGB:
- doc->color_profile.colorProfile = cmsCreate_sRGBProfile();
- break;
- case CUPS_CSPACE_ADOBERGB:
- doc->color_profile.colorProfile = adobergb_profile();
- break;
- case CUPS_CSPACE_SW:
- doc->color_profile.colorProfile = sgray_profile();
- break;
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_K:
- case CUPS_CSPACE_W:
- case CUPS_CSPACE_WHITE:
- case CUPS_CSPACE_GOLD:
- case CUPS_CSPACE_SILVER:
- /* We can set specified profile to output profile */
- doc->color_profile.outputColorProfile = doc->color_profile.colorProfile ;
- break;
- case CUPS_CSPACE_CMYK:
- case CUPS_CSPACE_KCMY:
- case CUPS_CSPACE_KCMYcm:
- case CUPS_CSPACE_YMCK:
- case CUPS_CSPACE_RGBA:
- case CUPS_CSPACE_RGBW:
- case CUPS_CSPACE_GMCK:
- case CUPS_CSPACE_GMCS:
- case CUPS_CSPACE_CMY:
- case CUPS_CSPACE_YMC:
- /* use standard RGB */
- doc->color_profile.outputColorProfile = NULL;
- break;
- default:
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPWGToRaster: Specified ColorSpace is not supported");
- return (1);
+ cmsxyY2XYZ(&(doc->color_profile.D65WhitePoint),&wp);
+ doc->color_profile.colorProfile = cmsCreateLab4Profile(&wp);
+ }
+ break;
+ case CUPS_CSPACE_SRGB:
+ doc->color_profile.colorProfile = cmsCreate_sRGBProfile();
+ break;
+ case CUPS_CSPACE_ADOBERGB:
+ doc->color_profile.colorProfile = adobergb_profile();
+ break;
+ case CUPS_CSPACE_SW:
+ doc->color_profile.colorProfile = sgray_profile();
+ break;
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_K:
+ case CUPS_CSPACE_W:
+ case CUPS_CSPACE_WHITE:
+ case CUPS_CSPACE_GOLD:
+ case CUPS_CSPACE_SILVER:
+ // We can set specified profile to output profile
+ doc->color_profile.outputColorProfile =
+ doc->color_profile.colorProfile;
+ break;
+ case CUPS_CSPACE_CMYK:
+ case CUPS_CSPACE_KCMY:
+ case CUPS_CSPACE_KCMYcm:
+ case CUPS_CSPACE_YMCK:
+ case CUPS_CSPACE_RGBA:
+ case CUPS_CSPACE_RGBW:
+ case CUPS_CSPACE_GMCK:
+ case CUPS_CSPACE_GMCS:
+ case CUPS_CSPACE_CMY:
+ case CUPS_CSPACE_YMC:
+ // use standard RGB
+ doc->color_profile.outputColorProfile = NULL;
+ break;
+ default:
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterPWGToRaster: Specified ColorSpace is not supported");
+ return (1);
}
return (0);
}
-int cfFilterPWGToRaster(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? (unused) */
- cf_filter_data_t *data,/* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters (unused)*/
+
+int
+cfFilterPWGToRaster(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ // (unused)
+ cf_filter_data_t *data,// I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
+ // (unused)
{
- cf_filter_out_format_t outformat;
- pwgtoraster_doc_t doc;
- int i;
- const char *val;
- cups_raster_t *inras = NULL,
- *outras = NULL;
- cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
- conversion_function_t convert;
+ cf_filter_out_format_t outformat;
+ pwgtoraster_doc_t doc;
+ int i;
+ const char *val;
+ cups_raster_t *inras = NULL,
+ *outras = NULL;
+ conversion_function_t convert;
+ cf_logfunc_t log = data->logfunc;
+ void *ld = data->logdata;
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
- void *icd = data->iscanceleddata;
- int ret = 0;
+ void *icd = data->iscanceleddata;
+ int ret = 0;
(void)inputseekable;
cmsSetLogErrorHandler(lcms_error_handler);
- /*
- * Open the input data stream specified by inputfd ...
- */
+ //
+ // Open the input data stream specified by inputfd ...
+ //
if ((inras = cupsRasterOpen(inputfd, CUPS_RASTER_READ)) == NULL)
{
return (1);
}
- /*
- * Prepare output document header
- */
+ //
+ // Prepare output document header
+ //
// Initialize data structure
memset(&doc, 0, sizeof(doc));
doc.outheader.MirrorPrint = CUPS_FALSE;
doc.outheader.Orientation = CUPS_ORIENT_0;
- if (doc.outheader.cupsBitsPerColor != 1
- && doc.outheader.cupsBitsPerColor != 2
- && doc.outheader.cupsBitsPerColor != 4
- && doc.outheader.cupsBitsPerColor != 8
- && doc.outheader.cupsBitsPerColor != 16) {
+ if (doc.outheader.cupsBitsPerColor != 1 &&
+ doc.outheader.cupsBitsPerColor != 2 &&
+ doc.outheader.cupsBitsPerColor != 4 &&
+ doc.outheader.cupsBitsPerColor != 8 &&
+ doc.outheader.cupsBitsPerColor != 16)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPWGToRaster: Specified color format is not supported.");
+ "cfFilterPWGToRaster: Specified color format is not supported.");
ret = 1;
goto out;
}
- if (doc.outheader.cupsColorOrder == CUPS_ORDER_PLANAR) {
+ if (doc.outheader.cupsColorOrder == CUPS_ORDER_PLANAR)
doc.nplanes = doc.outheader.cupsNumColors;
- } else {
+ else
doc.nplanes = 1;
- }
- if (doc.outheader.cupsColorOrder == CUPS_ORDER_BANDED) {
+ if (doc.outheader.cupsColorOrder == CUPS_ORDER_BANDED)
doc.nbands = doc.outheader.cupsNumColors;
- } else {
+ else
doc.nbands = 1;
- }
- /*
- * Check color space and set color profile
- */
-
- switch (doc.outheader.cupsColorSpace) {
- case CUPS_CSPACE_CIELab:
- case CUPS_CSPACE_ICC1:
- case CUPS_CSPACE_ICC2:
- case CUPS_CSPACE_ICC3:
- case CUPS_CSPACE_ICC4:
- case CUPS_CSPACE_ICC5:
- case CUPS_CSPACE_ICC6:
- case CUPS_CSPACE_ICC7:
- case CUPS_CSPACE_ICC8:
- case CUPS_CSPACE_ICC9:
- case CUPS_CSPACE_ICCA:
- case CUPS_CSPACE_ICCB:
- case CUPS_CSPACE_ICCC:
- case CUPS_CSPACE_ICCD:
- case CUPS_CSPACE_ICCE:
- case CUPS_CSPACE_ICCF:
- case CUPS_CSPACE_CIEXYZ:
- if (doc.outheader.cupsColorOrder != CUPS_ORDER_CHUNKED
- || (doc.outheader.cupsBitsPerColor != 8
- && doc.outheader.cupsBitsPerColor != 16)) {
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPWGToRaster: Specified color format is not supported.");
- ret = 1;
- goto out;
- }
- case CUPS_CSPACE_RGB:
- case CUPS_CSPACE_SRGB:
- case CUPS_CSPACE_ADOBERGB:
- case CUPS_CSPACE_CMY:
- case CUPS_CSPACE_YMC:
- case CUPS_CSPACE_CMYK:
- case CUPS_CSPACE_KCMY:
- case CUPS_CSPACE_KCMYcm:
- case CUPS_CSPACE_YMCK:
- case CUPS_CSPACE_RGBA:
- case CUPS_CSPACE_RGBW:
- case CUPS_CSPACE_GMCK:
- case CUPS_CSPACE_GMCS:
- doc.outputNumColors = 3;
- break;
- case CUPS_CSPACE_K:
- case CUPS_CSPACE_W:
- case CUPS_CSPACE_SW:
- case CUPS_CSPACE_WHITE:
- case CUPS_CSPACE_GOLD:
- case CUPS_CSPACE_SILVER:
- /* set paper color white */
- doc.outputNumColors = 1;
- break;
- default:
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPWGToRaster: Specified ColorSpace is not supported.");
- ret = 1;
- goto out;
+ //
+ // Check color space and set color profile
+ //
+
+ switch (doc.outheader.cupsColorSpace)
+ {
+ case CUPS_CSPACE_CIELab:
+ case CUPS_CSPACE_ICC1:
+ case CUPS_CSPACE_ICC2:
+ case CUPS_CSPACE_ICC3:
+ case CUPS_CSPACE_ICC4:
+ case CUPS_CSPACE_ICC5:
+ case CUPS_CSPACE_ICC6:
+ case CUPS_CSPACE_ICC7:
+ case CUPS_CSPACE_ICC8:
+ case CUPS_CSPACE_ICC9:
+ case CUPS_CSPACE_ICCA:
+ case CUPS_CSPACE_ICCB:
+ case CUPS_CSPACE_ICCC:
+ case CUPS_CSPACE_ICCD:
+ case CUPS_CSPACE_ICCE:
+ case CUPS_CSPACE_ICCF:
+ case CUPS_CSPACE_CIEXYZ:
+ if (doc.outheader.cupsColorOrder != CUPS_ORDER_CHUNKED ||
+ (doc.outheader.cupsBitsPerColor != 8 &&
+ doc.outheader.cupsBitsPerColor != 16))
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterPWGToRaster: Specified color format is not supported.");
+ ret = 1;
+ goto out;
+ }
+ case CUPS_CSPACE_RGB:
+ case CUPS_CSPACE_SRGB:
+ case CUPS_CSPACE_ADOBERGB:
+ case CUPS_CSPACE_CMY:
+ case CUPS_CSPACE_YMC:
+ case CUPS_CSPACE_CMYK:
+ case CUPS_CSPACE_KCMY:
+ case CUPS_CSPACE_KCMYcm:
+ case CUPS_CSPACE_YMCK:
+ case CUPS_CSPACE_RGBA:
+ case CUPS_CSPACE_RGBW:
+ case CUPS_CSPACE_GMCK:
+ case CUPS_CSPACE_GMCS:
+ doc.outputNumColors = 3;
+ break;
+ case CUPS_CSPACE_K:
+ case CUPS_CSPACE_W:
+ case CUPS_CSPACE_SW:
+ case CUPS_CSPACE_WHITE:
+ case CUPS_CSPACE_GOLD:
+ case CUPS_CSPACE_SILVER:
+ // set paper color white
+ doc.outputNumColors = 1;
+ break;
+ default:
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterPWGToRaster: Specified ColorSpace is not supported.");
+ ret = 1;
+ goto out;
}
- if (!(doc.color_profile.cm_disabled)) {
- if (set_color_profile(&doc, log, ld) == 1) {
+ if (!(doc.color_profile.cm_disabled))
+ {
+ if (set_color_profile(&doc, log, ld) == 1)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPWGToRaster: Cannot set color profile.");
ret = 1;
}
}
- /*
- * Open output raster stream
- */
+ //
+ // Open output raster stream
+ //
if ((outras = cupsRasterOpen(outputfd, (outformat ==
CF_FILTER_OUT_FORMAT_CUPS_RASTER ?
goto out;
}
- /*
- * Select conversion function
- */
+ //
+ // Select conversion function
+ //
memset(&convert, 0, sizeof(conversion_function_t));
if (select_convert_func(outras, &doc, &convert) == 1)
goto out;
}
- if (log) {
+ if (log)
+ {
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToRaster: Output page header");
if (doc.outheader.ImagingBoundingBox[3] > 0)
"cfFilterPWGToRaster: cupsHeight = %d", doc.outheader.cupsHeight);
if (doc.outheader.ImagingBoundingBox[3] > 0)
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsMediaType = %d", doc.outheader.cupsMediaType);
+ "cfFilterPWGToRaster: cupsMediaType = %d",
+ doc.outheader.cupsMediaType);
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPWGToRaster: cupsBitsPerColor = %d",
doc.outheader.cupsBitsPerColor);
"cfFilterPWGToRaster: cupsBytesPerLine = %d",
doc.outheader.cupsBytesPerLine);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsColorOrder = %d", doc.outheader.cupsColorOrder);
+ "cfFilterPWGToRaster: cupsColorOrder = %d",
+ doc.outheader.cupsColorOrder);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsColorSpace = %d", doc.outheader.cupsColorSpace);
+ "cfFilterPWGToRaster: cupsColorSpace = %d",
+ doc.outheader.cupsColorSpace);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsCompression = %d", doc.outheader.cupsCompression);
+ "cfFilterPWGToRaster: cupsCompression = %d",
+ doc.outheader.cupsCompression);
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterPWGToRaster: cupsPageSizeName = %s", doc.outheader.cupsPageSizeName);
+ "cfFilterPWGToRaster: cupsPageSizeName = %s",
+ doc.outheader.cupsPageSizeName);
}
- /*
- * Print the pages
- */
+ //
+ // Print the pages
+ //
i = 0;
while (out_page(&doc, i + 1, inras, outras, &convert))
out:
- /*
- * Close the streams
- */
+ //
+ // Close the streams
+ //
if (inras)
cupsRasterClose(inras);
cupsRasterClose(outras);
close(outputfd);
- /*
- * Clean up
- */
- if (doc.color_profile.colorProfile != NULL) {
+ //
+ // Clean up
+ //
+
+ if (doc.color_profile.colorProfile != NULL)
cmsCloseProfile(doc.color_profile.colorProfile);
- }
- if (doc.color_profile.outputColorProfile != NULL && doc.color_profile.outputColorProfile != doc.color_profile.colorProfile) {
+ if (doc.color_profile.outputColorProfile != NULL &&
+ doc.color_profile.outputColorProfile != doc.color_profile.colorProfile)
cmsCloseProfile(doc.color_profile.outputColorProfile);
- }
- if (doc.color_profile.colorTransform != NULL) {
+ if (doc.color_profile.colorTransform != NULL)
cmsDeleteTransform(doc.color_profile.colorTransform);
- }
return (ret);
}
-/*
- * Function to apply IPP options to a CUPS/PWG Raster header.
- *
- * Copyright 2013-2022 by Till Kamppeter.
- *
- * Distribution and use rights are outlined in the file "COPYING"
- * which should have been included with this file.
- *
- * Contents:
- *
- */
-
-
-/*
- * Include necessary headers.
- */
+//
+// Functions to handle CUPS/PWG Raster headers for libcupsfilters.
+//
+// Copyright 2013-2022 by Till Kamppeter.
+//
+// Distribution and use rights are outlined in the file "COPYING"
+// which should have been included with this file.
+//
+// Contents:
+//
+// cfRasterColorSpaceString() - Return strings for CUPS color spaces
+// cfGetBackSideOrientation() - Return backside orientation for duplex
+// printing
+// cfGetPrintRenderIntent() - Return rendering intent for a job
+// cfRasterPrepareHeader() - Prepare a Raster header for a job
+// cfRasterSetColorSpace() - Find best color space for print-color-mode
+// and print-quality setting
+// cfJoinJobOptionsAndAttrs() - Join job IPP attributes and job options in
+// one option list
+//
+
+//
+// Include necessary headers.
+//
#include <config.h>
#include <cups/cups.h>
#include <cupsfilters/ipp.h>
#include <cups/pwg.h>
-/*
- * Local functions
- */
+//
+// Local functions
+//
static int raster_base_header(cups_page_header2_t *h, cf_filter_data_t *data,
int pwg_raster);
-/*
- * '_strlcpy()' - Safely copy two strings.
- */
+//
+// '_strlcpy()' - Safely copy two strings.
+//
-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 */
+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
{
- size_t srclen; /* Length of source string */
+ size_t srclen; // Length of source string
- /*
- * Figure out how much room is needed...
- */
+ //
+ // Figure out how much room is needed...
+ //
size --;
srclen = strlen(src);
- /*
- * Copy the appropriate amount...
- */
+ //
+ // Copy the appropriate amount...
+ //
if (srclen > size)
srclen = size;
}
-/*
- * 'cfRasterColorSpaceString()' - Return the color space name for a
- * cupsColorSpace value.
- */
+//
+// 'cfRasterColorSpaceString()' - Return the color space name for a
+// cupsColorSpace value.
const char *
-cfRasterColorSpaceString(cups_cspace_t cspace) /* I - cupsColorSpace value */
+cfRasterColorSpaceString(cups_cspace_t cspace) // I - cupsColorSpace value
{
static const char * const cups_color_spaces[] =
- { /* Color spaces */
+ { // Color spaces
"W",
"RGB",
"RGBA",
}
-/*
- * 'cfGetBackSideOrientation()' - This functions returns the back
- * side orientation using printer
- * attributes. Meaning and reason for
- * backside orientation: It only
- * makes sense if printer supports
- * duplex, so, if printer reports that
- * it supports duplex printing via
- * sides-supported IPP attribute, then
- * it also reports back-side
- * orientation for each PDL in PDL
- * specific IPP attributes. Backside
- * orientation is specially needed for
- * raster PDLs as raster PDLs are
- * specially made for raster printers
- * which do not have sufficient memory
- * to hold a full page bitmap(raster
- * page). So they cannot build the
- * whole page in memory before
- * starting to print it. For one sided
- * printing it is easy to manage. The
- * printer's mechanism pulls the page
- * in on its upper edge and starts to
- * print, from top to bottom, after
- * that it ejects the page. For
- * double-sided printing it does the
- * same for the front side, but for
- * the back side the mechanics of the
- * printer has to turn over the sheet,
- * and now, depending on how the sheet
- * is turned over it happens that the
- * edge arriving in the printing
- * mechanism is the lower edge of the
- * back side. And if the printer
- * simply prints then, the back side
- * is the wrong way around. The
- * printer reports its need via back
- * side orientation in such a case, so
- * that the client knows to send the
- * back side upside down for example.
- * In vector PDL, PDF and PostScript,
- * always the full page's raster image
- * is completely generated in the
- * printer before the page is started,
- * and therefore the printer can start
- * to take the pixels from the lower
- * edge of the raster image if needed,
- * so back side orientation is always
- * "normal" for these PDLs. And if a
- * printer does not support duplex,
- * back side orientation is not
- * needed.
- */
-
-int /* O - Backside orientation (bit 0-2)
- Requires flipped margin?
- Yes: bit 4 set; No: bit 3 set */
-cfGetBackSideOrientation(cf_filter_data_t *data) /* I - Filter data */
+//
+// 'cfGetBackSideOrientation()' - This functions returns the back
+// side orientation using printer
+// attributes. Meaning and reason for
+// backside orientation: It only makes
+// sense if printer supports duplex,
+// so, if printer reports that it
+// supports duplex printing via
+// sides-supported IPP attribute, then
+// it also reports back-side
+// orientation for each PDL in PDL
+// specific IPP attributes. Backside
+// orientation is specially needed for
+// raster PDLs as raster PDLs are
+// specially made for raster printers
+// which do not have sufficient memory
+// to hold a full page bitmap(raster
+// page). So they cannot build the
+// whole page in memory before
+// starting to print it. For one sided
+// printing it is easy to manage. The
+// printer's mechanism pulls the page
+// in on its upper edge and starts to
+// print, from top to bottom, after
+// that it ejects the page. For
+// double-sided printing it does the
+// same for the front side, but for
+// the back side the mechanics of the
+// printer has to turn over the sheet,
+// and now, depending on how the sheet
+// is turned over it happens that the
+// edge arriving in the printing
+// mechanism is the lower edge of the
+// back side. And if the printer
+// simply prints then, the back side
+// is the wrong way around. The
+// printer reports its need via back
+// side orientation in such a case, so
+// that the client knows to send the
+// back side upside down for example.
+// In vector PDL, PDF and PostScript,
+// always the full page's raster image
+// is completely generated in the
+// printer before the page is started,
+// and therefore the printer can start
+// to take the pixels from the lower
+// edge of the raster image if needed,
+// so back side orientation is always
+// "normal" for these PDLs. And if a
+// printer does not support duplex,
+// back side orientation is not
+// needed.
+//
+
+int // O - Backside orientation (bit 0-2)
+ // Requires flipped margin?
+ // Yes: bit 4 set; No: bit 3 set
+cfGetBackSideOrientation(cf_filter_data_t *data) // I - Filter data
{
ipp_t *printer_attrs = data->printer_attrs;
int num_options = data->num_options;
cups_option_t *options = data->options;
char *final_content_type = data->final_content_type;
- ipp_attribute_t *ipp_attr = NULL; /* IPP attribute */
- int i, /* Looping variable */
+ ipp_attribute_t *ipp_attr = NULL; // IPP attribute
+ int i, // Looping variable
count;
const char *keyword;
- int backside = -1; /* backside obtained using printer attributes */
+ int backside = -1; // backside obtained using printer attributes
+
+
// also check options
if ((ipp_attr = ippFindAttribute(printer_attrs, "sides-supported",
- IPP_TAG_ZERO)) != NULL)
+ IPP_TAG_ZERO)) != NULL)
{
if (ippContainsString(ipp_attr, "two-sided-long-edge"))
{
{
for (i = 0, count = ippGetCount(ipp_attr); i < count; i ++)
{
- const char *dm = ippGetString(ipp_attr, i, NULL); /* DM value */
- if(!strcasecmp(dm, "DM1")){
+ const char *dm = ippGetString(ipp_attr, i, NULL); // DM value
+ if (!strcasecmp(dm, "DM1"))
+ {
backside = CF_BACKSIDE_NORMAL;
break;
}
- if(!strcasecmp(dm, "DM2")){
+ if (!strcasecmp(dm, "DM2"))
+ {
backside = CF_BACKSIDE_FLIPPED;
break;
}
- if(!strcasecmp(dm, "DM3")){
+ if (!strcasecmp(dm, "DM3"))
+ {
backside = CF_BACKSIDE_ROTATED;
break;
}
- if(!strcasecmp(dm, "DM4")){
+ if (!strcasecmp(dm, "DM4"))
+ {
backside = CF_BACKSIDE_MANUAL_TUMBLE;
break;
}
}
}
- return backside;
+ return (backside);
}
+
const char *
-cfGetPrintRenderIntent(cf_filter_data_t *data, char *ri, int ri_len)
+cfGetPrintRenderIntent(cf_filter_data_t *data,
+ char *ri,
+ int ri_len)
{
const char *val;
int num_options = 0;
else if (!strcasecmp(val, "perceptual"))
snprintf(ri, ri_len, "%s", "Perceptual");
else if (!strcasecmp(val, "relative"))
- snprintf(ri, ri_len, "%s", "Relative");
+ snprintf(ri, ri_len, "%s", "Relative");
else if (!strcasecmp(val, "relative-bpc") ||
!strcasecmp(val, "relativebpc"))
snprintf(ri, ri_len, "%s", "RelativeBpc");
else if (!strcasecmp(val, "saturation"))
- snprintf(ri, ri_len, "%s", "Saturation");
+ snprintf(ri, ri_len, "%s", "Saturation");
}
if ((ipp_attr = ippFindAttribute(printer_attrs,
const char *temp = ippGetString(ipp_attr, i, NULL);
if (!strcasecmp(temp, "auto")) autoRender = 1;
if (ri[0] != '\0')
- /* User has supplied a setting */
+ // User has supplied a setting
if (!strcasecmp(ri, temp))
break;
}
ri[0] = '\0';
}
if (ri[0] == '\0')
- { /* Either user has not supplied any setting
- or user supplied value is not supported by printer */
+ { // Either user has not supplied any setting
+ // or user supplied value is not supported by printer
if ((ipp_attr = ippFindAttribute(printer_attrs,
"print-rendering-intent-default",
IPP_TAG_ZERO)) != NULL)
return (ri);
}
-/*
- * 'cfRasterPrepareHeader() - This function creates a CUPS/PWG Raster
- * header for Raster output based on the
- * printer and job properties supplied to
- * the calling filter functions, printer
- * properties via printer IPP attributes
- * and job properties via CUPS option list
- * and job IPP attributesor optionally a
- * sample header. For PWG and Apple Raster
- * output the color space and depth is
- * auto-selected based on available options
- * listed in the urf-supported and
- * pwg-raster-document-type-supported
- * printer IPP attributes and the settings
- * of print-color-mode ("ColorModel") and
- * print-quality ("cupsPrintQuality") job
- * attributes/options.
- */
-
-int /* O - 0 on success,
- -1 on error */
-cfRasterPrepareHeader(cups_page_header2_t *h, /* I - Raster header */
- cf_filter_data_t *data, /* I - Job and printer data */
+
+//
+// 'cfRasterPrepareHeader() - This function creates a CUPS/PWG Raster
+// header for Raster output based on the
+// printer and job properties supplied to
+// the calling filter functions, printer
+// properties via printer IPP attributes
+// and job properties via CUPS option list
+// and job IPP attributesor optionally a
+// sample header. For PWG and Apple Raster
+// output the color space and depth is
+// auto-selected based on available options
+// listed in the urf-supported and
+// pwg-raster-document-type-supported
+// printer IPP attributes and the settings
+// of print-color-mode ("ColorModel") and
+// print-quality ("cupsPrintQuality") job
+// attributes/options.
+//
+
+int // O - 0 on success,
+ // -1 on error
+cfRasterPrepareHeader(cups_page_header2_t *h, // I - Raster header
+ cf_filter_data_t *data, // I - Job and printer data
cf_filter_out_format_t final_outformat,
- /* I - Job output format
- (determines color space,
- and resolution) */
+ // I - Job output format
+ // (determines color space,
+ // and resolution)
cf_filter_out_format_t header_outformat,
- /* I - This filter's output
- format (determines
- header format) */
- int no_high_depth, /* I - Suppress use of
- > 8 bit per color */
- cups_cspace_t *cspace) /* IO - Color space we want to
- use, -1 for auto, we
- return color space
- actually used, -1 if
- no suitable color space
- found. */
+ // I - This filter's output
+ // format (determines
+ // header format)
+ int no_high_depth, // I - Suppress use of
+ // > 8 bit per color
+ cups_cspace_t *cspace) // IO - Color space we want to
+ // use, -1 for auto, we
+ // return color space
+ // actually used, -1 if
+ // no suitable color space
+ // found.
{
int i;
ipp_t *printer_attrs, *job_attrs;
int num_options = 0;
cups_option_t *options = NULL;
cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
+ void *ld = data->logdata;
int pwgraster = 0,
appleraster = 0,
cupsraster = 0,
p = cupsGetOption("MediaClass", num_options, options);
if (p != NULL)
{
- if (strcasestr(p, "pwg")) {
+ if (strcasestr(p, "pwg"))
+ {
pwgraster = 1;
cupsraster = 0;
if (log)
log(ld, CF_LOGLEVEL_DEBUG,
"PWG Raster output requested (via \"MediaClass\"/\"media-class\" option)");
- } else
+ }
+ else
pwgraster = 0;
}
}
printer_attrs = data->printer_attrs;
job_attrs = data->job_attrs;
- /* These values will be used in case we don't find supported resolutions
- for given output format */
+ // These values will be used in case we don't find supported resolutions
+ // for given output format
if ((attr = ippFindAttribute(printer_attrs, "printer-resolution-default",
IPP_TAG_RESOLUTION)) != NULL)
{
else
yres = xres;
}
- /* Finding supported resolution for given output format */
+ // Finding supported resolution for given output format
if (pwgraster)
{
if ((attr = ippFindAttribute(printer_attrs,
}
}
- if (log) {
+ if (log)
+ {
if (*cspace == -1)
log(ld, CF_LOGLEVEL_DEBUG,
"Color space requested: Default");
}
if (data->header)
- *h = *(data->header); /* Copy sample header */
+ *h = *(data->header); // Copy sample header
else
raster_base_header(h, data, 1 - cupsrasterheader);
if (cfGetPageDimensions(data->printer_attrs, data->job_attrs,
(appleraster &&
(attr = ippFindAttribute(printer_attrs,
"urf-supported",
- IPP_TAG_ZERO)) != NULL))) {
+ IPP_TAG_ZERO)) != NULL)))
+ {
ippAttributeString(attr, valuebuffer, sizeof(valuebuffer));
cspaces_available = valuebuffer;
if ((color_mode = cupsGetOption("print-color-mode", num_options,
hi_depth = (!no_high_depth && quality &&
(!strcasecmp(quality, "high") || !strcmp(quality, "5"))) ?
1 : 0;
- if (log) {
+ if (log)
+ {
log(ld, CF_LOGLEVEL_DEBUG,
"Color mode requested: %s; color depth requested: %s",
color_mode, hi_depth ? "High" : "Standard");
}
else if (pclm)
{
- /* Available color spaces are always SRGB 8 and SGray 8 */
+ // Available color spaces are always SRGB 8 and SGray 8
cspaces_available = "srgb_8,sgray_8";
if ((color_mode = cupsGetOption("print-color-mode", num_options,
options)) == NULL)
cspace, &hi_depth);
}
- if (res != 1) {
- /* cfRasterSetColorSpace() was called */
- if (res < 0) {
- /* failed */
- if (log) {
+ if (res != 1)
+ {
+ // cfRasterSetColorSpace() was called
+ if (res < 0)
+ {
+ // failed
+ if (log)
+ {
log(ld, CF_LOGLEVEL_ERROR,
"Unable to set color space/depth for Raster output!");
if (*cspace < 0)
*cspace);
}
return (-1);
- } else
- /* succeeded */
+ }
+ else
+ // succeeded
if (log)
log(ld, CF_LOGLEVEL_DEBUG,
"Using color space #%d with %s color depth",
*cspace, hi_depth ? "high" : "standard");
}
- if ((h->HWResolution[0] == 100) && (h->HWResolution[1] == 100)) {
- /* No resolution set in header */
+ if ((h->HWResolution[0] == 100) && (h->HWResolution[1] == 100))
+ {
+ // No resolution set in header
if (xres != -1)
{
h->HWResolution[0] = xres;
h->cupsHeight = h->HWResolution[1] * h->PageSize[1] / 72;
}
- /* Make all page geometry fields in the header consistent */
- if (cupsrasterheader) {
+ // Make all page geometry fields in the header consistent
+ if (cupsrasterheader)
+ {
h->cupsWidth = ((dimensions[0] - margins[0] - margins[2]) /
72.0 * h->HWResolution[0]) + 0.5;
h->cupsHeight = ((dimensions[1] - margins[1] - margins[3]) /
72.0 * h->HWResolution[1]) + 0.5;
- } else {
+ }
+ else
+ {
h->cupsWidth = (dimensions[0] /
72.0 * h->HWResolution[0]) + 0.5;
h->cupsHeight = (dimensions[1] /
72.0 * h->HWResolution[1]) + 0.5;
}
- for (i = 0; i < 2; i ++) {
+ for (i = 0; i < 2; i ++)
+ {
h->cupsPageSize[i] = dimensions[i];
h->PageSize[i] = (unsigned int)(h->cupsPageSize[i] + 0.5);
if (cupsrasterheader)
else
h->Margins[i] = 0;
}
- if (cupsrasterheader) {
+ if (cupsrasterheader)
+ {
h->cupsImagingBBox[0] = margins[0];
h->cupsImagingBBox[1] = margins[1];
h->cupsImagingBBox[2] = dimensions[0] - margins[2];
for (i = 0; i < 4; i ++)
h->ImagingBoundingBox[i] =
(unsigned int)(h->cupsImagingBBox[i] + 0.5);
- } else
- for (i = 0; i < 4; i ++) {
+ }
+ else
+ for (i = 0; i < 4; i ++)
+ {
h->cupsImagingBBox[i] = 0.0;
h->ImagingBoundingBox[i] = 0;
}
if (h->cupsColorOrder == CUPS_ORDER_BANDED)
h->cupsBytesPerLine *= h->cupsNumColors;
- /* Mark header as PWG Raster if it is not CUPS Raster */
+ // Mark header as PWG Raster if it is not CUPS Raster
if (!cupsrasterheader)
strcpy(h->MediaClass, "PwgRaster");
}
-/*
- * 'cfRasterSetColorSpace() - Update a given CUPS/PWG Raster header to
- * the desired color mode, color space, and
- * color depth. We supply one of the printer
- * IPP attributes urf-supported or
- * pwg-raster-document-type-supported as they
- * contain a list of all valid combos of
- * color space and color depth supported by
- * the printer, tell the print-color-mode
- * attribute setting for this job and request
- * a color space and optionally high color
- * depth. Then it is checked first whether the
- * requested color space is available and if
- * not we fall back to the base color space
- * (usually sGray or sRGB). Then knowing the
- * color space we will use, we check whether in
- * this color space more than one color depth is
- * supported, we chooce the lowest, and if
- * high color depth is requested, the highest.
- */
-
-int /* O - 0 on success,
- -1 on error */
-cfRasterSetColorSpace(cups_page_header2_t *h, /* I - Raster header */
- const char *available, /* I - Available color spaces
- IPP attribute
- urf-supported or
- pwg-raster-document-type-supported */
- const char *color_mode, /* I - print-color-mode IPP
- attribute setting */
- cups_cspace_t *cspace, /* IO - Color space we want to
- use, -1 for auto, we
- return color space
- actually used, -1 if
- no suitable color space
- found. */
- int *high_depth) /* IO - Do we want to print in
- high color depth? We
- reset to 0 if high
- quality not supported
- in the color space
- used. */
+//
+// 'cfRasterSetColorSpace() - Update a given CUPS/PWG Raster header to
+// the desired color mode, color space, and
+// color depth. We supply one of the
+// printer IPP attributes urf-supported or
+// pwg-raster-document-type-supported as
+// they contain a list of all valid combos
+// of color space and color depth supported
+// by the printer, tell the
+// print-color-mode attribute setting for
+// this job and request a color space and
+// optionally high color depth. Then it is
+// checked first whether the requested
+// color space is available and if not we
+// fall back to the base color space
+// (usually sGray or sRGB). Then knowing
+// the color space we will use, we check
+// whether in this color space more than
+// one color depth is supported, we chooce
+// the lowest, and if high color depth is
+// requested, the highest.
+//
+
+int // O - 0 on success,
+ // -1 on error
+cfRasterSetColorSpace(cups_page_header2_t *h, // I - Raster header
+ const char *available, // I - Available color spaces
+ // from IPP attribute
+ // urf-supported or
+ // pwg-raster-document-type-supported
+ const char *color_mode, // I - print-color-mode IPP
+ // attribute setting
+ cups_cspace_t *cspace, // IO - Color space we want to
+ // use, -1 for auto, we
+ // return color space
+ // actually used, -1 if
+ // no suitable color space
+ // found.
+ int *high_depth) // IO - Do we want to print in
+ // high color depth? We
+ // reset to 0 if high
+ // quality not supported
+ // in the color space
+ // used.
{
int min_depth = 999;
int max_depth = 0;
int best_depth = -1;
int num_colors;
- int cspace_fallback = 0; /* 0: originally requested color space
- 1: sRGB for color, sGray for mono
- 2: sRGB for mono */
+ int cspace_fallback = 0; // 0: originally requested color space
+ // 1: sRGB for color, sGray for mono
+ // 2: sRGB for mono
const char *p, *q;
- /* Range-check */
+ // Range-check
if (!h || !available || !cspace)
- return -1;
+ return (-1);
if (*cspace != -1 && *cspace != CUPS_CSPACE_SW &&
*cspace != CUPS_CSPACE_SRGB && *cspace != CUPS_CSPACE_ADOBERGB &&
*cspace != CUPS_CSPACE_RGB && *cspace != CUPS_CSPACE_CMYK)
return (-1);
- /* True Bi-Level only available in PWG Raster.
- List of properties in pwg-raster-document-type-supported IPP attribute
- is lower-case-only whereas urf-supported for Apple Raster is upper-case-
- only */
+ // True Bi-Level only available in PWG Raster.
+ // List of properties in pwg-raster-document-type-supported IPP attribute
+ // is lower-case-only whereas urf-supported for Apple Raster is upper-case-
+ // only
if (islower(available[0]) &&
(p = strstr(available, "black_1")) != NULL &&
!isdigit(*(p + 7)) &&
(!strcmp(color_mode, "bi-level") ||
- !strcmp(color_mode, "process-bi-level"))) {
- /* Set parameters for bi-level, there is only one color space and color
- depth */
+ !strcmp(color_mode, "process-bi-level")))
+ {
+ // Set parameters for bi-level, there is only one color space and color
+ // depth
*cspace = CUPS_CSPACE_K;
best_depth = 1;
num_colors = 1;
- /* No high color depth in bi-level */
+ // No high color depth in bi-level
if (high_depth)
*high_depth = 0;
- } else {
- /* Any other color space */
- for (;;) { /* Loop through fallbacks to default if requested color space
- not supported */
- if (*cspace != -1) { /* Skip if no color space specified */
- for (p = available; p; p = q) {
+ }
+ else
+ {
+ // Any other color space
+ for (;;)
+ { // Loop through fallbacks to default if requested color space
+ // not supported
+ if (*cspace != -1)
+ { // Skip if no color space specified
+ for (p = available; p; p = q)
+ {
int n, dmin, dmax;
- /* Check whether requested color space is supported */
+ // Check whether requested color space is supported
if ((*cspace == CUPS_CSPACE_SW &&
(((q = strchr(p, 'W')) != NULL &&
(q == available || *(q - 1) == ',') &&
(q == available || *(q - 1) == ',') &&
(q += 5) &&
isdigit(*q))) &&
- (num_colors = 4))) {
- /* Color space supported, check color depth values */
+ (num_colors = 4)))
+ {
+ // Color space supported, check color depth values
n = sscanf(q, "%d-%d", &dmin, &dmax);
if (isupper(available[0]))
- /* urf-supported specifies bits per pixel, we need bits per
- color */
+ // urf-supported specifies bits per pixel, we need bits per
+ // color
dmin = dmin / num_colors;
if (dmin < min_depth)
min_depth = dmin;
- if (n == 2) {
+ if (n == 2)
+ {
if (isupper(available[0]))
- /* urf-supported specifies bits per pixel, we need bits per
- color */
+ // urf-supported specifies bits per pixel, we need bits per
+ // color
dmax = dmax / num_colors;
if (dmax > max_depth)
max_depth = dmax;
- } else {
+ }
+ else
+ {
if (dmin > max_depth)
max_depth = dmin;
}
- /* Select depth depending on whether we want to have high or
- standard color depth */
+ // Select depth depending on whether we want to have high or
+ // standard color depth
if (high_depth && *high_depth)
best_depth = max_depth;
else
best_depth = min_depth;
- } else
- /* Advance to the next color space entry */
+ }
+ else
+ // Advance to the next color space entry
if (q && *q != '\0')
q ++;
}
- if (best_depth > 0) {
- /* The requested color space is supported, so quit the fallback
- loop */
+ if (best_depth > 0)
+ {
+ // The requested color space is supported, so quit the fallback
+ // loop
if (high_depth && *high_depth && min_depth == max_depth)
- /* We requested high color depth but our color space is only
- supported with a single color depth, reset request to tell
- that we did not find a higher color depth */
+ // We requested high color depth but our color space is only
+ // supported with a single color depth, reset request to tell
+ // that we did not find a higher color depth
*high_depth = 0;
break;
}
}
- /* Arrived here, the requested color depth is not supported, try next
- fallback level */
+ // Arrived here, the requested color depth is not supported, try next
+ // fallback level
cspace_fallback ++;
- if (cspace_fallback > 2) {
- /* Gone through all fallbacks and still no suitable color space?
- Quit finally */
+ if (cspace_fallback > 2)
+ {
+ // Gone through all fallbacks and still no suitable color space?
+ // Quit finally
*cspace = -1;
return (-1);
}
- /* Fallback 1: Suitable color space for the requested color mode
- Fallback 2: Color always (if printer does not advertise mono mode or
- sRGB if DeviceRGB is requested but only sRGB available)
- AdobeRGB instead of sRGB only if available in 16 bit per color and
- high color depth is requested */
+ // Fallback 1: Suitable color space for the requested color mode
+ // Fallback 2: Color always (if printer does not advertise mono mode or
+ // sRGB if DeviceRGB is requested but only sRGB available)
+ // AdobeRGB instead of sRGB only if available in 16 bit per color and
+ // high color depth is requested
if ((cspace_fallback == 1 &&
(!strcasecmp(color_mode, "auto") ||
strcasestr(color_mode, "color") ||
strcasestr(color_mode, "rgb") ||
strcasestr(color_mode, "cmy"))) ||
- cspace_fallback == 2) {
+ cspace_fallback == 2)
+ {
if (strcasestr(color_mode, "adobe") ||
(high_depth && *high_depth &&
(strstr(available, "ADOBERGB24-48") ||
*cspace = CUPS_CSPACE_SRGB;
else
*cspace = CUPS_CSPACE_RGB;
- } else {
+ }
+ else
+ {
if (!strcasestr(color_mode, "device"))
*cspace = CUPS_CSPACE_SW;
else
}
}
- /* Success, update the raster header */
+ // Success, update the raster header
h->cupsBitsPerColor = best_depth;
h->cupsBitsPerPixel = best_depth * num_colors;
h->cupsColorSpace = *cspace;
}
-static int /* O - -1 on error, 0 on success */
-raster_base_header(cups_page_header2_t *h, /* O - Raster header */
- cf_filter_data_t *data, /* I - Filter data */
- int pwg_raster) /* I - 1 if PWG/Apple Raster */
+static int // O - -1 on error, 0 on success
+raster_base_header(cups_page_header2_t *h, // O - Raster header
+ cf_filter_data_t *data, // I - Filter data
+ int pwg_raster) // I - 1 if PWG/Apple Raster
{
- int i; /* Looping var */
- char *ptr, /* Pointer into string */
- s[255]; /* Temporary string */
- const char *val, /* Pointer into value */
- *media; /* media option */
- char *media_source, /* Media source */
- *media_type; /* Media type */
- pwg_media_t *size_found; /* page size found for given name */
- int num_options = 0; /* Number of options */
- cups_option_t *options = NULL; /* Options */
+ int i; // Looping var
+ char *ptr, // Pointer into string
+ s[255]; // Temporary string
+ const char *val, // Pointer into value
+ *media; // media option
+ char *media_source, // Media source
+ *media_type; // Media type
+ pwg_media_t *size_found; // page size found for given name
+ int num_options = 0; // Number of options
+ cups_option_t *options = NULL; // Options
ipp_attribute_t *attr;
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (!h)
return (-1);
- /*
- * Join the IPP attributes and the CUPS options in a single list
- */
+ //
+ // Join the IPP attributes and the CUPS options in a single list
+ //
num_options = cfJoinJobOptionsAndAttrs(data, num_options, &options);
- /*
- * Check if the supplied "media" option is a comma-separated list of any
- * combination of page size ("media"), media source ("media-position"),
- * and media type ("media-type") and if so, extract media type and source.
- * Media size will be handled separately.
- */
+ //
+ // Check if the supplied "media" option is a comma-separated list of any
+ // combination of page size ("media"), media source ("media-position"),
+ // and media type ("media-type") and if so, extract media type and source.
+ // Media size will be handled separately.
+ //
media_source = NULL;
media_type = NULL;
if ((media = cupsGetOption("media", num_options, options)) != NULL)
{
- /*
- * Loop through the option string, separating it at commas and setting each
- * individual option.
- *
- * For PageSize, we also check for an empty option value since some versions
- * of MacOS X use it to specify auto-selection of the media based solely on
- * the size.
- */
+ //
+ // Loop through the option string, separating it at commas and setting each
+ // individual option.
+ //
+ // For PageSize, we also check for an empty option value since some versions
+ // of MacOS X use it to specify auto-selection of the media based solely on
+ // the size.
+ //
for (val = media; *val;)
{
- /*
- * Extract the sub-option from the string...
- */
+ //
+ // Extract the sub-option from the string...
+ //
for (ptr = s; *val && *val != ',' && (ptr - s) < (sizeof(s) - 1);)
*ptr++ = *val++;
if (*val == ',')
val ++;
- /*
- * Identify it...
- */
+ //
+ // Identify it...
+ //
size_found = NULL;
if ((size_found = pwgMediaForPWG(s)) == NULL)
}
}
- /*
- * Initialize header
- */
+ //
+ // Initialize header
+ //
memset(h, 0, sizeof(cups_page_header2_t));
- /*
- * Fill in the items using printer and job IPP attributes and options
- */
+ //
+ // Fill in the items using printer and job IPP attributes and options
+ //
if (pwg_raster)
strcpy(h->MediaClass, "PwgRaster");
if (pwg_raster)
{
- /* Set "reserved" fields to 0 */
+ // Set "reserved" fields to 0
h->AdvanceDistance = 0;
h->AdvanceMedia = CUPS_ADVANCE_NONE;
h->Collate = CUPS_FALSE;
}
else
{
- /* TODO - Support for advance distance and advance media */
+ // TODO - Support for advance distance and advance media
h->AdvanceDistance = 0;
h->AdvanceMedia = CUPS_ADVANCE_NONE;
if ((val = cupsGetOption("Collate", num_options, options)) != NULL ||
options)) != NULL ||
(val = cupsGetOption("Resolution", num_options, options)) != NULL)
{
- int xres, /* X resolution */
- yres; /* Y resolution */
- char *ptr; /* Pointer into value */
+ int xres, // X resolution
+ yres; // Y resolution
+ char *ptr; // Pointer into value
xres = yres = strtol(val, (char **)&ptr, 10);
if (ptr > val && xres > 0)
}
else
{
- h->HWResolution[0] = 100; /* Resolution invalid */
+ h->HWResolution[0] = 100; // Resolution invalid
h->HWResolution[1] = 100;
}
}
else
{
- h->HWResolution[0] = 100; /* Resolution invalid */
+ h->HWResolution[0] = 100; // Resolution invalid
h->HWResolution[1] = 100;
}
}
}
- /* TODO - Support for insert sheets */
+ // TODO - Support for insert sheets
h->InsertSheet = CUPS_FALSE;
- /* TODO - Support for jog */
+ // TODO - Support for jog
h->Jog = CUPS_JOG_NONE;
if ((val = cupsGetOption("feed-orientation", num_options,
else
h->LeadingEdge = CUPS_EDGE_TOP;
- /* TODO - Support for manual feed */
+ // TODO - Support for manual feed
h->ManualFeed = CUPS_FALSE;
if ((val = cupsGetOption("media-position", num_options, options)) != NULL ||
h->MediaPosition = 49;
}
else
- h->MediaPosition = 0; /* Auto */
+ h->MediaPosition = 0; // Auto
if ((val = cupsGetOption("media-weight", num_options, options)) != NULL ||
(val = cupsGetOption("MediaWeight", num_options, options)) != NULL ||
if (pwg_raster)
{
- /* Set "reserved" fields to 0 */
+ // Set "reserved" fields to 0
h->MirrorPrint = CUPS_FALSE;
h->NegativePrint = CUPS_FALSE;
}
h->NumCopies = i;
}
else
- h->NumCopies = 1; /* 0 = Printer default */
+ h->NumCopies = 1; // 0 = Printer default
if ((val = cupsGetOption("orientation-requested", num_options,
options)) != NULL ||
if (pwg_raster)
{
- /* Set "reserved" fields to 0 */
+ // Set "reserved" fields to 0
h->OutputFaceUp = CUPS_FALSE;
}
else
if (pwg_raster)
{
- /* Set "reserved" fields to 0 */
+ // Set "reserved" fields to 0
h->Separations = CUPS_FALSE;
h->TraySwitch = CUPS_FALSE;
}
h->Tumble = CUPS_TRUE;
}
- /* TODO - Support for MediaType number */
+ // TODO - Support for MediaType number
h->cupsMediaType = 0;
- /* Only for CUPS Raster, if we do not have a sample header from a PPD file */
+ // Only for CUPS Raster, if we do not have a sample header from a PPD file
if (pwg_raster == 0 &&
((val = cupsGetOption("pwg-raster-document-type", num_options,
options)) != NULL ||
data->job_attrs,
"print-color-mode")) != NULL))
{
- int bitspercolor, /* Bits per color */
- bitsperpixel, /* Bits per pixel */
- colorspace, /* CUPS/PWG raster color space */
- numcolors; /* Number of colorants */
- const char *ptr; /* Pointer into value */
+ int bitspercolor, // Bits per color
+ bitsperpixel, // Bits per pixel
+ colorspace, // CUPS/PWG raster color space
+ numcolors; // Number of colorants
+ const char *ptr; // Pointer into value
ptr = NULL;
numcolors = 0;
}
else if (!strcasecmp(val, "auto"))
{
- /* Let "auto" not look like an error */
+ // Let "auto" not look like an error
colorspace = 19;
numcolors = 3;
}
if (ptr)
bitspercolor = strtol(ptr, (char **)&ptr, 10);
bitsperpixel = bitspercolor * numcolors;
- /* In 1-bit-per-color RGB modes we add a forth bit to each pixel
- to align the pixels with bytes */
+ // In 1-bit-per-color RGB modes we add a forth bit to each pixel
+ // to align the pixels with bytes
if (bitsperpixel == 3 &&
strcasestr(val, "Rgb"))
bitsperpixel = 4;
h->cupsNumColors = 3;
}
- /* TODO - Support for color orders 1 (banded) and 2 (planar) */
+ // TODO - Support for color orders 1 (banded) and 2 (planar)
h->cupsColorOrder = 0;
- /* TODO - Support for these parameters */
+ // TODO - Support for these parameters
h->cupsCompression = 0;
h->cupsRowCount = 0;
h->cupsRowFeed = 0;
h->cupsRowStep = 0;
- /* TODO - Support for cupsBorderlessScalingFactor */
+ // TODO - Support for cupsBorderlessScalingFactor
h->cupsBorderlessScalingFactor = 0.0;
- /* TODO - Support for custom values in CUPS Raster mode */
+ // TODO - Support for custom values in CUPS Raster mode
for (i = 0; i < 16; i ++)
{
h->cupsInteger[i] = 0;
h->cupsInteger[0] = impressions;
}
- /* Printer property, command line options only for development and
- debugging */
+ // Printer property, command line options only for development and
+ // debugging
if ((val = cupsGetOption("pwg-raster-document-sheet-back", num_options,
options)) != NULL ||
(val = cupsGetOption("back-side-orientation", num_options,
else // pwg-raster-document-sheet-back/pclm-raster-back-side
val = ippGetString(attr, 0, NULL);
}
- /* Set CrossFeedTransform and FeedTransform */
+ // Set CrossFeedTransform and FeedTransform
if (h->Duplex == CUPS_FALSE)
{
h->cupsInteger[1] = 1;
h->cupsInteger[2] = 1;
}
- /* TODO - Support for ImageBoxLeft, ImageBoxTop, ImageBoxRight, and
- ImageBoxBottom (h->cupsInteger[3..6]), leave on 0 for now */
+ // TODO - Support for ImageBoxLeft, ImageBoxTop, ImageBoxRight, and
+ // ImageBoxBottom (h->cupsInteger[3..6]), leave on 0 for now
if ((val = cupsGetOption("alternate-primary", num_options,
options)) != NULL ||
(val = cupsGetOption("AlternatePrimary", num_options,
options)) != NULL)
{
- int alternateprimary = atoi(val); /* SRGB value for black
- pixels */
+ int alternateprimary = atoi(val); // SRGB value for black
+ // pixels
h->cupsInteger[7] = alternateprimary;
}
(val = cupsGetOption("PrintQuality", num_options, options)) != NULL ||
(val = cupsGetOption("Quality", num_options, options)) != NULL)
{
- int quality = atoi(val); /* print-quality value */
+ int quality = atoi(val); // print-quality value
if (!quality ||
(quality >= IPP_QUALITY_DRAFT && quality <= IPP_QUALITY_HIGH))
h->cupsInteger[8] = quality;
}
- /* Leave "reserved" fields (h->cupsInteger[9..13]) on 0 */
+ // Leave "reserved" fields (h->cupsInteger[9..13]) on 0
if ((val = cupsGetOption("vendor-identifier", num_options,
options)) != NULL ||
(val = cupsGetOption("VendorIdentifier", num_options,
options)) != NULL)
{
- int vendorid = atoi(val); /* USB ID of manufacturer */
+ int vendorid = atoi(val); // USB ID of manufacturer
h->cupsInteger[14] = vendorid;
}
(val = cupsGetOption("VendorLength", num_options,
options)) != NULL)
{
- int vendorlength = atoi(val); /* How many bytes of vendor
- data? */
+ int vendorlength = atoi(val); // How many bytes of vendor
+ // data?
if (vendorlength > 0 && vendorlength <= 1088)
{
h->cupsInteger[15] = vendorlength;
options)) != NULL ||
(val = cupsGetOption("VendorData", num_options,
options)) != NULL)
- /* TODO - How to enter binary data here? */
+ // TODO - How to enter binary data here?
_strlcpy((char *)&(h->cupsReal[0]), val, 1088);
}
}
}
- /* Set "reserved" fields to 0 */
+ // Set "reserved" fields to 0
memset(h->cupsMarkerType, 0, 64);
if ((val = cupsGetOption("print-rendering-intent", num_options,
}
-/* Function for storing job-attrs in options */
-int cfJoinJobOptionsAndAttrs(cf_filter_data_t* data, int num_options, cups_option_t **options)
+//
+// 'cfJoinJobOptionsAndAttrs()' - Function for storing job IPP attribute in
+// option list, together with the options
+//
+
+int // O - New number of options
+ // in new option list
+cfJoinJobOptionsAndAttrs(cf_filter_data_t* data, // I - Filter data
+ int num_options, // I - Current mumber of
+ // options in new option
+ // list
+ cups_option_t **options) // IO - New option lsit
{
- ipp_t *job_attrs = data->job_attrs; /* Job attributes */
- ipp_attribute_t *ipp_attr; /* IPP attribute */
- int i = 0; /* Looping variable*/
- char buf[2048]; /* Buffer for storing value of ipp attr */
+ ipp_t *job_attrs = data->job_attrs; // Job attributes
+ ipp_attribute_t *ipp_attr; // IPP attribute
+ int i = 0; // Looping variable
+ char buf[2048]; // Buffer for storing value of ipp attr
cups_option_t *opt;
- for(i = 0, opt=data->options; i<data->num_options; i++, opt++){
+ for (i = 0, opt = data->options; i < data->num_options; i ++, opt ++)
num_options = cupsAddOption(opt->name, opt->value, num_options, options);
- }
- for(ipp_attr = ippFirstAttribute(job_attrs); ipp_attr; ipp_attr = ippNextAttribute(job_attrs)){
+ for (ipp_attr = ippFirstAttribute(job_attrs); ipp_attr;
+ ipp_attr = ippNextAttribute(job_attrs))
+ {
ippAttributeString(ipp_attr, buf, sizeof(buf));
- num_options = cupsAddOption(ippGetName(ipp_attr), buf, num_options, options);
+ num_options = cupsAddOption(ippGetName(ipp_attr), buf,
+ num_options, options);
}
- return num_options;
+ return (num_options);
}
-
-/*
- * End
- */
-/*
- * CUPS/PWG Raster utilities header file for cups-filters.
- *
- * Copyright 2013 by Till Kamppeter.
- *
- * Distribution and use rights are outlined in the file "COPYING"
- * which should have been included with this file.
- */
+//
+// Functions to handle CUPS/PWG Raster headers for libcupsfilters.
+//
+// Copyright 2013 by Till Kamppeter.
+//
+// Distribution and use rights are outlined in the file "COPYING"
+// which should have been included with this file.
+
#ifndef _CUPS_FILTERS_RASTER_H_
# define _CUPS_FILTERS_RASTER_H_
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
-/*
- * Include necessary headers...
- */
+//
+// Include necessary headers...
+//
# include "filter.h"
# include <stdio.h>
# else
# include <unistd.h>
# include <fcntl.h>
-# endif /* WIN32 || __EMX__ */
+# endif // WIN32 || __EMX__
# include <cups/cups.h>
# include <cups/raster.h>
-/*
- * Types
- */
+
+//
+// Types
+//
typedef enum cf_backside_orient_e
{
} cf_backside_orient_t;
-/*
- * Prototypes...
- */
+//
+// Prototypes...
+//
extern const char * cfRasterColorSpaceString(cups_cspace_t cspace);
extern int cfRasterPrepareHeader(cups_page_header2_t *h,
final_outformat,
cf_filter_out_format_t
header_outformat,
- int no_hig_depth,
+ int no_high_depth,
cups_cspace_t *cspace);
extern int cfRasterSetColorSpace(cups_page_header2_t *h,
const char *available,
# ifdef __cplusplus
}
-# endif /* __cplusplus */
-
-#endif /* !_CUPS_FILTERS_RASTER_H_ */
+# endif // __cplusplus
-/*
- * End
- */
+#endif // !_CUPS_FILTERS_RASTER_H_
-/*
- * CUPS raster to PWG raster format filter for CUPS.
- *
- * Copyright © 2011, 2014-2017 Apple Inc.
- *
- * Licensed under Apache License v2.0. See the file "LICENSE" for more
- * information.
- */
-
-/*
- * Include necessary headers...
- */
+//
+// CUPS raster to PWG raster format filter for libcupsfilters.
+//
+// Copyright © 2011, 2014-2017 Apple Inc.
+//
+// Licensed under Apache License v2.0. See the file "LICENSE" for more
+// information.
+
+
+//
+// Include necessary headers...
+
#include "filter.h"
#include "raster.h"
#include <string.h>
-/*
- * 'cfFilterRasterToPWG()' - Filter function to convert CUPS Raster
- * into PWG or Apple Raster
- */
-
-int /* O - Exit status */
-cfFilterRasterToPWG(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? (unused) */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters (unused) */
-{ /* I - Command-line arguments */
- cups_raster_t *inras; /* Input raster stream */
- cups_raster_t *outras; /* Output raster stream */
- cups_page_header2_t inheader, /* Input raster page header */
- outheader; /* Output raster page header */
- unsigned y; /* Current line */
- unsigned char *line; /* Line buffer */
- unsigned page = 0, /* Current page */
- page_width, /* Actual page width */
- page_height, /* Actual page height */
- page_top, /* Top margin */
- page_bottom, /* Bottom margin */
- page_left, /* Left margin */
- page_right, /* Right margin */
- linesize, /* Bytes per line */
- lineoffset; /* Offset into line */
+//
+// 'cfFilterRasterToPWG()' - Filter function to convert CUPS Raster
+// into PWG or Apple Raster
+
+int // O - Exit status
+cfFilterRasterToPWG(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ // (unused)
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
+ // (unused)
+{
+ cups_raster_t *inras; // Input raster stream
+ cups_raster_t *outras; // Output raster stream
+ cups_page_header2_t inheader, // Input raster page header
+ outheader; // Output raster page header
+ unsigned y; // Current line
+ unsigned char *line; // Line buffer
+ unsigned page = 0, // Current page
+ page_width, // Actual page width
+ page_height, // Actual page height
+ page_top, // Top margin
+ page_bottom, // Bottom margin
+ page_left, // Left margin
+ page_right, // Right margin
+ linesize, // Bytes per line
+ lineoffset; // Offset into line
int tmp;
- unsigned char white; /* White pixel */
- int back; /* Back side orientation */
+ unsigned char white; // White pixel
+ int back; // Back side orientation
char buf[64];
int width,
height,
right,
bottom,
top;
- int num_options = 0;/* Number of options */
- cups_option_t *options = NULL;/* Options */
- const char *val; /* Option value */
+ int num_options = 0;// Number of options
+ cups_option_t *options = NULL;// Options
+ const char *val; // Option value
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
- void *icd = data->iscanceleddata;
- cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
- int res = 0;
+ void *icd = data->iscanceleddata;
+ cf_logfunc_t log = data->logfunc;
+ void *ld = data->logdata;
+ int res = 0;
val = data->final_content_type;
- if (val) {
+ if (val)
+ {
if (strcasestr(val, "pwg") || strcasestr(val, "pclm"))
outras = cupsRasterOpen(outputfd, CUPS_RASTER_WRITE_PWG);
else if (strcasestr(val, "urf"))
{
if (iscanceled && iscanceled(icd))
{
- /* Canceled */
+ // Canceled
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterRasterToPWG: Job canceled on input page %d", page + 1);
}
- /*
- * Show page device dictionary...
- */
+ //
+ // Show page device dictionary...
+ //
+
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterRasterToPWG: Duplex = %d", inheader.Duplex);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterRasterToPWG: ManualFeed = %d", inheader.ManualFeed);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterRasterToPWG: MediaPosition = %d", inheader.MediaPosition);
+ "cfFilterRasterToPWG: MediaPosition = %d",
+ inheader.MediaPosition);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterRasterToPWG: NumCopies = %d", inheader.NumCopies);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterRasterToPWG: cupsHeight = %d", inheader.cupsHeight);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterRasterToPWG: cupsMediaType = %d", inheader.cupsMediaType);
+ "cfFilterRasterToPWG: cupsMediaType = %d",
+ inheader.cupsMediaType);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterRasterToPWG: cupsBitsPerColor = %d",
inheader.cupsBitsPerColor);
"cfFilterRasterToPWG: cupsBytesPerLine = %d",
inheader.cupsBytesPerLine);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterRasterToPWG: cupsColorOrder = %d", inheader.cupsColorOrder);
+ "cfFilterRasterToPWG: cupsColorOrder = %d",
+ inheader.cupsColorOrder);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterRasterToPWG: cupsColorSpace = %d", inheader.cupsColorSpace);
+ "cfFilterRasterToPWG: cupsColorSpace = %d",
+ inheader.cupsColorSpace);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterRasterToPWG: cupsCompression = %d", inheader.cupsCompression);
+ "cfFilterRasterToPWG: cupsCompression = %d",
+ inheader.cupsCompression);
- /*
- * Compute the real raster size...
- */
+ //
+ // Compute the real raster size...
+ //
page ++;
page_bottom = (unsigned)(inheader.cupsImagingBBox[1] *
inheader.HWResolution[1] / 72.0);
tmp = (int)(page_height - page_bottom - inheader.cupsHeight);
- if (tmp < 0 && tmp >= -1) /* Rounding error */
+ if (tmp < 0 && tmp >= -1) // Rounding error
page_top = 0;
else
page_top = (unsigned)tmp;
tmp = (int)(page_width - page_left - inheader.cupsWidth);
- if (tmp < 0 && tmp >= -1) /* Rounding error */
+ if (tmp < 0 && tmp >= -1) // Rounding error
page_right = 0;
else
page_right = (unsigned)tmp;
linesize = (page_width * inheader.cupsBitsPerPixel + 7) / 8;
- lineoffset = page_left * inheader.cupsBitsPerPixel / 8; /* Round down */
+ lineoffset = page_left * inheader.cupsBitsPerPixel / 8; // Round down
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterRasterToPWG: In pixels: Width: %u Height: %u Left: %u Right: %u Top: %u Bottom: %u",
outheader.cupsHeight = page_height;
outheader.cupsBytesPerLine = linesize;
- outheader.cupsInteger[14] = 0; /* VendorIdentifier */
- outheader.cupsInteger[15] = 0; /* VendorLength */
+ outheader.cupsInteger[14] = 0; // VendorIdentifier
+ outheader.cupsInteger[15] = 0; // VendorLength
if ((val = cupsGetOption("print-content-optimize", num_options,
options)) != NULL)
if ((val = cupsGetOption("print-quality",
num_options, options)) != NULL)
{
- unsigned quality = (unsigned)atoi(val); /* print-quality value */
+ unsigned quality = (unsigned)atoi(val); // print-quality value
if (quality >= IPP_QUALITY_DRAFT && quality <= IPP_QUALITY_HIGH)
outheader.cupsInteger[8] = quality;
}
}
- /* Update rendering intent with user settings or the default */
+ // Update rendering intent with user settings or the default
outheader.cupsRenderingIntent[0] = '\0';
cfGetPrintRenderIntent(data, outheader.cupsRenderingIntent,
sizeof(outheader.cupsRenderingIntent));
- /* First try to use the input page size name for the output page,
- check whether this size is supported by theprinter */
+ // First try to use the input page size name for the output page,
+ // check whether this size is supported by theprinter
buf[0] = '\0';
if (inheader.cupsPageSizeName[0])
{
- /* Take only a page size name for a page size the printer actually
- supports */
+ // Take only a page size name for a page size the printer actually
+ // supports
snprintf(buf, sizeof(buf), "%.63s", inheader.cupsPageSizeName);
cfGenerateSizes(data->printer_attrs, CF_GEN_SIZES_SEARCH, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
"%.63s", buf);
else
{
- /* No name found, find the printer's page size by the size dimensions
- and margins */
+ // No name found, find the printer's page size by the size dimensions
+ // and margins
width = (int)(2540.0 * inheader.cupsPageSize[0] / 72.0);
height = (int)(2540.0 * inheader.cupsPageSize[1] / 72.0);
left = (int)(2540.0 * inheader.ImagingBoundingBox[0] / 72.0);
{
if (inheader.Tumble)
{
- outheader.cupsInteger[1] = ~0U;/* CrossFeedTransform */
- outheader.cupsInteger[2] = 1; /* FeedTransform */
+ outheader.cupsInteger[1] = ~0U;// CrossFeedTransform
+ outheader.cupsInteger[2] = 1; // FeedTransform
outheader.cupsInteger[3] = page_right;
- /* ImageBoxLeft */
+ // ImageBoxLeft
outheader.cupsInteger[4] = page_top;
- /* ImageBoxTop */
+ // ImageBoxTop
outheader.cupsInteger[5] = page_width - page_left;
- /* ImageBoxRight */
+ // ImageBoxRight
outheader.cupsInteger[6] = page_height - page_bottom;
- /* ImageBoxBottom */
+ // ImageBoxBottom
}
else
{
- outheader.cupsInteger[1] = 1; /* CrossFeedTransform */
- outheader.cupsInteger[2] = ~0U;/* FeedTransform */
+ outheader.cupsInteger[1] = 1; // CrossFeedTransform
+ outheader.cupsInteger[2] = ~0U;// FeedTransform
outheader.cupsInteger[3] = page_left;
- /* ImageBoxLeft */
+ // ImageBoxLeft
outheader.cupsInteger[4] = page_bottom;
- /* ImageBoxTop */
+ // ImageBoxTop
outheader.cupsInteger[5] = page_left + inheader.cupsWidth;
- /* ImageBoxRight */
+ // ImageBoxRight
outheader.cupsInteger[6] = page_height - page_top;
- /* ImageBoxBottom */
+ // ImageBoxBottom
}
}
else if (back == CF_BACKSIDE_MANUAL_TUMBLE)
{
if (inheader.Tumble)
{
- outheader.cupsInteger[1] = ~0U;/* CrossFeedTransform */
- outheader.cupsInteger[2] = ~0U;/* FeedTransform */
+ outheader.cupsInteger[1] = ~0U;// CrossFeedTransform
+ outheader.cupsInteger[2] = ~0U;// FeedTransform
outheader.cupsInteger[3] = page_width - page_left -
inheader.cupsWidth;
- /* ImageBoxLeft */
+ // ImageBoxLeft
outheader.cupsInteger[4] = page_bottom;
- /* ImageBoxTop */
+ // ImageBoxTop
outheader.cupsInteger[5] = page_width - page_left;
- /* ImageBoxRight */
+ // ImageBoxRight
outheader.cupsInteger[6] = page_height - page_top;
- /* ImageBoxBottom */
+ // ImageBoxBottom
}
else
{
- outheader.cupsInteger[1] = 1; /* CrossFeedTransform */
- outheader.cupsInteger[2] = 1; /* FeedTransform */
+ outheader.cupsInteger[1] = 1; // CrossFeedTransform
+ outheader.cupsInteger[2] = 1; // FeedTransform
outheader.cupsInteger[3] = page_left;
- /* ImageBoxLeft */
+ // ImageBoxLeft
outheader.cupsInteger[4] = page_top;
- /* ImageBoxTop */
+ // ImageBoxTop
outheader.cupsInteger[5] = page_left + inheader.cupsWidth;
- /* ImageBoxRight */
+ // ImageBoxRight
outheader.cupsInteger[6] = page_height - page_bottom;
- /* ImageBoxBottom */
+ // ImageBoxBottom
}
}
else if (back == CF_BACKSIDE_ROTATED)
{
if (inheader.Tumble)
{
- outheader.cupsInteger[1] = ~0U;/* CrossFeedTransform */
- outheader.cupsInteger[2] = ~0U;/* FeedTransform */
+ outheader.cupsInteger[1] = ~0U;// CrossFeedTransform
+ outheader.cupsInteger[2] = ~0U;// FeedTransform
outheader.cupsInteger[3] = page_right;
- /* ImageBoxLeft */
+ // ImageBoxLeft
outheader.cupsInteger[4] = page_bottom;
- /* ImageBoxTop */
+ // ImageBoxTop
outheader.cupsInteger[5] = page_width - page_left;
- /* ImageBoxRight */
+ // ImageBoxRight
outheader.cupsInteger[6] = page_height - page_top;
- /* ImageBoxBottom */
+ // ImageBoxBottom
}
else
{
- outheader.cupsInteger[1] = 1; /* CrossFeedTransform */
- outheader.cupsInteger[2] = 1; /* FeedTransform */
+ outheader.cupsInteger[1] = 1; // CrossFeedTransform
+ outheader.cupsInteger[2] = 1; // FeedTransform
outheader.cupsInteger[3] = page_left;
- /* ImageBoxLeft */
+ // ImageBoxLeft
outheader.cupsInteger[4] = page_top;
- /* ImageBoxTop */
+ // ImageBoxTop
outheader.cupsInteger[5] = page_left + inheader.cupsWidth;
- /* ImageBoxRight */
+ // ImageBoxRight
outheader.cupsInteger[6] = page_height - page_bottom;
- /* ImageBoxBottom */
+ // ImageBoxBottom
}
}
else
{
- /*
- * Unsupported value...
- */
+ //
+ // Unsupported value...
+ //
if (log) log(ld,CF_LOGLEVEL_DEBUG,
"cfFilterRasterToPWG: Unsupported back side orientation value.");
- outheader.cupsInteger[1] = 1; /* CrossFeedTransform */
- outheader.cupsInteger[2] = 1; /* FeedTransform */
+ outheader.cupsInteger[1] = 1; // CrossFeedTransform
+ outheader.cupsInteger[2] = 1; // FeedTransform
outheader.cupsInteger[3] = page_left;
- /* ImageBoxLeft */
+ // ImageBoxLeft
outheader.cupsInteger[4] = page_top;
- /* ImageBoxTop */
+ // ImageBoxTop
outheader.cupsInteger[5] = page_left + inheader.cupsWidth;
- /* ImageBoxRight */
+ // ImageBoxRight
outheader.cupsInteger[6] = page_height - page_bottom;
- /* ImageBoxBottom */
+ // ImageBoxBottom
}
}
else
outheader.Duplex = inheader.Duplex;
outheader.Tumble = inheader.Tumble;
- outheader.cupsInteger[1] = 1; /* CrossFeedTransform */
- outheader.cupsInteger[2] = 1; /* FeedTransform */
+ outheader.cupsInteger[1] = 1; // CrossFeedTransform
+ outheader.cupsInteger[2] = 1; // FeedTransform
outheader.cupsInteger[3] = page_left;
- /* ImageBoxLeft */
+ // ImageBoxLeft
outheader.cupsInteger[4] = page_top;
- /* ImageBoxTop */
+ // ImageBoxTop
outheader.cupsInteger[5] = page_left + inheader.cupsWidth;
- /* ImageBoxRight */
+ // ImageBoxRight
outheader.cupsInteger[6] = page_height - page_bottom;
- /* ImageBoxBottom */
+ // ImageBoxBottom
}
if (!cupsRasterWriteHeader2(outras, &outheader))
goto fail;
}
- /*
- * Copy raster data...
- */
+ //
+ // Copy raster data...
+ //
if (linesize < inheader.cupsBytesPerLine)
linesize = inheader.cupsBytesPerLine;
-/*
- * RGB color separation code for CUPS.
- *
- * Copyright 2007 by Apple Inc.
- * Copyright 1993-2005 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * 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:
- *
- * cfRGBDelete() - Delete a color separation.
- * cfRGBDoGray() - Do a grayscale separation...
- * cfRGBDoRGB() - Do a RGB separation...
- * cfRGBNew() - Create a new RGB color separation.
- */
-
-/*
- * Include necessary headers.
- */
+//
+// RGB color separation code for libcupsfilters.
+//
+// Copyright 2007 by Apple Inc.
+// Copyright 1993-2005 by Easy Software Products.
+//
+// These coded instructions, statements, and computer programs are the
+// 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:
+//
+// cfRGBDelete() - Delete a color separation.
+// cfRGBDoGray() - Do a grayscale separation...
+// cfRGBDoRGB() - Do a RGB separation...
+// cfRGBNew() - Create a new RGB color separation.
+//
+
+//
+// Include necessary headers.
+//
#include "driver.h"
-/*
- * 'cfRGBDelete()' - Delete a color separation.
- */
+//
+// 'cfRGBDelete()' - Delete a color separation.
+//
void
-cfRGBDelete(cf_rgb_t *rgbptr) /* I - Color separation */
+cfRGBDelete(cf_rgb_t *rgbptr) // I - Color separation
{
if (rgbptr == NULL)
return;
}
-/*
- * 'cfRGBDoGray()' - Do a grayscale separation...
- */
+//
+// 'cfRGBDoGray()' - Do a grayscale separation...
+//
void
-cfRGBDoGray(cf_rgb_t *rgbptr,
- /* I - Color separation */
- const unsigned char *input,
- /* I - Input grayscale pixels */
- unsigned char *output,
- /* O - Output Device-N pixels */
- int num_pixels)
- /* I - Number of pixels */
+cfRGBDoGray(cf_rgb_t *rgbptr,// I - Color separation
+ const unsigned char *input, // I - Input grayscale pixels
+ unsigned char *output,// O - Output Device-N pixels
+ int num_pixels)
+ // I - Number of pixels
{
- int i; /* Looping var */
- int lastgray; /* Previous grayscale */
- int xs, ys, zs, /* Current RGB row offsets */
- g, gi, gm0, gm1;/* Current gray index and multipliers ... */
- const unsigned char *color; /* Current color data */
- int tempg; /* Current separation color */
- int rgbsize; /* Separation data size */
+ int i; // Looping var
+ int lastgray; // Previous grayscale
+ int xs, ys, zs, // Current RGB row offsets
+ g, gi, gm0, gm1;// Current gray index and
+ // multipliers ...
+ const unsigned char *color; // Current color data
+ int tempg; // Current separation color
+ int rgbsize; // Separation data size
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (!rgbptr || !input || !output || num_pixels <= 0)
return;
- /*
- * Initialize variables used for the duration of the separation...
- */
+ //
+ // Initialize variables used for the duration of the separation...
+ //
lastgray = -1;
rgbsize = rgbptr->num_channels;
ys = rgbptr->cube_size * rgbptr->num_channels;
zs = rgbptr->num_channels;
- /*
- * Loop through it all...
- */
+ //
+ // Loop through it all...
+ //
while (num_pixels > 0)
{
- /*
- * See if the next pixel is a cached value...
- */
+ //
+ // See if the next pixel is a cached value...
+ //
num_pixels --;
if (g == lastgray)
{
- /*
- * Copy previous color and continue...
- */
+ //
+ // Copy previous color and continue...
+ //
memcpy(output, output - rgbptr->num_channels, rgbsize);
}
else if (g == 0x00 && rgbptr->cache_init)
{
- /*
- * Copy black color and continue...
- */
+ //
+ // Copy black color and continue...
+ //
memcpy(output, rgbptr->black, rgbsize);
}
else if (g == 0xff && rgbptr->cache_init)
{
- /*
- * Copy white color and continue...
- */
+ //
+ // Copy white color and continue...
+ //
memcpy(output, rgbptr->white, rgbsize);
continue;
}
- /*
- * Nope, figure this one out on our own...
- */
+ //
+ // Nope, figure this one out on our own...
+ //
gi = rgbptr->cube_index[g];
gm0 = rgbptr->cube_mult[g];
}
-/*
- * 'cfRGBDoRGB()' - Do a RGB separation...
- */
+//
+// 'cfRGBDoRGB()' - Do a RGB separation...
+//
void
-cfRGBDoRGB(cf_rgb_t *rgbptr,
- /* I - Color separation */
- const unsigned char *input,
- /* I - Input RGB pixels */
- unsigned char *output,
- /* O - Output Device-N pixels */
- int num_pixels)
- /* I - Number of pixels */
+cfRGBDoRGB(cf_rgb_t *rgbptr, // I - Color separation
+ const unsigned char *input, // I - Input RGB pixels
+ unsigned char *output, // O - Output Device-N pixels
+ int num_pixels)
+ // I - Number of pixels
{
- int i; /* Looping var */
- int rgb, /* Current RGB color */
- lastrgb; /* Previous RGB color */
+ int i; // Looping var
+ int rgb, // Current RGB color
+ lastrgb; // Previous RGB color
int r, ri, rm0, rm1, rs,
- /* Current red index, multipliexs, and row offset */
+ // Current red index, multipliexs,
+ // and row offset
g, gi, gm0, gm1, gs,
- /* Current green ... */
+ // Current green ...
b, bi, bm0, bm1, bs;
- /* Current blue ... */
- const unsigned char *color; /* Current color data */
- int tempr, /* Current separation colors */
- tempg, /* ... */
- tempb ; /* ... */
- int rgbsize; /* Separation data size */
+ // Current blue ...
+ const unsigned char *color; // Current color data
+ int tempr, // Current separation colors
+ tempg, // ...
+ tempb ; // ...
+ int rgbsize; // Separation data size
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (!rgbptr || !input || !output || num_pixels <= 0)
return;
- /*
- * Initialize variables used for the duration of the separation...
- */
+ //
+ // Initialize variables used for the duration of the separation...
+ //
lastrgb = -1;
rgbsize = rgbptr->num_channels;
gs = rgbptr->cube_size * rgbptr->num_channels;
bs = rgbptr->num_channels;
- /*
- * Loop through it all...
- */
+ //
+ // Loop through it all...
+ //
while (num_pixels > 0)
{
- /*
- * See if the next pixel is a cached value...
- */
+ //
+ // See if the next pixel is a cached value...
+ //
num_pixels --;
if (rgb == lastrgb)
{
- /*
- * Copy previous color and continue...
- */
+ //
+ // Copy previous color and continue...
+ //
memcpy(output, output - rgbptr->num_channels, rgbsize);
}
else if (rgb == 0x000000 && rgbptr->cache_init)
{
- /*
- * Copy black color and continue...
- */
+ //
+ // Copy black color and continue...
+ //
memcpy(output, rgbptr->black, rgbsize);
}
else if (rgb == 0xffffff && rgbptr->cache_init)
{
- /*
- * Copy white color and continue...
- */
+ //
+ // Copy white color and continue...
+ //
memcpy(output, rgbptr->white, rgbsize);
continue;
}
- /*
- * Nope, figure this one out on our own...
- */
+ //
+ // Nope, figure this one out on our own...
+ //
ri = rgbptr->cube_index[r];
rm0 = rgbptr->cube_mult[r];
}
-/*
- * 'cfRGBNew()' - Create a new RGB color separation.
- */
+//
+// 'cfRGBNew()' - Create a new RGB color separation.
+//
-cf_rgb_t * /* O - New color separation or NULL */
-cfRGBNew(int num_samples, /* I - Number of samples */
- cf_sample_t *samples, /* I - Samples */
- int cube_size, /* I - Size of LUT cube */
- int num_channels) /* I - Number of color components */
+cf_rgb_t * // O - New color separation or NULL
+cfRGBNew(int num_samples, // I - Number of samples
+ cf_sample_t *samples, // I - Samples
+ int cube_size, // I - Size of LUT cube
+ int num_channels) // I - Number of color components
{
- cf_rgb_t *rgbptr; /* New color separation */
- int i; /* Looping var */
- int r, g, b; /* Current RGB */
- int tempsize; /* Sibe of main arrays */
- unsigned char *tempc; /* Pointer for C arrays */
- unsigned char **tempb ; /* Pointer for Z arrays */
- unsigned char ***tempg; /* Pointer for Y arrays */
- unsigned char ****tempr; /* Pointer for X array */
- unsigned char rgb[3]; /* Temporary RGB value */
+ cf_rgb_t *rgbptr; // New color separation
+ int i; // Looping var
+ int r, g, b; // Current RGB
+ int tempsize; // Sibe of main arrays
+ unsigned char *tempc; // Pointer for C arrays
+ unsigned char **tempb ; // Pointer for Z arrays
+ unsigned char ***tempg; // Pointer for Y arrays
+ unsigned char ****tempr; // Pointer for X array
+ unsigned char rgb[3]; // Temporary RGB value
- /*
- * Range-check the input...
- */
+ //
+ // Range-check the input...
+ //
if (!samples || num_samples != (cube_size * cube_size * cube_size) ||
num_channels <= 0 || num_channels > CF_MAX_RGB)
return (NULL);
- /*
- * Allocate memory for the separation...
- */
+ //
+ // Allocate memory for the separation...
+ //
if ((rgbptr = calloc(1, sizeof(cf_rgb_t))) == NULL)
return (NULL);
- /*
- * Allocate memory for the samples and the LUT cube...
- */
+ //
+ // Allocate memory for the samples and the LUT cube...
+ //
- tempsize = cube_size * cube_size * cube_size; /* FUTURE: num_samples < cs^3 */
+ tempsize = cube_size * cube_size * cube_size; // FUTURE: num_samples < cs^3
tempc = calloc(tempsize, num_channels);
tempb = calloc(tempsize, sizeof(unsigned char *));
return (NULL);
}
- /*
- * Fill in the arrays...
- */
+ //
+ // Fill in the arrays...
+ //
for (i = 0, r = 0; r < cube_size; r ++)
{
rgbptr->num_channels = num_channels;
rgbptr->colors = tempr;
- /*
- * Generate the lookup tables for the cube indices and multipliers...
- */
+ //
+ // Generate the lookup tables for the cube indices and multipliers...
+ //
for (i = 0; i < 256; i ++)
{
rgbptr->cube_mult[i] = 255 - ((i * (cube_size - 1)) & 255);
}
- /*
- * Generate the black and white cache values for the separation...
- */
+ //
+ // Generate the black and white cache values for the separation...
+ //
rgb[0] = 0;
rgb[1] = 0;
rgbptr->cache_init = 1;
- /*
- * Return the separation...
- */
+ //
+ // Return the separation...
+ //
return (rgbptr);
}
-
-/*
- * sRGB lookup tables for CUPS.
- *
- * Copyright 2007 by Apple Inc.
- * Copyright 1993-2005 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * 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.
- */
+//
+// sRGB lookup tables for libcupsfilters.
+//
+// Copyright 2007 by Apple Inc.
+// Copyright 1993-2005 by Easy Software Products.
+//
+// These coded instructions, statements, and computer programs are the
+// 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.
+//
-/*
- * Include necessary headers.
- */
+//
+// Include necessary headers.
+//
#include "driver.h"
-/*
- * sRGB gamma lookup table.
- */
+//
+// sRGB gamma lookup table.
+//
const unsigned char cf_srgb_lut[256] =
{
};
-/*
- * sRGB gamma lookup table (inverted output to map to CMYK...)
- */
+//
+// sRGB gamma lookup table (inverted output to map to CMYK...)
+//
const unsigned char cf_scmy_lut[256] =
{
7, 7, 6, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1,
0
};
-
-/*
- * Text to PDF filter function for the Common UNIX Printing System (CUPS).
- *
- * Copyright 2008,2012 by Tobias Hoffmann.
- * Copyright 2007 by Apple Inc.
- * Copyright 1993-2007 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * 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.
- */
-
-/*
- * Include necessary headers...
- */
+//
+// Text to PDF filter function for libcupsfilters.
+//
+// Copyright 2008,2012 by Tobias Hoffmann.
+// Copyright 2007 by Apple Inc.
+// Copyright 1993-2007 by Easy Software Products.
+//
+// These coded instructions, statements, and computer programs are the
+// 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.
+//
+
+//
+// Include necessary headers...
+//
#include "debug-internal.h"
#include <config.h>
#include "fontembed/sfnt.h"
#include "fontembed/fontfile.h"
-/*
- * Constants...
- */
+
+//
+// Constants...
+//
#define ATTR_NORMAL 0x00
#define ATTR_BOLD 0x01
#define PRETTY_PERL 4
#define PRETTY_HTML 5
-/*
- * Globals...
- */
-static char *code_keywords[] = /* List of known C/C++ keywords... */
+//
+// Globals...
+//
+
+static char *code_keywords[] = // List of known C/C++ keywords...
{
"and",
"and_eq",
"xor",
"xor_eq"
},
- *sh_keywords[] = /* List of known Boure/Korn/zsh/bash keywords... */
+ *sh_keywords[] = // List of known Boure/Korn/zsh/bash keywords...
{
"alias",
"bg",
"whence"
"while",
},
- *csh_keywords[] = /* List of known csh/tcsh keywords... */
+ *csh_keywords[] = // List of known csh/tcsh keywords...
{
"alias",
"aliases",
"which",
"while"
},
- *perl_keywords[] = /* List of known perl keywords... */
+ *perl_keywords[] = // List of known perl keywords...
{
"abs",
"accept",
"write"
};
-/*
- * Types...
- */
-typedef struct /**** Character/attribute structure... ****/
+//
+// Types...
+//
+
+typedef struct // **** Character/attribute structure... ****
{
- unsigned short ch, /* Character */
- attr; /* Any attributes */
+ unsigned short ch, // Character
+ attr; // Any attributes
} lchar_t;
typedef struct texttopdf_doc_s
{
- int NumFonts; /* Number of fonts to use */
- EMB_PARAMS *Fonts[256][4]; /* Fonts to use */
- unsigned short Chars[256]; /* Input char to unicode */
- unsigned char Codes[65536]; /* Unicode glyph mapping to font */
- int Widths[256]; /* Widths of each font */
- int Directions[256];/* Text directions for each font */
+ int NumFonts; // Number of fonts to use
+ EMB_PARAMS *Fonts[256][4]; // Fonts to use
+ unsigned short Chars[256]; // Input char to unicode
+ unsigned char Codes[65536]; // Unicode glyph mapping to font
+ int Widths[256]; // Widths of each font
+ int Directions[256];// Text directions for each font
cf_pdf_out_t *pdf;
- int FontResource; /* Object number of font resource dictionary */
- float FontScaleX, FontScaleY; /* The font matrix */
- lchar_t *Title, *Date; /* The title and date strings */
+ int FontResource; // Object number of font resource dictionary
+ float FontScaleX, FontScaleY; // The font matrix
+ lchar_t *Title, *Date; // The title and date strings
- cups_page_header2_t h; /* CUPS Raster page header, to */
- /* accommodate results of command */
- /* line/IPP attribute parsing */
+ cups_page_header2_t h; // CUPS Raster page header, to
+ // accommodate results of command
+ // line/IPP attribute parsing
cf_filter_texttopdf_parameter_t env_vars;
int NumKeywords;
- float PageLeft, /* Left margin */
- PageRight, /* Right margin */
- PageBottom, /* Bottom margin */
- PageTop, /* Top margin */
- PageWidth, /* Total page width */
+ float PageLeft, // Left margin
+ PageRight, // Right margin
+ PageBottom, // Bottom margin
+ PageTop, // Top margin
+ PageWidth, // Total page width
PageLength;
int NumPages;
- int WrapLines, /* Wrap text in lines */
- SizeLines, /* Number of lines on a page */
- SizeColumns, /* Number of columns on a line */
- PageColumns, /* Number of columns on a page */
- ColumnGutter, /* Number of characters between text columns */
- ColumnWidth, /* Width of each column */
- PrettyPrint, /* Do pretty code formatting? */
- Copies; /* Number of copies to produce */
- float CharsPerInch, /* Number of character columns per inch */
- LinesPerInch; /* Number of lines per inch */
+ int WrapLines, // Wrap text in lines
+ SizeLines, // Number of lines on a page
+ SizeColumns, // Number of columns on a line
+ PageColumns, // Number of columns on a page
+ ColumnGutter, // Number of characters between text columns
+ ColumnWidth, // Width of each column
+ PrettyPrint, // Do pretty code formatting?
+ Copies; // Number of copies to produce
+ float CharsPerInch, // Number of character columns per inch
+ LinesPerInch; // Number of lines per inch
int UTF8;
- char **Keywords; /* List of known keywords... */
+ char **Keywords; // List of known keywords...
- int Orientation, /* 0 = portrait, 1 = landscape, etc. */
- Duplex, /* Duplexed? */
- LanguageLevel, /* Language level of printer */
+ int Orientation, // 0 = portrait, 1 = landscape, etc.
+ Duplex, // Duplexed?
+ LanguageLevel, // Language level of printer
ColorDevice;
lchar_t **Page;
} texttopdf_doc_t;
-/*
- * Local functions...
- */
+//
+// Local functions...
+//
static EMB_PARAMS *font_load(const char *font, int fontwidth, cf_logfunc_t log,
void *ld);
static void write_epilogue(texttopdf_doc_t *doc);
-/*
- * 'cfFilterTextToPDF()' - Main entry for text to PDF filter.
- */
+//
+// 'cfFilterTextToPDF()' - Main entry for text to PDF filter.
+//
-int /* O - Exit status */
-cfFilterTextToPDF(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? (unused) */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters (unused) */
+int // O - Exit status
+cfFilterTextToPDF(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ // (unused)
+ cf_filter_data_t *data,
+ // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
+ // (unused)
{
texttopdf_doc_t doc;
- int i, /* Looping var */
- empty, /* Is the input empty? */
- ch, /* Current char from file */
- lastch, /* Previous char from file */
- attr, /* Current attribute */
- line, /* Current line */
- column, /* Current column */
- page_column; /* Current page column */
-
- const char *val; /* Option value */
- char keyword[64], /* Keyword string */
- *keyptr; /* Pointer into string */
- int keycol; /* Column where keyword starts */
- enum {NLstyl=-1, NoCmnt, SNTXstyl}
- cmntState; /* Inside a comment */
- enum {StrBeg=-1, NoStr, StrEnd}
- strState; /* Inside a dbl-quoted string */
-
- cf_logfunc_t log = data->logfunc;
+ int i, // Looping var
+ empty, // Is the input empty?
+ ch, // Current char from file
+ lastch, // Previous char from file
+ attr, // Current attribute
+ line, // Current line
+ column, // Current column
+ page_column; // Current page column
+
+ const char *val; // Option value
+ char keyword[64], // Keyword string
+ *keyptr; // Pointer into string
+ int keycol; // Column where keyword starts
+ enum {NLstyl = -1, NoCmnt, SNTXstyl}
+ cmntState; // Inside a comment
+ enum {StrBeg = -1, NoStr, StrEnd}
+ strState; // Inside a dbl-quoted string
+
+ cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
void *icd = data->iscanceleddata;
- FILE *fp; /* Print file */
- int stdoutbackupfd; /* The "real" stdout is backupped here while */
- /* stdout is redirected */
- int ret = 0; /* Return value */
+ FILE *fp; // Print file
+ int stdoutbackupfd; // The "real" stdout is backupped here while
+ // stdout is redirected
+ int ret = 0; // Return value
cups_cspace_t cspace = (cups_cspace_t)(-1);
- /*
- * Make sure status messages are not buffered...
- */
- #ifdef CUPS_1_4 /* CUPS 1.4.x or newer: only UTF8 is supported */
- doc.UTF8 = 1; /* Use UTF-8 encoding? */
- #endif /* CUPS_1_4 */
-
- doc.WrapLines = 1; /* Wrap text in lines */
- doc.SizeLines = 60; /* Number of lines on a page */
- doc.SizeColumns = 80; /* Number of columns on a line */
- doc.PageColumns = 1; /* Number of columns on a page */
- doc.ColumnGutter = 0; /* Number of characters between text columns */
- doc.ColumnWidth = 80; /* Width of each column */
- doc.PrettyPrint = 0; /* Do pretty code formatting */
- doc.Copies = 1; /* Number of copies */
- doc.Page = NULL; /* Page characters */
- doc.NumPages = 0; /* Number of pages in document */
- doc.CharsPerInch = 10; /* Number of character columns per inch */
- doc.LinesPerInch = 6; /* Number of lines per inch */
- doc.NumKeywords = 0; /* Number of known keywords */
- doc.Keywords = NULL; /* List of known keywords */
- doc.Orientation = 0; /* 0 = portrait, 1 = landscape, etc. */
- doc.Duplex = 0; /* Duplexed? */
- doc.LanguageLevel = 1; /* Language level of printer */
- doc.ColorDevice = 1; /* Do color text? */
- doc.PageLeft = 18.0f; /* Left margin */
- doc.PageRight = 594.0f; /* Right margin */
- doc.PageBottom = 36.0f; /* Bottom margin */
- doc.PageTop = 756.0f; /* Top margin */
- doc.PageWidth = 612.0f; /* Total page width */
- doc.PageLength = 792.0f; /* Total page length */
+ //
+ // Make sure status messages are not buffered...
+ //
+
+ doc.UTF8 = 1; // Use UTF-8 encoding?
+ doc.WrapLines = 1; // Wrap text in lines
+ doc.SizeLines = 60; // Number of lines on a page
+ doc.SizeColumns = 80; // Number of columns on a line
+ doc.PageColumns = 1; // Number of columns on a page
+ doc.ColumnGutter = 0; // Number of characters between text columns
+ doc.ColumnWidth = 80; // Width of each column
+ doc.PrettyPrint = 0; // Do pretty code formatting
+ doc.Copies = 1; // Number of copies
+ doc.Page = NULL; // Page characters
+ doc.NumPages = 0; // Number of pages in document
+ doc.CharsPerInch = 10; // Number of character columns per inch
+ doc.LinesPerInch = 6; // Number of lines per inch
+ doc.NumKeywords = 0; // Number of known keywords
+ doc.Keywords = NULL; // List of known keywords
+ doc.Orientation = 0; // 0 = portrait, 1 = landscape, etc.
+ doc.Duplex = 0; // Duplexed?
+ doc.LanguageLevel = 1; // Language level of printer
+ doc.ColorDevice = 1; // Do color text?
+ doc.PageLeft = 18.0f; // Left margin
+ doc.PageRight = 594.0f; // Right margin
+ doc.PageBottom = 36.0f; // Bottom margin
+ doc.PageTop = 756.0f; // Top margin
+ doc.PageWidth = 612.0f; // Total page width
+ doc.PageLength = 792.0f; // Total page length
doc.pdf = NULL;
- if (parameters) {
+ if (parameters)
doc.env_vars = *((cf_filter_texttopdf_parameter_t *)parameters);
- } else {
+ else
+ {
doc.env_vars.data_dir = CUPS_DATADIR;
doc.env_vars.char_set = NULL;
doc.env_vars.content_type = NULL;
setbuf(stderr, NULL);
- /*
- * Open the input data stream specified by the inputfd...
- */
+ //
+ // Open the input data stream specified by the inputfd...
+ //
if ((fp = fdopen(inputfd, "rb")) == NULL)
{
return (1);
}
- /*
- * Redirect stdout to the outputfd (the PDF output strem of this filter
- * function)
- */
+ //
+ // Redirect stdout to the outputfd (the PDF output strem of this filter
+ // function)
+ //
if (outputfd != 1)
{
close(outputfd);
}
- /*
- * Process command-line options and write the prolog...
- */
+ //
+ // Process command-line options and write the prolog...
+ //
if ((val = cupsGetOption("prettyprint",
data->num_options, data->options)) != NULL &&
(float)doc.h.ImagingBoundingBox[3];
doc.Copies = doc.h.NumCopies;
- /* Check whether we do borderless printing with overspray and let text only
- get printed on the actual media size */
+ // Check whether we do borderless printing with overspray and let text only
+ // get printed on the actual media size
if (doc.h.cupsPageSizeName[0] != '\0')
{
- /* The page size name in te header corresponds to the actual size of
- the media, so find the size dimensions */
+ // The page size name in te header corresponds to the actual size of
+ // the media, so find the size dimensions
pwg_media_t *size_found = NULL;
strncpy(keyword, doc.h.cupsPageSizeName, sizeof(keyword));
if ((keyptr = strchr(keyword, '.')) != NULL)
(size_found = pwgMediaForLegacy(keyword)) != NULL ||
(size_found = pwgMediaForPWG(keyword)) != NULL)
{
- /* Dimensions in PostScript points */
+ // Dimensions in PostScript points
float w = size_found->width / 2540.0 * 72.0;
float l = size_found->length / 2540.0 * 72.0;
if (w < doc.PageWidth)
{
- /* Width in header > actual media width => overspray */
- /* As the overspray is to cover tolerances in paper traction
- and the paper can be mis-aligned to any size, we let
- margins be at least double the overspray width on each
- side (not dividing by 2) */
+ // Width in header > actual media width => overspray
+ // As the overspray is to cover tolerances in paper traction
+ // and the paper can be mis-aligned to any size, we let
+ // margins be at least double the overspray width on each
+ // side (not dividing by 2)
float margin_needed = doc.PageWidth - w;
if (doc.PageLeft < margin_needed)
doc.PageLeft = margin_needed;
}
if (l < doc.PageLength)
{
- /* Length in header > actual media length => overspray */
- /* As the overspray is to cover tolerances in paper traction
- and the paper can be mis-aligned to any size, we let
- margins be at least double the overspray width on each
- side (not dividing by 2) */
+ // Length in header > actual media length => overspray
+ // As the overspray is to cover tolerances in paper traction
+ // and the paper can be mis-aligned to any size, we let
+ // margins be at least double the overspray width on each
+ // side (not dividing by 2)
float margin_needed = doc.PageLength - l;
if (doc.PageBottom < margin_needed)
doc.PageBottom = margin_needed;
if (doc.PrettyPrint)
doc.PageTop -= 216.0f / doc.LinesPerInch;
- /*
- * Allocate memory for the page...
- */
+ //
+ // Allocate memory for the page...
+ //
doc.SizeColumns = (doc.PageRight - doc.PageLeft) / 72.0 * doc.CharsPerInch;
doc.SizeLines = (doc.PageTop - doc.PageBottom) / 72.0 * doc.LinesPerInch;
- /*
- * Enforce minimum size...
- */
+ //
+ // Enforce minimum size...
+ //
+
if (doc.SizeColumns < 1)
doc.SizeColumns = 1;
if (doc.SizeLines < 1)
doc.Copies = data->copies;
- /*
- * Read text from the specified source and print it...
- */
+ //
+ // Read text from the specified source and print it...
+ //
empty = 1;
lastch = 0;
{
if (empty)
{
- /* Found the first valid character, write file header */
+ // Found the first valid character, write file header
empty = 0;
ret = write_prolog(data->job_title, data->job_user,
doc.env_vars.classification,
goto out;
}
- /*
- * Control codes:
- *
- * BS Backspace (0x08)
- * HT Horizontal tab; next 8th column (0x09)
- * LF Line feed; forward full line (0x0a)
- * VT Vertical tab; reverse full line (0x0b)
- * FF Form feed (0x0c)
- * CR Carriage return (0x0d)
- * ESC 7 Reverse full line (0x1b 0x37)
- * ESC 8 Reverse half line (0x1b 0x38)
- * ESC 9 Forward half line (0x1b 0x39)
- */
+ //
+ // Control codes:
+ //
+ // BS Backspace (0x08)
+ // HT Horizontal tab; next 8th column (0x09)
+ // LF Line feed; forward full line (0x0a)
+ // VT Vertical tab; reverse full line (0x0b)
+ // FF Form feed (0x0c)
+ // CR Carriage return (0x0d)
+ // ESC 7 Reverse full line (0x1b 0x37)
+ // ESC 8 Reverse half line (0x1b 0x38)
+ // ESC 9 Forward half line (0x1b 0x39)
+ //
switch (ch)
{
- case 0x08 : /* BS - backspace for boldface & underline */
+ case 0x08 : // BS - backspace for boldface & underline
if (column > 0)
column --;
keycol = column;
break;
- case 0x09 : /* HT - tab to next 8th column */
+ case 0x09 : // HT - tab to next 8th column
if (doc.PrettyPrint && keyptr > keyword)
{
*keyptr = '\0';
if (bsearch(&keyptr, doc.Keywords, doc.NumKeywords, sizeof(char *),
compare_keywords))
{
- /*
- * Put keywords in boldface...
- */
+ //
+ // Put keywords in boldface...
+ //
i = page_column * (doc.ColumnWidth + doc.ColumnGutter);
column = (column + 8) & ~7;
if (column >= doc.ColumnWidth && doc.WrapLines)
- { /* Wrap text to margins */
+ { // Wrap text to margins
line ++;
column = 0;
attr &= ~ATTR_BOLD;
break;
- case 0x0d : /* CR */
+ case 0x0d : // CR
#ifndef __APPLE__
- /*
- * All but MacOS/Darwin treat CR as was intended by ANSI
- * folks, namely to move to column 0/1. Some programs still
- * use this to do boldfacing and underlining...
- */
+ //
+ // All but MacOS/Darwin treat CR as was intended by ANSI
+ // folks, namely to move to column 0/1. Some programs still
+ // use this to do boldfacing and underlining...
+ //
column = 0;
break;
#else
- /*
- * MacOS/Darwin still need to treat CR as a line ending.
- */
+ //
+ // MacOS/Darwin still need to treat CR as a line ending.
+ //
{
int nextch;
else
ch = nextch;
}
-#endif /* !__APPLE__ */
+#endif // !__APPLE__
- case 0x0a : /* LF - output current line */
+ case 0x0a : // LF - output current line
if (doc.PrettyPrint && keyptr > keyword)
{
*keyptr = '\0';
if (bsearch(&keyptr, doc.Keywords, doc.NumKeywords, sizeof(char *),
compare_keywords))
{
- /*
- * Put keywords in boldface...
- */
+ //
+ // Put keywords in boldface...
+ //
i = page_column * (doc.ColumnWidth + doc.ColumnGutter);
}
break;
- case 0x0b : /* VT - move up 1 line */
+ case 0x0b : // VT - move up 1 line
if (line > 0)
line --;
ATTR_BLUE);
break;
- case 0x0c : /* FF - eject current page... */
+ case 0x0c : // FF - eject current page...
if (doc.PrettyPrint && keyptr > keyword)
{
*keyptr = '\0';
if (bsearch(&keyptr, doc.Keywords, doc.NumKeywords, sizeof(char *),
compare_keywords))
{
- /*
- * Put keywords in boldface...
- */
+ //
+ // Put keywords in boldface...
+ //
i = page_column * (doc.ColumnWidth + doc.ColumnGutter);
}
break;
- case 0x1b : /* Escape sequence */
+ case 0x1b : // Escape sequence
ch = get_utf8(fp);
if (ch == '7')
{
- /*
- * ESC 7 Reverse full line (0x1b 0x37)
- */
+ //
+ // ESC 7 Reverse full line (0x1b 0x37)
+ //
if (line > 0)
line --;
}
else if (ch == '8')
{
- /*
- * ESC 8 Reverse half line (0x1b 0x38)
- */
+ //
+ // ESC 8 Reverse half line (0x1b 0x38)
+ //
if ((attr & ATTR_RAISED) && line > 0)
{
}
else if (ch == '9')
{
- /*
- * ESC 9 Forward half line (0x1b 0x39)
- */
+ //
+ // ESC 9 Forward half line (0x1b 0x39)
+ //
if ((attr & ATTR_LOWERED) && line < (doc.SizeLines - 1))
{
}
break;
- default : /* All others... */
+ default : // All others...
if (ch < ' ')
- break; /* Ignore other control chars */
+ break; // Ignore other control chars
if (doc.PrettyPrint > PRETTY_PLAIN)
{
- /*
- * Do highlighting of C/C++ keywords, preprocessor commands,
- * and comments...
- */
+ //
+ // Do highlighting of C/C++ keywords, preprocessor commands,
+ // and comments...
+ //
if (ch == ' ' && (attr & ATTR_BOLD))
{
- /*
- * Stop bolding preprocessor command...
- */
+ //
+ // Stop bolding preprocessor command...
+ //
attr &= ~ATTR_BOLD;
}
else if (!(isalnum(ch & 255) || ch == '_') && keyptr > keyword)
{
- /*
- * Look for a keyword...
- */
+ //
+ // Look for a keyword...
+ //
*keyptr = '\0';
keyptr = keyword;
if (bsearch(&keyptr, doc.Keywords, doc.NumKeywords,
sizeof(char *), compare_keywords))
{
- /*
- * Put keywords in boldface...
- */
+ //
+ // Put keywords in boldface...
+ //
i = page_column * (doc.ColumnWidth + doc.ColumnGutter);
}
}
- /*
- * Look for Syntax-transition Starts...
- */
+ //
+ // Look for Syntax-transition Starts...
+ //
+
if (!cmntState && !strState)
{
if ((isalnum(ch & 255) || ch == '_'))
{
- /*
- * Add characters to the current keyword (if they'll fit).
- */
+ //
+ // Add characters to the current keyword (if they'll fit).
+ //
if (keyptr == keyword)
keycol = column;
}
else if (ch == '\"' && lastch != '\\')
{
- /*
- * Start a dbl-quote string constant...
- */
+ //
+ // Start a dbl-quote string constant...
+ //
strState = StrBeg;
attr = ATTR_BLUE;
else if (ch == '*' && lastch == '/' &&
doc.PrettyPrint != PRETTY_SHELL)
{
- /*
- * Start a C-style comment...
- */
+ //
+ // Start a C-style comment...
+ //
cmntState = SNTXstyl;
attr = ATTR_ITALIC | ATTR_GREEN;
else if (ch == '/' && lastch == '/' &&
doc.PrettyPrint == PRETTY_CODE)
{
- /*
- * Start a C++-style comment...
- */
+ //
+ // Start a C++-style comment...
+ //
cmntState = NLstyl;
attr = ATTR_ITALIC | ATTR_GREEN;
}
else if (ch == '#' && doc.PrettyPrint != PRETTY_CODE)
{
- /*
- * Start a shell-style comment...
- */
+ //
+ // Start a shell-style comment...
+ //
cmntState = NLstyl;
attr = ATTR_ITALIC | ATTR_GREEN;
else if (ch == '#' && column == 0 &&
doc.PrettyPrint == PRETTY_CODE)
{
- /*
- * Start a preprocessor command...
- */
+ //
+ // Start a preprocessor command...
+ //
attr = ATTR_BOLD | ATTR_RED;
}
}
if (column >= doc.ColumnWidth && doc.WrapLines)
- { /* Wrap text to margins */
+ { // Wrap text to margins
column = 0;
line ++;
}
}
- /*
- * Add text to the current column & line...
- */
+ //
+ // Add text to the current column & line...
+ //
if (column < doc.ColumnWidth)
{
if ((ch == '{' || ch == '}') && !cmntState && !strState &&
column < doc.ColumnWidth)
{
- /*
- * Highlight curley braces...
- */
+ //
+ // Highlight curley braces...
+ //
doc.Page[line][column].attr |= ATTR_BOLD;
}
column < doc.ColumnWidth &&
doc.PrettyPrint != PRETTY_SHELL)
{
- /*
- * Highlight first comment character...
- */
+ //
+ // Highlight first comment character...
+ //
doc.Page[line][column - 1].attr = attr;
}
else if (ch == '\"' && lastch != '\\' && !cmntState &&
strState == StrEnd)
{
- /*
- * End a dbl-quote string constant...
- */
+ //
+ // End a dbl-quote string constant...
+ //
strState = NoStr;
attr &= ~ATTR_BLUE;
}
else if (ch == '/' && lastch == '*' && cmntState)
{
- /*
- * End a C-style comment...
- */
+ //
+ // End a C-style comment...
+ //
cmntState = NoCmnt;
attr &= ~(ATTR_ITALIC | ATTR_GREEN);
break;
}
- /*
- * Save this character for the next cycle.
- */
+ //
+ // Save this character for the next cycle.
+ //
lastch = ch;
}
- /* Do not write anything if the input file is empty */
+ // Do not write anything if the input file is empty
if (empty)
{
if(log) log(ld, CF_LOGLEVEL_DEBUG,
goto out;
}
- /*
- * Write any remaining page data...
- */
+ //
+ // Write any remaining page data...
+ //
if (line > 0 || page_column > 0 || column > 0)
write_page(&doc);
- /*
- * Write the epilog and return...
- */
+ //
+ // Write the epilog and return...
+ //
write_epilogue(&doc);
out:
- /*
- * Close input data stream
- */
+ //
+ // Close input data stream
+ //
if (fp != stdin)
fclose(fp);
- /*
- * Flush and close output data stream
- */
+ //
+ // Flush and close output data stream
+ //
fflush(stdout);
close(1);
- /*
- * Re-activate stdout output
- */
+ //
+ // Re-activate stdout output
+ //
if (outputfd != 1)
{
close(stdoutbackupfd);
}
- /*
- * Clean up
- */
+ //
+ // Clean up
+ //
if (doc.Page)
{
}
-static EMB_PARAMS *font_load(const char *font, int fontwidth, cf_logfunc_t log,
- void *ld)
+static EMB_PARAMS *
+font_load(const char *font,
+ int fontwidth,
+ cf_logfunc_t log,
+ void *ld)
{
OTF_FILE *otf;
FcConfigSubstitute (0, pattern, FcMatchPattern);
FcDefaultSubstitute (pattern);
- /* Receive a sorted list of fonts matching our 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 */
+ // 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?
if (!fontname)
{
// TODO: try /usr/share/fonts/*/*/%s.ttf
- if(log) log(ld, CF_LOGLEVEL_ERROR,"cfFilterTextToPDF: No viable font found.");
- return NULL;
+ 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;
- }
+ return (NULL);
FONTFILE *ff = fontfile_open_sfnt(otf);
DEBUG_assert(ff);
EMB_C_TAKE_FONTFILE);
DEBUG_assert(emb);
DEBUG_assert(emb->plan&EMB_A_MULTIBYTE);
- return emb;
+
+ return (emb);
}
-static EMB_PARAMS *font_std(const char *name)
+static EMB_PARAMS *
+font_std(const char *name)
{
FONTFILE *ff = fontfile_open_std(name);
DEBUG_assert(ff);
EMB_DEST_PDF16,
EMB_C_TAKE_FONTFILE);
DEBUG_assert(emb);
- return emb;
+
+ return (emb);
}
-/*
- * 'compare_keywords()' - Compare two C/C++ keywords.
- */
+//
+// '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 */
+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...
- */
+//
+// '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 */
+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...
- */
+ 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? */
+ if (ch < 0xc0) // One byte character?
return (ch);
else if ((ch & 0xe0) == 0xc0)
{
- /*
- * Two byte character...
- */
+ //
+ // Two byte character...
+ //
if ((next = getc(fp)) == EOF)
return (EOF);
}
else if ((ch & 0xf0) == 0xe0)
{
- /*
- * Three byte character...
- */
+ //
+ // Three byte character...
+ //
if ((next = getc(fp)) == EOF)
return (EOF);
}
else
{
- /*
- * More than three bytes... We don't support that...
- */
+ //
+ // More than three bytes... We don't support that...
+ //
return (EOF);
}
}
-/*
- * 'write_epilogue()' - Write the PDF file epilogue.
- */
+//
+// 'write_epilogue()' - Write the PDF file epilogue.
+//
static void
write_epilogue(texttopdf_doc_t *doc)
{
- static char *names[] = /* Font names */
+ static char *names[] = // Font names
{ "FN","FB","FI","FBI" };
int i,j;
{
for (j = 0; j < doc->NumFonts; j ++)
{
- EMB_PARAMS *emb=doc->Fonts[j][i];
+ EMB_PARAMS *emb = doc->Fonts[j][i];
if (emb->font->fobj) // already embedded
- {
continue;
- }
if ((!emb->subset) ||
(bits_used(emb->subset, emb->font->sfnt->numGlyphs)))
{
- emb->font->fobj=cfPDFOutWriteFont(doc->pdf,emb);
+ emb->font->fobj = cfPDFOutWriteFont(doc->pdf,emb);
DEBUG_assert(emb->font->fobj);
}
}
}
- /*
- * Create the global fontdict
- */
+ //
+ // Create the global fontdict
+ //
// now fix FontResource
- doc->pdf->xref[doc->FontResource-1]=doc->pdf->filepos;
+ doc->pdf->xref[doc->FontResource - 1] = doc->pdf->filepos;
cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
- "<<\n",
- doc->FontResource);
+ "<<\n",
+ doc->FontResource);
for (i = doc->PrettyPrint ? 3 : 1; i >= 0; i --)
{
for (j = 0; j < doc->NumFonts; j ++)
{
- EMB_PARAMS *emb=doc->Fonts[j][i];
+ EMB_PARAMS *emb = doc->Fonts[j][i];
if (emb->font->fobj) // used
- {
- cfPDFOutPrintF(doc->pdf," /%s%02x %d 0 R\n",names[i],j,emb->font->fobj);
- }
+ cfPDFOutPrintF(doc->pdf, " /%s%02x %d 0 R\n", names[i], j,
+ emb->font->fobj);
}
}
cfPDFOutPrintF(doc->pdf,">>\n"
- "endobj\n");
+ "endobj\n");
cfPDFOutFinishPDF(doc->pdf);
cfPDFOutFree(doc->pdf);
}
-/*
- * {{{ 'write_page()' - Write a page of text.
- */
+
+//
+// {{{ 'write_page()' - Write a page of text.
+//
static void
write_page(texttopdf_doc_t *doc)
{
- int line; /* Current line */
+ int line; // Current line
- int content=cfPDFOutAddXRef(doc->pdf);
+ int content = cfPDFOutAddXRef(doc->pdf);
cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
- "<</Length %d 0 R\n"
- ">>\n"
- "stream\n"
- "q\n",
- content, content+1);
- long size=-((doc->pdf->filepos)-2);
-
- (doc->NumPages)++;
+ "<</Length %d 0 R\n"
+ ">>\n"
+ "stream\n"
+ "q\n",
+ content, content + 1);
+ long size = -((doc->pdf->filepos) - 2);
+
+ (doc->NumPages) ++;
if (doc->PrettyPrint)
write_pretty_header(doc);
for (line = 0; line < doc->SizeLines; line ++)
write_line(line, doc->Page[line], doc);
- size+= ((doc->pdf->filepos)+2);
+ size+= ((doc->pdf->filepos) + 2);
cfPDFOutPrintF(doc->pdf,"Q\n"
- "endstream\n"
- "endobj\n");
+ "endstream\n"
+ "endobj\n");
- int len_obj=cfPDFOutAddXRef(doc->pdf);
- DEBUG_assert(len_obj==content+1);
+ int len_obj = cfPDFOutAddXRef(doc->pdf);
+ DEBUG_assert(len_obj == content + 1);
cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
- "%ld\n"
- "endobj\n",
- len_obj,size);
+ "%ld\n"
+ "endobj\n",
+ len_obj,size);
- int obj=cfPDFOutAddXRef(doc->pdf);
+ int obj = cfPDFOutAddXRef(doc->pdf);
cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
- "<</Type/Page\n"
- " /Parent 1 0 R\n"
- " /MediaBox [0 0 %.0f %.0f]\n"
- " /Contents %d 0 R\n"
- " /Resources << /Font %d 0 R >>\n"
- ">>\n"
- "endobj\n",
- obj,doc->PageWidth, doc->PageLength, content,
- doc->FontResource);
+ "<</Type/Page\n"
+ " /Parent 1 0 R\n"
+ " /MediaBox [0 0 %.0f %.0f]\n"
+ " /Contents %d 0 R\n"
+ " /Resources << /Font %d 0 R >>\n"
+ ">>\n"
+ "endobj\n",
+ obj,doc->PageWidth, doc->PageLength, content,
+ doc->FontResource);
cfPDFOutAddPage(doc->pdf,obj);
memset(doc->Page[0], 0,
}
// }}}
-/*
- * {{{'write_prolog()' - Write the PDF file prolog with options.
- */
+
+//
+// {{{'write_prolog()' - Write the PDF file prolog with options.
+//
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 */
- texttopdf_doc_t *doc,
- cf_logfunc_t log,
- void *ld)
+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
+ texttopdf_doc_t *doc,
+ cf_logfunc_t log,
+ void *ld)
{
- int i, j, k; /* Looping vars */
- const char *charset; /* Character set string */
- char filename[1024]; /* Glyph filenames */
- FILE *fp; /* Glyph files */
- const char *datadir; /* CUPS_DATADIR environment variable */
- char line[1024], /* Line from file */
- *lineptr, /* Pointer into line */
- *valptr; /* Pointer to value in line */
-#ifndef CUPS_1_4 /* CUPS 1.4.x or newer: support for non-utf8 removed */
- int ch, unicode; /* Character values */
-#endif
- int start, end; /* Start and end values for range */
- time_t curtime; /* Current time */
- struct tm *curtm; /* Current date */
- char curdate[255]; /* Current date (text format) */
- int num_fonts = 0; /* Number of unique fonts */
- EMB_PARAMS *fonts[1024]; /* Unique fonts */
- char *fontnames[1024]; /* Unique fonts */
+ int i, j, k; // Looping vars
+ const char *charset; // Character set string
+ char filename[1024]; // Glyph filenames
+ FILE *fp; // Glyph files
+ const char *datadir; // CUPS_DATADIR environment variable
+ char line[1024], // Line from file
+ *lineptr, // Pointer into line
+ *valptr; // Pointer to value in line
+ int start, end; // Start and end values for range
+ time_t curtime; // Current time
+ struct tm *curtm; // Current date
+ char curdate[255]; // Current date (text format)
+ int num_fonts = 0; // Number of unique fonts
+ EMB_PARAMS *fonts[1024]; // Unique fonts
+ char *fontnames[1024]; // Unique fonts
#if 0
- static char *names[] = /* Font names */
+ static char *names[] = // Font names
{
- "FN","FB","FI"
- /*
+ "FN", "FB", "FI"
+ /*
"cupsNormal",
"cupsBold",
"cupsItalic"
- */
+ */
};
#endif
- /*
- * Get the data directory...
- */
+ //
+ // Get the data directory...
+ //
datadir = doc->env_vars.data_dir;
- /*
- * Adjust margins as necessary...
- */
+
+ //
+ // Adjust margins as necessary...
+ //
if (classification || label)
{
- /*
- * Leave room for labels...
- */
+ //
+ // Leave room for labels...
+ //
doc->PageBottom += 36;
doc->PageTop -= 36;
else
doc->ColumnWidth = doc->SizeColumns;
- /*
- * {{{ Output the PDF header...
- */
+ //
+ // {{{ Output the PDF header...
+ //
DEBUG_assert(!(doc->pdf));
doc->pdf = cfPDFOutNew();
cfPDFOutBeginPDF(doc->pdf);
cfPDFOutPrintF(doc->pdf,"%%cupsRotation: %d\n",
- (doc->Orientation & 3) * 90); // TODO?
+ (doc->Orientation & 3) * 90); // TODO?
- cfPDFOutAddKeyValue(doc->pdf,"Creator","texttopdf/" PACKAGE_VERSION);
+ cfPDFOutAddKeyValue(doc->pdf, "Creator", "texttopdf/" PACKAGE_VERSION);
curtime = time(NULL);
curtm = localtime(&curtime);
strftime(curdate, sizeof(curdate), "%c", curtm);
- cfPDFOutAddKeyValue(doc->pdf,"CreationDate",cfPDFOutToPDFDate(curtm));
- cfPDFOutAddKeyValue(doc->pdf,"Title",title);
- cfPDFOutAddKeyValue(doc->pdf,"Author",user); // was(PostScript): /For
+ cfPDFOutAddKeyValue(doc->pdf, "CreationDate", cfPDFOutToPDFDate(curtm));
+ cfPDFOutAddKeyValue(doc->pdf, "Title", title);
+ cfPDFOutAddKeyValue(doc->pdf, "Author", user); // was(PostScript): /For
// }}}
- /*
- * {{{ Initialize globals...
- */
+ //
+ // {{{ Initialize globals...
+ //
doc->NumFonts = 0;
memset(doc->Fonts, 0, sizeof(doc->Fonts));
memset(doc->Codes, 0, sizeof(doc->Codes));
// }}}
- /*
- * Get the output character set...
- */
+ //
+ // Get the output character set...
+ //
charset = doc->env_vars.char_set;
if (charset != NULL && strcmp(charset, "us-ascii") != 0) // {{{
if ((fp = fopen(filename, "r")) == NULL)
{
- /*
- * Can't open charset file!
- */
+ //
+ // Can't open charset file!
+ //
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterTextToPDF: Unable to open %s: %s",
return (1);
}
- /*
- * Opened charset file; now see if this is really a charset file...
- */
+ //
+ // Opened charset file; now see if this is really a charset file...
+ //
if (fgets(line, sizeof(line), fp) == NULL)
{
- /*
- * Bad/empty charset file!
- */
+ //
+ // Bad/empty charset file!
+ //
fclose(fp);
if (log) log(ld, CF_LOGLEVEL_ERROR,
if (strncmp(line, "charset", 7) != 0)
{
- /*
- * Bad format/not a charset file!
- */
+ //
+ // Bad format/not a charset file!
+ //
fclose(fp);
if (log) log(ld, CF_LOGLEVEL_ERROR,
return (1);
}
- /*
- * See if this is an 8-bit or UTF-8 character set file...
- */
+ //
+ // See if this is an 8-bit or UTF-8 character set file...
+ //
- line[strlen(line) - 1] = '\0'; /* Drop \n */
+ line[strlen(line) - 1] = '\0'; // Drop \n
for (lineptr = line + 7; isspace(*lineptr & 255); lineptr ++);
- /* Skip whitespace */
-
-#ifndef CUPS_1_4 /* CUPS 1.4.x or newer: support for non-utf8 removed */
- if (strcmp(lineptr, "8bit") == 0) // {{{
- {
- /*
- * 8-bit text...
- */
-
- doc->UTF8 = 0;
- doc->NumFonts = 0;
-
- /*
- * Read the font description(s)...
- */
-
- while (fgets(line, sizeof(line), fp) != NULL)
- {
- /*
- * Skip comment and blank lines...
- */
-
- if (line[0] == '#' || line[0] == '\n')
- continue;
-
- /*
- * Read the font descriptions that should look like:
- *
- * first last direction width normal [bold italic bold-italic]
- */
-
- lineptr = line;
-
- start = strtol(lineptr, &lineptr, 16);
- end = strtol(lineptr, &lineptr, 16);
-
- while (isspace(*lineptr & 255))
- lineptr ++;
-
- if (!*lineptr)
- break; /* Must be a font mapping */
-
- valptr = lineptr;
-
- while (!isspace(*lineptr & 255) && *lineptr)
- lineptr ++;
-
- if (!*lineptr)
- {
- /*
- * Can't have a font without all required values...
- */
-
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterTextToPDF: Bad font description line: %s", valptr);
- return (1);
- }
+ // Skip whitespace
- *lineptr++ = '\0';
-
- if (strcmp(valptr, "ltor") == 0)
- doc->Directions[doc->NumFonts] = 1;
- else if (strcmp(valptr, "rtol") == 0)
- doc->Directions[doc->NumFonts] = -1;
- else
- {
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterTextToPDF: Bad text direction %s", valptr);
- return (1);
- }
-
- /*
- * Got the direction, now get the width...
- */
-
- while (isspace(*lineptr & 255))
- lineptr ++;
-
- valptr = lineptr;
-
- while (!isspace(*lineptr & 255) && *lineptr)
- lineptr ++;
-
- if (!*lineptr)
- {
- /*
- * Can't have a font without all required values...
- */
-
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterTextToPDF: Bad font description line: %s", valptr);
- return (1);
- }
-
- *lineptr++ = '\0';
-
- if (strcmp(valptr, "single") == 0)
- doc->Widths[doc->NumFonts] = 1;
- else if (strcmp(valptr, "double") == 0)
- doc->Widths[doc->NumFonts] = 2;
- else
- {
- if(log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterTextToPDF: Bad text width %s", valptr);
- return (1);
- }
-
- /*
- * Get the fonts...
- */
-
- for (i = 0; *lineptr && i < 4; i ++)
- {
- while (isspace(*lineptr & 255))
- lineptr ++;
-
- valptr = lineptr;
-
- while (!isspace(*lineptr & 255) && *lineptr)
- lineptr ++;
-
- if (*lineptr)
- *lineptr++ = '\0';
-
- if (lineptr > valptr)
- {
- // search for duplicates
- for (k = 0; k < num_fonts; k ++)
- if (strcmp(valptr, fontnames[k]) == 0)
- {
- doc->Fonts[doc->NumFonts][i] = fonts[k];
- break;
- }
-
- if (k==num_fonts) // not found
- {
- fonts[num_fonts] = doc->Fonts[doc->NumFonts][i] =
- font_load(valptr, doc->Widths[doc->NumFonts], log, ld);
- if (!fonts[num_fonts]) // font missing/corrupt, replace by first
- {
- if(log) log(ld, CF_LOGLEVEL_WARN,
- "cfFilterTextToPDF: Ignored bad font \"%s\"",valptr);
- break;
- }
- fontnames[num_fonts++] = strdup(valptr);
- }
- }
- }
-
- /* ignore complete range, when the first font is not available */
- if (i==0)
- {
- continue;
- }
-
- /*
- * Fill in remaining fonts as needed...
- */
-
- for (j = i; j < 4; j ++)
- doc->Fonts[doc->NumFonts][j] = doc->Fonts[doc->NumFonts][0];
-
- /*
- * Define the character mappings...
- */
-
- for (i = start; i <= end; i ++)
- doc->Codes[i] = doc->NumFonts;
-
- (doc->NumFonts)++;
- }
-
- /*
- * Read encoding lines...
- */
-
- do
- {
- /*
- * Skip comment and blank lines...
- */
-
- if (line[0] == '#' || line[0] == '\n')
- continue;
-
- /*
- * Grab the character and unicode glyph number.
- */
-
- if (sscanf(line, "%x%x", &ch, &unicode) == 2 && ch < 256)
- doc->Chars[ch] = unicode;
- }
- while (fgets(line, sizeof(line), fp) != NULL);
-
- fclose(fp);
- } else // }}}
-#endif
if (strcmp(lineptr, "utf8") == 0) // {{{
{
- /*
- * UTF-8 (Unicode) text...
- */
+ //
+ // UTF-8 (Unicode) text...
+ //
doc->UTF8 = 1;
- /*
- * Read the font descriptions...
- */
+ //
+ // Read the font descriptions...
+ //
doc->NumFonts = 0;
while (fgets(line, sizeof(line), fp) != NULL)
{
- /*
- * Skip comment and blank lines...
- */
+ //
+ // Skip comment and blank lines...
+ //
if (line[0] == '#' || line[0] == '\n')
continue;
- /*
- * Read the font descriptions that should look like:
- *
- * start end direction width normal [bold italic bold-italic]
- */
+ //
+ // Read the font descriptions that should look like:
+ //
+ // start end direction width normal [bold italic bold-italic]
+ //
lineptr = line;
if (!*lineptr)
{
- /*
- * Can't have a font without all required values...
- */
+ //
+ // Can't have a font without all required values...
+ //
+
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterTextToPDF: Bad font description line: %s", valptr);
return (1);
return (1);
}
- /*
- * Got the direction, now get the width...
- */
+ //
+ // Got the direction, now get the width...
+ //
while (isspace(*lineptr & 255))
lineptr ++;
if (!*lineptr)
{
- /*
- * Can't have a font without all required values...
- */
+ //
+ // Can't have a font without all required values...
+ //
+
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterTextToPDF: Bad font description line: %s", valptr);
return (1);
return (1);
}
- /*
- * Get the fonts...
- */
+ //
+ // Get the fonts...
+ //
for (i = 0; *lineptr && i < 4; i ++)
{
break;
}
- if (k==num_fonts) // not found
+ if (k == num_fonts) // not found
{
fonts[num_fonts] = doc->Fonts[doc->NumFonts][i] =
font_load(valptr, doc->Widths[doc->NumFonts], log, ld);
}
}
- /* ignore complete range, when the first font is not available */
+ // ignore complete range, when the first font is not available
if (i == 0)
- {
continue;
- }
- /*
- * Fill in remaining fonts as needed...
- */
+ //
+ // Fill in remaining fonts as needed...
+ //
for (j = i; j < 4; j ++)
doc->Fonts[doc->NumFonts][j] = doc->Fonts[doc->NumFonts][0];
- /*
- * Define the character mappings...
- */
+ //
+ // Define the character mappings...
+ //
for (i = start; i <= end; i ++)
- {
doc->Codes[i] = doc->NumFonts;
- }
- /*
- * Move to the next font, stopping if needed...
- */
+ //
+ // Move to the next font, stopping if needed...
+ //
doc->NumFonts ++;
if (doc->NumFonts >= 256)
} // }}}
else // {{{ Standard ASCII
{
- /*
- * Standard ASCII output just uses Courier, Courier-Bold, and
- * possibly Courier-Oblique.
- */
+ //
+ // Standard ASCII output just uses Courier, Courier-Bold, and
+ // possibly Courier-Oblique.
+ //
doc->NumFonts = 1;
doc->Widths[0] = 1;
doc->Directions[0] = 1;
- /*
- * Define US-ASCII characters...
- */
+ //
+ // Define US-ASCII characters...
+ //
for (i = 32; i < 127; i ++)
{
doc->Chars[i] = i;
- doc->Codes[i] = doc->NumFonts-1;
+ doc->Codes[i] = doc->NumFonts - 1;
}
}
// }}}
- if (doc->NumFonts == 0) {
+ if (doc->NumFonts == 0)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterTextToPDF:No usable font available");
return (1);
}
- doc->FontScaleX=120.0 / (doc->CharsPerInch);
- doc->FontScaleY=68.0 / (doc->LinesPerInch);
+ doc->FontScaleX = 120.0 / (doc->CharsPerInch);
+ doc->FontScaleY = 68.0 / (doc->LinesPerInch);
// allocate now, for pages to use. will be fixed in epilogue
- doc->FontResource=cfPDFOutAddXRef(doc->pdf);
+ doc->FontResource = cfPDFOutAddXRef(doc->pdf);
if (doc->PrettyPrint)
{
- doc->Date=make_wide(curdate, doc);
- doc->Title=make_wide(title, doc);
+ doc->Date = make_wide(curdate, doc);
+ doc->Title = make_wide(title, doc);
}
return (0);
}
// }}}
-/*
- * {{{ 'write_line()' - Write a row of text.
- */
+
+//
+// {{{ 'write_line()' - Write a row of text.
+//
static void
-write_line(int row, /* I - Row number (0 to N) */
- lchar_t *line,
- texttopdf_doc_t *doc) /* I - Line to print */
+write_line(int row, // I - Row number (0 to N)
+ lchar_t *line, // I - Line to print
+ texttopdf_doc_t *doc)
{
- int i; /* Looping var */
- int col,xcol,xwid; /* Current column */
- int attr; /* Current attribute */
- int font, /* Font to use */
- lastfont, /* Last font */
- mono; /* Monospaced? */
- lchar_t *start; /* First character in sequence */
+ int i; // Looping var
+ int col,xcol,xwid; // Current column
+ int attr; // Current attribute
+ int font, // Font to use
+ lastfont, // Last font
+ mono; // Monospaced?
+ lchar_t *start; // First character in sequence
- xcol=0;
+ xcol = 0;
for (col = 0, start = line; col < doc->SizeColumns;)
{
while (col < doc->SizeColumns && (line->ch == ' ' || line->ch == 0))
if (doc->NumFonts == 1)
{
- /*
- * All characters in a single font - assume monospaced and single width...
- */
+ //
+ // All characters in a single font - assume monospaced and single width...
+ //
attr = line->attr;
start = line;
}
else
{
- /*
- * Multiple fonts; break up based on the font...
- */
+ //
+ // Multiple fonts; break up based on the font...
+ //
attr = line->attr;
start = line;
xwid = 0;
- if (doc->UTF8) {
+ if (doc->UTF8)
lastfont = doc->Codes[line->ch];
- } else {
+ else
lastfont = doc->Codes[doc->Chars[line->ch]];
- }
//mono = strncmp(Fonts[lastfont][0], "Courier", 7) == 0;
mono = 1; // TODO
while (col < doc->SizeColumns && line->ch != 0 && attr == line->attr)
{
if (doc->UTF8)
- {
font = doc->Codes[line->ch];
- }
else
- {
font = doc->Codes[doc->Chars[line->ch]];
- }
- if (/*strncmp(Fonts[font][0], "Courier", 7) != 0 ||*/ // TODO
+ if (//strncmp(Fonts[font][0], "Courier", 7) != 0 ||*/ // TODO
font != lastfont)
break;
}
else
{
- /*
- * Do right-to-left text... ; assume no font change without direction
- * change
- */
+ //
+ // Do right-to-left text... ; assume no font change without direction
+ // change
+ //
while (col < doc->SizeColumns && line->ch != 0 && attr == line->attr)
{
if (doc->UTF8)
- {
font = doc->Codes[line->ch];
- }
else
- {
font = doc->Codes[doc->Chars[line->ch]];
- }
if (doc->Directions[font] > 0 &&
!ispunct(line->ch & 255) && !isspace(line->ch & 255))
break;
write_string(xcol + xwid, row, 1, start, doc);
}
else
- {
xwid--;
- }
}
}
}
}
// }}}
-static lchar_t *make_wide(const char *buf, texttopdf_doc_t *doc)
+
+static lchar_t
+*make_wide(const char *buf,
+ texttopdf_doc_t *doc)
// {{{ - convert to lchar_t
{
- const unsigned char *utf8; /* UTF8 text */
+ const unsigned char *utf8; // UTF8 text
lchar_t *ret,*out;
-
- // this is enough, utf8 chars will only require less space
- out=ret=malloc((strlen(buf)+1)*sizeof(lchar_t));
+
+
+ // This is enough, utf8 chars will only require less space
+ out = ret = malloc((strlen(buf) + 1) * sizeof(lchar_t));
utf8 = (const unsigned char *)buf;
while (*utf8)
{
- out->attr=0;
+ out->attr = 0;
if (*utf8 < 0xc0 || !(doc->UTF8))
out->ch = *utf8 ++;
else if ((*utf8 & 0xe0) == 0xc0)
{
- /*
- * Two byte character...
- */
+ //
+ // Two byte character...
+ //
out->ch = ((utf8[0] & 0x1f) << 6) | (utf8[1] & 0x3f);
utf8 += 2;
}
else
{
- /*
- * Three byte character...
- */
+ //
+ // Three byte character...
+ //
out->ch = ((((utf8[0] & 0x1f) << 6) | (utf8[1] & 0x3f)) << 6) |
(utf8[2] & 0x3f);
out++;
}
- out->ch=out->attr=0;
- return ret;
+ out->ch = out->attr = 0;
+ return (ret);
}
// }}}
-/*
- * {{{ 'write_string()' - Write a string of text.
- */
+
+//
+// {{{ 'write_string()' - Write a string of text.
+//
static void
-write_string(int col, /* I - Start column */
- int row, /* I - Row */
- int len, /* I - Number of characters */
- lchar_t *s, /* I - String to print */
+write_string(int col, // I - Start column
+ int row, // I - Row
+ int len, // I - Number of characters
+ lchar_t *s, // I - String to print
texttopdf_doc_t *doc)
{
- float x, y; /* Position of text */
- unsigned attr; /* Character attributes */
+ float x, y; // Position of text
+ unsigned attr; // Character attributes
- /*
- * Position the text and set the font...
- */
+ //
+ // Position the text and set the font...
+ //
if (doc->Duplex && (doc->NumPages & 1) == 0)
{
if (attr & ATTR_UNDERLINE)
cfPDFOutPrintF(doc->pdf,"q 0.5 w 0 g %.3f %.3f m %.3f %.3f l S Q ",
- x, y - 6.8 / (doc->LinesPerInch),
- x + (float)len * 72.0 / (float)(doc->CharsPerInch),
- y - 6.8 / (doc->LinesPerInch));
+ x, y - 6.8 / (doc->LinesPerInch),
+ x + (float)len * 72.0 / (float)(doc->CharsPerInch),
+ y - 6.8 / (doc->LinesPerInch));
if (doc->PrettyPrint)
{
- if (doc->ColorDevice) {
+ if (doc->ColorDevice)
+ {
if (attr & ATTR_RED)
- cfPDFOutPrintF(doc->pdf,"0.5 0 0 rg\n");
+ cfPDFOutPrintF(doc->pdf, "0.5 0 0 rg\n");
else if (attr & ATTR_GREEN)
- cfPDFOutPrintF(doc->pdf,"0 0.5 0 rg\n");
+ cfPDFOutPrintF(doc->pdf, "0 0.5 0 rg\n");
else if (attr & ATTR_BLUE)
- cfPDFOutPrintF(doc->pdf,"0 0 0.5 rg\n");
+ cfPDFOutPrintF(doc->pdf, "0 0 0.5 rg\n");
else
- cfPDFOutPrintF(doc->pdf,"0 g\n");
- } else {
- if ( (attr & ATTR_RED)||(attr & ATTR_GREEN)||(attr & ATTR_BLUE) )
- cfPDFOutPrintF(doc->pdf,"0.2 g\n");
+ cfPDFOutPrintF(doc->pdf, "0 g\n");
+ }
+ else
+ {
+ if ((attr & ATTR_RED) || (attr & ATTR_GREEN) || (attr & ATTR_BLUE))
+ cfPDFOutPrintF(doc->pdf, "0.2 g\n");
else
- cfPDFOutPrintF(doc->pdf,"0 g\n");
+ cfPDFOutPrintF(doc->pdf, "0 g\n");
}
}
else
- cfPDFOutPrintF(doc->pdf,"0 g\n");
+ cfPDFOutPrintF(doc->pdf, "0 g\n");
- write_font_str(x,y,attr & ATTR_FONT,s,len, doc);
+ write_font_str(x, y, attr & ATTR_FONT, s, len, doc);
}
// }}}
+
// {{{ show >len characters from >str, using the right font(s) at >x,>y
-static void write_font_str(float x,float y,int fontid, lchar_t *str,
- int len, texttopdf_doc_t *doc)
+static void
+write_font_str(float x,
+ float y,
+ int fontid,
+ lchar_t *str,
+ int len,
+ texttopdf_doc_t *doc)
{
- unsigned short ch; /* Current character */
- static char *names[] = /* Font names */
+ unsigned short ch; // Current character
+ static char *names[] = // Font names
{ "FN","FB","FI","FBI" };
- if (len==-1) {
- for (len=0;str[len].ch;len++);
- }
- cfPDFOutPrintF(doc->pdf,"BT\n");
+
+ if (len == -1)
+ for (len = 0; str[len].ch; len++);
+
+ cfPDFOutPrintF(doc->pdf, "BT\n");
if (x == (int)x)
cfPDFOutPrintF(doc->pdf," %.0f ", x);
cfPDFOutPrintF(doc->pdf," %.3f ", x);
if (y == (int)y)
- cfPDFOutPrintF(doc->pdf,"%.0f Td\n", y);
+ cfPDFOutPrintF(doc->pdf, "%.0f Td\n", y);
else
- cfPDFOutPrintF(doc->pdf,"%.3f Td\n", y);
+ cfPDFOutPrintF(doc->pdf, "%.3f Td\n", y);
- int lastfont,font;
+ int lastfont, font;
// split on font boundary
while (len > 0)
{
- /*
- * Write a hex string...
- */
+ //
+ // Write a hex string...
+ //
+
if (doc->UTF8)
- {
- lastfont=doc->Codes[str->ch];
- }
+ lastfont = doc->Codes[str->ch];
else
- {
- lastfont=doc->Codes[doc->Chars[str->ch]];
- }
- EMB_PARAMS *emb=doc->Fonts[lastfont][fontid];
- OTF_FILE *otf=emb->font->sfnt;
+ lastfont = doc->Codes[doc->Chars[str->ch]];
+
+ EMB_PARAMS *emb = doc->Fonts[lastfont][fontid];
+ OTF_FILE *otf = emb->font->sfnt;
if (otf) // TODO?
{
cfPDFOutPrintF(doc->pdf," %.3f Tz\n",
- doc->FontScaleX * 600.0 /
- (otf_get_width(otf, 4) * 1000.0 /
- otf->unitsPerEm) * 100.0 / (doc->FontScaleY)); // TODO?
- // gid==4 is usually '!', the char after space. We just need "the"
- // width for the monospaced font. gid==0 is bad, and space might also
+ doc->FontScaleX * 600.0 /
+ (otf_get_width(otf, 4) * 1000.0 /
+ otf->unitsPerEm) * 100.0 / (doc->FontScaleY)); // TODO?
+ // gid == 4 is usually '!', the char after space. We just need "the"
+ // width for the monospaced font. gid == 0 is bad, and space might also
// be bad.
}
else
{
cfPDFOutPrintF(doc->pdf," %.3f Tz\n",
- doc->FontScaleX*100.0/(doc->FontScaleY)); // TODO?
+ doc->FontScaleX*100.0/(doc->FontScaleY)); // TODO?
}
cfPDFOutPrintF(doc->pdf," /%s%02x %.3f Tf <",
- names[fontid],lastfont,doc->FontScaleY);
+ names[fontid],lastfont,doc->FontScaleY);
while (len > 0)
{
if (doc->UTF8)
- {
ch = str->ch;
- }
else
- {
ch = doc->Chars[str->ch];
- }
font = doc->Codes[ch];
if (lastfont != font) // only possible, when not used via
// write_string (e.g. utf-8filename.txt in
// prettyprint)
- {
break;
- }
if (otf) // TODO
{
- const unsigned short gid=emb_get(emb,ch);
+ const unsigned short gid = emb_get(emb,ch);
cfPDFOutPrintF(doc->pdf, "%04x", gid);
}
else // std 14 font with 7-bit us-ascii uses single byte encoding, TODO
- {
cfPDFOutPrintF(doc->pdf, "%02x", ch);
- }
len --;
str ++;
}
// }}}
-static float string_width_x(lchar_t *str, texttopdf_doc_t * doc)
+
+static float
+string_width_x(lchar_t *str,
+ texttopdf_doc_t * doc)
{
int len;
- for (len=0;str[len].ch;len++);
- return (float)len * 72.0 / (float)(doc->CharsPerInch);
+ for (len = 0; str[len].ch; len ++);
+
+ return ((float)len * 72.0 / (float)(doc->CharsPerInch));
}
-static void write_pretty_header(texttopdf_doc_t *doc) // {{{
+
+static void
+write_pretty_header(texttopdf_doc_t *doc) // {{{
{
- float x,y;
+ float x, y;
cfPDFOutPrintF(doc->pdf,"q\n"
- "0.9 g\n");
+ "0.9 g\n");
if (doc->Duplex && (doc->NumPages & 1) == 0)
{
y = doc->PageTop + 72.0f / (doc->LinesPerInch);
}
- cfPDFOutPrintF(doc->pdf,"1 0 0 1 %.3f %.3f cm\n",x,y); // translate
- cfPDFOutPrintF(doc->pdf,"0 0 %.3f %.3f re f\n",
- doc->PageRight - doc->PageLeft, 144.0f / (doc->LinesPerInch));
- cfPDFOutPrintF(doc->pdf,"0 g 0 G\n");
+ cfPDFOutPrintF(doc->pdf, "1 0 0 1 %.3f %.3f cm\n", x, y); // translate
+ cfPDFOutPrintF(doc->pdf, "0 0 %.3f %.3f re f\n",
+ doc->PageRight - doc->PageLeft, 144.0f / (doc->LinesPerInch));
+ cfPDFOutPrintF(doc->pdf, "0 g 0 G\n");
if (doc->Duplex && (doc->NumPages & 1) == 0)
{
// convert pagenumber to string
char tmp[20];
- tmp[19]=0;
- snprintf(tmp,19,"%d",doc->NumPages);
- lchar_t *pagestr=make_wide(tmp, doc);
+ tmp[19] = 0;
+ snprintf(tmp, 19, "%d", doc->NumPages);
+ lchar_t *pagestr = make_wide(tmp, doc);
if (doc->Duplex && (doc->NumPages & 1) == 0)
- {
x = 36.0f / doc->LinesPerInch;
- }
else
- {
x = doc->PageRight - doc->PageLeft -
36.0f / doc->LinesPerInch - string_width_x(pagestr, doc);
- }
write_font_str(x, y, ATTR_BOLD, pagestr, -1, doc);
free(pagestr);
-/*
- * texttotext
- *
- * Filter to print text files on text-only printers. The filter has
- * several configuration options so that it should work with most
- * printer models.
- *
- * Copyright 2007-2011 by Apple Inc.
- * Copyright 1997-2006 by Easy Software Products.
- * Copyright 2011-2016 by Till Kamppeter
- *
- * Distribution and use rights are outlined in the file "COPYING"
- * which should have been included with this file.
- */
-
-/*
- * Include necessary headers...
- */
+//
+// texttotext
+//
+// Filter to print text files on text-only printers. The filter has
+// several configuration options so that it should work with most
+// printer models.
+//
+// Copyright 2007-2011 by Apple Inc.
+// Copyright 1997-2006 by Easy Software Products.
+// Copyright 2011-2016 by Till Kamppeter
+//
+// Distribution and use rights are outlined in the file "COPYING"
+// which should have been included with this file.
+//
+
+//
+// Include necessary headers...
+//
#include <config.h>
#include <cups/cups.h>
#include "ipp.h"
#include "filter.h"
-/*
- * Type definitions
- */
-typedef enum overlong_line_e {
+//
+// Type definitions
+//
+
+typedef enum overlong_line_e
+{
TRUNCATE = 0,
WORDWRAP = 1,
WRAPATWIDTH = 2
} overlong_line_t;
-typedef enum newline_char_e {
+typedef enum newline_char_e
+{
LF = 0,
CR = 1,
CRLF = 2
} newline_char_t;
-/*
- * Local functions...
- */
+//
+// Local functions...
+//
static int is_true(const char *value);
static int is_false(const char *value);
static int check_range(char *page_ranges, int even_pages,
int odd_pages, int page);
-int cfFilterTextToText(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? (unused)*/
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters */
+int
+cfFilterTextToText(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ // (unused)
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
{
- int i, j; /* Looping vars */
+ int i, j; // Looping vars
char *p;
- int exit_status = 0; /* Exit status */
- int fd; /* Copy file descriptor */
-
- int num_copies; /* Number of copies */
- int num_options; /* Number of options */
- cups_option_t *options; /* Options */
- const char *val; /* Option value */
- int num_lines = 66, /* Lines per page */
- num_columns = 80; /* Characters per line */
- int page_left = 0, /* Page margins */
+ int exit_status = 0; // Exit status
+ int fd; // Copy file descriptor
+
+ int num_copies; // Number of copies
+ int num_options; // Number of options
+ cups_option_t *options; // Options
+ const char *val; // Option value
+ int num_lines = 66, // Lines per page
+ num_columns = 80; // Characters per line
+ int page_left = 0, // Page margins
page_right = 0,
page_top = 0,
page_bottom = 0,
num_lines_per_inch = 0,
num_chars_per_inch = 0;
- int text_width, /* Width of the text area on the page */
- text_height; /* Height of the text area on the
- page */
- char encoding[64]; /* The printer'a encoding, to which
- the incoming UTF-8 is converted,
- must be 1-byte-per-character */
+ int text_width, // Width of the text area on the page
+ text_height; // Height of the text area on the
+ // page
+ char encoding[64]; // The printer'a encoding, to which
+ // the incoming UTF-8 is converted,
+ // must be 1-byte-per-character
overlong_line_t overlong_lines = WRAPATWIDTH;
- /* How to treat overlong lines */
- int tab_width = 8; /* Turn tabs to spaces with given
- width */
- int pagination = 1; /* Paginate text to allow margins
- and page management */
- int send_ff = 1; /* Send form-feed char at the end of
- each page */
- newline_char_t newline_char = CRLF; /* Character to send at end of line */
+ // How to treat overlong lines
+ int tab_width = 8; // Turn tabs to spaces with given
+ // width
+ int pagination = 1; // Paginate text to allow margins
+ // and page management
+ int send_ff = 1; // Send form-feed char at the end of
+ // each page
+ newline_char_t newline_char = CRLF; // Character to send at end of line
char *newline_char_str;
- char *page_ranges = NULL; /* Selection of pages to print */
- int even_pages = 1; /* Print the even pages */
- int odd_pages = 1; /* Print the odd pages */
- int reverse_order = 0; /* Ouput pages in reverse order? */
- int collate = 1; /* Collate multiple copies? */
- int page_size; /* Number of bytes needed for a page,
- to allocate the memory for the
- output page buffer */
- char *out_page = NULL; /* Output page buffer */
- cups_array_t *page_array = NULL; /* Array to hold the output pages
- for collated copies and reverse
- output order */
- iconv_t cd; /* Conversion descriptor, describes
- between which encodings iconv
- should convert */
- char outbuf[4096]; /* Output buffer for iconv */
- char inbuf[2048]; /* Input buffer for iconv */
- size_t outsize; /* Space left in outbuf */
- size_t insize = 0; /* Bytes still to be converted in
- inbuf */
- char *outptr = outbuf; /* Pointer for next converted
- character to be dropped */
- char *inptr = inbuf; /* Pointer to next character to be
- converted */
- size_t nread; /* Number of bytes read from file */
- size_t nconv; /* -1 on conversion error */
- int incomplete_char = 0; /* Was last character in input buffer
- incomplete */
- int result = 0; /* Conversion result (-1 on error) */
- char *procptr, /* Pointer into conversion output
- to indicate next byte to process
- for output page creation */
- *destptr; /* Pointer into output page buffer
- where next character will be put */
- int page, /* Number of current output page */
- line, column; /* Character coordiantes on output
- page */
- int page_empty; /* Is the current output page still
- empty (no visible characters)? */
- int previous_is_cr; /* Is the previous character processed
- a Carriage Return? */
- int new_line_started = 0; /* Is the proceeding of starting a
- new line (left margin, new page's
- top margin, wrapped word) already
- done for this line? */
- int skip_rest_of_line = 0; /* Are we truncating an overlong
- line? */
- int skip_spaces = 0; /* Are we skipping spaces at a line
- break when word-wrapping? */
- char *wrapped_word = NULL; /* Section of a word wrapped over
- to the next line */
- int num_pages = 0; /* Number of pages which get actually
- printed */
+ char *page_ranges = NULL; // Selection of pages to print
+ int even_pages = 1; // Print the even pages
+ int odd_pages = 1; // Print the odd pages
+ int reverse_order = 0; // Ouput pages in reverse order?
+ int collate = 1; // Collate multiple copies?
+ int page_size; // Number of bytes needed for a page,
+ // to allocate the memory for the
+ // output page buffer
+ char *out_page = NULL; // Output page buffer
+ cups_array_t *page_array = NULL; // Array to hold the output pages
+ // for collated copies and reverse
+ // output order
+ iconv_t cd; // Conversion descriptor, describes
+ // between which encodings iconv
+ // should convert
+ char outbuf[4096]; // Output buffer for iconv
+ char inbuf[2048]; // Input buffer for iconv
+ size_t outsize; // Space left in outbuf
+ size_t insize = 0; // Bytes still to be converted in
+ // inbuf
+ char *outptr = outbuf; // Pointer for next converted
+ // character to be dropped
+ char *inptr = inbuf; // Pointer to next character to be
+ // converted
+ size_t nread; // Number of bytes read from file
+ size_t nconv; // -1 on conversion error
+ int incomplete_char = 0; // Was last character in input buffer
+ // incomplete
+ int result = 0; // Conversion result (-1 on error)
+ char *procptr, // Pointer into conversion output
+ // to indicate next byte to process
+ // for output page creation
+ *destptr; // Pointer into output page buffer
+ // where next character will be put
+ int page, // Number of current output page
+ line, column; // Character coordiantes on output
+ // page
+ int page_empty; // Is the current output page still
+ // empty (no visible characters)?
+ int previous_is_cr; // Is the previous character processed
+ // a Carriage Return?
+ int new_line_started = 0; // Is the proceeding of starting a
+ // new line (left margin, new page's
+ // top margin, wrapped word) already
+ // done for this line?
+ int skip_rest_of_line = 0; // Are we truncating an overlong
+ // line?
+ int skip_spaces = 0; // Are we skipping spaces at a line
+ // break when word-wrapping?
+ char *wrapped_word = NULL; // Section of a word wrapped over
+ // to the next line
+ int num_pages = 0; // Number of pages which get actually
+ // printed
ipp_t *printer_attrs = data->printer_attrs;
ipp_t *job_attrs = data->job_attrs;
float paperdimensions[2];
char buf[2048];
- cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
+ cf_logfunc_t log = data->logfunc;
+ void *ld = data->logdata;
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
- void *icd = data->iscanceleddata;
+ void *icd = data->iscanceleddata;
cups_file_t *outputfp;
- /*
- * Make sure status messages are not buffered...
- */
- setbuf(stderr, NULL);
+ //
+ // Make sure status messages are not buffered...
+ //
+ setbuf(stderr, NULL);
if ((outputfp = cupsFileOpenFd(outputfd, "w")) == NULL)
{
return (1);
}
- /*
- * Number of copies
- */
+ //
+ // Number of copies
+ //
num_copies = data->copies;
if (num_copies < 1)
num_copies = 1;
- /*
- * Parse the options and IPP attributes
- */
+ //
+ // Parse the options and IPP attributes
+ //
num_options = data->num_options;
options = data->options;
- /* Number of lines and columns per inch This is mainly for
- development and debugging. With these set and the page size given
- as width and length dimension, the number of lines and columns on
- the page gets calculated. A way for using custom sizes. With
- these not set, the media-col-database entry for the page size is
- looked up and if it has the extra integer entries "num-lines" and
- "num-columns", the numbers here are used. */
+ // Number of lines and columns per inch This is mainly for
+ // development and debugging. With these set and the page size given
+ // as width and length dimension, the number of lines and columns on
+ // the page gets calculated. A way for using custom sizes. With
+ // these not set, the media-col-database entry for the page size is
+ // looked up and if it has the extra integer entries "num-lines" and
+ // "num-columns", the numbers here are used.
if ((val = cupsGetOption("NumLinesPerInch",
num_options, options)) != NULL ||
(val = cupsGetOption("num-lines-per-inch",
{
if (num_chars_per_inch <= 0)
log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Number of charcters per inch not set, if page dimensions are given, find number of characters per line via pre-defined page sizes");
+ "cfFilterTextToText: Number of charcters per inch not set, if page dimensions are given, find number of characters per line via pre-defined page sizes");
else
- if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Number of characters per inch = %d",
- num_chars_per_inch);
+ log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Number of characters per inch = %d",
+ num_chars_per_inch);
}
}
NULL, NULL, NULL, NULL, NULL, &media_col_entry);
if (media_col_entry)
{
- /* We have a media-col-database and the requested/default page size
- is contained in it (= size is supported), check whether we have
- a number of lines/columns registered via extra interger entries
- "num-columns" and "num-lines". */
+ // We have a media-col-database and the requested/default page size
+ // is contained in it (= size is supported), check whether we have
+ // a number of lines/columns registered via extra interger entries
+ // "num-columns" and "num-lines".
num_columns = ippGetInteger(ippFindAttribute(media_col_entry,
"num-columns",
IPP_TAG_ZERO), 0);
if (num_lines_per_inch > 0 && paperdimensions[1] > 0)
num_lines = (int)((paperdimensions[1] / 72.0) * (num_lines_per_inch));
- if (num_lines <= 0) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,"cfFilterTextToText: Invalid number of lines %d, using default: 66",
- num_lines);
+ if (num_lines <= 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid number of lines %d, using default: 66",
+ num_lines);
num_lines = 66;
}
- if (num_columns <= 0) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,"cfFilterTextToText: Invalid number of columns %d, using default: 80",
- num_columns);
+ if (num_columns <= 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid number of columns %d, using default: 80",
+ num_columns);
num_columns = 80;
}
- /* Direct specification of number of lines/columns, mainly for debugging
- and development */
+ // Direct specification of number of lines/columns, mainly for debugging
+ // and development
if ((val = cupsGetOption("PageHeight", num_options, options)) != NULL ||
(val = cupsGetOption("page-height", num_options, options)) != NULL ||
- (ipp = ippFindAttribute(job_attrs, "page-height", IPP_TAG_INTEGER))!=NULL) {
- if(val == NULL){
- ippAttributeString(ipp, buf, sizeof(buf));
- val = buf;
- }
+ (ipp = ippFindAttribute(job_attrs, "page-height", IPP_TAG_INTEGER)) !=
+ NULL)
+ {
+ if (val == NULL)
+ {
+ ippAttributeString(ipp, buf, sizeof(buf));
+ val = buf;
+ }
i = atoi(val);
if (i > 0)
num_lines = i;
else
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Invalid number of lines %d, using default value: %d",
- i, num_lines);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid number of lines %d, using default value: %d",
+ i, num_lines);
}
if ((val = cupsGetOption("PageWidth", num_options, options)) != NULL ||
(val = cupsGetOption("page-width", num_options, options)) != NULL ||
- (ipp = ippFindAttribute(job_attrs, "page-width", IPP_TAG_INTEGER))!=NULL) {
- if(val == NULL){
+ (ipp = ippFindAttribute(job_attrs, "page-width", IPP_TAG_INTEGER)) !=
+ NULL)
+ {
+ if (val == NULL)
+ {
ippAttributeString(ipp, buf, sizeof(buf));
val = buf;
}
if (i > 0)
num_columns = i;
else
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Invalid number of columns %d, using default value: %d",
- i, num_columns);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid number of columns %d, using default value: %d",
+ i, num_columns);
}
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Lines per page: %d; Characters per line: %d",
- num_lines, num_columns);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Lines per page: %d; Characters per line: %d",
+ num_lines, num_columns);
if ((val = cupsGetOption("PageLeft",
num_options, options)) != NULL ||
val += 7;
page_left = atoi(val);
}
- if (log)
+ if (page_left < 0 || page_left > num_columns - 1)
{
- if (page_left < 0 || page_left > num_columns - 1)
- {
- log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Left margin not set or invalid, use 0 columns");
- page_left = 0;
- }
- else
- if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Left margin: %d columns",
- page_left);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Left margin not set or invalid, use 0 columns");
+ page_left = 0;
}
+ else
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Left margin: %d columns",
+ page_left);
}
if ((val = cupsGetOption("PageRight",
val += 7;
page_right = atoi(val);
}
- if (log)
+ if (page_right < 0 || page_right > num_columns - 1)
{
- if (page_right < 0 || page_right > num_columns - 1)
- {
- log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Right margin not set or invalid, use 0 columns");
- page_right = 0;
- }
- else
- if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Right margin: %d columns",
- page_right);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Right margin not set or invalid, use 0 columns");
+ page_right = 0;
}
+ else
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Right margin: %d columns",
+ page_right);
}
if ((val = cupsGetOption("PageTop",
val += 7;
page_top = atoi(val);
}
- if (log)
+ if (page_top < 0 || page_top > num_lines - 1)
{
- if (page_top < 0 || page_top > num_lines - 1)
- {
- log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Top margin not set or invalid, use 0 lines");
- page_top = 0;
- }
- else
- if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Top margin: %d lines",
- page_top);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Top margin not set or invalid, use 0 lines");
+ page_top = 0;
}
+ else
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Top margin: %d lines",
+ page_top);
}
if ((val = cupsGetOption("PageBottom",
val += 7;
page_bottom = atoi(val);
}
- if (log)
+ if (page_bottom < 0 || page_bottom > num_lines - 1)
{
- if (page_bottom < 0 || page_bottom > num_lines - 1)
- {
- log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Bottom margin not set or invalid, use 0 lines");
- page_bottom = 0;
- }
- else
- if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Bottom margin: %d lines",
- page_bottom);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Bottom margin not set or invalid, use 0 lines");
+ page_bottom = 0;
}
+ else
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Bottom margin: %d lines",
+ page_bottom);
}
if (log) log(ld, CF_LOGLEVEL_DEBUG,
text_width = num_columns - page_left - page_right;
text_height = num_lines - page_top - page_bottom;
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Text area: Lines per page: %d; Characters per line: %d",
- text_height, text_width);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Text area: Lines per page: %d; Characters per line: %d",
+ text_height, text_width);
strcpy(encoding, "ASCII//IGNORE");
if ((val = cupsGetOption("PrinterEncoding",
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterTextToText: Tab width not set or invalid, use default");
else
- if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Tab width: %d columns",
- tab_width);
+ log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Tab width: %d columns",
+ tab_width);
}
}
if (log) log(ld, CF_LOGLEVEL_DEBUG,
else if (is_false(val))
pagination = 0;
else
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Invalid value for pagination: %s, using default value",
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid value for pagination: %s, using default value",
val);
}
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Pagination (Print in defined pages): %s",
- (pagination ? "Yes" : "No"));
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Pagination (Print in defined pages): %s",
+ (pagination ? "Yes" : "No"));
if ((val = cupsGetOption("SendFF",
num_options, options)) != NULL ||
else if (is_false(val))
send_ff = 0;
else
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Invalid value for send-ff: %s, using default value",
- val);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid value for send-ff: %s, using default value",
+ val);
}
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Send Form Feed character at end of page: %s",
- (send_ff ? "Yes" : "No"));
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Send Form Feed character at end of page: %s",
+ (send_ff ? "Yes" : "No"));
if ((val = cupsGetOption("NewlineCharacters",
num_options, options)) != NULL ||
else if (!strcasecmp(val, "crlf"))
newline_char = CRLF;
else
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Invalid value for newline-characters: %s, using default value",
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid value for newline-characters: %s, using default value",
val);
}
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterTextToText: Characters sent to make printer start a new line: %s",
- (newline_char == LF ? "Line Feed (LF)" :
- (newline_char == CR ? "Carriage Return (CR)" :
- "Carriage Return (CR) and Line Feed (LF)")));
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Characters sent to make printer start a new line: %s",
+ (newline_char == LF ? "Line Feed (LF)" :
+ (newline_char == CR ? "Carriage Return (CR)" :
+ "Carriage Return (CR) and Line Feed (LF)")));
if ((val = cupsGetOption("page-ranges", num_options, options)) !=
NULL ||
- (ipp = ippFindAttribute(job_attrs, "page-ranges", IPP_TAG_ZERO))!=NULL) {
- if(val == NULL){
- ippAttributeString(ipp, buf, sizeof(buf));
- val = buf;
- }
+ (ipp = ippFindAttribute(job_attrs, "page-ranges", IPP_TAG_ZERO)) != NULL)
+ {
+ if (val == NULL)
+ {
+ ippAttributeString(ipp, buf, sizeof(buf));
+ val = buf;
+ }
if (val[0] != '\0')
page_ranges = strdup(val);
}
if (page_ranges)
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Page selection: %s", page_ranges);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Page selection: %s", page_ranges);
if ((val = cupsGetOption("page-set", num_options, options)) !=
NULL ||
- (ipp = ippFindAttribute(job_attrs, "page-set", IPP_TAG_ZERO))!=NULL) {
- if(val == NULL){
- ippAttributeString(ipp, buf, sizeof(buf));
- val = buf;
- }
- if (!strcasecmp(val, "even")) {
+ (ipp = ippFindAttribute(job_attrs, "page-set", IPP_TAG_ZERO)) != NULL)
+ {
+ if (val == NULL)
+ {
+ ippAttributeString(ipp, buf, sizeof(buf));
+ val = buf;
+ }
+ if (!strcasecmp(val, "even"))
+ {
even_pages = 1;
odd_pages = 0;
- } else if (!strcasecmp(val, "odd")) {
+ }
+ else if (!strcasecmp(val, "odd"))
+ {
even_pages = 0;
odd_pages = 1;
- } else if (!strcasecmp(val, "all")) {
+ }
+ else if (!strcasecmp(val, "all"))
+ {
even_pages = 1;
odd_pages = 1;
} else
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Invalid value for page-set: %s, using default value",
- val);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid value for page-set: %s, using default value",
+ val);
}
if (!even_pages || !odd_pages)
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Print %s",
- (even_pages ? "only the even pages" :
- (odd_pages ? "only the odd pages" :
- "no pages")));
+ if (log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Print %s",
+ (even_pages ? "only the even pages" :
+ (odd_pages ? "only the odd pages" :
+ "no pages")));
if ((val = cupsGetOption("OutputOrder", num_options, options)) !=
NULL ||
(val = cupsGetOption("output-order", num_options, options)) !=
NULL ||
- (ipp = ippFindAttribute(job_attrs,"output-order", IPP_TAG_ZERO))!=NULL) {
- if(val == NULL){
- ippAttributeString(ipp, buf, sizeof(buf));
- val = buf;
- }
+ (ipp = ippFindAttribute(job_attrs,"output-order", IPP_TAG_ZERO)) != NULL)
+ {
+ if (val == NULL)
+ {
+ ippAttributeString(ipp, buf, sizeof(buf));
+ val = buf;
+ }
if (!strcasecmp(val, "reverse"))
reverse_order = 1;
else
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Invalid value for OutputOrder: %s, using default value",
- val);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid value for OutputOrder: %s, using default value",
+ val);
}
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Print pages in reverse order: %s",
- (reverse_order ? "Yes" : "No"));
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Print pages in reverse order: %s",
+ (reverse_order ? "Yes" : "No"));
if ((val = cupsGetOption("Collate", num_options, options)) != NULL ||
- (ipp = ippFindAttribute(job_attrs, "collate", IPP_TAG_ZERO))!=NULL) {
- if(val == NULL){
- ippAttributeString(ipp, buf, sizeof(buf));
- val = buf;
- }
+ (ipp = ippFindAttribute(job_attrs, "collate", IPP_TAG_ZERO)) != NULL)
+ {
+ if (val == NULL)
+ {
+ ippAttributeString(ipp, buf, sizeof(buf));
+ val = buf;
+ }
if (is_true(val))
collate = 1;
else if (is_false(val))
collate = 0;
else
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Invalid value for Collate: %s, using default value",
- val);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Invalid value for Collate: %s, using default value",
+ val);
}
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Collate copies: %s",
- (collate ? "Yes" : "No"));
+ if (log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Collate copies: %s",
+ (collate ? "Yes" : "No"));
- /* Create a string to insert as the newline mark */
+ // Create a string to insert as the newline mark
if (newline_char == LF)
newline_char_str = "\n";
else if (newline_char == CR)
else if (newline_char == CRLF)
newline_char_str = "\r\n";
- /* Size of the output page in bytes (up to 4-byte-per-character)
- in the worst case, no blank lines at top and bottom, no blank right
- margin, 2 characters for newline (CR + LF) plus form feed plus closing
- zero */
+ // Size of the output page in bytes (up to 4-byte-per-character)
+ // in the worst case, no blank lines at top and bottom, no blank right
+ // margin, 2 characters for newline (CR + LF) plus form feed plus closing
+ // zero
page_size = ((num_columns + 2) * num_lines + 2) * 4;
- /* Allocate output page buffer */
+ // Allocate output page buffer
out_page = calloc(page_size, sizeof(char));
- /* Set conversion mode of iconv */
+ // Set conversion mode of iconv
cd = iconv_open(encoding, "UTF-8");
- if (cd == (iconv_t) -1) {
- /* Something went wrong. */
+ if (cd == (iconv_t) -1)
+ {
+ // Something went wrong.
if (errno == EINVAL)
{
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterTextToText: Conversion from UTF-8 to %s not available",
- encoding);
- }else
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterTextToText: Conversion from UTF-8 to %s not available",
+ encoding);
+ }
+ else
{
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterTextToText: Error setting up conversion from UTF-8 to %s",
- encoding);
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterTextToText: Error setting up conversion from UTF-8 to %s",
+ encoding);
}
goto error;
}
- /* Open the input file */
+ // Open the input file
fd = inputfd;
- if (fd < 0) {
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterTextToText: Unable to open input text file");
+ if (fd < 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterTextToText: Unable to open input text file");
goto error;
}
- /* Create an array to hold the output pages for collated copies or
- reverse output order (only when printing paginated) */
+ // Create an array to hold the output pages for collated copies or
+ // reverse output order (only when printing paginated)
if (pagination &&
- ((num_copies != 1 && collate) || reverse_order)) {
- /* Create page array */
+ ((num_copies != 1 && collate) || reverse_order))
+ // Create page array
page_array = cupsArrayNew(NULL, NULL);
- }
- /* Main loop for reading the input file, converting the encoding, formatting
- the output, and printing the pages */
+ // Main loop for reading the input file, converting the encoding, formatting
+ // the output, and printing the pages
destptr = out_page;
page_empty = 1;
page = 1;
insize = 0;
new_line_started = 0;
do {
- /* Reset input pointer */
+ // Reset input pointer
inptr = inbuf;
- /* Mark the output buffer empty */
+ // Mark the output buffer empty
outsize = sizeof(outbuf);
outptr = outbuf;
- /* Read from the input file */
+ // Read from the input file
nread = read (fd, inbuf + insize, sizeof (inbuf) - insize);
- if (nread == 0) {
- /* When we come here the file is completely read.
- This still could mean there are some unused
- characters in the inbuf, meaning that the file
- ends with an incomplete UTF-8 character. Log
- this fact. */
- if (insize > 0 && incomplete_char){
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Input text file ends with incomplete UTF-8 character sequence, file possibly incomplete, but printing the successfully read part anyway");
+ if (nread == 0)
+ {
+ // When we come here the file is completely read.
+ // This still could mean there are some unused
+ // characters in the inbuf, meaning that the file
+ // ends with an incomplete UTF-8 character. Log
+ // this fact.
+ if (insize > 0 && incomplete_char)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Input text file ends with incomplete UTF-8 character sequence, file possibly incomplete, but printing the successfully read part anyway");
}
- /* Now write out the byte sequence to get into the
- initial state if this is necessary. */
+ // Now write out the byte sequence to get into the
+ // initial state if this is necessary.
iconv (cd, NULL, NULL, &outptr, &outsize);
}
insize += nread;
- /* Convert the incoming UTF-8-encoded text to the printer's encoding */
- if (insize > 0) { /* Do we have data to convert? */
- /* Do the conversion. */
+ // Convert the incoming UTF-8-encoded text to the printer's encoding
+ if (insize > 0) // Do we have data to convert?
+ {
+ // Do the conversion.
nconv = iconv (cd, &inptr, &insize, &outptr, &outsize);
if (log && nconv == (size_t) -1)
log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterTextToText: iconv() message: %s", strerror(errno));
- if (nconv == (size_t) -1 && insize > 0) {
- /* Not everything went right. It might only be
- an unfinished byte sequence at the end of the
- output buffer. Or it is a real problem. */
- if (errno == EINVAL || errno == E2BIG) {
- /* This is harmless. Simply move the unused
- bytes to the beginning of the buffer so that
- they can be used in the next round. */
+ if (nconv == (size_t) -1 && insize > 0)
+ {
+ // Not everything went right. It might only be
+ // an unfinished byte sequence at the end of the
+ // output buffer. Or it is a real problem.
+ if (errno == EINVAL || errno == E2BIG)
+ {
+ // This is harmless. Simply move the unused
+ // bytes to the beginning of the buffer so that
+ // they can be used in the next round.
if (errno == EINVAL)
incomplete_char = 1;
memmove (inbuf, inptr, insize);
- } else {
- /* We found an illegal UTF-8 byte sequence here,
- so error out at this point. */
- if(log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterTextToText: Illegal UTF-8 sequence found. Input file perhaps not UTF-8-encoded");
+ }
+ else
+ {
+ // We found an illegal UTF-8 byte sequence here,
+ // so error out at this point.
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterTextToText: Illegal UTF-8 sequence found. Input file perhaps not UTF-8-encoded");
result = -1;
break;
}
}
}
- /* Process the output to generate the output pages */
- if (outptr == outbuf) /* End of input file */
+ // Process the output to generate the output pages
+ if (outptr == outbuf) // End of input file
*(outptr ++) = '\0';
- for (procptr = outbuf; procptr < outptr; procptr ++) {
- if ((column >= text_width && /* Current line is full */
+ for (procptr = outbuf; procptr < outptr; procptr ++)
+ {
+ if ((column >= text_width && // Current line is full
*procptr != '\n' && *procptr != '\r' && *procptr != '\f') ||
- /* Next character is not newline or
- formfeed */
- (outbuf[0] == '\0' && column > 0)) { /* End of input file */
+ // Next character is not newline or
+ // formfeed
+ (outbuf[0] == '\0' && column > 0)) // End of input file
+ {
if (overlong_lines == TRUNCATE && outbuf[0] != '\0')
skip_rest_of_line = 1;
- else {
- if (overlong_lines == WORDWRAP && outbuf[0] != '\0') {
- if (*procptr > ' ') {
+ else
+ {
+ if (overlong_lines == WORDWRAP && outbuf[0] != '\0')
+ {
+ if (*procptr > ' ')
+ {
*destptr = '\0';
for (p = destptr - 1, i = column - 1; *p != ' ' && i >= 0;
p --, i--);
- if (i >= 0 && i < column - 1) {
+ if (i >= 0 && i < column - 1)
+ {
wrapped_word = strdup(p + 1);
for (; *p == ' ' && i >= 0; p --, i--);
if (*p != ' ' && i >= 0)
destptr = p + 1;
- else {
+ else
+ {
free(wrapped_word);
wrapped_word = NULL;
}
} else
skip_spaces = 1;
}
- /* Remove trailing whitespace */
+ // Remove trailing whitespace
while (destptr > out_page && *(destptr - 1) == ' ')
destptr --;
- /* Put newline character(s) */
+ // Put newline character(s)
for (j = 0; newline_char_str[j]; j ++)
*(destptr ++) = newline_char_str[j];
- /* Position cursor in next line */
+ // Position cursor in next line
line ++;
column = 0;
new_line_started = 0;
}
}
- if ((line >= text_height && /* Current page is full */
- *procptr != '\f') || /* Next character is not formfeed */
- outbuf[0] == '\0' ) { /* End of input file */
- /* Do we actually print this page? */
+ if ((line >= text_height && // Current page is full
+ *procptr != '\f') || // Next character is not formfeed
+ outbuf[0] == '\0' ) // End of input file
+ {
+ // Do we actually print this page?
if (!pagination ||
- check_range(page_ranges, even_pages, odd_pages, page)) {
- /* Finalize the page */
- if (pagination) {
- if (send_ff) {
+ check_range(page_ranges, even_pages, odd_pages, page))
+ {
+ // Finalize the page
+ if (pagination)
+ {
+ if (send_ff)
+ {
if (page_empty)
- destptr = out_page; /* Remove unneeded white space */
- /* Send Form Feed */
+ destptr = out_page; // Remove unneeded white space
+ // Send Form Feed
*(destptr ++) = '\f';
- } else if (outbuf[0] != '\0') {
- /* Fill up page with blank lines */
+ }
+ else if (outbuf[0] != '\0')
+ {
+ // Fill up page with blank lines
for (i = 0; i < page_bottom; i ++)
for (j = 0; newline_char_str[j]; j ++)
*(destptr ++) = newline_char_str[j];
}
}
- /* Allow to handle the finished page as a C string */
+ // Allow to handle the finished page as a C string
*(destptr ++) = '\0';
- /* Count pages which will actually get printed */
+ // Count pages which will actually get printed
num_pages ++;
- if (!pagination) {
- /* Log the page output (only once, when printing the first buffer
- load) */
+ if (!pagination)
+ {
+ // Log the page output (only once, when printing the first buffer
+ // load)
if (num_pages == 1)
{
- if(log) log(ld, CF_LOGLEVEL_CONTROL, "PAGE: 1 1");
+ if (log) log(ld, CF_LOGLEVEL_CONTROL, "PAGE: 1 1");
}
cupsFilePuts(outputfp, out_page);
- } else if ((num_copies == 1 || !collate) && !reverse_order) {
-
- /* Log the page output */
- if(log) log(ld, CF_LOGLEVEL_CONTROL, "PAGE: %d %d", num_pages, num_copies);
+ }
+ else if ((num_copies == 1 || !collate) && !reverse_order)
+ {
+ // Log the page output
+ if (log) log(ld, CF_LOGLEVEL_CONTROL,
+ "PAGE: %d %d", num_pages, num_copies);
cupsFilePuts(outputfp, out_page);
- } else {
- /* Save the page in the page array */
+ }
+ else
+ {
+ // Save the page in the page array
cupsArrayAdd(page_array, strdup(out_page));
}
}
- /* Reset for next page */
+ // Reset for next page
destptr = out_page;
page_empty = 1;
line = 0;
new_line_started = 0;
page ++;
}
- if (outbuf[0] == '\0') /* End of input file */
+ if (outbuf[0] == '\0') // End of input file
break;
- if (column == 0 && !new_line_started) { /* Start of new line */
+ if (column == 0 && !new_line_started) // Start of new line
+ {
new_line_started = 1;
- if (line == 0 && pagination) /* Start of new page */
+ if (line == 0 && pagination) // Start of new page
for (i = 0; i < page_top; i ++)
for (j = 0; newline_char_str[j]; j ++)
*(destptr ++) = newline_char_str[j];
for (i = 0; i < page_left; i ++)
*(destptr ++) = ' ';
- /* Did we wrap a word from the previous line? */
- if (wrapped_word) {
+ // Did we wrap a word from the previous line?
+ if (wrapped_word)
+ {
for (p = wrapped_word; *p != '\0'; p ++, column ++)
*(destptr ++) = *p;
free(wrapped_word);
skip_spaces = 0;
}
}
- if (*procptr == '\r' || *procptr == '\n') { /* CR or LF */
- /* Only write newline if we are not on the LF of a CR+LF */
- if (*procptr == '\r' || previous_is_cr == 0) {
- /* Remove trailing whitespace */
+ if (*procptr == '\r' || *procptr == '\n') // CR or LF
+ {
+ // Only write newline if we are not on the LF of a CR+LF
+ if (*procptr == '\r' || previous_is_cr == 0)
+ {
+ // Remove trailing whitespace
while (destptr > out_page && *(destptr - 1) == ' ')
destptr --;
- /* Put newline character(s) */
+ // Put newline character(s)
for (j = 0; newline_char_str[j]; j ++)
*(destptr ++) = newline_char_str[j];
- /* Position cursor in next line */
+ // Position cursor in next line
line ++;
column = 0;
new_line_started = 0;
- /* Finished truncating an overlong line */
+ // Finished truncating an overlong line
skip_rest_of_line = 0;
skip_spaces = 0;
}
previous_is_cr = 1;
else
previous_is_cr = 0;
- } else {
+ }
+ else
+ {
previous_is_cr = 0;
- if (*procptr == '\t') { /* Tab character */
- if (!skip_rest_of_line && !skip_spaces) {
- *(destptr ++) = ' '; /* Always at least one space */
+ if (*procptr == '\t') // Tab character
+ {
+ if (!skip_rest_of_line && !skip_spaces)
+ {
+ *(destptr ++) = ' '; // Always at least one space
column ++;
- /* Add spaces to reach next multiple of the tab width */
+ // Add spaces to reach next multiple of the tab width
for (; column % tab_width != 0 && column < text_width; column ++)
*(destptr ++) = ' ';
}
- } else if (*procptr == '\f') { /* Form feed */
- /* Skip to end of page */
+ }
+ else if (*procptr == '\f') // Form feed
+ {
+ // Skip to end of page
if (send_ff)
- /* Mark page full */
+ // Mark page full
line = text_height;
else if (pagination)
- /* Fill page with newlines */
+ // Fill page with newlines
for (; line < text_height; line ++)
for (j = 0; newline_char_str[j]; j ++)
*(destptr ++) = newline_char_str[j];
column = 0;
new_line_started = 0;
- /* Finished truncating an overlong line */
+ // Finished truncating an overlong line
skip_rest_of_line = 0;
skip_spaces = 0;
- } else if (*procptr == ' ') { /* Space */
- if (!skip_rest_of_line && !skip_spaces) {
+ }
+ else if (*procptr == ' ') // Space
+ {
+ if (!skip_rest_of_line && !skip_spaces)
+ {
*(destptr ++) = *procptr;
column ++;
}
- } else if (*procptr > ' ' || *procptr < '\0') { /* Regular character */
- if (!skip_rest_of_line) {
+ }
+ else if (*procptr > ' ' || *procptr < '\0') // Regular character
+ {
+ if (!skip_rest_of_line)
+ {
*(destptr ++) = *procptr;
column ++;
page_empty = 0;
}
}
}
- } while (outbuf[0] != '\0'); /* End of input file */
+ }
+ while (outbuf[0] != '\0'); // End of input file
close(fd);
if (iconv_close (cd) != 0)
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterTextToText: Error closing iconv encoding conversion session");
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterTextToText: Error closing iconv encoding conversion session");
- /* Error out on an illegal UTF-8 sequence in the input file */
+ // Error out on an illegal UTF-8 sequence in the input file
if (result < 0)
goto error;
- /* Print out the page array if we created one */
+ // Print out the page array if we created one
if (pagination &&
- ((num_copies != 1 && collate) || reverse_order)) {
- /* If we print collated copies, the outer loop (i) goes through the
- copies, if we do not collate, the inner loop (j) goes through the
- copies. The other loop only runs for one cycle. */
+ ((num_copies != 1 && collate) || reverse_order))
+ {
+ // If we print collated copies, the outer loop (i) goes through the
+ // copies, if we do not collate, the inner loop (j) goes through the
+ // copies. The other loop only runs for one cycle.
for (i = 0; i < (collate ? num_copies : 1); i ++)
for (page = (reverse_order ? num_pages : 1);
(reverse_order ? (page >= 1) : (page <= num_pages));
- page += (reverse_order ? -1 : 1)) {
+ page += (reverse_order ? -1 : 1))
+ {
p = (char *)cupsArrayIndex(page_array, page - 1);
- if(log) log(ld, CF_LOGLEVEL_INFO, "cfFilterTextToText: %d %d", page, (collate ? 1 : num_copies));
+ if (log) log(ld, CF_LOGLEVEL_INFO,
+ "cfFilterTextToText: %d %d", page, (collate ? 1 : num_copies));
}
- /* Clean up */
- for (page = 0; page < num_pages; page ++) {
+ // Clean up
+ for (page = 0; page < num_pages; page ++)
+ {
p = (char *)cupsArrayIndex(page_array, page);
free(p);
}
cupsArrayDelete(page_array);
}
- /*
- * Cleanup and exit...
- */
+ //
+ // Cleanup and exit...
+ //
error:
- if(outputfp)
+ if (outputfp)
cupsFileClose(outputfp);
free(page_ranges);
}
-/*
- * 'is_true()' - Check option value for boolean true
- */
+//
+// 'is_true()' - Check option value for boolean true
+//
-static int is_true(const char *value)
+static int
+is_true(const char *value)
{
if (!value)
- return 0;
- return (strcasecmp(value, "yes") == 0) ||
- (strcasecmp(value, "on") == 0) ||
- (strcasecmp(value, "true") == 0) ||
- (strcasecmp(value, "1") == 0);
+ return (0);
+ return ((strcasecmp(value, "yes") == 0) ||
+ (strcasecmp(value, "on") == 0) ||
+ (strcasecmp(value, "true") == 0) ||
+ (strcasecmp(value, "1") == 0));
}
-/*
- * 'is_false()' - Check option value for boolean false
- */
+//
+// 'is_false()' - Check option value for boolean false
+//
-static int is_false(const char *value)
+static int
+is_false(const char *value)
{
if (!value)
- return 0;
- return (strcasecmp(value, "no") == 0) ||
- (strcasecmp(value, "off") == 0) ||
- (strcasecmp(value, "false") == 0) ||
- (strcasecmp(value, "0") == 0);
+ return (0);
+ return ((strcasecmp(value, "no") == 0) ||
+ (strcasecmp(value, "off") == 0) ||
+ (strcasecmp(value, "false") == 0) ||
+ (strcasecmp(value, "0") == 0));
}
-/*
- * 'check_range()' - Check to see if the current page is selected for
- * printing.
- */
+//
+// 'check_range()' - Check to see if the current page is selected for
+// printing.
+//
-static int /* O - 1 if selected, 0 otherwise */
-check_range(char *page_ranges, /* I - Selection of pages to print */
- int even_pages, /* I - Print the even pages */
- int odd_pages, /* I - Print the odd pages */
- int page) /* I - Page number */
+static int // O - 1 if selected, 0 otherwise
+check_range(char *page_ranges, // I - Selection of pages to print
+ int even_pages, // I - Print the even pages
+ int odd_pages, // I - Print the odd pages
+ int page) // I - Page number
{
- const char *range; /* Pointer into range string */
- int lower, upper; /* Lower and upper page numbers */
+ const char *range; // Pointer into range string
+ int lower, upper; // Lower and upper page numbers
- /*
- * See if we only print even or odd pages...
- */
+ //
+ // See if we only print even or odd pages...
+ //
if (!odd_pages && (page & 1))
return (0);
if (!even_pages && !(page & 1))
return (0);
- /*
- * page-ranges option
- */
-
+ //
+ // page-ranges option
+ //
+
if (!page_ranges || page_ranges[0] == '\0')
- return (1); /* No range, print all pages... */
+ return (1); // No range, print all pages...
for (range = page_ranges; *range != '\0';)
{
return (0);
}
-
-/*
- * End
- */
#include <limits.h>
#include <cups/cups.h>
-int /* O - Error status */
-cfFilterUniversal(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters
- (input/output format) */
+int // O - Error status
+cfFilterUniversal(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
{
char *input;
char *final_output;
"cfFilterUniversal: Adding %s to chain", filter->name);
}
else
-#endif /* HAVE_GHOSTSCRIPT */
+#endif // HAVE_GHOSTSCRIPT
if (!strcasecmp(input_super, "text") ||
(!strcasecmp(input_super, "application") && input_type[0] == 'x'))
{
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterUniversal: Adding %s to chain", filter->name);
}
-#endif /* HAVE_GHOSTSCRIPT */
+#endif // HAVE_GHOSTSCRIPT
else if (!strcasecmp(input, "application/vnd.cups-pdf-banner"))
{
filter = malloc(sizeof(cf_filter_filter_in_chain_t));
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterUniversal: Adding %s to chain", filter->name);
}
-# endif /* HAVE_POPPLER_PDFTOPS */
-# endif /* HAVE_GHOSTSCRIPT */
+# endif // HAVE_POPPLER_PDFTOPS
+# endif // HAVE_GHOSTSCRIPT
}
else
{
-#endif /* HAVE_GHOSTSCRIPT || HAVE_POPPLER_PDFTOPS */
+#endif // HAVE_GHOSTSCRIPT || HAVE_POPPLER_PDFTOPS
// Output format is not PDF and unknown -> Error
ret = 1;
goto out;
#if defined(HAVE_GHOSTSCRIPT) || defined(HAVE_POPPLER_PDFTOPS)
}
}
-#endif /* HAVE_GHOSTSCRIPT || HAVE_POPPLER_PDFTOPS */
+#endif // HAVE_GHOSTSCRIPT || HAVE_POPPLER_PDFTOPS
}
}
input, output);
}
else
- /* Do the dirty work ... */
+ // Do the dirty work ...
ret = cfFilterChain(inputfd, outputfd, inputseekable, data, filter_chain);
for (filter = (cf_filter_filter_in_chain_t *)cupsArrayFirst(filter_chain);