43 float anchorX,
float baselineY,
float width,
bool whitespace_)
51 auto& context =
g.getInternalContext();
52 context.setFont (font);
53 context.drawGlyph (glyph,
t);
72 if (
auto t =
font.getTypefacePtr())
75 t->getOutlineForGlyph (
glyph,
p);
87 if (
auto t =
font.getTypefacePtr())
90 t->getOutlineForGlyph (
glyph,
p);
93 .scaled (1.0f / (
font.getHeight() *
font.getHorizontalScale()), 1.0f /
font.getHeight())
94 .transformPoint (px, py);
96 return p.contains (px, py);
113 glyphs.ensureStorageAllocated (128);
124 return glyphs.getReference (index);
140 glyphs.removeRange (startIndex, num < 0 ?
glyphs.size() : num);
150 float xOffset,
float yOffset,
151 float maxWidthPixels,
bool useEllipsis)
153 if (
text.isNotEmpty())
158 auto textLen = newGlyphs.
size();
159 glyphs.ensureStorageAllocated (
glyphs.size() + textLen);
161 auto t =
text.getCharPointer();
163 for (
int i = 0;
i < textLen; ++
i)
167 if (nextX > maxWidthPixels + 1.0f)
170 if (useEllipsis && textLen > 3 &&
glyphs.size() >= 3)
181 xOffset + thisX, yOffset,
182 nextX - thisX, isWhitespace));
198 float xOffset = 0.0f, yOffset = 0.0f;
200 while (endIndex > startIndex)
202 auto& pg =
glyphs.getReference (--endIndex);
209 if (xOffset + dx * 3 <= maxXPos)
213 for (
int i = 3; --
i >= 0;)
216 xOffset, yOffset, dx,
false));
220 if (xOffset > maxXPos)
229 float x,
float y,
float maxLineWidth,
233 auto lineStartIndex =
glyphs.size();
238 while (lineStartIndex <
glyphs.size())
240 int i = lineStartIndex;
242 if (
glyphs.getReference(
i).getCharacter() !=
'\n'
243 &&
glyphs.getReference(
i).getCharacter() !=
'\r')
246 auto lineMaxX =
glyphs.getReference (lineStartIndex).getLeft() + maxLineWidth;
247 int lastWordBreakIndex = -1;
251 auto& pg =
glyphs.getReference (
i);
252 auto c = pg.getCharacter();
254 if (
c ==
'\r' ||
c ==
'\n')
259 &&
glyphs.getReference(
i).getCharacter() ==
'\n')
265 if (pg.isWhitespace())
267 lastWordBreakIndex =
i + 1;
269 else if (pg.getRight() - 0.0001f >= lineMaxX)
271 if (lastWordBreakIndex >= 0)
272 i = lastWordBreakIndex;
280 auto currentLineStartX =
glyphs.getReference (lineStartIndex).getLeft();
281 auto currentLineEndX = currentLineStartX;
283 for (
int j =
i; --
j >= lineStartIndex;)
285 if (!
glyphs.getReference (
j).isWhitespace())
287 currentLineEndX =
glyphs.getReference (
j).getRight();
297 deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
299 deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
302 x + deltaX - currentLineStartX,
y - originalY);
313 float minimumHorizontalScale)
315 if (minimumHorizontalScale == 0.0f)
319 jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
321 if (
text.containsAnyOf (
"\r\n"))
327 auto startIndex =
glyphs.size();
328 auto trimmed =
text.trim();
330 auto numGlyphs =
glyphs.size() - startIndex;
334 auto lineWidth =
glyphs.getReference (
glyphs.size() - 1).getRight()
335 -
glyphs.getReference (startIndex).getLeft();
339 if (lineWidth * minimumHorizontalScale <
width)
341 if (lineWidth >
width)
346 else if (maximumLines <= 1)
349 f, layout, minimumHorizontalScale);
354 maximumLines, lineWidth, layout, minimumHorizontalScale);
366 if (dx != 0.0f ||
dy != 0.0f)
368 if (num < 0 || startIndex + num >
glyphs.size())
369 num =
glyphs.size() - startIndex;
372 glyphs.getReference (startIndex++).moveBy (dx,
dy);
383 auto dy =
y -
bb.getY();
397 auto lineStartX =
glyphs.getReference (
start).getLeft();
398 auto lineWidth =
glyphs.getReference (
start + numGlyphs - 1).getRight() - lineStartX;
402 if (minimumHorizontalScale < 1.0f)
405 lineWidth =
glyphs.getReference (
start + numGlyphs - 1).getRight() - lineStartX - 0.5f;
411 numGlyphs -= numDeleted;
423 if (num < 0 || startIndex + num >
glyphs.size())
424 num =
glyphs.size() - startIndex;
428 auto xAnchor =
glyphs.getReference (startIndex).getLeft();
432 auto& pg =
glyphs.getReference (startIndex++);
434 pg.x = xAnchor + (pg.x - xAnchor) * horizontalScaleFactor;
435 pg.font.setHorizontalScale (pg.font.getHorizontalScale() * horizontalScaleFactor);
436 pg.w *= horizontalScaleFactor;
445 if (num < 0 || startIndex + num >
glyphs.size())
446 num =
glyphs.size() - startIndex;
452 auto& pg =
glyphs.getReference (startIndex++);
454 if (includeWhitespace || ! pg.isWhitespace())
465 jassert (num >= 0 && startIndex >= 0);
467 if (
glyphs.size() > 0 && num > 0)
471 float deltaX =
x, deltaY =
y;
476 else deltaX -=
bb.getX();
480 else deltaY += (
height -
bb.getHeight()) * 0.5f -
bb.getY();
487 auto baseY =
glyphs.getReference (startIndex).getBaselineY();
490 for (
i = 0;
i < num; ++
i)
492 auto glyphY =
glyphs.getReference (startIndex +
i).getBaselineY();
512 &&
glyphs.getReference (
start + num - 1).getCharacter() !=
'\r'
513 &&
glyphs.getReference (
start + num - 1).getCharacter() !=
'\n')
518 for (
int i = 0;
i < num; ++
i)
531 numSpaces -= spacesAtEnd;
535 auto startX =
glyphs.getReference (
start).getLeft();
536 auto endX =
glyphs.getReference (
start + num - 1 - spacesAtEnd).getRight();
538 auto extraPaddingBetweenWords = (targetWidth - (endX - startX)) / (
float) numSpaces;
541 for (
int i = 0;
i < num; ++
i)
546 deltaX += extraPaddingBetweenWords;
558 float x,
float y,
float width,
float height,
int maximumLines,
559 float lineWidth,
Justification layout,
float minimumHorizontalScale)
562 auto originalStartIndex = startIndex;
565 if (
length <= 12 && !
text.containsAnyOf (
" -\t\r\n"))
570 while (numLines < maximumLines)
573 auto newFontHeight =
height / (float) numLines;
582 lineWidth =
glyphs.getReference (
glyphs.size() - 1).getRight()
583 -
glyphs.getReference (startIndex).getLeft();
588 const float lineLengthUnevennessAllowance = 80.0f;
590 if ((
float) numLines > (lineWidth + lineLengthUnevennessAllowance) /
width || newFontHeight < 8.0f)
599 auto widthPerLine =
jmin (
width / minimumHorizontalScale,
600 lineWidth / (
float) numLines);
604 auto endIndex = startIndex;
605 auto lineStartX =
glyphs.getReference (startIndex).getLeft();
606 auto lineBottomY = lineY + font.
getHeight();
608 if (lineIndex++ >= numLines - 1
611 widthPerLine =
width;
616 while (endIndex <
glyphs.size())
618 if (
glyphs.getReference (endIndex).getRight() - lineStartX > widthPerLine)
622 auto searchStartIndex = endIndex;
624 while (endIndex <
glyphs.size())
626 auto&
g =
glyphs.getReference (endIndex);
628 if ((
g.getRight() - lineStartX) * minimumHorizontalScale <
width)
639 endIndex = searchStartIndex;
641 for (
int back = 1; back <
jmin (7, endIndex - startIndex - 1); ++back)
645 endIndex -= back - 1;
662 auto wsStart = endIndex;
663 auto wsEnd = endIndex;
665 while (wsStart > 0 &&
glyphs.getReference (wsStart - 1).isWhitespace())
668 while (wsEnd <
glyphs.size() &&
glyphs.getReference (wsEnd).isWhitespace())
672 endIndex =
jmax (wsStart, startIndex + 1);
678 minimumHorizontalScale);
680 startIndex = endIndex;
683 if (startIndex >=
glyphs.size())
696 auto nextX = pg.
x + pg.
w;
699 nextX =
glyphs.getReference (
i + 1).x;
702 p.addRectangle (pg.
x, pg.
y + lineThickness * 2.0f, nextX - pg.
x, lineThickness);
703 g.fillPath (
p, transform);
713 auto& context =
g.getInternalContext();
714 auto lastFont = context.getFont();
715 bool needToRestore =
false;
719 auto& pg =
glyphs.getReference (
i);
721 if (pg.font.isUnderlined())
724 if (! pg.isWhitespace())
726 if (lastFont != pg.font)
732 needToRestore =
true;
736 context.setFont (lastFont);
740 .followedBy (transform));
745 context.restoreState();
757 if (
glyphs.getReference (
i).hitTest (
x,
y))
Type jmin(const Type a, const Type b)
Definition MathsFunctions.h:60
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_Array.h:56
ElementType getUnchecked(int index) const
Definition juce_Array.h:252
int size() const noexcept
Definition juce_Array.h:215
ElementType getFirst() const noexcept
Definition juce_Array.h:290
Definition juce_Font.h:42
void getGlyphPositions(const String &text, Array< int > &glyphs, Array< float > &xOffsets) const
Definition juce_Font.cpp:757
static float getDefaultMinimumHorizontalScaleFactor() noexcept
Definition juce_Font.cpp:45
float getDescent() const
Definition juce_Font.cpp:736
float getHeight() const noexcept
Definition juce_Font.cpp:735
void setHeight(float newHeight)
Definition juce_Font.cpp:568
void clear()
Definition juce_GlyphArrangement.cpp:117
void addGlyph(const PositionedGlyph &)
Definition juce_GlyphArrangement.cpp:133
void addLineOfText(const Font &font, const String &text, float x, float y)
Definition juce_GlyphArrangement.cpp:144
void createPath(Path &path) const
Definition juce_GlyphArrangement.cpp:748
void stretchRangeOfGlyphs(int startIndex, int numGlyphs, float horizontalScaleFactor)
Definition juce_GlyphArrangement.cpp:419
Rectangle< float > getBoundingBox(int startIndex, int numGlyphs, bool includeWhitespace) const
Definition juce_GlyphArrangement.cpp:441
void splitLines(const String &, Font, int start, float x, float y, float w, float h, int maxLines, float lineWidth, Justification, float minimumHorizontalScale)
Definition juce_GlyphArrangement.cpp:557
void addLinesWithLineBreaks(const String &, const Font &, float x, float y, float width, float height, Justification)
Definition juce_GlyphArrangement.cpp:376
int insertEllipsis(const Font &, float maxXPos, int startIndex, int endIndex)
Definition juce_GlyphArrangement.cpp:187
void addFittedText(const Font &font, const String &text, float x, float y, float width, float height, Justification layout, int maximumLinesToUse, float minimumHorizontalScale=0.0f)
Definition juce_GlyphArrangement.cpp:310
void addCurtailedLineOfText(const Font &font, const String &text, float x, float y, float maxWidthPixels, bool useEllipsis)
Definition juce_GlyphArrangement.cpp:149
Array< PositionedGlyph > glyphs
Definition juce_GlyphArrangement.h:307
void addJustifiedText(const Font &font, const String &text, float x, float y, float maxLineWidth, Justification horizontalLayout, float leading=0.0f)
Definition juce_GlyphArrangement.cpp:228
int findGlyphIndexAt(float x, float y) const
Definition juce_GlyphArrangement.cpp:754
void draw(const Graphics &) const
Definition juce_GlyphArrangement.cpp:706
GlyphArrangement()
Definition juce_GlyphArrangement.cpp:111
PositionedGlyph & getGlyph(int index) noexcept
Definition juce_GlyphArrangement.cpp:122
void addGlyphArrangement(const GlyphArrangement &)
Definition juce_GlyphArrangement.cpp:128
void drawGlyphUnderline(const Graphics &, const PositionedGlyph &, int, AffineTransform) const
Definition juce_GlyphArrangement.cpp:692
void justifyGlyphs(int startIndex, int numGlyphs, float x, float y, float width, float height, Justification justification)
Definition juce_GlyphArrangement.cpp:461
void moveRangeOfGlyphs(int startIndex, int numGlyphs, float deltaX, float deltaY)
Definition juce_GlyphArrangement.cpp:362
int fitLineIntoSpace(int start, int numGlyphs, float x, float y, float w, float h, const Font &, Justification, float minimumHorizontalScale)
Definition juce_GlyphArrangement.cpp:393
void removeRangeOfGlyphs(int startIndex, int numGlyphs)
Definition juce_GlyphArrangement.cpp:138
void spreadOutLine(int start, int numGlyphs, float targetWidth)
Definition juce_GlyphArrangement.cpp:509
Definition juce_GraphicsContext.h:45
Definition juce_Justification.h:41
@ horizontallyJustified
Definition juce_Justification.h:132
@ horizontallyCentred
Definition juce_Justification.h:115
@ bottom
Definition juce_Justification.h:122
@ verticallyCentred
Definition juce_Justification.h:126
@ top
Definition juce_Justification.h:119
@ right
Definition juce_Justification.h:111
int getOnlyHorizontalFlags() const noexcept
Definition juce_Justification.h:69
int getFlags() const noexcept
Definition juce_Justification.h:58
bool testFlags(int flagsToTest) const noexcept
Definition juce_Justification.h:63
Definition juce_Path.h:65
void addPath(const Path &pathToAppend)
Definition juce_Path.cpp:726
Definition juce_GlyphArrangement.h:42
PositionedGlyph() noexcept
Definition juce_GlyphArrangement.cpp:37
float w
Definition juce_GlyphArrangement.h:97
void draw(Graphics &g) const
Definition juce_GlyphArrangement.cpp:56
float y
Definition juce_GlyphArrangement.h:97
bool isWhitespace() const noexcept
Definition juce_GlyphArrangement.h:53
float x
Definition juce_GlyphArrangement.h:97
bool hitTest(float x, float y) const
Definition juce_GlyphArrangement.cpp:83
int glyph
Definition juce_GlyphArrangement.h:96
bool whitespace
Definition juce_GlyphArrangement.h:98
Font font
Definition juce_GlyphArrangement.h:94
void moveBy(float deltaX, float deltaY)
Definition juce_GlyphArrangement.cpp:103
Rectangle< float > getBounds() const
Definition juce_GlyphArrangement.h:66
void createPath(Path &path) const
Definition juce_GlyphArrangement.cpp:68
juce_wchar character
Definition juce_GlyphArrangement.h:95
Definition juce_Rectangle.h:67
Definition juce_String.h:53
UINT_D64 w
Definition inflate.c:942
G bb
Definition inflate.c:1057
struct huft * t
Definition inflate.c:943
register unsigned j
Definition inflate.c:1576
int y
Definition inflate.c:1588
int g
Definition inflate.c:1573
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
unsigned f
Definition inflate.c:1572
static int int height
Definition pugl.h:1594
static int width
Definition pugl.h:1593
virtual ASIOError start()=0
Definition carla_juce.cpp:31
static constexpr bool isNonBreakingSpace(const juce_wchar c)
Definition juce_GlyphArrangement.cpp:29
constexpr Type jmax(Type a, Type b)
Definition juce_MathsFunctions.h:94
static void drawGlyphWithFont(Graphics &g, int glyph, const Font &font, AffineTransform t)
Definition juce_GlyphArrangement.cpp:49
static bool isBreakableGlyph(const PositionedGlyph &g) noexcept
Definition juce_GlyphArrangement.cpp:552
wchar_t juce_wchar
Definition juce_CharacterFunctions.h:42
#define false
Definition ordinals.h:83
png_uint_32 length
Definition png.c:2247
const char * text
Definition swell-functions.h:167
uch * p
Definition crypt.c:594
return c
Definition crypt.c:175
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
int result
Definition process.c:1455
dy
Definition zipinfo.c:2288