31 static const char* getStyleName (
const bool bold,
32 const bool italic)
noexcept
34 if (bold && italic)
return "Bold Italic";
35 if (bold)
return "Bold";
36 if (italic)
return "Italic";
40 static const char* getStyleName (
const int styleFlags)
noexcept
42 return getStyleName ((styleFlags &
Font::bold) != 0,
46 static bool isBold (
const String& style)
noexcept
51 static bool isItalic (
const String& style)
noexcept
57 static bool isPlaceholderFamilyName (
const String& family)
98 static String getConcreteFamilyName (
const Font& font)
102 return isPlaceholderFamilyName (family) ? getConcreteFamilyNameFromPlaceholder (family)
113 font = font.
withHeight ((
float) standardHeight);
115 top = getAverageY (font,
"BDEFPRTZOQ",
true);
116 middle = getAverageY (font,
"acegmnopqrsuvwxy",
true);
117 bottom = getAverageY (font,
"BDELZOC",
false);
120 void applyVerticalHintingTransform (
float fontSize,
Path& path)
125 cachedScale = Scaling (top, middle, bottom,
fontSize);
135 switch (i.elementType)
140 i.x2, cachedScale.apply (i.y2));
break;
142 i.x2, cachedScale.apply (i.y2),
143 i.x3, cachedScale.apply (i.y3));
break;
155 Scaling() noexcept : middle(), upperScale(), upperOffset(), lowerScale(), lowerOffset() {}
157 Scaling (
float t,
float m,
float b,
float fontSize) noexcept : middle (m)
166 upperOffset =
newM - m * upperScale;
167 lowerOffset =
newB - b * lowerScale;
170 float apply (
float y)
const noexcept
172 return y < middle ? (y * upperScale + upperOffset)
173 : (y * lowerScale + lowerOffset);
176 float middle, upperScale, upperOffset, lowerScale, lowerOffset;
179 float cachedSize = 0;
182 static float getAverageY (
const Font& font,
const char*
chars,
bool getTop)
189 for (
auto& glyph :
ga)
192 glyph.createPath (p);
196 yValues.add (getTop ? bounds.getY() : bounds.getBottom());
207 if (std::abs (
median - y) < 0.05f * (
float) standardHeight)
214 return num < 4 ? 0.0f :
total / ((
float) num * (
float) standardHeight);
217 enum { standardHeight = 100 };
218 float top = 0, middle = 0, bottom = 0;
227 if (hintingParams ==
nullptr)
230 return hintingParams->applyVerticalHintingTransform (
fontSize, path);
245 return fallbackFont.getTypefacePtr();
Holds a resizable array of primitive or copy-by-value objects.
A table of horizontal scan-line segments - used for rasterising Paths.
Represents a particular font, including its size, style, etc.
static const String & getFallbackFontStyle()
Returns the font style of the typeface to be used for rendering glyphs that aren't found in the reque...
Font withHeight(float height) const
Returns a copy of this font with a new height.
static const String & getDefaultStyle()
Returns a font style name that represents the default style.
static const String & getFallbackFontName()
Returns the font family of the typeface to be used for rendering glyphs that aren't found in the requ...
static Typeface::Ptr getDefaultTypefaceForFont(const Font &font)
Returns the default system typeface for the given font.
static const String & getDefaultSansSerifFontName()
Returns a typeface font family that represents the default sans-serif font.
String getTypefaceName() const noexcept
Returns the font family of the typeface that this font uses.
static const String & getDefaultMonospacedFontName()
Returns a typeface font family that represents the default monospaced font.
@ italic
finds an italic version of the font.
static const String & getDefaultSerifFontName()
Returns a typeface font family that represents the default serif font.
Automatically locks and unlocks a mutex object.
A set of glyphs, each with a position.
void addLineOfText(const Font &font, const String &text, float x, float y)
Appends a line of text to the arrangement.
Iterates the lines and curves that a path contains.
bool next() noexcept
Moves onto the next element in the path.
@ quadraticTo
For this type, x1, y1, x2, y2 indicate the control point and endpoint of a quadratic curve.
@ closePath
Indicates that the sub-path is being closed.
@ lineTo
For this type, x1 and y1 indicate the end point of the line.
@ cubicTo
For this type, x1, y1, x2, y2, x3, y3 indicate the two control points and the endpoint of a cubic cur...
@ startNewSubPath
For this type, x1 and y1 will be set to indicate the first point in the subpath.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
void startNewSubPath(float startX, float startY)
Begins a new subpath with a given starting position.
void quadraticTo(float controlPointX, float controlPointY, float endPointX, float endPointY)
Adds a quadratic bezier curve from the shape's last position to a new position.
void cubicTo(float controlPoint1X, float controlPoint1Y, float controlPoint2X, float controlPoint2Y, float endPointX, float endPointY)
Adds a cubic bezier curve from the shape's last position to a new position.
Rectangle< float > getBoundsTransformed(const AffineTransform &transform) const noexcept
Returns the smallest rectangle that contains all points within the path after it's been transformed w...
void closeSubPath()
Closes a the current sub-path with a line back to its start-point.
Rectangle< float > getBounds() const noexcept
Returns the smallest rectangle that contains all points within the path.
void lineTo(float endX, float endY)
Adds a line from the shape's last position to a new end-point.
void swapWithPath(Path &) noexcept
Swaps the contents of this path with another one.
bool isEmpty() const noexcept
Returns true if the path doesn't contain any lines or curves.
Rectangle< int > getSmallestIntegerContainer() const noexcept
Returns the smallest integer-aligned rectangle that completely contains this one.
Rectangle expanded(ValueType deltaX, ValueType deltaY) const noexcept
Returns a rectangle that is larger than this one by a given amount.
bool containsWholeWordIgnoreCase(StringRef wordToLookFor) const noexcept
Tests whether the string contains another substring as a distinct word.
A typeface represents a size-independent font.
void applyVerticalHintingTransform(float fontHeight, Path &path)
Makes an attempt at performing a good overall distortion that will scale a font of the given size to ...
virtual bool getOutlineForGlyph(int glyphNumber, Path &path)=0
Returns the outline for a glyph.
const String & getName() const noexcept
Returns the font family of the typeface.
virtual EdgeTable * getEdgeTableForGlyph(int glyphNumber, const AffineTransform &transform, float fontHeight)
Returns a new EdgeTable that contains the path for the given glyph, with the specified transform appl...
ReferenceCountedObjectPtr< Typeface > Ptr
A handy typedef for a pointer to a typeface.
~Typeface() override
Destructor.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...