opentype.js icon indicating copy to clipboard operation
opentype.js copied to clipboard

Chinese .ttf fonts failing with one of two errors

Open dhowe opened this issue 7 years ago • 6 comments

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>

fonts.zip

dhowe avatar Apr 18 '17 12:04 dhowe

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.

fdb avatar Apr 25 '17 12:04 fdb

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

dhowe avatar Apr 26 '17 02:04 dhowe

With the introduction of CID-keyed fonts, a lot more of them should now work, although some still miss the correct cmap parsing.

fdb avatar Apr 26 '17 09:04 fdb

I have also encountered this situation. Is it resolved now? 1.TTF.zip

weiyunpeng avatar Feb 24 '20 10:02 weiyunpeng

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.

antony-hk avatar Feb 24 '20 16:02 antony-hk

heiti.ttf and DFBK1B.TTF already work with the current master, 1.TTF will work as soon as #648 will be implemented

Connum avatar Nov 27 '23 00:11 Connum