@@ -82,6 +82,26 @@ public function getToUnicodeCMap(): ?ToUnicodeCMap {
8282 return $ this ->toUnicodeCMap = ToUnicodeCMapParser::parse ($ stream , 0 , $ stream ->getSizeInBytes ());
8383 }
8484
85+ public function getToUnicodeCMapDescendantFont (): ?ToUnicodeCMap {
86+ foreach ($ this ->getDescendantFonts () as $ descendantFont ) {
87+ $ fontDictionary = $ descendantFont instanceof Dictionary ? $ descendantFont : $ descendantFont ->getDictionary ();
88+
89+ if (($ CIDSystemInfo = $ fontDictionary ->getValueForKey (DictionaryKey::CIDSYSTEM_INFO , Dictionary::class)) !== null ) {
90+ $ fontResource = RegistryOrchestrator::getForRegistryOrderingSupplement (
91+ $ CIDSystemInfo ->getValueForKey (DictionaryKey::REGISTRY , TextStringValue::class) ?? throw new ParseFailureException (),
92+ $ CIDSystemInfo ->getValueForKey (DictionaryKey::ORDERING , TextStringValue::class) ?? throw new ParseFailureException (),
93+ $ CIDSystemInfo ->getValueForKey (DictionaryKey::SUPPLEMENT , IntegerValue::class) ?? throw new ParseFailureException (),
94+ );
95+
96+ if ($ fontResource !== null ) {
97+ return $ fontResource ->getToUnicodeCMap ();
98+ }
99+ }
100+ }
101+
102+ return null ;
103+ }
104+
85105 /** @throws PdfParserException */
86106 public function getFirstChar (): ?int {
87107 return $ this ->getDictionary ()
@@ -225,33 +245,4 @@ public function getFontDescriptor(): ?ReferenceValue {
225245 return $ this ->getDictionary ()
226246 ->getValueForKey (DictionaryKey::FONT_DESCRIPTOR , ReferenceValue::class);
227247 }
228-
229- /** @throws PdfParserException */
230- public function toUnicode (string $ characterGroup ): string {
231- $ toUnicodeCMap = $ this ->getToUnicodeCMap ();
232- if ($ toUnicodeCMap !== null ) {
233- return $ toUnicodeCMap ->textToUnicode ($ characterGroup );
234- }
235-
236- $ descendantFonts = $ this ->getDictionary ()->getObjectsForReference ($ this ->document , DictionaryKey::DESCENDANT_FONTS , Font::class);
237- foreach ($ descendantFonts as $ descendantFont ) {
238- if (($ CIDSystemInfo = $ descendantFont ->getDictionary ()->getValueForKey (DictionaryKey::CIDSYSTEM_INFO , Dictionary::class)) !== null ) {
239- $ fontResource = RegistryOrchestrator::getForRegistryOrderingSupplement (
240- $ CIDSystemInfo ->getValueForKey (DictionaryKey::REGISTRY , TextStringValue::class) ?? throw new ParseFailureException (),
241- $ CIDSystemInfo ->getValueForKey (DictionaryKey::ORDERING , TextStringValue::class) ?? throw new ParseFailureException (),
242- $ CIDSystemInfo ->getValueForKey (DictionaryKey::SUPPLEMENT , IntegerValue::class) ?? throw new ParseFailureException (),
243- );
244-
245- if ($ fontResource !== null ) {
246- return $ fontResource ->getToUnicodeCMap ()->textToUnicode ($ characterGroup );
247- }
248- }
249- }
250-
251- if (($ encoding = $ this ->getEncoding ()) !== null ) {
252- return $ encoding ->decodeString (implode ('' , array_map (fn (string $ character ) => mb_chr ((int ) hexdec ($ character )), str_split ($ characterGroup , 2 ))));
253- }
254-
255- throw new ParseFailureException ('No ToUnicodeCMap or encoding information available for this font ' );
256- }
257248}
0 commit comments