Skip to content

Commit

Permalink
Initial commit of font style access, providing access to the styles a…
Browse files Browse the repository at this point in the history
…vailable for each font family.
  • Loading branch information
jules committed May 1, 2012
1 parent 9c21813 commit 941907a
Show file tree
Hide file tree
Showing 14 changed files with 824 additions and 348 deletions.
Expand Up @@ -38,7 +38,7 @@ SourceCodeEditor::SourceCodeEditor (OpenDocumentManager::Document* document_,

#if JUCE_MAC
Font font (10.6f);
font.setTypefaceName ("Menlo Regular");
font.setTypefaceName ("Menlo");
#else
Font font (10.0f);
font.setTypefaceName (Font::getDefaultMonospacedFontName());
Expand Down
35 changes: 23 additions & 12 deletions modules/juce_graphics/fonts/juce_CustomTypeface.cpp
Expand Up @@ -102,22 +102,25 @@ namespace CustomTypefaceHelpers

//==============================================================================
CustomTypeface::CustomTypeface()
: Typeface (String::empty)
: Typeface (String::empty, String::empty)
{
clear();
}

CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
: Typeface (String::empty)
: Typeface (String::empty, String::empty)
{
clear();

GZIPDecompressorInputStream gzin (serialisedTypefaceStream);
BufferedInputStream in (gzin, 32768);

name = in.readString();
isBold = in.readBool();
isItalic = in.readBool();

const bool isBold = in.readBool();
const bool isItalic = in.readBool();
style = FontStyleHelpers::getStyleName (isBold, isItalic);

ascent = in.readFloat();
defaultCharacter = CustomTypefaceHelpers::readChar (in);

Expand Down Expand Up @@ -153,19 +156,27 @@ void CustomTypeface::clear()
{
defaultCharacter = 0;
ascent = 1.0f;
isBold = isItalic = false;
style = "Regular";
zeromem (lookupTable, sizeof (lookupTable));
glyphs.clear();
}

void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
const bool isItalic_, const juce_wchar defaultCharacter_) noexcept
void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold,
const bool isItalic, const juce_wchar defaultCharacter_) noexcept
{
name = name_;
defaultCharacter = defaultCharacter_;
ascent = ascent_;
style = FontStyleHelpers::getStyleName (isBold, isItalic);
}

void CustomTypeface::setCharacteristics (const String& name_, const String& style_, const float ascent_,
const juce_wchar defaultCharacter_) noexcept
{
name = name_;
style = style_;
defaultCharacter = defaultCharacter_;
ascent = ascent_;
isBold = isBold_;
isItalic = isItalic_;
}

void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) noexcept
Expand Down Expand Up @@ -216,7 +227,7 @@ bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)

void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) noexcept
{
setCharacteristics (name, typefaceToCopy.getAscent(), isBold, isItalic, defaultCharacter);
setCharacteristics (name, style, typefaceToCopy.getAscent(), defaultCharacter);

for (int i = 0; i < numCharacters; ++i)
{
Expand Down Expand Up @@ -256,8 +267,8 @@ bool CustomTypeface::writeToStream (OutputStream& outputStream)
GZIPCompressorOutputStream out (&outputStream);

out.writeString (name);
out.writeBool (isBold);
out.writeBool (isItalic);
out.writeBool (FontStyleHelpers::isBold (style));
out.writeBool (FontStyleHelpers::isItalic (style));
out.writeFloat (ascent);
CustomTypefaceHelpers::writeChar (out, defaultCharacter);
out.writeInt (glyphs.size());
Expand Down
31 changes: 21 additions & 10 deletions modules/juce_graphics/fonts/juce_CustomTypeface.h
Expand Up @@ -64,19 +64,31 @@ class JUCE_API CustomTypeface : public Typeface
void clear();

/** Sets the vital statistics for the typeface.
@param name the typeface's name
@param ascent the ascent - this is normalised to a height of 1.0 and this is
the value that will be returned by Typeface::getAscent(). The
descent is assumed to be (1.0 - ascent)
@param isBold should be true if the typeface is bold
@param isItalic should be true if the typeface is italic
@param defaultCharacter the character to be used as a replacement if there's
no glyph available for the character that's being drawn
@param fontFamily the typeface's font family
@param ascent the ascent - this is normalised to a height of 1.0 and this is
the value that will be returned by Typeface::getAscent(). The
descent is assumed to be (1.0 - ascent)
@param isBold should be true if the typeface is bold
@param isItalic should be true if the typeface is italic
@param defaultCharacter the character to be used as a replacement if there's
no glyph available for the character that's being drawn
*/
void setCharacteristics (const String& name, float ascent,
void setCharacteristics (const String& fontFamily, float ascent,
bool isBold, bool isItalic,
juce_wchar defaultCharacter) noexcept;

/** Sets the vital statistics for the typeface.
@param fontFamily the typeface's font family
@param fontStyle the typeface's font style
@param ascent the ascent - this is normalised to a height of 1.0 and this is
the value that will be returned by Typeface::getAscent(). The
descent is assumed to be (1.0 - ascent)
@param defaultCharacter the character to be used as a replacement if there's
no glyph available for the character that's being drawn
*/
void setCharacteristics (const String& fontFamily, const String& fontStyle,
float ascent, juce_wchar defaultCharacter) noexcept;

/** Adds a glyph to the typeface.
The path that is passed in is normalised so that the font height is 1.0, and its
Expand Down Expand Up @@ -117,7 +129,6 @@ class JUCE_API CustomTypeface : public Typeface
//==============================================================================
juce_wchar defaultCharacter;
float ascent;
bool isBold, isItalic;

//==============================================================================
/** If a subclass overrides this, it can load glyphs into the font on-demand.
Expand Down

0 comments on commit 941907a

Please sign in to comment.