11use pdf_cmap:: ToUnicodeCMap ;
2- use pdf_object:: {
3- dictionary:: Dictionary , object_lookup:: ObjectLookupExt , object_resolver:: ObjectResolver ,
4- object_variant:: ObjectVariant ,
5- } ;
2+ use pdf_object:: { dictionary:: Dictionary , object_resolver:: ObjectResolver } ;
63
74use crate :: {
8- cid_system_info:: CidOrdering ,
9- encoding:: { Encoding , FontEncoding } ,
10- error:: FontError ,
11- flags:: FontFlags ,
12- simple_font_glyph_map:: SimpleFontGlyphWidthsMap ,
13- standard14:: Standard14Font ,
5+ cid_system_info:: CidOrdering , encoding:: Encoding , error:: FontError , flags:: FontFlags ,
6+ simple_font_glyph_map:: SimpleFontGlyphWidthsMap , standard14:: Standard14Font ,
147 true_type_font:: TrueTypeFont ,
158} ;
169
@@ -26,7 +19,7 @@ impl FallbackFontProgram {
2619 dictionary : & Dictionary ,
2720 objects : & dyn ObjectResolver ,
2821 ) -> Result < Self , FontError > {
29- let flags = descriptor_flags ( dictionary, objects) ?;
22+ let flags = FontFlags :: from_dictionary ( dictionary, objects) ?;
3023 let standard14 = Standard14Font :: from_dictionary ( dictionary, objects, flags) ;
3124 let is_cjk = is_cjk_cid_font ( dictionary, objects) ?;
3225
@@ -51,7 +44,9 @@ pub(crate) fn fallback_true_type_from_dictionary(
5144) -> Result < TrueTypeFont , FontError > {
5245 let fallback = FallbackFontProgram :: from_dictionary ( dictionary, objects) ?;
5346 let widths = SimpleFontGlyphWidthsMap :: from_dictionary ( dictionary, objects) ?;
54- let encoding = simple_font_encoding ( dictionary, objects) ;
47+ let encoding = Encoding :: from_dictionary ( dictionary, objects)
48+ . ok ( )
49+ . flatten ( ) ;
5550 let to_unicode = to_unicode_cmap ( dictionary, objects) ?;
5651
5752 Ok ( TrueTypeFont {
@@ -73,7 +68,7 @@ pub(crate) fn fallback_true_type_from_dictionary_best_effort(
7368 dictionary : & Dictionary ,
7469 objects : & dyn ObjectResolver ,
7570) -> TrueTypeFont {
76- let flags = descriptor_flags ( dictionary, objects) . unwrap_or_default ( ) ;
71+ let flags = FontFlags :: from_dictionary ( dictionary, objects) . unwrap_or_default ( ) ;
7772 let is_cjk = is_cjk_cid_font ( dictionary, objects) . unwrap_or ( false ) ;
7873 let standard14 = Standard14Font :: from_dictionary ( dictionary, objects, flags) ;
7974 let fallback = fallback_program ( flags, standard14, is_cjk) ;
@@ -106,55 +101,6 @@ fn fallback_program(
106101 }
107102}
108103
109- /// Read font descriptor flags from a font dictionary.
110- ///
111- /// # Paramaters
112- ///
113- /// - `dictionary`: The PDF font dictionary that may contain `/FontDescriptor`.
114- /// - `objects`: The resolver used to dereference indirect PDF objects.
115- ///
116- /// # Returns
117- ///
118- /// The parsed descriptor flags, or empty flags when the descriptor or `/Flags`
119- /// entry is absent.
120- pub ( crate ) fn descriptor_flags (
121- dictionary : & Dictionary ,
122- objects : & dyn ObjectResolver ,
123- ) -> Result < FontFlags , FontError > {
124- let Some ( descriptor) = dictionary. optional_dictionary ( "FontDescriptor" , objects) ? else {
125- return Ok ( FontFlags :: empty ( ) ) ;
126- } ;
127-
128- Ok ( descriptor
129- . get ( "Flags" )
130- . and_then ( |obj| obj. try_number :: < u32 > ( objects) . ok ( ) )
131- . map ( FontFlags :: from_bits_truncate)
132- . unwrap_or_default ( ) )
133- }
134-
135- /// Parse a simple font encoding from a font dictionary.
136- ///
137- /// # Paramaters
138- ///
139- /// - `dictionary`: The PDF font dictionary that may contain `/Encoding`.
140- /// - `objects`: The resolver used to dereference indirect PDF objects.
141- ///
142- /// # Returns
143- ///
144- /// The parsed encoding when `/Encoding` is present and supported.
145- fn simple_font_encoding ( dictionary : & Dictionary , objects : & dyn ObjectResolver ) -> Option < Encoding > {
146- dictionary. get ( "Encoding" ) . and_then ( |enc_obj| {
147- let resolved = objects. resolve_object ( enc_obj) . ok ( ) ?;
148- match resolved {
149- ObjectVariant :: Dictionary ( d) => Encoding :: from_dictionary ( d, objects) . ok ( ) ,
150- _ => {
151- let base = FontEncoding :: from ( resolved. try_str ( objects) . ok ( ) ?) ;
152- Encoding :: from_base_encoding ( base) . ok ( )
153- }
154- }
155- } )
156- }
157-
158104/// Parse an optional ToUnicode CMap from a font dictionary.
159105///
160106/// # Paramaters
0 commit comments