diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index 3755e7e595..2990e6f98c 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -36,43 +36,13 @@ TextLayout::Glyph::Glyph (int glyph, Point anch, float w) noexcept { } -TextLayout::Glyph::Glyph (const Glyph& other) noexcept - : glyphCode (other.glyphCode), anchor (other.anchor), width (other.width) -{ -} - -TextLayout::Glyph& TextLayout::Glyph::operator= (const Glyph& other) noexcept -{ - glyphCode = other.glyphCode; - anchor = other.anchor; - width = other.width; - return *this; -} - -TextLayout::Glyph::~Glyph() noexcept {} - //============================================================================== -TextLayout::Run::Run() noexcept - : colour (0xff000000) -{ -} - TextLayout::Run::Run (Range range, int numGlyphsToPreallocate) - : colour (0xff000000), stringRange (range) + : stringRange (range) { glyphs.ensureStorageAllocated (numGlyphsToPreallocate); } -TextLayout::Run::Run (const Run& other) - : font (other.font), - colour (other.colour), - glyphs (other.glyphs), - stringRange (other.stringRange) -{ -} - -TextLayout::Run::~Run() noexcept {} - Range TextLayout::Run::getRunBoundsX() const noexcept { Range range; @@ -97,11 +67,6 @@ Range TextLayout::Run::getRunBoundsX() const noexcept } //============================================================================== -TextLayout::Line::Line() noexcept - : ascent (0.0f), descent (0.0f), leading (0.0f) -{ -} - TextLayout::Line::Line (Range range, Point o, float asc, float desc, float lead, int numRunsToPreallocate) : stringRange (range), lineOrigin (o), @@ -117,8 +82,11 @@ TextLayout::Line::Line (const Line& other) runs.addCopiesOf (other.runs); } -TextLayout::Line::~Line() noexcept +TextLayout::Line& TextLayout::Line::operator= (const Line& other) { + auto copy = other; + swap (copy); + return *this; } Range TextLayout::Line::getLineBoundsX() const noexcept @@ -158,6 +126,16 @@ Rectangle TextLayout::Line::getLineBounds() const noexcept return { x.getStart(), y.getStart(), x.getLength(), y.getLength() }; } +void TextLayout::Line::swap (Line& other) noexcept +{ + std::swap (other.runs, runs); + std::swap (other.stringRange, stringRange); + std::swap (other.lineOrigin, lineOrigin); + std::swap (other.ascent, ascent); + std::swap (other.descent, descent); + std::swap (other.leading, leading); +} + //============================================================================== TextLayout::TextLayout() : width (0), height (0), justification (Justification::topLeft) diff --git a/modules/juce_graphics/fonts/juce_TextLayout.h b/modules/juce_graphics/fonts/juce_TextLayout.h index e466bf4d34..9e2e8578f5 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.h +++ b/modules/juce_graphics/fonts/juce_TextLayout.h @@ -145,9 +145,6 @@ public: { public: Glyph (int glyphCode, Point anchor, float width) noexcept; - Glyph (const Glyph&) noexcept; - Glyph& operator= (const Glyph&) noexcept; - ~Glyph() noexcept; /** The code number of this glyph. */ int glyphCode; @@ -168,21 +165,18 @@ public: class JUCE_API Run { public: - Run() noexcept; - Run (const Run&); + Run() = default; Run (Range stringRange, int numGlyphsToPreallocate); - ~Run() noexcept; /** Returns the X position range which contains all the glyphs in this run. */ Range getRunBoundsX() const noexcept; - Font font; /**< The run's font. */ - Colour colour; /**< The run's colour. */ - Array glyphs; /**< The glyphs in this run. */ - Range stringRange; /**< The character range that this run represents in the - original string that was used to create it. */ + Font font; /**< The run's font. */ + Colour colour { 0xff000000 }; /**< The run's colour. */ + Array glyphs; /**< The glyphs in this run. */ + Range stringRange; /**< The character range that this run represents in the + original string that was used to create it. */ private: - Run& operator= (const Run&); JUCE_LEAK_DETECTOR (Run) }; @@ -191,11 +185,17 @@ public: class JUCE_API Line { public: - Line() noexcept; - Line (const Line&); + Line() = default; Line (Range stringRange, Point lineOrigin, float ascent, float descent, float leading, int numRunsToPreallocate); - ~Line() noexcept; + + Line (const Line&); + Line& operator= (const Line&); + + Line (Line&&) noexcept = default; + Line& operator= (Line&&) noexcept = default; + + ~Line() noexcept = default; /** Returns the X position range which contains all the glyphs in this line. */ Range getLineBoundsX() const noexcept; @@ -206,14 +206,15 @@ public: /** Returns the smallest rectangle which contains all the glyphs in this line. */ Rectangle getLineBounds() const noexcept; + void swap (Line& other) noexcept; + OwnedArray runs; /**< The glyph-runs in this line. */ Range stringRange; /**< The character range that this line represents in the original string that was used to create it. */ Point lineOrigin; /**< The line's baseline origin. */ - float ascent, descent, leading; + float ascent = 0.0f, descent = 0.0f, leading = 0.0f; private: - Line& operator= (const Line&); JUCE_LEAK_DETECTOR (Line) };