svg-builder.h revision e45563a3c46261d8c32014f8e516857ba01bd7b7
#ifndef __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__
#define __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__
/** \file
* SVG representation creator using libpoppler.
*
* Authors:
* miklos erdelyi
*
* Copyright (C) 2007 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_POPPLER
class SPDocument;
namespace Inkscape {
namespace XML {
class Document;
class Node;
}
}
#include "libnr/nr-point.h"
#include "libnr/nr-matrix.h"
#include "CharTypes.h"
class GooString;
class Function;
class SampledFunction;
struct GfxState;
class GfxPattern;
class GfxShadingPattern;
class GfxTilingPattern;
class GfxFont;
class GfxImageColorMap;
class Stream;
class XRef;
class SPCSSAttr;
#include <vector>
#include <glib/gtypes.h>
namespace Inkscape {
namespace Extension {
namespace Internal {
/**
* \struct SvgGlyph
* Holds information about glyphs added by PdfParser which haven't been added
* to the document yet.
*/
struct SvgGlyph {
NR::Point position; // Absolute glyph coords
NR::Point text_position; // Absolute glyph coords in text space
double dx, dy; // Advance values
double rise; // Text rise parameter
char code[8]; // UTF-8 coded character
int code_size;
bool is_space;
bool style_changed; // Set to true if style has to be reset
SPCSSAttr *style;
int render_mode; // Text render mode
char *font_specification; // Pointer to current font specification
};
/**
* \class SvgBuilder
*
* Builds the inner SVG representation from the calls of PdfParser
*
*/
class SvgBuilder {
public:
SvgBuilder(SPDocument *document, XRef *xref);
SvgBuilder(SvgBuilder *parent, Inkscape::XML::Node *root);
~SvgBuilder();
// Property setting
void setDocumentSize(double width, double height); // Document size in px
// Handling the node stack
Inkscape::XML::Node *pushGroup();
Inkscape::XML::Node *popGroup();
Inkscape::XML::Node *getContainer(); // Returns current group node
// Path adding
void addPath(GfxState *state, bool fill, bool stroke, bool even_odd=false);
// Image handling
void addImage(GfxState *state, Stream *str, int width, int height,
GfxImageColorMap *color_map, int *mask_colors);
// Text handling
void beginString(GfxState *state, GooString *s);
void endString(GfxState *state);
void addChar(GfxState *state, double x, double y,
double dx, double dy,
double originX, double originY,
CharCode code, int nBytes, Unicode *u, int uLen);
void beginTextObject(GfxState *state);
void endTextObject(GfxState *state);
bool isPatternTypeSupported(GfxPattern *pattern);
// State manipulation
void saveState();
void restoreState();
void updateStyle(GfxState *state);
void updateFont(GfxState *state);
void updateTextPosition(double tx, double ty);
void updateTextShift(GfxState *state, double shift);
void updateTextMatrix(GfxState *state);
// Clipping
void clip(GfxState *state, bool even_odd=false);
void setClipPath(GfxState *state, bool even_odd=false);
// Transforming
void setTransform(double c0, double c1, double c2, double c3, double c4,
double c5);
void setTransform(double *transform);
bool getTransform(double *transform);
private:
SvgBuilder();
// Pattern creation
gchar *_createPattern(GfxPattern *pattern, GfxState *state, bool is_stroke=false);
gchar *_createGradient(GfxShadingPattern *shading_pattern);
bool _addStopsToGradient(Inkscape::XML::Node *gradient, Function *func, double opacity);
bool _addSamplesToGradient(Inkscape::XML::Node *gradient, SampledFunction *func,
double offset0, double offset1, double opacity);
gchar *_createTilingPattern(GfxTilingPattern *tiling_pattern, GfxState *state,
bool is_stroke=false);
// Image/mask creation
Inkscape::XML::Node *_createImage(Stream *str, int width, int height,
GfxImageColorMap *color_map, int *mask_colors,
bool alpha_only=false, bool invert_alpha=false);
// Style setting
SPCSSAttr *_setStyle(GfxState *state, bool fill, bool stroke, bool even_odd=false);
void _setStrokeStyle(SPCSSAttr *css, GfxState *state);
void _setFillStyle(SPCSSAttr *css, GfxState *state, bool even_odd);
void _flushText(); // Write buffered text into doc
std::vector<int> _group_depth; // Depth of nesting groups
SPCSSAttr *_font_style; // Current font style
GfxFont *_current_font;
char *_font_specification;
double _font_scaling;
bool _need_font_update;
NR::Matrix _text_matrix;
NR::Point _text_position;
std::vector<SvgGlyph> _glyphs; // Added characters
bool _in_text_object; // Whether we are inside a text object
bool _invalidated_style;
GfxState *_current_state;
SPDocument *_doc;
XRef *_xref; // Cross-reference table from the PDF doc we're converting from
Inkscape::XML::Document *_xml_doc;
Inkscape::XML::Node *_root; // Root node from the point of view of this SvgBuilder
Inkscape::XML::Node *_container; // Current container (group/pattern/mask)
double _width, _height; // Document size in px
};
} } } /* namespace Inkscape, Extension, Internal */
#endif /* HAVE_POPPLER */
#endif /* __EXTENSION_INTERNAL_PDFINPUT_SVGBUILDER_H__ */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :