NAP
linefromfile.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 #include <polyline.h>
8 #include <rect.h>
9 
10 namespace nap
11 {
16  enum class ESVGUnits : int
17  {
18  PX = 0,
19  PT,
20  PC,
21  MM,
22  CM,
23  DPI
24  };
25 
35  class NAPAPI LineFromFile : public PolyLine
36  {
37  RTTI_ENABLE(PolyLine)
38  public:
39  LineFromFile(nap::Core& core);
40 
44  virtual bool init(utility::ErrorState& errorState) override;
45 
49  virtual bool isClosed() const override;
50 
56  virtual bool isClosed(int shapeIndex) const;
57 
58  // Property: the svg file to read
59  std::string mFile;
60 
61  // Property: the cubic re-sample line tolerance
62  float mTolerance = 1.0f;
63 
64  // Property: units used when reading the svg file
66 
67  // Property: dpi used when reading the svg file
68  float mDPI = 96.0f;
69 
70  // Property: if the lines should be normalized relative to 0, ie: max bounds are -0.5 and 0.5
71  bool mNormalize = true;
72 
73  // Property: scale used as a multiplier for the loaded lines
74  float mScale = 1.0f;
75 
76  // Property: if the lines should be flipped on the x axis
77  bool mFlipX = false;
78 
79  // Property: if the lines should be flipped on the y axis
80  bool mFlipY = false;
81 
82  // The currently active line
83  int mLineIndex = 0;
84 
85  private:
86  using SVGPaths = std::vector<std::unique_ptr<std::vector<glm::vec3>>>;
87  using SVGState = std::vector<bool>;
88 
89  // Utility for extracting lines from all the paths
90  bool extractLinesFromPaths(const SVGPaths& paths, const SVGState& states, const math::Rect& rectangle, utility::ErrorState& errorState);
91 
92  // Create a mesh instance out of curve sampled vertices
93  void addShape(bool closed, std::vector<glm::vec3>& pathVertices, std::vector<glm::vec3>& pathNormals, std::vector<glm::vec3>& pathUvs);
94 
95  // All the lines closed states
96  std::vector<bool> mClosedStates;
97  };
98 }
nap::ESVGUnits::PT
@ PT
'pt' Points
nap::ESVGUnits::CM
@ CM
'cm' Centimeter
nap::LineFromFile::mFile
std::string mFile
Definition: linefromfile.h:59
nap::ESVGUnits
ESVGUnits
Definition: linefromfile.h:16
nap::ESVGUnits::PX
@ PX
'px' Pixels
nap::math::Rect
Definition: rect.h:19
nap::LineFromFile
Definition: linefromfile.h:35
nap::ESVGUnits::PC
@ PC
'pc' Points Centimeter
nap::utility::ErrorState
Definition: errorstate.h:19
nap::PolyLine
Definition: polyline.h:37
nap::Core
Definition: core.h:82
nap::ESVGUnits::DPI
@ DPI
'dpi' Dots per inch
nap
Definition: templateapp.h:17
nap::ESVGUnits::MM
@ MM
'mm' Millimeter