LibrePCB Developers Documentation
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_CORE_STROKEFONT_H
21#define LIBREPCB_CORE_STROKEFONT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../fileio/filepath.h"
27#include "../geometry/path.h"
28#include "../types/alignment.h"
29#include "../types/length.h"
30#include "../types/ratio.h"
31
32#include <QtCore>
33
34#include <memory>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace fontobene {
40class GlyphListAccessor;
41class GlyphListCache;
42struct Font;
43struct Polyline;
44struct Vertex;
45} // namespace fontobene
46
47namespace librepcb {
48
49/*******************************************************************************
50 * Class StrokeFont
51 ******************************************************************************/
52
56class StrokeFont final : public QObject {
57 Q_OBJECT
58
59public:
60 // Constructors / Destructor
61 StrokeFont(const FilePath& fontFilePath, const QByteArray& content) noexcept;
62 StrokeFont(const StrokeFont& other) = delete;
63 ~StrokeFont() noexcept;
64
65 // Getters
66 Ratio getLetterSpacing() const noexcept;
67 Ratio getLineSpacing() const noexcept;
68
69 // General Methods
70 QVector<Path> stroke(const QString& text, const PositiveLength& height,
71 const Length& letterSpacing, const Length& lineSpacing,
72 const Alignment& align, Point& bottomLeft,
73 Point& topRight) const noexcept;
74 QVector<QPair<QVector<Path>, Length>> strokeLines(
75 const QString& text, const PositiveLength& height,
76 const Length& letterSpacing, Length& width) const noexcept;
77 QVector<Path> strokeLine(const QString& text, const PositiveLength& height,
78 const Length& letterSpacing,
79 Length& width) const noexcept;
80 QVector<Path> strokeGlyph(const QChar& glyph, const PositiveLength& height,
81 Length& spacing) const noexcept;
82
83 // Operator Overloadings
84 StrokeFont& operator=(const StrokeFont& rhs) = delete;
85
86private:
87 void fontLoaded() noexcept;
88 const fontobene::GlyphListAccessor& accessor() const noexcept;
89 static QVector<Path> polylines2paths(
90 const QVector<fontobene::Polyline>& polylines,
91 const PositiveLength& height) noexcept;
92 static Path polyline2path(const fontobene::Polyline& p,
93 const PositiveLength& height) noexcept;
94 static Vertex convertVertex(const fontobene::Vertex& v,
95 const PositiveLength& height) noexcept;
97 qreal length) const noexcept;
98 static void computeBoundingRect(const QVector<Path>& paths, Point& bottomLeft,
99 Point& topRight) noexcept;
100
101private: // Data
103 QFuture<std::shared_ptr<fontobene::Font>> mFuture;
104 QFutureWatcher<std::shared_ptr<fontobene::Font>> mWatcher;
105 mutable std::shared_ptr<fontobene::Font> mFont;
106 mutable QScopedPointer<fontobene::GlyphListCache> mGlyphListCache;
107 mutable QScopedPointer<fontobene::GlyphListAccessor> mGlyphListAccessor;
108};
109
110/*******************************************************************************
111 * End of File
112 ******************************************************************************/
113
114} // namespace librepcb
115
116#endif
The Alignment class.
Definition: alignment.h:115
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:83
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition: path.h:58
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
The Ratio class is used to represent a ratio number (e.g. 13.37%)
Definition: ratio.h:45
The StrokeFont class.
Definition: strokefont.h:56
QVector< Path > strokeLine(const QString &text, const PositiveLength &height, const Length &letterSpacing, Length &width) const noexcept
Definition: strokefont.cpp:156
QScopedPointer< fontobene::GlyphListCache > mGlyphListCache
Definition: strokefont.h:106
Length convertLength(const PositiveLength &height, qreal length) const noexcept
Definition: strokefont.cpp:263
StrokeFont(const StrokeFont &other)=delete
QScopedPointer< fontobene::GlyphListAccessor > mGlyphListAccessor
Definition: strokefont.h:107
QFutureWatcher< std::shared_ptr< fontobene::Font > > mWatcher
Definition: strokefont.h:104
std::shared_ptr< fontobene::Font > mFont
Definition: strokefont.h:105
Ratio getLetterSpacing() const noexcept
Definition: strokefont.cpp:70
~StrokeFont() noexcept
Definition: strokefont.cpp:63
FilePath mFilePath
Definition: strokefont.h:102
QFuture< std::shared_ptr< fontobene::Font > > mFuture
Definition: strokefont.h:103
static Vertex convertVertex(const fontobene::Vertex &v, const PositiveLength &height) noexcept
Definition: strokefont.cpp:256
QVector< Path > strokeGlyph(const QChar &glyph, const PositiveLength &height, Length &spacing) const noexcept
Definition: strokefont.cpp:186
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:84
void fontLoaded() noexcept
Definition: strokefont.cpp:207
static Path polyline2path(const fontobene::Polyline &p, const PositiveLength &height) noexcept
Definition: strokefont.cpp:247
const fontobene::GlyphListAccessor & accessor() const noexcept
Definition: strokefont.cpp:211
QVector< QPair< QVector< Path >, Length > > strokeLines(const QString &text, const PositiveLength &height, const Length &letterSpacing, Length &width) const noexcept
Definition: strokefont.cpp:143
static void computeBoundingRect(const QVector< Path > &paths, Point &bottomLeft, Point &topRight) noexcept
Definition: strokefont.cpp:268
Ratio getLineSpacing() const noexcept
Definition: strokefont.cpp:75
static QVector< Path > polylines2paths(const QVector< fontobene::Polyline > &polylines, const PositiveLength &height) noexcept
Definition: strokefont.cpp:236
StrokeFont(const FilePath &fontFilePath, const QByteArray &content) noexcept
Definition: strokefont.cpp:48
The Vertex class.
Definition: vertex.h:44
Definition: strokefont.h:39
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812