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" |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 36 | #include "TextLayout.h" |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 37 | |
| 38 | // temporary for debugging |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 39 | #include <Caches.h> |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 40 | #include <utils/Log.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
| 42 | namespace android { |
| 43 | |
| 44 | struct JMetricsID { |
| 45 | jfieldID top; |
| 46 | jfieldID ascent; |
| 47 | jfieldID descent; |
| 48 | jfieldID bottom; |
| 49 | jfieldID leading; |
| 50 | }; |
| 51 | |
| 52 | static jclass gFontMetrics_class; |
| 53 | static JMetricsID gFontMetrics_fieldID; |
| 54 | |
| 55 | static jclass gFontMetricsInt_class; |
| 56 | static JMetricsID gFontMetricsInt_fieldID; |
| 57 | |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 58 | static void defaultSettingsForAndroid(SkPaint* paint) { |
Fabrice Di Meglio | c511bee8 | 2012-01-05 13:30:54 -0800 | [diff] [blame] | 59 | // GlyphID encoding is required because we are using Harfbuzz shaping |
| 60 | paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 61 | } |
| 62 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | class SkPaintGlue { |
| 64 | public: |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 65 | enum MoveOpt { |
| 66 | AFTER, AT_OR_AFTER, BEFORE, AT_OR_BEFORE, AT |
| 67 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | |
| 69 | static void finalizer(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 70 | delete obj; |
| 71 | } |
| 72 | |
| 73 | static SkPaint* init(JNIEnv* env, jobject clazz) { |
| 74 | SkPaint* obj = new SkPaint(); |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 75 | defaultSettingsForAndroid(obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | return obj; |
| 77 | } |
| 78 | |
| 79 | static SkPaint* intiWithPaint(JNIEnv* env, jobject clazz, SkPaint* paint) { |
| 80 | SkPaint* obj = new SkPaint(*paint); |
| 81 | return obj; |
| 82 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 83 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | static void reset(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 85 | obj->reset(); |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 86 | defaultSettingsForAndroid(obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | static void assign(JNIEnv* env, jobject clazz, SkPaint* dst, const SkPaint* src) { |
| 90 | *dst = *src; |
| 91 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 92 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | static jint getFlags(JNIEnv* env, jobject paint) { |
| 94 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 95 | return GraphicsJNI::getNativePaint(env, paint)->getFlags(); |
| 96 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 97 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | static void setFlags(JNIEnv* env, jobject paint, jint flags) { |
| 99 | NPE_CHECK_RETURN_VOID(env, paint); |
| 100 | GraphicsJNI::getNativePaint(env, paint)->setFlags(flags); |
| 101 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 102 | |
Dianne Hackborn | f43fa57 | 2011-08-12 18:59:39 -0700 | [diff] [blame] | 103 | static jint getHinting(JNIEnv* env, jobject paint) { |
| 104 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 105 | return GraphicsJNI::getNativePaint(env, paint)->getHinting() |
| 106 | == SkPaint::kNo_Hinting ? 0 : 1; |
| 107 | } |
| 108 | |
| 109 | static void setHinting(JNIEnv* env, jobject paint, jint mode) { |
| 110 | NPE_CHECK_RETURN_VOID(env, paint); |
| 111 | GraphicsJNI::getNativePaint(env, paint)->setHinting( |
| 112 | mode == 0 ? SkPaint::kNo_Hinting : SkPaint::kSlight_Hinting); |
| 113 | } |
| 114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | static void setAntiAlias(JNIEnv* env, jobject paint, jboolean aa) { |
| 116 | NPE_CHECK_RETURN_VOID(env, paint); |
| 117 | GraphicsJNI::getNativePaint(env, paint)->setAntiAlias(aa); |
| 118 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | static void setLinearText(JNIEnv* env, jobject paint, jboolean linearText) { |
| 121 | NPE_CHECK_RETURN_VOID(env, paint); |
| 122 | GraphicsJNI::getNativePaint(env, paint)->setLinearText(linearText); |
| 123 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | static void setSubpixelText(JNIEnv* env, jobject paint, jboolean subpixelText) { |
| 126 | NPE_CHECK_RETURN_VOID(env, paint); |
| 127 | GraphicsJNI::getNativePaint(env, paint)->setSubpixelText(subpixelText); |
| 128 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | static void setUnderlineText(JNIEnv* env, jobject paint, jboolean underlineText) { |
| 131 | NPE_CHECK_RETURN_VOID(env, paint); |
| 132 | GraphicsJNI::getNativePaint(env, paint)->setUnderlineText(underlineText); |
| 133 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | static void setStrikeThruText(JNIEnv* env, jobject paint, jboolean strikeThruText) { |
| 136 | NPE_CHECK_RETURN_VOID(env, paint); |
| 137 | GraphicsJNI::getNativePaint(env, paint)->setStrikeThruText(strikeThruText); |
| 138 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | static void setFakeBoldText(JNIEnv* env, jobject paint, jboolean fakeBoldText) { |
| 141 | NPE_CHECK_RETURN_VOID(env, paint); |
| 142 | GraphicsJNI::getNativePaint(env, paint)->setFakeBoldText(fakeBoldText); |
| 143 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | static void setFilterBitmap(JNIEnv* env, jobject paint, jboolean filterBitmap) { |
| 146 | NPE_CHECK_RETURN_VOID(env, paint); |
| 147 | GraphicsJNI::getNativePaint(env, paint)->setFilterBitmap(filterBitmap); |
| 148 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | static void setDither(JNIEnv* env, jobject paint, jboolean dither) { |
| 151 | NPE_CHECK_RETURN_VOID(env, paint); |
| 152 | GraphicsJNI::getNativePaint(env, paint)->setDither(dither); |
| 153 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | static jint getStyle(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 156 | return obj->getStyle(); |
| 157 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | static void setStyle(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Style style) { |
| 160 | obj->setStyle(style); |
| 161 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static jint getColor(JNIEnv* env, jobject paint) { |
| 164 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 165 | return GraphicsJNI::getNativePaint(env, paint)->getColor(); |
| 166 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | static jint getAlpha(JNIEnv* env, jobject paint) { |
| 169 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 170 | return GraphicsJNI::getNativePaint(env, paint)->getAlpha(); |
| 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 setColor(JNIEnv* env, jobject paint, jint color) { |
| 174 | NPE_CHECK_RETURN_VOID(env, paint); |
| 175 | GraphicsJNI::getNativePaint(env, paint)->setColor(color); |
| 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 setAlpha(JNIEnv* env, jobject paint, jint a) { |
| 179 | NPE_CHECK_RETURN_VOID(env, paint); |
| 180 | GraphicsJNI::getNativePaint(env, paint)->setAlpha(a); |
| 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 jfloat getStrokeWidth(JNIEnv* env, jobject paint) { |
| 184 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 185 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getStrokeWidth()); |
| 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 setStrokeWidth(JNIEnv* env, jobject paint, jfloat width) { |
| 189 | NPE_CHECK_RETURN_VOID(env, paint); |
| 190 | GraphicsJNI::getNativePaint(env, paint)->setStrokeWidth(SkFloatToScalar(width)); |
| 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 jfloat getStrokeMiter(JNIEnv* env, jobject paint) { |
| 194 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 195 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getStrokeMiter()); |
| 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 setStrokeMiter(JNIEnv* env, jobject paint, jfloat miter) { |
| 199 | NPE_CHECK_RETURN_VOID(env, paint); |
| 200 | GraphicsJNI::getNativePaint(env, paint)->setStrokeMiter(SkFloatToScalar(miter)); |
| 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 getStrokeCap(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 204 | return obj->getStrokeCap(); |
| 205 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | static void setStrokeCap(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Cap cap) { |
| 208 | obj->setStrokeCap(cap); |
| 209 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | static jint getStrokeJoin(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 212 | return obj->getStrokeJoin(); |
| 213 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | static void setStrokeJoin(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Join join) { |
| 216 | obj->setStrokeJoin(join); |
| 217 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | static jboolean getFillPath(JNIEnv* env, jobject clazz, SkPaint* obj, SkPath* src, SkPath* dst) { |
| 220 | return obj->getFillPath(*src, dst); |
| 221 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | static SkShader* setShader(JNIEnv* env, jobject clazz, SkPaint* obj, SkShader* shader) { |
| 224 | return obj->setShader(shader); |
| 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 SkColorFilter* setColorFilter(JNIEnv* env, jobject clazz, SkPaint* obj, SkColorFilter* filter) { |
| 228 | return obj->setColorFilter(filter); |
| 229 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | static SkXfermode* setXfermode(JNIEnv* env, jobject clazz, SkPaint* obj, SkXfermode* xfermode) { |
| 232 | return obj->setXfermode(xfermode); |
| 233 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | static SkPathEffect* setPathEffect(JNIEnv* env, jobject clazz, SkPaint* obj, SkPathEffect* effect) { |
| 236 | return obj->setPathEffect(effect); |
| 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 SkMaskFilter* setMaskFilter(JNIEnv* env, jobject clazz, SkPaint* obj, SkMaskFilter* maskfilter) { |
| 240 | return obj->setMaskFilter(maskfilter); |
| 241 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | static SkTypeface* setTypeface(JNIEnv* env, jobject clazz, SkPaint* obj, SkTypeface* typeface) { |
| 244 | return obj->setTypeface(typeface); |
| 245 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | static SkRasterizer* setRasterizer(JNIEnv* env, jobject clazz, SkPaint* obj, SkRasterizer* rasterizer) { |
| 248 | return obj->setRasterizer(rasterizer); |
| 249 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | static jint getTextAlign(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 252 | return obj->getTextAlign(); |
| 253 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | static void setTextAlign(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Align align) { |
| 256 | obj->setTextAlign(align); |
| 257 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 258 | |
Billy Hewlett | ac1cbaf | 2012-07-18 09:51:45 -0700 | [diff] [blame] | 259 | // generate bcp47 identifier for the supplied locale |
| 260 | static void toLanguageTag(char* output, size_t outSize, |
| 261 | const char* locale) { |
| 262 | if (output == NULL || outSize <= 0) { |
| 263 | return; |
| 264 | } |
| 265 | if (locale == NULL) { |
| 266 | output[0] = '\0'; |
| 267 | return; |
| 268 | } |
| 269 | char canonicalChars[ULOC_FULLNAME_CAPACITY]; |
| 270 | UErrorCode uErr = U_ZERO_ERROR; |
| 271 | uloc_canonicalize(locale, canonicalChars, ULOC_FULLNAME_CAPACITY, |
| 272 | &uErr); |
| 273 | if (U_SUCCESS(uErr)) { |
| 274 | char likelyChars[ULOC_FULLNAME_CAPACITY]; |
| 275 | uErr = U_ZERO_ERROR; |
| 276 | uloc_addLikelySubtags(canonicalChars, likelyChars, |
| 277 | ULOC_FULLNAME_CAPACITY, &uErr); |
| 278 | if (U_SUCCESS(uErr)) { |
| 279 | uErr = U_ZERO_ERROR; |
| 280 | uloc_toLanguageTag(likelyChars, output, outSize, FALSE, &uErr); |
| 281 | if (U_SUCCESS(uErr)) { |
| 282 | return; |
| 283 | } else { |
| 284 | ALOGD("uloc_toLanguageTag(\"%s\") failed: %s", likelyChars, |
| 285 | u_errorName(uErr)); |
| 286 | } |
| 287 | } else { |
| 288 | ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s", |
| 289 | canonicalChars, u_errorName(uErr)); |
| 290 | } |
| 291 | } else { |
| 292 | ALOGD("uloc_canonicalize(\"%s\") failed: %s", locale, |
| 293 | u_errorName(uErr)); |
| 294 | } |
| 295 | // unable to build a proper language identifier |
| 296 | output[0] = '\0'; |
| 297 | } |
| 298 | |
Fabrice Di Meglio | 517825f | 2012-04-06 16:53:48 -0700 | [diff] [blame] | 299 | static void setTextLocale(JNIEnv* env, jobject clazz, SkPaint* obj, jstring locale) { |
Billy Hewlett | ac1cbaf | 2012-07-18 09:51:45 -0700 | [diff] [blame] | 300 | ScopedUtfChars localeChars(env, locale); |
| 301 | char langTag[ULOC_FULLNAME_CAPACITY]; |
| 302 | toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, localeChars.c_str()); |
| 303 | obj->setLanguage(SkLanguage(langTag)); |
Fabrice Di Meglio | 517825f | 2012-04-06 16:53:48 -0700 | [diff] [blame] | 304 | } |
| 305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | static jfloat getTextSize(JNIEnv* env, jobject paint) { |
| 307 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 308 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getTextSize()); |
| 309 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | static void setTextSize(JNIEnv* env, jobject paint, jfloat textSize) { |
| 312 | NPE_CHECK_RETURN_VOID(env, paint); |
| 313 | GraphicsJNI::getNativePaint(env, paint)->setTextSize(SkFloatToScalar(textSize)); |
| 314 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | static jfloat getTextScaleX(JNIEnv* env, jobject paint) { |
| 317 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 318 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getTextScaleX()); |
| 319 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | static void setTextScaleX(JNIEnv* env, jobject paint, jfloat scaleX) { |
| 322 | NPE_CHECK_RETURN_VOID(env, paint); |
| 323 | GraphicsJNI::getNativePaint(env, paint)->setTextScaleX(SkFloatToScalar(scaleX)); |
| 324 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | static jfloat getTextSkewX(JNIEnv* env, jobject paint) { |
| 327 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 328 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getTextSkewX()); |
| 329 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | static void setTextSkewX(JNIEnv* env, jobject paint, jfloat skewX) { |
| 332 | NPE_CHECK_RETURN_VOID(env, paint); |
| 333 | GraphicsJNI::getNativePaint(env, paint)->setTextSkewX(SkFloatToScalar(skewX)); |
| 334 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | static jfloat ascent(JNIEnv* env, jobject paint) { |
| 337 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 338 | SkPaint::FontMetrics metrics; |
| 339 | (void)GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics); |
| 340 | return SkScalarToFloat(metrics.fAscent); |
| 341 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | static jfloat descent(JNIEnv* env, jobject paint) { |
| 344 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 345 | SkPaint::FontMetrics metrics; |
| 346 | (void)GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics); |
| 347 | return SkScalarToFloat(metrics.fDescent); |
| 348 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | static jfloat getFontMetrics(JNIEnv* env, jobject paint, jobject metricsObj) { |
| 351 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 352 | SkPaint::FontMetrics metrics; |
| 353 | SkScalar spacing = GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics); |
| 354 | |
| 355 | if (metricsObj) { |
| 356 | SkASSERT(env->IsInstanceOf(metricsObj, gFontMetrics_class)); |
| 357 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.top, SkScalarToFloat(metrics.fTop)); |
| 358 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.ascent, SkScalarToFloat(metrics.fAscent)); |
| 359 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.descent, SkScalarToFloat(metrics.fDescent)); |
| 360 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.bottom, SkScalarToFloat(metrics.fBottom)); |
| 361 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.leading, SkScalarToFloat(metrics.fLeading)); |
| 362 | } |
| 363 | return SkScalarToFloat(spacing); |
| 364 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | static jint getFontMetricsInt(JNIEnv* env, jobject paint, jobject metricsObj) { |
| 367 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 368 | SkPaint::FontMetrics metrics; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics); |
| 371 | int ascent = SkScalarRound(metrics.fAscent); |
| 372 | int descent = SkScalarRound(metrics.fDescent); |
| 373 | int leading = SkScalarRound(metrics.fLeading); |
| 374 | |
| 375 | if (metricsObj) { |
| 376 | SkASSERT(env->IsInstanceOf(metricsObj, gFontMetricsInt_class)); |
| 377 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.top, SkScalarFloor(metrics.fTop)); |
| 378 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.ascent, ascent); |
| 379 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.descent, descent); |
| 380 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.bottom, SkScalarCeil(metrics.fBottom)); |
| 381 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.leading, leading); |
| 382 | } |
| 383 | return descent - ascent + leading; |
| 384 | } |
| 385 | |
| 386 | static jfloat measureText_CII(JNIEnv* env, jobject jpaint, jcharArray text, int index, int count) { |
| 387 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 388 | NPE_CHECK_RETURN_ZERO(env, text); |
| 389 | |
| 390 | size_t textLength = env->GetArrayLength(text); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | if ((index | count) < 0 || (size_t)(index + count) > textLength) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 392 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | return 0; |
| 394 | } |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 395 | if (count == 0) { |
| 396 | return 0; |
| 397 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 399 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 401 | jfloat result = 0; |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 402 | |
Fabrice Di Meglio | 8fb5071 | 2011-05-13 18:51:21 -0700 | [diff] [blame] | 403 | TextLayout::getTextRunAdvances(paint, textArray, index, count, textLength, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 404 | NULL /* dont need all advances */, &result); |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 405 | |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 406 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); |
| 407 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | static jfloat measureText_StringII(JNIEnv* env, jobject jpaint, jstring text, int start, int end) { |
| 411 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 412 | NPE_CHECK_RETURN_ZERO(env, text); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 413 | |
Fabrice Di Meglio | 51f383d | 2011-09-13 15:57:58 -0700 | [diff] [blame] | 414 | size_t textLength = env->GetStringLength(text); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | int count = end - start; |
Fabrice Di Meglio | 51f383d | 2011-09-13 15:57:58 -0700 | [diff] [blame] | 416 | if ((start | count) < 0 || (size_t)end > textLength) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 417 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | return 0; |
| 419 | } |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 420 | if (count == 0) { |
| 421 | return 0; |
| 422 | } |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 423 | |
| 424 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 425 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 426 | jfloat width = 0; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 427 | |
Fabrice Di Meglio | 51f383d | 2011-09-13 15:57:58 -0700 | [diff] [blame] | 428 | TextLayout::getTextRunAdvances(paint, textArray, start, count, textLength, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 429 | NULL /* dont need all advances */, &width); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | env->ReleaseStringChars(text, textArray); |
| 432 | return width; |
| 433 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | static jfloat measureText_String(JNIEnv* env, jobject jpaint, jstring text) { |
| 436 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 437 | NPE_CHECK_RETURN_ZERO(env, text); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | size_t textLength = env->GetStringLength(text); |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 440 | if (textLength == 0) { |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 445 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 446 | jfloat width = 0; |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 447 | |
Fabrice Di Meglio | 8fb5071 | 2011-05-13 18:51:21 -0700 | [diff] [blame] | 448 | TextLayout::getTextRunAdvances(paint, textArray, 0, textLength, textLength, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 449 | NULL /* dont need all advances */, &width); |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | env->ReleaseStringChars(text, textArray); |
| 452 | return width; |
| 453 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | static int dotextwidths(JNIEnv* env, SkPaint* paint, const jchar text[], int count, jfloatArray widths) { |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 456 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 457 | NPE_CHECK_RETURN_ZERO(env, text); |
| 458 | |
| 459 | if (count < 0 || !widths) { |
| 460 | doThrowAIOOBE(env); |
| 461 | return 0; |
| 462 | } |
| 463 | if (count == 0) { |
| 464 | return 0; |
| 465 | } |
| 466 | size_t widthsLength = env->GetArrayLength(widths); |
| 467 | if ((size_t)count > widthsLength) { |
| 468 | doThrowAIOOBE(env); |
| 469 | return 0; |
| 470 | } |
| 471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | AutoJavaFloatArray autoWidths(env, widths, count); |
| 473 | jfloat* widthsArray = autoWidths.ptr(); |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 474 | |
Fabrice Di Meglio | 8fb5071 | 2011-05-13 18:51:21 -0700 | [diff] [blame] | 475 | TextLayout::getTextRunAdvances(paint, text, 0, count, count, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 476 | widthsArray, NULL /* dont need totalAdvance */); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | return count; |
| 479 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | static int getTextWidths___CII_F(JNIEnv* env, jobject clazz, SkPaint* paint, jcharArray text, int index, int count, jfloatArray widths) { |
| 482 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 483 | count = dotextwidths(env, paint, textArray + index, count, widths); |
| 484 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 485 | JNI_ABORT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | return count; |
| 487 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 488 | |
Fabrice Di Meglio | 9f82b58 | 2011-03-08 12:02:59 -0800 | [diff] [blame] | 489 | static int getTextWidths__StringII_F(JNIEnv* env, jobject clazz, SkPaint* paint, jstring text, |
| 490 | int start, int end, jfloatArray widths) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 492 | int count = dotextwidths(env, paint, textArray + start, end - start, widths); |
| 493 | env->ReleaseStringChars(text, textArray); |
| 494 | return count; |
| 495 | } |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 496 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 497 | static jfloat doTextRunAdvances(JNIEnv *env, SkPaint *paint, const jchar *text, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 498 | jint start, jint count, jint contextCount, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 499 | jfloatArray advances, jint advancesIndex) { |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 500 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 501 | NPE_CHECK_RETURN_ZERO(env, text); |
| 502 | |
| 503 | if ((start | count | contextCount | advancesIndex) < 0 || contextCount < count) { |
| 504 | doThrowAIOOBE(env); |
| 505 | return 0; |
| 506 | } |
| 507 | if (count == 0) { |
| 508 | return 0; |
| 509 | } |
| 510 | if (advances) { |
| 511 | size_t advancesLength = env->GetArrayLength(advances); |
| 512 | if ((size_t)count > advancesLength) { |
| 513 | doThrowAIOOBE(env); |
| 514 | return 0; |
| 515 | } |
| 516 | } |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 517 | jfloat advancesArray[count]; |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 518 | jfloat totalAdvance = 0; |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 519 | |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 520 | TextLayout::getTextRunAdvances(paint, text, start, count, contextCount, |
Fabrice Di Meglio | 79df532 | 2011-09-19 15:17:56 -0700 | [diff] [blame] | 521 | advancesArray, &totalAdvance); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 522 | |
| 523 | if (advances != NULL) { |
| 524 | env->SetFloatArrayRegion(advances, advancesIndex, count, advancesArray); |
| 525 | } |
| 526 | return totalAdvance; |
| 527 | } |
| 528 | |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 529 | static float getTextRunAdvances___CIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 530 | jcharArray text, jint index, jint count, jint contextIndex, jint contextCount, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 531 | jfloatArray advances, jint advancesIndex) { |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 532 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 533 | jfloat result = doTextRunAdvances(env, paint, textArray + contextIndex, |
| 534 | index - contextIndex, count, contextCount, advances, advancesIndex); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 535 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 536 | return result; |
| 537 | } |
| 538 | |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 539 | static float getTextRunAdvances__StringIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint, |
| 540 | jstring text, jint start, jint end, jint contextStart, jint contextEnd, |
| 541 | jfloatArray advances, jint advancesIndex) { |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 542 | const jchar* textArray = env->GetStringChars(text, NULL); |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 543 | jfloat result = doTextRunAdvances(env, paint, textArray + contextStart, |
| 544 | start - contextStart, end - start, contextEnd - contextStart, |
| 545 | advances, advancesIndex); |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 546 | env->ReleaseStringChars(text, textArray); |
| 547 | return result; |
| 548 | } |
| 549 | |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 550 | 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] | 551 | jint count, jint flags, jint offset, jint opt) { |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 552 | jfloat scalarArray[count]; |
Fabrice Di Meglio | 9c418db | 2011-09-18 12:54:38 -0700 | [diff] [blame] | 553 | |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 554 | TextLayout::getTextRunAdvances(paint, text, start, count, start + count, |
Fabrice Di Meglio | 79df532 | 2011-09-19 15:17:56 -0700 | [diff] [blame] | 555 | scalarArray, NULL /* dont need totalAdvance */); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 556 | |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 557 | jint pos = offset - start; |
| 558 | switch (opt) { |
| 559 | case AFTER: |
| 560 | if (pos < count) { |
| 561 | pos += 1; |
| 562 | } |
| 563 | // fall through |
| 564 | case AT_OR_AFTER: |
| 565 | while (pos < count && scalarArray[pos] == 0) { |
| 566 | ++pos; |
| 567 | } |
| 568 | break; |
| 569 | case BEFORE: |
| 570 | if (pos > 0) { |
| 571 | --pos; |
| 572 | } |
| 573 | // fall through |
| 574 | case AT_OR_BEFORE: |
| 575 | while (pos > 0 && scalarArray[pos] == 0) { |
| 576 | --pos; |
| 577 | } |
| 578 | break; |
| 579 | case AT: |
| 580 | default: |
| 581 | if (scalarArray[pos] == 0) { |
| 582 | pos = -1; |
| 583 | } |
| 584 | break; |
| 585 | } |
| 586 | |
| 587 | if (pos != -1) { |
| 588 | pos += start; |
| 589 | } |
| 590 | |
| 591 | return pos; |
| 592 | } |
| 593 | |
| 594 | static jint getTextRunCursor___C(JNIEnv* env, jobject clazz, SkPaint* paint, jcharArray text, |
Fabrice Di Meglio | a4bf811 | 2013-03-15 11:22:29 -0700 | [diff] [blame] | 595 | jint contextStart, jint contextCount, jint flags, jint offset, jint cursorOpt) { |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 596 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | a4bf811 | 2013-03-15 11:22:29 -0700 | [diff] [blame] | 597 | jint result = doTextRunCursor(env, paint, textArray, contextStart, contextCount, flags, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 598 | offset, cursorOpt); |
| 599 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 600 | return result; |
| 601 | } |
| 602 | |
| 603 | static jint getTextRunCursor__String(JNIEnv* env, jobject clazz, SkPaint* paint, jstring text, |
Fabrice Di Meglio | a4bf811 | 2013-03-15 11:22:29 -0700 | [diff] [blame] | 604 | jint contextStart, jint contextEnd, jint flags, jint offset, jint cursorOpt) { |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 605 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 606 | jint result = doTextRunCursor(env, paint, textArray, contextStart, |
Fabrice Di Meglio | a4bf811 | 2013-03-15 11:22:29 -0700 | [diff] [blame] | 607 | contextEnd - contextStart, flags, offset, cursorOpt); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 608 | env->ReleaseStringChars(text, textArray); |
| 609 | return result; |
| 610 | } |
| 611 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 612 | static void getTextPath(JNIEnv* env, SkPaint* paint, const jchar* text, jint count, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 613 | jfloat x, jfloat y, SkPath *path) { |
| 614 | TextLayout::getTextPath(paint, text, count, x, y, path); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 616 | |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 617 | static void getTextPath___C(JNIEnv* env, jobject clazz, SkPaint* paint, |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 618 | jcharArray text, int index, int count, jfloat x, jfloat y, SkPath* path) { |
| 619 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 620 | getTextPath(env, paint, textArray + index, count, x, y, path); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 621 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); |
| 622 | } |
| 623 | |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 624 | static void getTextPath__String(JNIEnv* env, jobject clazz, SkPaint* paint, |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 625 | jstring text, int start, int end, jfloat x, jfloat y, SkPath* path) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | const jchar* textArray = env->GetStringChars(text, NULL); |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 627 | getTextPath(env, paint, textArray + start, end - start, x, y, path); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | env->ReleaseStringChars(text, textArray); |
| 629 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | static void setShadowLayer(JNIEnv* env, jobject jpaint, jfloat radius, |
| 632 | jfloat dx, jfloat dy, int color) { |
| 633 | NPE_CHECK_RETURN_VOID(env, jpaint); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 634 | |
| 635 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | if (radius <= 0) { |
| 637 | paint->setLooper(NULL); |
| 638 | } |
| 639 | else { |
| 640 | paint->setLooper(new SkBlurDrawLooper(SkFloatToScalar(radius), |
| 641 | SkFloatToScalar(dx), |
| 642 | SkFloatToScalar(dy), |
| 643 | (SkColor)color))->unref(); |
| 644 | } |
| 645 | } |
| 646 | |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 647 | static int breakText(JNIEnv* env, SkPaint& paint, const jchar text[], |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 648 | int count, float maxWidth, jfloatArray jmeasured, |
| 649 | SkPaint::TextBufferDirection tbd) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 650 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(&paint, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 651 | text, 0, count, count); |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 652 | if (value == NULL) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 653 | return 0; |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 654 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 655 | SkScalar measured; |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 656 | size_t bytes = paint.breakText(value->getGlyphs(), value->getGlyphsCount() << 1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | SkFloatToScalar(maxWidth), &measured, tbd); |
| 658 | SkASSERT((bytes & 1) == 0); |
| 659 | |
| 660 | if (jmeasured && env->GetArrayLength(jmeasured) > 0) { |
| 661 | AutoJavaFloatArray autoMeasured(env, jmeasured, 1); |
| 662 | jfloat* array = autoMeasured.ptr(); |
| 663 | array[0] = SkScalarToFloat(measured); |
| 664 | } |
| 665 | return bytes >> 1; |
| 666 | } |
| 667 | |
| 668 | static int breakTextC(JNIEnv* env, jobject jpaint, jcharArray jtext, |
| 669 | int index, int count, float maxWidth, jfloatArray jmeasuredWidth) { |
| 670 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 671 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 672 | |
| 673 | SkPaint::TextBufferDirection tbd; |
| 674 | if (count < 0) { |
| 675 | tbd = SkPaint::kBackward_TextBufferDirection; |
| 676 | count = -count; |
| 677 | } |
| 678 | else { |
| 679 | tbd = SkPaint::kForward_TextBufferDirection; |
| 680 | } |
| 681 | |
| 682 | if ((index < 0) || (index + count > env->GetArrayLength(jtext))) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 683 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 688 | const jchar* text = env->GetCharArrayElements(jtext, NULL); |
| 689 | count = breakText(env, *paint, text + index, count, maxWidth, |
| 690 | jmeasuredWidth, tbd); |
| 691 | env->ReleaseCharArrayElements(jtext, const_cast<jchar*>(text), |
| 692 | JNI_ABORT); |
| 693 | return count; |
| 694 | } |
| 695 | |
| 696 | static int breakTextS(JNIEnv* env, jobject jpaint, jstring jtext, |
| 697 | bool forwards, float maxWidth, jfloatArray jmeasuredWidth) { |
| 698 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 699 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 700 | |
| 701 | SkPaint::TextBufferDirection tbd = forwards ? |
| 702 | SkPaint::kForward_TextBufferDirection : |
| 703 | SkPaint::kBackward_TextBufferDirection; |
| 704 | |
| 705 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 706 | int count = env->GetStringLength(jtext); |
| 707 | const jchar* text = env->GetStringChars(jtext, NULL); |
| 708 | count = breakText(env, *paint, text, count, maxWidth, |
| 709 | jmeasuredWidth, tbd); |
| 710 | env->ReleaseStringChars(jtext, text); |
| 711 | return count; |
| 712 | } |
| 713 | |
| 714 | static void doTextBounds(JNIEnv* env, const jchar* text, int count, |
| 715 | jobject bounds, const SkPaint& paint) |
| 716 | { |
Romain Guy | 059e12c | 2012-11-28 17:35:51 -0800 | [diff] [blame] | 717 | SkRect r; |
| 718 | r.set(0,0,0,0); |
| 719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | SkIRect ir; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 721 | |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 722 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(&paint, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 723 | text, 0, count, count); |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 724 | if (value == NULL) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 725 | return; |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 726 | } |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 727 | paint.measureText(value->getGlyphs(), value->getGlyphsCount() << 1, &r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | r.roundOut(&ir); |
| 729 | GraphicsJNI::irect_to_jrect(ir, env, bounds); |
| 730 | } |
| 731 | |
| 732 | static void getStringBounds(JNIEnv* env, jobject, const SkPaint* paint, |
| 733 | jstring text, int start, int end, jobject bounds) |
| 734 | { |
| 735 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 736 | doTextBounds(env, textArray + start, end - start, bounds, *paint); |
| 737 | env->ReleaseStringChars(text, textArray); |
| 738 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 739 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | static void getCharArrayBounds(JNIEnv* env, jobject, const SkPaint* paint, |
| 741 | jcharArray text, int index, int count, jobject bounds) |
| 742 | { |
| 743 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 744 | doTextBounds(env, textArray + index, count, bounds, *paint); |
| 745 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
| 746 | JNI_ABORT); |
| 747 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | }; |
| 750 | |
| 751 | static JNINativeMethod methods[] = { |
| 752 | {"finalizer", "(I)V", (void*) SkPaintGlue::finalizer}, |
| 753 | {"native_init","()I", (void*) SkPaintGlue::init}, |
| 754 | {"native_initWithPaint","(I)I", (void*) SkPaintGlue::intiWithPaint}, |
| 755 | {"native_reset","(I)V", (void*) SkPaintGlue::reset}, |
| 756 | {"native_set","(II)V", (void*) SkPaintGlue::assign}, |
| 757 | {"getFlags","()I", (void*) SkPaintGlue::getFlags}, |
| 758 | {"setFlags","(I)V", (void*) SkPaintGlue::setFlags}, |
Dianne Hackborn | f43fa57 | 2011-08-12 18:59:39 -0700 | [diff] [blame] | 759 | {"getHinting","()I", (void*) SkPaintGlue::getHinting}, |
| 760 | {"setHinting","(I)V", (void*) SkPaintGlue::setHinting}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | {"setAntiAlias","(Z)V", (void*) SkPaintGlue::setAntiAlias}, |
| 762 | {"setSubpixelText","(Z)V", (void*) SkPaintGlue::setSubpixelText}, |
| 763 | {"setLinearText","(Z)V", (void*) SkPaintGlue::setLinearText}, |
| 764 | {"setUnderlineText","(Z)V", (void*) SkPaintGlue::setUnderlineText}, |
| 765 | {"setStrikeThruText","(Z)V", (void*) SkPaintGlue::setStrikeThruText}, |
| 766 | {"setFakeBoldText","(Z)V", (void*) SkPaintGlue::setFakeBoldText}, |
| 767 | {"setFilterBitmap","(Z)V", (void*) SkPaintGlue::setFilterBitmap}, |
| 768 | {"setDither","(Z)V", (void*) SkPaintGlue::setDither}, |
| 769 | {"native_getStyle","(I)I", (void*) SkPaintGlue::getStyle}, |
| 770 | {"native_setStyle","(II)V", (void*) SkPaintGlue::setStyle}, |
| 771 | {"getColor","()I", (void*) SkPaintGlue::getColor}, |
| 772 | {"setColor","(I)V", (void*) SkPaintGlue::setColor}, |
| 773 | {"getAlpha","()I", (void*) SkPaintGlue::getAlpha}, |
| 774 | {"setAlpha","(I)V", (void*) SkPaintGlue::setAlpha}, |
| 775 | {"getStrokeWidth","()F", (void*) SkPaintGlue::getStrokeWidth}, |
| 776 | {"setStrokeWidth","(F)V", (void*) SkPaintGlue::setStrokeWidth}, |
| 777 | {"getStrokeMiter","()F", (void*) SkPaintGlue::getStrokeMiter}, |
| 778 | {"setStrokeMiter","(F)V", (void*) SkPaintGlue::setStrokeMiter}, |
| 779 | {"native_getStrokeCap","(I)I", (void*) SkPaintGlue::getStrokeCap}, |
| 780 | {"native_setStrokeCap","(II)V", (void*) SkPaintGlue::setStrokeCap}, |
| 781 | {"native_getStrokeJoin","(I)I", (void*) SkPaintGlue::getStrokeJoin}, |
| 782 | {"native_setStrokeJoin","(II)V", (void*) SkPaintGlue::setStrokeJoin}, |
| 783 | {"native_getFillPath","(III)Z", (void*) SkPaintGlue::getFillPath}, |
| 784 | {"native_setShader","(II)I", (void*) SkPaintGlue::setShader}, |
| 785 | {"native_setColorFilter","(II)I", (void*) SkPaintGlue::setColorFilter}, |
| 786 | {"native_setXfermode","(II)I", (void*) SkPaintGlue::setXfermode}, |
| 787 | {"native_setPathEffect","(II)I", (void*) SkPaintGlue::setPathEffect}, |
| 788 | {"native_setMaskFilter","(II)I", (void*) SkPaintGlue::setMaskFilter}, |
| 789 | {"native_setTypeface","(II)I", (void*) SkPaintGlue::setTypeface}, |
| 790 | {"native_setRasterizer","(II)I", (void*) SkPaintGlue::setRasterizer}, |
| 791 | {"native_getTextAlign","(I)I", (void*) SkPaintGlue::getTextAlign}, |
| 792 | {"native_setTextAlign","(II)V", (void*) SkPaintGlue::setTextAlign}, |
Fabrice Di Meglio | 517825f | 2012-04-06 16:53:48 -0700 | [diff] [blame] | 793 | {"native_setTextLocale","(ILjava/lang/String;)V", (void*) SkPaintGlue::setTextLocale}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | {"getTextSize","()F", (void*) SkPaintGlue::getTextSize}, |
| 795 | {"setTextSize","(F)V", (void*) SkPaintGlue::setTextSize}, |
| 796 | {"getTextScaleX","()F", (void*) SkPaintGlue::getTextScaleX}, |
| 797 | {"setTextScaleX","(F)V", (void*) SkPaintGlue::setTextScaleX}, |
| 798 | {"getTextSkewX","()F", (void*) SkPaintGlue::getTextSkewX}, |
| 799 | {"setTextSkewX","(F)V", (void*) SkPaintGlue::setTextSkewX}, |
| 800 | {"ascent","()F", (void*) SkPaintGlue::ascent}, |
| 801 | {"descent","()F", (void*) SkPaintGlue::descent}, |
| 802 | {"getFontMetrics", "(Landroid/graphics/Paint$FontMetrics;)F", (void*)SkPaintGlue::getFontMetrics}, |
| 803 | {"getFontMetricsInt", "(Landroid/graphics/Paint$FontMetricsInt;)I", (void*)SkPaintGlue::getFontMetricsInt}, |
Dianne Hackborn | afa7896 | 2009-09-28 17:33:54 -0700 | [diff] [blame] | 804 | {"native_measureText","([CII)F", (void*) SkPaintGlue::measureText_CII}, |
| 805 | {"native_measureText","(Ljava/lang/String;)F", (void*) SkPaintGlue::measureText_String}, |
| 806 | {"native_measureText","(Ljava/lang/String;II)F", (void*) SkPaintGlue::measureText_StringII}, |
| 807 | {"native_breakText","([CIIF[F)I", (void*) SkPaintGlue::breakTextC}, |
| 808 | {"native_breakText","(Ljava/lang/String;ZF[F)I", (void*) SkPaintGlue::breakTextS}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | {"native_getTextWidths","(I[CII[F)I", (void*) SkPaintGlue::getTextWidths___CII_F}, |
| 810 | {"native_getTextWidths","(ILjava/lang/String;II[F)I", (void*) SkPaintGlue::getTextWidths__StringII_F}, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 811 | {"native_getTextRunAdvances","(I[CIIII[FI)F", |
| 812 | (void*) SkPaintGlue::getTextRunAdvances___CIIII_FI}, |
| 813 | {"native_getTextRunAdvances","(ILjava/lang/String;IIII[FI)F", |
| 814 | (void*) SkPaintGlue::getTextRunAdvances__StringIIII_FI}, |
| 815 | {"native_getTextRunCursor", "(I[CIIII)I", (void*) SkPaintGlue::getTextRunCursor___C}, |
| 816 | {"native_getTextRunCursor", "(ILjava/lang/String;IIII)I", |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 817 | (void*) SkPaintGlue::getTextRunCursor__String}, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame] | 818 | {"native_getTextPath","(I[CIIFFI)V", (void*) SkPaintGlue::getTextPath___C}, |
| 819 | {"native_getTextPath","(ILjava/lang/String;IIFFI)V", (void*) SkPaintGlue::getTextPath__String}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | {"nativeGetStringBounds", "(ILjava/lang/String;IILandroid/graphics/Rect;)V", |
| 821 | (void*) SkPaintGlue::getStringBounds }, |
| 822 | {"nativeGetCharArrayBounds", "(I[CIILandroid/graphics/Rect;)V", |
| 823 | (void*) SkPaintGlue::getCharArrayBounds }, |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 824 | {"nSetShadowLayer", "(FFFI)V", (void*)SkPaintGlue::setShadowLayer} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | }; |
| 826 | |
| 827 | static jfieldID req_fieldID(jfieldID id) { |
| 828 | SkASSERT(id); |
| 829 | return id; |
| 830 | } |
| 831 | |
| 832 | int register_android_graphics_Paint(JNIEnv* env) { |
| 833 | gFontMetrics_class = env->FindClass("android/graphics/Paint$FontMetrics"); |
| 834 | SkASSERT(gFontMetrics_class); |
| 835 | gFontMetrics_class = (jclass)env->NewGlobalRef(gFontMetrics_class); |
| 836 | |
| 837 | gFontMetrics_fieldID.top = req_fieldID(env->GetFieldID(gFontMetrics_class, "top", "F")); |
| 838 | gFontMetrics_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetrics_class, "ascent", "F")); |
| 839 | gFontMetrics_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetrics_class, "descent", "F")); |
| 840 | gFontMetrics_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetrics_class, "bottom", "F")); |
| 841 | gFontMetrics_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetrics_class, "leading", "F")); |
| 842 | |
| 843 | gFontMetricsInt_class = env->FindClass("android/graphics/Paint$FontMetricsInt"); |
| 844 | SkASSERT(gFontMetricsInt_class); |
| 845 | gFontMetricsInt_class = (jclass)env->NewGlobalRef(gFontMetricsInt_class); |
| 846 | |
| 847 | gFontMetricsInt_fieldID.top = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "top", "I")); |
| 848 | gFontMetricsInt_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "ascent", "I")); |
| 849 | gFontMetricsInt_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "descent", "I")); |
| 850 | gFontMetricsInt_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "bottom", "I")); |
| 851 | gFontMetricsInt_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "leading", "I")); |
| 852 | |
| 853 | int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Paint", methods, |
| 854 | sizeof(methods) / sizeof(methods[0])); |
| 855 | return result; |
| 856 | } |
| 857 | |
| 858 | } |