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