sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
FontSpecsOf.hpp
1 // sciplot - a modern C++ scientific plotting library powered by gnuplot
2 // https://github.com/sciplot/sciplot
3 //
4 // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
5 //
6 // Copyright (c) 2018-2021 Allan Leal
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 // sciplot includes
29 #include <sciplot/Utils.hpp>
30 #include <sciplot/specs/Specs.hpp>
31 
32 namespace sciplot {
33 
35 template <typename DerivedSpecs>
36 class FontSpecsOf : virtual public Specs<DerivedSpecs>
37 {
38  public:
41 
43  auto fontName(std::string name) -> DerivedSpecs&;
44 
46  auto fontSize(std::size_t size) -> DerivedSpecs&;
47 
49  auto repr() const -> std::string;
50 
51  private:
53  std::string m_fontname;
54 
56  std::string m_fontsize;
57 };
58 
60 class FontSpecs : public FontSpecsOf<FontSpecs> {};
61 
62 template <typename DerivedSpecs>
64 {}
65 
66 template <typename DerivedSpecs>
67 auto FontSpecsOf<DerivedSpecs>::fontName(std::string name) -> DerivedSpecs&
68 {
69  m_fontname = name;
70  return static_cast<DerivedSpecs&>(*this);
71 }
72 
73 template <typename DerivedSpecs>
74 auto FontSpecsOf<DerivedSpecs>::fontSize(std::size_t size) -> DerivedSpecs&
75 {
76  m_fontsize = std::to_string(size);
77  return static_cast<DerivedSpecs&>(*this);
78 }
79 
80 template <typename DerivedSpecs>
81 auto FontSpecsOf<DerivedSpecs>::repr() const -> std::string
82 {
83  std::stringstream ss;
84  if(m_fontname.size() || m_fontsize.size())
85  ss << "font '" << m_fontname << "," << m_fontsize << "'";
86  return ss.str();
87 }
88 
89 } // namespace sciplot
auto repr() const -> std::string
Convert this FontSpecsOf object into a gnuplot formatted string.
Definition: FontSpecsOf.hpp:81
FontSpecsOf()
Construct a default FontSpecsOf instance.
Definition: FontSpecsOf.hpp:63
auto fontSize(std::size_t size) -> DerivedSpecs &
Set the point size of the font (e.g., 10, 12, 16).
Definition: FontSpecsOf.hpp:74
The base class for other specs classes (e.g., LineSpecsOf, DrawSpecs, BorderSpecs,...
Definition: Specs.hpp:36
auto fontName(std::string name) -> DerivedSpecs &
Set the name of the font (e.g., Helvetica, Georgia, Times).
Definition: FontSpecsOf.hpp:67
The class used to specify font options.
Definition: FontSpecsOf.hpp:60
The class used to attach font options to a type.
Definition: FontSpecsOf.hpp:37