android.text.style.MetricAffectingSpan Java Examples
The following examples show how to use
android.text.style.MetricAffectingSpan.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongolTextLine.java From mongol-library with MIT License | 6 votes |
TextRun(int offset, int length, boolean isRotated, boolean isSpanned) { this.offset = offset; this.length = length; this.isRotated = isRotated; TextPaintPlus wp; if (isSpanned) { wp = sWorkPaint; wp.set(mPaint); MetricAffectingSpan[] spans = ((Spanned) mText).getSpans(offset, offset + length, MetricAffectingSpan.class); for (MetricAffectingSpan span : spans) { span.updateDrawState(wp); } } else { wp = mPaint; } // just record the normal non-rotated values here // measure and draw will take rotation into account measuredWidth = wp.measureText(mText, offset, offset + length); measuredHeight = wp.getFontMetrics().bottom - wp.getFontMetrics().top; }
Example #2
Source File: TextLineImpl15.java From FastTextView with Apache License 2.0 | 6 votes |
/** * Returns the ascent of the text at start. This is used for scaling * emoji. * * @param pos the line-relative position * @return the ascent of the text at start */ float ascent(int pos) { if (mSpanned == null) { return mPaint.ascent(); } pos += mStart; MetricAffectingSpan[] spans = mSpanned.getSpans(pos, pos + 1, MetricAffectingSpan.class); if (spans.length == 0) { return mPaint.ascent(); } TextPaint wp = mWorkPaint; wp.set(mPaint); for (MetricAffectingSpan span : spans) { span.updateMeasureState(wp); } return wp.ascent(); }
Example #3
Source File: ShapingRunLocator.java From Tehreer-Android with Apache License 2.0 | 6 votes |
private @Nullable ShapingRun resolveRun(int runStart) { if (runStart < mLimit) { int runEnd = spanned.nextSpanTransition(runStart, mLimit, MetricAffectingSpan.class); MetricAffectingSpan[] spans = spanned.getSpans(runStart, runEnd, MetricAffectingSpan.class); ShapingRun shapingRun = new ShapingRun(); shapingRun.start = runStart; shapingRun.end = runEnd; shapingRun.typeface = initial.typeface; shapingRun.typeWeight = initial.typeWeight; shapingRun.typeSlope = initial.typeSlope; shapingRun.typeSize = initial.typeSize; shapingRun.scaleX = initial.scaleX; resolveSpans(shapingRun, spans); return shapingRun; } return null; }
Example #4
Source File: Spans.java From Pioneer with Apache License 2.0 | 6 votes |
@Override public int getSize(@NonNull Rect outRect, @NonNull Paint paint, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, @Nullable Paint.FontMetricsInt fm) { int width = super.getSize(outRect, paint, text, start, end, fm); if (styles != null) { for (CharacterStyle style : styles) { if (style instanceof SupportSpan) { width = Math.max(width, ((SupportSpan) style).getSize(frame, paint, text, start, end, fm)); } else if (style instanceof ReplacementSpan) { width = Math.max(width, ((ReplacementSpan) style).getSize(paint, text, start, end, fm)); } else if (paint instanceof TextPaint) { if (style instanceof MetricAffectingSpan) { ((MetricAffectingSpan) style).updateMeasureState((TextPaint) paint); } } } } frame.right = width; return width; }
Example #5
Source File: SpansV1.java From Pioneer with Apache License 2.0 | 6 votes |
@Override public int getSize(@NonNull Paint paint, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, @Nullable Paint.FontMetricsInt fm) { width = 0; for (CharacterStyle style : styles) { if (style instanceof ReplacementSpan) { width = Math.max(width, ((ReplacementSpan) style).getSize(paint, text, start, end, fm)); } else if (paint instanceof TextPaint) { if (style instanceof MetricAffectingSpan) { ((MetricAffectingSpan) style).updateMeasureState((TextPaint) paint); } } } if (fm != null) { paint.getFontMetricsInt(fm); } paint.getFontMetricsInt(fontMetricsInt); width = Math.max(width, (int) Math.ceil(paint.measureText(text, start, end))); frame.right = width; frame.top = fontMetricsInt.top; frame.bottom = fontMetricsInt.bottom; if (bitmap == null) { bitmap = Bitmap.createBitmap(width, frame.bottom - frame.top, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(bitmap); } return width; }
Example #6
Source File: Spans.java From Pioneer with Apache License 2.0 | 6 votes |
@Override public int getSize(@NonNull Rect outRect, @NonNull Paint paint, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, @Nullable Paint.FontMetricsInt fm) { int width = super.getSize(outRect, paint, text, start, end, fm); if (styles != null) { for (CharacterStyle style : styles) { if (style instanceof SupportSpan) { width = Math.max(width, ((SupportSpan) style).getSize(frame, paint, text, start, end, fm)); } else if (style instanceof ReplacementSpan) { width = Math.max(width, ((ReplacementSpan) style).getSize(paint, text, start, end, fm)); } else if (paint instanceof TextPaint) { if (style instanceof MetricAffectingSpan) { ((MetricAffectingSpan) style).updateMeasureState((TextPaint) paint); } } } } frame.right = width; return width; }
Example #7
Source File: SpansV1.java From Pioneer with Apache License 2.0 | 6 votes |
@Override public int getSize(@NonNull Paint paint, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, @Nullable Paint.FontMetricsInt fm) { width = 0; for (CharacterStyle style : styles) { if (style instanceof ReplacementSpan) { width = Math.max(width, ((ReplacementSpan) style).getSize(paint, text, start, end, fm)); } else if (paint instanceof TextPaint) { if (style instanceof MetricAffectingSpan) { ((MetricAffectingSpan) style).updateMeasureState((TextPaint) paint); } } } if (fm != null) { paint.getFontMetricsInt(fm); } paint.getFontMetricsInt(fontMetricsInt); width = Math.max(width, (int) Math.ceil(paint.measureText(text, start, end))); frame.right = width; frame.top = fontMetricsInt.top; frame.bottom = fontMetricsInt.bottom; if (bitmap == null) { bitmap = Bitmap.createBitmap(width, frame.bottom - frame.top, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(bitmap); } return width; }
Example #8
Source File: MeasuredParagraph.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Generates new MeasuredParagraph for measuring texts. * * If recycle is null, this returns new instance. If recycle is not null, this fills computed * result to recycle and returns recycle. * * @param paint the paint to be used for rendering the text. * @param text the character sequence to be measured * @param start the inclusive start offset of the target region in the text * @param end the exclusive end offset of the target region in the text * @param textDir the text direction * @param recycle pass existing MeasuredParagraph if you want to recycle it. * * @return measured text */ public static @NonNull MeasuredParagraph buildForMeasurement(@NonNull TextPaint paint, @NonNull CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, @NonNull TextDirectionHeuristic textDir, @Nullable MeasuredParagraph recycle) { final MeasuredParagraph mt = recycle == null ? obtain() : recycle; mt.resetAndAnalyzeBidi(text, start, end, textDir); mt.mWidths.resize(mt.mTextLength); if (mt.mTextLength == 0) { return mt; } if (mt.mSpanned == null) { // No style change by MetricsAffectingSpan. Just measure all text. mt.applyMetricsAffectingSpan( paint, null /* spans */, start, end, 0 /* native static layout ptr */); } else { // There may be a MetricsAffectingSpan. Split into span transitions and apply styles. int spanEnd; for (int spanStart = start; spanStart < end; spanStart = spanEnd) { spanEnd = mt.mSpanned.nextSpanTransition(spanStart, end, MetricAffectingSpan.class); MetricAffectingSpan[] spans = mt.mSpanned.getSpans(spanStart, spanEnd, MetricAffectingSpan.class); spans = TextUtils.removeEmptySpans(spans, mt.mSpanned, MetricAffectingSpan.class); mt.applyMetricsAffectingSpan( paint, spans, spanStart, spanEnd, 0 /* native static layout ptr */); } } return mt; }
Example #9
Source File: PrecomputedText.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @throws IllegalArgumentException if {@link MetricAffectingSpan} is specified. */ @Override public void setSpan(Object what, int start, int end, int flags) { if (what instanceof MetricAffectingSpan) { throw new IllegalArgumentException( "MetricAffectingSpan can not be set to PrecomputedText."); } mText.setSpan(what, start, end, flags); }
Example #10
Source File: PrecomputedText.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @throws IllegalArgumentException if {@link MetricAffectingSpan} is specified. */ @Override public void removeSpan(Object what) { if (what instanceof MetricAffectingSpan) { throw new IllegalArgumentException( "MetricAffectingSpan can not be removed from PrecomputedText."); } mText.removeSpan(what); }
Example #11
Source File: Truss.java From Pioneer with Apache License 2.0 | 5 votes |
private static MetricAffectingSpan convert(CharacterStyle style) { if (style instanceof MetricAffectingSpan) { return (MetricAffectingSpan) style; } else { return new MetricAffectAdapter(style); } }
Example #12
Source File: Truss.java From Pioneer with Apache License 2.0 | 5 votes |
private static MetricAffectingSpan convert(CharacterStyle style) { if (style instanceof MetricAffectingSpan) { return (MetricAffectingSpan) style; } else { return new MetricAffectAdapter(style); } }
Example #13
Source File: Truss.java From Pioneer with Apache License 2.0 | 4 votes |
public static MetricAffectingSpan wrap(CharacterStyle style) { return new MetricAffectAdapter(style); }
Example #14
Source File: Truss.java From Pioneer with Apache License 2.0 | 4 votes |
@Override public void updateMeasureState(TextPaint p) { if (style instanceof MetricAffectingSpan) { ((MetricAffectingSpan) style).updateMeasureState(p); } }
Example #15
Source File: Truss.java From Pioneer with Apache License 2.0 | 4 votes |
public static MetricAffectingSpan wrap(CharacterStyle style) { return new MetricAffectAdapter(style); }
Example #16
Source File: Truss.java From Pioneer with Apache License 2.0 | 4 votes |
@Override public void updateMeasureState(TextPaint p) { if (style instanceof MetricAffectingSpan) { ((MetricAffectingSpan) style).updateMeasureState(p); } }