-
Notifications
You must be signed in to change notification settings - Fork 139
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
Open
deepika-u
wants to merge
1
commit into
eclipse-platform:master
Choose a base branch
from
deepika-u:fix_for_issue184
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+156
−11
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...se.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue184_CarriageReturnHandled.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 IBM and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.swt.tests.manual; | ||
|
||
import org.eclipse.swt.*; | ||
import org.eclipse.swt.graphics.*; | ||
import org.eclipse.swt.widgets.*; | ||
|
||
public class Issue184_CarriageReturnHandled { | ||
|
||
private static FontData[] getFontData(Font font, int style) { | ||
FontData[] fontDatas = font.getFontData(); | ||
for (FontData fontData : fontDatas) { | ||
fontData.setStyle(style); | ||
} | ||
return fontDatas; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Display display = new Display(); | ||
final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED); | ||
shell.setText("Underline, Strike Out"); | ||
String text1 = "\r\nde\nep\rika\r\rudaya\n\ngiri\r"; | ||
|
||
FontData[] fontData = getFontData(shell.getFont(), SWT.BOLD); | ||
Font font = new Font(shell.getDisplay(), fontData); | ||
|
||
FontData[] fontData1 = getFontData(shell.getFont(), SWT.ITALIC | SWT.BOLD); | ||
Font font1 = new Font(shell.getDisplay(), fontData1); | ||
|
||
FontData[] fontData2 = getFontData(shell.getFont(), SWT.BOLD); | ||
Font font2 = new Font(shell.getDisplay(), fontData2); | ||
|
||
final TextLayout layout = new TextLayout(display); | ||
layout.setText(text1); | ||
|
||
TextStyle style1 = new TextStyle(font, null, null); | ||
layout.setStyle(style1, 3, 7); // eep in bold | ||
|
||
TextStyle style2 = new TextStyle(font1, null, null); | ||
layout.setStyle(style2, 12, 18); // udaya in bold | ||
|
||
TextStyle style3 = new TextStyle(font2, null, null); | ||
layout.setStyle(style3, 21, 24); // iri in bold | ||
|
||
shell.addListener(SWT.Paint, event -> { | ||
Point point = new Point(10, 10); | ||
int width = shell.getClientArea().width - 2 * point.x; | ||
layout.setWidth(width); | ||
layout.draw(event.gc, point.x, point.y); | ||
}); | ||
shell.setSize(400, 300); | ||
shell.open(); | ||
while (!shell.isDisposed()) { | ||
if (!display.readAndDispatch()) | ||
display.sleep(); | ||
} | ||
layout.dispose(); | ||
display.dispose(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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., alsoTextLayout#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)?