9298884a1898fddfddfb91d317be1269f345dabe
1 #ifndef __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__
2 #define __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__
4 /** \file
5 * SVG representation creator using libpoppler.
6 *
7 * Authors:
8 * miklos erdelyi
9 *
10 * Copyright (C) 2007 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
19 #ifdef HAVE_POPPLER
21 class SPDocument;
22 namespace Inkscape {
23 namespace XML {
24 class Document;
25 class Node;
26 }
27 }
29 #include "libnr/nr-point.h"
30 #include "libnr/nr-matrix.h"
32 #include "CharTypes.h"
33 class GooString;
34 class Function;
35 struct GfxState;
36 class GfxColor;
37 class GfxColorSpace;
38 class GfxRGB;
39 class GfxPath;
40 class GfxPattern;
41 class GfxTilingPattern;
42 class GfxShading;
43 class GfxFont;
44 class GfxImageColorMap;
45 class Stream;
46 class XRef;
48 class SPCSSAttr;
50 #include <vector>
51 #include <glib/gtypes.h>
53 namespace Inkscape {
54 namespace Extension {
55 namespace Internal {
57 struct SvgTransparencyGroup;
59 /**
60 * \struct SvgGraphicsState
61 * Holds information about the current softmask and group depth.
62 * Could be later used to store other graphics state parameters so that we could
63 * emit only the differences in style settings from the parent state.
64 */
65 struct SvgGraphicsState {
66 Inkscape::XML::Node *softmask; // Points to current softmask node
67 int group_depth; // Depth of nesting groups at this level
68 };
70 /**
71 * \struct SvgGlyph
72 * Holds information about glyphs added by PdfParser which haven't been added
73 * to the document yet.
74 */
75 struct SvgGlyph {
76 NR::Point position; // Absolute glyph coords
77 NR::Point text_position; // Absolute glyph coords in text space
78 double dx, dy; // Advance values
79 double rise; // Text rise parameter
80 char code[8]; // UTF-8 coded character
81 int code_size;
82 bool is_space;
84 bool style_changed; // Set to true if style has to be reset
85 SPCSSAttr *style;
86 int render_mode; // Text render mode
87 char *font_specification; // Pointer to current font specification
88 };
90 /**
91 * \class SvgBuilder
92 *
93 * Builds the inner SVG representation from the calls of PdfParser
94 *
95 */
96 class SvgBuilder {
97 public:
98 SvgBuilder(SPDocument *document, gchar *docname, XRef *xref);
99 SvgBuilder(SvgBuilder *parent, Inkscape::XML::Node *root);
100 ~SvgBuilder();
102 // Property setting
103 void setDocumentSize(double width, double height); // Document size in px
104 void setAsLayer(char *layer_name=NULL);
105 void setGroupOpacity(double opacity);
107 // Handling the node stack
108 Inkscape::XML::Node *pushGroup();
109 Inkscape::XML::Node *popGroup();
110 Inkscape::XML::Node *getContainer(); // Returns current group node
112 // Path adding
113 void addPath(GfxState *state, bool fill, bool stroke, bool even_odd=false);
114 void addShadedFill(GfxShading *shading, double *matrix, GfxPath *path, bool even_odd=false);
116 // Image handling
117 void addImage(GfxState *state, Stream *str, int width, int height,
118 GfxImageColorMap *color_map, int *mask_colors);
119 void addImageMask(GfxState *state, Stream *str, int width, int height,
120 bool invert);
121 void addMaskedImage(GfxState *state, Stream *str, int width, int height,
122 GfxImageColorMap *color_map,
123 Stream *mask_str, int mask_width, int mask_height,
124 bool invert_mask);
125 void addSoftMaskedImage(GfxState *state, Stream *str, int width, int height,
126 GfxImageColorMap *color_map,
127 Stream *mask_str, int mask_width, int mask_height,
128 GfxImageColorMap *mask_color_map);
130 // Transparency group and soft mask handling
131 void pushTransparencyGroup(GfxState *state, double *bbox,
132 GfxColorSpace *blending_color_space,
133 bool isolated, bool knockout,
134 bool for_softmask);
135 void popTransparencyGroup(GfxState *state);
136 void paintTransparencyGroup(GfxState *state, double *bbox);
137 void setSoftMask(GfxState *state, double *bbox, bool alpha,
138 Function *transfer_func, GfxColor *backdrop_color);
139 void clearSoftMask(GfxState *state);
141 // Text handling
142 void beginString(GfxState *state, GooString *s);
143 void endString(GfxState *state);
144 void addChar(GfxState *state, double x, double y,
145 double dx, double dy,
146 double originX, double originY,
147 CharCode code, int nBytes, Unicode *u, int uLen);
148 void beginTextObject(GfxState *state);
149 void endTextObject(GfxState *state);
151 bool isPatternTypeSupported(GfxPattern *pattern);
153 // State manipulation
154 void saveState();
155 void restoreState();
156 void updateStyle(GfxState *state);
157 void updateFont(GfxState *state);
158 void updateTextPosition(double tx, double ty);
159 void updateTextShift(GfxState *state, double shift);
160 void updateTextMatrix(GfxState *state);
162 // Clipping
163 void clip(GfxState *state, bool even_odd=false);
164 void setClipPath(GfxState *state, bool even_odd=false);
166 // Transforming
167 void setTransform(double c0, double c1, double c2, double c3, double c4,
168 double c5);
169 void setTransform(double *transform);
170 bool getTransform(double *transform);
172 private:
173 void _init();
175 // Pattern creation
176 gchar *_createPattern(GfxPattern *pattern, GfxState *state, bool is_stroke=false);
177 gchar *_createGradient(GfxShading *shading, double *matrix, bool for_shading=false);
178 void _addStopToGradient(Inkscape::XML::Node *gradient, double offset,
179 GfxRGB *color, double opacity);
180 bool _addGradientStops(Inkscape::XML::Node *gradient, GfxShading *shading,
181 Function *func);
182 gchar *_createTilingPattern(GfxTilingPattern *tiling_pattern, GfxState *state,
183 bool is_stroke=false);
184 // Image/mask creation
185 Inkscape::XML::Node *_createImage(Stream *str, int width, int height,
186 GfxImageColorMap *color_map, int *mask_colors,
187 bool alpha_only=false, bool invert_alpha=false);
188 Inkscape::XML::Node *_createMask(double width, double height);
189 // Style setting
190 SPCSSAttr *_setStyle(GfxState *state, bool fill, bool stroke, bool even_odd=false);
191 void _setStrokeStyle(SPCSSAttr *css, GfxState *state);
192 void _setFillStyle(SPCSSAttr *css, GfxState *state, bool even_odd);
194 void _flushText(); // Write buffered text into doc
196 // Handling of node stack
197 Inkscape::XML::Node *pushNode(const char* name);
198 Inkscape::XML::Node *popNode();
199 std::vector<Inkscape::XML::Node *> _node_stack;
200 std::vector<int> _group_depth; // Depth of nesting groups
201 SvgTransparencyGroup *_transp_group_stack; // Transparency group stack
202 std::vector<SvgGraphicsState> _state_stack;
204 SPCSSAttr *_font_style; // Current font style
205 GfxFont *_current_font;
206 char *_font_specification;
207 double _font_scaling;
208 bool _need_font_update;
209 NR::Matrix _text_matrix;
210 NR::Point _text_position;
211 std::vector<SvgGlyph> _glyphs; // Added characters
212 bool _in_text_object; // Whether we are inside a text object
213 bool _invalidated_style;
214 GfxState *_current_state;
216 bool _is_top_level; // Whether this SvgBuilder is the top-level one
217 SPDocument *_doc;
218 gchar *_docname; // Basename of the URI from which this document is created
219 XRef *_xref; // Cross-reference table from the PDF doc we're converting from
220 Inkscape::XML::Document *_xml_doc;
221 Inkscape::XML::Node *_root; // Root node from the point of view of this SvgBuilder
222 Inkscape::XML::Node *_container; // Current container (group/pattern/mask)
223 double _width, _height; // Document size in px
224 };
227 } } } /* namespace Inkscape, Extension, Internal */
229 #endif /* HAVE_POPPLER */
231 #endif /* __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__ */
233 /*
234 Local Variables:
235 mode:c++
236 c-file-style:"stroustrup"
237 c-file-offsets:((innamespace . 0)(inline-open . 0))
238 indent-tabs-mode:nil
239 fill-column:99
240 End:
241 */
242 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :