Browse Source

Added some point-size accessor methods to Font.

tags/2021-05-28
jules 12 years ago
parent
commit
c5f1e86cb3
2 changed files with 58 additions and 43 deletions
  1. +27
    -33
      modules/juce_graphics/fonts/juce_Font.cpp
  2. +31
    -10
      modules/juce_graphics/fonts/juce_Font.h

+ 27
- 33
modules/juce_graphics/fonts/juce_Font.cpp View File

@@ -350,10 +350,8 @@ const String& Font::getDefaultStyle()
return style;
}
const String& Font::getTypefaceName() const noexcept
{
return font->typefaceName;
}
const String& Font::getTypefaceName() const noexcept { return font->typefaceName; }
const String& Font::getTypefaceStyle() const noexcept { return font->typefaceStyle; }
void Font::setTypefaceName (const String& faceName)
{
@@ -368,11 +366,6 @@ void Font::setTypefaceName (const String& faceName)
}
}
const String& Font::getTypefaceStyle() const noexcept
{
return font->typefaceStyle;
}
void Font::setTypefaceStyle (const String& typefaceStyle)
{
if (typefaceStyle != font->typefaceStyle)
@@ -399,7 +392,10 @@ StringArray Font::getAvailableStyles() const
Typeface* Font::getTypeface() const
{
if (font->typeface == nullptr)
{
font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
jassert (font->typeface != nullptr);
}
return font->typeface;
}
@@ -434,11 +430,6 @@ void Font::setFallbackFontStyle (const String& style)
}
//==============================================================================
float Font::getHeight() const noexcept
{
return font->height;
}
Font Font::withHeight (const float newHeight) const
{
Font f (*this);
@@ -446,10 +437,15 @@ Font Font::withHeight (const float newHeight) const
return f;
}
float Font::getHeightToPointsFactor() const
{
return getTypeface()->getHeightToPointsFactor();
}
Font Font::withPointHeight (float heightInPoints) const
{
Font f (*this);
f.setHeight (heightInPoints / getTypeface()->getHeightToPointsFactor());
f.setHeight (heightInPoints / getHeightToPointsFactor());
return f;
}
@@ -549,11 +545,6 @@ void Font::setSizeAndStyle (float newHeight,
setTypefaceStyle (newStyle);
}
float Font::getHorizontalScale() const noexcept
{
return font->horizontalScale;
}
Font Font::withHorizontalScale (const float newHorizontalScale) const
{
Font f (*this);
@@ -568,6 +559,11 @@ void Font::setHorizontalScale (const float scaleFactor)
checkTypefaceSuitability();
}
float Font::getHorizontalScale() const noexcept
{
return font->horizontalScale;
}
float Font::getExtraKerningFactor() const noexcept
{
return font->kerning;
@@ -587,11 +583,12 @@ void Font::setExtraKerningFactor (const float extraKerning)
checkTypefaceSuitability();
}
Font Font::boldened() const { return withStyle (getStyleFlags() | bold); }
Font Font::italicised() const { return withStyle (getStyleFlags() | italic); }
Font Font::boldened() const { return withStyle (getStyleFlags() | bold); }
Font Font::italicised() const { return withStyle (getStyleFlags() | italic); }
bool Font::isBold() const noexcept { return FontStyleHelpers::isBold (font->typefaceStyle); }
bool Font::isItalic() const noexcept { return FontStyleHelpers::isItalic (font->typefaceStyle); }
bool Font::isBold() const noexcept { return FontStyleHelpers::isBold (font->typefaceStyle); }
bool Font::isItalic() const noexcept { return FontStyleHelpers::isItalic (font->typefaceStyle); }
bool Font::isUnderlined() const noexcept { return font->underline; }
void Font::setBold (const bool shouldBeBold)
{
@@ -614,11 +611,6 @@ void Font::setUnderline (const bool shouldBeUnderlined)
checkTypefaceSuitability();
}
bool Font::isUnderlined() const noexcept
{
return font->underline;
}
float Font::getAscent() const
{
if (font->ascent == 0)
@@ -627,10 +619,12 @@ float Font::getAscent() const
return font->height * font->ascent;
}
float Font::getDescent() const
{
return font->height - getAscent();
}
float Font::getHeight() const noexcept { return font->height; }
float Font::getDescent() const { return font->height - getAscent(); }
float Font::getHeightInPoints() const { return getHeight() * getHeightToPointsFactor(); }
float Font::getAscentInPoints() const { return getAscent() * getHeightToPointsFactor(); }
float Font::getDescentInPoints() const { return getDescent() * getHeightToPointsFactor(); }
int Font::getStringWidth (const String& text) const
{


+ 31
- 10
modules/juce_graphics/fonts/juce_Font.h View File

@@ -203,14 +203,6 @@ public:
static Typeface::Ptr getDefaultTypefaceForFont (const Font& font);
//==============================================================================
/** Returns the total height of this font.
This is the maximum height, from the top of the ascent to the bottom of the
descenders.
@see withHeight, setHeightWithoutChangingWidth, getAscent
*/
float getHeight() const noexcept;
/** Returns a copy of this font with a new height. */
Font withHeight (float height) const;
@@ -227,18 +219,46 @@ public:
*/
void setHeightWithoutChangingWidth (float newHeight);
/** Returns the height of the font above its baseline.
/** Returns the total height of this font, in pixels.
This is the maximum height, from the top of the ascent to the bottom of the
descenders.
@see withHeight, setHeightWithoutChangingWidth, getAscent
*/
float getHeight() const noexcept;
/** Returns the total height of this font, in points.
This is the maximum height, from the top of the ascent to the bottom of the
descenders.
@see withPointHeight, getHeight
*/
float getHeightInPoints() const;
/** Returns the height of the font above its baseline, in pixels.
This is the maximum height from the baseline to the top.
@see getHeight, getDescent
*/
float getAscent() const;
/** Returns the amount that the font descends below its baseline.
/** Returns the height of the font above its baseline, in points.
This is the maximum height from the baseline to the top.
@see getHeight, getDescent
*/
float getAscentInPoints() const;
/** Returns the amount that the font descends below its baseline, in pixels.
This is calculated as (getHeight() - getAscent()).
@see getAscent, getHeight
*/
float getDescent() const;
/** Returns the amount that the font descends below its baseline, in points.
This is calculated as (getHeight() - getAscent()).
@see getAscent, getHeight
*/
float getDescentInPoints() const;
//==============================================================================
/** Returns the font's style flags.
This will return a bitwise-or'ed combination of values from the FontStyleFlags
@@ -435,6 +455,7 @@ private:
ReferenceCountedObjectPtr <SharedFontInternal> font;
void dupeInternalIfShared();
void checkTypefaceSuitability();
float getHeightToPointsFactor() const;
JUCE_LEAK_DETECTOR (Font)
};


Loading…
Cancel
Save