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