Subversion Repositories Scribus

Rev

Rev 24537 | 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
 
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
 
24374 jghali 144
        QString currColorText;
145
        QString currColorFill;
146
        QString currColorStroke;
147
        double  fontSize {12};
148
        GooString *fontName {nullptr};
149
        GooString *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
 
24374 jghali 158
 
22514 jghali 159
class SlaOutputDev : public OutputDev
160
{
161
public:
162
        SlaOutputDev(ScribusDoc* doc, QList<PageItem*> *Elements, QStringList *importedColors, int flags);
163
        virtual ~SlaOutputDev();
164
 
165
        LinkAction* SC_getAction(AnnotWidget *ano);
23478 jghali 166
#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 86, 0)
167
        std::unique_ptr<LinkAction> SC_getAdditionalAction(const char *key, AnnotWidget *ano);
168
#else
22514 jghali 169
        LinkAction* SC_getAdditionalAction(const char *key, AnnotWidget *ano);
23478 jghali 170
#endif
22514 jghali 171
        static GBool annotations_callback(Annot *annota, void *user_data);
172
        bool handleTextAnnot(Annot* annota, double xCoor, double yCoor, double width, double height);
173
        bool handleLinkAnnot(Annot* annota, double xCoor, double yCoor, double width, double height);
174
        bool handleWidgetAnnot(Annot* annota, double xCoor, double yCoor, double width, double height);
22609 craig 175
        void applyTextStyle(PageItem* ite, const QString& fontName, const QString& textColor, double fontSize);
22514 jghali 176
        void handleActions(PageItem* ite, AnnotWidget *ano);
177
        void startDoc(PDFDoc *doc, XRef *xrefA, Catalog *catA);
178
 
179
        GBool isOk() { return gTrue; }
22916 jghali 180
        GBool upsideDown() override { return gTrue; }
181
        GBool useDrawChar() override { return gTrue; }
182
        GBool interpretType3Chars() override { return gTrue; }
183
        GBool useTilingPatternFill() override { return gTrue; }
184
        GBool useShadedFills(int type) override { return type <= 7; }
185
        GBool useFillColorStop() override { return gTrue; }
186
        GBool useDrawForm() override { return gFalse; }
187
 
22514 jghali 188
//      virtual GBool needClipToCropBox() { return gTrue; }
22916 jghali 189
        void startPage(int pageNum, GfxState *, XRef *) override;
190
        void endPage() override;
22917 jghali 191
 
22514 jghali 192
        // graphics state
22917 jghali 193
        void saveState(GfxState *state) override;
194
        void restoreState(GfxState *state) override;
22514 jghali 195
 
196
        //----- path painting
22916 jghali 197
        void stroke(GfxState *state) override;
198
        void fill(GfxState *state) override;
199
        void eoFill(GfxState *state) override;
24537 jghali 200
#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(21, 3, 0)
201
        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;
202
#else
22916 jghali 203
        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;
24537 jghali 204
#endif
22916 jghali 205
        GBool functionShadedFill(GfxState * /*state*/, GfxFunctionShading * /*shading*/) override { qDebug() << "Function Shaded Fill";  return gFalse; }
206
        GBool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax) override;
207
        GBool axialShadedSupportExtend(GfxState *state, GfxAxialShading *shading)  override { return (shading->getExtend0() == shading->getExtend1()); }
208
        GBool radialShadedFill(GfxState *state, GfxRadialShading *shading, double sMin, double sMax) override;
209
        GBool radialShadedSupportExtend(GfxState *state, GfxRadialShading *shading) override { return (shading->getExtend0() == shading->getExtend1()); }
210
        GBool gouraudTriangleShadedFill(GfxState *state, GfxGouraudTriangleShading *shading) override;
211
        GBool patchMeshShadedFill(GfxState *state, GfxPatchMeshShading *shading) override;
212
 
22514 jghali 213
        //----- path clipping
22916 jghali 214
        void clip(GfxState *state) override;
215
        void eoClip(GfxState *state) override;
216
        void clipToStrokePath(GfxState * /*state*/) override { qDebug() << "Clip to StrokePath"; }
22514 jghali 217
        virtual GBool deviceHasTextClip(GfxState *state) { return gFalse; }
218
 
219
  // If current colorspace is pattern,
220
  // does this device support text in pattern colorspace?
221
        virtual GBool supportTextCSPattern(GfxState *state)
