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

Fix #1041: Wrap long lines based on a settable maximum line width #1355

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion src/fontra/views/editor/scene-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -330,6 +337,7 @@ export class SceneController {
case "editBegin":
{
const glyphController = this.sceneModel.getSelectedPositionedGlyph().glyph;

this.sceneModel.ghostPath = glyphController.flattenedPath2d;
}
break;
Expand Down Expand Up @@ -829,6 +837,7 @@ export class SceneController {
return;
}
const glyphName = this.sceneModel.getSelectedGlyphName();

const varGlyph = await this.fontController.getGlyph(glyphName);
const baseChangePath = ["glyphs", glyphName];

Expand Down
34 changes: 30 additions & 4 deletions src/fontra/views/editor/scene-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;

Expand All @@ -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)) {
Expand All @@ -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,
Expand All @@ -413,7 +440,6 @@ export class SceneModel {
});
x += glyphInstance.xAdvance;
}

longestLineLength = Math.max(longestLineLength, x);

let offset = 0;
Expand Down