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 | |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 386 | static jfloat measureText_CIII(JNIEnv* env, jobject jpaint, jcharArray text, int index, int count, |
| 387 | jint bidiFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 389 | NPE_CHECK_RETURN_ZERO(env, text); |
| 390 | |
| 391 | size_t textLength = env->GetArrayLength(text); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | if ((index | count) < 0 || (size_t)(index + count) > textLength) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 393 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | return 0; |
| 395 | } |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 396 | if (count == 0) { |
| 397 | return 0; |
| 398 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 400 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 402 | jfloat result = 0; |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 403 | |
Fabrice Di Meglio | 8fb5071 | 2011-05-13 18:51:21 -0700 | [diff] [blame] | 404 | TextLayout::getTextRunAdvances(paint, textArray, index, count, textLength, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 405 | bidiFlags, NULL /* dont need all advances */, &result); |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 406 | |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 407 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); |
| 408 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 410 | |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 411 | static jfloat measureText_StringIII(JNIEnv* env, jobject jpaint, jstring text, int start, int end, |
| 412 | jint bidiFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 414 | NPE_CHECK_RETURN_ZERO(env, text); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 415 | |
Fabrice Di Meglio | 51f383d | 2011-09-13 15:57:58 -0700 | [diff] [blame] | 416 | size_t textLength = env->GetStringLength(text); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | int count = end - start; |
Fabrice Di Meglio | 51f383d | 2011-09-13 15:57:58 -0700 | [diff] [blame] | 418 | if ((start | count) < 0 || (size_t)end > textLength) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 419 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | return 0; |
| 421 | } |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 422 | if (count == 0) { |
| 423 | return 0; |
| 424 | } |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 425 | |
| 426 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 427 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 428 | jfloat width = 0; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 429 | |
Fabrice Di Meglio | 51f383d | 2011-09-13 15:57:58 -0700 | [diff] [blame] | 430 | TextLayout::getTextRunAdvances(paint, textArray, start, count, textLength, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 431 | bidiFlags, NULL /* dont need all advances */, &width); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | env->ReleaseStringChars(text, textArray); |
| 434 | return width; |
| 435 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 436 | |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 437 | static jfloat measureText_StringI(JNIEnv* env, jobject jpaint, jstring text, jint bidiFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 439 | NPE_CHECK_RETURN_ZERO(env, text); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | size_t textLength = env->GetStringLength(text); |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 442 | if (textLength == 0) { |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 447 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 448 | jfloat width = 0; |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 449 | |
Fabrice Di Meglio | 8fb5071 | 2011-05-13 18:51:21 -0700 | [diff] [blame] | 450 | TextLayout::getTextRunAdvances(paint, textArray, 0, textLength, textLength, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 451 | bidiFlags, NULL /* dont need all advances */, &width); |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | env->ReleaseStringChars(text, textArray); |
| 454 | return width; |
| 455 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 456 | |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 457 | static int dotextwidths(JNIEnv* env, SkPaint* paint, const jchar text[], int count, jfloatArray widths, |
| 458 | jint bidiFlags) { |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 459 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 460 | NPE_CHECK_RETURN_ZERO(env, text); |
| 461 | |
| 462 | if (count < 0 || !widths) { |
| 463 | doThrowAIOOBE(env); |
| 464 | return 0; |
| 465 | } |
| 466 | if (count == 0) { |
| 467 | return 0; |
| 468 | } |
| 469 | size_t widthsLength = env->GetArrayLength(widths); |
| 470 | if ((size_t)count > widthsLength) { |
| 471 | doThrowAIOOBE(env); |
| 472 | return 0; |
| 473 | } |
| 474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | AutoJavaFloatArray autoWidths(env, widths, count); |
| 476 | jfloat* widthsArray = autoWidths.ptr(); |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 477 | |
Fabrice Di Meglio | 8fb5071 | 2011-05-13 18:51:21 -0700 | [diff] [blame] | 478 | TextLayout::getTextRunAdvances(paint, text, 0, count, count, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 479 | bidiFlags, widthsArray, NULL /* dont need totalAdvance */); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | return count; |
| 482 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 483 | |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 484 | static int getTextWidths___CIII_F(JNIEnv* env, jobject clazz, SkPaint* paint, jcharArray text, |
| 485 | int index, int count, jint bidiFlags, jfloatArray widths) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 487 | count = dotextwidths(env, paint, textArray + index, count, widths, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 489 | JNI_ABORT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | return count; |
| 491 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 492 | |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 493 | static int getTextWidths__StringIII_F(JNIEnv* env, jobject clazz, SkPaint* paint, jstring text, |
| 494 | int start, int end, jint bidiFlags, jfloatArray widths) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | const jchar* textArray = env->GetStringChars(text, NULL); |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 496 | int count = dotextwidths(env, paint, textArray + start, end - start, widths, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | env->ReleaseStringChars(text, textArray); |
| 498 | return count; |
| 499 | } |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 500 | |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 501 | static int doTextGlyphs(JNIEnv* env, SkPaint* paint, const jchar* text, jint start, jint count, |
| 502 | jint contextCount, jint flags, jcharArray glyphs) { |
| 503 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 504 | NPE_CHECK_RETURN_ZERO(env, text); |
| 505 | |
| 506 | if ((start | count | contextCount) < 0 || contextCount < count || !glyphs) { |
| 507 | doThrowAIOOBE(env); |
| 508 | return 0; |
| 509 | } |
| 510 | if (count == 0) { |
| 511 | return 0; |
| 512 | } |
| 513 | size_t glypthsLength = env->GetArrayLength(glyphs); |
| 514 | if ((size_t)count > glypthsLength) { |
| 515 | doThrowAIOOBE(env); |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | jchar* glyphsArray = env->GetCharArrayElements(glyphs, NULL); |
| 520 | |
| 521 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, |
| 522 | text, start, count, contextCount, flags); |
| 523 | const jchar* shapedGlyphs = value->getGlyphs(); |
| 524 | size_t glyphsCount = value->getGlyphsCount(); |
| 525 | memcpy(glyphsArray, shapedGlyphs, sizeof(jchar) * glyphsCount); |
| 526 | |
| 527 | env->ReleaseCharArrayElements(glyphs, glyphsArray, JNI_ABORT); |
| 528 | return glyphsCount; |
| 529 | } |
| 530 | |
| 531 | static int getTextGlyphs__StringIIIII_C(JNIEnv* env, jobject clazz, SkPaint* paint, |
| 532 | jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint flags, |
| 533 | jcharArray glyphs) { |
| 534 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 535 | int count = doTextGlyphs(env, paint, textArray + contextStart, start - contextStart, |
| 536 | end - start, contextEnd - contextStart, flags, glyphs); |
| 537 | env->ReleaseStringChars(text, textArray); |
| 538 | return count; |
| 539 | } |
| 540 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 541 | static jfloat doTextRunAdvances(JNIEnv *env, SkPaint *paint, const jchar *text, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 542 | jint start, jint count, jint contextCount, jint flags, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 543 | jfloatArray advances, jint advancesIndex) { |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 544 | NPE_CHECK_RETURN_ZERO(env, paint); |
| 545 | NPE_CHECK_RETURN_ZERO(env, text); |
| 546 | |
| 547 | if ((start | count | contextCount | advancesIndex) < 0 || contextCount < count) { |
| 548 | doThrowAIOOBE(env); |
| 549 | return 0; |
| 550 | } |
| 551 | if (count == 0) { |
| 552 | return 0; |
| 553 | } |
| 554 | if (advances) { |
| 555 | size_t advancesLength = env->GetArrayLength(advances); |
| 556 | if ((size_t)count > advancesLength) { |
| 557 | doThrowAIOOBE(env); |
| 558 | return 0; |
| 559 | } |
| 560 | } |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 561 | jfloat advancesArray[count]; |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 562 | jfloat totalAdvance = 0; |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 563 | |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 564 | TextLayout::getTextRunAdvances(paint, text, start, count, contextCount, flags, |
Fabrice Di Meglio | 79df532 | 2011-09-19 15:17:56 -0700 | [diff] [blame] | 565 | advancesArray, &totalAdvance); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 566 | |
| 567 | if (advances != NULL) { |
| 568 | env->SetFloatArrayRegion(advances, advancesIndex, count, advancesArray); |
| 569 | } |
| 570 | return totalAdvance; |
| 571 | } |
| 572 | |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 573 | static float getTextRunAdvances___CIIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 574 | jcharArray text, jint index, jint count, jint contextIndex, jint contextCount, |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 575 | jint flags, jfloatArray advances, jint advancesIndex) { |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 576 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 577 | jfloat result = doTextRunAdvances(env, paint, textArray + contextIndex, |
| 578 | index - contextIndex, count, contextCount, flags, advances, advancesIndex); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 579 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 580 | return result; |
| 581 | } |
| 582 | |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 583 | static float getTextRunAdvances__StringIIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 584 | jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint flags, |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 585 | jfloatArray advances, jint advancesIndex) { |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 586 | const jchar* textArray = env->GetStringChars(text, NULL); |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 587 | jfloat result = doTextRunAdvances(env, paint, textArray + contextStart, |
| 588 | start - contextStart, end - start, contextEnd - contextStart, flags, |
| 589 | advances, advancesIndex); |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 590 | env->ReleaseStringChars(text, textArray); |
| 591 | return result; |
| 592 | } |
| 593 | |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 594 | 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] | 595 | jint count, jint flags, jint offset, jint opt) { |
Fabrice Di Meglio | 4f810c8 | 2011-04-19 14:53:58 -0700 | [diff] [blame] | 596 | jfloat scalarArray[count]; |
Fabrice Di Meglio | 9c418db | 2011-09-18 12:54:38 -0700 | [diff] [blame] | 597 | |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 598 | TextLayout::getTextRunAdvances(paint, text, start, count, start + count, flags, |
Fabrice Di Meglio | 79df532 | 2011-09-19 15:17:56 -0700 | [diff] [blame] | 599 | scalarArray, NULL /* dont need totalAdvance */); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 600 | |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 601 | jint pos = offset - start; |
| 602 | switch (opt) { |
| 603 | case AFTER: |
| 604 | if (pos < count) { |
| 605 | pos += 1; |
| 606 | } |
| 607 | // fall through |
| 608 | case AT_OR_AFTER: |
| 609 | while (pos < count && scalarArray[pos] == 0) { |
| 610 | ++pos; |
| 611 | } |
| 612 | break; |
| 613 | case BEFORE: |
| 614 | if (pos > 0) { |
| 615 | --pos; |
| 616 | } |
| 617 | // fall through |
| 618 | case AT_OR_BEFORE: |
| 619 | while (pos > 0 && scalarArray[pos] == 0) { |
| 620 | --pos; |
| 621 | } |
| 622 | break; |
| 623 | case AT: |
| 624 | default: |
| 625 | if (scalarArray[pos] == 0) { |
| 626 | pos = -1; |
| 627 | } |
| 628 | break; |
| 629 | } |
| 630 | |
| 631 | if (pos != -1) { |
| 632 | pos += start; |
| 633 | } |
| 634 | |
| 635 | return pos; |
| 636 | } |
| 637 | |
| 638 | 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] | 639 | jint contextStart, jint contextCount, jint flags, jint offset, jint cursorOpt) { |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 640 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | a4bf811 | 2013-03-15 11:22:29 -0700 | [diff] [blame] | 641 | jint result = doTextRunCursor(env, paint, textArray, contextStart, contextCount, flags, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 642 | offset, cursorOpt); |
| 643 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 644 | return result; |
| 645 | } |
| 646 | |
| 647 | 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] | 648 | jint contextStart, jint contextEnd, jint flags, jint offset, jint cursorOpt) { |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 649 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 650 | jint result = doTextRunCursor(env, paint, textArray, contextStart, |
Fabrice Di Meglio | a4bf811 | 2013-03-15 11:22:29 -0700 | [diff] [blame] | 651 | contextEnd - contextStart, flags, offset, cursorOpt); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 652 | env->ReleaseStringChars(text, textArray); |
| 653 | return result; |
| 654 | } |
| 655 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 656 | static void getTextPath(JNIEnv* env, SkPaint* paint, const jchar* text, jint count, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 657 | jint bidiFlags, jfloat x, jfloat y, SkPath *path) { |
| 658 | TextLayout::getTextPath(paint, text, count, bidiFlags, x, y, path); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 660 | |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 661 | static void getTextPath___C(JNIEnv* env, jobject clazz, SkPaint* paint, jint bidiFlags, |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 662 | jcharArray text, int index, int count, jfloat x, jfloat y, SkPath* path) { |
| 663 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 664 | getTextPath(env, paint, textArray + index, count, bidiFlags, x, y, path); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 665 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); |
| 666 | } |
| 667 | |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 668 | static void getTextPath__String(JNIEnv* env, jobject clazz, SkPaint* paint, jint bidiFlags, |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 669 | 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] | 670 | const jchar* textArray = env->GetStringChars(text, NULL); |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 671 | 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] | 672 | env->ReleaseStringChars(text, textArray); |
| 673 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 674 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | static void setShadowLayer(JNIEnv* env, jobject jpaint, jfloat radius, |
| 676 | jfloat dx, jfloat dy, int color) { |
| 677 | NPE_CHECK_RETURN_VOID(env, jpaint); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 678 | |
| 679 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 680 | if (radius <= 0) { |
| 681 | paint->setLooper(NULL); |
| 682 | } |
| 683 | else { |
| 684 | paint->setLooper(new SkBlurDrawLooper(SkFloatToScalar(radius), |
| 685 | SkFloatToScalar(dx), |
| 686 | SkFloatToScalar(dy), |
| 687 | (SkColor)color))->unref(); |
| 688 | } |
| 689 | } |
| 690 | |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 691 | static int breakText(JNIEnv* env, SkPaint& paint, const jchar text[], |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 692 | int count, float maxWidth, jint bidiFlags, jfloatArray jmeasured, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | SkPaint::TextBufferDirection tbd) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 694 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(&paint, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 695 | text, 0, count, count, bidiFlags); |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 696 | if (value == NULL) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 697 | return 0; |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 698 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | SkScalar measured; |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 700 | 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] | 701 | SkFloatToScalar(maxWidth), &measured, tbd); |
| 702 | SkASSERT((bytes & 1) == 0); |
| 703 | |
| 704 | if (jmeasured && env->GetArrayLength(jmeasured) > 0) { |
| 705 | AutoJavaFloatArray autoMeasured(env, jmeasured, 1); |
| 706 | jfloat* array = autoMeasured.ptr(); |
| 707 | array[0] = SkScalarToFloat(measured); |
| 708 | } |
| 709 | return bytes >> 1; |
| 710 | } |
| 711 | |
| 712 | static int breakTextC(JNIEnv* env, jobject jpaint, jcharArray jtext, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 713 | int index, int count, float maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 715 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 716 | |
| 717 | SkPaint::TextBufferDirection tbd; |
| 718 | if (count < 0) { |
| 719 | tbd = SkPaint::kBackward_TextBufferDirection; |
| 720 | count = -count; |
| 721 | } |
| 722 | else { |
| 723 | tbd = SkPaint::kForward_TextBufferDirection; |
| 724 | } |
| 725 | |
| 726 | if ((index < 0) || (index + count > env->GetArrayLength(jtext))) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 727 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 732 | const jchar* text = env->GetCharArrayElements(jtext, NULL); |
| 733 | count = breakText(env, *paint, text + index, count, maxWidth, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 734 | bidiFlags, jmeasuredWidth, tbd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | env->ReleaseCharArrayElements(jtext, const_cast<jchar*>(text), |
| 736 | JNI_ABORT); |
| 737 | return count; |
| 738 | } |
| 739 | |
| 740 | static int breakTextS(JNIEnv* env, jobject jpaint, jstring jtext, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 741 | bool forwards, float maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | NPE_CHECK_RETURN_ZERO(env, jpaint); |
| 743 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 744 | |
| 745 | SkPaint::TextBufferDirection tbd = forwards ? |
| 746 | SkPaint::kForward_TextBufferDirection : |
| 747 | SkPaint::kBackward_TextBufferDirection; |
| 748 | |
| 749 | SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint); |
| 750 | int count = env->GetStringLength(jtext); |
| 751 | const jchar* text = env->GetStringChars(jtext, NULL); |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 752 | count = breakText(env, *paint, text, count, maxWidth, bidiFlags, jmeasuredWidth, tbd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | env->ReleaseStringChars(jtext, text); |
| 754 | return count; |
| 755 | } |
| 756 | |
| 757 | static void doTextBounds(JNIEnv* env, const jchar* text, int count, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 758 | jobject bounds, const SkPaint& paint, jint bidiFlags) { |
Romain Guy | 059e12c | 2012-11-28 17:35:51 -0800 | [diff] [blame] | 759 | SkRect r; |
| 760 | r.set(0,0,0,0); |
| 761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | SkIRect ir; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 763 | |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 764 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(&paint, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 765 | text, 0, count, count, bidiFlags); |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 766 | if (value == NULL) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 767 | return; |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 768 | } |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 769 | paint.measureText(value->getGlyphs(), value->getGlyphsCount() << 1, &r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | r.roundOut(&ir); |
| 771 | GraphicsJNI::irect_to_jrect(ir, env, bounds); |
| 772 | } |
| 773 | |
| 774 | static void getStringBounds(JNIEnv* env, jobject, const SkPaint* paint, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 775 | jstring text, int start, int end, jint bidiFlags, jobject bounds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | const jchar* textArray = env->GetStringChars(text, NULL); |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 777 | doTextBounds(env, textArray + start, end - start, bounds, *paint, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | env->ReleaseStringChars(text, textArray); |
| 779 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | static void getCharArrayBounds(JNIEnv* env, jobject, const SkPaint* paint, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 782 | jcharArray text, int index, int count, jint bidiFlags, jobject bounds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 784 | doTextBounds(env, textArray + index, count, bounds, *paint, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
| 786 | JNI_ABORT); |
| 787 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | }; |
| 790 | |
| 791 | static JNINativeMethod methods[] = { |
| 792 | {"finalizer", "(I)V", (void*) SkPaintGlue::finalizer}, |
| 793 | {"native_init","()I", (void*) SkPaintGlue::init}, |
| 794 | {"native_initWithPaint","(I)I", (void*) SkPaintGlue::intiWithPaint}, |
| 795 | {"native_reset","(I)V", (void*) SkPaintGlue::reset}, |
| 796 | {"native_set","(II)V", (void*) SkPaintGlue::assign}, |
| 797 | {"getFlags","()I", (void*) SkPaintGlue::getFlags}, |
| 798 | {"setFlags","(I)V", (void*) SkPaintGlue::setFlags}, |
Dianne Hackborn | f43fa57 | 2011-08-12 18:59:39 -0700 | [diff] [blame] | 799 | {"getHinting","()I", (void*) SkPaintGlue::getHinting}, |
| 800 | {"setHinting","(I)V", (void*) SkPaintGlue::setHinting}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | {"setAntiAlias","(Z)V", (void*) SkPaintGlue::setAntiAlias}, |
| 802 | {"setSubpixelText","(Z)V", (void*) SkPaintGlue::setSubpixelText}, |
| 803 | {"setLinearText","(Z)V", (void*) SkPaintGlue::setLinearText}, |
| 804 | {"setUnderlineText","(Z)V", (void*) SkPaintGlue::setUnderlineText}, |
| 805 | {"setStrikeThruText","(Z)V", (void*) SkPaintGlue::setStrikeThruText}, |
| 806 | {"setFakeBoldText","(Z)V", (void*) SkPaintGlue::setFakeBoldText}, |
| 807 | {"setFilterBitmap","(Z)V", (void*) SkPaintGlue::setFilterBitmap}, |
| 808 | {"setDither","(Z)V", (void*) SkPaintGlue::setDither}, |
| 809 | {"native_getStyle","(I)I", (void*) SkPaintGlue::getStyle}, |
| 810 | {"native_setStyle","(II)V", (void*) SkPaintGlue::setStyle}, |
| 811 | {"getColor","()I", (void*) SkPaintGlue::getColor}, |
| 812 | {"setColor","(I)V", (void*) SkPaintGlue::setColor}, |
| 813 | {"getAlpha","()I", (void*) SkPaintGlue::getAlpha}, |
| 814 | {"setAlpha","(I)V", (void*) SkPaintGlue::setAlpha}, |
| 815 | {"getStrokeWidth","()F", (void*) SkPaintGlue::getStrokeWidth}, |
| 816 | {"setStrokeWidth","(F)V", (void*) SkPaintGlue::setStrokeWidth}, |
| 817 | {"getStrokeMiter","()F", (void*) SkPaintGlue::getStrokeMiter}, |
| 818 | {"setStrokeMiter","(F)V", (void*) SkPaintGlue::setStrokeMiter}, |
| 819 | {"native_getStrokeCap","(I)I", (void*) SkPaintGlue::getStrokeCap}, |
| 820 | {"native_setStrokeCap","(II)V", (void*) SkPaintGlue::setStrokeCap}, |
| 821 | {"native_getStrokeJoin","(I)I", (void*) SkPaintGlue::getStrokeJoin}, |
| 822 | {"native_setStrokeJoin","(II)V", (void*) SkPaintGlue::setStrokeJoin}, |
| 823 | {"native_getFillPath","(III)Z", (void*) SkPaintGlue::getFillPath}, |
| 824 | {"native_setShader","(II)I", (void*) SkPaintGlue::setShader}, |
| 825 | {"native_setColorFilter","(II)I", (void*) SkPaintGlue::setColorFilter}, |
| 826 | {"native_setXfermode","(II)I", (void*) SkPaintGlue::setXfermode}, |
| 827 | {"native_setPathEffect","(II)I", (void*) SkPaintGlue::setPathEffect}, |
| 828 | {"native_setMaskFilter","(II)I", (void*) SkPaintGlue::setMaskFilter}, |
| 829 | {"native_setTypeface","(II)I", (void*) SkPaintGlue::setTypeface}, |
| 830 | {"native_setRasterizer","(II)I", (void*) SkPaintGlue::setRasterizer}, |
| 831 | {"native_getTextAlign","(I)I", (void*) SkPaintGlue::getTextAlign}, |
| 832 | {"native_setTextAlign","(II)V", (void*) SkPaintGlue::setTextAlign}, |
Fabrice Di Meglio | 517825f | 2012-04-06 16:53:48 -0700 | [diff] [blame] | 833 | {"native_setTextLocale","(ILjava/lang/String;)V", (void*) SkPaintGlue::setTextLocale}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | {"getTextSize","()F", (void*) SkPaintGlue::getTextSize}, |
| 835 | {"setTextSize","(F)V", (void*) SkPaintGlue::setTextSize}, |
| 836 | {"getTextScaleX","()F", (void*) SkPaintGlue::getTextScaleX}, |
| 837 | {"setTextScaleX","(F)V", (void*) SkPaintGlue::setTextScaleX}, |
| 838 | {"getTextSkewX","()F", (void*) SkPaintGlue::getTextSkewX}, |
| 839 | {"setTextSkewX","(F)V", (void*) SkPaintGlue::setTextSkewX}, |
| 840 | {"ascent","()F", (void*) SkPaintGlue::ascent}, |
| 841 | {"descent","()F", (void*) SkPaintGlue::descent}, |
| 842 | {"getFontMetrics", "(Landroid/graphics/Paint$FontMetrics;)F", (void*)SkPaintGlue::getFontMetrics}, |
| 843 | {"getFontMetricsInt", "(Landroid/graphics/Paint$FontMetricsInt;)I", (void*)SkPaintGlue::getFontMetricsInt}, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 844 | {"native_measureText","([CIII)F", (void*) SkPaintGlue::measureText_CIII}, |
| 845 | {"native_measureText","(Ljava/lang/String;I)F", (void*) SkPaintGlue::measureText_StringI}, |
| 846 | {"native_measureText","(Ljava/lang/String;III)F", (void*) SkPaintGlue::measureText_StringIII}, |
| 847 | {"native_breakText","([CIIFI[F)I", (void*) SkPaintGlue::breakTextC}, |
| 848 | {"native_breakText","(Ljava/lang/String;ZFI[F)I", (void*) SkPaintGlue::breakTextS}, |
| 849 | {"native_getTextWidths","(I[CIII[F)I", (void*) SkPaintGlue::getTextWidths___CIII_F}, |
| 850 | {"native_getTextWidths","(ILjava/lang/String;III[F)I", (void*) SkPaintGlue::getTextWidths__StringIII_F}, |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 851 | {"native_getTextRunAdvances","(I[CIIIII[FI)F", |
| 852 | (void*) SkPaintGlue::getTextRunAdvances___CIIIII_FI}, |
| 853 | {"native_getTextRunAdvances","(ILjava/lang/String;IIIII[FI)F", |
| 854 | (void*) SkPaintGlue::getTextRunAdvances__StringIIIII_FI}, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 855 | |
| 856 | |
| 857 | {"native_getTextGlyphs","(ILjava/lang/String;IIIII[C)I", |
| 858 | (void*) SkPaintGlue::getTextGlyphs__StringIIIII_C}, |
| 859 | {"native_getTextRunCursor", "(I[CIIIII)I", (void*) SkPaintGlue::getTextRunCursor___C}, |
| 860 | {"native_getTextRunCursor", "(ILjava/lang/String;IIIII)I", |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 861 | (void*) SkPaintGlue::getTextRunCursor__String}, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 862 | {"native_getTextPath","(II[CIIFFI)V", (void*) SkPaintGlue::getTextPath___C}, |
| 863 | {"native_getTextPath","(IILjava/lang/String;IIFFI)V", (void*) SkPaintGlue::getTextPath__String}, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 864 | {"nativeGetStringBounds", "(ILjava/lang/String;IIILandroid/graphics/Rect;)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | (void*) SkPaintGlue::getStringBounds }, |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 866 | {"nativeGetCharArrayBounds", "(I[CIIILandroid/graphics/Rect;)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | (void*) SkPaintGlue::getCharArrayBounds }, |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 868 | {"nSetShadowLayer", "(FFFI)V", (void*)SkPaintGlue::setShadowLayer} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | }; |
| 870 | |
| 871 | static jfieldID req_fieldID(jfieldID id) { |
| 872 | SkASSERT(id); |
| 873 | return id; |
| 874 | } |
| 875 | |
| 876 | int register_android_graphics_Paint(JNIEnv* env) { |
| 877 | gFontMetrics_class = env->FindClass("android/graphics/Paint$FontMetrics"); |
| 878 | SkASSERT(gFontMetrics_class); |
| 879 | gFontMetrics_class = (jclass)env->NewGlobalRef(gFontMetrics_class); |
| 880 | |
| 881 | gFontMetrics_fieldID.top = req_fieldID(env->GetFieldID(gFontMetrics_class, "top", "F")); |
| 882 | gFontMetrics_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetrics_class, "ascent", "F")); |
| 883 | gFontMetrics_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetrics_class, "descent", "F")); |
| 884 | gFontMetrics_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetrics_class, "bottom", "F")); |
| 885 | gFontMetrics_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetrics_class, "leading", "F")); |
| 886 | |
| 887 | gFontMetricsInt_class = env->FindClass("android/graphics/Paint$FontMetricsInt"); |
| 888 | SkASSERT(gFontMetricsInt_class); |
| 889 | gFontMetricsInt_class = (jclass)env->NewGlobalRef(gFontMetricsInt_class); |
| 890 | |
| 891 | gFontMetricsInt_fieldID.top = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "top", "I")); |
| 892 | gFontMetricsInt_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "ascent", "I")); |
| 893 | gFontMetricsInt_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "descent", "I")); |
| 894 | gFontMetricsInt_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "bottom", "I")); |
| 895 | gFontMetricsInt_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "leading", "I")); |
| 896 | |
| 897 | int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Paint", methods, |
| 898 | sizeof(methods) / sizeof(methods[0])); |
| 899 | return result; |
| 900 | } |
| 901 | |
| 902 | } |