From 06da4f2daf5efa796c0d9b8a5f5f8e14a436f52d Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 11 Mar 2019 16:43:21 +0000 Subject: [PATCH] Added a font 'leading' parameter for multiline text layouts --- modules/juce_graphics/contexts/juce_GraphicsContext.cpp | 4 ++-- modules/juce_graphics/contexts/juce_GraphicsContext.h | 6 ++++-- modules/juce_graphics/fonts/juce_GlyphArrangement.cpp | 5 +++-- modules/juce_graphics/fonts/juce_GlyphArrangement.h | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp index 7dfed77266..d8b06703fe 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp @@ -274,7 +274,7 @@ void Graphics::drawSingleLineText (const String& text, const int startX, const i void Graphics::drawMultiLineText (const String& text, const int startX, const int baselineY, const int maximumLineWidth, - Justification justification) const + Justification justification, const float leading) const { if (text.isNotEmpty() && startX < context.getClipBounds().getRight()) @@ -282,7 +282,7 @@ void Graphics::drawMultiLineText (const String& text, const int startX, GlyphArrangement arr; arr.addJustifiedText (context.getFont(), text, (float) startX, (float) baselineY, (float) maximumLineWidth, - justification); + justification, leading); arr.draw (*this); } } diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.h b/modules/juce_graphics/contexts/juce_GraphicsContext.h index 50f517b5f2..1c2a293a8b 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.h +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.h @@ -139,14 +139,16 @@ public: 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 - 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 */ void drawMultiLineText (const String& text, int startX, int baselineY, 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. diff --git a/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp b/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp index 73d3c3f8c6..b96a893b46 100644 --- a/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp +++ b/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp @@ -256,7 +256,8 @@ int GlyphArrangement::insertEllipsis (const Font& font, float maxXPos, int start void GlyphArrangement::addJustifiedText (const Font& font, const String& text, float x, float y, float maxLineWidth, - Justification horizontalLayout) + Justification horizontalLayout, + float leading) { auto lineStartIndex = glyphs.size(); addLineOfText (font, text, x, y); @@ -331,7 +332,7 @@ void GlyphArrangement::addJustifiedText (const Font& font, const String& text, lineStartIndex = i; - y += font.getHeight(); + y += font.getHeight() + leading; } } diff --git a/modules/juce_graphics/fonts/juce_GlyphArrangement.h b/modules/juce_graphics/fonts/juce_GlyphArrangement.h index c70a79f1a2..b5f798b7d9 100644 --- a/modules/juce_graphics/fonts/juce_GlyphArrangement.h +++ b/modules/juce_graphics/fonts/juce_GlyphArrangement.h @@ -194,13 +194,14 @@ public: between x and (x + maxLineWidth). 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, const String& text, float x, float y, float maxLineWidth, - Justification horizontalLayout); + Justification horizontalLayout, + float leading = 0.0f); /** Tries to fit some text within a given space.