[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kviewshell-0.7/kviewshell
From:       Stefan Kebekus <kebekus () kde ! org>
Date:       2006-06-01 18:42:10
Message-ID: 1149187330.524837.16434.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 547336 by kebekus:

fixes printing for PDF files


 D             DESIGN  
 M  +3 -0      TODO  
 M  +37 -2     plugins/pdf/pdfMultipage.cpp  
 M  +3 -1      plugins/pdf/pdfMultipage.h  
 M  +10 -0     plugins/pdf/pdfRenderer.cpp  
 M  +16 -0     plugins/pdf/pdfRenderer.h  


--- branches/work/kviewshell-0.7/kviewshell/TODO #547335:547336
@@ -1,7 +1,10 @@
 STEFAN's IMMEDIATE TODO LIST
 ============================
 
+SHELL
 
+* Die default-Implementierung fürs Drucken geht nicht mehr.
+
 DVI
 
 * Does graphics inclusion still work?
--- branches/work/kviewshell-0.7/kviewshell/plugins/pdf/pdfMultipage.cpp #547335:547336
@@ -25,6 +25,8 @@
 #include <kconfigdialog.h>
 #include <kfiledialog.h>
 #include <kparts/genericfactory.h>
+#include <kprinter.h>
+#include <ktempfile.h>
 
 #include "pdfMultipage.h"
 #include "pdfWidget.h"
@@ -106,14 +108,15 @@
   return r;
 }
 
+/*
 DocumentWidget* PdfMultiPage::createDocumentWidget(PageView *parent, DocumentPageCache *cache)
 {
   PdfWidget* documentWidget = new PdfWidget(parent, cache, "singlePageWidget");
 
   return documentWidget;
 }
+*/
 
-
 void PdfMultiPage::addConfigDialogs(KConfigDialog* configDialog)
 {
   OptionDialogPdfWidget* pdfConfigWidget = new OptionDialogPdfWidget(parentWdg);
@@ -125,7 +128,7 @@
 
 void PdfMultiPage::inverseSearch(const PageNumber& pageNumber, QPoint point, bool call)
 {
-// FIXME
+#warning FIXME
 /*
   Length x;
   Length y;
@@ -139,4 +142,36 @@
 }
 
 
+void PdfMultiPage::print()
+{
+  // Paranoid safety checks
+  if (pdfRenderer.isEmpty())
+    return;
+  
+  // Allocate the printer structure
+  KPrinter *printer = getPrinter(false);
+  if (printer == 0)
+    return;
+  
+  // initialize the printer using the print dialog
+  if ( printer->setup(parentWdg, i18n("Print %1").arg(m_file.section('/', -1))) ) {    
+    // Now do the printing. 
+    QValueList<int> pageList = printer->pageList();
+    if (pageList.isEmpty()) 
+      printer->abort();
+    else {
+      KTempFile tmpPSFile(QString::null, "ps");
+      tmpPSFile.close();
+      tmpPSFile.setAutoDelete(true);
+      
+      if (pdfRenderer.convertToPSFile(tmpPSFile.name(), pageList ) == true)
+	printer->printFiles( QStringList(tmpPSFile.name()), true );
+      else
+	printer->abort();
+    }
+    delete printer;
+  }
+}
+
+
 #include "pdfMultipage.moc"
--- branches/work/kviewshell-0.7/kviewshell/plugins/pdf/pdfMultipage.h #547335:547336
@@ -121,8 +121,10 @@
 
   virtual void addConfigDialogs(KConfigDialog* configDialog);
 
-  virtual DocumentWidget* createDocumentWidget(PageView *parent, DocumentPageCache *cache);
+  //  virtual DocumentWidget* createDocumentWidget(PageView *parent, DocumentPageCache *cache);
 
+  virtual void print();
+
 protected:
   virtual void setFile(bool success);
   virtual void enableActions(bool);
--- branches/work/kviewshell-0.7/kviewshell/plugins/pdf/pdfRenderer.cpp #547335:547336
@@ -455,6 +455,16 @@
 }
 
 
+bool PdfRenderer::convertToPSFile(QString filename, QValueList<int> &pageList )
+{
+  if (document == 0)
+    return false;
+
+#warning THIS BLOCKS THE GUI FOR SOME TIME, AN ASYNC METHOD WOULD BE BETTER
+  return document->print(filename, pageList, 600, 600, 0);
+}
+
+
 void PdfRenderer::inverseSearch(PageNumber pageNumber, Length x, Length y, bool call)
 {
   if (!pageNumber.isValid() || pageNumber > numPages)
--- branches/work/kviewshell-0.7/kviewshell/plugins/pdf/pdfRenderer.h #547335:547336
@@ -120,6 +120,22 @@
 
   virtual bool supportsTextSearch() const { return true; };
 
+
+  /** PDF to PostScript conversion
+      
+  This method converts the document to a PostScript file.
+  
+  @param filename name of the PostScript file to generate
+  
+  @param pageList list of pages that are to be converted, with the
+  usual convention that "1" means "first page"
+  
+  @returns 'true' if the conversion was successful, 'false' if it
+  wasn't. The conversion can fail, for example, when the user aborts
+  the operation.
+  */
+  bool convertToPSFile(QString filename, QValueList<int> &pageList );
+
   void inverseSearch(PageNumber pageNumber, Length x, Length y, bool call = false);
 
   /** This method will try to parse the reference part of the PDF
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic