diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index eed977edfe..583358bea4 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -155,27 +155,40 @@ void Typeface::setTypefaceCacheSize (int numFontsToCache) class Font::SharedFontInternal : public SingleThreadedReferenceCountedObject { public: - SharedFontInternal (const String& typefaceStyle_, const float height_) noexcept + SharedFontInternal() noexcept + : typefaceName (Font::getDefaultSansSerifFontName()), + typefaceStyle (Font::getDefaultStyle()), + height (FontValues::defaultFontHeight), + horizontalScale (1.0f), + kerning (0), + ascent (0), + underline (false), + typeface (TypefaceCache::getInstance()->getDefaultTypeface()) + { + } + + SharedFontInternal (const String& typefaceStyle_, const float height_, + const bool underline_) noexcept : typefaceName (Font::getDefaultSansSerifFontName()), typefaceStyle (typefaceStyle_), height (height_), horizontalScale (1.0f), kerning (0), ascent (0), - underline (false), - typeface (typefaceStyle_ == Font::getDefaultStyle() - ? TypefaceCache::getInstance()->getDefaultTypeface() : nullptr) + underline (underline_), + typeface (nullptr) { } - SharedFontInternal (const String& typefaceName_, const String& typefaceStyle_, const float height_) noexcept + SharedFontInternal (const String& typefaceName_, const String& typefaceStyle_, + const float height_, const bool underline_) noexcept : typefaceName (typefaceName_), typefaceStyle (typefaceStyle_), height (height_), horizontalScale (1.0f), kerning (0), ascent (0), - underline (false), + underline (underline_), typeface (nullptr) { if (typefaceName.isEmpty()) @@ -225,32 +238,32 @@ public: //============================================================================== Font::Font() - : font (new SharedFontInternal (Font::getDefaultStyle(), FontValues::defaultFontHeight)) + : font (new SharedFontInternal()) { } Font::Font (const float fontHeight, const int styleFlags) - : font (new SharedFontInternal (Font::getDefaultStyle(), FontValues::limitFontHeight (fontHeight))) + : font (new SharedFontInternal (FontStyleHelpers::getStyleName (styleFlags), + FontValues::limitFontHeight (fontHeight), + (styleFlags & underlined) != 0)) { - setStyleFlags (styleFlags); } Font::Font (const String& typefaceName, const float fontHeight, const int styleFlags) : font (new SharedFontInternal (typefaceName, - FontStyleHelpers::getStyleName ((styleFlags & bold) != 0, - (styleFlags & italic) != 0), - FontValues::limitFontHeight (fontHeight))) + FontStyleHelpers::getStyleName (styleFlags), + FontValues::limitFontHeight (fontHeight), + (styleFlags & underlined) != 0)) { - setStyleFlags (styleFlags); } Font::Font (const String& typefaceStyle, float fontHeight) - : font (new SharedFontInternal (typefaceStyle, FontValues::limitFontHeight (fontHeight))) + : font (new SharedFontInternal (typefaceStyle, FontValues::limitFontHeight (fontHeight), false)) { } Font::Font (const String& typefaceName, const String& typefaceStyle, float fontHeight) - : font (new SharedFontInternal (typefaceName, typefaceStyle, FontValues::limitFontHeight (fontHeight))) + : font (new SharedFontInternal (typefaceName, typefaceStyle, FontValues::limitFontHeight (fontHeight), false)) { } @@ -463,8 +476,7 @@ void Font::setStyleFlags (const int newFlags) if (getStyleFlags() != newFlags) { dupeInternalIfShared(); - font->typefaceStyle = FontStyleHelpers::getStyleName ((newFlags & bold) != 0, - (newFlags & italic) != 0); + font->typefaceStyle = FontStyleHelpers::getStyleName (newFlags); font->underline = (newFlags & underlined) != 0; font->typeface = nullptr; font->ascent = 0; @@ -550,15 +562,8 @@ void Font::setExtraKerningFactor (const float extraKerning) Font Font::boldened() const { return withStyle (getStyleFlags() | bold); } Font Font::italicised() const { return withStyle (getStyleFlags() | italic); } -bool Font::isBold() const noexcept -{ - return FontStyleHelpers::isBold (font->typefaceStyle); -} - -bool Font::isItalic() const noexcept -{ - return FontStyleHelpers::isItalic (font->typefaceStyle); -} +bool Font::isBold() const noexcept { return FontStyleHelpers::isBold (font->typefaceStyle); } +bool Font::isItalic() const noexcept { return FontStyleHelpers::isItalic (font->typefaceStyle); } void Font::setBold (const bool shouldBeBold) { diff --git a/modules/juce_graphics/fonts/juce_Typeface.cpp b/modules/juce_graphics/fonts/juce_Typeface.cpp index 8a41c85d7a..cd2b09bebf 100644 --- a/modules/juce_graphics/fonts/juce_Typeface.cpp +++ b/modules/juce_graphics/fonts/juce_Typeface.cpp @@ -34,6 +34,12 @@ namespace FontStyleHelpers return "Regular"; } + static const char* getStyleName (const int styleFlags) noexcept + { + return getStyleName ((styleFlags & Font::bold) != 0, + (styleFlags & Font::italic) != 0); + } + static bool isBold (const String& style) noexcept { return style.containsWholeWordIgnoreCase ("Bold"); diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index ad7ce03070..87d6a52c92 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -1312,9 +1312,7 @@ public: void paint (Graphics& g) { - Font f (getLookAndFeel().getPopupMenuFont()); - f.setBold (true); - g.setFont (f); + g.setFont (getLookAndFeel().getPopupMenuFont().boldened()); g.setColour (findColour (PopupMenu::headerTextColourId)); g.drawFittedText (getName(), diff --git a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp index 28daf2f556..598a7c884b 100644 --- a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp @@ -392,7 +392,7 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize) int iconSpace = 0; AttributedString attributedText; - attributedText.append (getName(), Font (font.getHeight() * 1.1f, Font::bold)); + attributedText.append (getName(), font.withHeight (font.getHeight() * 1.1f).boldened()); if (text.isNotEmpty()) attributedText.append ("\n\n" + text, font);