1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Typeface: Add getGlyphBounds

This commit is contained in:
attila 2024-03-12 18:57:03 +01:00 committed by reuk
parent a2c7f1ea37
commit ade5461de3
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
2 changed files with 20 additions and 0 deletions

View file

@ -413,6 +413,23 @@ void Typeface::getOutlineForGlyph (TypefaceMetricsKind kind, int glyphNumber, Pa
path.applyTransform (AffineTransform::scale (scale, -scale));
}
Rectangle<float> Typeface::getGlyphBounds (TypefaceMetricsKind kind, int glyphNumber) const
{
auto* font = getNativeDetails().getFont();
hb_glyph_extents_t extents{};
if (! hb_font_get_glyph_extents (font, (hb_codepoint_t) glyphNumber, &extents))
return {};
const auto native = getNativeDetails();
const auto metrics = native.getMetrics (kind);
const auto scale = metrics.getHeightToPointsFactor() / (float) hb_face_get_upem (hb_font_get_face (font));
return Rectangle { (float) extents.width, (float) extents.height }
.withPosition ((float) extents.x_bearing, (float) extents.y_bearing)
.transformedBy (AffineTransform::scale (scale).scaled (1.0f, -1.0f));
}
void Typeface::applyVerticalHintingTransform (float, Path&)
{
jassertfalse;

View file

@ -214,6 +214,9 @@ public:
*/
void getOutlineForGlyph (TypefaceMetricsKind, int glyphNumber, Path& path) const;
/** Returns glyph bounds, normalised to a font height of 1.0. */
Rectangle<float> getGlyphBounds (TypefaceMetricsKind, int glyphNumber) const;
/** @deprecated
Returns a new EdgeTable that contains the path for the given glyph, with the specified transform applied.