Commit 887f35efaa60653dcb92ea96c5f4d17bdd859d93
1 parent
a2124f99
When resolving font from /DR, copy it into resources
Showing
5 changed files
with
7686 additions
and
1 deletions
libqpdf/QPDFFormFieldObjectHelper.cc
| @@ -963,11 +963,28 @@ QPDFFormFieldObjectHelper::generateTextAppearance( | @@ -963,11 +963,28 @@ QPDFFormFieldObjectHelper::generateTextAppearance( | ||
| 963 | // See if the font is encoded with something we know about. | 963 | // See if the font is encoded with something we know about. |
| 964 | QPDFObjectHandle resources = AS.getDict().getKey("/Resources"); | 964 | QPDFObjectHandle resources = AS.getDict().getKey("/Resources"); |
| 965 | QPDFObjectHandle font = getFontFromResource(resources, font_name); | 965 | QPDFObjectHandle font = getFontFromResource(resources, font_name); |
| 966 | + bool found_font_in_dr = false; | ||
| 966 | if (! font.isInitialized()) | 967 | if (! font.isInitialized()) |
| 967 | { | 968 | { |
| 968 | QPDFObjectHandle dr = getDefaultResources(); | 969 | QPDFObjectHandle dr = getDefaultResources(); |
| 969 | font = getFontFromResource(dr, font_name); | 970 | font = getFontFromResource(dr, font_name); |
| 971 | + found_font_in_dr = (font.isInitialized() && font.isDictionary()); | ||
| 970 | } | 972 | } |
| 973 | + if (found_font_in_dr && resources.isDictionary()) | ||
| 974 | + { | ||
| 975 | + QTC::TC("qpdf", "QPDFFormFieldObjectHelper get font from /DR"); | ||
| 976 | + if (resources.isIndirect()) | ||
| 977 | + { | ||
| 978 | + resources = resources.getOwningQPDF()->makeIndirectObject( | ||
| 979 | + resources.shallowCopy()); | ||
| 980 | + AS.getDict().replaceKey("/Resources", resources); | ||
| 981 | + } | ||
| 982 | + // Use mergeResources to force /Font to be local | ||
| 983 | + resources.mergeResources( | ||
| 984 | + QPDFObjectHandle::parse("<< /Font << >> >>")); | ||
| 985 | + resources.getKey("/Font").replaceKey(font_name, font); | ||
| 986 | + } | ||
| 987 | + | ||
| 971 | if (font.isInitialized() && | 988 | if (font.isInitialized() && |
| 972 | font.isDictionary() && | 989 | font.isDictionary() && |
| 973 | font.getKey("/Encoding").isName()) | 990 | font.getKey("/Encoding").isName()) |
qpdf/qpdf.testcov
| @@ -583,3 +583,4 @@ qpdf pages keeping field from original 0 | @@ -583,3 +583,4 @@ qpdf pages keeping field from original 0 | ||
| 583 | qpdf no more fields in pages 0 | 583 | qpdf no more fields in pages 0 |
| 584 | QPDFObjectHandle merge reuse 0 | 584 | QPDFObjectHandle merge reuse 0 |
| 585 | QPDFObjectHandle merge generate 0 | 585 | QPDFObjectHandle merge generate 0 |
| 586 | +QPDFFormFieldObjectHelper get font from /DR 0 |
qpdf/qtest/qpdf.test
| @@ -385,7 +385,7 @@ $td->runtest("compare files", | @@ -385,7 +385,7 @@ $td->runtest("compare files", | ||
| 385 | show_ntests(); | 385 | show_ntests(); |
| 386 | # ---------- | 386 | # ---------- |
| 387 | $td->notify("--- Appearance Streams ---"); | 387 | $td->notify("--- Appearance Streams ---"); |
| 388 | -$n_tests += 8; | 388 | +$n_tests += 10; |
| 389 | 389 | ||
| 390 | foreach my $f ('need-appearances', | 390 | foreach my $f ('need-appearances', |
| 391 | 'need-appearances-more', | 391 | 'need-appearances-more', |
| @@ -444,6 +444,17 @@ foreach my $i (@choice_values) | @@ -444,6 +444,17 @@ foreach my $i (@choice_values) | ||
| 444 | {$td->FILE => "appearances-$i.pdf"}); | 444 | {$td->FILE => "appearances-$i.pdf"}); |
| 445 | } | 445 | } |
| 446 | 446 | ||
| 447 | +$td->runtest("Update resources from /DR", | ||
| 448 | + {$td->COMMAND => | ||
| 449 | + "qpdf --qdf --no-original-object-ids --static-id" . | ||
| 450 | + " --generate-appearances" . | ||
| 451 | + " resource-from-dr.pdf a.pdf"}, | ||
| 452 | + {$td->STRING => "", $td->EXIT_STATUS => 0}, | ||
| 453 | + $td->NORMALIZE_NEWLINES); | ||
| 454 | +$td->runtest("compare files", | ||
| 455 | + {$td->FILE => "a.pdf"}, | ||
| 456 | + {$td->FILE => "resource-from-dr-out.pdf"}); | ||
| 457 | + | ||
| 447 | show_ntests(); | 458 | show_ntests(); |
| 448 | # ---------- | 459 | # ---------- |
| 449 | $td->notify("--- Form XObject, underlay, overlay ---"); | 460 | $td->notify("--- Form XObject, underlay, overlay ---"); |
qpdf/qtest/qpdf/resource-from-dr-out.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/resource-from-dr.pdf
0 → 100644
No preview for this file type