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