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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<int> (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<Font> 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())

View file

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

View file

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

View file

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

View file

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

View file

@ -69,7 +69,7 @@ public:
addAndMakeVisible (statusLabel);
statusLabel.setJustificationType (Justification::topLeft);
statusLabel.setFont (Font (14.0f));
statusLabel.setFont (FontOptions (14.0f));
auto presets = getPresets();

View file

@ -1156,7 +1156,7 @@ public:
private:
TableListBox table; // the table component itself
Font font { 14.0f };
Font font { FontOptions { 14.0f } };
std::unique_ptr<XmlElement> 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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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

View file

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

View file

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

View file

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

View file

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

View file

@ -130,7 +130,7 @@ void Graphics::resetToDefaultState()
{
saveStateIfPending();
context.setFill (FillType());
context.setFont (Font());
context.setFont (FontOptions{});
context.setInterpolationQuality (Graphics::mediumResamplingQuality);
}

View file

@ -108,7 +108,7 @@ protected:
RectangleList<int> clip;
int xOffset, yOffset;
FillType fillType;
Font font;
Font font { FontOptions{} };
};
OwnedArray<SavedState> stateStack;

View file

@ -117,7 +117,7 @@ namespace
{
if (atts.size() == 0)
{
atts.add ({ Range<int> (0, length), f != nullptr ? *f : Font(), c != nullptr ? *c : Colour (0xff000000) });
atts.add ({ Range<int> (0, length), f != nullptr ? *f : FontOptions{}, c != nullptr ? *c : Colour (0xff000000) });
}
else
{

View file

@ -175,7 +175,7 @@ public:
Range<int> range;
/** The font for this range of characters. */
Font font;
Font font { FontOptions{} };
/** The colour for this range of characters. */
Colour colour { 0xff000000 };

View file

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

View file

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

View file

@ -100,7 +100,7 @@ public:
private:
//==============================================================================
friend class GlyphArrangement;
Font font;
Font font { FontOptions{} };
juce_wchar character;
int glyph;
float x, y, w;

View file

@ -180,7 +180,7 @@ public:
/** Returns the X position range which contains all the glyphs in this run. */
Range<float> getRunBoundsX() const noexcept;
Font font; /**< The run's font. */
Font font { FontOptions{} }; /**< The run's font. */
Colour colour { 0xff000000 }; /**< The run's colour. */
Array<Glyph> glyphs; /**< The glyphs in this run. */
Range<int> stringRange; /**< The character range that this run represents in the

View file

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

View file

@ -212,7 +212,7 @@ struct CoreGraphicsContext::SavedState
}
FillType fillType;
Font font { 1.0f };
Font font { FontOptions { 1.0f } };
CFUniquePtr<CTFontRef> 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()

View file

@ -437,9 +437,7 @@ public:
}
}
[[nodiscard]] ComSmartPtr<ID2D1Factory> getD2D1Factory() const { return d2dFactory; }
[[nodiscard]] ComSmartPtr<IDWriteFactory> getDWriteFactory() const { return directWriteFactory; }
[[nodiscard]] ComSmartPtr<ID2D1DCRenderTarget> getD2D1DCRenderTarget() const { return directWriteRenderTarget; }
[[nodiscard]] AggregateFontCollection& getFonts() { jassert (fonts.has_value()); return *fonts; }
[[nodiscard]] ComSmartPtr<IDWriteFontCollectionLoader> 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<const std::byte> 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<IDWriteFont> font,
ComSmartPtr<IDWriteFontFace> face,
HbFont hbFontIn,
TypefaceAscentDescent metrics,
ComSmartPtr<IDWriteFontCollection> 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<IDWriteFontFace> 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<TypefaceAscentDescent> 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<Direct2DFactories> factories;
ComSmartPtr<IDWriteFontCollection> collection;
ComSmartPtr<IDWriteFont> dwFont;
ComSmartPtr<IDWriteFontFace> dwFontFace;
HbFont hbFont;
TypefaceAscentDescent nonPortableMetrics;
};
struct DefaultFontNames

View file

@ -95,10 +95,18 @@ DECLARE_JNI_CLASS (AndroidAssetManager, "android/content/res/AssetManager")
// Defined in juce_core
std::unique_ptr<InputStream> makeAndroidInputStreamWrapper (jobject stream);
struct AndroidCachedTypeface
{
std::shared_ptr<hb_font_t> 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<hb_font_t> 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<hb_font_t> find (const Key& key)
std::optional<Value> 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<Key, std::shared_ptr<hb_font_t>> cache;
std::map<Key, Value> 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<const char*> (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<const std::byte> 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<hb_font_t> fontIn, const String& name, const String& style)
AndroidTypeface (DoCache cache,
std::shared_ptr<hb_font_t> 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<MemoryBlock, TypefaceAscentDescent> 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,12 +448,12 @@ private:
{
auto* env = getEnv();
const LocalRef<jobject> assetManager { env->CallObjectMethod (getAppContext().get(), AndroidContext.getAssets) };
const LocalRef assetManager { env->CallObjectMethod (getAppContext().get(), AndroidContext.getAssets) };
if (assetManager == nullptr)
return {};
const LocalRef<jobject> inputStream { env->CallObjectMethod (assetManager,
const LocalRef inputStream { env->CallObjectMethod (assetManager,
AndroidAssetManager.open,
javaString ("fonts/" + typefaceName).get()) };
@ -458,8 +474,111 @@ private:
return streamWrapper->isExhausted() ? result : MemoryBlock{};
}
static File getCacheFileForData (Span<const std::byte> data)
{
static CriticalSection cs;
static std::map<String, File> 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<const std::byte> 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<jobject>& 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<hb_font_t> hbFont;
DoCache doCache;
TypefaceAscentDescent nonPortableMetrics;
};
//==============================================================================

View file

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

View file

@ -406,9 +406,9 @@ namespace CoreTextTypeLayout
CFUniquePtr<CFStringRef> cfsFontFamily ((CFStringRef) CTFontCopyAttribute (ctRunFont, kCTFontFamilyNameAttribute));
CFUniquePtr<CFStringRef> cfsFontStyle ((CFStringRef) CTFontCopyAttribute (ctRunFont, kCTFontStyleNameAttribute));
Font result (String::fromCFString (cfsFontFamily.get()),
Font result (FontOptions { String::fromCFString (cfsFontFamily.get()),
String::fromCFString (cfsFontStyle.get()),
(float) (CTFontGetSize (ctRunFont) / fontHeightToPointsFactor));
(float) (CTFontGetSize (ctRunFont) / fontHeightToPointsFactor) });
auto isUnderlined = [&]
{

View file

@ -2498,7 +2498,7 @@ public:
//==============================================================================
Image image;
Font font;
Font font { FontOptions{} };
private:
SoftwareRendererSavedState& operator= (const SoftwareRendererSavedState&) = delete;

View file

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

View file

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

View file

@ -40,7 +40,7 @@ DrawableText::DrawableText()
justification (Justification::centredLeft)
{
setBoundingBox (Parallelogram<float> ({ 0.0f, 0.0f, 50.0f, 20.0f }));
setFont (Font (15.0f), true);
setFont (FontOptions (15.0f), true);
}
DrawableText::DrawableText (const DrawableText& other)

View file

@ -114,7 +114,7 @@ private:
//==============================================================================
Parallelogram<float> bounds;
float fontHeight, fontHScale;
Font font, scaledFont;
Font font { FontOptions{} }, scaledFont { FontOptions{} };
String text;
Colour colour;
Justification justification;

View file

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

View file

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

View file

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

View file

@ -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<int
g.drawRect (area);
g.setColour (Colours::white);
g.setFont (Font ((float) area.getHeight() * 0.7f).boldened());
g.setFont (Font (FontOptions { (float) area.getHeight() * 0.7f }).boldened());
g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
}
@ -1884,7 +1884,7 @@ void LookAndFeel_V2::drawDocumentWindowTitleBar (DocumentWindow& window, Graphic
window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f), (float) h));
g.fillAll();
Font font ((float) h * 0.65f, Font::bold);
Font font (FontOptions { (float) h * 0.65f, Font::bold });
g.setFont (font);
int textW = font.getStringWidth (window.getName());
@ -2124,7 +2124,7 @@ void LookAndFeel_V2::drawGroupComponentOutline (Graphics& g, int width, int heig
const float textEdgeGap = 4.0f;
auto cs = 5.0f;
Font f (textH);
Font f (FontOptions { textH });
Path p;
auto x = indent;
@ -2190,7 +2190,7 @@ int LookAndFeel_V2::getTabButtonSpaceAroundImage()
int LookAndFeel_V2::getTabButtonBestWidth (TabBarButton& button, int tabDepth)
{
int width = Font ((float) tabDepth * 0.6f).getStringWidth (button.getButtonText().trim())
int width = Font (FontOptions { (float) tabDepth * 0.6f }).getStringWidth (button.getButtonText().trim())
+ getTabButtonOverlap (tabDepth) * 2;
if (auto* extraComponent = button.getExtraComponent())
@ -2312,7 +2312,7 @@ void LookAndFeel_V2::fillTabButtonShape (TabBarButton& button, Graphics& g, cons
Font LookAndFeel_V2::getTabButtonFont (TabBarButton&, float height)
{
return { height * 0.6f };
return FontOptions { height * 0.6f };
}
void LookAndFeel_V2::drawTabButtonText (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
@ -2515,7 +2515,7 @@ void LookAndFeel_V2::drawTableHeaderColumn (Graphics& g, TableHeaderComponent& h
}
g.setColour (header.findColour (TableHeaderComponent::textColourId));
g.setFont (Font ((float) height * 0.5f, Font::bold));
g.setFont (FontOptions ((float) height * 0.5f, Font::bold));
g.drawFittedText (columnName, area, Justification::centredLeft, 1);
}
@ -2585,7 +2585,7 @@ void LookAndFeel_V2::drawPropertyPanelSectionHeader (Graphics& g, const String&
auto textX = (int) (buttonIndent * 2.0f + buttonSize + 2.0f);
g.setColour (Colours::black);
g.setFont (Font ((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);
}
@ -2660,8 +2660,8 @@ AttributedString LookAndFeel_V2::createFileChooserHeaderText (const String& titl
s.setJustification (Justification::centred);
auto colour = findColour (FileChooserDialogBox::titleTextColourId);
s.append (title + "\n\n", Font (17.0f, Font::bold), colour);
s.append (instructions, Font (14.0f), colour);
s.append (title + "\n\n", FontOptions (17.0f, Font::bold), colour);
s.append (instructions, FontOptions (14.0f), colour);
return s;
}
@ -2950,7 +2950,7 @@ void LookAndFeel_V2::drawKeymapChangeButton (Graphics& g, int width, int height,
//==============================================================================
Font LookAndFeel_V2::getSidePanelTitleFont (SidePanel&)
{
return Font (18.0f);
return FontOptions (18.0f);
}
Justification LookAndFeel_V2::getSidePanelTitleJustification (SidePanel& panel)

View file

@ -111,7 +111,7 @@ void LookAndFeel_V3::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int
g.fillRect (area.withTop (area.getBottom() - 1));
g.setColour (bkg.contrasting());
g.setFont (Font ((float) area.getHeight() * 0.6f).boldened());
g.setFont (Font (FontOptions { (float) area.getHeight() * 0.6f }).boldened());
g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
}
@ -187,7 +187,7 @@ int LookAndFeel_V3::getTabButtonSpaceAroundImage() { return 0
void LookAndFeel_V3::createTabTextLayout (const TabBarButton& button, float length, float depth,
Colour colour, TextLayout& textLayout)
{
Font font (depth * 0.5f);
Font font (FontOptions { depth * 0.5f });
font.setUnderline (button.hasKeyboardFocus (false));
AttributedString s;

View file

@ -244,7 +244,7 @@ void LookAndFeel_V4::drawDocumentWindowTitleBar (DocumentWindow& window, Graphic
g.setColour (getCurrentColourScheme().getUIColour (ColourScheme::widgetBackground));
g.fillAll();
Font font ((float) h * 0.65f, Font::plain);
Font font (FontOptions { (float) h * 0.65f, Font::plain });
g.setFont (font);
auto textW = font.getStringWidth (window.getName());
@ -284,7 +284,7 @@ void LookAndFeel_V4::drawDocumentWindowTitleBar (DocumentWindow& window, Graphic
//==============================================================================
Font LookAndFeel_V4::getTextButtonFont (TextButton&, int buttonHeight)
{
return { jmin (16.0f, (float) buttonHeight * 0.6f) };
return FontOptions { jmin (16.0f, (float) buttonHeight * 0.6f) };
}
void LookAndFeel_V4::drawButtonBackground (Graphics& g,
@ -384,7 +384,7 @@ void LookAndFeel_V4::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) + 14, button.getHeight());
}
@ -462,7 +462,7 @@ void LookAndFeel_V4::drawAlertBox (Graphics& g, AlertWindow& alert,
}
GlyphArrangement ga;
ga.addFittedText ({ (float) iconRect.getHeight() * 0.9f, Font::bold },
ga.addFittedText (FontOptions { (float) iconRect.getHeight() * 0.9f, Font::bold },
String::charToString ((juce_wchar) (uint8) character),
static_cast<float> (iconRect.getX()), static_cast<float> (iconRect.getY()),
static_cast<float> (iconRect.getWidth()), static_cast<float> (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);
}

View file

@ -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<TextEditor> editor;
ListenerList<Listener> listeners;

View file

@ -825,7 +825,7 @@ private:
Range<int> 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<UniformTextSection> sections;

View file

@ -770,7 +770,7 @@ private:
}
addAndMakeVisible (instructions);
instructions.setFont (Font (13.0f));
instructions.setFont (FontOptions (13.0f));
setSize (500, 300);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1814,7 +1814,7 @@ struct SavedState final : public RenderingHelpers::SavedStateBase<SavedState>
}
//==============================================================================
Font font;
Font font { FontOptions{} };
GLState* state;
bool isUsingCustomShader = false;

View file

@ -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 font (FontOptions { Font::getDefaultTypefaceForFont (FontOptions (Font::getDefaultSansSerifFontName(),
Font::getDefaultStyle(),
5.0f)));
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