diff --git a/modules/juce_graphics/fonts/juce_Typeface.cpp b/modules/juce_graphics/fonts/juce_Typeface.cpp index 174c2df20f..7457503b5f 100644 --- a/modules/juce_graphics/fonts/juce_Typeface.cpp +++ b/modules/juce_graphics/fonts/juce_Typeface.cpp @@ -807,6 +807,15 @@ std::vector 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(); } diff --git a/modules/juce_graphics/fonts/juce_Typeface.h b/modules/juce_graphics/fonts/juce_Typeface.h index 6e1a7f8f48..7a0917b1f4 100644 --- a/modules/juce_graphics/fonts/juce_Typeface.h +++ b/modules/juce_graphics/fonts/juce_Typeface.h @@ -212,6 +212,36 @@ public: */ std::vector 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);