diff --git a/build/linux/platform_specific_code/juce_linux_Fonts.cpp b/build/linux/platform_specific_code/juce_linux_Fonts.cpp index bc97bb7227..6a4303ed17 100644 --- a/build/linux/platform_specific_code/juce_linux_Fonts.cpp +++ b/build/linux/platform_specific_code/juce_linux_Fonts.cpp @@ -630,7 +630,7 @@ static const String linux_getDefaultMonospacedFontName() return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono"); } -void Font::getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw() +void Typeface::getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw() { defaultSans = linux_getDefaultSansSerifFontName(); defaultSerif = linux_getDefaultSerifFontName(); diff --git a/build/macosx/platform_specific_code/juce_mac_Fonts.mm b/build/macosx/platform_specific_code/juce_mac_Fonts.mm index aa93ec1391..1858df063c 100644 --- a/build/macosx/platform_specific_code/juce_mac_Fonts.mm +++ b/build/macosx/platform_specific_code/juce_mac_Fonts.mm @@ -522,7 +522,7 @@ const StringArray Font::findAllTypefaceNames() throw() return names; } -void Font::getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw() +void Typeface::getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw() { defaultSans = "Lucida Grande"; defaultSerif = "Times New Roman"; diff --git a/build/win32/platform_specific_code/juce_win32_Fonts.cpp b/build/win32/platform_specific_code/juce_win32_Fonts.cpp index 2980bba299..f4046b79af 100644 --- a/build/win32/platform_specific_code/juce_win32_Fonts.cpp +++ b/build/win32/platform_specific_code/juce_win32_Fonts.cpp @@ -111,9 +111,9 @@ const StringArray Font::findAllTypefaceNames() throw() extern bool juce_IsRunningInWine() throw(); -void Font::getDefaultFontNames (String& defaultSans, - String& defaultSerif, - String& defaultFixed) throw() +void Typeface::getDefaultFontNames (String& defaultSans, + String& defaultSerif, + String& defaultFixed) throw() { if (juce_IsRunningInWine()) { diff --git a/extras/the jucer/src/templates/jucer_ComponentTemplate.cpp b/extras/the jucer/src/templates/jucer_ComponentTemplate.cpp index e28a59b218..28a72216c0 100644 --- a/extras/the jucer/src/templates/jucer_ComponentTemplate.cpp +++ b/extras/the jucer/src/templates/jucer_ComponentTemplate.cpp @@ -9,7 +9,7 @@ the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded and re-saved. - Jucer version: 1.11 + Jucer version: 1.12 ------------------------------------------------------------------------------ diff --git a/extras/the jucer/src/templates/jucer_ComponentTemplate.h b/extras/the jucer/src/templates/jucer_ComponentTemplate.h index e7027396cc..210d2372b0 100644 --- a/extras/the jucer/src/templates/jucer_ComponentTemplate.h +++ b/extras/the jucer/src/templates/jucer_ComponentTemplate.h @@ -9,7 +9,7 @@ the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded and re-saved. - Jucer version: 1.11 + Jucer version: 1.12 ------------------------------------------------------------------------------ diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 550373175b..582887371b 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -15665,7 +15665,6 @@ void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI() initialiseJuce_NonGUI(); MessageManager::getInstance(); - Font::initialiseDefaultFontNames(); LookAndFeel::setDefaultLookAndFeel (0); #if JUCE_WIN32 && JUCE_DEBUG @@ -59460,6 +59459,15 @@ static const Colour createBaseColour (const Colour& buttonColour, return baseColour; } +static String defaultSansName, defaultSerifName, defaultFixedName; + +void clearUpDefaultFontNames() throw() +{ + defaultSansName = String::empty; + defaultSerifName = String::empty; + defaultFixedName = String::empty; +} + LookAndFeel::LookAndFeel() { /* if this fails it means you're trying to create a LookAndFeel object before @@ -59583,6 +59591,13 @@ LookAndFeel::LookAndFeel() for (int i = 0; i < numElementsInArray (standardColours); i += 2) setColour (standardColours [i], Colour (standardColours [i + 1])); + + if (defaultSansName.isEmpty()) + Typeface::getDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName); + + defaultSans = defaultSansName; + defaultSerif = defaultSerifName; + defaultFixed = defaultFixedName; } LookAndFeel::~LookAndFeel() @@ -59658,6 +59673,25 @@ void LookAndFeel::clearDefaultLookAndFeel() throw() deleteAndZero (defaultLF); } +const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font) +{ + String faceName (font.getTypefaceName()); + + if (faceName == Typeface::defaultTypefaceNameSans) + faceName = defaultSans; + else if (faceName == Typeface::defaultTypefaceNameSerif) + faceName = defaultSerif; + else if (faceName == Typeface::defaultTypefaceNameMono) + faceName = defaultFixed; + + return new Typeface (faceName, font.isBold(), font.isItalic()); +} + +void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName) +{ + defaultSans = newName; +} + void LookAndFeel::drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour, @@ -81031,10 +81065,8 @@ static const float minFontHeight = 0.1f; static const float maxFontHeight = 10000.0f; static const float defaultFontHeight = 14.0f; -static String defaultSans, defaultSerif, defaultFixed, fallbackFont; - Font::Font() throw() - : typefaceName (defaultSans), + : typefaceName (Typeface::defaultTypefaceNameSans), height (defaultFontHeight), horizontalScale (1.0f), kerning (0), @@ -81045,7 +81077,7 @@ Font::Font() throw() void Font::resetToDefaultState() throw() { - typefaceName = defaultSans; + typefaceName = Typeface::defaultTypefaceNameSans; height = defaultFontHeight; horizontalScale = 1.0f; kerning = 0; @@ -81056,7 +81088,7 @@ void Font::resetToDefaultState() throw() Font::Font (const float fontHeight, const int styleFlags_) throw() - : typefaceName (defaultSans), + : typefaceName (Typeface::defaultTypefaceNameSans), height (jlimit (minFontHeight, maxFontHeight, fontHeight)), horizontalScale (1.0f), kerning (0), @@ -81142,40 +81174,7 @@ void Font::setTypefaceName (const String& faceName) throw() ascent = 0; } -void Font::initialiseDefaultFontNames() throw() -{ - Font::getDefaultFontNames (defaultSans, - defaultSerif, - defaultFixed); -} - -void clearUpDefaultFontNames() throw() // called at shutdown by code in Typface -{ - defaultSans = String::empty; - defaultSerif = String::empty; - defaultFixed = String::empty; - fallbackFont = String::empty; -} - -const String Font::getDefaultSansSerifFontName() throw() -{ - return defaultSans; -} - -const String Font::getDefaultSerifFontName() throw() -{ - return defaultSerif; -} - -const String Font::getDefaultMonospacedFontName() throw() -{ - return defaultFixed; -} - -void Font::setDefaultSansSerifFontName (const String& name) throw() -{ - defaultSans = name; -} +static String fallbackFont; const String Font::getFallbackFontName() throw() { @@ -82915,6 +82914,10 @@ int TypefaceGlyphInfo::getNumKerningPairs() const throw() return kerningPairs.getSize() / sizeof (KerningPair); } +const tchar* Typeface::defaultTypefaceNameSans = T(""); +const tchar* Typeface::defaultTypefaceNameSerif = T(""); +const tchar* Typeface::defaultTypefaceNameMono = T(""); + Typeface::Typeface() throw() : hash (0), isFullyPopulated (false) @@ -83227,7 +83230,7 @@ void Typeface::setItalic (const bool shouldBeItalic) throw() class TypefaceCache; static TypefaceCache* typefaceCacheInstance = 0; -void clearUpDefaultFontNames() throw(); // in juce_Font.cpp +void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp class TypefaceCache : private DeletedAtShutdown { @@ -83272,8 +83275,6 @@ public: faces.clear(); jassert (typefaceCacheInstance == this); typefaceCacheInstance = 0; - - // just a courtesy call to get avoid leaking these strings at shutdown clearUpDefaultFontNames(); } @@ -83321,9 +83322,7 @@ public: face->typefaceName = font.getTypefaceName(); face->flags = flags; face->lastUsageCount = ++counter; - face->typeFace = new Typeface (font.getTypefaceName(), - font.isBold(), - font.isItalic()); + face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font); return face->typeFace; } @@ -244511,9 +244510,9 @@ const StringArray Font::findAllTypefaceNames() throw() extern bool juce_IsRunningInWine() throw(); -void Font::getDefaultFontNames (String& defaultSans, - String& defaultSerif, - String& defaultFixed) throw() +void Typeface::getDefaultFontNames (String& defaultSans, + String& defaultSerif, + String& defaultFixed) throw() { if (juce_IsRunningInWine()) { @@ -258022,7 +258021,7 @@ static const String linux_getDefaultMonospacedFontName() return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono"); } -void Font::getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw() +void Typeface::getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw() { defaultSans = linux_getDefaultSansSerifFontName(); defaultSerif = linux_getDefaultSerifFontName(); @@ -268825,7 +268824,7 @@ const StringArray Font::findAllTypefaceNames() throw() return names; } -void Font::getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw() +void Typeface::getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw() { defaultSans = "Lucida Grande"; defaultSerif = "Times New Roman"; diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 88b9d0c2c3..0b986d55dc 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -17198,6 +17198,36 @@ public: */ void serialise (OutputStream& outputStream); + /** A name that represents the default sans-serif typeface name. + + Note that this is NOT the platform-specific typeface name (e.g. "Times"), but + is a generic string that represents whatever that font is, such as "DefaultSans". + + If you try to create a typeface with this name, the global default LookAndFeel + object will be asked to provide an appropriate typeface. + */ + static const tchar* defaultTypefaceNameSans; + + /** A name that represents the default serif typeface name. + + Note that this is NOT the platform-specific typeface name (e.g. "Times"), but + is a generic string that represents it, such as "DefaultSans". + + If you try to create a typeface with this name, the global default LookAndFeel + object will be asked to provide an appropriate typeface. + */ + static const tchar* defaultTypefaceNameSerif; + + /** A name that represents the default monospaced typeface name. + + Note that this is NOT the platform-specific typeface name (e.g. "Times"), but + is a generic string that represents it, such as "DefaultSans". + + If you try to create a typeface with this name, the global default LookAndFeel + object will be asked to provide an appropriate typeface. + */ + static const tchar* defaultTypefaceNameMono; + /** A handy typedef to make it easy to use ref counted pointers to this class. */ typedef ReferenceCountedObjectPtr Ptr; @@ -17234,6 +17264,9 @@ private: bool findAndAddSystemGlyph (juce_wchar character) throw(); void updateHashCode() throw(); + + friend class LookAndFeel; + static void getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw(); }; #endif // __JUCE_TYPEFACE_JUCEHEADER__ @@ -17269,7 +17302,7 @@ public: @param styleFlags the style to use - this can be a combination of the Font::bold, Font::italic and Font::underlined, or just Font::plain for the normal style. - @see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName + @see FontStyleFlags, getDefaultSansSerifFontName */ Font (const float fontHeight, const int styleFlags = plain) throw(); @@ -17281,7 +17314,7 @@ public: @param styleFlags the style to use - this can be a combination of the Font::bold, Font::italic and Font::underlined, or just Font::plain for the normal style. - @see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName + @see FontStyleFlags, getDefaultSansSerifFontName */ Font (const String& typefaceName, const float fontHeight, @@ -17318,6 +17351,10 @@ public: e.g. "Arial", "Courier", etc. + This may also be set to Typeface::defaultTypefaceNameSans, Typeface::defaultTypefaceNameSerif, + or Typeface::defaultTypefaceNameMono, which are not actual platform-specific font names, but + are generic names that are used to represent the various default fonts. + If a suitable font isn't found on the machine, it'll just use a default instead. */ void setTypefaceName (const String& faceName) throw(); @@ -17325,39 +17362,44 @@ public: /** Returns the name of the typeface family that this font uses. e.g. "Arial", "Courier", etc. + + Note that this may also be one of the values: Typeface::defaultTypefaceNameSans, + Typeface::defaultTypefaceNameSerif, or Typeface::defaultTypefaceNameMono, which are not actual + platform-specific font names, but are generic names that are used to represent the various + default fonts. If you need to know the exact typeface name being used, you can call + Font::getTypeface()->getTypefaceName(), which will give you the platform-specific name. */ const String& getTypefaceName() const throw() { return typefaceName; } - /** Returns a platform-specific font family that is recommended for sans-serif fonts. + /** Returns a typeface name that represents the default sans-serif font. - This is the typeface that will be used when a font is created without - specifying another name. - - @see setTypefaceName, getDefaultSerifFontName, getDefaultMonospacedFontName, - setDefaultSansSerifFontName - */ - static const String getDefaultSansSerifFontName() throw(); + This is also the typeface that will be used when a font is created without + specifying any typeface details. - /** Returns a platform-specific font family that is recommended for serif fonts. + Note that this method just returns the same value as Typeface::defaultTypefaceNameSans, + which is a generic placeholder string, and not a platform-specific font name. - @see setTypefaceName, getDefaultSansSerifFontName, getDefaultMonospacedFontName + @see Typeface::defaultTypefaceNameSans, setTypefaceName, getDefaultSerifFontName, getDefaultMonospacedFontName, */ - static const String getDefaultSerifFontName() throw(); + static const String getDefaultSansSerifFontName() throw() { return Typeface::defaultTypefaceNameSans; } - /** Returns a platform-specific font family that is recommended for monospaced fonts. + /** Returns a typeface name that represents the default sans-serif font. - @see setTypefaceName, getDefaultSansSerifFontName, getDefaultSerifFontName + Note that this method just returns the same value as Typeface::defaultTypefaceNameSerif, + which is a generic placeholder string, and not a platform-specific font name. + + @see Typeface::defaultTypefaceNameSerif, setTypefaceName, getDefaultSansSerifFontName, getDefaultMonospacedFontName */ - static const String getDefaultMonospacedFontName() throw(); + static const String getDefaultSerifFontName() throw() { return Typeface::defaultTypefaceNameSerif; } - /** Changes the default sans-serif typeface family name. + /** Returns a typeface name that represents the default sans-serif font. - This changes the value that is returned by getDefaultSansSerifFontName(), so - changing this will change the default system font used. + Note that this method just returns the same value as Typeface::defaultTypefaceNameMono, + which is a generic placeholder string, and not a platform-specific font name. - @see getDefaultSansSerifFontName + @see Typeface::defaultTypefaceNameMono, setTypefaceName, getDefaultSansSerifFontName, getDefaultSerifFontName */ - static void setDefaultSansSerifFontName (const String& name) throw(); + static const String getDefaultMonospacedFontName() throw() { return Typeface::defaultTypefaceNameMono; } /** Returns the total height of this font. @@ -17536,12 +17578,6 @@ private: mutable float ascent; int styleFlags; mutable Typeface::Ptr typeface; - - // platform-specific calls - static void getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw(); - - friend void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI(); - static void initialiseDefaultFontNames() throw(); }; #endif // __JUCE_FONT_JUCEHEADER__ @@ -52876,6 +52912,16 @@ public: */ bool isColourSpecified (const int colourId) const throw(); + virtual const Typeface::Ptr getTypefaceForFont (const Font& font); + + /** Allows you to change the default sans-serif font. + + If you need to supply your own Typeface object for any of the default fonts, rather + than just supplying the name (e.g. if you want to use an embedded font), then + you should instead override getTypefaceForFont() to create and return the typeface. + */ + void setDefaultSansSerifTypefaceName (const String& newName); + /** Draws the lozenge-shaped background for a standard button. */ virtual void drawButtonBackground (Graphics& g, Button& button, @@ -53325,6 +53371,9 @@ private: Array colourIds; Array colours; + // default typeface names + String defaultSans, defaultSerif, defaultFixed; + void drawShinyButtonShape (Graphics& g, float x, float y, float w, float h, float maxCornerSize, const Colour& baseColour, diff --git a/src/juce_appframework/application/juce_Application.cpp b/src/juce_appframework/application/juce_Application.cpp index 23017d7f85..d56b961ea2 100644 --- a/src/juce_appframework/application/juce_Application.cpp +++ b/src/juce_appframework/application/juce_Application.cpp @@ -309,7 +309,6 @@ void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI() initialiseJuce_NonGUI(); MessageManager::getInstance(); - Font::initialiseDefaultFontNames(); LookAndFeel::setDefaultLookAndFeel (0); #if JUCE_WIN32 && JUCE_DEBUG diff --git a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp index 61074c0070..0c81be3e91 100644 --- a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp +++ b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp @@ -90,6 +90,16 @@ static const Colour createBaseColour (const Colour& buttonColour, return baseColour; } +//============================================================================== +static String defaultSansName, defaultSerifName, defaultFixedName; + +void clearUpDefaultFontNames() throw() +{ + defaultSansName = String::empty; + defaultSerifName = String::empty; + defaultFixedName = String::empty; +} + //============================================================================== LookAndFeel::LookAndFeel() { @@ -214,6 +224,13 @@ LookAndFeel::LookAndFeel() for (int i = 0; i < numElementsInArray (standardColours); i += 2) setColour (standardColours [i], Colour (standardColours [i + 1])); + + if (defaultSansName.isEmpty()) + Typeface::getDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName); + + defaultSans = defaultSansName; + defaultSerif = defaultSerifName; + defaultFixed = defaultFixedName; } LookAndFeel::~LookAndFeel() @@ -291,6 +308,27 @@ void LookAndFeel::clearDefaultLookAndFeel() throw() deleteAndZero (defaultLF); } + +//============================================================================== +const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font) +{ + String faceName (font.getTypefaceName()); + + if (faceName == Typeface::defaultTypefaceNameSans) + faceName = defaultSans; + else if (faceName == Typeface::defaultTypefaceNameSerif) + faceName = defaultSerif; + else if (faceName == Typeface::defaultTypefaceNameMono) + faceName = defaultFixed; + + return new Typeface (faceName, font.isBold(), font.isItalic()); +} + +void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName) +{ + defaultSans = newName; +} + //============================================================================== void LookAndFeel::drawButtonBackground (Graphics& g, Button& button, diff --git a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h index 3e9262d794..ba0b6a31fc 100644 --- a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h +++ b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h @@ -131,6 +131,18 @@ public: */ bool isColourSpecified (const int colourId) const throw(); + + //============================================================================== + virtual const Typeface::Ptr getTypefaceForFont (const Font& font); + + /** Allows you to change the default sans-serif font. + + If you need to supply your own Typeface object for any of the default fonts, rather + than just supplying the name (e.g. if you want to use an embedded font), then + you should instead override getTypefaceForFont() to create and return the typeface. + */ + void setDefaultSansSerifTypefaceName (const String& newName); + //============================================================================== /** Draws the lozenge-shaped background for a standard button. */ virtual void drawButtonBackground (Graphics& g, @@ -609,6 +621,9 @@ private: Array colourIds; Array colours; + // default typeface names + String defaultSans, defaultSerif, defaultFixed; + void drawShinyButtonShape (Graphics& g, float x, float y, float w, float h, float maxCornerSize, const Colour& baseColour, diff --git a/src/juce_appframework/gui/graphics/fonts/juce_Font.cpp b/src/juce_appframework/gui/graphics/fonts/juce_Font.cpp index 91c649c934..813332560e 100644 --- a/src/juce_appframework/gui/graphics/fonts/juce_Font.cpp +++ b/src/juce_appframework/gui/graphics/fonts/juce_Font.cpp @@ -42,12 +42,10 @@ static const float minFontHeight = 0.1f; static const float maxFontHeight = 10000.0f; static const float defaultFontHeight = 14.0f; -static String defaultSans, defaultSerif, defaultFixed, fallbackFont; - //============================================================================== Font::Font() throw() - : typefaceName (defaultSans), + : typefaceName (Typeface::defaultTypefaceNameSans), height (defaultFontHeight), horizontalScale (1.0f), kerning (0), @@ -58,7 +56,7 @@ Font::Font() throw() void Font::resetToDefaultState() throw() { - typefaceName = defaultSans; + typefaceName = Typeface::defaultTypefaceNameSans; height = defaultFontHeight; horizontalScale = 1.0f; kerning = 0; @@ -69,7 +67,7 @@ void Font::resetToDefaultState() throw() Font::Font (const float fontHeight, const int styleFlags_) throw() - : typefaceName (defaultSans), + : typefaceName (Typeface::defaultTypefaceNameSans), height (jlimit (minFontHeight, maxFontHeight, fontHeight)), horizontalScale (1.0f), kerning (0), @@ -157,40 +155,7 @@ void Font::setTypefaceName (const String& faceName) throw() } //============================================================================== -void Font::initialiseDefaultFontNames() throw() -{ - Font::getDefaultFontNames (defaultSans, - defaultSerif, - defaultFixed); -} - -void clearUpDefaultFontNames() throw() // called at shutdown by code in Typface -{ - defaultSans = String::empty; - defaultSerif = String::empty; - defaultFixed = String::empty; - fallbackFont = String::empty; -} - -const String Font::getDefaultSansSerifFontName() throw() -{ - return defaultSans; -} - -const String Font::getDefaultSerifFontName() throw() -{ - return defaultSerif; -} - -const String Font::getDefaultMonospacedFontName() throw() -{ - return defaultFixed; -} - -void Font::setDefaultSansSerifFontName (const String& name) throw() -{ - defaultSans = name; -} +static String fallbackFont; const String Font::getFallbackFontName() throw() { diff --git a/src/juce_appframework/gui/graphics/fonts/juce_Font.h b/src/juce_appframework/gui/graphics/fonts/juce_Font.h index bdb9de2b29..fa4f6a2fb0 100644 --- a/src/juce_appframework/gui/graphics/fonts/juce_Font.h +++ b/src/juce_appframework/gui/graphics/fonts/juce_Font.h @@ -70,7 +70,7 @@ public: @param styleFlags the style to use - this can be a combination of the Font::bold, Font::italic and Font::underlined, or just Font::plain for the normal style. - @see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName + @see FontStyleFlags, getDefaultSansSerifFontName */ Font (const float fontHeight, const int styleFlags = plain) throw(); @@ -82,7 +82,7 @@ public: @param styleFlags the style to use - this can be a combination of the Font::bold, Font::italic and Font::underlined, or just Font::plain for the normal style. - @see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName + @see FontStyleFlags, getDefaultSansSerifFontName */ Font (const String& typefaceName, const float fontHeight, @@ -120,6 +120,10 @@ public: e.g. "Arial", "Courier", etc. + This may also be set to Typeface::defaultTypefaceNameSans, Typeface::defaultTypefaceNameSerif, + or Typeface::defaultTypefaceNameMono, which are not actual platform-specific font names, but + are generic names that are used to represent the various default fonts. + If a suitable font isn't found on the machine, it'll just use a default instead. */ void setTypefaceName (const String& faceName) throw(); @@ -127,39 +131,45 @@ public: /** Returns the name of the typeface family that this font uses. e.g. "Arial", "Courier", etc. + + Note that this may also be one of the values: Typeface::defaultTypefaceNameSans, + Typeface::defaultTypefaceNameSerif, or Typeface::defaultTypefaceNameMono, which are not actual + platform-specific font names, but are generic names that are used to represent the various + default fonts. If you need to know the exact typeface name being used, you can call + Font::getTypeface()->getTypefaceName(), which will give you the platform-specific name. */ const String& getTypefaceName() const throw() { return typefaceName; } - /** Returns a platform-specific font family that is recommended for sans-serif fonts. - - This is the typeface that will be used when a font is created without - specifying another name. + //============================================================================== + /** Returns a typeface name that represents the default sans-serif font. - @see setTypefaceName, getDefaultSerifFontName, getDefaultMonospacedFontName, - setDefaultSansSerifFontName - */ - static const String getDefaultSansSerifFontName() throw(); + This is also the typeface that will be used when a font is created without + specifying any typeface details. - /** Returns a platform-specific font family that is recommended for serif fonts. + Note that this method just returns the same value as Typeface::defaultTypefaceNameSans, + which is a generic placeholder string, and not a platform-specific font name. - @see setTypefaceName, getDefaultSansSerifFontName, getDefaultMonospacedFontName + @see Typeface::defaultTypefaceNameSans, setTypefaceName, getDefaultSerifFontName, getDefaultMonospacedFontName, */ - static const String getDefaultSerifFontName() throw(); + static const String getDefaultSansSerifFontName() throw() { return Typeface::defaultTypefaceNameSans; } + + /** Returns a typeface name that represents the default sans-serif font. - /** Returns a platform-specific font family that is recommended for monospaced fonts. + Note that this method just returns the same value as Typeface::defaultTypefaceNameSerif, + which is a generic placeholder string, and not a platform-specific font name. - @see setTypefaceName, getDefaultSansSerifFontName, getDefaultSerifFontName + @see Typeface::defaultTypefaceNameSerif, setTypefaceName, getDefaultSansSerifFontName, getDefaultMonospacedFontName */ - static const String getDefaultMonospacedFontName() throw(); + static const String getDefaultSerifFontName() throw() { return Typeface::defaultTypefaceNameSerif; } - /** Changes the default sans-serif typeface family name. + /** Returns a typeface name that represents the default sans-serif font. - This changes the value that is returned by getDefaultSansSerifFontName(), so - changing this will change the default system font used. + Note that this method just returns the same value as Typeface::defaultTypefaceNameMono, + which is a generic placeholder string, and not a platform-specific font name. - @see getDefaultSansSerifFontName + @see Typeface::defaultTypefaceNameMono, setTypefaceName, getDefaultSansSerifFontName, getDefaultSerifFontName */ - static void setDefaultSansSerifFontName (const String& name) throw(); + static const String getDefaultMonospacedFontName() throw() { return Typeface::defaultTypefaceNameMono; } //============================================================================== /** Returns the total height of this font. @@ -349,12 +359,6 @@ private: mutable float ascent; int styleFlags; mutable Typeface::Ptr typeface; - - // platform-specific calls - static void getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw(); - - friend void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI(); - static void initialiseDefaultFontNames() throw(); }; #endif // __JUCE_FONT_JUCEHEADER__ diff --git a/src/juce_appframework/gui/graphics/fonts/juce_Typeface.cpp b/src/juce_appframework/gui/graphics/fonts/juce_Typeface.cpp index a223271b55..551d21caf8 100644 --- a/src/juce_appframework/gui/graphics/fonts/juce_Typeface.cpp +++ b/src/juce_appframework/gui/graphics/fonts/juce_Typeface.cpp @@ -36,6 +36,7 @@ BEGIN_JUCE_NAMESPACE #include "juce_Typeface.h" #include "juce_Font.h" +#include "../../components/lookandfeel/juce_LookAndFeel.h" #include "../../../../juce_core/io/streams/juce_GZIPDecompressorInputStream.h" #include "../../../../juce_core/io/streams/juce_GZIPCompressorOutputStream.h" #include "../../../../juce_core/io/streams/juce_BufferedInputStream.h" @@ -95,6 +96,11 @@ int TypefaceGlyphInfo::getNumKerningPairs() const throw() } +//============================================================================== +const tchar* Typeface::defaultTypefaceNameSans = T(""); +const tchar* Typeface::defaultTypefaceNameSerif = T(""); +const tchar* Typeface::defaultTypefaceNameMono = T(""); + //============================================================================== Typeface::Typeface() throw() : hash (0), @@ -410,7 +416,7 @@ void Typeface::setItalic (const bool shouldBeItalic) throw() class TypefaceCache; static TypefaceCache* typefaceCacheInstance = 0; -void clearUpDefaultFontNames() throw(); // in juce_Font.cpp +void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp //============================================================================== @@ -457,8 +463,6 @@ public: faces.clear(); jassert (typefaceCacheInstance == this); typefaceCacheInstance = 0; - - // just a courtesy call to get avoid leaking these strings at shutdown clearUpDefaultFontNames(); } @@ -508,9 +512,7 @@ public: face->typefaceName = font.getTypefaceName(); face->flags = flags; face->lastUsageCount = ++counter; - face->typeFace = new Typeface (font.getTypefaceName(), - font.isBold(), - font.isItalic()); + face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font); return face->typeFace; } diff --git a/src/juce_appframework/gui/graphics/fonts/juce_Typeface.h b/src/juce_appframework/gui/graphics/fonts/juce_Typeface.h index 8044399b0c..d013e7f893 100644 --- a/src/juce_appframework/gui/graphics/fonts/juce_Typeface.h +++ b/src/juce_appframework/gui/graphics/fonts/juce_Typeface.h @@ -260,6 +260,37 @@ public: */ void serialise (OutputStream& outputStream); + //============================================================================== + /** A name that represents the default sans-serif typeface name. + + Note that this is NOT the platform-specific typeface name (e.g. "Times"), but + is a generic string that represents whatever that font is, such as "DefaultSans". + + If you try to create a typeface with this name, the global default LookAndFeel + object will be asked to provide an appropriate typeface. + */ + static const tchar* defaultTypefaceNameSans; + + /** A name that represents the default serif typeface name. + + Note that this is NOT the platform-specific typeface name (e.g. "Times"), but + is a generic string that represents it, such as "DefaultSans". + + If you try to create a typeface with this name, the global default LookAndFeel + object will be asked to provide an appropriate typeface. + */ + static const tchar* defaultTypefaceNameSerif; + + /** A name that represents the default monospaced typeface name. + + Note that this is NOT the platform-specific typeface name (e.g. "Times"), but + is a generic string that represents it, such as "DefaultSans". + + If you try to create a typeface with this name, the global default LookAndFeel + object will be asked to provide an appropriate typeface. + */ + static const tchar* defaultTypefaceNameMono; + //============================================================================== /** A handy typedef to make it easy to use ref counted pointers to this class. */ typedef ReferenceCountedObjectPtr Ptr; @@ -298,6 +329,9 @@ private: bool findAndAddSystemGlyph (juce_wchar character) throw(); void updateHashCode() throw(); + + friend class LookAndFeel; + static void getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw(); };