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

Steps towards background layers #1781

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
da67da8
First UI stubs for background layers
justvanrossum Oct 19, 2024
1d445b7
Only show layers list in edit mode
justvanrossum Oct 19, 2024
d79b8ed
Factor out updating of the layers list; ensure it is hidden when not …
justvanrossum Oct 20, 2024
119c8cf
Add helper method to retrieve (background) layer names for a source
justvanrossum Oct 20, 2024
ff654f9
Steps towards computing a layer names list
justvanrossum Oct 20, 2024
a93de44
Also rebuild scene if the edit layer changes
justvanrossum Oct 21, 2024
1219ea7
Use object for layer list items; switch edit layer on layer list sel …
justvanrossum Oct 21, 2024
ad8a771
Fix arg name
justvanrossum Oct 21, 2024
d55e755
Set editingLayers, this makes it work a little
justvanrossum Oct 21, 2024
73d87a2
Add missing await
justvanrossum Oct 21, 2024
4bfae39
Make changes to editLayerName trigger scene update
justvanrossum Oct 21, 2024
9e757aa
Use this.sources getter
justvanrossum Oct 21, 2024
bf5cf04
Rename method
justvanrossum Oct 21, 2024
9b1141b
Make getBackgroundLayerNamesForSourceIndex use a cache; add and use g…
justvanrossum Oct 21, 2024
c31537c
Rename method
justvanrossum Oct 21, 2024
2f6bc6a
Fix method name
justvanrossum Oct 21, 2024
3c186d9
Rename method
justvanrossum Oct 21, 2024
49bafb2
Move method
justvanrossum Oct 21, 2024
58188c5
Rename method
justvanrossum Oct 21, 2024
24a11cc
Rename method and property
justvanrossum Oct 21, 2024
72781bd
Fix accordeon item title; add todo comment
justvanrossum Oct 24, 2024
dbb5d20
Disable bg layers feature for now
justvanrossum Nov 12, 2024
44a83c6
Rename argument
justvanrossum Nov 12, 2024
0e7e5cd
Methods to find source index from location
justvanrossum Nov 25, 2024
40b5f3c
Use location string to idintify bg glyphs and edit glyphs
justvanrossum Nov 25, 2024
1bb6523
Fix 'view all bg layers'
justvanrossum Nov 25, 2024
cac78ef
Remove unused method
justvanrossum Nov 25, 2024
d174462
Add comment
justvanrossum Nov 25, 2024
1572bca
Rename method and change logic so it also returns the 'default' layer
justvanrossum Nov 25, 2024
8eb72d9
No need to add the foreground layer separately, just fill in a name
justvanrossum Nov 25, 2024
f24ce3e
backgroundLayersList -> sourceLayersList
justvanrossum Nov 25, 2024
e3f9ae2
Move background layers to scene settings
justvanrossum Nov 26, 2024
9bbfaaf
Move editingLayers to scene settings
justvanrossum Nov 26, 2024
56a36aa
Take locationBase into account when making loc string
justvanrossum Nov 26, 2024
b5a9a7c
Keep locationString as part of source item
justvanrossum Nov 26, 2024
39687cf
We have a var for layerName
justvanrossum Nov 26, 2024
c69a562
Subscribe to bg layer / editing layer changes, and update list items
justvanrossum Nov 26, 2024
0a9eb3b
Make the updating go via the editingLayers scene settings field inste…
justvanrossum Nov 26, 2024
1252631
Delete unused method
justvanrossum Nov 26, 2024
c238f37
Make the updating go via the editingLayers scene settings field inste…
justvanrossum Nov 26, 2024
997d6df
Rename property
justvanrossum Nov 26, 2024
b35d2ff
Rename variable
justvanrossum Nov 26, 2024
ddfd591
Make getSourceLayerNamesForSourceIndex return list of objects
justvanrossum Nov 26, 2024
8e87372
Don't mess with the editing layers if we're editing a bg layer
justvanrossum Nov 26, 2024
09a6efe
Fill in proper loc string when selecting bg layer
justvanrossum Nov 26, 2024
c423a09
Select the first item when switching sources
justvanrossum Nov 26, 2024
a7c9643
Rename methods to be more precise
justvanrossum Nov 26, 2024
1746b61
Slight simplification/optimization
justvanrossum Nov 26, 2024
dcb8e51
Keep edit layer info with undo record
justvanrossum Nov 27, 2024
283b967
Select the right source layer item
justvanrossum Nov 27, 2024
86b6bcb
Make edit layers persistent through in the URL fragment
justvanrossum Nov 27, 2024
237c755
Don't do things when there's no items
justvanrossum Nov 27, 2024
bad896d
Put 'select glyph/source/layer' menu items under submenu
justvanrossum Nov 27, 2024
bb266d7
Make --include-wip take an argument for further filtering
justvanrossum Nov 27, 2024
941f032
Add new UI strings
justvanrossum Nov 27, 2024
1459cbe
Add submenu title
justvanrossum Nov 27, 2024
a071c4f
Plug in select-next-source-layer functionality
justvanrossum Nov 27, 2024
9abce6c
Use altKey instead of shiftKey: shift-command-arrow key shifts by 100…
justvanrossum Nov 27, 2024
1878981
Don't crash on on-of-bounds point index
justvanrossum Nov 27, 2024
38e80e7
Merge French and Japanese additions
justvanrossum Nov 30, 2024
631a3c5
Merge main, resolving conflicts
justvanrossum Nov 30, 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
17 changes: 12 additions & 5 deletions scripts/rebuild_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ def main():
)
parser.add_argument(
"--include-wip",
action="store_true",
help="Include work-in-progress strings, as marked with 'WIP' in the the first column.",
help="Include work-in-progress strings that contain this argument "
"*and* the string 'WIP' in the the first column. The special string 'all' "
"matches all 'WIP' strings.",
)
args = parser.parse_args()
includeWorkInProgress = args.include_wip
includeWorkInProgressTag = args.include_wip
languageSpreadsheetURL = (
"https://docs.google.com/"
"spreadsheets/d/1woTU8dZCHJh7yvdk-N1kgQBUj4Sn3SdRsbKgn6ltJQs/"
Expand Down Expand Up @@ -108,8 +109,14 @@ def main():
languageStrings[languageCode] = strings = {}

for row in rows:
if "WIP" in row[0] and not includeWorkInProgress:
# Skip rows marked as work in progress
includeRow = "WIP" not in row[0] or (
includeWorkInProgressTag
and (
includeWorkInProgressTag == "all"
or includeWorkInProgressTag in row[0]
)
)
if not includeRow:
continue

key = row[1]
Expand Down
7 changes: 1 addition & 6 deletions src/fontra/client/core/font-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class FontController {
return;
}
const getGlyphFunc = this.getGlyph.bind(this);
return varGlyph.getLayerGlyphController(layerName, sourceIndex, getGlyphFunc);
return await varGlyph.getLayerGlyphController(layerName, sourceIndex, getGlyphFunc);
}

