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 | ** |
| 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 |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 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 |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | // This file was generated from the C++ include file: SkPaint.h |
| 19 | // Any changes made to this file will be discarded by the build. |
| 20 | // To change this file, either edit the include, or device/tools/gluemaker/main.cpp, |
| 21 | // or one of the auxilary file specifications in device/tools/gluemaker. |
| 22 | |
| 23 | #include "jni.h" |
| 24 | #include "GraphicsJNI.h" |
| 25 | #include <android_runtime/AndroidRuntime.h> |
| 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" |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 34 | #include "unicode/ushape.h" |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 35 | #include "TextLayout.h" |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 36 | |
| 37 | // temporary for debugging |
| 38 | #include <utils/Log.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
| 40 | namespace android { |
| 41 | |
| 42 | struct JMetricsID { |
| 43 | jfieldID top; |
| 44 | jfieldID ascent; |
| 45 | jfieldID descent; |
| 46 | jfieldID bottom; |
| 47 | jfieldID leading; |
| 48 | }; |
| 49 | |
| 50 | static jclass gFontMetrics_class; |
| 51 | static JMetricsID gFontMetrics_fieldID; |
| 52 | |
| 53 | static jclass gFontMetricsInt_class; |
| 54 | static JMetricsID gFontMetricsInt_fieldID; |
| 55 | |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 56 | static void defaultSettingsForAndroid(SkPaint* paint) { |
| 57 | // looks best we decided |
| 58 | paint->setHinting(SkPaint::kSlight_Hinting); |
| 59 | // utf16 is required for java |
| 60 | paint->setTextEncoding(SkPaint::kUTF16_TextEncoding); |
| 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 | } |
| 83 | |
| 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 | } |
| 88 | |
| 89 | static void assign(JNIEnv* env, jobject clazz, SkPaint* dst, const SkPaint* src) { |
| 90 | *dst = *src; |
| 91 | } |
| 92 | |
| 93 | static jint getFlags(JNIEnv* env, jobject paint) { |
| 94 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 95 | return GraphicsJNI::getNativePaint(env, paint)->getFlags(); |
| 96 | } |
| 97 | |
| 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 | } |
| 102 | |
| 103 | static void setAntiAlias(JNIEnv* env, jobject paint, jboolean aa) { |
| 104 | NPE_CHECK_RETURN_VOID(env, paint); |
| 105 | GraphicsJNI::getNativePaint(env, paint)->setAntiAlias(aa); |
| 106 | } |
| 107 | |
| 108 | static void setLinearText(JNIEnv* env, jobject paint, jboolean linearText) { |
| 109 | NPE_CHECK_RETURN_VOID(env, paint); |
| 110 | GraphicsJNI::getNativePaint(env, paint)->setLinearText(linearText); |
| 111 | } |
| 112 | |
| 113 | static void setSubpixelText(JNIEnv* env, jobject paint, jboolean subpixelText) { |
| 114 | NPE_CHECK_RETURN_VOID(env, paint); |
| 115 | GraphicsJNI::getNativePaint(env, paint)->setSubpixelText(subpixelText); |
| 116 | } |
| 117 | |
| 118 | static void setUnderlineText(JNIEnv* env, jobject paint, jboolean underlineText) { |
| 119 | NPE_CHECK_RETURN_VOID(env, paint); |
| 120 | GraphicsJNI::getNativePaint(env, paint)->setUnderlineText(underlineText); |
| 121 | } |
| 122 | |
| 123 | static void setStrikeThruText(JNIEnv* env, jobject paint, jboolean strikeThruText) { |
| 124 | NPE_CHECK_RETURN_VOID(env, paint); |
| 125 | GraphicsJNI::getNativePaint(env, paint)->setStrikeThruText(strikeThruText); |
| 126 | } |
| 127 | |
| 128 | static void setFakeBoldText(JNIEnv* env, jobject paint, jboolean fakeBoldText) { |
| 129 | NPE_CHECK_RETURN_VOID(env, paint); |
| 130 | GraphicsJNI::getNativePaint(env, paint)->setFakeBoldText(fakeBoldText); |
| 131 | } |
| 132 | |
| 133 | static void setFilterBitmap(JNIEnv* env, jobject paint, jboolean filterBitmap) { |
| 134 | NPE_CHECK_RETURN_VOID(env, paint); |
| 135 | GraphicsJNI::getNativePaint(env, paint)->setFilterBitmap(filterBitmap); |
| 136 | } |
| 137 | |
| 138 | static void setDither(JNIEnv* env, jobject paint, jboolean dither) { |
| 139 | NPE_CHECK_RETURN_VOID(env, paint); |
| 140 | GraphicsJNI::getNativePaint(env, paint)->setDither(dither); |
| 141 | } |
| 142 | |
| 143 | static jint getStyle(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 144 | return obj->getStyle(); |
| 145 | } |
| 146 | |
| 147 | static void setStyle(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Style style) { |
| 148 | obj->setStyle(style); |
| 149 | } |
| 150 | |
| 151 | static jint getColor(JNIEnv* env, jobject paint) { |
| 152 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 153 | return GraphicsJNI::getNativePaint(env, paint)->getColor(); |
| 154 | } |
| 155 | |
| 156 | static jint getAlpha(JNIEnv* env, jobject paint) { |
| 157 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 158 | return GraphicsJNI::getNativePaint(env, paint)->getAlpha(); |
| 159 | } |
| 160 | |
| 161 | static void setColor(JNIEnv* env, jobject paint, jint color) { |
| 162 | NPE_CHECK_RETURN_VOID(env, paint); |
| 163 | GraphicsJNI::getNativePaint(env, paint)->setColor(color); |
| 164 | } |
| 165 | |
| 166 | static void setAlpha(JNIEnv* env, jobject paint, jint a) { |
| 167 | NPE_CHECK_RETURN_VOID(env, paint); |
| 168 | GraphicsJNI::getNativePaint(env, paint)->setAlpha(a); |
| 169 | } |
| 170 | |
| 171 | static jfloat getStrokeWidth(JNIEnv* env, jobject paint) { |
| 172 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 173 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getStrokeWidth()); |
| 174 | } |
| 175 | |
| 176 | static void setStrokeWidth(JNIEnv* env, jobject paint, jfloat width) { |
| 177 | NPE_CHECK_RETURN_VOID(env, paint); |
| 178 | GraphicsJNI::getNativePaint(env, paint)->setStrokeWidth(SkFloatToScalar(width)); |
| 179 | } |
| 180 | |
| 181 | static jfloat getStrokeMiter(JNIEnv* env, jobject paint) { |
| 182 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 183 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getStrokeMiter()); |
| 184 | } |
| 185 | |
| 186 | static void setStrokeMiter(JNIEnv* env, jobject paint, jfloat miter) { |
| 187 | NPE_CHECK_RETURN_VOID(env, paint); |
| 188 | GraphicsJNI::getNativePaint(env, paint)->setStrokeMiter(SkFloatToScalar(miter)); |
| 189 | } |
| 190 | |
| 191 | static jint getStrokeCap(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 192 | return obj->getStrokeCap(); |
| 193 | } |
| 194 | |
| 195 | static void setStrokeCap(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Cap cap) { |
| 196 | obj->setStrokeCap(cap); |
| 197 | } |
| 198 | |
| 199 | static jint getStrokeJoin(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 200 | return obj->getStrokeJoin(); |
| 201 | } |
| 202 | |
| 203 | static void setStrokeJoin(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Join join) { |
| 204 | obj->setStrokeJoin(join); |
| 205 | } |
| 206 | |
| 207 | static jboolean getFillPath(JNIEnv* env, jobject clazz, SkPaint* obj, SkPath* src, SkPath* dst) { |
| 208 | return obj->getFillPath(*src, dst); |
| 209 | } |
| 210 | |
| 211 | static SkShader* setShader(JNIEnv* env, jobject clazz, SkPaint* obj, SkShader* shader) { |
| 212 | return obj->setShader(shader); |
| 213 | } |
| 214 | |
| 215 | static SkColorFilter* setColorFilter(JNIEnv* env, jobject clazz, SkPaint* obj, SkColorFilter* filter) { |
| 216 | return obj->setColorFilter(filter); |
| 217 | } |
| 218 | |
| 219 | static SkXfermode* setXfermode(JNIEnv* env, jobject clazz, SkPaint* obj, SkXfermode* xfermode) { |
| 220 | return obj->setXfermode(xfermode); |
| 221 | } |
| 222 | |
| 223 | static SkPathEffect* setPathEffect(JNIEnv* env, jobject clazz, SkPaint* obj, SkPathEffect* effect) { |
| 224 | return obj->setPathEffect(effect); |
| 225 | } |
| 226 | |
| 227 | static SkMaskFilter* setMaskFilter(JNIEnv* env, jobject clazz, SkPaint* obj, SkMaskFilter* maskfilter) { |
| 228 | return obj->setMaskFilter(maskfilter); |
| 229 | } |
| 230 | |
| 231 | static SkTypeface* setTypeface(JNIEnv* env, jobject clazz, SkPaint* obj, SkTypeface* typeface) { |
| 232 | return obj->setTypeface(typeface); |
| 233 | } |
| 234 | |
| 235 | static SkRasterizer* setRasterizer(JNIEnv* env, jobject clazz, SkPaint* obj, SkRasterizer* rasterizer) { |
| 236 | return obj->setRasterizer(rasterizer); |
| 237 | } |
| 238 | |
| 239 | static jint getTextAlign(JNIEnv* env, jobject clazz, SkPaint* obj) { |
| 240 | return obj->getTextAlign(); |
| 241 | } |
| 242 | |
| 243 | static void setTextAlign(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Align align) { |
| 244 | obj->setTextAlign(align); |
| 245 | } |
| 246 | |
| 247 | static jfloat getTextSize(JNIEnv* env, jobject paint) { |
| 248 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 249 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getTextSize()); |
| 250 | } |
| 251 | |
| 252 | static void setTextSize(JNIEnv* env, jobject paint, jfloat textSize) { |
| 253 | NPE_CHECK_RETURN_VOID(env, paint); |
| 254 | GraphicsJNI::getNativePaint(env, paint)->setTextSize(SkFloatToScalar(textSize)); |
| 255 | } |
| 256 | |
| 257 | static jfloat getTextScaleX(JNIEnv* env, jobject paint) { |
| 258 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 259 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getTextScaleX()); |
| 260 | } |
| 261 | |
| 262 | static void setTextScaleX(JNIEnv* env, jobject paint, jfloat scaleX) { |
| 263 | NPE_CHECK_RETURN_VOID(env, paint); |
| 264 | GraphicsJNI::getNativePaint(env, paint)->setTextScaleX(SkFloatToScalar(scaleX)); |
| 265 | } |
| 266 | |
| 267 | static jfloat getTextSkewX(JNIEnv* env, jobject paint) { |
| 268 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 269 | return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getTextSkewX()); |
| 270 | } |
| 271 | |
| 272 | static void setTextSkewX(JNIEnv* env, jobject paint, jfloat skewX) { |
| 273 | NPE_CHECK_RETURN_VOID(env, paint); |
| 274 | GraphicsJNI::getNativePaint(env, paint)->setTextSkewX(SkFloatToScalar(skewX)); |
| 275 | } |
| 276 | |
| 277 | static jfloat ascent(JNIEnv* env, jobject paint) { |
| 278 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 279 | SkPaint::FontMetrics metrics; |
| 280 | (void)GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics); |
| 281 | return SkScalarToFloat(metrics.fAscent); |
| 282 | } |
| 283 | |
| 284 | static jfloat descent(JNIEnv* env, jobject paint) { |
| 285 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 286 | SkPaint::FontMetrics metrics; |
| 287 | (void)GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics); |
| 288 | return SkScalarToFloat(metrics.fDescent); |
| 289 | } |
| 290 | |
| 291 | static jfloat getFontMetrics(JNIEnv* env, jobject paint, jobject metricsObj) { |
| 292 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 293 | SkPaint::FontMetrics metrics; |
| 294 | SkScalar spacing = GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics); |
| 295 | |
| 296 | if (metricsObj) { |
| 297 | SkASSERT(env->IsInstanceOf(metricsObj, gFontMetrics_class)); |
| 298 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.top, SkScalarToFloat(metrics.fTop)); |
| 299 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.ascent, SkScalarToFloat(metrics.fAscent)); |
| 300 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.descent, SkScalarToFloat(metrics.fDescent)); |
| 301 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.bottom, SkScalarToFloat(metrics.fBottom)); |
| 302 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.leading, SkScalarToFloat(metrics.fLeading)); |
| 303 | } |
| 304 | return SkScalarToFloat(spacing); |
| 305 | } |
| 306 | |
| 307 | static jint getFontMetricsInt(JNIEnv* env, jobject paint, jobject metricsObj) { |
| 308 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 309 | SkPaint::FontMetrics metrics; |
| 310 | |
| 311 | GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics); |
| 312 | int ascent = SkScalarRound(metrics.fAscent); |
| 313 | int descent = SkScalarRound(metrics.fDescent); |
| 314 | int leading = SkScalarRound(metrics.fLeading); |
| 315 | |
| 316 | if (metricsObj) { |
| 317 | SkASSERT(env->IsInstanceOf(metricsObj, gFontMetricsInt_class)); |
| 318 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.top, SkScalarFloor(metrics.fTop)); |
| 319 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.ascent, ascent); |
| 320 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.descent, descent); |
| 321 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.bottom, SkScalarCeil(metrics.fBottom)); |
| 322 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.leading, leading); |
| 323 | } |
| 324 | return descent - ascent + leading; |
| 325 | } |
| 326 | |
| 327 | static jfloat measureText_CII(JNIEnv* env, jobject jpaint, jcharArray text, int index, int count) { |
| 328 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 329 | NPE_CHECK_RETURN_ZERO(env, text); |
| 330 | |
| 331 | size_t textLength = env->GetArrayLength(text); |
| 332 | |
| 333 | if ((index | count) < 0 || (size_t)(index + count) > textLength) { |
| 334 | doThrow(env, "java/lang/ArrayIndexOutOfBoundsException"); |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | const SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 339 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 340 | // we double count, since measureText wants a byteLength |
| 341 | SkScalar width = paint->measureText(textArray + index, count << 1); |
| 342 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
| 343 | JNI_ABORT); |
| 344 | |
| 345 | return SkScalarToFloat(width); |
| 346 | } |
| 347 | |
| 348 | static jfloat measureText_StringII(JNIEnv* env, jobject jpaint, jstring text, int start, int end) { |
| 349 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 350 | NPE_CHECK_RETURN_ZERO(env, text); |
| 351 | |
| 352 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 353 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 354 | size_t textLength = env->GetStringLength(text); |
| 355 | |
| 356 | int count = end - start; |
| 357 | if ((start | count) < 0 || (size_t)count > textLength) { |
| 358 | doThrow(env, "java/lang/IndexOutOfBoundsException"); |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | jfloat width = SkScalarToFloat(paint->measureText(textArray + start, count << 1)); |
| 363 | env->ReleaseStringChars(text, textArray); |
| 364 | return width; |
| 365 | } |
| 366 | |
| 367 | static jfloat measureText_String(JNIEnv* env, jobject jpaint, jstring text) { |
| 368 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 369 | NPE_CHECK_RETURN_ZERO(env, text); |
| 370 | |
| 371 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 372 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 373 | size_t textLength = env->GetStringLength(text); |
| 374 | |
| 375 | jfloat width = SkScalarToFloat(paint->measureText(textArray, textLength << 1)); |
| 376 | env->ReleaseStringChars(text, textArray); |
| 377 | return width; |
| 378 | } |
| 379 | |
| 380 | static int dotextwidths(JNIEnv* env, SkPaint* paint, const jchar text[], int count, jfloatArray widths) { |
| 381 | AutoJavaFloatArray autoWidths(env, widths, count); |
| 382 | jfloat* widthsArray = autoWidths.ptr(); |
| 383 | SkScalar* scalarArray = (SkScalar*)widthsArray; |
| 384 | |
| 385 | count = paint->getTextWidths(text, count << 1, scalarArray); |
| 386 | for (int i = 0; i < count; i++) { |
| 387 | widthsArray[i] = SkScalarToFloat(scalarArray[i]); |
| 388 | } |
| 389 | return count; |
| 390 | } |
| 391 | |
| 392 | static int getTextWidths___CII_F(JNIEnv* env, jobject clazz, SkPaint* paint, jcharArray text, int index, int count, jfloatArray widths) { |
| 393 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 394 | count = dotextwidths(env, paint, textArray + index, count, widths); |
| 395 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
| 396 | JNI_ABORT); |
| 397 | return count; |
| 398 | } |
| 399 | |
| 400 | static int getTextWidths__StringII_F(JNIEnv* env, jobject clazz, SkPaint* paint, jstring text, int start, int end, jfloatArray widths) { |
| 401 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 402 | int count = dotextwidths(env, paint, textArray + start, end - start, widths); |
| 403 | env->ReleaseStringChars(text, textArray); |
| 404 | return count; |
| 405 | } |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 406 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 407 | static jfloat doTextRunAdvances(JNIEnv *env, SkPaint *paint, const jchar *text, |
| 408 | jint start, jint count, jint contextCount, jint flags, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 409 | jfloatArray advances, jint advancesIndex) { |
| 410 | jfloat advancesArray[count]; |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 411 | jfloat totalAdvance; |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 412 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 413 | TextLayout::getTextRunAdvances(paint, text, start, count, contextCount, flags, |
| 414 | advancesArray, totalAdvance); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 415 | |
| 416 | if (advances != NULL) { |
| 417 | env->SetFloatArrayRegion(advances, advancesIndex, count, advancesArray); |
| 418 | } |
| 419 | return totalAdvance; |
| 420 | } |
| 421 | |
| 422 | static float getTextRunAdvances___CIIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint, |
| 423 | jcharArray text, jint index, jint count, jint contextIndex, jint contextCount, |
| 424 | jint flags, jfloatArray advances, jint advancesIndex) { |
| 425 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 426 | jfloat result = doTextRunAdvances(env, paint, textArray + contextIndex, |
| 427 | index - contextIndex, count, contextCount, flags, advances, advancesIndex); |
| 428 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 429 | return result; |
| 430 | } |
| 431 | |
| 432 | static float getTextRunAdvances__StringIIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint, |
| 433 | jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint flags, |
| 434 | jfloatArray advances, jint advancesIndex) { |
| 435 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 436 | jfloat result = doTextRunAdvances(env, paint, textArray + contextStart, |
| 437 | start - contextStart, end - start, contextEnd - contextStart, flags, advances, |
| 438 | advancesIndex); |
| 439 | env->ReleaseStringChars(text, textArray); |
| 440 | return result; |
| 441 | } |
| 442 | |
| 443 | static jint doTextRunCursor(JNIEnv *env, SkPaint* paint, const jchar *text, jint start, |
| 444 | jint count, jint flags, jint offset, jint opt) { |
| 445 | SkScalar scalarArray[count]; |
| 446 | jchar buffer[count]; |
| 447 | |
| 448 | // this is where we'd call harfbuzz |
| 449 | // for now we just use ushape.c and widths returned from skia |
| 450 | |
| 451 | int widths; |
| 452 | if (flags & 0x1) { // rtl, call arabic shaping in case |
| 453 | UErrorCode status = U_ZERO_ERROR; |
| 454 | // Use fixed length since we need to keep start and count valid |
| 455 | u_shapeArabic(text + start, count, buffer, count, |
| 456 | U_SHAPE_LENGTH_FIXED_SPACES_NEAR | U_SHAPE_TEXT_DIRECTION_LOGICAL | |
| 457 | U_SHAPE_LETTERS_SHAPE | U_SHAPE_X_LAMALEF_SUB_ALTERNATE, &status); |
| 458 | // we shouldn't fail unless there's an out of memory condition, |
| 459 | // in which case we're hosed anyway |
| 460 | for (int i = 0; i < count; ++i) { |
| 461 | if (buffer[i] == 0xffff) { |
| 462 | buffer[i] = 0x200b; // zero-width-space for skia |
| 463 | } |
| 464 | } |
| 465 | widths = paint->getTextWidths(buffer, count << 1, scalarArray); |
| 466 | } else { |
| 467 | widths = paint->getTextWidths(text + start, count << 1, scalarArray); |
| 468 | } |
| 469 | |
| 470 | if (widths < count) { |
| 471 | // Skia operates on code points, not code units, so surrogate pairs return only one |
| 472 | // value. Expand the result so we have one value per UTF-16 code unit. |
| 473 | |
| 474 | // Note, skia's getTextWidth gets confused if it encounters a surrogate pair, |
| 475 | // leaving the remaining widths zero. Not nice. |
| 476 | const jchar *chars = text + start; |
| 477 | for (int i = count, p = widths - 1; --i > p;) { |
| 478 | if (chars[i] >= 0xdc00 && chars[i] < 0xe000 && |
| 479 | chars[i-1] >= 0xd800 && chars[i-1] < 0xdc00) { |
| 480 | scalarArray[i] = 0; |
| 481 | } else { |
| 482 | scalarArray[i] = scalarArray[--p]; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | jint pos = offset - start; |
| 488 | switch (opt) { |
| 489 | case AFTER: |
| 490 | if (pos < count) { |
| 491 | pos += 1; |
| 492 | } |
| 493 | // fall through |
| 494 | case AT_OR_AFTER: |
| 495 | while (pos < count && scalarArray[pos] == 0) { |
| 496 | ++pos; |
| 497 | } |
| 498 | break; |
| 499 | case BEFORE: |
| 500 | if (pos > 0) { |
| 501 | --pos; |
| 502 | } |
| 503 | // fall through |
| 504 | case AT_OR_BEFORE: |
| 505 | while (pos > 0 && scalarArray[pos] == 0) { |
| 506 | --pos; |
| 507 | } |
| 508 | break; |
| 509 | case AT: |
| 510 | default: |
| 511 | if (scalarArray[pos] == 0) { |
| 512 | pos = -1; |
| 513 | } |
| 514 | break; |
| 515 | } |
| 516 | |
| 517 | if (pos != -1) { |
| 518 | pos += start; |
| 519 | } |
| 520 | |
| 521 | return pos; |
| 522 | } |
| 523 | |
| 524 | static jint getTextRunCursor___C(JNIEnv* env, jobject clazz, SkPaint* paint, jcharArray text, |
| 525 | jint contextStart, jint contextCount, jint flags, jint offset, jint cursorOpt) { |
| 526 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 527 | jint result = doTextRunCursor(env, paint, textArray, contextStart, contextCount, flags, |
| 528 | offset, cursorOpt); |
| 529 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 530 | return result; |
| 531 | } |
| 532 | |
| 533 | static jint getTextRunCursor__String(JNIEnv* env, jobject clazz, SkPaint* paint, jstring text, |
| 534 | jint contextStart, jint contextEnd, jint flags, jint offset, jint cursorOpt) { |
| 535 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 536 | jint result = doTextRunCursor(env, paint, textArray, contextStart, |
| 537 | contextEnd - contextStart, flags, offset, cursorOpt); |
| 538 | env->ReleaseStringChars(text, textArray); |
| 539 | return result; |
| 540 | } |
| 541 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 542 | static void getTextPath(JNIEnv* env, SkPaint* paint, const jchar* text, jint count, |
| 543 | jint bidiFlags, jfloat x, jfloat y, SkPath *path) { |
| 544 | TextLayout::getTextPath(paint, text, count, bidiFlags, x, y, path); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 545 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 546 | |
| 547 | static void getTextPath___C(JNIEnv* env, jobject clazz, SkPaint* paint, jint bidiFlags, |
| 548 | jcharArray text, int index, int count, jfloat x, jfloat y, SkPath* path) { |
| 549 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 550 | getTextPath(env, paint, textArray + index, count, bidiFlags, x, y, path); |
| 551 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); |
| 552 | } |
| 553 | |
| 554 | static void getTextPath__String(JNIEnv* env, jobject clazz, SkPaint* paint, jint bidiFlags, |
| 555 | 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] | 556 | const jchar* textArray = env->GetStringChars(text, NULL); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 557 | getTextPath(env, paint, textArray + start, end - start, bidiFlags, x, y, path); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | env->ReleaseStringChars(text, textArray); |
| 559 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | static void setShadowLayer(JNIEnv* env, jobject jpaint, jfloat radius, |
| 562 | jfloat dx, jfloat dy, int color) { |
| 563 | NPE_CHECK_RETURN_VOID(env, jpaint); |
| 564 | |
| 565 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 566 | if (radius <= 0) { |
| 567 | paint->setLooper(NULL); |
| 568 | } |
| 569 | else { |
| 570 | paint->setLooper(new SkBlurDrawLooper(SkFloatToScalar(radius), |
| 571 | SkFloatToScalar(dx), |
| 572 | SkFloatToScalar(dy), |
| 573 | (SkColor)color))->unref(); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | static int breakText(JNIEnv* env, const SkPaint& paint, const jchar text[], |
| 578 | int count, float maxWidth, jfloatArray jmeasured, |
| 579 | SkPaint::TextBufferDirection tbd) { |
| 580 | SkASSERT(paint.getTextEncoding() == SkPaint::kUTF16_TextEncoding); |
| 581 | |
| 582 | SkScalar measured; |
| 583 | size_t bytes = paint.breakText(text, count << 1, |
| 584 | SkFloatToScalar(maxWidth), &measured, tbd); |
| 585 | SkASSERT((bytes & 1) == 0); |
| 586 | |
| 587 | if (jmeasured && env->GetArrayLength(jmeasured) > 0) { |
| 588 | AutoJavaFloatArray autoMeasured(env, jmeasured, 1); |
| 589 | jfloat* array = autoMeasured.ptr(); |
| 590 | array[0] = SkScalarToFloat(measured); |
| 591 | } |
| 592 | return bytes >> 1; |
| 593 | } |
| 594 | |
| 595 | static int breakTextC(JNIEnv* env, jobject jpaint, jcharArray jtext, |
| 596 | int index, int count, float maxWidth, jfloatArray jmeasuredWidth) { |
| 597 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 598 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 599 | |
| 600 | SkPaint::TextBufferDirection tbd; |
| 601 | if (count < 0) { |
| 602 | tbd = SkPaint::kBackward_TextBufferDirection; |
| 603 | count = -count; |
| 604 | } |
| 605 | else { |
| 606 | tbd = SkPaint::kForward_TextBufferDirection; |
| 607 | } |
| 608 | |
| 609 | if ((index < 0) || (index + count > env->GetArrayLength(jtext))) { |
| 610 | doThrow(env, "java/lang/ArrayIndexOutOfBoundsException"); |
| 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 615 | const jchar* text = env->GetCharArrayElements(jtext, NULL); |
| 616 | count = breakText(env, *paint, text + index, count, maxWidth, |
| 617 | jmeasuredWidth, tbd); |
| 618 | env->ReleaseCharArrayElements(jtext, const_cast<jchar*>(text), |
| 619 | JNI_ABORT); |
| 620 | return count; |
| 621 | } |
| 622 | |
| 623 | static int breakTextS(JNIEnv* env, jobject jpaint, jstring jtext, |
| 624 | bool forwards, float maxWidth, jfloatArray jmeasuredWidth) { |
| 625 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 626 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 627 | |
| 628 | SkPaint::TextBufferDirection tbd = forwards ? |
| 629 | SkPaint::kForward_TextBufferDirection : |
| 630 | SkPaint::kBackward_TextBufferDirection; |
| 631 | |
| 632 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 633 | int count = env->GetStringLength(jtext); |
| 634 | const jchar* text = env->GetStringChars(jtext, NULL); |
| 635 | count = breakText(env, *paint, text, count, maxWidth, |
| 636 | jmeasuredWidth, tbd); |
| 637 | env->ReleaseStringChars(jtext, text); |
| 638 | return count; |
| 639 | } |
| 640 | |
| 641 | static void doTextBounds(JNIEnv* env, const jchar* text, int count, |
| 642 | jobject bounds, const SkPaint& paint) |
| 643 | { |
| 644 | SkRect r; |
| 645 | SkIRect ir; |
| 646 | |
| 647 | paint.measureText(text, count << 1, &r); |
| 648 | r.roundOut(&ir); |
| 649 | GraphicsJNI::irect_to_jrect(ir, env, bounds); |
| 650 | } |
| 651 | |
| 652 | static void getStringBounds(JNIEnv* env, jobject, const SkPaint* paint, |
| 653 | jstring text, int start, int end, jobject bounds) |
| 654 | { |
| 655 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 656 | doTextBounds(env, textArray + start, end - start, bounds, *paint); |
| 657 | env->ReleaseStringChars(text, textArray); |
| 658 | } |
| 659 | |
| 660 | static void getCharArrayBounds(JNIEnv* env, jobject, const SkPaint* paint, |
| 661 | jcharArray text, int index, int count, jobject bounds) |
| 662 | { |
| 663 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 664 | doTextBounds(env, textArray + index, count, bounds, *paint); |
| 665 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
| 666 | JNI_ABORT); |
| 667 | } |
| 668 | |
| 669 | }; |
| 670 | |
| 671 | static JNINativeMethod methods[] = { |
| 672 | {"finalizer", "(I)V", (void*) SkPaintGlue::finalizer}, |
| 673 | {"native_init","()I", (void*) SkPaintGlue::init}, |
| 674 | {"native_initWithPaint","(I)I", (void*) SkPaintGlue::intiWithPaint}, |
| 675 | {"native_reset","(I)V", (void*) SkPaintGlue::reset}, |
| 676 | {"native_set","(II)V", (void*) SkPaintGlue::assign}, |
| 677 | {"getFlags","()I", (void*) SkPaintGlue::getFlags}, |
| 678 | {"setFlags","(I)V", (void*) SkPaintGlue::setFlags}, |
| 679 | {"setAntiAlias","(Z)V", (void*) SkPaintGlue::setAntiAlias}, |
| 680 | {"setSubpixelText","(Z)V", (void*) SkPaintGlue::setSubpixelText}, |
| 681 | {"setLinearText","(Z)V", (void*) SkPaintGlue::setLinearText}, |
| 682 | {"setUnderlineText","(Z)V", (void*) SkPaintGlue::setUnderlineText}, |
| 683 | {"setStrikeThruText","(Z)V", (void*) SkPaintGlue::setStrikeThruText}, |
| 684 | {"setFakeBoldText","(Z)V", (void*) SkPaintGlue::setFakeBoldText}, |
| 685 | {"setFilterBitmap","(Z)V", (void*) SkPaintGlue::setFilterBitmap}, |
| 686 | {"setDither","(Z)V", (void*) SkPaintGlue::setDither}, |
| 687 | {"native_getStyle","(I)I", (void*) SkPaintGlue::getStyle}, |
| 688 | {"native_setStyle","(II)V", (void*) SkPaintGlue::setStyle}, |
| 689 | {"getColor","()I", (void*) SkPaintGlue::getColor}, |
| 690 | {"setColor","(I)V", (void*) SkPaintGlue::setColor}, |
| 691 | {"getAlpha","()I", (void*) SkPaintGlue::getAlpha}, |
| 692 | {"setAlpha","(I)V", (void*) SkPaintGlue::setAlpha}, |
| 693 | {"getStrokeWidth","()F", (void*) SkPaintGlue::getStrokeWidth}, |
| 694 | {"setStrokeWidth","(F)V", (void*) SkPaintGlue::setStrokeWidth}, |
| 695 | {"getStrokeMiter","()F", (void*) SkPaintGlue::getStrokeMiter}, |
| 696 | {"setStrokeMiter","(F)V", (void*) SkPaintGlue::setStrokeMiter}, |
| 697 | {"native_getStrokeCap","(I)I", (void*) SkPaintGlue::getStrokeCap}, |
| 698 | {"native_setStrokeCap","(II)V", (void*) SkPaintGlue::setStrokeCap}, |
| 699 | {"native_getStrokeJoin","(I)I", (void*) SkPaintGlue::getStrokeJoin}, |
| 700 | {"native_setStrokeJoin","(II)V", (void*) SkPaintGlue::setStrokeJoin}, |
| 701 | {"native_getFillPath","(III)Z", (void*) SkPaintGlue::getFillPath}, |
| 702 | {"native_setShader","(II)I", (void*) SkPaintGlue::setShader}, |
| 703 | {"native_setColorFilter","(II)I", (void*) SkPaintGlue::setColorFilter}, |
| 704 | {"native_setXfermode","(II)I", (void*) SkPaintGlue::setXfermode}, |
| 705 | {"native_setPathEffect","(II)I", (void*) SkPaintGlue::setPathEffect}, |
| 706 | {"native_setMaskFilter","(II)I", (void*) SkPaintGlue::setMaskFilter}, |
| 707 | {"native_setTypeface","(II)I", (void*) SkPaintGlue::setTypeface}, |
| 708 | {"native_setRasterizer","(II)I", (void*) SkPaintGlue::setRasterizer}, |
| 709 | {"native_getTextAlign","(I)I", (void*) SkPaintGlue::getTextAlign}, |
| 710 | {"native_setTextAlign","(II)V", (void*) SkPaintGlue::setTextAlign}, |
| 711 | {"getTextSize","()F", (void*) SkPaintGlue::getTextSize}, |
| 712 | {"setTextSize","(F)V", (void*) SkPaintGlue::setTextSize}, |
| 713 | {"getTextScaleX","()F", (void*) SkPaintGlue::getTextScaleX}, |
| 714 | {"setTextScaleX","(F)V", (void*) SkPaintGlue::setTextScaleX}, |
| 715 | {"getTextSkewX","()F", (void*) SkPaintGlue::getTextSkewX}, |
| 716 | {"setTextSkewX","(F)V", (void*) SkPaintGlue::setTextSkewX}, |
| 717 | {"ascent","()F", (void*) SkPaintGlue::ascent}, |
| 718 | {"descent","()F", (void*) SkPaintGlue::descent}, |
| 719 | {"getFontMetrics", "(Landroid/graphics/Paint$FontMetrics;)F", (void*)SkPaintGlue::getFontMetrics}, |
| 720 | {"getFontMetricsInt", "(Landroid/graphics/Paint$FontMetricsInt;)I", (void*)SkPaintGlue::getFontMetricsInt}, |
Dianne Hackborn | afa7896 | 2009-09-28 17:33:54 -0700 | [diff] [blame] | 721 | {"native_measureText","([CII)F", (void*) SkPaintGlue::measureText_CII}, |
| 722 | {"native_measureText","(Ljava/lang/String;)F", (void*) SkPaintGlue::measureText_String}, |
| 723 | {"native_measureText","(Ljava/lang/String;II)F", (void*) SkPaintGlue::measureText_StringII}, |
| 724 | {"native_breakText","([CIIF[F)I", (void*) SkPaintGlue::breakTextC}, |
| 725 | {"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] | 726 | {"native_getTextWidths","(I[CII[F)I", (void*) SkPaintGlue::getTextWidths___CII_F}, |
| 727 | {"native_getTextWidths","(ILjava/lang/String;II[F)I", (void*) SkPaintGlue::getTextWidths__StringII_F}, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 728 | {"native_getTextRunAdvances","(I[CIIIII[FI)F", (void*) |
| 729 | SkPaintGlue::getTextRunAdvances___CIIIII_FI}, |
| 730 | {"native_getTextRunAdvances","(ILjava/lang/String;IIIII[FI)F", |
| 731 | (void*) SkPaintGlue::getTextRunAdvances__StringIIIII_FI}, |
| 732 | {"native_getTextRunCursor", "(I[CIIIII)I", (void*) SkPaintGlue::getTextRunCursor___C}, |
| 733 | {"native_getTextRunCursor", "(ILjava/lang/String;IIIII)I", |
| 734 | (void*) SkPaintGlue::getTextRunCursor__String}, |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 735 | {"native_getTextPath","(II[CIIFFI)V", (void*) SkPaintGlue::getTextPath___C}, |
| 736 | {"native_getTextPath","(IILjava/lang/String;IIFFI)V", (void*) SkPaintGlue::getTextPath__String}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | {"nativeGetStringBounds", "(ILjava/lang/String;IILandroid/graphics/Rect;)V", |
| 738 | (void*) SkPaintGlue::getStringBounds }, |
| 739 | {"nativeGetCharArrayBounds", "(I[CIILandroid/graphics/Rect;)V", |
| 740 | (void*) SkPaintGlue::getCharArrayBounds }, |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame^] | 741 | {"nSetShadowLayer", "(FFFI)V", (void*)SkPaintGlue::setShadowLayer} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | }; |
| 743 | |
| 744 | static jfieldID req_fieldID(jfieldID id) { |
| 745 | SkASSERT(id); |
| 746 | return id; |
| 747 | } |
| 748 | |
| 749 | int register_android_graphics_Paint(JNIEnv* env) { |
| 750 | gFontMetrics_class = env->FindClass("android/graphics/Paint$FontMetrics"); |
| 751 | SkASSERT(gFontMetrics_class); |
| 752 | gFontMetrics_class = (jclass)env->NewGlobalRef(gFontMetrics_class); |
| 753 | |
| 754 | gFontMetrics_fieldID.top = req_fieldID(env->GetFieldID(gFontMetrics_class, "top", "F")); |
| 755 | gFontMetrics_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetrics_class, "ascent", "F")); |
| 756 | gFontMetrics_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetrics_class, "descent", "F")); |
| 757 | gFontMetrics_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetrics_class, "bottom", "F")); |
| 758 | gFontMetrics_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetrics_class, "leading", "F")); |
| 759 | |
| 760 | gFontMetricsInt_class = env->FindClass("android/graphics/Paint$FontMetricsInt"); |
| 761 | SkASSERT(gFontMetricsInt_class); |
| 762 | gFontMetricsInt_class = (jclass)env->NewGlobalRef(gFontMetricsInt_class); |
| 763 | |
| 764 | gFontMetricsInt_fieldID.top = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "top", "I")); |
| 765 | gFontMetricsInt_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "ascent", "I")); |
| 766 | gFontMetricsInt_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "descent", "I")); |
| 767 | gFontMetricsInt_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "bottom", "I")); |
| 768 | gFontMetricsInt_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "leading", "I")); |
| 769 | |
| 770 | int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Paint", methods, |
| 771 | sizeof(methods) / sizeof(methods[0])); |
| 772 | return result; |
| 773 | } |
| 774 | |
| 775 | } |