Subversion Repositories Scribus

Rev

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