From fc0aa0f5d229ffb3954c887d2c6d3d86434cb99f Mon Sep 17 00:00:00 2001 From: Kang Hyunwoong Date: Sun, 12 May 2024 18:18:29 +0900 Subject: [PATCH 1/3] basic wrapping done, but selection has bugs --- src/fontra/views/editor/scene-model.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/fontra/views/editor/scene-model.js b/src/fontra/views/editor/scene-model.js index 0470580484..bb89e0d12d 100644 --- a/src/fontra/views/editor/scene-model.js +++ b/src/fontra/views/editor/scene-model.js @@ -349,10 +349,12 @@ export class SceneModel { glyphIndex: selectedGlyphIndex, isEditing: selectedGlyphIsEditing, } = this.selectedGlyph || {}; + console.log(selectedLineIndex); 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 +376,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 +407,12 @@ export class SceneModel { glyphInfo.glyphName ); } + console.log(x + glyphInstance.xAdvance, maxLineLength); + if (x + glyphInstance.xAdvance > maxLineLength) { + stack.push(glyphLine.slice(glyphIndex)); + break; + } + positionedLine.glyphs.push({ x: x, y: y, @@ -413,7 +426,6 @@ export class SceneModel { }); x += glyphInstance.xAdvance; } - longestLineLength = Math.max(longestLineLength, x); let offset = 0; From a93b0c2e49b4946b788de3f1f398ece07b8b6da5 Mon Sep 17 00:00:00 2001 From: Kang Hyunwoong Date: Mon, 13 May 2024 14:00:19 +0900 Subject: [PATCH 2/3] fix bugs related to selection --- src/fontra/views/editor/scene-controller.js | 9 ++++++++- src/fontra/views/editor/scene-model.js | 22 +++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/fontra/views/editor/scene-controller.js b/src/fontra/views/editor/scene-controller.js index 84ed08b02f..375c124ee3 100644 --- a/src/fontra/views/editor/scene-controller.js +++ b/src/fontra/views/editor/scene-controller.js @@ -155,9 +155,14 @@ export class SceneController { this.sceneSettingsController.addKeyListener( ["selectedGlyph", "glyphLines"], (event) => { + const lines = this.sceneModel.positionedLines.map((line) => { + return line.glyphs.map((g) => ({ + glyphName: g.glyphName, + })); + }); this.sceneSettings.selectedGlyphName = getSelectedGlyphName( this.sceneSettings.selectedGlyph, - this.sceneSettings.glyphLines + lines ); }, true @@ -330,6 +335,7 @@ export class SceneController { case "editBegin": { const glyphController = this.sceneModel.getSelectedPositionedGlyph().glyph; + this.sceneModel.ghostPath = glyphController.flattenedPath2d; } break; @@ -829,6 +835,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 bb89e0d12d..313c3b69ac 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,7 +364,7 @@ export class SceneModel { glyphIndex: selectedGlyphIndex, isEditing: selectedGlyphIsEditing, } = this.selectedGlyph || {}; - console.log(selectedLineIndex); + const editLayerName = this.sceneSettings.editLayerName; let y = 0; @@ -407,7 +422,6 @@ export class SceneModel { glyphInfo.glyphName ); } - console.log(x + glyphInstance.xAdvance, maxLineLength); if (x + glyphInstance.xAdvance > maxLineLength) { stack.push(glyphLine.slice(glyphIndex)); break; From e48cc8e1ae53af208328c85fa3727f2568746f37 Mon Sep 17 00:00:00 2001 From: Kang Hyunwoong Date: Mon, 13 May 2024 14:02:53 +0900 Subject: [PATCH 3/3] code consistency when replacing glyphLines by positionedLines --- src/fontra/views/editor/scene-controller.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fontra/views/editor/scene-controller.js b/src/fontra/views/editor/scene-controller.js index 375c124ee3..870aa76ff7 100644 --- a/src/fontra/views/editor/scene-controller.js +++ b/src/fontra/views/editor/scene-controller.js @@ -156,8 +156,10 @@ export class SceneController { ["selectedGlyph", "glyphLines"], (event) => { const lines = this.sceneModel.positionedLines.map((line) => { - return line.glyphs.map((g) => ({ - glyphName: g.glyphName, + return line.glyphs.map((glyph) => ({ + character: glyph.character, + glyphName: glyph.glyphName, + isUndefined: glyph.isUndefined, })); }); this.sceneSettings.selectedGlyphName = getSelectedGlyphName(