Subversion Repositories Scribus

Rev

Rev 22917 | Rev 23289 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22514 jghali 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
7
#ifndef SLAOUTPUT_H
8
#define SLAOUTPUT_H
9
 
10
#include <QBuffer>
11
#include <QColor>
12
#include <QBrush>
13
#include <QDebug>
14
#include <QImage>
15
#include <QPen>
16
#include <QList>
17
#include <QSizeF>
18
#include <QStack>
19
#include <QString>
20
#include <QTextStream>
21
#include <QTransform>
22
 
23
#include "fpointarray.h"
24
#include "importpdfconfig.h"
25
#include "pageitem.h"
26
#include "scribusdoc.h"
27
#include "scribusview.h"
28
#include "selection.h"
29
#include "vgradient.h"
30
 
22806 jghali 31
#if POPPLER_ENCODED_VERSION < POPPLER_VERSION_ENCODE(0, 73, 0)
22514 jghali 32
#include <poppler/goo/gtypes.h>
22806 jghali 33
#endif
22514 jghali 34
#include <poppler/Object.h>
35
#include <poppler/OutputDev.h>
36
#include <poppler/Gfx.h>
37
#include <poppler/GfxState.h>
38
#include <poppler/Stream.h>
39
#include <poppler/GfxFont.h>
40
#include <poppler/Link.h>
41
#include <poppler/PDFDoc.h>
42
#include <poppler/Error.h>
43
#include <poppler/Form.h>
44
#include <poppler/Page.h>
45
#include <poppler/Catalog.h>
46
#include <poppler/CharCodeToUnicode.h>
47
#include <poppler/FontEncodingTables.h>
48
#include <poppler/splash/SplashFontFileID.h>
49
#include <poppler/splash/SplashFontFile.h>
50
#include <poppler/splash/SplashFontEngine.h>
51
#include <poppler/splash/SplashFont.h>
52
#include <poppler/splash/SplashMath.h>
53
#include <poppler/splash/SplashPath.h>
54
#include <poppler/splash/SplashGlyphBitmap.h>
55
 
56
//------------------------------------------------------------------------
57
// LinkSubmitData
58
//------------------------------------------------------------------------
59
 
60
class LinkSubmitForm: public LinkAction
61
{
62
public:
63
        // Build a LinkImportData from an action dictionary.
64
        LinkSubmitForm(Object *actionObj);
65
        // Destructor.
66
        virtual ~LinkSubmitForm();
22918 jghali 67
 
22514 jghali 68
        // Was the LinkImportData created successfully?
22918 jghali 69
        GBool isOk() POPPLER_CONST override { return fileName != nullptr; }
22514 jghali 70
        // Accessors.
22918 jghali 71
        LinkActionKind getKind() POPPLER_CONST override { return actionUnknown; }
22514 jghali 72
        GooString *getFileName() { return fileName; }
73
        int getFlags() { return m_flags; }
22918 jghali 74
 
22514 jghali 75
private:
76
        GooString *fileName;            // file name
77
        int m_flags;
78
};
79
 
80
//------------------------------------------------------------------------
81
// LinkImportData
82
//------------------------------------------------------------------------
83
 
84
class LinkImportData: public LinkAction
85
{
86
public:
87
        // Build a LinkImportData from an action dictionary.
88
        LinkImportData(Object *actionObj);
89
        // Destructor.
90
        virtual ~LinkImportData();
22918 jghali 91
 
22514 jghali 92
        // Was the LinkImportData created successfully?
22918 jghali 93
        GBool isOk() POPPLER_CONST override { return fileName != nullptr; }
22514 jghali 94
        // Accessors.
22918 jghali 95
        LinkActionKind getKind() POPPLER_CONST override { return actionUnknown; }
22514 jghali 96
        GooString *getFileName() { return fileName; }
22918 jghali 97
 
22514 jghali 98
private:
99
        GooString *fileName;            // file name
100
};
101
//------------------------------------------------------------------------
102
// SplashOutFontFileID
103
//------------------------------------------------------------------------
104
 
