Skip to content

Commit 692e773

Browse files
committed
Initialize font internally when required.
1 parent 97feff3 commit 692e773

File tree

5 files changed

+26
-37
lines changed

5 files changed

+26
-37
lines changed

src/bin/daemon/LCDPlugins/endscreen.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ void Endscreen::init(FontsManager* const pFonts, const std::string & product)
5555
fs::path PBMDirectory(PBM_DATA_DIR);
5656
PBMDirectory /= _plugin.getName();
5757

58-
pFonts->initializeFont(FontID::DEJAVUSANSBOLD1616);
59-
6058
this->addPBMClearedFrame(); /* frame #0 */
6159
this->writeStringOnLastFrame(pFonts, FontID::DEJAVUSANSBOLD1616, product, 32, 10);
6260

src/bin/daemon/LCDPlugins/fontsManager.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* This file is part of GLogiK project.
44
* GLogiK, daemon to handle special features on gaming keyboards
5-
* Copyright (C) 2016-2018 Fabrice Delliaux <[email protected]>
5+
* Copyright (C) 2016-2021 Fabrice Delliaux <[email protected]>
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -44,32 +44,30 @@ FontsManager::~FontsManager()
4444

4545
void FontsManager::initializeFont(const FontID fontID)
4646
{
47+
#if DEBUGGING_ON
48+
LOG(DEBUG2) << "initializing font " << toUInt(toEnumType(fontID));
49+
#endif
50+
PBMFont* font = nullptr;
4751
try {
48-
_fonts.at(fontID);
49-
}
50-
catch (const std::out_of_range& oor) {
51-
PBMFont* font = nullptr;
52-
try {
53-
switch(fontID) {
54-
case FontID::MONOSPACE85:
55-
font = new FontMonospace85();
56-
break;
57-
case FontID::MONOSPACE86:
58-
font = new FontMonospace86();
59-
break;
60-
case FontID::DEJAVUSANSBOLD1616:
61-
font = new FontDejaVuSansBold1616();
62-
break;
63-
default:
64-
throw GLogiKExcept("unknown font ID");
65-
}
52+
switch(fontID) {
53+
case FontID::MONOSPACE85:
54+
font = new FontMonospace85();
55+
break;
56+
case FontID::MONOSPACE86:
57+
font = new FontMonospace86();
58+
break;
59+
case FontID::DEJAVUSANSBOLD1616:
60+
font = new FontDejaVuSansBold1616();
61+
break;
62+
default:
63+
throw GLogiKExcept("unknown font ID");
6664
}
67-
catch (const std::bad_alloc& e) { /* handle new() failure */
68-
throw GLogiKBadAlloc("font bad allocation");
69-
}
70-
71-
_fonts[fontID] = font;
7265
}
66+
catch (const std::bad_alloc& e) { /* handle new() failure */
67+
throw GLogiKBadAlloc("font bad allocation");
68+
}
69+
70+
_fonts[fontID] = font;
7371
}
7472

7573
void FontsManager::printCharacterOnFrame(
@@ -83,10 +81,8 @@ void FontsManager::printCharacterOnFrame(
8381
_fonts.at(fontID)->printCharacterOnFrame(frame, c, PBMXPos, PBMYPos);
8482
}
8583
catch (const std::out_of_range& oor) {
86-
std::string warn("unknown font : ");
87-
warn += std::to_string(toEnumType(fontID));
88-
GKSysLog(LOG_WARNING, WARNING, warn);
89-
throw GLogiKExcept("unknown font ID");
84+
this->initializeFont(fontID);
85+
_fonts.at(fontID)->printCharacterOnFrame(frame, c, PBMXPos, PBMYPos);
9086
}
9187
}
9288

src/bin/daemon/LCDPlugins/fontsManager.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* This file is part of GLogiK project.
44
* GLogiK, daemon to handle special features on gaming keyboards
5-
* Copyright (C) 2016-2018 Fabrice Delliaux <[email protected]>
5+
* Copyright (C) 2016-2021 Fabrice Delliaux <[email protected]>
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -39,8 +39,6 @@ class FontsManager
3939
FontsManager(void);
4040
~FontsManager(void);
4141

42-
void initializeFont(const FontID fontID);
43-
4442
void printCharacterOnFrame(
4543
const FontID fontID,
4644
PBMDataArray & frame,
@@ -54,6 +52,7 @@ class FontsManager
5452
private:
5553
std::map<const FontID, PBMFont*> _fonts;
5654

55+
void initializeFont(const FontID fontID);
5756
};
5857

5958
} // namespace GLogiK

src/bin/daemon/LCDPlugins/splashscreen.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ void Splashscreen::init(FontsManager* const pFonts, const std::string & product)
5555
fs::path PBMDirectory(PBM_DATA_DIR);
5656
PBMDirectory /= _plugin.getName();
5757

58-
pFonts->initializeFont(FontID::MONOSPACE85);
59-
6058
this->addPBMClearedFrame(); /* frame #0 */
6159
this->addPBMFrame(PBMDirectory, "splashscreen01.pbm", 1); /* #1 */
6260
this->addPBMFrame(PBMDirectory, "splashscreen01.pbm", 3); /* #2 #3 #4 */

src/bin/daemon/LCDPlugins/systemMonitor.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ void SystemMonitor::init(FontsManager* const pFonts, const std::string & product
6565
fs::path PBMDirectory(PBM_DATA_DIR);
6666
PBMDirectory /= _plugin.getName();
6767

68-
pFonts->initializeFont(FontID::MONOSPACE85);
69-
7068
this->addPBMFrame(PBMDirectory, "skeleton.pbm");
7169

7270
std::string host;

0 commit comments

Comments
 (0)