Commit 4fca42dd authored by Albert Astals Cid's avatar Albert Astals Cid

*** empty log message ***

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=360211
parent 89cd5a2f
......@@ -42,7 +42,7 @@ shellrc_DATA = kpdf_shell.rc
kde_module_LTLIBRARIES = libkpdfpart.la
# the Part's source, library search path, and link libraries
libkpdfpart_la_SOURCES = QOutputDev.cpp QOutputDevKPrinter.cpp kpdf_part.cpp pageview.cpp thumbnaillist.cpp kpdf_error.cpp xpdf_errors.cpp thumbnailgenerator.cpp document.cpp page.cpp searchwidget.cpp toc.cpp kpdf_dcop.skel pageviewutils.cpp
libkpdfpart_la_SOURCES = QOutputDev.cpp kpdf_part.cpp pageview.cpp thumbnaillist.cpp kpdf_error.cpp xpdf_errors.cpp thumbnailgenerator.cpp document.cpp page.cpp searchwidget.cpp toc.cpp kpdf_dcop.skel pageviewutils.cpp
libkpdfpart_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
libkpdfpart_la_LIBADD = ../xpdf/libxpdf.la conf/libconf.la $(LIB_KPARTS) $(LIB_KFILE) $(LIB_KDEPRINT) $(LIB_KUTILS) -lm
......
/***************************************************************************
* Copyright (C) 2004 by Dominique Devriese <devriese@kde.org> *
* Copyright (C) 2004 by Christophe Devriese *
* <Christophe.Devriese@student.kuleuven.ac.be> *
* Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "SplashBitmap.h"
#include "SplashTypes.h"
#include "QOutputDevKPrinter.h"
#include <kprinter.h>
#include <qpainter.h>
#include <qimage.h>
QOutputDevKPrinter::QOutputDevKPrinter(QPainter& painter, SplashColor paperColor, KPrinter& printer )
: SplashOutputDev(splashModeRGB8, false, paperColor), m_printer( printer ), m_painter( painter )
{
}
QOutputDevKPrinter::~QOutputDevKPrinter()
{
}
void QOutputDevKPrinter::startPage(int page, GfxState *state)
{
// TODO: page size ?
SplashOutputDev::startPage( page, state);
}
void QOutputDevKPrinter::endPage()
{
SplashColorPtr dataPtr;
int bh, bw;
SplashOutputDev::endPage();
bh = getBitmap()->getHeight();
bw = getBitmap()->getWidth();
dataPtr = getBitmap()->getDataPtr();
m_painter.drawPixmap(0, 0, QImage((uchar*)dataPtr.rgb8, bw, bh, 32, 0, 0, QImage::IgnoreEndian));
}
/***************************************************************************
* Copyright (C) 2004 by Dominique Devriese <devriese@kde.org> *
* Copyright (C) 2004 by Christophe Devriese *
* <Christophe.Devriese@student.kuleuven.ac.be> *
* Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef QOUTPUTDEVKPRINTER_H
#define QOUTPUTDEVKPRINTER_H
#include "XRef.h"
#include "SplashOutputDev.h"
class KPrinter;
class QPainter;
class QOutputDevKPrinter : public SplashOutputDev
{
public:
QOutputDevKPrinter(QPainter& painter, SplashColor paperColor, KPrinter& printer);
virtual ~QOutputDevKPrinter();
// Start a page.
virtual void startPage(int pageNum, GfxState *state);
// End a page
virtual void endPage();
private:
KPrinter& m_printer; // the printer that we're drawing to
QPainter& m_painter; // the painter that we're drawing to
};
#endif
......@@ -16,7 +16,6 @@ Things to do in order to merge in HEAD (first item has highest priority):
-> fix viewport restoring after zoom (not, fix zoom globally)
-> link thumbnails view with document
-> this may be postponed after merge: implementing async document generator using Albert's generator thread
-> this may be postponed after merge: albert: printing in a good way
-> new icons (contest at kde-look has ended and we know the winner. good choice :-)
-> take care of naming on merge, too differences (remove some kpdf_* prefixes
and rename internals toodocument->kpdfdocument)
......@@ -41,6 +40,8 @@ More items (first items will enter 'In progress list' first):
-> wrong zoom buttons order (BR74248) (check consistancy with kdvi/kghostview/.. (not konq))
Done (newest feature comes firts):
-> ADD: Printing as PS instead of as image (Albert)
-> ADD: Remember page on session logout and put the document in it on session restore (Albert)
-> ADD: gfx capturing tool
-> ADD: composited renderer framework (in addition to a fast light one)
-> FIX: pageview repaint done internally (speed boost and reduced memory consumption)
......
......@@ -21,7 +21,9 @@
#include <kmessagebox.h>
#include <kmimetype.h>
#include <kpassdlg.h>
#include <kprinter.h>
#include <kstandarddirs.h>
#include <ktempfile.h>
#include <kapplication.h>
#include <krun.h>
#include <kurl.h>
......@@ -31,6 +33,7 @@
// local includes
#include "ErrorCodes.h"
#include "PDFDoc.h"
#include "PSOutputDev.h"
#include "QOutputDev.h"
#include "kpdf_error.h"
......@@ -299,6 +302,49 @@ void KPDFDocument::requestTextPage( uint n )
page->setSearchPage( td.takeTextPage() );
}
bool KPDFDocument::okToPrint() const
{
return d->pdfdoc->okToPrint();
}
bool KPDFDocument::print(KPrinter &printer)
{
KTempFile tf( QString::null, ".ps" );
PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), d->pdfdoc->getXRef(), d->pdfdoc->getCatalog(), 1, d->pdfdoc->getNumPages(), psModePS);
if (psOut->isOk())
{
std::list<int> pages;
if (!printer.previewOnly())
{
QValueList<int> pageList = printer.pageList();
QValueList<int>::const_iterator it;
for(it = pageList.begin(); it != pageList.end(); ++it) pages.push_back(*it);
}
else
{
for(int i = 1; i <= d->pdfdoc->getNumPages(); i++) pages.push_back(i);
}
d->docLock.lock();
d->pdfdoc->displayPages(psOut, pages, 72, 72, 0, globalParams->getPSCrop(), gFalse);
d->docLock.unlock();
// needs to be here so that the file is flushed, do not merge with the one
// in the else
delete psOut;
printer.printFiles(tf.name(), true);
return true;
}
else
{
delete psOut;
return false;
}
}
// BEGIN slots
void KPDFDocument::slotSetCurrentPage( int page, const QRect & viewport )
{
......
......@@ -14,6 +14,8 @@
#include <qobject.h>
#include <qvaluevector.h>
class KPrinter;
class Outline;
class KPDFPage;
......@@ -74,6 +76,9 @@ public:
void requestPixmap( int id, uint page, int width, int height, bool syncronous = false );
void requestTextPage( uint page );
bool okToPrint() const;
bool print(KPrinter &printer);
//public slots:
// document commands via slots
void slotSetCurrentPage( int page, const QRect & viewport = QRect() );
......
......@@ -47,13 +47,13 @@
#include "kpdf_error.h"
#include "GlobalParams.h"
#include "QOutputDevKPrinter.h"
#include "kpdf_part.h"
#include "pageview.h"
#include "thumbnaillist.h"
#include "searchwidget.h"
#include "document.h"
#include "page.h"
#include "toc.h"
#include "preferencesdialog.h"
#include "settings.h"
......@@ -398,91 +398,79 @@ void Part::slotNewConfig()
void Part::slotPrintPreview()
{
/*
if (m_doc == 0)
return;
if (document->pages() == 0) return;
double width, height;
int landscape, portrait;
KPrinter printer;
const KPDFPage *page;
printer.setMinMax(1, m_doc->getNumPages());
printer.setMinMax(1, document->pages());
printer.setPreviewOnly( true );
printer.setMargins(0, 0, 0, 0);
// if some pages are landscape and others are not the most common win as kprinter does
// not accept a per page setting
// if some pages are landscape and others are not the most common win as kprinter does
// not accept a per page setting
landscape = 0;
portrait = 0;
for (int i = 1; i <= m_doc->getNumPages(); i++)
for (uint i = 0; i < document->pages(); i++)
{
width = m_doc->getPageWidth(i);
height = m_doc->getPageHeight(i);
if (m_doc->getPageRotate(i) == 90 || m_doc->getPageRotate(i) == 270) qSwap(width, height);
if (width > height) landscape++;
else portrait++;
}
page = document->page(i);
width = page->width();
height = page->height();
if (page->rotation() == 90 || page->rotation() == 270) qSwap(width, height);
if (width > height) landscape++;
else portrait++;
}
if (landscape > portrait) printer.setOption("orientation-requested", "4");
doPrint(printer);
*/
}
void Part::slotPrint()
{
/*
if (m_doc == 0)
return;
double width, height;
int landscape, portrait;
KPrinter printer;
printer.setPageSelection(KPrinter::ApplicationSide);
printer.setMinMax(1, m_doc->getNumPages());
printer.setCurrentPage(m_currentPage);
printer.setMargins(0, 0, 0, 0);
// if some pages are landscape and others are not the most common win as kprinter does
// not accept a per page setting
landscape = 0;
portrait = 0;
for (int i = 1; i <= m_doc->getNumPages(); i++)
{
width = m_doc->getPageWidth(i);
height = m_doc->getPageHeight(i);
if (m_doc->getPageRotate(i) == 90 || m_doc->getPageRotate(i) == 270) qSwap(width, height);
if (width > height) landscape++;
else portrait++;
}
if (landscape > portrait) printer.setOrientation(KPrinter::Landscape);
if (printer.setup(widget()))
{
doPrint( printer );
}
*/
if (document->pages() == 0) return;
double width, height;
int landscape, portrait;
KPrinter printer;
const KPDFPage *page;
printer.setPageSelection(KPrinter::ApplicationSide);
printer.setMinMax(1, document->pages());
printer.setCurrentPage(document->currentPage()+1);
printer.setMargins(0, 0, 0, 0);
// if some pages are landscape and others are not the most common win as kprinter does
// not accept a per page setting
landscape = 0;
portrait = 0;
for (uint i = 0; i < document->pages(); i++)
{
page = document->page(i);
width = page->width();
height = page->height();
if (page->rotation() == 90 || page->rotation() == 270) qSwap(width, height);
if (width > height) landscape++;
else portrait++;
}
if (landscape > portrait) printer.setOrientation(KPrinter::Landscape);
if (printer.setup(widget())) doPrint( printer );
}
void Part::doPrint( KPrinter& /*printer*/ )
void Part::doPrint(KPrinter &printer)
{
/*
QPainter painter( &printer );
SplashColor paperColor;
paperColor.rgb8 = splashMakeRGB8(0xff, 0xff, 0xff);
QOutputDevKPrinter printdev( painter, paperColor, printer );
printdev.startDoc(m_doc->getXRef());
QValueList<int> pages = printer.pageList();
for ( QValueList<int>::ConstIterator i = pages.begin(); i != pages.end();)
{
m_docMutex.lock();
m_doc->displayPage(&printdev, *i, printer.resolution(), printer.resolution(), 0, true, true);
if ( ++i != pages.end() )
printer.newPage();
m_docMutex.unlock();
}
*/
if (!document->okToPrint())
{
KMessageBox::error(widget(), i18n("Printing this document is not allowed."));
return;
}
if (!document->print(printer))
{
KMessageBox::error(widget(), i18n("Could not print the document. Please report to bugs.kde.org"));
}
}
void Part::restoreDocument(const KURL &url, int page)
......
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