105
class SplashOutFontFileID: public SplashFontFileID
106
{
107
public:
108
 
109
        SplashOutFontFileID(const Ref *rA) { r = *rA; }
110
        ~SplashOutFontFileID() {}
111
        GBool matches(SplashFontFileID *id)
112
        {
113
                return ((SplashOutFontFileID *)id)->r.num == r.num && ((SplashOutFontFileID *)id)->r.gen == r.gen;
114
        }
115
 
116
private:
117
        Ref r;
118
};
119
 
120
 
121
class AnoOutputDev : public OutputDev
122
{
123
public:
124
        AnoOutputDev(ScribusDoc* doc, QStringList *importedColors);
125
        virtual ~AnoOutputDev();
22916 jghali 126
 
22514 jghali 127
        GBool isOk() { return gTrue; }
22916 jghali 128
        GBool upsideDown() override { return gTrue; }
129
        GBool useDrawChar() override { return gFalse; }
130
        GBool interpretType3Chars() override { return gFalse; }
131
        GBool useTilingPatternFill() override  { return gFalse; }
132
        GBool useShadedFills(int type) override { return gFalse; }
133
        GBool useFillColorStop() override { return gFalse; }
134
        GBool useDrawForm() override { return gFalse; }
22514 jghali 135
 
22916 jghali 136
        void stroke(GfxState *state) override;
137
        void eoFill(GfxState *state) override;
138
        void fill(GfxState *state) override;
139
        void drawString(GfxState *state, POPPLER_CONST GooString *s) override;
140
 
22514 jghali 141
        QString CurrColorText;
142
        QString CurrColorFill;
143
        QString CurrColorStroke;
144
        double m_fontSize;
145
        GooString *m_fontName;
146
        GooString *m_itemText;
22918 jghali 147
 
22514 jghali 148
private:
22741 jghali 149
        QString getColor(GfxColorSpace *color_space, POPPLER_CONST_070 GfxColor *color, int *shade);
22514 jghali 150
        ScribusDoc* m_doc;
151
        QStringList *m_importedColors;
152
};
153
 
154
 
155
class SlaOutputDev : public OutputDev
156
{
157
public:
158
        SlaOutputDev(ScribusDoc* doc, QList<PageItem*> *Elements, QStringList *importedColors, int flags);
159
        virtual ~SlaOutputDev();
160
 
161
        LinkAction* SC_getAction(AnnotWidget *ano);
162
        LinkAction* SC_getAdditionalAction(const char *key, AnnotWidget *ano);
163
        static GBool annotations_callback(Annot *annota, void *user_data);
164
        bool handleTextAnnot(Annot* annota, double xCoor, double yCoor, double width, double height);
165
        bool handleLinkAnnot(Annot* annota, double xCoor, double yCoor, double width, double height);
166
        bool handleWidgetAnnot(Annot* annota, double xCoor, double yCoor, double width, double height);
22609 craig 167
        void applyTextStyle(PageItem* ite, const QString& fontName, const QString& textColor, double fontSize);
22514 jghali 168
        void handleActions(PageItem* ite, AnnotWidget *ano);
169
        void startDoc(PDFDoc *doc, XRef *xrefA, Catalog *catA);
170
 
171
        GBool isOk() { return gTrue; }
22916 jghali 172
        GBool upsideDown() override { return gTrue; }
173
        GBool useDrawChar() override { return gTrue; }
174
        GBool interpretType3Chars() override { return gTrue; }
175
        GBool useTilingPatternFill() override { return gTrue; }
176
        GBool useShadedFills(int type) override { return type <= 7; }
177
        GBool useFillColorStop() override { return gTrue; }
178
        GBool useDrawForm() override { return gFalse; }
179
 
22514 jghali 180
//      virtual GBool needClipToCropBox() { return gTrue; }
22916 jghali 181
        void startPage(int pageNum, GfxState *, XRef *) override;
182
        void endPage() override;
22917 jghali 183
 
22514 jghali 184
        // graphics state
22917 jghali 185
        void saveState(GfxState *state) override;
186
        void restoreState(GfxState *state) override;
22514 jghali 187
 
188
        //----- path painting
22916 jghali 189
        void stroke(GfxState *state) override;
190
        void fill(GfxState *state) override;
191
        void eoFill(GfxState *state) override;
192
        GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str, POPPLER_CONST_070 double *pmat, int paintType, int tilingType, Dict *resDict, POPPLER_CONST_070 double *mat, POPPLER_CONST_070 double *bbox, int x0, int y0, int x1, int y1, double xStep, double yStep) override;
