Add bounding box based text layout APIs.

This CL adds bounding box based text layout features.
By setting setUseBoundsForWidth, the line break width and drawing
offset is adjusted based on bounding box instead of advances.

Bug: 63938206
Test: atest CtsTextTestCases

Change-Id: I993c455eee1b4100656db9aef38675e3cda3309d
diff --git a/libs/hwui/jni/text/LineBreaker.cpp b/libs/hwui/jni/text/LineBreaker.cpp
index 9ebf23c..c512256 100644
--- a/libs/hwui/jni/text/LineBreaker.cpp
+++ b/libs/hwui/jni/text/LineBreaker.cpp
@@ -51,13 +51,12 @@
 
 // set text and set a number of parameters for creating a layout (width, tabstops, strategy,
 // hyphenFrequency)
-static jlong nInit(JNIEnv* env, jclass /* unused */,
-        jint breakStrategy, jint hyphenationFrequency, jboolean isJustified, jintArray indents) {
+static jlong nInit(JNIEnv* env, jclass /* unused */, jint breakStrategy, jint hyphenationFrequency,
+                   jboolean isJustified, jintArray indents, jboolean useBoundsForWidth) {
     return reinterpret_cast<jlong>(new minikin::android::StaticLayoutNative(
             static_cast<minikin::BreakStrategy>(breakStrategy),
-            static_cast<minikin::HyphenationFrequency>(hyphenationFrequency),
-            isJustified,
-            jintArrayToFloatVector(env, indents)));
+            static_cast<minikin::HyphenationFrequency>(hyphenationFrequency), isJustified,
+            jintArrayToFloatVector(env, indents), useBoundsForWidth));
 }
 
 static void nFinish(jlong nativePtr) {
@@ -128,39 +127,44 @@
 }
 
 static const JNINativeMethod gMethods[] = {
-    // Fast Natives
-    {"nInit", "("
-        "I"  // breakStrategy
-        "I"  // hyphenationFrequency
-        "Z"  // isJustified
-        "[I"  // indents
-        ")J", (void*) nInit},
+        // Fast Natives
+        {"nInit",
+         "("
+         "I"   // breakStrategy
+         "I"   // hyphenationFrequency
+         "Z"   // isJustified
+         "[I"  // indents
+         "Z"   // useBoundsForWidth
+         ")J",
+         (void*)nInit},
 
-    // Critical Natives
-    {"nGetReleaseFunc", "()J", (void*) nGetReleaseFunc},
+        // Critical Natives
+        {"nGetReleaseFunc", "()J", (void*)nGetReleaseFunc},
 
-    // Regular JNI
-    {"nComputeLineBreaks", "("
-        "J"  // nativePtr
-        "[C"  // text
-        "J"  // MeasuredParagraph ptr.
-        "I"  // length
-        "F"  // firstWidth
-        "I"  // firstWidthLineCount
-        "F"  // restWidth
-        "[F"  // variableTabStops
-        "F"  // defaultTabStop
-        "I"  // indentsOffset
-        ")J", (void*) nComputeLineBreaks},
+        // Regular JNI
+        {"nComputeLineBreaks",
+         "("
+         "J"   // nativePtr
+         "[C"  // text
+         "J"   // MeasuredParagraph ptr.
+         "I"   // length
+         "F"   // firstWidth
+         "I"   // firstWidthLineCount
+         "F"   // restWidth
+         "[F"  // variableTabStops
+         "F"   // defaultTabStop
+         "I"   // indentsOffset
+         ")J",
+         (void*)nComputeLineBreaks},
 
-    // Result accessors, CriticalNatives
-    {"nGetLineCount", "(J)I", (void*)nGetLineCount},
-    {"nGetLineBreakOffset", "(JI)I", (void*)nGetLineBreakOffset},
-    {"nGetLineWidth", "(JI)F", (void*)nGetLineWidth},
-    {"nGetLineAscent", "(JI)F", (void*)nGetLineAscent},
-    {"nGetLineDescent", "(JI)F", (void*)nGetLineDescent},
-    {"nGetLineFlag", "(JI)I", (void*)nGetLineFlag},
-    {"nGetReleaseResultFunc", "()J", (void*)nGetReleaseResultFunc},
+        // Result accessors, CriticalNatives
+        {"nGetLineCount", "(J)I", (void*)nGetLineCount},
+        {"nGetLineBreakOffset", "(JI)I", (void*)nGetLineBreakOffset},
+        {"nGetLineWidth", "(JI)F", (void*)nGetLineWidth},
+        {"nGetLineAscent", "(JI)F", (void*)nGetLineAscent},
+        {"nGetLineDescent", "(JI)F", (void*)nGetLineDescent},
+        {"nGetLineFlag", "(JI)I", (void*)nGetLineFlag},
+        {"nGetReleaseResultFunc", "()J", (void*)nGetReleaseResultFunc},
 };
 
 int register_android_graphics_text_LineBreaker(JNIEnv* env) {
diff --git a/libs/hwui/jni/text/MeasuredText.cpp b/libs/hwui/jni/text/MeasuredText.cpp
index 081713a..f6ae169 100644
--- a/libs/hwui/jni/text/MeasuredText.cpp
+++ b/libs/hwui/jni/text/MeasuredText.cpp
@@ -81,13 +81,14 @@
 // Regular JNI
 static jlong nBuildMeasuredText(JNIEnv* env, jclass /* unused */, jlong builderPtr, jlong hintPtr,
                                 jcharArray javaText, jboolean computeHyphenation,
-                                jboolean computeLayout, jboolean fastHyphenationMode) {
+                                jboolean computeLayout, jboolean computeBounds,
+                                jboolean fastHyphenationMode) {
     ScopedCharArrayRO text(env, javaText);
     const minikin::U16StringPiece textBuffer(text.get(), text.size());
 
     // Pass the ownership to Java.
     return toJLong(toBuilder(builderPtr)
-                           ->build(textBuffer, computeHyphenation, computeLayout,
+                           ->build(textBuffer, computeHyphenation, computeLayout, computeBounds,
                                    fastHyphenationMode, toMeasuredParagraph(hintPtr))
                            .release());
 }
@@ -160,7 +161,7 @@
         {"nInitBuilder", "()J", (void*)nInitBuilder},
         {"nAddStyleRun", "(JJIIIIZ)V", (void*)nAddStyleRun},
         {"nAddReplacementRun", "(JJIIF)V", (void*)nAddReplacementRun},
-        {"nBuildMeasuredText", "(JJ[CZZZ)J", (void*)nBuildMeasuredText},
+        {"nBuildMeasuredText", "(JJ[CZZZZ)J", (void*)nBuildMeasuredText},
         {"nFreeBuilder", "(J)V", (void*)nFreeBuilder},
 };