C++, font renderer: add support for explicit newlines

backup
Christian Seiler 2 weeks ago
parent 4b4febb3ea
commit 02b4b8b4cc
  1. 21
      cpp/src/monoformat_fontreader.hpp

@ -527,9 +527,10 @@ public:
continue; continue;
} }
// FIXME: newline support
if (cp == '\n') { if (cp == '\n') {
cp = ' '; advance.x = 0;
advance.y += m_font.lineHeight();
continue;
} }
auto dims = renderGlyph(cp, position + advance, m_font, display, fontColor, bgColor); auto dims = renderGlyph(cp, position + advance, m_font, display, fontColor, bgColor);
@ -557,10 +558,11 @@ public:
continue; continue;
} }
// FIXME: newline support
// also FIXME: call ensureAdvance when handling newline
if (cp == '\n') { if (cp == '\n') {
cp = ' '; ensureAdvance(boundingBox, advance);
advance.x = 0;
advance.y += m_font.lineHeight();
continue;
} }
auto dims = computeGlyphDimensions(cp, position + advance, m_font); auto dims = computeGlyphDimensions(cp, position + advance, m_font);
@ -627,15 +629,14 @@ private:
return std::nullopt; return std::nullopt;
} }
// FIXME: once we support multi-line also handle y component
auto bottomRight = a->getBottomRight(); auto bottomRight = a->getBottomRight();
if ((bottomRight.x + 1) < advance.x) { if ((bottomRight.x + 1) < advance.x) {
bottomRight.x = advance.x - 1; bottomRight.x = advance.x - 1;
return Rectangle::fromCorners(a->topLeft, bottomRight);
} else {
return a;
} }
if ((bottomRight.y + 1) < advance.y) {
bottomRight.y = advance.y - 1;
}
return Rectangle::fromCorners(a->topLeft, bottomRight);
} }
template<typename Display> template<typename Display>

Loading…
Cancel
Save