[poppler] poppler/qt4/src: poppler-document.cc, 1.29, 1.30 poppler-link.cc, 1.9, 1.10 poppler-page.cc, 1.33, 1.34 poppler-private.h, 1.18, 1.19

Albert Astals Cid aacid at kemper.freedesktop.org
Sat Jan 13 15:19:23 PST 2007


Update of /cvs/poppler/poppler/qt4/src
In directory kemper:/tmp/cvs-serv15199/qt4/src

Modified Files:
	poppler-document.cc poppler-link.cc poppler-page.cc 
	poppler-private.h 
Log Message:
        * 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.


Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-document.cc,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- poppler-document.cc	13 Jan 2007 18:29:39 -0000	1.29
+++ poppler-document.cc	13 Jan 2007 23:19:21 -0000	1.30
@@ -56,13 +56,7 @@
 			      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 @@
     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 @@
     {
 	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 @@
 
     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 @@
 
     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 @@
 
     int Document::numPages() const
     {
-	return m_doc->doc.getNumPages();
+	return m_doc->doc->getNumPages();
     }
 
     QList<FontInfo> Document::fonts() const
@@ -206,7 +210,7 @@
 	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 @@
 	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 @@
 	    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 @@
 
     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 @@
 
     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 @@
 	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 @@
 
     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 @@
     
     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 @@
         {
             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;

Index: poppler-link.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-link.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- poppler-link.cc	13 Jan 2007 18:29:39 -0000	1.9
+++ poppler-link.cc	13 Jan 2007 23:19:21 -0000	1.10
@@ -37,7 +37,7 @@
 		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 @@
 		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();

Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-page.cc,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- poppler-page.cc	13 Jan 2007 18:29:39 -0000	1.33
+++ poppler-page.cc	13 Jan 2007 23:19:21 -0000	1.34
@@ -175,7 +175,7 @@
 #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 @@
       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 @@
   ::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 @@
 
   // 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 @@
   
   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 @@
   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 @@
 {
   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 @@
     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 @@
 {
   ::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 @@
 
 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 @@
 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 @@
   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<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 @@
             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 @@
 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;
 }

Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-private.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- poppler-private.h	13 Jan 2007 18:29:39 -0000	1.18
+++ poppler-private.h	13 Jan 2007 23:19:21 -0000	1.19
@@ -69,15 +69,19 @@
 
     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 @@
 	
 	~DocumentData()
 	{
+		delete doc;
 		qDeleteAll(m_embeddedFiles);
 		delete m_outputDev;
 		delete m_fontInfoScanner;
@@ -121,7 +126,7 @@
 			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 @@
 	
 	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;



More information about the poppler mailing list