1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a font 'leading' parameter for multiline text layouts

This commit is contained in:
ed 2019-03-11 16:43:21 +00:00
parent 1a22a3fafb
commit 06da4f2daf
4 changed files with 12 additions and 8 deletions

View file

@ -274,7 +274,7 @@ void Graphics::drawSingleLineText (const String& text, const int startX, const i
void Graphics::drawMultiLineText (const String& text, const int startX, void Graphics::drawMultiLineText (const String& text, const int startX,
const int baselineY, const int maximumLineWidth, const int baselineY, const int maximumLineWidth,
Justification justification) const Justification justification, const float leading) const
{ {
if (text.isNotEmpty() if (text.isNotEmpty()
&& startX < context.getClipBounds().getRight()) && startX < context.getClipBounds().getRight())
@ -282,7 +282,7 @@ void Graphics::drawMultiLineText (const String& text, const int startX,
GlyphArrangement arr; GlyphArrangement arr;
arr.addJustifiedText (context.getFont(), text, arr.addJustifiedText (context.getFont(), text,
(float) startX, (float) baselineY, (float) maximumLineWidth, (float) startX, (float) baselineY, (float) maximumLineWidth,
justification); justification, leading);
arr.draw (*this); arr.draw (*this);
} }
} }

View file

@ -139,14 +139,16 @@ public:
This will break the text onto a new line where there's a new-line or This will break the text onto a new line where there's a new-line or
carriage-return character, or at a word-boundary when the text becomes wider carriage-return character, or at a word-boundary when the text becomes wider
than the size specified by the maximumLineWidth parameter. than the size specified by the maximumLineWidth parameter. New-lines
will be vertically separated by the specified leading.
@see setFont, drawSingleLineText, drawFittedText, GlyphArrangement::addJustifiedText @see setFont, drawSingleLineText, drawFittedText, GlyphArrangement::addJustifiedText
*/ */
void drawMultiLineText (const String& text, void drawMultiLineText (const String& text,
int startX, int baselineY, int startX, int baselineY,
int maximumLineWidth, int maximumLineWidth,
Justification justification = Justification::left) const; Justification justification = Justification::left,
float leading = 0.0f) const;
/** Draws a line of text within a specified rectangle. /** Draws a line of text within a specified rectangle.

View file

@ -256,7 +256,8 @@ int GlyphArrangement::insertEllipsis (const Font& font, float maxXPos, int start
void GlyphArrangement::addJustifiedText (const Font& font, const String& text, void GlyphArrangement::addJustifiedText (const Font& font, const String& text,
float x, float y, float maxLineWidth, float x, float y, float maxLineWidth,
Justification horizontalLayout) Justification horizontalLayout,
float leading)
{ {
auto lineStartIndex = glyphs.size(); auto lineStartIndex = glyphs.size();
addLineOfText (font, text, x, y); addLineOfText (font, text, x, y);
@ -331,7 +332,7 @@ void GlyphArrangement::addJustifiedText (const Font& font, const String& text,
lineStartIndex = i; lineStartIndex = i;
y += font.getHeight(); y += font.getHeight() + leading;
} }
} }

View file

@ -194,13 +194,14 @@ public:
between x and (x + maxLineWidth). between x and (x + maxLineWidth).
The y coordinate is the position of the baseline of the first line of text - subsequent The y coordinate is the position of the baseline of the first line of text - subsequent
lines will be placed below it, separated by a distance of font.getHeight(). lines will be placed below it, separated by a distance of font.getHeight() + leading.
*/ */
void addJustifiedText (const Font& font, void addJustifiedText (const Font& font,
const String& text, const String& text,
float x, float y, float x, float y,
float maxLineWidth, float maxLineWidth,
Justification horizontalLayout); Justification horizontalLayout,
float leading = 0.0f);
/** Tries to fit some text within a given space. /** Tries to fit some text within a given space.