Subversion Repositories Scribus

Rev

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