31 int getLength (
const Array<AttributedString::Attribute>& atts)
noexcept
33 return atts.size() != 0 ? atts.getReference (atts.size() - 1).range.getEnd() : 0;
36 void splitAttributeRanges (Array<AttributedString::Attribute>& atts,
int position)
38 for (
int i = atts.
size(); --
i >= 0;)
41 auto offset =
position - att.range.getStart();
45 if (offset > 0 && position < att.range.getEnd())
47 atts.
insert (
i + 1, AttributedString::Attribute (att));
57 inline bool areInvariantsMaintained (
const String&
text,
const Array<AttributedString::Attribute>& atts)
62 if (atts.
getFirst().range.getStart() != 0)
68 for (
auto it = std::next (atts.
begin()); it != atts.
end(); ++it)
69 if (it->range.getStart() != std::prev (it)->range.getEnd())
75 Range<int> splitAttributeRanges (Array<AttributedString::Attribute>& atts, Range<int> newRange)
77 newRange = newRange.getIntersectionWith ({ 0, getLength (atts) });
79 if (! newRange.isEmpty())
81 splitAttributeRanges (atts, newRange.getStart());
82 splitAttributeRanges (atts, newRange.getEnd());
88 void mergeAdjacentRanges (Array<AttributedString::Attribute>& atts)
90 for (
int i = atts.
size() - 1; --
i >= 0;)
95 if (a1.colour == a2.colour && a1.font == a2.font)
97 a1.range.setEnd (a2.range.getEnd());
100 if (
i < atts.
size() - 1)
106 void appendRange (Array<AttributedString::Attribute>& atts,
107 int length,
const Font*
f,
const Colour*
c)
109 if (atts.
size() == 0)
111 atts.
add ({ Range<int> (0,
length),
f !=
nullptr ? *
f : Font(),
c !=
nullptr ? *
c : Colour (0xff000000) });
115 auto start = getLength (atts);
120 mergeAdjacentRanges (atts);
124 void applyFontAndColour (Array<AttributedString::Attribute>& atts,
125 Range<int> range,
const Font*
f,
const Colour*
c)
127 range = splitAttributeRanges (atts, range);
129 for (
auto& att : atts)
131 if (range.getStart() < att.range.getEnd())
133 if (range.getEnd() <= att.range.getStart())
136 if (
c !=
nullptr) att.colour = *
c;
137 if (
f !=
nullptr) att.font = *
f;
141 mergeAdjacentRanges (atts);
144 void truncate (Array<AttributedString::Attribute>& atts,
int newLength)
146 splitAttributeRanges (atts, newLength);
148 for (
int i = atts.
size(); --
i >= 0;)
163 auto newLength = newText.
length();
166 if (newLength > oldLength)
167 appendRange (
attributes, newLength - oldLength,
nullptr,
nullptr);
168 else if (newLength < oldLength)
177 text += textToAppend;
184 text += textToAppend;
191 text += textToAppend;
198 text += textToAppend;
211 attributes.getReference (
i).range += originalLength;
245 applyFontAndColour (
attributes, range,
nullptr, &colour);
251 applyFontAndColour (
attributes, range, &font,
nullptr);
273 if (!
g.getInternalContext().drawTextLayout (*
this, area))
277 layout.
draw (
g, area);
#define noexcept
Definition DistrhoDefines.h:72
ElementType & getReference(const int index) const noexcept
Definition Array.h:243
bool add(const ElementType &newElement) noexcept
Definition Array.h:354
ElementType * begin() const noexcept
Definition Array.h:292
int size() const noexcept
Definition Array.h:187
ElementType * end() const noexcept
Definition Array.h:300
ElementType getUnchecked(const int index) const
Definition Array.h:228
void remove(int indexToRemove)
Definition Array.h:724
bool insert(int indexToInsertAt, ParameterType newElement) noexcept
Definition Array.h:375
ElementType getLast() const
Definition Array.h:268
ElementType getFirst() const
Definition Array.h:253
bool isEmpty() const noexcept
Definition Array.h:193
Colour colour
Definition juce_AttributedString.h:172
Font font
Definition juce_AttributedString.h:169
Range< int > range
Definition juce_AttributedString.h:166
void setColour(Range< int > range, Colour colour)
Definition juce_AttributedString.cpp:243
ReadingDirection readingDirection
Definition juce_AttributedString.h:204
float lineSpacing
Definition juce_AttributedString.h:201
void setLineSpacing(float newLineSpacing) noexcept
Definition juce_AttributedString.cpp:238
void clear()
Definition juce_AttributedString.cpp:217
AttributedString()=default
Justification justification
Definition juce_AttributedString.h:202
void draw(Graphics &g, const Rectangle< float > &area) const
Definition juce_AttributedString.cpp:267
void setReadingDirection(ReadingDirection newReadingDirection) noexcept
Definition juce_AttributedString.cpp:233
void append(const String &textToAppend)
Definition juce_AttributedString.cpp:175
WordWrap wordWrap
Definition juce_AttributedString.h:203
String text
Definition juce_AttributedString.h:200
Array< Attribute > attributes
Definition juce_AttributedString.h:205
ReadingDirection
Definition juce_AttributedString.h:131
WordWrap
Definition juce_AttributedString.h:114
void setText(const String &newText)
Definition juce_AttributedString.cpp:161
void setJustification(Justification newJustification) noexcept
Definition juce_AttributedString.cpp:223
void setWordWrap(WordWrap newWordWrap) noexcept
Definition juce_AttributedString.cpp:228
void setFont(Range< int > range, const Font &font)
Definition juce_AttributedString.cpp:249
Definition juce_Colour.h:38
Definition juce_Font.h:42
Definition juce_GraphicsContext.h:45
Definition juce_Justification.h:41
Definition juce_Range.h:40
Definition juce_Rectangle.h:67
Rectangle< int > getSmallestIntegerContainer() const noexcept
Definition juce_Rectangle.h:840
ValueType getWidth() const noexcept
Definition juce_Rectangle.h:133
Definition juce_String.h:53
int length() const noexcept
Definition juce_String.cpp:511
Definition juce_TextLayout.h:41
void draw(Graphics &, Rectangle< float > area) const
Definition juce_TextLayout.cpp:197
void createLayout(const AttributedString &, float maxWidth)
Definition juce_TextLayout.cpp:243
int g
Definition inflate.c:1573
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
virtual ASIOError start()=0
Definition carla_juce.cpp:31
QPoint position(const QDropEvent *de)
position is a backwards-compatible adapter for QDropEvent::position and pos functions.
Definition DeprecationHelper.h:47
png_uint_32 length
Definition png.c:2247
const char * text
Definition swell-functions.h:167
return c
Definition crypt.c:175
int r
Definition crypt.c:458