Browse Source

Text: use Math::join() on ranges instead of custom code.

It does the same in a shorter and less error-prone way.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
2867f99138
  1. 8
      src/Magnum/Text/AbstractFont.cpp
  2. 8
      src/Magnum/Text/Renderer.cpp

8
src/Magnum/Text/AbstractFont.cpp

@ -340,11 +340,9 @@ Containers::Pair<Range2D, Range2D> AbstractLayouter::renderGlyph(const UnsignedI
/* Move the quad to cursor */
const Range2D quadPosition = quadPositionTextureCoordinatesAdvance.first().translated(cursorPosition);
/* Extend rectangle with current quad bounds. If zero size, replace it. */
if(!rectangle.size().isZero()) {
rectangle.bottomLeft() = Math::min(rectangle.bottomLeft(), quadPosition.bottomLeft());
rectangle.topRight() = Math::max(rectangle.topRight(), quadPosition.topRight());
} else rectangle = quadPosition;
/* Extend the rectangle with current quad bounds. If the original is zero
size, it gets replaced. */
rectangle = Math::join(rectangle, quadPosition);
/* Advance cursor position to next character */
cursorPosition += quadPositionTextureCoordinatesAdvance.third();

8
src/Magnum/Text/Renderer.cpp

@ -150,11 +150,9 @@ std::tuple<std::vector<Vertex>, Range2D> renderVerticesInternal(AbstractFont& fo
for(auto it = vertices.begin()+lastLineLastVertex; it != vertices.end(); ++it)
it->position.x() += alignmentOffsetX;
/* Add final line bounds to total bounds, similarly to AbstractFont::renderGlyph() */
if(!rectangle.size().isZero()) {
rectangle.bottomLeft() = Math::min(rectangle.bottomLeft(), lineRectangle.bottomLeft());
rectangle.topRight() = Math::max(rectangle.topRight(), lineRectangle.topRight());
} else rectangle = lineRectangle;
/* Extend the rectangle with final line bounds, similarly to
AbstractFont::renderGlyph() */
rectangle = Math::join(rectangle, lineRectangle);
/* Move to next line */
} while(prevPos = pos+1,

Loading…
Cancel
Save