From 4533077b750a17b09e920454ffce2874ac032698 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 20 Mar 2024 14:37:06 +0000 Subject: [PATCH] LookAndFeel: Allow specifying a default typeface metrics kind to use --- .../scanning/juce_PluginListComponent.cpp | 2 +- .../gui/juce_AudioDeviceSelectorComponent.cpp | 2 +- .../gui/juce_MPEKeyboardComponent.cpp | 2 +- .../gui/juce_MidiKeyboardComponent.cpp | 2 +- .../contexts/juce_GraphicsContext.cpp | 2 +- .../buttons/juce_HyperlinkButton.cpp | 4 +- .../components/juce_Component.cpp | 5 +++ .../components/juce_Component.h | 3 ++ .../detail/juce_LookAndFeelHelpers.h | 4 +- .../drawables/juce_DrawableText.cpp | 2 +- .../drawables/juce_DrawableText.h | 2 +- .../juce_FileSearchPathListComponent.cpp | 2 +- .../lookandfeel/juce_LookAndFeel.h | 13 ++++++ .../lookandfeel/juce_LookAndFeel_V1.cpp | 2 +- .../lookandfeel/juce_LookAndFeel_V2.cpp | 42 +++++++++---------- .../lookandfeel/juce_LookAndFeel_V3.cpp | 4 +- .../lookandfeel/juce_LookAndFeel_V4.cpp | 22 +++++----- modules/juce_gui_basics/widgets/juce_Label.h | 2 +- .../juce_gui_basics/widgets/juce_TextEditor.h | 2 +- .../juce_gui_basics/widgets/juce_Toolbar.cpp | 2 +- .../code_editor/juce_CodeEditorComponent.cpp | 2 +- .../code_editor/juce_CodeEditorComponent.h | 2 +- .../misc/juce_ColourSelector.cpp | 2 +- .../misc/juce_KeyMappingEditorComponent.cpp | 4 +- .../misc/juce_LiveConstantEditor.cpp | 2 +- .../marketplace/juce_OnlineUnlockForm.cpp | 9 ++-- 26 files changed, 82 insertions(+), 60 deletions(-) diff --git a/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp b/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp index c3b3c4f205..4b51311a37 100644 --- a/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp +++ b/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp @@ -97,7 +97,7 @@ public: g.setColour (isBlacklisted ? Colours::red : columnId == nameCol ? defaultTextColour : defaultTextColour.interpolatedWith (Colours::transparentBlack, 0.3f)); - g.setFont (FontOptions ((float) height * 0.7f, Font::bold)); + g.setFont (owner.withDefaultMetrics (FontOptions ((float) height * 0.7f, Font::bold))); g.drawFittedText (text, 4, 0, width - 6, height, Justification::centredLeft, 1, 0.9f); } } diff --git a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp index a8937e2d13..2e0f4bc740 100644 --- a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp @@ -82,7 +82,7 @@ static void drawTextLayout (Graphics& g, Component& owner, StringRef text, const AttributedString attributedString { text }; attributedString.setColour (textColour); - attributedString.setFont (FontOptions { (float) textBounds.getHeight() * 0.6f }); + attributedString.setFont (owner.withDefaultMetrics (FontOptions { (float) textBounds.getHeight() * 0.6f })); attributedString.setJustification (Justification::centredLeft); attributedString.setWordWrap (AttributedString::WordWrap::none); diff --git a/modules/juce_audio_utils/gui/juce_MPEKeyboardComponent.cpp b/modules/juce_audio_utils/gui/juce_MPEKeyboardComponent.cpp index f646762984..35eb16b10c 100644 --- a/modules/juce_audio_utils/gui/juce_MPEKeyboardComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_MPEKeyboardComponent.cpp @@ -109,7 +109,7 @@ void MPEKeyboardComponent::drawWhiteKey (int midiNoteNumber, Graphics& g, Rectan auto text = MidiMessage::getMidiNoteName (midiNoteNumber, true, true, getOctaveForMiddleC()); g.setColour (findColour (textLabelColourId)); - g.setFont (Font (FontOptions { fontHeight }).withHorizontalScale (0.8f)); + g.setFont (withDefaultMetrics (FontOptions { fontHeight }).withHorizontalScale (0.8f)); switch (getOrientation()) { diff --git a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp index d34eb72128..5baac327b3 100644 --- a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp @@ -379,7 +379,7 @@ void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber, Graphics& g, Rect auto fontHeight = jmin (12.0f, getKeyWidth() * 0.9f); g.setColour (textColour); - g.setFont (Font (FontOptions { fontHeight }).withHorizontalScale (0.8f)); + g.setFont (withDefaultMetrics (FontOptions { fontHeight }).withHorizontalScale (0.8f)); switch (currentOrientation) { diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp index 9c08a75f02..4631b3cb59 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp @@ -130,7 +130,7 @@ void Graphics::resetToDefaultState() { saveStateIfPending(); context.setFill (FillType()); - context.setFont (FontOptions{}); + context.setFont (FontOptions{}.withMetricsKind (TypefaceMetricsKind::legacy)); context.setInterpolationQuality (Graphics::mediumResamplingQuality); } diff --git a/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp b/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp index 73e57719b0..9f548dcf13 100644 --- a/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp @@ -39,7 +39,7 @@ HyperlinkButton::HyperlinkButton (const String& linkText, const URL& linkURL) : Button (linkText), url (linkURL), - font (FontOptions { 14.0f, Font::underlined }), + font (withDefaultMetrics (FontOptions { 14.0f, Font::underlined })), resizeFont (true), justification (Justification::centred) { @@ -49,7 +49,7 @@ HyperlinkButton::HyperlinkButton (const String& linkText, HyperlinkButton::HyperlinkButton() : Button (String()), - font (FontOptions { 14.0f, Font::underlined }), + font (withDefaultMetrics (FontOptions { 14.0f, Font::underlined })), resizeFont (true), justification (Justification::centred) { diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 38323451ab..63350d1844 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -1856,6 +1856,11 @@ void Component::setLookAndFeel (LookAndFeel* newLookAndFeel) } } +FontOptions Component::withDefaultMetrics (FontOptions opt) const +{ + return getLookAndFeel().withDefaultMetrics (std::move (opt)); +} + void Component::lookAndFeelChanged() {} void Component::colourChanged() {} diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index 6fc7522903..dbc47b034d 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -1181,6 +1181,9 @@ public: */ void setLookAndFeel (LookAndFeel* newLookAndFeel); + /** Returns a copy of the FontOptions with the default metrics kind from the component's LookAndFeel. */ + FontOptions withDefaultMetrics (FontOptions opt) const; + /** Called to let the component react to a change in the look-and-feel setting. When the look-and-feel is changed for a component, this method, repaint(), and diff --git a/modules/juce_gui_basics/detail/juce_LookAndFeelHelpers.h b/modules/juce_gui_basics/detail/juce_LookAndFeelHelpers.h index 58f52fe604..959b411eb1 100644 --- a/modules/juce_gui_basics/detail/juce_LookAndFeelHelpers.h +++ b/modules/juce_gui_basics/detail/juce_LookAndFeelHelpers.h @@ -53,14 +53,14 @@ struct LookAndFeelHelpers return baseColour; } - static TextLayout layoutTooltipText (const String& text, Colour colour) noexcept + static TextLayout layoutTooltipText (TypefaceMetricsKind metrics, const String& text, Colour colour) noexcept { const float tooltipFontSize = 13.0f; const int maxToolTipWidth = 400; AttributedString s; s.setJustification (Justification::centred); - s.append (text, FontOptions (tooltipFontSize, Font::bold), colour); + s.append (text, FontOptions (tooltipFontSize, Font::bold).withMetricsKind (metrics), colour); TextLayout tl; tl.createLayoutWithBalancedLineLengths (s, (float) maxToolTipWidth); diff --git a/modules/juce_gui_basics/drawables/juce_DrawableText.cpp b/modules/juce_gui_basics/drawables/juce_DrawableText.cpp index b38e6e4962..16ccb03387 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableText.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableText.cpp @@ -40,7 +40,7 @@ DrawableText::DrawableText() justification (Justification::centredLeft) { setBoundingBox (Parallelogram ({ 0.0f, 0.0f, 50.0f, 20.0f })); - setFont (FontOptions (15.0f), true); + setFont (withDefaultMetrics (FontOptions (15.0f)), true); } DrawableText::DrawableText (const DrawableText& other) diff --git a/modules/juce_gui_basics/drawables/juce_DrawableText.h b/modules/juce_gui_basics/drawables/juce_DrawableText.h index b92130f31d..1af5a7bcd5 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableText.h +++ b/modules/juce_gui_basics/drawables/juce_DrawableText.h @@ -114,7 +114,7 @@ private: //============================================================================== Parallelogram bounds; float fontHeight, fontHScale; - Font font { FontOptions{} }, scaledFont { FontOptions{} }; + Font font { withDefaultMetrics (FontOptions{}) }, scaledFont { withDefaultMetrics (FontOptions{}) }; String text; Colour colour; Justification justification; diff --git a/modules/juce_gui_basics/filebrowser/juce_FileSearchPathListComponent.cpp b/modules/juce_gui_basics/filebrowser/juce_FileSearchPathListComponent.cpp index 06a1c3f32d..83f0c5ed4c 100644 --- a/modules/juce_gui_basics/filebrowser/juce_FileSearchPathListComponent.cpp +++ b/modules/juce_gui_basics/filebrowser/juce_FileSearchPathListComponent.cpp @@ -134,7 +134,7 @@ void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, g.fillAll (findColour (TextEditor::highlightColourId)); g.setColour (findColour (ListBox::textColourId)); - Font f (FontOptions { (float) height * 0.7f }); + Font f (withDefaultMetrics (FontOptions { (float) height * 0.7f })); f.setHorizontalScale (0.9f); g.setFont (f); diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h index f3095866f7..9f18174970 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h @@ -184,6 +184,19 @@ public: */ virtual Typeface::Ptr getTypefaceForFont (const Font&); + /** Widgets can call this to find out the kind of metrics they should use when creating their + own fonts. + + The default implementation returns the legacy metrics kind, but you can override this if + you want to use the portable metrics kind instead. Using portable metrics may cause text + to render at a different size, so you should check that text in your app still renders at an + appropriate size, and potentially adjust font sizes where necessary after overriding this. + */ + virtual TypefaceMetricsKind getDefaultMetricsKind() const { return TypefaceMetricsKind::legacy; } + + /** Returns a copy of the FontOptions with the LookAndFeel's default metrics kind set. */ + FontOptions withDefaultMetrics (FontOptions opt) const { return opt.withMetricsKind (getDefaultMetricsKind()); } + /** Allows you to supply a default typeface that will be returned as the default sans-serif font. diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V1.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V1.cpp index d03fa9cc20..980ba502fd 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V1.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V1.cpp @@ -371,7 +371,7 @@ void LookAndFeel_V1::drawComboBox (Graphics& g, int width, int height, Font LookAndFeel_V1::getComboBoxFont (ComboBox& box) { - Font f (FontOptions { jmin (15.0f, (float) box.getHeight() * 0.85f) }); + Font f (withDefaultMetrics (FontOptions { jmin (15.0f, (float) box.getHeight() * 0.85f) })); f.setHorizontalScale (0.9f); return f; } diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index d29b6bd62a..142ffa4704 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -260,7 +260,7 @@ void LookAndFeel_V2::drawButtonBackground (Graphics& g, Font LookAndFeel_V2::getTextButtonFont (TextButton&, int buttonHeight) { - return FontOptions (jmin (15.0f, (float) buttonHeight * 0.6f)); + return withDefaultMetrics (FontOptions (jmin (15.0f, (float) buttonHeight * 0.6f))); } int LookAndFeel_V2::getTextButtonWidthToFitText (TextButton& b, int buttonHeight) @@ -359,7 +359,7 @@ void LookAndFeel_V2::changeToggleButtonWidthToFitText (ToggleButton& button) auto fontSize = jmin (15.0f, (float) button.getHeight() * 0.75f); auto tickWidth = fontSize * 1.1f; - Font font (FontOptions { fontSize }); + Font font (withDefaultMetrics (FontOptions { fontSize })); button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 9, button.getHeight()); @@ -471,7 +471,7 @@ void LookAndFeel_V2::drawAlertBox (Graphics& g, AlertWindow& alert, } GlyphArrangement ga; - ga.addFittedText (FontOptions ((float) iconRect.getHeight() * 0.9f, Font::bold), + ga.addFittedText (withDefaultMetrics (FontOptions ((float) iconRect.getHeight() * 0.9f, Font::bold)), String::charToString ((juce_wchar) (uint8) character), (float) iconRect.getX(), (float) iconRect.getY(), (float) iconRect.getWidth(), (float) iconRect.getHeight(), @@ -528,12 +528,12 @@ Font LookAndFeel_V2::getAlertWindowTitleFont() Font LookAndFeel_V2::getAlertWindowMessageFont() { - return FontOptions (15.0f); + return withDefaultMetrics (FontOptions (15.0f)); } Font LookAndFeel_V2::getAlertWindowFont() { - return FontOptions (12.0f); + return withDefaultMetrics (FontOptions (12.0f)); } //============================================================================== @@ -864,7 +864,7 @@ void LookAndFeel_V2::setComponentEffectForBubbleComponent (BubbleComponent& bubb //============================================================================== Font LookAndFeel_V2::getPopupMenuFont() { - return FontOptions (17.0f); + return withDefaultMetrics (FontOptions (17.0f)); } void LookAndFeel_V2::getIdealPopupMenuItemSize (const String& text, const bool isSeparator, @@ -1112,7 +1112,7 @@ void LookAndFeel_V2::drawMenuBarBackground (Graphics& g, int width, int height, Font LookAndFeel_V2::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/) { - return FontOptions ((float) menuBar.getHeight() * 0.7f); + return withDefaultMetrics (FontOptions ((float) menuBar.getHeight() * 0.7f)); } int LookAndFeel_V2::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText) @@ -1264,7 +1264,7 @@ void LookAndFeel_V2::drawComboBox (Graphics& g, int width, int height, const boo Font LookAndFeel_V2::getComboBoxFont (ComboBox& box) { - return FontOptions (jmin (15.0f, (float) box.getHeight() * 0.85f)); + return withDefaultMetrics (FontOptions (jmin (15.0f, (float) box.getHeight() * 0.85f))); } Label* LookAndFeel_V2::createComboBoxTextBox (ComboBox&) @@ -1645,7 +1645,7 @@ ImageEffectFilter* LookAndFeel_V2::getSliderEffect (Slider&) Font LookAndFeel_V2::getSliderPopupFont (Slider&) { - return FontOptions (15.0f, Font::bold); + return withDefaultMetrics (FontOptions (15.0f, Font::bold)); } int LookAndFeel_V2::getSliderPopupPlacement (Slider&) @@ -1728,7 +1728,7 @@ Slider::SliderLayout LookAndFeel_V2::getSliderLayout (Slider& slider) //============================================================================== Rectangle LookAndFeel_V2::getTooltipBounds (const String& tipText, Point screenPos, Rectangle parentArea) { - const TextLayout tl (detail::LookAndFeelHelpers::layoutTooltipText (tipText, Colours::black)); + const TextLayout tl (detail::LookAndFeelHelpers::layoutTooltipText (getDefaultMetricsKind(), tipText, Colours::black)); auto w = (int) (tl.getWidth() + 14.0f); auto h = (int) (tl.getHeight() + 6.0f); @@ -1748,7 +1748,7 @@ void LookAndFeel_V2::drawTooltip (Graphics& g, const String& text, int width, in g.drawRect (0, 0, width, height, 1); #endif - detail::LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId)) + detail::LookAndFeelHelpers::layoutTooltipText (getDefaultMetricsKind(), text, findColour (TooltipWindow::textColourId)) .draw (g, Rectangle ((float) width, (float) height)); } @@ -1784,7 +1784,7 @@ void LookAndFeel_V2::drawConcertinaPanelHeader (Graphics& g, const Rectangle (iconRect.getX()), static_cast (iconRect.getY()), static_cast (iconRect.getWidth()), static_cast (iconRect.getHeight()), @@ -485,9 +485,9 @@ void LookAndFeel_V4::drawAlertBox (Graphics& g, AlertWindow& alert, } int LookAndFeel_V4::getAlertWindowButtonHeight() { return 40; } -Font LookAndFeel_V4::getAlertWindowTitleFont() { return FontOptions { 18.0f, Font::bold }; } -Font LookAndFeel_V4::getAlertWindowMessageFont() { return FontOptions { 16.0f }; } -Font LookAndFeel_V4::getAlertWindowFont() { return FontOptions { 14.0f }; } +Font LookAndFeel_V4::getAlertWindowTitleFont() { return withDefaultMetrics (FontOptions { 18.0f, Font::bold }); } +Font LookAndFeel_V4::getAlertWindowMessageFont() { return withDefaultMetrics (FontOptions { 16.0f }); } +Font LookAndFeel_V4::getAlertWindowFont() { return withDefaultMetrics (FontOptions { 14.0f }); } //============================================================================== void LookAndFeel_V4::drawProgressBar (Graphics& g, ProgressBar& progressBar, @@ -629,7 +629,7 @@ void LookAndFeel_V4::drawCircularProgressBar (Graphics& g, const ProgressBar& pr if (textToShow.isNotEmpty()) { g.setColour (progressBar.findColour (TextButton::textColourOffId)); - g.setFont (FontOptions { 12.0f, Font::italic }); + g.setFont (progressBar.withDefaultMetrics (FontOptions { 12.0f, Font::italic })); g.drawText (textToShow, barBounds, Justification::centred, false); } } @@ -950,7 +950,7 @@ void LookAndFeel_V4::drawComboBox (Graphics& g, int width, int height, bool, Font LookAndFeel_V4::getComboBoxFont (ComboBox& box) { - return FontOptions { jmin (16.0f, (float) box.getHeight() * 0.85f) }; + return withDefaultMetrics (FontOptions { jmin (16.0f, (float) box.getHeight() * 0.85f) }); } void LookAndFeel_V4::positionComboBoxText (ComboBox& box, Label& label) @@ -1162,7 +1162,7 @@ void LookAndFeel_V4::drawTooltip (Graphics& g, const String& text, int width, in g.setColour (findColour (TooltipWindow::outlineColourId)); g.drawRoundedRectangle (bounds.toFloat().reduced (0.5f, 0.5f), cornerSize, 1.0f); - detail::LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId)) + detail::LookAndFeelHelpers::layoutTooltipText (getDefaultMetricsKind(), text, findColour (TooltipWindow::textColourId)) .draw (g, { static_cast (width), static_cast (height) }); } @@ -1268,7 +1268,7 @@ void LookAndFeel_V4::drawPropertyPanelSectionHeader (Graphics& g, const String& g.setColour (findColour (PropertyComponent::labelTextColourId)); - g.setFont (FontOptions { (float) height * 0.7f, Font::bold }); + g.setFont (withDefaultMetrics (FontOptions { (float) height * 0.7f, Font::bold })); g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true); } diff --git a/modules/juce_gui_basics/widgets/juce_Label.h b/modules/juce_gui_basics/widgets/juce_Label.h index ef2905405d..3560b55ded 100644 --- a/modules/juce_gui_basics/widgets/juce_Label.h +++ b/modules/juce_gui_basics/widgets/juce_Label.h @@ -355,7 +355,7 @@ private: //============================================================================== Value textValue; String lastTextValue; - Font font { FontOptions { 15.0f } }; + Font font { withDefaultMetrics (FontOptions { 15.0f }) }; Justification justification = Justification::centredLeft; std::unique_ptr editor; ListenerList listeners; diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.h b/modules/juce_gui_basics/widgets/juce_TextEditor.h index 0aec33143c..044e26c2f0 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.h +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.h @@ -825,7 +825,7 @@ private: Range selection; int leftIndent = 4, topIndent = 4; unsigned int lastTransactionTime = 0; - Font currentFont { FontOptions { 14.0f } }; + Font currentFont { withDefaultMetrics (FontOptions { 14.0f }) }; mutable int totalNumChars = 0; int caretPosition = 0; OwnedArray sections; diff --git a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp index 27dc8dc1d9..d198afdd3b 100644 --- a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp +++ b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp @@ -770,7 +770,7 @@ private: } addAndMakeVisible (instructions); - instructions.setFont (FontOptions (13.0f)); + instructions.setFont (withDefaultMetrics (FontOptions (13.0f))); setSize (500, 300); } diff --git a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp index bdb78d0280..6297ddd9d2 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp +++ b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp @@ -467,7 +467,7 @@ CodeEditorComponent::CodeEditorComponent (CodeDocument& doc, CodeTokeniser* cons addAndMakeVisible (horizontalScrollBar); horizontalScrollBar.setSingleStepSize (1.0); - Font f (FontOptions { 12.0f }); + Font f (withDefaultMetrics (FontOptions { 12.0f })); f.setTypefaceName (Font::getDefaultMonospacedFontName()); setFont (f); diff --git a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h index a20e92f24c..37f6b4948d 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h +++ b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.h @@ -416,7 +416,7 @@ private: //============================================================================== CodeDocument& document; - Font font { FontOptions{} }; + Font font { withDefaultMetrics (FontOptions{}) }; int firstLineOnScreen = 0, spacesPerTab = 4; float charWidth = 0; int lineHeight = 0, linesOnScreen = 0, columnsOnScreen = 0; diff --git a/modules/juce_gui_extra/misc/juce_ColourSelector.cpp b/modules/juce_gui_extra/misc/juce_ColourSelector.cpp index 245628a5c8..c83283c1f8 100644 --- a/modules/juce_gui_extra/misc/juce_ColourSelector.cpp +++ b/modules/juce_gui_extra/misc/juce_ColourSelector.cpp @@ -382,7 +382,7 @@ private: ColourSelector& owner; Colour currentColour; - Font labelFont { FontOptions { 14.0f, Font::bold } }; + Font labelFont { withDefaultMetrics (FontOptions { 14.0f, Font::bold }) }; int labelWidth = 0; Label colourLabel; diff --git a/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp b/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp index 80507d89ca..9a6c88cc25 100644 --- a/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp +++ b/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp @@ -97,7 +97,7 @@ public: if (keyNum < 0) setSize (h, h); else - setSize (jlimit (h * 4, h * 8, 6 + Font (FontOptions { (float) h * 0.6f }).getStringWidth (getName())), h); + setSize (jlimit (h * 4, h * 8, 6 + Font (withDefaultMetrics (FontOptions { (float) h * 0.6f })).getStringWidth (getName())), h); } //============================================================================== @@ -321,7 +321,7 @@ public: void paintItem (Graphics& g, int width, int height) override { - g.setFont (FontOptions ((float) height * 0.7f, Font::bold)); + g.setFont (owner.withDefaultMetrics (FontOptions ((float) height * 0.7f, Font::bold))); g.setColour (owner.findColour (KeyMappingEditorComponent::textColourId)); g.drawText (TRANS (categoryName), 2, 0, width - 2, height, Justification::centredLeft, true); diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp index b59990c176..391f567189 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp @@ -144,7 +144,7 @@ LivePropertyEditorBase::LivePropertyEditorBase (LiveValueBase& v, CodeDocument& findOriginalValueInCode(); selectOriginalValue(); - name.setFont (FontOptions { 13.0f }); + name.setFont (withDefaultMetrics (FontOptions { 13.0f })); name.setText (v.name, dontSendNotification); valueEditor.setMultiLine (v.isString()); valueEditor.setReturnKeyStartsNewLine (v.isString()); diff --git a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp index 4dba0e5708..f6de1f09c0 100644 --- a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp +++ b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp @@ -250,9 +250,10 @@ void OnlineUnlockForm::resized() r.removeFromBottom (20); // (force use of a default system font to make sure it has the password blob character) - Font font (FontOptions { Font::getDefaultTypefaceForFont (FontOptions (Font::getDefaultSansSerifFontName(), - Font::getDefaultStyle(), - 5.0f)) }); + const auto typeface = Font::getDefaultTypefaceForFont (FontOptions (Font::getDefaultSansSerifFontName(), + Font::getDefaultStyle(), + 5.0f)); + Font font (withDefaultMetrics (FontOptions { typeface })); const int boxHeight = 24; passwordBox.setBounds (r.removeFromBottom (boxHeight)); @@ -286,7 +287,7 @@ void OnlineUnlockForm::showBubbleMessage (const String& text, Component& target) addChildComponent (bubble.get()); AttributedString attString; - attString.append (text, FontOptions (16.0f)); + attString.append (text, withDefaultMetrics (FontOptions (16.0f))); bubble->showAt (getLocalArea (&target, target.getLocalBounds()), attString, 500, // numMillisecondsBeforeRemoving