1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Font: Deprecate old Font constructors

This commit is contained in:
reuk 2024-03-19 20:32:19 +00:00
parent 2ed9b84070
commit 4f2c287f9b
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
95 changed files with 428 additions and 209 deletions

View file

@ -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);

View file

@ -553,7 +553,7 @@ struct GraphEditorPanel::PluginComponent final : public Component,
int numInputs = 0, numOutputs = 0;
int pinSize = 16;
Point<int> originalPos;
Font font { 13.0f, Font::bold };
Font font = FontOptions { 13.0f, Font::bold };
int numIns = 0, numOuts = 0;
DropShadowEffect shadow;
std::unique_ptr<PopupMenu> 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<float> (getHeight()) * 0.5f, Font::plain));
titleLabel.setFont (FontOptions (static_cast<float> (getHeight()) * 0.5f, Font::plain));
titleLabel.setBounds (r);
}

View file

@ -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(),

View file

@ -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;

View file

@ -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<const uint16_t> indices,
Span<const Point<float>> 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<uint16_t, Path> 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<SharedCanvasHolder> transparencyLayer;
float transparencyOpacity = 1.0f;
};

View file

@ -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);

View file

@ -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));

View file

@ -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);

View file

@ -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<var> colourValues;
void saveScheme (bool isExit)

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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);
}

View file

@ -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{} };
};
};

View file

@ -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)
{

View file

@ -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);

View file

@ -55,8 +55,8 @@ public:
Array<Font> 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());

View file

@ -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;)

View file

@ -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<int> (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<LabelPropertyComponent> (description, 16, Font (16.0f),
properties.push_back (std::make_unique<LabelPropertyComponent> (description, 16, FontOptions (16.0f),
Justification::centredLeft));
for (auto* comp : newProps.components)

View file

@ -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);

View file

@ -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);

View file

@ -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

View file

@ -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);
}

View file

@ -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)

View file

@ -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<float>& area, Colour /*backgroundColour*/, bool isMouseOver)

View file

@ -90,7 +90,7 @@ public:
bool filled, Justification justification);
static Path getChoiceComponentArrowPath (Rectangle<float> 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()