JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_TextLayout.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
40class JUCE_API TextLayout final
41{
42private:
43 template <typename Iterator>
44 class DereferencingIterator
45 {
46 public:
48 using difference_type = typename std::iterator_traits<Iterator>::difference_type;
49 using pointer = value_type*;
50 using reference = value_type&;
51 using iterator_category = typename std::iterator_traits<Iterator>::iterator_category;
52
53 explicit DereferencingIterator (Iterator in) : iterator (std::move (in)) {}
54
55 DereferencingIterator& operator+= (difference_type distance)
56 {
57 iterator += distance;
58 return *this;
59 }
60
61 friend DereferencingIterator operator+ (DereferencingIterator i, difference_type d) { return i += d; }
62 friend DereferencingIterator operator+ (difference_type d, DereferencingIterator i) { return i += d; }
63
64 DereferencingIterator& operator-= (difference_type distance)
65 {
66 iterator -= distance;
67 return *this;
68 }
69
70 friend DereferencingIterator operator- (DereferencingIterator i, difference_type d) { return i -= d; }
71
72 friend difference_type operator- (DereferencingIterator a, DereferencingIterator b) { return a.iterator - b.iterator; }
73
74 reference operator[] (difference_type d) const { return *iterator[d]; }
75
76 friend bool operator< (DereferencingIterator a, DereferencingIterator b) { return a.iterator < b.iterator; }
77 friend bool operator<= (DereferencingIterator a, DereferencingIterator b) { return a.iterator <= b.iterator; }
78 friend bool operator> (DereferencingIterator a, DereferencingIterator b) { return a.iterator > b.iterator; }
79 friend bool operator>= (DereferencingIterator a, DereferencingIterator b) { return a.iterator >= b.iterator; }
80 friend bool operator== (DereferencingIterator a, DereferencingIterator b) { return a.iterator == b.iterator; }
81 friend bool operator!= (DereferencingIterator a, DereferencingIterator b) { return a.iterator != b.iterator; }
82
83 DereferencingIterator& operator++() { ++iterator; return *this; }
84 DereferencingIterator& operator--() { --iterator; return *this; }
85 DereferencingIterator operator++ (int) const { DereferencingIterator copy (*this); ++(*this); return copy; }
86 DereferencingIterator operator-- (int) const { DereferencingIterator copy (*this); --(*this); return copy; }
87
88 reference operator* () const { return **iterator; }
89 pointer operator->() const { return *iterator; }
90
91 private:
92 Iterator iterator;
93 };
94
95public:
100 TextLayout();
101 TextLayout (const TextLayout&);
102 TextLayout& operator= (const TextLayout&);
103 TextLayout (TextLayout&&) noexcept;
104 TextLayout& operator= (TextLayout&&) noexcept;
105
107 ~TextLayout();
108
109 //==============================================================================
113 void createLayout (const AttributedString&, float maxWidth);
114
118 void createLayout (const AttributedString&, float maxWidth, float maxHeight);
119
126 void createLayoutWithBalancedLineLengths (const AttributedString&, float maxWidth);
127
134 void createLayoutWithBalancedLineLengths (const AttributedString&, float maxWidth, float maxHeight);
135
140 void draw (Graphics&, Rectangle<float> area) const;
141
142 //==============================================================================
144 class JUCE_API Glyph
145 {
146 public:
147 Glyph (int glyphCode, Point<float> anchor, float width) noexcept;
148
151
156
157 float width;
158
159 private:
161 };
162
163 //==============================================================================
165 class JUCE_API Run
166 {
167 public:
168 Run() = default;
169 Run (Range<int> stringRange, int numGlyphsToPreallocate);
170
172 Range<float> getRunBoundsX() const noexcept;
173
175 Colour colour { 0xff000000 };
179 private:
181 };
182
183 //==============================================================================
185 class JUCE_API Line
186 {
187 public:
188 Line() = default;
189 Line (Range<int> stringRange, Point<float> lineOrigin,
190 float ascent, float descent, float leading, int numRunsToPreallocate);
191
192 Line (const Line&);
193 Line& operator= (const Line&);
194
195 Line (Line&&) noexcept = default;
196 Line& operator= (Line&&) noexcept = default;
197
198 ~Line() noexcept = default;
199
201 Range<float> getLineBoundsX() const noexcept;
202
204 Range<float> getLineBoundsY() const noexcept;
205
207 Rectangle<float> getLineBounds() const noexcept;
208
209 void swap (Line& other) noexcept;
210
215 float ascent = 0.0f, descent = 0.0f, leading = 0.0f;
216
217 private:
219 };
220
221 //==============================================================================
223 float getWidth() const noexcept { return width; }
224
226 float getHeight() const noexcept { return height; }
227
229 int getNumLines() const noexcept { return lines.size(); }
230
232 Line& getLine (int index) const noexcept;
233
236 void addLine (std::unique_ptr<Line>);
237
239 void ensureStorageAllocated (int numLinesNeeded);
240
241 using iterator = DereferencingIterator< Line* const*>;
242 using const_iterator = DereferencingIterator<const Line* const*>;
243
245 iterator begin() { return iterator (lines.begin()); }
246 const_iterator begin() const { return const_iterator (lines.begin()); }
247 const_iterator cbegin() const { return const_iterator (lines.begin()); }
248
250 iterator end() { return iterator (lines.end()); }
251 const_iterator end() const { return const_iterator (lines.end()); }
252 const_iterator cend() const { return const_iterator (lines.end()); }
253
257 void recalculateSize();
258
259private:
260 OwnedArray<Line> lines;
261 float width, height;
262 Justification justification;
263
264 void createStandardLayout (const AttributedString&);
265 bool createNativeLayout (const AttributedString&);
266
267 JUCE_LEAK_DETECTOR (TextLayout)
268};
269
270} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
A text string with a set of colour/font settings that are associated with sub-ranges of the text.
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
A graphics context, used for drawing a component or image.
Represents a line.
Definition juce_Line.h:47
An array designed for holding objects.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
A general-purpose range object, that simply represents any linear range with a start and end point.
Definition juce_Range.h:40
Manages a rectangle and allows geometric operations to be performed on it.
A positioned glyph.
Point< float > anchor
The glyph's anchor point - this is relative to the line's origin.
int glyphCode
The code number of this glyph.
A line containing a sequence of glyph-runs.
Range< int > stringRange
The character range that this line represents in the original string that was used to create it.
Point< float > lineOrigin
The line's baseline origin.
OwnedArray< Run > runs
The glyph-runs in this line.
A sequence of glyphs with a common font and colour.
Range< int > stringRange
The character range that this run represents in the original string that was used to create it.
Array< Glyph > glyphs
The glyphs in this run.
Font font
The run's font.
A Pre-formatted piece of text, which may contain multiple fonts and colours.
iterator begin()
Returns an iterator over the lines of content.
int getNumLines() const noexcept
Returns the number of lines in the layout.
float getWidth() const noexcept
Returns the maximum width of the content.
iterator end()
Returns an iterator over the lines of content.
float getHeight() const noexcept
Returns the maximum height of the content.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88