diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index a45209f594..68f117907e 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -2,6 +2,35 @@ # Version 8.0.0 +## Change + +Signatures of several Typeface member functions have been updated to accept a +new TypefaceMetricsKind argument. The getAscent(), getDescent(), and +getHeightToPointsFactor() members have been replaced by getMetrics(), which +returns the same metrics information all at once. + +**Possible Issues** + +Code that calls any of the affected functions will fail to compile. + +**Workaround** + +Specify the kind of metrics you require when calling Typeface member functions. +Call getMetrics() instead of the old individual getters for metrics. + +**Rationale** + +Until now, the same font data could produce different results from +Typeface::getAscent() et al. depending on the platform. The updated interfaces +allow the user to choose between the old-style non-portable metrics (to avoid +layout changes in existing projects), and portable metrics (more suitable for +new or cross-platform projects). +Most users will fetch metrics from Font objects rather than from the Typeface. +Font will continue to return non-portable metrics when constructed using the +existing (deprecated) constructors. Portable metrics can be enabled by +switching to the new Font constructor that takes a FontOptions argument. + + ## Change Typeface::getOutlineForGlyph now returns void instead of bool. diff --git a/examples/Audio/AudioPlaybackDemo.h b/examples/Audio/AudioPlaybackDemo.h index c6c312a2ae..c31e311efa 100644 --- a/examples/Audio/AudioPlaybackDemo.h +++ b/examples/Audio/AudioPlaybackDemo.h @@ -267,7 +267,7 @@ public: AudioPlaybackDemo() { addAndMakeVisible (zoomLabel); - zoomLabel.setFont (Font (15.00f, Font::plain)); + zoomLabel.setFont (FontOptions (15.00f, Font::plain)); zoomLabel.setJustificationType (Justification::centredRight); zoomLabel.setEditable (false, false, false); zoomLabel.setColour (TextEditor::textColourId, Colours::black); @@ -289,7 +289,7 @@ public: fileTreeComp.addListener (this); addAndMakeVisible (explanation); - explanation.setFont (Font (14.00f, Font::plain)); + explanation.setFont (FontOptions (14.00f, Font::plain)); explanation.setJustificationType (Justification::bottomRight); explanation.setEditable (false, false, false); explanation.setColour (TextEditor::textColourId, Colours::black); diff --git a/examples/Audio/AudioRecordingDemo.h b/examples/Audio/AudioRecordingDemo.h index 10192a6db7..6782616e04 100644 --- a/examples/Audio/AudioRecordingDemo.h +++ b/examples/Audio/AudioRecordingDemo.h @@ -243,7 +243,7 @@ public: addAndMakeVisible (liveAudioScroller); addAndMakeVisible (explanationLabel); - explanationLabel.setFont (Font (15.0f, Font::plain)); + explanationLabel.setFont (FontOptions (15.0f, Font::plain)); explanationLabel.setJustificationType (Justification::topLeft); explanationLabel.setEditable (false, false, false); explanationLabel.setColour (TextEditor::textColourId, Colours::black); diff --git a/examples/Audio/CapabilityInquiryDemo.h b/examples/Audio/CapabilityInquiryDemo.h index 21bccc8b09..42048e08a1 100644 --- a/examples/Audio/CapabilityInquiryDemo.h +++ b/examples/Audio/CapabilityInquiryDemo.h @@ -907,7 +907,7 @@ class MonospaceEditor : public TextEditor public: MonospaceEditor() { - setFont (Font { Font::getDefaultMonospacedFontName(), 12, 0 }); + setFont (FontOptions { Font::getDefaultMonospacedFontName(), 12, 0 }); } void onCommit (std::function fn) @@ -926,7 +926,7 @@ class MonospaceLabel : public Label public: MonospaceLabel() { - setFont (Font { Font::getDefaultMonospacedFontName(), 12, 0 }); + setFont (FontOptions { Font::getDefaultMonospacedFontName(), 12, 0 }); setMinimumHorizontalScale (1.0f); setInterceptsMouseClicks (false, false); } @@ -1531,7 +1531,7 @@ public: const auto groupWidth = 100; GlyphArrangement groupArrangement; - groupArrangement.addJustifiedText ({}, + groupArrangement.addJustifiedText (FontOptions{}, "Group", 0, 0, @@ -1571,7 +1571,7 @@ public: const auto bounds = buttons[(size_t) i].getBounds(); GlyphArrangement channelArrangement; - channelArrangement.addJustifiedText ({}, + channelArrangement.addJustifiedText (FontOptions{}, i < 16 ? String (i + 1) : "All", 0, 0, diff --git a/examples/Audio/MidiDemo.h b/examples/Audio/MidiDemo.h index f00986c732..854ed086b1 100644 --- a/examples/Audio/MidiDemo.h +++ b/examples/Audio/MidiDemo.h @@ -449,7 +449,7 @@ private: //============================================================================== void addLabelAndSetStyle (Label& label) { - label.setFont (Font (15.00f, Font::plain)); + label.setFont (FontOptions (15.00f, Font::plain)); label.setJustificationType (Justification::centredLeft); label.setEditable (false, false, false); label.setColour (TextEditor::textColourId, Colours::black); diff --git a/examples/CMake/GuiApp/MainComponent.cpp b/examples/CMake/GuiApp/MainComponent.cpp index 82fee61a18..b3a1b9acc7 100644 --- a/examples/CMake/GuiApp/MainComponent.cpp +++ b/examples/CMake/GuiApp/MainComponent.cpp @@ -12,7 +12,7 @@ void MainComponent::paint (juce::Graphics& g) // (Our component is opaque, so we must completely fill the background with a solid colour) g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId)); - g.setFont (juce::Font (16.0f)); + g.setFont (juce::FontOptions (16.0f)); g.setColour (juce::Colours::white); g.drawText ("Hello World!", getLocalBounds(), juce::Justification::centred, true); } diff --git a/examples/DemoRunner/Source/UI/SettingsContent.h b/examples/DemoRunner/Source/UI/SettingsContent.h index 4db5c72ee7..2ae54a727c 100644 --- a/examples/DemoRunner/Source/UI/SettingsContent.h +++ b/examples/DemoRunner/Source/UI/SettingsContent.h @@ -74,7 +74,7 @@ private: mainComponent (comp) { addAndMakeVisible (titleLabel); - titleLabel.setFont (titleLabelFontHeight); + titleLabel.setFont (FontOptions { titleLabelFontHeight }); addLookAndFeels(); @@ -184,7 +184,7 @@ private: : deviceSelectorComp (getSharedAudioDeviceManager(), 0, 256, 0, 256, true, true, true, false) { addAndMakeVisible (titleLabel); - titleLabel.setFont (titleLabelFontHeight); + titleLabel.setFont (FontOptions { titleLabelFontHeight }); addAndMakeVisible (deviceSelectorComp); deviceSelectorComp.setItemHeight (itemHeight); diff --git a/examples/GUI/AnimationEasingDemo.h b/examples/GUI/AnimationEasingDemo.h index 2efd95bef4..25d0301f05 100644 --- a/examples/GUI/AnimationEasingDemo.h +++ b/examples/GUI/AnimationEasingDemo.h @@ -227,7 +227,7 @@ class CubicBezierSettingsComponent final : public Component public: CubicBezierSettingsComponent() { - textEditor.setFont (Font (18.0f)); + textEditor.setFont (FontOptions (18.0f)); textEditor.setColour (TextEditor::ColourIds::backgroundColourId, {}); textEditor.setColour (TextEditor::ColourIds::highlightColourId, {}); textEditor.setColour (TextEditor::ColourIds::outlineColourId, {}); diff --git a/examples/GUI/FontsDemo.h b/examples/GUI/FontsDemo.h index ce0a991685..4b4fa6c68f 100644 --- a/examples/GUI/FontsDemo.h +++ b/examples/GUI/FontsDemo.h @@ -218,20 +218,20 @@ public: if (rowIsSelected) g.fillAll (Colours::lightblue); - auto font = fonts[rowNumber]; + auto font = getFont (rowNumber); AttributedString s; s.setWordWrap (AttributedString::none); s.setJustification (Justification::centredLeft); s.append (getNameForRow (rowNumber), font.withHeight ((float) height * 0.7f), Colours::black); - s.append (" " + font.getTypefaceName(), Font ((float) height * 0.5f, Font::italic), Colours::grey); + s.append (" " + font.getTypefaceName(), FontOptions ((float) height * 0.5f, Font::italic), Colours::grey); s.draw (g, Rectangle (width, height).expanded (-4, 50).toFloat()); } String getNameForRow (int rowNumber) override { - return fonts[rowNumber].getTypefaceName(); + return getFont (rowNumber).getTypefaceName(); } void selectedRowsChanged (int /*lastRowselected*/) override @@ -240,6 +240,11 @@ public: } private: + Font getFont (int rowNumber) const + { + return isPositiveAndBelow (rowNumber, fonts.size()) ? fonts.getUnchecked (rowNumber) : FontOptions{}; + } + Array fonts; StringArray currentStyleList; @@ -317,7 +322,7 @@ private: auto italic = italicToggle.getToggleState(); auto useStyle = ! (bold || italic); - auto font = fonts[listBox.getSelectedRow()]; + auto font = getFont (listBox.getSelectedRow()); font = font.withPointHeight ((float) heightSlider .getValue()) .withExtraKerningFactor ((float) kerningSlider.getValue()) diff --git a/examples/GUI/GraphicsDemo.h b/examples/GUI/GraphicsDemo.h index c97de5391b..3aed2eaca9 100644 --- a/examples/GUI/GraphicsDemo.h +++ b/examples/GUI/GraphicsDemo.h @@ -124,7 +124,7 @@ public: : Component (name), controls (cc) { - displayFont = Font (Font::getDefaultMonospacedFontName(), 12.0f, Font::bold); + displayFont = FontOptions (Font::getDefaultMonospacedFontName(), 12.0f, Font::bold); } AffineTransform getTransform() @@ -278,7 +278,7 @@ public: double lastRenderStartTime = 0.0, averageTimeMs = 0.0, averageActualFPS = 0.0; Image clipImage; - Font displayFont; + Font displayFont { FontOptions{} }; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphicsDemoBase) }; @@ -458,7 +458,7 @@ public: GlyphsDemo (ControllersComponent& cc) : GraphicsDemoBase (cc, "Glyphs") { - glyphs.addFittedText ({ 20.0f }, "The Quick Brown Fox Jumps Over The Lazy Dog", + glyphs.addFittedText (FontOptions { 20.0f }, "The Quick Brown Fox Jumps Over The Lazy Dog", -120, -50, 240, 100, Justification::centred, 2, 1.0f); } diff --git a/examples/GUI/HelloWorldDemo.h b/examples/GUI/HelloWorldDemo.h index adb57ed016..e195662429 100644 --- a/examples/GUI/HelloWorldDemo.h +++ b/examples/GUI/HelloWorldDemo.h @@ -60,7 +60,7 @@ public: { addAndMakeVisible (helloWorldLabel); - helloWorldLabel.setFont (Font (40.00f, Font::bold)); + helloWorldLabel.setFont (FontOptions (40.00f, Font::bold)); helloWorldLabel.setJustificationType (Justification::centred); helloWorldLabel.setEditable (false, false, false); helloWorldLabel.setColour (Label::textColourId, Colours::black); diff --git a/examples/GUI/MenusDemo.h b/examples/GUI/MenusDemo.h index ba5e9f34ed..eb2650024d 100644 --- a/examples/GUI/MenusDemo.h +++ b/examples/GUI/MenusDemo.h @@ -106,7 +106,7 @@ private: burgerButton.setBounds (r.removeFromRight (40).withSizeKeepingCentre (20, 20)); - titleLabel.setFont (Font ((float) getHeight() * 0.5f, Font::plain)); + titleLabel.setFont (FontOptions ((float) getHeight() * 0.5f, Font::plain)); titleLabel.setBounds (r); } diff --git a/examples/GUI/OpenGLDemo.h b/examples/GUI/OpenGLDemo.h index cba6b6eb81..9d222136e5 100644 --- a/examples/GUI/OpenGLDemo.h +++ b/examples/GUI/OpenGLDemo.h @@ -997,7 +997,7 @@ private: { addAndMakeVisible (statusLabel); statusLabel.setJustificationType (Justification::topLeft); - statusLabel.setFont (Font (14.0f)); + statusLabel.setFont (FontOptions (14.0f)); addAndMakeVisible (sizeSlider); sizeSlider.setRange (0.0, 1.0, 0.001); diff --git a/examples/GUI/OpenGLDemo2D.h b/examples/GUI/OpenGLDemo2D.h index ad6ab51ca9..3026c4ee0f 100644 --- a/examples/GUI/OpenGLDemo2D.h +++ b/examples/GUI/OpenGLDemo2D.h @@ -69,7 +69,7 @@ public: addAndMakeVisible (statusLabel); statusLabel.setJustificationType (Justification::topLeft); - statusLabel.setFont (Font (14.0f)); + statusLabel.setFont (FontOptions (14.0f)); auto presets = getPresets(); diff --git a/examples/GUI/WidgetsDemo.h b/examples/GUI/WidgetsDemo.h index ee16549494..8969688fee 100644 --- a/examples/GUI/WidgetsDemo.h +++ b/examples/GUI/WidgetsDemo.h @@ -1156,7 +1156,7 @@ public: private: TableListBox table; // the table component itself - Font font { 14.0f }; + Font font { FontOptions { 14.0f } }; std::unique_ptr demoData; // This is the XML document loaded from the embedded file "demo table data.xml" XmlElement* columnList = nullptr; // A pointer to the sub-node of demoData that contains the list of columns diff --git a/examples/Plugins/ARAPluginDemo.h b/examples/Plugins/ARAPluginDemo.h index bed4787444..d146801740 100644 --- a/examples/Plugins/ARAPluginDemo.h +++ b/examples/Plugins/ARAPluginDemo.h @@ -1049,7 +1049,7 @@ public: const auto rulerHeight = bounds.getHeight() / 3; g.drawRect (drawBounds.getX(), rulerHeight, drawBounds.getRight(), rulerHeight); - g.setFont (Font (12.0f)); + g.setFont (FontOptions (12.0f)); const int lightLineWidth = 1; const int heavyLineWidth = 3; @@ -1455,12 +1455,12 @@ public: } else { - g.setFont (Font (12.0f)); + g.setFont (FontOptions (12.0f)); g.drawText ("Audio Access Disabled", getLocalBounds(), Justification::centred); } g.setColour (Colours::white.withMultipliedAlpha (0.9f)); - g.setFont (Font (12.0f)); + g.setFont (FontOptions (12.0f)); g.drawText (convertOptionalARAString (playbackRegion.getEffectiveName()), getLocalBounds(), Justification::topLeft); @@ -2325,7 +2325,7 @@ public: if (! isARAEditorView()) { g.setColour (Colours::white); - g.setFont (15.0f); + g.setFont (FontOptions (15.0f)); g.drawFittedText ("ARA host isn't detected. This plugin only supports ARA mode", getLocalBounds(), Justification::centred, diff --git a/examples/Plugins/AudioPluginDemo.h b/examples/Plugins/AudioPluginDemo.h index 1ee98d34ab..f295d0cbea 100644 --- a/examples/Plugins/AudioPluginDemo.h +++ b/examples/Plugins/AudioPluginDemo.h @@ -386,17 +386,17 @@ private: // add some labels for the sliders.. gainLabel.attachToComponent (&gainSlider, false); - gainLabel.setFont (Font (11.0f)); + gainLabel.setFont (FontOptions (11.0f)); delayLabel.attachToComponent (&delaySlider, false); - delayLabel.setFont (Font (11.0f)); + delayLabel.setFont (FontOptions (11.0f)); // add the midi keyboard component.. addAndMakeVisible (midiKeyboard); // add a label that will display the current timecode and status.. addAndMakeVisible (timecodeDisplayLabel); - timecodeDisplayLabel.setFont (Font (Font::getDefaultMonospacedFontName(), 15.0f, Font::plain)); + timecodeDisplayLabel.setFont (FontOptions (Font::getDefaultMonospacedFontName(), 15.0f, Font::plain)); // set resize limits for this plug-in setResizeLimits (400, 200, 1024, 700); diff --git a/examples/Plugins/DSPModulePluginDemo.h b/examples/Plugins/DSPModulePluginDemo.h index 2cfd81c38e..0d42665df8 100644 --- a/examples/Plugins/DSPModulePluginDemo.h +++ b/examples/Plugins/DSPModulePluginDemo.h @@ -1582,10 +1582,10 @@ public: g.fillRect (rectChoice); g.setColour (Colours::white); - g.setFont (Font (20.0f).italicised().withExtraKerningFactor (0.1f)); + g.setFont (Font (FontOptions (20.0f)).italicised().withExtraKerningFactor (0.1f)); g.drawFittedText ("DSP MODULE DEMO", rectTop.reduced (10, 0), Justification::centredLeft, 1); - g.setFont (Font (14.0f)); + g.setFont (FontOptions (14.0f)); String strText = "IR length (reverb): " + String (proc.getCurrentIRSize()) + " samples"; g.drawFittedText (strText, rectBottom.reduced (10, 0), Justification::centredRight, 1); } diff --git a/examples/Utilities/ChildProcessDemo.h b/examples/Utilities/ChildProcessDemo.h index aefcc98f3f..136c7438bc 100644 --- a/examples/Utilities/ChildProcessDemo.h +++ b/examples/Utilities/ChildProcessDemo.h @@ -99,7 +99,7 @@ public: addAndMakeVisible (testResultsBox); testResultsBox.setMultiLine (true); - testResultsBox.setFont ({ Font::getDefaultMonospacedFontName(), 12.0f, Font::plain }); + testResultsBox.setFont (FontOptions { Font::getDefaultMonospacedFontName(), 12.0f, Font::plain }); logMessage (String ("This demo uses the ChildProcessCoordinator and ChildProcessWorker classes to launch and communicate " "with a child process, sending messages in the form of serialised ValueTree objects.") + newLine diff --git a/examples/Utilities/InAppPurchasesDemo.h b/examples/Utilities/InAppPurchasesDemo.h index 491c3205ca..48e260e2d0 100644 --- a/examples/Utilities/InAppPurchasesDemo.h +++ b/examples/Utilities/InAppPurchasesDemo.h @@ -395,10 +395,10 @@ public: else stopTimer(); - nameLabel.setFont (Font (16).withStyle (Font::bold | (hasBeenPurchased ? 0 : Font::italic))); + nameLabel.setFont (FontOptions { 16.0f, Font::bold | (hasBeenPurchased ? 0 : Font::italic) }); nameLabel.setColour (Label::textColourId, hasBeenPurchased ? Colours::white : Colours::grey); - priceLabel.setFont (Font (10).withStyle (purchase.priceIsKnown ? 0 : Font::italic)); + priceLabel.setFont (FontOptions { 10.0f, purchase.priceIsKnown ? 0 : Font::italic }); priceLabel.setColour (Label::textColourId, hasBeenPurchased ? Colours::white : Colours::grey); priceLabel.setText (purchase.purchasePrice, NotificationType::dontSendNotification); diff --git a/examples/Utilities/JavaScriptDemo.h b/examples/Utilities/JavaScriptDemo.h index 56b888aa03..2f5e1c9f7b 100644 --- a/examples/Utilities/JavaScriptDemo.h +++ b/examples/Utilities/JavaScriptDemo.h @@ -86,13 +86,13 @@ public: editor.reset (new CodeEditorComponent (codeDocument, nullptr)); addAndMakeVisible (editor.get()); - editor->setFont ({ Font::getDefaultMonospacedFontName(), 14.0f, Font::plain }); + editor->setFont (FontOptions { Font::getDefaultMonospacedFontName(), 14.0f, Font::plain }); editor->setTabSize (4, true); outputDisplay.setMultiLine (true); outputDisplay.setReadOnly (true); outputDisplay.setCaretVisible (false); - outputDisplay.setFont ({ Font::getDefaultMonospacedFontName(), 14.0f, Font::plain }); + outputDisplay.setFont (FontOptions { Font::getDefaultMonospacedFontName(), 14.0f, Font::plain }); addAndMakeVisible (outputDisplay); codeDocument.addListener (this); diff --git a/examples/Utilities/OSCDemo.h b/examples/Utilities/OSCDemo.h index 25701b741b..71dd26fc0c 100644 --- a/examples/Utilities/OSCDemo.h +++ b/examples/Utilities/OSCDemo.h @@ -458,7 +458,7 @@ private: auto textColour = isConnected() ? Colours::green : Colours::red; connectionStatusLabel.setText (text, dontSendNotification); - connectionStatusLabel.setFont (Font (15.00f, Font::bold)); + connectionStatusLabel.setFont (FontOptions (15.00f, Font::bold)); connectionStatusLabel.setColour (Label::textColourId, textColour); connectionStatusLabel.setJustificationType (Justification::centredRight); } diff --git a/examples/Utilities/SystemInfoDemo.h b/examples/Utilities/SystemInfoDemo.h index 4c1941e796..76b91ae9d2 100644 --- a/examples/Utilities/SystemInfoDemo.h +++ b/examples/Utilities/SystemInfoDemo.h @@ -232,7 +232,7 @@ public: resultsBox.setReadOnly (true); resultsBox.setMultiLine (true); resultsBox.setColour (TextEditor::backgroundColourId, Colours::transparentBlack); - resultsBox.setFont ({ Font::getDefaultMonospacedFontName(), 12.0f, Font::plain }); + resultsBox.setFont (FontOptions { Font::getDefaultMonospacedFontName(), 12.0f, Font::plain }); resultsBox.setText (getAllSystemInfo()); setSize (500, 500); diff --git a/examples/Utilities/TimersAndEventsDemo.h b/examples/Utilities/TimersAndEventsDemo.h index 6bc44b8aa9..ea126ffb04 100644 --- a/examples/Utilities/TimersAndEventsDemo.h +++ b/examples/Utilities/TimersAndEventsDemo.h @@ -221,7 +221,7 @@ public: s.append (newLine); s.append ("Click the \"Set Random Colour\" button to change the colour of one of the circles."); s.append (newLine); - s.setFont (16.0f); + s.setFont (FontOptions { 16.0f }); s.setColour (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::defaultText, Colours::lightgrey)); s.draw (g, explanationArea.reduced (10).toFloat()); } diff --git a/examples/Utilities/UnitTestsDemo.h b/examples/Utilities/UnitTestsDemo.h index 8dcd2b092b..61beabd631 100644 --- a/examples/Utilities/UnitTestsDemo.h +++ b/examples/Utilities/UnitTestsDemo.h @@ -70,7 +70,7 @@ public: addAndMakeVisible (testResultsBox); testResultsBox.setMultiLine (true); - testResultsBox.setFont (Font (Font::getDefaultMonospacedFontName(), 12.0f, Font::plain)); + testResultsBox.setFont (FontOptions (Font::getDefaultMonospacedFontName(), 12.0f, Font::plain)); addAndMakeVisible (categoriesBox); categoriesBox.addItem ("All Tests", 1); diff --git a/extras/AudioPerformanceTest/Source/MainComponent.h b/extras/AudioPerformanceTest/Source/MainComponent.h index 1305799372..5f57c23428 100644 --- a/extras/AudioPerformanceTest/Source/MainComponent.h +++ b/extras/AudioPerformanceTest/Source/MainComponent.h @@ -117,7 +117,7 @@ public: void paint (Graphics& g) override { g.fillAll (Colours::black); - g.setFont (Font (16.0f)); + g.setFont (FontOptions (16.0f)); g.setColour (Colours::white); g.drawText ("loop iterations / audio callback", getLocalBounds().withY (loopIterationsSlider.getHeight()), Justification::centred, true); diff --git a/extras/AudioPluginHost/Source/UI/GraphEditorPanel.cpp b/extras/AudioPluginHost/Source/UI/GraphEditorPanel.cpp index 2c73cb7350..96f1111023 100644 --- a/extras/AudioPluginHost/Source/UI/GraphEditorPanel.cpp +++ b/extras/AudioPluginHost/Source/UI/GraphEditorPanel.cpp @@ -553,7 +553,7 @@ struct GraphEditorPanel::PluginComponent final : public Component, int numInputs = 0, numOutputs = 0; int pinSize = 16; Point originalPos; - Font font { 13.0f, Font::bold }; + Font font = FontOptions { 13.0f, Font::bold }; int numIns = 0, numOuts = 0; DropShadowEffect shadow; std::unique_ptr menu; @@ -1020,7 +1020,7 @@ struct GraphDocumentComponent::TooltipBar final : public Component, void paint (Graphics& g) override { - g.setFont (Font ((float) getHeight() * 0.7f, Font::bold)); + g.setFont (FontOptions ((float) getHeight() * 0.7f, Font::bold)); g.setColour (Colours::black); g.drawFittedText (tip, 10, 0, getWidth() - 12, getHeight(), Justification::centredLeft, 1); } @@ -1124,7 +1124,7 @@ private: pluginButton.setBounds (r.removeFromRight (40).withSizeKeepingCentre (20, 20)); - titleLabel.setFont (Font (static_cast (getHeight()) * 0.5f, Font::plain)); + titleLabel.setFont (FontOptions (static_cast (getHeight()) * 0.5f, Font::plain)); titleLabel.setBounds (r); } diff --git a/extras/NetworkGraphicsDemo/Source/ClientComponent.h b/extras/NetworkGraphicsDemo/Source/ClientComponent.h index 0227ec5e6c..e5b0c39ec4 100644 --- a/extras/NetworkGraphicsDemo/Source/ClientComponent.h +++ b/extras/NetworkGraphicsDemo/Source/ClientComponent.h @@ -164,14 +164,14 @@ private: if (clientArea.isEmpty()) { g.setColour (Colours::red.withAlpha (0.5f)); - g.setFont (20.0f); + g.setFont (FontOptions (20.0f)); g.drawText ("Not Connected", getLocalBounds(), Justification::centred, false); return; } canvas.draw (g, getLocalBounds().toFloat(), clientArea); - g.setFont (Font (34.0f)); + g.setFont (FontOptions (34.0f)); g.setColour (Colours::white.withAlpha (0.6f)); g.drawText (getMachineInfoToDisplay(), diff --git a/extras/NetworkGraphicsDemo/Source/Demos.h b/extras/NetworkGraphicsDemo/Source/Demos.h index f41d451ff1..b63d2de549 100644 --- a/extras/NetworkGraphicsDemo/Source/Demos.h +++ b/extras/NetworkGraphicsDemo/Source/Demos.h @@ -414,7 +414,7 @@ struct FlockWithText final : public FlockDemo String text = String (messages[currentMessage]).replace ("NUMDEVICES", String (canvas.clients.size())); AttributedString as; - as.append (text, Font (textSize * scale), Colour (0x80ffffff).withMultipliedAlpha (alpha)); + as.append (text, FontOptions (textSize * scale), Colour (0x80ffffff).withMultipliedAlpha (alpha)); as.setJustification (Justification::centred); auto middle = canvas.clients[clientIndex % canvas.clients.size()].centre * scale; diff --git a/extras/NetworkGraphicsDemo/Source/SharedCanvas.h b/extras/NetworkGraphicsDemo/Source/SharedCanvas.h index 743343e4bc..c98e3eaf27 100644 --- a/extras/NetworkGraphicsDemo/Source/SharedCanvas.h +++ b/extras/NetworkGraphicsDemo/Source/SharedCanvas.h @@ -404,12 +404,28 @@ public: const Font& getFont() override { return getState().font; } void setFont (const Font& newFont) override { getState().font = newFont; } - void drawGlyph (int glyphNumber, const AffineTransform& transform) override + void drawGlyphs (Span indices, + Span> positions, + const AffineTransform& transform) override { - Path p; - Font& font = getState().font; - font.getTypefacePtr()->getOutlineForGlyph (glyphNumber, p); - fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform)); + std::unordered_map cache; + + const auto& font = getState().font; + + for (size_t i = 0; i < indices.size(); i++) + { + const auto glyphNumber = indices[i]; + const auto pos = positions[i]; + auto& path = cache[glyphNumber]; + + if (path.isEmpty()) + font.getTypefacePtr()->getOutlineForGlyph (TypefaceMetricsKind::legacy, glyphNumber, path); + + auto t = AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()) + .followedBy (AffineTransform::translation (pos)) + .followedBy (transform); + fillPath (path, t); + } } private: @@ -423,7 +439,7 @@ private: { FillType fillType; AffineTransform transform; - Font font; + Font font { FontOptions{} }; ReferenceCountedObjectPtr transparencyLayer; float transparencyOpacity = 1.0f; }; diff --git a/extras/Projucer/Source/Application/StartPage/jucer_ContentComponents.h b/extras/Projucer/Source/Application/StartPage/jucer_ContentComponents.h index 77b306dc4d..d1525fea90 100644 --- a/extras/Projucer/Source/Application/StartPage/jucer_ContentComponents.h +++ b/extras/Projucer/Source/Application/StartPage/jucer_ContentComponents.h @@ -50,7 +50,7 @@ public: icon (makeIcon (iconSvgData)) { addAndMakeVisible (nameLabel); - nameLabel.setFont (18.0f); + nameLabel.setFont (FontOptions { 18.0f }); nameLabel.setMinimumHorizontalScale (1.0f); addAndMakeVisible (descriptionLabel); diff --git a/extras/Projucer/Source/Application/UserAccount/jucer_LoginFormComponent.h b/extras/Projucer/Source/Application/UserAccount/jucer_LoginFormComponent.h index 63e41f1169..2efec07dbe 100644 --- a/extras/Projucer/Source/Application/UserAccount/jucer_LoginFormComponent.h +++ b/extras/Projucer/Source/Application/UserAccount/jucer_LoginFormComponent.h @@ -73,13 +73,13 @@ public: addAndMakeVisible (userAvatar); addAndMakeVisible (createAccountLabel); - createAccountLabel.setFont (Font (14.0f, Font::underlined)); + createAccountLabel.setFont (FontOptions (14.0f, Font::underlined)); createAccountLabel.addMouseListener (this, false); createAccountLabel.setMouseCursor (MouseCursor::PointingHandCursor); addAndMakeVisible (errorMessageLabel); errorMessageLabel.setMinimumHorizontalScale (1.0f); - errorMessageLabel.setFont (12.0f); + errorMessageLabel.setFont (FontOptions { 12.0f }); errorMessageLabel.setColour (Label::textColourId, Colours::red); errorMessageLabel.setVisible (false); @@ -119,8 +119,8 @@ public: passwordBox.setBounds (bounds.removeFromTop (textEditorHeight)); bounds.removeFromTop (spacing * 2); - emailBox.setFont (Font ((float) textEditorHeight / 2.5f)); - passwordBox.setFont (Font ((float) textEditorHeight / 2.5f)); + emailBox.setFont (FontOptions ((float) textEditorHeight / 2.5f)); + passwordBox.setFont (FontOptions ((float) textEditorHeight / 2.5f)); logInButton.setBounds (bounds.removeFromTop (textEditorHeight)); diff --git a/extras/Projucer/Source/Application/Windows/jucer_AboutWindowComponent.h b/extras/Projucer/Source/Application/Windows/jucer_AboutWindowComponent.h index 8f336b74f7..efd7647f98 100644 --- a/extras/Projucer/Source/Application/Windows/jucer_AboutWindowComponent.h +++ b/extras/Projucer/Source/Application/Windows/jucer_AboutWindowComponent.h @@ -43,7 +43,7 @@ public: { addAndMakeVisible (titleLabel); titleLabel.setJustificationType (Justification::centred); - titleLabel.setFont (Font (35.0f, Font::FontStyleFlags::bold)); + titleLabel.setFont (FontOptions (35.0f, Font::FontStyleFlags::bold)); auto buildDate = Time::getCompilationDate(); addAndMakeVisible (versionLabel); diff --git a/extras/Projucer/Source/Application/Windows/jucer_EditorColourSchemeWindowComponent.h b/extras/Projucer/Source/Application/Windows/jucer_EditorColourSchemeWindowComponent.h index 10527db44b..76488e7ce3 100644 --- a/extras/Projucer/Source/Application/Windows/jucer_EditorColourSchemeWindowComponent.h +++ b/extras/Projucer/Source/Application/Windows/jucer_EditorColourSchemeWindowComponent.h @@ -116,7 +116,7 @@ private: // This is unfortunately a bit slow, but will work on all platforms. static bool isMonospacedTypeface (const String& name) { - const Font font (name, 20.0f, Font::plain); + const Font font = FontOptions (name, 20.0f, Font::plain); const auto width = font.getStringWidth ("...."); @@ -188,7 +188,7 @@ private: PropertyPanel panel; TextButton loadButton, saveButton; - Font codeFont; + Font codeFont { FontOptions{} }; Array colourValues; void saveScheme (bool isExit) diff --git a/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp b/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp index 6048ba2896..73cd04f131 100644 --- a/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp +++ b/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp @@ -139,17 +139,17 @@ public: UpdateDialog (const String& newVersion, const String& releaseNotes) { titleLabel.setText ("JUCE version " + newVersion, dontSendNotification); - titleLabel.setFont ({ 15.0f, Font::bold }); + titleLabel.setFont (FontOptions { 15.0f, Font::bold }); titleLabel.setJustificationType (Justification::centred); addAndMakeVisible (titleLabel); contentLabel.setText ("A new version of JUCE is available - would you like to download it?", dontSendNotification); - contentLabel.setFont (15.0f); + contentLabel.setFont (FontOptions { 15.0f }); contentLabel.setJustificationType (Justification::topLeft); addAndMakeVisible (contentLabel); releaseNotesLabel.setText ("Release notes:", dontSendNotification); - releaseNotesLabel.setFont (15.0f); + releaseNotesLabel.setFont (FontOptions { 15.0f }); releaseNotesLabel.setJustificationType (Justification::topLeft); addAndMakeVisible (releaseNotesLabel); diff --git a/extras/Projucer/Source/BinaryData/Templates/jucer_AudioPluginARAEditorTemplate.cpp b/extras/Projucer/Source/BinaryData/Templates/jucer_AudioPluginARAEditorTemplate.cpp index 1a0c02fe98..2fa5508739 100644 --- a/extras/Projucer/Source/BinaryData/Templates/jucer_AudioPluginARAEditorTemplate.cpp +++ b/extras/Projucer/Source/BinaryData/Templates/jucer_AudioPluginARAEditorTemplate.cpp @@ -37,7 +37,7 @@ void %%editor_class_name%%::paint (juce::Graphics& g) g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId)); g.setColour (juce::Colours::white); - g.setFont (15.0f); + g.setFont (juce::FontOptions (15.0f)); g.drawFittedText ("Hello World!", getLocalBounds(), juce::Justification::centred, 1); } diff --git a/extras/Projucer/Source/BinaryData/Templates/jucer_AudioPluginEditorTemplate.cpp b/extras/Projucer/Source/BinaryData/Templates/jucer_AudioPluginEditorTemplate.cpp index e68c0a7ee3..670272a036 100644 --- a/extras/Projucer/Source/BinaryData/Templates/jucer_AudioPluginEditorTemplate.cpp +++ b/extras/Projucer/Source/BinaryData/Templates/jucer_AudioPluginEditorTemplate.cpp @@ -28,7 +28,7 @@ void %%editor_class_name%%::paint (juce::Graphics& g) g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId)); g.setColour (juce::Colours::white); - g.setFont (15.0f); + g.setFont (juce::FontOptions (15.0f)); g.drawFittedText ("Hello World!", getLocalBounds(), juce::Justification::centred, 1); } diff --git a/extras/Projucer/Source/BinaryData/Templates/jucer_ContentCompSimpleTemplate.h b/extras/Projucer/Source/BinaryData/Templates/jucer_ContentCompSimpleTemplate.h index 696efd7bb1..a50c5d5f96 100644 --- a/extras/Projucer/Source/BinaryData/Templates/jucer_ContentCompSimpleTemplate.h +++ b/extras/Projucer/Source/BinaryData/Templates/jucer_ContentCompSimpleTemplate.h @@ -26,7 +26,7 @@ public: // (Our component is opaque, so we must completely fill the background with a solid colour) g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId)); - g.setFont (juce::Font (16.0f)); + g.setFont (juce::FontOptions (16.0f)); g.setColour (juce::Colours::white); g.drawText ("Hello World!", getLocalBounds(), juce::Justification::centred, true); } diff --git a/extras/Projucer/Source/BinaryData/Templates/jucer_ContentCompTemplate.cpp b/extras/Projucer/Source/BinaryData/Templates/jucer_ContentCompTemplate.cpp index 59e3da349b..0fe4b5e711 100644 --- a/extras/Projucer/Source/BinaryData/Templates/jucer_ContentCompTemplate.cpp +++ b/extras/Projucer/Source/BinaryData/Templates/jucer_ContentCompTemplate.cpp @@ -16,7 +16,7 @@ void %%content_component_class%%::paint (juce::Graphics& g) // (Our component is opaque, so we must completely fill the background with a solid colour) g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId)); - g.setFont (juce::Font (16.0f)); + g.setFont (juce::FontOptions (16.0f)); g.setColour (juce::Colours::white); g.drawText ("Hello World!", getLocalBounds(), juce::Justification::centred, true); } diff --git a/extras/Projucer/Source/BinaryData/Templates/jucer_InlineComponentTemplate.h b/extras/Projucer/Source/BinaryData/Templates/jucer_InlineComponentTemplate.h index 51476373d9..20ba8f0c98 100644 --- a/extras/Projucer/Source/BinaryData/Templates/jucer_InlineComponentTemplate.h +++ b/extras/Projucer/Source/BinaryData/Templates/jucer_InlineComponentTemplate.h @@ -23,7 +23,7 @@ public: g.drawRect (getLocalBounds(), 1); // draw an outline around the component g.setColour (juce::Colours::white); - g.setFont (14.0f); + g.setFont (juce::FontOptions (14.0f)); g.drawText ("%%component_class%%", getLocalBounds(), juce::Justification::centred, true); // draw some placeholder text } diff --git a/extras/Projucer/Source/BinaryData/Templates/jucer_NewComponentTemplate.cpp b/extras/Projucer/Source/BinaryData/Templates/jucer_NewComponentTemplate.cpp index 5d6fb68f2b..4d361cfc47 100644 --- a/extras/Projucer/Source/BinaryData/Templates/jucer_NewComponentTemplate.cpp +++ b/extras/Projucer/Source/BinaryData/Templates/jucer_NewComponentTemplate.cpp @@ -38,7 +38,7 @@ void %%component_class%%::paint (juce::Graphics& g) g.drawRect (getLocalBounds(), 1); // draw an outline around the component g.setColour (juce::Colours::white); - g.setFont (14.0f); + g.setFont (juce::FontOptions (14.0f)); g.drawText ("%%component_class%%", getLocalBounds(), juce::Justification::centred, true); // draw some placeholder text } diff --git a/extras/Projucer/Source/BinaryData/Templates/jucer_NewInlineComponentTemplate.h b/extras/Projucer/Source/BinaryData/Templates/jucer_NewInlineComponentTemplate.h index b6dc046d17..94a37a694e 100644 --- a/extras/Projucer/Source/BinaryData/Templates/jucer_NewInlineComponentTemplate.h +++ b/extras/Projucer/Source/BinaryData/Templates/jucer_NewInlineComponentTemplate.h @@ -44,7 +44,7 @@ public: g.drawRect (getLocalBounds(), 1); // draw an outline around the component g.setColour (juce::Colours::white); - g.setFont (14.0f); + g.setFont (juce::FontOptions (14.0f)); g.drawText ("%%component_class%%", getLocalBounds(), juce::Justification::centred, true); // draw some placeholder text } diff --git a/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h b/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h index ae5716b6b9..3a5f3910c5 100644 --- a/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h +++ b/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h @@ -74,7 +74,7 @@ public: .getTransformToFit (contentBounds, area.toFloat())); } - g.setFont (Font (14.0f, Font::bold)); + g.setFont (FontOptions (14.0f, Font::bold)); g.setColour (findColour (defaultTextColourId)); g.drawMultiLineText (facts.joinIntoString ("\n"), 10, 15, getWidth() - 16); } diff --git a/extras/Projucer/Source/ComponentEditor/Components/jucer_LabelHandler.h b/extras/Projucer/Source/ComponentEditor/Components/jucer_LabelHandler.h index 1ca9373d29..e55ef13c3a 100644 --- a/extras/Projucer/Source/ComponentEditor/Components/jucer_LabelHandler.h +++ b/extras/Projucer/Source/ComponentEditor/Components/jucer_LabelHandler.h @@ -89,7 +89,7 @@ public: Label defaultLabel; - Font font; + Font font { FontOptions{} }; font.setHeight ((float) xml.getDoubleAttribute ("fontsize", 15.0)); font.setBold (xml.getBoolAttribute ("bold", false)); font.setItalic (xml.getBoolAttribute ("italic", false)); @@ -703,7 +703,7 @@ private: return true; } - Font newState, oldState; + Font newState { FontOptions{} }, oldState { FontOptions{} }; }; }; diff --git a/extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementText.h b/extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementText.h index 0bb5729cf8..2d204fba7c 100644 --- a/extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementText.h +++ b/extras/Projucer/Source/ComponentEditor/PaintElements/jucer_PaintElementText.h @@ -45,7 +45,7 @@ public: PaintElementText (PaintRoutine* pr) : ColouredElement (pr, "Text", false, false), text ("Your text goes here"), - font (15.0f), + font (FontOptions { 15.0f }), typefaceName (FontPropertyComponent::getDefaultFont()), justification (Justification::centred) { diff --git a/extras/Projucer/Source/ComponentEditor/Properties/jucer_ColourPropertyComponent.h b/extras/Projucer/Source/ComponentEditor/Properties/jucer_ColourPropertyComponent.h index cb2dfa7b99..d007b25ba1 100644 --- a/extras/Projucer/Source/ComponentEditor/Properties/jucer_ColourPropertyComponent.h +++ b/extras/Projucer/Source/ComponentEditor/Properties/jucer_ColourPropertyComponent.h @@ -75,7 +75,7 @@ public: Colour (0xffffffff).overlaidWith (colour)); g.setColour (Colours::white.overlaidWith (colour).contrasting()); - g.setFont (Font ((float) getHeight() * 0.6f, Font::bold)); + g.setFont (FontOptions ((float) getHeight() * 0.6f, Font::bold)); g.drawFittedText (colour.toDisplayString (true), 2, 1, getWidth() - 4, getHeight() - 1, Justification::centred, 1); diff --git a/extras/Projucer/Source/ComponentEditor/Properties/jucer_FontPropertyComponent.h b/extras/Projucer/Source/ComponentEditor/Properties/jucer_FontPropertyComponent.h index 25be8deced..21adac2be6 100644 --- a/extras/Projucer/Source/ComponentEditor/Properties/jucer_FontPropertyComponent.h +++ b/extras/Projucer/Source/ComponentEditor/Properties/jucer_FontPropertyComponent.h @@ -55,8 +55,8 @@ public: Array fonts; Font::findFonts (fonts); - for (int i = 0; i < fonts.size(); ++i) - fontNames.add (fonts[i].getTypefaceName()); + for (const auto& font : fonts) + fontNames.add (font.getTypefaceName()); } choices.addArray (fontNames); @@ -90,14 +90,15 @@ public: static Font applyNameToFont (const String& typefaceName, const Font& font) { - auto extraKerning = font.getExtraKerningFactor(); + const auto extraKerning = font.getExtraKerningFactor(); + const auto kerned = [extraKerning] (Font f) { return f.withExtraKerningFactor (extraKerning); }; - if (typefaceName == getDefaultFont()) return Font (font.getHeight(), font.getStyleFlags()).withExtraKerningFactor (extraKerning); - if (typefaceName == getDefaultSans()) return Font (Font::getDefaultSansSerifFontName(), font.getHeight(), font.getStyleFlags()).withExtraKerningFactor (extraKerning); - if (typefaceName == getDefaultSerif()) return Font (Font::getDefaultSerifFontName(), font.getHeight(), font.getStyleFlags()).withExtraKerningFactor (extraKerning); - if (typefaceName == getDefaultMono()) return Font (Font::getDefaultMonospacedFontName(), font.getHeight(), font.getStyleFlags()).withExtraKerningFactor (extraKerning); + if (typefaceName == getDefaultFont()) return kerned (FontOptions (font.getHeight(), font.getStyleFlags())); + if (typefaceName == getDefaultSans()) return kerned (FontOptions (Font::getDefaultSansSerifFontName(), font.getHeight(), font.getStyleFlags())); + if (typefaceName == getDefaultSerif()) return kerned (FontOptions (Font::getDefaultSerifFontName(), font.getHeight(), font.getStyleFlags())); + if (typefaceName == getDefaultMono()) return kerned (FontOptions (Font::getDefaultMonospacedFontName(), font.getHeight(), font.getStyleFlags())); - auto f = Font (typefaceName, font.getHeight(), font.getStyleFlags()).withExtraKerningFactor (extraKerning); + auto f = kerned (FontOptions { typefaceName, font.getHeight(), font.getStyleFlags() }); if (f.getAvailableStyles().contains (font.getTypefaceStyle())) f.setTypefaceStyle (font.getTypefaceStyle()); diff --git a/extras/Projucer/Source/ComponentEditor/UI/jucer_ResourceEditorPanel.cpp b/extras/Projucer/Source/ComponentEditor/UI/jucer_ResourceEditorPanel.cpp index e525e215a6..672dfe758d 100644 --- a/extras/Projucer/Source/ComponentEditor/UI/jucer_ResourceEditorPanel.cpp +++ b/extras/Projucer/Source/ComponentEditor/UI/jucer_ResourceEditorPanel.cpp @@ -167,7 +167,7 @@ int ResourceEditorPanel::getColumnAutoSizeWidth (int columnId) if (columnId == 4) return 0; - Font f (13.0f); + Font f (FontOptions { 13.0f }); int widest = 40; for (int i = document.getResources().size(); --i >= 0;) diff --git a/extras/Projucer/Source/Project/UI/jucer_ContentViewComponents.h b/extras/Projucer/Source/Project/UI/jucer_ContentViewComponents.h index 6dc6622235..f2e2e64cc1 100644 --- a/extras/Projucer/Source/Project/UI/jucer_ContentViewComponents.h +++ b/extras/Projucer/Source/Project/UI/jucer_ContentViewComponents.h @@ -54,7 +54,7 @@ struct ContentViewHeader final : public Component icon.withColour (Colours::white).draw (g, bounds.toFloat().removeFromRight (30), false); g.setColour (Colours::white); - g.setFont (Font (18.0f)); + g.setFont (FontOptions (18.0f)); g.drawFittedText (name, bounds, Justification::centredLeft, 1); } @@ -206,7 +206,7 @@ public: { info = infoToDisplay; - auto stringWidth = roundToInt (Font (14.0f).getStringWidthFloat (info)); + auto stringWidth = roundToInt (Font (FontOptions (14.0f)).getStringWidthFloat (info)); width = jmin (300, stringWidth); numLines += static_cast (stringWidth / width); @@ -238,7 +238,7 @@ private: g.fillAll (findColour (secondaryBackgroundColourId)); g.setColour (findColour (defaultTextColourId)); - g.setFont (Font (14.0f)); + g.setFont (FontOptions (14.0f)); g.drawFittedText (stringToDisplay, getLocalBounds(), Justification::centred, 15, 0.75f); } @@ -265,7 +265,7 @@ public: clearProperties(); if (description.isNotEmpty()) - properties.push_back (std::make_unique (description, 16, Font (16.0f), + properties.push_back (std::make_unique (description, 16, FontOptions (16.0f), Justification::centredLeft)); for (auto* comp : newProps.components) diff --git a/extras/Projucer/Source/Project/UI/jucer_HeaderComponent.cpp b/extras/Projucer/Source/Project/UI/jucer_HeaderComponent.cpp index 110f11b5f3..2ed303b537 100644 --- a/extras/Projucer/Source/Project/UI/jucer_HeaderComponent.cpp +++ b/extras/Projucer/Source/Project/UI/jucer_HeaderComponent.cpp @@ -67,7 +67,7 @@ HeaderComponent::HeaderComponent (ProjectContentComponent* pcc) void HeaderComponent::resized() { auto bounds = getLocalBounds(); - configLabel.setFont ({ (float) bounds.getHeight() / 3.0f }); + configLabel.setFont (FontOptions { (float) bounds.getHeight() / 3.0f }); { auto headerBounds = bounds.removeFromLeft (tabsWidth); diff --git a/extras/Projucer/Source/Project/UI/jucer_ProjectMessagesComponent.h b/extras/Projucer/Source/Project/UI/jucer_ProjectMessagesComponent.h index a5e08bb8b0..009f4891bd 100644 --- a/extras/Projucer/Source/Project/UI/jucer_ProjectMessagesComponent.h +++ b/extras/Projucer/Source/Project/UI/jucer_ProjectMessagesComponent.h @@ -179,11 +179,11 @@ private: icon = (ProjectMessages::getTypeForMessage (message) == ProjectMessages::Ids::warning ? getIcons().warning : getIcons().info); messageTitleLabel.setText (ProjectMessages::getTitleForMessage (message), dontSendNotification); - messageTitleLabel.setFont (Font (11.0f).boldened()); + messageTitleLabel.setFont (FontOptions { 11.0f, Font::bold }); addAndMakeVisible (messageTitleLabel); messageDescriptionLabel.setText (ProjectMessages::getDescriptionForMessage (message), dontSendNotification); - messageDescriptionLabel.setFont (Font (11.0f)); + messageDescriptionLabel.setFont (FontOptions (11.0f)); messageDescriptionLabel.setJustificationType (Justification::topLeft); addAndMakeVisible (messageDescriptionLabel); diff --git a/extras/Projucer/Source/Settings/jucer_AppearanceSettings.cpp b/extras/Projucer/Source/Settings/jucer_AppearanceSettings.cpp index f8fdd769a8..5f71e60fc6 100644 --- a/extras/Projucer/Source/Settings/jucer_AppearanceSettings.cpp +++ b/extras/Projucer/Source/Settings/jucer_AppearanceSettings.cpp @@ -149,7 +149,7 @@ bool AppearanceSettings::writeToFile (const File& file) const Font AppearanceSettings::getDefaultCodeFont() { - return Font (Font::getDefaultMonospacedFontName(), Font::getDefaultStyle(), 13.0f); + return FontOptions (Font::getDefaultMonospacedFontName(), Font::getDefaultStyle(), 13.0f); } StringArray AppearanceSettings::getColourNames() const diff --git a/extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_ColourPropertyComponent.h b/extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_ColourPropertyComponent.h index e8c766e6f0..0fcf6424e0 100644 --- a/extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_ColourPropertyComponent.h +++ b/extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_ColourPropertyComponent.h @@ -80,7 +80,7 @@ private: Colour (0xffffffff).overlaidWith (colour)); g.setColour (Colours::white.overlaidWith (colour).contrasting()); - g.setFont (Font ((float) getHeight() * 0.6f, Font::bold)); + g.setFont (FontOptions ((float) getHeight() * 0.6f, Font::bold)); g.drawFittedText (colour.toDisplayString (true), getLocalBounds().reduced (2, 1), Justification::centred, 1); } diff --git a/extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_LabelPropertyComponent.h b/extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_LabelPropertyComponent.h index 07bf59bf3a..9bbf43098e 100644 --- a/extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_LabelPropertyComponent.h +++ b/extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_LabelPropertyComponent.h @@ -40,7 +40,7 @@ class LabelPropertyComponent final : public PropertyComponent { public: LabelPropertyComponent (const String& labelText, int propertyHeight = 25, - Font labelFont = Font (16.0f, Font::bold), + Font labelFont = FontOptions (16.0f, Font::bold), Justification labelJustification = Justification::centred) : PropertyComponent (labelText), labelToDisplay ({}, labelText) diff --git a/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp b/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp index d56e87d2f9..1b6a31ce12 100644 --- a/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp +++ b/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp @@ -85,7 +85,7 @@ void JucerTreeViewBase::refreshSubItems() Font JucerTreeViewBase::getFont() const { - return Font ((float) getItemHeight() * 0.6f); + return FontOptions ((float) getItemHeight() * 0.6f); } void JucerTreeViewBase::paintOpenCloseButton (Graphics& g, const Rectangle& area, Colour /*backgroundColour*/, bool isMouseOver) diff --git a/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.h b/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.h index d28b0a44ac..5f445dc6e3 100644 --- a/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.h +++ b/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.h @@ -90,7 +90,7 @@ public: bool filled, Justification justification); static Path getChoiceComponentArrowPath (Rectangle arrowZone); - static Font getPropertyComponentFont() { return { 14.0f, Font::FontStyleFlags::bold }; } + static Font getPropertyComponentFont() { return FontOptions { 14.0f, Font::FontStyleFlags::bold }; } static int getTextWidthForPropertyComponent (const PropertyComponent& pc) { return jmin (200, pc.getWidth() / 2); } static ColourScheme getProjucerDarkColourScheme() diff --git a/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp b/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp index 39d4cf6bde..c3b3c4f205 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 (Font ((float) height * 0.7f, Font::bold)); + g.setFont (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 bdd3ab2b7d..a8937e2d13 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 ((float) textBounds.getHeight() * 0.6f); + attributedString.setFont (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 a1680a64a6..f646762984 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 (fontHeight).withHorizontalScale (0.8f)); + g.setFont (Font (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 7d6df6770a..d34eb72128 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 (fontHeight).withHorizontalScale (0.8f)); + g.setFont (Font (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 58cbf9a5b6..9c08a75f02 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 (Font()); + context.setFont (FontOptions{}); context.setInterpolationQuality (Graphics::mediumResamplingQuality); } diff --git a/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h b/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h index 568d68682f..9697cc6fe2 100644 --- a/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h +++ b/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h @@ -108,7 +108,7 @@ protected: RectangleList clip; int xOffset, yOffset; FillType fillType; - Font font; + Font font { FontOptions{} }; }; OwnedArray stateStack; diff --git a/modules/juce_graphics/fonts/juce_AttributedString.cpp b/modules/juce_graphics/fonts/juce_AttributedString.cpp index 7308e393eb..2c3df7b15b 100644 --- a/modules/juce_graphics/fonts/juce_AttributedString.cpp +++ b/modules/juce_graphics/fonts/juce_AttributedString.cpp @@ -117,7 +117,7 @@ namespace { if (atts.size() == 0) { - atts.add ({ Range (0, length), f != nullptr ? *f : Font(), c != nullptr ? *c : Colour (0xff000000) }); + atts.add ({ Range (0, length), f != nullptr ? *f : FontOptions{}, c != nullptr ? *c : Colour (0xff000000) }); } else { diff --git a/modules/juce_graphics/fonts/juce_AttributedString.h b/modules/juce_graphics/fonts/juce_AttributedString.h index 1faa9fa969..e153a1ae5b 100644 --- a/modules/juce_graphics/fonts/juce_AttributedString.h +++ b/modules/juce_graphics/fonts/juce_AttributedString.h @@ -175,7 +175,7 @@ public: Range range; /** The font for this range of characters. */ - Font font; + Font font { FontOptions{} }; /** The colour for this range of characters. */ Colour colour { 0xff000000 }; diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index 93fa398a81..89ce72b777 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -354,6 +354,11 @@ private: }; //============================================================================== +Font::Font (FontOptions opt) + : font (new SharedFontInternal (std::move (opt))) +{ +} + Font::Font() : font (new SharedFontInternal (FontOptions{})) {} Font::Font (const Typeface::Ptr& typeface) : font (new SharedFontInternal (FontOptions { typeface })) {} Font::Font (const Font& other) noexcept : font (other.font) {} @@ -747,7 +752,7 @@ void Font::findFonts (Array& destArray) if (! styles.contains (style, true)) style = styles[0]; - destArray.add (Font (name, style, FontValues::defaultFontHeight)); + destArray.add (FontOptions (name, style, FontValues::defaultFontHeight)); } } @@ -851,7 +856,7 @@ Font Font::fromString (const String& fontDescription) const String style (sizeAndStyle.fromFirstOccurrenceOf (" ", false, false)); - return Font (name, style, height); + return FontOptions (name, style, height); } Font::Native Font::getNativeDetails() const diff --git a/modules/juce_graphics/fonts/juce_Font.h b/modules/juce_graphics/fonts/juce_Font.h index 2b2114265f..0aab026e33 100644 --- a/modules/juce_graphics/fonts/juce_Font.h +++ b/modules/juce_graphics/fonts/juce_Font.h @@ -61,6 +61,9 @@ public: underlined = 4 /**< underlines the font. @see setStyleFlags */ }; + /** Constructs a Font from a set of options describing the font. */ + Font (FontOptions options); + //============================================================================== /** Creates a sans-serif font in a given size. @@ -70,6 +73,7 @@ public: just Font::plain for the normal style. @see FontStyleFlags, getDefaultSansSerifFontName */ + [[deprecated ("Use the constructor that takes a FontOptions argument")]] Font (float fontHeight, int styleFlags = plain); /** Creates a font with a given typeface and parameters. @@ -81,6 +85,7 @@ public: just Font::plain for the normal style. @see FontStyleFlags, getDefaultSansSerifFontName */ + [[deprecated ("Use the constructor that takes a FontOptions argument")]] Font (const String& typefaceName, float fontHeight, int styleFlags); /** Creates a font with a given typeface and parameters. @@ -89,12 +94,11 @@ public: @param typefaceStyle the font style of the typeface to use @param fontHeight the height in pixels (can be fractional) */ + [[deprecated ("Use the constructor that takes a FontOptions argument")]] Font (const String& typefaceName, const String& typefaceStyle, float fontHeight); - /** Creates a copy of another Font object. */ - Font (const Font& other) noexcept; - /** Creates a font for a typeface. */ + [[deprecated ("Use the constructor that takes a FontOptions argument")]] Font (const Typeface::Ptr& typeface); /** Creates a basic sans-serif font at a default height. @@ -103,8 +107,12 @@ public: on drawing with - this constructor is here to help initialise objects before changing the font's settings later. */ + [[deprecated ("Use the constructor that takes a FontOptions argument")]] Font(); + /** Creates a copy of another Font object. */ + Font (const Font& other) noexcept; + /** Move constructor */ Font (Font&& other) noexcept; diff --git a/modules/juce_graphics/fonts/juce_GlyphArrangement.h b/modules/juce_graphics/fonts/juce_GlyphArrangement.h index 7e4c9e3a47..f733b965f8 100644 --- a/modules/juce_graphics/fonts/juce_GlyphArrangement.h +++ b/modules/juce_graphics/fonts/juce_GlyphArrangement.h @@ -100,7 +100,7 @@ public: private: //============================================================================== friend class GlyphArrangement; - Font font; + Font font { FontOptions{} }; juce_wchar character; int glyph; float x, y, w; diff --git a/modules/juce_graphics/fonts/juce_TextLayout.h b/modules/juce_graphics/fonts/juce_TextLayout.h index 5eed82969f..6fd9771a08 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.h +++ b/modules/juce_graphics/fonts/juce_TextLayout.h @@ -180,7 +180,7 @@ public: /** Returns the X position range which contains all the glyphs in this run. */ Range getRunBoundsX() const noexcept; - Font font; /**< The run's font. */ + Font font { FontOptions{} }; /**< The run's font. */ Colour colour { 0xff000000 }; /**< The run's colour. */ Array glyphs; /**< The glyphs in this run. */ Range stringRange; /**< The character range that this run represents in the diff --git a/modules/juce_graphics/fonts/juce_Typeface.cpp b/modules/juce_graphics/fonts/juce_Typeface.cpp index 7457503b5f..a09dc297a8 100644 --- a/modules/juce_graphics/fonts/juce_Typeface.cpp +++ b/modules/juce_graphics/fonts/juce_Typeface.cpp @@ -292,7 +292,7 @@ struct FontStyleHelpers private: static String findName (const String& placeholder) { - const Font f (placeholder, 15.0f, Font::plain); + const Font f (FontOptions (placeholder, 15.0f, Font::plain)); return Font::getDefaultTypefaceForFont (f)->getName(); } @@ -957,7 +957,7 @@ public: beginTest ("Typefaces loaded from memory are found when creating font instances by name"); { - Font font (ptr->getName(), ptr->getStyle(), 12.0f); + Font font (FontOptions (ptr->getName(), ptr->getStyle(), 12.0f)); expect (font.getTypefacePtr() != nullptr); expect (font.getTypefacePtr()->getName() == ptr->getName()); diff --git a/modules/juce_graphics/native/juce_CoreGraphicsContext_mac.mm b/modules/juce_graphics/native/juce_CoreGraphicsContext_mac.mm index 6ec9f43dd6..1627e3a057 100644 --- a/modules/juce_graphics/native/juce_CoreGraphicsContext_mac.mm +++ b/modules/juce_graphics/native/juce_CoreGraphicsContext_mac.mm @@ -212,7 +212,7 @@ struct CoreGraphicsContext::SavedState } FillType fillType; - Font font { 1.0f }; + Font font { FontOptions { 1.0f } }; CFUniquePtr fontRef{}; CGAffineTransform textMatrix = CGAffineTransformIdentity, inverseTextMatrix = CGAffineTransformIdentity; @@ -244,7 +244,7 @@ CoreGraphicsContext::CoreGraphicsContext (CGContextRef c, float h) CGContextSetBlendMode (context.get(), kCGBlendModeNormal); rgbColourSpace.reset (CGColorSpaceCreateWithName (kCGColorSpaceSRGB)); greyColourSpace.reset (CGColorSpaceCreateWithName (kCGColorSpaceGenericGrayGamma2_2)); - setFont (Font()); + setFont (FontOptions()); } CoreGraphicsContext::~CoreGraphicsContext() diff --git a/modules/juce_graphics/native/juce_DirectWriteTypeface_windows.cpp b/modules/juce_graphics/native/juce_DirectWriteTypeface_windows.cpp index 643e7dc40c..337bee2d11 100644 --- a/modules/juce_graphics/native/juce_DirectWriteTypeface_windows.cpp +++ b/modules/juce_graphics/native/juce_DirectWriteTypeface_windows.cpp @@ -437,9 +437,7 @@ public: } } - [[nodiscard]] ComSmartPtr getD2D1Factory() const { return d2dFactory; } [[nodiscard]] ComSmartPtr getDWriteFactory() const { return directWriteFactory; } - [[nodiscard]] ComSmartPtr getD2D1DCRenderTarget() const { return directWriteRenderTarget; } [[nodiscard]] AggregateFontCollection& getFonts() { jassert (fonts.has_value()); return *fonts; } [[nodiscard]] ComSmartPtr getCollectionLoader() const { return collectionLoader; } @@ -510,7 +508,12 @@ public: HbFont hbFont { hb_font_create (hbFace.get()) }; FontStyleHelpers::initSynthetics (hbFont.get(), f); - return new WindowsDirectWriteTypeface (name, style, dwFont, dwFontFace, std::move (hbFont)); + return new WindowsDirectWriteTypeface (name, + style, + dwFont, + dwFontFace, + std::move (hbFont), + getDwriteMetrics (dwFontFace)); } static Typeface::Ptr from (Span blob) @@ -520,7 +523,7 @@ public: Native getNativeDetails() const override { - return Native { hbFont.get() }; + return Native { hbFont.get(), nonPortableMetrics }; } Typeface::Ptr createSystemFallback (const String& c, const String& language) const override @@ -687,8 +690,16 @@ private: const auto style = getLocalisedStyle (*dwFont); const HbFace hbFace { hb_directwrite_face_create (dwFontFace) }; + HbFont font { hb_font_create (hbFace.get()) }; + const auto metrics = getGdiMetrics (font.get()).value_or (getDwriteMetrics (dwFontFace)); - return new WindowsDirectWriteTypeface (name, style, dwFont, dwFontFace, HbFont { hb_font_create (hbFace.get()) }, std::move (customFontCollection)); + return new WindowsDirectWriteTypeface (name, + style, + dwFont, + dwFontFace, + std::move (font), + metrics, + customFontCollection); } static String getLocalisedFamilyName (IDWriteFont& font) @@ -723,22 +734,45 @@ private: ComSmartPtr font, ComSmartPtr face, HbFont hbFontIn, + TypefaceAscentDescent metrics, ComSmartPtr collectionIn = nullptr) : Typeface (name, style), collection (std::move (collectionIn)), dwFont (font), dwFontFace (face), - hbFont (std::move (hbFontIn)) + hbFont (std::move (hbFontIn)), + nonPortableMetrics (metrics) { if (collection != nullptr) factories->getFonts().addCollection (collection); } + static TypefaceAscentDescent getDwriteMetrics (ComSmartPtr face) + { + DWRITE_FONT_METRICS dwriteFontMetrics{}; + face->GetMetrics (&dwriteFontMetrics); + return TypefaceAscentDescent { (float) dwriteFontMetrics.ascent / (float) dwriteFontMetrics.designUnitsPerEm, + (float) dwriteFontMetrics.descent / (float) dwriteFontMetrics.designUnitsPerEm }; + } + + static std::optional getGdiMetrics (hb_font_t* font) + { + hb_position_t ascent{}, descent{}; + + if (! hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_HORIZONTAL_CLIPPING_ASCENT, &ascent) || + ! hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_HORIZONTAL_CLIPPING_DESCENT, &descent)) + return {}; + + const auto upem = (float) hb_face_get_upem (hb_font_get_face (font)); + return TypefaceAscentDescent { (float) ascent / upem, (float) descent / upem }; + } + SharedResourcePointer factories; ComSmartPtr collection; ComSmartPtr dwFont; ComSmartPtr dwFontFace; HbFont hbFont; + TypefaceAscentDescent nonPortableMetrics; }; struct DefaultFontNames diff --git a/modules/juce_graphics/native/juce_Fonts_android.cpp b/modules/juce_graphics/native/juce_Fonts_android.cpp index c2287221ac..35143b19f1 100644 --- a/modules/juce_graphics/native/juce_Fonts_android.cpp +++ b/modules/juce_graphics/native/juce_Fonts_android.cpp @@ -95,10 +95,18 @@ DECLARE_JNI_CLASS (AndroidAssetManager, "android/content/res/AssetManager") // Defined in juce_core std::unique_ptr makeAndroidInputStreamWrapper (jobject stream); +struct AndroidCachedTypeface +{ + std::shared_ptr font; + TypefaceAscentDescent nonPortableMetrics; +}; + //============================================================================== class MemoryFontCache : public DeletedAtShutdown { public: + using Value = AndroidCachedTypeface; + ~MemoryFontCache() { clearSingletonInstance(); @@ -112,10 +120,10 @@ public: bool operator== (const Key& other) const { return tie() == other.tie(); } }; - void add (const Key& key, std::shared_ptr ptr) + void add (const Key& key, const Value& value) { const std::scoped_lock lock { mutex }; - cache.emplace (key, ptr); + cache.emplace (key, value); } void remove (const Key& p) @@ -156,7 +164,7 @@ public: return result; } - std::shared_ptr find (const Key& key) + std::optional find (const Key& key) const { const std::scoped_lock lock { mutex }; @@ -165,13 +173,13 @@ public: if (iter != cache.end()) return iter->second; - return nullptr; + return {}; } JUCE_DECLARE_SINGLETON (MemoryFontCache, true) private: - std::map> cache; + std::map cache; mutable std::mutex mutex; }; @@ -223,13 +231,19 @@ StringArray Font::findAllTypefaceStyles (const String& family) class AndroidTypeface final : public Typeface { public: + enum class DoCache + { + no, + yes + }; + static Typeface::Ptr from (const Font& font) { if (auto* cache = MemoryFontCache::getInstance()) if (auto result = cache->find ({ font.getTypefaceName(), font.getTypefaceStyle() })) - return new AndroidTypeface (DoCache::no, result, font.getTypefaceName(), font.getTypefaceStyle()); + return new AndroidTypeface (DoCache::no, result->font, result->nonPortableMetrics, font.getTypefaceName(), font.getTypefaceStyle()); - auto blob = getBlobForFont (font); + auto [blob, metrics] = getBlobForFont (font); auto face = FontStyleHelpers::getFaceForBlob ({ static_cast (blob.getData()), blob.getSize() }, 0); if (face == nullptr) @@ -241,15 +255,9 @@ public: HbFont hbFont { hb_font_create (face.get()) }; FontStyleHelpers::initSynthetics (hbFont.get(), font); - return new AndroidTypeface (DoCache::no, std::move (hbFont), font.getTypefaceName(), font.getTypefaceStyle()); + return new AndroidTypeface (DoCache::no, std::move (hbFont), metrics, font.getTypefaceName(), font.getTypefaceStyle()); } - enum class DoCache - { - no, - yes - }; - static Typeface::Ptr from (Span blob, unsigned int index = 0) { return fromMemory (DoCache::yes, blob, index); @@ -257,7 +265,7 @@ public: Native getNativeDetails() const override { - return Native { hbFont.get() }; + return Native { hbFont.get(), nonPortableMetrics }; } Typeface::Ptr createSystemFallback (const String& text, const String& language) const override @@ -342,7 +350,7 @@ private: // If the font only uses unsupported colour technologies, assume it's the system emoji font // and try to return a compatible version of the font if (tech != 0 && ! hasSupportedColours) - if (auto fallback = from ({ "NotoColorEmojiLegacy", FontValues::defaultFontHeight, Font::plain }); fallback != nullptr) + if (auto fallback = from (FontOptions { "NotoColorEmojiLegacy", FontValues::defaultFontHeight, Font::plain }); fallback != nullptr) return fallback; return result; @@ -355,10 +363,13 @@ private: if (face == nullptr) return {}; + const auto metrics = findNonPortableMetricsForData (blob); + return new AndroidTypeface (cache, HbFont { hb_font_create (face.get()) }, + metrics, readFontName (face.get(), HB_OT_NAME_ID_FONT_FAMILY, nullptr), - {}); + readFontName (face.get(), HB_OT_NAME_ID_FONT_SUBFAMILY, nullptr)); } static String readFontName (hb_face_t* face, hb_ot_name_id_t nameId, hb_language_t language) @@ -372,22 +383,27 @@ private: return nameString.data(); } - AndroidTypeface (DoCache cache, std::shared_ptr fontIn, const String& name, const String& style) + AndroidTypeface (DoCache cache, + std::shared_ptr fontIn, + TypefaceAscentDescent nonPortableMetricsIn, + const String& name, + const String& style) : Typeface (name, style), hbFont (std::move (fontIn)), - doCache (cache) + doCache (cache), + nonPortableMetrics (nonPortableMetricsIn) { if (doCache == DoCache::yes) if (auto* c = MemoryFontCache::getInstance()) - c->add ({ name, style }, hbFont); + c->add ({ name, style }, { hbFont, nonPortableMetrics }); } - static MemoryBlock getBlobForFont (const Font& font) + static std::tuple getBlobForFont (const Font& font) { auto memory = loadFontAsset (font.getTypefaceName()); if (! memory.isEmpty()) - return memory; + return std::tuple (memory, findNonPortableMetricsForAsset (font.getTypefaceName())); const auto file = findFontFile (font); @@ -403,7 +419,7 @@ private: MemoryBlock result; stream.readIntoMemoryBlock (result); - return stream.isExhausted() ? result : MemoryBlock{}; + return std::tuple (stream.isExhausted() ? result : MemoryBlock{}, findNonPortableMetricsForFile (file)); } static File findFontFile (const Font& font) @@ -432,14 +448,14 @@ private: { auto* env = getEnv(); - const LocalRef assetManager { env->CallObjectMethod (getAppContext().get(), AndroidContext.getAssets) }; + const LocalRef assetManager { env->CallObjectMethod (getAppContext().get(), AndroidContext.getAssets) }; if (assetManager == nullptr) return {}; - const LocalRef inputStream { env->CallObjectMethod (assetManager, - AndroidAssetManager.open, - javaString ("fonts/" + typefaceName).get()) }; + const LocalRef inputStream { env->CallObjectMethod (assetManager, + AndroidAssetManager.open, + javaString ("fonts/" + typefaceName).get()) }; // Opening an input stream for an asset might throw if the asset isn't found jniCheckHasExceptionOccurredAndClear(); @@ -458,8 +474,111 @@ private: return streamWrapper->isExhausted() ? result : MemoryBlock{}; } + static File getCacheFileForData (Span data) + { + static CriticalSection cs; + static std::map cache; + + JNIEnv* const env = getEnv(); + + const auto key = [&] + { + LocalRef digest (env->CallStaticObjectMethod (JavaMessageDigest, JavaMessageDigest.getInstance, javaString ("MD5").get())); + LocalRef bytes (env->NewByteArray ((int) data.size())); + + jboolean ignore; + auto* jbytes = env->GetByteArrayElements (bytes.get(), &ignore); + memcpy (jbytes, data.data(), data.size()); + env->ReleaseByteArrayElements (bytes.get(), jbytes, 0); + + env->CallVoidMethod (digest.get(), JavaMessageDigest.update, bytes.get()); + LocalRef result ((jbyteArray) env->CallObjectMethod (digest.get(), JavaMessageDigest.digest)); + auto* md5Bytes = env->GetByteArrayElements (result.get(), &ignore); + const ScopeGuard scope { [&] { env->ReleaseByteArrayElements (result.get(), md5Bytes, 0); } }; + + return String::toHexString (md5Bytes, env->GetArrayLength (result.get()), 0); + }(); + + const ScopedLock lock (cs); + auto& mapEntry = cache[key]; + + if (mapEntry == File()) + { + static const File cacheDirectory = [] + { + auto appContext = getAppContext(); + + if (appContext == nullptr) + return File{}; + + auto* localEnv = getEnv(); + + LocalRef cacheFile (localEnv->CallObjectMethod (appContext.get(), AndroidContext.getCacheDir)); + LocalRef jPath ((jstring) localEnv->CallObjectMethod (cacheFile.get(), JavaFile.getAbsolutePath)); + + return File (juceString (localEnv, jPath.get())); + }(); + + mapEntry = cacheDirectory.getChildFile ("bindata_" + key); + mapEntry.replaceWithData (data.data(), data.size()); + } + + return mapEntry; + } + + static TypefaceAscentDescent findNonPortableMetricsForFile (File file) + { + auto* env = getEnv(); + const LocalRef typeface { env->CallStaticObjectMethod (TypefaceClass, + TypefaceClass.createFromFile, + javaString (file.getFullPathName()).get()) }; + return findNonPortableMetricsForTypeface (typeface); + } + + static TypefaceAscentDescent findNonPortableMetricsForData (Span bytes) + { + const auto file = getCacheFileForData (bytes); + return findNonPortableMetricsForFile (file); + } + + static TypefaceAscentDescent findNonPortableMetricsForAsset (const String& name) + { + auto* env = getEnv(); + + const LocalRef assetManager { env->CallObjectMethod (getAppContext().get(), AndroidContext.getAssets) }; + const LocalRef typeface { env->CallStaticObjectMethod (TypefaceClass, + TypefaceClass.createFromAsset, + assetManager.get(), + javaString ("fonts/" + name).get()) }; + return findNonPortableMetricsForTypeface (typeface); + } + + static TypefaceAscentDescent findNonPortableMetricsForTypeface (const LocalRef& typeface) + { + constexpr auto referenceFontSize = 256.0f; + + auto* env = getEnv(); + + jint constructorFlags = 1 /*ANTI_ALIAS_FLAG*/ + | 2 /*FILTER_BITMAP_FLAG*/ + | 4 /*DITHER_FLAG*/ + | 128 /*SUBPIXEL_TEXT_FLAG*/; + + const LocalRef paint { env->NewObject (AndroidPaint, AndroidPaint.constructor, constructorFlags) }; + + env->CallObjectMethod (paint, AndroidPaint.setTypeface, typeface.get()); + env->CallVoidMethod (paint, AndroidPaint.setTextSize, referenceFontSize); + + const auto fullAscent = std::abs (env->CallFloatMethod (paint, AndroidPaint.ascent)); + const auto fullDescent = std::abs (env->CallFloatMethod (paint, AndroidPaint.descent)); + + return TypefaceAscentDescent { fullAscent / referenceFontSize, + fullDescent / referenceFontSize }; + } + std::shared_ptr hbFont; DoCache doCache; + TypefaceAscentDescent nonPortableMetrics; }; //============================================================================== diff --git a/modules/juce_graphics/native/juce_Fonts_freetype.cpp b/modules/juce_graphics/native/juce_Fonts_freetype.cpp index 0e3528efb8..c9da674348 100644 --- a/modules/juce_graphics/native/juce_Fonts_freetype.cpp +++ b/modules/juce_graphics/native/juce_Fonts_freetype.cpp @@ -425,7 +425,7 @@ public: Native getNativeDetails() const override { - return Native { hb.get() }; + return Native { hb.get(), nonPortableMetrics }; } Typeface::Ptr createSystemFallback ([[maybe_unused]] const String& text, @@ -535,6 +535,8 @@ private: FTFaceWrapper::Ptr ftFace; HbFont hb; DoCache doCache; + TypefaceAscentDescent nonPortableMetrics { (float) std::abs (ftFace->face->ascender) / (float) ftFace->face->units_per_EM, + (float) std::abs (ftFace->face->descender) / (float) ftFace->face->units_per_EM }; JUCE_DECLARE_NON_COPYABLE (FreeTypeTypeface) }; diff --git a/modules/juce_graphics/native/juce_Fonts_mac.mm b/modules/juce_graphics/native/juce_Fonts_mac.mm index 26cae3b501..3382c2c8e5 100644 --- a/modules/juce_graphics/native/juce_Fonts_mac.mm +++ b/modules/juce_graphics/native/juce_Fonts_mac.mm @@ -406,9 +406,9 @@ namespace CoreTextTypeLayout CFUniquePtr cfsFontFamily ((CFStringRef) CTFontCopyAttribute (ctRunFont, kCTFontFamilyNameAttribute)); CFUniquePtr cfsFontStyle ((CFStringRef) CTFontCopyAttribute (ctRunFont, kCTFontStyleNameAttribute)); - Font result (String::fromCFString (cfsFontFamily.get()), - String::fromCFString (cfsFontStyle.get()), - (float) (CTFontGetSize (ctRunFont) / fontHeightToPointsFactor)); + Font result (FontOptions { String::fromCFString (cfsFontFamily.get()), + String::fromCFString (cfsFontStyle.get()), + (float) (CTFontGetSize (ctRunFont) / fontHeightToPointsFactor) }); auto isUnderlined = [&] { diff --git a/modules/juce_graphics/native/juce_RenderingHelpers.h b/modules/juce_graphics/native/juce_RenderingHelpers.h index beb0ff1e10..f08d5a8fef 100644 --- a/modules/juce_graphics/native/juce_RenderingHelpers.h +++ b/modules/juce_graphics/native/juce_RenderingHelpers.h @@ -2498,7 +2498,7 @@ public: //============================================================================== Image image; - Font font; + Font font { FontOptions{} }; private: SoftwareRendererSavedState& operator= (const SoftwareRendererSavedState&) = delete; diff --git a/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp b/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp index d256c710b8..73e57719b0 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 (14.0f, Font::underlined), + font (FontOptions { 14.0f, Font::underlined }), resizeFont (true), justification (Justification::centred) { @@ -49,7 +49,7 @@ HyperlinkButton::HyperlinkButton (const String& linkText, HyperlinkButton::HyperlinkButton() : Button (String()), - font (14.0f, Font::underlined), + font (FontOptions { 14.0f, Font::underlined }), resizeFont (true), justification (Justification::centred) { diff --git a/modules/juce_gui_basics/detail/juce_LookAndFeelHelpers.h b/modules/juce_gui_basics/detail/juce_LookAndFeelHelpers.h index d69ac2673e..58f52fe604 100644 --- a/modules/juce_gui_basics/detail/juce_LookAndFeelHelpers.h +++ b/modules/juce_gui_basics/detail/juce_LookAndFeelHelpers.h @@ -60,7 +60,7 @@ struct LookAndFeelHelpers AttributedString s; s.setJustification (Justification::centred); - s.append (text, Font (tooltipFontSize, Font::bold), colour); + s.append (text, FontOptions (tooltipFontSize, Font::bold), 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 33de969eb5..b38e6e4962 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 (Font (15.0f), true); + setFont (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 c6228437e1..b92130f31d 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, scaledFont; + Font font { FontOptions{} }, scaledFont { FontOptions{} }; String text; Colour colour; Justification justification; diff --git a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp index 50d113042e..e47823f962 100644 --- a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp +++ b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp @@ -1225,7 +1225,7 @@ private: Font getFont (const XmlPath& xml) const { - Font f; + Font f { FontOptions{} }; auto family = getStyleAttribute (xml, "font-family").unquoted(); if (family.isNotEmpty()) diff --git a/modules/juce_gui_basics/filebrowser/juce_FileSearchPathListComponent.cpp b/modules/juce_gui_basics/filebrowser/juce_FileSearchPathListComponent.cpp index db0d63ead7..06a1c3f32d 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 ((float) height * 0.7f); + Font f (FontOptions { (float) height * 0.7f }); f.setHorizontalScale (0.9f); g.setFont (f); diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V1.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V1.cpp index 12c9b11cd9..d03fa9cc20 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 (jmin (15.0f, (float) box.getHeight() * 0.85f)); + Font f (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 73ce23b577..d29b6bd62a 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 Font (jmin (15.0f, (float) buttonHeight * 0.6f)); + return 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 (fontSize); + Font font (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 (Font ((float) iconRect.getHeight() * 0.9f, Font::bold), + ga.addFittedText (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 Font (15.0f); + return FontOptions (15.0f); } Font LookAndFeel_V2::getAlertWindowFont() { - return Font (12.0f); + return FontOptions (12.0f); } //============================================================================== @@ -864,7 +864,7 @@ void LookAndFeel_V2::setComponentEffectForBubbleComponent (BubbleComponent& bubb //============================================================================== Font LookAndFeel_V2::getPopupMenuFont() { - return Font (17.0f); + return 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 Font ((float) menuBar.getHeight() * 0.7f); + return 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 Font (jmin (15.0f, (float) box.getHeight() * 0.85f)); + return 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 Font (15.0f, Font::bold); + return FontOptions (15.0f, Font::bold); } int LookAndFeel_V2::getSliderPopupPlacement (Slider&) @@ -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 { 18.0f, Font::bold }; } -Font LookAndFeel_V4::getAlertWindowMessageFont() { return { 16.0f }; } -Font LookAndFeel_V4::getAlertWindowFont() { return { 14.0f }; } +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 }; } //============================================================================== 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 ({ 12.0f, Font::italic }); + g.setFont (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 { jmin (16.0f, (float) box.getHeight() * 0.85f) }; + return FontOptions { jmin (16.0f, (float) box.getHeight() * 0.85f) }; } void LookAndFeel_V4::positionComboBoxText (ComboBox& box, Label& label) @@ -1268,7 +1268,7 @@ void LookAndFeel_V4::drawPropertyPanelSectionHeader (Graphics& g, const String& g.setColour (findColour (PropertyComponent::labelTextColourId)); - g.setFont ({ (float) height * 0.7f, Font::bold }); + g.setFont (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 a128f1e06b..ef2905405d 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 { 15.0f }; + Font font { 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 63997f7091..0aec33143c 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 { 14.0f }; + Font currentFont { 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 c348ecd9bf..27dc8dc1d9 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 (Font (13.0f)); + instructions.setFont (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 d462929b6b..bdb78d0280 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 (12.0f); + Font f (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 0fe83e8179..a20e92f24c 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; + Font font { 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 2495271993..245628a5c8 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 { 14.0f, Font::bold }; + Font labelFont { 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 85a5dd3b28..80507d89ca 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 ((float) h * 0.6f).getStringWidth (getName())), h); + setSize (jlimit (h * 4, h * 8, 6 + Font (FontOptions { (float) h * 0.6f }).getStringWidth (getName())), h); } //============================================================================== @@ -321,7 +321,7 @@ public: void paintItem (Graphics& g, int width, int height) override { - g.setFont (Font ((float) height * 0.7f, Font::bold)); + g.setFont (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 905e07edfe..b59990c176 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 (13.0f); + name.setFont (FontOptions { 13.0f }); name.setText (v.name, dontSendNotification); valueEditor.setMultiLine (v.isString()); valueEditor.setReturnKeyStartsNewLine (v.isString()); diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index 4dafbce29c..a55bdd592f 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -1814,7 +1814,7 @@ struct SavedState final : public RenderingHelpers::SavedStateBase } //============================================================================== - Font font; + Font font { FontOptions{} }; GLState* state; bool isUsingCustomShader = false; diff --git a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp index faa89ba020..4dba0e5708 100644 --- a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp +++ b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp @@ -250,9 +250,9 @@ void OnlineUnlockForm::resized() r.removeFromBottom (20); // (force use of a default system font to make sure it has the password blob character) - Font font (Font::getDefaultTypefaceForFont (Font (Font::getDefaultSansSerifFontName(), - Font::getDefaultStyle(), - 5.0f))); + Font font (FontOptions { Font::getDefaultTypefaceForFont (FontOptions (Font::getDefaultSansSerifFontName(), + Font::getDefaultStyle(), + 5.0f)) }); const int boxHeight = 24; passwordBox.setBounds (r.removeFromBottom (boxHeight)); @@ -286,7 +286,7 @@ void OnlineUnlockForm::showBubbleMessage (const String& text, Component& target) addChildComponent (bubble.get()); AttributedString attString; - attString.append (text, Font (16.0f)); + attString.append (text, FontOptions (16.0f)); bubble->showAt (getLocalArea (&target, target.getLocalBounds()), attString, 500, // numMillisecondsBeforeRemoving