@@ -46,7 +46,7 @@ Among the unsupported features are currently:
4646mod render;
4747mod util;
4848
49- use pdf_writer:: { Content , Filter , Finish , PdfWriter , Rect , Ref , TextStr } ;
49+ use pdf_writer:: { Chunk , Content , Filter , Finish , Pdf , Rect , Ref , TextStr } ;
5050use usvg:: utils:: view_box_to_transform;
5151use usvg:: { Align , AspectRatio , NonZeroRect , Size , Transform , Tree , TreeParsing } ;
5252
@@ -161,35 +161,35 @@ pub fn convert_str(src: &str, options: Options) -> Result<Vec<u8>, usvg::Error>
161161pub fn convert_tree ( tree : & Tree , options : Options ) -> Vec < u8 > {
162162 let pdf_size = pdf_size ( tree, options) ;
163163 let mut ctx = Context :: new ( tree, options, None ) ;
164- let mut writer = PdfWriter :: new ( ) ;
164+ let mut pdf = Pdf :: new ( ) ;
165165
166166 let catalog_ref = ctx. alloc_ref ( ) ;
167167 let page_tree_ref = ctx. alloc_ref ( ) ;
168168 let page_ref = ctx. alloc_ref ( ) ;
169169 let content_ref = ctx. alloc_ref ( ) ;
170170
171- writer . catalog ( catalog_ref) . pages ( page_tree_ref) ;
172- writer . pages ( page_tree_ref) . count ( 1 ) . kids ( [ page_ref] ) ;
171+ pdf . catalog ( catalog_ref) . pages ( page_tree_ref) ;
172+ pdf . pages ( page_tree_ref) . count ( 1 ) . kids ( [ page_ref] ) ;
173173
174174 // Generate main content
175175 ctx. deferrer . push ( ) ;
176176 let mut content = Content :: new ( ) ;
177177 tree_to_stream (
178178 tree,
179- & mut writer ,
179+ & mut pdf ,
180180 & mut content,
181181 & mut ctx,
182182 initial_transform ( options. aspect , tree, pdf_size) ,
183183 ) ;
184184 let content_stream = ctx. finish_content ( content) ;
185- let mut stream = writer . stream ( content_ref, & content_stream) ;
185+ let mut stream = pdf . stream ( content_ref, & content_stream) ;
186186
187187 if ctx. options . compress {
188188 stream. filter ( Filter :: FlateDecode ) ;
189189 }
190190 stream. finish ( ) ;
191191
192- let mut page = writer . page ( page_ref) ;
192+ let mut page = pdf . page ( page_ref) ;
193193 let mut page_resources = page. resources ( ) ;
194194 ctx. deferrer . pop ( & mut page_resources) ;
195195 page_resources. finish ( ) ;
@@ -206,27 +206,27 @@ pub fn convert_tree(tree: &Tree, options: Options) -> Vec<u8> {
206206 page. finish ( ) ;
207207
208208 let document_info_id = ctx. alloc_ref ( ) ;
209- writer . document_info ( document_info_id) . producer ( TextStr ( "svg2pdf" ) ) ;
209+ pdf . document_info ( document_info_id) . producer ( TextStr ( "svg2pdf" ) ) ;
210210
211- writer . finish ( )
211+ pdf . finish ( )
212212}
213213
214214/// Convert a [`usvg` tree](Tree) into a Form XObject that can be used as
215215/// part of a larger document.
216216///
217- /// This method is intended for use in an existing [`PdfWriter `] workflow. It
218- /// will always return an XObject with the width and height of one printer's
217+ /// This method is intended for use in an existing [`pdf-writer `] workflow. It
218+ /// will always produce an XObject with the width and height of one printer's
219219/// point, just like an [`ImageXObject`](pdf_writer::writers::ImageXObject)
220220/// would.
221221///
222- /// The resulting object can be used by registering a name and the `id` with a
223- /// page's [`/XObject`](pdf_writer::writers::Resources::x_objects) resources
224- /// dictionary and then invoking the [`Do`](Content::x_object) operator with the
225- /// name in the page's content stream.
222+ /// The resulting object can be used by registering a name and the `start_ref`
223+ /// with a page's [`/XObject`](pdf_writer::writers::Resources::x_objects)
224+ /// resources dictionary and then invoking the [`Do`](Content::x_object)
225+ /// operator with the name in the page's content stream.
226226///
227227/// As the conversion process may need to create multiple indirect objects in
228- /// the PDF, this function allocates consecutive IDs starting at `id ` for its
229- /// objects and returns the next available ID for your future writing.
228+ /// the PDF, this function allocates consecutive IDs starting at `start_ref ` for
229+ /// its objects and returns the next available ID for your future writing.
230230///
231231/// ## Example
232232/// Write a PDF file with some text and an SVG graphic.
@@ -248,12 +248,12 @@ pub fn convert_tree(tree: &Tree, options: Options) -> Vec<u8> {
248248/// let svg_name = Name(b"S1");
249249///
250250/// // Start writing a PDF.
251- /// let mut writer = PdfWriter ::new();
252- /// writer .catalog(catalog_id).pages(page_tree_id);
253- /// writer .pages(page_tree_id).kids([page_id]).count(1);
251+ /// let mut pdf = Pdf ::new();
252+ /// pdf .catalog(catalog_id).pages(page_tree_id);
253+ /// pdf .pages(page_tree_id).kids([page_id]).count(1);
254254///
255255/// // Set up a simple A4 page.
256- /// let mut page = writer .page(page_id);
256+ /// let mut page = pdf .page(page_id);
257257/// page.media_box(Rect::new(0.0, 0.0, 595.0, 842.0));
258258/// page.parent(page_tree_id);
259259/// page.contents(content_id);
@@ -267,7 +267,7 @@ pub fn convert_tree(tree: &Tree, options: Options) -> Vec<u8> {
267267/// page.finish();
268268///
269269/// // Set a predefined font, so we do not have to load anything extra.
270- /// writer .type1_font(font_id).base_font(Name(b"Helvetica"));
270+ /// pdf .type1_font(font_id).base_font(Name(b"Helvetica"));
271271///
272272/// // Let's add an SVG graphic to this file.
273273/// // We need to load its source first and manually parse it into a usvg Tree.
@@ -280,7 +280,7 @@ pub fn convert_tree(tree: &Tree, options: Options) -> Vec<u8> {
280280/// // This call allocates some indirect object reference IDs for itself. If we
281281/// // wanted to write some more indirect objects afterwards, we could use the
282282/// // return value as the next unused reference ID.
283- /// svg2pdf::convert_tree_into(&tree, svg2pdf::Options::default(), &mut writer , svg_id);
283+ /// svg2pdf::convert_tree_into(&tree, svg2pdf::Options::default(), &mut pdf , svg_id);
284284///
285285/// // Write a content stream with some text and our SVG.
286286/// let mut content = Content::new();
@@ -297,14 +297,14 @@ pub fn convert_tree(tree: &Tree, options: Options) -> Vec<u8> {
297297/// .x_object(svg_name);
298298///
299299/// // Write the file to the disk.
300- /// writer .stream(content_id, &content.finish());
301- /// std::fs::write("target/embedded.pdf", writer .finish())?;
300+ /// pdf .stream(content_id, &content.finish());
301+ /// std::fs::write("target/embedded.pdf", pdf .finish())?;
302302/// # Ok(()) }
303303/// ```
304304pub fn convert_tree_into (
305305 tree : & Tree ,
306306 options : Options ,
307- writer : & mut PdfWriter ,
307+ chunk : & mut Chunk ,
308308 start_ref : Ref ,
309309) -> Ref {
310310 let pdf_size = pdf_size ( tree, options) ;
@@ -316,14 +316,14 @@ pub fn convert_tree_into(
316316 let mut content = Content :: new ( ) ;
317317 tree_to_stream (
318318 tree,
319- writer ,
319+ chunk ,
320320 & mut content,
321321 & mut ctx,
322322 initial_transform ( options. aspect , tree, pdf_size) ,
323323 ) ;
324324 let content_stream = ctx. finish_content ( content) ;
325325
326- let mut x_object = writer . form_xobject ( x_ref, & content_stream) ;
326+ let mut x_object = chunk . form_xobject ( x_ref, & content_stream) ;
327327 x_object. bbox ( Rect :: new ( 0.0 , 0.0 , pdf_size. width ( ) , pdf_size. height ( ) ) ) ;
328328 x_object. matrix ( [
329329 1.0 / pdf_size. width ( ) ,
0 commit comments