Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonah Graham2021-11-09 19:51:43 +0000
committerNiraj Modi2021-11-30 11:15:02 +0000
commitdafe6e1134c037d6f15b61bd1a99a5af37062379 (patch)
tree89c377f2c51497607c5f28da70702b417d314bae
parent15e5660efaf716f25c22dff4fd09f83b59781b0a (diff)
downloadeclipse.platform.swt-dafe6e1134c037d6f15b61bd1a99a5af37062379.tar.gz
eclipse.platform.swt-dafe6e1134c037d6f15b61bd1a99a5af37062379.tar.xz
eclipse.platform.swt-dafe6e1134c037d6f15b61bd1a99a5af37062379.zip
Bug 577238: Wrapper for OS.ScriptCPtoX
This makes the code more readable and makes sure that all the special parameters are consistently converted before calling OS.ScriptCPtoX Change-Id: Id2268f93854f506a8d326a4c2592c42c288fcf07 Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/187696 Tested-by: Niraj Modi <niraj.modi@in.ibm.com> Reviewed-by: Niraj Modi <niraj.modi@in.ibm.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java50
1 files changed, 28 insertions, 22 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java
index 676214df23..dbbbac9e4d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java
@@ -1697,10 +1697,8 @@ Rectangle getBoundsInPixels (int start, int end) {
GlyphMetrics metrics = run.style.metrics;
cx = metrics.getWidthInPixels() * (start - run.start);
} else if (!run.tab) {
- int[] piX = new int[1];
- long advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptCPtoX(start - run.start, false, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, run.analysis, piX);
- cx = isRTL ? run.width - piX[0] : piX[0];
+ int iX = ScriptCPtoX(start - run.start, false, run);
+ cx = isRTL ? run.width - iX : iX;
}
if (run.analysis.fRTL ^ isRTL) {
runTrail = run.x + cx;
@@ -1714,10 +1712,8 @@ Rectangle getBoundsInPixels (int start, int end) {
GlyphMetrics metrics = run.style.metrics;
cx = metrics.getWidthInPixels() * (end - run.start + 1);
} else if (!run.tab) {
- int[] piX = new int[1];
- long advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptCPtoX(end - run.start, true, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, run.analysis, piX);
- cx = isRTL ? run.width - piX[0] : piX[0];
+ int iX = ScriptCPtoX(end - run.start, true, run);
+ cx = isRTL ? run.width - iX : iX;
}
if (run.analysis.fRTL ^ isRTL) {
runLead = run.x + cx;
@@ -2088,12 +2084,8 @@ Point getLocationInPixels (int offset, boolean trailing) {
width = (trailing || (offset == length)) ? run.width : 0;
} else {
int runOffset = offset - run.start;
- int cChars = run.length;
- int gGlyphs = run.glyphCount;
- int[] piX = new int[1];
- long advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptCPtoX(runOffset, trailing, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX);
- width = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? run.width - piX[0] : piX[0];
+ final int iX = ScriptCPtoX(runOffset, trailing, run);
+ width = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? run.width - iX : iX;
}
return new Point(run.x + width, DPIUtil.autoScaleUp(getDevice(), lineY[line]) + getScaledVerticalIndent());
}
@@ -2102,6 +2094,24 @@ Point getLocationInPixels (int offset, boolean trailing) {
}
/**
+ * Wrapper around
+ * {@link OS#ScriptCPtoX(int, boolean, int, int, long, long, long, SCRIPT_ANALYSIS, int[])}
+ * to handle common arguments consistently.
+ *
+ * @param characterPosition the first argument of OS.ScriptCPtoX
+ * @param trailing the first argument of OS.ScriptCPtoX
+ * @param run used to define remaining arguments of OS.ScriptCPtoX
+ * @return x position of the caret.
+ */
+private int ScriptCPtoX(int characterPosition, boolean trailing, StyleItem run) {
+ int[] piX = new int[1];
+ long advances = run.justify != 0 ? run.justify : run.advances;
+ OS.ScriptCPtoX(characterPosition, trailing, run.length, run.glyphCount, run.clusters, run.visAttrs, advances,
+ run.analysis, piX);
+ return piX[0];
+}
+
+/**
* Returns the next offset for the specified offset and movement
* type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
* <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>,
@@ -2360,16 +2370,12 @@ void getPartialSelection(StyleItem run, int selectionStart, int selectionEnd, RE
int end = run.start + run.length - 1;
int selStart = Math.max(selectionStart, run.start) - run.start;
int selEnd = Math.min(selectionEnd, end) - run.start;
- int cChars = run.length;
- int gGlyphs = run.glyphCount;
- int[] piX = new int[1];
int x = rect.left;
- long advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptCPtoX(selStart, false, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX);
- int runX = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? run.width - piX[0] : piX[0];
+ int iX = ScriptCPtoX(selStart, false, run);
+ int runX = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? run.width - iX : iX;
rect.left = x + runX;
- OS.ScriptCPtoX(selEnd, true, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX);
- runX = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? run.width - piX[0] : piX[0];
+ iX = ScriptCPtoX(selEnd, true, run);
+ runX = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? run.width - iX : iX;
rect.right = x + runX;
}

Back to the top