openshot-audio  0.1.6
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_GLYPHARRANGEMENT_H_INCLUDED
26 #define JUCE_GLYPHARRANGEMENT_H_INCLUDED
27 
28 
29 //==============================================================================
40 {
41 public:
42  //==============================================================================
44  PositionedGlyph (const Font& font, juce_wchar character, int glyphNumber,
45  float anchorX, float baselineY, float width, bool isWhitespace);
46 
48  PositionedGlyph& operator= (const PositionedGlyph&);
49 
50  #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
53  #endif
54 
55  ~PositionedGlyph();
56 
58  juce_wchar getCharacter() const noexcept { return character; }
60  bool isWhitespace() const noexcept { return whitespace; }
61 
63  float getLeft() const noexcept { return x; }
65  float getRight() const noexcept { return x + w; }
67  float getBaselineY() const noexcept { return y; }
69  float getTop() const { return y - font.getAscent(); }
71  float getBottom() const { return y + font.getDescent(); }
73  Rectangle<float> getBounds() const { return Rectangle<float> (x, getTop(), w, font.getHeight()); }
74 
75  //==============================================================================
77  void moveBy (float deltaX, float deltaY);
78 
79  //==============================================================================
83  void draw (Graphics& g) const;
84 
88  void draw (Graphics& g, const AffineTransform& transform) const;
89 
93  void createPath (Path& path) const;
94 
96  bool hitTest (float x, float y) const;
97 
98 private:
99  //==============================================================================
100  friend class GlyphArrangement;
101  Font font;
102  juce_wchar character;
103  int glyph;
104  float x, y, w;
105  bool whitespace;
106 
108 };
109 
110 
111 //==============================================================================
122 {
123 public:
124  //==============================================================================
127 
130 
134  GlyphArrangement& operator= (const GlyphArrangement&);
135 
137  ~GlyphArrangement();
138 
139  //==============================================================================
141  int getNumGlyphs() const noexcept { return glyphs.size(); }
142 
149  PositionedGlyph& getGlyph (int index) const noexcept;
150 
151  //==============================================================================
153  void clear();
154 
163  void addLineOfText (const Font& font,
164  const String& text,
165  float x, float y);
166 
173  void addCurtailedLineOfText (const Font& font,
174  const String& text,
175  float x, float y,
176  float maxWidthPixels,
177  bool useEllipsis);
178 
192  void addJustifiedText (const Font& font,
193  const String& text,
194  float x, float y,
195  float maxLineWidth,
196  Justification horizontalLayout);
197 
217  void addFittedText (const Font& font,
218  const String& text,
219  float x, float y, float width, float height,
220  Justification layout,
221  int maximumLinesToUse,
222  float minimumHorizontalScale = 0.0f);
223 
225  void addGlyphArrangement (const GlyphArrangement&);
226 
228  void addGlyph (const PositionedGlyph&);
229 
230  //==============================================================================
236  void draw (const Graphics&) const;
237 
243  void draw (const Graphics&, const AffineTransform&) const;
244 
248  void createPath (Path& path) const;
249 
253  int findGlyphIndexAt (float x, float y) const;
254 
255  //==============================================================================
265  Rectangle<float> getBoundingBox (int startIndex, int numGlyphs, bool includeWhitespace) const;
266 
275  void moveRangeOfGlyphs (int startIndex, int numGlyphs,
276  float deltaX, float deltaY);
277 
284  void removeRangeOfGlyphs (int startIndex, int numGlyphs);
285 
293  void stretchRangeOfGlyphs (int startIndex, int numGlyphs,
294  float horizontalScaleFactor);
295 
304  void justifyGlyphs (int startIndex, int numGlyphs,
305  float x, float y, float width, float height,
306  Justification justification);
307 
308 
309 private:
310  //==============================================================================
311  Array<PositionedGlyph> glyphs;
312 
313  int insertEllipsis (const Font&, float maxXPos, int startIndex, int endIndex);
314  int fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font&,
316  void spreadOutLine (int start, int numGlyphs, float targetWidth);
317  void splitLines (const String&, Font, int start, float x, float y, float w, float h, int maxLines,
318  float lineWidth, Justification, float minimumHorizontalScale);
319  void addLinesWithLineBreaks (const String&, const Font&, float x, float y, float width, float height, Justification);
320  void drawGlyphUnderline (const Graphics&, const PositionedGlyph&, int, const AffineTransform&) const;
321 
323 };
324 
325 
326 #endif // JUCE_GLYPHARRANGEMENT_H_INCLUDED
float getLeft() const noexcept
Definition: juce_GlyphArrangement.h:63
Definition: juce_Font.h:39
float getTop() const
Definition: juce_GlyphArrangement.h:69
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_Justification.h:38
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
float getAscent() const
Definition: juce_Font.cpp:617
#define const
Definition: juce_Rectangle.h:36
juce_wchar getCharacter() const noexcept
Definition: juce_GlyphArrangement.h:58
float minimumHorizontalScale
Definition: juce_Font.cpp:33
Definition: juce_Path.h:62
bool isWhitespace() const noexcept
Definition: juce_GlyphArrangement.h:60
png_const_structrp png_const_inforp int png_fixed_point * width
Definition: juce_PNGLoader.cpp:2339
Definition: juce_GlyphArrangement.h:39
float getBaselineY() const noexcept
Definition: juce_GlyphArrangement.h:67
float getDescent() const
Definition: juce_Font.cpp:626
Definition: juce_GraphicsContext.h:42
Definition: juce_AffineTransform.h:40
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition: juce_LeakedObjectDetector.h:141
Definition: juce_GlyphArrangement.h:121
float getHeight() const noexcept
Definition: juce_Font.cpp:625
Rectangle< float > getBounds() const
Definition: juce_GlyphArrangement.h:73
wchar_t juce_wchar
Definition: juce_CharacterFunctions.h:49
float getBottom() const
Definition: juce_GlyphArrangement.h:71
float getRight() const noexcept
Definition: juce_GlyphArrangement.h:65
int getNumGlyphs() const noexcept
Definition: juce_GlyphArrangement.h:141