9 #include "../contrib/pugixml-1.4/src/pugixml.hpp"
10 #include "stb_truetype.h"
12 typedef struct stbtt_fontinfo stbtt_fontinfo;
19 Real c; // skew x by y
20 Real e; // translate x
22 Real b; // skew y by x
24 Real f; // translate y
26 // SVG matrix transforms (x,y) <- (a x' + c y' + e, b x' + d y' + f)
27 // Equivelant to OpenGL 3d matrix transform ((a, c, e) (b, d, f) (0,0,1))
32 Document(const std::string & filename = "", const std::string & font_filename = "fonts/DejaVuSansMono.ttf") : m_objects(), m_count(0), m_font_data(NULL), m_font()
35 if (font_filename != "")
36 SetFont(font_filename);
45 void Load(const std::string & filename = "");
46 void Save(const std::string & filename);
47 void DebugDumpObjects();
49 unsigned ObjectCount() const {return m_count;}
50 inline const Objects & GetObjects() const {return m_objects;}
52 bool operator==(const Document & equ) const;
53 bool operator!=(const Document & equ) const {return !(this->operator==(equ));}
55 unsigned AddPath(unsigned start_index, unsigned end_index, const Colour & shading=Colour(0.6,0.6,0.6,1), const Colour & stroke=Colour(0,0,0,0));
56 unsigned AddBezier(const Bezier & bezier);
57 unsigned Add(ObjectType type, const Rect & bounds, unsigned data_index = 0, QuadTreeIndex qtnode = 0);
58 unsigned AddBezierData(const Bezier & bezier);
59 unsigned AddPathData(const Path & path);
62 /** SVG Related functions **/
64 /** Load an SVG text file and add to the document **/
65 void LoadSVG(const std::string & filename, const Rect & bounds = Rect(0,0,1,1));
66 void ParseSVG(const std::string & svg, const Rect & bounds = Rect(0,0,1,1));
68 /** Parse an SVG node or SVG-group node, adding children to the document **/
69 void ParseSVGNode(pugi::xml_node & root, SVGMatrix & transform);
70 /** Parse an SVG path with string **/
71 std::pair<unsigned, unsigned> ParseSVGPathData(const std::string & d, const SVGMatrix & transform, bool & closed);
73 /** Modify an SVG transformation matrix **/
74 static void ParseSVGTransform(const std::string & s, SVGMatrix & transform);
76 /** Extract CSS values (shudder) from style **/
77 static void ParseSVGStyleData(const std::string & style, std::map<std::string, std::string> & results);
79 /** Font related functions **/
80 void SetFont(const std::string & font_filename);
81 void AddText(const std::string & text, Real scale, Real x, Real y);
83 void AddFontGlyphAtPoint(stbtt_fontinfo *font, int character, Real scale, Real x, Real y);
85 void TransformObjectBounds(const SVGMatrix & transform);
86 void TranslateObjects(const Real & x, const Real & y, ObjectType type = NUMBER_OF_OBJECT_TYPES);
87 void ScaleObjectsAboutPoint(const Real & x, const Real & y, const Real & scale_amount, ObjectType type = NUMBER_OF_OBJECT_TYPES);
89 #ifndef QUADTREE_DISABLED
90 inline const QuadTree& GetQuadTree() { if (m_quadtree.root_id == QUADTREE_EMPTY) { GenBaseQuadtree(); } return m_quadtree; }
91 QuadTreeIndex GenQuadChild(QuadTreeIndex parent, QuadTreeNodeChildren type);
92 QuadTreeIndex GenQuadParent(QuadTreeIndex child, QuadTreeNodeChildren mytype);
93 // Returns the number of objects the current object formed when clipped, the objects in question are added to the end of the document.
94 int ClipObjectToQuadChild(int object_id, QuadTreeNodeChildren type);
100 #ifndef QUADTREE_DISABLED
102 void GenBaseQuadtree();
105 unsigned char * m_font_data;
106 stbtt_fontinfo m_font;