193
        GBool functionShadedFill(GfxState * /*state*/, GfxFunctionShading * /*shading*/) override { qDebug() << "Function Shaded Fill";  return gFalse; }
194
        GBool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax) override;
195
        GBool axialShadedSupportExtend(GfxState *state, GfxAxialShading *shading)  override { return (shading->getExtend0() == shading->getExtend1()); }
196
        GBool radialShadedFill(GfxState *state, GfxRadialShading *shading, double sMin, double sMax) override;
197
        GBool radialShadedSupportExtend(GfxState *state, GfxRadialShading *shading) override { return (shading->getExtend0() == shading->getExtend1()); }
198
        GBool gouraudTriangleShadedFill(GfxState *state, GfxGouraudTriangleShading *shading) override;
199
        GBool patchMeshShadedFill(GfxState *state, GfxPatchMeshShading *shading) override;
200
 
22514 jghali 201
        //----- path clipping
22916 jghali 202
        void clip(GfxState *state) override;
203
        void eoClip(GfxState *state) override;
204
        void clipToStrokePath(GfxState * /*state*/) override { qDebug() << "Clip to StrokePath"; }
22514 jghali 205
        virtual GBool deviceHasTextClip(GfxState *state) { return gFalse; }
206
 
207
  // If current colorspace is pattern,
208
  // does this device support text in pattern colorspace?
209
        virtual GBool supportTextCSPattern(GfxState *state)
210
        {
211
                return state->getFillColorSpace()->getMode() == csPattern;
212
        }
213
 
214
  // If current colorspace is pattern,
215
  // need this device special handling for masks in pattern colorspace?
216
        virtual GBool fillMaskCSPattern(GfxState * state)
217
        {
218
                return state->getFillColorSpace()->getMode() == csPattern;
219
        }
220
 
221
        virtual void endMaskClip(GfxState *state) { qDebug() << "End Mask Clip"; }
222
 
223
  //----- grouping operators
22916 jghali 224
        void beginMarkedContent(POPPLER_CONST char *name, Dict *properties) override;
22678 jghali 225
        virtual void beginMarkedContent(POPPLER_CONST char *name, Object *dictRef);
22916 jghali 226
        void endMarkedContent(GfxState *state) override;
227
        void markPoint(POPPLER_CONST char *name) override;
228
        void markPoint(POPPLER_CONST char *name, Dict *properties) override;
229
 
22514 jghali 230
        //----- image drawing
22916 jghali 231
        void drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool interpolate, GBool inlineImg) override;
232
        void drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool interpolate, int *maskColors, GBool inlineImg) override;
233
        void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
22514 jghali 234
                                   int width, int height,
235
                                   GfxImageColorMap *colorMap,
236
                                   GBool interpolate,
237
                                   Stream *maskStr,
238
                                   int maskWidth, int maskHeight,
239
                                   GfxImageColorMap *maskColorMap,
22916 jghali 240
                                   GBool maskInterpolate) override;
22514 jghali 241
 
22916 jghali 242
        void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
22514 jghali 243
                                   int width, int height,
244
                                   GfxImageColorMap *colorMap,
245
                                   GBool interpolate,
246
                                   Stream *maskStr,
247
                                   int maskWidth, int maskHeight,
22916 jghali 248
                                   GBool maskInvert, GBool maskInterpolate) override; // { qDebug() << "Draw Masked Image"; }
22514 jghali 249
 
250
        //----- transparency groups and soft masks
22916 jghali 251
        void beginTransparencyGroup(GfxState *state, POPPLER_CONST_070 double *bbox, GfxColorSpace * /*blendingColorSpace*/, GBool /*isolated*/, GBool /*knockout*/, GBool /*forSoftMask*/) override;
252
        void paintTransparencyGroup(GfxState *state, POPPLER_CONST_070 double *bbox) override;
253
        void endTransparencyGroup(GfxState *state) override;
254
        void setSoftMask(GfxState * /*state*/, POPPLER_CONST_070 double * /*bbox*/, GBool /*alpha*/, Function * /*transferFunc*/, GfxColor * /*backdropColor*/) override;
255
        void clearSoftMask(GfxState * /*state*/) override;
