android.text.GraphicsOperations Java Examples

The following examples show how to use android.text.GraphicsOperations. 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 Project: android_9.0.0_r45   Author: lulululbj   File: RecordingCanvas.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final void drawText(@NonNull CharSequence text, int start, int end, float x, float y,
        @NonNull Paint paint) {
    if ((start | end | (end - start) | (text.length() - end)) < 0) {
        throw new IndexOutOfBoundsException();
    }
    if (text instanceof String || text instanceof SpannedString
            || text instanceof SpannableString) {
        nDrawText(mNativeCanvasWrapper, text.toString(), start, end, x, y,
                paint.mBidiFlags, paint.getNativeInstance());
    } else if (text instanceof GraphicsOperations) {
        ((GraphicsOperations) text).drawText(this, start, end, x, y,
                paint);
    } else {
        char[] buf = TemporaryBuffer.obtain(end - start);
        TextUtils.getChars(text, start, end, buf, 0);
        nDrawText(mNativeCanvasWrapper, buf, 0, end - start, x, y,
                paint.mBidiFlags, paint.getNativeInstance());
        TemporaryBuffer.recycle(buf);
    }
}
 
Example #2
Source Project: android_9.0.0_r45   Author: lulululbj   File: RecordingCanvas.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public final void drawTextRun(@NonNull CharSequence text, int start, int end, int contextStart,
        int contextEnd, float x, float y, boolean isRtl, @NonNull Paint paint) {

    if (text == null) {
        throw new NullPointerException("text is null");
    }
    if (paint == null) {
        throw new NullPointerException("paint is null");
    }
    if ((start | end | contextStart | contextEnd | start - contextStart | end - start
            | contextEnd - end | text.length() - contextEnd) < 0) {
        throw new IndexOutOfBoundsException();
    }

    if (text instanceof String || text instanceof SpannedString
            || text instanceof SpannableString) {
        nDrawTextRun(mNativeCanvasWrapper, text.toString(), start, end, contextStart,
                contextEnd, x, y, isRtl, paint.getNativeInstance());
    } else if (text instanceof GraphicsOperations) {
        ((GraphicsOperations) text).drawTextRun(this, start, end,
                contextStart, contextEnd, x, y, isRtl, paint);
    } else {
        int contextLen = contextEnd - contextStart;
        int len = end - start;
        char[] buf = TemporaryBuffer.obtain(contextLen);
        TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
        long measuredTextPtr = 0;
        if (text instanceof PrecomputedText) {
            PrecomputedText mt = (PrecomputedText) text;
            int paraIndex = mt.findParaIndex(start);
            if (end <= mt.getParagraphEnd(paraIndex)) {
                // Only support if the target is in the same paragraph.
                measuredTextPtr = mt.getMeasuredParagraph(paraIndex).getNativePtr();
            }
        }
        nDrawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len,
                0, contextLen, x, y, isRtl, paint.getNativeInstance(), measuredTextPtr);
        TemporaryBuffer.recycle(buf);
    }
}