Commit 503620ae authored by Fabio D'Urso's avatar Fabio D'Urso Committed by Albert Astals Cid

Do not recreate Annots when writing to PS, Export poppler-generated Annot appearance resource dict

1) With previous code each Annot object was reconstructed from the pdf object when
writing to PS, leading to the fact that writeDocSetup couldn't see the
generated appearance.
This patch makes writeDocSetup use the same Annots object returned by
Page::getAnnots.

2) This patch also enables each Annot subtype to control the exported
resources. AnnotFreeText uses this new method to export font information.

3) Comment fixed in Page.h: Page::getAnnots does *not* give away ownership, in
fact the returned object is destroyed by ~Page.
parent 27335048
......@@ -1552,6 +1552,25 @@ void Annot::createResourcesDict(const char *formName, Object *formStream,
resDict->dictSet("XObject", &formDict);
}
Object *Annot::getAppearanceResDict(Object *dest) {
Object obj1, obj2;
dest->initNull(); // Default value
// Fetch appearance's resource dict (if any)
appearance.fetch(xref, &obj1);
if (obj1.isStream()) {
obj1.streamGetDict()->lookup("Resources", &obj2);
if (obj2.isDict()) {
obj2.copy(dest);
}
obj2.free();
}
obj1.free();
return dest;
}
GBool Annot::isVisible(GBool printing) {
// check the flags
if ((flags & flagHidden) ||
......@@ -2682,6 +2701,15 @@ void AnnotFreeText::draw(Gfx *gfx, GBool printing) {
obj.free();
}
// Before retrieving the res dict, regenerate the appearance stream if needed,
// because AnnotFreeText::draw needs to store font info in the res dict
Object *AnnotFreeText::getAppearanceResDict(Object *dest) {
if (appearance.isNull()) {
generateFreeTextAppearance();
}
return Annot::getAppearanceResDict(dest);
}
//------------------------------------------------------------------------
// AnnotLine
//------------------------------------------------------------------------
......
......@@ -492,8 +492,8 @@ public:
void decRefCnt();
virtual void draw(Gfx *gfx, GBool printing);
// Get appearance object.
Object *getAppearance(Object *obj) { return appearance.fetch(xref, obj); }
// Get the resource dict of the appearance stream
virtual Object *getAppearanceResDict(Object *dest);
GBool match(Ref *refA)
{ return ref.num == refA->num && ref.gen == refA->gen; }
......@@ -842,6 +842,7 @@ public:
~AnnotFreeText();
virtual void draw(Gfx *gfx, GBool printing);
virtual Object *getAppearanceResDict(Object *dest);
void setAppearanceString(GooString *new_string);
void setQuadding(AnnotFreeTextQuadding new_quadding);
......
......@@ -11,6 +11,7 @@
// Copyright (C) 2010, 2012 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2010 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2011 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -53,7 +54,7 @@ GooList *FontInfoScanner::scan(int nPages) {
Page *page;
Dict *resDict;
Annots *annots;
Object obj1, obj2;
Object obj1;
int lastPage;
if (currentPage > doc->getNumPages()) {
......@@ -76,12 +77,8 @@ GooList *FontInfoScanner::scan(int nPages) {
}
annots = page->getAnnots();
for (int i = 0; i < annots->getNumAnnots(); ++i) {
if (annots->getAnnot(i)->getAppearance(&obj1)->isStream()) {
obj1.streamGetDict()->lookup("Resources", &obj2);
if (obj2.isDict()) {
scanFonts(obj2.getDict(), result);
}
obj2.free();
if (annots->getAnnot(i)->getAppearanceResDict(&obj1)->isDict()) {
scanFonts(obj1.getDict(), result);
}
obj1.free();
}
......
......@@ -1553,19 +1553,13 @@ void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog *catalog,
if ((resDict = page->getResourceDict())) {
setupResources(resDict);
}
annots = new Annots(doc, page->getAnnots(&obj1));
obj1.free();
annots = page->getAnnots();
for (i = 0; i < annots->getNumAnnots(); ++i) {
if (annots->getAnnot(i)->getAppearance(&obj1)->isStream()) {
obj1.streamGetDict()->lookup("Resources", &obj2);
if (obj2.isDict()) {
setupResources(obj2.getDict());
}
obj2.free();
if (annots->getAnnot(i)->getAppearanceResDict(&obj1)->isDict()) {
setupResources(obj1.getDict());
}
obj1.free();
}
delete annots;
}
if ((acroForm = catalog->getAcroForm()) && acroForm->isDict()) {
if (acroForm->dictLookup("DR", &obj1)->isDict()) {
......
......@@ -178,7 +178,7 @@ public:
// Return a list of links.
Links *getLinks();
// Return a list of annots. Ownership is transferred to the caller.
// Return a list of annots. It will be valid until the page is destroyed
Annots *getAnnots();
// Get contents.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment