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, ...@@ -1552,6 +1552,25 @@ void Annot::createResourcesDict(const char *formName, Object *formStream,
resDict->dictSet("XObject", &formDict); 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) { GBool Annot::isVisible(GBool printing) {
// check the flags // check the flags
if ((flags & flagHidden) || if ((flags & flagHidden) ||
...@@ -2682,6 +2701,15 @@ void AnnotFreeText::draw(Gfx *gfx, GBool printing) { ...@@ -2682,6 +2701,15 @@ void AnnotFreeText::draw(Gfx *gfx, GBool printing) {
obj.free(); 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 // AnnotLine
//------------------------------------------------------------------------ //------------------------------------------------------------------------
......
...@@ -492,8 +492,8 @@ public: ...@@ -492,8 +492,8 @@ public:
void decRefCnt(); void decRefCnt();
virtual void draw(Gfx *gfx, GBool printing); virtual void draw(Gfx *gfx, GBool printing);
// Get appearance object. // Get the resource dict of the appearance stream
Object *getAppearance(Object *obj) { return appearance.fetch(xref, obj); } virtual Object *getAppearanceResDict(Object *dest);
GBool match(Ref *refA) GBool match(Ref *refA)
{ return ref.num == refA->num && ref.gen == refA->gen; } { return ref.num == refA->num && ref.gen == refA->gen; }
...@@ -842,6 +842,7 @@ public: ...@@ -842,6 +842,7 @@ public:
~AnnotFreeText(); ~AnnotFreeText();
virtual void draw(Gfx *gfx, GBool printing); virtual void draw(Gfx *gfx, GBool printing);
virtual Object *getAppearanceResDict(Object *dest);
void setAppearanceString(GooString *new_string); void setAppearanceString(GooString *new_string);
void setQuadding(AnnotFreeTextQuadding new_quadding); void setQuadding(AnnotFreeTextQuadding new_quadding);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
// Copyright (C) 2010, 2012 Adrian Johnson <ajohnson@redneon.com> // Copyright (C) 2010, 2012 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2010 Thomas Freitag <Thomas.Freitag@alfa.de> // Copyright (C) 2010 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2011 Carlos Garcia Campos <carlosgc@gnome.org> // 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 // 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 // came with your tarball or type make ChangeLog if you are building from git
...@@ -53,7 +54,7 @@ GooList *FontInfoScanner::scan(int nPages) { ...@@ -53,7 +54,7 @@ GooList *FontInfoScanner::scan(int nPages) {
Page *page; Page *page;
Dict *resDict; Dict *resDict;
Annots *annots; Annots *annots;
Object obj1, obj2; Object obj1;
int lastPage; int lastPage;
if (currentPage > doc->getNumPages()) { if (currentPage > doc->getNumPages()) {
...@@ -76,12 +77,8 @@ GooList *FontInfoScanner::scan(int nPages) { ...@@ -76,12 +77,8 @@ GooList *FontInfoScanner::scan(int nPages) {
} }
annots = page->getAnnots(); annots = page->getAnnots();
for (int i = 0; i < annots->getNumAnnots(); ++i) { for (int i = 0; i < annots->getNumAnnots(); ++i) {
if (annots->getAnnot(i)->getAppearance(&obj1)->isStream()) { if (annots->getAnnot(i)->getAppearanceResDict(&obj1)->isDict()) {
obj1.streamGetDict()->lookup("Resources", &obj2); scanFonts(obj1.getDict(), result);
if (obj2.isDict()) {
scanFonts(obj2.getDict(), result);
}
obj2.free();
} }
obj1.free(); obj1.free();
} }
......
...@@ -1553,19 +1553,13 @@ void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog *catalog, ...@@ -1553,19 +1553,13 @@ void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog *catalog,
if ((resDict = page->getResourceDict())) { if ((resDict = page->getResourceDict())) {
setupResources(resDict); setupResources(resDict);
} }
annots = new Annots(doc, page->getAnnots(&obj1)); annots = page->getAnnots();
obj1.free();
for (i = 0; i < annots->getNumAnnots(); ++i) { for (i = 0; i < annots->getNumAnnots(); ++i) {
if (annots->getAnnot(i)->getAppearance(&obj1)->isStream()) { if (annots->getAnnot(i)->getAppearanceResDict(&obj1)->isDict()) {
obj1.streamGetDict()->lookup("Resources", &obj2); setupResources(obj1.getDict());
if (obj2.isDict()) {
setupResources(obj2.getDict());
}
obj2.free();
} }
obj1.free(); obj1.free();
} }
delete annots;
} }
if ((acroForm = catalog->getAcroForm()) && acroForm->isDict()) { if ((acroForm = catalog->getAcroForm()) && acroForm->isDict()) {
if (acroForm->dictLookup("DR", &obj1)->isDict()) { if (acroForm->dictLookup("DR", &obj1)->isDict()) {
......
...@@ -178,7 +178,7 @@ public: ...@@ -178,7 +178,7 @@ public:
// Return a list of links. // Return a list of links.
Links *getLinks(); 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(); Annots *getAnnots();
// Get contents. // 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