Browse Source

Text: expose a Renderer::fontSize() getter.

pull/603/head
Vladimír Vondruš 4 years ago
parent
commit
852fd165c1
  1. 4
      doc/changelog.dox
  2. 4
      src/Magnum/Text/Renderer.cpp
  3. 8
      src/Magnum/Text/Renderer.h
  4. 1
      src/Magnum/Text/Test/RendererGLTest.cpp

4
doc/changelog.dox

@ -546,6 +546,10 @@ See also:
the color map offset was not a part of per-draw data, but rather material the color map offset was not a part of per-draw data, but rather material
data. data.
@subsubsection changelog-latest-changes-text Text library
- Added @ref Text::Renderer::fontSize()
@subsubsection changelog-latest-changes-trade Trade library @subsubsection changelog-latest-changes-trade Trade library
- A changed signature of the @ref Trade::AbstractImporter::doOpenData(Containers::Array<char>&&, DataFlags) - A changed signature of the @ref Trade::AbstractImporter::doOpenData(Containers::Array<char>&&, DataFlags)

4
src/Magnum/Text/Renderer.cpp

@ -297,7 +297,7 @@ void AbstractRenderer::bufferUnmapImplementationDefault(GL::Buffer& buffer)
#endif #endif
} }
AbstractRenderer::AbstractRenderer(AbstractFont& font, const GlyphCache& cache, const Float size, const Alignment alignment): _vertexBuffer{GL::Buffer::TargetHint::Array}, _indexBuffer{GL::Buffer::TargetHint::ElementArray}, font(font), cache(cache), size(size), _alignment(alignment), _capacity(0) { AbstractRenderer::AbstractRenderer(AbstractFont& font, const GlyphCache& cache, const Float size, const Alignment alignment): _vertexBuffer{GL::Buffer::TargetHint::Array}, _indexBuffer{GL::Buffer::TargetHint::ElementArray}, font(font), cache(cache), _fontSize{size}, _alignment(alignment), _capacity(0) {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
MAGNUM_ASSERT_GL_EXTENSION_SUPPORTED(GL::Extensions::ARB::map_buffer_range); MAGNUM_ASSERT_GL_EXTENSION_SUPPORTED(GL::Extensions::ARB::map_buffer_range);
#elif defined(MAGNUM_TARGET_GLES2) && !defined(CORRADE_TARGET_EMSCRIPTEN) #elif defined(MAGNUM_TARGET_GLES2) && !defined(CORRADE_TARGET_EMSCRIPTEN)
@ -362,7 +362,7 @@ void AbstractRenderer::render(const std::string& text) {
/* Render vertex data */ /* Render vertex data */
std::vector<Vertex> vertexData; std::vector<Vertex> vertexData;
_rectangle = {}; _rectangle = {};
std::tie(vertexData, _rectangle) = renderVerticesInternal(font, cache, size, text, _alignment); std::tie(vertexData, _rectangle) = renderVerticesInternal(font, cache, _fontSize, text, _alignment);
const UnsignedInt glyphCount = vertexData.size()/4; const UnsignedInt glyphCount = vertexData.size()/4;
const UnsignedInt vertexCount = glyphCount*4; const UnsignedInt vertexCount = glyphCount*4;

8
src/Magnum/Text/Renderer.h

@ -78,6 +78,12 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer {
*/ */
UnsignedInt capacity() const { return _capacity; } UnsignedInt capacity() const { return _capacity; }
/**
* @brief Font size
* @m_since_latest
*/
Float fontSize() const { return _fontSize; }
/** @brief Rectangle spanning the rendered text */ /** @brief Rectangle spanning the rendered text */
Range2D rectangle() const { return _rectangle; } Range2D rectangle() const { return _rectangle; }
@ -135,7 +141,7 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer {
private: private:
AbstractFont& font; AbstractFont& font;
const GlyphCache& cache; const GlyphCache& cache;
Float size; Float _fontSize;
Alignment _alignment; Alignment _alignment;
UnsignedInt _capacity; UnsignedInt _capacity;
Range2D _rectangle; Range2D _rectangle;

1
src/Magnum/Text/Test/RendererGLTest.cpp

@ -274,6 +274,7 @@ void RendererGLTest::mutableText() {
Text::Renderer2D renderer(font, nullGlyphCache, 0.25f); Text::Renderer2D renderer(font, nullGlyphCache, 0.25f);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(renderer.capacity(), 0); CORRADE_COMPARE(renderer.capacity(), 0);
CORRADE_COMPARE(renderer.fontSize(), 0.25f);
CORRADE_COMPARE(renderer.rectangle(), Range2D()); CORRADE_COMPARE(renderer.rectangle(), Range2D());
/* Reserve some capacity */ /* Reserve some capacity */

Loading…
Cancel
Save