Board  0.9.5
Transforms.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_TRANSFORMS_H
27 #define BOARD_TRANSFORMS_H
28 
29 #include <cmath>
30 #include <limits>
31 #include <map>
32 #include <vector>
33 #include "TransformMatrix.h"
34 #include "board/Point.h"
35 #include "board/Rect.h"
36 namespace LibBoard
37 {
38 
39 struct Shape;
40 struct ShapeList;
41 
46 struct Transform {
47  inline Transform();
48  virtual ~Transform();
49  virtual double mapX(double x) const;
50  virtual double mapY(double y) const = 0;
51  virtual Point map(const Point &) const;
52  virtual void apply(double & x, double & y) const;
53  virtual double scale(double x) const;
54  virtual Point scale(const Point &) const;
55  virtual double rounded(double x) const;
56  virtual void setBoundingBox(const Rect & rect, const double pageWidth, const double pageHeight, const double margin) = 0;
57  static inline double round(const double & x);
58 
59 protected:
60  double _scale;
61  double _deltaX;
62  double _deltaY;
63  double _height;
64 };
65 
71 struct TransformEPS : public Transform {
72  double mapWidth(double w) const;
73  double mapY(double y) const;
74  void setBoundingBox(const Rect & rect, const double pageWidth, const double pageHeight, const double margin);
75  double scaleBackMM(double);
76  Rect pageBoundingBox() const;
77 
78 private:
79  Rect _pageBoundingBox;
80 };
81 
87 struct TransformFIG : public Transform {
88  inline TransformFIG();
89  double rounded(double x) const;
90  double mapY(double y) const;
91  int mapWidth(double width) const;
92  void setBoundingBox(const Rect & rect, const double pageWidth, const double pageHeight, const double margin);
93  unsigned int shapeDepth(const Shape *) const;
94  unsigned int mapDepth(unsigned int depth) const;
95  void setDepthMap(const std::map<const Shape *, unsigned int> *, unsigned int min);
96 
97 private:
98  unsigned int _maxDepth;
99  unsigned int _minDepth;
100  double _postscriptScale;
101  const std::map<const Shape *, unsigned int> * _depthMap;
102 };
103 
109 struct TransformSVG : public Transform {
110  double rounded(double x) const;
111  double mapY(double y) const;
112  double mapWidth(double width) const;
113  void setBoundingBox(const Rect & rect, const double pageWidth, const double pageHeight, const double margin);
114  double scaleBackMM(double);
115  TransformMatrix matrix() const;
116  Point translation() const;
117  double deltaX() const;
118  double deltaY() const;
119 };
120 
126 struct TransformTikZ : public TransformSVG {
127  ~TransformTikZ() override;
128 };
129 
130 // Inline methods and functions
131 
132 #if defined(max)
133 #undef max
134 #define HAS_MSVC_MAX true
135 #endif
136 
137 Transform::Transform() : _scale(1.0), _deltaX(0.0), _deltaY(0.0), _height(0.0) {}
138 
139 TransformFIG::TransformFIG() : _maxDepth(std::numeric_limits<int>::max()), _minDepth(0), _postscriptScale(1.0)
140 {
141  _depthMap = nullptr;
142 }
143 
144 double Transform::round(const double & x)
145 {
146  return std::floor(x + 0.5);
147 }
148 
149 #if defined(HAS_MSVC_MAX)
150 #define max(A, B) ((A) > (B) ? (A) : (B))
151 #endif
152 
153 } // namespace LibBoard
154 
155 #endif /* BOARD_TRANSFORMS_H */
Point.h
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition: Rect.h:39
TransformMatrix.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::Transform
Definition: Transforms.h:46
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:42
LibBoard::TransformEPS
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:71
LibBoard::Shape
Abstract structure for a 2D shape.
Definition: Shape.h:63
LibBoard::TransformTikZ
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:126
LibBoard::TransformFIG
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:87
LibBoard::TransformMatrix
Definition: TransformMatrix.h:36
Rect.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::TransformSVG
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:109