Repository navigation
Support offsetX for text placed along a line - #17576
Conversation
|
📦 Preview the website for this branch here: https://deploy-preview-17576--ol-site.netlify.app/. |
There was a problem hiding this comment.
Thanks, @sobol-sudo. This change breaks existing rendering tests.
case cases/text-style-linestring-nice/main.js': mismatch 0.016326904296875
case cases/text-style-linestring-ugly/main.js': mismatch 0.023956298828125
RENDERING TESTS FAILED
Also, please add a rendering test. With a large font size, a stright line, text without offsetX with a negative offsetY and text with offsetX with a positive offsetX. This will allow for visual comparion on the reference image. If the new rendering test fails with your reference image, I'll happily replace it with the CI generated one.
|
Thanks for the pointers. On the two broken tests — I think the mismatch is the fix doing its job. Both I also added One caveat on the reference images, since you offered to replace them. They were generated on macOS and mine don't line up with yours: with the fix reverted and a clean build, Worth noting |
ahocevar
left a comment
There was a problem hiding this comment.
If you compare the text-style-linestring-ugly reference image, you'll see flipped offsetY on the "set properties" and "small text" paths. These can not be explained with the fixed offsetX handling.
Regarding the new rendering test. I was envisioning a single line with two text styles, one above the line and one below (achieved by offsetY), and one of the text styles with an offsetX, one without. Both with textAlign: left, so the difference can be seen.
07a39c6 to
3dfea2a
Compare
|
You're right, and regenerating those two references was a mistake on my part — I've reverted both, they're back to what's on main. To isolate what the change actually touches, I replaced The flip on the two that do have an offsetX is explainable though, and I think it's worth deciding on deliberately. If you'd rather Rendering test rewritten to your description: one line, two text styles, both |
Ok, let's look more closely at the There is no Looking at the way the |
3dfea2a to
9021c86
Compare
|
You're right about the anchor, and I've reworked it that way — but I don't think the state bleeds, and I'd rather not leave that hanging. Two checks. First, a unit test: build with a style that has That cluster is On The flip is gone with this:
|
ahocevar
left a comment
There was a problem hiding this comment.
Reference images updated. The issue with "small text" persists, but it predates this pull request. I reduced the pixel tolerance of that test to prevent future regressions.
Thanks, @sobol-sudo


Fixes #16342.
offsetXon aTextstyle is applied when the text is placed on a point, but silently dropped whenplacementis'line'.drawChars_readstextOffsetY_and puts it in theDRAW_CHARSinstruction, but never readstextOffsetX_, so the executor has nothing to shift by.This carries it through the same way
offsetYalready travels:drawChars_multipliestextOffsetX_by the pixel ratio and appends it to both the regular and the hit-detectionDRAW_CHARSinstruction, andExecutoradds it tostartM, the distance along the path where the text starts. I appended the value at the end of the instruction array rather than inserting it next tooffsetY, so every existing index stays where it was —DRAW_CHARSis only produced and consumed inTextBuilder.jsandExecutor.js, so there are no other readers.Scaling by
pixelRatioand not by the text scale matches what the point-placement path does inExecutor.js, and it keeps the term dimensionally consistent withtextLengthin the same expression, which is already multiplied by the measure pixel ratio.I added two cases to
test/browser/spec/ol/render/canvas/textbuilder.test.jsasserting the emitted instruction carries the scaled offset, and zero when none is configured. Both fail on main.I did not add a rendering case. The reference images are generated on your Ubuntu CI and the existing text cases depend on the Ubuntu font, so a PNG I generate on macOS would almost certainly differ on antialiasing and just make the build red. Happy to add one if you can regenerate the reference, or if you'd rather I try to match the CI environment more closely.