Further improve Ot name derivation
This commit is contained in:
parent
6c8233937f
commit
1babc986cd
4 changed files with 53 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
||||||
const { Joining } = require("../../support/gr");
|
const { Joining, AnyCv, TieMark } = require("../../support/gr");
|
||||||
|
|
||||||
const ApplePostNames = new Map([
|
const ApplePostNames = new Map([
|
||||||
/* spell-checker: disable */
|
/* spell-checker: disable */
|
||||||
|
@ -261,7 +261,7 @@ const ApplePostNames = new Map([
|
||||||
/* spell-checker: enable */
|
/* spell-checker: enable */
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function nameSingleGlyph(gid, gSrc, primaryUnicode, conflictSet) {
|
function nameSingleGlyph1(gid, gSrc, primaryUnicode, conflictSet) {
|
||||||
if (gid === 0) return ".notdef";
|
if (gid === 0) return ".notdef";
|
||||||
if (gid === 1) return ".null";
|
if (gid === 1) return ".null";
|
||||||
|
|
||||||
|
@ -272,11 +272,7 @@ function nameSingleGlyph(gid, gSrc, primaryUnicode, conflictSet) {
|
||||||
}
|
}
|
||||||
if (preferredName && !conflictSet.has(preferredName)) {
|
if (preferredName && !conflictSet.has(preferredName)) {
|
||||||
conflictSet.add(preferredName);
|
conflictSet.add(preferredName);
|
||||||
} else {
|
|
||||||
preferredName = `.gid${gid}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
preferredName = Joining.amendOtName(preferredName, Joining.get(gSrc));
|
|
||||||
return preferredName;
|
return preferredName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,4 +280,31 @@ function formatCodePointHex(u) {
|
||||||
return u.toString(16).padStart(4, "0").toUpperCase();
|
return u.toString(16).padStart(4, "0").toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.nameSingleGlyph = nameSingleGlyph;
|
function nameSingleGlyph2(gSrcBase, baseName, internalNameMap, conflictSet) {
|
||||||
|
if (!baseName) return;
|
||||||
|
for (const cv of AnyCv.query(gSrcBase)) {
|
||||||
|
nameByGr(cv, gSrcBase, baseName, internalNameMap, conflictSet);
|
||||||
|
}
|
||||||
|
if (TieMark.get(gSrcBase)) {
|
||||||
|
nameByGr(TieMark, gSrcBase, baseName, internalNameMap, conflictSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function nameByGr(gr, gSrcBase, baseName, internalNameMap, conflictSet) {
|
||||||
|
const gnDst = gr.get(gSrcBase);
|
||||||
|
const gOtDst = internalNameMap.get(gnDst);
|
||||||
|
const nameT = gr.amendOtName(baseName);
|
||||||
|
if (gOtDst && !gOtDst.name && !conflictSet.has(nameT)) {
|
||||||
|
conflictSet.add(nameT);
|
||||||
|
gOtDst.name = nameT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function nameSingleGlyph3(gid, gSrc, gnOrig) {
|
||||||
|
if (!gnOrig) gnOrig = `.gid${gid}`;
|
||||||
|
gnOrig = Joining.amendOtName(gnOrig, Joining.get(gSrc));
|
||||||
|
return gnOrig;
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.nameSingleGlyph1 = nameSingleGlyph1;
|
||||||
|
exports.nameSingleGlyph2 = nameSingleGlyph2;
|
||||||
|
exports.nameSingleGlyph3 = nameSingleGlyph3;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const { Ot } = require("ot-builder");
|
const { Ot } = require("ot-builder");
|
||||||
const Point = require("../../support/point");
|
const Point = require("../../support/point");
|
||||||
const { nameSingleGlyph } = require("./glyph-name");
|
const { nameSingleGlyph1, nameSingleGlyph2, nameSingleGlyph3 } = require("./glyph-name");
|
||||||
|
|
||||||
class MappedGlyphStore {
|
class MappedGlyphStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -48,8 +48,22 @@ class MappedGlyphStore {
|
||||||
let conflictSet = new Set();
|
let conflictSet = new Set();
|
||||||
let rev = new Map();
|
let rev = new Map();
|
||||||
for (const [u, g] of this.m_primaryUnicodeMapping) rev.set(g, u);
|
for (const [u, g] of this.m_primaryUnicodeMapping) rev.set(g, u);
|
||||||
|
for (const [gSrc, gOt] of this.m_mapping) gOt.name = undefined;
|
||||||
|
|
||||||
|
// Name by Unicode
|
||||||
|
gid = 0;
|
||||||
for (const [gSrc, gOt] of this.m_mapping) {
|
for (const [gSrc, gOt] of this.m_mapping) {
|
||||||
gOt.name = nameSingleGlyph(gid, gSrc, rev.get(gSrc), conflictSet);
|
gOt.name = nameSingleGlyph1(gid, gSrc, rev.get(gSrc), conflictSet);
|
||||||
|
gid++;
|
||||||
|
}
|
||||||
|
// Name by CV
|
||||||
|
for (const [gSrcBase, gOtBase] of this.m_mapping) {
|
||||||
|
nameSingleGlyph2(gSrcBase, gOtBase.name, this.m_nameMapping, conflictSet);
|
||||||
|
}
|
||||||
|
// Name rest
|
||||||
|
gid = 0;
|
||||||
|
for (const [gSrc, gOt] of this.m_mapping) {
|
||||||
|
gOt.name = nameSingleGlyph3(gid, gSrc, gOt.name);
|
||||||
gid++;
|
gid++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,4 +331,4 @@ glyph-block Letter-Latin-Z : begin
|
||||||
CreateAccentedComposition 'zBar' 0x1B6 'z/reduced' 'barOver'
|
CreateAccentedComposition 'zBar' 0x1B6 'z/reduced' 'barOver'
|
||||||
CreateAccentedComposition 'ZCaron' 0x17D 'Z' 'caronAbove'
|
CreateAccentedComposition 'ZCaron' 0x17D 'Z' 'caronAbove'
|
||||||
CreateAccentedComposition 'zCaron' 0x17E 'z' 'caronAbove'
|
CreateAccentedComposition 'zCaron' 0x17E 'z' 'caronAbove'
|
||||||
CreateAccentedComposition 'zRTailBR' 0x290 'z/rtailBase' 'rtailBR'
|
derive-composites 'zRTailBR' 0x290 'z/rtailBase' 'rtailBR'
|
||||||
|
|
|
@ -72,6 +72,9 @@ const TieMark = {
|
||||||
},
|
},
|
||||||
amendName(name) {
|
amendName(name) {
|
||||||
return `TieMark{${name}}`;
|
return `TieMark{${name}}`;
|
||||||
|
},
|
||||||
|
amendOtName(name) {
|
||||||
|
return name + ".tieMark";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -167,6 +170,9 @@ function Cv(tag, rank) {
|
||||||
},
|
},
|
||||||
amendName(name) {
|
amendName(name) {
|
||||||
return name + "." + key;
|
return name + "." + key;
|
||||||
|
},
|
||||||
|
amendOtName(name) {
|
||||||
|
return name + "." + tag + "-" + rank;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
CvTagCache.set(key, rel);
|
CvTagCache.set(key, rel);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue