diff options
| -rw-r--r-- | core/java/android/text/MeasuredParagraph.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/java/android/text/MeasuredParagraph.java b/core/java/android/text/MeasuredParagraph.java index 2b6684ea8f1d..a72d34de748f 100644 --- a/core/java/android/text/MeasuredParagraph.java +++ b/core/java/android/text/MeasuredParagraph.java @@ -700,6 +700,22 @@ public class MeasuredParagraph { bidiRequest = isRtl ? Bidi.RTL : Bidi.LTR; } mBidi = new Bidi(mCopiedBuffer, 0, null, 0, mCopiedBuffer.length, bidiRequest); + + if (mBidi.getParagraphIndex(mCopiedBuffer.length - 1) != 0) { + // Historically, the MeasuredParagraph does not treat the CR letters as paragraph + // breaker but ICU BiDi treats it as paragraph breaker. In the MeasureParagraph, + // the given range always represents a single paragraph, so if the BiDi object has + // multiple paragraph, it should contains a CR letters in the text. Using CR is not + // common in Android and also it should not penalize the easy case, e.g. all LTR, + // check the paragraph count here and replace the CR letters and re-calculate + // BiDi again. + for (int i = 0; i < mTextLength; ++i) { + if (mCopiedBuffer[i] == '\r') { + mCopiedBuffer[i] = OBJECT_REPLACEMENT_CHARACTER; + } + } + mBidi = new Bidi(mCopiedBuffer, 0, null, 0, mCopiedBuffer.length, bidiRequest); + } mLevels.resize(mTextLength); byte[] rawArray = mLevels.getRawArray(); for (int i = 0; i < mTextLength; ++i) { |