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" |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 24 | #include "core_jni_helpers.h" |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 25 | #include <ScopedStringChars.h> |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 26 | #include <ScopedUtfChars.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | #include "SkBlurDrawLooper.h" |
| 29 | #include "SkColorFilter.h" |
| 30 | #include "SkMaskFilter.h" |
Derek Sollenberger | eba81d0 | 2015-10-26 10:22:37 -0400 | [diff] [blame] | 31 | #include "SkPath.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include "SkRasterizer.h" |
| 33 | #include "SkShader.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include "SkXfermode.h" |
Billy Hewlett | ac1cbaf | 2012-07-18 09:51:45 -0700 | [diff] [blame] | 35 | #include "unicode/uloc.h" |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 36 | #include "unicode/ushape.h" |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 37 | #include "utils/Blur.h" |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 38 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 39 | #include <hwui/MinikinSkia.h> |
| 40 | #include <hwui/MinikinUtils.h> |
| 41 | #include <hwui/Paint.h> |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 42 | #include <hwui/Typeface.h> |
Raph Levien | e368b6b | 2014-06-15 17:37:57 -0700 | [diff] [blame] | 43 | #include <minikin/GraphemeBreak.h> |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 44 | #include <minikin/Measurement.h> |
Seigo Nonaka | bb1a966 | 2015-10-21 23:24:25 +0900 | [diff] [blame] | 45 | #include <unicode/utf16.h> |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 46 | |
Roozbeh Pournader | f036ead | 2015-10-19 16:56:39 -0700 | [diff] [blame] | 47 | #include <cassert> |
| 48 | #include <cstring> |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 49 | #include <memory> |
Roozbeh Pournader | f036ead | 2015-10-19 16:56:39 -0700 | [diff] [blame] | 50 | #include <vector> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | |
| 52 | namespace android { |
| 53 | |
| 54 | struct JMetricsID { |
| 55 | jfieldID top; |
| 56 | jfieldID ascent; |
| 57 | jfieldID descent; |
| 58 | jfieldID bottom; |
| 59 | jfieldID leading; |
| 60 | }; |
| 61 | |
| 62 | static jclass gFontMetrics_class; |
| 63 | static JMetricsID gFontMetrics_fieldID; |
| 64 | |
| 65 | static jclass gFontMetricsInt_class; |
| 66 | static JMetricsID gFontMetricsInt_fieldID; |
| 67 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 68 | static void defaultSettingsForAndroid(Paint* paint) { |
Fabrice Di Meglio | c511bee8 | 2012-01-05 13:30:54 -0800 | [diff] [blame] | 69 | // GlyphID encoding is required because we are using Harfbuzz shaping |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 70 | paint->setTextEncoding(Paint::kGlyphID_TextEncoding); |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 71 | } |
| 72 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 73 | namespace PaintGlue { |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 74 | enum MoveOpt { |
| 75 | AFTER, AT_OR_AFTER, BEFORE, AT_OR_BEFORE, AT |
| 76 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | |
Richard Uhler | 775873a | 2015-12-29 12:37:39 -0800 | [diff] [blame] | 78 | static void deletePaint(Paint* paint) { |
| 79 | delete paint; |
| 80 | } |
| 81 | |
| 82 | static jlong getNativeFinalizer(JNIEnv*, jobject) { |
| 83 | return static_cast<jlong>(reinterpret_cast<uintptr_t>(&deletePaint)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | } |
| 85 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 86 | static jlong init(JNIEnv* env, jobject) { |
Ben Wagner | e3a40ea | 2015-08-19 15:49:37 -0400 | [diff] [blame] | 87 | static_assert(1 << 0 == SkPaint::kAntiAlias_Flag, "paint_flags_mismatch"); |
| 88 | static_assert(1 << 2 == SkPaint::kDither_Flag, "paint_flags_mismatch"); |
| 89 | static_assert(1 << 3 == SkPaint::kUnderlineText_Flag, "paint_flags_mismatch"); |
| 90 | static_assert(1 << 4 == SkPaint::kStrikeThruText_Flag, "paint_flags_mismatch"); |
| 91 | static_assert(1 << 5 == SkPaint::kFakeBoldText_Flag, "paint_flags_mismatch"); |
| 92 | static_assert(1 << 6 == SkPaint::kLinearText_Flag, "paint_flags_mismatch"); |
| 93 | static_assert(1 << 7 == SkPaint::kSubpixelText_Flag, "paint_flags_mismatch"); |
| 94 | static_assert(1 << 8 == SkPaint::kDevKernText_Flag, "paint_flags_mismatch"); |
| 95 | static_assert(1 << 10 == SkPaint::kEmbeddedBitmapText_Flag, "paint_flags_mismatch"); |
Derek Sollenberger | 0b86062 | 2015-03-25 10:08:30 -0400 | [diff] [blame] | 96 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 97 | Paint* obj = new Paint(); |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 98 | defaultSettingsForAndroid(obj); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 99 | return reinterpret_cast<jlong>(obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 102 | static jlong initWithPaint(JNIEnv* env, jobject clazz, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 103 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 104 | Paint* obj = new Paint(*paint); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 105 | return reinterpret_cast<jlong>(obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 107 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 108 | static void reset(JNIEnv* env, jobject clazz, jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 109 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | obj->reset(); |
Mike Reed | 3d63e01 | 2009-07-27 09:50:31 -0400 | [diff] [blame] | 111 | defaultSettingsForAndroid(obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 113 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 114 | static void assign(JNIEnv* env, jobject clazz, jlong dstPaintHandle, jlong srcPaintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 115 | Paint* dst = reinterpret_cast<Paint*>(dstPaintHandle); |
| 116 | const Paint* src = reinterpret_cast<Paint*>(srcPaintHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | *dst = *src; |
| 118 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 119 | |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 120 | // Equivalent to the Java Paint's FILTER_BITMAP_FLAG. |
| 121 | static const uint32_t sFilterBitmapFlag = 0x02; |
| 122 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 123 | static jint getFlags(JNIEnv* env, jobject, jlong paintHandle) { |
| 124 | Paint* nativePaint = reinterpret_cast<Paint*>(paintHandle); |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 125 | uint32_t result = nativePaint->getFlags(); |
| 126 | result &= ~sFilterBitmapFlag; // Filtering no longer stored in this bit. Mask away. |
Mike Reed | 2a1ce8a | 2015-03-16 11:16:09 -0400 | [diff] [blame] | 127 | if (nativePaint->getFilterQuality() != kNone_SkFilterQuality) { |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 128 | result |= sFilterBitmapFlag; |
| 129 | } |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 130 | return static_cast<jint>(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 132 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 133 | static void setFlags(JNIEnv* env, jobject, jlong paintHandle, jint flags) { |
| 134 | Paint* nativePaint = reinterpret_cast<Paint*>(paintHandle); |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 135 | // Instead of modifying 0x02, change the filter level. |
Mike Reed | 2a1ce8a | 2015-03-16 11:16:09 -0400 | [diff] [blame] | 136 | nativePaint->setFilterQuality(flags & sFilterBitmapFlag |
| 137 | ? kLow_SkFilterQuality |
| 138 | : kNone_SkFilterQuality); |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 139 | // Don't pass through filter flag, which is no longer stored in paint's flags. |
| 140 | flags &= ~sFilterBitmapFlag; |
| 141 | // Use the existing value for 0x02. |
| 142 | const uint32_t existing0x02Flag = nativePaint->getFlags() & sFilterBitmapFlag; |
| 143 | flags |= existing0x02Flag; |
| 144 | nativePaint->setFlags(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 146 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 147 | static jint getHinting(JNIEnv* env, jobject, jlong paintHandle) { |
| 148 | return reinterpret_cast<Paint*>(paintHandle)->getHinting() |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 149 | == Paint::kNo_Hinting ? 0 : 1; |
Dianne Hackborn | f43fa57 | 2011-08-12 18:59:39 -0700 | [diff] [blame] | 150 | } |
| 151 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 152 | static void setHinting(JNIEnv* env, jobject, jlong paintHandle, jint mode) { |
| 153 | reinterpret_cast<Paint*>(paintHandle)->setHinting( |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 154 | mode == 0 ? Paint::kNo_Hinting : Paint::kNormal_Hinting); |
Dianne Hackborn | f43fa57 | 2011-08-12 18:59:39 -0700 | [diff] [blame] | 155 | } |
| 156 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 157 | static void setAntiAlias(JNIEnv* env, jobject, jlong paintHandle, jboolean aa) { |
| 158 | reinterpret_cast<Paint*>(paintHandle)->setAntiAlias(aa); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 160 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 161 | static void setLinearText(JNIEnv* env, jobject, jlong paintHandle, jboolean linearText) { |
| 162 | reinterpret_cast<Paint*>(paintHandle)->setLinearText(linearText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 164 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 165 | static void setSubpixelText(JNIEnv* env, jobject, jlong paintHandle, jboolean subpixelText) { |
| 166 | reinterpret_cast<Paint*>(paintHandle)->setSubpixelText(subpixelText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 168 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 169 | static void setUnderlineText(JNIEnv* env, jobject, jlong paintHandle, jboolean underlineText) { |
| 170 | reinterpret_cast<Paint*>(paintHandle)->setUnderlineText(underlineText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 172 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 173 | static void setStrikeThruText(JNIEnv* env, jobject, jlong paintHandle, jboolean strikeThruText) { |
| 174 | reinterpret_cast<Paint*>(paintHandle)->setStrikeThruText(strikeThruText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 176 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 177 | static void setFakeBoldText(JNIEnv* env, jobject, jlong paintHandle, jboolean fakeBoldText) { |
| 178 | reinterpret_cast<Paint*>(paintHandle)->setFakeBoldText(fakeBoldText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 180 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 181 | static void setFilterBitmap(JNIEnv* env, jobject, jlong paintHandle, jboolean filterBitmap) { |
| 182 | reinterpret_cast<Paint*>(paintHandle)->setFilterQuality( |
Mike Reed | 2a1ce8a | 2015-03-16 11:16:09 -0400 | [diff] [blame] | 183 | filterBitmap ? kLow_SkFilterQuality : kNone_SkFilterQuality); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 185 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 186 | static void setDither(JNIEnv* env, jobject, jlong paintHandle, jboolean dither) { |
| 187 | reinterpret_cast<Paint*>(paintHandle)->setDither(dither); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 189 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 190 | static jint getStyle(JNIEnv* env, jobject clazz,jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 191 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 192 | return static_cast<jint>(obj->getStyle()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 194 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 195 | static void setStyle(JNIEnv* env, jobject clazz, jlong objHandle, jint styleHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 196 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 197 | Paint::Style style = static_cast<Paint::Style>(styleHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | obj->setStyle(style); |
| 199 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 200 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 201 | static jint getColor(JNIEnv* env, jobject, jlong paintHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 202 | int color; |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 203 | color = reinterpret_cast<Paint*>(paintHandle)->getColor(); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 204 | return static_cast<jint>(color); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 206 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 207 | static jint getAlpha(JNIEnv* env, jobject, jlong paintHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 208 | int alpha; |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 209 | alpha = reinterpret_cast<Paint*>(paintHandle)->getAlpha(); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 210 | return static_cast<jint>(alpha); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 212 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 213 | static void setColor(JNIEnv* env, jobject, jlong paintHandle, jint color) { |
| 214 | reinterpret_cast<Paint*>(paintHandle)->setColor(color); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 216 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 217 | static void setAlpha(JNIEnv* env, jobject, jlong paintHandle, jint a) { |
| 218 | reinterpret_cast<Paint*>(paintHandle)->setAlpha(a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 220 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 221 | static jfloat getStrokeWidth(JNIEnv* env, jobject, jlong paintHandle) { |
| 222 | return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getStrokeWidth()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 224 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 225 | static void setStrokeWidth(JNIEnv* env, jobject, jlong paintHandle, jfloat width) { |
| 226 | reinterpret_cast<Paint*>(paintHandle)->setStrokeWidth(width); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 228 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 229 | static jfloat getStrokeMiter(JNIEnv* env, jobject, jlong paintHandle) { |
| 230 | return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getStrokeMiter()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 232 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 233 | static void setStrokeMiter(JNIEnv* env, jobject, jlong paintHandle, jfloat miter) { |
| 234 | reinterpret_cast<Paint*>(paintHandle)->setStrokeMiter(miter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 236 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 237 | static jint getStrokeCap(JNIEnv* env, jobject clazz, jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 238 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 239 | return static_cast<jint>(obj->getStrokeCap()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 241 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 242 | static void setStrokeCap(JNIEnv* env, jobject clazz, jlong objHandle, jint capHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 243 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 244 | Paint::Cap cap = static_cast<Paint::Cap>(capHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | obj->setStrokeCap(cap); |
| 246 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 247 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 248 | static jint getStrokeJoin(JNIEnv* env, jobject clazz, jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 249 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 250 | return static_cast<jint>(obj->getStrokeJoin()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 252 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 253 | static void setStrokeJoin(JNIEnv* env, jobject clazz, jlong objHandle, jint joinHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 254 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 255 | Paint::Join join = (Paint::Join) joinHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | obj->setStrokeJoin(join); |
| 257 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 258 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 259 | static jboolean getFillPath(JNIEnv* env, jobject clazz, jlong objHandle, jlong srcHandle, jlong dstHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 260 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 261 | SkPath* src = reinterpret_cast<SkPath*>(srcHandle); |
| 262 | SkPath* dst = reinterpret_cast<SkPath*>(dstHandle); |
| 263 | return obj->getFillPath(*src, dst) ? JNI_TRUE : JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 265 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 266 | static jlong setShader(JNIEnv* env, jobject clazz, jlong objHandle, jlong shaderHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 267 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 268 | SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); |
| 269 | return reinterpret_cast<jlong>(obj->setShader(shader)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 271 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 272 | static jlong setColorFilter(JNIEnv* env, jobject clazz, jlong objHandle, jlong filterHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 273 | Paint* obj = reinterpret_cast<Paint *>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 274 | SkColorFilter* filter = reinterpret_cast<SkColorFilter *>(filterHandle); |
| 275 | return reinterpret_cast<jlong>(obj->setColorFilter(filter)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 277 | |
John Reck | 5d31a29 | 2016-09-15 10:13:10 -0700 | [diff] [blame] | 278 | static void setXfermode(JNIEnv* env, jobject clazz, jlong paintHandle, jint xfermodeHandle) { |
| 279 | // validate that the Java enum values match our expectations |
| 280 | static_assert(0 == SkXfermode::kClear_Mode, "xfermode_mismatch"); |
| 281 | static_assert(1 == SkXfermode::kSrc_Mode, "xfermode_mismatch"); |
| 282 | static_assert(2 == SkXfermode::kDst_Mode, "xfermode_mismatch"); |
| 283 | static_assert(3 == SkXfermode::kSrcOver_Mode, "xfermode_mismatch"); |
| 284 | static_assert(4 == SkXfermode::kDstOver_Mode, "xfermode_mismatch"); |
| 285 | static_assert(5 == SkXfermode::kSrcIn_Mode, "xfermode_mismatch"); |
| 286 | static_assert(6 == SkXfermode::kDstIn_Mode, "xfermode_mismatch"); |
| 287 | static_assert(7 == SkXfermode::kSrcOut_Mode, "xfermode_mismatch"); |
| 288 | static_assert(8 == SkXfermode::kDstOut_Mode, "xfermode_mismatch"); |
| 289 | static_assert(9 == SkXfermode::kSrcATop_Mode, "xfermode_mismatch"); |
| 290 | static_assert(10 == SkXfermode::kDstATop_Mode, "xfermode_mismatch"); |
| 291 | static_assert(11 == SkXfermode::kXor_Mode, "xfermode_mismatch"); |
| 292 | static_assert(16 == SkXfermode::kDarken_Mode, "xfermode_mismatch"); |
| 293 | static_assert(17 == SkXfermode::kLighten_Mode, "xfermode_mismatch"); |
| 294 | static_assert(13 == SkXfermode::kModulate_Mode, "xfermode_mismatch"); |
| 295 | static_assert(14 == SkXfermode::kScreen_Mode, "xfermode_mismatch"); |
| 296 | static_assert(12 == SkXfermode::kPlus_Mode, "xfermode_mismatch"); |
| 297 | static_assert(15 == SkXfermode::kOverlay_Mode, "xfermode_mismatch"); |
| 298 | |
| 299 | SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(xfermodeHandle); |
| 300 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 301 | paint->setXfermodeMode(mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 303 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 304 | static jlong setPathEffect(JNIEnv* env, jobject clazz, jlong objHandle, jlong effectHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 305 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 306 | SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle); |
| 307 | return reinterpret_cast<jlong>(obj->setPathEffect(effect)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 309 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 310 | static jlong setMaskFilter(JNIEnv* env, jobject clazz, jlong objHandle, jlong maskfilterHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 311 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 312 | SkMaskFilter* maskfilter = reinterpret_cast<SkMaskFilter*>(maskfilterHandle); |
| 313 | return reinterpret_cast<jlong>(obj->setMaskFilter(maskfilter)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 315 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 316 | static jlong setTypeface(JNIEnv* env, jobject clazz, jlong objHandle, jlong typefaceHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 317 | // TODO: in Paint refactoring, set typeface on android Paint, not Paint |
Raph Levien | a033630 | 2013-05-22 16:16:59 -0700 | [diff] [blame] | 318 | return NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 320 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 321 | static jlong setRasterizer(JNIEnv* env, jobject clazz, jlong objHandle, jlong rasterizerHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 322 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 323 | SkAutoTUnref<SkRasterizer> rasterizer(GraphicsJNI::refNativeRasterizer(rasterizerHandle)); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 324 | return reinterpret_cast<jlong>(obj->setRasterizer(rasterizer)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 326 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 327 | static jint getTextAlign(JNIEnv* env, jobject clazz, jlong objHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 328 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 329 | return static_cast<jint>(obj->getTextAlign()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 331 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 332 | static void setTextAlign(JNIEnv* env, jobject clazz, jlong objHandle, jint alignHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 333 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 334 | Paint::Align align = static_cast<Paint::Align>(alignHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | obj->setTextAlign(align); |
| 336 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 337 | |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 338 | static jint setTextLocales(JNIEnv* env, jobject clazz, jlong objHandle, jstring locales) { |
Roozbeh Pournader | f036ead | 2015-10-19 16:56:39 -0700 | [diff] [blame] | 339 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 340 | ScopedUtfChars localesChars(env, locales); |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 341 | jint minikinLangListId = minikin::FontStyle::registerLanguageList(localesChars.c_str()); |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 342 | obj->setMinikinLangListId(minikinLangListId); |
| 343 | return minikinLangListId; |
| 344 | } |
Roozbeh Pournader | f036ead | 2015-10-19 16:56:39 -0700 | [diff] [blame] | 345 | |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 346 | static void setTextLocalesByMinikinLangListId(JNIEnv* env, jobject clazz, jlong objHandle, |
| 347 | jint minikinLangListId) { |
| 348 | Paint* obj = reinterpret_cast<Paint*>(objHandle); |
| 349 | obj->setMinikinLangListId(minikinLangListId); |
Fabrice Di Meglio | 517825f | 2012-04-06 16:53:48 -0700 | [diff] [blame] | 350 | } |
| 351 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 352 | static jboolean isElegantTextHeight(JNIEnv* env, jobject, jlong paintHandle) { |
| 353 | Paint* obj = reinterpret_cast<Paint*>(paintHandle); |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 354 | return obj->getFontVariant() == minikin::VARIANT_ELEGANT; |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 355 | } |
| 356 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 357 | static void setElegantTextHeight(JNIEnv* env, jobject, jlong paintHandle, jboolean aa) { |
| 358 | Paint* obj = reinterpret_cast<Paint*>(paintHandle); |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 359 | obj->setFontVariant(aa ? minikin::VARIANT_ELEGANT : minikin::VARIANT_DEFAULT); |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 360 | } |
| 361 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 362 | static jfloat getTextSize(JNIEnv* env, jobject, jlong paintHandle) { |
| 363 | return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getTextSize()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 365 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 366 | static void setTextSize(JNIEnv* env, jobject, jlong paintHandle, jfloat textSize) { |
| 367 | reinterpret_cast<Paint*>(paintHandle)->setTextSize(textSize); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 369 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 370 | static jfloat getTextScaleX(JNIEnv* env, jobject, jlong paintHandle) { |
| 371 | return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getTextScaleX()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 373 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 374 | static void setTextScaleX(JNIEnv* env, jobject, jlong paintHandle, jfloat scaleX) { |
| 375 | reinterpret_cast<Paint*>(paintHandle)->setTextScaleX(scaleX); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 377 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 378 | static jfloat getTextSkewX(JNIEnv* env, jobject, jlong paintHandle) { |
| 379 | return SkScalarToFloat(reinterpret_cast<Paint*>(paintHandle)->getTextSkewX()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 381 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 382 | static void setTextSkewX(JNIEnv* env, jobject, jlong paintHandle, jfloat skewX) { |
| 383 | reinterpret_cast<Paint*>(paintHandle)->setTextSkewX(skewX); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 385 | |
Behdad Esfahbod | fa80f74 | 2014-07-17 19:10:39 -0400 | [diff] [blame] | 386 | static jfloat getLetterSpacing(JNIEnv* env, jobject clazz, jlong paintHandle) { |
| 387 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 388 | return paint->getLetterSpacing(); |
| 389 | } |
| 390 | |
| 391 | static void setLetterSpacing(JNIEnv* env, jobject clazz, jlong paintHandle, jfloat letterSpacing) { |
| 392 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 393 | paint->setLetterSpacing(letterSpacing); |
| 394 | } |
| 395 | |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 396 | static void setFontFeatureSettings(JNIEnv* env, jobject clazz, jlong paintHandle, jstring settings) { |
| 397 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Behdad Esfahbod | e9ad393 | 2014-07-30 19:46:53 -0400 | [diff] [blame] | 398 | if (!settings) { |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 399 | paint->setFontFeatureSettings(std::string()); |
Behdad Esfahbod | e9ad393 | 2014-07-30 19:46:53 -0400 | [diff] [blame] | 400 | } else { |
Behdad Esfahbod | 805f6eb | 2014-07-29 18:43:03 -0400 | [diff] [blame] | 401 | ScopedUtfChars settingsChars(env, settings); |
| 402 | paint->setFontFeatureSettings(std::string(settingsChars.c_str(), settingsChars.size())); |
| 403 | } |
| 404 | } |
| 405 | |
Raph Levien | 210a189 | 2015-03-09 14:42:14 -0700 | [diff] [blame] | 406 | static jint getHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) { |
| 407 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 408 | return paint->getHyphenEdit(); |
| 409 | } |
| 410 | |
| 411 | static void setHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) { |
| 412 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 413 | paint->setHyphenEdit((uint32_t)hyphen); |
| 414 | } |
| 415 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 416 | static SkScalar getMetricsInternal(jlong paintHandle, jlong typefaceHandle, |
| 417 | Paint::FontMetrics *metrics) { |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 418 | const int kElegantTop = 2500; |
| 419 | const int kElegantBottom = -1000; |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 420 | const int kElegantAscent = 1900; |
| 421 | const int kElegantDescent = -500; |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 422 | const int kElegantLeading = 0; |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 423 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 424 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
| 425 | typeface = Typeface::resolveDefault(typeface); |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 426 | minikin::FakedFont baseFont = typeface->fFontCollection->baseFontFaked(typeface->fStyle); |
Raph Levien | 0627ec0 | 2014-06-06 22:31:15 -0700 | [diff] [blame] | 427 | float saveSkewX = paint->getTextSkewX(); |
| 428 | bool savefakeBold = paint->isFakeBoldText(); |
Raph Levien | 1fc0fa8 | 2014-06-06 18:05:22 -0700 | [diff] [blame] | 429 | MinikinFontSkia::populateSkPaint(paint, baseFont.font, baseFont.fakery); |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 430 | SkScalar spacing = paint->getFontMetrics(metrics); |
Raph Levien | 0627ec0 | 2014-06-06 22:31:15 -0700 | [diff] [blame] | 431 | // The populateSkPaint call may have changed fake bold / text skew |
| 432 | // because we want to measure with those effects applied, so now |
| 433 | // restore the original settings. |
| 434 | paint->setTextSkewX(saveSkewX); |
| 435 | paint->setFakeBoldText(savefakeBold); |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 436 | if (paint->getFontVariant() == minikin::VARIANT_ELEGANT) { |
Raph Levien | 53c0077 | 2014-04-14 14:11:02 -0700 | [diff] [blame] | 437 | SkScalar size = paint->getTextSize(); |
| 438 | metrics->fTop = -size * kElegantTop / 2048; |
| 439 | metrics->fBottom = -size * kElegantBottom / 2048; |
| 440 | metrics->fAscent = -size * kElegantAscent / 2048; |
| 441 | metrics->fDescent = -size * kElegantDescent / 2048; |
| 442 | metrics->fLeading = size * kElegantLeading / 2048; |
| 443 | spacing = metrics->fDescent - metrics->fAscent + metrics->fLeading; |
| 444 | } |
| 445 | return spacing; |
| 446 | } |
| 447 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 448 | static jfloat ascent(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 449 | Paint::FontMetrics metrics; |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 450 | getMetricsInternal(paintHandle, typefaceHandle, &metrics); |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 451 | return SkScalarToFloat(metrics.fAscent); |
| 452 | } |
| 453 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 454 | static jfloat descent(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 455 | Paint::FontMetrics metrics; |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 456 | getMetricsInternal(paintHandle, typefaceHandle, &metrics); |
Raph Levien | 817ef4a | 2014-06-05 22:38:08 -0700 | [diff] [blame] | 457 | return SkScalarToFloat(metrics.fDescent); |
| 458 | } |
| 459 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 460 | static jfloat getFontMetrics(JNIEnv* env, jobject, jlong paintHandle, |
| 461 | jlong typefaceHandle, jobject metricsObj) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 462 | Paint::FontMetrics metrics; |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 463 | SkScalar spacing = getMetricsInternal(paintHandle, typefaceHandle, &metrics); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | |
| 465 | if (metricsObj) { |
| 466 | SkASSERT(env->IsInstanceOf(metricsObj, gFontMetrics_class)); |
| 467 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.top, SkScalarToFloat(metrics.fTop)); |
| 468 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.ascent, SkScalarToFloat(metrics.fAscent)); |
| 469 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.descent, SkScalarToFloat(metrics.fDescent)); |
| 470 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.bottom, SkScalarToFloat(metrics.fBottom)); |
| 471 | env->SetFloatField(metricsObj, gFontMetrics_fieldID.leading, SkScalarToFloat(metrics.fLeading)); |
| 472 | } |
| 473 | return SkScalarToFloat(spacing); |
| 474 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 475 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 476 | static jint getFontMetricsInt(JNIEnv* env, jobject, jlong paintHandle, |
| 477 | jlong typefaceHandle, jobject metricsObj) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 478 | Paint::FontMetrics metrics; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 479 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 480 | getMetricsInternal(paintHandle, typefaceHandle, &metrics); |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 481 | int ascent = SkScalarRoundToInt(metrics.fAscent); |
| 482 | int descent = SkScalarRoundToInt(metrics.fDescent); |
| 483 | int leading = SkScalarRoundToInt(metrics.fLeading); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | |
| 485 | if (metricsObj) { |
| 486 | SkASSERT(env->IsInstanceOf(metricsObj, gFontMetricsInt_class)); |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 487 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.top, SkScalarFloorToInt(metrics.fTop)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.ascent, ascent); |
| 489 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.descent, descent); |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 490 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.bottom, SkScalarCeilToInt(metrics.fBottom)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | env->SetIntField(metricsObj, gFontMetricsInt_fieldID.leading, leading); |
| 492 | } |
| 493 | return descent - ascent + leading; |
| 494 | } |
| 495 | |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 496 | static jfloat doTextAdvances(JNIEnv *env, Paint *paint, Typeface* typeface, |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 497 | const jchar *text, jint start, jint count, jint contextCount, jint bidiFlags, |
| 498 | jfloatArray advances, jint advancesIndex) { |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 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); |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 510 | if ((size_t)(count + advancesIndex) > advancesLength) { |
Fabrice Di Meglio | 6ab90ed | 2011-08-08 16:19:38 -0700 | [diff] [blame] | 511 | doThrowAIOOBE(env); |
| 512 | return 0; |
| 513 | } |
| 514 | } |
Keisuke Kuroyanagi | a3024bd | 2015-09-16 20:02:15 -0700 | [diff] [blame] | 515 | std::unique_ptr<jfloat[]> advancesArray; |
| 516 | if (advances) { |
| 517 | advancesArray.reset(new jfloat[count]); |
| 518 | } |
| 519 | const float advance = MinikinUtils::measureText(paint, bidiFlags, typeface, text, |
| 520 | start, count, contextCount, advancesArray.get()); |
| 521 | if (advances) { |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 522 | env->SetFloatArrayRegion(advances, advancesIndex, count, advancesArray.get()); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 523 | } |
Keisuke Kuroyanagi | a3024bd | 2015-09-16 20:02:15 -0700 | [diff] [blame] | 524 | return advance; |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 527 | static jfloat getTextAdvances___CIIIII_FI(JNIEnv* env, jobject clazz, jlong paintHandle, |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 528 | jlong typefaceHandle, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 529 | jcharArray text, jint index, jint count, jint contextIndex, jint contextCount, |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 530 | jint bidiFlags, jfloatArray advances, jint advancesIndex) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 531 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 532 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 533 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 534 | jfloat result = doTextAdvances(env, paint, typeface, textArray + contextIndex, |
| 535 | index - contextIndex, count, contextCount, bidiFlags, advances, advancesIndex); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 536 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 537 | return result; |
| 538 | } |
| 539 | |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 540 | static jfloat getTextAdvances__StringIIIII_FI(JNIEnv* env, jobject clazz, jlong paintHandle, |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 541 | jlong typefaceHandle, |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 542 | jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint bidiFlags, |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 543 | jfloatArray advances, jint advancesIndex) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 544 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 545 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 546 | const jchar* textArray = env->GetStringChars(text, NULL); |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 547 | jfloat result = doTextAdvances(env, paint, typeface, textArray + contextStart, |
| 548 | start - contextStart, end - start, contextEnd - contextStart, bidiFlags, |
Fabrice Di Meglio | 665f02c | 2013-03-20 14:56:05 -0700 | [diff] [blame] | 549 | advances, advancesIndex); |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 550 | env->ReleaseStringChars(text, textArray); |
| 551 | return result; |
| 552 | } |
| 553 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 554 | static jint doTextRunCursor(JNIEnv *env, Paint* paint, const jchar *text, jint start, |
Fabrice Di Meglio | a4bf811 | 2013-03-15 11:22:29 -0700 | [diff] [blame] | 555 | jint count, jint flags, jint offset, jint opt) { |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 556 | minikin::GraphemeBreak::MoveOpt moveOpt = minikin::GraphemeBreak::MoveOpt(opt); |
| 557 | size_t result = minikin::GraphemeBreak::getTextRunCursor(text, start, count, offset, |
| 558 | moveOpt); |
Raph Levien | e368b6b | 2014-06-15 17:37:57 -0700 | [diff] [blame] | 559 | return static_cast<jint>(result); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 562 | static jint getTextRunCursor___C(JNIEnv* env, jobject clazz, jlong paintHandle, jcharArray text, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 563 | jint contextStart, jint contextCount, jint dir, jint offset, jint cursorOpt) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 564 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 565 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 566 | jint result = doTextRunCursor(env, paint, textArray, contextStart, contextCount, dir, |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 567 | offset, cursorOpt); |
| 568 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 569 | return result; |
| 570 | } |
| 571 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 572 | static jint getTextRunCursor__String(JNIEnv* env, jobject clazz, jlong paintHandle, jstring text, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 573 | jint contextStart, jint contextEnd, jint dir, jint offset, jint cursorOpt) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 574 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 575 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 576 | jint result = doTextRunCursor(env, paint, textArray, contextStart, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 577 | contextEnd - contextStart, dir, offset, cursorOpt); |
Doug Felt | 0c702b8 | 2010-05-14 10:55:42 -0700 | [diff] [blame] | 578 | env->ReleaseStringChars(text, textArray); |
| 579 | return result; |
| 580 | } |
| 581 | |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 582 | class GetTextFunctor { |
| 583 | public: |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 584 | GetTextFunctor(const minikin::Layout& layout, SkPath* path, jfloat x, jfloat y, |
| 585 | Paint* paint, uint16_t* glyphs, SkPoint* pos) |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 586 | : layout(layout), path(path), x(x), y(y), paint(paint), glyphs(glyphs), pos(pos) { |
| 587 | } |
| 588 | |
Raph Levien | 1fc0fa8 | 2014-06-06 18:05:22 -0700 | [diff] [blame] | 589 | void operator()(size_t start, size_t end) { |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 590 | for (size_t i = start; i < end; i++) { |
| 591 | glyphs[i] = layout.getGlyphId(i); |
| 592 | pos[i].fX = x + layout.getX(i); |
| 593 | pos[i].fY = y + layout.getY(i); |
| 594 | } |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 595 | if (start == 0) { |
| 596 | paint->getPosTextPath(glyphs + start, (end - start) << 1, pos + start, path); |
| 597 | } else { |
| 598 | paint->getPosTextPath(glyphs + start, (end - start) << 1, pos + start, &tmpPath); |
| 599 | path->addPath(tmpPath); |
| 600 | } |
| 601 | } |
| 602 | private: |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 603 | const minikin::Layout& layout; |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 604 | SkPath* path; |
| 605 | jfloat x; |
| 606 | jfloat y; |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 607 | Paint* paint; |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 608 | uint16_t* glyphs; |
| 609 | SkPoint* pos; |
| 610 | SkPath tmpPath; |
| 611 | }; |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 612 | |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 613 | static void getTextPath(JNIEnv* env, Paint* paint, Typeface* typeface, const jchar* text, |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 614 | jint count, jint bidiFlags, jfloat x, jfloat y, SkPath* path) { |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 615 | minikin::Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 616 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 617 | size_t nGlyphs = layout.nGlyphs(); |
| 618 | uint16_t* glyphs = new uint16_t[nGlyphs]; |
| 619 | SkPoint* pos = new SkPoint[nGlyphs]; |
| 620 | |
| 621 | x += MinikinUtils::xOffsetForTextAlign(paint, layout); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 622 | Paint::Align align = paint->getTextAlign(); |
| 623 | paint->setTextAlign(Paint::kLeft_Align); |
| 624 | paint->setTextEncoding(Paint::kGlyphID_TextEncoding); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 625 | GetTextFunctor f(layout, path, x, y, paint, glyphs, pos); |
Raph Levien | 1fc0fa8 | 2014-06-06 18:05:22 -0700 | [diff] [blame] | 626 | MinikinUtils::forFontRun(layout, paint, f); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 627 | paint->setTextAlign(align); |
| 628 | delete[] glyphs; |
| 629 | delete[] pos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 631 | |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 632 | static void getTextPath___C(JNIEnv* env, jobject clazz, jlong paintHandle, |
| 633 | jlong typefaceHandle, jint bidiFlags, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 634 | jcharArray text, jint index, jint count, jfloat x, jfloat y, jlong pathHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 635 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 636 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 637 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 638 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 639 | getTextPath(env, paint, typeface, textArray + index, count, bidiFlags, x, y, path); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 640 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); |
| 641 | } |
| 642 | |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 643 | static void getTextPath__String(JNIEnv* env, jobject clazz, jlong paintHandle, |
| 644 | jlong typefaceHandle, jint bidiFlags, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 645 | jstring text, jint start, jint end, jfloat x, jfloat y, jlong pathHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 646 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 647 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 648 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | const jchar* textArray = env->GetStringChars(text, NULL); |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 650 | getTextPath(env, paint, typeface, textArray + start, end - start, bidiFlags, x, y, path); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | env->ReleaseStringChars(text, textArray); |
| 652 | } |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 653 | |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 654 | static void setShadowLayer(JNIEnv* env, jobject clazz, jlong paintHandle, jfloat radius, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 655 | jfloat dx, jfloat dy, jint color) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 656 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | if (radius <= 0) { |
| 658 | paint->setLooper(NULL); |
| 659 | } |
| 660 | else { |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 661 | SkScalar sigma = android::uirenderer::Blur::convertRadiusToSigma(radius); |
Victoria Lease | 49f0db3 | 2014-05-19 16:00:17 -0700 | [diff] [blame] | 662 | paint->setLooper(SkBlurDrawLooper::Create((SkColor)color, sigma, dx, dy))->unref(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 666 | static jboolean hasShadowLayer(JNIEnv* env, jobject clazz, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 667 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | c29a0a4 | 2014-03-31 13:52:39 -0400 | [diff] [blame] | 668 | return paint->getLooper() && paint->getLooper()->asABlurShadow(NULL); |
| 669 | } |
| 670 | |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 671 | static int breakText(JNIEnv* env, const Paint& paint, Typeface* typeface, const jchar text[], |
Victoria Lease | 626d3c2 | 2013-03-27 15:35:53 -0700 | [diff] [blame] | 672 | int count, float maxWidth, jint bidiFlags, jfloatArray jmeasured, |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 673 | const bool forwardScan) { |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 674 | size_t measuredCount = 0; |
| 675 | float measured = 0; |
| 676 | |
Keisuke Kuroyanagi | 4c8a526 | 2016-02-18 11:31:56 -0800 | [diff] [blame] | 677 | std::unique_ptr<float[]> advancesArray(new float[count]); |
| 678 | MinikinUtils::measureText(&paint, bidiFlags, typeface, text, 0, count, count, |
| 679 | advancesArray.get()); |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 680 | |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 681 | for (int i = 0; i < count; i++) { |
| 682 | // traverse in the given direction |
| 683 | int index = forwardScan ? i : (count - i - 1); |
Keisuke Kuroyanagi | 4c8a526 | 2016-02-18 11:31:56 -0800 | [diff] [blame] | 684 | float width = advancesArray[index]; |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 685 | if (measured + width > maxWidth) { |
| 686 | break; |
| 687 | } |
| 688 | // properly handle clusters when scanning backwards |
| 689 | if (forwardScan || width != 0.0f) { |
| 690 | measuredCount = i + 1; |
| 691 | } |
| 692 | measured += width; |
| 693 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | |
| 695 | if (jmeasured && env->GetArrayLength(jmeasured) > 0) { |
| 696 | AutoJavaFloatArray autoMeasured(env, jmeasured, 1); |
| 697 | jfloat* array = autoMeasured.ptr(); |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 698 | array[0] = measured; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | } |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 700 | return measuredCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | } |
| 702 | |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 703 | static jint breakTextC(JNIEnv* env, jobject clazz, jlong paintHandle, jlong typefaceHandle, jcharArray jtext, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 704 | jint index, jint count, jfloat maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 706 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 707 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 708 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 709 | |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 710 | bool forwardTextDirection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 711 | if (count < 0) { |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 712 | forwardTextDirection = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | count = -count; |
| 714 | } |
| 715 | else { |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 716 | forwardTextDirection = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | if ((index < 0) || (index + count > env->GetArrayLength(jtext))) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 720 | doThrowAIOOBE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | return 0; |
| 722 | } |
| 723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | const jchar* text = env->GetCharArrayElements(jtext, NULL); |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 725 | count = breakText(env, *paint, typeface, text + index, count, maxWidth, |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 726 | bidiFlags, jmeasuredWidth, forwardTextDirection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | env->ReleaseCharArrayElements(jtext, const_cast<jchar*>(text), |
| 728 | JNI_ABORT); |
| 729 | return count; |
| 730 | } |
| 731 | |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 732 | static jint breakTextS(JNIEnv* env, jobject clazz, jlong paintHandle, jlong typefaceHandle, jstring jtext, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 733 | jboolean forwards, jfloat maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 734 | NPE_CHECK_RETURN_ZERO(env, jtext); |
| 735 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 736 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 737 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
Anish Athalye | a7aa1b0 | 2014-06-12 12:53:09 -0700 | [diff] [blame] | 738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | int count = env->GetStringLength(jtext); |
| 740 | const jchar* text = env->GetStringChars(jtext, NULL); |
Derek Sollenberger | 57c4fed | 2014-10-08 09:23:32 -0400 | [diff] [blame] | 741 | count = breakText(env, *paint, typeface, text, count, maxWidth, bidiFlags, jmeasuredWidth, forwards); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | env->ReleaseStringChars(jtext, text); |
| 743 | return count; |
| 744 | } |
| 745 | |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 746 | static void doTextBounds(JNIEnv* env, const jchar* text, int count, jobject bounds, |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 747 | const Paint& paint, Typeface* typeface, jint bidiFlags) { |
Romain Guy | 059e12c | 2012-11-28 17:35:51 -0800 | [diff] [blame] | 748 | SkRect r; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | SkIRect ir; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 750 | |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 751 | minikin::Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 752 | MinikinUtils::doLayout(&layout, &paint, bidiFlags, typeface, text, 0, count, count); |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 753 | minikin::MinikinRect rect; |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 754 | layout.getBounds(&rect); |
| 755 | r.fLeft = rect.mLeft; |
| 756 | r.fTop = rect.mTop; |
| 757 | r.fRight = rect.mRight; |
| 758 | r.fBottom = rect.mBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | r.roundOut(&ir); |
| 760 | GraphicsJNI::irect_to_jrect(ir, env, bounds); |
| 761 | } |
| 762 | |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 763 | static void getStringBounds(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 764 | jstring text, jint start, jint end, jint bidiFlags, jobject bounds) { |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 765 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 766 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | const jchar* textArray = env->GetStringChars(text, NULL); |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 768 | doTextBounds(env, textArray + start, end - start, bounds, *paint, typeface, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | env->ReleaseStringChars(text, textArray); |
| 770 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 771 | |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 772 | static void getCharArrayBounds(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 773 | jcharArray text, jint index, jint count, jint bidiFlags, jobject bounds) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 774 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 775 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | const jchar* textArray = env->GetCharArrayElements(text, NULL); |
Raph Levien | 854363e | 2014-06-03 19:56:05 -0700 | [diff] [blame] | 777 | doTextBounds(env, textArray + index, count, bounds, *paint, typeface, bidiFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), |
| 779 | JNI_ABORT); |
| 780 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 781 | |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 782 | static jboolean layoutContainsNotdef(const minikin::Layout& layout) { |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 783 | for (size_t i = 0; i < layout.nGlyphs(); i++) { |
| 784 | if (layout.getGlyphId(i) == 0) { |
| 785 | return true; |
| 786 | } |
| 787 | } |
| 788 | return false; |
| 789 | } |
| 790 | |
Raph Levien | 6141db3 | 2016-07-11 13:59:58 -0700 | [diff] [blame] | 791 | // Don't count glyphs that are the recommended "space" glyph and are zero width. |
| 792 | // This logic makes assumptions about HarfBuzz layout, but does correctly handle |
| 793 | // cases where ligatures form and zero width space glyphs are left in as |
| 794 | // placeholders. |
| 795 | static size_t countNonSpaceGlyphs(const minikin::Layout& layout) { |
| 796 | size_t count = 0; |
| 797 | static unsigned int kSpaceGlyphId = 3; |
| 798 | for (size_t i = 0; i < layout.nGlyphs(); i++) { |
| 799 | if (layout.getGlyphId(i) != kSpaceGlyphId || layout.getCharAdvance(i) != 0.0) { |
| 800 | count++; |
| 801 | } |
| 802 | } |
| 803 | return count; |
| 804 | } |
| 805 | |
Seigo Nonaka | 589cddc | 2016-04-05 14:43:14 +0900 | [diff] [blame] | 806 | // Returns true if the given string is exact one pair of regional indicators. |
| 807 | static bool isFlag(const jchar* str, size_t length) { |
| 808 | const jchar RI_LEAD_SURROGATE = 0xD83C; |
| 809 | const jchar RI_TRAIL_SURROGATE_MIN = 0xDDE6; |
| 810 | const jchar RI_TRAIL_SURROGATE_MAX = 0xDDFF; |
| 811 | |
| 812 | if (length != 4) { |
| 813 | return false; |
| 814 | } |
| 815 | if (str[0] != RI_LEAD_SURROGATE || str[2] != RI_LEAD_SURROGATE) { |
| 816 | return false; |
| 817 | } |
| 818 | return RI_TRAIL_SURROGATE_MIN <= str[1] && str[1] <= RI_TRAIL_SURROGATE_MAX && |
| 819 | RI_TRAIL_SURROGATE_MIN <= str[3] && str[3] <= RI_TRAIL_SURROGATE_MAX; |
| 820 | } |
| 821 | |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 822 | static jboolean hasGlyph(JNIEnv *env, jclass, jlong paintHandle, jlong typefaceHandle, |
| 823 | jint bidiFlags, jstring string) { |
| 824 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 825 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 826 | ScopedStringChars str(env, string); |
| 827 | |
Seigo Nonaka | bb1a966 | 2015-10-21 23:24:25 +0900 | [diff] [blame] | 828 | /* Start by rejecting unsupported base code point and variation selector pairs. */ |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 829 | size_t nChars = 0; |
Seigo Nonaka | bb1a966 | 2015-10-21 23:24:25 +0900 | [diff] [blame] | 830 | const uint32_t kStartOfString = 0xFFFFFFFF; |
| 831 | uint32_t prevCp = kStartOfString; |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 832 | for (size_t i = 0; i < str.size(); i++) { |
Seigo Nonaka | bb1a966 | 2015-10-21 23:24:25 +0900 | [diff] [blame] | 833 | jchar cu = str[i]; |
| 834 | uint32_t cp = cu; |
| 835 | if (U16_IS_TRAIL(cu)) { |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 836 | // invalid UTF-16, unpaired trailing surrogate |
| 837 | return false; |
Seigo Nonaka | bb1a966 | 2015-10-21 23:24:25 +0900 | [diff] [blame] | 838 | } else if (U16_IS_LEAD(cu)) { |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 839 | if (i + 1 == str.size()) { |
| 840 | // invalid UTF-16, unpaired leading surrogate at end of string |
| 841 | return false; |
| 842 | } |
| 843 | i++; |
Seigo Nonaka | bb1a966 | 2015-10-21 23:24:25 +0900 | [diff] [blame] | 844 | jchar cu2 = str[i]; |
| 845 | if (!U16_IS_TRAIL(cu2)) { |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 846 | // invalid UTF-16, unpaired leading surrogate |
| 847 | return false; |
| 848 | } |
Seigo Nonaka | bb1a966 | 2015-10-21 23:24:25 +0900 | [diff] [blame] | 849 | cp = U16_GET_SUPPLEMENTARY(cu, cu2); |
| 850 | } |
| 851 | |
| 852 | if (prevCp != kStartOfString && |
Raph Levien | 032a359 | 2016-04-14 21:22:37 -0700 | [diff] [blame] | 853 | ((0xFE00 <= cp && cp <= 0xFE0F) || (0xE0100 <= cp && cp <= 0xE01EF))) { |
| 854 | bool hasVS = MinikinUtils::hasVariationSelector(typeface, prevCp, cp); |
| 855 | if (!hasVS) { |
| 856 | // No font has a glyph for the code point and variation selector pair. |
| 857 | return false; |
| 858 | } else if (nChars == 1 && i + 1 == str.size()) { |
| 859 | // The string is just a codepoint and a VS, we have an authoritative answer |
| 860 | return true; |
| 861 | } |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 862 | } |
| 863 | nChars++; |
Seigo Nonaka | bb1a966 | 2015-10-21 23:24:25 +0900 | [diff] [blame] | 864 | prevCp = cp; |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 865 | } |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 866 | minikin::Layout layout; |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 867 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, str.get(), 0, str.size(), |
| 868 | str.size()); |
Raph Levien | 6141db3 | 2016-07-11 13:59:58 -0700 | [diff] [blame] | 869 | size_t nGlyphs = countNonSpaceGlyphs(layout); |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 870 | if (nGlyphs != 1 && nChars > 1) { |
| 871 | // multiple-character input, and was not a ligature |
| 872 | // TODO: handle ZWJ/ZWNJ characters specially so we can detect certain ligatures |
| 873 | // in joining scripts, such as Arabic and Mongolian. |
| 874 | return false; |
| 875 | } |
Seigo Nonaka | 589cddc | 2016-04-05 14:43:14 +0900 | [diff] [blame] | 876 | |
| 877 | if (nGlyphs == 0 || layoutContainsNotdef(layout)) { |
| 878 | return false; // The collection doesn't have a glyph. |
| 879 | } |
| 880 | |
| 881 | if (nChars == 2 && isFlag(str.get(), str.size())) { |
| 882 | // Some font may have a special glyph for unsupported regional indicator pairs. |
| 883 | // To return false for this case, need to compare the glyph id with the one of ZZ |
| 884 | // since ZZ is reserved for unknown or invalid territory. |
| 885 | // U+1F1FF (REGIONAL INDICATOR SYMBOL LETTER Z) is \uD83C\uDDFF in UTF16. |
| 886 | static const jchar ZZ_FLAG_STR[] = { 0xD83C, 0xDDFF, 0xD83C, 0xDDFF }; |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 887 | minikin::Layout zzLayout; |
Seigo Nonaka | 589cddc | 2016-04-05 14:43:14 +0900 | [diff] [blame] | 888 | MinikinUtils::doLayout(&zzLayout, paint, bidiFlags, typeface, ZZ_FLAG_STR, 0, 4, 4); |
| 889 | if (zzLayout.nGlyphs() != 1 || layoutContainsNotdef(zzLayout)) { |
| 890 | // The font collection doesn't have a glyph for unknown flag. Just return true. |
| 891 | return true; |
| 892 | } |
| 893 | return zzLayout.getGlyphId(0) != layout.getGlyphId(0); |
| 894 | } |
| 895 | return true; |
Raph Levien | f7f969e6 | 2015-04-01 14:41:21 -0700 | [diff] [blame] | 896 | } |
| 897 | |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 898 | static jfloat doRunAdvance(const Paint* paint, Typeface* typeface, const jchar buf[], |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 899 | jint start, jint count, jint bufSize, jboolean isRtl, jint offset) { |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 900 | int bidiFlags = isRtl ? minikin::kBidi_Force_RTL : minikin::kBidi_Force_LTR; |
Keisuke Kuroyanagi | b367771 | 2016-03-28 19:16:30 +0900 | [diff] [blame] | 901 | if (offset == start + count) { |
Keisuke Kuroyanagi | 4c8a526 | 2016-02-18 11:31:56 -0800 | [diff] [blame] | 902 | return MinikinUtils::measureText(paint, bidiFlags, typeface, buf, start, count, |
| 903 | bufSize, nullptr); |
| 904 | } |
| 905 | std::unique_ptr<float[]> advancesArray(new float[count]); |
| 906 | MinikinUtils::measureText(paint, bidiFlags, typeface, buf, start, count, bufSize, |
| 907 | advancesArray.get()); |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 908 | return minikin::getRunAdvance(advancesArray.get(), buf, start, count, offset); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static jfloat getRunAdvance___CIIIIZI_F(JNIEnv *env, jclass, jlong paintHandle, |
| 912 | jlong typefaceHandle, jcharArray text, jint start, jint end, jint contextStart, |
| 913 | jint contextEnd, jboolean isRtl, jint offset) { |
| 914 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 915 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame] | 916 | jchar* textArray = (jchar*) env->GetPrimitiveArrayCritical(text, NULL); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 917 | jfloat result = doRunAdvance(paint, typeface, textArray + contextStart, |
Raph Levien | 36ff86c | 2015-06-03 10:58:33 -0700 | [diff] [blame] | 918 | start - contextStart, end - start, contextEnd - contextStart, isRtl, |
| 919 | offset - contextStart); |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame] | 920 | env->ReleasePrimitiveArrayCritical(text, textArray, JNI_ABORT); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 921 | return result; |
| 922 | } |
| 923 | |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 924 | static jint doOffsetForAdvance(const Paint* paint, Typeface* typeface, const jchar buf[], |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 925 | jint start, jint count, jint bufSize, jboolean isRtl, jfloat advance) { |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 926 | int bidiFlags = isRtl ? minikin::kBidi_Force_RTL : minikin::kBidi_Force_LTR; |
Keisuke Kuroyanagi | 4c8a526 | 2016-02-18 11:31:56 -0800 | [diff] [blame] | 927 | std::unique_ptr<float[]> advancesArray(new float[count]); |
| 928 | MinikinUtils::measureText(paint, bidiFlags, typeface, buf, start, count, bufSize, |
| 929 | advancesArray.get()); |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 930 | return minikin::getOffsetForAdvance(advancesArray.get(), buf, start, count, advance); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 931 | } |
Keisuke Kuroyanagi | 4c8a526 | 2016-02-18 11:31:56 -0800 | [diff] [blame] | 932 | |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 933 | static jint getOffsetForAdvance___CIIIIZF_I(JNIEnv *env, jclass, jlong paintHandle, |
| 934 | jlong typefaceHandle, jcharArray text, jint start, jint end, jint contextStart, |
| 935 | jint contextEnd, jboolean isRtl, jfloat advance) { |
| 936 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 937 | Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle); |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame] | 938 | jchar* textArray = (jchar*) env->GetPrimitiveArrayCritical(text, NULL); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 939 | jint result = doOffsetForAdvance(paint, typeface, textArray + contextStart, |
| 940 | start - contextStart, end - start, contextEnd - contextStart, isRtl, advance); |
| 941 | result += contextStart; |
John Reck | c6024cd | 2015-07-10 10:55:49 -0700 | [diff] [blame] | 942 | env->ReleasePrimitiveArrayCritical(text, textArray, JNI_ABORT); |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 943 | return result; |
| 944 | } |
| 945 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 946 | }; // namespace PaintGlue |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 948 | static const JNINativeMethod methods[] = { |
Richard Uhler | 775873a | 2015-12-29 12:37:39 -0800 | [diff] [blame] | 949 | {"nGetNativeFinalizer", "()J", (void*) PaintGlue::getNativeFinalizer}, |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 950 | {"nInit","()J", (void*) PaintGlue::init}, |
| 951 | {"nInitWithPaint","(J)J", (void*) PaintGlue::initWithPaint}, |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 952 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 953 | {"nReset","!(J)V", (void*) PaintGlue::reset}, |
| 954 | {"nSet","!(JJ)V", (void*) PaintGlue::assign}, |
| 955 | {"nGetFlags","!(J)I", (void*) PaintGlue::getFlags}, |
| 956 | {"nSetFlags","!(JI)V", (void*) PaintGlue::setFlags}, |
| 957 | {"nGetHinting","!(J)I", (void*) PaintGlue::getHinting}, |
| 958 | {"nSetHinting","!(JI)V", (void*) PaintGlue::setHinting}, |
| 959 | {"nSetAntiAlias","!(JZ)V", (void*) PaintGlue::setAntiAlias}, |
| 960 | {"nSetSubpixelText","!(JZ)V", (void*) PaintGlue::setSubpixelText}, |
| 961 | {"nSetLinearText","!(JZ)V", (void*) PaintGlue::setLinearText}, |
| 962 | {"nSetUnderlineText","!(JZ)V", (void*) PaintGlue::setUnderlineText}, |
| 963 | {"nSetStrikeThruText","!(JZ)V", (void*) PaintGlue::setStrikeThruText}, |
| 964 | {"nSetFakeBoldText","!(JZ)V", (void*) PaintGlue::setFakeBoldText}, |
| 965 | {"nSetFilterBitmap","!(JZ)V", (void*) PaintGlue::setFilterBitmap}, |
| 966 | {"nSetDither","!(JZ)V", (void*) PaintGlue::setDither}, |
| 967 | {"nGetStyle","!(J)I", (void*) PaintGlue::getStyle}, |
| 968 | {"nSetStyle","!(JI)V", (void*) PaintGlue::setStyle}, |
| 969 | {"nGetColor","!(J)I", (void*) PaintGlue::getColor}, |
| 970 | {"nSetColor","!(JI)V", (void*) PaintGlue::setColor}, |
| 971 | {"nGetAlpha","!(J)I", (void*) PaintGlue::getAlpha}, |
| 972 | {"nSetAlpha","!(JI)V", (void*) PaintGlue::setAlpha}, |
| 973 | {"nGetStrokeWidth","!(J)F", (void*) PaintGlue::getStrokeWidth}, |
| 974 | {"nSetStrokeWidth","!(JF)V", (void*) PaintGlue::setStrokeWidth}, |
| 975 | {"nGetStrokeMiter","!(J)F", (void*) PaintGlue::getStrokeMiter}, |
| 976 | {"nSetStrokeMiter","!(JF)V", (void*) PaintGlue::setStrokeMiter}, |
| 977 | {"nGetStrokeCap","!(J)I", (void*) PaintGlue::getStrokeCap}, |
| 978 | {"nSetStrokeCap","!(JI)V", (void*) PaintGlue::setStrokeCap}, |
| 979 | {"nGetStrokeJoin","!(J)I", (void*) PaintGlue::getStrokeJoin}, |
| 980 | {"nSetStrokeJoin","!(JI)V", (void*) PaintGlue::setStrokeJoin}, |
| 981 | {"nGetFillPath","!(JJJ)Z", (void*) PaintGlue::getFillPath}, |
| 982 | {"nSetShader","!(JJ)J", (void*) PaintGlue::setShader}, |
| 983 | {"nSetColorFilter","!(JJ)J", (void*) PaintGlue::setColorFilter}, |
John Reck | 5d31a29 | 2016-09-15 10:13:10 -0700 | [diff] [blame] | 984 | {"nSetXfermode","!(JI)V", (void*) PaintGlue::setXfermode}, |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 985 | {"nSetPathEffect","!(JJ)J", (void*) PaintGlue::setPathEffect}, |
| 986 | {"nSetMaskFilter","!(JJ)J", (void*) PaintGlue::setMaskFilter}, |
| 987 | {"nSetTypeface","!(JJ)J", (void*) PaintGlue::setTypeface}, |
| 988 | {"nSetRasterizer","!(JJ)J", (void*) PaintGlue::setRasterizer}, |
| 989 | {"nGetTextAlign","!(J)I", (void*) PaintGlue::getTextAlign}, |
| 990 | {"nSetTextAlign","!(JI)V", (void*) PaintGlue::setTextAlign}, |
Seigo Nonaka | cfc607c | 2015-12-02 10:53:18 +0900 | [diff] [blame] | 991 | {"nSetTextLocales","!(JLjava/lang/String;)I", (void*) PaintGlue::setTextLocales}, |
| 992 | {"nSetTextLocalesByMinikinLangListId","!(JI)V", |
| 993 | (void*) PaintGlue::setTextLocalesByMinikinLangListId}, |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 994 | {"nIsElegantTextHeight","!(J)Z", (void*) PaintGlue::isElegantTextHeight}, |
| 995 | {"nSetElegantTextHeight","!(JZ)V", (void*) PaintGlue::setElegantTextHeight}, |
| 996 | {"nGetTextSize","!(J)F", (void*) PaintGlue::getTextSize}, |
| 997 | {"nSetTextSize","!(JF)V", (void*) PaintGlue::setTextSize}, |
| 998 | {"nGetTextScaleX","!(J)F", (void*) PaintGlue::getTextScaleX}, |
| 999 | {"nSetTextScaleX","!(JF)V", (void*) PaintGlue::setTextScaleX}, |
| 1000 | {"nGetTextSkewX","!(J)F", (void*) PaintGlue::getTextSkewX}, |
| 1001 | {"nSetTextSkewX","!(JF)V", (void*) PaintGlue::setTextSkewX}, |
| 1002 | {"nGetLetterSpacing","!(J)F", (void*) PaintGlue::getLetterSpacing}, |
| 1003 | {"nSetLetterSpacing","!(JF)V", (void*) PaintGlue::setLetterSpacing}, |
| 1004 | {"nSetFontFeatureSettings","(JLjava/lang/String;)V", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1005 | (void*) PaintGlue::setFontFeatureSettings}, |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1006 | {"nGetHyphenEdit", "!(J)I", (void*) PaintGlue::getHyphenEdit}, |
| 1007 | {"nSetHyphenEdit", "!(JI)V", (void*) PaintGlue::setHyphenEdit}, |
| 1008 | {"nAscent","!(JJ)F", (void*) PaintGlue::ascent}, |
| 1009 | {"nDescent","!(JJ)F", (void*) PaintGlue::descent}, |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 1010 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1011 | {"nGetFontMetrics", "!(JJLandroid/graphics/Paint$FontMetrics;)F", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1012 | (void*)PaintGlue::getFontMetrics}, |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1013 | {"nGetFontMetricsInt", "!(JJLandroid/graphics/Paint$FontMetricsInt;)I", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1014 | (void*)PaintGlue::getFontMetricsInt}, |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 1015 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1016 | {"nBreakText","(JJ[CIIFI[F)I", (void*) PaintGlue::breakTextC}, |
| 1017 | {"nBreakText","(JJLjava/lang/String;ZFI[F)I", (void*) PaintGlue::breakTextS}, |
| 1018 | {"nGetTextAdvances","(JJ[CIIIII[FI)F", |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 1019 | (void*) PaintGlue::getTextAdvances___CIIIII_FI}, |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1020 | {"nGetTextAdvances","(JJLjava/lang/String;IIIII[FI)F", |
Keisuke Kuroyanagi | 536afe6 | 2015-09-29 13:52:45 -0700 | [diff] [blame] | 1021 | (void*) PaintGlue::getTextAdvances__StringIIIII_FI}, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1022 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1023 | {"nGetTextRunCursor", "(J[CIIIII)I", (void*) PaintGlue::getTextRunCursor___C}, |
| 1024 | {"nGetTextRunCursor", "(JLjava/lang/String;IIIII)I", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1025 | (void*) PaintGlue::getTextRunCursor__String}, |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1026 | {"nGetTextPath", "(JJI[CIIFFJ)V", (void*) PaintGlue::getTextPath___C}, |
| 1027 | {"nGetTextPath", "(JJILjava/lang/String;IIFFJ)V", (void*) PaintGlue::getTextPath__String}, |
| 1028 | {"nGetStringBounds", "(JJLjava/lang/String;IIILandroid/graphics/Rect;)V", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1029 | (void*) PaintGlue::getStringBounds }, |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1030 | {"nGetCharArrayBounds", "(JJ[CIIILandroid/graphics/Rect;)V", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1031 | (void*) PaintGlue::getCharArrayBounds }, |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1032 | {"nHasGlyph", "(JJILjava/lang/String;)Z", (void*) PaintGlue::hasGlyph }, |
| 1033 | {"nGetRunAdvance", "(JJ[CIIIIZI)F", (void*) PaintGlue::getRunAdvance___CIIIIZI_F}, |
| 1034 | {"nGetOffsetForAdvance", "(JJ[CIIIIZF)I", |
Raph Levien | a027ec5 | 2015-04-06 16:21:59 -0700 | [diff] [blame] | 1035 | (void*) PaintGlue::getOffsetForAdvance___CIIIIZF_I}, |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 1036 | |
John Reck | dbffd25 | 2015-10-01 14:46:12 -0700 | [diff] [blame] | 1037 | {"nSetShadowLayer", "!(JFFFI)V", (void*)PaintGlue::setShadowLayer}, |
| 1038 | {"nHasShadowLayer", "!(J)Z", (void*)PaintGlue::hasShadowLayer} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | }; |
| 1040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | int register_android_graphics_Paint(JNIEnv* env) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1042 | gFontMetrics_class = FindClassOrDie(env, "android/graphics/Paint$FontMetrics"); |
| 1043 | gFontMetrics_class = MakeGlobalRefOrDie(env, gFontMetrics_class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1045 | gFontMetrics_fieldID.top = GetFieldIDOrDie(env, gFontMetrics_class, "top", "F"); |
| 1046 | gFontMetrics_fieldID.ascent = GetFieldIDOrDie(env, gFontMetrics_class, "ascent", "F"); |
| 1047 | gFontMetrics_fieldID.descent = GetFieldIDOrDie(env, gFontMetrics_class, "descent", "F"); |
| 1048 | gFontMetrics_fieldID.bottom = GetFieldIDOrDie(env, gFontMetrics_class, "bottom", "F"); |
| 1049 | gFontMetrics_fieldID.leading = GetFieldIDOrDie(env, gFontMetrics_class, "leading", "F"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1051 | gFontMetricsInt_class = FindClassOrDie(env, "android/graphics/Paint$FontMetricsInt"); |
| 1052 | gFontMetricsInt_class = MakeGlobalRefOrDie(env, gFontMetricsInt_class); |
Derek Sollenberger | ab22c1c | 2014-09-03 14:12:47 -0400 | [diff] [blame] | 1053 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1054 | gFontMetricsInt_fieldID.top = GetFieldIDOrDie(env, gFontMetricsInt_class, "top", "I"); |
| 1055 | gFontMetricsInt_fieldID.ascent = GetFieldIDOrDie(env, gFontMetricsInt_class, "ascent", "I"); |
| 1056 | gFontMetricsInt_fieldID.descent = GetFieldIDOrDie(env, gFontMetricsInt_class, "descent", "I"); |
| 1057 | gFontMetricsInt_fieldID.bottom = GetFieldIDOrDie(env, gFontMetricsInt_class, "bottom", "I"); |
| 1058 | gFontMetricsInt_fieldID.leading = GetFieldIDOrDie(env, gFontMetricsInt_class, "leading", "I"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1060 | return RegisterMethodsOrDie(env, "android/graphics/Paint", methods, NELEM(methods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | } |