How it works
We test for color font support by rendering color glyphs to canvas, and then reading out the pixels to see if we have any color.
Older versions of Firefox, the first browser to support color fonts, had some bugs that needed to be circumvented. This was done by sticking the font in an SVG image, and then drawing that image on canvas. This is how ChromaCheck still works today.
How to use
chromacheck-min.js in your page and it'll add classes to the
html element for each supported color format:
chromacheck-svgif there's support for OpenType-SVG.
chromacheck-colrif there's support for COLR.
chromacheck-sbixif there's support for SBIX.
chromacheck-cbdtif there's support for CBDT/CBLC.
Take note that this test is async, so it can take a split millisecond before the classes are added.
- IE11 on Windows 8 will report false negatives because of a bug in drawing SVG to canvas in IE11.
- IE10 in Windows 8 will report false negatives because of a very strict security measure when drawing SVG to canvas.
- CBDT/CBLC might be reported as not being supported, because ChromaCheck checks for the implementation as described by the spec. A few implementations in the wild, specifically Chrome on Android, do support CBDT/CBLC, but only when implemented with the specs during the proposal phase instead of the final specs. More info.
The SVG-on-canvas method might be replaced or extended with a non-SVG method to address the SVG related issues. Likewise it'd be possible to include two CBDT/CBLC fonts to test with: one on the old specs, one one the new. If you have a need for that right now, check out the
ChromaCheck is released under the MIT license.