19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* libs/android_runtime/android/graphics/Paint.cpp
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project**
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** Copyright 2006, The Android Open Source Project
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project**
58451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes** Licensed under the Apache License, Version 2.0 (the "License");
68451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes** you may not use this file except in compliance with the License.
78451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes** You may obtain a copy of the License at
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project**
98451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes**     http://www.apache.org/licenses/LICENSE-2.0
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project**
118451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes** Unless required by applicable law or agreed to in writing, software
128451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes** distributed under the License is distributed on an "AS IS" BASIS,
138451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
148451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes** See the License for the specific language governing permissions and
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** limitations under the License.
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project*/
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18f43fa5746ee5b81a6e386d36594094d079ac8160Dianne Hackborn#define LOG_TAG "Paint"
19f43fa5746ee5b81a6e386d36594094d079ac8160Dianne Hackborn
20f43fa5746ee5b81a6e386d36594094d079ac8160Dianne Hackborn#include <utils/Log.h>
21f43fa5746ee5b81a6e386d36594094d079ac8160Dianne Hackborn
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "jni.h"
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "GraphicsJNI.h"
24ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe#include "core_jni_helpers.h"
25f7f969e67e9ab420404807b1b103dcd18d7aa7b7Raph Levien#include <ScopedStringChars.h>
26a027ec5c2dbfbbf10cac9ea538f5e230b093be2fRaph Levien#include <ScopedUtfChars.h>
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "SkBlurDrawLooper.h"
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "SkColorFilter.h"
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "SkMaskFilter.h"
31eba81d0f88f52ca097204ca526e796a83fdd57d5Derek Sollenberger#include "SkPath.h"
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "SkRasterizer.h"
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "SkShader.h"
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "SkTypeface.h"
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "SkXfermode.h"
36ac1cbaf2e5575ac75a0160e13089d51a0bb232faBilly Hewlett#include "unicode/uloc.h"
370c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt#include "unicode/ushape.h"
38c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger#include "utils/Blur.h"
390c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt
40dccca44ffda4836b56a21da95a046c9708ffd49csergeyv#include <hwui/MinikinSkia.h>
41dccca44ffda4836b56a21da95a046c9708ffd49csergeyv#include <hwui/MinikinUtils.h>
42dccca44ffda4836b56a21da95a046c9708ffd49csergeyv#include <hwui/Paint.h>
43bad99183916ba2bac6659efc8a28273e344ba511sergeyv#include <hwui/Typeface.h>
44e368b6bcfd499543a876b4cae02f1ca563ff1cb6Raph Levien#include <minikin/GraphemeBreak.h>
45a027ec5c2dbfbbf10cac9ea538f5e230b093be2fRaph Levien#include <minikin/Measurement.h>
46bb1a96647a82df5a134bf631fc9db342e7ef61deSeigo Nonaka#include <unicode/utf16.h>
471a73f732f91e97c9c66b808c245ddda36a10e987Raph Levien
48f036ead2a218ffa43697fcaa999b666a4c6d13cfRoozbeh Pournader#include <cassert>
49f036ead2a218ffa43697fcaa999b666a4c6d13cfRoozbeh Pournader#include <cstring>
50536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi#include <memory>
51f036ead2a218ffa43697fcaa999b666a4c6d13cfRoozbeh Pournader#include <vector>
529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectnamespace android {
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstruct JMetricsID {
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jfieldID    top;
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jfieldID    ascent;
589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jfieldID    descent;
599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jfieldID    bottom;
609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    jfieldID    leading;
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project};
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jclass   gFontMetrics_class;
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic JMetricsID gFontMetrics_fieldID;
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jclass   gFontMetricsInt_class;
679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic JMetricsID gFontMetricsInt_fieldID;
689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
696ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbodstatic void defaultSettingsForAndroid(Paint* paint) {
70c511bee87cda99a252d1a62487f47c8f05aee78cFabrice Di Meglio    // GlyphID encoding is required because we are using Harfbuzz shaping
716ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod    paint->setTextEncoding(Paint::kGlyphID_TextEncoding);
723d63e0119dc763ed0a06fd7498375746fd391d80Mike Reed}
733d63e0119dc763ed0a06fd7498375746fd391d80Mike Reed
74dbffd250003e60c0f11ac3ad2b63f91f67962610John Recknamespace PaintGlue {
750c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt    enum MoveOpt {
760c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        AFTER, AT_OR_AFTER, BEFORE, AT_OR_BEFORE, AT
770c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt    };
789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
79775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler    static void deletePaint(Paint* paint) {
80775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler        delete paint;
81775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler    }
82775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler
83775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler    static jlong getNativeFinalizer(JNIEnv*, jobject) {
84775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler        return static_cast<jlong>(reinterpret_cast<uintptr_t>(&deletePaint));
859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
87dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jlong init(JNIEnv* env, jobject) {
88e3a40ea488c7cfa396d5901255719a6ddab791d4Ben Wagner        static_assert(1 <<  0 == SkPaint::kAntiAlias_Flag,          "paint_flags_mismatch");
89e3a40ea488c7cfa396d5901255719a6ddab791d4Ben Wagner        static_assert(1 <<  2 == SkPaint::kDither_Flag,             "paint_flags_mismatch");
90e3a40ea488c7cfa396d5901255719a6ddab791d4Ben Wagner        static_assert(1 <<  3 == SkPaint::kUnderlineText_Flag,      "paint_flags_mismatch");
91e3a40ea488c7cfa396d5901255719a6ddab791d4Ben Wagner        static_assert(1 <<  4 == SkPaint::kStrikeThruText_Flag,     "paint_flags_mismatch");
92e3a40ea488c7cfa396d5901255719a6ddab791d4Ben Wagner        static_assert(1 <<  5 == SkPaint::kFakeBoldText_Flag,       "paint_flags_mismatch");
93e3a40ea488c7cfa396d5901255719a6ddab791d4Ben Wagner        static_assert(1 <<  6 == SkPaint::kLinearText_Flag,         "paint_flags_mismatch");
94e3a40ea488c7cfa396d5901255719a6ddab791d4Ben Wagner        static_assert(1 <<  7 == SkPaint::kSubpixelText_Flag,       "paint_flags_mismatch");
95e3a40ea488c7cfa396d5901255719a6ddab791d4Ben Wagner        static_assert(1 <<  8 == SkPaint::kDevKernText_Flag,        "paint_flags_mismatch");
96e3a40ea488c7cfa396d5901255719a6ddab791d4Ben Wagner        static_assert(1 << 10 == SkPaint::kEmbeddedBitmapText_Flag, "paint_flags_mismatch");
970b8606266c1afc69cbeb73acda67c85d87943318Derek Sollenberger
986ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = new Paint();
993d63e0119dc763ed0a06fd7498375746fd391d80Mike Reed        defaultSettingsForAndroid(obj);
10036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return reinterpret_cast<jlong>(obj);
1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jlong initWithPaint(JNIEnv* env, jobject clazz, jlong paintHandle) {
1046ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
1056ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = new Paint(*paint);
10636bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return reinterpret_cast<jlong>(obj);
1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1088451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
10936bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static void reset(JNIEnv* env, jobject clazz, jlong objHandle) {
1106ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        obj->reset();
1123d63e0119dc763ed0a06fd7498375746fd391d80Mike Reed        defaultSettingsForAndroid(obj);
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1148451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
11536bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static void assign(JNIEnv* env, jobject clazz, jlong dstPaintHandle, jlong srcPaintHandle) {
1166ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* dst = reinterpret_cast<Paint*>(dstPaintHandle);
1176ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        const Paint* src = reinterpret_cast<Paint*>(srcPaintHandle);
1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        *dst = *src;
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1208451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
1214c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed    // Equivalent to the Java Paint's FILTER_BITMAP_FLAG.
1224c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed    static const uint32_t sFilterBitmapFlag = 0x02;
1234c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed
124dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jint getFlags(JNIEnv* env, jobject, jlong paintHandle) {
125dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        Paint* nativePaint = reinterpret_cast<Paint*>(paintHandle);
1264c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        uint32_t result = nativePaint->getFlags();
1274c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        result &= ~sFilterBitmapFlag; // Filtering no longer stored in this bit. Mask away.
1282a1ce8a4e5258b6599cb8e86864eb816d24d69b4Mike Reed        if (nativePaint->getFilterQuality() != kNone_SkFilterQuality) {
1294c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed            result |= sFilterBitmapFlag;
1304c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        }
13136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return static_cast<jint>(result);
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1338451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
134dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setFlags(JNIEnv* env, jobject, jlong paintHandle, jint flags) {
135dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        Paint* nativePaint = reinterpret_cast<Paint*>(paintHandle);
1364c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        // Instead of modifying 0x02, change the filter level.
1372a1ce8a4e5258b6599cb8e86864eb816d24d69b4Mike Reed        nativePaint->setFilterQuality(flags & sFilterBitmapFlag
1382a1ce8a4e5258b6599cb8e86864eb816d24d69b4Mike Reed                ? kLow_SkFilterQuality
1392a1ce8a4e5258b6599cb8e86864eb816d24d69b4Mike Reed                : kNone_SkFilterQuality);
1404c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        // Don't pass through filter flag, which is no longer stored in paint's flags.
1414c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        flags &= ~sFilterBitmapFlag;
1424c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        // Use the existing value for 0x02.
1434c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        const uint32_t existing0x02Flag = nativePaint->getFlags() & sFilterBitmapFlag;
1444c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        flags |= existing0x02Flag;
1454c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        nativePaint->setFlags(flags);
1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1478451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
148dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jint getHinting(JNIEnv* env, jobject, jlong paintHandle) {
149dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        return reinterpret_cast<Paint*>(paintHandle)->getHinting()
1506ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod                == Paint::kNo_Hinting ? 0 : 1;
151f43fa5746ee5b81a6e386d36594094d079ac8160Dianne Hackborn    }
152f43fa5746ee5b81a6e386d36594094d079ac8160Dianne Hackborn
153dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setHinting(JNIEnv* env, jobject, jlong paintHandle, jint mode) {
154dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setHinting(
1556ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod                mode == 0 ? Paint::kNo_Hinting : Paint::kNormal_Hinting);
156f43fa5746ee5b81a6e386d36594094d079ac8160Dianne Hackborn    }
157f43fa5746ee5b81a6e386d36594094d079ac8160Dianne Hackborn
158dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setAntiAlias(JNIEnv* env, jobject, jlong paintHandle, jboolean aa) {
159dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setAntiAlias(aa);
1609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1618451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
162dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setLinearText(JNIEnv* env, jobject, jlong paintHandle, jboolean linearText) {
163dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setLinearText(linearText);
1649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1658451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
166dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setSubpixelText(JNIEnv* env, jobject, jlong paintHandle, jboolean subpixelText) {
167dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setSubpixelText(subpixelText);
1689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1698451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
170dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setUnderlineText(JNIEnv* env, jobject, jlong paintHandle, jboolean underlineText) {
171dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setUnderlineText(underlineText);
1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1738451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
174dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setStrikeThruText(JNIEnv* env, jobject, jlong paintHandle, jboolean strikeThruText) {
175dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setStrikeThruText(strikeThruText);
1769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1778451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
178dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setFakeBoldText(JNIEnv* env, jobject, jlong paintHandle, jboolean fakeBoldText) {
179dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setFakeBoldText(fakeBoldText);
1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1818451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
182dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setFilterBitmap(JNIEnv* env, jobject, jlong paintHandle, jboolean filterBitmap) {
183dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setFilterQuality(
1842a1ce8a4e5258b6599cb8e86864eb816d24d69b4Mike Reed                filterBitmap ? kLow_SkFilterQuality : kNone_SkFilterQuality);
1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1868451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
187dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setDither(JNIEnv* env, jobject, jlong paintHandle, jboolean dither) {
188dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setDither(dither);
1899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1908451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
19136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jint getStyle(JNIEnv* env, jobject clazz,jlong objHandle) {
1926ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
19336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return static_cast<jint>(obj->getStyle());
1949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1958451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
19636bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static void setStyle(JNIEnv* env, jobject clazz, jlong objHandle, jint styleHandle) {
1976ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
1986ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint::Style style = static_cast<Paint::Style>(styleHandle);
1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        obj->setStyle(style);
2009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2018451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
202dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jint getColor(JNIEnv* env, jobject, jlong paintHandle) {
20336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        int color;
204dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        color = reinterpret_cast<Paint*>(paintHandle)->getColor();
20536bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return static_cast<jint>(color);
2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2078451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
208dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jint getAlpha(JNIEnv* env, jobject, jlong paintHandle) {
20936bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        int alpha;
210dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        alpha = reinterpret_cast<Paint*>(paintHandle)->getAlpha();
21136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return static_cast<jint>(alpha);
2129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2138451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
214dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setColor(JNIEnv* env, jobject, jlong paintHandle, jint color) {
215dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setColor(color);
2169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2178451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
218dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setAlpha(JNIEnv* env, jobject, jlong paintHandle, jint a) {
219dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setAlpha(a);
2209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2218451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
222dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jfloat getStrokeWidth(JNIEnv* env, jobject, jlong paintHandle) {
223dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getStrokeWidth());
2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2258451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
226dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setStrokeWidth(JNIEnv* env, jobject, jlong paintHandle, jfloat width) {
227dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setStrokeWidth(width);
2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2298451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
230dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jfloat getStrokeMiter(JNIEnv* env, jobject, jlong paintHandle) {
231dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getStrokeMiter());
2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2338451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
234dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setStrokeMiter(JNIEnv* env, jobject, jlong paintHandle, jfloat miter) {
235dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setStrokeMiter(miter);
2369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2378451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
23836bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jint getStrokeCap(JNIEnv* env, jobject clazz, jlong objHandle) {
2396ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
24036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return static_cast<jint>(obj->getStrokeCap());
2419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2428451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
24336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static void setStrokeCap(JNIEnv* env, jobject clazz, jlong objHandle, jint capHandle) {
2446ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
2456ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint::Cap cap = static_cast<Paint::Cap>(capHandle);
2469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        obj->setStrokeCap(cap);
2479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2488451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
24936bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jint getStrokeJoin(JNIEnv* env, jobject clazz, jlong objHandle) {
2506ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
25136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return static_cast<jint>(obj->getStrokeJoin());
2529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2538451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
25436bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static void setStrokeJoin(JNIEnv* env, jobject clazz, jlong objHandle, jint joinHandle) {
2556ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
2566ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint::Join join = (Paint::Join) joinHandle;
2579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        obj->setStrokeJoin(join);
2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2598451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
26036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jboolean getFillPath(JNIEnv* env, jobject clazz, jlong objHandle, jlong srcHandle, jlong dstHandle) {
2616ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
26236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        SkPath* src = reinterpret_cast<SkPath*>(srcHandle);
26336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        SkPath* dst = reinterpret_cast<SkPath*>(dstHandle);
26436bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return obj->getFillPath(*src, dst) ? JNI_TRUE : JNI_FALSE;
2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2668451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
26736bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jlong setShader(JNIEnv* env, jobject clazz, jlong objHandle, jlong shaderHandle) {
2686ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
26936bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
27036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return reinterpret_cast<jlong>(obj->setShader(shader));
2719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2728451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
27336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jlong setColorFilter(JNIEnv* env, jobject clazz, jlong objHandle, jlong filterHandle) {
2746ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint *>(objHandle);
27536bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        SkColorFilter* filter  = reinterpret_cast<SkColorFilter *>(filterHandle);
27636bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return reinterpret_cast<jlong>(obj->setColorFilter(filter));
2779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2788451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
27936bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jlong setXfermode(JNIEnv* env, jobject clazz, jlong objHandle, jlong xfermodeHandle) {
2806ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
28136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        SkXfermode* xfermode = reinterpret_cast<SkXfermode*>(xfermodeHandle);
28236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return reinterpret_cast<jlong>(obj->setXfermode(xfermode));
2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2848451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
28536bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jlong setPathEffect(JNIEnv* env, jobject clazz, jlong objHandle, jlong effectHandle) {
2866ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
28736bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        SkPathEffect* effect  = reinterpret_cast<SkPathEffect*>(effectHandle);
28836bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return reinterpret_cast<jlong>(obj->setPathEffect(effect));
2899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2908451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
29136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jlong setMaskFilter(JNIEnv* env, jobject clazz, jlong objHandle, jlong maskfilterHandle) {
2926ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
29336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        SkMaskFilter* maskfilter  = reinterpret_cast<SkMaskFilter*>(maskfilterHandle);
29436bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return reinterpret_cast<jlong>(obj->setMaskFilter(maskfilter));
2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2968451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
29736bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jlong setTypeface(JNIEnv* env, jobject clazz, jlong objHandle, jlong typefaceHandle) {
2986ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        // TODO: in Paint refactoring, set typeface on android Paint, not Paint
299a033630e805c407080221e20b236b6054f324670Raph Levien        return NULL;
3009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3018451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
30236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jlong setRasterizer(JNIEnv* env, jobject clazz, jlong objHandle, jlong rasterizerHandle) {
3036ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
3044c9355c35a0f62805739823a62ad41ca1cbc6502Mike Reed        SkAutoTUnref<SkRasterizer> rasterizer(GraphicsJNI::refNativeRasterizer(rasterizerHandle));
30536bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return reinterpret_cast<jlong>(obj->setRasterizer(rasterizer));
3069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3078451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
30836bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jint getTextAlign(JNIEnv* env, jobject clazz, jlong objHandle) {
3096ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
31036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat        return static_cast<jint>(obj->getTextAlign());
3119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3128451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
31336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static void setTextAlign(JNIEnv* env, jobject clazz, jlong objHandle, jint alignHandle) {
3146ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
3156ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint::Align align = static_cast<Paint::Align>(alignHandle);
3169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        obj->setTextAlign(align);
3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3188451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
319cfc607cf57d453f977c9c4bf09b41ac481c4bbecSeigo Nonaka    static jint setTextLocales(JNIEnv* env, jobject clazz, jlong objHandle, jstring locales) {
3206ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* obj = reinterpret_cast<Paint*>(objHandle);
321f036ead2a218ffa43697fcaa999b666a4c6d13cfRoozbeh Pournader        ScopedUtfChars localesChars(env, locales);
3224ea7d1d2ab51fd7f67087db669dbaf693560b838Seigo Nonaka        jint minikinLangListId = FontStyle::registerLanguageList(localesChars.c_str());
323cfc607cf57d453f977c9c4bf09b41ac481c4bbecSeigo Nonaka        obj->setMinikinLangListId(minikinLangListId);
324cfc607cf57d453f977c9c4bf09b41ac481c4bbecSeigo Nonaka        return minikinLangListId;
325cfc607cf57d453f977c9c4bf09b41ac481c4bbecSeigo Nonaka    }
326d7a80774f0a2175f9ee81a7741f9a171c78e0b8bDerek Sollenberger
327cfc607cf57d453f977c9c4bf09b41ac481c4bbecSeigo Nonaka    static void setTextLocalesByMinikinLangListId(JNIEnv* env, jobject clazz, jlong objHandle,
328cfc607cf57d453f977c9c4bf09b41ac481c4bbecSeigo Nonaka            jint minikinLangListId) {
329cfc607cf57d453f977c9c4bf09b41ac481c4bbecSeigo Nonaka        Paint* obj = reinterpret_cast<Paint*>(objHandle);
330cfc607cf57d453f977c9c4bf09b41ac481c4bbecSeigo Nonaka        obj->setMinikinLangListId(minikinLangListId);
331517825f1a9f14f92908bd7859b91b927c2eec6d9Fabrice Di Meglio    }
332517825f1a9f14f92908bd7859b91b927c2eec6d9Fabrice Di Meglio
333dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jboolean isElegantTextHeight(JNIEnv* env, jobject, jlong paintHandle) {
334dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        Paint* obj = reinterpret_cast<Paint*>(paintHandle);
3356f03023ece076d33d8b171d5398c8ed70abf3f54Derek Sollenberger        return obj->getFontVariant() == VARIANT_ELEGANT;
33653c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien    }
33753c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien
338dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setElegantTextHeight(JNIEnv* env, jobject, jlong paintHandle, jboolean aa) {
339dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        Paint* obj = reinterpret_cast<Paint*>(paintHandle);
3406f03023ece076d33d8b171d5398c8ed70abf3f54Derek Sollenberger        obj->setFontVariant(aa ? VARIANT_ELEGANT : VARIANT_DEFAULT);
34153c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien    }
34253c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien
343dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jfloat getTextSize(JNIEnv* env, jobject, jlong paintHandle) {
344dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getTextSize());
3459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3468451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
347dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setTextSize(JNIEnv* env, jobject, jlong paintHandle, jfloat textSize) {
348dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setTextSize(textSize);
3499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3508451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
351dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jfloat getTextScaleX(JNIEnv* env, jobject, jlong paintHandle) {
352dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getTextScaleX());
3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3548451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
355dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setTextScaleX(JNIEnv* env, jobject, jlong paintHandle, jfloat scaleX) {
356dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setTextScaleX(scaleX);
3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3588451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
359dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jfloat getTextSkewX(JNIEnv* env, jobject, jlong paintHandle) {
360dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getTextSkewX());
3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3628451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
363dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static void setTextSkewX(JNIEnv* env, jobject, jlong paintHandle, jfloat skewX) {
364dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        reinterpret_cast<Paint*>(paintHandle)->setTextSkewX(skewX);
3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3668451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
367fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod    static jfloat getLetterSpacing(JNIEnv* env, jobject clazz, jlong paintHandle) {
368fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
369fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod        return paint->getLetterSpacing();
370fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod    }
371fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod
372fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod    static void setLetterSpacing(JNIEnv* env, jobject clazz, jlong paintHandle, jfloat letterSpacing) {
373fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
374fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod        paint->setLetterSpacing(letterSpacing);
375fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod    }
376fa80f7491df82d71b7084500519a2195afbea706Behdad Esfahbod
377805f6ebf17e2791624bb1a30834b4c1cc65583bfBehdad Esfahbod    static void setFontFeatureSettings(JNIEnv* env, jobject clazz, jlong paintHandle, jstring settings) {
378805f6ebf17e2791624bb1a30834b4c1cc65583bfBehdad Esfahbod        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
379e9ad3931fae71c8a8cd000fd52d5df4be79b0895Behdad Esfahbod        if (!settings) {
380805f6ebf17e2791624bb1a30834b4c1cc65583bfBehdad Esfahbod            paint->setFontFeatureSettings(std::string());
381e9ad3931fae71c8a8cd000fd52d5df4be79b0895Behdad Esfahbod        } else {
382805f6ebf17e2791624bb1a30834b4c1cc65583bfBehdad Esfahbod            ScopedUtfChars settingsChars(env, settings);
383805f6ebf17e2791624bb1a30834b4c1cc65583bfBehdad Esfahbod            paint->setFontFeatureSettings(std::string(settingsChars.c_str(), settingsChars.size()));
384805f6ebf17e2791624bb1a30834b4c1cc65583bfBehdad Esfahbod        }
385805f6ebf17e2791624bb1a30834b4c1cc65583bfBehdad Esfahbod    }
386805f6ebf17e2791624bb1a30834b4c1cc65583bfBehdad Esfahbod
387210a189e226d5ce64f760d557efc6570409c8147Raph Levien    static jint getHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) {
388210a189e226d5ce64f760d557efc6570409c8147Raph Levien        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
389210a189e226d5ce64f760d557efc6570409c8147Raph Levien        return paint->getHyphenEdit();
390210a189e226d5ce64f760d557efc6570409c8147Raph Levien    }
391210a189e226d5ce64f760d557efc6570409c8147Raph Levien
392210a189e226d5ce64f760d557efc6570409c8147Raph Levien    static void setHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) {
393210a189e226d5ce64f760d557efc6570409c8147Raph Levien        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
394210a189e226d5ce64f760d557efc6570409c8147Raph Levien        paint->setHyphenEdit((uint32_t)hyphen);
395210a189e226d5ce64f760d557efc6570409c8147Raph Levien    }
396210a189e226d5ce64f760d557efc6570409c8147Raph Levien
397dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static SkScalar getMetricsInternal(jlong paintHandle, jlong typefaceHandle,
398dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck            Paint::FontMetrics *metrics) {
39953c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien        const int kElegantTop = 2500;
40053c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien        const int kElegantBottom = -1000;
401817ef4ae79bd39b5e55fc6ca4e3b8e47e114579fRaph Levien        const int kElegantAscent = 1900;
402817ef4ae79bd39b5e55fc6ca4e3b8e47e114579fRaph Levien        const int kElegantDescent = -500;
40353c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien        const int kElegantLeading = 0;
404dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
405bad99183916ba2bac6659efc8a28273e344ba511sergeyv        Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
406bad99183916ba2bac6659efc8a28273e344ba511sergeyv        typeface = Typeface::resolveDefault(typeface);
4071fc0fa87d42ce9268ece76b85b9edc834593e53aRaph Levien        FakedFont baseFont = typeface->fFontCollection->baseFontFaked(typeface->fStyle);
4080627ec08dcc2e87c17e9b85f045dfb27dc4884b3Raph Levien        float saveSkewX = paint->getTextSkewX();
4090627ec08dcc2e87c17e9b85f045dfb27dc4884b3Raph Levien        bool savefakeBold = paint->isFakeBoldText();
4101fc0fa87d42ce9268ece76b85b9edc834593e53aRaph Levien        MinikinFontSkia::populateSkPaint(paint, baseFont.font, baseFont.fakery);
41153c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien        SkScalar spacing = paint->getFontMetrics(metrics);
4120627ec08dcc2e87c17e9b85f045dfb27dc4884b3Raph Levien        // The populateSkPaint call may have changed fake bold / text skew
4130627ec08dcc2e87c17e9b85f045dfb27dc4884b3Raph Levien        // because we want to measure with those effects applied, so now
4140627ec08dcc2e87c17e9b85f045dfb27dc4884b3Raph Levien        // restore the original settings.
4150627ec08dcc2e87c17e9b85f045dfb27dc4884b3Raph Levien        paint->setTextSkewX(saveSkewX);
4160627ec08dcc2e87c17e9b85f045dfb27dc4884b3Raph Levien        paint->setFakeBoldText(savefakeBold);
4176f03023ece076d33d8b171d5398c8ed70abf3f54Derek Sollenberger        if (paint->getFontVariant() == VARIANT_ELEGANT) {
41853c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien            SkScalar size = paint->getTextSize();
41953c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien            metrics->fTop = -size * kElegantTop / 2048;
42053c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien            metrics->fBottom = -size * kElegantBottom / 2048;
42153c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien            metrics->fAscent = -size * kElegantAscent / 2048;
42253c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien            metrics->fDescent = -size * kElegantDescent / 2048;
42353c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien            metrics->fLeading = size * kElegantLeading / 2048;
42453c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien            spacing = metrics->fDescent - metrics->fAscent + metrics->fLeading;
42553c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien        }
42653c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien        return spacing;
42753c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien    }
42853c0077256afebb0312f01ef4f60a7445da1f5d9Raph Levien
429dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jfloat ascent(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle) {
4306ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint::FontMetrics metrics;
431dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        getMetricsInternal(paintHandle, typefaceHandle, &metrics);
432817ef4ae79bd39b5e55fc6ca4e3b8e47e114579fRaph Levien        return SkScalarToFloat(metrics.fAscent);
433817ef4ae79bd39b5e55fc6ca4e3b8e47e114579fRaph Levien    }
434817ef4ae79bd39b5e55fc6ca4e3b8e47e114579fRaph Levien
435dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jfloat descent(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle) {
4366ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint::FontMetrics metrics;
437dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        getMetricsInternal(paintHandle, typefaceHandle, &metrics);
438817ef4ae79bd39b5e55fc6ca4e3b8e47e114579fRaph Levien        return SkScalarToFloat(metrics.fDescent);
439817ef4ae79bd39b5e55fc6ca4e3b8e47e114579fRaph Levien    }
440817ef4ae79bd39b5e55fc6ca4e3b8e47e114579fRaph Levien
441dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jfloat getFontMetrics(JNIEnv* env, jobject, jlong paintHandle,
442dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck            jlong typefaceHandle, jobject metricsObj) {
4436ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint::FontMetrics metrics;
444dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        SkScalar spacing = getMetricsInternal(paintHandle, typefaceHandle, &metrics);
4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (metricsObj) {
4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            SkASSERT(env->IsInstanceOf(metricsObj, gFontMetrics_class));
4489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            env->SetFloatField(metricsObj, gFontMetrics_fieldID.top, SkScalarToFloat(metrics.fTop));
4499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            env->SetFloatField(metricsObj, gFontMetrics_fieldID.ascent, SkScalarToFloat(metrics.fAscent));
4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            env->SetFloatField(metricsObj, gFontMetrics_fieldID.descent, SkScalarToFloat(metrics.fDescent));
4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            env->SetFloatField(metricsObj, gFontMetrics_fieldID.bottom, SkScalarToFloat(metrics.fBottom));
4529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            env->SetFloatField(metricsObj, gFontMetrics_fieldID.leading, SkScalarToFloat(metrics.fLeading));
4539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
4549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return SkScalarToFloat(spacing);
4559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4568451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
457dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck    static jint getFontMetricsInt(JNIEnv* env, jobject, jlong paintHandle,
458dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck            jlong typefaceHandle, jobject metricsObj) {
4596ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint::FontMetrics metrics;
4608451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes
461dbffd250003e60c0f11ac3ad2b63f91f67962610John Reck        getMetricsInternal(paintHandle, typefaceHandle, &metrics);
46246cb9bdbf56b27cbf2ab878b41d21e30896a4feaLeon Scroggins        int ascent = SkScalarRoundToInt(metrics.fAscent);
46346cb9bdbf56b27cbf2ab878b41d21e30896a4feaLeon Scroggins        int descent = SkScalarRoundToInt(metrics.fDescent);
46446cb9bdbf56b27cbf2ab878b41d21e30896a4feaLeon Scroggins        int leading = SkScalarRoundToInt(metrics.fLeading);
4659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (metricsObj) {
4679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            SkASSERT(env->IsInstanceOf(metricsObj, gFontMetricsInt_class));
46846cb9bdbf56b27cbf2ab878b41d21e30896a4feaLeon Scroggins            env->SetIntField(metricsObj, gFontMetricsInt_fieldID.top, SkScalarFloorToInt(metrics.fTop));
4699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            env->SetIntField(metricsObj, gFontMetricsInt_fieldID.ascent, ascent);
4709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            env->SetIntField(metricsObj, gFontMetricsInt_fieldID.descent, descent);
47146cb9bdbf56b27cbf2ab878b41d21e30896a4feaLeon Scroggins            env->SetIntField(metricsObj, gFontMetricsInt_fieldID.bottom, SkScalarCeilToInt(metrics.fBottom));
4729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            env->SetIntField(metricsObj, gFontMetricsInt_fieldID.leading, leading);
4739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
4749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return descent - ascent + leading;
4759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
477bad99183916ba2bac6659efc8a28273e344ba511sergeyv    static jfloat doTextAdvances(JNIEnv *env, Paint *paint, Typeface* typeface,
478536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi            const jchar *text, jint start, jint count, jint contextCount, jint bidiFlags,
479536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi            jfloatArray advances, jint advancesIndex) {
4806ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio        NPE_CHECK_RETURN_ZERO(env, text);
4816ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio
4826ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio        if ((start | count | contextCount | advancesIndex) < 0 || contextCount < count) {
4836ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio            doThrowAIOOBE(env);
4846ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio            return 0;
4856ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio        }
4866ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio        if (count == 0) {
4876ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio            return 0;
4886ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio        }
4896ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio        if (advances) {
4906ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio            size_t advancesLength = env->GetArrayLength(advances);
491536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi            if ((size_t)(count  + advancesIndex) > advancesLength) {
4926ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio                doThrowAIOOBE(env);
4936ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio                return 0;
4946ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio            }
4956ab90ed017fb52aac4493a2fac897299d345874fFabrice Di Meglio        }
496a3024bd7026deb777556dd75dd34a719ea1c2b39Keisuke Kuroyanagi        std::unique_ptr<jfloat[]> advancesArray;
497a3024bd7026deb777556dd75dd34a719ea1c2b39Keisuke Kuroyanagi        if (advances) {
498a3024bd7026deb777556dd75dd34a719ea1c2b39Keisuke Kuroyanagi            advancesArray.reset(new jfloat[count]);
499a3024bd7026deb777556dd75dd34a719ea1c2b39Keisuke Kuroyanagi        }
500a3024bd7026deb777556dd75dd34a719ea1c2b39Keisuke Kuroyanagi        const float advance = MinikinUtils::measureText(paint, bidiFlags, typeface, text,
501a3024bd7026deb777556dd75dd34a719ea1c2b39Keisuke Kuroyanagi                start, count, contextCount, advancesArray.get());
502a3024bd7026deb777556dd75dd34a719ea1c2b39Keisuke Kuroyanagi        if (advances) {
503536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi            env->SetFloatArrayRegion(advances, advancesIndex, count, advancesArray.get());
5040c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        }
505a3024bd7026deb777556dd75dd34a719ea1c2b39Keisuke Kuroyanagi        return advance;
5060c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt    }
5070c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt
508536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi    static jfloat getTextAdvances___CIIIII_FI(JNIEnv* env, jobject clazz, jlong paintHandle,
5091a73f732f91e97c9c66b808c245ddda36a10e987Raph Levien            jlong typefaceHandle,
5100c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt            jcharArray text, jint index, jint count, jint contextIndex, jint contextCount,
511536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi            jint bidiFlags, jfloatArray advances, jint advancesIndex) {
5126ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
513bad99183916ba2bac6659efc8a28273e344ba511sergeyv        Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
5140c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        jchar* textArray = env->GetCharArrayElements(text, NULL);
515536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi        jfloat result = doTextAdvances(env, paint, typeface, textArray + contextIndex,
516536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi                index - contextIndex, count, contextCount, bidiFlags, advances, advancesIndex);
5170c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
5180c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        return result;
5190c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt    }
5200c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt
521536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi    static jfloat getTextAdvances__StringIIIII_FI(JNIEnv* env, jobject clazz, jlong paintHandle,
5221a73f732f91e97c9c66b808c245ddda36a10e987Raph Levien            jlong typefaceHandle,
523536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi            jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint bidiFlags,
524665f02c66702b77db25e950ff433230186bc3243Fabrice Di Meglio            jfloatArray advances, jint advancesIndex) {
5256ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
526bad99183916ba2bac6659efc8a28273e344ba511sergeyv        Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
5270c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        const jchar* textArray = env->GetStringChars(text, NULL);
528536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi        jfloat result = doTextAdvances(env, paint, typeface, textArray + contextStart,
529536afe6ef79a663e59c3b9781c561f7029ee9319Keisuke Kuroyanagi                start - contextStart, end - start, contextEnd - contextStart, bidiFlags,
530665f02c66702b77db25e950ff433230186bc3243Fabrice Di Meglio                advances, advancesIndex);
531eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio        env->ReleaseStringChars(text, textArray);
532eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio        return result;
533eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio    }
534eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio
5356ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod    static jint doTextRunCursor(JNIEnv *env, Paint* paint, const jchar *text, jint start,
536a4bf8114a73371b51a0eba9d5d61dfeb597a1abbFabrice Di Meglio            jint count, jint flags, jint offset, jint opt) {
537e368b6bcfd499543a876b4cae02f1ca563ff1cb6Raph Levien        GraphemeBreak::MoveOpt moveOpt = GraphemeBreak::MoveOpt(opt);
538e368b6bcfd499543a876b4cae02f1ca563ff1cb6Raph Levien        size_t result = GraphemeBreak::getTextRunCursor(text, start, count, offset, moveOpt);
539e368b6bcfd499543a876b4cae02f1ca563ff1cb6Raph Levien        return static_cast<jint>(result);
5400c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt    }
5410c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt
54236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jint getTextRunCursor___C(JNIEnv* env, jobject clazz, jlong paintHandle, jcharArray text,
543051910b9f998030dacb8a0722588cc715813fde1Raph Levien            jint contextStart, jint contextCount, jint dir, jint offset, jint cursorOpt) {
5446ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
5450c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        jchar* textArray = env->GetCharArrayElements(text, NULL);
546051910b9f998030dacb8a0722588cc715813fde1Raph Levien        jint result = doTextRunCursor(env, paint, textArray, contextStart, contextCount, dir,
5470c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt                offset, cursorOpt);
5480c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
5490c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        return result;
5500c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt    }
5510c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt
55236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat    static jint getTextRunCursor__String(JNIEnv* env, jobject clazz, jlong paintHandle, jstring text,
553051910b9f998030dacb8a0722588cc715813fde1Raph Levien            jint contextStart, jint contextEnd, jint dir, jint offset, jint cursorOpt) {
5546ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
5550c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        const jchar* textArray = env->GetStringChars(text, NULL);
5560c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        jint result = doTextRunCursor(env, paint, textArray, contextStart,
557051910b9f998030dacb8a0722588cc715813fde1Raph Levien                contextEnd - contextStart, dir, offset, cursorOpt);
5580c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        env->ReleaseStringChars(text, textArray);
5590c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt        return result;
5600c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt    }
5610c702b88c5d0d4380930b920f5be6e66dd95a0d8Doug Felt
562f2114d5646194100242206b267ddd6e7194b7da9Raph Levien    class GetTextFunctor {
563f2114d5646194100242206b267ddd6e7194b7da9Raph Levien    public:
5646ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        GetTextFunctor(const Layout& layout, SkPath* path, jfloat x, jfloat y, Paint* paint,
565f2114d5646194100242206b267ddd6e7194b7da9Raph Levien                    uint16_t* glyphs, SkPoint* pos)
566f2114d5646194100242206b267ddd6e7194b7da9Raph Levien                : layout(layout), path(path), x(x), y(y), paint(paint), glyphs(glyphs), pos(pos) {
567f2114d5646194100242206b267ddd6e7194b7da9Raph Levien        }
568f2114d5646194100242206b267ddd6e7194b7da9Raph Levien
5691fc0fa87d42ce9268ece76b85b9edc834593e53aRaph Levien        void operator()(size_t start, size_t end) {
570f2114d5646194100242206b267ddd6e7194b7da9Raph Levien            for (size_t i = start; i < end; i++) {
571f2114d5646194100242206b267ddd6e7194b7da9Raph Levien                glyphs[i] = layout.getGlyphId(i);
572f2114d5646194100242206b267ddd6e7194b7da9Raph Levien                pos[i].fX = x + layout.getX(i);
573f2114d5646194100242206b267ddd6e7194b7da9Raph Levien                pos[i].fY = y + layout.getY(i);
574f2114d5646194100242206b267ddd6e7194b7da9Raph Levien            }
575f2114d5646194100242206b267ddd6e7194b7da9Raph Levien            if (start == 0) {
576f2114d5646194100242206b267ddd6e7194b7da9Raph Levien                paint->getPosTextPath(glyphs + start, (end - start) << 1, pos + start, path);
577f2114d5646194100242206b267ddd6e7194b7da9Raph Levien            } else {
578f2114d5646194100242206b267ddd6e7194b7da9Raph Levien                paint->getPosTextPath(glyphs + start, (end - start) << 1, pos + start, &tmpPath);
579f2114d5646194100242206b267ddd6e7194b7da9Raph Levien                path->addPath(tmpPath);
580f2114d5646194100242206b267ddd6e7194b7da9Raph Levien            }
581f2114d5646194100242206b267ddd6e7194b7da9Raph Levien        }
582f2114d5646194100242206b267ddd6e7194b7da9Raph Levien    private:
583f2114d5646194100242206b267ddd6e7194b7da9Raph Levien        const Layout& layout;
584f2114d5646194100242206b267ddd6e7194b7da9Raph Levien        SkPath* path;
585f2114d5646194100242206b267ddd6e7194b7da9Raph Levien        jfloat x;
586f2114d5646194100242206b267ddd6e7194b7da9Raph Levien        jfloat y;
5876ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod        Paint* paint;
588f2114d5646194100242206b267ddd6e7194b7da9Raph Levien        uint16_t* glyphs;
589f2114d5646194100242206b267ddd6e7194b7da9Raph Levien        SkPoint* pos;
590f2114d5646194100242206b267ddd6e7194b7da9Raph Levien        SkPath tmpPath;
591f2114d5646194100242206b267ddd6e7194b7da9Raph Levien    };
592f2114d5646194100242206b267ddd6e7194b7da9Raph Levien
593