-
Notifications
You must be signed in to change notification settings - Fork 6k
Handle paragraph alignment and direction in newline rectangles #17750
Conversation
5d2cc57
to
c2acd16
Compare
Thanks for handling the RTL case, really appreciate the extra pair of eyes on this. This will need a test before it goes in in order to stay in sync with the currently-under-development SkParagraph by Skia. Look at cc @jason-simmons This version handles the RTL case, we should go ahead with this instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good! Just missing a test :)
c2acd16
to
2d1be00
Compare
I saw the test file but I don't how to run these tests locally. |
I was just mid typing when you made the changes about tracking per line. Thanks. The tests can be run by building a host debug engine build, and running the txt_unittests executable in the engine build directory. So |
Note that the tests are meant to be run on linux, but should still be able to run on mac or windows. Some may be disabled on those platforms though due to differences in the values provided by coretext and opentype. |
This test fails. Do you know why? @GaryQian
|
What OS are you running this on? Things should pass on linux, but if it is windows or mac, we may have missed a disable here or there. |
I'm running tests on Debian 10 Linux and it failed. |
Hmm, can you try pushing your code and seeing if the presubmit tests pass? If it does, I would just ignore it. There can be minor differences based on the exact OS you are running, which we expect. We only require maintaining a passing state across our testing infra. In particular, fonts are often interpreted slightly different across platforms. This usually manifests itself in places such as line height, which I suspect is what is happening here. Although the latency is higher, feel free to push changes and look at the presubmit runs to see the results. |
fe76c77
to
50afb22
Compare
Tests are successful but it looks like the solution is still not reliable in mixed bidi runs in one line. |
50afb22
to
ede4a0b
Compare
So I changed my code to get the newline position from the correct ending of the last bidi run. |
1d612bf
to
6a903a3
Compare
paragraph_style_.effective_align() == TextAlign::center) { | ||
x = width_ / 2; | ||
SkScalar x; | ||
if (glyph_lines_[line_number].positions.empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use newline_box_positions.find(line_number)
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If newline is in the selected range, it's position is evaluated in one related bidi run in the previous loop.
So we are sure about the value.
I also don't know how to handle find()
here or what to do if it's value becomes end()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try this:
auto it = newline_x_positions.find(line_number);
if (it != newline_x_positions.end()) {
x = it->second;
} else {
x = GetLineXOffset(0, line_number, false);
}
If there are glyphs on the line, then newline_x_positions
will have a value for the line and that value should be used. If not, then use the offset for an empty line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You already handled that case in the if statement.
if (glyph_lines_[line_number].positions.empty()) {
x = GetLineXOffset(0, line_number, false);
} else {
x = newline_x_positions[line_number];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal is to ensure that the code does not accidentally use a newline_x_positions
value that was never set.
If something goes wrong and glyph_lines_[line_number].positions
is nonempty but newline_x_positions[line_number]
was never set, then newline_x_positions[line_number]
is going to yield a default value. That will produce an unintended result.
Checking newline_x_positions.find(line_number)
will ensure that this does not happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The newline_x_positions.find(line_number)
check should replace the glyph_lines_[line_number].positions.empty()
check. Both checks should always have the same value if everything is working as expected, but using newline_x_positions
is safer as discussed above.
Remove the if glyph_lines_[line_number].positions.empty()
block, and just keep the block inside the else
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it now.
Done.
Thanks for your review
cd7c3b7
to
7ea21e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
Please rebase this onto the current flutter/engine master branch.
I removed the line_number
parameter from GetLineXOffset
, so that call will need to be updated.
GetRectsForRange inserts empty rectangles that represent newline characters within the specified range of text positions. The x coordinate of these rectangles needs to account for left/right/center alignment. Fixes flutter/flutter#53057
7ea21e0
to
cdcf7cd
Compare
Done |
This pull request is not suitable for automatic merging in its current state.
|
Based on #17744 and fixes flutter/flutter#53057