requestGlyphInstance(glyphName, sourceLocation) {
Expand Down Expand Up @@ -562,11 +562,6 @@ export class FontController {
return new StaticGlyphController(glyphName, dummyGlyph, undefined);
}

async getSourceIndex(glyphName, sourceLocation) {
const glyph = await this.getGlyph(glyphName);
return glyph?.getSourceIndex(sourceLocation);
}

addGlyphChangeListener(glyphName, listener) {
if (!this._glyphChangeListeners[glyphName]) {
this._glyphChangeListeners[glyphName] = [];
Expand Down
97 changes: 84 additions & 13 deletions src/fontra/client/core/glyph-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { addItemwise } from "./var-funcs.js";
import { StaticGlyph } from "./var-glyph.js";
import {
locationToString,
makeSparseLocation,
makeSparseNormalizedLocation,
mapAxesFromUserSpaceToSourceSpace,
normalizeLocation,
Expand All @@ -52,6 +53,9 @@ export class VariableGlyphController {
this._fontSources = fontSources;
this._locationToSourceIndex = {};
this._layerGlyphControllers = {};
this._layerNameToSourceIndex = {};
this._sourceIndexToSourceLayerNames = new Map();
this._locationStringToSourceIndex = null;
}

get name() {
Expand Down Expand Up @@ -157,14 +161,6 @@ export class VariableGlyphController {
return undefined;
}

getSourceIndexFromName(sourceName) {
for (const [sourceIndex, source] of enumerate(this.sources)) {
if (source.name === sourceName) {
return sourceIndex;
}
}
}

getAllComponentNames() {
// Return a set of all component names used by all layers of all sources
const componentNames = new Set();
Expand Down Expand Up @@ -196,6 +192,9 @@ export class VariableGlyphController {
delete this._fontAxesSourceSpace;
this._locationToSourceIndex = {};
this._layerGlyphControllers = {};
this._layerNameToSourceIndex = {};
this._sourceIndexToSourceLayerNames = new Map();
this._locationStringToSourceIndex = null;
}

get model() {
Expand Down Expand Up @@ -451,15 +450,18 @@ export class VariableGlyphController {
return instanceController;
}

getSourceLocationFromSourceIndex(sourceIndex) {
getDenseSourceLocationForSourceIndex(sourceIndex) {
return this.getDenseSourceLocationForSource(this.sources[sourceIndex]);
}

getDenseSourceLocationForSource(source) {
const fontDefaultLocation = makeDefaultLocation(this.fontAxesSourceSpace);
const glyphDefaultLocation = makeDefaultLocation(this.axes);
const defaultLocation = { ...fontDefaultLocation, ...glyphDefaultLocation };
const sourceLocation = this.getSourceLocation(this.sources[sourceIndex]);
return { ...defaultLocation, ...sourceLocation };
const sourceLocation = this.getSourceLocation(source);
return { ...fontDefaultLocation, ...glyphDefaultLocation, ...sourceLocation };
}

findNearestSourceFromSourceLocation(sourceLocation, skipInactive = false) {
findNearestSourceForSourceLocation(sourceLocation, skipInactive = false) {
sourceLocation = this.expandNLIAxes(sourceLocation);

// Ensure locations are *not* sparse
Expand All @@ -483,6 +485,75 @@ export class VariableGlyphController {
return sourceIndexMapping[nearestIndex];
}

getSourceIndexForLayerName(layerName) {
let sourceIndex = this._layerNameToSourceIndex[layerName];
if (sourceIndex === undefined) {
for (const i of range(this.sources.length)) {
const names = this.getSourceLayerNamesForSourceIndex(i);
const layerNames = names.map((layer) => layer.fullName);
if (layerNames.includes(layerName)) {
sourceIndex = i;
break;
}
}
}
return sourceIndex;
}

getSourceLayerNamesForSourceIndex(sourceIndex) {
let sourceLayerNames = this._sourceIndexToSourceLayerNames.get(sourceIndex);

if (!sourceLayerNames) {
const source = this.sources[sourceIndex];
this._layerNameToSourceIndex[source.layerName] = sourceIndex;

const layerNamePrefix = source.layerName + ".";
const layerNames = Object.keys(this.glyph.layers).filter(
(layerName) =>
layerName.startsWith(layerNamePrefix) &&
layerName.length > layerNamePrefix.length
);
layerNames.forEach((layerName) => {
this._layerNameToSourceIndex[layerName] = sourceIndex;
});
sourceLayerNames = [{ fullName: source.layerName, shortName: null }];
sourceLayerNames.push(
...layerNames.map((layerName) => ({
fullName: layerName,
shortName: layerName.slice(layerNamePrefix.length),
}))
);
this._sourceIndexToSourceLayerNames.set(sourceIndex, sourceLayerNames);
}

return sourceLayerNames;
}

getSourceIndexForSourceLocationString(sourceLocationString) {
if (!this._locationStringToSourceIndex) {
this._buildLocationStringToSourceIndexMapping();
}
return this._locationStringToSourceIndex[sourceLocationString];
}

_buildLocationStringToSourceIndexMapping() {
this._locationStringToSourceIndex = {};
for (const [sourceIndex, source] of enumerate(this.sources)) {
this._locationStringToSourceIndex[this.getSparseLocationStringForSource(source)] =
sourceIndex;
}
}

getSparseLocationStringForSource(source) {
return this.getSparseLocationStringForSourceLocation(
this.getSourceLocation(source)
);
}

getSparseLocationStringForSourceLocation(sourceLocation) {
return locationToString(makeSparseLocation(sourceLocation, this.combinedAxes));
}

expandNLIAxes(sourceLocation) {
return mapLocationExpandNLI(sourceLocation, this.axes);
}
Expand Down
3 changes: 3 additions & 0 deletions src/fontra/client/lang/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,13 @@ export const strings = {
"Entferne ausgewählten Glyphen von der Zeichenfläche",
"menubar.view.replace-selected-glyph-on-canvas":
"Ersetze ausgewählten Glyphen auf der Zeichenfläche",
"menubar.view.select-glyph-source-layer": "Select glyph/source/layer",
"menubar.view.select-next-glyph": "Nächster Glyph",
"menubar.view.select-next-source": "Nächste Source",
"menubar.view.select-next-source-layer": "Select next source layer",
"menubar.view.select-previous-glyph": "Vorheriger Glyph",
"menubar.view.select-previous-source": "Vorherige Source",
"menubar.view.select-previous-source-layer": "Select previous source layer",
"message.cancel-editing": "Jemand anderes hat vor dir etwas geändert.",
"message.edit-has-been-reverted": "Die Änderung wurde rückgängig gemacht.",
"message.glyph-could-not-be-saved": "Glyph konnte nicht gespeichert werden.",
Expand Down
3 changes: 3 additions & 0 deletions src/fontra/client/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,13 @@ export const strings = {
"menubar.view.find-glyphs-that-use": "Find glyphs that use '%0'",
"menubar.view.remove-selected-glyph-from-canvas": "Remove selected glyph from canvas",
"menubar.view.replace-selected-glyph-on-canvas": "Replace selected glyph on canvas",
"menubar.view.select-glyph-source-layer": "Select glyph/source/layer",
"menubar.view.select-next-glyph": "Select next glyph",
"menubar.view.select-next-source": "Select next source",
"menubar.view.select-next-source-layer": "Select next source layer",
"menubar.view.select-previous-glyph": "Select previous glyph",
"menubar.view.select-previous-source": "Select previous source",
"menubar.view.select-previous-source-layer": "Select previous source layer",
"message.cancel-editing": "Someone else made an edit just before you.",
"message.edit-has-been-reverted": "The edit has been reverted.",
"message.glyph-could-not-be-saved": "The glyph could not be saved.",
Expand Down
3 changes: 3 additions & 0 deletions src/fontra/client/lang/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,13 @@ export const strings = {
"Retirer le glyphe sélectionné du canvas",
"menubar.view.replace-selected-glyph-on-canvas":
"Remplacer le glyphe sélectionné du canvas",
"menubar.view.select-glyph-source-layer": "Select glyph/source/layer",
"menubar.view.select-next-glyph": "Sélectionner le prochain glyphe",
"menubar.view.select-next-source": "Sélectionner la source suivante ",
"menubar.view.select-next-source-layer": "Select next source layer",
"menubar.view.select-previous-glyph": "Sélectionner le glyphe précédente",
"menubar.view.select-previous-source": "Sélectionner la source précédente",
"menubar.view.select-previous-source-layer": "Select previous source layer",
"message.cancel-editing": "Quelqu'un d'autre a édité juste avant vous",
"message.edit-has-been-reverted": "L'édition a été annulé",
"message.glyph-could-not-be-saved": "Le glyphe n'a pas pu être enregistré",
Expand Down
3 changes: 3 additions & 0 deletions src/fontra/client/lang/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@ export const strings = {
"menubar.view.remove-selected-glyph-from-canvas": "エディターから選択グリフを削除",
"menubar.view.replace-selected-glyph-on-canvas":
"選択中のグリフを別のグリフに切り替え",
"menubar.view.select-glyph-source-layer": "グリフ/ソース/レイヤーを選択",
"menubar.view.select-next-glyph": "次のグリフを選択",
"menubar.view.select-next-source": "次のソースを選択",
"menubar.view.select-next-source-layer": "次のソースレイヤーを選択",
"menubar.view.select-previous-glyph": "前のグリフを選択",
"menubar.view.select-previous-source": "前のソースを選択",
"menubar.view.select-previous-source-layer": "前のソースレイヤーを選択",
"message.cancel-editing": "他のユーザーがあなたの直前に操作を行いました。",
"message.edit-has-been-reverted": "このグリフは前の状態に戻されました。",
"message.glyph-could-not-be-saved": "このグリフは保存されません。",
Expand Down
3 changes: 3 additions & 0 deletions src/fontra/client/lang/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,13 @@ export const strings = {
"Verwijder de geselecteerde glyph van het canvas",
"menubar.view.replace-selected-glyph-on-canvas":
"Vervang de geselecteerde glyph op het canvas",
"menubar.view.select-glyph-source-layer": "Select glyph/source/layer",
"menubar.view.select-next-glyph": "Select next glyph",
"menubar.view.select-next-source": "Selecteer de volgende source",
"menubar.view.select-next-source-layer": "Select next source layer",
"menubar.view.select-previous-glyph": "Select previous glyph",
"menubar.view.select-previous-source": "Selecteer de vorige source",
"menubar.view.select-previous-source-layer": "Select previous source layer",
"message.cancel-editing": "Someone else made an edit just before you.",
"message.edit-has-been-reverted": "The edit has been reverted.",
"message.glyph-could-not-be-saved": "The glyph could not be saved.",
Expand Down
3 changes: 3 additions & 0 deletions src/fontra/client/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,13 @@ export const strings = {
"menubar.view.find-glyphs-that-use": "寻找使用了 '%0' 的字形",
"menubar.view.remove-selected-glyph-from-canvas": "将选中字形从编辑区域中删除",
"menubar.view.replace-selected-glyph-on-canvas": "在编辑区域中替换选中字形",
"menubar.view.select-glyph-source-layer": "选择字形/源/图层",
"menubar.view.select-next-glyph": "选择下一个字形",
"menubar.view.select-next-source": "选择下一个源",
"menubar.view.select-next-source-layer": "选择下一个源图层",
"menubar.view.select-previous-glyph": "选择上一个字形",
"menubar.view.select-previous-source": "选择上一个源",
"menubar.view.select-previous-source-layer": "选择上一个源图层",
"message.cancel-editing": "有人在你之前做了编辑。",
"message.edit-has-been-reverted": "编辑将被复原。",
"message.glyph-could-not-be-saved": "该字形无法被保存。",
Expand Down
4 changes: 4 additions & 0 deletions src/fontra/views/editor/edit-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,11 @@ function unpackContours(path, selectedPointIndices) {
// when no points from this contour are selected, or an object with contour info,
const contours = new Array(path.contourInfo.length);
let contourIndex = 0;
const numPoints = path.numPoints;
for (const pointIndex of selectedPointIndices) {
if (pointIndex >= numPoints) {
break;
}
while (path.contourInfo[contourIndex].endPoint < pointIndex) {
contourIndex++;
}
Expand Down
Loading