222
        {
223
                return state->getFillColorSpace()->getMode() == csPattern;
224
        }
225
 
226
  // If current colorspace is pattern,
227
  // need this device special handling for masks in pattern colorspace?
228
        virtual GBool fillMaskCSPattern(GfxState * state)
229
        {
230
                return state->getFillColorSpace()->getMode() == csPattern;
231
        }
232
 
233
        virtual void endMaskClip(GfxState *state) { qDebug() << "End Mask Clip"; }
234
 
235
  //----- grouping operators
22916 jghali 236
        void beginMarkedContent(POPPLER_CONST char *name, Dict *properties) override;
22678 jghali 237
        virtual void beginMarkedContent(POPPLER_CONST char *name, Object *dictRef);
22916 jghali 238
        void endMarkedContent(GfxState *state) override;
239
        void markPoint(POPPLER_CONST char *name) override;
240
        void markPoint(POPPLER_CONST char *name, Dict *properties) override;
241
 
22514 jghali 242
        //----- image drawing
22916 jghali 243
        void drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool interpolate, GBool inlineImg) override;
23289 jghali 244
        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 245
        void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
22514 jghali 246
                                   int width, int height,
247
                                   GfxImageColorMap *colorMap,
248
                                   GBool interpolate,
249
                                   Stream *maskStr,
250
                                   int maskWidth, int maskHeight,
251
                                   GfxImageColorMap *maskColorMap,
22916 jghali 252
                                   GBool maskInterpolate) override;
22514 jghali 253
 
22916 jghali 254
        void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
22514 jghali 255
                                   int width, int height,
256
                                   GfxImageColorMap *colorMap,
257
                                   GBool interpolate,
258
                                   Stream *maskStr,
259
                                   int maskWidth, int maskHeight,
22916 jghali 260
                                   GBool maskInvert, GBool maskInterpolate) override; // { qDebug() << "Draw Masked Image"; }
22514 jghali 261
 
262
        //----- transparency groups and soft masks
22916 jghali 263
        void beginTransparencyGroup(GfxState *state, POPPLER_CONST_070 double *bbox, GfxColorSpace * /*blendingColorSpace*/, GBool /*isolated*/, GBool /*knockout*/, GBool /*forSoftMask*/) override;
264
        void paintTransparencyGroup(GfxState *state, POPPLER_CONST_070 double *bbox) override;
265
        void endTransparencyGroup(GfxState *state) override;
266
        void setSoftMask(GfxState * /*state*/, POPPLER_CONST_070 double * /*bbox*/, GBool /*alpha*/, Function * /*transferFunc*/, GfxColor * /*backdropColor*/) override;
267
        void clearSoftMask(GfxState * /*state*/) override;
22514 jghali 268
 
22916 jghali 269
        void updateFillColor(GfxState *state) override;
270
        void updateStrokeColor(GfxState *state) override;
24374 jghali 271
        void updateFont(GfxState* state) override;
22916 jghali 272
 
22514 jghali 273
        //----- text drawing
22916 jghali 274
        void  beginTextObject(GfxState *state) override;
275
        void  endTextObject(GfxState *state) override;
23289 jghali 276
        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;
277
        GBool beginType3Char(GfxState * /*state*/, double /*x*/, double /*y*/, double /*dx*/, double /*dy*/, CharCode /*code*/, POPPLER_CONST_082 Unicode * /*u*/, int /*uLen*/) override;
22916 jghali 278
        void  endType3Char(GfxState * /*state*/) override;
279
        void  type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/) override;
280
        void  type3D1(GfxState * /*state*/, double /*wx*/, double /*wy*/, double /*llx*/, double /*lly*/, double /*urx*/, double /*ury*/) override;
281
 
22514 jghali 282
        //----- form XObjects
22916 jghali 283
        void drawForm(Ref /*id*/) override { qDebug() << "Draw Form"; }
284
 
22514 jghali 285
        //----- links
22916 jghali 286
        void processLink(AnnotLink * /*link*/) override { qDebug() << "Draw Link"; }
287
 
22514 jghali 288
        bool layersSetByOCG;
23377 craig 289
        double cropOffsetX {0.0};
290
        double cropOffsetY {0.0};
22514 jghali 291
        int rotate;
292
 
24374 jghali 293
protected:
294
        void setItemFillAndStroke(GfxState* state, PageItem* textNode);
295
        void applyMask(PageItem* ite);
