Skip to content

Commit

Permalink
Now all mappings can be deleted (such that an avar-free font is compi…
Browse files Browse the repository at this point in the history
…led)
  • Loading branch information
Lorp committed May 20, 2024
1 parent 59056ee commit db47562
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions src/fencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,9 @@ function mappingsChanged(mode) {
gridLocations.push(gridLocation);
});
});

//
let avarBuf; // if this remains undefined, we didn’t create an avar table

// are there any mappings? (locs.length==1 means no mappings)
if (locs.length > 1) {
Expand Down Expand Up @@ -926,44 +929,45 @@ function mappingsChanged(mode) {
avar.ivsBuffer = new SamsaBuffer(ivsBufOversize.buffer, 0, ivsLength); // the ivsBuffer we use is a slice of ivsBufOversize

// write new avar table
const avarBuf = GLOBAL.font.tableEncoders.avar(GLOBAL.font, avar);
avarBuf = GLOBAL.font.tableEncoders.avar(GLOBAL.font, avar);


}

// create a new binary font
// create a new binary font
if (avarBuf)
GLOBAL.fontBuffer = exportFontWithTables(GLOBAL.font, { avar: avarBuf }); // we’re inserting an avar table with binary contents avarBuf
else
GLOBAL.fontBuffer = exportFontWithTables(GLOBAL.font, undefined, { avar: true }); // explicitly delete any avar table

// create a new SamsaFont from the binary font, so that we can create instances and detemine transformed tuples
const sf = new SamsaFont(GLOBAL.fontBuffer);

// connect the new font to the UI
GLOBAL.familyName = "Fencer-" + Math.random().toString(36).substring(7);
if (GLOBAL.fontFace)
document.fonts.delete(GLOBAL.fontFace);
GLOBAL.fontFace = new FontFace(GLOBAL.familyName, GLOBAL.fontBuffer.buffer);
document.fonts.add(GLOBAL.fontFace);
GLOBAL.fontFace.load().then(() => {
Qall(".render").forEach( renderEl => renderEl.style.fontFamily = GLOBAL.familyName );
});
// create a new SamsaFont from the binary font, so that we can create instances and detemine transformed tuples
const sf = new SamsaFont(GLOBAL.fontBuffer);

// create an instance for each location, in order to gets its normalized tuple
const locations = [GLOBAL.current, ...GLOBAL.instances];
locations.forEach((location, l) => {
const axisSettings = {};
GLOBAL.font.fvar.axes.forEach((axis, a) => axisSettings[axis.axisTag] = location[0][a]);
const si = new SamsaInstance(sf, axisSettings);
location[1] = denormalizeTuple(si.tuple);
});
// connect the new font to the UI
GLOBAL.familyName = "Fencer-" + Math.random().toString(36).substring(7);
if (GLOBAL.fontFace)
document.fonts.delete(GLOBAL.fontFace);
GLOBAL.fontFace = new FontFace(GLOBAL.familyName, GLOBAL.fontBuffer.buffer);
document.fonts.add(GLOBAL.fontFace);
GLOBAL.fontFace.load().then(() => {
Qall(".render").forEach( renderEl => renderEl.style.fontFamily = GLOBAL.familyName );
});

// modify the grid locations if there are mappings
gridLocations.forEach((location, l) => {
const axisSettings = {};
GLOBAL.font.fvar.axes.forEach((axis, a) => axisSettings[axis.axisTag] = location[0][a] );
const si = new SamsaInstance(sf, axisSettings);
const denorm = denormalizeTuple(si.tuple); // denormalize the tuple into axis values for the current[1] array
location[1] = [...denorm];
});

// update the location[1] values for a given array of location[0] values
function instantiateLocation(sf, location) {
const axisSettings = {};
GLOBAL.font.fvar.axes.forEach((axis, a) => axisSettings[axis.axisTag] = location[0][a]); // untransformed
const si = new SamsaInstance(sf, axisSettings); // si.tuple is the transformed normalized tuple
location[1] = denormalizeTuple(si.tuple); // transformed and denormalized tuple
}

// create an instance for each location, in order to gets its normalized tuple
const locations = [GLOBAL.current, ...GLOBAL.instances];
[...locations, ...gridLocations].forEach(location => instantiateLocation(sf, location));




// ok start redrawing the SVG
GLOBAL.svgEl.innerHTML = "";

Expand Down

0 comments on commit db47562

Please sign in to comment.