Commit 841bee94 authored by Albert Astals Cid's avatar Albert Astals Cid

* poppler/Stream.h:

        * poppler/Stream.cc: Remove MemStream::setNeedFree method i really did
        not need it
        * qt4/src/poppler-document.cc:
        * qt4/src/poppler-link.cc:
        * qt4/src/poppler-page.cc:
        * qt4/src/poppler-private.h: Make Document::loadFromData work on
        documents with a password and don't need to do a malloc and a memcpy.
parent e1432fd7
2007-01-13 Albert Astals Cid <aacid@kde.org>
* poppler/Stream.h:
* poppler/Stream.cc: Remove MemStream::setNeedFree method i really did
not need it
* qt4/src/poppler-document.cc:
* qt4/src/poppler-link.cc:
* qt4/src/poppler-page.cc:
* qt4/src/poppler-private.h: Make Document::loadFromData work on
documents with a password and don't need to do a malloc and a memcpy.
2007-01-13 Albert Astals Cid <aacid@kde.org>
* configure.ac
......
......@@ -806,11 +806,6 @@ void MemStream::doDecryption(Guchar *fileKey, int keyLength,
}
}
void MemStream::setNeedFree(GBool needsFree)
{
needFree = needsFree;
}
//------------------------------------------------------------------------
// EmbedStream
//------------------------------------------------------------------------
......
......@@ -318,7 +318,6 @@ public:
virtual void moveStart(int delta);
virtual void doDecryption(Guchar *fileKey, int keyLength,
int objNum, int objGen);
void setNeedFree(GBool needsFree);
private:
......
......@@ -56,13 +56,7 @@ namespace Poppler {
const QByteArray &userPassword)
{
// create stream
Object obj;
obj.initNull();
char *data = (char*)gmalloc(fileContents.length());
memcpy(data, fileContents.data(), fileContents.length() * sizeof(char));
MemStream *str = new MemStream(data, 0, fileContents.length(), &obj);
str->setNeedFree(true);
DocumentData *doc = new DocumentData(str,
DocumentData *doc = new DocumentData(fileContents,
new GooString(ownerPassword.data()),
new GooString(userPassword.data()));
return checkDocument(doc);
......@@ -71,9 +65,9 @@ namespace Poppler {
Document *Document::checkDocument(DocumentData *doc)
{
Document *pdoc;
if (doc->doc.isOk() || doc->doc.getErrorCode() == errEncrypted) {
if (doc->doc->isOk() || doc->doc->getErrorCode() == errEncrypted) {
pdoc = new Document(doc);
if (doc->doc.getErrorCode() == errEncrypted)
if (doc->doc->getErrorCode() == errEncrypted)
pdoc->m_doc->locked = true;
else
{
......@@ -109,10 +103,20 @@ namespace Poppler {
{
if (m_doc->locked) {
/* racier then it needs to be */
DocumentData *doc2 = new DocumentData(new GooString(m_doc->doc.getFileName()),
new GooString(ownerPassword.data()),
new GooString(userPassword.data()));
if (!doc2->doc.isOk()) {
DocumentData *doc2;
if (!m_doc->fileContents.isEmpty())
{
doc2 = new DocumentData(m_doc->fileContents,
new GooString(ownerPassword.data()),
new GooString(userPassword.data()));
}
else
{
doc2 = new DocumentData(new GooString(m_doc->doc->getFileName()),
new GooString(ownerPassword.data()),
new GooString(userPassword.data()));
}
if (!doc2->doc->isOk()) {
delete doc2;
} else {
delete m_doc;
......@@ -126,7 +130,7 @@ namespace Poppler {
Document::PageMode Document::pageMode(void) const
{
switch (m_doc->doc.getCatalog()->getPageMode()) {
switch (m_doc->doc->getCatalog()->getPageMode()) {
case Catalog::pageModeNone:
return UseNone;
case Catalog::pageModeOutlines:
......@@ -146,7 +150,7 @@ namespace Poppler {
Document::PageLayout Document::pageLayout(void) const
{
switch (m_doc->doc.getCatalog()->getPageLayout()) {
switch (m_doc->doc->getCatalog()->getPageLayout()) {
case Catalog::pageLayoutNone:
return NoLayout;
case Catalog::pageLayoutSinglePage:
......@@ -168,7 +172,7 @@ namespace Poppler {
int Document::numPages() const
{
return m_doc->doc.getNumPages();
return m_doc->doc->getNumPages();
}
QList<FontInfo> Document::fonts() const
......@@ -206,7 +210,7 @@ namespace Poppler {
if ( m_doc->locked )
return NULL;
m_doc->doc.getDocInfo( &info );
m_doc->doc->getDocInfo( &info );
if ( !info.isDict() )
return NULL;
......@@ -262,7 +266,7 @@ namespace Poppler {
if ( m_doc->locked )
return QStringList();
m_doc->doc.getDocInfo( &info );
m_doc->doc->getDocInfo( &info );
if ( !info.isDict() )
return QStringList();
......@@ -286,7 +290,7 @@ namespace Poppler {
return QDateTime();
Object info;
m_doc->doc.getDocInfo( &info );
m_doc->doc->getDocInfo( &info );
if ( !info.isDict() ) {
info.free();
return QDateTime();
......@@ -309,42 +313,42 @@ namespace Poppler {
bool Document::isEncrypted() const
{
return m_doc->doc.isEncrypted();
return m_doc->doc->isEncrypted();
}
bool Document::isLinearized() const
{
return m_doc->doc.isLinearized();
return m_doc->doc->isLinearized();
}
bool Document::okToPrint() const
{
return m_doc->doc.okToPrint();
return m_doc->doc->okToPrint();
}
bool Document::okToPrintHighRes() const
{
return m_doc->doc.okToPrintHighRes();
return m_doc->doc->okToPrintHighRes();
}
bool Document::okToChange() const
{
return m_doc->doc.okToChange();
return m_doc->doc->okToChange();
}
bool Document::okToCopy() const
{
return m_doc->doc.okToCopy();
return m_doc->doc->okToCopy();
}
bool Document::okToAddNotes() const
{
return m_doc->doc.okToAddNotes();
return m_doc->doc->okToAddNotes();
}
bool Document::okToFillForm() const
{
return m_doc->doc.okToFillForm();
return m_doc->doc->okToFillForm();
}
bool Document::okToCreateFormFields() const
......@@ -354,17 +358,17 @@ namespace Poppler {
bool Document::okToExtractForAccessibility() const
{
return m_doc->doc.okToAccessibility();
return m_doc->doc->okToAccessibility();
}
bool Document::okToAssemble() const
{
return m_doc->doc.okToAssemble();
return m_doc->doc->okToAssemble();
}
double Document::pdfVersion() const
{
return m_doc->doc.getPDFVersion();
return m_doc->doc->getPDFVersion();
}
Page *Document::page(const QString &label) const
......@@ -372,7 +376,7 @@ namespace Poppler {
GooString label_g(label.toAscii().data());
int index;
if (!m_doc->doc.getCatalog()->labelToIndex (&label_g, &index))
if (!m_doc->doc->getCatalog()->labelToIndex (&label_g, &index))
return NULL;
return page(index);
......@@ -380,12 +384,12 @@ namespace Poppler {
bool Document::hasEmbeddedFiles() const
{
return (!(0 == m_doc->doc.getCatalog()->numEmbeddedFiles()));
return (!(0 == m_doc->doc->getCatalog()->numEmbeddedFiles()));
}
QDomDocument *Document::toc() const
{
Outline * outline = m_doc->doc.getOutline();
Outline * outline = m_doc->doc->getOutline();
if ( !outline )
return NULL;
......@@ -414,7 +418,7 @@ namespace Poppler {
bool Document::print(const QString &file, const QList<int> &pageList, double hDPI, double vDPI, int rotate, int paperWidth, int paperHeight, int marginRight, int marginBottom, int marginLeft, int marginTop, bool strictMargins)
{
PSOutputDev *psOut = new PSOutputDev(file.toLatin1().data(), m_doc->doc.getXRef(), m_doc->doc.getCatalog(), 1, m_doc->doc.getNumPages(), psModePS, paperWidth, paperHeight, gFalse, marginRight, marginBottom, paperWidth - marginLeft, paperHeight - marginTop);
PSOutputDev *psOut = new PSOutputDev(file.toLatin1().data(), m_doc->doc->getXRef(), m_doc->doc->getCatalog(), 1, m_doc->doc->getNumPages(), psModePS, paperWidth, paperHeight, gFalse, marginRight, marginBottom, paperWidth - marginLeft, paperHeight - marginTop);
if (strictMargins)
{
......@@ -427,7 +431,7 @@ namespace Poppler {
{
foreach(int page, pageList)
{
m_doc->doc.displayPage(psOut, page, hDPI, vDPI, rotate, gFalse, globalParams->getPSCrop(), gFalse);
m_doc->doc->displayPage(psOut, page, hDPI, vDPI, rotate, gFalse, globalParams->getPSCrop(), gFalse);
}
delete psOut;
......
......@@ -37,7 +37,7 @@ namespace Poppler {
if ( data.namedDest && !ld )
{
deleteDest = true;
ld = data.doc->doc.findDest( data.namedDest );
ld = data.doc->doc->findDest( data.namedDest );
}
if (!ld) return;
......@@ -55,7 +55,7 @@ namespace Poppler {
else
{
Ref ref = ld->getPageRef();
m_pageNum = data.doc->doc.findPage( ref.num, ref.gen );
m_pageNum = data.doc->doc->findPage( ref.num, ref.gen );
}
double left = ld->getLeft();
double bottom = ld->getBottom();
......
......@@ -175,7 +175,7 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h,
#if defined(HAVE_SPLASH)
SplashOutputDev *splash_output = static_cast<SplashOutputDev *>(m_page->parentDoc->m_doc->getOutputDev());
m_page->parentDoc->m_doc->doc.displayPageSlice(splash_output, m_page->index + 1, xres, yres,
m_page->parentDoc->m_doc->doc->displayPageSlice(splash_output, m_page->index + 1, xres, yres,
rotation, false, true, doLinks, x, y, w, h);
SplashBitmap *bitmap = splash_output->getBitmap();
......@@ -221,8 +221,8 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h,
if (w == -1 && h == -1)
painter.scale((double)w/(double)size.width(), (double)h/(double)size.height());
ArthurOutputDev arthur_output(&painter);
arthur_output.startDoc(m_page->parentDoc->m_doc->doc.getXRef());
m_page->parentDoc->m_doc->doc.displayPageSlice(&arthur_output,
arthur_output.startDoc(m_page->parentDoc->m_doc->doc->getXRef());
m_page->parentDoc->m_doc->doc->displayPageSlice(&arthur_output,
m_page->index + 1,
xres,
yres,
......@@ -254,9 +254,9 @@ QString Page::text(const QRectF &r) const
::Page *p;
output_dev = new TextOutputDev(0, gFalse, gFalse, gFalse);
m_page->parentDoc->m_doc->doc.displayPageSlice(output_dev, m_page->index + 1, 72, 72,
m_page->parentDoc->m_doc->doc->displayPageSlice(output_dev, m_page->index + 1, 72, 72,
0, false, true, false, -1, -1, -1, -1);
p = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1);
p = m_page->parentDoc->m_doc->doc->getCatalog()->getPage(m_page->index + 1);
if (r.isNull())
{
rect = p->getCropBox();
......@@ -300,7 +300,7 @@ bool Page::search(const QString &text, QRectF &rect, SearchDirection direction,
// fetch ourselves a textpage
TextOutputDev td(NULL, gTrue, gFalse, gFalse);
m_page->parentDoc->m_doc->doc.displayPage( &td, m_page->index + 1, 72, 72, rotation, false, true, false );
m_page->parentDoc->m_doc->doc->displayPage( &td, m_page->index + 1, 72, 72, rotation, false, true, false );
TextPage *textPage=td.takeText();
if (direction == FromTop)
......@@ -333,7 +333,7 @@ QList<TextBox*> Page::textList(Rotation rotate) const
int rotation = (int)rotate * 90;
m_page->parentDoc->m_doc->doc.displayPageSlice(output_dev, m_page->index + 1, 72, 72,
m_page->parentDoc->m_doc->doc->displayPageSlice(output_dev, m_page->index + 1, 72, 72,
rotation, false, false, false, -1, -1, -1, -1);
TextWordList *word_list = output_dev->makeWordList();
......@@ -380,7 +380,7 @@ PageTransition *Page::transition() const
if (!m_page->transition) {
Object o;
PageTransitionParams params;
params.dictObj = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1)->getTrans(&o);
params.dictObj = m_page->parentDoc->m_doc->doc->getCatalog()->getPage(m_page->index + 1)->getTrans(&o);
if (params.dictObj->isDict()) m_page->transition = new PageTransition(params);
o.free();
}
......@@ -391,7 +391,7 @@ Link *Page::action( PageAction act ) const
{
if ( act == Page::Opening || act == Page::Closing )
{
::Page *p = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1);
::Page *p = m_page->parentDoc->m_doc->doc->getCatalog()->getPage(m_page->index + 1);
Object o;
p->getActions(&o);
if (!o.isDict())
......@@ -403,7 +403,7 @@ Link *Page::action( PageAction act ) const
Object o2;
const char *key = act == Page::Opening ? "O" : "C";
dict->lookup(key, &o2);
::LinkAction *act = ::LinkAction::parseAction(&o2, m_page->parentDoc->m_doc->doc.getCatalog()->getBaseURI() );
::LinkAction *act = ::LinkAction::parseAction(&o2, m_page->parentDoc->m_doc->doc->getCatalog()->getBaseURI() );
o2.free();
o.free();
Link *popplerLink = NULL;
......@@ -421,7 +421,7 @@ QSizeF Page::pageSizeF() const
{
::Page *p;
p = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1);
p = m_page->parentDoc->m_doc->doc->getCatalog()->getPage(m_page->index + 1);
if ( ( Page::Landscape == orientation() ) || (Page::Seascape == orientation() ) ) {
return QSizeF( p->getCropHeight(), p->getCropWidth() );
} else {
......@@ -436,7 +436,7 @@ QSize Page::pageSize() const
Page::Orientation Page::orientation() const
{
int rotation = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1)->getRotate();
int rotation = m_page->parentDoc->m_doc->doc->getCatalog()->getPage(m_page->index + 1)->getRotate();
switch (rotation) {
case 90:
return Page::Landscape;
......@@ -455,7 +455,7 @@ Page::Orientation Page::orientation() const
void Page::defaultCTM(double *CTM, double dpiX, double dpiY, int rotate, bool upsideDown)
{
::Page *p;
p = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1);
p = m_page->parentDoc->m_doc->doc->getCatalog()->getPage(m_page->index + 1);
p->getDefaultCTM(CTM, dpiX, dpiY, rotate, upsideDown);
}
......@@ -466,7 +466,7 @@ QList<Link*> Page::links() const
if (output_dev == NULL)
return popplerLinks;
Links *xpdfLinks = m_page->parentDoc->m_doc->doc.takeLinks();
Links *xpdfLinks = m_page->parentDoc->m_doc->doc->takeLinks();
for (int i = 0; i < xpdfLinks->getNumLinks(); ++i)
{
::Link *xpdfLink = xpdfLinks->getLink(i);
......@@ -500,7 +500,7 @@ QList<Link*> Page::links() const
QList<Annotation*> Page::annotations() const
{
Object annotArray;
::Page *pdfPage = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1);
::Page *pdfPage = m_page->parentDoc->m_doc->doc->getCatalog()->getPage(m_page->index + 1);
pdfPage->getAnnots( &annotArray );
if ( !annotArray.isArray() || annotArray.arrayGetLength() < 1 )
{
......@@ -894,7 +894,7 @@ QList<Annotation*> Page::annotations() const
annotDict->lookup( "PA", &objPA );
if (!objPA.isNull())
{
::LinkAction * a = ::LinkAction::parseAction( &objPA, m_page->parentDoc->m_doc->doc.getCatalog()->getBaseURI() );
::LinkAction * a = ::LinkAction::parseAction( &objPA, m_page->parentDoc->m_doc->doc->getCatalog()->getBaseURI() );
Link * popplerLink = m_page->convertLinkActionToLink( a, QRectF(), m_page->parentDoc->m_doc );
if ( popplerLink )
{
......@@ -1237,7 +1237,7 @@ QList<Annotation*> Page::annotations() const
double Page::duration() const
{
::Page *p;
p = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1);
p = m_page->parentDoc->m_doc->doc->getCatalog()->getPage(m_page->index + 1);
if (p) return p->getDuration();
else return -1;
}
......
......@@ -69,15 +69,19 @@ namespace Poppler {
class DocumentData {
public:
DocumentData(GooString *filePath, GooString *ownerPassword, GooString *userPassword) :
doc(filePath, ownerPassword, userPassword)
DocumentData(GooString *filePath, GooString *ownerPassword, GooString *userPassword)
{
doc = new PDFDoc(filePath, ownerPassword, userPassword);
init(ownerPassword, userPassword);
}
DocumentData(MemStream *str, GooString *ownerPassword, GooString *userPassword) :
doc(str, ownerPassword, userPassword)
DocumentData(const QByteArray &data, GooString *ownerPassword, GooString *userPassword)
{
Object obj;
fileContents = data;
obj.initNull();
MemStream *str = new MemStream((char*)fileContents.data(), 0, fileContents.length(), &obj);
doc = new PDFDoc(str, ownerPassword, userPassword);
init(ownerPassword, userPassword);
}
......@@ -97,6 +101,7 @@ namespace Poppler {
~DocumentData()
{
delete doc;
qDeleteAll(m_embeddedFiles);
delete m_outputDev;
delete m_fontInfoScanner;
......@@ -121,7 +126,7 @@ namespace Poppler {
bgColor[1] = paperColor.green();
bgColor[2] = paperColor.blue();
SplashOutputDev * splashOutputDev = new SplashOutputDev(splashModeRGB8Qt, 4, gFalse, bgColor);
splashOutputDev->startDoc(doc.getXRef());
splashOutputDev->startDoc(doc->getXRef());
m_outputDev = splashOutputDev;
#endif
break;
......@@ -198,19 +203,20 @@ namespace Poppler {
void fillMembers()
{
m_fontInfoScanner = new FontInfoScanner(&doc);
int numEmb = doc.getCatalog()->numEmbeddedFiles();
m_fontInfoScanner = new FontInfoScanner(doc);
int numEmb = doc->getCatalog()->numEmbeddedFiles();
if (!(0 == numEmb)) {
// we have some embedded documents, build the list
for (int yalv = 0; yalv < numEmb; ++yalv) {
EmbFile *ef = doc.getCatalog()->embeddedFile(yalv);
EmbFile *ef = doc->getCatalog()->embeddedFile(yalv);
m_embeddedFiles.append(new EmbeddedFile(ef));
delete ef;
}
}
}
class PDFDoc doc;
PDFDoc *doc;
QByteArray fileContents;
bool locked;
FontInfoScanner *m_fontInfoScanner;
Document::RenderBackend m_backend;
......
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