From 39c9bd2cbc75a0761711261dce1e7f7ddde2eb4d Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 10 Oct 2022 20:37:04 +0200 Subject: [PATCH] Added font size overflow restrictions to TextComponent and DateTimeComponent. Also fixed a crash that could occur in TextComponent when blank/dummy fonts were used. --- es-core/src/components/DateTimeComponent.cpp | 10 +++++++++- es-core/src/components/TextComponent.cpp | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/es-core/src/components/DateTimeComponent.cpp b/es-core/src/components/DateTimeComponent.cpp index 08a0ae052..faa2537ce 100644 --- a/es-core/src/components/DateTimeComponent.cpp +++ b/es-core/src/components/DateTimeComponent.cpp @@ -209,6 +209,14 @@ void DateTimeComponent::applyTheme(const std::shared_ptr& theme, } } + float maxHeight {0.0f}; + + if (!theme->isLegacyTheme() && properties & elem->has("size")) { + const glm::vec2 size {elem->get("size")}; + if (size.x != 0.0f && size.y != 0.0f) + maxHeight = mSize.y * 2.0f; + } + // Legacy themes only. if (properties & FORCE_UPPERCASE && elem->has("forceUppercase")) setUppercase(elem->get("forceUppercase")); @@ -216,5 +224,5 @@ void DateTimeComponent::applyTheme(const std::shared_ptr& theme, if (properties & LINE_SPACING && elem->has("lineSpacing")) setLineSpacing(glm::clamp(elem->get("lineSpacing"), 0.5f, 3.0f)); - setFont(Font::getFromTheme(elem, properties, mFont)); + setFont(Font::getFromTheme(elem, properties, mFont, maxHeight)); } diff --git a/es-core/src/components/TextComponent.cpp b/es-core/src/components/TextComponent.cpp index f84a77aef..2c13226cc 100644 --- a/es-core/src/components/TextComponent.cpp +++ b/es-core/src/components/TextComponent.cpp @@ -69,7 +69,7 @@ TextComponent::TextComponent(const std::string& text, void TextComponent::onSizeChanged() { - mAutoCalcExtent = glm::ivec2 {(getSize().x == 0), (getSize().y == 0)}; + mAutoCalcExtent = glm::ivec2 {getSize().x == 0, getSize().y == 0}; onTextChanged(); } @@ -254,8 +254,12 @@ void TextComponent::onTextChanged() text = mText; // Original case. } - if (mFont && mAutoCalcExtent.x) + if (mFont && mAutoCalcExtent.x) { mSize = mFont->sizeText(text, mLineSpacing); + // This can happen under special circumstances like when a blank/dummy font is used. + if (mSize.x == 0.0f) + return; + } if (!mFont || text.empty() || mSize.x < 0.0f) return; @@ -453,6 +457,14 @@ void TextComponent::applyTheme(const std::shared_ptr& theme, } } + float maxHeight {0.0f}; + + if (!theme->isLegacyTheme() && properties & elem->has("size")) { + const glm::vec2 size {elem->get("size")}; + if (size.x != 0.0f && size.y != 0.0f) + maxHeight = mSize.y * 2.0f; + } + // Legacy themes only. if (properties & FORCE_UPPERCASE && elem->has("forceUppercase")) setUppercase(elem->get("forceUppercase")); @@ -460,5 +472,5 @@ void TextComponent::applyTheme(const std::shared_ptr& theme, if (properties & LINE_SPACING && elem->has("lineSpacing")) setLineSpacing(glm::clamp(elem->get("lineSpacing"), 0.5f, 3.0f)); - setFont(Font::getFromTheme(elem, properties, mFont)); + setFont(Font::getFromTheme(elem, properties, mFont, maxHeight)); }