Paint.java revision fee44846376c212114223fc4259382921e6dca7a
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.graphics; 18 19import android.annotation.ColorInt; 20import android.annotation.NonNull; 21import android.annotation.Size; 22import android.text.GraphicsOperations; 23import android.text.SpannableString; 24import android.text.SpannedString; 25import android.text.TextUtils; 26import android.util.LocaleList; 27 28import com.android.internal.annotations.GuardedBy; 29 30import java.util.HashMap; 31import java.util.Locale; 32 33import libcore.util.NativeAllocationRegistry; 34 35/** 36 * The Paint class holds the style and color information about how to draw 37 * geometries, text and bitmaps. 38 */ 39public class Paint { 40 41 private long mNativePaint; 42 private long mNativeShader = 0; 43 44 // The approximate size of a native paint object. 45 private static final long NATIVE_PAINT_SIZE = 98; 46 47 private static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry( 48 nGetNativeFinalizer(), NATIVE_PAINT_SIZE); 49 50 /** 51 * @hide 52 */ 53 public long mNativeTypeface; 54 55 private ColorFilter mColorFilter; 56 private MaskFilter mMaskFilter; 57 private PathEffect mPathEffect; 58 private Rasterizer mRasterizer; 59 private Shader mShader; 60 private Typeface mTypeface; 61 private Xfermode mXfermode; 62 63 private boolean mHasCompatScaling; 64 private float mCompatScaling; 65 private float mInvCompatScaling; 66 67 private LocaleList mLocales; 68 private String mFontFeatureSettings; 69 70 private static final Object sCacheLock = new Object(); 71 72 /** 73 * Cache for the Minikin language list ID. 74 * 75 * A map from a string representation of the LocaleList to Minikin's language list ID. 76 */ 77 @GuardedBy("sCacheLock") 78 private static final HashMap<String, Integer> sMinikinLangListIdCache = new HashMap<>(); 79 80 /** 81 * @hide 82 */ 83 public int mBidiFlags = BIDI_DEFAULT_LTR; 84 85 static final Style[] sStyleArray = { 86 Style.FILL, Style.STROKE, Style.FILL_AND_STROKE 87 }; 88 static final Cap[] sCapArray = { 89 Cap.BUTT, Cap.ROUND, Cap.SQUARE 90 }; 91 static final Join[] sJoinArray = { 92 Join.MITER, Join.ROUND, Join.BEVEL 93 }; 94 static final Align[] sAlignArray = { 95 Align.LEFT, Align.CENTER, Align.RIGHT 96 }; 97 98 /** 99 * Paint flag that enables antialiasing when drawing. 100 * 101 * <p>Enabling this flag will cause all draw operations that support 102 * antialiasing to use it.</p> 103 * 104 * @see #Paint(int) 105 * @see #setFlags(int) 106 */ 107 public static final int ANTI_ALIAS_FLAG = 0x01; 108 /** 109 * Paint flag that enables bilinear sampling on scaled bitmaps. 110 * 111 * <p>If cleared, scaled bitmaps will be drawn with nearest neighbor 112 * sampling, likely resulting in artifacts. This should generally be on 113 * when drawing bitmaps, unless performance-bound (rendering to software 114 * canvas) or preferring pixelation artifacts to blurriness when scaling 115 * significantly.</p> 116 * 117 * <p>If bitmaps are scaled for device density at creation time (as 118 * resource bitmaps often are) the filtering will already have been 119 * done.</p> 120 * 121 * @see #Paint(int) 122 * @see #setFlags(int) 123 */ 124 public static final int FILTER_BITMAP_FLAG = 0x02; 125 /** 126 * Paint flag that enables dithering when blitting. 127 * 128 * <p>Enabling this flag applies a dither to any blit operation where the 129 * target's colour space is more constrained than the source. 130 * 131 * @see #Paint(int) 132 * @see #setFlags(int) 133 */ 134 public static final int DITHER_FLAG = 0x04; 135 /** 136 * Paint flag that applies an underline decoration to drawn text. 137 * 138 * @see #Paint(int) 139 * @see #setFlags(int) 140 */ 141 public static final int UNDERLINE_TEXT_FLAG = 0x08; 142 /** 143 * Paint flag that applies a strike-through decoration to drawn text. 144 * 145 * @see #Paint(int) 146 * @see #setFlags(int) 147 */ 148 public static final int STRIKE_THRU_TEXT_FLAG = 0x10; 149 /** 150 * Paint flag that applies a synthetic bolding effect to drawn text. 151 * 152 * <p>Enabling this flag will cause text draw operations to apply a 153 * simulated bold effect when drawing a {@link Typeface} that is not 154 * already bold.</p> 155 * 156 * @see #Paint(int) 157 * @see #setFlags(int) 158 */ 159 public static final int FAKE_BOLD_TEXT_FLAG = 0x20; 160 /** 161 * Paint flag that enables smooth linear scaling of text. 162 * 163 * <p>Enabling this flag does not actually scale text, but rather adjusts 164 * text draw operations to deal gracefully with smooth adjustment of scale. 165 * When this flag is enabled, font hinting is disabled to prevent shape 166 * deformation between scale factors, and glyph caching is disabled due to 167 * the large number of glyph images that will be generated.</p> 168 * 169 * <p>{@link #SUBPIXEL_TEXT_FLAG} should be used in conjunction with this 170 * flag to prevent glyph positions from snapping to whole pixel values as 171 * scale factor is adjusted.</p> 172 * 173 * @see #Paint(int) 174 * @see #setFlags(int) 175 */ 176 public static final int LINEAR_TEXT_FLAG = 0x40; 177 /** 178 * Paint flag that enables subpixel positioning of text. 179 * 180 * <p>Enabling this flag causes glyph advances to be computed with subpixel 181 * accuracy.</p> 182 * 183 * <p>This can be used with {@link #LINEAR_TEXT_FLAG} to prevent text from 184 * jittering during smooth scale transitions.</p> 185 * 186 * @see #Paint(int) 187 * @see #setFlags(int) 188 */ 189 public static final int SUBPIXEL_TEXT_FLAG = 0x80; 190 /** Legacy Paint flag, no longer used. */ 191 public static final int DEV_KERN_TEXT_FLAG = 0x100; 192 /** @hide bit mask for the flag enabling subpixel glyph rendering for text */ 193 public static final int LCD_RENDER_TEXT_FLAG = 0x200; 194 /** 195 * Paint flag that enables the use of bitmap fonts when drawing text. 196 * 197 * <p>Disabling this flag will prevent text draw operations from using 198 * embedded bitmap strikes in fonts, causing fonts with both scalable 199 * outlines and bitmap strikes to draw only the scalable outlines, and 200 * fonts with only bitmap strikes to not draw at all.</p> 201 * 202 * @see #Paint(int) 203 * @see #setFlags(int) 204 */ 205 public static final int EMBEDDED_BITMAP_TEXT_FLAG = 0x400; 206 /** @hide bit mask for the flag forcing freetype's autohinter on for text */ 207 public static final int AUTO_HINTING_TEXT_FLAG = 0x800; 208 /** @hide bit mask for the flag enabling vertical rendering for text */ 209 public static final int VERTICAL_TEXT_FLAG = 0x1000; 210 211 // These flags are always set on a new/reset paint, even if flags 0 is passed. 212 static final int HIDDEN_DEFAULT_PAINT_FLAGS = DEV_KERN_TEXT_FLAG | EMBEDDED_BITMAP_TEXT_FLAG; 213 214 /** 215 * Font hinter option that disables font hinting. 216 * 217 * @see #setHinting(int) 218 */ 219 public static final int HINTING_OFF = 0x0; 220 221 /** 222 * Font hinter option that enables font hinting. 223 * 224 * @see #setHinting(int) 225 */ 226 public static final int HINTING_ON = 0x1; 227 228 /** 229 * Bidi flag to set LTR paragraph direction. 230 * 231 * @hide 232 */ 233 public static final int BIDI_LTR = 0x0; 234 235 /** 236 * Bidi flag to set RTL paragraph direction. 237 * 238 * @hide 239 */ 240 public static final int BIDI_RTL = 0x1; 241 242 /** 243 * Bidi flag to detect paragraph direction via heuristics, defaulting to 244 * LTR. 245 * 246 * @hide 247 */ 248 public static final int BIDI_DEFAULT_LTR = 0x2; 249 250 /** 251 * Bidi flag to detect paragraph direction via heuristics, defaulting to 252 * RTL. 253 * 254 * @hide 255 */ 256 public static final int BIDI_DEFAULT_RTL = 0x3; 257 258 /** 259 * Bidi flag to override direction to all LTR (ignore bidi). 260 * 261 * @hide 262 */ 263 public static final int BIDI_FORCE_LTR = 0x4; 264 265 /** 266 * Bidi flag to override direction to all RTL (ignore bidi). 267 * 268 * @hide 269 */ 270 public static final int BIDI_FORCE_RTL = 0x5; 271 272 /** 273 * Maximum Bidi flag value. 274 * @hide 275 */ 276 private static final int BIDI_MAX_FLAG_VALUE = BIDI_FORCE_RTL; 277 278 /** 279 * Mask for bidi flags. 280 * @hide 281 */ 282 private static final int BIDI_FLAG_MASK = 0x7; 283 284 /** 285 * Flag for getTextRunAdvances indicating left-to-right run direction. 286 * @hide 287 */ 288 public static final int DIRECTION_LTR = 0; 289 290 /** 291 * Flag for getTextRunAdvances indicating right-to-left run direction. 292 * @hide 293 */ 294 public static final int DIRECTION_RTL = 1; 295 296 /** 297 * Option for getTextRunCursor to compute the valid cursor after 298 * offset or the limit of the context, whichever is less. 299 * @hide 300 */ 301 public static final int CURSOR_AFTER = 0; 302 303 /** 304 * Option for getTextRunCursor to compute the valid cursor at or after 305 * the offset or the limit of the context, whichever is less. 306 * @hide 307 */ 308 public static final int CURSOR_AT_OR_AFTER = 1; 309 310 /** 311 * Option for getTextRunCursor to compute the valid cursor before 312 * offset or the start of the context, whichever is greater. 313 * @hide 314 */ 315 public static final int CURSOR_BEFORE = 2; 316 317 /** 318 * Option for getTextRunCursor to compute the valid cursor at or before 319 * offset or the start of the context, whichever is greater. 320 * @hide 321 */ 322 public static final int CURSOR_AT_OR_BEFORE = 3; 323 324 /** 325 * Option for getTextRunCursor to return offset if the cursor at offset 326 * is valid, or -1 if it isn't. 327 * @hide 328 */ 329 public static final int CURSOR_AT = 4; 330 331 /** 332 * Maximum cursor option value. 333 */ 334 private static final int CURSOR_OPT_MAX_VALUE = CURSOR_AT; 335 336 /** 337 * The Style specifies if the primitive being drawn is filled, stroked, or 338 * both (in the same color). The default is FILL. 339 */ 340 public enum Style { 341 /** 342 * Geometry and text drawn with this style will be filled, ignoring all 343 * stroke-related settings in the paint. 344 */ 345 FILL (0), 346 /** 347 * Geometry and text drawn with this style will be stroked, respecting 348 * the stroke-related fields on the paint. 349 */ 350 STROKE (1), 351 /** 352 * Geometry and text drawn with this style will be both filled and 353 * stroked at the same time, respecting the stroke-related fields on 354 * the paint. This mode can give unexpected results if the geometry 355 * is oriented counter-clockwise. This restriction does not apply to 356 * either FILL or STROKE. 357 */ 358 FILL_AND_STROKE (2); 359 360 Style(int nativeInt) { 361 this.nativeInt = nativeInt; 362 } 363 final int nativeInt; 364 } 365 366 /** 367 * The Cap specifies the treatment for the beginning and ending of 368 * stroked lines and paths. The default is BUTT. 369 */ 370 public enum Cap { 371 /** 372 * The stroke ends with the path, and does not project beyond it. 373 */ 374 BUTT (0), 375 /** 376 * The stroke projects out as a semicircle, with the center at the 377 * end of the path. 378 */ 379 ROUND (1), 380 /** 381 * The stroke projects out as a square, with the center at the end 382 * of the path. 383 */ 384 SQUARE (2); 385 386 private Cap(int nativeInt) { 387 this.nativeInt = nativeInt; 388 } 389 final int nativeInt; 390 } 391 392 /** 393 * The Join specifies the treatment where lines and curve segments 394 * join on a stroked path. The default is MITER. 395 */ 396 public enum Join { 397 /** 398 * The outer edges of a join meet at a sharp angle 399 */ 400 MITER (0), 401 /** 402 * The outer edges of a join meet in a circular arc. 403 */ 404 ROUND (1), 405 /** 406 * The outer edges of a join meet with a straight line 407 */ 408 BEVEL (2); 409 410 private Join(int nativeInt) { 411 this.nativeInt = nativeInt; 412 } 413 final int nativeInt; 414 } 415 416 /** 417 * Align specifies how drawText aligns its text relative to the 418 * [x,y] coordinates. The default is LEFT. 419 */ 420 public enum Align { 421 /** 422 * The text is drawn to the right of the x,y origin 423 */ 424 LEFT (0), 425 /** 426 * The text is drawn centered horizontally on the x,y origin 427 */ 428 CENTER (1), 429 /** 430 * The text is drawn to the left of the x,y origin 431 */ 432 RIGHT (2); 433 434 private Align(int nativeInt) { 435 this.nativeInt = nativeInt; 436 } 437 final int nativeInt; 438 } 439 440 /** 441 * Create a new paint with default settings. 442 */ 443 public Paint() { 444 this(0); 445 } 446 447 /** 448 * Create a new paint with the specified flags. Use setFlags() to change 449 * these after the paint is created. 450 * 451 * @param flags initial flag bits, as if they were passed via setFlags(). 452 */ 453 public Paint(int flags) { 454 mNativePaint = nInit(); 455 sRegistry.registerNativeAllocation(this, mNativePaint); 456 setFlags(flags | HIDDEN_DEFAULT_PAINT_FLAGS); 457 // TODO: Turning off hinting has undesirable side effects, we need to 458 // revisit hinting once we add support for subpixel positioning 459 // setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV 460 // ? HINTING_OFF : HINTING_ON); 461 mCompatScaling = mInvCompatScaling = 1; 462 setTextLocales(LocaleList.getAdjustedDefault()); 463 } 464 465 /** 466 * Create a new paint, initialized with the attributes in the specified 467 * paint parameter. 468 * 469 * @param paint Existing paint used to initialized the attributes of the 470 * new paint. 471 */ 472 public Paint(Paint paint) { 473 mNativePaint = nInitWithPaint(paint.getNativeInstance()); 474 sRegistry.registerNativeAllocation(this, mNativePaint); 475 setClassVariablesFrom(paint); 476 } 477 478 /** Restores the paint to its default settings. */ 479 public void reset() { 480 nReset(mNativePaint); 481 setFlags(HIDDEN_DEFAULT_PAINT_FLAGS); 482 483 // TODO: Turning off hinting has undesirable side effects, we need to 484 // revisit hinting once we add support for subpixel positioning 485 // setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV 486 // ? HINTING_OFF : HINTING_ON); 487 488 mColorFilter = null; 489 mMaskFilter = null; 490 mPathEffect = null; 491 mRasterizer = null; 492 mShader = null; 493 mNativeShader = 0; 494 mTypeface = null; 495 mNativeTypeface = 0; 496 mXfermode = null; 497 498 mHasCompatScaling = false; 499 mCompatScaling = 1; 500 mInvCompatScaling = 1; 501 502 mBidiFlags = BIDI_DEFAULT_LTR; 503 setTextLocales(LocaleList.getAdjustedDefault()); 504 setElegantTextHeight(false); 505 mFontFeatureSettings = null; 506 } 507 508 /** 509 * Copy the fields from src into this paint. This is equivalent to calling 510 * get() on all of the src fields, and calling the corresponding set() 511 * methods on this. 512 */ 513 public void set(Paint src) { 514 if (this != src) { 515 // copy over the native settings 516 nSet(mNativePaint, src.mNativePaint); 517 setClassVariablesFrom(src); 518 } 519 } 520 521 /** 522 * Set all class variables using current values from the given 523 * {@link Paint}. 524 */ 525 private void setClassVariablesFrom(Paint paint) { 526 mColorFilter = paint.mColorFilter; 527 mMaskFilter = paint.mMaskFilter; 528 mPathEffect = paint.mPathEffect; 529 mRasterizer = paint.mRasterizer; 530 mShader = paint.mShader; 531 mNativeShader = paint.mNativeShader; 532 mTypeface = paint.mTypeface; 533 mNativeTypeface = paint.mNativeTypeface; 534 mXfermode = paint.mXfermode; 535 536 mHasCompatScaling = paint.mHasCompatScaling; 537 mCompatScaling = paint.mCompatScaling; 538 mInvCompatScaling = paint.mInvCompatScaling; 539 540 mBidiFlags = paint.mBidiFlags; 541 mLocales = paint.mLocales; 542 mFontFeatureSettings = paint.mFontFeatureSettings; 543 } 544 545 /** @hide */ 546 public void setCompatibilityScaling(float factor) { 547 if (factor == 1.0) { 548 mHasCompatScaling = false; 549 mCompatScaling = mInvCompatScaling = 1.0f; 550 } else { 551 mHasCompatScaling = true; 552 mCompatScaling = factor; 553 mInvCompatScaling = 1.0f/factor; 554 } 555 } 556 557 /** 558 * Return the pointer to the native object while ensuring that any 559 * mutable objects that are attached to the paint are also up-to-date. 560 * 561 * @hide 562 */ 563 public long getNativeInstance() { 564 long newNativeShader = mShader == null ? 0 : mShader.getNativeInstance(); 565 if (newNativeShader != mNativeShader) { 566 mNativeShader = newNativeShader; 567 nSetShader(mNativePaint, mNativeShader); 568 } 569 return mNativePaint; 570 } 571 572 /** 573 * Return the bidi flags on the paint. 574 * 575 * @return the bidi flags on the paint 576 * @hide 577 */ 578 public int getBidiFlags() { 579 return mBidiFlags; 580 } 581 582 /** 583 * Set the bidi flags on the paint. 584 * @hide 585 */ 586 public void setBidiFlags(int flags) { 587 // only flag value is the 3-bit BIDI control setting 588 flags &= BIDI_FLAG_MASK; 589 if (flags > BIDI_MAX_FLAG_VALUE) { 590 throw new IllegalArgumentException("unknown bidi flag: " + flags); 591 } 592 mBidiFlags = flags; 593 } 594 595 /** 596 * Return the paint's flags. Use the Flag enum to test flag values. 597 * 598 * @return the paint's flags (see enums ending in _Flag for bit masks) 599 */ 600 public int getFlags() { 601 return nGetFlags(mNativePaint); 602 } 603 604 private native int nGetFlags(long paintPtr); 605 606 /** 607 * Set the paint's flags. Use the Flag enum to specific flag values. 608 * 609 * @param flags The new flag bits for the paint 610 */ 611 public void setFlags(int flags) { 612 nSetFlags(mNativePaint, flags); 613 } 614 615 private native void nSetFlags(long paintPtr, int flags); 616 617 /** 618 * Return the paint's hinting mode. Returns either 619 * {@link #HINTING_OFF} or {@link #HINTING_ON}. 620 */ 621 public int getHinting() { 622 return nGetHinting(mNativePaint); 623 } 624 625 private native int nGetHinting(long paintPtr); 626 627 /** 628 * Set the paint's hinting mode. May be either 629 * {@link #HINTING_OFF} or {@link #HINTING_ON}. 630 */ 631 public void setHinting(int mode) { 632 nSetHinting(mNativePaint, mode); 633 } 634 635 private native void nSetHinting(long paintPtr, int mode); 636 637 /** 638 * Helper for getFlags(), returning true if ANTI_ALIAS_FLAG bit is set 639 * AntiAliasing smooths out the edges of what is being drawn, but is has 640 * no impact on the interior of the shape. See setDither() and 641 * setFilterBitmap() to affect how colors are treated. 642 * 643 * @return true if the antialias bit is set in the paint's flags. 644 */ 645 public final boolean isAntiAlias() { 646 return (getFlags() & ANTI_ALIAS_FLAG) != 0; 647 } 648 649 /** 650 * Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit 651 * AntiAliasing smooths out the edges of what is being drawn, but is has 652 * no impact on the interior of the shape. See setDither() and 653 * setFilterBitmap() to affect how colors are treated. 654 * 655 * @param aa true to set the antialias bit in the flags, false to clear it 656 */ 657 public void setAntiAlias(boolean aa) { 658 nSetAntiAlias(mNativePaint, aa); 659 } 660 661 private native void nSetAntiAlias(long paintPtr, boolean aa); 662 663 /** 664 * Helper for getFlags(), returning true if DITHER_FLAG bit is set 665 * Dithering affects how colors that are higher precision than the device 666 * are down-sampled. No dithering is generally faster, but higher precision 667 * colors are just truncated down (e.g. 8888 -> 565). Dithering tries to 668 * distribute the error inherent in this process, to reduce the visual 669 * artifacts. 670 * 671 * @return true if the dithering bit is set in the paint's flags. 672 */ 673 public final boolean isDither() { 674 return (getFlags() & DITHER_FLAG) != 0; 675 } 676 677 /** 678 * Helper for setFlags(), setting or clearing the DITHER_FLAG bit 679 * Dithering affects how colors that are higher precision than the device 680 * are down-sampled. No dithering is generally faster, but higher precision 681 * colors are just truncated down (e.g. 8888 -> 565). Dithering tries to 682 * distribute the error inherent in this process, to reduce the visual 683 * artifacts. 684 * 685 * @param dither true to set the dithering bit in flags, false to clear it 686 */ 687 public void setDither(boolean dither) { 688 nSetDither(mNativePaint, dither); 689 } 690 691 private native void nSetDither(long paintPtr, boolean dither); 692 693 /** 694 * Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set 695 * 696 * @return true if the lineartext bit is set in the paint's flags 697 */ 698 public final boolean isLinearText() { 699 return (getFlags() & LINEAR_TEXT_FLAG) != 0; 700 } 701 702 /** 703 * Helper for setFlags(), setting or clearing the LINEAR_TEXT_FLAG bit 704 * 705 * @param linearText true to set the linearText bit in the paint's flags, 706 * false to clear it. 707 */ 708 public void setLinearText(boolean linearText) { 709 nSetLinearText(mNativePaint, linearText); 710 } 711 712 private native void nSetLinearText(long paintPtr, boolean linearText); 713 714 /** 715 * Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set 716 * 717 * @return true if the subpixel bit is set in the paint's flags 718 */ 719 public final boolean isSubpixelText() { 720 return (getFlags() & SUBPIXEL_TEXT_FLAG) != 0; 721 } 722 723 /** 724 * Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit 725 * 726 * @param subpixelText true to set the subpixelText bit in the paint's 727 * flags, false to clear it. 728 */ 729 public void setSubpixelText(boolean subpixelText) { 730 nSetSubpixelText(mNativePaint, subpixelText); 731 } 732 733 private native void nSetSubpixelText(long paintPtr, boolean subpixelText); 734 735 /** 736 * Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set 737 * 738 * @return true if the underlineText bit is set in the paint's flags. 739 */ 740 public final boolean isUnderlineText() { 741 return (getFlags() & UNDERLINE_TEXT_FLAG) != 0; 742 } 743 744 /** 745 * Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit 746 * 747 * @param underlineText true to set the underlineText bit in the paint's 748 * flags, false to clear it. 749 */ 750 public void setUnderlineText(boolean underlineText) { 751 nSetUnderlineText(mNativePaint, underlineText); 752 } 753 754 private native void nSetUnderlineText(long paintPtr, boolean underlineText); 755 756 /** 757 * Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set 758 * 759 * @return true if the strikeThruText bit is set in the paint's flags. 760 */ 761 public final boolean isStrikeThruText() { 762 return (getFlags() & STRIKE_THRU_TEXT_FLAG) != 0; 763 } 764 765 /** 766 * Helper for setFlags(), setting or clearing the STRIKE_THRU_TEXT_FLAG bit 767 * 768 * @param strikeThruText true to set the strikeThruText bit in the paint's 769 * flags, false to clear it. 770 */ 771 public void setStrikeThruText(boolean strikeThruText) { 772 nSetStrikeThruText(mNativePaint, strikeThruText); 773 } 774 775 private native void nSetStrikeThruText(long paintPtr, boolean strikeThruText); 776 777 /** 778 * Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set 779 * 780 * @return true if the fakeBoldText bit is set in the paint's flags. 781 */ 782 public final boolean isFakeBoldText() { 783 return (getFlags() & FAKE_BOLD_TEXT_FLAG) != 0; 784 } 785 786 /** 787 * Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit 788 * 789 * @param fakeBoldText true to set the fakeBoldText bit in the paint's 790 * flags, false to clear it. 791 */ 792 public void setFakeBoldText(boolean fakeBoldText) { 793 nSetFakeBoldText(mNativePaint, fakeBoldText); 794 } 795 796 private native void nSetFakeBoldText(long paintPtr, boolean fakeBoldText); 797 798 /** 799 * Whether or not the bitmap filter is activated. 800 * Filtering affects the sampling of bitmaps when they are transformed. 801 * Filtering does not affect how the colors in the bitmap are converted into 802 * device pixels. That is dependent on dithering and xfermodes. 803 * 804 * @see #setFilterBitmap(boolean) setFilterBitmap() 805 */ 806 public final boolean isFilterBitmap() { 807 return (getFlags() & FILTER_BITMAP_FLAG) != 0; 808 } 809 810 /** 811 * Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit. 812 * Filtering affects the sampling of bitmaps when they are transformed. 813 * Filtering does not affect how the colors in the bitmap are converted into 814 * device pixels. That is dependent on dithering and xfermodes. 815 * 816 * @param filter true to set the FILTER_BITMAP_FLAG bit in the paint's 817 * flags, false to clear it. 818 */ 819 public void setFilterBitmap(boolean filter) { 820 nSetFilterBitmap(mNativePaint, filter); 821 } 822 823 private native void nSetFilterBitmap(long paintPtr, boolean filter); 824 825 /** 826 * Return the paint's style, used for controlling how primitives' 827 * geometries are interpreted (except for drawBitmap, which always assumes 828 * FILL_STYLE). 829 * 830 * @return the paint's style setting (Fill, Stroke, StrokeAndFill) 831 */ 832 public Style getStyle() { 833 return sStyleArray[nGetStyle(mNativePaint)]; 834 } 835 836 /** 837 * Set the paint's style, used for controlling how primitives' 838 * geometries are interpreted (except for drawBitmap, which always assumes 839 * Fill). 840 * 841 * @param style The new style to set in the paint 842 */ 843 public void setStyle(Style style) { 844 nSetStyle(mNativePaint, style.nativeInt); 845 } 846 847 /** 848 * Return the paint's color. Note that the color is a 32bit value 849 * containing alpha as well as r,g,b. This 32bit value is not premultiplied, 850 * meaning that its alpha can be any value, regardless of the values of 851 * r,g,b. See the Color class for more details. 852 * 853 * @return the paint's color (and alpha). 854 */ 855 @ColorInt 856 public int getColor() { 857 return nGetColor(mNativePaint); 858 } 859 860 private native int nGetColor(long paintPtr); 861 862 /** 863 * Set the paint's color. Note that the color is an int containing alpha 864 * as well as r,g,b. This 32bit value is not premultiplied, meaning that 865 * its alpha can be any value, regardless of the values of r,g,b. 866 * See the Color class for more details. 867 * 868 * @param color The new color (including alpha) to set in the paint. 869 */ 870 public void setColor(@ColorInt int color) { 871 nSetColor(mNativePaint, color); 872 } 873 874 private native void nSetColor(long paintPtr, @ColorInt int color); 875 876 /** 877 * Helper to getColor() that just returns the color's alpha value. This is 878 * the same as calling getColor() >>> 24. It always returns a value between 879 * 0 (completely transparent) and 255 (completely opaque). 880 * 881 * @return the alpha component of the paint's color. 882 */ 883 public int getAlpha() { 884 return nGetAlpha(mNativePaint); 885 } 886 887 private native int nGetAlpha(long paintPtr); 888 889 /** 890 * Helper to setColor(), that only assigns the color's alpha value, 891 * leaving its r,g,b values unchanged. Results are undefined if the alpha 892 * value is outside of the range [0..255] 893 * 894 * @param a set the alpha component [0..255] of the paint's color. 895 */ 896 public void setAlpha(int a) { 897 nSetAlpha(mNativePaint, a); 898 } 899 900 private native void nSetAlpha(long paintPtr, int a); 901 902 /** 903 * Helper to setColor(), that takes a,r,g,b and constructs the color int 904 * 905 * @param a The new alpha component (0..255) of the paint's color. 906 * @param r The new red component (0..255) of the paint's color. 907 * @param g The new green component (0..255) of the paint's color. 908 * @param b The new blue component (0..255) of the paint's color. 909 */ 910 public void setARGB(int a, int r, int g, int b) { 911 setColor((a << 24) | (r << 16) | (g << 8) | b); 912 } 913 914 /** 915 * Return the width for stroking. 916 * <p /> 917 * A value of 0 strokes in hairline mode. 918 * Hairlines always draws a single pixel independent of the canva's matrix. 919 * 920 * @return the paint's stroke width, used whenever the paint's style is 921 * Stroke or StrokeAndFill. 922 */ 923 public float getStrokeWidth() { 924 return nGetStrokeWidth(mNativePaint); 925 } 926 927 private native float nGetStrokeWidth(long paintPtr); 928 929 /** 930 * Set the width for stroking. 931 * Pass 0 to stroke in hairline mode. 932 * Hairlines always draws a single pixel independent of the canva's matrix. 933 * 934 * @param width set the paint's stroke width, used whenever the paint's 935 * style is Stroke or StrokeAndFill. 936 */ 937 public void setStrokeWidth(float width) { 938 nSetStrokeWidth(mNativePaint, width); 939 } 940 941 private native void nSetStrokeWidth(long paintPtr, float width); 942 943 /** 944 * Return the paint's stroke miter value. Used to control the behavior 945 * of miter joins when the joins angle is sharp. 946 * 947 * @return the paint's miter limit, used whenever the paint's style is 948 * Stroke or StrokeAndFill. 949 */ 950 public float getStrokeMiter() { 951 return nGetStrokeMiter(mNativePaint); 952 } 953 954 private native float nGetStrokeMiter(long paintPtr); 955 956 /** 957 * Set the paint's stroke miter value. This is used to control the behavior 958 * of miter joins when the joins angle is sharp. This value must be >= 0. 959 * 960 * @param miter set the miter limit on the paint, used whenever the paint's 961 * style is Stroke or StrokeAndFill. 962 */ 963 public void setStrokeMiter(float miter) { 964 nSetStrokeMiter(mNativePaint, miter); 965 } 966 967 private native void nSetStrokeMiter(long paintPtr, float miter); 968 969 /** 970 * Return the paint's Cap, controlling how the start and end of stroked 971 * lines and paths are treated. 972 * 973 * @return the line cap style for the paint, used whenever the paint's 974 * style is Stroke or StrokeAndFill. 975 */ 976 public Cap getStrokeCap() { 977 return sCapArray[nGetStrokeCap(mNativePaint)]; 978 } 979 980 /** 981 * Set the paint's Cap. 982 * 983 * @param cap set the paint's line cap style, used whenever the paint's 984 * style is Stroke or StrokeAndFill. 985 */ 986 public void setStrokeCap(Cap cap) { 987 nSetStrokeCap(mNativePaint, cap.nativeInt); 988 } 989 990 /** 991 * Return the paint's stroke join type. 992 * 993 * @return the paint's Join. 994 */ 995 public Join getStrokeJoin() { 996 return sJoinArray[nGetStrokeJoin(mNativePaint)]; 997 } 998 999 /** 1000 * Set the paint's Join. 1001 * 1002 * @param join set the paint's Join, used whenever the paint's style is 1003 * Stroke or StrokeAndFill. 1004 */ 1005 public void setStrokeJoin(Join join) { 1006 nSetStrokeJoin(mNativePaint, join.nativeInt); 1007 } 1008 1009 /** 1010 * Applies any/all effects (patheffect, stroking) to src, returning the 1011 * result in dst. The result is that drawing src with this paint will be 1012 * the same as drawing dst with a default paint (at least from the 1013 * geometric perspective). 1014 * 1015 * @param src input path 1016 * @param dst output path (may be the same as src) 1017 * @return true if the path should be filled, or false if it should be 1018 * drawn with a hairline (width == 0) 1019 */ 1020 public boolean getFillPath(Path src, Path dst) { 1021 return nGetFillPath(mNativePaint, src.ni(), dst.ni()); 1022 } 1023 1024 /** 1025 * Get the paint's shader object. 1026 * 1027 * @return the paint's shader (or null) 1028 */ 1029 public Shader getShader() { 1030 return mShader; 1031 } 1032 1033 /** 1034 * Set or clear the shader object. 1035 * <p /> 1036 * Pass null to clear any previous shader. 1037 * As a convenience, the parameter passed is also returned. 1038 * 1039 * @param shader May be null. the new shader to be installed in the paint 1040 * @return shader 1041 */ 1042 public Shader setShader(Shader shader) { 1043 // If mShader changes, cached value of native shader aren't valid, since 1044 // old shader's pointer may be reused by another shader allocation later 1045 if (mShader != shader) { 1046 mNativeShader = -1; 1047 } 1048 // Defer setting the shader natively until getNativeInstance() is called 1049 mShader = shader; 1050 return shader; 1051 } 1052 1053 /** 1054 * Get the paint's colorfilter (maybe be null). 1055 * 1056 * @return the paint's colorfilter (maybe be null) 1057 */ 1058 public ColorFilter getColorFilter() { 1059 return mColorFilter; 1060 } 1061 1062 /** 1063 * Set or clear the paint's colorfilter, returning the parameter. 1064 * 1065 * @param filter May be null. The new filter to be installed in the paint 1066 * @return filter 1067 */ 1068 public ColorFilter setColorFilter(ColorFilter filter) { 1069 long filterNative = 0; 1070 if (filter != null) 1071 filterNative = filter.native_instance; 1072 nSetColorFilter(mNativePaint, filterNative); 1073 mColorFilter = filter; 1074 return filter; 1075 } 1076 1077 /** 1078 * Get the paint's xfermode object. 1079 * 1080 * @return the paint's xfermode (or null) 1081 */ 1082 public Xfermode getXfermode() { 1083 return mXfermode; 1084 } 1085 1086 /** 1087 * Set or clear the xfermode object. 1088 * <p /> 1089 * Pass null to clear any previous xfermode. 1090 * As a convenience, the parameter passed is also returned. 1091 * 1092 * @param xfermode May be null. The xfermode to be installed in the paint 1093 * @return xfermode 1094 */ 1095 public Xfermode setXfermode(Xfermode xfermode) { 1096 long xfermodeNative = 0; 1097 if (xfermode != null) 1098 xfermodeNative = xfermode.native_instance; 1099 nSetXfermode(mNativePaint, xfermodeNative); 1100 mXfermode = xfermode; 1101 return xfermode; 1102 } 1103 1104 /** 1105 * Get the paint's patheffect object. 1106 * 1107 * @return the paint's patheffect (or null) 1108 */ 1109 public PathEffect getPathEffect() { 1110 return mPathEffect; 1111 } 1112 1113 /** 1114 * Set or clear the patheffect object. 1115 * <p /> 1116 * Pass null to clear any previous patheffect. 1117 * As a convenience, the parameter passed is also returned. 1118 * 1119 * @param effect May be null. The patheffect to be installed in the paint 1120 * @return effect 1121 */ 1122 public PathEffect setPathEffect(PathEffect effect) { 1123 long effectNative = 0; 1124 if (effect != null) { 1125 effectNative = effect.native_instance; 1126 } 1127 nSetPathEffect(mNativePaint, effectNative); 1128 mPathEffect = effect; 1129 return effect; 1130 } 1131 1132 /** 1133 * Get the paint's maskfilter object. 1134 * 1135 * @return the paint's maskfilter (or null) 1136 */ 1137 public MaskFilter getMaskFilter() { 1138 return mMaskFilter; 1139 } 1140 1141 /** 1142 * Set or clear the maskfilter object. 1143 * <p /> 1144 * Pass null to clear any previous maskfilter. 1145 * As a convenience, the parameter passed is also returned. 1146 * 1147 * @param maskfilter May be null. The maskfilter to be installed in the 1148 * paint 1149 * @return maskfilter 1150 */ 1151 public MaskFilter setMaskFilter(MaskFilter maskfilter) { 1152 long maskfilterNative = 0; 1153 if (maskfilter != null) { 1154 maskfilterNative = maskfilter.native_instance; 1155 } 1156 nSetMaskFilter(mNativePaint, maskfilterNative); 1157 mMaskFilter = maskfilter; 1158 return maskfilter; 1159 } 1160 1161 /** 1162 * Get the paint's typeface object. 1163 * <p /> 1164 * The typeface object identifies which font to use when drawing or 1165 * measuring text. 1166 * 1167 * @return the paint's typeface (or null) 1168 */ 1169 public Typeface getTypeface() { 1170 return mTypeface; 1171 } 1172 1173 /** 1174 * Set or clear the typeface object. 1175 * <p /> 1176 * Pass null to clear any previous typeface. 1177 * As a convenience, the parameter passed is also returned. 1178 * 1179 * @param typeface May be null. The typeface to be installed in the paint 1180 * @return typeface 1181 */ 1182 public Typeface setTypeface(Typeface typeface) { 1183 long typefaceNative = 0; 1184 if (typeface != null) { 1185 typefaceNative = typeface.native_instance; 1186 } 1187 nSetTypeface(mNativePaint, typefaceNative); 1188 mTypeface = typeface; 1189 mNativeTypeface = typefaceNative; 1190 return typeface; 1191 } 1192 1193 /** 1194 * Get the paint's rasterizer (or null). 1195 * <p /> 1196 * The raster controls/modifies how paths/text are turned into alpha masks. 1197 * 1198 * @return the paint's rasterizer (or null) 1199 * 1200 * @deprecated Rasterizer is not supported by either the HW or PDF backends. 1201 */ 1202 @Deprecated 1203 public Rasterizer getRasterizer() { 1204 return mRasterizer; 1205 } 1206 1207 /** 1208 * Set or clear the rasterizer object. 1209 * <p /> 1210 * Pass null to clear any previous rasterizer. 1211 * As a convenience, the parameter passed is also returned. 1212 * 1213 * @param rasterizer May be null. The new rasterizer to be installed in 1214 * the paint. 1215 * @return rasterizer 1216 * 1217 * @deprecated Rasterizer is not supported by either the HW or PDF backends. 1218 */ 1219 @Deprecated 1220 public Rasterizer setRasterizer(Rasterizer rasterizer) { 1221 long rasterizerNative = 0; 1222 if (rasterizer != null) { 1223 rasterizerNative = rasterizer.native_instance; 1224 } 1225 nSetRasterizer(mNativePaint, rasterizerNative); 1226 mRasterizer = rasterizer; 1227 return rasterizer; 1228 } 1229 1230 /** 1231 * This draws a shadow layer below the main layer, with the specified 1232 * offset and color, and blur radius. If radius is 0, then the shadow 1233 * layer is removed. 1234 * <p> 1235 * Can be used to create a blurred shadow underneath text. Support for use 1236 * with other drawing operations is constrained to the software rendering 1237 * pipeline. 1238 * <p> 1239 * The alpha of the shadow will be the paint's alpha if the shadow color is 1240 * opaque, or the alpha from the shadow color if not. 1241 */ 1242 public void setShadowLayer(float radius, float dx, float dy, int shadowColor) { 1243 nSetShadowLayer(mNativePaint, radius, dx, dy, shadowColor); 1244 } 1245 1246 /** 1247 * Clear the shadow layer. 1248 */ 1249 public void clearShadowLayer() { 1250 setShadowLayer(0, 0, 0, 0); 1251 } 1252 1253 /** 1254 * Checks if the paint has a shadow layer attached 1255 * 1256 * @return true if the paint has a shadow layer attached and false otherwise 1257 * @hide 1258 */ 1259 public boolean hasShadowLayer() { 1260 return nHasShadowLayer(mNativePaint); 1261 } 1262 1263 /** 1264 * Return the paint's Align value for drawing text. This controls how the 1265 * text is positioned relative to its origin. LEFT align means that all of 1266 * the text will be drawn to the right of its origin (i.e. the origin 1267 * specifieds the LEFT edge of the text) and so on. 1268 * 1269 * @return the paint's Align value for drawing text. 1270 */ 1271 public Align getTextAlign() { 1272 return sAlignArray[nGetTextAlign(mNativePaint)]; 1273 } 1274 1275 /** 1276 * Set the paint's text alignment. This controls how the 1277 * text is positioned relative to its origin. LEFT align means that all of 1278 * the text will be drawn to the right of its origin (i.e. the origin 1279 * specifieds the LEFT edge of the text) and so on. 1280 * 1281 * @param align set the paint's Align value for drawing text. 1282 */ 1283 public void setTextAlign(Align align) { 1284 nSetTextAlign(mNativePaint, align.nativeInt); 1285 } 1286 1287 /** 1288 * Get the text's primary Locale. Note that this is not all of the locale-related information 1289 * Paint has. Use {@link #getTextLocales()} to get the complete list. 1290 * 1291 * @return the paint's primary Locale used for drawing text, never null. 1292 */ 1293 @NonNull 1294 public Locale getTextLocale() { 1295 return mLocales.get(0); 1296 } 1297 1298 /** 1299 * Get the text locale list. 1300 * 1301 * @return the paint's LocaleList used for drawing text, never null or empty. 1302 */ 1303 @NonNull @Size(min=1) 1304 public LocaleList getTextLocales() { 1305 return mLocales; 1306 } 1307 1308 /** 1309 * Set the text locale list to a one-member list consisting of just the locale. 1310 * 1311 * See {@link #setTextLocales(LocaleList)} for how the locale list affects 1312 * the way the text is drawn for some languages. 1313 * 1314 * @param locale the paint's locale value for drawing text, must not be null. 1315 */ 1316 public void setTextLocale(@NonNull Locale locale) { 1317 if (locale == null) { 1318 throw new IllegalArgumentException("locale cannot be null"); 1319 } 1320 if (mLocales != null && mLocales.size() == 1 && locale.equals(mLocales.get(0))) { 1321 return; 1322 } 1323 mLocales = new LocaleList(locale); 1324 syncTextLocalesWithMinikin(); 1325 } 1326 1327 /** 1328 * Set the text locale list. 1329 * 1330 * The text locale list affects how the text is drawn for some languages. 1331 * 1332 * For example, if the locale list contains {@link Locale#CHINESE} or {@link Locale#CHINA}, 1333 * then the text renderer will prefer to draw text using a Chinese font. Likewise, 1334 * if the locale list contains {@link Locale#JAPANESE} or {@link Locale#JAPAN}, then the text 1335 * renderer will prefer to draw text using a Japanese font. If the locale list contains both, 1336 * the order those locales appear in the list is considered for deciding the font. 1337 * 1338 * This distinction is important because Chinese and Japanese text both use many 1339 * of the same Unicode code points but their appearance is subtly different for 1340 * each language. 1341 * 1342 * By default, the text locale list is initialized to a one-member list just containing the 1343 * system locales. This assumes that the text to be rendered will most likely be in the user's 1344 * preferred language. 1345 * 1346 * If the actual language or languages of the text is/are known, then they can be provided to 1347 * the text renderer using this method. The text renderer may attempt to guess the 1348 * language script based on the contents of the text to be drawn independent of 1349 * the text locale here. Specifying the text locales just helps it do a better 1350 * job in certain ambiguous cases. 1351 * 1352 * @param locales the paint's locale list for drawing text, must not be null or empty. 1353 */ 1354 public void setTextLocales(@NonNull @Size(min=1) LocaleList locales) { 1355 if (locales == null || locales.isEmpty()) { 1356 throw new IllegalArgumentException("locales cannot be null or empty"); 1357 } 1358 if (locales.equals(mLocales)) return; 1359 mLocales = locales; 1360 syncTextLocalesWithMinikin(); 1361 } 1362 1363 private void syncTextLocalesWithMinikin() { 1364 final String languageTags = mLocales.toLanguageTags(); 1365 final Integer minikinLangListId; 1366 synchronized (sCacheLock) { 1367 minikinLangListId = sMinikinLangListIdCache.get(languageTags); 1368 if (minikinLangListId == null) { 1369 final int newID = nSetTextLocales(mNativePaint, languageTags); 1370 sMinikinLangListIdCache.put(languageTags, newID); 1371 return; 1372 } 1373 } 1374 nSetTextLocalesByMinikinLangListId(mNativePaint, minikinLangListId.intValue()); 1375 } 1376 1377 /** 1378 * Get the elegant metrics flag. 1379 * 1380 * @return true if elegant metrics are enabled for text drawing. 1381 */ 1382 public boolean isElegantTextHeight() { 1383 return nIsElegantTextHeight(mNativePaint); 1384 } 1385 1386 private native boolean nIsElegantTextHeight(long paintPtr); 1387 1388 /** 1389 * Set the paint's elegant height metrics flag. This setting selects font 1390 * variants that have not been compacted to fit Latin-based vertical 1391 * metrics, and also increases top and bottom bounds to provide more space. 1392 * 1393 * @param elegant set the paint's elegant metrics flag for drawing text. 1394 */ 1395 public void setElegantTextHeight(boolean elegant) { 1396 nSetElegantTextHeight(mNativePaint, elegant); 1397 } 1398 1399 private native void nSetElegantTextHeight(long paintPtr, boolean elegant); 1400 1401 /** 1402 * Return the paint's text size. 1403 * 1404 * @return the paint's text size. 1405 */ 1406 public float getTextSize() { 1407 return nGetTextSize(mNativePaint); 1408 } 1409 1410 private native float nGetTextSize(long paintPtr); 1411 1412 /** 1413 * Set the paint's text size. This value must be > 0 1414 * 1415 * @param textSize set the paint's text size. 1416 */ 1417 public void setTextSize(float textSize) { 1418 nSetTextSize(mNativePaint, textSize); 1419 } 1420 1421 private native void nSetTextSize(long paintPtr, float textSize); 1422 1423 /** 1424 * Return the paint's horizontal scale factor for text. The default value 1425 * is 1.0. 1426 * 1427 * @return the paint's scale factor in X for drawing/measuring text 1428 */ 1429 public float getTextScaleX() { 1430 return nGetTextScaleX(mNativePaint); 1431 } 1432 1433 private native float nGetTextScaleX(long paintPtr); 1434 1435 /** 1436 * Set the paint's horizontal scale factor for text. The default value 1437 * is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will 1438 * stretch the text narrower. 1439 * 1440 * @param scaleX set the paint's scale in X for drawing/measuring text. 1441 */ 1442 public void setTextScaleX(float scaleX) { 1443 nSetTextScaleX(mNativePaint, scaleX); 1444 } 1445 1446 private native void nSetTextScaleX(long paintPtr, float scaleX); 1447 1448 /** 1449 * Return the paint's horizontal skew factor for text. The default value 1450 * is 0. 1451 * 1452 * @return the paint's skew factor in X for drawing text. 1453 */ 1454 public float getTextSkewX() { 1455 return nGetTextSkewX(mNativePaint); 1456 } 1457 1458 private native float nGetTextSkewX(long paintPtr); 1459 1460 /** 1461 * Set the paint's horizontal skew factor for text. The default value 1462 * is 0. For approximating oblique text, use values around -0.25. 1463 * 1464 * @param skewX set the paint's skew factor in X for drawing text. 1465 */ 1466 public void setTextSkewX(float skewX) { 1467 nSetTextSkewX(mNativePaint, skewX); 1468 } 1469 1470 private native void nSetTextSkewX(long paintPtr, float skewX); 1471 1472 /** 1473 * Return the paint's letter-spacing for text. The default value 1474 * is 0. 1475 * 1476 * @return the paint's letter-spacing for drawing text. 1477 */ 1478 public float getLetterSpacing() { 1479 return nGetLetterSpacing(mNativePaint); 1480 } 1481 1482 /** 1483 * Set the paint's letter-spacing for text. The default value 1484 * is 0. The value is in 'EM' units. Typical values for slight 1485 * expansion will be around 0.05. Negative values tighten text. 1486 * 1487 * @param letterSpacing set the paint's letter-spacing for drawing text. 1488 */ 1489 public void setLetterSpacing(float letterSpacing) { 1490 nSetLetterSpacing(mNativePaint, letterSpacing); 1491 } 1492 1493 /** 1494 * Get font feature settings. Default is null. 1495 * 1496 * @return the paint's currently set font feature settings. 1497 */ 1498 public String getFontFeatureSettings() { 1499 return mFontFeatureSettings; 1500 } 1501 1502 /** 1503 * Set font feature settings. 1504 * 1505 * The format is the same as the CSS font-feature-settings attribute: 1506 * http://dev.w3.org/csswg/css-fonts/#propdef-font-feature-settings 1507 * 1508 * @param settings the font feature settings string to use, may be null. 1509 */ 1510 public void setFontFeatureSettings(String settings) { 1511 if (settings != null && settings.equals("")) { 1512 settings = null; 1513 } 1514 if ((settings == null && mFontFeatureSettings == null) 1515 || (settings != null && settings.equals(mFontFeatureSettings))) { 1516 return; 1517 } 1518 mFontFeatureSettings = settings; 1519 nSetFontFeatureSettings(mNativePaint, settings); 1520 } 1521 1522 /** 1523 * Get the current value of hyphen edit. 1524 * 1525 * @return the current hyphen edit value 1526 * 1527 * @hide 1528 */ 1529 public int getHyphenEdit() { 1530 return nGetHyphenEdit(mNativePaint); 1531 } 1532 1533 /** 1534 * Set a hyphen edit on the paint (causes a hyphen to be added to text when 1535 * measured or drawn). 1536 * 1537 * @param hyphen 0 for no edit, 1 for adding a hyphen (other values in future) 1538 * 1539 * @hide 1540 */ 1541 public void setHyphenEdit(int hyphen) { 1542 nSetHyphenEdit(mNativePaint, hyphen); 1543 } 1544 1545 /** 1546 * Return the distance above (negative) the baseline (ascent) based on the 1547 * current typeface and text size. 1548 * 1549 * @return the distance above (negative) the baseline (ascent) based on the 1550 * current typeface and text size. 1551 */ 1552 public float ascent() { 1553 return nAscent(mNativePaint, mNativeTypeface); 1554 } 1555 1556 private native float nAscent(long paintPtr, long typefacePtr); 1557 1558 /** 1559 * Return the distance below (positive) the baseline (descent) based on the 1560 * current typeface and text size. 1561 * 1562 * @return the distance below (positive) the baseline (descent) based on 1563 * the current typeface and text size. 1564 */ 1565 public float descent() { 1566 return nDescent(mNativePaint, mNativeTypeface); 1567 } 1568 1569 private native float nDescent(long paintPtr, long typefacePtr); 1570 1571 /** 1572 * Class that describes the various metrics for a font at a given text size. 1573 * Remember, Y values increase going down, so those values will be positive, 1574 * and values that measure distances going up will be negative. This class 1575 * is returned by getFontMetrics(). 1576 */ 1577 public static class FontMetrics { 1578 /** 1579 * The maximum distance above the baseline for the tallest glyph in 1580 * the font at a given text size. 1581 */ 1582 public float top; 1583 /** 1584 * The recommended distance above the baseline for singled spaced text. 1585 */ 1586 public float ascent; 1587 /** 1588 * The recommended distance below the baseline for singled spaced text. 1589 */ 1590 public float descent; 1591 /** 1592 * The maximum distance below the baseline for the lowest glyph in 1593 * the font at a given text size. 1594 */ 1595 public float bottom; 1596 /** 1597 * The recommended additional space to add between lines of text. 1598 */ 1599 public float leading; 1600 } 1601 1602 /** 1603 * Return the font's recommended interline spacing, given the Paint's 1604 * settings for typeface, textSize, etc. If metrics is not null, return the 1605 * fontmetric values in it. 1606 * 1607 * @param metrics If this object is not null, its fields are filled with 1608 * the appropriate values given the paint's text attributes. 1609 * @return the font's recommended interline spacing. 1610 */ 1611 public float getFontMetrics(FontMetrics metrics) { 1612 return nGetFontMetrics(mNativePaint, mNativeTypeface, metrics); 1613 } 1614 1615 private native float nGetFontMetrics(long paintPtr, 1616 long typefacePtr, FontMetrics metrics); 1617 1618 /** 1619 * Allocates a new FontMetrics object, and then calls getFontMetrics(fm) 1620 * with it, returning the object. 1621 */ 1622 public FontMetrics getFontMetrics() { 1623 FontMetrics fm = new FontMetrics(); 1624 getFontMetrics(fm); 1625 return fm; 1626 } 1627 1628 /** 1629 * Convenience method for callers that want to have FontMetrics values as 1630 * integers. 1631 */ 1632 public static class FontMetricsInt { 1633 public int top; 1634 public int ascent; 1635 public int descent; 1636 public int bottom; 1637 public int leading; 1638 1639 @Override public String toString() { 1640 return "FontMetricsInt: top=" + top + " ascent=" + ascent + 1641 " descent=" + descent + " bottom=" + bottom + 1642 " leading=" + leading; 1643 } 1644 } 1645 1646 /** 1647 * Return the font's interline spacing, given the Paint's settings for 1648 * typeface, textSize, etc. If metrics is not null, return the fontmetric 1649 * values in it. Note: all values have been converted to integers from 1650 * floats, in such a way has to make the answers useful for both spacing 1651 * and clipping. If you want more control over the rounding, call 1652 * getFontMetrics(). 1653 * 1654 * @return the font's interline spacing. 1655 */ 1656 public int getFontMetricsInt(FontMetricsInt fmi) { 1657 return nGetFontMetricsInt(mNativePaint, mNativeTypeface, fmi); 1658 } 1659 1660 private native int nGetFontMetricsInt(long paintPtr, 1661 long typefacePtr, FontMetricsInt fmi); 1662 1663 public FontMetricsInt getFontMetricsInt() { 1664 FontMetricsInt fm = new FontMetricsInt(); 1665 getFontMetricsInt(fm); 1666 return fm; 1667 } 1668 1669 /** 1670 * Return the recommend line spacing based on the current typeface and 1671 * text size. 1672 * 1673 * @return recommend line spacing based on the current typeface and 1674 * text size. 1675 */ 1676 public float getFontSpacing() { 1677 return getFontMetrics(null); 1678 } 1679 1680 /** 1681 * Return the width of the text. 1682 * 1683 * @param text The text to measure. Cannot be null. 1684 * @param index The index of the first character to start measuring 1685 * @param count THe number of characters to measure, beginning with start 1686 * @return The width of the text 1687 */ 1688 public float measureText(char[] text, int index, int count) { 1689 if (text == null) { 1690 throw new IllegalArgumentException("text cannot be null"); 1691 } 1692 if ((index | count) < 0 || index + count > text.length) { 1693 throw new ArrayIndexOutOfBoundsException(); 1694 } 1695 1696 if (text.length == 0 || count == 0) { 1697 return 0f; 1698 } 1699 if (!mHasCompatScaling) { 1700 return (float) Math.ceil(nGetTextAdvances(mNativePaint, mNativeTypeface, text, 1701 index, count, index, count, mBidiFlags, null, 0)); 1702 } 1703 1704 final float oldSize = getTextSize(); 1705 setTextSize(oldSize * mCompatScaling); 1706 float w = nGetTextAdvances(mNativePaint, mNativeTypeface, text, index, count, index, 1707 count, mBidiFlags, null, 0); 1708 setTextSize(oldSize); 1709 return (float) Math.ceil(w*mInvCompatScaling); 1710 } 1711 1712 /** 1713 * Return the width of the text. 1714 * 1715 * @param text The text to measure. Cannot be null. 1716 * @param start The index of the first character to start measuring 1717 * @param end 1 beyond the index of the last character to measure 1718 * @return The width of the text 1719 */ 1720 public float measureText(String text, int start, int end) { 1721 if (text == null) { 1722 throw new IllegalArgumentException("text cannot be null"); 1723 } 1724 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1725 throw new IndexOutOfBoundsException(); 1726 } 1727 1728 if (text.length() == 0 || start == end) { 1729 return 0f; 1730 } 1731 if (!mHasCompatScaling) { 1732 return (float) Math.ceil(nGetTextAdvances(mNativePaint, mNativeTypeface, text, 1733 start, end, start, end, mBidiFlags, null, 0)); 1734 } 1735 final float oldSize = getTextSize(); 1736 setTextSize(oldSize * mCompatScaling); 1737 float w = nGetTextAdvances(mNativePaint, mNativeTypeface, text, start, end, start, 1738 end, mBidiFlags, null, 0); 1739 setTextSize(oldSize); 1740 return (float) Math.ceil(w * mInvCompatScaling); 1741 } 1742 1743 /** 1744 * Return the width of the text. 1745 * 1746 * @param text The text to measure. Cannot be null. 1747 * @return The width of the text 1748 */ 1749 public float measureText(String text) { 1750 if (text == null) { 1751 throw new IllegalArgumentException("text cannot be null"); 1752 } 1753 return measureText(text, 0, text.length()); 1754 } 1755 1756 /** 1757 * Return the width of the text. 1758 * 1759 * @param text The text to measure 1760 * @param start The index of the first character to start measuring 1761 * @param end 1 beyond the index of the last character to measure 1762 * @return The width of the text 1763 */ 1764 public float measureText(CharSequence text, int start, int end) { 1765 if (text == null) { 1766 throw new IllegalArgumentException("text cannot be null"); 1767 } 1768 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1769 throw new IndexOutOfBoundsException(); 1770 } 1771 1772 if (text.length() == 0 || start == end) { 1773 return 0f; 1774 } 1775 if (text instanceof String) { 1776 return measureText((String)text, start, end); 1777 } 1778 if (text instanceof SpannedString || 1779 text instanceof SpannableString) { 1780 return measureText(text.toString(), start, end); 1781 } 1782 if (text instanceof GraphicsOperations) { 1783 return ((GraphicsOperations)text).measureText(start, end, this); 1784 } 1785 1786 char[] buf = TemporaryBuffer.obtain(end - start); 1787 TextUtils.getChars(text, start, end, buf, 0); 1788 float result = measureText(buf, 0, end - start); 1789 TemporaryBuffer.recycle(buf); 1790 return result; 1791 } 1792 1793 /** 1794 * Measure the text, stopping early if the measured width exceeds maxWidth. 1795 * Return the number of chars that were measured, and if measuredWidth is 1796 * not null, return in it the actual width measured. 1797 * 1798 * @param text The text to measure. Cannot be null. 1799 * @param index The offset into text to begin measuring at 1800 * @param count The number of maximum number of entries to measure. If count 1801 * is negative, then the characters are measured in reverse order. 1802 * @param maxWidth The maximum width to accumulate. 1803 * @param measuredWidth Optional. If not null, returns the actual width 1804 * measured. 1805 * @return The number of chars that were measured. Will always be <= 1806 * abs(count). 1807 */ 1808 public int breakText(char[] text, int index, int count, 1809 float maxWidth, float[] measuredWidth) { 1810 if (text == null) { 1811 throw new IllegalArgumentException("text cannot be null"); 1812 } 1813 if (index < 0 || text.length - index < Math.abs(count)) { 1814 throw new ArrayIndexOutOfBoundsException(); 1815 } 1816 1817 if (text.length == 0 || count == 0) { 1818 return 0; 1819 } 1820 if (!mHasCompatScaling) { 1821 return nBreakText(mNativePaint, mNativeTypeface, text, index, count, maxWidth, 1822 mBidiFlags, measuredWidth); 1823 } 1824 1825 final float oldSize = getTextSize(); 1826 setTextSize(oldSize * mCompatScaling); 1827 int res = nBreakText(mNativePaint, mNativeTypeface, text, index, count, 1828 maxWidth * mCompatScaling, mBidiFlags, measuredWidth); 1829 setTextSize(oldSize); 1830 if (measuredWidth != null) measuredWidth[0] *= mInvCompatScaling; 1831 return res; 1832 } 1833 1834 private static native int nBreakText(long nObject, long nTypeface, 1835 char[] text, int index, int count, 1836 float maxWidth, int bidiFlags, float[] measuredWidth); 1837 1838 /** 1839 * Measure the text, stopping early if the measured width exceeds maxWidth. 1840 * Return the number of chars that were measured, and if measuredWidth is 1841 * not null, return in it the actual width measured. 1842 * 1843 * @param text The text to measure. Cannot be null. 1844 * @param start The offset into text to begin measuring at 1845 * @param end The end of the text slice to measure. 1846 * @param measureForwards If true, measure forwards, starting at start. 1847 * Otherwise, measure backwards, starting with end. 1848 * @param maxWidth The maximum width to accumulate. 1849 * @param measuredWidth Optional. If not null, returns the actual width 1850 * measured. 1851 * @return The number of chars that were measured. Will always be <= 1852 * abs(end - start). 1853 */ 1854 public int breakText(CharSequence text, int start, int end, 1855 boolean measureForwards, 1856 float maxWidth, float[] measuredWidth) { 1857 if (text == null) { 1858 throw new IllegalArgumentException("text cannot be null"); 1859 } 1860 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1861 throw new IndexOutOfBoundsException(); 1862 } 1863 1864 if (text.length() == 0 || start == end) { 1865 return 0; 1866 } 1867 if (start == 0 && text instanceof String && end == text.length()) { 1868 return breakText((String) text, measureForwards, maxWidth, 1869 measuredWidth); 1870 } 1871 1872 char[] buf = TemporaryBuffer.obtain(end - start); 1873 int result; 1874 1875 TextUtils.getChars(text, start, end, buf, 0); 1876 1877 if (measureForwards) { 1878 result = breakText(buf, 0, end - start, maxWidth, measuredWidth); 1879 } else { 1880 result = breakText(buf, 0, -(end - start), maxWidth, measuredWidth); 1881 } 1882 1883 TemporaryBuffer.recycle(buf); 1884 return result; 1885 } 1886 1887 /** 1888 * Measure the text, stopping early if the measured width exceeds maxWidth. 1889 * Return the number of chars that were measured, and if measuredWidth is 1890 * not null, return in it the actual width measured. 1891 * 1892 * @param text The text to measure. Cannot be null. 1893 * @param measureForwards If true, measure forwards, starting with the 1894 * first character in the string. Otherwise, 1895 * measure backwards, starting with the 1896 * last character in the string. 1897 * @param maxWidth The maximum width to accumulate. 1898 * @param measuredWidth Optional. If not null, returns the actual width 1899 * measured. 1900 * @return The number of chars that were measured. Will always be <= 1901 * abs(count). 1902 */ 1903 public int breakText(String text, boolean measureForwards, 1904 float maxWidth, float[] measuredWidth) { 1905 if (text == null) { 1906 throw new IllegalArgumentException("text cannot be null"); 1907 } 1908 1909 if (text.length() == 0) { 1910 return 0; 1911 } 1912 if (!mHasCompatScaling) { 1913 return nBreakText(mNativePaint, mNativeTypeface, text, measureForwards, 1914 maxWidth, mBidiFlags, measuredWidth); 1915 } 1916 1917 final float oldSize = getTextSize(); 1918 setTextSize(oldSize*mCompatScaling); 1919 int res = nBreakText(mNativePaint, mNativeTypeface, text, measureForwards, 1920 maxWidth*mCompatScaling, mBidiFlags, measuredWidth); 1921 setTextSize(oldSize); 1922 if (measuredWidth != null) measuredWidth[0] *= mInvCompatScaling; 1923 return res; 1924 } 1925 1926 private static native int nBreakText(long nObject, long nTypeface, 1927 String text, boolean measureForwards, 1928 float maxWidth, int bidiFlags, float[] measuredWidth); 1929 1930 /** 1931 * Return the advance widths for the characters in the string. 1932 * 1933 * @param text The text to measure. Cannot be null. 1934 * @param index The index of the first char to to measure 1935 * @param count The number of chars starting with index to measure 1936 * @param widths array to receive the advance widths of the characters. 1937 * Must be at least a large as count. 1938 * @return the actual number of widths returned. 1939 */ 1940 public int getTextWidths(char[] text, int index, int count, 1941 float[] widths) { 1942 if (text == null) { 1943 throw new IllegalArgumentException("text cannot be null"); 1944 } 1945 if ((index | count) < 0 || index + count > text.length 1946 || count > widths.length) { 1947 throw new ArrayIndexOutOfBoundsException(); 1948 } 1949 1950 if (text.length == 0 || count == 0) { 1951 return 0; 1952 } 1953 if (!mHasCompatScaling) { 1954 nGetTextAdvances(mNativePaint, mNativeTypeface, text, index, count, index, count, 1955 mBidiFlags, widths, 0); 1956 return count; 1957 } 1958 1959 final float oldSize = getTextSize(); 1960 setTextSize(oldSize * mCompatScaling); 1961 nGetTextAdvances(mNativePaint, mNativeTypeface, text, index, count, index, count, 1962 mBidiFlags, widths, 0); 1963 setTextSize(oldSize); 1964 for (int i = 0; i < count; i++) { 1965 widths[i] *= mInvCompatScaling; 1966 } 1967 return count; 1968 } 1969 1970 /** 1971 * Return the advance widths for the characters in the string. 1972 * 1973 * @param text The text to measure. Cannot be null. 1974 * @param start The index of the first char to to measure 1975 * @param end The end of the text slice to measure 1976 * @param widths array to receive the advance widths of the characters. 1977 * Must be at least a large as (end - start). 1978 * @return the actual number of widths returned. 1979 */ 1980 public int getTextWidths(CharSequence text, int start, int end, 1981 float[] widths) { 1982 if (text == null) { 1983 throw new IllegalArgumentException("text cannot be null"); 1984 } 1985 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1986 throw new IndexOutOfBoundsException(); 1987 } 1988 if (end - start > widths.length) { 1989 throw new ArrayIndexOutOfBoundsException(); 1990 } 1991 1992 if (text.length() == 0 || start == end) { 1993 return 0; 1994 } 1995 if (text instanceof String) { 1996 return getTextWidths((String) text, start, end, widths); 1997 } 1998 if (text instanceof SpannedString || 1999 text instanceof SpannableString) { 2000 return getTextWidths(text.toString(), start, end, widths); 2001 } 2002 if (text instanceof GraphicsOperations) { 2003 return ((GraphicsOperations) text).getTextWidths(start, end, 2004 widths, this); 2005 } 2006 2007 char[] buf = TemporaryBuffer.obtain(end - start); 2008 TextUtils.getChars(text, start, end, buf, 0); 2009 int result = getTextWidths(buf, 0, end - start, widths); 2010 TemporaryBuffer.recycle(buf); 2011 return result; 2012 } 2013 2014 /** 2015 * Return the advance widths for the characters in the string. 2016 * 2017 * @param text The text to measure. Cannot be null. 2018 * @param start The index of the first char to to measure 2019 * @param end The end of the text slice to measure 2020 * @param widths array to receive the advance widths of the characters. 2021 * Must be at least a large as the text. 2022 * @return the number of code units in the specified text. 2023 */ 2024 public int getTextWidths(String text, int start, int end, float[] widths) { 2025 if (text == null) { 2026 throw new IllegalArgumentException("text cannot be null"); 2027 } 2028 if ((start | end | (end - start) | (text.length() - end)) < 0) { 2029 throw new IndexOutOfBoundsException(); 2030 } 2031 if (end - start > widths.length) { 2032 throw new ArrayIndexOutOfBoundsException(); 2033 } 2034 2035 if (text.length() == 0 || start == end) { 2036 return 0; 2037 } 2038 if (!mHasCompatScaling) { 2039 nGetTextAdvances(mNativePaint, mNativeTypeface, text, start, end, start, end, 2040 mBidiFlags, widths, 0); 2041 return end - start; 2042 } 2043 2044 final float oldSize = getTextSize(); 2045 setTextSize(oldSize * mCompatScaling); 2046 nGetTextAdvances(mNativePaint, mNativeTypeface, text, start, end, start, end, 2047 mBidiFlags, widths, 0); 2048 setTextSize(oldSize); 2049 for (int i = 0; i < end - start; i++) { 2050 widths[i] *= mInvCompatScaling; 2051 } 2052 return end - start; 2053 } 2054 2055 /** 2056 * Return the advance widths for the characters in the string. 2057 * 2058 * @param text The text to measure 2059 * @param widths array to receive the advance widths of the characters. 2060 * Must be at least a large as the text. 2061 * @return the number of code units in the specified text. 2062 */ 2063 public int getTextWidths(String text, float[] widths) { 2064 return getTextWidths(text, 0, text.length(), widths); 2065 } 2066 2067 /** 2068 * Convenience overload that takes a char array instead of a 2069 * String. 2070 * 2071 * @see #getTextRunAdvances(String, int, int, int, int, boolean, float[], int) 2072 * @hide 2073 */ 2074 public float getTextRunAdvances(char[] chars, int index, int count, 2075 int contextIndex, int contextCount, boolean isRtl, float[] advances, 2076 int advancesIndex) { 2077 2078 if (chars == null) { 2079 throw new IllegalArgumentException("text cannot be null"); 2080 } 2081 if ((index | count | contextIndex | contextCount | advancesIndex 2082 | (index - contextIndex) | (contextCount - count) 2083 | ((contextIndex + contextCount) - (index + count)) 2084 | (chars.length - (contextIndex + contextCount)) 2085 | (advances == null ? 0 : 2086 (advances.length - (advancesIndex + count)))) < 0) { 2087 throw new IndexOutOfBoundsException(); 2088 } 2089 2090 if (chars.length == 0 || count == 0){ 2091 return 0f; 2092 } 2093 if (!mHasCompatScaling) { 2094 return nGetTextAdvances(mNativePaint, mNativeTypeface, chars, index, count, 2095 contextIndex, contextCount, isRtl ? BIDI_FORCE_RTL : BIDI_FORCE_LTR, advances, 2096 advancesIndex); 2097 } 2098 2099 final float oldSize = getTextSize(); 2100 setTextSize(oldSize * mCompatScaling); 2101 float res = nGetTextAdvances(mNativePaint, mNativeTypeface, chars, index, count, 2102 contextIndex, contextCount, isRtl ? BIDI_FORCE_RTL : BIDI_FORCE_LTR, advances, 2103 advancesIndex); 2104 setTextSize(oldSize); 2105 2106 if (advances != null) { 2107 for (int i = advancesIndex, e = i + count; i < e; i++) { 2108 advances[i] *= mInvCompatScaling; 2109 } 2110 } 2111 return res * mInvCompatScaling; // assume errors are not significant 2112 } 2113 2114 /** 2115 * Convenience overload that takes a CharSequence instead of a 2116 * String. 2117 * 2118 * @see #getTextRunAdvances(String, int, int, int, int, boolean, float[], int) 2119 * @hide 2120 */ 2121 public float getTextRunAdvances(CharSequence text, int start, int end, 2122 int contextStart, int contextEnd, boolean isRtl, float[] advances, 2123 int advancesIndex) { 2124 if (text == null) { 2125 throw new IllegalArgumentException("text cannot be null"); 2126 } 2127 if ((start | end | contextStart | contextEnd | advancesIndex | (end - start) 2128 | (start - contextStart) | (contextEnd - end) 2129 | (text.length() - contextEnd) 2130 | (advances == null ? 0 : 2131 (advances.length - advancesIndex - (end - start)))) < 0) { 2132 throw new IndexOutOfBoundsException(); 2133 } 2134 2135 if (text instanceof String) { 2136 return getTextRunAdvances((String) text, start, end, 2137 contextStart, contextEnd, isRtl, advances, advancesIndex); 2138 } 2139 if (text instanceof SpannedString || 2140 text instanceof SpannableString) { 2141 return getTextRunAdvances(text.toString(), start, end, 2142 contextStart, contextEnd, isRtl, advances, advancesIndex); 2143 } 2144 if (text instanceof GraphicsOperations) { 2145 return ((GraphicsOperations) text).getTextRunAdvances(start, end, 2146 contextStart, contextEnd, isRtl, advances, advancesIndex, this); 2147 } 2148 if (text.length() == 0 || end == start) { 2149 return 0f; 2150 } 2151 2152 int contextLen = contextEnd - contextStart; 2153 int len = end - start; 2154 char[] buf = TemporaryBuffer.obtain(contextLen); 2155 TextUtils.getChars(text, contextStart, contextEnd, buf, 0); 2156 float result = getTextRunAdvances(buf, start - contextStart, len, 2157 0, contextLen, isRtl, advances, advancesIndex); 2158 TemporaryBuffer.recycle(buf); 2159 return result; 2160 } 2161 2162 /** 2163 * Returns the total advance width for the characters in the run 2164 * between start and end, and if advances is not null, the advance 2165 * assigned to each of these characters (java chars). 2166 * 2167 * <p>The trailing surrogate in a valid surrogate pair is assigned 2168 * an advance of 0. Thus the number of returned advances is 2169 * always equal to count, not to the number of unicode codepoints 2170 * represented by the run. 2171 * 2172 * <p>In the case of conjuncts or combining marks, the total 2173 * advance is assigned to the first logical character, and the 2174 * following characters are assigned an advance of 0. 2175 * 2176 * <p>This generates the sum of the advances of glyphs for 2177 * characters in a reordered cluster as the width of the first 2178 * logical character in the cluster, and 0 for the widths of all 2179 * other characters in the cluster. In effect, such clusters are 2180 * treated like conjuncts. 2181 * 2182 * <p>The shaping bounds limit the amount of context available 2183 * outside start and end that can be used for shaping analysis. 2184 * These bounds typically reflect changes in bidi level or font 2185 * metrics across which shaping does not occur. 2186 * 2187 * @param text the text to measure. Cannot be null. 2188 * @param start the index of the first character to measure 2189 * @param end the index past the last character to measure 2190 * @param contextStart the index of the first character to use for shaping context, 2191 * must be <= start 2192 * @param contextEnd the index past the last character to use for shaping context, 2193 * must be >= end 2194 * @param isRtl whether the run is in RTL direction 2195 * @param advances array to receive the advances, must have room for all advances, 2196 * can be null if only total advance is needed 2197 * @param advancesIndex the position in advances at which to put the 2198 * advance corresponding to the character at start 2199 * @return the total advance 2200 * 2201 * @hide 2202 */ 2203 public float getTextRunAdvances(String text, int start, int end, int contextStart, 2204 int contextEnd, boolean isRtl, float[] advances, int advancesIndex) { 2205 if (text == null) { 2206 throw new IllegalArgumentException("text cannot be null"); 2207 } 2208 if ((start | end | contextStart | contextEnd | advancesIndex | (end - start) 2209 | (start - contextStart) | (contextEnd - end) 2210 | (text.length() - contextEnd) 2211 | (advances == null ? 0 : 2212 (advances.length - advancesIndex - (end - start)))) < 0) { 2213 throw new IndexOutOfBoundsException(); 2214 } 2215 2216 if (text.length() == 0 || start == end) { 2217 return 0f; 2218 } 2219 2220 if (!mHasCompatScaling) { 2221 return nGetTextAdvances(mNativePaint, mNativeTypeface, text, start, end, 2222 contextStart, contextEnd, isRtl ? BIDI_FORCE_RTL : BIDI_FORCE_LTR, advances, 2223 advancesIndex); 2224 } 2225 2226 final float oldSize = getTextSize(); 2227 setTextSize(oldSize * mCompatScaling); 2228 float totalAdvance = nGetTextAdvances(mNativePaint, mNativeTypeface, text, start, 2229 end, contextStart, contextEnd, isRtl ? BIDI_FORCE_RTL : BIDI_FORCE_LTR, advances, 2230 advancesIndex); 2231 setTextSize(oldSize); 2232 2233 if (advances != null) { 2234 for (int i = advancesIndex, e = i + (end - start); i < e; i++) { 2235 advances[i] *= mInvCompatScaling; 2236 } 2237 } 2238 return totalAdvance * mInvCompatScaling; // assume errors are insignificant 2239 } 2240 2241 /** 2242 * Returns the next cursor position in the run. This avoids placing the 2243 * cursor between surrogates, between characters that form conjuncts, 2244 * between base characters and combining marks, or within a reordering 2245 * cluster. 2246 * 2247 * <p>ContextStart and offset are relative to the start of text. 2248 * The context is the shaping context for cursor movement, generally 2249 * the bounds of the metric span enclosing the cursor in the direction of 2250 * movement. 2251 * 2252 * <p>If cursorOpt is {@link #CURSOR_AT} and the offset is not a valid 2253 * cursor position, this returns -1. Otherwise this will never return a 2254 * value before contextStart or after contextStart + contextLength. 2255 * 2256 * @param text the text 2257 * @param contextStart the start of the context 2258 * @param contextLength the length of the context 2259 * @param dir either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR} 2260 * @param offset the cursor position to move from 2261 * @param cursorOpt how to move the cursor, one of {@link #CURSOR_AFTER}, 2262 * {@link #CURSOR_AT_OR_AFTER}, {@link #CURSOR_BEFORE}, 2263 * {@link #CURSOR_AT_OR_BEFORE}, or {@link #CURSOR_AT} 2264 * @return the offset of the next position, or -1 2265 * @hide 2266 */ 2267 public int getTextRunCursor(char[] text, int contextStart, int contextLength, 2268 int dir, int offset, int cursorOpt) { 2269 int contextEnd = contextStart + contextLength; 2270 if (((contextStart | contextEnd | offset | (contextEnd - contextStart) 2271 | (offset - contextStart) | (contextEnd - offset) 2272 | (text.length - contextEnd) | cursorOpt) < 0) 2273 || cursorOpt > CURSOR_OPT_MAX_VALUE) { 2274 throw new IndexOutOfBoundsException(); 2275 } 2276 2277 return nGetTextRunCursor(mNativePaint, text, 2278 contextStart, contextLength, dir, offset, cursorOpt); 2279 } 2280 2281 /** 2282 * Returns the next cursor position in the run. This avoids placing the 2283 * cursor between surrogates, between characters that form conjuncts, 2284 * between base characters and combining marks, or within a reordering 2285 * cluster. 2286 * 2287 * <p>ContextStart, contextEnd, and offset are relative to the start of 2288 * text. The context is the shaping context for cursor movement, generally 2289 * the bounds of the metric span enclosing the cursor in the direction of 2290 * movement. 2291 * 2292 * <p>If cursorOpt is {@link #CURSOR_AT} and the offset is not a valid 2293 * cursor position, this returns -1. Otherwise this will never return a 2294 * value before contextStart or after contextEnd. 2295 * 2296 * @param text the text 2297 * @param contextStart the start of the context 2298 * @param contextEnd the end of the context 2299 * @param dir either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR} 2300 * @param offset the cursor position to move from 2301 * @param cursorOpt how to move the cursor, one of {@link #CURSOR_AFTER}, 2302 * {@link #CURSOR_AT_OR_AFTER}, {@link #CURSOR_BEFORE}, 2303 * {@link #CURSOR_AT_OR_BEFORE}, or {@link #CURSOR_AT} 2304 * @return the offset of the next position, or -1 2305 * @hide 2306 */ 2307 public int getTextRunCursor(CharSequence text, int contextStart, 2308 int contextEnd, int dir, int offset, int cursorOpt) { 2309 2310 if (text instanceof String || text instanceof SpannedString || 2311 text instanceof SpannableString) { 2312 return getTextRunCursor(text.toString(), contextStart, contextEnd, 2313 dir, offset, cursorOpt); 2314 } 2315 if (text instanceof GraphicsOperations) { 2316 return ((GraphicsOperations) text).getTextRunCursor( 2317 contextStart, contextEnd, dir, offset, cursorOpt, this); 2318 } 2319 2320 int contextLen = contextEnd - contextStart; 2321 char[] buf = TemporaryBuffer.obtain(contextLen); 2322 TextUtils.getChars(text, contextStart, contextEnd, buf, 0); 2323 int relPos = getTextRunCursor(buf, 0, contextLen, dir, offset - contextStart, cursorOpt); 2324 TemporaryBuffer.recycle(buf); 2325 return (relPos == -1) ? -1 : relPos + contextStart; 2326 } 2327 2328 /** 2329 * Returns the next cursor position in the run. This avoids placing the 2330 * cursor between surrogates, between characters that form conjuncts, 2331 * between base characters and combining marks, or within a reordering 2332 * cluster. 2333 * 2334 * <p>ContextStart, contextEnd, and offset are relative to the start of 2335 * text. The context is the shaping context for cursor movement, generally 2336 * the bounds of the metric span enclosing the cursor in the direction of 2337 * movement. 2338 * 2339 * <p>If cursorOpt is {@link #CURSOR_AT} and the offset is not a valid 2340 * cursor position, this returns -1. Otherwise this will never return a 2341 * value before contextStart or after contextEnd. 2342 * 2343 * @param text the text 2344 * @param contextStart the start of the context 2345 * @param contextEnd the end of the context 2346 * @param dir either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR} 2347 * @param offset the cursor position to move from 2348 * @param cursorOpt how to move the cursor, one of {@link #CURSOR_AFTER}, 2349 * {@link #CURSOR_AT_OR_AFTER}, {@link #CURSOR_BEFORE}, 2350 * {@link #CURSOR_AT_OR_BEFORE}, or {@link #CURSOR_AT} 2351 * @return the offset of the next position, or -1 2352 * @hide 2353 */ 2354 public int getTextRunCursor(String text, int contextStart, int contextEnd, 2355 int dir, int offset, int cursorOpt) { 2356 if (((contextStart | contextEnd | offset | (contextEnd - contextStart) 2357 | (offset - contextStart) | (contextEnd - offset) 2358 | (text.length() - contextEnd) | cursorOpt) < 0) 2359 || cursorOpt > CURSOR_OPT_MAX_VALUE) { 2360 throw new IndexOutOfBoundsException(); 2361 } 2362 2363 return nGetTextRunCursor(mNativePaint, text, 2364 contextStart, contextEnd, dir, offset, cursorOpt); 2365 } 2366 2367 /** 2368 * Return the path (outline) for the specified text. 2369 * Note: just like Canvas.drawText, this will respect the Align setting in 2370 * the paint. 2371 * 2372 * @param text The text to retrieve the path from 2373 * @param index The index of the first character in text 2374 * @param count The number of characterss starting with index 2375 * @param x The x coordinate of the text's origin 2376 * @param y The y coordinate of the text's origin 2377 * @param path The path to receive the data describing the text. Must 2378 * be allocated by the caller. 2379 */ 2380 public void getTextPath(char[] text, int index, int count, 2381 float x, float y, Path path) { 2382 if ((index | count) < 0 || index + count > text.length) { 2383 throw new ArrayIndexOutOfBoundsException(); 2384 } 2385 nGetTextPath(mNativePaint, mNativeTypeface, mBidiFlags, text, index, count, x, y, 2386 path.ni()); 2387 } 2388 2389 /** 2390 * Return the path (outline) for the specified text. 2391 * Note: just like Canvas.drawText, this will respect the Align setting 2392 * in the paint. 2393 * 2394 * @param text The text to retrieve the path from 2395 * @param start The first character in the text 2396 * @param end 1 past the last charcter in the text 2397 * @param x The x coordinate of the text's origin 2398 * @param y The y coordinate of the text's origin 2399 * @param path The path to receive the data describing the text. Must 2400 * be allocated by the caller. 2401 */ 2402 public void getTextPath(String text, int start, int end, 2403 float x, float y, Path path) { 2404 if ((start | end | (end - start) | (text.length() - end)) < 0) { 2405 throw new IndexOutOfBoundsException(); 2406 } 2407 nGetTextPath(mNativePaint, mNativeTypeface, mBidiFlags, text, start, end, x, y, 2408 path.ni()); 2409 } 2410 2411 /** 2412 * Return in bounds (allocated by the caller) the smallest rectangle that 2413 * encloses all of the characters, with an implied origin at (0,0). 2414 * 2415 * @param text String to measure and return its bounds 2416 * @param start Index of the first char in the string to measure 2417 * @param end 1 past the last char in the string measure 2418 * @param bounds Returns the unioned bounds of all the text. Must be 2419 * allocated by the caller. 2420 */ 2421 public void getTextBounds(String text, int start, int end, Rect bounds) { 2422 if ((start | end | (end - start) | (text.length() - end)) < 0) { 2423 throw new IndexOutOfBoundsException(); 2424 } 2425 if (bounds == null) { 2426 throw new NullPointerException("need bounds Rect"); 2427 } 2428 nGetStringBounds(mNativePaint, mNativeTypeface, text, start, end, mBidiFlags, bounds); 2429 } 2430 2431 /** 2432 * Return in bounds (allocated by the caller) the smallest rectangle that 2433 * encloses all of the characters, with an implied origin at (0,0). 2434 * 2435 * @param text Array of chars to measure and return their unioned bounds 2436 * @param index Index of the first char in the array to measure 2437 * @param count The number of chars, beginning at index, to measure 2438 * @param bounds Returns the unioned bounds of all the text. Must be 2439 * allocated by the caller. 2440 */ 2441 public void getTextBounds(char[] text, int index, int count, Rect bounds) { 2442 if ((index | count) < 0 || index + count > text.length) { 2443 throw new ArrayIndexOutOfBoundsException(); 2444 } 2445 if (bounds == null) { 2446 throw new NullPointerException("need bounds Rect"); 2447 } 2448 nGetCharArrayBounds(mNativePaint, mNativeTypeface, text, index, count, mBidiFlags, 2449 bounds); 2450 } 2451 2452 /** 2453 * Determine whether the typeface set on the paint has a glyph supporting the string. The 2454 * simplest case is when the string contains a single character, in which this method 2455 * determines whether the font has the character. In the case of multiple characters, the 2456 * method returns true if there is a single glyph representing the ligature. For example, if 2457 * the input is a pair of regional indicator symbols, determine whether there is an emoji flag 2458 * for the pair. 2459 * 2460 * <p>Finally, if the string contains a variation selector, the method only returns true if 2461 * the fonts contains a glyph specific to that variation. 2462 * 2463 * <p>Checking is done on the entire fallback chain, not just the immediate font referenced. 2464 * 2465 * @param string the string to test whether there is glyph support 2466 * @return true if the typeface has a glyph for the string 2467 */ 2468 public boolean hasGlyph(String string) { 2469 return nHasGlyph(mNativePaint, mNativeTypeface, mBidiFlags, string); 2470 } 2471 2472 /** 2473 * Measure cursor position within a run of text. 2474 * 2475 * <p>The run of text includes the characters from {@code start} to {@code end} in the text. In 2476 * addition, the range {@code contextStart} to {@code contextEnd} is used as context for the 2477 * purpose of complex text shaping, such as Arabic text potentially shaped differently based on 2478 * the text next to it. 2479 * 2480 * <p>All text outside the range {@code contextStart..contextEnd} is ignored. The text between 2481 * {@code start} and {@code end} will be laid out to be measured. 2482 * 2483 * <p>The returned width measurement is the advance from {@code start} to {@code offset}. It is 2484 * generally a positive value, no matter the direction of the run. If {@code offset == end}, 2485 * the return value is simply the width of the whole run from {@code start} to {@code end}. 2486 * 2487 * <p>Ligatures are formed for characters in the range {@code start..end} (but not for 2488 * {@code start..contextStart} or {@code end..contextEnd}). If {@code offset} points to a 2489 * character in the middle of such a formed ligature, but at a grapheme cluster boundary, the 2490 * return value will also reflect an advance in the middle of the ligature. See 2491 * {@link #getOffsetForAdvance} for more discussion of grapheme cluster boundaries. 2492 * 2493 * <p>The direction of the run is explicitly specified by {@code isRtl}. Thus, this method is 2494 * suitable only for runs of a single direction. 2495 * 2496 * <p>All indices are relative to the start of {@code text}. Further, {@code 0 <= contextStart 2497 * <= start <= offset <= end <= contextEnd <= text.length} must hold on entry. 2498 * 2499 * @param text the text to measure. Cannot be null. 2500 * @param start the index of the start of the range to measure 2501 * @param end the index + 1 of the end of the range to measure 2502 * @param contextStart the index of the start of the shaping context 2503 * @param contextEnd the index + 1 of the end of the shaping context 2504 * @param isRtl whether the run is in RTL direction 2505 * @param offset index of caret position 2506 * @return width measurement between start and offset 2507 */ 2508 public float getRunAdvance(char[] text, int start, int end, int contextStart, int contextEnd, 2509 boolean isRtl, int offset) { 2510 if (text == null) { 2511 throw new IllegalArgumentException("text cannot be null"); 2512 } 2513 if ((contextStart | start | offset | end | contextEnd 2514 | start - contextStart | offset - start | end - offset 2515 | contextEnd - end | text.length - contextEnd) < 0) { 2516 throw new IndexOutOfBoundsException(); 2517 } 2518 if (end == start) { 2519 return 0.0f; 2520 } 2521 // TODO: take mCompatScaling into account (or eliminate compat scaling)? 2522 return nGetRunAdvance(mNativePaint, mNativeTypeface, text, start, end, 2523 contextStart, contextEnd, isRtl, offset); 2524 } 2525 2526 /** 2527 * @see #getRunAdvance(char[], int, int, int, int, boolean, int) 2528 * 2529 * @param text the text to measure. Cannot be null. 2530 * @param start the index of the start of the range to measure 2531 * @param end the index + 1 of the end of the range to measure 2532 * @param contextStart the index of the start of the shaping context 2533 * @param contextEnd the index + 1 of the end of the shaping context 2534 * @param isRtl whether the run is in RTL direction 2535 * @param offset index of caret position 2536 * @return width measurement between start and offset 2537 */ 2538 public float getRunAdvance(CharSequence text, int start, int end, int contextStart, 2539 int contextEnd, boolean isRtl, int offset) { 2540 if (text == null) { 2541 throw new IllegalArgumentException("text cannot be null"); 2542 } 2543 if ((contextStart | start | offset | end | contextEnd 2544 | start - contextStart | offset - start | end - offset 2545 | contextEnd - end | text.length() - contextEnd) < 0) { 2546 throw new IndexOutOfBoundsException(); 2547 } 2548 if (end == start) { 2549 return 0.0f; 2550 } 2551 // TODO performance: specialized alternatives to avoid buffer copy, if win is significant 2552 char[] buf = TemporaryBuffer.obtain(contextEnd - contextStart); 2553 TextUtils.getChars(text, contextStart, contextEnd, buf, 0); 2554 float result = getRunAdvance(buf, start - contextStart, end - contextStart, 0, 2555 contextEnd - contextStart, isRtl, offset - contextStart); 2556 TemporaryBuffer.recycle(buf); 2557 return result; 2558 } 2559 2560 /** 2561 * Get the character offset within the string whose position is closest to the specified 2562 * horizontal position. 2563 * 2564 * <p>The returned value is generally the value of {@code offset} for which 2565 * {@link #getRunAdvance} yields a result most closely approximating {@code advance}, 2566 * and which is also on a grapheme cluster boundary. As such, it is the preferred method 2567 * for positioning a cursor in response to a touch or pointer event. The grapheme cluster 2568 * boundaries are based on 2569 * <a href="http://unicode.org/reports/tr29/">Unicode Standard Annex #29</a> but with some 2570 * tailoring for better user experience. 2571 * 2572 * <p>Note that {@code advance} is a (generally positive) width measurement relative to the start 2573 * of the run. Thus, for RTL runs it the distance from the point to the right edge. 2574 * 2575 * <p>All indices are relative to the start of {@code text}. Further, {@code 0 <= contextStart 2576 * <= start <= end <= contextEnd <= text.length} must hold on entry, and {@code start <= result 2577 * <= end} will hold on return. 2578 * 2579 * @param text the text to measure. Cannot be null. 2580 * @param start the index of the start of the range to measure 2581 * @param end the index + 1 of the end of the range to measure 2582 * @param contextStart the index of the start of the shaping context 2583 * @param contextEnd the index + 1 of the end of the range to measure 2584 * @param isRtl whether the run is in RTL direction 2585 * @param advance width relative to start of run 2586 * @return index of offset 2587 */ 2588 public int getOffsetForAdvance(char[] text, int start, int end, int contextStart, 2589 int contextEnd, boolean isRtl, float advance) { 2590 if (text == null) { 2591 throw new IllegalArgumentException("text cannot be null"); 2592 } 2593 if ((contextStart | start | end | contextEnd 2594 | start - contextStart | end - start | contextEnd - end 2595 | text.length - contextEnd) < 0) { 2596 throw new IndexOutOfBoundsException(); 2597 } 2598 // TODO: take mCompatScaling into account (or eliminate compat scaling)? 2599 return nGetOffsetForAdvance(mNativePaint, mNativeTypeface, text, start, end, 2600 contextStart, contextEnd, isRtl, advance); 2601 } 2602 2603 /** 2604 * @see #getOffsetForAdvance(char[], int, int, int, int, boolean, float) 2605 * 2606 * @param text the text to measure. Cannot be null. 2607 * @param start the index of the start of the range to measure 2608 * @param end the index + 1 of the end of the range to measure 2609 * @param contextStart the index of the start of the shaping context 2610 * @param contextEnd the index + 1 of the end of the range to measure 2611 * @param isRtl whether the run is in RTL direction 2612 * @param advance width relative to start of run 2613 * @return index of offset 2614 */ 2615 public int getOffsetForAdvance(CharSequence text, int start, int end, int contextStart, 2616 int contextEnd, boolean isRtl, float advance) { 2617 if (text == null) { 2618 throw new IllegalArgumentException("text cannot be null"); 2619 } 2620 if ((contextStart | start | end | contextEnd 2621 | start - contextStart | end - start | contextEnd - end 2622 | text.length() - contextEnd) < 0) { 2623 throw new IndexOutOfBoundsException(); 2624 } 2625 // TODO performance: specialized alternatives to avoid buffer copy, if win is significant 2626 char[] buf = TemporaryBuffer.obtain(contextEnd - contextStart); 2627 TextUtils.getChars(text, contextStart, contextEnd, buf, 0); 2628 int result = getOffsetForAdvance(buf, start - contextStart, end - contextStart, 0, 2629 contextEnd - contextStart, isRtl, advance) + contextStart; 2630 TemporaryBuffer.recycle(buf); 2631 return result; 2632 } 2633 2634 private static native long nInit(); 2635 private static native long nInitWithPaint(long paint); 2636 private static native void nReset(long paintPtr); 2637 private static native void nSet(long paintPtrDest, long paintPtrSrc); 2638 private static native int nGetStyle(long paintPtr); 2639 private static native void nSetStyle(long paintPtr, int style); 2640 private static native int nGetStrokeCap(long paintPtr); 2641 private static native void nSetStrokeCap(long paintPtr, int cap); 2642 private static native int nGetStrokeJoin(long paintPtr); 2643 private static native void nSetStrokeJoin(long paintPtr, 2644 int join); 2645 private static native boolean nGetFillPath(long paintPtr, 2646 long src, long dst); 2647 private static native long nSetShader(long paintPtr, long shader); 2648 private static native long nSetColorFilter(long paintPtr, 2649 long filter); 2650 private static native long nSetXfermode(long paintPtr, 2651 long xfermode); 2652 private static native long nSetPathEffect(long paintPtr, 2653 long effect); 2654 private static native long nSetMaskFilter(long paintPtr, 2655 long maskfilter); 2656 private static native long nSetTypeface(long paintPtr, 2657 long typeface); 2658 private static native long nSetRasterizer(long paintPtr, 2659 long rasterizer); 2660 2661 private static native int nGetTextAlign(long paintPtr); 2662 private static native void nSetTextAlign(long paintPtr, 2663 int align); 2664 2665 private static native int nSetTextLocales(long paintPtr, String locales); 2666 private static native void nSetTextLocalesByMinikinLangListId(long paintPtr, 2667 int mMinikinLangListId); 2668 2669 private static native float nGetTextAdvances(long paintPtr, long typefacePtr, 2670 char[] text, int index, int count, int contextIndex, int contextCount, 2671 int bidiFlags, float[] advances, int advancesIndex); 2672 private static native float nGetTextAdvances(long paintPtr, long typefacePtr, 2673 String text, int start, int end, int contextStart, int contextEnd, 2674 int bidiFlags, float[] advances, int advancesIndex); 2675 2676 private native int nGetTextRunCursor(long paintPtr, char[] text, 2677 int contextStart, int contextLength, int dir, int offset, int cursorOpt); 2678 private native int nGetTextRunCursor(long paintPtr, String text, 2679 int contextStart, int contextEnd, int dir, int offset, int cursorOpt); 2680 2681 private static native void nGetTextPath(long paintPtr, long typefacePtr, 2682 int bidiFlags, char[] text, int index, int count, float x, float y, long path); 2683 private static native void nGetTextPath(long paintPtr, long typefacePtr, 2684 int bidiFlags, String text, int start, int end, float x, float y, long path); 2685 private static native void nGetStringBounds(long nativePaint, long typefacePtr, 2686 String text, int start, int end, int bidiFlags, Rect bounds); 2687 private static native void nGetCharArrayBounds(long nativePaint, long typefacePtr, 2688 char[] text, int index, int count, int bidiFlags, Rect bounds); 2689 private static native long nGetNativeFinalizer(); 2690 2691 private static native void nSetShadowLayer(long paintPtr, 2692 float radius, float dx, float dy, int color); 2693 private static native boolean nHasShadowLayer(long paintPtr); 2694 2695 private static native float nGetLetterSpacing(long paintPtr); 2696 private static native void nSetLetterSpacing(long paintPtr, 2697 float letterSpacing); 2698 private static native void nSetFontFeatureSettings(long paintPtr, 2699 String settings); 2700 private static native int nGetHyphenEdit(long paintPtr); 2701 private static native void nSetHyphenEdit(long paintPtr, int hyphen); 2702 private static native boolean nHasGlyph(long paintPtr, long typefacePtr, 2703 int bidiFlags, String string); 2704 private static native float nGetRunAdvance(long paintPtr, long typefacePtr, 2705 char[] text, int start, int end, int contextStart, int contextEnd, boolean isRtl, 2706 int offset); 2707 private static native int nGetOffsetForAdvance(long paintPtr, 2708 long typefacePtr, char[] text, int start, int end, int contextStart, int contextEnd, 2709 boolean isRtl, float advance); 2710} 2711