Code

Do not set inkscape:groupmode for sub-page objects (eg. patterns)
[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 class SampledFunction;
36 struct GfxState;
37 class GfxPattern;
38 class GfxShadingPattern;
39 class GfxTilingPattern;
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);
98     // Image handling
99     void addImage(GfxState *state, Stream *str, int width, int height,
100                   GfxImageColorMap *color_map, int *mask_colors);
102     // Text handling
103     void beginString(GfxState *state, GooString *s);
104     void endString(GfxState *state);
105     void addChar(GfxState *state, double x, double y,
106                  double dx, double dy,
107                  double originX, double originY,
108                  CharCode code, int nBytes, Unicode *u, int uLen);
109     void beginTextObject(GfxState *state);
110     void endTextObject(GfxState *state);
112     bool isPatternTypeSupported(GfxPattern *pattern);
114     // State manipulation
115     void saveState();
116     void restoreState();
117     void updateStyle(GfxState *state);
118     void updateFont(GfxState *state);
119     void updateTextPosition(double tx, double ty);
120     void updateTextShift(GfxState *state, double shift);
121     void updateTextMatrix(GfxState *state);
123     // Clipping
124     void clip(GfxState *state, bool even_odd=false);
125     void setClipPath(GfxState *state, bool even_odd=false);
127     // Transforming
128     void setTransform(double c0, double c1, double c2, double c3, double c4,
129                       double c5);
130     void setTransform(double *transform);
131     bool getTransform(double *transform);
133 private:
134     SvgBuilder();
136     // Pattern creation
137     gchar *_createPattern(GfxPattern *pattern, GfxState *state, bool is_stroke=false);
138     gchar *_createGradient(GfxShadingPattern *shading_pattern);
139     bool _addStopsToGradient(Inkscape::XML::Node *gradient, Function *func, double opacity);
140     bool _addSamplesToGradient(Inkscape::XML::Node *gradient, SampledFunction *func,
141                               double offset0, double offset1, double opacity);
142     gchar *_createTilingPattern(GfxTilingPattern *tiling_pattern, GfxState *state,
143                                 bool is_stroke=false);
144     // Image/mask creation
145     Inkscape::XML::Node *_createImage(Stream *str, int width, int height,
146                                       GfxImageColorMap *color_map, int *mask_colors,
147                                       bool alpha_only=false, bool invert_alpha=false);
148     // Style setting
149     SPCSSAttr *_setStyle(GfxState *state, bool fill, bool stroke, bool even_odd=false);
150     void _setStrokeStyle(SPCSSAttr *css, GfxState *state);
151     void _setFillStyle(SPCSSAttr *css, GfxState *state, bool even_odd);
153     void _flushText();    // Write buffered text into doc
155     std::vector<int> _group_depth;    // Depth of nesting groups
157     SPCSSAttr *_font_style;          // Current font style
158     GfxFont *_current_font;
159     char *_font_specification;
160     double _font_scaling;
161     bool _need_font_update;
162     NR::Matrix _text_matrix;
163     NR::Point _text_position;
164     std::vector<SvgGlyph> _glyphs;   // Added characters
165     bool _in_text_object;   // Whether we are inside a text object
166     bool _invalidated_style;
167     GfxState *_current_state;
169     bool _is_top_level;  // Whether this SvgBuilder is the top-level one
170     SPDocument *_doc;
171     gchar *_docname;    // Basename of the URI from which this document is created
172     XRef *_xref;    // Cross-reference table from the PDF doc we're converting from
173     Inkscape::XML::Document *_xml_doc;
174     Inkscape::XML::Node *_root;  // Root node from the point of view of this SvgBuilder
175     Inkscape::XML::Node *_container; // Current container (group/pattern/mask)
176     double _width, _height;       // Document size in px
177 };
180 } } } /* namespace Inkscape, Extension, Internal */
182 #endif /* HAVE_POPPLER */
184 #endif /* __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__ */
186 /*
187   Local Variables:
188   mode:c++
189   c-file-style:"stroustrup"
190   c-file-offsets:((innamespace . 0)(inline-open . 0))
191   indent-tabs-mode:nil
192   fill-column:99
193   End:
194 */
195 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :