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 /*******************************************************************************
21 * Includes
22 ******************************************************************************/
23 #include "strokefontpool.h"
24
25 #include "../fileio/filesystem.h"
26
27 #include <QtCore>
28
29 /*******************************************************************************
30 * Namespace
31 ******************************************************************************/
32 namespace librepcb {
33
34 /*******************************************************************************
35 * Constructors / Destructor
36 ******************************************************************************/
37
StrokeFontPool(const FileSystem & directory)38 StrokeFontPool::StrokeFontPool(const FileSystem& directory) noexcept {
39 foreach (const QString& filename, directory.getFiles()) {
40 FilePath fp = directory.getAbsPath(filename);
41 if (fp.getSuffix() != "bene") continue;
42 try {
43 qDebug() << "Load stroke font:" << filename;
44 mFonts.insert(
45 filename,
46 std::make_shared<StrokeFont>(fp,
47 directory.read(filename))); // can throw
48 } catch (const Exception& e) {
49 qCritical() << "Failed to load stroke font" << fp.toNative() << ":"
50 << e.getMsg();
51 }
52 }
53 }
54
~StrokeFontPool()55 StrokeFontPool::~StrokeFontPool() noexcept {
56 }
57
58 /*******************************************************************************
59 * Getters
60 ******************************************************************************/
61
getFont(const QString & filename) const62 const StrokeFont& StrokeFontPool::getFont(const QString& filename) const {
63 if (mFonts.contains(filename)) {
64 return *mFonts[filename];
65 } else {
66 throw RuntimeError(
67 __FILE__, __LINE__,
68 tr("The font \"%1\" does not exist in the font pool.").arg(filename));
69 }
70 }
71
72 /*******************************************************************************
73 * End of File
74 ******************************************************************************/
75
76 } // namespace librepcb
77