Merge "Remove mtOffset from drawTextRun" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
bc20993e4b
@@ -474,8 +474,7 @@ public class RecordingCanvas extends Canvas {
|
||||
}
|
||||
|
||||
nDrawTextRun(mNativeCanvasWrapper, text, index, count, contextIndex, contextCount,
|
||||
x, y, isRtl, paint.getNativeInstance(), 0 /* measured text */,
|
||||
0 /* measured text offset */);
|
||||
x, y, isRtl, paint.getNativeInstance(), 0 /* measured text */);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -506,19 +505,16 @@ public class RecordingCanvas extends Canvas {
|
||||
char[] buf = TemporaryBuffer.obtain(contextLen);
|
||||
TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
|
||||
long measuredTextPtr = 0;
|
||||
int measuredTextOffset = 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();
|
||||
measuredTextOffset = start - mt.getParagraphStart(paraIndex);
|
||||
}
|
||||
}
|
||||
nDrawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len,
|
||||
0, contextLen, x, y, isRtl, paint.getNativeInstance(),
|
||||
measuredTextPtr, measuredTextOffset);
|
||||
0, contextLen, x, y, isRtl, paint.getNativeInstance(), measuredTextPtr);
|
||||
TemporaryBuffer.recycle(buf);
|
||||
}
|
||||
}
|
||||
@@ -641,7 +637,7 @@ public class RecordingCanvas extends Canvas {
|
||||
@FastNative
|
||||
private static native void nDrawTextRun(long nativeCanvas, char[] text, int start, int count,
|
||||
int contextStart, int contextCount, float x, float y, boolean isRtl, long nativePaint,
|
||||
long nativePrecomputedText, int measuredTextOffset);
|
||||
long nativePrecomputedText);
|
||||
|
||||
@FastNative
|
||||
private static native void nDrawTextOnPath(long nativeCanvas, char[] text, int index, int count,
|
||||
|
||||
@@ -309,7 +309,7 @@ namespace PaintGlue {
|
||||
jint count, jint bidiFlags, jfloat x, jfloat y, SkPath* path) {
|
||||
minikin::Layout layout = MinikinUtils::doLayout(
|
||||
paint, static_cast<minikin::Bidi>(bidiFlags), typeface, text, 0, count, count,
|
||||
nullptr, 0);
|
||||
nullptr);
|
||||
size_t nGlyphs = layout.nGlyphs();
|
||||
uint16_t* glyphs = new uint16_t[nGlyphs];
|
||||
SkPoint* pos = new SkPoint[nGlyphs];
|
||||
@@ -351,8 +351,7 @@ namespace PaintGlue {
|
||||
SkIRect ir;
|
||||
|
||||
minikin::Layout layout = MinikinUtils::doLayout(&paint,
|
||||
static_cast<minikin::Bidi>(bidiFlags), typeface, text, 0, count, count, nullptr,
|
||||
0);
|
||||
static_cast<minikin::Bidi>(bidiFlags), typeface, text, 0, count, count, nullptr);
|
||||
minikin::MinikinRect rect;
|
||||
layout.getBounds(&rect);
|
||||
r.fLeft = rect.mLeft;
|
||||
@@ -468,7 +467,7 @@ namespace PaintGlue {
|
||||
}
|
||||
minikin::Layout layout = MinikinUtils::doLayout(paint,
|
||||
static_cast<minikin::Bidi>(bidiFlags), typeface, str.get(), 0, str.size(),
|
||||
str.size(), nullptr, 0);
|
||||
str.size(), nullptr);
|
||||
size_t nGlyphs = countNonSpaceGlyphs(layout);
|
||||
if (nGlyphs != 1 && nChars > 1) {
|
||||
// multiple-character input, and was not a ligature
|
||||
@@ -489,7 +488,7 @@ namespace PaintGlue {
|
||||
static const jchar ZZ_FLAG_STR[] = { 0xD83C, 0xDDFF, 0xD83C, 0xDDFF };
|
||||
minikin::Layout zzLayout = MinikinUtils::doLayout(paint,
|
||||
static_cast<minikin::Bidi>(bidiFlags), typeface, ZZ_FLAG_STR, 0, 4, 4,
|
||||
nullptr, 0);
|
||||
nullptr);
|
||||
if (zzLayout.nGlyphs() != 1 || layoutContainsNotdef(zzLayout)) {
|
||||
// The font collection doesn't have a glyph for unknown flag. Just return true.
|
||||
return true;
|
||||
|
||||
@@ -484,7 +484,7 @@ static void drawTextChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray t
|
||||
const Typeface* typeface = paint->getAndroidTypeface();
|
||||
jchar* jchars = env->GetCharArrayElements(text, NULL);
|
||||
get_canvas(canvasHandle)->drawText(jchars + index, 0, count, count, x, y,
|
||||
static_cast<minikin::Bidi>(bidiFlags), *paint, typeface, nullptr, 0);
|
||||
static_cast<minikin::Bidi>(bidiFlags), *paint, typeface, nullptr);
|
||||
env->ReleaseCharArrayElements(text, jchars, JNI_ABORT);
|
||||
}
|
||||
|
||||
@@ -496,13 +496,13 @@ static void drawTextString(JNIEnv* env, jobject, jlong canvasHandle, jstring tex
|
||||
const int count = end - start;
|
||||
const jchar* jchars = env->GetStringChars(text, NULL);
|
||||
get_canvas(canvasHandle)->drawText(jchars + start, 0, count, count, x, y,
|
||||
static_cast<minikin::Bidi>(bidiFlags), *paint, typeface, nullptr, 0);
|
||||
static_cast<minikin::Bidi>(bidiFlags), *paint, typeface, nullptr);
|
||||
env->ReleaseStringChars(text, jchars);
|
||||
}
|
||||
|
||||
static void drawTextRunChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray text, jint index,
|
||||
jint count, jint contextIndex, jint contextCount, jfloat x, jfloat y,
|
||||
jboolean isRtl, jlong paintHandle, jlong mtHandle, jint mtOffset) {
|
||||
jboolean isRtl, jlong paintHandle, jlong mtHandle) {
|
||||
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
|
||||
minikin::MeasuredText* mt = reinterpret_cast<minikin::MeasuredText*>(mtHandle);
|
||||
const Typeface* typeface = paint->getAndroidTypeface();
|
||||
@@ -510,8 +510,7 @@ static void drawTextRunChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArra
|
||||
const minikin::Bidi bidiFlags = isRtl ? minikin::Bidi::FORCE_RTL : minikin::Bidi::FORCE_LTR;
|
||||
jchar* jchars = env->GetCharArrayElements(text, NULL);
|
||||
get_canvas(canvasHandle)->drawText(jchars + contextIndex, index - contextIndex, count,
|
||||
contextCount, x, y, bidiFlags, *paint, typeface, mt,
|
||||
mtOffset);
|
||||
contextCount, x, y, bidiFlags, *paint, typeface, mt);
|
||||
env->ReleaseCharArrayElements(text, jchars, JNI_ABORT);
|
||||
}
|
||||
|
||||
@@ -526,7 +525,7 @@ static void drawTextRunString(JNIEnv* env, jobject obj, jlong canvasHandle, jstr
|
||||
jint contextCount = contextEnd - contextStart;
|
||||
const jchar* jchars = env->GetStringChars(text, NULL);
|
||||
get_canvas(canvasHandle)->drawText(jchars + contextStart, start - contextStart, count,
|
||||
contextCount, x, y, bidiFlags, *paint, typeface, nullptr, 0);
|
||||
contextCount, x, y, bidiFlags, *paint, typeface, nullptr);
|
||||
env->ReleaseStringChars(text, jchars);
|
||||
}
|
||||
|
||||
@@ -640,7 +639,7 @@ static const JNINativeMethod gDrawMethods[] = {
|
||||
{"nDrawBitmap", "(J[IIIFFIIZJ)V", (void*)CanvasJNI::drawBitmapArray},
|
||||
{"nDrawText","(J[CIIFFIJ)V", (void*) CanvasJNI::drawTextChars},
|
||||
{"nDrawText","(JLjava/lang/String;IIFFIJ)V", (void*) CanvasJNI::drawTextString},
|
||||
{"nDrawTextRun","(J[CIIIIFFZJJI)V", (void*) CanvasJNI::drawTextRunChars},
|
||||
{"nDrawTextRun","(J[CIIIIFFZJJ)V", (void*) CanvasJNI::drawTextRunChars},
|
||||
{"nDrawTextRun","(JLjava/lang/String;IIIIFFZJ)V", (void*) CanvasJNI::drawTextRunString},
|
||||
{"nDrawTextOnPath","(J[CIIJFFIJ)V", (void*) CanvasJNI::drawTextOnPathChars},
|
||||
{"nDrawTextOnPath","(JLjava/lang/String;JFFIJ)V", (void*) CanvasJNI::drawTextOnPathString},
|
||||
|
||||
@@ -454,8 +454,7 @@ public abstract class BaseCanvas {
|
||||
|
||||
throwIfHasHwBitmapInSwMode(paint);
|
||||
nDrawTextRun(mNativeCanvasWrapper, text, index, count, contextIndex, contextCount,
|
||||
x, y, isRtl, paint.getNativeInstance(), 0 /* measured text */,
|
||||
0 /* measured text offset */);
|
||||
x, y, isRtl, paint.getNativeInstance(), 0 /* measured text */);
|
||||
}
|
||||
|
||||
public void drawTextRun(@NonNull CharSequence text, int start, int end, int contextStart,
|
||||
@@ -486,19 +485,16 @@ public abstract class BaseCanvas {
|
||||
char[] buf = TemporaryBuffer.obtain(contextLen);
|
||||
TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
|
||||
long measuredTextPtr = 0;
|
||||
int measuredTextOffset = 0;
|
||||
if (text instanceof PrecomputedText) {
|
||||
PrecomputedText mt = (PrecomputedText) text;
|
||||
int paraIndex = mt.findParaIndex(start);
|
||||
if (end <= mt.getParagraphEnd(paraIndex)) {
|
||||
// Only suppor the same paragraph.
|
||||
// Only suppor the text in the same paragraph.
|
||||
measuredTextPtr = mt.getMeasuredParagraph(paraIndex).getNativePtr();
|
||||
measuredTextOffset = start - mt.getParagraphStart(paraIndex);
|
||||
}
|
||||
}
|
||||
nDrawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len,
|
||||
0, contextLen, x, y, isRtl, paint.getNativeInstance(),
|
||||
measuredTextPtr, measuredTextOffset);
|
||||
0, contextLen, x, y, isRtl, paint.getNativeInstance(), measuredTextPtr);
|
||||
TemporaryBuffer.recycle(buf);
|
||||
}
|
||||
}
|
||||
@@ -647,7 +643,7 @@ public abstract class BaseCanvas {
|
||||
|
||||
private static native void nDrawTextRun(long nativeCanvas, char[] text, int start, int count,
|
||||
int contextStart, int contextCount, float x, float y, boolean isRtl, long nativePaint,
|
||||
long nativePrecomputedText, int measuredTextOffset);
|
||||
long nativePrecomputedText);
|
||||
|
||||
private static native void nDrawTextOnPath(long nativeCanvas, char[] text, int index, int count,
|
||||
long nativePath, float hOffset, float vOffset, int bidiFlags, long nativePaint);
|
||||
|
||||
@@ -158,13 +158,13 @@ private:
|
||||
|
||||
void Canvas::drawText(const uint16_t* text, int start, int count, int contextCount, float x,
|
||||
float y, minikin::Bidi bidiFlags, const Paint& origPaint,
|
||||
const Typeface* typeface, minikin::MeasuredText* mt, int mtOffset) {
|
||||
const Typeface* typeface, minikin::MeasuredText* mt) {
|
||||
// minikin may modify the original paint
|
||||
Paint paint(origPaint);
|
||||
|
||||
minikin::Layout layout =
|
||||
MinikinUtils::doLayout(&paint, bidiFlags, typeface, text, start, count, contextCount,
|
||||
mt, mtOffset);
|
||||
mt);
|
||||
|
||||
x += MinikinUtils::xOffsetForTextAlign(&paint, layout);
|
||||
|
||||
@@ -212,8 +212,7 @@ void Canvas::drawTextOnPath(const uint16_t* text, int count, minikin::Bidi bidiF
|
||||
const Typeface* typeface) {
|
||||
Paint paintCopy(paint);
|
||||
minikin::Layout layout =
|
||||
MinikinUtils::doLayout(&paintCopy, bidiFlags, typeface, text, 0, count, count, nullptr,
|
||||
0);
|
||||
MinikinUtils::doLayout(&paintCopy, bidiFlags, typeface, text, 0, count, count, nullptr);
|
||||
hOffset += MinikinUtils::hOffsetForTextAlign(&paintCopy, layout, path);
|
||||
|
||||
// Set align to left for drawing, as we don't want individual
|
||||
|
||||
@@ -270,7 +270,7 @@ public:
|
||||
*/
|
||||
void drawText(const uint16_t* text, int start, int count, int contextCount, float x, float y,
|
||||
minikin::Bidi bidiFlags, const Paint& origPaint, const Typeface* typeface,
|
||||
minikin::MeasuredText* mt, int mtOffset);
|
||||
minikin::MeasuredText* mt);
|
||||
|
||||
void drawTextOnPath(const uint16_t* text, int count, minikin::Bidi bidiFlags,
|
||||
const SkPath& path, float hOffset, float vOffset, const Paint& paint,
|
||||
|
||||
@@ -49,8 +49,7 @@ minikin::MinikinPaint MinikinUtils::prepareMinikinPaint(const Paint* paint,
|
||||
|
||||
minikin::Layout MinikinUtils::doLayout(const Paint* paint, minikin::Bidi bidiFlags,
|
||||
const Typeface* typeface, const uint16_t* buf, size_t start,
|
||||
size_t count, size_t bufSize, minikin::MeasuredText* mt,
|
||||
int mtOffset) {
|
||||
size_t count, size_t bufSize, minikin::MeasuredText* mt) {
|
||||
minikin::MinikinPaint minikinPaint = prepareMinikinPaint(paint, typeface);
|
||||
minikin::Layout layout;
|
||||
|
||||
@@ -62,15 +61,9 @@ minikin::Layout MinikinUtils::doLayout(const Paint* paint, minikin::Bidi bidiFla
|
||||
|
||||
if (mt == nullptr) {
|
||||
layout.doLayout(textBuf,range, bidiFlags, minikinPaint, startHyphen, endHyphen);
|
||||
return layout;
|
||||
} else {
|
||||
mt->buildLayout(textBuf, range, minikinPaint, bidiFlags, startHyphen, endHyphen, &layout);
|
||||
}
|
||||
|
||||
if (mt->buildLayout(textBuf, range, minikinPaint, bidiFlags, mtOffset, startHyphen, endHyphen,
|
||||
&layout)) {
|
||||
return layout;
|
||||
}
|
||||
|
||||
layout.doLayout(textBuf, range, bidiFlags, minikinPaint, startHyphen, endHyphen);
|
||||
return layout;
|
||||
}
|
||||
|
||||
@@ -85,7 +78,8 @@ float MinikinUtils::measureText(const Paint* paint, minikin::Bidi bidiFlags,
|
||||
const minikin::EndHyphenEdit endHyphen = minikin::endHyphenEdit(hyphenEdit);
|
||||
|
||||
return minikin::Layout::measureText(textBuf, range, bidiFlags, minikinPaint, startHyphen,
|
||||
endHyphen, advances, nullptr /* extent */);
|
||||
endHyphen, advances, nullptr /* extent */,
|
||||
nullptr /* layout pieces */);
|
||||
}
|
||||
|
||||
bool MinikinUtils::hasVariationSelector(const Typeface* typeface, uint32_t codepoint, uint32_t vs) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
ANDROID_API static minikin::Layout doLayout(const Paint* paint, minikin::Bidi bidiFlags,
|
||||
const Typeface* typeface, const uint16_t* buf,
|
||||
size_t start, size_t count, size_t bufSize,
|
||||
minikin::MeasuredText* mt, int mtOffset);
|
||||
minikin::MeasuredText* mt);
|
||||
|
||||
ANDROID_API static float measureText(const Paint* paint, minikin::Bidi bidiFlags,
|
||||
const Typeface* typeface, const uint16_t* buf,
|
||||
|
||||
@@ -125,7 +125,7 @@ void TestUtils::drawUtf8ToCanvas(Canvas* canvas, const char* text, const SkPaint
|
||||
SkPaint glyphPaint(paint);
|
||||
glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
canvas->drawText(utf16.get(), 0, strlen(text), strlen(text), x, y, minikin::Bidi::LTR,
|
||||
glyphPaint, nullptr, nullptr /* measured text */, 0 /* measured text offset */);
|
||||
glyphPaint, nullptr, nullptr /* measured text */);
|
||||
}
|
||||
|
||||
void TestUtils::drawUtf8ToCanvas(Canvas* canvas, const char* text, const SkPaint& paint,
|
||||
|
||||
Reference in New Issue
Block a user