When resolving font from /DR, copy it into resources

This commit is contained in:
Jay Berkenbilt 2021-03-03 16:57:37 -05:00
parent a2124f992c
commit 887f35efaa
5 changed files with 7686 additions and 1 deletions

View File

@ -963,11 +963,28 @@ QPDFFormFieldObjectHelper::generateTextAppearance(
// See if the font is encoded with something we know about.
QPDFObjectHandle resources = AS.getDict().getKey("/Resources");
QPDFObjectHandle font = getFontFromResource(resources, font_name);
bool found_font_in_dr = false;
if (! font.isInitialized())
{
QPDFObjectHandle dr = getDefaultResources();
font = getFontFromResource(dr, font_name);
found_font_in_dr = (font.isInitialized() && font.isDictionary());
}
if (found_font_in_dr && resources.isDictionary())
{
QTC::TC("qpdf", "QPDFFormFieldObjectHelper get font from /DR");
if (resources.isIndirect())
{
resources = resources.getOwningQPDF()->makeIndirectObject(
resources.shallowCopy());
AS.getDict().replaceKey("/Resources", resources);
}
// Use mergeResources to force /Font to be local
resources.mergeResources(
QPDFObjectHandle::parse("<< /Font << >> >>"));
resources.getKey("/Font").replaceKey(font_name, font);
}
if (font.isInitialized() &&
font.isDictionary() &&
font.getKey("/Encoding").isName())

View File

@ -583,3 +583,4 @@ qpdf pages keeping field from original 0
qpdf no more fields in pages 0
QPDFObjectHandle merge reuse 0
QPDFObjectHandle merge generate 0
QPDFFormFieldObjectHelper get font from /DR 0

View File

@ -385,7 +385,7 @@ $td->runtest("compare files",
show_ntests();
# ----------
$td->notify("--- Appearance Streams ---");
$n_tests += 8;
$n_tests += 10;
foreach my $f ('need-appearances',
'need-appearances-more',
@ -444,6 +444,17 @@ foreach my $i (@choice_values)
{$td->FILE => "appearances-$i.pdf"});
}
$td->runtest("Update resources from /DR",
{$td->COMMAND =>
"qpdf --qdf --no-original-object-ids --static-id" .
" --generate-appearances" .
" resource-from-dr.pdf a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("compare files",
{$td->FILE => "a.pdf"},
{$td->FILE => "resource-from-dr-out.pdf"});
show_ntests();
# ----------
$td->notify("--- Form XObject, underlay, overlay ---");

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff