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,19 +101,36 @@ const Layer = function(tp, layerID, fontsAndAxes, autoInit = true) {
let axes = fontsAndAxes[selectedFontIndex].axes;
if (axes.length > 0) {
let variationAxes = {};
let doThese = [];
for (let a = 0; a < axes.length; a++) {
const sanity_minMax = axes[a].minValue < axes[a].maxValue;
const sanity_minDefault = axes[a].minValue <= axes[a].defaultValue;
const sanity_maxDefault = axes[a].maxValue >= axes[a].defaultValue;
if (sanity_minMax && sanity_minDefault && sanity_maxDefault) {
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 {
console.log('js::layer::selectFont', 'this axis is insane, abort', axes[a]);
}
}
props.fontVariationAxes = tp.core.types.compound(variationAxes);
doThese.forEach((d) => {
d();
});
} else {
delete props.fontVariationAxes;
}