return count;
}
- static int doTextGlyphs(JNIEnv* env, SkPaint* paint, const jchar* text, jint start, jint count,
- jint contextCount, jint flags, jcharArray glyphs) {
- NPE_CHECK_RETURN_ZERO(env, paint);
- NPE_CHECK_RETURN_ZERO(env, text);
-
- if ((start | count | contextCount) < 0 || contextCount < count || !glyphs) {
- doThrowAIOOBE(env);
- return 0;
- }
- if (count == 0) {
- return 0;
- }
- size_t glypthsLength = env->GetArrayLength(glyphs);
- if ((size_t)count > glypthsLength) {
- doThrowAIOOBE(env);
- return 0;
- }
-
- jchar* glyphsArray = env->GetCharArrayElements(glyphs, NULL);
-
- sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint,
- text, start, count, contextCount, flags);
- const jchar* shapedGlyphs = value->getGlyphs();
- size_t glyphsCount = value->getGlyphsCount();
- memcpy(glyphsArray, shapedGlyphs, sizeof(jchar) * glyphsCount);
-
- env->ReleaseCharArrayElements(glyphs, glyphsArray, JNI_ABORT);
- return glyphsCount;
- }
-
- static jint getTextGlyphs__StringIIIII_C(JNIEnv* env, jobject clazz, jlong paintHandle,
- jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint flags,
- jcharArray glyphs) {
- SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
- const jchar* textArray = env->GetStringChars(text, NULL);
- int count = doTextGlyphs(env, paint, textArray + contextStart, start - contextStart,
- end - start, contextEnd - contextStart, flags, glyphs);
- env->ReleaseStringChars(text, textArray);
- return count;
- }
-
static jfloat doTextRunAdvances(JNIEnv *env, SkPaint *paint, TypefaceImpl* typeface, const jchar *text,
jint start, jint count, jint contextCount, jboolean isRtl,
jfloatArray advances, jint advancesIndex) {
{"native_getTextRunAdvances","(JJLjava/lang/String;IIIIZ[FI)F",
(void*) SkPaintGlue::getTextRunAdvances__StringIIIIZ_FI},
-
- {"native_getTextGlyphs","(JLjava/lang/String;IIIII[C)I",
- (void*) SkPaintGlue::getTextGlyphs__StringIIIII_C},
{"native_getTextRunCursor", "(J[CIIIII)I", (void*) SkPaintGlue::getTextRunCursor___C},
{"native_getTextRunCursor", "(JLjava/lang/String;IIIII)I",
(void*) SkPaintGlue::getTextRunCursor__String},
}
/**
- * Return the glyph Ids for the characters in the string.
- *
- * @param text The text to measure
- * @param start The index of the first char to to measure
- * @param end The end of the text slice to measure
- * @param contextStart the index of the first character to use for shaping context,
- * must be <= start
- * @param contextEnd the index past the last character to use for shaping context,
- * must be >= end
- * @param flags the flags to control the advances, either {@link #DIRECTION_LTR}
- * or {@link #DIRECTION_RTL}
- * @param glyphs array to receive the glyph Ids of the characters.
- * Must be at least a large as the text.
- * @return the number of glyphs in the returned array
- *
- * @hide
- *
- * Used only for BiDi / RTL Tests
- */
- public int getTextGlyphs(String text, int start, int end, int contextStart, int contextEnd,
- int flags, char[] glyphs) {
- if (text == null) {
- throw new IllegalArgumentException("text cannot be null");
- }
- if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) {
- throw new IllegalArgumentException("unknown flags value: " + flags);
- }
- if ((start | end | contextStart | contextEnd | (end - start)
- | (start - contextStart) | (contextEnd - end) | (text.length() - end)
- | (text.length() - contextEnd)) < 0) {
- throw new IndexOutOfBoundsException();
- }
- if (end - start > glyphs.length) {
- throw new ArrayIndexOutOfBoundsException();
- }
- return native_getTextGlyphs(mNativePaint, text, start, end, contextStart, contextEnd,
- flags, glyphs);
- }
-
- /**
* Convenience overload that takes a char array instead of a
* String.
*