Code

Reworked text output to create <text> nodes on text matrix changes rather than on...
[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 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);
116     void updateTextMatrix(GfxState *state);
118     // Clipping
119     void clip(GfxState *state, bool even_odd=false);
120     void setClipPath(GfxState *state, bool even_odd=false);
122     // Transforming
123     void setTransform(double c0, double c1, double c2, double c3, double c4,
124                       double c5);
125     void setTransform(double *transform);
126     bool getTransform(double *transform);
128 private:
129     SvgBuilder();
131     // Pattern creation
132     gchar *_createPattern(GfxPattern *pattern, GfxState *state, bool is_stroke=false);
133     gchar *_createGradient(GfxShadingPattern *shading_pattern);
134     bool _addStopsToGradient(Inkscape::XML::Node *gradient, Function *func, double opacity);
135     bool _addSamplesToGradient(Inkscape::XML::Node *gradient, SampledFunction *func,
136                               double offset0, double offset1, double opacity);
137     gchar *_createTilingPattern(GfxTilingPattern *tiling_pattern, GfxState *state,
138                                 bool is_stroke=false);
139     // Image/mask creation
140     Inkscape::XML::Node *_createImage(Stream *str, int width, int height,
141                                       GfxImageColorMap *color_map, int *mask_colors,
142                                       bool alpha_only=false, bool invert_alpha=false);
143     // Style setting
144     SPCSSAttr *_setStyle(GfxState *state, bool fill, bool stroke, bool even_odd=false);
145     void _setStrokeStyle(SPCSSAttr *css, GfxState *state);
146     void _setFillStyle(SPCSSAttr *css, GfxState *state, bool even_odd);
148     void _flushText();    // Write buffered text into doc
150     std::vector<int> _group_depth;    // Depth of nesting groups
152     SPCSSAttr *_font_style;          // Current font style
153     GfxFont *_current_font;
154     char *_font_specification;
155     bool _need_font_update;
156     NR::Matrix _text_matrix;
157     std::vector<SvgGlyph> _glyphs;   // Added characters
158     bool _in_text_object;   // Whether we are inside a text object
159     bool _invalidated_style;
160     GfxState *_current_state;
162     SPDocument *_doc;
163     XRef *_xref;    // Cross-reference table from the PDF doc we're converting from
164     Inkscape::XML::Document *_xml_doc;
165     Inkscape::XML::Node *_root;  // Root node from the point of view of this SvgBuilder
166     Inkscape::XML::Node *_container; // Current container (group/pattern/mask)
167     double _width, _height;       // Document size in px
168 };
171 } } } /* namespace Inkscape, Extension, Internal */
173 #endif /* HAVE_POPPLER */
175 #endif /* __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__ */
177 /*
178   Local Variables:
179   mode:c++
180   c-file-style:"stroustrup"
181   c-file-offsets:((innamespace . 0)(inline-open . 0))
182   indent-tabs-mode:nil
183   fill-column:99
184   End:
185 */
186 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :