openEmbroider  0.1
an open source embroidery software
OE_svgParser.h
1 /*
2  * Copyright (c) 2015 Tricoire Sebastien 3dsman@free.fr
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty. In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  * claim that you wrote the original software. If you use this software
14  * in a product, an acknowledgment in the product documentation would be
15  * appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  *
20  */
21 
22 #ifndef OE_SVGPARSER_H
23 #define OE_SVGPARSER_H
24 
25 #include "xml/tinyxml.h"
26 
27 #include "OE_document.h"
28 
30 {
31  public:
33  OE_svgParser();
35  virtual ~OE_svgParser();
36 
38  OE_document * ParseFile(const std::string filename, const char* units, float dpi);
39 
40  protected:
41  private:
42 
43  char id[64]; // Optional 'id' attr of the curve or its group
44  float opacity; // Opacity of the curve.
45  float strokeWidth; // Stroke width (scaled).
46  char strokeLineJoin; // Stroke join type.
47  char strokeLineCap; // Stroke cap type.
48  float bounds[4]; // Tight bounding box of the curve [minx,miny,maxx,maxy].
49 
50  OE_document* document;
51 
52  static float sqr(float x);
53  static float vmag(float x, float y);
54  static float vecrat(float ux, float uy, float vx, float vy);
55  static float vecang(float ux, float uy, float vx, float vy);
56  static void xformPoint(float* dx, float* dy, float x, float y, float* t);
57  static void xformVec(float* dx, float* dy, float x, float y, float* t);
58 
59  int isspace(char c);
60  int isdigit(char c);
61  int isnum(char c);
62  const char* parseNumber(const char* s, char* it, const int size);
63  const char* getNextPathItem(const char* s, char* it);
64 
66  int getArgsPerElement(char cmd);
67  void pathMoveTo(OE_pointcurve* curve, float* cpx, float* cpy, float* args, int rel);
68  void pathLineTo(OE_pointcurve* curve, float* cpx, float* cpy, float* args, int rel);
69  void pathHLineTo(OE_pointcurve* curve, float* cpx, float* cpy, float* args, int rel);
70  void pathVLineTo(OE_pointcurve* curve, float* cpx, float* cpy, float* args, int rel);
71  void pathCubicBezTo(OE_pointcurve* curve, float* cpx, float* cpy, float* cpx2, float* cpy2, float* args, int rel);
72  void pathCubicBezShortTo(OE_pointcurve* curve, float* cpx, float* cpy, float* cpx2, float* cpy2, float* args, int rel);
73  void pathQuadBezTo(OE_pointcurve* curve, float* cpx, float* cpy, float* cpx2, float* cpy2, float* args, int rel);
74  void pathQuadBezShortTo(OE_pointcurve* curve, float* cpx, float* cpy, float* cpx2, float* cpy2, float* args, int rel);
75  void pathArcTo(OE_pointcurve* curve, float* cpx, float* cpy, float* args, int rel);
76 
78  bool parsePath(TiXmlElement *input);
79  bool parseSvg(TiXmlElement *input);
80 
81  bool pushCurve(OE_pointcurve * curve);
82 
83 };
84 
85 #endif // OE_SVGPARSER_H
Definition: OE_pointcurve.h:30
OE_svgParser()
Definition: OE_svgParser.cpp:31
Definition: OE_svgParser.h:29
OE_document * ParseFile(const std::string filename, const char *units, float dpi)
Definition: OE_svgParser.cpp:464
Definition: OE_document.h:32
virtual ~OE_svgParser()
Definition: OE_svgParser.cpp:40