Skip to content

Commit

Permalink
Compute source contributions from delta weights and scalars (needs ve…
Browse files Browse the repository at this point in the history
…rification)
  • Loading branch information
justvanrossum committed Sep 17, 2023
1 parent a756a0f commit d7eabda
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/fontra/client/core/glyph-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
registerRepresentationFactory,
} from "./representation-cache.js";
import { Transform } from "./transform.js";
import { enumerate, makeAffineTransform, range } from "./utils.js";
import { enumerate, makeAffineTransform, range, reversedEnumerate } from "./utils.js";
import { StaticGlyph } from "./var-glyph.js";
import { addItemwise } from "./var-funcs.js";
import {
Expand Down Expand Up @@ -237,20 +237,30 @@ export class VariableGlyphController {

getInterpolationContributions(location) {
location = this.mapLocationGlobalToLocal(location);
const rawScalars = this.model.getScalars(
const scalars = this.model.getScalars(
normalizeLocation(location, this.combinedAxes)
);
const contributions = [...scalars];
for (const [i, weights] of reversedEnumerate(this.model.deltaWeights)) {
for (const [j, weight] of weights.entries()) {
if (j >= i) {
throw new Error("assert -- bad i/j indices");
}
contributions[j] -= contributions[i] * weight;
}
}
let sourceIndex = 0;
const scalars = [];
const orderedContributions = [];
for (const source of this.sources) {
if (source.inactive) {
scalars.push(null);
orderedContributions.push(null);
} else {
scalars.push(rawScalars[this.model.mapping[sourceIndex]]);
const value = contributions[this.model.mapping[sourceIndex]];
orderedContributions.push(value);
sourceIndex++;
}
}
return scalars;
return orderedContributions;
}

async getLayerGlyphController(layerName, sourceIndex, getGlyphFunc) {
Expand Down
3 changes: 2 additions & 1 deletion src/fontra/views/editor/panel-designspace-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,12 +963,13 @@ function interpolationContributionCell(item, colDesc) {
const rawValue = item[colDesc.key];
if (rawValue != null) {
let index;
index = Math.round(Math.sqrt(rawValue) * 4);
index = Math.round(Math.sqrt(Math.abs(rawValue)) * 4);
if (index === 0 && rawValue > 0) {
// Ensure non-zero has one "bar"
index = 1;
}
iconElement.src = interpolationContributionIconSources[index];
iconElement.style.color = rawValue < 0 ? "#F36" : null;
} else {
iconElement.src = "";
}
Expand Down

0 comments on commit d7eabda

Please sign in to comment.