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 5 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
16 changes: 16 additions & 0 deletions src/fontra/client/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,22 @@ export function rgbaToCSS(rgba) {
return `${channels.length === 4 ? "rgba" : "rgb"}(${channels.join(",")})`;
}

// according to the documentation, the alpha value must be a value
// between 0.0 and 1.0, why it's not possible to use rgbaToCSS
// more: https://doc.qt.io/qt-5/qml-qtquick-context2d.html#fillStyle-prop
ollimeier marked this conversation as resolved.
Show resolved Hide resolved
export function rgbaToFillStyle(rgba) {
let alpha = undefined;
if (rgba.length === 4) {
alpha = rgba[3];
rgba.pop();
}
const channels = rgba.map((channel) => Math.round(channel * 255));
if (alpha !== undefined && alpha != 1) {
channels.push(alpha);
}
return `${channels.length === 4 ? "rgba" : "rgb"}(${channels.join(",")})`;
}

export function clamp(number, min, max) {
return Math.max(Math.min(number, max), min);
}
Expand Down
56 changes: 56 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,
rgbaToFillStyle,
round,
unionIndexSets,
withSavedState,
Expand Down Expand Up @@ -1020,6 +1022,60 @@ registerVisualizationLayerDefinition({
},
});

registerVisualizationLayerDefinition({
identifier: "fontra.status.color",
name: "Status color",
selectionMode: "editing",
userSwitchable: true,
defaultOn: false,
zIndex: 100,
screenParameters: { thickness: 20 },
colors: { opacity: 0.5 },
draw: _drawStatusColor,
});

registerVisualizationLayerDefinition({
identifier: "fontra.status.color.non-editing",
name: "Status color for non-editing glyphs",
selectionMode: "notediting",
userSwitchable: true,
defaultOn: false,
zIndex: 100,
screenParameters: { thickness: 20 },
colors: { opacity: 1.0 },
draw: _drawStatusColor,
});

function _drawStatusColor(context, positionedGlyph, parameters, model, controller) {
parameters.opacity;
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 thickness = clamp(parameters.thickness, 20, 150);
let color = statusFieldDefinitions[status].color;
color[3] = parameters.opacity;
ollimeier marked this conversation as resolved.
Show resolved Hide resolved
context.fillStyle = rgbaToFillStyle(color);
context.beginPath();
context.rect(0, -100 - thickness, positionedGlyph.glyph.xAdvance, thickness);
context.fill();
}

registerVisualizationLayerDefinition({
identifier: "fontra.edit.background.layers",
name: "Background glyph layers",
Expand Down
17 changes: 17 additions & 0 deletions test-js/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
reversed,
reversedEnumerate,
rgbaToCSS,
rgbaToFillStyle,
round,
scheduleCalls,
splitGlyphNameExtension,
Expand Down Expand Up @@ -371,6 +372,22 @@ describe("rgbaToCSS", () => {
});
});

describe("rgbaToFillStyle", () => {
it("should convert an array of decimals to rgb string", () => {
expect(rgbaToFillStyle([0, 0, 0])).to.be.equal("rgb(0,0,0)");
expect(rgbaToFillStyle([0, 1, 0])).to.be.equal("rgb(0,255,0)");
expect(rgbaToFillStyle([1, 0, 0, 1])).to.be.equal("rgb(255,0,0)");
});
it("should convert an array of decimals to rgba string", () => {
expect(rgbaToFillStyle([0, 0, 0, 0])).to.be.equal("rgba(0,0,0,0)");
expect(rgbaToFillStyle([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(rgbaToFillStyle([0, 0, 0, 1])).to.be.equal("rgb(0,0,0)");
expect(rgbaToFillStyle([0, 0, 0, 1.0])).to.be.equal("rgb(0,0,0)");
});
});

describe("clamp", () => {
it("should give the minimum when the number is below the range", () => {
expect(clamp(10, 50, 80)).equals(50);
Expand Down