Skip to content

Commit

Permalink
Text: expose a Renderer::fontSize() getter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Oct 21, 2022
1 parent 365409d commit 852fd16
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,10 @@ See also:
the color map offset was not a part of per-draw data, but rather material
data.

@subsubsection changelog-latest-changes-text Text library

- Added @ref Text::Renderer::fontSize()

@subsubsection changelog-latest-changes-trade Trade library

- A changed signature of the @ref Trade::AbstractImporter::doOpenData(Containers::Array<char>&&, DataFlags)
Expand Down
4 changes: 2 additions & 2 deletions src/Magnum/Text/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void AbstractRenderer::bufferUnmapImplementationDefault(GL::Buffer& buffer)
#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
MAGNUM_ASSERT_GL_EXTENSION_SUPPORTED(GL::Extensions::ARB::map_buffer_range);
#elif defined(MAGNUM_TARGET_GLES2) && !defined(CORRADE_TARGET_EMSCRIPTEN)
Expand Down Expand Up @@ -362,7 +362,7 @@ void AbstractRenderer::render(const std::string& text) {
/* Render vertex data */
std::vector<Vertex> vertexData;
_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 vertexCount = glyphCount*4;
Expand Down
8 changes: 7 additions & 1 deletion src/Magnum/Text/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer {
*/
UnsignedInt capacity() const { return _capacity; }

/**
* @brief Font size
* @m_since_latest
*/
Float fontSize() const { return _fontSize; }

/** @brief Rectangle spanning the rendered text */
Range2D rectangle() const { return _rectangle; }

Expand Down Expand Up @@ -135,7 +141,7 @@ class MAGNUM_TEXT_EXPORT AbstractRenderer {
private:
AbstractFont& font;
const GlyphCache& cache;
Float size;
Float _fontSize;
Alignment _alignment;
UnsignedInt _capacity;
Range2D _rectangle;
Expand Down
1 change: 1 addition & 0 deletions src/Magnum/Text/Test/RendererGLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ void RendererGLTest::mutableText() {
Text::Renderer2D renderer(font, nullGlyphCache, 0.25f);
MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(renderer.capacity(), 0);
CORRADE_COMPARE(renderer.fontSize(), 0.25f);
CORRADE_COMPARE(renderer.rectangle(), Range2D());

/* Reserve some capacity */
Expand Down

0 comments on commit 852fd16

Please sign in to comment.