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