22514 jghali 256
 
22916 jghali 257
        void updateFillColor(GfxState *state) override;
258
        void updateStrokeColor(GfxState *state) override;
259
        void updateFont(GfxState *state) override;
260
 
22514 jghali 261
        //----- text drawing
22916 jghali 262
        void  beginTextObject(GfxState *state) override;
263
        void  endTextObject(GfxState *state) override;
264
        void  drawChar(GfxState *state, double /*x*/, double /*y*/, double /*dx*/, double /*dy*/, double /*originX*/, double /*originY*/, CharCode /*code*/, int /*nBytes*/, Unicode * /*u*/, int /*uLen*/) override;
265
        GBool beginType3Char(GfxState * /*state*/, double /*x*/, double /*y*/, double /*dx*/, double /*dy*/, CharCode /*code*/, Unicode * /*u*/, int /*uLen*/) override;
266
        void  endType3Char(GfxState * /*state*/) override;
267
        void  type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/) override;
268
        void  type3D1(GfxState * /*state*/, double /*wx*/, double /*wy*/, double /*llx*/, double /*lly*/, double /*urx*/, double /*ury*/) override;
269
 
22514 jghali 270
        //----- form XObjects
22916 jghali 271
        void drawForm(Ref /*id*/) override { qDebug() << "Draw Form"; }
272
 
22514 jghali 273
        //----- links
22916 jghali 274
        void processLink(AnnotLink * /*link*/) override { qDebug() << "Draw Link"; }
275
 
22514 jghali 276
        bool layersSetByOCG;
277
        double cropOffsetX;
278
        double cropOffsetY;
279
        int rotate;
280
 
281
private:
282
        void getPenState(GfxState *state);
22741 jghali 283
        QString getColor(GfxColorSpace *color_space, POPPLER_CONST_070 GfxColor *color, int *shade);
22514 jghali 284
        QString getAnnotationColor(const AnnotColor *color);
285
        QString convertPath(GfxPath *path);
286
        int getBlendMode(GfxState *state);
287
        void applyMask(PageItem *ite);
22635 craig 288
        void pushGroup(const QString& maskName = "", GBool forSoftMask = gFalse, GBool alpha = gFalse, bool inverted = false);
22514 jghali 289
        QString UnicodeParsedString(POPPLER_CONST GooString *s1);
290
        bool checkClip();
291
        bool pathIsClosed;
292
        QString CurrColorFill;
293
        int CurrFillShade;
294
        QString CurrColorStroke;
295
        int CurrStrokeShade;
296
        Qt::PenCapStyle PLineEnd;
297
        Qt::PenJoinStyle PLineJoin;
298
        QVector<double> DashValues;
299
        double DashOffset;
300
        QString Coords;
301
        FPointArray m_currentClipPath;
302
        QStack<FPointArray> m_clipPaths;
303
        struct groupEntry
304
        {
305
                QList<PageItem*> Items;
306
                GBool forSoftMask;
307
                GBool isolated;
308
                GBool alpha;
309
                QString maskName;
310
                bool inverted;
311
        };
312
        QStack<groupEntry> m_groupStack;
313
        QString m_currentMask;
314
        ScribusDoc* m_doc;
315
        Selection* tmpSel;
316
        QList<PageItem*> *m_Elements;
317
        QStringList *m_importedColors;
318
        QTransform m_ctm;
319
        struct F3Entry
320
        {
321
                bool colored;
322
        };
323
        QStack<F3Entry> m_F3Stack;
324
        struct mContent
325
        {
326
                QString name;
327
                QString ocgName;
328
        };
329
        QStack<mContent> m_mcStack;
330
        int inPattern;
331
        int layerNum;
332
        int currentLayer;
333
        bool firstLayer;
334
        int importerFlags;
335
        int updateGUICounter;
336
        XRef *xref;             // xref table for current document
337
        PDFDoc *pdfDoc;
338
        Catalog *catalog;
339
        SplashFontEngine *m_fontEngine;
340
        SplashFont *m_font;
341
        FormPageWidgets *m_formWidgets;
342
        QHash<QString, QList<int> > m_radioMap;
343
        QHash<int, PageItem*> m_radioButtons;
344
        int m_actPage;
345
};
346
 
347
#endif