Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status color of glyphs #1342

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1e75438
Adding status color visualization
ollimeier May 7, 2024
fbd8e33
Be as close as possible to the briefing (undo use of constants)
ollimeier May 7, 2024
d526504
Update src/fontra/views/editor/visualization-layer-definitions.js
ollimeier May 8, 2024
c877550
Update src/fontra/views/editor/visualization-layer-definitions.js
ollimeier May 8, 2024
0c74175
add opacity for editing glyph + thickness with clamp
ollimeier May 8, 2024
ad8ac39
Add isEditing boolean property to positionedGlyph, so visualization l…
justvanrossum May 8, 2024
02d7e59
Also add isSelected flag
justvanrossum May 8, 2024
8aea55a
Merge pull request #1345 from googlefonts/add-edit-status-to-position…
justvanrossum May 8, 2024
d2af79b
Adding status color visualization
ollimeier May 7, 2024
63a6138
Be as close as possible to the briefing (undo use of constants)
ollimeier May 7, 2024
422c312
Update src/fontra/views/editor/visualization-layer-definitions.js
ollimeier May 8, 2024
97674e6
Update src/fontra/views/editor/visualization-layer-definitions.js
ollimeier May 8, 2024
50111e0
add opacity for editing glyph + thickness with clamp
ollimeier May 8, 2024
fcb6cc8
Revert "add opacity for editing glyph + thickness with clamp"
ollimeier May 9, 2024
20c094e
First fix unittest for rgbaToCSS: alpha must be between 0.0 and 1.0
ollimeier May 9, 2024
d49d5de
Fix rgbaToCSS
ollimeier May 9, 2024
f888355
clone array status color and use new positionedGlyph.isEditing for op…
ollimeier May 9, 2024
934a3e0
use min and maxThickness with clamp
ollimeier May 9, 2024
27d8daf
Merge branch 'issue-926-status-colour-glyphs' of https://github.com/g…
ollimeier May 9, 2024
bd6cfd3
Removing rgbaToFillStyle: something went wrong with the merge conflict.
ollimeier May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/fontra/client/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,10 @@ export function arrayExtend(thisArray, itemsArray) {
}

export function rgbaToCSS(rgba) {
const channels = rgba.map((channel) => Math.round(channel * 255));
if (channels[3] == 255) {
channels.pop();
const channels = rgba.slice(0, 3).map((channel) => Math.round(channel * 255));
const alpha = rgba.length === 4 ? rgba[3] : undefined;
ollimeier marked this conversation as resolved.
Show resolved Hide resolved
if (alpha !== undefined && 0 <= alpha && alpha < 1) {
channels.push(alpha);
}
return `${channels.length === 4 ? "rgba" : "rgb"}(${channels.join(",")})`;
}
Expand Down
18 changes: 11 additions & 7 deletions src/fontra/views/editor/scene-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,11 @@ export class SceneModel {
const fontController = this.fontController;
const glyphLines = this.glyphLines;
const align = this.sceneSettings.align;
const { lineIndex: selectedLineIndex, glyphIndex: selectedGlyphIndex } =
this.selectedGlyph || {};
const {
lineIndex: selectedLineIndex,
glyphIndex: selectedGlyphIndex,
isEditing: selectedGlyphIsEditing,
} = this.selectedGlyph || {};
const editLayerName = this.sceneSettings.editLayerName;

let y = 0;
Expand All @@ -358,12 +361,11 @@ export class SceneModel {
const positionedLine = { glyphs: [] };
let x = 0;
for (const [glyphIndex, glyphInfo] of enumerate(glyphLine)) {
const isSelectedGlyph =
lineIndex == selectedLineIndex && glyphIndex == selectedGlyphIndex;

const thisGlyphEditLayerName =
editLayerName &&
lineIndex == selectedLineIndex &&
glyphIndex == selectedGlyphIndex
? editLayerName
: undefined;
editLayerName && isSelectedGlyph ? editLayerName : undefined;

const varGlyph = await this.fontController.getGlyph(glyphInfo.glyphName);
let glyphInstance = await this.getGlyphInstance(
Expand All @@ -384,6 +386,8 @@ export class SceneModel {
glyphName: glyphInfo.glyphName,
character: glyphInfo.character,
isUndefined: isUndefined,
isSelected: isSelectedGlyph,
isEditing: !!(isSelectedGlyph && selectedGlyphIsEditing),
});
x += glyphInstance.xAdvance;
}
Expand Down
51 changes: 51 additions & 0 deletions src/fontra/views/editor/visualization-layer-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { subVectors } from "../core/vector.js";
import { decomposedToTransform } from "/core/transform.js";
import {
chain,
clamp,
enumerate,
makeUPlusStringFromCodePoint,
parseSelection,
rgbaToCSS,
round,
unionIndexSets,
withSavedState,
Expand Down Expand Up @@ -1020,6 +1022,55 @@ registerVisualizationLayerDefinition({
},
});

registerVisualizationLayerDefinition({
identifier: "fontra.status.color",
name: "Status color",
selectionMode: "all",
userSwitchable: true,
defaultOn: false,
zIndex: 100,
screenParameters: {
minThickness: 3,
maxThickness: 15,
},
draw: (context, positionedGlyph, parameters, model, controller) => {
const statusFieldDefinitions =
model.fontController.customData["fontra.sourceStatusFieldDefinitions"];
if (!statusFieldDefinitions) {
return;
}

const sourceIndex = positionedGlyph.glyph.sourceIndex;
if (sourceIndex === undefined) {
return;
}

const status =
positionedGlyph.varGlyph.sources[sourceIndex].customData[
"fontra.development.status"
];
if (status === undefined) {
return;
}

const color = [...statusFieldDefinitions[status].color];
if (positionedGlyph.isEditing) {
// in editing mode make opacity 50%
color[3] = color[3] * 0.5;
ollimeier marked this conversation as resolved.
Show resolved Hide resolved
}

const thickness = clamp(
0.05 * model.fontController.unitsPerEm,
parameters.minThickness,
parameters.maxThickness
);
context.fillStyle = rgbaToCSS(color);
context.beginPath();
ollimeier marked this conversation as resolved.
Show resolved Hide resolved
context.rect(0, -100 - thickness, positionedGlyph.glyph.xAdvance, thickness);
context.fill();
},
});

registerVisualizationLayerDefinition({
identifier: "fontra.edit.background.layers",
name: "Background glyph layers",
Expand Down
2 changes: 1 addition & 1 deletion test-js/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe("rgbaToCSS", () => {
});
it("should convert an array of decimals to rgba string", () => {
expect(rgbaToCSS([0, 0, 0, 0])).to.be.equal("rgba(0,0,0,0)");
expect(rgbaToCSS([0, 0, 0, 0.2])).to.be.equal("rgba(0,0,0,51)");
expect(rgbaToCSS([0, 0, 0, 0.2])).to.be.equal("rgba(0,0,0,0.2)");
});
it("should always create rgb if the opacity is 1", () => {
expect(rgbaToCSS([0, 0, 0, 1])).to.be.equal("rgb(0,0,0)");
Expand Down