LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
strokefont.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_STROKEFONT_H
21 #define LIBREPCB_STROKEFONT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../alignment.h"
27 #include "../fileio/filepath.h"
28 #include "../geometry/path.h"
29 
30 #include <QtCore>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace fontobene {
36 struct Vertex;
37 struct Polyline;
38 struct Font;
39 class GlyphListCache;
40 class GlyphListAccessor;
41 } // namespace fontobene
42 
43 namespace librepcb {
44 
45 /*******************************************************************************
46  * Class StrokeFont
47  ******************************************************************************/
48 
52 class StrokeFont final : public QObject {
53  Q_OBJECT
54 
55 public:
56  // Constructors / Destructor
57  StrokeFont(const FilePath& fontFilePath) noexcept;
58  StrokeFont(const StrokeFont& other) = delete;
59  ~StrokeFont() noexcept;
60 
61  // Getters
62  Ratio getLetterSpacing() const noexcept;
63  Ratio getLineSpacing() const noexcept;
64 
65  // General Methods
66  QVector<Path> stroke(const QString& text, const PositiveLength& height,
67  const Length& letterSpacing, const Length& lineSpacing,
68  const Alignment& align, Point& bottomLeft,
69  Point& topRight) const noexcept;
70  QVector<QPair<QVector<Path>, Length>> strokeLines(
71  const QString& text, const PositiveLength& height,
72  const Length& letterSpacing, Length& width) const noexcept;
73  QVector<Path> strokeLine(const QString& text, const PositiveLength& height,
74  const Length& letterSpacing, Length& width) const
75  noexcept;
76  QVector<Path> strokeGlyph(const QChar& glyph, const PositiveLength& height,
77  Length& spacing) const noexcept;
78 
79  // Operator Overloadings
80  StrokeFont& operator=(const StrokeFont& rhs) = delete;
81 
82 private:
83  void fontLoaded() noexcept;
84  const fontobene::GlyphListAccessor& accessor() const noexcept;
85  static QVector<Path> polylines2paths(
86  const QVector<fontobene::Polyline>& polylines,
87  const PositiveLength& height) noexcept;
88  static Path polyline2path(const fontobene::Polyline& p,
89  const PositiveLength& height) noexcept;
90  static Vertex convertVertex(const fontobene::Vertex& v,
91  const PositiveLength& height) noexcept;
92  Length convertLength(const PositiveLength& height, qreal length) const
93  noexcept;
94  static void computeBoundingRect(const QVector<Path>& paths, Point& bottomLeft,
95  Point& topRight) noexcept;
96 
97 private: // Data
99  QFuture<fontobene::Font> mFuture;
100  QFutureWatcher<fontobene::Font> mWatcher;
101  mutable QScopedPointer<fontobene::Font> mFont;
102  mutable QScopedPointer<fontobene::GlyphListCache> mGlyphListCache;
103  mutable QScopedPointer<fontobene::GlyphListAccessor> mGlyphListAccessor;
104 };
105 
106 /*******************************************************************************
107  * End of File
108  ******************************************************************************/
109 
110 } // namespace librepcb
111 
112 #endif // LIBREPCB_STROKEFONT_H
The Vertex class.
Definition: vertex.h:43
Ratio getLineSpacing() const noexcept
Definition: strokefont.cpp:67
QScopedPointer< fontobene::Font > mFont
Definition: strokefont.h:101
QFuture< fontobene::Font > mFuture
Definition: strokefont.h:99
QScopedPointer< fontobene::GlyphListAccessor > mGlyphListAccessor
Definition: strokefont.h:103
The Alignment class.
Definition: alignment.h:193
static Path polyline2path(const fontobene::Polyline &p, const PositiveLength &height) noexcept
Definition: strokefont.cpp:239
QVector< QPair< QVector< Path >, Length > > strokeLines(const QString &text, const PositiveLength &height, const Length &letterSpacing, Length &width) const noexcept
Definition: strokefont.cpp:135
QFutureWatcher< fontobene::Font > mWatcher
Definition: strokefont.h:100
static Vertex convertVertex(const fontobene::Vertex &v, const PositiveLength &height) noexcept
Definition: strokefont.cpp:246
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
FilePath mFilePath
Definition: strokefont.h:98
Ratio getLetterSpacing() const noexcept
Definition: strokefont.cpp:62
~StrokeFont() noexcept
Definition: strokefont.cpp:55
QVector< Path > strokeLine(const QString &text, const PositiveLength &height, const Length &letterSpacing, Length &width) const noexcept
Definition: strokefont.cpp:148
static void computeBoundingRect(const QVector< Path > &paths, Point &bottomLeft, Point &topRight) noexcept
Definition: strokefont.cpp:258
Length convertLength(const PositiveLength &height, qreal length) const noexcept
Definition: strokefont.cpp:253
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
QVector< Path > stroke(const QString &text, const PositiveLength &height, const Length &letterSpacing, const Length &lineSpacing, const Alignment &align, Point &bottomLeft, Point &topRight) const noexcept
Definition: strokefont.cpp:76
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
StrokeFont & operator=(const StrokeFont &rhs)=delete
static QVector< Path > polylines2paths(const QVector< fontobene::Polyline > &polylines, const PositiveLength &height) noexcept
Definition: strokefont.cpp:228
StrokeFont(const FilePath &fontFilePath) noexcept
Definition: strokefont.cpp:44
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
The Ratio class is used to represent a ratio number (e.g. 13.37%)
Definition: ratio.h:47
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:85
QVector< Path > strokeGlyph(const QChar &glyph, const PositiveLength &height, Length &spacing) const noexcept
Definition: strokefont.cpp:178
QScopedPointer< fontobene::GlyphListCache > mGlyphListCache
Definition: strokefont.h:102
void fontLoaded() noexcept
Definition: strokefont.cpp:199
const fontobene::GlyphListAccessor & accessor() const noexcept
Definition: strokefont.cpp:203
The StrokeFont class.
Definition: strokefont.h:52