xps-imp.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. // Copyright (C) 2004-2024 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. #ifndef SOURCE_XPS_IMP_H
  23. #define SOURCE_XPS_IMP_H
  24. typedef struct xps_document_s xps_document;
  25. typedef struct xps_page_s xps_page;
  26. fz_document *xps_open_document(fz_context *ctx, const char *filename);
  27. fz_document *xps_open_document_with_stream(fz_context *ctx, fz_stream *file);
  28. fz_document *xps_open_document_with_directory(fz_context *ctx, fz_archive *dir);
  29. int xps_count_pages(fz_context *ctx, fz_document *doc, int chapter);
  30. fz_page *xps_load_page(fz_context *ctx, fz_document *doc, int chapter, int number);
  31. fz_outline *xps_load_outline(fz_context *ctx, fz_document *doc);
  32. void xps_run_page(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
  33. fz_link *xps_load_links(fz_context *ctx, fz_page *page);
  34. fz_link_dest xps_lookup_link_target(fz_context *ctx, fz_document *doc, const char *target_uri);
  35. int xps_strcasecmp(char *a, char *b);
  36. void xps_resolve_url(fz_context *ctx, xps_document *doc, char *output, char *base_uri, char *path, int output_size);
  37. char *xps_parse_point(fz_context *ctx, xps_document *doc, char *s_in, float *x, float *y);
  38. typedef struct xps_part_s xps_part;
  39. struct xps_part_s
  40. {
  41. char *name;
  42. fz_buffer *data;
  43. };
  44. int xps_has_part(fz_context *ctx, xps_document *doc, char *partname);
  45. /*
  46. Read and interleave split parts from a ZIP file.
  47. */
  48. xps_part *xps_read_part(fz_context *ctx, xps_document *doc, char *partname);
  49. void xps_drop_part(fz_context *ctx, xps_document *doc, xps_part *part);
  50. typedef struct xps_fixdoc_s xps_fixdoc;
  51. typedef struct xps_fixpage_s xps_fixpage;
  52. typedef struct xps_target_s xps_target;
  53. struct xps_fixdoc_s
  54. {
  55. char *name;
  56. char *outline;
  57. xps_fixdoc *next;
  58. };
  59. struct xps_fixpage_s
  60. {
  61. char *name;
  62. int number;
  63. int width;
  64. int height;
  65. xps_fixpage *next;
  66. };
  67. struct xps_page_s
  68. {
  69. fz_page super;
  70. xps_fixpage *fix;
  71. fz_xml_doc *xml;
  72. };
  73. struct xps_target_s
  74. {
  75. char *name;
  76. int page;
  77. xps_target *next;
  78. };
  79. void xps_read_page_list(fz_context *ctx, xps_document *doc);
  80. void xps_print_page_list(fz_context *ctx, xps_document *doc);
  81. void xps_drop_page_list(fz_context *ctx, xps_document *doc);
  82. typedef struct xps_font_cache_s xps_font_cache;
  83. struct xps_font_cache_s
  84. {
  85. char *name;
  86. fz_font *font;
  87. xps_font_cache *next;
  88. };
  89. typedef struct xps_glyph_metrics_s xps_glyph_metrics;
  90. struct xps_glyph_metrics_s
  91. {
  92. float hadv, vadv, vorg;
  93. };
  94. int xps_count_font_encodings(fz_context *ctx, fz_font *font);
  95. void xps_identify_font_encoding(fz_context *ctx, fz_font *font, int idx, int *pid, int *eid);
  96. void xps_select_font_encoding(fz_context *ctx, fz_font *font, int idx);
  97. int xps_encode_font_char(fz_context *ctx, fz_font *font, int key);
  98. void xps_measure_font_glyph(fz_context *ctx, xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx);
  99. void xps_print_path(fz_context *ctx, xps_document *doc);
  100. void xps_parse_color(fz_context *ctx, xps_document *doc, char *base_uri, char *hexstring, fz_colorspace **csp, float *samples);
  101. void xps_set_color(fz_context *ctx, xps_document *doc, fz_colorspace *colorspace, float *samples);
  102. typedef struct xps_resource_s xps_resource;
  103. struct xps_resource_s
  104. {
  105. char *name;
  106. char *base_uri; /* only used in the head nodes */
  107. fz_xml_doc *base_xml; /* only used in the head nodes, to free the xml document */
  108. fz_xml *data;
  109. xps_resource *next;
  110. xps_resource *parent; /* up to the previous dict in the stack */
  111. };
  112. xps_resource * xps_parse_resource_dictionary(fz_context *ctx, xps_document *doc, char *base_uri, fz_xml *root);
  113. void xps_drop_resource_dictionary(fz_context *ctx, xps_document *doc, xps_resource *dict);
  114. void xps_resolve_resource_reference(fz_context *ctx, xps_document *doc, xps_resource *dict, char **attp, fz_xml **tagp, char **urip);
  115. void xps_print_resource_dictionary(fz_context *ctx, xps_document *doc, xps_resource *dict);
  116. void xps_parse_fixed_page(fz_context *ctx, xps_document *doc, fz_matrix ctm, xps_page *page);
  117. void xps_parse_canvas(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
  118. /*
  119. Parse an XPS <Path> element, and call relevant
  120. functions for drawing and/or clipping the child elements.
  121. */
  122. void xps_parse_path(fz_context *ctx, xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node);
  123. void xps_parse_glyphs(fz_context *ctx, xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node);
  124. void xps_parse_solid_color_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node);
  125. void xps_parse_image_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
  126. void xps_parse_visual_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
  127. void xps_parse_linear_gradient_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
  128. void xps_parse_radial_gradient_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
  129. void xps_parse_tiling_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *root, void(*func)(fz_context *ctx, xps_document*, fz_matrix, fz_rect, char*, xps_resource*, fz_xml*, void*), void *user);
  130. fz_font *xps_lookup_font(fz_context *ctx, xps_document *doc, char *base_uri, char *font_uri, char *style_att);
  131. /*
  132. Parse an abbreviated geometry string, and call
  133. moveto/lineto/curveto functions to build up a path.
  134. */
  135. fz_path *xps_parse_abbreviated_geometry(fz_context *ctx, xps_document *doc, char *geom, int *fill_rule);
  136. fz_path *xps_parse_path_geometry(fz_context *ctx, xps_document *doc, xps_resource *dict, fz_xml *root, int stroking, int *fill_rule);
  137. fz_matrix xps_parse_transform(fz_context *ctx, xps_document *doc, char *att, fz_xml *tag, fz_matrix ctm);
  138. fz_rect xps_parse_rectangle(fz_context *ctx, xps_document *doc, char *text);
  139. void xps_begin_opacity(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, char *opacity_att, fz_xml *opacity_mask_tag);
  140. void xps_end_opacity(fz_context *ctx, xps_document *doc, char *base_uri, xps_resource *dict, char *opacity_att, fz_xml *opacity_mask_tag);
  141. void xps_parse_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
  142. void xps_parse_element(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
  143. void xps_clip(fz_context *ctx, xps_document *doc, fz_matrix ctm, xps_resource *dict, char *clip_att, fz_xml *clip_tag);
  144. fz_xml *xps_lookup_alternate_content(fz_context *ctx, xps_document *doc, fz_xml *node);
  145. typedef struct xps_entry_s xps_entry;
  146. /* Implementation details: Subject to change. */
  147. struct xps_entry_s
  148. {
  149. char *name;
  150. int64_t offset;
  151. int csize;
  152. int usize;
  153. };
  154. struct xps_document_s
  155. {
  156. fz_document super;
  157. fz_archive *zip;
  158. char *start_part; /* fixed document sequence */
  159. xps_fixdoc *first_fixdoc; /* first fixed document */
  160. xps_fixdoc *last_fixdoc; /* last fixed document */
  161. xps_fixpage *first_page; /* first page of document */
  162. xps_fixpage *last_page; /* last page of document */
  163. int page_count;
  164. xps_target *target; /* link targets */
  165. char *base_uri; /* base uri for parsing XML and resolving relative paths */
  166. char *part_uri; /* part uri for parsing metadata relations */
  167. /* We cache font resources */
  168. xps_font_cache *font_table;
  169. /* Opacity attribute stack */
  170. float opacity[64];
  171. int opacity_top;
  172. /* Current color */
  173. fz_colorspace *colorspace;
  174. float color[8];
  175. float alpha;
  176. /* Current device */
  177. fz_device *dev;
  178. fz_cookie *cookie;
  179. };
  180. /*
  181. Parse unicode and indices strings and encode glyphs.
  182. Calculate metrics for positioning.
  183. */
  184. fz_text *xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, fz_matrix ctm,
  185. fz_font *font, float size, float originx, float originy,
  186. int is_sideways, int bidi_level,
  187. char *indices, char *unicode);
  188. #endif