diff --git a/lib/GfxRenderer/GfxRenderer.cpp b/lib/GfxRenderer/GfxRenderer.cpp index 32afb7a8..5ac49fd5 100644 --- a/lib/GfxRenderer/GfxRenderer.cpp +++ b/lib/GfxRenderer/GfxRenderer.cpp @@ -74,13 +74,14 @@ void GfxRenderer::drawPixel(const int x, const int y, const bool state) const { } int GfxRenderer::getTextWidth(const int fontId, const char* text, const EpdFontFamily::Style style) const { - if (fontMap.count(fontId) == 0) { + const auto fontIt = fontMap.find(fontId); + if (fontIt == fontMap.end()) { LOG_ERR("GFX", "Font %d not found", fontId); return 0; } int w = 0, h = 0; - fontMap.at(fontId).getTextDimensions(text, &w, &h, style); + fontIt->second.getTextDimensions(text, &w, &h, style); return w; } @@ -100,11 +101,12 @@ void GfxRenderer::drawText(const int fontId, const int x, const int y, const cha return; } - if (fontMap.count(fontId) == 0) { + const auto fontIt = fontMap.find(fontId); + if (fontIt == fontMap.end()) { LOG_ERR("GFX", "Font %d not found", fontId); return; } - const auto font = fontMap.at(fontId); + const auto& font = fontIt->second; // no printable characters if (!font.hasPrintableChars(text, style)) { @@ -709,52 +711,58 @@ int GfxRenderer::getScreenHeight() const { } int GfxRenderer::getSpaceWidth(const int fontId) const { - if (fontMap.count(fontId) == 0) { + const auto fontIt = fontMap.find(fontId); + if (fontIt == fontMap.end()) { LOG_ERR("GFX", "Font %d not found", fontId); return 0; } - return fontMap.at(fontId).getGlyph(' ', EpdFontFamily::REGULAR)->advanceX; + return fontIt->second.getGlyph(' ', EpdFontFamily::REGULAR)->advanceX; } int GfxRenderer::getTextAdvanceX(const int fontId, const char* text) const { - if (fontMap.count(fontId) == 0) { + const auto fontIt = fontMap.find(fontId); + if (fontIt == fontMap.end()) { LOG_ERR("GFX", "Font %d not found", fontId); return 0; } uint32_t cp; int width = 0; + const auto& font = fontIt->second; while ((cp = utf8NextCodepoint(reinterpret_cast(&text)))) { - width += fontMap.at(fontId).getGlyph(cp, EpdFontFamily::REGULAR)->advanceX; + width += font.getGlyph(cp, EpdFontFamily::REGULAR)->advanceX; } return width; } int GfxRenderer::getFontAscenderSize(const int fontId) const { - if (fontMap.count(fontId) == 0) { + const auto fontIt = fontMap.find(fontId); + if (fontIt == fontMap.end()) { LOG_ERR("GFX", "Font %d not found", fontId); return 0; } - return fontMap.at(fontId).getData(EpdFontFamily::REGULAR)->ascender; + return fontIt->second.getData(EpdFontFamily::REGULAR)->ascender; } int GfxRenderer::getLineHeight(const int fontId) const { - if (fontMap.count(fontId) == 0) { + const auto fontIt = fontMap.find(fontId); + if (fontIt == fontMap.end()) { LOG_ERR("GFX", "Font %d not found", fontId); return 0; } - return fontMap.at(fontId).getData(EpdFontFamily::REGULAR)->advanceY; + return fontIt->second.getData(EpdFontFamily::REGULAR)->advanceY; } int GfxRenderer::getTextHeight(const int fontId) const { - if (fontMap.count(fontId) == 0) { + const auto fontIt = fontMap.find(fontId); + if (fontIt == fontMap.end()) { LOG_ERR("GFX", "Font %d not found", fontId); return 0; } - return fontMap.at(fontId).getData(EpdFontFamily::REGULAR)->ascender; + return fontIt->second.getData(EpdFontFamily::REGULAR)->ascender; } void GfxRenderer::drawTextRotated90CW(const int fontId, const int x, const int y, const char* text, const bool black, @@ -764,11 +772,13 @@ void GfxRenderer::drawTextRotated90CW(const int fontId, const int x, const int y return; } - if (fontMap.count(fontId) == 0) { + const auto fontIt = fontMap.find(fontId); + if (fontIt == fontMap.end()) { LOG_ERR("GFX", "Font %d not found", fontId); return; } - const auto font = fontMap.at(fontId); + + const auto& font = fontIt->second; // No printable characters if (!font.hasPrintableChars(text, style)) {