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

Typeface: Add API to determine colour technologies used by fonts

This commit is contained in:
reuk 2024-03-13 15:02:04 +00:00
parent 6c4c78baac
commit b42fd71c9e
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
2 changed files with 39 additions and 0 deletions

View file

@ -807,6 +807,15 @@ std::vector<GlyphLayer> Typeface::getLayersForGlyph (int glyphNumber, const Affi
return std::move (context).getLayers();
}
int Typeface::getColourGlyphFormats() const
{
auto* face = hb_font_get_face (getNativeDetails().getFont());
return (hb_ot_color_has_png (face) ? colourGlyphFormatBitmap : 0)
| (hb_ot_color_has_svg (face) ? colourGlyphFormatSvg : 0)
| (hb_ot_color_has_layers (face) ? colourGlyphFormatCOLRv0 : 0)
| (hb_ot_color_has_paint (face) ? colourGlyphFormatCOLRv1 : 0);
}
float Typeface::getAscent() const { return getNativeDetails().getLegacyMetrics().getScaledAscent(); }
float Typeface::getDescent() const { return getNativeDetails().getLegacyMetrics().getScaledDescent(); }
float Typeface::getHeightToPointsFactor() const { return getNativeDetails().getLegacyMetrics().getHeightToPointsFactor(); }

View file

@ -212,6 +212,36 @@ public:
*/
std::vector<GlyphLayer> getLayersForGlyph (int glyphNumber, const AffineTransform&, float normalisedHeight) const;
/** Kinds of colour glyph format that may be implemented by a particular typeface.
Most typefaces are monochromatic, and do not support any colour formats.
Emoji fonts are likely to implement one or more colour font formats.
At this time, JUCE is able to render only bitmap and COLRv0 fonts.
If you allow users to customise fonts, you may wish to hide or otherwise prevent users from
selecting fonts that use unsupported colour formats.
*/
enum ColourGlyphFormat
{
colourGlyphFormatBitmap = 1 << 0, ///< The typeface includes glyphs represented as bitmaps (normally PNGs)
colourGlyphFormatSvg = 1 << 1, ///< The typeface includes glyphs represented as SVGs
colourGlyphFormatCOLRv0 = 1 << 2, ///< The typeface uses the COLRv0 format, with support for flat colours
colourGlyphFormatCOLRv1 = 1 << 3, ///< The typeface uses the COLRv1 format, with support for gradients and blending modes
};
/** Returns an int with bits set indicating the format of colour glyphs contained in the typeface.
If the typeface has no colour glyphs, no bits will be set. Otherwise, one or more bits will
be set depending on the format of the colour glyph information. You can use a bitwise-and
operation with the members of the ColourGlyphFormat enum to determine whether a particular
format is supported.
@code
const auto isMonochrome = typeface->getColourGlyphFormats() == 0;
const auto isSvg = (typeface->getColourGlyphFormats() & Typeface::colourGlyphFormatSvg) != 0;
const auto isSimpleColour = (typeface->getColourGlyphFormats() & (Typeface::colourGlyphFormatBitmap | Typeface::colourGlyphFormatCOLRv0)) != 0;
*/
int getColourGlyphFormats() const;
//==============================================================================
/** Changes the number of fonts that are cached in memory. */
static void setTypefaceCacheSize (int numFontsToCache);