diff --git a/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp b/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp index 6fea0d1a03..6736a59b1e 100644 --- a/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp +++ b/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp @@ -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(); + + 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 values; values.add (Font::getDefaultMonospacedFontName()); @@ -453,7 +520,7 @@ struct AppearanceEditor StringArray names; names.add (""); names.add (String::empty); - names.addArray (getAppSettings().getFontNames()); + names.addArray (getAppSettings().monospacedFontNames); return new ChoicePropertyComponent (Value (new FontNameValueSource (value)), title, names, values); diff --git a/extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp b/extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp index 01c840cd1a..fe1ea40a7a 100644 --- a/extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp +++ b/extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp @@ -147,14 +147,6 @@ void StoredSettings::setLastProjects (const Array& files) props->setValue ("lastProjects", s.joinIntoString ("|")); } -const StringArray& StoredSettings::getFontNames() -{ - if (fontNames.size() == 0) - fontNames = Font::findAllTypefaceNames(); - - return fontNames; -} - //============================================================================== void StoredSettings::loadSwatchColours() { diff --git a/extras/Introjucer/Source/Utility/jucer_StoredSettings.h b/extras/Introjucer/Source/Utility/jucer_StoredSettings.h index 1ef07cf1df..4a4fb7e076 100644 --- a/extras/Introjucer/Source/Utility/jucer_StoredSettings.h +++ b/extras/Introjucer/Source/Utility/jucer_StoredSettings.h @@ -48,8 +48,6 @@ public: Array getLastProjects() const; void setLastProjects (const Array& files); - const StringArray& getFontNames(); - //============================================================================== Array swatchColours; @@ -66,9 +64,10 @@ public: //============================================================================== AppearanceSettings appearance; + StringArray monospacedFontNames; + private: ScopedPointer props; - StringArray fontNames; void loadSwatchColours();