From 6a1a96247b92d338a8955bf1eea84788eb866a32 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 19 Jan 2022 15:22:41 +0000 Subject: [PATCH] GlyphArrangement: Avoid breaking on non-breaking spaces --- .../juce_graphics/fonts/juce_GlyphArrangement.cpp | 14 ++++++++++---- .../juce_graphics/fonts/juce_GlyphArrangement.h | 7 ------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp b/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp index 1d621f8517..eb5313eee3 100644 --- a/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp +++ b/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp @@ -26,6 +26,14 @@ namespace juce { +static constexpr bool isNonBreakingSpace (const juce_wchar c) +{ + return c == 0x00a0 + || c == 0x2007 + || c == 0x202f + || c == 0x2060; +} + PositionedGlyph::PositionedGlyph() noexcept : character (0), glyph (0), x (0), y (0), w (0), whitespace (false) { @@ -38,8 +46,6 @@ PositionedGlyph::PositionedGlyph (const Font& font_, juce_wchar character_, int { } -PositionedGlyph::~PositionedGlyph() {} - static void drawGlyphWithFont (Graphics& g, int glyph, const Font& font, AffineTransform t) { auto& context = g.getInternalContext(); @@ -168,7 +174,7 @@ void GlyphArrangement::addCurtailedLineOfText (const Font& font, const String& t } auto thisX = xOffsets.getUnchecked (i); - bool isWhitespace = t.isWhitespace(); + auto isWhitespace = isNonBreakingSpace (*t) || t.isWhitespace(); glyphs.add (PositionedGlyph (font, t.getAndAdvance(), newGlyphs.getUnchecked(i), @@ -545,7 +551,7 @@ void GlyphArrangement::spreadOutLine (int start, int num, float targetWidth) static bool isBreakableGlyph (const PositionedGlyph& g) noexcept { - return g.isWhitespace() || g.getCharacter() == '-'; + return ! isNonBreakingSpace (g.getCharacter()) && (g.isWhitespace() || g.getCharacter() == '-'); } void GlyphArrangement::splitLines (const String& text, Font font, int startIndex, diff --git a/modules/juce_graphics/fonts/juce_GlyphArrangement.h b/modules/juce_graphics/fonts/juce_GlyphArrangement.h index 18500f5366..068e46b24f 100644 --- a/modules/juce_graphics/fonts/juce_GlyphArrangement.h +++ b/modules/juce_graphics/fonts/juce_GlyphArrangement.h @@ -47,13 +47,6 @@ public: PositionedGlyph (const Font& font, juce_wchar character, int glyphNumber, float anchorX, float baselineY, float width, bool isWhitespace); - PositionedGlyph (const PositionedGlyph&) = default; - PositionedGlyph& operator= (const PositionedGlyph&) = default; - PositionedGlyph (PositionedGlyph&&) noexcept = default; - PositionedGlyph& operator= (PositionedGlyph&&) noexcept = default; - - ~PositionedGlyph(); - /** Returns the character the glyph represents. */ juce_wchar getCharacter() const noexcept { return character; } /** Checks whether the glyph is actually empty. */