diff --git a/src/fontra/views/editor/scene-controller.js b/src/fontra/views/editor/scene-controller.js index 84ed08b02..870aa76ff 100644 --- a/src/fontra/views/editor/scene-controller.js +++ b/src/fontra/views/editor/scene-controller.js @@ -155,9 +155,16 @@ export class SceneController { this.sceneSettingsController.addKeyListener( ["selectedGlyph", "glyphLines"], (event) => { + const lines = this.sceneModel.positionedLines.map((line) => { + return line.glyphs.map((glyph) => ({ + character: glyph.character, + glyphName: glyph.glyphName, + isUndefined: glyph.isUndefined, + })); + }); this.sceneSettings.selectedGlyphName = getSelectedGlyphName( this.sceneSettings.selectedGlyph, - this.sceneSettings.glyphLines + lines ); }, true @@ -330,6 +337,7 @@ export class SceneController { case "editBegin": { const glyphController = this.sceneModel.getSelectedPositionedGlyph().glyph; + this.sceneModel.ghostPath = glyphController.flattenedPath2d; } break; @@ -829,6 +837,7 @@ export class SceneController { return; } const glyphName = this.sceneModel.getSelectedGlyphName(); + const varGlyph = await this.fontController.getGlyph(glyphName); const baseChangePath = ["glyphs", glyphName]; diff --git a/src/fontra/views/editor/scene-model.js b/src/fontra/views/editor/scene-model.js index 047058048..313c3b69a 100644 --- a/src/fontra/views/editor/scene-model.js +++ b/src/fontra/views/editor/scene-model.js @@ -91,17 +91,32 @@ export class SceneModel { if (!glyphSelection) { return undefined; } + return this.positionedLines[glyphSelection.lineIndex]?.glyphs[ glyphSelection.glyphIndex ]; } getSelectedGlyphInfo() { - return getSelectedGlyphInfo(this.selectedGlyph, this.glyphLines); + const lines = this.positionedLines.map((line) => { + return line.glyphs.map((glyph) => ({ + character: glyph.character, + glyphName: glyph.glyphName, + isUndefined: glyph.isUndefined, + })); + }); + return getSelectedGlyphInfo(this.selectedGlyph, lines); } getSelectedGlyphName() { - return getSelectedGlyphName(this.selectedGlyph, this.glyphLines); + const lines = this.positionedLines.map((line) => { + return line.glyphs.map((glyph) => ({ + character: glyph.character, + glyphName: glyph.glyphName, + isUndefined: glyph.isUndefined, + })); + }); + return getSelectedGlyphName(this.selectedGlyph, lines); } isSelectedGlyphLocked() { @@ -349,10 +364,12 @@ export class SceneModel { glyphIndex: selectedGlyphIndex, isEditing: selectedGlyphIsEditing, } = this.selectedGlyph || {}; + const editLayerName = this.sceneSettings.editLayerName; let y = 0; const lineDistance = 1.1 * fontController.unitsPerEm; // TODO make factor user-configurable + const maxLineLength = 12 * fontController.unitsPerEm; // TODO make factor user-configurable const positionedLines = []; let longestLineLength = 0; @@ -374,7 +391,12 @@ export class SceneModel { return; } - for (const [lineIndex, glyphLine] of enumerate(glyphLines)) { + const stack = [...glyphLines].reverse(); + + let lineIndex = -1; + while (stack.length > 0) { + lineIndex += 1; + const glyphLine = stack.pop(); const positionedLine = { glyphs: [] }; let x = 0; for (const [glyphIndex, glyphInfo] of enumerate(glyphLine)) { @@ -400,6 +422,11 @@ export class SceneModel { glyphInfo.glyphName ); } + if (x + glyphInstance.xAdvance > maxLineLength) { + stack.push(glyphLine.slice(glyphIndex)); + break; + } + positionedLine.glyphs.push({ x: x, y: y, @@ -413,7 +440,6 @@ export class SceneModel { }); x += glyphInstance.xAdvance; } - longestLineLength = Math.max(longestLineLength, x); let offset = 0;