Reduce the need of creating pre-baked composites
This commit is contained in:
parent
7fc538f4f0
commit
99c8687812
2 changed files with 46 additions and 44 deletions
|
@ -133,26 +133,36 @@ glyph-block AutoBuild-Accents : begin
|
||||||
set s_parts parts
|
set s_parts parts
|
||||||
return : create-glyph goalName code construction
|
return : create-glyph goalName code construction
|
||||||
|
|
||||||
|
define [NeedBuildMesh glyphName part0Name] : begin
|
||||||
|
define g : query-glyph glyphName
|
||||||
|
define part0 : query-glyph part0Name
|
||||||
|
if [not g] : return false
|
||||||
|
if [not part0] : return false
|
||||||
|
if [not : CvDecompose.get g] : return true
|
||||||
|
if [DotlessOrNot.query part0] : return true
|
||||||
|
return false
|
||||||
|
|
||||||
foreach [_id : items-of : Object.keys foundDecompositions] : do
|
foreach [_id : items-of : Object.keys foundDecompositions] : do
|
||||||
local { glyphName code parts } foundDecompositions.(_id)
|
local { glyphName code parts } foundDecompositions.(_id)
|
||||||
|
|
||||||
local result : RootGlyphProc glyphName code parts
|
local saved : RootGlyphProc glyphName code parts
|
||||||
if result : begin
|
if saved : begin
|
||||||
define part0Name : glyphStore.queryNameOf parts.0
|
define part0Name : glyphStore.queryNameOf parts.0
|
||||||
if (parts.0 != [query-glyph part0Name]) : throw : new Error "Unreachable"
|
if (parts.0 != [query-glyph part0Name]) : throw : new Error "Unreachable"
|
||||||
|
|
||||||
local dstTree {}
|
if [NeedBuildMesh glyphName part0Name] : begin
|
||||||
local targetNameMap {.}
|
local dstTree {}
|
||||||
set targetNameMap.(part0Name) glyphName
|
local targetNameMap {.}
|
||||||
local tree : getGrTree part0Name { DotlessOrNot AnyDerivingCv } query-glyph
|
set targetNameMap.(part0Name) glyphName
|
||||||
foreach [{gr origBase relBase} : items-of tree] : begin
|
local tree : getGrTree part0Name { DotlessOrNot AnyDerivingCv } query-glyph
|
||||||
local origGN targetNameMap.(origBase)
|
foreach [{gr origBase relBase} : items-of tree] : begin
|
||||||
if [not origGN] : throw : new Error 'Unreachable'
|
local origGN targetNameMap.(origBase)
|
||||||
local relGN : suggestMappedName targetNameMap relBase [gr.amendName origGN]
|
if [not origGN] : throw : new Error 'Unreachable'
|
||||||
local parts1 : parts.slice 0
|
local relGN : suggestMappedName targetNameMap relBase [gr.amendName origGN]
|
||||||
set parts1.0 : query-glyph relBase
|
local parts1 : parts.slice 0
|
||||||
if [not : query-glyph relGN] : RootGlyphProc relGN null parts1
|
set parts1.0 : query-glyph relBase
|
||||||
if [query-glyph origGN] : gr.set [query-glyph origGN] relGN
|
if [not : query-glyph relGN] : RootGlyphProc relGN null parts1
|
||||||
|
if [query-glyph origGN] : gr.set [query-glyph origGN] relGN
|
||||||
|
|
||||||
define customDecompositions : object
|
define customDecompositions : object
|
||||||
# Latvians use comma instead of cedillas in several letters.
|
# Latvians use comma instead of cedillas in several letters.
|
||||||
|
|
|
@ -85,18 +85,10 @@ module.exports = class Glyph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const newContours = this.includeGeometry(g, shift.x, shift.y);
|
this.includeGlyphImpl(g, shift.x, shift.y);
|
||||||
if (copyAnchors || g.isMarkSet) this.copyAnchors(g);
|
if (copyAnchors || g.isMarkSet) this.copyAnchors(g);
|
||||||
if (copyWidth && g.advanceWidth >= 0) this.advanceWidth = g.advanceWidth;
|
if (copyWidth && g.advanceWidth >= 0) this.advanceWidth = g.advanceWidth;
|
||||||
this.dependsOn(g);
|
this.dependsOn(g);
|
||||||
if (g._m_identifier && newContours && newContours.length) {
|
|
||||||
this.semanticInclusions.push({
|
|
||||||
glyph: g,
|
|
||||||
x: shift.x,
|
|
||||||
y: shift.y,
|
|
||||||
contours: newContours
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cloneFromGlyph(g) {
|
cloneFromGlyph(g) {
|
||||||
this.includeGlyph(g, true, true);
|
this.includeGlyph(g, true, true);
|
||||||
|
@ -113,12 +105,6 @@ module.exports = class Glyph {
|
||||||
this.avoidBeingComposite = g.avoidBeingComposite;
|
this.avoidBeingComposite = g.avoidBeingComposite;
|
||||||
}
|
}
|
||||||
|
|
||||||
includeGeometry(geom, shiftX, shiftY) {
|
|
||||||
if (!geom || !geom.contours || !geom.contours.length) return null;
|
|
||||||
if (this.includeGeometryAsTransparentReferences(geom, shiftX, shiftY)) return null;
|
|
||||||
return this.includeContours(geom.contours, shiftX, shiftY);
|
|
||||||
}
|
|
||||||
|
|
||||||
isPureComposite() {
|
isPureComposite() {
|
||||||
if (!this.semanticInclusions || !this.semanticInclusions.length) return false;
|
if (!this.semanticInclusions || !this.semanticInclusions.length) return false;
|
||||||
const origContourSet = new Set(this.contours);
|
const origContourSet = new Set(this.contours);
|
||||||
|
@ -133,22 +119,28 @@ module.exports = class Glyph {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
includeGeometryAsTransparentReferences(geom, shiftX, shiftY) {
|
includeGlyphImpl(g, shiftX, shiftY) {
|
||||||
if (!(geom instanceof Glyph && !geom._m_identifier)) return false;
|
if (g._m_identifier) {
|
||||||
if (!geom.isPureComposite()) return false;
|
this.includeGlyphComponentImpl(g, shiftX, shiftY);
|
||||||
|
} else {
|
||||||
for (const sr of geom.semanticInclusions) {
|
this.includeGeometry(g, shiftX, shiftY);
|
||||||
const cs = this.includeContours(sr.glyph.contours, sr.x + shiftX, sr.y + shiftY);
|
|
||||||
if (cs) {
|
|
||||||
this.semanticInclusions.push({
|
|
||||||
glyph: sr.glyph,
|
|
||||||
x: sr.x + shiftX,
|
|
||||||
y: sr.y + shiftY,
|
|
||||||
contours: cs
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
|
includeGlyphComponentImpl(g, shiftX, shiftY) {
|
||||||
|
const newContours = this.includeGeometry(g, shiftX, shiftY);
|
||||||
|
if (newContours && newContours.length) {
|
||||||
|
this.semanticInclusions.push({
|
||||||
|
glyph: g,
|
||||||
|
x: shiftX,
|
||||||
|
y: shiftY,
|
||||||
|
contours: newContours
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
includeGeometry(geom, shiftX, shiftY) {
|
||||||
|
if (!geom || !geom.contours || !geom.contours.length) return null;
|
||||||
|
return this.includeContours(geom.contours, shiftX, shiftY);
|
||||||
}
|
}
|
||||||
includeContours(contours, shiftX, shiftY) {
|
includeContours(contours, shiftX, shiftY) {
|
||||||
let newContours = [];
|
let newContours = [];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue