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