Commit 2cb22b69 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Print PS and not images

Fixes 92204, backporting in a moment

svn path=/trunk/kdegraphics/kpdf/; revision=359628
parent a00e6146
......@@ -41,7 +41,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 QOutputDevPixmap.cpp QOutputDevKPrinter.cpp kpdf_part.cpp kpdf_pagewidget.cc part.cpp thumbnail.cpp thumbnaillist.cpp kpdf_error.cpp xpdf_errors.cpp thumbnailgenerator.cpp toc.cpp
libkpdfpart_la_SOURCES = QOutputDev.cpp QOutputDevPixmap.cpp kpdf_part.cpp kpdf_pagewidget.cc part.cpp thumbnail.cpp thumbnaillist.cpp kpdf_error.cpp xpdf_errors.cpp thumbnailgenerator.cpp toc.cpp
libkpdfpart_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
libkpdfpart_la_LIBADD = ../xpdf/libxpdf.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 )
: QOutputDev(paperColor), m_printer( printer ), m_painter( painter )
{
}
QOutputDevKPrinter::~QOutputDevKPrinter()
{
}
void QOutputDevKPrinter::startPage(int page, GfxState *state)
{
// TODO: page size ?
QOutputDev::startPage( page, state);
}
void QOutputDevKPrinter::endPage()
{
SplashColorPtr dataPtr;
int bh, bw;
QOutputDev::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 "QOutputDev.h"
class KPrinter;
class QOutputDevKPrinter : public QOutputDev
{
public:
QOutputDevKPrinter(QPainter& painter, SplashColor paperColor, KPrinter& printer);
virtual ~QOutputDevKPrinter();
//----- initialization and control
// Start a page.
virtual void startPage(int pageNum, GfxState *state);
// End a page
virtual void endPage();
protected:
void draw();
private:
KPrinter& m_printer; // the printer that we're drawing to
QPainter& m_painter; // the painter that we're drawing to
};
#endif
......@@ -46,6 +46,7 @@
#include <kuserprofile.h>
#include <kpassdlg.h>
#include <kio/netaccess.h>
#include <ktempfile.h>
#include "kpdf_error.h"
#include "part.h"
......@@ -58,8 +59,8 @@
#include "xpdf/ErrorCodes.h"
#include "GlobalParams.h"
#include "PDFDoc.h"
#include "PSOutputDev.h"
#include "TextOutputDev.h"
#include "QOutputDevKPrinter.h"
#include "QOutputDevPixmap.h"
#include "kpdf_pagewidget.h"
......@@ -917,20 +918,45 @@ void Part::printPreview()
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();)
if (!m_doc->okToPrint())
{
KMessageBox::error(widget(), i18n("Printing this document is not allowed."));
return;
}
KTempFile tf( QString::null, ".ps" );
PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), m_doc->getXRef(), m_doc->getCatalog(), 1, m_doc->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 <= m_doc->getNumPages(); i++) pages.push_back(i);
}
m_docMutex.lock();
m_doc->displayPage(&printdev, *i, printer.resolution(), printer.resolution(), 0, true, true);
if ( ++i != pages.end() )
printer.newPage();
m_doc->displayPages(psOut, pages, 72, 72, 0, globalParams->getPSCrop(), gFalse);
m_docMutex.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);
}
else
{
KMessageBox::error(widget(), i18n("Could not print the document. Please report to bugs.kde.org"));
delete psOut;
}
}
......
......@@ -1191,7 +1191,7 @@ int JBIG2Stream::lookChar() {
return EOF;
}
GString *JBIG2Stream::getPSFilter(int /*psLevel*/, char */*indent*/) {
GString *JBIG2Stream::getPSFilter(int /*psLevel*/, const char */*indent*/) {
return NULL;
}
......
......@@ -39,7 +39,7 @@ public:
virtual void reset();
virtual int getChar();
virtual int lookChar();
virtual GString *getPSFilter(int psLevel, char *indent);
virtual GString *getPSFilter(int psLevel, const char *indent);
virtual GBool isBinary(GBool last = gTrue);
private:
......
......@@ -366,7 +366,7 @@ void JPXStream::fillReadBuf() {
} while (readBufLen < 8);
}
GString *JPXStream::getPSFilter(int /*psLevel*/, char */*indent*/) {
GString *JPXStream::getPSFilter(int /*psLevel*/, const char */*indent*/) {
return NULL;
}
......
......@@ -273,7 +273,7 @@ public:
virtual void reset();
virtual int getChar();
virtual int lookChar();
virtual GString *getPSFilter(int psLevel, char *indent);
virtual GString *getPSFilter(int psLevel, const char *indent);
virtual GBool isBinary(GBool last = gTrue);
private:
......
......@@ -8,7 +8,7 @@ libxpdf_la_SOURCES = Annot.cc Array.cc BuiltinFont.cc BuiltinFontTables.cc \
GfxFont.cc GfxState.cc GlobalParams.cc JArithmeticDecoder.cc \
JBIG2Stream.cc Lexer.cc Link.cc NameToCharCode.cc Object.cc Outline.cc \
OutputDev.cc PDFDoc.cc PDFDocEncoding.cc PSTokenizer.cc \
Page.cc Parser.cc SplashOutputDev.cc Stream.cc JPXStream.cc \
Page.cc Parser.cc PSOutputDev.cc SplashOutputDev.cc Stream.cc JPXStream.cc \
TextOutputDev.cc UnicodeMap.cc UnicodeTypeTable.cc XRef.cc
noinst_LTLIBRARIES = libxpdf.la
......@@ -236,6 +236,19 @@ void PDFDoc::displayPages(OutputDev *out, int firstPage, int lastPage,
}
}
void PDFDoc::displayPages(OutputDev *out, list<int> &pages,
double hDPI, double vDPI, int rotate,
GBool crop, GBool doLinks,
GBool (*abortCheckCbk)(void *data),
void *abortCheckCbkData)
{
list<int>::const_iterator i;
for(i = pages.begin(); i != pages.end(); ++i)
displayPage(out, *i, hDPI, vDPI, rotate, crop, doLinks,
abortCheckCbk, abortCheckCbkData);
}
void PDFDoc::displayPageSlice(OutputDev *out, int page,
double hDPI, double vDPI,
int rotate, GBool crop,
......
......@@ -15,6 +15,7 @@
#pragma interface
#endif
#include <list>
#include <stdio.h>
#include "XRef.h"
#include "Link.h"
......@@ -29,6 +30,8 @@ class LinkAction;
class LinkDest;
class Outline;
using namespace std;
//------------------------------------------------------------------------
// PDFDoc
//------------------------------------------------------------------------
......@@ -91,6 +94,15 @@ public:
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
// Added by kpdf authors
// Display some pages
void displayPages(OutputDev *out, list<int> &pages,
double hDPI, double vDPI, int rotate,
GBool crop, GBool doLinks,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
// Display part of a page.
void displayPageSlice(OutputDev *out, int page,
double hDPI, double vDPI,
......
This diff is collapsed.
//========================================================================
//
// PSOutputDev.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef PSOUTPUTDEV_H
#define PSOUTPUTDEV_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include <stddef.h>
#include "config.h"
#include "Object.h"
#include "GlobalParams.h"
#include "OutputDev.h"
class GfxPath;
class GfxFont;
class GfxColorSpace;
class GfxSeparationColorSpace;
class PDFRectangle;
struct PSFont16Enc;
class PSOutCustomColor;
//------------------------------------------------------------------------
// PSOutputDev
//------------------------------------------------------------------------
enum PSOutMode {
psModePS,
psModeEPS,
psModeForm
};
enum PSFileType {
psFile, // write to file
psPipe, // write to pipe
psStdout, // write to stdout
psGeneric // write to a generic stream
};
typedef void (*PSOutputFunc)(void *stream, const char *data, int len);
class PSOutputDev: public OutputDev {
public:
// Open a PostScript output file, and write the prolog.
PSOutputDev(const char *fileName, XRef *xrefA, Catalog *catalog,
int firstPage, int lastPage, PSOutMode modeA,
int imgLLXA = 0, int imgLLYA = 0,
int imgURXA = 0, int imgURYA = 0,
GBool manualCtrlA = gFalse);
// Open a PSOutputDev that will write to a generic stream.
PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
XRef *xrefA, Catalog *catalog,
int firstPage, int lastPage, PSOutMode modeA,
int imgLLXA = 0, int imgLLYA = 0,
int imgURXA = 0, int imgURYA = 0,
GBool manualCtrlA = gFalse);
// Destructor -- writes the trailer and closes the file.
virtual ~PSOutputDev();
// Check if file was successfully created.
virtual GBool isOk() { return ok; }
//---- get info about output device
// Does this device use upside-down coordinates?
// (Upside-down means (0,0) is the top left corner of the page.)
virtual GBool upsideDown() { return gFalse; }
// Does this device use drawChar() or drawString()?
virtual GBool useDrawChar() { return gFalse; }
// Does this device use beginType3Char/endType3Char? Otherwise,
// text in Type 3 fonts will be drawn with drawChar/drawString.
virtual GBool interpretType3Chars() { return gFalse; }
//----- header/trailer (used only if manualCtrl is true)
// Write the document-level header.
void writeHeader(int firstPage, int lastPage,
PDFRectangle *mediaBox, PDFRectangle *cropBox);
// Write the Xpdf procset.
void writeXpdfProcset();
// Write the document-level setup.
void writeDocSetup(Catalog *catalog, int firstPage, int lastPage);
// Write the setup for the current page.
void writePageSetup();
// Write the trailer for the current page.
void writePageTrailer();
// Write the document trailer.
void writeTrailer();
//----- initialization and control
// Start a page.
virtual void startPage(int pageNum, GfxState *state);
// End a page.
virtual void endPage();
//----- save/restore graphics state
virtual void saveState(GfxState *state);
virtual void restoreState(GfxState *state);
//----- update graphics state
virtual void updateCTM(GfxState *state, double m11, double m12,
double m21, double m22, double m31, double m32);
virtual void updateLineDash(GfxState *state);
virtual void updateFlatness(GfxState *state);
virtual void updateLineJoin(GfxState *state);
virtual void updateLineCap(GfxState *state);
virtual void updateMiterLimit(GfxState *state);
virtual void updateLineWidth(GfxState *state);
virtual void updateFillColor(GfxState *state);
virtual void updateStrokeColor(GfxState *state);
//----- update text state
virtual void updateFont(GfxState *state);
virtual void updateTextMat(GfxState *state);
virtual void updateCharSpace(GfxState *state);
virtual void updateRender(GfxState *state);
virtual void updateRise(GfxState *state);
virtual void updateWordSpace(GfxState *state);
virtual void updateHorizScaling(GfxState *state);
virtual void updateTextPos(GfxState *state);
virtual void updateTextShift(GfxState *state, double shift);
//----- path painting
virtual void stroke(GfxState *state);
virtual void fill(GfxState *state);
virtual void eoFill(GfxState *state);
//----- path clipping
virtual void clip(GfxState *state);
virtual void eoClip(GfxState *state);
//----- text drawing
virtual void drawString(GfxState *state, GString *s);
virtual void endTextObject(GfxState *state);
//----- image drawing
virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg);
virtual void drawImage(GfxState *state, Object *ref, Stream *str,
int width, int height, GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg);
#if OPI_SUPPORT
//----- OPI functions
virtual void opiBegin(GfxState *state, Dict *opiDict);
virtual void opiEnd(GfxState *state, Dict *opiDict);
#endif
//----- Type 3 font operators
virtual void type3D0(GfxState *state, double wx, double wy);
virtual void type3D1(GfxState *state, double wx, double wy,
double llx, double lly, double urx, double ury);
//----- PostScript XObjects
virtual void psXObject(Stream *psStream, Stream *level1Stream);
//----- miscellaneous
void setOffset(double x, double y)
{ tx0 = x; ty0 = y; }
void setScale(double x, double y)
{ xScale0 = x; yScale0 = y; }
void setRotate(int rotateA)
{ rotate0 = rotateA; }
void setClip(double llx, double lly, double urx, double ury)
{ clipLLX0 = llx; clipLLY0 = lly; clipURX0 = urx; clipURY0 = ury; }
void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
void *data)
{ underlayCbk = cbk; underlayCbkData = data; }
void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
void *data)
{ overlayCbk = cbk; overlayCbkData = data; }
private:
void init(PSOutputFunc outputFuncA, void *outputStreamA,
PSFileType fileTypeA, XRef *xrefA, Catalog *catalog,
int firstPage, int lastPage, PSOutMode modeA,
int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
GBool manualCtrlA);
void setupResources(Dict *resDict);
void setupFonts(Dict *resDict);
void setupFont(GfxFont *font, Dict *parentResDict);
void setupEmbeddedType1Font(Ref *id, GString *psName);
void setupExternalType1Font(GString *fileName, GString *psName);
void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GString *psName);
void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
void setupExternalTrueTypeFont(GfxFont *font, GString *psName);
void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GString *psName);
void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
void setupType3Font(GfxFont *font, GString *psName, Dict *parentResDict);
void setupImages(Dict *resDict);
void setupImage(Ref id, Stream *str);
void addProcessColor(double c, double m, double y, double k);
void addCustomColor(GfxSeparationColorSpace *sepCS);
void doPath(GfxPath *path);
void doImageL1(Object *ref, GfxImageColorMap *colorMap,
GBool invert, GBool inlineImg,
Stream *str, int width, int height, int len);
void doImageL1Sep(GfxImageColorMap *colorMap,
GBool invert, GBool inlineImg,
Stream *str, int width, int height, int len);
void doImageL2(Object *ref, GfxImageColorMap *colorMap,
GBool invert, GBool inlineImg,
Stream *str, int width, int height, int len);
void dumpColorSpaceL2(GfxColorSpace *colorSpace);
#if OPI_SUPPORT
void opiBegin20(GfxState *state, Dict *dict);
void opiBegin13(GfxState *state, Dict *dict);
void opiTransform(GfxState *state, double x0, double y0,
double *x1, double *y1);
GBool getFileSpec(Object *fileSpec, Object *fileName);
#endif
void writePSChar(char c);
void writePS(const char *s);
void writePSFmt(const char *fmt, ...);
void writePSString(GString *s);
void writePSName(const char *s);
GString *filterPSName(GString *name);
PSLevel level; // PostScript level (1, 2, separation)
PSOutMode mode; // PostScript mode (PS, EPS, form)
int paperWidth; // width of paper, in pts
int paperHeight; // height of paper, in pts
int imgLLX, imgLLY, // imageable area, in pts
imgURX, imgURY;
PSOutputFunc outputFunc;
void *outputStream;
PSFileType fileType; // file / pipe / stdout
GBool manualCtrl;
int seqPage; // current sequential page number
void (*underlayCbk)(PSOutputDev *psOut, void *data);
void *underlayCbkData;
void (*overlayCbk)(PSOutputDev *psOut, void *data);
void *overlayCbkData;
XRef *xref; // the xref table for this PDF file
Ref *fontIDs; // list of object IDs of all used fonts
int fontIDLen; // number of entries in fontIDs array
int fontIDSize; // size of fontIDs array
Ref *fontFileIDs; // list of object IDs of all embedded fonts
int fontFileIDLen; // number of entries in fontFileIDs array
int fontFileIDSize; // size of fontFileIDs array
GString **fontFileNames; // list of names of all embedded external fonts
int fontFileNameLen; // number of entries in fontFileNames array
int fontFileNameSize; // size of fontFileNames array
int nextTrueTypeNum; // next unique number to append to a TrueType
// font name
PSFont16Enc *font16Enc; // encodings for substitute 16-bit fonts
int font16EncLen; // number of entries in font16Enc array
int font16EncSize; // size of font16Enc array
GList *xobjStack; // stack of XObject dicts currently being
// processed
int numSaves; // current number of gsaves
double tx0, ty0; // global translation
double xScale0, yScale0; // global scaling
int rotate0; // rotation angle (0, 90, 180, 270)
double clipLLX0, clipLLY0,
clipURX0, clipURY0;
double tx, ty; // global translation for current page
double xScale, yScale; // global scaling for current page
int rotate; // rotation angle for current page
GString *embFontList; // resource comments for embedded fonts
int processColors; // used process colors
PSOutCustomColor // used custom colors
*customColors;
GBool haveTextClip; // set if text has been drawn with a
// clipping render mode
GBool inType3Char; // inside a Type 3 CharProc
GString *t3String; // Type 3 content string
double t3WX, t3WY, // Type 3 character parameters
t3LLX, t3LLY, t3URX, t3URY;
GBool t3Cacheable; // cleared if char is not cacheable
#if OPI_SUPPORT
int opi13Nest; // nesting level of OPI 1.3 objects
int opi20Nest; // nesting level of OPI 2.0 objects
#endif
GBool ok; // set up ok?
friend class WinPDFPrinter;
};
#endif
......@@ -905,7 +905,7 @@ int ASCIIHexStream::lookChar() {
return buf;
}
GString *ASCIIHexStream::getPSFilter(int psLevel, char *indent) {
GString *ASCIIHexStream::getPSFilter(int psLevel, const char *indent) {
GString *s;
if (psLevel < 2) {
......@@ -986,7 +986,7 @@ int ASCII85Stream::lookChar() {
return b[index];
}
GString *ASCII85Stream::getPSFilter(int psLevel, char *indent) {
GString *ASCII85Stream::getPSFilter(int psLevel, const char *indent) {
GString *s;
if (psLevel < 2) {
......@@ -1168,7 +1168,7 @@ int LZWStream::getCode() {
return code;
}