From ea5f2149fb869c481e88c957d62318f59a6d3192 Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Wed, 6 Apr 2022 23:15:52 +0200 Subject: [PATCH] libcupsfilters: Rename API functions of pdf.h to "cf..." Also renamed constants to start with "CF_" and data types to start with "cf_". --- cupsfilters/bannertopdf.c | 38 ++++++++++++------------- cupsfilters/ghostscript.c | 2 +- cupsfilters/pdf.cxx | 58 +++++++++++++++++++-------------------- cupsfilters/pdf.h | 36 ++++++++++++------------ cupsfilters/pdftops.c | 2 +- 5 files changed, 69 insertions(+), 67 deletions(-) diff --git a/cupsfilters/bannertopdf.c b/cupsfilters/bannertopdf.c index 4241ecd59..8ed496524 100644 --- a/cupsfilters/bannertopdf.c +++ b/cupsfilters/bannertopdf.c @@ -530,7 +530,7 @@ static const char *human_time(const char *timestamp) /* * Add new key & value. */ -static opt_t *add_opt(opt_t *in_opt, const char *key, const char *val) +static cf_opt_t *add_opt(cf_opt_t *in_opt, const char *key, const char *val) { if (!key || !val) { @@ -542,7 +542,7 @@ static opt_t *add_opt(opt_t *in_opt, const char *key, const char *val) return in_opt; } - opt_t *entry = malloc(sizeof(opt_t)); + cf_opt_t *entry = malloc(sizeof(cf_opt_t)); if (!entry) { return in_opt; @@ -561,7 +561,7 @@ static opt_t *add_opt(opt_t *in_opt, const char *key, const char *val) * * Create PDF form's field names according above. */ -opt_t *get_known_opts( +cf_opt_t *get_known_opts( cf_filter_data_t *data, const char *jobid, const char *user, @@ -573,7 +573,7 @@ opt_t *get_known_opts( ppd_file_t *ppd = data->ppd; ppd_attr_t *attr; - opt_t *opt = NULL; + cf_opt_t *opt = NULL; ipp_t *printer_attrs = data->printer_attrs; ipp_attribute_t *ipp_attr; char buf[1024]; @@ -730,7 +730,7 @@ static int generate_banner_pdf(banner_t *banner, char *buf; size_t len; FILE *s; - pdf_t *doc; + cf_pdf_t *doc; float page_width, page_length; float media_limits[4]; float page_scale; @@ -745,7 +745,7 @@ static int generate_banner_pdf(banner_t *banner, struct stat st; #endif - if (!(doc = pdf_load_template(banner->template_file))) + if (!(doc = cfPDFLoadTemplate(banner->template_file))) { if (log) log(ld, CF_LOGLEVEL_ERROR, "PDF template must exist and contain exactly 1 page: %s", @@ -756,19 +756,19 @@ static int generate_banner_pdf(banner_t *banner, get_pagesize(data, noptions, options, &page_width, &page_length, media_limits); - if (pdf_resize_page(doc, 1, page_width, page_length, &page_scale) != 0) + if (cfPDFResizePage(doc, 1, page_width, page_length, &page_scale) != 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "Unable to resize requested PDF page"); - pdf_free(doc); + cfPDFFree(doc); return (1); } - if (pdf_add_type1_font(doc, 1, "Courier") != 0) + if (cfPDFAddType1Font(doc, 1, "Courier") != 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "Unable to add type1 font to requested PDF page"); - pdf_free(doc); + cfPDFFree(doc); return (1); } @@ -779,7 +779,7 @@ static int generate_banner_pdf(banner_t *banner, { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Cannot create temp file: %s\n", strerror(errno)); - pdf_free(doc); + cfPDFFree(doc); return 1; } #endif @@ -948,7 +948,7 @@ static int generate_banner_pdf(banner_t *banner, #endif /* !HAVE_OPEN_MEMSTREAM */ fclose(s); - opt_t *known_opts = get_known_opts(data, + cf_opt_t *known_opts = get_known_opts(data, jobid, user, jobtitle, @@ -959,13 +959,13 @@ static int generate_banner_pdf(banner_t *banner, * Try to find a PDF form in PDF template and fill it. */ - if (pdf_fill_form(doc, known_opts) != 0) + if (cfPDFFillForm(doc, known_opts) != 0) { /* * Could we fill a PDF form? If no, just add PDF stream. */ - if (pdf_prepend_stream(doc, 1, buf, len) != 0) + if (cfPDFPrependStream(doc, 1, buf, len) != 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "Unable to prepend stream to requested PDF page"); @@ -979,17 +979,17 @@ static int generate_banner_pdf(banner_t *banner, if (copies > 1) { - if (pdf_duplicate_page(doc, 1, copies - 1) != 0) + if (cfPDFDuplicatePage(doc, 1, copies - 1) != 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "Unable to duplicate requested PDF page"); } } - pdf_write(doc, outputfp); + cfPDFWrite(doc, outputfp); - opt_t *opt_current = known_opts; - opt_t *opt_next = NULL; + cf_opt_t *opt_current = known_opts; + cf_opt_t *opt_next = NULL; while (opt_current != NULL) { opt_next = opt_current->next; @@ -998,7 +998,7 @@ static int generate_banner_pdf(banner_t *banner, } free(buf); - pdf_free(doc); + cfPDFFree(doc); return 0; } diff --git a/cupsfilters/ghostscript.c b/cupsfilters/ghostscript.c index 9eab20d17..ec1a71dea 100644 --- a/cupsfilters/ghostscript.c +++ b/cupsfilters/ghostscript.c @@ -888,7 +888,7 @@ cfFilterGhostscript(int inputfd, /* I - File descriptor input } if (doc_type == GS_DOC_TYPE_PDF) { - int pages = pdf_pages_fp(fp); + int pages = cfPDFPagesFP(fp); if (pages == 0) { if (log) log(ld, CF_LOGLEVEL_DEBUG, diff --git a/cupsfilters/pdf.cxx b/cupsfilters/pdf.cxx index 97a9b8fe3..2102161d8 100644 --- a/cupsfilters/pdf.cxx +++ b/cupsfilters/pdf.cxx @@ -54,11 +54,11 @@ static QPDFObjectHandle makeRealBox(float values[4]) /** - * 'pdf_load_template()' - Load an existing PDF file and do initial parsing + * 'cfPDFLoadTemplate()' - Load an existing PDF file and do initial parsing * using QPDF. * I - Filename to open */ -extern "C" pdf_t * pdf_load_template(const char *filename) +extern "C" cf_pdf_t * cfPDFLoadTemplate(const char *filename) { QPDF *pdf = new QPDF(); try { @@ -80,55 +80,55 @@ extern "C" pdf_t * pdf_load_template(const char *filename) /** - * 'pdf_free()' - Free pointer used by PDF object + * 'cfPDFFree()' - Free pointer used by PDF object * I - Pointer to PDF object */ -extern "C" void pdf_free(pdf_t *pdf) +extern "C" void cfPDFFree(cf_pdf_t *pdf) { delete pdf; } /* - * 'pdf_pages()' - Count number of pages in file + * 'cfPDFPages()' - Count number of pages in file * using QPDF. * I - Filename to open * O - Number of pages or -1 on error */ -int pdf_pages(const char *filename) +int cfPDFPages(const char *filename) { QPDF *pdf = new QPDF(); if (pdf) { try{ pdf->processFile(filename); } catch(...) { - pdf_free(pdf); + cfPDFFree(pdf); return -1; } int pages = (pdf->getAllPages()).size(); - pdf_free(pdf); + cfPDFFree(pdf); return pages; } else return -1; } /* - * 'pdf_pages_fp()' - Count number of pages in file + * '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 pdf_pages_fp(FILE *file) +int cfPDFPagesFP(FILE *file) { QPDF *pdf = new QPDF(); if (pdf) { try{ pdf->processFile("", file, false); } catch(...) { - pdf_free(pdf); + cfPDFFree(pdf); return -1; } int pages = (pdf->getAllPages()).size(); - pdf_free(pdf); + cfPDFFree(pdf); return pages; } else return -1; @@ -136,14 +136,14 @@ int pdf_pages_fp(FILE *file) /** - * 'pdf_prepend_stream' - Prepend a stream to the contents of a specified + * '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 pdf_prepend_stream(pdf_t *pdf, +extern "C" int cfPDFPrependStream(cf_pdf_t *pdf, unsigned page_num, char const *buf, size_t len) @@ -182,13 +182,13 @@ extern "C" int pdf_prepend_stream(pdf_t *pdf, /** - * 'pdf_add_type1_font()' - Add the specified type1 fontface to the specified + * '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 pdf_add_type1_font(pdf_t *pdf, +extern "C" int cfPDFAddType1Font(cf_pdf_t *pdf, unsigned page_num, const char *name) { @@ -294,14 +294,14 @@ static void fit_rect(float oldrect[4], /** - * 'pdf_resize_page()' - Resize page in a PDF with the given dimensions. + * '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 pdf_resize_page (pdf_t *pdf, +extern "C" int cfPDFResizePage (cf_pdf_t *pdf, unsigned page_num, float width, float length, @@ -333,12 +333,12 @@ extern "C" int pdf_resize_page (pdf_t *pdf, /** - * 'pdf_duplicate_page()' - Duplicate a specified pdf page in a PDF + * '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 pdf_duplicate_page (pdf_t *pdf, +extern "C" int cfPDFDuplicatePage (cf_pdf_t *pdf, unsigned page_num, unsigned count) { @@ -358,13 +358,13 @@ extern "C" int pdf_duplicate_page (pdf_t *pdf, /** - * 'pdf_write()' - Write the contents of PDF object to an already open FILE*. + * '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 pdf_write(pdf_t *pdf, FILE *file) +extern "C" void cfPDFWrite(cf_pdf_t *pdf, FILE *file) { - QPDFWriter output(*pdf, "pdf_write", file, false); + QPDFWriter output(*pdf, "cfPDFWrite", file, false); output.write(); } @@ -372,12 +372,12 @@ extern "C" void pdf_write(pdf_t *pdf, FILE *file) /* * 'lookup_opt()' - Get value according to key in the options list. - * I - pointer to the opt_t type 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. */ -std::string lookup_opt(opt_t *opt, std::string const& key) { +std::string lookup_opt(cf_opt_t *opt, std::string const& key) { if ( ! opt || key.empty() ) { return ""; } @@ -396,14 +396,14 @@ std::string lookup_opt(opt_t *opt, std::string const& key) { /* - * 'pdf_fill_form()' - 1. Lookup in PDF template file for form. + * '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 opt_t type list + * I - Pointer to the cf_opt_t type list * O - status of form fill - 0 for success, 1 for failure */ -extern "C" int pdf_fill_form(pdf_t *doc, opt_t *opt) +extern "C" int cfPDFFillForm(cf_pdf_t *doc, cf_opt_t *opt) { // initialize AcroFormDocumentHelper and PageDocumentHelper objects // to work with forms in the PDF @@ -416,7 +416,7 @@ extern "C" int pdf_fill_form(pdf_t *doc, opt_t *opt) // 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 `pdf_load_template()` function + // check has already been performed in the `cfPDFLoadTemplate()` function std::vector pages = pdh.getAllPages(); if (pages.empty()) return 1; diff --git a/cupsfilters/pdf.h b/cupsfilters/pdf.h index e6b4042ce..2ed09166e 100644 --- a/cupsfilters/pdf.h +++ b/cupsfilters/pdf.h @@ -15,8 +15,8 @@ * with this program. If not, see . */ -#ifndef pdf_h -#define pdf_h +#ifndef _CUPS_FILTERS_PDF_H_ +#define _CUPS_FILTERS_PDF_H_ #include @@ -24,32 +24,34 @@ extern "C" { #endif -typedef struct QPDF pdf_t; +typedef struct QPDF cf_pdf_t; -typedef struct _opt opt_t; +typedef struct _cf_opt cf_opt_t; /* * Type to bunch PDF form field name and its value. */ -struct _opt { +struct _cf_opt { const char* key; const char* val; - opt_t *next; + cf_opt_t *next; }; -pdf_t * pdf_load_template(const char *filename); -void pdf_free(pdf_t *pdf); -void pdf_write(pdf_t *doc, FILE *file); -int pdf_prepend_stream(pdf_t *doc, unsigned page, char const *buf, size_t len); -int pdf_add_type1_font(pdf_t *doc, unsigned page, const char *name); -int pdf_resize_page(pdf_t *doc, unsigned page, float width, float length, float *scale); -int pdf_duplicate_page (pdf_t *doc, unsigned page, unsigned count); -int pdf_fill_form(pdf_t *doc, opt_t *opt); -int pdf_pages(const char *filename); -int pdf_pages_fp(FILE *file); +cf_pdf_t *cfPDFLoadTemplate(const char *filename); +void cfPDFFree(cf_pdf_t *pdf); +void cfPDFWrite(cf_pdf_t *doc, FILE *file); +int cfPDFPrependStream(cf_pdf_t *doc, unsigned page, char const *buf, + size_t len); +int cfPDFAddType1Font(cf_pdf_t *doc, unsigned page, const char *name); +int cfPDFResizePage(cf_pdf_t *doc, unsigned page, float width, float length, + float *scale); +int cfPDFDuplicatePage(cf_pdf_t *doc, unsigned page, unsigned count); +int cfPDFFillForm(cf_pdf_t *doc, cf_opt_t *opt); +int cfPDFPages(const char *filename); +int cfPDFPagesFP(FILE *file); #ifdef __cplusplus } #endif -#endif +#endif /* !_CUPS_FILTERS_PDF_H_ */ diff --git a/cupsfilters/pdftops.c b/cupsfilters/pdftops.c index 17f2ffd8c..bd03ad7ea 100644 --- a/cupsfilters/pdftops.c +++ b/cupsfilters/pdftops.c @@ -190,7 +190,7 @@ is_empty(char *filename, /* I - Input file */ return 1; } fclose(fp); - int pages = pdf_pages(filename); + int pages = cfPDFPages(filename); if (pages == 0) { if (log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterPDFToPS: No pages left, outputting empty file."); -- 2.47.3