summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Heidrich <fheidric>2007-07-05 18:27:13 +0000
committerFelipe Heidrich <fheidric>2007-07-05 18:27:13 +0000
commit1c30084b09387782ae7310d0f6b69abce2f396a8 (patch)
treea052e9103e9f08ab56f4dc67310c02916c609923
parent1fb12053b80b263df45cd22a53291eee547e711e (diff)
downloadeclipse.platform.swt-1c30084b09387782ae7310d0f6b69abce2f396a8.tar.gz
eclipse.platform.swt-1c30084b09387782ae7310d0f6b69abce2f396a8.tar.xz
eclipse.platform.swt-1c30084b09387782ae7310d0f6b69abce2f396a8.zip
Bug 166745 shortenText() in CLabel and CTabItem may cause globalization problems
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabItem.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabItem.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabItem.java
index e3898264a1..7e3068238e 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabItem.java
@@ -143,16 +143,19 @@ String shortenText(GC gc, String text, int width, String ellipses) {
if (gc.textExtent(text, FLAGS).x <= width) return text;
int ellipseWidth = gc.textExtent(ellipses, FLAGS).x;
int length = text.length();
- int end = length - 1;
+ TextLayout layout = new TextLayout(getDisplay());
+ layout.setText(text);
+ int end = layout.getPreviousOffset(length, SWT.MOVEMENT_CLUSTER);
while (end > 0) {
text = text.substring(0, end);
int l = gc.textExtent(text, FLAGS).x;
if (l + ellipseWidth <= width) {
- return text + ellipses;
+ break;
}
- end--;
+ end = layout.getPreviousOffset(end, SWT.MOVEMENT_CLUSTER);
}
- return text.substring(0,1);
+ layout.dispose();
+ return end == 0 ? text.substring(0, 1) : text + ellipses;
}
public void dispose() {