From 583dcca1e597efc47b3a6d0080b421d4b3d000d0 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 3 Sep 2012 12:27:49 +0100 Subject: [PATCH] Added a method for concatenating AttributedStrings. --- .../fonts/juce_AttributedString.cpp | 16 ++++++++++++++++ .../juce_graphics/fonts/juce_AttributedString.h | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/modules/juce_graphics/fonts/juce_AttributedString.cpp b/modules/juce_graphics/fonts/juce_AttributedString.cpp index 953f6d7314..4dfb91fde9 100644 --- a/modules/juce_graphics/fonts/juce_AttributedString.cpp +++ b/modules/juce_graphics/fonts/juce_AttributedString.cpp @@ -40,6 +40,13 @@ AttributedString::Attribute::Attribute (const Attribute& other) { } +AttributedString::Attribute::Attribute (const Attribute& other, const int offset) + : range (other.range + offset), + font (other.font.createCopy()), + colour (other.colour.createCopy()) +{ +} + AttributedString::Attribute::~Attribute() {} //============================================================================== @@ -149,6 +156,15 @@ void AttributedString::append (const String& textToAppend, const Font& font, con setColour (Range (oldLength, oldLength + newLength), colour); } +void AttributedString::append (const AttributedString& other) +{ + const int originalLength = text.length(); + text += other.text; + + for (int i = 0; i < other.attributes.size(); ++i) + attributes.add (new Attribute (*other.attributes.getUnchecked(i), originalLength)); +} + void AttributedString::clear() { text = String::empty; diff --git a/modules/juce_graphics/fonts/juce_AttributedString.h b/modules/juce_graphics/fonts/juce_AttributedString.h index f2c289b691..dde2cb8dce 100644 --- a/modules/juce_graphics/fonts/juce_AttributedString.h +++ b/modules/juce_graphics/fonts/juce_AttributedString.h @@ -75,6 +75,12 @@ public: /** Appends some text, with a specified font and colour. */ void append (const String& textToAppend, const Font& font, const Colour& colour); + /** Appends another AttributedString to this one. + Note that this will only append the text, fonts, and colours - it won't copy any + other properties such as justification, line-spacing, etc from the other object. + */ + void append (const AttributedString& other); + /** Resets the string, clearing all text and attributes. Note that this won't affect global settings like the justification type, word-wrap mode, etc. @@ -171,6 +177,8 @@ public: ScopedPointer font; ScopedPointer colour; + friend class AttributedString; + Attribute (const Attribute&, int); Attribute& operator= (const Attribute&); JUCE_LEAK_DETECTOR (Attribute);