Browse Source

GlyphArrangement: Avoid breaking on non-breaking spaces

v6.1.6
reuk 3 years ago
parent
commit
6a1a96247b
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
2 changed files with 10 additions and 11 deletions
  1. +10
    -4
      modules/juce_graphics/fonts/juce_GlyphArrangement.cpp
  2. +0
    -7
      modules/juce_graphics/fonts/juce_GlyphArrangement.h

+ 10
- 4
modules/juce_graphics/fonts/juce_GlyphArrangement.cpp View File

@@ -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,


+ 0
- 7
modules/juce_graphics/fonts/juce_GlyphArrangement.h View File

@@ -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. */


Loading…
Cancel
Save