A library for working with phylogenetic and population genetic data.
v0.32.0
text.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_FORMATS_SVG_TEXT_H_
2 #define GENESIS_UTILS_FORMATS_SVG_TEXT_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2017 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
36 
37 #include <iosfwd>
38 #include <string>
39 
40 namespace genesis {
41 namespace utils {
42 
43 // =================================================================================================
44 // Svg Text
45 // =================================================================================================
46 
47 struct SvgText
48 {
49 public:
50 
51  // -------------------------------------------------------------
52  // Typedefs and Enums
53  // -------------------------------------------------------------
54 
55  using self_type = SvgText;
56 
57  enum class Anchor
58  {
59  kNone,
60  kStart,
61  kMiddle,
62  kEnd
63  };
64 
65  enum class DominantBaseline
66  {
67  kNone,
68  kAuto,
69  kUseScript,
70  kNoChange,
71  kResetSize,
74  kHanging,
76  kCentral,
77  kMiddle,
80  kInherit
81  };
82 
83  enum class AlignmentBaseline
84  {
85  kNone,
86  kAuto,
87  kBaseline,
90  kMiddle,
91  kCentral,
92  kAfterEdge,
96  kHanging,
98  kInherit
99  };
100 
101  // -------------------------------------------------------------
102  // Constructors and Rule of Five
103  // -------------------------------------------------------------
104 
105  SvgText(
106  std::string const& text = "",
107  SvgPoint const& position = SvgPoint(),
108  SvgFont const& font = SvgFont(),
109  SvgFill const& fill = SvgFill(),
111  );
112 
113  ~SvgText() = default;
114 
115  SvgText( SvgText const& ) = default;
116  SvgText( SvgText&& ) = default;
117 
118  SvgText& operator= ( SvgText const& ) = default;
119  SvgText& operator= ( SvgText&& ) = default;
120 
121  // -------------------------------------------------------------
122  // Drawing Function
123  // -------------------------------------------------------------
124 
125  SvgBox bounding_box() const;
126 
127  void write(
128  std::ostream& out,
129  size_t indent = 0,
130  SvgDrawingOptions const& options = SvgDrawingOptions()
131  ) const;
132 
133  // -------------------------------------------------------------
134  // Helper Functions
135  // -------------------------------------------------------------
136 
137  static std::string anchor_to_string( Anchor value );
138  static std::string dominant_baseline_to_string( DominantBaseline value );
139  static std::string alignment_baseline_to_string( AlignmentBaseline value );
140 
141  // -------------------------------------------------------------
142  // Properties
143  // -------------------------------------------------------------
144 
145  std::string id;
146 
147  std::string text;
149 
153 
157 
158  double kerning;
160  double word_spacing;
161 
162  std::string dx;
163  std::string dy;
164 
166 
167 };
168 
169 } // namespace utils
170 } // namespace genesis
171 
172 #endif // include guard
genesis::utils::SvgText::DominantBaseline::kIdeographic
@ kIdeographic
genesis::utils::SvgText::write
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: text.cpp:102
genesis::utils::SvgText::DominantBaseline::kNoChange
@ kNoChange
genesis::utils::SvgText::anchor
Anchor anchor
Definition: text.hpp:154
helper.hpp
genesis::utils::SvgText::SvgText
SvgText(std::string const &text="", SvgPoint const &position=SvgPoint(), SvgFont const &font=SvgFont(), SvgFill const &fill=SvgFill(), SvgStroke const &stroke=SvgStroke(SvgStroke::Type::kOmit))
Definition: text.cpp:51
genesis::utils::indent
std::string indent(std::string const &text, std::string const &indentation)
Indent each line of text with indentation and return the result.
Definition: string.cpp:719
genesis::utils::SvgText::DominantBaseline::kTextBeforeEdge
@ kTextBeforeEdge
genesis::utils::SvgText::bounding_box
SvgBox bounding_box() const
Definition: text.cpp:72
genesis::utils::SvgText::font
SvgFont font
Definition: text.hpp:150
genesis::utils::SvgText::AlignmentBaseline::kBaseline
@ kBaseline
genesis::utils::SvgText::position
SvgPoint position
Definition: text.hpp:148
genesis::utils::SvgText::Anchor::kNone
@ kNone
genesis::utils::SvgText::AlignmentBaseline::kIdeographic
@ kIdeographic
genesis::utils::SvgStroke::Type::kOmit
@ kOmit
genesis::utils::SvgText::stroke
SvgStroke stroke
Definition: text.hpp:152
genesis::utils::SvgText::dx
std::string dx
Definition: text.hpp:162
genesis::utils::SvgText::word_spacing
double word_spacing
Definition: text.hpp:160
genesis::utils::SvgText::Anchor::kEnd
@ kEnd
genesis::utils::SvgText::AlignmentBaseline::kTextBeforeEdge
@ kTextBeforeEdge
genesis::utils::SvgText::DominantBaseline::kCentral
@ kCentral
genesis::utils::SvgBox
Definition: utils/formats/svg/helper.hpp:127
genesis::utils::SvgText::Anchor::kStart
@ kStart
genesis::utils::SvgText::operator=
SvgText & operator=(SvgText const &)=default
genesis::utils::SvgText::DominantBaseline::kHanging
@ kHanging
genesis::utils::SvgText::AlignmentBaseline::kMathematical
@ kMathematical
genesis::utils::SvgPoint
Definition: utils/formats/svg/helper.hpp:57
genesis::utils::SvgStroke
Definition: attributes.hpp:49
genesis::utils::SvgText::DominantBaseline
DominantBaseline
Definition: text.hpp:65
genesis::utils::SvgText::DominantBaseline::kMiddle
@ kMiddle
genesis::utils::SvgText::DominantBaseline::kNone
@ kNone
genesis::utils::SvgText::DominantBaseline::kAlphabetic
@ kAlphabetic
genesis::utils::SvgText::DominantBaseline::kMathematical
@ kMathematical
genesis::utils::SvgText::text
std::string text
Definition: text.hpp:147
genesis::utils::SvgText::AlignmentBaseline::kCentral
@ kCentral
genesis::utils::SvgText::DominantBaseline::kInherit
@ kInherit
genesis::utils::SvgText::fill
SvgFill fill
Definition: text.hpp:151
genesis::utils::SvgText::dominant_baseline_to_string
static std::string dominant_baseline_to_string(DominantBaseline value)
Definition: text.cpp:182
genesis::utils::SvgText::AlignmentBaseline::kInherit
@ kInherit
genesis::utils::SvgText::dy
std::string dy
Definition: text.hpp:163
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::SvgText::Anchor::kMiddle
@ kMiddle
genesis::utils::SvgText::letter_spacing
double letter_spacing
Definition: text.hpp:159
genesis::utils::SvgFill
Definition: attributes.hpp:131
genesis::utils::SvgText::anchor_to_string
static std::string anchor_to_string(Anchor value)
Definition: text.cpp:166
genesis::utils::SvgText::AlignmentBaseline::kAfterEdge
@ kAfterEdge
genesis::utils::SvgText::dominant_baseline
DominantBaseline dominant_baseline
Definition: text.hpp:155
genesis::utils::SvgFont
Definition: attributes.hpp:195
genesis::utils::SvgTransform
Definition: attributes.hpp:238
genesis::utils::SvgText::AlignmentBaseline::kNone
@ kNone
genesis::utils::SvgText::~SvgText
~SvgText()=default
genesis::utils::SvgText::Anchor
Anchor
Definition: text.hpp:57
genesis::utils::SvgText::alignment_baseline_to_string
static std::string alignment_baseline_to_string(AlignmentBaseline value)
Definition: text.cpp:220
genesis::utils::SvgText::AlignmentBaseline::kMiddle
@ kMiddle
genesis::utils::SvgText::AlignmentBaseline::kAuto
@ kAuto
genesis::utils::SvgText
Definition: text.hpp:47
genesis::utils::SvgText::AlignmentBaseline::kBeforeEdge
@ kBeforeEdge
genesis::utils::SvgText::DominantBaseline::kTextAfterEdge
@ kTextAfterEdge
genesis::utils::SvgText::AlignmentBaseline::kAlphabetic
@ kAlphabetic
genesis::utils::SvgText::transform
SvgTransform transform
Definition: text.hpp:165
attributes.hpp
genesis::utils::SvgText::kerning
double kerning
Definition: text.hpp:158
genesis::utils::SvgText::AlignmentBaseline
AlignmentBaseline
Definition: text.hpp:83
genesis::utils::SvgDrawingOptions
Definition: utils/formats/svg/helper.hpp:213
genesis::utils::SvgText::AlignmentBaseline::kHanging
@ kHanging
genesis::utils::SvgText::DominantBaseline::kUseScript
@ kUseScript
genesis::utils::SvgText::DominantBaseline::kResetSize
@ kResetSize
genesis::utils::SvgText::id
std::string id
Definition: text.hpp:145
genesis::utils::SvgText::DominantBaseline::kAuto
@ kAuto
genesis::utils::SvgText::AlignmentBaseline::kTextAfterEdge
@ kTextAfterEdge
genesis::utils::SvgText::alignment_baseline
AlignmentBaseline alignment_baseline
Definition: text.hpp:156