///////////////////////////////////////////////////////
| 756 | |
| 757 | //////////////////////////////////////////////////////////// |
| 758 | void Text::ensureGeometryUpdate() const |
| 759 | { |
| 760 | // Do nothing, if geometry has not changed and the font texture has not changed |
| 761 | if (!m_geometryNeedUpdate && m_font->getTexture(m_characterSize).m_cacheId == m_fontTextureId) |
| 762 | return; |
| 763 | |
| 764 | // Save the current fonts texture id |
| 765 | m_fontTextureId = m_font->getTexture(m_characterSize).m_cacheId; |
| 766 | |
| 767 | // Mark geometry as updated |
| 768 | m_geometryNeedUpdate = false; |
| 769 | |
| 770 | // Clear the previous geometry |
| 771 | m_vertices.clear(); |
| 772 | m_outlineVertices.clear(); |
| 773 | m_glyphs.clear(); |
| 774 | m_bounds = FloatRect(); |
| 775 | |
| 776 | // No text: nothing to draw |
| 777 | if (m_string.isEmpty()) |
| 778 | return; |
| 779 | |
| 780 | // Compute values related to the text style |
| 781 | const bool isBold = m_style & Bold; |
| 782 | const bool isUnderlined = m_style & Underlined; |
| 783 | const bool isStrikeThrough = m_style & StrikeThrough; |
| 784 | const float underlineOffset = m_font->getUnderlinePosition(m_characterSize); |
| 785 | const float underlineThickness = m_font->getUnderlineThickness(m_characterSize); |
| 786 | |
| 787 | // Compute the location of the strikethrough dynamically |
| 788 | // We use the center point of the lowercase 'x' glyph as the reference |
| 789 | // We reuse the underline thickness as the thickness of the strikethrough as well |
| 790 | const float strikeThroughOffset = m_font->getGlyph(U'x', m_characterSize, isBold).bounds.getCenter().y; |
| 791 | |
| 792 | // Precompute the variables needed by the algorithm |
| 793 | const float whitespaceWidth = m_font->getGlyph(U' ', m_characterSize, isBold).advance; |
| 794 | const float letterSpacing = (whitespaceWidth / 3.0f) * (m_letterSpacingFactor - 1.0f); |
| 795 | const float lineSpacing = m_font->getLineSpacing(m_characterSize) * m_lineSpacingFactor; |
| 796 | float x = 0.0f; |
| 797 | auto y = (m_textOrientation == TextOrientation::Default) ? static_cast<float>(m_characterSize) : 0.0f; |
| 798 | |
| 799 | // Variables used to compute bounds |
| 800 | auto minX = static_cast<float>(m_characterSize); |
| 801 | auto minY = static_cast<float>(m_characterSize); |
| 802 | auto maxX = 0.0f; |
| 803 | auto maxY = 0.0f; |
| 804 | |
| 805 | // Check that we have a usable font |
| 806 | const auto fontId = m_font->getInfo().id; |
| 807 | auto* const fontHandle = m_font->getFontHandle(); |
| 808 | |
| 809 | assert(fontId && fontHandle && "Font not usable for shaping text"); |
| 810 | |
| 811 | // Ensure the font is set to the size expected by the shaper |
| 812 | if (!m_font->setCurrentSize(m_characterSize)) |
| 813 | { |
| 814 | assert(false && "Failed to set font size"); |
| 815 | return; |
nothing calls this directly
no test coverage detected