Repository navigation
Conversation
|
PS: Here I'm less confident in my own review of the code as I do not have the necessary in-depth knowledge. |
|
@benoitkugler done #296 |
whereswaldon
left a comment
There was a problem hiding this comment.
I've been able to review through 563ce7f so far. I'm out of time for today, so I'll circle back when I can.
whereswaldon
left a comment
There was a problem hiding this comment.
This seems like a nice set of improvements, thank you for submitting them. It took a long time to go through it all, and I have a small number of remaining questions and requests.
| } | ||
| } | ||
|
|
||
| func TestSplitByFaceIgnoresInputFace(t *testing.T) { |
There was a problem hiding this comment.
Why is it desirable to ignore the input face?
There was a problem hiding this comment.
Clarified in code documentation.
| for a, b := 0, len(run.Glyphs)-1; a < b; a, b = a+1, b-1 { | ||
| run.Glyphs[a], run.Glyphs[b] = run.Glyphs[b], run.Glyphs[a] | ||
| } |
There was a problem hiding this comment.
Why not slices.Reverse here?
There was a problem hiding this comment.
The code initially was based on Go 1.19 which didn't have slices.Reverse. Updated it to use slices.Reverse.
| copy(split, line[:i]) | ||
| split[i] = prefix | ||
| copy(split[i+2:], line[i+1:]) |
There was a problem hiding this comment.
On an initial read, I couldn't figure out why we never wrote to split[i+1]. After taking a step back, I realized that we modify i at the end of this block, and then the loop-end line[i] = run is writing into that index in the slice. This is sufficiently subtle and non-local to warrant a comment, in my opinion.
| case run.Runes.Offset <= 4 && run.Runes.Offset+run.Runes.Count > 4: | ||
| before = run.VisualIndex | ||
| case run.Runes.Offset <= 8 && run.Runes.Offset+run.Runes.Count > 8: | ||
| digits = run.VisualIndex | ||
| case run.Runes.Offset <= 12 && run.Runes.Offset+run.Runes.Count > 12: | ||
| after = run.VisualIndex |
There was a problem hiding this comment.
Using these inequality ranges feels unnecessarily complex here. The text should segment at multiples of four runes in this sample text, and the runs should be stored in logical order within the line. Why not just say:
before = lines[0].Runs[1].VisualIndex
digits = lines[0].Runs[2].VisualIndex
after = lines[0].Runs[3].VisualIndexOnly tests referenced mapRunesToClusterIndices v1/v2 and mapRuneToClusterIndex. Rename v3 to mapRunesToClusterIndices.
A Face carries the variation coordinates. Two Faces on one Font with different coords shaped with the same cached harfbuzz.Font.
Size is already in 26.6 units, the same scaleShift the shaper removes from the harfbuzz positions. Sizes 12.5 and 13 now shape differently, and Output.Size matches the metrics. Tests using Size 72 and 36 relied on the ceiling to 2 and 1 px. They now pass those sizes directly.
Glyphs are in visual order, so with a TowardTopLeft progression index 0 is the logical end of the run. AddLetterSpacing and trimStartLetterSpacing assumed index 0 was the start. They now read the run progression to find the logical start and end.
cutRun and postProcessLine modified the caller Output.Glyphs in place, so wrapping the same runs again produced stale advances. Copy the glyph slice only when it changes.
WrapParagraph skipped trailing whitespace trimming for a single run that fits. Prepare and WrapNextLine trimmed it.
processBreakOption discarded the Peek ok flag and indexed a nil mapping. The last available run now ends the text, checked against the usual width and truncation rules.
UAX go-text#9 L1 resets whitespace at the end of each line to the paragraph embedding level, so it sits at the line end whatever direction the run containing it has. The wrapper left such whitespace inside the run, so a space at the end of an RTL run in an LTR paragraph was drawn at the visual start of the run, in the middle of the line. postProcessLine now applies L1 at each wrapped line boundary (resetTrailingBidiWhitespace). Trailing whitespace inside a run that opposes the paragraph direction is cut off into its own Output, which takes the paragraph direction and base level, with its glyphs reversed into a copy. A wrapped Line can therefore hold more Outputs than the caller fed in. Clusters that mix whitespace with visible characters stay whole. advanceSpaceAware measures an opposing run without its trailing L1 whitespace, so the space that L1 moves to the line end no longer decides whether the word before it fits. Only spaces L1 covers count; a no-break space stays inside the run and keeps its width. A run with Level 0 and a direction opposing the paragraph was built by hand rather than by Segmenter, and is left alone.
b27cba7 to
2b364f0
Compare
|
@egonelbre In the future, please don't force-push or re-push the work already reviewed when you address the review comments. It means I have to re-review all of that code because I can't know that it hasn't changed in-place from the version I already reviewed. I know this was likely a tool doing it for you, but please see if you can prevent it in the future. |
whereswaldon
left a comment
There was a problem hiding this comment.
Thank you, these look good to me know. @benoitkugler @andydotxyz , could we get a second review?
|
@whereswaldon of course, no problem. Also, in this case it was manual. Different projects have different ways of working. I'm mostly used to Go (the project) approach, which prefers linear history and reviewing one commit at a time. It does use Gerrit, which makes that workflow significantly easier. Unfortunately, Github isn't so kind to linear history and doesn't provide out of the box reviewing and tracing through per-commit history. Also, personally I prefer linear history such that every single commit stays correct and is buildable. Either way, I'm not trying to convince you, I just don't know what approach a project uses unless it's communicated somewhere upfront. I guess based on how the git history roughly looks and will get it wrong sometimes. PS: there is |
Sorry I've been out of action for a while and trying to catch up - but big PRs will take a while to get to, if Benoit can it will be faster :) |
Sixteen commits, one fix each. Grouped by area.
Bidi ordering:
line[i]andline[end-1-i]. That only works while the indices are still in logical order. Once a higher level has reversed an inner sequence the swap scrambles them. Levels{0,2,2,1,1,1,0}, an LTR paragraph with an RTL span holding two LTR runs, came out with the LTR runs swapped and the RTL runs shuffled. The two "bidi example" test cases with nested levels expected that output and now expect whatUAX #9specifies.Outputat the paragraph level, and measures the run without it when deciding whether the word fits. No-break spaces stay inside the run.bidiclosed a run only when the direction changed, so level 0 text followed by level 2 text inside an LRE shared one run and one reported level. A run now ends on any level change. Callers see more runs, and kerning no longer applies across an LRE or LRI boundary. Pango and ICU itemize the same way.Line wrapping:
cutRunand post-processing mutated the caller's glyph slice, so wrapping the same runs twice used stale advances. The slice is copied only when it changes.Segmenterpassed the caller'sFacethrough to every run instead of selecting one, when the input had a face set.Spacing:
Shaper:
Font, so twoFaces with different variation coordinates shared one shaped result. It is keyed on theFacenow.SetFontCacheSizeshrank it, it stayed over the limit. A negative size no longer panics.Output.Sizedisagreed with the metrics. Tests that relied on the ceiling pass integer sizes now.Runesand cluster counts used the unclamped run range while the glyphs used the clamped one.