Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Yan2018-08-17 14:26:24 +0000
committerXi Yan2018-08-20 17:21:04 +0000
commit23d65c30e28bf3ac50666f5d621156cd02248454 (patch)
tree97adafc367af6c85a8872fdf633e5351441f1f32
parent2c794c9363967f39916541462e07d3fa8782164b (diff)
downloadeclipse.platform.swt-23d65c30e28bf3ac50666f5d621156cd02248454.tar.gz
eclipse.platform.swt-23d65c30e28bf3ac50666f5d621156cd02248454.tar.xz
eclipse.platform.swt-23d65c30e28bf3ac50666f5d621156cd02248454.zip
Bug 442831 - TextLayout.getLineBounds returns incorrect values for right
to left text pango_layout_iter_get_line_extents gets the extents in layout coordinates from top-left corner. Removed recalculation of x when using RTL since already in correct direction. Change-Id: Ib7e1bbb552805eab89ebf072481dfcdec7599caf Signed-off-by: Xi Yan <xixiyan@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java12
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug442831_TextLayoutRTL.java135
2 files changed, 138 insertions, 9 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
index 00ee75fbe6..d9b6526fc6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
@@ -880,9 +880,6 @@ Rectangle getBoundsInPixels(int start, int end) {
GDK.gdk_region_get_clipbox(clipRegion, rect);
GDK.gdk_region_destroy(clipRegion);
- if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
- rect.x = width() - rect.x - rect.width;
- }
rect.x += Math.min (indent, wrapIndent);
return new Rectangle(rect.x, rect.y, rect.width, rect.height);
}
@@ -1036,9 +1033,6 @@ Rectangle getLineBoundsInPixels(int lineIndex) {
if (ascentInPoints != -1 && descentInPoints != -1) {
height = Math.max (height, DPIUtil.autoScaleUp(getDevice(), ascentInPoints + descentInPoints));
}
- if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
- x = width() - x - width;
- }
x += Math.min (indent, wrapIndent);
return new Rectangle(x, y, width, height);
}
@@ -2343,9 +2337,9 @@ int width () {
* @exception SWTException <ul>
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
- *
- * @noreference This method is not intended to be referenced by clients.
- *
+ *
+ * @noreference This method is not intended to be referenced by clients.
+ *
* DO NOT USE This might be removed in 4.8
* @since 3.107
*/
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug442831_TextLayoutRTL.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug442831_TextLayoutRTL.java
new file mode 100644
index 0000000000..d3303adb36
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug442831_TextLayoutRTL.java
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.TextLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class Bug442831_TextLayoutRTL {
+
+ protected Shell shell;
+ Button btnRightToLeft;
+ Text text;
+ Canvas canvas;
+
+ /**
+ * Launch the application.
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+ try {
+ Bug442831_TextLayoutRTL window = new Bug442831_TextLayoutRTL();
+ window.open();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Open the window.
+ */
+ public void open() {
+ Display display = Display.getDefault();
+ createContents();
+ shell.open();
+ shell.layout();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ }
+
+ /**
+ * Create contents of the window.
+ */
+ protected void createContents() {
+ shell = new Shell();
+ shell.setSize(801, 481);
+ shell.setText("SWT Application");
+
+ btnRightToLeft = new Button(shell, SWT.CHECK);
+ btnRightToLeft.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ update();
+ }
+ });
+ btnRightToLeft.setBounds(643, 30, 134, 25);
+ btnRightToLeft.setData("name", "btnRightToLeft");
+ btnRightToLeft.setText("RTL");
+
+ text = new Text(shell, SWT.BORDER | SWT.WRAP | SWT.MULTI);
+ text.addModifyListener(e -> update());
+ text.setBounds(22, 30, 593, 125);
+ text.setData("name", "text");
+
+ canvas = new Canvas(shell, SWT.NONE);
+ canvas.setBounds(22, 177, 593, 224);
+ canvas.setData("name", "canvas");
+
+ canvas.addPaintListener(e -> drawCanvas(e.gc));
+
+ text.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit."
+ + "Praesent quis dapibus nibh."
+ + "Integer dolor sem, sagittis quis pharetra in, lacinia laoreet augue."
+ + "Ut porttitor rhoncus gravida." + "Mauris nec orci vel mi posuere rutrum."
+ + "Nam aliquam interdum condimentum."
+ + "Aenean a sollicitudin mi, sit amet pharetra nisl."
+ + "Nulla imperdiet quam non metus blandit porta id ut sem."
+ + "Nunc bibendum et ex id ullamcorper."
+ + "Morbi tincidunt lacus id eros volutpat pretium."
+ + "Cras at sapien non justo porttitor dignissim." + "Vivamus sed risus libero."
+ + "Sed et nisi sit amet nibh malesuada cursus sit amet vitae ligula."
+ + "Vestibulum varius quam at mauris pharetra maximus eget non diam."
+ + "Nunc volutpat consequat dolor ut interdum."
+ + "Suspendisse sed tristique ipsum, nec dictum eros.");
+
+ }
+
+ protected void drawCanvas(GC gc) {
+ Display display = shell.getDisplay();
+ TextLayout layout = new TextLayout(display);
+ layout.setAlignment(SWT.LEFT);
+ layout.setOrientation(btnRightToLeft.getSelection() ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT);
+ layout.setWidth(canvas.getBounds().width);
+ layout.setText(text.getText());
+
+ layout.draw(gc, 0, 0);
+
+ gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
+ Rectangle bounds = layout.getBounds();
+ gc.drawRectangle(bounds);
+
+ gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
+ gc.setLineDash(new int[] { 1, 7 });
+ int lines = layout.getLineCount();
+ for (int i = 0; i < lines; i++) {
+ bounds = layout.getLineBounds(i);
+ gc.drawRectangle(bounds);
+ }
+
+ }
+
+ protected void update() {
+ canvas.redraw();
+ }
+}

Back to the top