//
// Copyright 2012 Canonical Ltd.
// Copyright 2018 Sahil Arora <sahilarora.535@gmail.com>
// Copyright 2024-2026 Uddhav Phatak <uddhavphatak@gmail.com>
//
// Licensed under Apache License v2.0.  See the file "LICENSE" for more
// information.
//

#ifndef _CUPS_FILTERS_PDF_H_
#define _CUPS_FILTERS_PDF_H_

#include <stdio.h>
#include <pdfio.h>

// cf_pdf_t is an opaque data type. It is supposed to be only used with the
// functions of the cfPDF... API which is defined in this file (pdf.h). Its
// internal structure is not expected to be used directly.
//
// Due to this the name after "struct" is meaningless. We keep the "QPDF" here
// to satisfy automatic checkers of the API used by the packaging and build
// server infrastructure of operating system distributions. This way we do not
// need to bump the soname for this meaningless symbol.
typedef struct pdfio_file_t cf_pdf_t;

typedef struct _cf_opt cf_opt_t;

//
// Type to bunch PDF form field name and its value.
//

struct _cf_opt
{
  const char* key;
  const char* val;
  cf_opt_t *next;
};

typedef struct iterate_data_s
{
  cf_pdf_t 	*pdf;
  pdfio_dict_t	*page_dict;
  pdfio_dict_t  *page_resdict;
}iterate_data_t;

cf_pdf_t* cfPDFLoadTemplate(const char *filename);

cf_pdf_t* cfCopyPDFdoc(cf_pdf_t *input_doc, FILE *output_file, iterate_data_t *iterate_helper );

void cfPDFFree(cf_pdf_t *pdf);

void cfPDFWrite(cf_pdf_t *doc, 
		FILE *file);

int cfPDFPrependStream(cf_pdf_t *doc, 
		       unsigned page, 
		       const char *buf, 
		       size_t len);

int cfPDFPrependStream1(cf_pdf_t *doc, 
		        iterate_data_t *iterate_helper,
		       	unsigned page, 
			const char *buf, 
			size_t len);

int cfPDFAddType1Font(cf_pdf_t *doc, 
		      unsigned page, 
		      const char *name);

int cfPDFAddType1Font1(cf_pdf_t *doc, 
		       iterate_data_t *iterate_helper,
		       unsigned page, 
		       const char *name);

int cfPDFResizePage(cf_pdf_t *doc, 
		    unsigned page, 
		    float width, 
		    float length, 
		    float *scale);

int cfPDFResizePage1(cf_pdf_t *doc, 
		     iterate_data_t *iterate_helper,
		     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);

#endif // !_CUPS_FILTERS_PDF_H_

