esvg.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <etk/types.hpp>
9 #include <vector>
10 #include <etk/math/Vector2D.hpp>
11 #include <etk/os/FSNode.hpp>
12 
13 #include <esvg/Base.hpp>
14 
18 namespace esvg {
19  class Document : public esvg::Base {
20  private:
21  std::string m_fileName;
22  bool m_loadOK;
23  std::string m_version;
24  std::string m_title;
25  std::vector<ememory::SharedPtr<esvg::Base>> m_subElementList;
26  std::vector<ememory::SharedPtr<esvg::Base>> m_refList;
27  vec2 m_size;
28  public:
29  Document();
30  ~Document();
31  void clear();
38  bool parse(const std::string& _data);
45  bool generate(std::string& _data);
52  bool load(const std::string& _file);
59  bool store(const std::string& _file);
60  protected:
64  virtual bool cleanStyleProperty(const exml::Element& _root);
65  virtual bool parseXMLData(const exml::Element& _root, bool _isReference = false);
66  public:
67  bool isLoadOk() {
68  return m_loadOK;
69  };
73  void displayDebug();
74  // TODO: remove this fucntion : use generic function ...
75  void generateAnImage(const std::string& _fileName, bool _visualDebug=false);
76  void generateAnImage(const ivec2& _size, const std::string& _fileName, bool _visualDebug=false);
82  std::vector<etk::Color<float,4>> renderImageFloatRGBA(ivec2& _size);
84  std::vector<etk::Color<float,3>> renderImageFloatRGB(ivec2& _size);
86  std::vector<etk::Color<uint8_t,4>> renderImageU8RGBA(ivec2& _size);
88  std::vector<etk::Color<uint8_t,3>> renderImageU8RGB(ivec2& _size);
89  std::vector<std::vector<vec2>> getLines(vec2 _size=vec2(256,256));
90  protected:
91  void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level=0) override;
92  public:
93  vec2 getDefinedSize() {
94  return m_size;
95  };
96  ememory::SharedPtr<esvg::Base> getReference(const std::string& _name);
97  protected:
98  void drawShapePoints(std::vector<std::vector<vec2>>& _out,
99  int32_t _recurtionMax,
100  float _threshold,
101  mat2& _basicTrans,
102  int32_t _level=1) override;
103  };
104 }
105 
std::vector< etk::Color< uint8_t, 4 > > renderImageU8RGBA(ivec2 &_size)
Main esvg namespace.
Definition: Base.hpp:24
std::vector< etk::Color< uint8_t, 3 > > renderImageU8RGB(ivec2 &_size)
std::vector< etk::Color< float, 3 > > renderImageFloatRGB(ivec2 &_size)
std::vector< etk::Color< float, 4 > > renderImageFloatRGBA(ivec2 &_size)
Generate Image in a specific format.
Definition: Base.hpp:52
bool load(const std::string &_file)
Load the file that might contain the svg.
Definition: Renderer.hpp:16
bool parse(const std::string &_data)
parse a string that contain an svg stream
virtual bool cleanStyleProperty(const exml::Element &_root)
change all style in a xml atribute
void displayDebug()
Display all the node in the svg file.
void drawShapePoints(std::vector< std::vector< vec2 >> &_out, int32_t _recurtionMax, float _threshold, mat2 &_basicTrans, int32_t _level=1) override
Draw rhe shape with all points.
Definition: esvg.hpp:19
bool generate(std::string &_data)
generate a string that contain the created SVG
void draw(esvg::Renderer &_myRenderer, mat2 &_basicTrans, int32_t _level=0) override
Draw the form in the renderer.
bool store(const std::string &_file)
Store the SVG in the file.