Loading core/java/android/text/Layout.java +27 −10 Original line number Diff line number Diff line Loading @@ -103,21 +103,38 @@ public abstract class Layout { ArrayUtils.emptyArray(ParagraphStyle.class); /** * Return how wide a layout must be in order to display the * specified text with one line per paragraph. * Return how wide a layout must be in order to display the specified text with one line per * paragraph. * * <p>As of O, Uses * {@link TextDirectionHeuristics#FIRSTSTRONG_LTR} as the default text direction heuristics. In * the earlier versions uses {@link TextDirectionHeuristics#LTR} as the default.</p> */ public static float getDesiredWidth(CharSequence source, TextPaint paint) { return getDesiredWidth(source, 0, source.length(), paint); } /** * Return how wide a layout must be in order to display the specified text slice with one * line per paragraph. * * <p>As of O, Uses * {@link TextDirectionHeuristics#FIRSTSTRONG_LTR} as the default text direction heuristics. In * the earlier versions uses {@link TextDirectionHeuristics#LTR} as the default.</p> */ public static float getDesiredWidth(CharSequence source, int start, int end, TextPaint paint) { return getDesiredWidth(source, start, end, paint, TextDirectionHeuristics.FIRSTSTRONG_LTR); } /** * Return how wide a layout must be in order to display the * specified text slice with one line per paragraph. * * @hide */ public static float getDesiredWidth(CharSequence source, int start, int end, TextPaint paint) { public static float getDesiredWidth(CharSequence source, int start, int end, TextPaint paint, TextDirectionHeuristic textDir) { float need = 0; int next; Loading @@ -128,7 +145,7 @@ public abstract class Layout { next = end; // note, omits trailing paragraph char float w = measurePara(paint, source, i, next); float w = measurePara(paint, source, i, next, textDir); if (w > need) need = w; Loading Loading @@ -1679,12 +1696,12 @@ public abstract class Layout { } /* package */ static float measurePara(TextPaint paint, CharSequence text, int start, int end) { static float measurePara(TextPaint paint, CharSequence text, int start, int end, TextDirectionHeuristic textDir) { MeasuredText mt = MeasuredText.obtain(); TextLine tl = TextLine.obtain(); try { mt.setPara(text, start, end, TextDirectionHeuristics.LTR, null); mt.setPara(text, start, end, textDir, null); Directions directions; int dir; if (mt.mEasy) { Loading Loading @@ -1726,7 +1743,7 @@ public abstract class Layout { } } tl.set(paint, text, start, end, dir, directions, hasTabs, tabStops); return margin + tl.metrics(null); return margin + Math.abs(tl.metrics(null)); } finally { TextLine.recycle(tl); MeasuredText.recycle(mt); Loading core/java/android/widget/Switch.java +3 −2 Original line number Diff line number Diff line Loading @@ -889,8 +889,9 @@ public class Switch extends CompoundButton { ? mSwitchTransformationMethod.getTransformation(text, this) : text; return new StaticLayout(transformed, mTextPaint, (int) Math.ceil(Layout.getDesiredWidth(transformed, mTextPaint)), int width = (int) Math.ceil(Layout.getDesiredWidth(transformed, 0, transformed.length(), mTextPaint, getTextDirectionHeuristic())); return new StaticLayout(transformed, mTextPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.f, 0, true); } Loading core/java/android/widget/TextView.java +4 −2 Original line number Diff line number Diff line Loading @@ -7076,7 +7076,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (boring == null || boring == UNKNOWN_BORING) { if (des < 0) { des = (int) Math.ceil(Layout.getDesiredWidth(mTransformed, mTextPaint)); des = (int) Math.ceil(Layout.getDesiredWidth(mTransformed, 0, mTransformed.length(), mTextPaint, mTextDir)); } width = des; } else { Loading Loading @@ -7106,7 +7107,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (hintBoring == null || hintBoring == UNKNOWN_BORING) { if (hintDes < 0) { hintDes = (int) Math.ceil(Layout.getDesiredWidth(mHint, mTextPaint)); hintDes = (int) Math.ceil(Layout.getDesiredWidth(mHint, 0, mHint.length(), mTextPaint, mTextDir)); } hintWidth = hintDes; } else { Loading core/java/com/android/internal/view/menu/IconMenuItemView.java +2 −1 Original line number Diff line number Diff line Loading @@ -265,7 +265,8 @@ public final class IconMenuItemView extends TextView implements MenuView.ItemVie } // Set the desired width of item lp.desiredWidth = (int) Layout.getDesiredWidth(getText(), getPaint()); lp.desiredWidth = (int) Layout.getDesiredWidth(getText(), 0, getText().length(), getPaint(), getTextDirectionHeuristic()); return lp; } Loading Loading
core/java/android/text/Layout.java +27 −10 Original line number Diff line number Diff line Loading @@ -103,21 +103,38 @@ public abstract class Layout { ArrayUtils.emptyArray(ParagraphStyle.class); /** * Return how wide a layout must be in order to display the * specified text with one line per paragraph. * Return how wide a layout must be in order to display the specified text with one line per * paragraph. * * <p>As of O, Uses * {@link TextDirectionHeuristics#FIRSTSTRONG_LTR} as the default text direction heuristics. In * the earlier versions uses {@link TextDirectionHeuristics#LTR} as the default.</p> */ public static float getDesiredWidth(CharSequence source, TextPaint paint) { return getDesiredWidth(source, 0, source.length(), paint); } /** * Return how wide a layout must be in order to display the specified text slice with one * line per paragraph. * * <p>As of O, Uses * {@link TextDirectionHeuristics#FIRSTSTRONG_LTR} as the default text direction heuristics. In * the earlier versions uses {@link TextDirectionHeuristics#LTR} as the default.</p> */ public static float getDesiredWidth(CharSequence source, int start, int end, TextPaint paint) { return getDesiredWidth(source, start, end, paint, TextDirectionHeuristics.FIRSTSTRONG_LTR); } /** * Return how wide a layout must be in order to display the * specified text slice with one line per paragraph. * * @hide */ public static float getDesiredWidth(CharSequence source, int start, int end, TextPaint paint) { public static float getDesiredWidth(CharSequence source, int start, int end, TextPaint paint, TextDirectionHeuristic textDir) { float need = 0; int next; Loading @@ -128,7 +145,7 @@ public abstract class Layout { next = end; // note, omits trailing paragraph char float w = measurePara(paint, source, i, next); float w = measurePara(paint, source, i, next, textDir); if (w > need) need = w; Loading Loading @@ -1679,12 +1696,12 @@ public abstract class Layout { } /* package */ static float measurePara(TextPaint paint, CharSequence text, int start, int end) { static float measurePara(TextPaint paint, CharSequence text, int start, int end, TextDirectionHeuristic textDir) { MeasuredText mt = MeasuredText.obtain(); TextLine tl = TextLine.obtain(); try { mt.setPara(text, start, end, TextDirectionHeuristics.LTR, null); mt.setPara(text, start, end, textDir, null); Directions directions; int dir; if (mt.mEasy) { Loading Loading @@ -1726,7 +1743,7 @@ public abstract class Layout { } } tl.set(paint, text, start, end, dir, directions, hasTabs, tabStops); return margin + tl.metrics(null); return margin + Math.abs(tl.metrics(null)); } finally { TextLine.recycle(tl); MeasuredText.recycle(mt); Loading
core/java/android/widget/Switch.java +3 −2 Original line number Diff line number Diff line Loading @@ -889,8 +889,9 @@ public class Switch extends CompoundButton { ? mSwitchTransformationMethod.getTransformation(text, this) : text; return new StaticLayout(transformed, mTextPaint, (int) Math.ceil(Layout.getDesiredWidth(transformed, mTextPaint)), int width = (int) Math.ceil(Layout.getDesiredWidth(transformed, 0, transformed.length(), mTextPaint, getTextDirectionHeuristic())); return new StaticLayout(transformed, mTextPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.f, 0, true); } Loading
core/java/android/widget/TextView.java +4 −2 Original line number Diff line number Diff line Loading @@ -7076,7 +7076,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (boring == null || boring == UNKNOWN_BORING) { if (des < 0) { des = (int) Math.ceil(Layout.getDesiredWidth(mTransformed, mTextPaint)); des = (int) Math.ceil(Layout.getDesiredWidth(mTransformed, 0, mTransformed.length(), mTextPaint, mTextDir)); } width = des; } else { Loading Loading @@ -7106,7 +7107,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (hintBoring == null || hintBoring == UNKNOWN_BORING) { if (hintDes < 0) { hintDes = (int) Math.ceil(Layout.getDesiredWidth(mHint, mTextPaint)); hintDes = (int) Math.ceil(Layout.getDesiredWidth(mHint, 0, mHint.length(), mTextPaint, mTextDir)); } hintWidth = hintDes; } else { Loading
core/java/com/android/internal/view/menu/IconMenuItemView.java +2 −1 Original line number Diff line number Diff line Loading @@ -265,7 +265,8 @@ public final class IconMenuItemView extends TextView implements MenuView.ItemVie } // Set the desired width of item lp.desiredWidth = (int) Layout.getDesiredWidth(getText(), getPaint()); lp.desiredWidth = (int) Layout.getDesiredWidth(getText(), 0, getText().length(), getPaint(), getTextDirectionHeuristic()); return lp; } Loading