Code

Added support for the shading operator
[inkscape.git] / src / extension / internal / pdfinput / svg-builder.h
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 GfxPath;
37 class GfxPattern;
38 class GfxTilingPattern;
39 class GfxShading;
40 class GfxFont;
41 class GfxImageColorMap;
42 class Stream;
43 class XRef;
45 class SPCSSAttr;
47 #include <vector>
48 #include <glib/gtypes.h>
50 namespace Inkscape {
51 namespace Extension {
52 namespace Internal {
54 /**
55  * \struct SvgGlyph
56  * Holds information about glyphs added by PdfParser which haven't been added
57  * to the document yet.
58  */
59 struct SvgGlyph {
60     NR::Point position;    // Absolute glyph coords
61     NR::Point text_position; // Absolute glyph coords in text space
62     double dx, dy;  // Advance values
63     double rise;    // Text rise parameter
64     char code[8];   // UTF-8 coded character
65     int code_size;
66     bool is_space;
68     bool style_changed;  // Set to true if style has to be reset
69     SPCSSAttr *style;
70     int render_mode;    // Text render mode
71     char *font_specification;   // Pointer to current font specification
72 };
74 /**
75  * \class SvgBuilder
76  *
77  * Builds the inner SVG representation from the calls of PdfParser
78  *
79  */
80 class SvgBuilder {
81 public:
82     SvgBuilder(SPDocument *document, gchar *docname, XRef *xref);
83     SvgBuilder(SvgBuilder *parent, Inkscape::XML::Node *root);
84     ~SvgBuilder();
86     // Property setting
87     void setDocumentSize(double width, double height);  // Document size in px
88     void setAsLayer(char *layer_name=NULL);
90     // Handling the node stack
91     Inkscape::XML::Node *pushGroup();
92     Inkscape::XML::Node *popGroup();
93     Inkscape::XML::Node *getContainer();    // Returns current group node
95     // Path adding
96     void addPath(GfxState *state, bool fill, bool stroke, bool even_odd=false);
97     void addShadedFill(GfxShading *shading, double *matrix, GfxPath *path, bool even_odd=false);
99     // Image handling
100     void addImage(GfxState *state, Stream *str, int width, int height,
101                   GfxImageColorMap *color_map, int *mask_colors);
102     void addImageMask(GfxState *state, Stream *str, int width, int height,
103                       bool invert);
104     void addMaskedImage(GfxState *state, Stream *str, int width, int height,
105                         GfxImageColorMap *color_map,
106                         Stream *mask_str, int mask_width, int mask_height,
107                         bool invert_mask);
108     void addSoftMaskedImage(GfxState *state, Stream *str, int width, int height,
109                             GfxImageColorMap *color_map,
110                             Stream *mask_str, int mask_width, int mask_height,
111                             GfxImageColorMap *mask_color_map);
113     // Text handling
114     void beginString(GfxState *state, GooString *s);
115     void endString(GfxState *state);
116     void addChar(GfxState *state, double x, double y,
117                  double dx, double dy,
118                  double originX, double originY,
119                  CharCode code, int nBytes, Unicode *u, int uLen);
120     void beginTextObject(GfxState *state);
121     void endTextObject(GfxState *state);
123     bool isPatternTypeSupported(GfxPattern *pattern);
125     // State manipulation
126     void saveState();
127     void restoreState();
128     void updateStyle(GfxState *state);
129     void updateFont(GfxState *state);
130     void updateTextPosition(double tx, double ty);
131     void updateTextShift(GfxState *state, double shift);
132     void updateTextMatrix(GfxState *state);
134     // Clipping
135     void clip(GfxState *state, bool even_odd=false);
136     void setClipPath(GfxState *state, bool even_odd=false);
138     // Transforming
139     void setTransform(double c0, double c1, double c2, double c3, double c4,
140                       double c5);
141     void setTransform(double *transform);
142     bool getTransform(double *transform);
144 private:
145     SvgBuilder();
147     // Pattern creation
148     gchar *_createPattern(GfxPattern *pattern, GfxState *state, bool is_stroke=false);
149     gchar *_createGradient(GfxShading *shading, double *matrix);
150     bool _addStopsToGradient(Inkscape::XML::Node *gradient, Function *func, double opacity);
151     bool _addSamplesToGradient(Inkscape::XML::Node *gradient, Function *func,
152                                double offset0, double offset1, double opacity);
153     gchar *_createTilingPattern(GfxTilingPattern *tiling_pattern, GfxState *state,
154                                 bool is_stroke=false);
155     // Image/mask creation
156     Inkscape::XML::Node *_createImage(Stream *str, int width, int height,
157                                       GfxImageColorMap *color_map, int *mask_colors,
158                                       bool alpha_only=false, bool invert_alpha=false);
159     Inkscape::XML::Node *_createMask(double width, double height);
160     // Style setting
161     SPCSSAttr *_setStyle(GfxState *state, bool fill, bool stroke, bool even_odd=false);
162     void _setStrokeStyle(SPCSSAttr *css, GfxState *state);
163     void _setFillStyle(SPCSSAttr *css, GfxState *state, bool even_odd);
165     void _flushText();    // Write buffered text into doc
167     std::vector<int> _group_depth;    // Depth of nesting groups
169     SPCSSAttr *_font_style;          // Current font style
170     GfxFont *_current_font;
171     char *_font_specification;
172     double _font_scaling;
173     bool _need_font_update;
174     NR::Matrix _text_matrix;
175     NR::Point _text_position;
176     std::vector<SvgGlyph> _glyphs;   // Added characters
177     bool _in_text_object;   // Whether we are inside a text object
178     bool _invalidated_style;
179     GfxState *_current_state;
181     bool _is_top_level;  // Whether this SvgBuilder is the top-level one
182     SPDocument *_doc;
183     gchar *_docname;    // Basename of the URI from which this document is created
184     XRef *_xref;    // Cross-reference table from the PDF doc we're converting from
185     Inkscape::XML::Document *_xml_doc;
186     Inkscape::XML::Node *_root;  // Root node from the point of view of this SvgBuilder
187     Inkscape::XML::Node *_container; // Current container (group/pattern/mask)
188     double _width, _height;       // Document size in px
189 };
192 } } } /* namespace Inkscape, Extension, Internal */
194 #endif /* HAVE_POPPLER */
196 #endif /* __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__ */
198 /*
199   Local Variables:
200   mode:c++
201   c-file-style:"stroustrup"
202   c-file-offsets:((innamespace . 0)(inline-open . 0))
203   indent-tabs-mode:nil
204   fill-column:99
205   End:
206 */
207 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :