Skip to content

Commit

Permalink
Generate appearance stream for annotation stamp when it is not availa…
Browse files Browse the repository at this point in the history
…ble (i.e. was invalidated), taking into account the custom image case
  • Loading branch information
lbaudin authored and tsdgeos committed Nov 28, 2024
1 parent 89ac0c4 commit 1448906
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
53 changes: 35 additions & 18 deletions poppler/Annot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5798,6 +5798,35 @@ void AnnotStamp::generateStampCustomAppearance()
const double bboxArray[4] = { 0, 0, rect->x2 - rect->x1, rect->y2 - rect->y1 };
const GooString *appearBuf = appearBuilder.buffer();
appearance = createForm(appearBuf, bboxArray, false, resDict);

if (updatedAppearanceStream == Ref::INVALID()) {
updatedAppearanceStream = doc->getXRef()->addIndirectObject(appearance);
} else {
Object obj1 = appearance.fetch(doc->getXRef());
doc->getXRef()->setModifiedObject(&obj1, updatedAppearanceStream);
}

Object obj1 = Object(new Dict(doc->getXRef()));
obj1.dictAdd("N", Object(updatedAppearanceStream));
update("AP", std::move(obj1));
}

void AnnotStamp::updateAppearanceResDict()
{
if (appearance.isNull()) {
if (stampImageHelper != nullptr) {
generateStampCustomAppearance();
} else {
generateStampDefaultAppearance();
}
}
}

Object AnnotStamp::getAppearanceResDict()
{
updateAppearanceResDict();

return Annot::getAppearanceResDict();
}

void AnnotStamp::generateStampDefaultAppearance()
Expand Down Expand Up @@ -5904,13 +5933,9 @@ void AnnotStamp::draw(Gfx *gfx, bool printing)
}

annotLocker();
if (appearance.isNull()) {
if (stampImageHelper != nullptr) {
generateStampCustomAppearance();
} else {
generateStampDefaultAppearance();
}
}

// generate the appearance stream
updateAppearanceResDict();

// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
Expand Down Expand Up @@ -5943,18 +5968,10 @@ void AnnotStamp::setCustomImage(AnnotStampImageHelper *stampImageHelperA)
clearCustomImage();

stampImageHelper = stampImageHelperA;
generateStampCustomAppearance();

if (updatedAppearanceStream == Ref::INVALID()) {
updatedAppearanceStream = doc->getXRef()->addIndirectObject(appearance);
} else {
Object obj1 = appearance.fetch(doc->getXRef());
doc->getXRef()->setModifiedObject(&obj1, updatedAppearanceStream);
}

Object obj1 = Object(new Dict(doc->getXRef()));
obj1.dictAdd("N", Object(updatedAppearanceStream));
update("AP", std::move(obj1));
// Regenerate appearance stream
invalidateAppearance();
updateAppearanceResDict();
}

void AnnotStamp::clearCustomImage()
Expand Down
3 changes: 3 additions & 0 deletions poppler/Annot.h
Original file line number Diff line number Diff line change
Expand Up @@ -1236,10 +1236,13 @@ class POPPLER_PRIVATE_EXPORT AnnotStamp : public AnnotMarkup
// getters
const GooString *getIcon() const { return icon.get(); }

Object getAppearanceResDict() override;

private:
void initialize(PDFDoc *docA, Dict *dict);
void generateStampDefaultAppearance();
void generateStampCustomAppearance();
void updateAppearanceResDict();

std::unique_ptr<GooString> icon; // Name (Default Draft)
AnnotStampImageHelper *stampImageHelper;
Expand Down

0 comments on commit 1448906

Please sign in to comment.