@@ -5,7 +5,7 @@ use pdf_object::{
55} ;
66
77use crate :: {
8- cid_system_info:: cid_ordering_from_dictionary ,
8+ cid_system_info:: CidOrdering ,
99 encoding:: { Encoding , FontEncoding } ,
1010 error:: FontError ,
1111 flags:: FontFlags ,
@@ -20,26 +20,18 @@ pub(crate) struct FallbackFontProgram {
2020 pub ( crate ) flags : FontFlags ,
2121}
2222
23- /// Select fallback font bytes and metadata for a font dictionary.
24- ///
25- /// # Paramaters
26- ///
27- /// - `dictionary`: The PDF font dictionary that needs fallback font data.
28- /// - `objects`: The resolver used to dereference indirect PDF objects.
29- ///
30- /// # Returns
31- ///
32- /// A fallback font program with borrowed bundled bytes, the selected Standard
33- /// 14 identity, and descriptor flags.
34- pub ( crate ) fn fallback_program_from_dictionary (
35- dictionary : & Dictionary ,
36- objects : & dyn ObjectResolver ,
37- ) -> Result < FallbackFontProgram , FontError > {
38- let flags = descriptor_flags ( dictionary, objects) ?;
39- let standard14 = standard14_from_dictionary ( dictionary, objects, flags) ;
40- let is_cjk = is_cjk_cid_font ( dictionary, objects) ?;
41-
42- Ok ( fallback_program ( flags, standard14, is_cjk) )
23+ impl FallbackFontProgram {
24+ /// Select fallback font bytes and metadata for a font dictionary.
25+ pub ( crate ) fn from_dictionary (
26+ dictionary : & Dictionary ,
27+ objects : & dyn ObjectResolver ,
28+ ) -> Result < Self , FontError > {
29+ let flags = descriptor_flags ( dictionary, objects) ?;
30+ let standard14 = Standard14Font :: from_dictionary ( dictionary, objects, flags) ;
31+ let is_cjk = is_cjk_cid_font ( dictionary, objects) ?;
32+
33+ Ok ( fallback_program ( flags, standard14, is_cjk) )
34+ }
4335}
4436
4537/// Build a synthetic TrueType font from fallback font data.
@@ -57,7 +49,7 @@ pub(crate) fn fallback_true_type_from_dictionary(
5749 dictionary : & Dictionary ,
5850 objects : & dyn ObjectResolver ,
5951) -> Result < TrueTypeFont , FontError > {
60- let fallback = fallback_program_from_dictionary ( dictionary, objects) ?;
52+ let fallback = FallbackFontProgram :: from_dictionary ( dictionary, objects) ?;
6153 let widths = SimpleFontGlyphWidthsMap :: from_dictionary ( dictionary, objects) ?;
6254 let encoding = simple_font_encoding ( dictionary, objects) ;
6355 let to_unicode = to_unicode_cmap ( dictionary, objects) ?;
@@ -83,31 +75,14 @@ pub(crate) fn fallback_true_type_from_dictionary_best_effort(
8375) -> TrueTypeFont {
8476 let flags = descriptor_flags ( dictionary, objects) . unwrap_or_default ( ) ;
8577 let is_cjk = is_cjk_cid_font ( dictionary, objects) . unwrap_or ( false ) ;
86- let standard14 = standard14_from_dictionary ( dictionary, objects, flags) ;
78+ let standard14 = Standard14Font :: from_dictionary ( dictionary, objects, flags) ;
8779 let fallback = fallback_program ( flags, standard14, is_cjk) ;
8880 let mut font = TrueTypeFont :: from_bytes ( fallback. font_file , Some ( fallback. standard14 ) ) ;
8981 font. flags = fallback. flags ;
9082
9183 font
9284}
9385
94- /// Resolve the Standard 14 identity to use for fallback substitution.
95- ///
96- /// This prefers a readable `/BaseFont` name when it maps to a known Standard 14
97- /// font. If `/BaseFont` is missing, malformed, or unrecognized, it falls back
98- /// to the flag-driven Standard 14 selection.
99- fn standard14_from_dictionary (
100- dictionary : & Dictionary ,
101- objects : & dyn ObjectResolver ,
102- flags : FontFlags ,
103- ) -> Standard14Font {
104- dictionary
105- . get ( "BaseFont" )
106- . and_then ( |value| value. try_str ( objects) . ok ( ) )
107- . and_then ( Standard14Font :: from_base_font_name)
108- . unwrap_or_else ( || Standard14Font :: from ( flags) )
109- }
110-
11186/// Build the fallback font program descriptor from already-decided inputs.
11287///
11388/// `standard14` selects the Standard 14 identity for simple-font fallback,
@@ -217,5 +192,5 @@ fn is_cjk_cid_font(
217192 dictionary : & Dictionary ,
218193 objects : & dyn ObjectResolver ,
219194) -> Result < bool , FontError > {
220- Ok ( cid_ordering_from_dictionary ( dictionary, objects) ?. is_some ( ) )
195+ Ok ( CidOrdering :: from_dictionary ( dictionary, objects) ?. is_some ( ) )
221196}
0 commit comments