Skip to content

Commit

Permalink
implement support and tests for cmap format 13 (#647)
Browse files Browse the repository at this point in the history
* implement support and tests for cmap format 13

* stop tracking of dist files
  • Loading branch information
Connum authored Nov 24, 2023
1 parent 820373a commit a6d0a75
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 29,470 deletions.
14,737 changes: 0 additions & 14,737 deletions dist/opentype.js

This file was deleted.

2 changes: 0 additions & 2 deletions dist/opentype.js.map

This file was deleted.

14,720 changes: 0 additions & 14,720 deletions dist/opentype.module.js

This file was deleted.

2 changes: 0 additions & 2 deletions dist/opentype.module.js.map

This file was deleted.

16 changes: 10 additions & 6 deletions src/tables/cmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function parseCmapTableFormat0(cmap, p, platformID, encodingID) {
cmap.glyphIndexMap = glyphIndexMap;
}

function parseCmapTableFormat12(cmap, p) {
function parseCmapTableFormat12or13(cmap, p, format) {
//Skip reserved.
p.parseUShort();

Expand All @@ -43,7 +43,9 @@ function parseCmapTableFormat12(cmap, p) {

for (let c = startCharCode; c <= endCharCode; c += 1) {
cmap.glyphIndexMap[c] = startGlyphId;
startGlyphId++;
if (format === 12) {
startGlyphId++;
}
}
}
}
Expand Down Expand Up @@ -171,11 +173,13 @@ function parseCmapTable(data, start) {
let offset = -1;
let platformId = null;
let encodingId = null;
const platform0Encodings = [0,1,2,3,4,6];
const platform3Encodings = [0,1,10];
for (let i = cmap.numTables - 1; i >= 0; i -= 1) {
platformId = parse.getUShort(data, start + 4 + (i * 8));
encodingId = parse.getUShort(data, start + 4 + (i * 8) + 2);
if ((platformId === 3 && (encodingId === 0 || encodingId === 1 || encodingId === 10)) ||
(platformId === 0 && (encodingId === 0 || encodingId === 1 || encodingId === 2 || encodingId === 3 || encodingId === 4)) ||
if ((platformId === 3 && platform3Encodings.includes(encodingId)) ||
(platformId === 0 && platform0Encodings.includes(encodingId)) ||
(platformId === 1 && encodingId === 0) // MacOS <= 9
) {
offset = parse.getULong(data, start + 4 + (i * 8) + 4);
Expand Down Expand Up @@ -203,8 +207,8 @@ function parseCmapTable(data, start) {

if (cmap.format === 0) {
parseCmapTableFormat0(cmap, p, platformId, encodingId);
} else if (cmap.format === 12) {
parseCmapTableFormat12(cmap, p);
} else if (cmap.format === 12 || cmap.format === 13) {
parseCmapTableFormat12or13(cmap, p, cmap.format);
} else if (cmap.format === 4) {
parseCmapTableFormat4(cmap, p, data, start, offset);
} else {
Expand Down
10 changes: 7 additions & 3 deletions test/fonts/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ SourceSansPro-Regular.otf
SIL Open Font License, Version 1.1
https://www.fontsquirrel.com/license/source-sans-pro

TestCMAP13.otf
Copyright 2023 Unicode Inc. All rights reserved.
SIL Open Font License version 1.1 (OFL-1.1)
https://opensource.org/licenses/OFL-1.1

TestCMAP14.otf
Copyright 2016 Unicode Inc. All rights reserved.
Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0
https://github.com/unicode-org/text-rendering-tests/blob/main/LICENSE.md
SIL Open Font License
http://scripts.sil.org/OFL

TestCMAPMacTurkish.ttf
Copyright © 2016 by Unicode Inc.
Expand Down
Binary file added test/fonts/TestCMAP13.ttf
Binary file not shown.
11 changes: 11 additions & 0 deletions test/tables/cmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,15 @@ describe('tables/cmap.js', function() {
}
assert.deepEqual(glyphIds, expectedGlyphIds);
});

it('can parse CMAP table format 13', function() {
let font;
assert.doesNotThrow(function() {
font = loadSync('./test/fonts/TestCMAP13.ttf');
});
const testString = 'U\u13EF\u{1203C}\u{1FA00}';
const glyphIds = font.stringToGlyphIndexes(testString);
const expectedGlyphIds = [1,2,3,4];
assert.deepEqual(glyphIds, expectedGlyphIds);
});
});

0 comments on commit a6d0a75

Please sign in to comment.