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 transformed_position; // Glyph coords transformed by text matrix
62 double dx, dy; // Advance values
63 char code[8]; // UTF-8 coded character
64 int code_size;
65 bool is_space;
67 bool style_changed; // Set to true if style has to be reset
68 SPCSSAttr *style;
69 int render_mode; // Text render mode
70 };
72 /**
73 * \class SvgBuilder
74 *
75 * Builds the inner SVG representation from the calls of PdfParser
76 *
77 */
78 class SvgBuilder {
79 public:
80 SvgBuilder(SPDocument *document, XRef *xref);
81 SvgBuilder(SvgBuilder *parent, Inkscape::XML::Node *root);
82 ~SvgBuilder();
84 // Property setting
85 void setDocumentSize(double width, double height); // Document size in px
87 // Handling the node stack
88 Inkscape::XML::Node *pushGroup();
89 Inkscape::XML::Node *popGroup();
90 Inkscape::XML::Node *getContainer(); // Returns current group node
92 // Path adding
93 void addPath(GfxState *state, bool fill, bool stroke, bool even_odd=false);
95 // Image handling
96 void addImage(GfxState *state, Stream *str, int width, int height,
97 GfxImageColorMap *color_map, int *mask_colors);
99 // Text handling
100 void beginString(GfxState *state, GooString *s);
101 void endString(GfxState *state);
102 void addChar(GfxState *state, double x, double y,
103 double dx, double dy,
104 double originX, double originY,
105 CharCode code, int nBytes, Unicode *u, int uLen);
106 void beginTextObject(GfxState *state);
107 void endTextObject(GfxState *state);
109 bool isPatternTypeSupported(GfxPattern *pattern);
111 // State manipulation
112 void saveState();
113 void restoreState();
114 void updateStyle(GfxState *state);
115 void updateFont(GfxState *state);
117 // Clipping
118 void clip(GfxState *state, bool even_odd=false);
119 void setClipPath(GfxState *state, bool even_odd=false);
121 // Transforming
122 void setTransform(double c0, double c1, double c2, double c3, double c4,
123 double c5);
124 void setTransform(double *transform);
125 bool getTransform(double *transform);
127 private:
128 SvgBuilder();
130 // Pattern creation
131 gchar *_createPattern(GfxPattern *pattern, GfxState *state, bool is_stroke=false);
132 gchar *_createGradient(GfxShadingPattern *shading_pattern);
133 bool _addStopsToGradient(Inkscape::XML::Node *gradient, Function *func, double opacity);
134 bool _addSamplesToGradient(Inkscape::XML::Node *gradient, SampledFunction *func,
135 double offset0, double offset1, double opacity);
136 gchar *_createTilingPattern(GfxTilingPattern *tiling_pattern, GfxState *state,
137 bool is_stroke=false);
138 // Image/mask creation
139 Inkscape::XML::Node *_createImage(Stream *str, int width, int height,
140 GfxImageColorMap *color_map, int *mask_colors,
141 bool alpha_only=false, bool invert_alpha=false);
142 // Style setting
143 SPCSSAttr *_setStyle(GfxState *state, bool fill, bool stroke, bool even_odd=false);
144 void _setStrokeStyle(SPCSSAttr *css, GfxState *state);
145 void _setFillStyle(SPCSSAttr *css, GfxState *state, bool even_odd);
147 void _flushText(); // Write buffered text into doc
149 std::vector<int> _group_depth; // Depth of nesting groups
151 SPCSSAttr *_font_style; // Current font style
152 GfxFont *_current_font;
153 char *_font_specification;
154 bool _need_font_update;
155 NR::Matrix _text_matrix;
156 std::vector<SvgGlyph> _glyphs; // Added characters
157 bool _in_text_object; // Whether we are inside a text object
158 bool _invalidated_style;
159 GfxState *_current_state;
161 SPDocument *_doc;
162 XRef *_xref; // Cross-reference table from the PDF doc we're converting from
163 Inkscape::XML::Document *_xml_doc;
164 Inkscape::XML::Node *_root; // Root node from the point of view of this SvgBuilder
165 Inkscape::XML::Node *_container; // Current container (group/pattern/mask)
166 double _width, _height; // Document size in px
167 };
170 } } } /* namespace Inkscape, Extension, Internal */
172 #endif /* HAVE_POPPLER */
174 #endif /* __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__ */
176 /*
177 Local Variables:
178 mode:c++
179 c-file-style:"stroustrup"
180 c-file-offsets:((innamespace . 0)(inline-open . 0))
181 indent-tabs-mode:nil
182 fill-column:99
183 End:
184 */
185 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :