@@ -58,6 +58,7 @@ mod util;
5858
5959pub use usvg;
6060
61+ use crate :: render:: text:: write_font;
6162use once_cell:: sync:: Lazy ;
6263use pdf_writer:: { Chunk , Content , Filter , Finish , Pdf , Rect , Ref , TextStr } ;
6364use usvg:: { fontdb, Align , AspectRatio , NonZeroRect , Size , Transform , Tree , ViewBox } ;
@@ -154,7 +155,7 @@ pub fn convert_str(
154155 usvg_options. default_size = size;
155156 }
156157 let tree = Tree :: from_str ( src, & usvg_options, fontdb) ?;
157- Ok ( convert_tree ( & tree, options) )
158+ Ok ( convert_tree ( & tree, options, fontdb . clone ( ) ) )
158159}
159160
160161/// Convert a [`usvg` tree](Tree) into a standalone PDF buffer.
@@ -182,9 +183,9 @@ pub fn convert_str(
182183/// std::fs::write(output, pdf)?;
183184/// # Ok(()) }
184185/// ```
185- pub fn convert_tree ( tree : & Tree , options : Options ) -> Vec < u8 > {
186+ pub fn convert_tree ( tree : & Tree , options : Options , fontdb : fontdb :: Database ) -> Vec < u8 > {
186187 let pdf_size = pdf_size ( tree, options) ;
187- let mut ctx = Context :: new ( tree, options, None ) ;
188+ let mut ctx = Context :: new ( tree, options, None , fontdb ) ;
188189 let mut pdf = Pdf :: new ( ) ;
189190
190191 let catalog_ref = ctx. alloc_ref ( ) ;
@@ -229,6 +230,11 @@ pub fn convert_tree(tree: &Tree, options: Options) -> Vec<u8> {
229230 page. contents ( content_ref) ;
230231 page. finish ( ) ;
231232
233+ let font_ids = ctx. fonts . keys ( ) . copied ( ) . collect :: < Vec < _ > > ( ) ;
234+ for font_id in font_ids {
235+ write_font ( & mut pdf, & mut ctx, font_id) . unwrap ( ) ;
236+ }
237+
232238 write_color_spaces ( & mut ctx, & mut pdf) ;
233239
234240 let document_info_id = ctx. alloc_ref ( ) ;
@@ -334,9 +340,10 @@ pub fn convert_tree_into(
334340 options : Options ,
335341 chunk : & mut Chunk ,
336342 start_ref : Ref ,
343+ fontdb : fontdb:: Database ,
337344) -> Ref {
338345 let pdf_size = pdf_size ( tree, options) ;
339- let mut ctx = Context :: new ( tree, options, Some ( start_ref. get ( ) ) ) ;
346+ let mut ctx = Context :: new ( tree, options, Some ( start_ref. get ( ) ) , fontdb ) ;
340347
341348 let x_ref = ctx. alloc_ref ( ) ;
342349 ctx. deferrer . push ( ) ;
0 commit comments