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