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_GlyphArrangement.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//==============================================================================
41class JUCE_API PositionedGlyph final
42{
43public:
44 //==============================================================================
45 PositionedGlyph() noexcept;
46
47 PositionedGlyph (const Font& font, juce_wchar character, int glyphNumber,
48 float anchorX, float baselineY, float width, bool isWhitespace);
49
51 juce_wchar getCharacter() const noexcept { return character; }
53 bool isWhitespace() const noexcept { return whitespace; }
54
56 float getLeft() const noexcept { return x; }
58 float getRight() const noexcept { return x + w; }
60 float getBaselineY() const noexcept { return y; }
62 float getTop() const { return y - font.getAscent(); }
64 float getBottom() const { return y + font.getDescent(); }
66 Rectangle<float> getBounds() const { return { x, getTop(), w, font.getHeight() }; }
67
68 //==============================================================================
70 void moveBy (float deltaX, float deltaY);
71
72 //==============================================================================
76 void draw (Graphics& g) const;
77
81 void draw (Graphics& g, AffineTransform transform) const;
82
86 void createPath (Path& path) const;
87
89 bool hitTest (float x, float y) const;
90
91private:
92 //==============================================================================
93 friend class GlyphArrangement;
94 Font font;
95 juce_wchar character;
96 int glyph;
97 float x, y, w;
98 bool whitespace;
99
101};
102
103
104//==============================================================================
117{
118public:
119 //==============================================================================
122
123 GlyphArrangement (const GlyphArrangement&) = default;
124 GlyphArrangement& operator= (const GlyphArrangement&) = default;
126 GlyphArrangement& operator= (GlyphArrangement&&) = default;
127
129 ~GlyphArrangement() = default;
130
131 //==============================================================================
133 int getNumGlyphs() const noexcept { return glyphs.size(); }
134
141 PositionedGlyph& getGlyph (int index) noexcept;
142
143 const PositionedGlyph* begin() const { return glyphs.begin(); }
144 const PositionedGlyph* end() const { return glyphs.end(); }
145
146 //==============================================================================
148 void clear();
149
158 void addLineOfText (const Font& font,
159 const String& text,
160 float x, float y);
161
168 void addCurtailedLineOfText (const Font& font,
169 const String& text,
170 float x, float y,
171 float maxWidthPixels,
172 bool useEllipsis);
173
187 void addJustifiedText (const Font& font,
188 const String& text,
189 float x, float y,
190 float maxLineWidth,
191 Justification horizontalLayout,
192 float leading = 0.0f);
193
213 void addFittedText (const Font& font,
214 const String& text,
215 float x, float y, float width, float height,
216 Justification layout,
217 int maximumLinesToUse,
218 float minimumHorizontalScale = 0.0f);
219
221 void addGlyphArrangement (const GlyphArrangement&);
222
224 void addGlyph (const PositionedGlyph&);
225
226 //==============================================================================
232 void draw (const Graphics&) const;
233
239 void draw (const Graphics&, AffineTransform) const;
240
244 void createPath (Path& path) const;
245
249 int findGlyphIndexAt (float x, float y) const;
250
251 //==============================================================================
261 Rectangle<float> getBoundingBox (int startIndex, int numGlyphs, bool includeWhitespace) const;
262
271 void moveRangeOfGlyphs (int startIndex, int numGlyphs,
272 float deltaX, float deltaY);
273
280 void removeRangeOfGlyphs (int startIndex, int numGlyphs);
281
289 void stretchRangeOfGlyphs (int startIndex, int numGlyphs,
290 float horizontalScaleFactor);
291
300 void justifyGlyphs (int startIndex, int numGlyphs,
301 float x, float y, float width, float height,
302 Justification justification);
303
304
305private:
306 //==============================================================================
307 Array<PositionedGlyph> glyphs;
308
309 int insertEllipsis (const Font&, float maxXPos, int startIndex, int endIndex);
310 int fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font&,
311 Justification, float minimumHorizontalScale);
312 void spreadOutLine (int start, int numGlyphs, float targetWidth);
313 void splitLines (const String&, Font, int start, float x, float y, float w, float h, int maxLines,
314 float lineWidth, Justification, float minimumHorizontalScale);
315 void addLinesWithLineBreaks (const String&, const Font&, float x, float y, float width, float height, Justification);
316 void drawGlyphUnderline (const Graphics&, const PositionedGlyph&, int, AffineTransform) const;
317
318 JUCE_LEAK_DETECTOR (GlyphArrangement)
319};
320
321} // namespace juce
Represents a 2D affine-transformation matrix.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
float getDescent() const
Returns the amount that the font descends below its baseline, in pixels.
float getHeight() const noexcept
Returns the total height of this font, in pixels.
float getAscent() const
Returns the height of the font above its baseline, in pixels.
A set of glyphs, each with a position.
int getNumGlyphs() const noexcept
Returns the total number of glyphs in the arrangement.
~GlyphArrangement()=default
Destructor.
A graphics context, used for drawing a component or image.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
Definition juce_Path.h:65
A glyph from a particular font, with a particular size, style, typeface and position.
float getBaselineY() const noexcept
Returns the y position of the glyph's baseline.
juce_wchar getCharacter() const noexcept
Returns the character the glyph represents.
bool isWhitespace() const noexcept
Checks whether the glyph is actually empty.
float getRight() const noexcept
Returns the position of the glyph's right-hand edge.
float getBottom() const
Returns the y position of the bottom of the glyph.
float getTop() const
Returns the y position of the top of the glyph.
float getLeft() const noexcept
Returns the position of the glyph's left-hand edge.
Rectangle< float > getBounds() const
Returns the bounds of the glyph.
Manages a rectangle and allows geometric operations to be performed on it.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
JUCE Namespace.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
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