reset fontvariationaxes on font change

This commit is contained in:
jrkb 2023-10-24 07:42:29 +02:00
parent ab3786ef23
commit 2d55ef11b0

View file

@ -101,6 +101,7 @@ const Layer = function(tp, layerID, fontsAndAxes, autoInit = true) {
let axes = fontsAndAxes[selectedFontIndex].axes; let axes = fontsAndAxes[selectedFontIndex].axes;
if (axes.length > 0) { if (axes.length > 0) {
let variationAxes = {}; let variationAxes = {};
let doThese = [];
for (let a = 0; a < axes.length; a++) { for (let a = 0; a < axes.length; a++) {
const sanity_minMax = axes[a].minValue < axes[a].maxValue; const sanity_minMax = axes[a].minValue < axes[a].maxValue;
const sanity_minDefault = axes[a].minValue <= axes[a].defaultValue; const sanity_minDefault = axes[a].minValue <= axes[a].defaultValue;
@ -109,11 +110,27 @@ const Layer = function(tp, layerID, fontsAndAxes, autoInit = true) {
variationAxes[axes[a].name] = tp.core.types.number(axes[a].defaultValue, { variationAxes[axes[a].name] = tp.core.types.number(axes[a].defaultValue, {
range: [axes[a].minValue, axes[a].maxValue], range: [axes[a].minValue, axes[a].maxValue],
}); });
if (typeof audio === 'object' &&
typeof audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`] === 'object' &&
typeof audio.getMapping()[this.id()][`fontVariationAxes.${axes[a].name}`] === 'object' &&
tp.getPanel() !== null) {
doThese.push(() => {
audio.removeAudioOptions(this, `fontVariationAxes.${axes[a].name}`);
audio.removeAudioMapping(this, `fontVariationAxes.${axes[a].name}`);
audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`].min_out = axes[a].minValue;
audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`].max_out = axes[a].maxValue;
audio.addAudioMapping(this, `fontVariationAxes.${axes[a].name}`);
audio.addAudioOptions(this, `fontVariationAxes.${axes[a].name}`);
});
}
} else { } else {
console.log('js::layer::selectFont', 'this axis is insane, abort', axes[a]); console.log('js::layer::selectFont', 'this axis is insane, abort', axes[a]);
} }
} }
props.fontVariationAxes = tp.core.types.compound(variationAxes); props.fontVariationAxes = tp.core.types.compound(variationAxes);
doThese.forEach((d) => {
d();
});
} else { } else {
delete props.fontVariationAxes; delete props.fontVariationAxes;
} }