mupdf
Loading...
Searching...
No Matches
story-writer.h
Go to the documentation of this file.
1// Copyright (C) 2022-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
23#ifndef MUPDF_FITZ_STORY_WRITER_H
24#define MUPDF_FITZ_STORY_WRITER_H
25
26#include "mupdf/fitz/story.h"
27#include "mupdf/fitz/writer.h"
28
29/*
30 * A fz_story_element_position plus page number information; used with
31 * fz_write_story() and fz_write_stabilized_story().
32 */
38
39/*
40 * A set of fz_write_story_position items; used with
41 * fz_write_stabilized_story().
42 */
48
49
50/*
51 * Callback type used by fz_write_story() and fz_write_stabilized_story().
52 *
53 * Should set *rect to rect number <num>. If this is on a new page should also
54 * set *mediabox and return 1, otherwise return 0.
55 *
56 * ref:
57 * As passed to fz_write_story() or fz_write_stabilized_story().
58 * num:
59 * The rect number. Will typically increment by one each time, being reset
60 * to zero when fz_write_stabilized_story() starts a new iteration.
61 * filled:
62 * From earlier internal call to fz_place_story().
63 * rect:
64 * Out param.
65 * ctm:
66 * Out param, defaults to fz_identity.
67 * mediabox:
68 * Out param, only used if we return 1.
69 */
70typedef int (fz_write_story_rectfn)(fz_context *ctx, void *ref, int num, fz_rect filled, fz_rect *rect, fz_matrix *ctm, fz_rect *mediabox);
71
72/*
73 * Callback used by fz_write_story() to report information about element
74 * positions. Slightly different from fz_story_position_callback() because
75 * <position> also includes the page number.
76 *
77 * ref:
78 * As passed to fz_write_story() or fz_write_stabilized_story().
79 * position:
80 * Called via internal call to fz_story_position_callback().
81 */
82typedef void (fz_write_story_positionfn)(fz_context *ctx, void *ref, const fz_write_story_position *position);
83
84/*
85 * Callback for fz_write_story(), called twice for each page, before (after=0)
86 * and after (after=1) the story is written.
87 *
88 * ref:
89 * As passed to fz_write_story() or fz_write_stabilized_story().
90 * page_num:
91 * Page number, starting from 1.
92 * mediabox:
93 * As returned from fz_write_story_rectfn().
94 * dev:
95 * Created from the fz_writer passed to fz_write_story() or
96 * fz_write_stabilized_story().
97 * after:
98 * 0 - before writing the story.
99 * 1 - after writing the story.
100 */
101typedef void (fz_write_story_pagefn)(fz_context *ctx, void *ref, int page_num, fz_rect mediabox, fz_device *dev, int after);
102
103/*
104 * Callback type for fz_write_stabilized_story().
105 *
106 * Should populate the supplied buffer with html content for use with internal
107 * calls to fz_new_story(). This may include extra content derived from
108 * information in <positions>, for example a table of contents.
109 *
110 * ref:
111 * As passed to fz_write_stabilized_story().
112 * positions:
113 * Information from previous iteration.
114 * buffer:
115 * Where to write the new content. Will be initially empty.
116 */
117typedef void (fz_write_story_contentfn)(fz_context *ctx, void *ref, const fz_write_story_positions *positions, fz_buffer *buffer);
118
119
120/*
121 * Places and writes a story to a fz_document_writer. Avoids the need
122 * for calling code to implement a loop that calls fz_place_story()
123 * and fz_draw_story() etc, at the expense of having to provide a
124 * fz_write_story_rectfn() callback.
125 *
126 * story:
127 * The story to place and write.
128 * writer:
129 * Where to write the story; can be NULL.
130 * rectfn:
131 * Should return information about the rect to be used in the next
132 * internal call to fz_place_story().
133 * rectfn_ref:
134 * Passed to rectfn().
135 * positionfn:
136 * If not NULL, is called via internal calls to fz_story_positions().
137 * positionfn_ref:
138 * Passed to positionfn().
139 * pagefn:
140 * If not NULL, called at start and end of each page (before and after all
141 * story content has been written to the device).
142 * pagefn_ref:
143 * Passed to pagefn().
144 */
146 fz_context *ctx,
147 fz_document_writer *writer,
148 fz_story *story,
150 void *rectfn_ref,
151 fz_write_story_positionfn positionfn,
152 void *positionfn_ref,
154 void *pagefn_ref
155 );
156
157
158/*
159 * Does iterative layout of html content to a fz_document_writer. For example
160 * this allows one to add a table of contents section while ensuring that page
161 * numbers are patched up until stable.
162 *
163 * Repeatedly creates new story from (contentfn(), contentfn_ref, user_css, em)
164 * and lays it out with internal call to fz_write_story(); uses a NULL writer
165 * and populates a fz_write_story_positions which is passed to the next call of
166 * contentfn().
167 *
168 * When the html from contentfn() becomes unchanged, we do a final iteration
169 * using <writer>.
170 *
171 * writer:
172 * Where to write in the final iteration.
173 * user_css:
174 * Used in internal calls to fz_new_story().
175 * em:
176 * Used in internal calls to fz_new_story().
177 * contentfn:
178 * Should return html content for use with fz_new_story(), possibly
179 * including extra content such as a table-of-contents.
180 * contentfn_ref:
181 * Passed to contentfn().
182 * rectfn:
183 * Should return information about the rect to be used in the next
184 * internal call to fz_place_story().
185 * rectfn_ref:
186 * Passed to rectfn().
187 * fz_write_story_pagefn:
188 * If not NULL, called at start and end of each page (before and after all
189 * story content has been written to the device).
190 * pagefn_ref:
191 * Passed to pagefn().
192 * dir:
193 * NULL, or a directory context to load images etc from.
194 */
196 fz_context *ctx,
197 fz_document_writer *writer,
198 const char *user_css,
199 float em,
200 fz_write_story_contentfn contentfn,
201 void *contentfn_ref,
203 void *rectfn_ref,
205 void *pagefn_ref,
206 fz_archive *dir
207 );
208
209#endif
int fz_write_story_rectfn(fz_context *ctx, void *ref, int num, fz_rect filled, fz_rect *rect, fz_matrix *ctm, fz_rect *mediabox)
Definition story-writer.h:70
void fz_write_story_positionfn(fz_context *ctx, void *ref, const fz_write_story_position *position)
Definition story-writer.h:82
void fz_write_story_pagefn(fz_context *ctx, void *ref, int page_num, fz_rect mediabox, fz_device *dev, int after)
Definition story-writer.h:101
void fz_write_story(fz_context *ctx, fz_document_writer *writer, fz_story *story, fz_write_story_rectfn rectfn, void *rectfn_ref, fz_write_story_positionfn positionfn, void *positionfn_ref, fz_write_story_pagefn pagefn, void *pagefn_ref)
void fz_write_stabilized_story(fz_context *ctx, fz_document_writer *writer, const char *user_css, float em, fz_write_story_contentfn contentfn, void *contentfn_ref, fz_write_story_rectfn rectfn, void *rectfn_ref, fz_write_story_pagefn pagefn, void *pagefn_ref, fz_archive *dir)
void fz_write_story_contentfn(fz_context *ctx, void *ref, const fz_write_story_positions *positions, fz_buffer *buffer)
Definition story-writer.h:117
struct fz_story fz_story
Definition story.h:52
Definition archive.h:429
Definition buffer.h:41
Definition context.h:886
Definition device.h:290
Definition writer.h:225
Definition geometry.h:388
Definition geometry.h:231
Definition story.h:159
Definition story-writer.h:34
int page_num
Definition story-writer.h:36
fz_story_element_position element
Definition story-writer.h:35
Definition story-writer.h:44
int num
Definition story-writer.h:46
fz_write_story_position * positions
Definition story-writer.h:45