296
        void pushGroup(const QString& maskName = "", GBool forSoftMask = gFalse, GBool alpha = gFalse, bool inverted = false);
297
 
298
        ScribusDoc* m_doc;
299
        Qt::PenCapStyle m_lineEnd{ Qt::FlatCap };
300
        Qt::PenJoinStyle m_lineJoin{ Qt::MiterJoin };
301
        QList<PageItem*>* m_Elements;
302
 
303
        struct groupEntry
304
        {
305
                QList<PageItem*> Items;
306
                GBool forSoftMask;
307
                GBool isolated;
308
                GBool alpha;
309
                QString maskName;
310
                QPointF maskPos;
311
                bool inverted;
312
        };
313
 
314
        QStack<groupEntry> m_groupStack;
315
        QString m_currColorFill;
316
        QString m_currColorStroke;
317
        int m_currFillShade{ 100 };
318
        int m_currStrokeShade {100};
319
 
22514 jghali 320
private:
321
        void getPenState(GfxState *state);
22741 jghali 322
        QString getColor(GfxColorSpace *color_space, POPPLER_CONST_070 GfxColor *color, int *shade);
22514 jghali 323
        QString getAnnotationColor(const AnnotColor *color);
23395 jghali 324
        QString convertPath(POPPLER_CONST_083 GfxPath *path);
22514 jghali 325
        int getBlendMode(GfxState *state);
326
        QString UnicodeParsedString(POPPLER_CONST GooString *s1);
23478 jghali 327
        QString UnicodeParsedString(const std::string& s1);
22514 jghali 328
        bool checkClip();
23525 jghali 329
 
23536 jghali 330
        // Intersect the current clip path with the new path in state where filled areas
331
        // are interpreted according to fillRule.
332
        void adjustClip(GfxState *state, Qt::FillRule fillRule);
333
 
334
        // Take the current path of state and interpret it according to fillRule,
335
        // intersect it with the clipping path and create a new pageitem for it.
336
        void createFillItem(GfxState *state, Qt::FillRule fillRule);
337
 
23525 jghali 338
        void createImageFrame(QImage& image, GfxState *state, int numColorComponents);
339
 
23377 craig 340
        bool pathIsClosed {false};
22514 jghali 341
        QVector<double> DashValues;
23377 craig 342
        double DashOffset {0.0};
22514 jghali 343
        QString Coords;
23536 jghali 344
        // The currently visible area. If it is empty, everything is visible.
345
        // QPainterPath has the drawback that it sometimes approximates Bezier curves
346
        // by line segments for numerical stability. If available, a better class
347
        // should be used. However, it is important that the used class knows which
348
        // areas are covered and does not rely on external information about the fill
349
        // rule to use.
350
        QPainterPath m_currentClipPath;
351
        QStack<QPainterPath> m_clipPaths;
23588 jghali 352
        // Collect the paths of character glyphs for clipping of a whole text group.
353
        QPainterPath  m_clipTextPath;
23536 jghali 354
 
22514 jghali 355
        QString m_currentMask;
23550 jghali 356
        QPointF m_currentMaskPosition;
22514 jghali 357
        Selection* tmpSel;
358
        QStringList *m_importedColors;
359
        QTransform m_ctm;
360
        struct F3Entry
361
        {
362
                bool colored;
363
        };
364
        QStack<F3Entry> m_F3Stack;
365
        struct mContent
366
        {
367
                QString name;
368
                QString ocgName;
369
        };
370
        QStack<mContent> m_mcStack;
23377 craig 371
        int inPattern {0};
372
        int layerNum {1};
22514 jghali 373
        int currentLayer;
23377 craig 374
        bool firstLayer {true};
22514 jghali 375
        int importerFlags;
23377 craig 376
        int updateGUICounter {0};
377
        XRef *xref {nullptr};           // xref table for current document
378
        PDFDoc *pdfDoc {nullptr};
379
        Catalog *catalog {nullptr};
380
        SplashFontEngine *m_fontEngine {nullptr};
381
        SplashFont *m_font {nullptr};
24599 jghali 382
#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(21, 4, 0)
383
        std::unique_ptr<FormPageWidgets> m_formWidgets;
384
#else
23377 craig 385
        FormPageWidgets *m_formWidgets {nullptr};
24599 jghali 386
#endif
22514 jghali 387
        QHash<QString, QList<int> > m_radioMap;
388
        QHash<int, PageItem*> m_radioButtons;
389
        int m_actPage;
390
};
391
#endif