-
Notifications
You must be signed in to change notification settings - Fork 143
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
Corrected TextLayout to produce right number of lines when '\r\n' sequence comes. #1320
base: master
Are you sure you want to change the base?
Conversation
Anyone testing this pr can use the below snippet.
|
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java
Outdated
Show resolved
Hide resolved
@@ -2952,8 +2952,11 @@ StyleItem[] merge (long items, int itemCount) { | |||
linkBefore = false; | |||
} | |||
char ch = segmentsText.charAt(start); | |||
if(ch == '\r') { | |||
ch = segmentsText.charAt(start+1); |
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.
is a boundcheck required here maybe? Just assume a single \r
at end of line would read bejond the 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.
yes agree
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 am checking on further if the string in full is just a "\r", what needs to be 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.
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.
If you agree to my changes, i can squash the commits.
89bd04a
to
aae8e16
Compare
@niraj-modi @merks @laeubi : Do you have any additional comments on this fix? or are we good to merge this? |
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 don't have time for a more detailed for the next days. But some comments generally follow a for or if keyword with a space.
String text, segmentsText; | ||
int lineSpacingInPoints; | ||
String text, segmentsText, originalText; | ||
int lineSpacingInPoints, previousCountNextLine = 0, previousEnd = -1; |
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.
Initializing to 0 is pointless and actually generates more byte code.
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.
Updated initialization as part of constructor.
case '\t': | ||
item.tab = true; | ||
break; | ||
if(ch == '\r' && (start+1 < 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.
The formatting of if(
is poor. The () around the < condition is redundant and odd that it's not used for the == test
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.
corrected it.
loop = previousEnd+1; | ||
else | ||
loop = previousEnd; | ||
for(int i = loop; i < end; i++) { |
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.
Here for(
is not nice format.
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.
corrected it.
0740eef
to
26a2d76
Compare
this.originalText = text; | ||
String[] strings = text.split("\r"); | ||
text = ""; | ||
for(int i = 0; i < strings.length; i++) |
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 formatting of this for loop could also be improved.
e60de1d
to
223b000
Compare
this.originalText = text; | ||
String[] strings = text.split("\r"); | ||
text = ""; | ||
for (int i = 0; i < strings.length; i++) |
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.
This can be done using a map reduction. Anyway, please add braces to the for loop
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.
It's this a complicated and poorly performance way of doing test.replace("\r", "")?
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.
@merks yes, looks like it. Your approach is the best to me!
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.
let me test and update here back.
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.
Thanks @merks for your feedback, after updating this i found a better way of fixing the issue. So new change is updated, you may please review now.
else | ||
loop = previousEnd; | ||
for (int i = loop; i < end; i++) { | ||
if (originalText.charAt(i) == '\r' && originalText.charAt(i+1) =='\n') |
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.
Is i + 1 necessarily < 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.
let me check it.
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 are correct, when string ends with \r, it is resulting OOB exception. So corrected it.
223b000
to
4f760cf
Compare
79bb600
to
52e92e2
Compare
@niraj-modi @merks @laeubi @Wittmaxi : Do you have any additional comments on this fix? or are we good to merge this? |
2e2b765
to
4d7e7e8
Compare
4d7e7e8
to
48b7ea7
Compare
Could you please squash this to a single commit? |
48b7ea7
to
e500d29
Compare
Done. |
e500d29
to
d53e86e
Compare
c378aa1
to
b5dc868
Compare
Wouldn't it be better for there to be actual tests that run with every build? |
Apart from this manual test(tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue184_CarriageReturnHandled.java) which is already added, please let me know what else needs to be done, so that this can be taken forward. Can you point me to a sample kind of instance? to refer. |
8b4764a
to
63a46d7
Compare
@merks : I have added some junits for the fix. Can you check now please? |
is this only an issue on Windows? May the macOS and Linux implementation have the same issue? |
@BeckerWdf : Atleast from the parent #184 => this is marked as only windows issue and i have implemented the fix only for windows. In the past i remember vaguely but when tested with mac, the behavior on mac Vs behavior on windows (before the fix) were different. So took it up as windows specific issue. |
Thanks. |
63a46d7
to
048b496
Compare
@merks : |
048b496
to
e05f6fc
Compare
@merks |
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.
It looks okay to me.
That being said, I would prefer that at least one other person deeply involved in SWT reviews this too.
Do you know who else might be good to review this? |
@sratz @jukzi @laeubi @HeikoKlare |
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 have not worked on TextLayout so far. Thus, unfortunately, I cannot say with high confidence whether the overall change is okay. Still, from what I understand, the conceptual change and the code for it looks sound to me. I've tested the proposed change with the snippet in the original issue and it indeed fixes it.
I have remarks regarding the automated and manual test. In particular the automated test does not seem to be an adequate regression test, as the same test succeeds on master
, thus it does not seem to cover the addressed issue.
@@ -0,0 +1,68 @@ | |||
package org.eclipse.swt.tests.manual; |
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.
Please add missing copyright header
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.
Updated.
TextStyle style3 = new TextStyle(font2, null, null); | ||
layout.setStyle(style3, 21, 24); // iri in bold | ||
|
||
int[] offsets = layout.getLineOffsets(); |
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.
This variable is unused and thus produces a warning. It should be safe to just delete this line of code.
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.
Removed.
@@ -547,6 +547,60 @@ public void test_setStyle() { | |||
assertNull(layout.getStyle(4)); | |||
assertNull(layout.getStyle(5)); | |||
layout.dispose(); | |||
|
|||
layout = new TextLayout (display); |
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 test with these changes succeeds on master, so it's not a regression test for the changes made in this PR. Can you adapt the test so that it serves as a regression test for the addressed issue?
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.
Here we have not changed the behavior of the api's. The original behavior of the api's still work the same. We are internally detecting, correcting and passing the corrected content in specific cases only. We dint even add new api's. It is only the look and feel by which you can make out if some extra lines are expected or not expected varies. - is my understanding.
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.
Okay, I mistakenly expected the added test to be a regression test for the fix because of #1320 (comment)
Still, this change is no refactoring but affects the behavior of public APIs (e.g., TextLayout#draw(...)
behaves differently). I guess that, e.g., also TextLayout#getBounds()
now behaves differently, so wouldn't it be possible to have a regression test comparing the bounds of two configurations that should actually result in the bounds but did not do before this change (or vice versa)?
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.
@HeikoKlare
As per your suggestion i have added new junit tests with TextLayout#getLineCount()
and TextLayout#getBounds()
.
Since this change is only with respect to windows, i have excluded mac, gtk for the tests to run.
I guess this makes it all complete as we discussed. If i missed out any, please do let me know.
Can you review it and take it forward please?
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.
Please hold on, let me cross check and update you again.
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.
Hi @HeikoKlare
Sorry for the confusion caused.
I am successfull in adding only TextLayout#getLineCount() junit. I think we can go ahead with this pr now.
I have tried even TextLayout#getBounds() but had to withdraw as the behavior is not consistent across.
With the sample input taken,
- On master, getBounds() is returning {0, 0, 30, 220} where width and height are 30, 220 respectively. [junit is failing]
- On the branch where i committed my changes(fix_for_issue184), getBounds() is returning {0, 0, 43, 140}. [junit is passing]
- To cross check, i have pulled the pr 1320 to local, getBounds() is returning {0, 0, 43, 140}. [junit is passing]
- But on the build machine, getBounds() is returning {0, 0, 34, 105}. [junit is failing because it is getting 34 but expecting 43]. -> https://github.com/eclipse-platform/eclipse.platform.swt/actions/runs/12312890737/job/34365830603?pr=1320
Neither able to understand the reason for the failure(to fix) nor able to replicate the problem locally to debug further.
Can you please check now?
And one additional remark: since the |
c368f7f
to
514957c
Compare
Thanks for your opinion. Since it is already tested now by various people, i feel we are safe to merge this. Considering the M3 deadline is 8th Nov(2 weeks far and not away like 2days or so) and we can give it a try. If something is breaking we'll revert it immediately and rectify to make it to next M1? Atleast this risk we can take to improve SWT - i feel so in particularly such long standing issues when they passed all the stages of fixing, review, successfully verified. |
63bcef0
to
1756000
Compare
sequence comes. Added some junit tests as well. Updated getStyle() and setStyle() accordingly. Added failing and success junits again. Fixes eclipse-platform#184
1756000
to
a3510b6
Compare
Corrected TextLayout to produce right number of lines when '\r\n' sequence comes.
Fixes #184
@sravanlakkimsetti
@niraj-modi
@merks
Can one of you review this fix please.