diff --git a/cpp/src/monoformat_fontreader.hpp b/cpp/src/monoformat_fontreader.hpp index dcdf69a..5418e0e 100644 --- a/cpp/src/monoformat_fontreader.hpp +++ b/cpp/src/monoformat_fontreader.hpp @@ -558,6 +558,7 @@ public: } // FIXME: newline support + // also FIXME: call ensureAdvance when handling newline if (cp == '\n') { cp = ' '; } @@ -570,6 +571,8 @@ public: boundingBox = combineBoundingBoxes(boundingBox, dims->boundingBox); } + boundingBox = ensureAdvance(boundingBox, advance); + return RenderedDimensions{advance, boundingBox}; } @@ -619,6 +622,22 @@ private: } } + static std::optional ensureAdvance(std::optional a, Point advance) { + if (!a) { + return std::nullopt; + } + + // FIXME: once we support multi-line also handle y component + + auto bottomRight = a->getBottomRight(); + if ((bottomRight.x + 1) < advance.x) { + bottomRight.x = advance.x - 1; + return Rectangle::fromCorners(a->topLeft, bottomRight); + } else { + return a; + } + } + template static std::expected renderGlyph(std::uint32_t cp, Point position, FontReader const& font, Display& display, typename Display::Color fontColor, std::optional bgColor) { auto glyph_ = font.tryRetrieveGlyphData(cp);