opentype.js
opentype.js copied to clipboard
Chinese .ttf fonts failing with one of two errors
Uncaught Error: Only format 4 and 12 cmap tables are supported. or Uncaught TypeError: Cannot read property 'glyphIndexMap' of null
I suppose the first is an expected error.
Code here:
<html>
<head>
<meta charset="UTF-8">
<script src="lib/opentype.js"></script>
<script>
window.onload = function() {
opentype.load('fonts/font.ttf', function(err, font) {
if (err) {
alert('Font could not be loaded: ' + err);
} else {
var ctx = document.getElementById('canvas').getContext('2d');
var path = font.getPath('Hello, World!', 0, 100, 22);
path.draw(ctx);
}
});
}
</script>
</head>
<body>
<canvas id="canvas" style="width: 600px"></canvas>
</body>
</html>
Both errors have to do with unsupported cmap
tables.
- The
DFBK1B.TTF
font file has a supported cmap sub-table, but with an unsupported format 0. - The
heiti.ttf
font file only has a Unicode sub-table (PlatformID 0 EncodingId 3), which we do not support.
I'm not sure about supporting format 0 as used by DFBK1B.TTF
, since it can only encode 255 characters and seems not to be used very often.
The Unicode platform is something we should support, as more fonts are using this, including some built-in fonts on OS X.
Indeed, unicode support would be great. We had significant difficulty getting any (of what we thought were) standard Chinese fonts on OS X to work with opentype
With the introduction of CID-keyed fonts, a lot more of them should now work, although some still miss the correct cmap parsing.
I have also encountered this situation. Is it resolved now? 1.TTF.zip
I have also encountered this situation. Is it resolved now? 1.TTF.zip
This is a font without any Unicode cmap
tables (platform ID 3 encoding ID 3). Seems the library will not support it at this moment, but I would like to try to make it work for this library.
heiti.ttf
and DFBK1B.TTF
already work with the current master, 1.TTF
will work as soon as #648 will be implemented