The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* libs/android_runtime/android/graphics/Paint.cpp |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | ** |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | ** |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Dianne Hackborn | f43fa57 | 2011-08-12 18:59:39 -0700 | [diff] [blame] | 18 | #define LOG_TAG "Paint" |
| 19 | |
| 20 | #include <utils/Log.h> |
| 21 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include "jni.h" |
| 23 | #include "GraphicsJNI.h" |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 24 | #include "core_jni_helpers.h" |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 25 | #include <ScopedStringChars.h> |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 26 | #include <ScopedUtfChars.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | #include "SkBlurDrawLooper.h" |
| 29 | #include "SkColorFilter.h" |
| 30 | #include "SkMaskFilter.h" |
| 31 | #include "SkRasterizer.h" |
| 32 | #include "SkShader.h" |
| 33 | #include "SkTypeface.h" |
| 34 | #include "SkXfermode.h" |
Billy Hewlett | ac1cbaf | 2012-07-18 09:51:45 -0700 | [diff] [blame] | 35 | #include "unicode/uloc.h" |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 36 | #include "unicode/ushape.h" |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 37 | #include "utils/Blur.h" |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 38 | |
Raph Levien | e368b6b | 2014-06-15 17:37:57 -0700 | [diff] [blame] | 39 | #include <minikin/GraphemeBreak.h> |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 40 | #include <minikin/Measurement.h> |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 41 | #include "MinikinSkia.h" |
| 42 | #include "MinikinUtils.h" |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 43 | #include "Paint.h" |
Raph Levien | 3d528c40 | 2014-06-26 09:04:54 -0700 | [diff] [blame] | 44 | #include "TypefaceImpl.h" |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 45 | |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 46 | #include <vector> |
| 47 | |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 48 | // temporary for debugging |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 49 | #include <Caches.h> |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 50 | #include <utils/Log.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | |
| 52 | namespace android { |
| 53 | |
| 54 | struct JMetricsID { |
| 55 | jfieldID top; |
| 56 | jfieldID ascent; |
| 57 | jfieldID descent; |
| 58 | jfieldID bottom; |
| 59 | jfieldID leading; |
| 60 | }; |
| 61 | |
| 62 | static jclass gFontMetrics_class; |
| 63 | static JMetricsID gFontMetrics_fieldID; |
| 64 | |
| 65 | static jclass gFontMetricsInt_class; |
| 66 | static JMetricsID gFontMetricsInt_fieldID; |
| 67 | |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 68 | static jclass gPaint_class; |
| 69 | static jfieldID gPaint_nativeInstanceID; |
| 70 | static jfieldID gPaint_nativeTypefaceID; |
| 71 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 72 | static void defaultSettingsForAndroid(Paint* paint) { |
Fabrice Di Meglio | c511bee8 | 2012-01-05 13:30:54 -0800 | [diff] [blame] | 73 | // GlyphID encoding is required because we are using Harfbuzz shaping |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 74 | paint->setTextEncoding(Paint::kGlyphID_TextEncoding); |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 75 | } |
| 76 | |
John Reck | 476f715 | 2015-07-10 09:56:34 -0700 | [diff] [blame] | 77 | struct LocaleCacheEntry { |
| 78 | std::string javaLocale; |
| 79 | std::string languageTag; |
| 80 | }; |
| 81 | |
| 82 | static thread_local LocaleCacheEntry sSingleEntryLocaleCache; |
| 83 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 84 | class PaintGlue { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | public: |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 86 | enum MoveOpt { |
| 87 | AFTER, AT_OR_AFTER, BEFORE, AT_OR_BEFORE, AT |
| 88 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 90 | static Paint* getNativePaint(JNIEnv* env, jobject paint) { |
| 91 | SkASSERT(env); |
| 92 | SkASSERT(paint); |
| 93 | SkASSERT(env->IsInstanceOf(paint, gPaint_class)); |
| 94 | jlong paintHandle = env->GetLongField(paint, gPaint_nativeInstanceID); |
| 95 | android::Paint* p = reinterpret_cast<android::Paint*>(paintHandle); |
| 96 | SkASSERT(p); |
| 97 | return p; |
| 98 | } |
| 99 | |
| 100 | static TypefaceImpl* getNativeTypeface(JNIEnv* env, jobject paint) { |
| 101 | SkASSERT(env); |
| 102 | SkASSERT(paint); |
| 103 | SkASSERT(env->IsInstanceOf(paint, gPaint_class)); |
| 104 | jlong typefaceHandle = env->GetLongField(paint, gPaint_nativeTypefaceID); |
| 105 | android::TypefaceImpl* p = reinterpret_cast<android::TypefaceImpl*>(typefaceHandle); |
| 106 | return p; |
| 107 | } |
| 108 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 109 | static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 110 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | delete obj; |
| 112 | } |
| 113 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 114 | static jlong init(JNIEnv* env, jobject clazz) { |
Derek Sollenberger | 0b86062 | 2015-03-25 10:08:30 -0400 | [diff] [blame] | 115 | SK_COMPILE_ASSERT(1 << 0 == SkPaint::kAntiAlias_Flag, paint_flags_mismatch); |
| 116 | SK_COMPILE_ASSERT(1 << 2 == SkPaint::kDither_Flag, paint_flags_mismatch); |
| 117 | SK_COMPILE_ASSERT(1 << 3 == SkPaint::kUnderlineText_Flag, paint_flags_mismatch); |
| 118 | SK_COMPILE_ASSERT(1 << 4 == SkPaint::kStrikeThruText_Flag, paint_flags_mismatch); |
| 119 | SK_COMPILE_ASSERT(1 << 5 == SkPaint::kFakeBoldText_Flag, paint_flags_mismatch); |
| 120 | SK_COMPILE_ASSERT(1 << 6 == SkPaint::kLinearText_Flag, paint_flags_mismatch); |
| 121 | SK_COMPILE_ASSERT(1 << 7 == SkPaint::kSubpixelText_Flag, paint_flags_mismatch); |
| 122 | SK_COMPILE_ASSERT(1 << 8 == SkPaint::kDevKernText_Flag, paint_flags_mismatch); |
| 123 | SK_COMPILE_ASSERT(1 << 10 == SkPaint::kEmbeddedBitmapText_Flag, paint_flags_mismatch); |
| 124 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 125 | Paint* obj = new Paint(); |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 126 | defaultSettingsForAndroid(obj); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 127 | return reinterpret_cast<jlong>(obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 130 | static jlong initWithPaint(JNIEnv* env, jobject clazz, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 131 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 132 | Paint* obj = new Paint(*paint); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 133 | return reinterpret_cast<jlong>(obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 135 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 136 | static void reset(JNIEnv* env, jobject clazz, jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 137 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | obj->reset(); |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 139 | defaultSettingsForAndroid(obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 141 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 142 | static void assign(JNIEnv* env, jobject clazz, jlong dstPaintHandle, jlong srcPaintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 143 | Paint* dst = reinterpret_cast<Paint*>(dstPaintHandle); |
| 144 | const Paint* src = reinterpret_cast<Paint*>(srcPaintHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | *dst = *src; |
| 146 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 147 | |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 148 | // Equivalent to the Java Paint's FILTER_BITMAP_FLAG. |
| 149 | static const uint32_t sFilterBitmapFlag = 0x02; |
| 150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | static jint getFlags(JNIEnv* env, jobject paint) { |
| 152 | NPE_CHECK_RETURN_ZERO(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 153 | Paint* nativePaint = getNativePaint(env, paint); |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 154 | uint32_t result = nativePaint->getFlags(); |
| 155 | result &= ~sFilterBitmapFlag; // Filtering no longer stored in this bit. Mask away. |
Mike Reed | 2a1ce8a | 2015-03-16 11:16:09 -0400 | [diff] [blame] | 156 | if (nativePaint->getFilterQuality() != kNone_SkFilterQuality) { |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 157 | result |= sFilterBitmapFlag; |
| 158 | } |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 159 | return static_cast<jint>(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | static void setFlags(JNIEnv* env, jobject paint, jint flags) { |
| 163 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 164 | Paint* nativePaint = getNativePaint(env, paint); |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 165 | // Instead of modifying 0x02, change the filter level. |
Mike Reed | 2a1ce8a | 2015-03-16 11:16:09 -0400 | [diff] [blame] | 166 | nativePaint->setFilterQuality(flags & sFilterBitmapFlag |
| 167 | ? kLow_SkFilterQuality |
| 168 | : kNone_SkFilterQuality); |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 169 | // Don't pass through filter flag, which is no longer stored in paint's flags. |
| 170 | flags &= ~sFilterBitmapFlag; |
| 171 | // Use the existing value for 0x02. |
| 172 | const uint32_t existing0x02Flag = nativePaint->getFlags() & sFilterBitmapFlag; |
| 173 | flags |= existing0x02Flag; |
| 174 | nativePaint->setFlags(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 176 | |
Dianne Hackborn | f43fa57 | 2011-08-12 18:59:39 -0700 | [diff] [blame] | 177 | static jint getHinting(JNIEnv* env, jobject paint) { |
| 178 | NPE_CHECK_RETURN_ZERO(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 179 | return getNativePaint(env, paint)->getHinting() |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 180 | == Paint::kNo_Hinting ? 0 : 1; |
Dianne Hackborn | f43fa57 | 2011-08-12 18:59:39 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static void setHinting(JNIEnv* env, jobject paint, jint mode) { |
| 184 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 185 | getNativePaint(env, paint)->setHinting( |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 186 | mode == 0 ? Paint::kNo_Hinting : Paint::kNormal_Hinting); |
Dianne Hackborn | f43fa57 | 2011-08-12 18:59:39 -0700 | [diff] [blame] | 187 | } |
| 188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | static void setAntiAlias(JNIEnv* env, jobject paint, jboolean aa) { |
| 190 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 191 | getNativePaint(env, paint)->setAntiAlias(aa); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | static void setLinearText(JNIEnv* env, jobject paint, jboolean linearText) { |
| 195 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 196 | getNativePaint(env, paint)->setLinearText(linearText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | static void setSubpixelText(JNIEnv* env, jobject paint, jboolean subpixelText) { |
| 200 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 201 | getNativePaint(env, paint)->setSubpixelText(subpixelText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | static void setUnderlineText(JNIEnv* env, jobject paint, jboolean underlineText) { |
| 205 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 206 | getNativePaint(env, paint)->setUnderlineText(underlineText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | static void setStrikeThruText(JNIEnv* env, jobject paint, jboolean strikeThruText) { |
| 210 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 211 | getNativePaint(env, paint)->setStrikeThruText(strikeThruText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | static void setFakeBoldText(JNIEnv* env, jobject paint, jboolean fakeBoldText) { |
| 215 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 216 | getNativePaint(env, paint)->setFakeBoldText(fakeBoldText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | static void setFilterBitmap(JNIEnv* env, jobject paint, jboolean filterBitmap) { |
| 220 | NPE_CHECK_RETURN_VOID(env, paint); |
Mike Reed | 2a1ce8a | 2015-03-16 11:16:09 -0400 | [diff] [blame] | 221 | getNativePaint(env, paint)->setFilterQuality( |
| 222 | filterBitmap ? kLow_SkFilterQuality : kNone_SkFilterQuality); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | static void setDither(JNIEnv* env, jobject paint, jboolean dither) { |
| 226 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 227 | getNativePaint(env, paint)->setDither(dither); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 229 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 230 | static jint getStyle(JNIEnv* env, jobject clazz,jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 231 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 232 | return static_cast<jint>(obj->getStyle()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 234 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 235 | static void setStyle(JNIEnv* env, jobject clazz, jlong objHandle, jint styleHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 236 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 237 | Paint::Style style = static_cast<Paint::Style>(styleHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | obj->setStyle(style); |
| 239 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | static jint getColor(JNIEnv* env, jobject paint) { |
| 242 | NPE_CHECK_RETURN_ZERO(env, paint); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 243 | int color; |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 244 | color = getNativePaint(env, paint)->getColor(); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 245 | return static_cast<jint>(color); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | static jint getAlpha(JNIEnv* env, jobject paint) { |
| 249 | NPE_CHECK_RETURN_ZERO(env, paint); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 250 | int alpha; |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 251 | alpha = getNativePaint(env, paint)->getAlpha(); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 252 | return static_cast<jint>(alpha); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | static void setColor(JNIEnv* env, jobject paint, jint color) { |
| 256 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 257 | getNativePaint(env, paint)->setColor(color); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | static void setAlpha(JNIEnv* env, jobject paint, jint a) { |
| 261 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 262 | getNativePaint(env, paint)->setAlpha(a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | static jfloat getStrokeWidth(JNIEnv* env, jobject paint) { |
| 266 | NPE_CHECK_RETURN_ZERO(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 267 | return SkScalarToFloat(getNativePaint(env, paint)->getStrokeWidth()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | static void setStrokeWidth(JNIEnv* env, jobject paint, jfloat width) { |
| 271 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 272 | getNativePaint(env, paint)->setStrokeWidth(width); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | static jfloat getStrokeMiter(JNIEnv* env, jobject paint) { |
| 276 | NPE_CHECK_RETURN_ZERO(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 277 | return SkScalarToFloat(getNativePaint(env, paint)->getStrokeMiter()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | static void setStrokeMiter(JNIEnv* env, jobject paint, jfloat miter) { |
| 281 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 282 | getNativePaint(env, paint)->setStrokeMiter(miter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 284 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 285 | static jint getStrokeCap(JNIEnv* env, jobject clazz, jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 286 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 287 | return static_cast<jint>(obj->getStrokeCap()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 289 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 290 | static void setStrokeCap(JNIEnv* env, jobject clazz, jlong objHandle, jint capHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 291 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 292 | Paint::Cap cap = static_cast<Paint::Cap>(capHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | obj->setStrokeCap(cap); |
| 294 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 295 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 296 | static jint getStrokeJoin(JNIEnv* env, jobject clazz, jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 297 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 298 | return static_cast<jint>(obj->getStrokeJoin()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 300 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 301 | static void setStrokeJoin(JNIEnv* env, jobject clazz, jlong objHandle, jint joinHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 302 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 303 | Paint::Join join = (Paint::Join) joinHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | obj->setStrokeJoin(join); |
| 305 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 306 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 307 | static jboolean getFillPath(JNIEnv* env, jobject clazz, jlong objHandle, jlong srcHandle, jlong dstHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 308 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 309 | SkPath* src = reinterpret_cast<SkPath*>(srcHandle); |
| 310 | SkPath* dst = reinterpret_cast<SkPath*>(dstHandle); |
| 311 | return obj->getFillPath(*src, dst) ? JNI_TRUE : JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 313 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 314 | static jlong setShader(JNIEnv* env, jobject clazz, jlong objHandle, jlong shaderHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 315 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 316 | SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); |
| 317 | return reinterpret_cast<jlong>(obj->setShader(shader)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 319 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 320 | static jlong setColorFilter(JNIEnv* env, jobject clazz, jlong objHandle, jlong filterHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 321 | Paint* obj = reinterpret_cast<Paint *>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 322 | SkColorFilter* filter = reinterpret_cast<SkColorFilter *>(filterHandle); |
| 323 | return reinterpret_cast<jlong>(obj->setColorFilter(filter)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 325 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 326 | static jlong setXfermode(JNIEnv* env, jobject clazz, jlong objHandle, jlong xfermodeHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 327 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 328 | SkXfermode* xfermode = reinterpret_cast<SkXfermode*>(xfermodeHandle); |
| 329 | return reinterpret_cast<jlong>(obj->setXfermode(xfermode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 331 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 332 | static jlong setPathEffect(JNIEnv* env, jobject clazz, jlong objHandle, jlong effectHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 333 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 334 | SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle); |
| 335 | return reinterpret_cast<jlong>(obj->setPathEffect(effect)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 337 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 338 | static jlong setMaskFilter(JNIEnv* env, jobject clazz, jlong objHandle, jlong maskfilterHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 339 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 340 | SkMaskFilter* maskfilter = reinterpret_cast<SkMaskFilter*>(maskfilterHandle); |
| 341 | return reinterpret_cast<jlong>(obj->setMaskFilter(maskfilter)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 343 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 344 | static jlong setTypeface(JNIEnv* env, jobject clazz, jlong objHandle, jlong typefaceHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 345 | // TODO: in Paint refactoring, set typeface on android Paint, not Paint |
Raph Levien | a033630 | 2013-05-22 16:16:59 -0700 | [diff] [blame] | 346 | return NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 348 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 349 | static jlong setRasterizer(JNIEnv* env, jobject clazz, jlong objHandle, jlong rasterizerHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 350 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 351 | SkAutoTUnref<SkRasterizer> rasterizer(GraphicsJNI::refNativeRasterizer(rasterizerHandle)); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 352 | return reinterpret_cast<jlong>(obj->setRasterizer(rasterizer)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 354 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 355 | static jint getTextAlign(JNIEnv* env, jobject clazz, jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 356 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 357 | return static_cast<jint>(obj->getTextAlign()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 359 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 360 | static void setTextAlign(JNIEnv* env, jobject clazz, jlong objHandle, jint alignHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 361 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 362 | Paint::Align align = static_cast<Paint::Align>(alignHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | obj->setTextAlign(align); |
| 364 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 365 | |
Billy Hewlett | ac1cbaf | 2012-07-18 09:51:45 -0700 | [diff] [blame] | 366 | // generate bcp47 identifier for the supplied locale |
| 367 | static void toLanguageTag(char* output, size_t outSize, |
| 368 | const char* locale) { |
| 369 | if (output == NULL || outSize <= 0) { |
| 370 | return; |
| 371 | } |
| 372 | if (locale == NULL) { |
| 373 | output[0] = '\0'; |
| 374 | return; |
| 375 | } |
| 376 | char canonicalChars[ULOC_FULLNAME_CAPACITY]; |
| 377 | UErrorCode uErr = U_ZERO_ERROR; |
| 378 | uloc_canonicalize(locale, canonicalChars, ULOC_FULLNAME_CAPACITY, |
| 379 | &uErr); |
| 380 | if (U_SUCCESS(uErr)) { |
| 381 | char likelyChars[ULOC_FULLNAME_CAPACITY]; |
| 382 | uErr = U_ZERO_ERROR; |
| 383 | uloc_addLikelySubtags(canonicalChars, likelyChars, |
| 384 | ULOC_FULLNAME_CAPACITY, &uErr); |
| 385 | if (U_SUCCESS(uErr)) { |
| 386 | uErr = U_ZERO_ERROR; |
| 387 | uloc_toLanguageTag(likelyChars, output, outSize, FALSE, &uErr); |
| 388 | if (U_SUCCESS(uErr)) { |
| 389 | return; |
| 390 | } else { |
| 391 | ALOGD("uloc_toLanguageTag(\"%s\") failed: %s", likelyChars, |
| 392 | u_errorName(uErr)); |
| 393 | } |
| 394 | } else { |
| 395 | ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s", |
| 396 | canonicalChars, u_errorName(uErr)); |
| 397 | } |
| 398 | } else { |
| 399 | ALOGD("uloc_canonicalize(\"%s\") failed: %s", locale, |
| 400 | u_errorName(uErr)); |
| 401 | } |
| 402 | // unable to build a proper language identifier |
| 403 | output[0] = '\0'; |
| 404 | } |
| 405 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 406 | static void setTextLocale(JNIEnv* env, jobject clazz, jlong objHandle, jstring locale) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 407 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Billy Hewlett | ac1cbaf | 2012-07-18 09:51:45 -0700 | [diff] [blame] | 408 | ScopedUtfChars localeChars(env, locale); |
John Reck | 476f715 | 2015-07-10 09:56:34 -0700 | [diff] [blame] | 409 | if (sSingleEntryLocaleCache.javaLocale != localeChars.c_str()) { |
| 410 | sSingleEntryLocaleCache.javaLocale = localeChars.c_str(); |
| 411 | char langTag[ULOC_FULLNAME_CAPACITY]; |
| 412 | toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, localeChars.c_str()); |
| 413 | sSingleEntryLocaleCache.languageTag = langTag; |
| 414 | } |
Derek Sollenberger | d7a8077 | 2013-05-28 10:44:26 -0400 | [diff] [blame] | 415 | |
John Reck | 476f715 | 2015-07-10 09:56:34 -0700 | [diff] [blame] | 416 | obj->setTextLocale(sSingleEntryLocaleCache.languageTag); |
Fabrice Di Meglio | 517825f | 2012-04-06 16:53:48 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 419 | static jboolean isElegantTextHeight(JNIEnv* env, jobject paint) { |
| 420 | NPE_CHECK_RETURN_ZERO(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 421 | Paint* obj = getNativePaint(env, paint); |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 422 | return obj->getFontVariant() == VARIANT_ELEGANT; |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static void setElegantTextHeight(JNIEnv* env, jobject paint, jboolean aa) { |
| 426 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 427 | Paint* obj = getNativePaint(env, paint); |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 428 | obj->setFontVariant(aa ? VARIANT_ELEGANT : VARIANT_DEFAULT); |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 429 | } |
| 430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | static jfloat getTextSize(JNIEnv* env, jobject paint) { |
| 432 | NPE_CHECK_RETURN_ZERO(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 433 | return SkScalarToFloat(getNativePaint(env, paint)->getTextSize()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | static void setTextSize(JNIEnv* env, jobject paint, jfloat textSize) { |
| 437 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 438 | getNativePaint(env, paint)->setTextSize(textSize); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | static jfloat getTextScaleX(JNIEnv* env, jobject paint) { |
| 442 | NPE_CHECK_RETURN_ZERO(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 443 | return SkScalarToFloat(getNativePaint(env, paint)->getTextScaleX()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | static void setTextScaleX(JNIEnv* env, jobject paint, jfloat scaleX) { |
| 447 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 448 | getNativePaint(env, paint)->setTextScaleX(scaleX); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | static jfloat getTextSkewX(JNIEnv* env, jobject paint) { |
| 452 | NPE_CHECK_RETURN_ZERO(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 453 | return SkScalarToFloat(getNativePaint(env, paint)->getTextSkewX()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | static void setTextSkewX(JNIEnv* env, jobject paint, jfloat skewX) { |
| 457 | NPE_CHECK_RETURN_VOID(env, paint); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 458 | getNativePaint(env, paint)->setTextSkewX(skewX); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 460 | |
Behdad Esfahbod | fa80f74 | 2014-07-17 19:10:39 -0400 | [diff] [blame] | 461 | static jfloat getLetterSpacing(JNIEnv* env, jobject clazz, jlong paintHandle) { |
| 462 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 463 | return paint->getLetterSpacing(); |
| 464 | } |
| 465 | |
| 466 | static void setLetterSpacing(JNIEnv* env, jobject clazz, jlong paintHandle, jfloat letterSpacing) { |
| 467 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 468 | paint->setLetterSpacing(letterSpacing); |
| 469 | } |
| 470 | |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 471 | static void setFontFeatureSettings(JNIEnv* env, jobject clazz, jlong paintHandle, jstring settings) { |
| 472 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Behdad Esfahbod | e9ad393 | 2014-07-30 19:46:53 -0400 | [diff] [blame] | 473 | if (!settings) { |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 474 | paint->setFontFeatureSettings(std::string()); |
Behdad Esfahbod | e9ad393 | 2014-07-30 19:46:53 -0400 | [diff] [blame] | 475 | } else { |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 476 | ScopedUtfChars settingsChars(env, settings); |
| 477 | paint->setFontFeatureSettings(std::string(settingsChars.c_str(), settingsChars.size())); |
| 478 | } |
| 479 | } |
| 480 | |
Raph Levien | 210a189 | 2015-03-09 14:42:14 -0700 | [diff] [blame] | 481 | static jint getHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) { |
| 482 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 483 | return paint->getHyphenEdit(); |
| 484 | } |
| 485 | |
| 486 | static void setHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) { |
| 487 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 488 | paint->setHyphenEdit((uint32_t)hyphen); |
| 489 | } |
| 490 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 491 | static SkScalar getMetricsInternal(JNIEnv* env, jobject jpaint, Paint::FontMetrics *metrics) { |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 492 | const int kElegantTop = 2500; |
| 493 | const int kElegantBottom = -1000; |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 494 | const int kElegantAscent = 1900; |
| 495 | const int kElegantDescent = -500; |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 496 | const int kElegantLeading = 0; |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 497 | Paint* paint = getNativePaint(env, jpaint); |
| 498 | TypefaceImpl* typeface = getNativeTypeface(env, jpaint); |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 499 | typeface = TypefaceImpl_resolveDefault(typeface); |
Raph Levien | 1fc0fa8 | 2014-06-06 18:05:22 -0700 | [diff] [blame] | 500 | FakedFont baseFont = typeface->fFontCollection->baseFontFaked(typeface->fStyle); |
Raph Levien | 0627ec0 | 2014-06-06 22:31:15 -0700 | [diff] [blame] | 501 | float saveSkewX = paint->getTextSkewX(); |
| 502 | bool savefakeBold = paint->isFakeBoldText(); |
Raph Levien | 1fc0fa8 | 2014-06-06 18:05:22 -0700 | [diff] [blame] | 503 | MinikinFontSkia::populateSkPaint(paint, baseFont.font, baseFont.fakery); |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 504 | SkScalar spacing = paint->getFontMetrics(metrics); |
Raph Levien | 0627ec0 | 2014-06-06 22:31:15 -0700 | [diff] [blame] | 505 | // The populateSkPaint call may have changed fake bold / text skew |
| 506 | // because we want to measure with those effects applied, so now |
| 507 | // restore the original settings. |
| 508 | paint->setTextSkewX(saveSkewX); |
| 509 | paint->setFakeBoldText(savefakeBold); |
Derek Sollenberger | 6f03023 | 2014-08-07 08:10:39 -0400 | [diff] [blame] | 510 | if (paint->getFontVariant() == VARIANT_ELEGANT) { |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 511 | SkScalar size = paint->getTextSize(); |
| 512 | metrics->fTop = -size * kElegantTop / 2048; |
| 513 | metrics->fBottom = -size * kElegantBottom / 2048; |
| 514 | metrics->fAscent = -size * kElegantAscent / 2048; |
| 515 | metrics->fDescent = -size * kElegantDescent / 2048; |
| 516 | metrics->fLeading = size * kElegantLeading / 2048; |
| 517 | spacing = metrics->fDescent - metrics->fAscent + metrics->fLeading; |
| 518 | } |
| 519 | return spacing; |
| 520 | } |
| 521 | |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 522 | static jfloat ascent(JNIEnv* env, jobject paint) { |
| 523 | NPE_CHECK_RETURN_ZERO(env, paint); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 524 | Paint::FontMetrics metrics; |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 525 | getMetricsInternal(env, paint, &metrics); |
| 526 | return SkScalarToFloat(metrics.fAscent); |
| 527 | } |
| 528 | |
| 529 | static jfloat descent(JNIEnv* env, jobject paint) { |
| 530 | NPE_CHECK_RETURN_ZERO(env, paint); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 531 | Paint::FontMetrics metrics; |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 532 | getMetricsInternal(env, paint, &metrics); |
| 533 | return SkScalarToFloat(metrics.fDescent); |
| 534 | } |
| 535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | static jfloat getFontMetrics(JNIEnv* env, jobject paint, jobject metricsObj) { |
| 537 | NPE_CHECK_RETURN_ZERO(env, paint); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 538 | Paint::FontMetrics metrics; |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 539 | SkScalar spacing = getMetricsInternal(env, paint, &metrics); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | |
| 541 | if (metricsObj) { |
| 542 | SkASSERT(env->IsInstanceOf(metricsObj, gFontMetrics_class)); |
| 543 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.top, SkScalarToFloat(metrics.fTop)); |
| 544 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.ascent, SkScalarToFloat(metrics.fAscent)); |
| 545 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.descent, SkScalarToFloat(metrics.fDescent)); |
| 546 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.bottom, SkScalarToFloat(metrics.fBottom)); |
| 547 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.leading, SkScalarToFloat(metrics.fLeading)); |
| 548 | } |
| 549 | return SkScalarToFloat(spacing); |
| 550 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | static jint getFontMetricsInt(JNIEnv* env, jobject paint, jobject metricsObj) { |
| 553 | NPE_CHECK_RETURN_ZERO(env, paint); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 554 | Paint::FontMetrics metrics; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 555 | |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 556 | getMetricsInternal(env, paint, &metrics); |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 557 | int ascent = SkScalarRoundToInt(metrics.fAscent); |
| 558 | int descent = SkScalarRoundToInt(metrics.fDescent); |
| 559 | int leading = SkScalarRoundToInt(metrics.fLeading); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | |
| 561 | if (metricsObj) { |
| 562 | SkASSERT(env->IsInstanceOf(metricsObj, gFontMetricsInt_class)); |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 563 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.top, SkScalarFloorToInt(metrics.fTop)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.ascent, ascent); |
| 565 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.descent, descent); |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 566 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.bottom, SkScalarCeilToInt(metrics.fBottom)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.leading, leading); |
| 568 | } |
| 569 | return descent - ascent + leading; |
| 570 | } |
| 571 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 572 | static jfloat measureText_CIII(JNIEnv* env, jobject jpaint, jcharArray text, jint index, jint count, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 573 | jint bidiFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 575 | NPE_CHECK_RETURN_ZERO(env, text); |
| 576 | |
| 577 | size_t textLength = env->GetArrayLength(text); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | if ((index | count) < 0 || (size_t)(index + count) > textLength) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 579 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | return 0; |
| 581 | } |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 582 | if (count == 0) { |
| 583 | return 0; |
| 584 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 586 | Paint* paint = getNativePaint(env, jpaint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 588 | jfloat result = 0; |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 589 | |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 590 | Layout layout; |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 591 | TypefaceImpl* typeface = getNativeTypeface(env, jpaint); |
Raph Levien | 80b485d | 2015-04-03 10:41:52 -0700 | [diff] [blame] | 592 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, textArray + index, 0, count, |
| 593 | count); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 594 | result = layout.getAdvance(); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 595 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); |
| 596 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 598 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 599 | static jfloat measureText_StringIII(JNIEnv* env, jobject jpaint, jstring text, jint start, jint end, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 600 | jint bidiFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 602 | NPE_CHECK_RETURN_ZERO(env, text); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 603 | |
Fabrice Di Meglio | 51f383d | 2011-09-13 15:57:58 -0700 | [diff] [blame] | 604 | size_t textLength = env->GetStringLength(text); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | int count = end - start; |
Fabrice Di Meglio | 51f383d | 2011-09-13 15:57:58 -0700 | [diff] [blame] | 606 | if ((start | count) < 0 || (size_t)end > textLength) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 607 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | return 0; |
| 609 | } |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 610 | if (count == 0) { |
| 611 | return 0; |
| 612 | } |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 613 | |
| 614 | const jchar* textArray = env->GetStringChars(text, NULL); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 615 | Paint* paint = getNativePaint(env, jpaint); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 616 | jfloat width = 0; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 617 | |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 618 | Layout layout; |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 619 | TypefaceImpl* typeface = getNativeTypeface(env, jpaint); |
Raph Levien | 1149cdc | 2015-06-24 09:36:31 -0700 | [diff] [blame] | 620 | // Only the substring is used for measurement, so no additional context is passed in. This |
| 621 | // behavior is consistent between char[] and String specializations. |
| 622 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, textArray + start, 0, count, count); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 623 | width = layout.getAdvance(); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | env->ReleaseStringChars(text, textArray); |
| 626 | return width; |
| 627 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 628 | |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 629 | static jfloat measureText_StringI(JNIEnv* env, jobject jpaint, jstring text, jint bidiFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 631 | NPE_CHECK_RETURN_ZERO(env, text); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | size_t textLength = env->GetStringLength(text); |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 634 | if (textLength == 0) { |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | const jchar* textArray = env->GetStringChars(text, NULL); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 639 | Paint* paint = getNativePaint(env, jpaint); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 640 | jfloat width = 0; |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 641 | |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 642 | Layout layout; |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 643 | TypefaceImpl* typeface = getNativeTypeface(env, jpaint); |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 644 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, textArray, 0, textLength, textLength); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 645 | width = layout.getAdvance(); |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | env->ReleaseStringChars(text, textArray); |
| 648 | return width; |
| 649 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 650 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 651 | static int dotextwidths(JNIEnv* env, Paint* paint, TypefaceImpl* typeface, const jchar text[], int count, |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 652 | jfloatArray widths, jint bidiFlags) { |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 653 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 654 | NPE_CHECK_RETURN_ZERO(env, text); |
| 655 | |
| 656 | if (count < 0 || !widths) { |
| 657 | doThrowAIOOBE(env); |
| 658 | return 0; |
| 659 | } |
| 660 | if (count == 0) { |
| 661 | return 0; |
| 662 | } |
| 663 | size_t widthsLength = env->GetArrayLength(widths); |
| 664 | if ((size_t)count > widthsLength) { |
| 665 | doThrowAIOOBE(env); |
| 666 | return 0; |
| 667 | } |
| 668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | AutoJavaFloatArray autoWidths(env, widths, count); |
| 670 | jfloat* widthsArray = autoWidths.ptr(); |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 671 | |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 672 | Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 673 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 674 | layout.getAdvances(widthsArray); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | return count; |
| 677 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 678 | |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 679 | static jint getTextWidths___CIII_F(JNIEnv* env, jobject clazz, jlong paintHandle, jlong typefaceHandle, jcharArray text, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 680 | jint index, jint count, jint bidiFlags, jfloatArray widths) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 681 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 682 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 684 | count = dotextwidths(env, paint, typeface, textArray + index, count, widths, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 686 | JNI_ABORT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | return count; |
| 688 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 689 | |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 690 | static jint getTextWidths__StringIII_F(JNIEnv* env, jobject clazz, jlong paintHandle, jlong typefaceHandle, jstring text, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 691 | jint start, jint end, jint bidiFlags, jfloatArray widths) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 692 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 693 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | const jchar* textArray = env->GetStringChars(text, NULL); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 695 | int count = dotextwidths(env, paint, typeface, textArray + start, end - start, widths, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 696 | env->ReleaseStringChars(text, textArray); |
| 697 | return count; |
| 698 | } |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 699 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 700 | static jfloat doTextRunAdvances(JNIEnv *env, Paint *paint, TypefaceImpl* typeface, const jchar *text, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 701 | jint start, jint count, jint contextCount, jboolean isRtl, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 702 | jfloatArray advances, jint advancesIndex) { |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 703 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 704 | NPE_CHECK_RETURN_ZERO(env, text); |
| 705 | |
| 706 | if ((start | count | contextCount | advancesIndex) < 0 || contextCount < count) { |
| 707 | doThrowAIOOBE(env); |
| 708 | return 0; |
| 709 | } |
| 710 | if (count == 0) { |
| 711 | return 0; |
| 712 | } |
| 713 | if (advances) { |
| 714 | size_t advancesLength = env->GetArrayLength(advances); |
| 715 | if ((size_t)count > advancesLength) { |
| 716 | doThrowAIOOBE(env); |
| 717 | return 0; |
| 718 | } |
| 719 | } |
Victoria Lease | 3af2a37 | 2014-03-17 16:03:28 -0700 | [diff] [blame] | 720 | jfloat* advancesArray = new jfloat[count]; |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 721 | jfloat totalAdvance = 0; |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 722 | |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 723 | int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; |
| 724 | |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 725 | Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 726 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, start, count, contextCount); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 727 | layout.getAdvances(advancesArray); |
| 728 | totalAdvance = layout.getAdvance(); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 729 | |
| 730 | if (advances != NULL) { |
| 731 | env->SetFloatArrayRegion(advances, advancesIndex, count, advancesArray); |
| 732 | } |
Victoria Lease | 3af2a37 | 2014-03-17 16:03:28 -0700 | [diff] [blame] | 733 | delete [] advancesArray; |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 734 | return totalAdvance; |
| 735 | } |
| 736 | |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 737 | static jfloat getTextRunAdvances___CIIIIZ_FI(JNIEnv* env, jobject clazz, jlong paintHandle, |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 738 | jlong typefaceHandle, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 739 | jcharArray text, jint index, jint count, jint contextIndex, jint contextCount, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 740 | jboolean isRtl, jfloatArray advances, jint advancesIndex) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 741 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 742 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 743 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 744 | jfloat result = doTextRunAdvances(env, paint, typeface, textArray + contextIndex, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 745 | index - contextIndex, count, contextCount, isRtl, advances, advancesIndex); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 746 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 747 | return result; |
| 748 | } |
| 749 | |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 750 | static jfloat getTextRunAdvances__StringIIIIZ_FI(JNIEnv* env, jobject clazz, jlong paintHandle, |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 751 | jlong typefaceHandle, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 752 | jstring text, jint start, jint end, jint contextStart, jint contextEnd, jboolean isRtl, |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 753 | jfloatArray advances, jint advancesIndex) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 754 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 755 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 756 | const jchar* textArray = env->GetStringChars(text, NULL); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 757 | jfloat result = doTextRunAdvances(env, paint, typeface, textArray + contextStart, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 758 | start - contextStart, end - start, contextEnd - contextStart, isRtl, |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 759 | advances, advancesIndex); |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 760 | env->ReleaseStringChars(text, textArray); |
| 761 | return result; |
| 762 | } |
| 763 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 764 | static jint doTextRunCursor(JNIEnv *env, Paint* paint, const jchar *text, jint start, |
Fabrice Di Meglio | a4bf811 | 2013-03-15 11:22:29 -0700 | [diff] [blame] | 765 | jint count, jint flags, jint offset, jint opt) { |
Raph Levien | e368b6b | 2014-06-15 17:37:57 -0700 | [diff] [blame] | 766 | GraphemeBreak::MoveOpt moveOpt = GraphemeBreak::MoveOpt(opt); |
| 767 | size_t result = GraphemeBreak::getTextRunCursor(text, start, count, offset, moveOpt); |
| 768 | return static_cast<jint>(result); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 771 | static jint getTextRunCursor___C(JNIEnv* env, jobject clazz, jlong paintHandle, jcharArray text, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 772 | jint contextStart, jint contextCount, jint dir, jint offset, jint cursorOpt) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 773 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 774 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 775 | jint result = doTextRunCursor(env, paint, textArray, contextStart, contextCount, dir, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 776 | offset, cursorOpt); |
| 777 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 778 | return result; |
| 779 | } |
| 780 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 781 | static jint getTextRunCursor__String(JNIEnv* env, jobject clazz, jlong paintHandle, jstring text, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 782 | jint contextStart, jint contextEnd, jint dir, jint offset, jint cursorOpt) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 783 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 784 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 785 | jint result = doTextRunCursor(env, paint, textArray, contextStart, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 786 | contextEnd - contextStart, dir, offset, cursorOpt); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 787 | env->ReleaseStringChars(text, textArray); |
| 788 | return result; |
| 789 | } |
| 790 | |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 791 | class GetTextFunctor { |
| 792 | public: |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 793 | GetTextFunctor(const Layout& layout, SkPath* path, jfloat x, jfloat y, Paint* paint, |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 794 | uint16_t* glyphs, SkPoint* pos) |
| 795 | : layout(layout), path(path), x(x), y(y), paint(paint), glyphs(glyphs), pos(pos) { |
| 796 | } |
| 797 | |
Raph Levien | 1fc0fa8 | 2014-06-06 18:05:22 -0700 | [diff] [blame] | 798 | void operator()(size_t start, size_t end) { |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 799 | for (size_t i = start; i < end; i++) { |
| 800 | glyphs[i] = layout.getGlyphId(i); |
| 801 | pos[i].fX = x + layout.getX(i); |
| 802 | pos[i].fY = y + layout.getY(i); |
| 803 | } |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 804 | if (start == 0) { |
| 805 | paint->getPosTextPath(glyphs + start, (end - start) << 1, pos + start, path); |
| 806 | } else { |
| 807 | paint->getPosTextPath(glyphs + start, (end - start) << 1, pos + start, &tmpPath); |
| 808 | path->addPath(tmpPath); |
| 809 | } |
| 810 | } |
| 811 | private: |
| 812 | const Layout& layout; |
| 813 | SkPath* path; |
| 814 | jfloat x; |
| 815 | jfloat y; |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 816 | Paint* paint; |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 817 | uint16_t* glyphs; |
| 818 | SkPoint* pos; |
| 819 | SkPath tmpPath; |
| 820 | }; |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 821 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 822 | static void getTextPath(JNIEnv* env, Paint* paint, TypefaceImpl* typeface, const jchar* text, |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 823 | jint count, jint bidiFlags, jfloat x, jfloat y, SkPath* path) { |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 824 | Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 825 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 826 | size_t nGlyphs = layout.nGlyphs(); |
| 827 | uint16_t* glyphs = new uint16_t[nGlyphs]; |
| 828 | SkPoint* pos = new SkPoint[nGlyphs]; |
| 829 | |
| 830 | x += MinikinUtils::xOffsetForTextAlign(paint, layout); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 831 | Paint::Align align = paint->getTextAlign(); |
| 832 | paint->setTextAlign(Paint::kLeft_Align); |
| 833 | paint->setTextEncoding(Paint::kGlyphID_TextEncoding); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 834 | GetTextFunctor f(layout, path, x, y, paint, glyphs, pos); |
Raph Levien | 1fc0fa8 | 2014-06-06 18:05:22 -0700 | [diff] [blame] | 835 | MinikinUtils::forFontRun(layout, paint, f); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 836 | paint->setTextAlign(align); |
| 837 | delete[] glyphs; |
| 838 | delete[] pos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 840 | |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 841 | static void getTextPath___C(JNIEnv* env, jobject clazz, jlong paintHandle, |
| 842 | jlong typefaceHandle, jint bidiFlags, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 843 | jcharArray text, jint index, jint count, jfloat x, jfloat y, jlong pathHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 844 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 845 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 846 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 847 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 848 | getTextPath(env, paint, typeface, textArray + index, count, bidiFlags, x, y, path); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 849 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); |
| 850 | } |
| 851 | |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 852 | static void getTextPath__String(JNIEnv* env, jobject clazz, jlong paintHandle, |
| 853 | jlong typefaceHandle, jint bidiFlags, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 854 | jstring text, jint start, jint end, jfloat x, jfloat y, jlong pathHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 855 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 856 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 857 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | const jchar* textArray = env->GetStringChars(text, NULL); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 859 | getTextPath(env, paint, typeface, textArray + start, end - start, bidiFlags, x, y, path); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | env->ReleaseStringChars(text, textArray); |
| 861 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 862 | |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 863 | static void setShadowLayer(JNIEnv* env, jobject clazz, jlong paintHandle, jfloat radius, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 864 | jfloat dx, jfloat dy, jint color) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 865 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | if (radius <= 0) { |
| 867 | paint->setLooper(NULL); |
| 868 | } |
| 869 | else { |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 870 | SkScalar sigma = android::uirenderer::Blur::convertRadiusToSigma(radius); |
Victoria Lease | 49f0db3 | 2014-05-19 16:00:17 -0700 | [diff] [blame] | 871 | paint->setLooper(SkBlurDrawLooper::Create((SkColor)color, sigma, dx, dy))->unref(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 875 | static jboolean hasShadowLayer(JNIEnv* env, jobject clazz, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 876 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 877 | return paint->getLooper() && paint->getLooper()->asABlurShadow(NULL); |
| 878 | } |
| 879 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 880 | static int breakText(JNIEnv* env, const Paint& paint, TypefaceImpl* typeface, const jchar text[], |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 881 | int count, float maxWidth, jint bidiFlags, jfloatArray jmeasured, |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 882 | const bool forwardScan) { |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 883 | size_t measuredCount = 0; |
| 884 | float measured = 0; |
| 885 | |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 886 | Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 887 | MinikinUtils::doLayout(&layout, &paint, bidiFlags, typeface, text, 0, count, count); |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 888 | float* advances = new float[count]; |
| 889 | layout.getAdvances(advances); |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 890 | |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 891 | for (int i = 0; i < count; i++) { |
| 892 | // traverse in the given direction |
| 893 | int index = forwardScan ? i : (count - i - 1); |
| 894 | float width = advances[index]; |
| 895 | if (measured + width > maxWidth) { |
| 896 | break; |
| 897 | } |
| 898 | // properly handle clusters when scanning backwards |
| 899 | if (forwardScan || width != 0.0f) { |
| 900 | measuredCount = i + 1; |
| 901 | } |
| 902 | measured += width; |
| 903 | } |
| 904 | delete[] advances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | |
| 906 | if (jmeasured && env->GetArrayLength(jmeasured) > 0) { |
| 907 | AutoJavaFloatArray autoMeasured(env, jmeasured, 1); |
| 908 | jfloat* array = autoMeasured.ptr(); |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 909 | array[0] = measured; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | } |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 911 | return measuredCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | } |
| 913 | |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 914 | static jint breakTextC(JNIEnv* env, jobject clazz, jlong paintHandle, jlong typefaceHandle, jcharArray jtext, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 915 | jint index, jint count, jfloat maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 917 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 918 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 919 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
| 920 | |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 921 | bool forwardTextDirection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | if (count < 0) { |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 923 | forwardTextDirection = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | count = -count; |
| 925 | } |
| 926 | else { |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 927 | forwardTextDirection = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | if ((index < 0) || (index + count > env->GetArrayLength(jtext))) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 931 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | return 0; |
| 933 | } |
| 934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | const jchar* text = env->GetCharArrayElements(jtext, NULL); |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 936 | count = breakText(env, *paint, typeface, text + index, count, maxWidth, |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 937 | bidiFlags, jmeasuredWidth, forwardTextDirection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | env->ReleaseCharArrayElements(jtext, const_cast<jchar*>(text), |
| 939 | JNI_ABORT); |
| 940 | return count; |
| 941 | } |
| 942 | |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 943 | static jint breakTextS(JNIEnv* env, jobject clazz, jlong paintHandle, jlong typefaceHandle, jstring jtext, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 944 | jboolean forwards, jfloat maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 945 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 946 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 947 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 948 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
| 949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | int count = env->GetStringLength(jtext); |
| 951 | const jchar* text = env->GetStringChars(jtext, NULL); |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 952 | count = breakText(env, *paint, typeface, text, count, maxWidth, bidiFlags, jmeasuredWidth, forwards); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | env->ReleaseStringChars(jtext, text); |
| 954 | return count; |
| 955 | } |
| 956 | |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 957 | static void doTextBounds(JNIEnv* env, const jchar* text, int count, jobject bounds, |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 958 | const Paint& paint, TypefaceImpl* typeface, jint bidiFlags) { |
Romain Guy | 059e12c | 2012-11-28 17:35:51 -0800 | [diff] [blame] | 959 | SkRect r; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 960 | SkIRect ir; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 961 | |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 962 | Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 963 | MinikinUtils::doLayout(&layout, &paint, bidiFlags, typeface, text, 0, count, count); |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 964 | MinikinRect rect; |
| 965 | layout.getBounds(&rect); |
| 966 | r.fLeft = rect.mLeft; |
| 967 | r.fTop = rect.mTop; |
| 968 | r.fRight = rect.mRight; |
| 969 | r.fBottom = rect.mBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | r.roundOut(&ir); |
| 971 | GraphicsJNI::irect_to_jrect(ir, env, bounds); |
| 972 | } |
| 973 | |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 974 | static void getStringBounds(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 975 | jstring text, jint start, jint end, jint bidiFlags, jobject bounds) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 976 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle);; |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 977 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | const jchar* textArray = env->GetStringChars(text, NULL); |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 979 | doTextBounds(env, textArray + start, end - start, bounds, *paint, typeface, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | env->ReleaseStringChars(text, textArray); |
| 981 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 982 | |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 983 | static void getCharArrayBounds(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 984 | jcharArray text, jint index, jint count, jint bidiFlags, jobject bounds) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 985 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 986 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 987 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 988 | doTextBounds(env, textArray + index, count, bounds, *paint, typeface, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 989 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
| 990 | JNI_ABORT); |
| 991 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 992 | |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 993 | static jboolean layoutContainsNotdef(const Layout& layout) { |
| 994 | for (size_t i = 0; i < layout.nGlyphs(); i++) { |
| 995 | if (layout.getGlyphId(i) == 0) { |
| 996 | return true; |
| 997 | } |
| 998 | } |
| 999 | return false; |
| 1000 | } |
| 1001 | |
| 1002 | static jboolean hasGlyphVariation(const Paint* paint, TypefaceImpl* typeface, jint bidiFlags, |
| 1003 | const jchar* chars, size_t size) { |
| 1004 | // TODO: query font for whether character has variation selector; requires a corresponding |
| 1005 | // function in Minikin. |
| 1006 | return false; |
| 1007 | } |
| 1008 | |
| 1009 | static jboolean hasGlyph(JNIEnv *env, jclass, jlong paintHandle, jlong typefaceHandle, |
| 1010 | jint bidiFlags, jstring string) { |
| 1011 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 1012 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
| 1013 | ScopedStringChars str(env, string); |
| 1014 | |
| 1015 | /* start by rejecting variation selectors (not supported yet) */ |
| 1016 | size_t nChars = 0; |
| 1017 | for (size_t i = 0; i < str.size(); i++) { |
| 1018 | jchar c = str[i]; |
| 1019 | if (0xDC00 <= c && c <= 0xDFFF) { |
| 1020 | // invalid UTF-16, unpaired trailing surrogate |
| 1021 | return false; |
| 1022 | } else if (0xD800 <= c && c <= 0xDBFF) { |
| 1023 | if (i + 1 == str.size()) { |
| 1024 | // invalid UTF-16, unpaired leading surrogate at end of string |
| 1025 | return false; |
| 1026 | } |
| 1027 | i++; |
| 1028 | jchar c2 = str[i]; |
| 1029 | if (!(0xDC00 <= c2 && c2 <= 0xDFFF)) { |
| 1030 | // invalid UTF-16, unpaired leading surrogate |
| 1031 | return false; |
| 1032 | } |
| 1033 | // UTF-16 encoding of range U+E0100..U+E01EF is DB40 DD00 .. DB40 DDEF |
| 1034 | if (c == 0xDB40 && 0xDD00 <= c2 && c2 <= 0xDDEF) { |
| 1035 | return hasGlyphVariation(paint, typeface, bidiFlags, str.get(), str.size()); |
| 1036 | } |
| 1037 | } else if (0xFE00 <= c && c <= 0xFE0F) { |
| 1038 | return hasGlyphVariation(paint, typeface, bidiFlags, str.get(), str.size()); |
| 1039 | } |
| 1040 | nChars++; |
| 1041 | } |
| 1042 | Layout layout; |
| 1043 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, str.get(), 0, str.size(), |
| 1044 | str.size()); |
| 1045 | size_t nGlyphs = layout.nGlyphs(); |
| 1046 | if (nGlyphs != 1 && nChars > 1) { |
| 1047 | // multiple-character input, and was not a ligature |
| 1048 | // TODO: handle ZWJ/ZWNJ characters specially so we can detect certain ligatures |
| 1049 | // in joining scripts, such as Arabic and Mongolian. |
| 1050 | return false; |
| 1051 | } |
| 1052 | return nGlyphs > 0 && !layoutContainsNotdef(layout); |
| 1053 | } |
| 1054 | |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1055 | static jfloat doRunAdvance(const Paint* paint, TypefaceImpl* typeface, const jchar buf[], |
| 1056 | jint start, jint count, jint bufSize, jboolean isRtl, jint offset) { |
| 1057 | Layout layout; |
| 1058 | int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; |
| 1059 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, buf, start, count, bufSize); |
| 1060 | return getRunAdvance(layout, buf, start, count, offset); |
| 1061 | } |
| 1062 | |
| 1063 | static jfloat getRunAdvance___CIIIIZI_F(JNIEnv *env, jclass, jlong paintHandle, |
| 1064 | jlong typefaceHandle, jcharArray text, jint start, jint end, jint contextStart, |
| 1065 | jint contextEnd, jboolean isRtl, jint offset) { |
| 1066 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 1067 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame^] | 1068 | jchar* textArray = (jchar*) env->GetPrimitiveArrayCritical(text, NULL); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1069 | jfloat result = doRunAdvance(paint, typeface, textArray + contextStart, |
Raph Levien | 36ff86c | 2015-06-03 10:58:33 -0700 | [diff] [blame] | 1070 | start - contextStart, end - start, contextEnd - contextStart, isRtl, |
| 1071 | offset - contextStart); |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame^] | 1072 | env->ReleasePrimitiveArrayCritical(text, textArray, JNI_ABORT); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1073 | return result; |
| 1074 | } |
| 1075 | |
| 1076 | static jint doOffsetForAdvance(const Paint* paint, TypefaceImpl* typeface, const jchar buf[], |
| 1077 | jint start, jint count, jint bufSize, jboolean isRtl, jfloat advance) { |
| 1078 | Layout layout; |
| 1079 | int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; |
| 1080 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, buf, start, count, bufSize); |
| 1081 | return getOffsetForAdvance(layout, buf, start, count, advance); |
| 1082 | } |
| 1083 | static jint getOffsetForAdvance___CIIIIZF_I(JNIEnv *env, jclass, jlong paintHandle, |
| 1084 | jlong typefaceHandle, jcharArray text, jint start, jint end, jint contextStart, |
| 1085 | jint contextEnd, jboolean isRtl, jfloat advance) { |
| 1086 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 1087 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle); |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame^] | 1088 | jchar* textArray = (jchar*) env->GetPrimitiveArrayCritical(text, NULL); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1089 | jint result = doOffsetForAdvance(paint, typeface, textArray + contextStart, |
| 1090 | start - contextStart, end - start, contextEnd - contextStart, isRtl, advance); |
| 1091 | result += contextStart; |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame^] | 1092 | env->ReleasePrimitiveArrayCritical(text, textArray, JNI_ABORT); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1093 | return result; |
| 1094 | } |
| 1095 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | }; |
| 1097 | |
| 1098 | static JNINativeMethod methods[] = { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 1099 | {"finalizer", "(J)V", (void*) PaintGlue::finalizer}, |
| 1100 | {"native_init","()J", (void*) PaintGlue::init}, |
| 1101 | {"native_initWithPaint","(J)J", (void*) PaintGlue::initWithPaint}, |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 1102 | |
| 1103 | {"native_reset","!(J)V", (void*) PaintGlue::reset}, |
| 1104 | {"native_set","!(JJ)V", (void*) PaintGlue::assign}, |
| 1105 | {"getFlags","!()I", (void*) PaintGlue::getFlags}, |
| 1106 | {"setFlags","!(I)V", (void*) PaintGlue::setFlags}, |
| 1107 | {"getHinting","!()I", (void*) PaintGlue::getHinting}, |
| 1108 | {"setHinting","!(I)V", (void*) PaintGlue::setHinting}, |
| 1109 | {"setAntiAlias","!(Z)V", (void*) PaintGlue::setAntiAlias}, |
| 1110 | {"setSubpixelText","!(Z)V", (void*) PaintGlue::setSubpixelText}, |
| 1111 | {"setLinearText","!(Z)V", (void*) PaintGlue::setLinearText}, |
| 1112 | {"setUnderlineText","!(Z)V", (void*) PaintGlue::setUnderlineText}, |
| 1113 | {"setStrikeThruText","!(Z)V", (void*) PaintGlue::setStrikeThruText}, |
| 1114 | {"setFakeBoldText","!(Z)V", (void*) PaintGlue::setFakeBoldText}, |
| 1115 | {"setFilterBitmap","!(Z)V", (void*) PaintGlue::setFilterBitmap}, |
| 1116 | {"setDither","!(Z)V", (void*) PaintGlue::setDither}, |
| 1117 | {"native_getStyle","!(J)I", (void*) PaintGlue::getStyle}, |
| 1118 | {"native_setStyle","!(JI)V", (void*) PaintGlue::setStyle}, |
| 1119 | {"getColor","!()I", (void*) PaintGlue::getColor}, |
| 1120 | {"setColor","!(I)V", (void*) PaintGlue::setColor}, |
| 1121 | {"getAlpha","!()I", (void*) PaintGlue::getAlpha}, |
| 1122 | {"setAlpha","!(I)V", (void*) PaintGlue::setAlpha}, |
| 1123 | {"getStrokeWidth","!()F", (void*) PaintGlue::getStrokeWidth}, |
| 1124 | {"setStrokeWidth","!(F)V", (void*) PaintGlue::setStrokeWidth}, |
| 1125 | {"getStrokeMiter","!()F", (void*) PaintGlue::getStrokeMiter}, |
| 1126 | {"setStrokeMiter","!(F)V", (void*) PaintGlue::setStrokeMiter}, |
| 1127 | {"native_getStrokeCap","!(J)I", (void*) PaintGlue::getStrokeCap}, |
| 1128 | {"native_setStrokeCap","!(JI)V", (void*) PaintGlue::setStrokeCap}, |
| 1129 | {"native_getStrokeJoin","!(J)I", (void*) PaintGlue::getStrokeJoin}, |
| 1130 | {"native_setStrokeJoin","!(JI)V", (void*) PaintGlue::setStrokeJoin}, |
| 1131 | {"native_getFillPath","!(JJJ)Z", (void*) PaintGlue::getFillPath}, |
| 1132 | {"native_setShader","!(JJ)J", (void*) PaintGlue::setShader}, |
| 1133 | {"native_setColorFilter","!(JJ)J", (void*) PaintGlue::setColorFilter}, |
| 1134 | {"native_setXfermode","!(JJ)J", (void*) PaintGlue::setXfermode}, |
| 1135 | {"native_setPathEffect","!(JJ)J", (void*) PaintGlue::setPathEffect}, |
| 1136 | {"native_setMaskFilter","!(JJ)J", (void*) PaintGlue::setMaskFilter}, |
| 1137 | {"native_setTypeface","!(JJ)J", (void*) PaintGlue::setTypeface}, |
| 1138 | {"native_setRasterizer","!(JJ)J", (void*) PaintGlue::setRasterizer}, |
| 1139 | {"native_getTextAlign","!(J)I", (void*) PaintGlue::getTextAlign}, |
| 1140 | {"native_setTextAlign","!(JI)V", (void*) PaintGlue::setTextAlign}, |
| 1141 | {"native_setTextLocale","!(JLjava/lang/String;)V", (void*) PaintGlue::setTextLocale}, |
| 1142 | {"isElegantTextHeight","!()Z", (void*) PaintGlue::isElegantTextHeight}, |
| 1143 | {"setElegantTextHeight","!(Z)V", (void*) PaintGlue::setElegantTextHeight}, |
| 1144 | {"getTextSize","!()F", (void*) PaintGlue::getTextSize}, |
| 1145 | {"setTextSize","!(F)V", (void*) PaintGlue::setTextSize}, |
| 1146 | {"getTextScaleX","!()F", (void*) PaintGlue::getTextScaleX}, |
| 1147 | {"setTextScaleX","!(F)V", (void*) PaintGlue::setTextScaleX}, |
| 1148 | {"getTextSkewX","!()F", (void*) PaintGlue::getTextSkewX}, |
| 1149 | {"setTextSkewX","!(F)V", (void*) PaintGlue::setTextSkewX}, |
| 1150 | {"native_getLetterSpacing","!(J)F", (void*) PaintGlue::getLetterSpacing}, |
| 1151 | {"native_setLetterSpacing","!(JF)V", (void*) PaintGlue::setLetterSpacing}, |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1152 | {"native_setFontFeatureSettings","(JLjava/lang/String;)V", |
| 1153 | (void*) PaintGlue::setFontFeatureSettings}, |
Raph Levien | 210a189 | 2015-03-09 14:42:14 -0700 | [diff] [blame] | 1154 | {"native_getHyphenEdit", "!(J)I", (void*) PaintGlue::getHyphenEdit}, |
| 1155 | {"native_setHyphenEdit", "!(JI)V", (void*) PaintGlue::setHyphenEdit}, |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 1156 | {"ascent","!()F", (void*) PaintGlue::ascent}, |
| 1157 | {"descent","!()F", (void*) PaintGlue::descent}, |
| 1158 | |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame^] | 1159 | {"getFontMetrics", "!(Landroid/graphics/Paint$FontMetrics;)F", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1160 | (void*)PaintGlue::getFontMetrics}, |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame^] | 1161 | {"getFontMetricsInt", "!(Landroid/graphics/Paint$FontMetricsInt;)I", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1162 | (void*)PaintGlue::getFontMetricsInt}, |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 1163 | {"native_measureText","([CIII)F", (void*) PaintGlue::measureText_CIII}, |
| 1164 | {"native_measureText","(Ljava/lang/String;I)F", (void*) PaintGlue::measureText_StringI}, |
| 1165 | {"native_measureText","(Ljava/lang/String;III)F", (void*) PaintGlue::measureText_StringIII}, |
| 1166 | {"native_breakText","(JJ[CIIFI[F)I", (void*) PaintGlue::breakTextC}, |
| 1167 | {"native_breakText","(JJLjava/lang/String;ZFI[F)I", (void*) PaintGlue::breakTextS}, |
| 1168 | {"native_getTextWidths","(JJ[CIII[F)I", (void*) PaintGlue::getTextWidths___CIII_F}, |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1169 | {"native_getTextWidths","(JJLjava/lang/String;III[F)I", |
| 1170 | (void*) PaintGlue::getTextWidths__StringIII_F}, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 1171 | {"native_getTextRunAdvances","(JJ[CIIIIZ[FI)F", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1172 | (void*) PaintGlue::getTextRunAdvances___CIIIIZ_FI}, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 1173 | {"native_getTextRunAdvances","(JJLjava/lang/String;IIIIZ[FI)F", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1174 | (void*) PaintGlue::getTextRunAdvances__StringIIIIZ_FI}, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1175 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 1176 | {"native_getTextRunCursor", "(J[CIIIII)I", (void*) PaintGlue::getTextRunCursor___C}, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1177 | {"native_getTextRunCursor", "(JLjava/lang/String;IIIII)I", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1178 | (void*) PaintGlue::getTextRunCursor__String}, |
| 1179 | {"native_getTextPath", "(JJI[CIIFFJ)V", (void*) PaintGlue::getTextPath___C}, |
| 1180 | {"native_getTextPath", "(JJILjava/lang/String;IIFFJ)V", (void*) PaintGlue::getTextPath__String}, |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 1181 | {"nativeGetStringBounds", "(JJLjava/lang/String;IIILandroid/graphics/Rect;)V", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1182 | (void*) PaintGlue::getStringBounds }, |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 1183 | {"nativeGetCharArrayBounds", "(JJ[CIIILandroid/graphics/Rect;)V", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1184 | (void*) PaintGlue::getCharArrayBounds }, |
| 1185 | {"native_hasGlyph", "(JJILjava/lang/String;)Z", (void*) PaintGlue::hasGlyph }, |
| 1186 | {"native_getRunAdvance", "(JJ[CIIIIZI)F", (void*) PaintGlue::getRunAdvance___CIIIIZI_F}, |
| 1187 | {"native_getOffsetForAdvance", "(JJ[CIIIIZF)I", |
| 1188 | (void*) PaintGlue::getOffsetForAdvance___CIIIIZF_I}, |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 1189 | |
| 1190 | {"native_setShadowLayer", "!(JFFFI)V", (void*)PaintGlue::setShadowLayer}, |
| 1191 | {"native_hasShadowLayer", "!(J)Z", (void*)PaintGlue::hasShadowLayer} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | }; |
| 1193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | int register_android_graphics_Paint(JNIEnv* env) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1195 | gFontMetrics_class = FindClassOrDie(env, "android/graphics/Paint$FontMetrics"); |
| 1196 | gFontMetrics_class = MakeGlobalRefOrDie(env, gFontMetrics_class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1198 | gFontMetrics_fieldID.top = GetFieldIDOrDie(env, gFontMetrics_class, "top", "F"); |
| 1199 | gFontMetrics_fieldID.ascent = GetFieldIDOrDie(env, gFontMetrics_class, "ascent", "F"); |
| 1200 | gFontMetrics_fieldID.descent = GetFieldIDOrDie(env, gFontMetrics_class, "descent", "F"); |
| 1201 | gFontMetrics_fieldID.bottom = GetFieldIDOrDie(env, gFontMetrics_class, "bottom", "F"); |
| 1202 | gFontMetrics_fieldID.leading = GetFieldIDOrDie(env, gFontMetrics_class, "leading", "F"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1204 | gFontMetricsInt_class = FindClassOrDie(env, "android/graphics/Paint$FontMetricsInt"); |
| 1205 | gFontMetricsInt_class = MakeGlobalRefOrDie(env, gFontMetricsInt_class); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 1206 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1207 | gFontMetricsInt_fieldID.top = GetFieldIDOrDie(env, gFontMetricsInt_class, "top", "I"); |
| 1208 | gFontMetricsInt_fieldID.ascent = GetFieldIDOrDie(env, gFontMetricsInt_class, "ascent", "I"); |
| 1209 | gFontMetricsInt_fieldID.descent = GetFieldIDOrDie(env, gFontMetricsInt_class, "descent", "I"); |
| 1210 | gFontMetricsInt_fieldID.bottom = GetFieldIDOrDie(env, gFontMetricsInt_class, "bottom", "I"); |
| 1211 | gFontMetricsInt_fieldID.leading = GetFieldIDOrDie(env, gFontMetricsInt_class, "leading", "I"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | |
Andreas Gampe | 158b6c9 | 2014-11-21 14:03:34 -0800 | [diff] [blame] | 1213 | gPaint_class = MakeGlobalRefOrDie(env, FindClassOrDie(env, "android/graphics/Paint")); |
| 1214 | gPaint_nativeInstanceID = GetFieldIDOrDie(env, gPaint_class, "mNativePaint", "J"); |
| 1215 | gPaint_nativeTypefaceID = GetFieldIDOrDie(env, gPaint_class, "mNativeTypeface", "J"); |
| 1216 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1217 | return RegisterMethodsOrDie(env, "android/graphics/Paint", methods, NELEM(methods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | } |