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 49 /** 50 * @brief The StrokeFont class 51 */ 52 class StrokeFont final : public QObject { 53 Q_OBJECT 54 55 public: 56 // Constructors / Destructor 57 StrokeFont(const FilePath& fontFilePath, const QByteArray& content) 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 98 FilePath mFilePath; 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 113