/*
* 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)
{
return in_opt;
}
- opt_t *entry = malloc(sizeof(opt_t));
+ cf_opt_t *entry = malloc(sizeof(cf_opt_t));
if (!entry)
{
return in_opt;
*
* 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,
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];
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;
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",
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);
}
{
if (log)
log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Cannot create temp file: %s\n", strerror(errno));
- pdf_free(doc);
+ cfPDFFree(doc);
return 1;
}
#endif
#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,
* 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");
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;
}
free(buf);
- pdf_free(doc);
+ cfPDFFree(doc);
return 0;
}
}
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,
/**
- * '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 {
/**
- * '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;
/**
- * '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)
/**
- * '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)
{
/**
- * '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,
/**
- * '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)
{
/**
- * '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();
}
/*
* '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 "";
}
/*
- * '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
// 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<QPDFPageObjectHelper> pages = pdh.getAllPages();
if (pages.empty())
return 1;
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef pdf_h
-#define pdf_h
+#ifndef _CUPS_FILTERS_PDF_H_
+#define _CUPS_FILTERS_PDF_H_
#include <stdio.h>
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_ */
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.");