diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index a73cf4ed3c..cc69e2635e 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -2,6 +2,36 @@ # develop +## Change + +Font::getStringWidth and Font::getStringWidthFloat have been deprecated. +Font::getGlyphPositions has been removed. + +**Possible Issues** + +Code that uses these functions will raise warnings at compile time, or fail +to build. + +**Workaround** + +Use GlyphArrangement::getStringWidth or TextLayout::getStringWidth to find the +width of a string taking font-fallback and shaping into account. + +To find individual glyph positions, lay out the string using GlyphArrangement +or TextLayout, then use the positions provided by +GlyphArrangement::PositionedGlyph and/or TextLayout::Glyph. + +**Rationale** + +The results of the old Font member functions computed their results assuming +that ligatures and other font features would not be used when rendering the +string. The functions would also substitute missing characters with the Font's +notdef/tofu glyph instead of using a fallback font. + +Using GlyphArrangement or TextLayout will use a sophisticated text shaping +algorithm to lay out the string, with support for font fallback. + + ## Change The constructors of the WebSliderRelay, WebToggleButtonRelay and diff --git a/examples/GUI/AnimationEasingDemo.h b/examples/GUI/AnimationEasingDemo.h index c88af9ddf4..42a75366fa 100644 --- a/examples/GUI/AnimationEasingDemo.h +++ b/examples/GUI/AnimationEasingDemo.h @@ -157,7 +157,8 @@ private: void resized() final { auto bounds = getLocalBounds(); - const auto labelWidth = label.getFont().getStringWidth (label.getText()) + AnimationEasingDemoConstants::largeGapSize; + const auto labelWidth = GlyphArrangement::getStringWidthInt (label.getFont(), label.getText()) + + AnimationEasingDemoConstants::largeGapSize; label.setBounds (bounds.removeFromLeft (labelWidth)); slider.setBounds (bounds); } diff --git a/examples/GUI/WidgetsDemo.h b/examples/GUI/WidgetsDemo.h index 1565c62b1d..f1f477961b 100644 --- a/examples/GUI/WidgetsDemo.h +++ b/examples/GUI/WidgetsDemo.h @@ -1117,7 +1117,7 @@ public: { auto text = rowElement->getStringAttribute (getAttributeNameForColumnId (columnId)); - widest = jmax (widest, font.getStringWidth (text)); + widest = jmax (widest, GlyphArrangement::getStringWidthInt (font, text)); } } diff --git a/extras/AudioPluginHost/Source/UI/GraphEditorPanel.cpp b/extras/AudioPluginHost/Source/UI/GraphEditorPanel.cpp index 96f1111023..f81bd98aec 100644 --- a/extras/AudioPluginHost/Source/UI/GraphEditorPanel.cpp +++ b/extras/AudioPluginHost/Source/UI/GraphEditorPanel.cpp @@ -361,7 +361,7 @@ struct GraphEditorPanel::PluginComponent final : public Component, w = jmax (w, (jmax (numIns, numOuts) + 1) * 20); - const int textWidth = font.getStringWidth (processor.getName()); + const auto textWidth = GlyphArrangement::getStringWidthInt (font, processor.getName()); w = jmax (w, 16 + jmin (textWidth, 300)); if (textWidth > 300) h = 100; diff --git a/extras/Projucer/Source/Application/Windows/jucer_EditorColourSchemeWindowComponent.h b/extras/Projucer/Source/Application/Windows/jucer_EditorColourSchemeWindowComponent.h index 76488e7ce3..425b2df3b5 100644 --- a/extras/Projucer/Source/Application/Windows/jucer_EditorColourSchemeWindowComponent.h +++ b/extras/Projucer/Source/Application/Windows/jucer_EditorColourSchemeWindowComponent.h @@ -118,12 +118,12 @@ private: { const Font font = FontOptions (name, 20.0f, Font::plain); - const auto width = font.getStringWidth ("...."); + const auto width = GlyphArrangement::getStringWidthInt (font, "...."); - return width == font.getStringWidth ("WWWW") - && width == font.getStringWidth ("0000") - && width == font.getStringWidth ("1111") - && width == font.getStringWidth ("iiii"); + return width == GlyphArrangement::getStringWidthInt (font, "WWWW") + && width == GlyphArrangement::getStringWidthInt (font, "0000") + && width == GlyphArrangement::getStringWidthInt (font, "1111") + && width == GlyphArrangement::getStringWidthInt (font, "iiii"); } StringArray fontsToScan, fontsFound; diff --git a/extras/Projucer/Source/Project/UI/jucer_ContentViewComponents.h b/extras/Projucer/Source/Project/UI/jucer_ContentViewComponents.h index f2e2e64cc1..8201ac4b19 100644 --- a/extras/Projucer/Source/Project/UI/jucer_ContentViewComponents.h +++ b/extras/Projucer/Source/Project/UI/jucer_ContentViewComponents.h @@ -206,7 +206,7 @@ public: { info = infoToDisplay; - auto stringWidth = roundToInt (Font (FontOptions (14.0f)).getStringWidthFloat (info)); + auto stringWidth = roundToInt (GlyphArrangement::getStringWidth (FontOptions (14.0f), info)); width = jmin (300, stringWidth); numLines += static_cast (stringWidth / width); @@ -433,7 +433,7 @@ private: return 0; const auto font = ProjucerLookAndFeel::getPropertyComponentFont(); - const auto labelWidth = font.getStringWidthFloat (pp.getName()); + const auto labelWidth = GlyphArrangement::getStringWidth (font, pp.getName()); const auto numLines = (int) (labelWidth / (float) availableTextWidth) + 1; return (int) std::round ((float) numLines * font.getHeight() * 1.1f); } diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index bd74814ba0..2be250479f 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -756,7 +756,11 @@ float Font::getDescentInPoints() const { return getDescent() * getHeightToP int Font::getStringWidth (const String& text) const { + JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996) + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") return (int) std::ceil (getStringWidthFloat (text)); + JUCE_END_IGNORE_WARNINGS_GCC_LIKE + JUCE_END_IGNORE_WARNINGS_MSVC } float Font::getStringWidthFloat (const String& text) const @@ -765,21 +769,6 @@ float Font::getStringWidthFloat (const String& text) const return w + (getHeight() * getHorizontalScale() * getExtraKerningFactor() * (float) text.length()); } -void Font::getGlyphPositions (const String& text, Array& glyphs, Array& xOffsets) const -{ - getTypefacePtr()->getGlyphPositions (getMetricsKind(), text, glyphs, xOffsets, getHeight(), getHorizontalScale()); - - if (auto num = xOffsets.size()) - { - auto scale = getHeight() * getHorizontalScale(); - auto* x = xOffsets.getRawDataPointer(); - - if (! approximatelyEqual (getExtraKerningFactor(), 0.0f)) - for (int i = 0; i < num; ++i) - x[i] += ((float) i * getExtraKerningFactor() * scale); - } -} - void Font::findFonts (Array& destArray) { for (auto& name : findAllTypefaceNames()) diff --git a/modules/juce_graphics/fonts/juce_Font.h b/modules/juce_graphics/fonts/juce_Font.h index aff8f99e67..99b9c2dfcf 100644 --- a/modules/juce_graphics/fonts/juce_Font.h +++ b/modules/juce_graphics/fonts/juce_Font.h @@ -450,21 +450,40 @@ public: //============================================================================== /** Returns the total width of a string as it would be drawn using this font. For a more accurate floating-point result, use getStringWidthFloat(). + + This function does not take font fallback into account. If this font doesn't + include glyphs to represent all characters in the string, then the width + will be computed as though those characters were replaced with the "glyph not + found" character. + + If you are trying to find the amount of space required to display a given string, + you'll get more accurate results by actually measuring the results of whichever + text layout engine (e.g. GlyphArrangement, TextLayout) you'll use when displaying + the string. + + @see TextLayout::getStringWidth(), GlyphArrangement::getStringWidthInt() */ + [[deprecated ("Use GlyphArrangement or TextLayout to compute text layouts")]] int getStringWidth (const String& text) const; /** Returns the total width of a string as it would be drawn using this font. @see getStringWidth + + This function does not take font fallback into account. If this font doesn't + include glyphs to represent all characters in the string, then the width + will be computed as though those characters were replaced with the "glyph not + found" character. + + If you are trying to find the amount of space required to display a given string, + you'll get more accurate results by actually measuring the results of whichever + text layout engine (e.g. GlyphArrangement, TextLayout) you'll use when displaying + the string. + + @see TextLayout::getStringWidth(), GlyphArrangement::getStringWidth() */ + [[deprecated ("Use GlyphArrangement or TextLayout to compute text layouts")]] float getStringWidthFloat (const String& text) const; - /** Returns the series of glyph numbers and their x offsets needed to represent a string. - - An extra x offset is added at the end of the run, to indicate where the right hand - edge of the last character is. - */ - void getGlyphPositions (const String& text, Array& glyphs, Array& xOffsets) const; - //============================================================================== /** Returns the main typeface used by this font. diff --git a/modules/juce_graphics/fonts/juce_GlyphArrangement.h b/modules/juce_graphics/fonts/juce_GlyphArrangement.h index 2bc5dd302c..d8c03e3e05 100644 --- a/modules/juce_graphics/fonts/juce_GlyphArrangement.h +++ b/modules/juce_graphics/fonts/juce_GlyphArrangement.h @@ -310,6 +310,35 @@ public: float x, float y, float width, float height, Justification justification); + /** This convenience function adds text to a GlyphArrangement using the specified font + and returns the bounding box of the text after shaping. + + The returned bounding box is positioned with its origin at the left end of the text's + baseline. + */ + static Rectangle getStringBounds (const Font& font, StringRef text) + { + GlyphArrangement arrangement; + arrangement.addLineOfText (font, text, 0.0f, 0.0f); + return arrangement.getBoundingBox (0, arrangement.getNumGlyphs(), true); + } + + /** This convenience function adds text to a GlyphArrangement using the specified font + and returns the width of the bounding box of the text after shaping. + */ + static float getStringWidth (const Font& font, StringRef text) + { + return getStringBounds (font, text).getWidth(); + } + + /** This convenience function adds text to a GlyphArrangement using the specified font + and returns the width of the bounding box of the text after shaping, rounded up to the + next integer. + */ + static int getStringWidthInt (const Font& font, StringRef text) + { + return (int) std::ceil (getStringWidth (font, text)); + } private: //============================================================================== diff --git a/modules/juce_graphics/fonts/juce_TextLayout.h b/modules/juce_graphics/fonts/juce_TextLayout.h index dcea6d9ec5..aa27ec6f79 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.h +++ b/modules/juce_graphics/fonts/juce_TextLayout.h @@ -265,6 +265,48 @@ public: */ void recalculateSize(); + /** This convenience function adds an AttributedString to a TextLayout + and returns the bounding box of the text after shaping. + + The returned bounding box is positioned with its origin at the left end of the text's + baseline. + */ + static Rectangle getStringBounds (const AttributedString& string) + { + TextLayout layout; + layout.createLayout (string, std::numeric_limits::max()); + return layout.getLine (0).getLineBounds(); + } + + /** This convenience function adds text to a TextLayout using the specified font + and returns the bounding box of the text after shaping. + + The returned bounding box is positioned with its origin at the left end of the text's + baseline. + */ + static Rectangle getStringBounds (const Font& font, StringRef text) + { + AttributedString string; + string.append (text, font); + return getStringBounds (string); + } + + /** This convenience function adds an AttributedString to a TextLayout + and returns the bounding box of the text after shaping. + */ + static float getStringWidth (const AttributedString& string) + { + return getStringBounds (string).getWidth(); + } + + /** This convenience function adds text to a TextLayout using the specified font + and returns the width of the bounding box of the text after shaping. + */ + static float getStringWidth (const Font& font, StringRef text) + { + return getStringBounds (font, text).getWidth(); + } + private: OwnedArray lines; float width, height; diff --git a/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp b/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp index 9f548dcf13..d77175455b 100644 --- a/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp @@ -87,7 +87,7 @@ Font HyperlinkButton::getFontToUse() const void HyperlinkButton::changeWidthToFitText() { - setSize (getFontToUse().getStringWidth (getButtonText()) + 6, getHeight()); + setSize (GlyphArrangement::getStringWidthInt (getFontToUse(), getButtonText()) + 6, getHeight()); } void HyperlinkButton::setJustificationType (Justification newJustification) diff --git a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp index e47823f962..04175c6e5c 100644 --- a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp +++ b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp @@ -1204,7 +1204,7 @@ private: const auto y = optY.value_or (layoutState.getNextStartingPos().getY()); Rectangle bounds (x, y - font.getAscent(), - font.getStringWidthFloat (text), font.getHeight()); + GlyphArrangement::getStringWidth (font, text), font.getHeight()); if (anchorStr == "middle") bounds.setX (bounds.getX() - bounds.getWidth() / 2.0f); else if (anchorStr == "end") bounds.setX (bounds.getX() - bounds.getWidth()); diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index 142ffa4704..909ead8057 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -265,7 +265,7 @@ Font LookAndFeel_V2::getTextButtonFont (TextButton&, int buttonHeight) int LookAndFeel_V2::getTextButtonWidthToFitText (TextButton& b, int buttonHeight) { - return getTextButtonFont (b, buttonHeight).getStringWidth (b.getButtonText()) + buttonHeight; + return GlyphArrangement::getStringWidthInt (getTextButtonFont (b, buttonHeight), b.getButtonText()) + buttonHeight; } void LookAndFeel_V2::drawButtonText (Graphics& g, TextButton& button, @@ -361,7 +361,7 @@ void LookAndFeel_V2::changeToggleButtonWidthToFitText (ToggleButton& button) Font font (withDefaultMetrics (FontOptions { fontSize })); - button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 9, + button.setSize (GlyphArrangement::getStringWidthInt (font, button.getButtonText()) + roundToInt (tickWidth) + 9, button.getHeight()); } @@ -883,7 +883,7 @@ void LookAndFeel_V2::getIdealPopupMenuItemSize (const String& text, const bool i font.setHeight ((float) standardMenuItemHeight / 1.3f); idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f); - idealWidth = font.getStringWidth (text) + idealHeight * 2; + idealWidth = GlyphArrangement::getStringWidthInt (font, text) + idealHeight * 2; } } @@ -1117,8 +1117,7 @@ Font LookAndFeel_V2::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex* int LookAndFeel_V2::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText) { - return getMenuBarFont (menuBar, itemIndex, itemText) - .getStringWidth (itemText) + menuBar.getHeight(); + return GlyphArrangement::getStringWidthInt (getMenuBarFont (menuBar, itemIndex, itemText), itemText) + menuBar.getHeight(); } void LookAndFeel_V2::drawMenuBarItem (Graphics& g, int width, int height, @@ -1887,7 +1886,7 @@ void LookAndFeel_V2::drawDocumentWindowTitleBar (DocumentWindow& window, Graphic Font font (withDefaultMetrics (FontOptions { (float) h * 0.65f, Font::bold })); g.setFont (font); - int textW = font.getStringWidth (window.getName()); + int textW = GlyphArrangement::getStringWidthInt (font, window.getName()); int iconW = 0; int iconH = 0; @@ -2137,7 +2136,7 @@ void LookAndFeel_V2::drawGroupComponentOutline (Graphics& g, int width, int heig auto textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), - (float) f.getStringWidth (text) + textEdgeGap * 2.0f); + (float) GlyphArrangement::getStringWidthInt (f, text) + textEdgeGap * 2.0f); auto textX = cs + textEdgeGap; if (position.testFlags (Justification::horizontallyCentred)) @@ -2190,8 +2189,9 @@ int LookAndFeel_V2::getTabButtonSpaceAroundImage() int LookAndFeel_V2::getTabButtonBestWidth (TabBarButton& button, int tabDepth) { - int width = Font (withDefaultMetrics (FontOptions { (float) tabDepth * 0.6f })).getStringWidth (button.getButtonText().trim()) - + getTabButtonOverlap (tabDepth) * 2; + int width = GlyphArrangement::getStringWidthInt (withDefaultMetrics (FontOptions { (float) tabDepth * 0.6f }), + button.getButtonText().trim()) + + getTabButtonOverlap (tabDepth) * 2; if (auto* extraComponent = button.getExtraComponent()) width += button.getTabbedButtonBar().isVertical() ? extraComponent->getHeight() diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp index 9eed31d5fa..a9ed7700fb 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp @@ -247,7 +247,7 @@ void LookAndFeel_V4::drawDocumentWindowTitleBar (DocumentWindow& window, Graphic Font font (withDefaultMetrics (FontOptions { (float) h * 0.65f, Font::plain })); g.setFont (font); - auto textW = font.getStringWidth (window.getName()); + auto textW = GlyphArrangement::getStringWidthInt (font, window.getName()); auto iconW = 0; auto iconH = 0; @@ -386,7 +386,7 @@ void LookAndFeel_V4::changeToggleButtonWidthToFitText (ToggleButton& button) Font font (withDefaultMetrics (FontOptions { fontSize })); - button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 14, button.getHeight()); + button.setSize (GlyphArrangement::getStringWidthInt (font, button.getButtonText()) + roundToInt (tickWidth) + 14, button.getHeight()); } //============================================================================== @@ -882,7 +882,7 @@ void LookAndFeel_V4::getIdealPopupMenuItemSize (const String& text, const bool i font.setHeight ((float) standardMenuItemHeight / 1.3f); idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f); - idealWidth = font.getStringWidth (text) + idealHeight * 2; + idealWidth = GlyphArrangement::getStringWidthInt (font, text) + idealHeight * 2; } } diff --git a/modules/juce_gui_basics/widgets/juce_Label.cpp b/modules/juce_gui_basics/widgets/juce_Label.cpp index 1db52d49c1..a8b4d24540 100644 --- a/modules/juce_gui_basics/widgets/juce_Label.cpp +++ b/modules/juce_gui_basics/widgets/juce_Label.cpp @@ -174,7 +174,7 @@ void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bo if (leftOfOwnerComp) { - auto width = jmin (roundToInt (f.getStringWidthFloat (textValue.toString()) + 0.5f) + auto width = jmin (roundToInt (GlyphArrangement::getStringWidth (f, textValue.toString()) + 0.5f) + borderSize.getLeftAndRight(), component.getX()); diff --git a/modules/juce_gui_basics/widgets/juce_Slider.cpp b/modules/juce_gui_basics/widgets/juce_Slider.cpp index d28d5bbb82..e567414288 100644 --- a/modules/juce_gui_basics/widgets/juce_Slider.cpp +++ b/modules/juce_gui_basics/widgets/juce_Slider.cpp @@ -1389,7 +1389,7 @@ public: void getContentSize (int& w, int& h) override { - w = font.getStringWidth (text) + 18; + w = GlyphArrangement::getStringWidthInt (font, text) + 18; h = (int) (font.getHeight() * 1.6f); } diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index e288039b1f..41063ce336 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -104,7 +104,7 @@ public: { lastAtom.atomText += first.atomText; lastAtom.numChars = (uint16) (lastAtom.numChars + first.numChars); - lastAtom.width = font.getStringWidthFloat (lastAtom.getText (passwordChar)); + lastAtom.width = GlyphArrangement::getStringWidth (font, lastAtom.getText (passwordChar)); ++i; } } @@ -143,13 +143,13 @@ public: { TextAtom secondAtom; secondAtom.atomText = atom.atomText.substring (indexToBreakAt - index); - secondAtom.width = font.getStringWidthFloat (secondAtom.getText (passwordChar)); + secondAtom.width = GlyphArrangement::getStringWidth (font, secondAtom.getText (passwordChar)); secondAtom.numChars = (uint16) secondAtom.atomText.length(); section2->atoms.add (secondAtom); atom.atomText = atom.atomText.substring (0, indexToBreakAt - index); - atom.width = font.getStringWidthFloat (atom.getText (passwordChar)); + atom.width = GlyphArrangement::getStringWidth (font, atom.getText (passwordChar)); atom.numChars = (uint16) (indexToBreakAt - index); for (int j = i + 1; j < atoms.size(); ++j) @@ -212,7 +212,7 @@ public: passwordChar = passwordCharToUse; for (auto& atom : atoms) - atom.width = newFont.getStringWidthFloat (atom.getText (passwordChar)); + atom.width = GlyphArrangement::getStringWidth (newFont, atom.getText (passwordChar)); } } @@ -272,7 +272,7 @@ private: TextAtom atom; atom.atomText = String (start, numChars); - atom.width = (atom.isNewLine() ? 0.0f : font.getStringWidthFloat (atom.getText (passwordChar))); + atom.width = (atom.isNewLine() ? 0.0f : GlyphArrangement::getStringWidth (font, atom.getText (passwordChar))); atom.numChars = (uint16) numChars; atoms.add (atom); } diff --git a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp index 282e3c0057..557e5ba216 100644 --- a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp @@ -273,7 +273,7 @@ public: setFont (font); setText (message, false); - bestWidth = 2 * (int) std::sqrt (font.getHeight() * (float) font.getStringWidth (message)); + bestWidth = 2 * (int) std::sqrt (font.getHeight() * GlyphArrangement::getStringWidth (font, message)); } void updateLayout (const int width) @@ -386,8 +386,8 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize) auto& lf = getLookAndFeel(); auto messageFont (lf.getAlertWindowMessageFont()); - auto wid = jmax (messageFont.getStringWidth (text), - messageFont.getStringWidth (getName())); + auto wid = jmax (GlyphArrangement::getStringWidth (messageFont, text), + GlyphArrangement::getStringWidth (messageFont, getName())); auto sw = (int) std::sqrt (messageFont.getHeight() * (float) wid); auto w = jmin (300 + sw * 2, (int) ((float) getParentWidth() * 0.7f)); diff --git a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp index 6297ddd9d2..4a83998c50 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp +++ b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp @@ -1696,7 +1696,13 @@ int CodeEditorComponent::columnToIndex (int lineNum, int column) const noexcept void CodeEditorComponent::setFont (const Font& newFont) { font = newFont; + + JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996) + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") charWidth = font.getStringWidthFloat ("0"); + JUCE_END_IGNORE_WARNINGS_GCC_LIKE + JUCE_END_IGNORE_WARNINGS_MSVC + lineHeight = roundToInt (font.getHeight()); resized(); } diff --git a/modules/juce_gui_extra/misc/juce_ColourSelector.cpp b/modules/juce_gui_extra/misc/juce_ColourSelector.cpp index c83283c1f8..970c9cbc86 100644 --- a/modules/juce_gui_extra/misc/juce_ColourSelector.cpp +++ b/modules/juce_gui_extra/misc/juce_ColourSelector.cpp @@ -352,7 +352,7 @@ public: colourLabel.setColour (Label::textWhenEditingColourId, textColour); colourLabel.setText (currentColour.toDisplayString ((owner.flags & showAlphaChannel) != 0), dontSendNotification); - labelWidth = labelFont.getStringWidth (colourLabel.getText()); + labelWidth = GlyphArrangement::getStringWidthInt (labelFont, colourLabel.getText()); repaint(); } diff --git a/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp b/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp index 9a6c88cc25..17257008f8 100644 --- a/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp +++ b/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp @@ -95,9 +95,14 @@ public: void fitToContent (const int h) noexcept { if (keyNum < 0) + { setSize (h, h); + } else - setSize (jlimit (h * 4, h * 8, 6 + Font (withDefaultMetrics (FontOptions { (float) h * 0.6f })).getStringWidth (getName())), h); + { + const auto idealWidth = GlyphArrangement::getStringWidthInt (withDefaultMetrics (FontOptions { (float) h * 0.6f }), getName()); + setSize (jlimit (h * 4, h * 8, 6 + idealWidth), h); + } } //==============================================================================