Browse Source

Rearranged the default font mechanism so that the LookAndFeel class has a chance to create custom typefaces for global use.

tags/2021-05-28
jules 17 years ago
parent
commit
835b66084d
14 changed files with 263 additions and 158 deletions
  1. +1
    -1
      build/linux/platform_specific_code/juce_linux_Fonts.cpp
  2. +1
    -1
      build/macosx/platform_specific_code/juce_mac_Fonts.mm
  3. +3
    -3
      build/win32/platform_specific_code/juce_win32_Fonts.cpp
  4. +1
    -1
      extras/the jucer/src/templates/jucer_ComponentTemplate.cpp
  5. +1
    -1
      extras/the jucer/src/templates/jucer_ComponentTemplate.h
  6. +50
    -51
      juce_amalgamated.cpp
  7. +76
    -27
      juce_amalgamated.h
  8. +0
    -1
      src/juce_appframework/application/juce_Application.cpp
  9. +38
    -0
      src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp
  10. +15
    -0
      src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h
  11. +4
    -39
      src/juce_appframework/gui/graphics/fonts/juce_Font.cpp
  12. +31
    -27
      src/juce_appframework/gui/graphics/fonts/juce_Font.h
  13. +8
    -6
      src/juce_appframework/gui/graphics/fonts/juce_Typeface.cpp
  14. +34
    -0
      src/juce_appframework/gui/graphics/fonts/juce_Typeface.h

+ 1
- 1
build/linux/platform_specific_code/juce_linux_Fonts.cpp View File

@@ -630,7 +630,7 @@ static const String linux_getDefaultMonospacedFontName()
return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono"); 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(); defaultSans = linux_getDefaultSansSerifFontName();
defaultSerif = linux_getDefaultSerifFontName(); defaultSerif = linux_getDefaultSerifFontName();


+ 1
- 1
build/macosx/platform_specific_code/juce_mac_Fonts.mm View File

@@ -522,7 +522,7 @@ const StringArray Font::findAllTypefaceNames() throw()
return names; 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"; defaultSans = "Lucida Grande";
defaultSerif = "Times New Roman"; defaultSerif = "Times New Roman";


+ 3
- 3
build/win32/platform_specific_code/juce_win32_Fonts.cpp View File

@@ -111,9 +111,9 @@ const StringArray Font::findAllTypefaceNames() throw()
extern bool juce_IsRunningInWine() 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()) if (juce_IsRunningInWine())
{ {


+ 1
- 1
extras/the jucer/src/templates/jucer_ComponentTemplate.cpp View File

@@ -9,7 +9,7 @@
the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
and re-saved. and re-saved.
Jucer version: 1.11
Jucer version: 1.12
------------------------------------------------------------------------------ ------------------------------------------------------------------------------


+ 1
- 1
extras/the jucer/src/templates/jucer_ComponentTemplate.h View File

@@ -9,7 +9,7 @@
the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
and re-saved. and re-saved.
Jucer version: 1.11
Jucer version: 1.12
------------------------------------------------------------------------------ ------------------------------------------------------------------------------


+ 50
- 51
juce_amalgamated.cpp View File

@@ -15665,7 +15665,6 @@ void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()


initialiseJuce_NonGUI(); initialiseJuce_NonGUI();
MessageManager::getInstance(); MessageManager::getInstance();
Font::initialiseDefaultFontNames();
LookAndFeel::setDefaultLookAndFeel (0); LookAndFeel::setDefaultLookAndFeel (0);


#if JUCE_WIN32 && JUCE_DEBUG #if JUCE_WIN32 && JUCE_DEBUG
@@ -59460,6 +59459,15 @@ static const Colour createBaseColour (const Colour& buttonColour,
return baseColour; return baseColour;
} }


static String defaultSansName, defaultSerifName, defaultFixedName;

void clearUpDefaultFontNames() throw()
{
defaultSansName = String::empty;
defaultSerifName = String::empty;
defaultFixedName = String::empty;
}

LookAndFeel::LookAndFeel() LookAndFeel::LookAndFeel()
{ {
/* if this fails it means you're trying to create a LookAndFeel object before /* 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) for (int i = 0; i < numElementsInArray (standardColours); i += 2)
setColour (standardColours [i], Colour (standardColours [i + 1])); setColour (standardColours [i], Colour (standardColours [i + 1]));

if (defaultSansName.isEmpty())
Typeface::getDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);

defaultSans = defaultSansName;
defaultSerif = defaultSerifName;
defaultFixed = defaultFixedName;
} }


LookAndFeel::~LookAndFeel() LookAndFeel::~LookAndFeel()
@@ -59658,6 +59673,25 @@ void LookAndFeel::clearDefaultLookAndFeel() throw()
deleteAndZero (defaultLF); 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, void LookAndFeel::drawButtonBackground (Graphics& g,
Button& button, Button& button,
const Colour& backgroundColour, const Colour& backgroundColour,
@@ -81031,10 +81065,8 @@ static const float minFontHeight = 0.1f;
static const float maxFontHeight = 10000.0f; static const float maxFontHeight = 10000.0f;
static const float defaultFontHeight = 14.0f; static const float defaultFontHeight = 14.0f;


static String defaultSans, defaultSerif, defaultFixed, fallbackFont;

Font::Font() throw() Font::Font() throw()
: typefaceName (defaultSans),
: typefaceName (Typeface::defaultTypefaceNameSans),
height (defaultFontHeight), height (defaultFontHeight),
horizontalScale (1.0f), horizontalScale (1.0f),
kerning (0), kerning (0),
@@ -81045,7 +81077,7 @@ Font::Font() throw()


void Font::resetToDefaultState() throw() void Font::resetToDefaultState() throw()
{ {
typefaceName = defaultSans;
typefaceName = Typeface::defaultTypefaceNameSans;
height = defaultFontHeight; height = defaultFontHeight;
horizontalScale = 1.0f; horizontalScale = 1.0f;
kerning = 0; kerning = 0;
@@ -81056,7 +81088,7 @@ void Font::resetToDefaultState() throw()


Font::Font (const float fontHeight, Font::Font (const float fontHeight,
const int styleFlags_) throw() const int styleFlags_) throw()
: typefaceName (defaultSans),
: typefaceName (Typeface::defaultTypefaceNameSans),
height (jlimit (minFontHeight, maxFontHeight, fontHeight)), height (jlimit (minFontHeight, maxFontHeight, fontHeight)),
horizontalScale (1.0f), horizontalScale (1.0f),
kerning (0), kerning (0),
@@ -81142,40 +81174,7 @@ void Font::setTypefaceName (const String& faceName) throw()
ascent = 0; 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() const String Font::getFallbackFontName() throw()
{ {
@@ -82915,6 +82914,10 @@ int TypefaceGlyphInfo::getNumKerningPairs() const throw()
return kerningPairs.getSize() / sizeof (KerningPair); return kerningPairs.getSize() / sizeof (KerningPair);
} }


const tchar* Typeface::defaultTypefaceNameSans = T("<Sans-Serif>");
const tchar* Typeface::defaultTypefaceNameSerif = T("<Serif>");
const tchar* Typeface::defaultTypefaceNameMono = T("<Monospaced>");

Typeface::Typeface() throw() Typeface::Typeface() throw()
: hash (0), : hash (0),
isFullyPopulated (false) isFullyPopulated (false)
@@ -83227,7 +83230,7 @@ void Typeface::setItalic (const bool shouldBeItalic) throw()
class TypefaceCache; class TypefaceCache;
static TypefaceCache* typefaceCacheInstance = 0; static TypefaceCache* typefaceCacheInstance = 0;


void clearUpDefaultFontNames() throw(); // in juce_Font.cpp
void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp


class TypefaceCache : private DeletedAtShutdown class TypefaceCache : private DeletedAtShutdown
{ {
@@ -83272,8 +83275,6 @@ public:
faces.clear(); faces.clear();
jassert (typefaceCacheInstance == this); jassert (typefaceCacheInstance == this);
typefaceCacheInstance = 0; typefaceCacheInstance = 0;

// just a courtesy call to get avoid leaking these strings at shutdown
clearUpDefaultFontNames(); clearUpDefaultFontNames();
} }


@@ -83321,9 +83322,7 @@ public:
face->typefaceName = font.getTypefaceName(); face->typefaceName = font.getTypefaceName();
face->flags = flags; face->flags = flags;
face->lastUsageCount = ++counter; face->lastUsageCount = ++counter;
face->typeFace = new Typeface (font.getTypefaceName(),
font.isBold(),
font.isItalic());
face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);


return face->typeFace; return face->typeFace;
} }
@@ -244511,9 +244510,9 @@ const StringArray Font::findAllTypefaceNames() throw()


extern bool juce_IsRunningInWine() 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()) if (juce_IsRunningInWine())
{ {
@@ -258022,7 +258021,7 @@ static const String linux_getDefaultMonospacedFontName()
return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono"); 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(); defaultSans = linux_getDefaultSansSerifFontName();
defaultSerif = linux_getDefaultSerifFontName(); defaultSerif = linux_getDefaultSerifFontName();
@@ -268825,7 +268824,7 @@ const StringArray Font::findAllTypefaceNames() throw()
return names; 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"; defaultSans = "Lucida Grande";
defaultSerif = "Times New Roman"; defaultSerif = "Times New Roman";


+ 76
- 27
juce_amalgamated.h View File

@@ -17198,6 +17198,36 @@ public:
*/ */
void serialise (OutputStream& outputStream); 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. */ /** A handy typedef to make it easy to use ref counted pointers to this class. */
typedef ReferenceCountedObjectPtr <Typeface> Ptr; typedef ReferenceCountedObjectPtr <Typeface> Ptr;


@@ -17234,6 +17264,9 @@ private:
bool findAndAddSystemGlyph (juce_wchar character) throw(); bool findAndAddSystemGlyph (juce_wchar character) throw();


void updateHashCode() throw(); void updateHashCode() throw();

friend class LookAndFeel;
static void getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw();
}; };


#endif // __JUCE_TYPEFACE_JUCEHEADER__ #endif // __JUCE_TYPEFACE_JUCEHEADER__
@@ -17269,7 +17302,7 @@ public:
@param styleFlags the style to use - this can be a combination of the @param styleFlags the style to use - this can be a combination of the
Font::bold, Font::italic and Font::underlined, or Font::bold, Font::italic and Font::underlined, or
just Font::plain for the normal style. just Font::plain for the normal style.
@see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName
@see FontStyleFlags, getDefaultSansSerifFontName
*/ */
Font (const float fontHeight, Font (const float fontHeight,
const int styleFlags = plain) throw(); const int styleFlags = plain) throw();
@@ -17281,7 +17314,7 @@ public:
@param styleFlags the style to use - this can be a combination of the @param styleFlags the style to use - this can be a combination of the
Font::bold, Font::italic and Font::underlined, or Font::bold, Font::italic and Font::underlined, or
just Font::plain for the normal style. just Font::plain for the normal style.
@see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName
@see FontStyleFlags, getDefaultSansSerifFontName
*/ */
Font (const String& typefaceName, Font (const String& typefaceName,
const float fontHeight, const float fontHeight,
@@ -17318,6 +17351,10 @@ public:


e.g. "Arial", "Courier", etc. 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. If a suitable font isn't found on the machine, it'll just use a default instead.
*/ */
void setTypefaceName (const String& faceName) throw(); void setTypefaceName (const String& faceName) throw();
@@ -17325,39 +17362,44 @@ public:
/** Returns the name of the typeface family that this font uses. /** Returns the name of the typeface family that this font uses.


e.g. "Arial", "Courier", etc. 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; } 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. /** Returns the total height of this font.


@@ -17536,12 +17578,6 @@ private:
mutable float ascent; mutable float ascent;
int styleFlags; int styleFlags;
mutable Typeface::Ptr typeface; 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__ #endif // __JUCE_FONT_JUCEHEADER__
@@ -52876,6 +52912,16 @@ public:
*/ */
bool isColourSpecified (const int colourId) const throw(); 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. */ /** Draws the lozenge-shaped background for a standard button. */
virtual void drawButtonBackground (Graphics& g, virtual void drawButtonBackground (Graphics& g,
Button& button, Button& button,
@@ -53325,6 +53371,9 @@ private:
Array <int> colourIds; Array <int> colourIds;
Array <Colour> colours; Array <Colour> colours;


// default typeface names
String defaultSans, defaultSerif, defaultFixed;

void drawShinyButtonShape (Graphics& g, void drawShinyButtonShape (Graphics& g,
float x, float y, float w, float h, float maxCornerSize, float x, float y, float w, float h, float maxCornerSize,
const Colour& baseColour, const Colour& baseColour,


+ 0
- 1
src/juce_appframework/application/juce_Application.cpp View File

@@ -309,7 +309,6 @@ void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
initialiseJuce_NonGUI(); initialiseJuce_NonGUI();
MessageManager::getInstance(); MessageManager::getInstance();
Font::initialiseDefaultFontNames();
LookAndFeel::setDefaultLookAndFeel (0); LookAndFeel::setDefaultLookAndFeel (0);
#if JUCE_WIN32 && JUCE_DEBUG #if JUCE_WIN32 && JUCE_DEBUG


+ 38
- 0
src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp View File

@@ -90,6 +90,16 @@ static const Colour createBaseColour (const Colour& buttonColour,
return baseColour; return baseColour;
} }
//==============================================================================
static String defaultSansName, defaultSerifName, defaultFixedName;
void clearUpDefaultFontNames() throw()
{
defaultSansName = String::empty;
defaultSerifName = String::empty;
defaultFixedName = String::empty;
}
//============================================================================== //==============================================================================
LookAndFeel::LookAndFeel() LookAndFeel::LookAndFeel()
{ {
@@ -214,6 +224,13 @@ LookAndFeel::LookAndFeel()
for (int i = 0; i < numElementsInArray (standardColours); i += 2) for (int i = 0; i < numElementsInArray (standardColours); i += 2)
setColour (standardColours [i], Colour (standardColours [i + 1])); setColour (standardColours [i], Colour (standardColours [i + 1]));
if (defaultSansName.isEmpty())
Typeface::getDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
defaultSans = defaultSansName;
defaultSerif = defaultSerifName;
defaultFixed = defaultFixedName;
} }
LookAndFeel::~LookAndFeel() LookAndFeel::~LookAndFeel()
@@ -291,6 +308,27 @@ void LookAndFeel::clearDefaultLookAndFeel() throw()
deleteAndZero (defaultLF); 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, void LookAndFeel::drawButtonBackground (Graphics& g,
Button& button, Button& button,


+ 15
- 0
src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h View File

@@ -131,6 +131,18 @@ public:
*/ */
bool isColourSpecified (const int colourId) const throw(); 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. */ /** Draws the lozenge-shaped background for a standard button. */
virtual void drawButtonBackground (Graphics& g, virtual void drawButtonBackground (Graphics& g,
@@ -609,6 +621,9 @@ private:
Array <int> colourIds; Array <int> colourIds;
Array <Colour> colours; Array <Colour> colours;
// default typeface names
String defaultSans, defaultSerif, defaultFixed;
void drawShinyButtonShape (Graphics& g, void drawShinyButtonShape (Graphics& g,
float x, float y, float w, float h, float maxCornerSize, float x, float y, float w, float h, float maxCornerSize,
const Colour& baseColour, const Colour& baseColour,


+ 4
- 39
src/juce_appframework/gui/graphics/fonts/juce_Font.cpp View File

@@ -42,12 +42,10 @@ static const float minFontHeight = 0.1f;
static const float maxFontHeight = 10000.0f; static const float maxFontHeight = 10000.0f;
static const float defaultFontHeight = 14.0f; static const float defaultFontHeight = 14.0f;
static String defaultSans, defaultSerif, defaultFixed, fallbackFont;
//============================================================================== //==============================================================================
Font::Font() throw() Font::Font() throw()
: typefaceName (defaultSans),
: typefaceName (Typeface::defaultTypefaceNameSans),
height (defaultFontHeight), height (defaultFontHeight),
horizontalScale (1.0f), horizontalScale (1.0f),
kerning (0), kerning (0),
@@ -58,7 +56,7 @@ Font::Font() throw()
void Font::resetToDefaultState() throw() void Font::resetToDefaultState() throw()
{ {
typefaceName = defaultSans;
typefaceName = Typeface::defaultTypefaceNameSans;
height = defaultFontHeight; height = defaultFontHeight;
horizontalScale = 1.0f; horizontalScale = 1.0f;
kerning = 0; kerning = 0;
@@ -69,7 +67,7 @@ void Font::resetToDefaultState() throw()
Font::Font (const float fontHeight, Font::Font (const float fontHeight,
const int styleFlags_) throw() const int styleFlags_) throw()
: typefaceName (defaultSans),
: typefaceName (Typeface::defaultTypefaceNameSans),
height (jlimit (minFontHeight, maxFontHeight, fontHeight)), height (jlimit (minFontHeight, maxFontHeight, fontHeight)),
horizontalScale (1.0f), horizontalScale (1.0f),
kerning (0), 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() const String Font::getFallbackFontName() throw()
{ {


+ 31
- 27
src/juce_appframework/gui/graphics/fonts/juce_Font.h View File

@@ -70,7 +70,7 @@ public:
@param styleFlags the style to use - this can be a combination of the @param styleFlags the style to use - this can be a combination of the
Font::bold, Font::italic and Font::underlined, or Font::bold, Font::italic and Font::underlined, or
just Font::plain for the normal style. just Font::plain for the normal style.
@see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName
@see FontStyleFlags, getDefaultSansSerifFontName
*/ */
Font (const float fontHeight, Font (const float fontHeight,
const int styleFlags = plain) throw(); const int styleFlags = plain) throw();
@@ -82,7 +82,7 @@ public:
@param styleFlags the style to use - this can be a combination of the @param styleFlags the style to use - this can be a combination of the
Font::bold, Font::italic and Font::underlined, or Font::bold, Font::italic and Font::underlined, or
just Font::plain for the normal style. just Font::plain for the normal style.
@see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName
@see FontStyleFlags, getDefaultSansSerifFontName
*/ */
Font (const String& typefaceName, Font (const String& typefaceName,
const float fontHeight, const float fontHeight,
@@ -120,6 +120,10 @@ public:
e.g. "Arial", "Courier", etc. 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. If a suitable font isn't found on the machine, it'll just use a default instead.
*/ */
void setTypefaceName (const String& faceName) throw(); void setTypefaceName (const String& faceName) throw();
@@ -127,39 +131,45 @@ public:
/** Returns the name of the typeface family that this font uses. /** Returns the name of the typeface family that this font uses.
e.g. "Arial", "Courier", etc. 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; } 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. /** Returns the total height of this font.
@@ -349,12 +359,6 @@ private:
mutable float ascent; mutable float ascent;
int styleFlags; int styleFlags;
mutable Typeface::Ptr typeface; 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__ #endif // __JUCE_FONT_JUCEHEADER__

+ 8
- 6
src/juce_appframework/gui/graphics/fonts/juce_Typeface.cpp View File

@@ -36,6 +36,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_Typeface.h" #include "juce_Typeface.h"
#include "juce_Font.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_GZIPDecompressorInputStream.h"
#include "../../../../juce_core/io/streams/juce_GZIPCompressorOutputStream.h" #include "../../../../juce_core/io/streams/juce_GZIPCompressorOutputStream.h"
#include "../../../../juce_core/io/streams/juce_BufferedInputStream.h" #include "../../../../juce_core/io/streams/juce_BufferedInputStream.h"
@@ -95,6 +96,11 @@ int TypefaceGlyphInfo::getNumKerningPairs() const throw()
} }
//==============================================================================
const tchar* Typeface::defaultTypefaceNameSans = T("<Sans-Serif>");
const tchar* Typeface::defaultTypefaceNameSerif = T("<Serif>");
const tchar* Typeface::defaultTypefaceNameMono = T("<Monospaced>");
//============================================================================== //==============================================================================
Typeface::Typeface() throw() Typeface::Typeface() throw()
: hash (0), : hash (0),
@@ -410,7 +416,7 @@ void Typeface::setItalic (const bool shouldBeItalic) throw()
class TypefaceCache; class TypefaceCache;
static TypefaceCache* typefaceCacheInstance = 0; 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(); faces.clear();
jassert (typefaceCacheInstance == this); jassert (typefaceCacheInstance == this);
typefaceCacheInstance = 0; typefaceCacheInstance = 0;
// just a courtesy call to get avoid leaking these strings at shutdown
clearUpDefaultFontNames(); clearUpDefaultFontNames();
} }
@@ -508,9 +512,7 @@ public:
face->typefaceName = font.getTypefaceName(); face->typefaceName = font.getTypefaceName();
face->flags = flags; face->flags = flags;
face->lastUsageCount = ++counter; face->lastUsageCount = ++counter;
face->typeFace = new Typeface (font.getTypefaceName(),
font.isBold(),
font.isItalic());
face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
return face->typeFace; return face->typeFace;
} }


+ 34
- 0
src/juce_appframework/gui/graphics/fonts/juce_Typeface.h View File

@@ -260,6 +260,37 @@ public:
*/ */
void serialise (OutputStream& outputStream); 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. */ /** A handy typedef to make it easy to use ref counted pointers to this class. */
typedef ReferenceCountedObjectPtr <Typeface> Ptr; typedef ReferenceCountedObjectPtr <Typeface> Ptr;
@@ -298,6 +329,9 @@ private:
bool findAndAddSystemGlyph (juce_wchar character) throw(); bool findAndAddSystemGlyph (juce_wchar character) throw();
void updateHashCode() throw(); void updateHashCode() throw();
friend class LookAndFeel;
static void getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw();
}; };


Loading…
Cancel
Save