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