Paint.java revision e7197a996ff9c4a51d32dd2f918aab97d2b191ef
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.text.GraphicsOperations; 20import android.text.SpannableString; 21import android.text.SpannedString; 22import android.text.TextUtils; 23import android.util.DisplayMetrics; 24 25/** 26 * The Paint class holds the style and color information about how to draw 27 * geometries, text and bitmaps. 28 */ 29public class Paint { 30 31 /** 32 * @hide 33 */ 34 public int mNativePaint; 35 36 private ColorFilter mColorFilter; 37 private MaskFilter mMaskFilter; 38 private PathEffect mPathEffect; 39 private Rasterizer mRasterizer; 40 private Shader mShader; 41 private Typeface mTypeface; 42 private Xfermode mXfermode; 43 44 private boolean mHasCompatScaling; 45 private float mCompatScaling; 46 private float mInvCompatScaling; 47 48 /** 49 * @hide 50 */ 51 public boolean hasShadow; 52 /** 53 * @hide 54 */ 55 public float shadowDx; 56 /** 57 * @hide 58 */ 59 public float shadowDy; 60 /** 61 * @hide 62 */ 63 public float shadowRadius; 64 /** 65 * @hide 66 */ 67 public int shadowColor; 68 69 /** 70 * @hide 71 */ 72 public int mBidiFlags = BIDI_DEFAULT_LTR; 73 74 static final Style[] sStyleArray = { 75 Style.FILL, Style.STROKE, Style.FILL_AND_STROKE 76 }; 77 static final Cap[] sCapArray = { 78 Cap.BUTT, Cap.ROUND, Cap.SQUARE 79 }; 80 static final Join[] sJoinArray = { 81 Join.MITER, Join.ROUND, Join.BEVEL 82 }; 83 static final Align[] sAlignArray = { 84 Align.LEFT, Align.CENTER, Align.RIGHT 85 }; 86 87 /** bit mask for the flag enabling antialiasing */ 88 public static final int ANTI_ALIAS_FLAG = 0x01; 89 /** bit mask for the flag enabling bitmap filtering */ 90 public static final int FILTER_BITMAP_FLAG = 0x02; 91 /** bit mask for the flag enabling dithering */ 92 public static final int DITHER_FLAG = 0x04; 93 /** bit mask for the flag enabling underline text */ 94 public static final int UNDERLINE_TEXT_FLAG = 0x08; 95 /** bit mask for the flag enabling strike-thru text */ 96 public static final int STRIKE_THRU_TEXT_FLAG = 0x10; 97 /** bit mask for the flag enabling fake-bold text */ 98 public static final int FAKE_BOLD_TEXT_FLAG = 0x20; 99 /** bit mask for the flag enabling linear-text (no caching) */ 100 public static final int LINEAR_TEXT_FLAG = 0x40; 101 /** bit mask for the flag enabling subpixel-text */ 102 public static final int SUBPIXEL_TEXT_FLAG = 0x80; 103 /** bit mask for the flag enabling device kerning for text */ 104 public static final int DEV_KERN_TEXT_FLAG = 0x100; 105 106 // we use this when we first create a paint 107 static final int DEFAULT_PAINT_FLAGS = DEV_KERN_TEXT_FLAG; 108 109 /** 110 * Option for {@link #setHinting}: disable hinting. 111 */ 112 public static final int HINTING_OFF = 0x0; 113 114 /** 115 * Option for {@link #setHinting}: enable hinting. 116 */ 117 public static final int HINTING_ON = 0x1; 118 119 /** 120 * Bidi flag to set LTR paragraph direction. 121 * 122 * @hide 123 */ 124 public static final int BIDI_LTR = 0x0; 125 126 /** 127 * Bidi flag to set RTL paragraph direction. 128 * 129 * @hide 130 */ 131 public static final int BIDI_RTL = 0x1; 132 133 /** 134 * Bidi flag to detect paragraph direction via heuristics, defaulting to 135 * LTR. 136 * 137 * @hide 138 */ 139 public static final int BIDI_DEFAULT_LTR = 0x2; 140 141 /** 142 * Bidi flag to detect paragraph direction via heuristics, defaulting to 143 * RTL. 144 * 145 * @hide 146 */ 147 public static final int BIDI_DEFAULT_RTL = 0x3; 148 149 /** 150 * Bidi flag to override direction to all LTR (ignore bidi). 151 * 152 * @hide 153 */ 154 public static final int BIDI_FORCE_LTR = 0x4; 155 156 /** 157 * Bidi flag to override direction to all RTL (ignore bidi). 158 * 159 * @hide 160 */ 161 public static final int BIDI_FORCE_RTL = 0x5; 162 163 /** 164 * Maximum Bidi flag value. 165 * @hide 166 */ 167 private static final int BIDI_MAX_FLAG_VALUE = BIDI_FORCE_RTL; 168 169 /** 170 * Mask for bidi flags. 171 * @hide 172 */ 173 private static final int BIDI_FLAG_MASK = 0x7; 174 175 /** 176 * Flag for getTextRunAdvances indicating left-to-right run direction. 177 * @hide 178 */ 179 public static final int DIRECTION_LTR = 0; 180 181 /** 182 * Flag for getTextRunAdvances indicating right-to-left run direction. 183 * @hide 184 */ 185 public static final int DIRECTION_RTL = 1; 186 187 /** 188 * Option for getTextRunCursor to compute the valid cursor after 189 * offset or the limit of the context, whichever is less. 190 * @hide 191 */ 192 public static final int CURSOR_AFTER = 0; 193 194 /** 195 * Option for getTextRunCursor to compute the valid cursor at or after 196 * the offset or the limit of the context, whichever is less. 197 * @hide 198 */ 199 public static final int CURSOR_AT_OR_AFTER = 1; 200 201 /** 202 * Option for getTextRunCursor to compute the valid cursor before 203 * offset or the start of the context, whichever is greater. 204 * @hide 205 */ 206 public static final int CURSOR_BEFORE = 2; 207 208 /** 209 * Option for getTextRunCursor to compute the valid cursor at or before 210 * offset or the start of the context, whichever is greater. 211 * @hide 212 */ 213 public static final int CURSOR_AT_OR_BEFORE = 3; 214 215 /** 216 * Option for getTextRunCursor to return offset if the cursor at offset 217 * is valid, or -1 if it isn't. 218 * @hide 219 */ 220 public static final int CURSOR_AT = 4; 221 222 /** 223 * Maximum cursor option value. 224 */ 225 private static final int CURSOR_OPT_MAX_VALUE = CURSOR_AT; 226 227 /** 228 * The Style specifies if the primitive being drawn is filled, stroked, or 229 * both (in the same color). The default is FILL. 230 */ 231 public enum Style { 232 /** 233 * Geometry and text drawn with this style will be filled, ignoring all 234 * stroke-related settings in the paint. 235 */ 236 FILL (0), 237 /** 238 * Geometry and text drawn with this style will be stroked, respecting 239 * the stroke-related fields on the paint. 240 */ 241 STROKE (1), 242 /** 243 * Geometry and text drawn with this style will be both filled and 244 * stroked at the same time, respecting the stroke-related fields on 245 * the paint. This mode can give unexpected results if the geometry 246 * is oriented counter-clockwise. This restriction does not apply to 247 * either FILL or STROKE. 248 */ 249 FILL_AND_STROKE (2); 250 251 Style(int nativeInt) { 252 this.nativeInt = nativeInt; 253 } 254 final int nativeInt; 255 } 256 257 /** 258 * The Cap specifies the treatment for the beginning and ending of 259 * stroked lines and paths. The default is BUTT. 260 */ 261 public enum Cap { 262 /** 263 * The stroke ends with the path, and does not project beyond it. 264 */ 265 BUTT (0), 266 /** 267 * The stroke projects out as a semicircle, with the center at the 268 * end of the path. 269 */ 270 ROUND (1), 271 /** 272 * The stroke projects out as a square, with the center at the end 273 * of the path. 274 */ 275 SQUARE (2); 276 277 private Cap(int nativeInt) { 278 this.nativeInt = nativeInt; 279 } 280 final int nativeInt; 281 } 282 283 /** 284 * The Join specifies the treatment where lines and curve segments 285 * join on a stroked path. The default is MITER. 286 */ 287 public enum Join { 288 /** 289 * The outer edges of a join meet at a sharp angle 290 */ 291 MITER (0), 292 /** 293 * The outer edges of a join meet in a circular arc. 294 */ 295 ROUND (1), 296 /** 297 * The outer edges of a join meet with a straight line 298 */ 299 BEVEL (2); 300 301 private Join(int nativeInt) { 302 this.nativeInt = nativeInt; 303 } 304 final int nativeInt; 305 } 306 307 /** 308 * Align specifies how drawText aligns its text relative to the 309 * [x,y] coordinates. The default is LEFT. 310 */ 311 public enum Align { 312 /** 313 * The text is drawn to the right of the x,y origin 314 */ 315 LEFT (0), 316 /** 317 * The text is drawn centered horizontally on the x,y origin 318 */ 319 CENTER (1), 320 /** 321 * The text is drawn to the left of the x,y origin 322 */ 323 RIGHT (2); 324 325 private Align(int nativeInt) { 326 this.nativeInt = nativeInt; 327 } 328 final int nativeInt; 329 } 330 331 /** 332 * Create a new paint with default settings. 333 */ 334 public Paint() { 335 this(0); 336 } 337 338 /** 339 * Create a new paint with the specified flags. Use setFlags() to change 340 * these after the paint is created. 341 * 342 * @param flags initial flag bits, as if they were passed via setFlags(). 343 */ 344 public Paint(int flags) { 345 mNativePaint = native_init(); 346 setFlags(flags | DEFAULT_PAINT_FLAGS); 347 setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV 348 ? HINTING_OFF : HINTING_ON); 349 mCompatScaling = mInvCompatScaling = 1; 350 } 351 352 /** 353 * Create a new paint, initialized with the attributes in the specified 354 * paint parameter. 355 * 356 * @param paint Existing paint used to initialized the attributes of the 357 * new paint. 358 */ 359 public Paint(Paint paint) { 360 mNativePaint = native_initWithPaint(paint.mNativePaint); 361 setClassVariablesFrom(paint); 362 } 363 364 /** Restores the paint to its default settings. */ 365 public void reset() { 366 native_reset(mNativePaint); 367 setFlags(DEFAULT_PAINT_FLAGS); 368 setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV 369 ? HINTING_OFF : HINTING_ON); 370 mHasCompatScaling = false; 371 mCompatScaling = mInvCompatScaling = 1; 372 mBidiFlags = BIDI_DEFAULT_LTR; 373 } 374 375 /** 376 * Copy the fields from src into this paint. This is equivalent to calling 377 * get() on all of the src fields, and calling the corresponding set() 378 * methods on this. 379 */ 380 public void set(Paint src) { 381 if (this != src) { 382 // copy over the native settings 383 native_set(mNativePaint, src.mNativePaint); 384 setClassVariablesFrom(src); 385 } 386 } 387 388 /** 389 * Set all class variables using current values from the given 390 * {@link Paint}. 391 */ 392 private void setClassVariablesFrom(Paint paint) { 393 mColorFilter = paint.mColorFilter; 394 mMaskFilter = paint.mMaskFilter; 395 mPathEffect = paint.mPathEffect; 396 mRasterizer = paint.mRasterizer; 397 mShader = paint.mShader; 398 mTypeface = paint.mTypeface; 399 mXfermode = paint.mXfermode; 400 401 mHasCompatScaling = paint.mHasCompatScaling; 402 mCompatScaling = paint.mCompatScaling; 403 mInvCompatScaling = paint.mInvCompatScaling; 404 405 hasShadow = paint.hasShadow; 406 shadowDx = paint.shadowDx; 407 shadowDy = paint.shadowDy; 408 shadowRadius = paint.shadowRadius; 409 shadowColor = paint.shadowColor; 410 411 mBidiFlags = paint.mBidiFlags; 412 } 413 414 /** @hide */ 415 public void setCompatibilityScaling(float factor) { 416 if (factor == 1.0) { 417 mHasCompatScaling = false; 418 mCompatScaling = mInvCompatScaling = 1.0f; 419 } else { 420 mHasCompatScaling = true; 421 mCompatScaling = factor; 422 mInvCompatScaling = 1.0f/factor; 423 } 424 } 425 426 /** 427 * Return the bidi flags on the paint. 428 * 429 * @return the bidi flags on the paint 430 * @hide 431 */ 432 public int getBidiFlags() { 433 return mBidiFlags; 434 } 435 436 /** 437 * Set the bidi flags on the paint. 438 * @hide 439 */ 440 public void setBidiFlags(int flags) { 441 // only flag value is the 3-bit BIDI control setting 442 flags &= BIDI_FLAG_MASK; 443 if (flags > BIDI_MAX_FLAG_VALUE) { 444 throw new IllegalArgumentException("unknown bidi flag: " + flags); 445 } 446 mBidiFlags = flags; 447 } 448 449 /** 450 * Return the paint's flags. Use the Flag enum to test flag values. 451 * 452 * @return the paint's flags (see enums ending in _Flag for bit masks) 453 */ 454 public native int getFlags(); 455 456 /** 457 * Set the paint's flags. Use the Flag enum to specific flag values. 458 * 459 * @param flags The new flag bits for the paint 460 */ 461 public native void setFlags(int flags); 462 463 /** 464 * Return the paint's hinting mode. Returns either 465 * {@link #HINTING_OFF} or {@link #HINTING_ON}. 466 */ 467 public native int getHinting(); 468 469 /** 470 * Set the paint's hinting mode. May be either 471 * {@link #HINTING_OFF} or {@link #HINTING_ON}. 472 */ 473 public native void setHinting(int mode); 474 475 /** 476 * Helper for getFlags(), returning true if ANTI_ALIAS_FLAG bit is set 477 * AntiAliasing smooths out the edges of what is being drawn, but is has 478 * no impact on the interior of the shape. See setDither() and 479 * setFilterBitmap() to affect how colors are treated. 480 * 481 * @return true if the antialias bit is set in the paint's flags. 482 */ 483 public final boolean isAntiAlias() { 484 return (getFlags() & ANTI_ALIAS_FLAG) != 0; 485 } 486 487 /** 488 * Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit 489 * AntiAliasing smooths out the edges of what is being drawn, but is has 490 * no impact on the interior of the shape. See setDither() and 491 * setFilterBitmap() to affect how colors are treated. 492 * 493 * @param aa true to set the antialias bit in the flags, false to clear it 494 */ 495 public native void setAntiAlias(boolean aa); 496 497 /** 498 * Helper for getFlags(), returning true if DITHER_FLAG bit is set 499 * Dithering affects how colors that are higher precision than the device 500 * are down-sampled. No dithering is generally faster, but higher precision 501 * colors are just truncated down (e.g. 8888 -> 565). Dithering tries to 502 * distribute the error inherent in this process, to reduce the visual 503 * artifacts. 504 * 505 * @return true if the dithering bit is set in the paint's flags. 506 */ 507 public final boolean isDither() { 508 return (getFlags() & DITHER_FLAG) != 0; 509 } 510 511 /** 512 * Helper for setFlags(), setting or clearing the DITHER_FLAG bit 513 * Dithering affects how colors that are higher precision than the device 514 * are down-sampled. No dithering is generally faster, but higher precision 515 * colors are just truncated down (e.g. 8888 -> 565). Dithering tries to 516 * distribute the error inherent in this process, to reduce the visual 517 * artifacts. 518 * 519 * @param dither true to set the dithering bit in flags, false to clear it 520 */ 521 public native void setDither(boolean dither); 522 523 /** 524 * Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set 525 * 526 * @return true if the lineartext bit is set in the paint's flags 527 */ 528 public final boolean isLinearText() { 529 return (getFlags() & LINEAR_TEXT_FLAG) != 0; 530 } 531 532 /** 533 * Helper for setFlags(), setting or clearing the LINEAR_TEXT_FLAG bit 534 * 535 * @param linearText true to set the linearText bit in the paint's flags, 536 * false to clear it. 537 */ 538 public native void setLinearText(boolean linearText); 539 540 /** 541 * Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set 542 * 543 * @return true if the subpixel bit is set in the paint's flags 544 */ 545 public final boolean isSubpixelText() { 546 return (getFlags() & SUBPIXEL_TEXT_FLAG) != 0; 547 } 548 549 /** 550 * Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit 551 * 552 * @param subpixelText true to set the subpixelText bit in the paint's 553 * flags, false to clear it. 554 */ 555 public native void setSubpixelText(boolean subpixelText); 556 557 /** 558 * Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set 559 * 560 * @return true if the underlineText bit is set in the paint's flags. 561 */ 562 public final boolean isUnderlineText() { 563 return (getFlags() & UNDERLINE_TEXT_FLAG) != 0; 564 } 565 566 /** 567 * Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit 568 * 569 * @param underlineText true to set the underlineText bit in the paint's 570 * flags, false to clear it. 571 */ 572 public native void setUnderlineText(boolean underlineText); 573 574 /** 575 * Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set 576 * 577 * @return true if the strikeThruText bit is set in the paint's flags. 578 */ 579 public final boolean isStrikeThruText() { 580 return (getFlags() & STRIKE_THRU_TEXT_FLAG) != 0; 581 } 582 583 /** 584 * Helper for setFlags(), setting or clearing the STRIKE_THRU_TEXT_FLAG bit 585 * 586 * @param strikeThruText true to set the strikeThruText bit in the paint's 587 * flags, false to clear it. 588 */ 589 public native void setStrikeThruText(boolean strikeThruText); 590 591 /** 592 * Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set 593 * 594 * @return true if the fakeBoldText bit is set in the paint's flags. 595 */ 596 public final boolean isFakeBoldText() { 597 return (getFlags() & FAKE_BOLD_TEXT_FLAG) != 0; 598 } 599 600 /** 601 * Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit 602 * 603 * @param fakeBoldText true to set the fakeBoldText bit in the paint's 604 * flags, false to clear it. 605 */ 606 public native void setFakeBoldText(boolean fakeBoldText); 607 608 /** 609 * Whether or not the bitmap filter is activated. 610 * Filtering affects the sampling of bitmaps when they are transformed. 611 * Filtering does not affect how the colors in the bitmap are converted into 612 * device pixels. That is dependent on dithering and xfermodes. 613 * 614 * @see #setFilterBitmap(boolean) setFilterBitmap() 615 */ 616 public final boolean isFilterBitmap() { 617 return (getFlags() & FILTER_BITMAP_FLAG) != 0; 618 } 619 620 /** 621 * Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit. 622 * Filtering affects the sampling of bitmaps when they are transformed. 623 * Filtering does not affect how the colors in the bitmap are converted into 624 * device pixels. That is dependent on dithering and xfermodes. 625 * 626 * @param filter true to set the FILTER_BITMAP_FLAG bit in the paint's 627 * flags, false to clear it. 628 */ 629 public native void setFilterBitmap(boolean filter); 630 631 /** 632 * Return the paint's style, used for controlling how primitives' 633 * geometries are interpreted (except for drawBitmap, which always assumes 634 * FILL_STYLE). 635 * 636 * @return the paint's style setting (Fill, Stroke, StrokeAndFill) 637 */ 638 public Style getStyle() { 639 return sStyleArray[native_getStyle(mNativePaint)]; 640 } 641 642 /** 643 * Set the paint's style, used for controlling how primitives' 644 * geometries are interpreted (except for drawBitmap, which always assumes 645 * Fill). 646 * 647 * @param style The new style to set in the paint 648 */ 649 public void setStyle(Style style) { 650 native_setStyle(mNativePaint, style.nativeInt); 651 } 652 653 /** 654 * Return the paint's color. Note that the color is a 32bit value 655 * containing alpha as well as r,g,b. This 32bit value is not premultiplied, 656 * meaning that its alpha can be any value, regardless of the values of 657 * r,g,b. See the Color class for more details. 658 * 659 * @return the paint's color (and alpha). 660 */ 661 public native int getColor(); 662 663 /** 664 * Set the paint's color. Note that the color is an int containing alpha 665 * as well as r,g,b. This 32bit value is not premultiplied, meaning that 666 * its alpha can be any value, regardless of the values of r,g,b. 667 * See the Color class for more details. 668 * 669 * @param color The new color (including alpha) to set in the paint. 670 */ 671 public native void setColor(int color); 672 673 /** 674 * Helper to getColor() that just returns the color's alpha value. This is 675 * the same as calling getColor() >>> 24. It always returns a value between 676 * 0 (completely transparent) and 255 (completely opaque). 677 * 678 * @return the alpha component of the paint's color. 679 */ 680 public native int getAlpha(); 681 682 /** 683 * Helper to setColor(), that only assigns the color's alpha value, 684 * leaving its r,g,b values unchanged. Results are undefined if the alpha 685 * value is outside of the range [0..255] 686 * 687 * @param a set the alpha component [0..255] of the paint's color. 688 */ 689 public native void setAlpha(int a); 690 691 /** 692 * Helper to setColor(), that takes a,r,g,b and constructs the color int 693 * 694 * @param a The new alpha component (0..255) of the paint's color. 695 * @param r The new red component (0..255) of the paint's color. 696 * @param g The new green component (0..255) of the paint's color. 697 * @param b The new blue component (0..255) of the paint's color. 698 */ 699 public void setARGB(int a, int r, int g, int b) { 700 setColor((a << 24) | (r << 16) | (g << 8) | b); 701 } 702 703 /** 704 * Return the width for stroking. 705 * <p /> 706 * A value of 0 strokes in hairline mode. 707 * Hairlines always draws a single pixel independent of the canva's matrix. 708 * 709 * @return the paint's stroke width, used whenever the paint's style is 710 * Stroke or StrokeAndFill. 711 */ 712 public native float getStrokeWidth(); 713 714 /** 715 * Set the width for stroking. 716 * Pass 0 to stroke in hairline mode. 717 * Hairlines always draws a single pixel independent of the canva's matrix. 718 * 719 * @param width set the paint's stroke width, used whenever the paint's 720 * style is Stroke or StrokeAndFill. 721 */ 722 public native void setStrokeWidth(float width); 723 724 /** 725 * Return the paint's stroke miter value. Used to control the behavior 726 * of miter joins when the joins angle is sharp. 727 * 728 * @return the paint's miter limit, used whenever the paint's style is 729 * Stroke or StrokeAndFill. 730 */ 731 public native float getStrokeMiter(); 732 733 /** 734 * Set the paint's stroke miter value. This is used to control the behavior 735 * of miter joins when the joins angle is sharp. This value must be >= 0. 736 * 737 * @param miter set the miter limit on the paint, used whenever the paint's 738 * style is Stroke or StrokeAndFill. 739 */ 740 public native void setStrokeMiter(float miter); 741 742 /** 743 * Return the paint's Cap, controlling how the start and end of stroked 744 * lines and paths are treated. 745 * 746 * @return the line cap style for the paint, used whenever the paint's 747 * style is Stroke or StrokeAndFill. 748 */ 749 public Cap getStrokeCap() { 750 return sCapArray[native_getStrokeCap(mNativePaint)]; 751 } 752 753 /** 754 * Set the paint's Cap. 755 * 756 * @param cap set the paint's line cap style, used whenever the paint's 757 * style is Stroke or StrokeAndFill. 758 */ 759 public void setStrokeCap(Cap cap) { 760 native_setStrokeCap(mNativePaint, cap.nativeInt); 761 } 762 763 /** 764 * Return the paint's stroke join type. 765 * 766 * @return the paint's Join. 767 */ 768 public Join getStrokeJoin() { 769 return sJoinArray[native_getStrokeJoin(mNativePaint)]; 770 } 771 772 /** 773 * Set the paint's Join. 774 * 775 * @param join set the paint's Join, used whenever the paint's style is 776 * Stroke or StrokeAndFill. 777 */ 778 public void setStrokeJoin(Join join) { 779 native_setStrokeJoin(mNativePaint, join.nativeInt); 780 } 781 782 /** 783 * Applies any/all effects (patheffect, stroking) to src, returning the 784 * result in dst. The result is that drawing src with this paint will be 785 * the same as drawing dst with a default paint (at least from the 786 * geometric perspective). 787 * 788 * @param src input path 789 * @param dst output path (may be the same as src) 790 * @return true if the path should be filled, or false if it should be 791 * drawn with a hairline (width == 0) 792 */ 793 public boolean getFillPath(Path src, Path dst) { 794 return native_getFillPath(mNativePaint, src.ni(), dst.ni()); 795 } 796 797 /** 798 * Get the paint's shader object. 799 * 800 * @return the paint's shader (or null) 801 */ 802 public Shader getShader() { 803 return mShader; 804 } 805 806 /** 807 * Set or clear the shader object. 808 * <p /> 809 * Pass null to clear any previous shader. 810 * As a convenience, the parameter passed is also returned. 811 * 812 * @param shader May be null. the new shader to be installed in the paint 813 * @return shader 814 */ 815 public Shader setShader(Shader shader) { 816 int shaderNative = 0; 817 if (shader != null) 818 shaderNative = shader.native_instance; 819 native_setShader(mNativePaint, shaderNative); 820 mShader = shader; 821 return shader; 822 } 823 824 /** 825 * Get the paint's colorfilter (maybe be null). 826 * 827 * @return the paint's colorfilter (maybe be null) 828 */ 829 public ColorFilter getColorFilter() { 830 return mColorFilter; 831 } 832 833 /** 834 * Set or clear the paint's colorfilter, returning the parameter. 835 * 836 * @param filter May be null. The new filter to be installed in the paint 837 * @return filter 838 */ 839 public ColorFilter setColorFilter(ColorFilter filter) { 840 int filterNative = 0; 841 if (filter != null) 842 filterNative = filter.native_instance; 843 native_setColorFilter(mNativePaint, filterNative); 844 mColorFilter = filter; 845 return filter; 846 } 847 848 /** 849 * Get the paint's xfermode object. 850 * 851 * @return the paint's xfermode (or null) 852 */ 853 public Xfermode getXfermode() { 854 return mXfermode; 855 } 856 857 /** 858 * Set or clear the xfermode object. 859 * <p /> 860 * Pass null to clear any previous xfermode. 861 * As a convenience, the parameter passed is also returned. 862 * 863 * @param xfermode May be null. The xfermode to be installed in the paint 864 * @return xfermode 865 */ 866 public Xfermode setXfermode(Xfermode xfermode) { 867 int xfermodeNative = 0; 868 if (xfermode != null) 869 xfermodeNative = xfermode.native_instance; 870 native_setXfermode(mNativePaint, xfermodeNative); 871 mXfermode = xfermode; 872 return xfermode; 873 } 874 875 /** 876 * Get the paint's patheffect object. 877 * 878 * @return the paint's patheffect (or null) 879 */ 880 public PathEffect getPathEffect() { 881 return mPathEffect; 882 } 883 884 /** 885 * Set or clear the patheffect object. 886 * <p /> 887 * Pass null to clear any previous patheffect. 888 * As a convenience, the parameter passed is also returned. 889 * 890 * @param effect May be null. The patheffect to be installed in the paint 891 * @return effect 892 */ 893 public PathEffect setPathEffect(PathEffect effect) { 894 int effectNative = 0; 895 if (effect != null) { 896 effectNative = effect.native_instance; 897 } 898 native_setPathEffect(mNativePaint, effectNative); 899 mPathEffect = effect; 900 return effect; 901 } 902 903 /** 904 * Get the paint's maskfilter object. 905 * 906 * @return the paint's maskfilter (or null) 907 */ 908 public MaskFilter getMaskFilter() { 909 return mMaskFilter; 910 } 911 912 /** 913 * Set or clear the maskfilter object. 914 * <p /> 915 * Pass null to clear any previous maskfilter. 916 * As a convenience, the parameter passed is also returned. 917 * 918 * @param maskfilter May be null. The maskfilter to be installed in the 919 * paint 920 * @return maskfilter 921 */ 922 public MaskFilter setMaskFilter(MaskFilter maskfilter) { 923 int maskfilterNative = 0; 924 if (maskfilter != null) { 925 maskfilterNative = maskfilter.native_instance; 926 } 927 native_setMaskFilter(mNativePaint, maskfilterNative); 928 mMaskFilter = maskfilter; 929 return maskfilter; 930 } 931 932 /** 933 * Get the paint's typeface object. 934 * <p /> 935 * The typeface object identifies which font to use when drawing or 936 * measuring text. 937 * 938 * @return the paint's typeface (or null) 939 */ 940 public Typeface getTypeface() { 941 return mTypeface; 942 } 943 944 /** 945 * Set or clear the typeface object. 946 * <p /> 947 * Pass null to clear any previous typeface. 948 * As a convenience, the parameter passed is also returned. 949 * 950 * @param typeface May be null. The typeface to be installed in the paint 951 * @return typeface 952 */ 953 public Typeface setTypeface(Typeface typeface) { 954 int typefaceNative = 0; 955 if (typeface != null) { 956 typefaceNative = typeface.native_instance; 957 } 958 native_setTypeface(mNativePaint, typefaceNative); 959 mTypeface = typeface; 960 return typeface; 961 } 962 963 /** 964 * Get the paint's rasterizer (or null). 965 * <p /> 966 * The raster controls/modifies how paths/text are turned into alpha masks. 967 * 968 * @return the paint's rasterizer (or null) 969 */ 970 public Rasterizer getRasterizer() { 971 return mRasterizer; 972 } 973 974 /** 975 * Set or clear the rasterizer object. 976 * <p /> 977 * Pass null to clear any previous rasterizer. 978 * As a convenience, the parameter passed is also returned. 979 * 980 * @param rasterizer May be null. The new rasterizer to be installed in 981 * the paint. 982 * @return rasterizer 983 */ 984 public Rasterizer setRasterizer(Rasterizer rasterizer) { 985 int rasterizerNative = 0; 986 if (rasterizer != null) { 987 rasterizerNative = rasterizer.native_instance; 988 } 989 native_setRasterizer(mNativePaint, rasterizerNative); 990 mRasterizer = rasterizer; 991 return rasterizer; 992 } 993 994 /** 995 * This draws a shadow layer below the main layer, with the specified 996 * offset and color, and blur radius. If radius is 0, then the shadow 997 * layer is removed. 998 */ 999 public void setShadowLayer(float radius, float dx, float dy, int color) { 1000 hasShadow = radius > 0.0f; 1001 shadowRadius = radius; 1002 shadowDx = dx; 1003 shadowDy = dy; 1004 shadowColor = color; 1005 nSetShadowLayer(radius, dx, dy, color); 1006 } 1007 1008 private native void nSetShadowLayer(float radius, float dx, float dy, int color); 1009 1010 /** 1011 * Clear the shadow layer. 1012 */ 1013 public void clearShadowLayer() { 1014 hasShadow = false; 1015 nSetShadowLayer(0, 0, 0, 0); 1016 } 1017 1018 /** 1019 * Return the paint's Align value for drawing text. This controls how the 1020 * text is positioned relative to its origin. LEFT align means that all of 1021 * the text will be drawn to the right of its origin (i.e. the origin 1022 * specifieds the LEFT edge of the text) and so on. 1023 * 1024 * @return the paint's Align value for drawing text. 1025 */ 1026 public Align getTextAlign() { 1027 return sAlignArray[native_getTextAlign(mNativePaint)]; 1028 } 1029 1030 /** 1031 * Set the paint's text alignment. This controls how the 1032 * text is positioned relative to its origin. LEFT align means that all of 1033 * the text will be drawn to the right of its origin (i.e. the origin 1034 * specifieds the LEFT edge of the text) and so on. 1035 * 1036 * @param align set the paint's Align value for drawing text. 1037 */ 1038 public void setTextAlign(Align align) { 1039 native_setTextAlign(mNativePaint, align.nativeInt); 1040 } 1041 1042 /** 1043 * Return the paint's text size. 1044 * 1045 * @return the paint's text size. 1046 */ 1047 public native float getTextSize(); 1048 1049 /** 1050 * Set the paint's text size. This value must be > 0 1051 * 1052 * @param textSize set the paint's text size. 1053 */ 1054 public native void setTextSize(float textSize); 1055 1056 /** 1057 * Return the paint's horizontal scale factor for text. The default value 1058 * is 1.0. 1059 * 1060 * @return the paint's scale factor in X for drawing/measuring text 1061 */ 1062 public native float getTextScaleX(); 1063 1064 /** 1065 * Set the paint's horizontal scale factor for text. The default value 1066 * is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will 1067 * stretch the text narrower. 1068 * 1069 * @param scaleX set the paint's scale in X for drawing/measuring text. 1070 */ 1071 public native void setTextScaleX(float scaleX); 1072 1073 /** 1074 * Return the paint's horizontal skew factor for text. The default value 1075 * is 0. 1076 * 1077 * @return the paint's skew factor in X for drawing text. 1078 */ 1079 public native float getTextSkewX(); 1080 1081 /** 1082 * Set the paint's horizontal skew factor for text. The default value 1083 * is 0. For approximating oblique text, use values around -0.25. 1084 * 1085 * @param skewX set the paint's skew factor in X for drawing text. 1086 */ 1087 public native void setTextSkewX(float skewX); 1088 1089 /** 1090 * Return the distance above (negative) the baseline (ascent) based on the 1091 * current typeface and text size. 1092 * 1093 * @return the distance above (negative) the baseline (ascent) based on the 1094 * current typeface and text size. 1095 */ 1096 public native float ascent(); 1097 1098 /** 1099 * Return the distance below (positive) the baseline (descent) based on the 1100 * current typeface and text size. 1101 * 1102 * @return the distance below (positive) the baseline (descent) based on 1103 * the current typeface and text size. 1104 */ 1105 public native float descent(); 1106 1107 /** 1108 * Class that describes the various metrics for a font at a given text size. 1109 * Remember, Y values increase going down, so those values will be positive, 1110 * and values that measure distances going up will be negative. This class 1111 * is returned by getFontMetrics(). 1112 */ 1113 public static class FontMetrics { 1114 /** 1115 * The maximum distance above the baseline for the tallest glyph in 1116 * the font at a given text size. 1117 */ 1118 public float top; 1119 /** 1120 * The recommended distance above the baseline for singled spaced text. 1121 */ 1122 public float ascent; 1123 /** 1124 * The recommended distance below the baseline for singled spaced text. 1125 */ 1126 public float descent; 1127 /** 1128 * The maximum distance below the baseline for the lowest glyph in 1129 * the font at a given text size. 1130 */ 1131 public float bottom; 1132 /** 1133 * The recommended additional space to add between lines of text. 1134 */ 1135 public float leading; 1136 } 1137 1138 /** 1139 * Return the font's recommended interline spacing, given the Paint's 1140 * settings for typeface, textSize, etc. If metrics is not null, return the 1141 * fontmetric values in it. 1142 * 1143 * @param metrics If this object is not null, its fields are filled with 1144 * the appropriate values given the paint's text attributes. 1145 * @return the font's recommended interline spacing. 1146 */ 1147 public native float getFontMetrics(FontMetrics metrics); 1148 1149 /** 1150 * Allocates a new FontMetrics object, and then calls getFontMetrics(fm) 1151 * with it, returning the object. 1152 */ 1153 public FontMetrics getFontMetrics() { 1154 FontMetrics fm = new FontMetrics(); 1155 getFontMetrics(fm); 1156 return fm; 1157 } 1158 1159 /** 1160 * Convenience method for callers that want to have FontMetrics values as 1161 * integers. 1162 */ 1163 public static class FontMetricsInt { 1164 public int top; 1165 public int ascent; 1166 public int descent; 1167 public int bottom; 1168 public int leading; 1169 1170 @Override public String toString() { 1171 return "FontMetricsInt: top=" + top + " ascent=" + ascent + 1172 " descent=" + descent + " bottom=" + bottom + 1173 " leading=" + leading; 1174 } 1175 } 1176 1177 /** 1178 * Return the font's interline spacing, given the Paint's settings for 1179 * typeface, textSize, etc. If metrics is not null, return the fontmetric 1180 * values in it. Note: all values have been converted to integers from 1181 * floats, in such a way has to make the answers useful for both spacing 1182 * and clipping. If you want more control over the rounding, call 1183 * getFontMetrics(). 1184 * 1185 * @return the font's interline spacing. 1186 */ 1187 public native int getFontMetricsInt(FontMetricsInt fmi); 1188 1189 public FontMetricsInt getFontMetricsInt() { 1190 FontMetricsInt fm = new FontMetricsInt(); 1191 getFontMetricsInt(fm); 1192 return fm; 1193 } 1194 1195 /** 1196 * Return the recommend line spacing based on the current typeface and 1197 * text size. 1198 * 1199 * @return recommend line spacing based on the current typeface and 1200 * text size. 1201 */ 1202 public float getFontSpacing() { 1203 return getFontMetrics(null); 1204 } 1205 1206 /** 1207 * Return the width of the text. 1208 * 1209 * @param text The text to measure. Cannot be null. 1210 * @param index The index of the first character to start measuring 1211 * @param count THe number of characters to measure, beginning with start 1212 * @return The width of the text 1213 */ 1214 public float measureText(char[] text, int index, int count) { 1215 if (text == null) { 1216 throw new IllegalArgumentException("text cannot be null"); 1217 } 1218 if ((index | count) < 0 || index + count > text.length) { 1219 throw new ArrayIndexOutOfBoundsException(); 1220 } 1221 1222 if (text.length == 0 || count == 0) { 1223 return 0f; 1224 } 1225 if (!mHasCompatScaling) { 1226 return native_measureText(text, index, count); 1227 } 1228 1229 final float oldSize = getTextSize(); 1230 setTextSize(oldSize*mCompatScaling); 1231 float w = native_measureText(text, index, count); 1232 setTextSize(oldSize); 1233 return w*mInvCompatScaling; 1234 } 1235 1236 private native float native_measureText(char[] text, int index, int count); 1237 1238 /** 1239 * Return the width of the text. 1240 * 1241 * @param text The text to measure. Cannot be null. 1242 * @param start The index of the first character to start measuring 1243 * @param end 1 beyond the index of the last character to measure 1244 * @return The width of the text 1245 */ 1246 public float measureText(String text, int start, int end) { 1247 if (text == null) { 1248 throw new IllegalArgumentException("text cannot be null"); 1249 } 1250 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1251 throw new IndexOutOfBoundsException(); 1252 } 1253 1254 if (text.length() == 0 || start == end) { 1255 return 0f; 1256 } 1257 if (!mHasCompatScaling) { 1258 return native_measureText(text, start, end); 1259 } 1260 1261 final float oldSize = getTextSize(); 1262 setTextSize(oldSize*mCompatScaling); 1263 float w = native_measureText(text, start, end); 1264 setTextSize(oldSize); 1265 return w*mInvCompatScaling; 1266 } 1267 1268 private native float native_measureText(String text, int start, int end); 1269 1270 /** 1271 * Return the width of the text. 1272 * 1273 * @param text The text to measure. Cannot be null. 1274 * @return The width of the text 1275 */ 1276 public float measureText(String text) { 1277 if (text == null) { 1278 throw new IllegalArgumentException("text cannot be null"); 1279 } 1280 1281 if (text.length() == 0) { 1282 return 0f; 1283 } 1284 1285 if (!mHasCompatScaling) return native_measureText(text); 1286 final float oldSize = getTextSize(); 1287 setTextSize(oldSize*mCompatScaling); 1288 float w = native_measureText(text); 1289 setTextSize(oldSize); 1290 return w*mInvCompatScaling; 1291 } 1292 1293 private native float native_measureText(String text); 1294 1295 /** 1296 * Return the width of the text. 1297 * 1298 * @param text The text to measure 1299 * @param start The index of the first character to start measuring 1300 * @param end 1 beyond the index of the last character to measure 1301 * @return The width of the text 1302 */ 1303 public float measureText(CharSequence text, int start, int end) { 1304 if (text == null) { 1305 throw new IllegalArgumentException("text cannot be null"); 1306 } 1307 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1308 throw new IndexOutOfBoundsException(); 1309 } 1310 1311 if (text.length() == 0 || start == end) { 1312 return 0f; 1313 } 1314 if (text instanceof String) { 1315 return measureText((String)text, start, end); 1316 } 1317 if (text instanceof SpannedString || 1318 text instanceof SpannableString) { 1319 return measureText(text.toString(), start, end); 1320 } 1321 if (text instanceof GraphicsOperations) { 1322 return ((GraphicsOperations)text).measureText(start, end, this); 1323 } 1324 1325 char[] buf = TemporaryBuffer.obtain(end - start); 1326 TextUtils.getChars(text, start, end, buf, 0); 1327 float result = measureText(buf, 0, end - start); 1328 TemporaryBuffer.recycle(buf); 1329 return result; 1330 } 1331 1332 /** 1333 * Measure the text, stopping early if the measured width exceeds maxWidth. 1334 * Return the number of chars that were measured, and if measuredWidth is 1335 * not null, return in it the actual width measured. 1336 * 1337 * @param text The text to measure. Cannot be null. 1338 * @param index The offset into text to begin measuring at 1339 * @param count The number of maximum number of entries to measure. If count 1340 * is negative, then the characters are measured in reverse order. 1341 * @param maxWidth The maximum width to accumulate. 1342 * @param measuredWidth Optional. If not null, returns the actual width 1343 * measured. 1344 * @return The number of chars that were measured. Will always be <= 1345 * abs(count). 1346 */ 1347 public int breakText(char[] text, int index, int count, 1348 float maxWidth, float[] measuredWidth) { 1349 if (text == null) { 1350 throw new IllegalArgumentException("text cannot be null"); 1351 } 1352 if (index < 0 || text.length - index < Math.abs(count)) { 1353 throw new ArrayIndexOutOfBoundsException(); 1354 } 1355 1356 if (text.length == 0 || count == 0) { 1357 return 0; 1358 } 1359 if (!mHasCompatScaling) { 1360 return native_breakText(text, index, count, maxWidth, measuredWidth); 1361 } 1362 1363 final float oldSize = getTextSize(); 1364 setTextSize(oldSize*mCompatScaling); 1365 int res = native_breakText(text, index, count, maxWidth*mCompatScaling, 1366 measuredWidth); 1367 setTextSize(oldSize); 1368 if (measuredWidth != null) measuredWidth[0] *= mInvCompatScaling; 1369 return res; 1370 } 1371 1372 private native int native_breakText(char[] text, int index, int count, 1373 float maxWidth, float[] measuredWidth); 1374 1375 /** 1376 * Measure the text, stopping early if the measured width exceeds maxWidth. 1377 * Return the number of chars that were measured, and if measuredWidth is 1378 * not null, return in it the actual width measured. 1379 * 1380 * @param text The text to measure. Cannot be null. 1381 * @param start The offset into text to begin measuring at 1382 * @param end The end of the text slice to measure. 1383 * @param measureForwards If true, measure forwards, starting at start. 1384 * Otherwise, measure backwards, starting with end. 1385 * @param maxWidth The maximum width to accumulate. 1386 * @param measuredWidth Optional. If not null, returns the actual width 1387 * measured. 1388 * @return The number of chars that were measured. Will always be <= 1389 * abs(end - start). 1390 */ 1391 public int breakText(CharSequence text, int start, int end, 1392 boolean measureForwards, 1393 float maxWidth, float[] measuredWidth) { 1394 if (text == null) { 1395 throw new IllegalArgumentException("text cannot be null"); 1396 } 1397 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1398 throw new IndexOutOfBoundsException(); 1399 } 1400 1401 if (text.length() == 0 || start == end) { 1402 return 0; 1403 } 1404 if (start == 0 && text instanceof String && end == text.length()) { 1405 return breakText((String) text, measureForwards, maxWidth, 1406 measuredWidth); 1407 } 1408 1409 char[] buf = TemporaryBuffer.obtain(end - start); 1410 int result; 1411 1412 TextUtils.getChars(text, start, end, buf, 0); 1413 1414 if (measureForwards) { 1415 result = breakText(buf, 0, end - start, maxWidth, measuredWidth); 1416 } else { 1417 result = breakText(buf, 0, -(end - start), maxWidth, measuredWidth); 1418 } 1419 1420 TemporaryBuffer.recycle(buf); 1421 return result; 1422 } 1423 1424 /** 1425 * Measure the text, stopping early if the measured width exceeds maxWidth. 1426 * Return the number of chars that were measured, and if measuredWidth is 1427 * not null, return in it the actual width measured. 1428 * 1429 * @param text The text to measure. Cannot be null. 1430 * @param measureForwards If true, measure forwards, starting with the 1431 * first character in the string. Otherwise, 1432 * measure backwards, starting with the 1433 * last character in the string. 1434 * @param maxWidth The maximum width to accumulate. 1435 * @param measuredWidth Optional. If not null, returns the actual width 1436 * measured. 1437 * @return The number of chars that were measured. Will always be <= 1438 * abs(count). 1439 */ 1440 public int breakText(String text, boolean measureForwards, 1441 float maxWidth, float[] measuredWidth) { 1442 if (text == null) { 1443 throw new IllegalArgumentException("text cannot be null"); 1444 } 1445 1446 if (text.length() == 0) { 1447 return 0; 1448 } 1449 if (!mHasCompatScaling) { 1450 return native_breakText(text, measureForwards, maxWidth, measuredWidth); 1451 } 1452 1453 final float oldSize = getTextSize(); 1454 setTextSize(oldSize*mCompatScaling); 1455 int res = native_breakText(text, measureForwards, maxWidth*mCompatScaling, 1456 measuredWidth); 1457 setTextSize(oldSize); 1458 if (measuredWidth != null) measuredWidth[0] *= mInvCompatScaling; 1459 return res; 1460 } 1461 1462 private native int native_breakText(String text, boolean measureForwards, 1463 float maxWidth, float[] measuredWidth); 1464 1465 /** 1466 * Return the advance widths for the characters in the string. 1467 * 1468 * @param text The text to measure. Cannot be null. 1469 * @param index The index of the first char to to measure 1470 * @param count The number of chars starting with index to measure 1471 * @param widths array to receive the advance widths of the characters. 1472 * Must be at least a large as count. 1473 * @return the actual number of widths returned. 1474 */ 1475 public int getTextWidths(char[] text, int index, int count, 1476 float[] widths) { 1477 if (text == null) { 1478 throw new IllegalArgumentException("text cannot be null"); 1479 } 1480 if ((index | count) < 0 || index + count > text.length 1481 || count > widths.length) { 1482 throw new ArrayIndexOutOfBoundsException(); 1483 } 1484 1485 if (text.length == 0 || count == 0) { 1486 return 0; 1487 } 1488 if (!mHasCompatScaling) { 1489 return native_getTextWidths(mNativePaint, text, index, count, widths); 1490 } 1491 1492 final float oldSize = getTextSize(); 1493 setTextSize(oldSize*mCompatScaling); 1494 int res = native_getTextWidths(mNativePaint, text, index, count, widths); 1495 setTextSize(oldSize); 1496 for (int i=0; i<res; i++) { 1497 widths[i] *= mInvCompatScaling; 1498 } 1499 return res; 1500 } 1501 1502 /** 1503 * Return the advance widths for the characters in the string. 1504 * 1505 * @param text The text to measure. Cannot be null. 1506 * @param start The index of the first char to to measure 1507 * @param end The end of the text slice to measure 1508 * @param widths array to receive the advance widths of the characters. 1509 * Must be at least a large as (end - start). 1510 * @return the actual number of widths returned. 1511 */ 1512 public int getTextWidths(CharSequence text, int start, int end, 1513 float[] widths) { 1514 if (text == null) { 1515 throw new IllegalArgumentException("text cannot be null"); 1516 } 1517 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1518 throw new IndexOutOfBoundsException(); 1519 } 1520 if (end - start > widths.length) { 1521 throw new ArrayIndexOutOfBoundsException(); 1522 } 1523 1524 if (text.length() == 0 || start == end) { 1525 return 0; 1526 } 1527 if (text instanceof String) { 1528 return getTextWidths((String) text, start, end, widths); 1529 } 1530 if (text instanceof SpannedString || 1531 text instanceof SpannableString) { 1532 return getTextWidths(text.toString(), start, end, widths); 1533 } 1534 if (text instanceof GraphicsOperations) { 1535 return ((GraphicsOperations) text).getTextWidths(start, end, 1536 widths, this); 1537 } 1538 1539 char[] buf = TemporaryBuffer.obtain(end - start); 1540 TextUtils.getChars(text, start, end, buf, 0); 1541 int result = getTextWidths(buf, 0, end - start, widths); 1542 TemporaryBuffer.recycle(buf); 1543 return result; 1544 } 1545 1546 /** 1547 * Return the advance widths for the characters in the string. 1548 * 1549 * @param text The text to measure. Cannot be null. 1550 * @param start The index of the first char to to measure 1551 * @param end The end of the text slice to measure 1552 * @param widths array to receive the advance widths of the characters. 1553 * Must be at least a large as the text. 1554 * @return the number of unichars in the specified text. 1555 */ 1556 public int getTextWidths(String text, int start, int end, float[] widths) { 1557 if (text == null) { 1558 throw new IllegalArgumentException("text cannot be null"); 1559 } 1560 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1561 throw new IndexOutOfBoundsException(); 1562 } 1563 if (end - start > widths.length) { 1564 throw new ArrayIndexOutOfBoundsException(); 1565 } 1566 1567 if (text.length() == 0 || start == end) { 1568 return 0; 1569 } 1570 if (!mHasCompatScaling) { 1571 return native_getTextWidths(mNativePaint, text, start, end, widths); 1572 } 1573 1574 final float oldSize = getTextSize(); 1575 setTextSize(oldSize*mCompatScaling); 1576 int res = native_getTextWidths(mNativePaint, text, start, end, widths); 1577 setTextSize(oldSize); 1578 for (int i=0; i<res; i++) { 1579 widths[i] *= mInvCompatScaling; 1580 } 1581 return res; 1582 } 1583 1584 /** 1585 * Return the advance widths for the characters in the string. 1586 * 1587 * @param text The text to measure 1588 * @param widths array to receive the advance widths of the characters. 1589 * Must be at least a large as the text. 1590 * @return the number of unichars in the specified text. 1591 */ 1592 public int getTextWidths(String text, float[] widths) { 1593 return getTextWidths(text, 0, text.length(), widths); 1594 } 1595 1596 /** 1597 * Return the glypth Ids for the characters in the string. 1598 * 1599 * @param text The text to measure 1600 * @param start The index of the first char to to measure 1601 * @param end The end of the text slice to measure 1602 * @param contextStart the index of the first character to use for shaping context, 1603 * must be <= start 1604 * @param contextEnd the index past the last character to use for shaping context, 1605 * must be >= end 1606 * @param flags the flags to control the advances, either {@link #DIRECTION_LTR} 1607 * or {@link #DIRECTION_RTL} 1608 * @param glyphs array to receive the glyph Ids of the characters. 1609 * Must be at least a large as the text. 1610 * @return the number of glyphs in the returned array 1611 * 1612 * @hide 1613 * 1614 * Used only for BiDi / RTL Tests 1615 */ 1616 public int getTextGlypths(String text, int start, int end, int contextStart, int contextEnd, 1617 int flags, char[] glyphs) { 1618 if (text == null) { 1619 throw new IllegalArgumentException("text cannot be null"); 1620 } 1621 if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { 1622 throw new IllegalArgumentException("unknown flags value: " + flags); 1623 } 1624 if ((start | end | contextStart | contextEnd | (end - start) 1625 | (start - contextStart) | (contextEnd - end) | (text.length() - end) 1626 | (text.length() - contextEnd)) < 0) { 1627 throw new IndexOutOfBoundsException(); 1628 } 1629 if (end - start > glyphs.length) { 1630 throw new ArrayIndexOutOfBoundsException(); 1631 } 1632 return native_getTextGlyphs(mNativePaint, text, start, end, contextStart, contextEnd, 1633 flags, glyphs); 1634 } 1635 1636 /** 1637 * Convenience overload that takes a char array instead of a 1638 * String. 1639 * 1640 * @see #getTextRunAdvances(String, int, int, int, int, int, float[], int) 1641 * @hide 1642 */ 1643 public float getTextRunAdvances(char[] chars, int index, int count, 1644 int contextIndex, int contextCount, int flags, float[] advances, 1645 int advancesIndex) { 1646 return getTextRunAdvances(chars, index, count, contextIndex, contextCount, flags, 1647 advances, advancesIndex, 0 /* use Harfbuzz*/); 1648 } 1649 1650 /** 1651 * Convenience overload that takes a char array instead of a 1652 * String. 1653 * 1654 * @see #getTextRunAdvances(String, int, int, int, int, int, float[], int, int) 1655 * @hide 1656 */ 1657 public float getTextRunAdvances(char[] chars, int index, int count, 1658 int contextIndex, int contextCount, int flags, float[] advances, 1659 int advancesIndex, int reserved) { 1660 1661 if (chars == null) { 1662 throw new IllegalArgumentException("text cannot be null"); 1663 } 1664 if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { 1665 throw new IllegalArgumentException("unknown flags value: " + flags); 1666 } 1667 if ((index | count | contextIndex | contextCount | advancesIndex 1668 | (index - contextIndex) | (contextCount - count) 1669 | ((contextIndex + contextCount) - (index + count)) 1670 | (chars.length - (contextIndex + contextCount)) 1671 | (advances == null ? 0 : 1672 (advances.length - (advancesIndex + count)))) < 0) { 1673 throw new IndexOutOfBoundsException(); 1674 } 1675 1676 if (chars.length == 0 || count == 0){ 1677 return 0f; 1678 } 1679 if (!mHasCompatScaling) { 1680 return native_getTextRunAdvances(mNativePaint, chars, index, count, 1681 contextIndex, contextCount, flags, advances, advancesIndex, reserved); 1682 } 1683 1684 final float oldSize = getTextSize(); 1685 setTextSize(oldSize * mCompatScaling); 1686 float res = native_getTextRunAdvances(mNativePaint, chars, index, count, 1687 contextIndex, contextCount, flags, advances, advancesIndex, reserved); 1688 setTextSize(oldSize); 1689 1690 if (advances != null) { 1691 for (int i = advancesIndex, e = i + count; i < e; i++) { 1692 advances[i] *= mInvCompatScaling; 1693 } 1694 } 1695 return res * mInvCompatScaling; // assume errors are not significant 1696 } 1697 1698 /** 1699 * Convenience overload that takes a CharSequence instead of a 1700 * String. 1701 * 1702 * @see #getTextRunAdvances(String, int, int, int, int, int, float[], int) 1703 * @hide 1704 */ 1705 public float getTextRunAdvances(CharSequence text, int start, int end, 1706 int contextStart, int contextEnd, int flags, float[] advances, 1707 int advancesIndex) { 1708 return getTextRunAdvances(text, start, end, contextStart, contextEnd, flags, 1709 advances, advancesIndex, 0 /* use Harfbuzz */); 1710 } 1711 1712 /** 1713 * Convenience overload that takes a CharSequence instead of a 1714 * String. 1715 * 1716 * @see #getTextRunAdvances(String, int, int, int, int, int, float[], int) 1717 * @hide 1718 */ 1719 public float getTextRunAdvances(CharSequence text, int start, int end, 1720 int contextStart, int contextEnd, int flags, float[] advances, 1721 int advancesIndex, int reserved) { 1722 1723 if (text == null) { 1724 throw new IllegalArgumentException("text cannot be null"); 1725 } 1726 if ((start | end | contextStart | contextEnd | advancesIndex | (end - start) 1727 | (start - contextStart) | (contextEnd - end) 1728 | (text.length() - contextEnd) 1729 | (advances == null ? 0 : 1730 (advances.length - advancesIndex - (end - start)))) < 0) { 1731 throw new IndexOutOfBoundsException(); 1732 } 1733 1734 if (text instanceof String) { 1735 return getTextRunAdvances((String) text, start, end, 1736 contextStart, contextEnd, flags, advances, advancesIndex, reserved); 1737 } 1738 if (text instanceof SpannedString || 1739 text instanceof SpannableString) { 1740 return getTextRunAdvances(text.toString(), start, end, 1741 contextStart, contextEnd, flags, advances, advancesIndex, reserved); 1742 } 1743 if (text instanceof GraphicsOperations) { 1744 return ((GraphicsOperations) text).getTextRunAdvances(start, end, 1745 contextStart, contextEnd, flags, advances, advancesIndex, this); 1746 } 1747 if (text.length() == 0 || end == start) { 1748 return 0f; 1749 } 1750 1751 int contextLen = contextEnd - contextStart; 1752 int len = end - start; 1753 char[] buf = TemporaryBuffer.obtain(contextLen); 1754 TextUtils.getChars(text, contextStart, contextEnd, buf, 0); 1755 float result = getTextRunAdvances(buf, start - contextStart, len, 1756 0, contextLen, flags, advances, advancesIndex, reserved); 1757 TemporaryBuffer.recycle(buf); 1758 return result; 1759 } 1760 1761 /** 1762 * Returns the total advance width for the characters in the run 1763 * between start and end, and if advances is not null, the advance 1764 * assigned to each of these characters (java chars). 1765 * 1766 * <p>The trailing surrogate in a valid surrogate pair is assigned 1767 * an advance of 0. Thus the number of returned advances is 1768 * always equal to count, not to the number of unicode codepoints 1769 * represented by the run. 1770 * 1771 * <p>In the case of conjuncts or combining marks, the total 1772 * advance is assigned to the first logical character, and the 1773 * following characters are assigned an advance of 0. 1774 * 1775 * <p>This generates the sum of the advances of glyphs for 1776 * characters in a reordered cluster as the width of the first 1777 * logical character in the cluster, and 0 for the widths of all 1778 * other characters in the cluster. In effect, such clusters are 1779 * treated like conjuncts. 1780 * 1781 * <p>The shaping bounds limit the amount of context available 1782 * outside start and end that can be used for shaping analysis. 1783 * These bounds typically reflect changes in bidi level or font 1784 * metrics across which shaping does not occur. 1785 * 1786 * @param text the text to measure. Cannot be null. 1787 * @param start the index of the first character to measure 1788 * @param end the index past the last character to measure 1789 * @param contextStart the index of the first character to use for shaping context, 1790 * must be <= start 1791 * @param contextEnd the index past the last character to use for shaping context, 1792 * must be >= end 1793 * @param flags the flags to control the advances, either {@link #DIRECTION_LTR} 1794 * or {@link #DIRECTION_RTL} 1795 * @param advances array to receive the advances, must have room for all advances, 1796 * can be null if only total advance is needed 1797 * @param advancesIndex the position in advances at which to put the 1798 * advance corresponding to the character at start 1799 * @return the total advance 1800 * 1801 * @hide 1802 */ 1803 public float getTextRunAdvances(String text, int start, int end, int contextStart, 1804 int contextEnd, int flags, float[] advances, int advancesIndex) { 1805 return getTextRunAdvances(text, start, end, contextStart, contextEnd, flags, 1806 advances, advancesIndex, 0 /* use Harfbuzz*/); 1807 } 1808 1809 /** 1810 * Returns the total advance width for the characters in the run 1811 * between start and end, and if advances is not null, the advance 1812 * assigned to each of these characters (java chars). 1813 * 1814 * <p>The trailing surrogate in a valid surrogate pair is assigned 1815 * an advance of 0. Thus the number of returned advances is 1816 * always equal to count, not to the number of unicode codepoints 1817 * represented by the run. 1818 * 1819 * <p>In the case of conjuncts or combining marks, the total 1820 * advance is assigned to the first logical character, and the 1821 * following characters are assigned an advance of 0. 1822 * 1823 * <p>This generates the sum of the advances of glyphs for 1824 * characters in a reordered cluster as the width of the first 1825 * logical character in the cluster, and 0 for the widths of all 1826 * other characters in the cluster. In effect, such clusters are 1827 * treated like conjuncts. 1828 * 1829 * <p>The shaping bounds limit the amount of context available 1830 * outside start and end that can be used for shaping analysis. 1831 * These bounds typically reflect changes in bidi level or font 1832 * metrics across which shaping does not occur. 1833 * 1834 * @param text the text to measure. Cannot be null. 1835 * @param start the index of the first character to measure 1836 * @param end the index past the last character to measure 1837 * @param contextStart the index of the first character to use for shaping context, 1838 * must be <= start 1839 * @param contextEnd the index past the last character to use for shaping context, 1840 * must be >= end 1841 * @param flags the flags to control the advances, either {@link #DIRECTION_LTR} 1842 * or {@link #DIRECTION_RTL} 1843 * @param advances array to receive the advances, must have room for all advances, 1844 * can be null if only total advance is needed 1845 * @param advancesIndex the position in advances at which to put the 1846 * advance corresponding to the character at start 1847 * @param reserved int reserved value 1848 * @return the total advance 1849 * 1850 * @hide 1851 */ 1852 public float getTextRunAdvances(String text, int start, int end, int contextStart, 1853 int contextEnd, int flags, float[] advances, int advancesIndex, int reserved) { 1854 1855 if (text == null) { 1856 throw new IllegalArgumentException("text cannot be null"); 1857 } 1858 if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { 1859 throw new IllegalArgumentException("unknown flags value: " + flags); 1860 } 1861 if ((start | end | contextStart | contextEnd | advancesIndex | (end - start) 1862 | (start - contextStart) | (contextEnd - end) 1863 | (text.length() - contextEnd) 1864 | (advances == null ? 0 : 1865 (advances.length - advancesIndex - (end - start)))) < 0) { 1866 throw new IndexOutOfBoundsException(); 1867 } 1868 1869 if (text.length() == 0 || start == end) { 1870 return 0f; 1871 } 1872 1873 if (!mHasCompatScaling) { 1874 return native_getTextRunAdvances(mNativePaint, text, start, end, 1875 contextStart, contextEnd, flags, advances, advancesIndex, reserved); 1876 } 1877 1878 final float oldSize = getTextSize(); 1879 setTextSize(oldSize * mCompatScaling); 1880 float totalAdvance = native_getTextRunAdvances(mNativePaint, text, start, end, 1881 contextStart, contextEnd, flags, advances, advancesIndex, reserved); 1882 setTextSize(oldSize); 1883 1884 if (advances != null) { 1885 for (int i = advancesIndex, e = i + (end - start); i < e; i++) { 1886 advances[i] *= mInvCompatScaling; 1887 } 1888 } 1889 return totalAdvance * mInvCompatScaling; // assume errors are insignificant 1890 } 1891 1892 /** 1893 * Returns the next cursor position in the run. This avoids placing the 1894 * cursor between surrogates, between characters that form conjuncts, 1895 * between base characters and combining marks, or within a reordering 1896 * cluster. 1897 * 1898 * <p>ContextStart and offset are relative to the start of text. 1899 * The context is the shaping context for cursor movement, generally 1900 * the bounds of the metric span enclosing the cursor in the direction of 1901 * movement. 1902 * 1903 * <p>If cursorOpt is {@link #CURSOR_AT} and the offset is not a valid 1904 * cursor position, this returns -1. Otherwise this will never return a 1905 * value before contextStart or after contextStart + contextLength. 1906 * 1907 * @param text the text 1908 * @param contextStart the start of the context 1909 * @param contextLength the length of the context 1910 * @param flags either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR} 1911 * @param offset the cursor position to move from 1912 * @param cursorOpt how to move the cursor, one of {@link #CURSOR_AFTER}, 1913 * {@link #CURSOR_AT_OR_AFTER}, {@link #CURSOR_BEFORE}, 1914 * {@link #CURSOR_AT_OR_BEFORE}, or {@link #CURSOR_AT} 1915 * @return the offset of the next position, or -1 1916 * @hide 1917 */ 1918 public int getTextRunCursor(char[] text, int contextStart, int contextLength, 1919 int flags, int offset, int cursorOpt) { 1920 int contextEnd = contextStart + contextLength; 1921 if (((contextStart | contextEnd | offset | (contextEnd - contextStart) 1922 | (offset - contextStart) | (contextEnd - offset) 1923 | (text.length - contextEnd) | cursorOpt) < 0) 1924 || cursorOpt > CURSOR_OPT_MAX_VALUE) { 1925 throw new IndexOutOfBoundsException(); 1926 } 1927 1928 return native_getTextRunCursor(mNativePaint, text, 1929 contextStart, contextLength, flags, offset, cursorOpt); 1930 } 1931 1932 /** 1933 * Returns the next cursor position in the run. This avoids placing the 1934 * cursor between surrogates, between characters that form conjuncts, 1935 * between base characters and combining marks, or within a reordering 1936 * cluster. 1937 * 1938 * <p>ContextStart, contextEnd, and offset are relative to the start of 1939 * text. The context is the shaping context for cursor movement, generally 1940 * the bounds of the metric span enclosing the cursor in the direction of 1941 * movement. 1942 * 1943 * <p>If cursorOpt is {@link #CURSOR_AT} and the offset is not a valid 1944 * cursor position, this returns -1. Otherwise this will never return a 1945 * value before contextStart or after contextEnd. 1946 * 1947 * @param text the text 1948 * @param contextStart the start of the context 1949 * @param contextEnd the end of the context 1950 * @param flags either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR} 1951 * @param offset the cursor position to move from 1952 * @param cursorOpt how to move the cursor, one of {@link #CURSOR_AFTER}, 1953 * {@link #CURSOR_AT_OR_AFTER}, {@link #CURSOR_BEFORE}, 1954 * {@link #CURSOR_AT_OR_BEFORE}, or {@link #CURSOR_AT} 1955 * @return the offset of the next position, or -1 1956 * @hide 1957 */ 1958 public int getTextRunCursor(CharSequence text, int contextStart, 1959 int contextEnd, int flags, int offset, int cursorOpt) { 1960 1961 if (text instanceof String || text instanceof SpannedString || 1962 text instanceof SpannableString) { 1963 return getTextRunCursor(text.toString(), contextStart, contextEnd, 1964 flags, offset, cursorOpt); 1965 } 1966 if (text instanceof GraphicsOperations) { 1967 return ((GraphicsOperations) text).getTextRunCursor( 1968 contextStart, contextEnd, flags, offset, cursorOpt, this); 1969 } 1970 1971 int contextLen = contextEnd - contextStart; 1972 char[] buf = TemporaryBuffer.obtain(contextLen); 1973 TextUtils.getChars(text, contextStart, contextEnd, buf, 0); 1974 int result = getTextRunCursor(buf, 0, contextLen, flags, offset - contextStart, cursorOpt); 1975 TemporaryBuffer.recycle(buf); 1976 return result; 1977 } 1978 1979 /** 1980 * Returns the next cursor position in the run. This avoids placing the 1981 * cursor between surrogates, between characters that form conjuncts, 1982 * between base characters and combining marks, or within a reordering 1983 * cluster. 1984 * 1985 * <p>ContextStart, contextEnd, and offset are relative to the start of 1986 * text. The context is the shaping context for cursor movement, generally 1987 * the bounds of the metric span enclosing the cursor in the direction of 1988 * movement. 1989 * 1990 * <p>If cursorOpt is {@link #CURSOR_AT} and the offset is not a valid 1991 * cursor position, this returns -1. Otherwise this will never return a 1992 * value before contextStart or after contextEnd. 1993 * 1994 * @param text the text 1995 * @param contextStart the start of the context 1996 * @param contextEnd the end of the context 1997 * @param flags either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR} 1998 * @param offset the cursor position to move from 1999 * @param cursorOpt how to move the cursor, one of {@link #CURSOR_AFTER}, 2000 * {@link #CURSOR_AT_OR_AFTER}, {@link #CURSOR_BEFORE}, 2001 * {@link #CURSOR_AT_OR_BEFORE}, or {@link #CURSOR_AT} 2002 * @return the offset of the next position, or -1 2003 * @hide 2004 */ 2005 public int getTextRunCursor(String text, int contextStart, int contextEnd, 2006 int flags, int offset, int cursorOpt) { 2007 if (((contextStart | contextEnd | offset | (contextEnd - contextStart) 2008 | (offset - contextStart) | (contextEnd - offset) 2009 | (text.length() - contextEnd) | cursorOpt) < 0) 2010 || cursorOpt > CURSOR_OPT_MAX_VALUE) { 2011 throw new IndexOutOfBoundsException(); 2012 } 2013 2014 return native_getTextRunCursor(mNativePaint, text, 2015 contextStart, contextEnd, flags, offset, cursorOpt); 2016 } 2017 2018 /** 2019 * Return the path (outline) for the specified text. 2020 * Note: just like Canvas.drawText, this will respect the Align setting in 2021 * the paint. 2022 * 2023 * @param text The text to retrieve the path from 2024 * @param index The index of the first character in text 2025 * @param count The number of characterss starting with index 2026 * @param x The x coordinate of the text's origin 2027 * @param y The y coordinate of the text's origin 2028 * @param path The path to receive the data describing the text. Must 2029 * be allocated by the caller. 2030 */ 2031 public void getTextPath(char[] text, int index, int count, 2032 float x, float y, Path path) { 2033 if ((index | count) < 0 || index + count > text.length) { 2034 throw new ArrayIndexOutOfBoundsException(); 2035 } 2036 native_getTextPath(mNativePaint, mBidiFlags, text, index, count, x, y, 2037 path.ni()); 2038 } 2039 2040 /** 2041 * Return the path (outline) for the specified text. 2042 * Note: just like Canvas.drawText, this will respect the Align setting 2043 * in the paint. 2044 * 2045 * @param text The text to retrieve the path from 2046 * @param start The first character in the text 2047 * @param end 1 past the last charcter in the text 2048 * @param x The x coordinate of the text's origin 2049 * @param y The y coordinate of the text's origin 2050 * @param path The path to receive the data describing the text. Must 2051 * be allocated by the caller. 2052 */ 2053 public void getTextPath(String text, int start, int end, 2054 float x, float y, Path path) { 2055 if ((start | end | (end - start) | (text.length() - end)) < 0) { 2056 throw new IndexOutOfBoundsException(); 2057 } 2058 native_getTextPath(mNativePaint, mBidiFlags, text, start, end, x, y, 2059 path.ni()); 2060 } 2061 2062 /** 2063 * Return in bounds (allocated by the caller) the smallest rectangle that 2064 * encloses all of the characters, with an implied origin at (0,0). 2065 * 2066 * @param text String to measure and return its bounds 2067 * @param start Index of the first char in the string to measure 2068 * @param end 1 past the last char in the string measure 2069 * @param bounds Returns the unioned bounds of all the text. Must be 2070 * allocated by the caller. 2071 */ 2072 public void getTextBounds(String text, int start, int end, Rect bounds) { 2073 if ((start | end | (end - start) | (text.length() - end)) < 0) { 2074 throw new IndexOutOfBoundsException(); 2075 } 2076 if (bounds == null) { 2077 throw new NullPointerException("need bounds Rect"); 2078 } 2079 nativeGetStringBounds(mNativePaint, text, start, end, bounds); 2080 } 2081 2082 /** 2083 * Return in bounds (allocated by the caller) the smallest rectangle that 2084 * encloses all of the characters, with an implied origin at (0,0). 2085 * 2086 * @param text Array of chars to measure and return their unioned bounds 2087 * @param index Index of the first char in the array to measure 2088 * @param count The number of chars, beginning at index, to measure 2089 * @param bounds Returns the unioned bounds of all the text. Must be 2090 * allocated by the caller. 2091 */ 2092 public void getTextBounds(char[] text, int index, int count, Rect bounds) { 2093 if ((index | count) < 0 || index + count > text.length) { 2094 throw new ArrayIndexOutOfBoundsException(); 2095 } 2096 if (bounds == null) { 2097 throw new NullPointerException("need bounds Rect"); 2098 } 2099 nativeGetCharArrayBounds(mNativePaint, text, index, count, bounds); 2100 } 2101 2102 @Override 2103 protected void finalize() throws Throwable { 2104 try { 2105 finalizer(mNativePaint); 2106 } finally { 2107 super.finalize(); 2108 } 2109 } 2110 2111 private static native int native_init(); 2112 private static native int native_initWithPaint(int paint); 2113 private static native void native_reset(int native_object); 2114 private static native void native_set(int native_dst, int native_src); 2115 private static native int native_getStyle(int native_object); 2116 private static native void native_setStyle(int native_object, int style); 2117 private static native int native_getStrokeCap(int native_object); 2118 private static native void native_setStrokeCap(int native_object, int cap); 2119 private static native int native_getStrokeJoin(int native_object); 2120 private static native void native_setStrokeJoin(int native_object, 2121 int join); 2122 private static native boolean native_getFillPath(int native_object, 2123 int src, int dst); 2124 private static native int native_setShader(int native_object, int shader); 2125 private static native int native_setColorFilter(int native_object, 2126 int filter); 2127 private static native int native_setXfermode(int native_object, 2128 int xfermode); 2129 private static native int native_setPathEffect(int native_object, 2130 int effect); 2131 private static native int native_setMaskFilter(int native_object, 2132 int maskfilter); 2133 private static native int native_setTypeface(int native_object, 2134 int typeface); 2135 private static native int native_setRasterizer(int native_object, 2136 int rasterizer); 2137 2138 private static native int native_getTextAlign(int native_object); 2139 private static native void native_setTextAlign(int native_object, 2140 int align); 2141 2142 private static native float native_getFontMetrics(int native_paint, 2143 FontMetrics metrics); 2144 private static native int native_getTextWidths(int native_object, 2145 char[] text, int index, int count, float[] widths); 2146 private static native int native_getTextWidths(int native_object, 2147 String text, int start, int end, float[] widths); 2148 2149 private static native int native_getTextGlyphs(int native_object, 2150 String text, int start, int end, int contextStart, int contextEnd, 2151 int flags, char[] glyphs); 2152 2153 private static native float native_getTextRunAdvances(int native_object, 2154 char[] text, int index, int count, int contextIndex, int contextCount, 2155 int flags, float[] advances, int advancesIndex, int reserved); 2156 private static native float native_getTextRunAdvances(int native_object, 2157 String text, int start, int end, int contextStart, int contextEnd, 2158 int flags, float[] advances, int advancesIndex, int reserved); 2159 2160 private native int native_getTextRunCursor(int native_object, char[] text, 2161 int contextStart, int contextLength, int flags, int offset, int cursorOpt); 2162 private native int native_getTextRunCursor(int native_object, String text, 2163 int contextStart, int contextEnd, int flags, int offset, int cursorOpt); 2164 2165 private static native void native_getTextPath(int native_object, int bidiFlags, 2166 char[] text, int index, int count, float x, float y, int path); 2167 private static native void native_getTextPath(int native_object, int bidiFlags, 2168 String text, int start, int end, float x, float y, int path); 2169 private static native void nativeGetStringBounds(int nativePaint, 2170 String text, int start, int end, Rect bounds); 2171 private static native void nativeGetCharArrayBounds(int nativePaint, 2172 char[] text, int index, int count, Rect bounds); 2173 private static native void finalizer(int nativePaint); 2174} 2175