writer.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef MUPDF_FITZ_WRITER_H
  2. #define MUPDF_FITZ_WRITER_H
  3. #include "mupdf/fitz/system.h"
  4. #include "mupdf/fitz/context.h"
  5. #include "mupdf/fitz/output.h"
  6. #include "mupdf/fitz/document.h"
  7. #include "mupdf/fitz/device.h"
  8. typedef struct fz_document_writer_s fz_document_writer;
  9. /*
  10. fz_document_writer_begin_page_fn: Function type to start
  11. the process of writing a page to a document.
  12. mediabox: page size rectangle in points.
  13. Returns a fz_device to write page contents to.
  14. */
  15. typedef fz_device *(fz_document_writer_begin_page_fn)(fz_context *ctx, fz_document_writer *wri, const fz_rect *mediabox);
  16. /*
  17. fz_document_writer_end_page_fn: Function type to end the
  18. process of writing a page to a document.
  19. dev: The device created by the begin_page function.
  20. */
  21. typedef void (fz_document_writer_end_page_fn)(fz_context *ctx, fz_document_writer *wri, fz_device *dev);
  22. /*
  23. fz_document_writer_close_writer_fn: Function type to end
  24. the process of writing pages to a document.
  25. This writes any file level trailers required. After this
  26. completes successfully the file is up to date and complete.
  27. */
  28. typedef void (fz_document_writer_close_writer_fn)(fz_context *ctx, fz_document_writer *wri);
  29. /*
  30. fz_document_writer_drop_writer_fn: Function type to discard
  31. an fz_document_writer. This may be called at any time during
  32. the process to release all the resources owned by the writer.
  33. Calling drop without having previously called close may leave
  34. the file in an inconsistent state.
  35. */
  36. typedef void (fz_document_writer_drop_writer_fn)(fz_context *ctx, fz_document_writer *wri);
  37. /*
  38. Structure is public to allow other structures to
  39. be derived from it. Do not access members directly.
  40. */
  41. struct fz_document_writer_s
  42. {
  43. fz_document_writer_begin_page_fn *begin_page;
  44. fz_document_writer_end_page_fn *end_page;
  45. fz_document_writer_close_writer_fn *close_writer;
  46. fz_document_writer_drop_writer_fn *drop_writer;
  47. fz_device *dev;
  48. };
  49. /*
  50. fz_new_document_writer_of_size: Internal function to allocate a
  51. block for a derived document_writer structure, with the base
  52. structure's function pointers populated correctly, and the extra
  53. space zero initialised.
  54. */
  55. fz_document_writer *fz_new_document_writer_of_size(fz_context *ctx, size_t size, fz_document_writer_begin_page_fn *begin_page,
  56. fz_document_writer_end_page_fn *end_page, fz_document_writer_close_writer_fn *close, fz_document_writer_drop_writer_fn *drop);
  57. #define fz_new_derived_document_writer(CTX,TYPE,BEGIN_PAGE,END_PAGE,CLOSE,DROP) \
  58. ((TYPE *)Memento_label(fz_new_document_writer_of_size(CTX,sizeof(TYPE),BEGIN_PAGE,END_PAGE,CLOSE,DROP),#TYPE))
  59. int fz_has_option(fz_context *ctx, const char *opts, const char *key, const char **val);
  60. int fz_option_eq(const char *a, const char *b);
  61. /*
  62. fz_new_document_writer: Create a new fz_document_writer, for a
  63. file of the given type.
  64. path: The document name to write (or NULL for default)
  65. format: Which format to write (currently cbz, pdf, pam, pbm,
  66. pgm, pkm, png, ppm, pnm, svg, tga)
  67. options: NULL, or pointer to comma separated string to control
  68. file generation.
  69. */
  70. fz_document_writer *fz_new_document_writer(fz_context *ctx, const char *path, const char *format, const char *options);
  71. fz_document_writer *fz_new_cbz_writer(fz_context *ctx, const char *path, const char *options);
  72. fz_document_writer *fz_new_pdf_writer(fz_context *ctx, const char *path, const char *options);
  73. fz_document_writer *fz_new_svg_writer(fz_context *ctx, const char *path, const char *options);
  74. fz_document_writer *fz_new_png_pixmap_writer(fz_context *ctx, const char *path, const char *options);
  75. fz_document_writer *fz_new_tga_pixmap_writer(fz_context *ctx, const char *path, const char *options);
  76. fz_document_writer *fz_new_pam_pixmap_writer(fz_context *ctx, const char *path, const char *options);
  77. fz_document_writer *fz_new_pnm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
  78. fz_document_writer *fz_new_pgm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
  79. fz_document_writer *fz_new_ppm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
  80. fz_document_writer *fz_new_pbm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
  81. fz_document_writer *fz_new_pkm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
  82. /*
  83. fz_begin_page: Called to start the process of writing a page to
  84. a document.
  85. mediabox: page size rectangle in points.
  86. Returns a fz_device to write page contents to.
  87. */
  88. fz_device *fz_begin_page(fz_context *ctx, fz_document_writer *wri, const fz_rect *mediabox);
  89. /*
  90. fz_end_page: Called to end the process of writing a page to a
  91. document.
  92. */
  93. void fz_end_page(fz_context *ctx, fz_document_writer *wri);
  94. /*
  95. fz_close_document_writer: Called to end the process of writing
  96. pages to a document.
  97. This writes any file level trailers required. After this
  98. completes successfully the file is up to date and complete.
  99. */
  100. void fz_close_document_writer(fz_context *ctx, fz_document_writer *wri);
  101. /*
  102. fz_drop_document_writer: Called to discard a fz_document_writer.
  103. This may be called at any time during the process to release all
  104. the resources owned by the writer.
  105. Calling drop without having previously called close may leave
  106. the file in an inconsistent state.
  107. */
  108. void fz_drop_document_writer(fz_context *ctx, fz_document_writer *wri);
  109. fz_document_writer *fz_new_pixmap_writer(fz_context *ctx, const char *path, const char *options, const char *default_path, int n,
  110. void (*save)(fz_context *ctx, fz_pixmap *pix, const char *filename));
  111. extern const char *fz_cbz_write_options_usage;
  112. extern const char *fz_pdf_write_options_usage;
  113. extern const char *fz_svg_write_options_usage;
  114. #endif