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 */ /* Move the quad to cursor */
const Range2D quadPosition = quadPositionTextureCoordinatesAdvance.first().translated(cursorPosition); const Range2D quadPosition = quadPositionTextureCoordinatesAdvance.first().translated(cursorPosition);
/* Extend rectangle with current quad bounds. If zero size, replace it. */ /* Extend the rectangle with current quad bounds. If the original is zero
if(!rectangle.size().isZero()) { size, it gets replaced. */
rectangle.bottomLeft() = Math::min(rectangle.bottomLeft(), quadPosition.bottomLeft()); rectangle = Math::join(rectangle, quadPosition);
rectangle.topRight() = Math::max(rectangle.topRight(), quadPosition.topRight());
} else rectangle = quadPosition;
/* Advance cursor position to next character */ /* Advance cursor position to next character */
cursorPosition += quadPositionTextureCoordinatesAdvance.third(); 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) for(auto it = vertices.begin()+lastLineLastVertex; it != vertices.end(); ++it)
it->position.x() += alignmentOffsetX; it->position.x() += alignmentOffsetX;
/* Add final line bounds to total bounds, similarly to AbstractFont::renderGlyph() */ /* Extend the rectangle with final line bounds, similarly to
if(!rectangle.size().isZero()) { AbstractFont::renderGlyph() */
rectangle.bottomLeft() = Math::min(rectangle.bottomLeft(), lineRectangle.bottomLeft()); rectangle = Math::join(rectangle, lineRectangle);
rectangle.topRight() = Math::max(rectangle.topRight(), lineRectangle.topRight());
} else rectangle = lineRectangle;
/* Move to next line */ /* Move to next line */
} while(prevPos = pos+1, } while(prevPos = pos+1,

Loading…
Cancel
Save