Browse Source

Introjucer: restricted font list to fixed-width fonts.

tags/2021-05-28
jules 13 years ago
parent
commit
7ef8246cae
3 changed files with 73 additions and 15 deletions
  1. +71
    -4
      extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp
  2. +0
    -8
      extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp
  3. +2
    -3
      extras/Introjucer/Source/Utility/jucer_StoredSettings.h

+ 71
- 4
extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp View File

@@ -294,7 +294,12 @@ struct AppearanceEditor
Window() : DialogWindow ("Appearance Settings", Colours::darkgrey, true, true)
{
setUsingNativeTitleBar (true);
setContentOwned (new EditorPanel(), false);
if (getAppSettings().monospacedFontNames.size() == 0)
setContentOwned (new FontScanPanel(), false);
else
setContentOwned (new EditorPanel(), false);
setResizable (true, true);
const int width = 350;
@@ -326,6 +331,67 @@ struct AppearanceEditor
JUCE_DECLARE_NON_COPYABLE (Window);
};
//==============================================================================
class FontScanPanel : public Component,
private Timer
{
public:
FontScanPanel()
{
fontsToScan = Font::findAllTypefaceNames();
startTimer (1);
}
void paint (Graphics& g)
{
g.fillAll (Colours::darkgrey);
g.setFont (14.0f);
g.setColour (Colours::white);
g.drawFittedText ("Scanning for fonts..", getLocalBounds(), Justification::centred, 2);
const int size = 30;
getLookAndFeel().drawSpinningWaitAnimation (g, Colours::white, (getWidth() - size) / 2, getHeight() / 2 - 50, size, size);
}
void timerCallback()
{
repaint();
if (fontsToScan.size() == 0)
{
getAppSettings().monospacedFontNames = fontsFound;
Window* w = findParentComponentOfClass<Window>();
if (w != nullptr)
w->setContentOwned (new EditorPanel(), false);
}
else
{
if (isMonospacedTypeface (fontsToScan[0]))
fontsFound.add (fontsToScan[0]);
fontsToScan.remove (0);
}
}
// A rather hacky trick to select only the fixed-pitch fonts..
// 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 int width = font.getStringWidth ("....");
return width == font.getStringWidth ("WWWW")
&& width == font.getStringWidth ("0000")
&& width == font.getStringWidth ("1111")
&& width == font.getStringWidth ("iiii");
}
StringArray fontsToScan, fontsFound;
};
//==============================================================================
class EditorPanel : public Component,
private Button::Listener
@@ -435,13 +501,14 @@ struct AppearanceEditor
void setValue (const var& newValue)
{
Font font (Font::fromString (sourceValue.toString()));
font.setTypefaceName (newValue.toString());
font.setTypefaceName (newValue.toString().isEmpty() ? Font::getDefaultMonospacedFontName()
: newValue.toString());
sourceValue = font.toString();
}
static ChoicePropertyComponent* createProperty (const String& title, const Value& value)
{
StringArray fontNames = getAppSettings().getFontNames();
StringArray fontNames = getAppSettings().monospacedFontNames;
Array<var> values;
values.add (Font::getDefaultMonospacedFontName());
@@ -453,7 +520,7 @@ struct AppearanceEditor
StringArray names;
names.add ("<Default Monospaced>");
names.add (String::empty);
names.addArray (getAppSettings().getFontNames());
names.addArray (getAppSettings().monospacedFontNames);
return new ChoicePropertyComponent (Value (new FontNameValueSource (value)),
title, names, values);


+ 0
- 8
extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp View File

@@ -147,14 +147,6 @@ void StoredSettings::setLastProjects (const Array<File>& files)
props->setValue ("lastProjects", s.joinIntoString ("|"));
}
const StringArray& StoredSettings::getFontNames()
{
if (fontNames.size() == 0)
fontNames = Font::findAllTypefaceNames();
return fontNames;
}
//==============================================================================
void StoredSettings::loadSwatchColours()
{


+ 2
- 3
extras/Introjucer/Source/Utility/jucer_StoredSettings.h View File

@@ -48,8 +48,6 @@ public:
Array<File> getLastProjects() const;
void setLastProjects (const Array<File>& files);
const StringArray& getFontNames();
//==============================================================================
Array <Colour> swatchColours;
@@ -66,9 +64,10 @@ public:
//==============================================================================
AppearanceSettings appearance;
StringArray monospacedFontNames;
private:
ScopedPointer<PropertiesFile> props;
StringArray fontNames;
void loadSwatchColours();


Loading…
Cancel
Save