Board  0.9.5
Text.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_TEXT_H
27 #define BOARD_TEXT_H
28 
29 #include "board/ShapeWithStyle.h"
30 
31 // TODO : Add a sketchy line text font
32 
33 namespace LibBoard
34 {
35 
40 struct Text : public ShapeWithStyle {
41 
52  Text(double x, double y, const std::string & text, const Fonts::Font font, double size, Color color = Color::Black);
53 
63  Text(Point p, const std::string & text, const Fonts::Font font, double size, Color color = Color::Black);
64 
76  Text(double x, double y, const std::string & text, const Fonts::Font font, const std::string & svgFont, double size, Color color = Color::Black);
77 
88  Text(Point p, const std::string & text, const Fonts::Font font, const std::string & svgFont, double size, Color color = Color::Black);
89 
95  const std::string & name() const override;
96 
97  Point center(LineWidthFlag lineWidthFlag = IgnoreLineWidth) const override;
98 
99  Text & rotate(double angle, const Point & center) override;
100 
101  Text rotated(double angle, const Point & center) const;
102 
103  Text & rotate(double angle) override;
104 
105  Text rotated(double angle) const;
106 
115  Text & translate(double dx, double dy) override;
116 
125  Text translated(double dx, double dy) const;
126 
135  Text & scale(double sx, double sy) override;
136 
144  Text & scale(double s) override;
145 
154  Text scaled(double sx, double sy) const;
155 
163  Text scaled(double s) const;
164 
171  void scaleAll(double s) override;
172 
173  void flushPostscript(std::ostream & stream, const TransformEPS & transform) const override;
174 
175  void flushFIG(std::ostream & stream, const TransformFIG & transform, std::map<Color, int> & colormap) const override;
176 
177  void flushSVG(std::ostream & stream, const TransformSVG & transform) const override;
178 
179  void flushTikZ(std::ostream & stream, const TransformTikZ & transform) const override;
180 
186  virtual void accept(ShapeVisitor & visitor) override;
187 
193  virtual void accept(const ShapeVisitor & visitor) override;
194 
200  virtual void accept(ConstShapeVisitor & visitor) const override;
201 
207  virtual void accept(const ConstShapeVisitor & visitor) const override;
208 
213  virtual Shape * accept(CompositeShapeTransform & transform) const override;
214 
220  virtual Shape * accept(const CompositeShapeTransform & transform) const override;
221 
222  Rect boundingBox(LineWidthFlag) const override;
223 
224  Text * clone() const override;
225 
226  Text(const Text &) = default;
227  Text(Text &&) = default;
228  Text & operator=(Text &&) = default;
229  Text & operator=(const Text &) = default;
230  ~Text() override = default;
231 
232 private:
233  static const std::string _name;
235  double boxHeight(const Transform &) const;
236  double boxLength(const Transform &) const;
237 
238  double angle() const;
239 
240  Point position() const;
241 
242 protected:
243  std::string _text;
244  Fonts::Font _font;
245  std::string _svgFont;
246  double _size;
247  double _xScale;
248  double _yScale;
249  Path _box; // Rectangle around the text
250 };
251 
252 } // namespace LibBoard
253 
254 #endif /* BOARD_TEXT_H */
ShapeWithStyle.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::Text::accept
virtual void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition: Text.cpp:325
LibBoard::Text::boundingBox
Rect boundingBox(LineWidthFlag) const override
Definition: Text.cpp:355
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition: Rect.h:39
LibBoard::Text::translate
Text & translate(double dx, double dy) override
Definition: Text.cpp:147
LibBoard::Text::Text
Text(double x, double y, const std::string &text, const Fonts::Font font, double size, Color color=Color::Black)
Definition: Text.cpp:52
LibBoard::Text::flushSVG
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Text.cpp:256
LibBoard::CompositeShapeTransform
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition: ShapeVisitor.h:103
LibBoard::Text::translated
Text translated(double dx, double dy) const
Definition: Text.cpp:153
LibBoard::Text::flushFIG
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Text.cpp:237
LibBoard::Text::scaleAll
void scaleAll(double s) override
Definition: Text.cpp:185
LibBoard::Text
A piece of text.
Definition: Text.h:40
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::Text::flushTikZ
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Text.cpp:275
LibBoard::ConstShapeVisitor
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:78
LibBoard::Path
A path, according to Postscript and SVG definition.
Definition: Path.h:45
LibBoard::TransformTikZ
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:126
LibBoard::Text::center
Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const override
Definition: Text.cpp:105
LibBoard::TransformFIG
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:87
LibBoard::Text::scale
Text & scale(double sx, double sy) override
Definition: Text.cpp:158
LibBoard::Text::name
const std::string & name() const override
Definition: Text.cpp:100
LibBoard::Text::flushPostscript
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Text.cpp:224
LibBoard::Text::clone
Text * clone() const override
Definition: Text.cpp:190
LibBoard::ShapeVisitor
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:53
LibBoard::TransformSVG
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:109
LibBoard::Text::rotate
Text & rotate(double angle, const Point &center) override
Definition: Text.cpp:110
LibBoard::Text::scaled
Text scaled(double sx, double sy) const
Definition: Text.cpp:175
LibBoard::Color
Structure representing an RGB triple.
Definition: Color.h:43
LibBoard::ShapeWithStyle
Abstract structure for a 2D shape.
Definition: ShapeWithStyle.h:38