Merge "Remove nGetWidths and pass the jfloat[] as nComputeLineBreaks argument."
This commit is contained in:
committed by
Android (Google) Code Review
commit
a30e82213b
@@ -433,7 +433,6 @@ public class StaticLayout extends Layout {
|
||||
* + addStyleRun (a text run, to be measured in native code)
|
||||
* + addReplacementRun (a replacement run, width is given)
|
||||
*
|
||||
* After measurement, nGetWidths() is valid if the widths are needed (eg for ellipsis).
|
||||
* Run nComputeLineBreaks() to obtain line breaks for the paragraph.
|
||||
*
|
||||
* After all paragraphs, call finish() to release expensive buffers.
|
||||
@@ -866,10 +865,9 @@ public class StaticLayout extends Layout {
|
||||
spanEndCacheCount++;
|
||||
}
|
||||
|
||||
nGetWidths(b.mNativePtr, widths);
|
||||
int breakCount = nComputeLineBreaks(b.mNativePtr, lineBreaks, lineBreaks.breaks,
|
||||
lineBreaks.widths, lineBreaks.ascents, lineBreaks.descents, lineBreaks.flags,
|
||||
lineBreaks.breaks.length);
|
||||
lineBreaks.breaks.length, widths);
|
||||
|
||||
final int[] breaks = lineBreaks.breaks;
|
||||
final float[] lineWidths = lineBreaks.widths;
|
||||
@@ -1551,16 +1549,17 @@ public class StaticLayout extends Layout {
|
||||
@FloatRange(from = 0.0f) float width, @Nullable String languageTags,
|
||||
@Nullable long[] hyphenators);
|
||||
|
||||
private static native void nGetWidths(long nativePtr, float[] widths);
|
||||
|
||||
// populates LineBreaks and returns the number of breaks found
|
||||
//
|
||||
// the arrays inside the LineBreaks objects are passed in as well
|
||||
// to reduce the number of JNI calls in the common case where the
|
||||
// arrays do not have to be resized
|
||||
// The individual character widths will be returned in charWidths. The length of charWidths must
|
||||
// be at least the length of the text.
|
||||
private static native int nComputeLineBreaks(long nativePtr, LineBreaks recycle,
|
||||
int[] recycleBreaks, float[] recycleWidths, float[] recycleAscents,
|
||||
float[] recycleDescents, int[] recycleFlags, int recycleLength);
|
||||
float[] recycleDescents, int[] recycleFlags, int recycleLength,
|
||||
float[] charWidths);
|
||||
|
||||
private int mLineCount;
|
||||
private int mTopPadding, mBottomPadding;
|
||||
|
||||
@@ -166,7 +166,7 @@ static jint nComputeLineBreaks(JNIEnv* env, jclass, jlong nativePtr,
|
||||
jobject recycle, jintArray recycleBreaks,
|
||||
jfloatArray recycleWidths, jfloatArray recycleAscents,
|
||||
jfloatArray recycleDescents, jintArray recycleFlags,
|
||||
jint recycleLength) {
|
||||
jint recycleLength, jfloatArray charWidths) {
|
||||
minikin::LineBreaker* b = reinterpret_cast<minikin::LineBreaker*>(nativePtr);
|
||||
|
||||
size_t nBreaks = b->computeBreaks();
|
||||
@@ -175,6 +175,8 @@ static jint nComputeLineBreaks(JNIEnv* env, jclass, jlong nativePtr,
|
||||
recycleFlags, recycleLength, nBreaks, b->getBreaks(), b->getWidths(), b->getAscents(),
|
||||
b->getDescents(), b->getFlags());
|
||||
|
||||
env->SetFloatArrayRegion(charWidths, 0, b->size(), b->charWidths());
|
||||
|
||||
b->finish();
|
||||
|
||||
return static_cast<jint>(nBreaks);
|
||||
@@ -256,11 +258,6 @@ static void nAddReplacementRun(JNIEnv* env, jclass, jlong nativePtr,
|
||||
b->addReplacement(start, end, width, langTagsString.get(), makeHyphenators(env, hyphenators));
|
||||
}
|
||||
|
||||
static void nGetWidths(JNIEnv* env, jclass, jlong nativePtr, jfloatArray widths) {
|
||||
minikin::LineBreaker* b = reinterpret_cast<minikin::LineBreaker*>(nativePtr);
|
||||
env->SetFloatArrayRegion(widths, 0, b->size(), b->charWidths());
|
||||
}
|
||||
|
||||
static const JNINativeMethod gMethods[] = {
|
||||
// TODO performance: many of these are candidates for fast jni, awaiting guidance
|
||||
{"nNewBuilder", "()J", (void*) nNewBuilder},
|
||||
@@ -269,8 +266,7 @@ static const JNINativeMethod gMethods[] = {
|
||||
{"nSetupParagraph", "(J[CIFIF[IIIIZ[I[I[II)V", (void*) nSetupParagraph},
|
||||
{"nAddStyleRun", "(JJIIZLjava/lang/String;[J)V", (void*) nAddStyleRun},
|
||||
{"nAddReplacementRun", "(JIIFLjava/lang/String;[J)V", (void*) nAddReplacementRun},
|
||||
{"nGetWidths", "(J[F)V", (void*) nGetWidths},
|
||||
{"nComputeLineBreaks", "(JLandroid/text/StaticLayout$LineBreaks;[I[F[F[F[II)I",
|
||||
{"nComputeLineBreaks", "(JLandroid/text/StaticLayout$LineBreaks;[I[F[F[F[II[F)I",
|
||||
(void*) nComputeLineBreaks}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user