From 844d9e8d866530693936d8133e2d25c12045e1bc Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 17 Mar 2015 11:41:14 +0000 Subject: [PATCH] Added method Font::getDefaultMinimumHorizontalScaleFactor() to make it possible to change the global minimum font squashing amount. --- .../juce_graphics/contexts/juce_GraphicsContext.h | 8 ++++---- modules/juce_graphics/fonts/juce_Font.cpp | 4 ++++ modules/juce_graphics/fonts/juce_Font.h | 12 ++++++++++++ .../juce_graphics/fonts/juce_GlyphArrangement.cpp | 5 ++++- modules/juce_graphics/fonts/juce_GlyphArrangement.h | 6 +++++- modules/juce_gui_basics/widgets/juce_Label.cpp | 2 +- modules/juce_gui_basics/widgets/juce_Label.h | 2 +- 7 files changed, 31 insertions(+), 8 deletions(-) diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.h b/modules/juce_graphics/contexts/juce_GraphicsContext.h index ed0bc404b5..a43da2af2f 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.h +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.h @@ -203,7 +203,7 @@ public: The minimumHorizontalScale parameter specifies how much the text can be squashed horizontally to try to squeeze it into the space. If you don't want any horizontal scaling to occur, you - can set this value to 1.0f. + can set this value to 1.0f. Pass 0 if you want it to use a default value. @see GlyphArrangement::addFittedText */ @@ -211,7 +211,7 @@ public: int x, int y, int width, int height, Justification justificationFlags, int maximumNumberOfLines, - float minimumHorizontalScale = 0.7f) const; + float minimumHorizontalScale = 0.0f) const; /** Tries to draw a text string inside a given space. @@ -228,7 +228,7 @@ public: The minimumHorizontalScale parameter specifies how much the text can be squashed horizontally to try to squeeze it into the space. If you don't want any horizontal scaling to occur, you - can set this value to 1.0f. + can set this value to 1.0f. Pass 0 if you want it to use a default value. @see GlyphArrangement::addFittedText */ @@ -236,7 +236,7 @@ public: const Rectangle& area, Justification justificationFlags, int maximumNumberOfLines, - float minimumHorizontalScale = 0.7f) const; + float minimumHorizontalScale = 0.0f) const; //============================================================================== /** Fills the context's entire clip region with the current colour or brush. diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index f0668d1d7c..1a4adf598c 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -30,6 +30,7 @@ namespace FontValues } const float defaultFontHeight = 14.0f; + float minimumHorizontalScale = 1.0f; String fallbackFont; String fallbackFontStyle; } @@ -37,6 +38,9 @@ namespace FontValues typedef Typeface::Ptr (*GetTypefaceForFont) (const Font&); GetTypefaceForFont juce_getTypefaceForFont = nullptr; +float Font::getDefaultMinimumHorizontalScaleFactor() noexcept { return FontValues::minimumHorizontalScale; } +void Font::setDefaultMinimumHorizontalScaleFactor (float newValue) noexcept { FontValues::minimumHorizontalScale = newValue; } + //============================================================================== class TypefaceCache : private DeletedAtShutdown { diff --git a/modules/juce_graphics/fonts/juce_Font.h b/modules/juce_graphics/fonts/juce_Font.h index 9888b27887..3da239d731 100644 --- a/modules/juce_graphics/fonts/juce_Font.h +++ b/modules/juce_graphics/fonts/juce_Font.h @@ -319,6 +319,18 @@ public: */ void setHorizontalScale (float scaleFactor); + /** Returns the minimum horizontal scale to which fonts may be squashed when trying to + create a layout. + @see setDefaultMinimumHorizontalScaleFactor + */ + static float getDefaultMinimumHorizontalScaleFactor() noexcept; + + /** Sets the minimum horizontal scale to which fonts may be squashed when trying to + create a text layout. + @see getDefaultMinimumHorizontalScaleFactor + */ + static void setDefaultMinimumHorizontalScaleFactor (float newMinimumScaleFactor) noexcept; + /** Returns the font's kerning. This is the extra space added between adjacent characters, as a proportion diff --git a/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp b/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp index 7b0de6ef51..8951668599 100644 --- a/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp +++ b/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp @@ -366,8 +366,11 @@ void GlyphArrangement::addFittedText (const Font& f, const float width, const float height, Justification layout, int maximumLines, - const float minimumHorizontalScale) + float minimumHorizontalScale) { + if (minimumHorizontalScale == 0.0f) + minimumHorizontalScale = Font::getDefaultMinimumHorizontalScaleFactor(); + // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0 jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f); diff --git a/modules/juce_graphics/fonts/juce_GlyphArrangement.h b/modules/juce_graphics/fonts/juce_GlyphArrangement.h index c771bffe69..1749728cda 100644 --- a/modules/juce_graphics/fonts/juce_GlyphArrangement.h +++ b/modules/juce_graphics/fonts/juce_GlyphArrangement.h @@ -208,6 +208,10 @@ public: A Justification parameter lets you specify how the text is laid out within the rectangle, both horizontally and vertically. + The minimumHorizontalScale parameter specifies how much the text can be squashed horizontally + to try to squeeze it into the space. If you don't want any horizontal scaling to occur, you + can set this value to 1.0f. Pass 0 if you want it to use the default value. + @see Graphics::drawFittedText */ void addFittedText (const Font& font, @@ -215,7 +219,7 @@ public: float x, float y, float width, float height, Justification layout, int maximumLinesToUse, - float minimumHorizontalScale = 0.7f); + float minimumHorizontalScale = 0.0f); /** Appends another glyph arrangement to this one. */ void addGlyphArrangement (const GlyphArrangement&); diff --git a/modules/juce_gui_basics/widgets/juce_Label.cpp b/modules/juce_gui_basics/widgets/juce_Label.cpp index 2531394b64..9bfb4fde6c 100644 --- a/modules/juce_gui_basics/widgets/juce_Label.cpp +++ b/modules/juce_gui_basics/widgets/juce_Label.cpp @@ -29,7 +29,7 @@ Label::Label (const String& name, const String& labelText) font (15.0f), justification (Justification::centredLeft), border (1, 5, 1, 5), - minimumHorizontalScale (0.7f), + minimumHorizontalScale (0.0f), keyboardType (TextEditor::textKeyboard), editSingleClick (false), editDoubleClick (false), diff --git a/modules/juce_gui_basics/widgets/juce_Label.h b/modules/juce_gui_basics/widgets/juce_Label.h index e71e5d522f..30116ca147 100644 --- a/modules/juce_gui_basics/widgets/juce_Label.h +++ b/modules/juce_gui_basics/widgets/juce_Label.h @@ -154,7 +154,7 @@ public: bool isAttachedOnLeft() const noexcept { return leftOfOwnerComp; } /** Specifies the minimum amount that the font can be squashed horizontally before it starts - using ellipsis. + using ellipsis. Use a value of 0 for a default value. @see Graphics::drawFittedText */