Revert "Add cluster count API"
Revert submission 25573460-cluster_api
Reason for revert: b/319192202
Reverted changes: /q/submissionid:25573460-cluster_api
Change-Id: I727b194ca7b29e6af21a7c64fd5004624b8713c5
diff --git a/core/api/current.txt b/core/api/current.txt
index cc376d8..f245b5c 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -47216,7 +47216,6 @@
method public int getLineForOffset(int);
method public int getLineForVertical(int);
method public float getLineLeft(int);
- method @FlaggedApi("com.android.text.flags.inter_character_justification") @IntRange(from=0) public int getLineLetterSpacingUnitCount(@IntRange(from=0) int, boolean);
method public float getLineMax(int);
method public float getLineRight(int);
method @FlaggedApi("com.android.text.flags.use_bounds_for_width") public final float getLineSpacingAmount();
diff --git a/core/java/android/text/BoringLayout.java b/core/java/android/text/BoringLayout.java
index a6d3bb4..4c81888 100644
--- a/core/java/android/text/BoringLayout.java
+++ b/core/java/android/text/BoringLayout.java
@@ -454,7 +454,7 @@
line.set(paint, source, 0, source.length(), Layout.DIR_LEFT_TO_RIGHT,
Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null,
mEllipsizedStart, mEllipsizedStart + mEllipsizedCount, useFallbackLineSpacing);
- mMax = (int) Math.ceil(line.metrics(null, null, false, null));
+ mMax = (int) Math.ceil(line.metrics(null, null, false));
TextLine.recycle(line);
}
@@ -603,7 +603,7 @@
0 /* ellipsisStart, 0 since text has not been ellipsized at this point */,
0 /* ellipsisEnd, 0 since text has not been ellipsized at this point */,
useFallbackLineSpacing);
- fm.width = (int) Math.ceil(line.metrics(fm, fm.mDrawingBounds, false, null));
+ fm.width = (int) Math.ceil(line.metrics(fm, fm.mDrawingBounds, false));
TextLine.recycle(line);
return fm;
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java
index 42d00d8..89aceb9 100644
--- a/core/java/android/text/Layout.java
+++ b/core/java/android/text/Layout.java
@@ -18,7 +18,6 @@
import static com.android.text.flags.Flags.FLAG_FIX_LINE_HEIGHT_FOR_LOCALE;
import static com.android.text.flags.Flags.FLAG_USE_BOUNDS_FOR_WIDTH;
-import static com.android.text.flags.Flags.FLAG_INTER_CHARACTER_JUSTIFICATION;
import android.annotation.FlaggedApi;
import android.annotation.FloatRange;
@@ -51,10 +50,8 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import java.text.BreakIterator;
import java.util.Arrays;
import java.util.List;
-import java.util.Locale;
/**
* A base class that manages text layout in visual elements on
@@ -672,8 +669,7 @@
int start = previousLineEnd;
previousLineEnd = getLineStart(lineNum + 1);
final boolean justify = isJustificationRequired(lineNum);
- int end = getLineVisibleEnd(lineNum, start, previousLineEnd,
- true /* trailingSpaceAtLastLineIsVisible */);
+ int end = getLineVisibleEnd(lineNum, start, previousLineEnd);
paint.setStartHyphenEdit(getStartHyphenEdit(lineNum));
paint.setEndHyphenEdit(getEndHyphenEdit(lineNum));
@@ -1060,7 +1056,7 @@
if (isJustificationRequired(line)) {
tl.justify(getJustifyWidth(line));
}
- tl.metrics(null, rectF, false, null);
+ tl.metrics(null, rectF, false);
float lineLeft = rectF.left;
float lineRight = rectF.right;
@@ -1460,7 +1456,7 @@
tl.set(mPaint, mText, start, end, dir, directions, hasTab, tabStops,
getEllipsisStart(line), getEllipsisStart(line) + getEllipsisCount(line),
isFallbackLineSpacingEnabled());
- float wid = tl.measure(offset - start, trailing, null, null, null);
+ float wid = tl.measure(offset - start, trailing, null, null);
TextLine.recycle(tl);
if (clamped && wid > mWidth) {
@@ -1796,69 +1792,12 @@
if (isJustificationRequired(line)) {
tl.justify(getJustifyWidth(line));
}
- final float width = tl.metrics(null, null, mUseBoundsForWidth, null);
+ final float width = tl.metrics(null, null, mUseBoundsForWidth);
TextLine.recycle(tl);
return width;
}
/**
- * Returns the number of letter spacing unit in the line.
- *
- * <p>
- * This API returns a number of letters that is a target of letter spacing. The letter spacing
- * won't be added to the middle of the characters that are needed to be treated as a single,
- * e.g. ligatured or conjunct form. Note that this value is different from the number of]
- * grapheme clusters that is calculated by {@link BreakIterator#getCharacterInstance(Locale)}.
- * For example, if the "fi" is ligatured, the ligatured form is treated as single uni and letter
- * spacing is not added, but it has two separate grapheme cluster.
- *
- * <p>
- * This value is used for calculating the letter spacing amount for the justification because
- * the letter spacing is applied between clusters. For example, if extra {@code W} pixels needed
- * to be filled by letter spacing, the amount of letter spacing to be applied is
- * {@code W}/(letter spacing unit count - 1) px.
- *
- * @param line the index of the line
- * @param includeTrailingWhitespace whether to include trailing whitespace
- * @return the number of cluster count in the line.
- */
- @IntRange(from = 0)
- @FlaggedApi(FLAG_INTER_CHARACTER_JUSTIFICATION)
- public int getLineLetterSpacingUnitCount(@IntRange(from = 0) int line,
- boolean includeTrailingWhitespace) {
- final int start = getLineStart(line);
- final int end = includeTrailingWhitespace ? getLineEnd(line)
- : getLineVisibleEnd(line, getLineStart(line), getLineStart(line + 1),
- false // trailingSpaceAtLastLineIsVisible: Treating trailing whitespaces at
- // the last line as a invisible chars for single line justification.
- );
-
- final Directions directions = getLineDirections(line);
- // Returned directions can actually be null
- if (directions == null) {
- return 0;
- }
- final int dir = getParagraphDirection(line);
-
- final TextLine tl = TextLine.obtain();
- final TextPaint paint = mWorkPaint;
- paint.set(mPaint);
- paint.setStartHyphenEdit(getStartHyphenEdit(line));
- paint.setEndHyphenEdit(getEndHyphenEdit(line));
- tl.set(paint, mText, start, end, dir, directions,
- false, null, // tab width is not used for cluster counting.
- getEllipsisStart(line), getEllipsisStart(line) + getEllipsisCount(line),
- isFallbackLineSpacingEnabled());
- if (mLineInfo == null) {
- mLineInfo = new TextLine.LineInfo();
- }
- mLineInfo.setClusterCount(0);
- tl.metrics(null, null, mUseBoundsForWidth, mLineInfo);
- TextLine.recycle(tl);
- return mLineInfo.getClusterCount();
- }
-
- /**
* Returns the signed horizontal extent of the specified line, excluding
* leading margin. If full is false, excludes trailing whitespace.
* @param line the index of the line
@@ -1884,7 +1823,7 @@
if (isJustificationRequired(line)) {
tl.justify(getJustifyWidth(line));
}
- final float width = tl.metrics(null, null, mUseBoundsForWidth, null);
+ final float width = tl.metrics(null, null, mUseBoundsForWidth);
TextLine.recycle(tl);
return width;
}
@@ -2493,21 +2432,14 @@
* is not counted) on the specified line.
*/
public int getLineVisibleEnd(int line) {
- return getLineVisibleEnd(line, getLineStart(line), getLineStart(line + 1),
- true /* trailingSpaceAtLastLineIsVisible */);
+ return getLineVisibleEnd(line, getLineStart(line), getLineStart(line+1));
}
- private int getLineVisibleEnd(int line, int start, int end,
- boolean trailingSpaceAtLastLineIsVisible) {
+ private int getLineVisibleEnd(int line, int start, int end) {
CharSequence text = mText;
char ch;
-
- // Historically, trailing spaces at the last line is counted as visible. However, this
- // doesn't work well for justification.
- if (trailingSpaceAtLastLineIsVisible) {
- if (line == getLineCount() - 1) {
- return end;
- }
+ if (line == getLineCount() - 1) {
+ return end;
}
for (; end > start; end--) {
@@ -3007,7 +2939,7 @@
tl.set(paint, text, start, end, dir, directions, hasTabs, tabStops,
0 /* ellipsisStart */, 0 /* ellipsisEnd */,
false /* use fallback line spacing. unused */);
- return margin + Math.abs(tl.metrics(null, null, useBoundsForWidth, null));
+ return margin + Math.abs(tl.metrics(null, null, useBoundsForWidth));
} finally {
TextLine.recycle(tl);
if (mt != null) {
@@ -3405,8 +3337,6 @@
private boolean mUseBoundsForWidth;
private @Nullable Paint.FontMetrics mMinimumFontMetrics;
- private TextLine.LineInfo mLineInfo = null;
-
/** @hide */
@IntDef(prefix = { "DIR_" }, value = {
DIR_LEFT_TO_RIGHT,
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java
index 135935c..f9abec0 100644
--- a/core/java/android/text/TextLine.java
+++ b/core/java/android/text/TextLine.java
@@ -76,21 +76,6 @@
private RectF mTmpRectForPaintAPI;
private Rect mTmpRectForPrecompute;
- // Recycling object for Paint APIs. Do not use outside getRunAdvances method.
- private Paint.RunInfo mRunInfo;
-
- public static final class LineInfo {
- private int mClusterCount;
-
- public int getClusterCount() {
- return mClusterCount;
- }
-
- public void setClusterCount(int clusterCount) {
- mClusterCount = clusterCount;
- }
- };
-
private boolean mUseFallbackExtent = false;
// The start and end of a potentially existing ellipsis on this text line.
@@ -285,7 +270,7 @@
// width.
return;
}
- final float width = Math.abs(measure(end, false, null, null, null));
+ final float width = Math.abs(measure(end, false, null, null));
mAddedWidthForJustify = (justifyWidth - width) / spaces;
mIsJustifying = true;
}
@@ -330,12 +315,10 @@
* @param drawBounds output parameter for drawing bounding box. optional.
* @param returnDrawWidth true for returning width of the bounding box, false for returning
* total advances.
- * @param lineInfo an optional output parameter for filling line information.
* @return the signed width of the line
*/
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
- public float metrics(FontMetricsInt fmi, @Nullable RectF drawBounds, boolean returnDrawWidth,
- @Nullable LineInfo lineInfo) {
+ public float metrics(FontMetricsInt fmi, @Nullable RectF drawBounds, boolean returnDrawWidth) {
if (returnDrawWidth) {
if (drawBounds == null) {
if (mTmpRectForMeasure == null) {
@@ -344,7 +327,7 @@
drawBounds = mTmpRectForMeasure;
}
drawBounds.setEmpty();
- float w = measure(mLen, false, fmi, drawBounds, lineInfo);
+ float w = measure(mLen, false, fmi, drawBounds);
float boundsWidth = drawBounds.width();
if (Math.abs(w) > boundsWidth) {
return w;
@@ -354,7 +337,7 @@
return Math.signum(w) * boundsWidth;
}
} else {
- return measure(mLen, false, fmi, drawBounds, lineInfo);
+ return measure(mLen, false, fmi, drawBounds);
}
}
@@ -424,13 +407,12 @@
* the edge of the preceding run's edge. See example above.
* @param fmi receives metrics information about the requested character, can be null
* @param drawBounds output parameter for drawing bounding box. optional.
- * @param lineInfo an optional output parameter for filling line information.
* @return the signed graphical offset from the leading margin to the requested character edge.
* The positive value means the offset is right from the leading edge. The negative
* value means the offset is left from the leading edge.
*/
public float measure(@IntRange(from = 0) int offset, boolean trailing,
- @NonNull FontMetricsInt fmi, @Nullable RectF drawBounds, @Nullable LineInfo lineInfo) {
+ @NonNull FontMetricsInt fmi, @Nullable RectF drawBounds) {
if (offset > mLen) {
throw new IndexOutOfBoundsException(
"offset(" + offset + ") should be less than line limit(" + mLen + ")");
@@ -455,16 +437,16 @@
if (targetIsInThisSegment && sameDirection) {
return h + measureRun(segStart, offset, j, runIsRtl, fmi, drawBounds, null,
- 0, h, lineInfo);
+ 0, h);
}
final float segmentWidth = measureRun(segStart, j, j, runIsRtl, fmi, drawBounds,
- null, 0, h, lineInfo);
+ null, 0, h);
h += sameDirection ? segmentWidth : -segmentWidth;
if (targetIsInThisSegment) {
return h + measureRun(segStart, offset, j, runIsRtl, null, null, null, 0,
- h, lineInfo);
+ h);
}
if (j != runLimit) { // charAt(j) == TAB_CHAR
@@ -555,8 +537,7 @@
final boolean sameDirection = (mDir == Layout.DIR_RIGHT_TO_LEFT) == runIsRtl;
final float segmentWidth =
- measureRun(segStart, j, j, runIsRtl, null, null, advances, segStart, 0,
- null);
+ measureRun(segStart, j, j, runIsRtl, null, null, advances, segStart, 0);
final float oldh = h;
h += sameDirection ? segmentWidth : -segmentWidth;
@@ -597,7 +578,7 @@
}
/**
- * @see #measure(int, boolean, FontMetricsInt, RectF, LineInfo)
+ * @see #measure(int, boolean, FontMetricsInt, RectF)
* @return The measure results for all possible offsets
*/
@VisibleForTesting
@@ -629,7 +610,7 @@
final float previousSegEndHorizontal = measurement[segStart];
final float width =
measureRun(segStart, j, j, runIsRtl, fmi, null, measurement, segStart,
- 0, null);
+ 0);
horizontal += sameDirection ? width : -width;
float currHorizontal = sameDirection ? oldHorizontal : horizontal;
@@ -694,14 +675,14 @@
boolean needWidth) {
if ((mDir == Layout.DIR_LEFT_TO_RIGHT) == runIsRtl) {
- float w = -measureRun(start, limit, limit, runIsRtl, null, null, null, 0, 0, null);
+ float w = -measureRun(start, limit, limit, runIsRtl, null, null, null, 0, 0);
handleRun(start, limit, limit, runIsRtl, c, null, x + w, top,
- y, bottom, null, null, false, null, 0, null);
+ y, bottom, null, null, false, null, 0);
return w;
}
return handleRun(start, limit, limit, runIsRtl, c, null, x, top,
- y, bottom, null, null, needWidth, null, 0, null);
+ y, bottom, null, null, needWidth, null, 0);
}
/**
@@ -717,20 +698,19 @@
* @param advances receives the advance information about the requested run, can be null.
* @param advancesIndex the start index to fill in the advance information.
* @param x horizontal offset of the run.
- * @param lineInfo an optional output parameter for filling line information.
* @return the signed width from the start of the run to the leading edge
* of the character at offset, based on the run (not paragraph) direction
*/
private float measureRun(int start, int offset, int limit, boolean runIsRtl,
@Nullable FontMetricsInt fmi, @Nullable RectF drawBounds, @Nullable float[] advances,
- int advancesIndex, float x, @Nullable LineInfo lineInfo) {
+ int advancesIndex, float x) {
if (drawBounds != null && (mDir == Layout.DIR_LEFT_TO_RIGHT) == runIsRtl) {
- float w = -measureRun(start, offset, limit, runIsRtl, null, null, null, 0, 0, null);
+ float w = -measureRun(start, offset, limit, runIsRtl, null, null, null, 0, 0);
return handleRun(start, offset, limit, runIsRtl, null, null, x + w, 0, 0, 0, fmi,
- drawBounds, true, advances, advancesIndex, lineInfo);
+ drawBounds, true, advances, advancesIndex);
}
return handleRun(start, offset, limit, runIsRtl, null, null, x, 0, 0, 0, fmi, drawBounds,
- true, advances, advancesIndex, lineInfo);
+ true, advances, advancesIndex);
}
/**
@@ -749,14 +729,14 @@
int limit, boolean runIsRtl, float x, boolean needWidth) {
if ((mDir == Layout.DIR_LEFT_TO_RIGHT) == runIsRtl) {
- float w = -measureRun(start, limit, limit, runIsRtl, null, null, null, 0, 0, null);
+ float w = -measureRun(start, limit, limit, runIsRtl, null, null, null, 0, 0);
handleRun(start, limit, limit, runIsRtl, null, consumer, x + w, 0, 0, 0, null, null,
- false, null, 0, null);
+ false, null, 0);
return w;
}
return handleRun(start, limit, limit, runIsRtl, null, consumer, x, 0, 0, 0, null, null,
- needWidth, null, 0, null);
+ needWidth, null, 0);
}
@@ -1097,35 +1077,16 @@
private float getRunAdvance(TextPaint wp, int start, int end, int contextStart, int contextEnd,
boolean runIsRtl, int offset, @Nullable float[] advances, int advancesIndex,
- RectF drawingBounds, @Nullable LineInfo lineInfo) {
- if (lineInfo != null) {
- if (mRunInfo == null) {
- mRunInfo = new Paint.RunInfo();
- }
- mRunInfo.setClusterCount(0);
- } else {
- mRunInfo = null;
- }
+ RectF drawingBounds) {
if (mCharsValid) {
- float r = wp.getRunCharacterAdvance(mChars, start, end, contextStart, contextEnd,
- runIsRtl, offset, advances, advancesIndex, drawingBounds, mRunInfo);
- if (lineInfo != null) {
- lineInfo.setClusterCount(lineInfo.getClusterCount() + mRunInfo.getClusterCount());
- }
- return r;
+ return wp.getRunCharacterAdvance(mChars, start, end, contextStart, contextEnd,
+ runIsRtl, offset, advances, advancesIndex, drawingBounds);
} else {
final int delta = mStart;
- // TODO: Add cluster information to the PrecomputedText for better performance of
- // justification.
- if (mComputed == null || advances != null || lineInfo != null) {
- float r = wp.getRunCharacterAdvance(mText, delta + start, delta + end,
+ if (mComputed == null || advances != null) {
+ return wp.getRunCharacterAdvance(mText, delta + start, delta + end,
delta + contextStart, delta + contextEnd, runIsRtl,
- delta + offset, advances, advancesIndex, drawingBounds, mRunInfo);
- if (lineInfo != null) {
- lineInfo.setClusterCount(
- lineInfo.getClusterCount() + mRunInfo.getClusterCount());
- }
- return r;
+ delta + offset, advances, advancesIndex, drawingBounds);
} else {
if (drawingBounds != null) {
if (mTmpRectForPrecompute == null) {
@@ -1159,7 +1120,6 @@
* @param decorations the list of locations and paremeters for drawing decorations
* @param advances receives the advance information about the requested run, can be null.
* @param advancesIndex the start index to fill in the advance information.
- * @param lineInfo an optional output parameter for filling line information.
* @return the signed width of the run based on the run direction; only
* valid if needWidth is true
*/
@@ -1168,7 +1128,7 @@
Canvas c, TextShaper.GlyphsConsumer consumer, float x, int top, int y, int bottom,
FontMetricsInt fmi, RectF drawBounds, boolean needWidth, int offset,
@Nullable ArrayList<DecorationInfo> decorations,
- @Nullable float[] advances, int advancesIndex, @Nullable LineInfo lineInfo) {
+ @Nullable float[] advances, int advancesIndex) {
if (mIsJustifying) {
wp.setWordSpacing(mAddedWidthForJustify);
@@ -1195,8 +1155,7 @@
mTmpRectForPaintAPI = new RectF();
}
totalWidth = getRunAdvance(wp, start, end, contextStart, contextEnd, runIsRtl, offset,
- advances, advancesIndex, drawBounds == null ? null : mTmpRectForPaintAPI,
- lineInfo);
+ advances, advancesIndex, drawBounds == null ? null : mTmpRectForPaintAPI);
if (drawBounds != null) {
if (runIsRtl) {
mTmpRectForPaintAPI.offset(x - totalWidth, 0);
@@ -1247,9 +1206,9 @@
final int decorationStart = Math.max(info.start, start);
final int decorationEnd = Math.min(info.end, offset);
float decorationStartAdvance = getRunAdvance(wp, start, end, contextStart,
- contextEnd, runIsRtl, decorationStart, null, 0, null, null);
+ contextEnd, runIsRtl, decorationStart, null, 0, null);
float decorationEndAdvance = getRunAdvance(wp, start, end, contextStart,
- contextEnd, runIsRtl, decorationEnd, null, 0, null, null);
+ contextEnd, runIsRtl, decorationEnd, null, 0, null);
final float decorationXLeft, decorationXRight;
if (runIsRtl) {
decorationXLeft = rightX - decorationEndAdvance;
@@ -1418,7 +1377,6 @@
* @param needWidth true if the width is required
* @param advances receives the advance information about the requested run, can be null.
* @param advancesIndex the start index to fill in the advance information.
- * @param lineInfo an optional output parameter for filling line information.
* @return the signed width of the run based on the run direction; only
* valid if needWidth is true
*/
@@ -1426,7 +1384,7 @@
int limit, boolean runIsRtl, Canvas c,
TextShaper.GlyphsConsumer consumer, float x, int top, int y,
int bottom, FontMetricsInt fmi, RectF drawBounds, boolean needWidth,
- @Nullable float[] advances, int advancesIndex, @Nullable LineInfo lineInfo) {
+ @Nullable float[] advances, int advancesIndex) {
if (measureLimit < start || measureLimit > limit) {
throw new IndexOutOfBoundsException("measureLimit (" + measureLimit + ") is out of "
@@ -1473,7 +1431,7 @@
wp.setEndHyphenEdit(adjustEndHyphenEdit(limit, wp.getEndHyphenEdit()));
return handleText(wp, start, limit, start, limit, runIsRtl, c, consumer, x, top,
y, bottom, fmi, drawBounds, needWidth, measureLimit, null, advances,
- advancesIndex, lineInfo);
+ advancesIndex);
}
// Shaping needs to take into account context up to metric boundaries,
@@ -1565,7 +1523,7 @@
consumer, x, top, y, bottom, fmi, drawBounds,
needWidth || activeEnd < measureLimit,
Math.min(activeEnd, mlimit), mDecorations,
- advances, advancesIndex + activeStart - start, lineInfo);
+ advances, advancesIndex + activeStart - start);
activeStart = j;
activePaint.set(wp);
@@ -1593,7 +1551,7 @@
x += handleText(activePaint, activeStart, activeEnd, i, inext, runIsRtl, c, consumer, x,
top, y, bottom, fmi, drawBounds, needWidth || activeEnd < measureLimit,
Math.min(activeEnd, mlimit), mDecorations,
- advances, advancesIndex + activeStart - start, lineInfo);
+ advances, advancesIndex + activeStart - start);
}
return x - originalX;
diff --git a/core/tests/coretests/src/android/graphics/PaintTest.java b/core/tests/coretests/src/android/graphics/PaintTest.java
index 0dec756..bf56df1 100644
--- a/core/tests/coretests/src/android/graphics/PaintTest.java
+++ b/core/tests/coretests/src/android/graphics/PaintTest.java
@@ -19,7 +19,6 @@
import static org.junit.Assert.assertNotEquals;
import android.test.InstrumentationTestCase;
-import android.text.TextUtils;
import androidx.test.filters.SmallTest;
@@ -363,44 +362,4 @@
// = 30
assertEquals(30.0f, p.getUnderlineThickness(), 0.5f);
}
-
- private int getClusterCount(Paint p, String text) {
- Paint.RunInfo runInfo = new Paint.RunInfo();
- p.getRunCharacterAdvance(text, 0, text.length(), 0, text.length(), false, 0, null, 0, null,
- runInfo);
- int ccByString = runInfo.getClusterCount();
- runInfo.setClusterCount(0);
- char[] buf = new char[text.length()];
- TextUtils.getChars(text, 0, text.length(), buf, 0);
- p.getRunCharacterAdvance(buf, 0, buf.length, 0, buf.length, false, 0, null, 0, null,
- runInfo);
- int ccByChars = runInfo.getClusterCount();
- assertEquals(ccByChars, ccByString);
- return ccByChars;
- }
-
- public void testCluster() {
- final Paint p = new Paint();
- p.setTextSize(100);
-
- // Regular String
- assertEquals(1, getClusterCount(p, "A"));
- assertEquals(2, getClusterCount(p, "AB"));
-
- // Ligature is in the same cluster
- assertEquals(1, getClusterCount(p, "fi")); // Ligature
- p.setFontFeatureSettings("'liga' off");
- assertEquals(2, getClusterCount(p, "fi")); // Ligature is disabled
- p.setFontFeatureSettings("");
-
- // Combining character
- assertEquals(1, getClusterCount(p, "\u0061\u0300")); // A + COMBINING GRAVE ACCENT
-
- // BiDi
- final String rtlStr = "\u05D0\u05D1\u05D2";
- final String ltrStr = "abc";
- assertEquals(3, getClusterCount(p, rtlStr));
- assertEquals(6, getClusterCount(p, rtlStr + ltrStr));
- assertEquals(9, getClusterCount(p, ltrStr + rtlStr + ltrStr));
- }
}
diff --git a/core/tests/coretests/src/android/text/TextLineTest.java b/core/tests/coretests/src/android/text/TextLineTest.java
index a31992c..34842a0 100644
--- a/core/tests/coretests/src/android/text/TextLineTest.java
+++ b/core/tests/coretests/src/android/text/TextLineTest.java
@@ -50,11 +50,11 @@
tl.set(paint, line, 0, line.length(), Layout.DIR_LEFT_TO_RIGHT,
Layout.DIRS_ALL_LEFT_TO_RIGHT, false /* hasTabs */, null /* tabStops */,
0, 0 /* no ellipsis */, false /* useFallbackLinespace */);
- final float originalWidth = tl.metrics(null, null, false, null);
+ final float originalWidth = tl.metrics(null, null, false);
final float expandedWidth = 2 * originalWidth;
tl.justify(expandedWidth);
- final float newWidth = tl.metrics(null, null, false, null);
+ final float newWidth = tl.metrics(null, null, false);
TextLine.recycle(tl);
return Math.abs(newWidth - expandedWidth) < 0.5;
}
@@ -128,7 +128,7 @@
private void assertMeasurements(final TextLine tl, final int length, boolean trailing,
final float[] expected) {
for (int offset = 0; offset <= length; ++offset) {
- assertEquals(expected[offset], tl.measure(offset, trailing, null, null, null), 0.0f);
+ assertEquals(expected[offset], tl.measure(offset, trailing, null, null), 0.0f);
}
final boolean[] trailings = new boolean[length + 1];
@@ -318,7 +318,7 @@
tl.set(new TextPaint(), text, 0, text.length(), 1, Layout.DIRS_ALL_LEFT_TO_RIGHT,
false /* hasTabs */, null /* tabStops */, 9, 12,
false /* useFallbackLineSpacing */);
- tl.measure(text.length(), false /* trailing */, null /* fmi */, null, null);
+ tl.measure(text.length(), false /* trailing */, null /* fmi */, null);
assertFalse(span.mIsUsed);
}
@@ -335,7 +335,7 @@
tl.set(new TextPaint(), text, 0, text.length(), 1, Layout.DIRS_ALL_LEFT_TO_RIGHT,
false /* hasTabs */, null /* tabStops */, 9, 12,
false /* useFallbackLineSpacing */);
- tl.measure(text.length(), false /* trailing */, null /* fmi */, null, null);
+ tl.measure(text.length(), false /* trailing */, null /* fmi */, null);
assertTrue(span.mIsUsed);
}
@@ -352,7 +352,7 @@
tl.set(new TextPaint(), text, 0, text.length(), 1, Layout.DIRS_ALL_LEFT_TO_RIGHT,
false /* hasTabs */, null /* tabStops */, 9, 12,
false /* useFallbackLineSpacing */);
- tl.measure(text.length(), false /* trailing */, null /* fmi */, null, null);
+ tl.measure(text.length(), false /* trailing */, null /* fmi */, null);
assertTrue(span.mIsUsed);
}
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index 3e8f442..f10cdb8 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -2474,19 +2474,6 @@
nGetFontMetricsInt(mNativePaint, metrics, true);
}
- /** @hide */
- public static final class RunInfo {
- private int mClusterCount = 0;
-
- public int getClusterCount() {
- return mClusterCount;
- }
-
- public void setClusterCount(int clusterCount) {
- mClusterCount = clusterCount;
- }
- }
-
/**
* Return the recommend line spacing based on the current typeface and
* text size.
@@ -3333,7 +3320,7 @@
int contextEnd, boolean isRtl, int offset,
@Nullable float[] advances, int advancesIndex) {
return getRunCharacterAdvance(text, start, end, contextStart, contextEnd, isRtl, offset,
- advances, advancesIndex, null, null);
+ advances, advancesIndex, null);
}
/**
@@ -3352,14 +3339,12 @@
* @param advances the array that receives the computed character advances
* @param advancesIndex the start index from which the advances array is filled
* @param drawBounds the output parameter for the bounding box of drawing text, optional
- * @param runInfo the output parameter for storing run information.
* @return width measurement between start and offset
- * @hide TODO: Reorganize APIs
+ * @hide
*/
public float getRunCharacterAdvance(@NonNull char[] text, int start, int end, int contextStart,
int contextEnd, boolean isRtl, int offset,
- @Nullable float[] advances, int advancesIndex, @Nullable RectF drawBounds,
- @Nullable RunInfo runInfo) {
+ @Nullable float[] advances, int advancesIndex, @Nullable RectF drawBounds) {
if (text == null) {
throw new IllegalArgumentException("text cannot be null");
}
@@ -3385,14 +3370,11 @@
}
if (end == start) {
- if (runInfo != null) {
- runInfo.setClusterCount(0);
- }
return 0.0f;
}
return nGetRunCharacterAdvance(mNativePaint, text, start, end, contextStart, contextEnd,
- isRtl, offset, advances, advancesIndex, drawBounds, runInfo);
+ isRtl, offset, advances, advancesIndex, drawBounds);
}
/**
@@ -3420,7 +3402,7 @@
int contextStart, int contextEnd, boolean isRtl, int offset,
@Nullable float[] advances, int advancesIndex) {
return getRunCharacterAdvance(text, start, end, contextStart, contextEnd, isRtl, offset,
- advances, advancesIndex, null, null);
+ advances, advancesIndex, null);
}
/**
@@ -3436,14 +3418,12 @@
* @param advances the array that receives the computed character advances
* @param advancesIndex the start index from which the advances array is filled
* @param drawBounds the output parameter for the bounding box of drawing text, optional
- * @param runInfo an optional output parameter for filling run information.
* @return width measurement between start and offset
- * @hide TODO: Reorganize APIs
+ * @hide
*/
public float getRunCharacterAdvance(@NonNull CharSequence text, int start, int end,
int contextStart, int contextEnd, boolean isRtl, int offset,
- @Nullable float[] advances, int advancesIndex, @Nullable RectF drawBounds,
- @Nullable RunInfo runInfo) {
+ @Nullable float[] advances, int advancesIndex, @Nullable RectF drawBounds) {
if (text == null) {
throw new IllegalArgumentException("text cannot be null");
}
@@ -3476,7 +3456,7 @@
TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
final float result = getRunCharacterAdvance(buf, start - contextStart, end - contextStart,
0, contextEnd - contextStart, isRtl, offset - contextStart,
- advances, advancesIndex, drawBounds, runInfo);
+ advances, advancesIndex, drawBounds);
TemporaryBuffer.recycle(buf);
return result;
}
@@ -3594,7 +3574,7 @@
int contextStart, int contextEnd, boolean isRtl, int offset);
private static native float nGetRunCharacterAdvance(long paintPtr, char[] text, int start,
int end, int contextStart, int contextEnd, boolean isRtl, int offset, float[] advances,
- int advancesIndex, RectF drawingBounds, RunInfo runInfo);
+ int advancesIndex, RectF drawingBounds);
private static native int nGetOffsetForAdvance(long paintPtr, char[] text, int start, int end,
int contextStart, int contextEnd, boolean isRtl, float advance);
private static native void nGetFontMetricsIntForText(long paintPtr, char[] text,
diff --git a/libs/hwui/hwui/MinikinUtils.cpp b/libs/hwui/hwui/MinikinUtils.cpp
index 833069f..7552b56d 100644
--- a/libs/hwui/hwui/MinikinUtils.cpp
+++ b/libs/hwui/hwui/MinikinUtils.cpp
@@ -96,7 +96,7 @@
float MinikinUtils::measureText(const Paint* paint, minikin::Bidi bidiFlags,
const Typeface* typeface, const uint16_t* buf, size_t start,
size_t count, size_t bufSize, float* advances,
- minikin::MinikinRect* bounds, uint32_t* clusterCount) {
+ minikin::MinikinRect* bounds) {
minikin::MinikinPaint minikinPaint = prepareMinikinPaint(paint, typeface);
const minikin::U16StringPiece textBuf(buf, bufSize);
const minikin::Range range(start, start + count);
@@ -104,7 +104,7 @@
const minikin::EndHyphenEdit endHyphen = paint->getEndHyphenEdit();
return minikin::Layout::measureText(textBuf, range, bidiFlags, minikinPaint, startHyphen,
- endHyphen, advances, bounds, clusterCount);
+ endHyphen, advances, bounds);
}
minikin::MinikinExtent MinikinUtils::getFontExtent(const Paint* paint, minikin::Bidi bidiFlags,
diff --git a/libs/hwui/hwui/MinikinUtils.h b/libs/hwui/hwui/MinikinUtils.h
index f8574ee..61bc881 100644
--- a/libs/hwui/hwui/MinikinUtils.h
+++ b/libs/hwui/hwui/MinikinUtils.h
@@ -53,7 +53,7 @@
static float measureText(const Paint* paint, minikin::Bidi bidiFlags, const Typeface* typeface,
const uint16_t* buf, size_t start, size_t count, size_t bufSize,
- float* advances, minikin::MinikinRect* bounds, uint32_t* clusterCount);
+ float* advances, minikin::MinikinRect* bounds);
static minikin::MinikinExtent getFontExtent(const Paint* paint, minikin::Bidi bidiFlags,
const Typeface* typeface, const uint16_t* buf,
diff --git a/libs/hwui/jni/Graphics.cpp b/libs/hwui/jni/Graphics.cpp
index 8315c4c..7cc4866 100644
--- a/libs/hwui/jni/Graphics.cpp
+++ b/libs/hwui/jni/Graphics.cpp
@@ -247,9 +247,6 @@
static jfieldID gFontMetricsInt_bottom;
static jfieldID gFontMetricsInt_leading;
-static jclass gRunInfo_class;
-static jfieldID gRunInfo_clusterCount;
-
///////////////////////////////////////////////////////////////////////////////
void GraphicsJNI::get_jrect(JNIEnv* env, jobject obj, int* L, int* T, int* R, int* B)
@@ -514,10 +511,6 @@
return descent - ascent + leading;
}
-void GraphicsJNI::set_cluster_count_to_run_info(JNIEnv* env, jobject runInfo, jint clusterCount) {
- env->SetIntField(runInfo, gRunInfo_clusterCount, clusterCount);
-}
-
///////////////////////////////////////////////////////////////////////////////////////////
jobject GraphicsJNI::createBitmapRegionDecoder(JNIEnv* env, BitmapRegionDecoderWrapper* bitmap) {
@@ -841,10 +834,5 @@
gFontMetricsInt_bottom = GetFieldIDOrDie(env, gFontMetricsInt_class, "bottom", "I");
gFontMetricsInt_leading = GetFieldIDOrDie(env, gFontMetricsInt_class, "leading", "I");
- gRunInfo_class = FindClassOrDie(env, "android/graphics/Paint$RunInfo");
- gRunInfo_class = MakeGlobalRefOrDie(env, gRunInfo_class);
-
- gRunInfo_clusterCount = GetFieldIDOrDie(env, gRunInfo_class, "mClusterCount", "I");
-
return 0;
}
diff --git a/libs/hwui/jni/GraphicsJNI.h b/libs/hwui/jni/GraphicsJNI.h
index b0a1074..b9fff36 100644
--- a/libs/hwui/jni/GraphicsJNI.h
+++ b/libs/hwui/jni/GraphicsJNI.h
@@ -77,8 +77,6 @@
static SkRect* jrect_to_rect(JNIEnv*, jobject jrect, SkRect*);
static void rect_to_jrectf(const SkRect&, JNIEnv*, jobject jrectf);
- static void set_cluster_count_to_run_info(JNIEnv* env, jobject runInfo, jint clusterCount);
-
static void set_jpoint(JNIEnv*, jobject jrect, int x, int y);
static SkIPoint* jpoint_to_ipoint(JNIEnv*, jobject jpoint, SkIPoint* point);
diff --git a/libs/hwui/jni/Paint.cpp b/libs/hwui/jni/Paint.cpp
index 286f06a..d84b73d 100644
--- a/libs/hwui/jni/Paint.cpp
+++ b/libs/hwui/jni/Paint.cpp
@@ -114,7 +114,7 @@
std::unique_ptr<float[]> advancesArray(new float[count]);
MinikinUtils::measureText(&paint, static_cast<minikin::Bidi>(bidiFlags), typeface, text, 0,
- count, count, advancesArray.get(), nullptr, nullptr);
+ count, count, advancesArray.get(), nullptr);
for (int i = 0; i < count; i++) {
// traverse in the given direction
@@ -206,7 +206,7 @@
}
const float advance = MinikinUtils::measureText(
paint, static_cast<minikin::Bidi>(bidiFlags), typeface, text, start, count,
- contextCount, advancesArray.get(), nullptr, nullptr);
+ contextCount, advancesArray.get(), nullptr);
if (advances) {
env->SetFloatArrayRegion(advances, advancesIndex, count, advancesArray.get());
}
@@ -244,7 +244,7 @@
minikin::Bidi bidiFlags = dir == 1 ? minikin::Bidi::FORCE_RTL : minikin::Bidi::FORCE_LTR;
std::unique_ptr<float[]> advancesArray(new float[count]);
MinikinUtils::measureText(paint, bidiFlags, typeface, text, start, count, start + count,
- advancesArray.get(), nullptr, nullptr);
+ advancesArray.get(), nullptr);
size_t result = minikin::GraphemeBreak::getTextRunCursor(advancesArray.get(), text,
start, count, offset, moveOpt);
return static_cast<jint>(result);
@@ -508,7 +508,7 @@
static jfloat doRunAdvance(JNIEnv* env, const Paint* paint, const Typeface* typeface,
const jchar buf[], jint start, jint count, jint bufSize,
jboolean isRtl, jint offset, jfloatArray advances,
- jint advancesIndex, SkRect* drawBounds, uint32_t* clusterCount) {
+ jint advancesIndex, SkRect* drawBounds) {
if (advances) {
size_t advancesLength = env->GetArrayLength(advances);
if ((size_t)(count + advancesIndex) > advancesLength) {
@@ -519,9 +519,9 @@
minikin::Bidi bidiFlags = isRtl ? minikin::Bidi::FORCE_RTL : minikin::Bidi::FORCE_LTR;
minikin::MinikinRect bounds;
if (offset == start + count && advances == nullptr) {
- float result = MinikinUtils::measureText(paint, bidiFlags, typeface, buf, start, count,
- bufSize, nullptr,
- drawBounds ? &bounds : nullptr, clusterCount);
+ float result =
+ MinikinUtils::measureText(paint, bidiFlags, typeface, buf, start, count,
+ bufSize, nullptr, drawBounds ? &bounds : nullptr);
if (drawBounds) {
copyMinikinRectToSkRect(bounds, drawBounds);
}
@@ -529,8 +529,7 @@
}
std::unique_ptr<float[]> advancesArray(new float[count]);
MinikinUtils::measureText(paint, bidiFlags, typeface, buf, start, count, bufSize,
- advancesArray.get(), drawBounds ? &bounds : nullptr,
- clusterCount);
+ advancesArray.get(), drawBounds ? &bounds : nullptr);
if (drawBounds) {
copyMinikinRectToSkRect(bounds, drawBounds);
@@ -550,7 +549,7 @@
ScopedCharArrayRO textArray(env, text);
jfloat result = doRunAdvance(env, paint, typeface, textArray.get() + contextStart,
start - contextStart, end - start, contextEnd - contextStart,
- isRtl, offset - contextStart, nullptr, 0, nullptr, nullptr);
+ isRtl, offset - contextStart, nullptr, 0, nullptr);
return result;
}
@@ -559,22 +558,18 @@
jint contextStart, jint contextEnd,
jboolean isRtl, jint offset,
jfloatArray advances, jint advancesIndex,
- jobject drawBounds, jobject runInfo) {
+ jobject drawBounds) {
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
const Typeface* typeface = paint->getAndroidTypeface();
ScopedCharArrayRO textArray(env, text);
SkRect skDrawBounds;
- uint32_t clusterCount = 0;
jfloat result = doRunAdvance(env, paint, typeface, textArray.get() + contextStart,
start - contextStart, end - start, contextEnd - contextStart,
isRtl, offset - contextStart, advances, advancesIndex,
- drawBounds ? &skDrawBounds : nullptr, &clusterCount);
+ drawBounds ? &skDrawBounds : nullptr);
if (drawBounds != nullptr) {
GraphicsJNI::rect_to_jrectf(skDrawBounds, env, drawBounds);
}
- if (runInfo) {
- GraphicsJNI::set_cluster_count_to_run_info(env, runInfo, clusterCount);
- }
return result;
}
@@ -583,7 +578,7 @@
minikin::Bidi bidiFlags = isRtl ? minikin::Bidi::FORCE_RTL : minikin::Bidi::FORCE_LTR;
std::unique_ptr<float[]> advancesArray(new float[count]);
MinikinUtils::measureText(paint, bidiFlags, typeface, buf, start, count, bufSize,
- advancesArray.get(), nullptr, nullptr);
+ advancesArray.get(), nullptr);
return minikin::getOffsetForAdvance(advancesArray.get(), buf, start, count, advance);
}
@@ -1150,8 +1145,7 @@
(void*)PaintGlue::getCharArrayBounds},
{"nHasGlyph", "(JILjava/lang/String;)Z", (void*)PaintGlue::hasGlyph},
{"nGetRunAdvance", "(J[CIIIIZI)F", (void*)PaintGlue::getRunAdvance___CIIIIZI_F},
- {"nGetRunCharacterAdvance",
- "(J[CIIIIZI[FILandroid/graphics/RectF;Landroid/graphics/Paint$RunInfo;)F",
+ {"nGetRunCharacterAdvance", "(J[CIIIIZI[FILandroid/graphics/RectF;)F",
(void*)PaintGlue::getRunCharacterAdvance___CIIIIZI_FI_F},
{"nGetOffsetForAdvance", "(J[CIIIIZF)I", (void*)PaintGlue::getOffsetForAdvance___CIIIIZF_I},
{"nGetFontMetricsIntForText", "(J[CIIIIZLandroid/graphics/Paint$FontMetricsInt;)V",