Canvas.java revision 0d181540e0c96da454f45e65987f690b27b929d9
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; 23 24import javax.microedition.khronos.opengles.GL; 25 26/** 27 * The Canvas class holds the "draw" calls. To draw something, you need 28 * 4 basic components: A Bitmap to hold the pixels, a Canvas to host 29 * the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, 30 * Path, text, Bitmap), and a paint (to describe the colors and styles for the 31 * drawing). 32 * 33 * <div class="special reference"> 34 * <h3>Developer Guides</h3> 35 * <p>For more information about how to use Canvas, read the 36 * <a href="{@docRoot}guide/topics/graphics/2d-graphics.html"> 37 * Canvas and Drawables</a> developer guide.</p></div> 38 */ 39public class Canvas { 40 41 // assigned in constructors or setBitmap, freed in finalizer 42 private long mNativeCanvas; 43 44 /** @hide */ 45 public long getNativeCanvas() { 46 return mNativeCanvas; 47 } 48 49 // may be null 50 private Bitmap mBitmap; 51 52 // optional field set by the caller 53 private DrawFilter mDrawFilter; 54 55 /** 56 * @hide 57 */ 58 protected int mDensity = Bitmap.DENSITY_NONE; 59 60 /** 61 * Used to determine when compatibility scaling is in effect. 62 * 63 * @hide 64 */ 65 protected int mScreenDensity = Bitmap.DENSITY_NONE; 66 67 // Used by native code 68 @SuppressWarnings("UnusedDeclaration") 69 private int mSurfaceFormat; 70 71 /** 72 * Flag for drawTextRun indicating left-to-right run direction. 73 * @hide 74 */ 75 public static final int DIRECTION_LTR = 0; 76 77 /** 78 * Flag for drawTextRun indicating right-to-left run direction. 79 * @hide 80 */ 81 public static final int DIRECTION_RTL = 1; 82 83 // Maximum bitmap size as defined in Skia's native code 84 // (see SkCanvas.cpp, SkDraw.cpp) 85 private static final int MAXMIMUM_BITMAP_SIZE = 32766; 86 87 // This field is used to finalize the native Canvas properly 88 private final CanvasFinalizer mFinalizer; 89 90 private static final class CanvasFinalizer { 91 private long mNativeCanvas; 92 93 public CanvasFinalizer(long nativeCanvas) { 94 mNativeCanvas = nativeCanvas; 95 } 96 97 @Override 98 protected void finalize() throws Throwable { 99 try { 100 dispose(); 101 } finally { 102 super.finalize(); 103 } 104 } 105 106 public void dispose() { 107 if (mNativeCanvas != 0) { 108 finalizer(mNativeCanvas); 109 mNativeCanvas = 0; 110 } 111 } 112 } 113 114 /** 115 * Construct an empty raster canvas. Use setBitmap() to specify a bitmap to 116 * draw into. The initial target density is {@link Bitmap#DENSITY_NONE}; 117 * this will typically be replaced when a target bitmap is set for the 118 * canvas. 119 */ 120 public Canvas() { 121 if (!isHardwareAccelerated()) { 122 // 0 means no native bitmap 123 mNativeCanvas = initRaster(0); 124 mFinalizer = new CanvasFinalizer(mNativeCanvas); 125 } else { 126 mFinalizer = null; 127 } 128 } 129 130 /** 131 * Construct a canvas with the specified bitmap to draw into. The bitmap 132 * must be mutable. 133 * 134 * <p>The initial target density of the canvas is the same as the given 135 * bitmap's density. 136 * 137 * @param bitmap Specifies a mutable bitmap for the canvas to draw into. 138 */ 139 public Canvas(Bitmap bitmap) { 140 if (!bitmap.isMutable()) { 141 throw new IllegalStateException("Immutable bitmap passed to Canvas constructor"); 142 } 143 throwIfCannotDraw(bitmap); 144 mNativeCanvas = initRaster(bitmap.ni()); 145 mFinalizer = new CanvasFinalizer(mNativeCanvas); 146 mBitmap = bitmap; 147 mDensity = bitmap.mDensity; 148 } 149 150 /** @hide */ 151 public Canvas(long nativeCanvas) { 152 if (nativeCanvas == 0) { 153 throw new IllegalStateException(); 154 } 155 mNativeCanvas = nativeCanvas; 156 mFinalizer = new CanvasFinalizer(mNativeCanvas); 157 mDensity = Bitmap.getDefaultDensity(); 158 } 159 160 /** 161 * Replace existing canvas while ensuring that the swap has occurred before 162 * the previous native canvas is unreferenced. 163 */ 164 private void safeCanvasSwap(long nativeCanvas, boolean copyState) { 165 final long oldCanvas = mNativeCanvas; 166 mNativeCanvas = nativeCanvas; 167 mFinalizer.mNativeCanvas = nativeCanvas; 168 if (copyState) { 169 copyNativeCanvasState(oldCanvas, mNativeCanvas); 170 } 171 finalizer(oldCanvas); 172 } 173 174 /** 175 * Returns null. 176 * 177 * @deprecated This method is not supported and should not be invoked. 178 * 179 * @hide 180 */ 181 @Deprecated 182 protected GL getGL() { 183 return null; 184 } 185 186 /** 187 * Indicates whether this Canvas uses hardware acceleration. 188 * 189 * Note that this method does not define what type of hardware acceleration 190 * may or may not be used. 191 * 192 * @return True if drawing operations are hardware accelerated, 193 * false otherwise. 194 */ 195 public boolean isHardwareAccelerated() { 196 return false; 197 } 198 199 /** 200 * Specify a bitmap for the canvas to draw into. All canvas state such as 201 * layers, filters, and the save/restore stack are reset with the exception 202 * of the current matrix and clip stack. Additionally, as a side-effect 203 * the canvas' target density is updated to match that of the bitmap. 204 * 205 * @param bitmap Specifies a mutable bitmap for the canvas to draw into. 206 * @see #setDensity(int) 207 * @see #getDensity() 208 */ 209 public void setBitmap(Bitmap bitmap) { 210 if (isHardwareAccelerated()) { 211 throw new RuntimeException("Can't set a bitmap device on a GL canvas"); 212 } 213 214 if (bitmap == null) { 215 safeCanvasSwap(initRaster(0), false); 216 mDensity = Bitmap.DENSITY_NONE; 217 } else { 218 if (!bitmap.isMutable()) { 219 throw new IllegalStateException(); 220 } 221 throwIfCannotDraw(bitmap); 222 223 safeCanvasSwap(initRaster(bitmap.ni()), true); 224 mDensity = bitmap.mDensity; 225 } 226 227 mBitmap = bitmap; 228 } 229 230 /** 231 * Set the viewport dimensions if this canvas is GL based. If it is not, 232 * this method is ignored and no exception is thrown. 233 * 234 * @param width The width of the viewport 235 * @param height The height of the viewport 236 * 237 * @hide 238 */ 239 public void setViewport(int width, int height) {} 240 241 /** 242 * @hide 243 */ 244 public void initializeLight(float lightX, float lightY, float lightZ, float lightRadius) {} 245 246 /** 247 * Return true if the device that the current layer draws into is opaque 248 * (i.e. does not support per-pixel alpha). 249 * 250 * @return true if the device that the current layer draws into is opaque 251 */ 252 public native boolean isOpaque(); 253 254 /** 255 * Returns the width of the current drawing layer 256 * 257 * @return the width of the current drawing layer 258 */ 259 public native int getWidth(); 260 261 /** 262 * Returns the height of the current drawing layer 263 * 264 * @return the height of the current drawing layer 265 */ 266 public native int getHeight(); 267 268 /** 269 * <p>Returns the target density of the canvas. The default density is 270 * derived from the density of its backing bitmap, or 271 * {@link Bitmap#DENSITY_NONE} if there is not one.</p> 272 * 273 * @return Returns the current target density of the canvas, which is used 274 * to determine the scaling factor when drawing a bitmap into it. 275 * 276 * @see #setDensity(int) 277 * @see Bitmap#getDensity() 278 */ 279 public int getDensity() { 280 return mDensity; 281 } 282 283 /** 284 * <p>Specifies the density for this Canvas' backing bitmap. This modifies 285 * the target density of the canvas itself, as well as the density of its 286 * backing bitmap via {@link Bitmap#setDensity(int) Bitmap.setDensity(int)}. 287 * 288 * @param density The new target density of the canvas, which is used 289 * to determine the scaling factor when drawing a bitmap into it. Use 290 * {@link Bitmap#DENSITY_NONE} to disable bitmap scaling. 291 * 292 * @see #getDensity() 293 * @see Bitmap#setDensity(int) 294 */ 295 public void setDensity(int density) { 296 if (mBitmap != null) { 297 mBitmap.setDensity(density); 298 } 299 mDensity = density; 300 } 301 302 /** @hide */ 303 public void setScreenDensity(int density) { 304 mScreenDensity = density; 305 } 306 307 /** 308 * Returns the maximum allowed width for bitmaps drawn with this canvas. 309 * Attempting to draw with a bitmap wider than this value will result 310 * in an error. 311 * 312 * @see #getMaximumBitmapHeight() 313 */ 314 public int getMaximumBitmapWidth() { 315 return MAXMIMUM_BITMAP_SIZE; 316 } 317 318 /** 319 * Returns the maximum allowed height for bitmaps drawn with this canvas. 320 * Attempting to draw with a bitmap taller than this value will result 321 * in an error. 322 * 323 * @see #getMaximumBitmapWidth() 324 */ 325 public int getMaximumBitmapHeight() { 326 return MAXMIMUM_BITMAP_SIZE; 327 } 328 329 // the SAVE_FLAG constants must match their native equivalents 330 331 /** restore the current matrix when restore() is called */ 332 public static final int MATRIX_SAVE_FLAG = 0x01; 333 /** restore the current clip when restore() is called */ 334 public static final int CLIP_SAVE_FLAG = 0x02; 335 /** the layer needs to per-pixel alpha */ 336 public static final int HAS_ALPHA_LAYER_SAVE_FLAG = 0x04; 337 /** the layer needs to 8-bits per color component */ 338 public static final int FULL_COLOR_LAYER_SAVE_FLAG = 0x08; 339 /** clip against the layer's bounds */ 340 public static final int CLIP_TO_LAYER_SAVE_FLAG = 0x10; 341 /** restore everything when restore() is called */ 342 public static final int ALL_SAVE_FLAG = 0x1F; 343 344 /** 345 * Saves the current matrix and clip onto a private stack. Subsequent 346 * calls to translate,scale,rotate,skew,concat or clipRect,clipPath 347 * will all operate as usual, but when the balancing call to restore() 348 * is made, those calls will be forgotten, and the settings that existed 349 * before the save() will be reinstated. 350 * 351 * @return The value to pass to restoreToCount() to balance this save() 352 */ 353 public native int save(); 354 355 /** 356 * Based on saveFlags, can save the current matrix and clip onto a private 357 * stack. Subsequent calls to translate,scale,rotate,skew,concat or 358 * clipRect,clipPath will all operate as usual, but when the balancing 359 * call to restore() is made, those calls will be forgotten, and the 360 * settings that existed before the save() will be reinstated. 361 * 362 * @param saveFlags flag bits that specify which parts of the Canvas state 363 * to save/restore 364 * @return The value to pass to restoreToCount() to balance this save() 365 */ 366 public native int save(int saveFlags); 367 368 /** 369 * This behaves the same as save(), but in addition it allocates an 370 * offscreen bitmap. All drawing calls are directed there, and only when 371 * the balancing call to restore() is made is that offscreen transfered to 372 * the canvas (or the previous layer). Subsequent calls to translate, 373 * scale, rotate, skew, concat or clipRect, clipPath all operate on this 374 * copy. When the balancing call to restore() is made, this copy is 375 * deleted and the previous matrix/clip state is restored. 376 * 377 * @param bounds May be null. The maximum size the offscreen bitmap 378 * needs to be (in local coordinates) 379 * @param paint This is copied, and is applied to the offscreen when 380 * restore() is called. 381 * @param saveFlags see _SAVE_FLAG constants 382 * @return value to pass to restoreToCount() to balance this save() 383 */ 384 public int saveLayer(RectF bounds, Paint paint, int saveFlags) { 385 return native_saveLayer(mNativeCanvas, bounds, 386 paint != null ? paint.mNativePaint : 0, 387 saveFlags); 388 } 389 390 /** 391 * Convenience for saveLayer(bounds, paint, {@link #ALL_SAVE_FLAG}) 392 */ 393 public int saveLayer(RectF bounds, Paint paint) { 394 return saveLayer(bounds, paint, ALL_SAVE_FLAG); 395 } 396 397 /** 398 * Helper version of saveLayer() that takes 4 values rather than a RectF. 399 */ 400 public int saveLayer(float left, float top, float right, float bottom, Paint paint, 401 int saveFlags) { 402 return native_saveLayer(mNativeCanvas, left, top, right, bottom, 403 paint != null ? paint.mNativePaint : 0, 404 saveFlags); 405 } 406 407 /** 408 * Convenience for saveLayer(left, top, right, bottom, paint, {@link #ALL_SAVE_FLAG}) 409 */ 410 public int saveLayer(float left, float top, float right, float bottom, Paint paint) { 411 return saveLayer(left, top, right, bottom, paint, ALL_SAVE_FLAG); 412 } 413 414 /** 415 * This behaves the same as save(), but in addition it allocates an 416 * offscreen bitmap. All drawing calls are directed there, and only when 417 * the balancing call to restore() is made is that offscreen transfered to 418 * the canvas (or the previous layer). Subsequent calls to translate, 419 * scale, rotate, skew, concat or clipRect, clipPath all operate on this 420 * copy. When the balancing call to restore() is made, this copy is 421 * deleted and the previous matrix/clip state is restored. 422 * 423 * @param bounds The maximum size the offscreen bitmap needs to be 424 * (in local coordinates) 425 * @param alpha The alpha to apply to the offscreen when when it is 426 drawn during restore() 427 * @param saveFlags see _SAVE_FLAG constants 428 * @return value to pass to restoreToCount() to balance this call 429 */ 430 public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) { 431 alpha = Math.min(255, Math.max(0, alpha)); 432 return native_saveLayerAlpha(mNativeCanvas, bounds, alpha, saveFlags); 433 } 434 435 /** 436 * Convenience for saveLayerAlpha(bounds, alpha, {@link #ALL_SAVE_FLAG}) 437 */ 438 public int saveLayerAlpha(RectF bounds, int alpha) { 439 return saveLayerAlpha(bounds, alpha, ALL_SAVE_FLAG); 440 } 441 442 /** 443 * Helper for saveLayerAlpha() that takes 4 values instead of a RectF. 444 */ 445 public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, 446 int saveFlags) { 447 return native_saveLayerAlpha(mNativeCanvas, left, top, right, bottom, 448 alpha, saveFlags); 449 } 450 451 /** 452 * Helper for saveLayerAlpha(left, top, right, bottom, alpha, {@link #ALL_SAVE_FLAG}) 453 */ 454 public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha) { 455 return saveLayerAlpha(left, top, right, bottom, alpha, ALL_SAVE_FLAG); 456 } 457 458 /** 459 * This call balances a previous call to save(), and is used to remove all 460 * modifications to the matrix/clip state since the last save call. It is 461 * an error to call restore() more times than save() was called. 462 */ 463 public native void restore(); 464 465 /** 466 * Returns the number of matrix/clip states on the Canvas' private stack. 467 * This will equal # save() calls - # restore() calls. 468 */ 469 public native int getSaveCount(); 470 471 /** 472 * Efficient way to pop any calls to save() that happened after the save 473 * count reached saveCount. It is an error for saveCount to be less than 1. 474 * 475 * Example: 476 * int count = canvas.save(); 477 * ... // more calls potentially to save() 478 * canvas.restoreToCount(count); 479 * // now the canvas is back in the same state it was before the initial 480 * // call to save(). 481 * 482 * @param saveCount The save level to restore to. 483 */ 484 public native void restoreToCount(int saveCount); 485 486 /** 487 * Preconcat the current matrix with the specified translation 488 * 489 * @param dx The distance to translate in X 490 * @param dy The distance to translate in Y 491 */ 492 public native void translate(float dx, float dy); 493 494 /** 495 * Preconcat the current matrix with the specified scale. 496 * 497 * @param sx The amount to scale in X 498 * @param sy The amount to scale in Y 499 */ 500 public native void scale(float sx, float sy); 501 502 /** 503 * Preconcat the current matrix with the specified scale. 504 * 505 * @param sx The amount to scale in X 506 * @param sy The amount to scale in Y 507 * @param px The x-coord for the pivot point (unchanged by the scale) 508 * @param py The y-coord for the pivot point (unchanged by the scale) 509 */ 510 public final void scale(float sx, float sy, float px, float py) { 511 translate(px, py); 512 scale(sx, sy); 513 translate(-px, -py); 514 } 515 516 /** 517 * Preconcat the current matrix with the specified rotation. 518 * 519 * @param degrees The amount to rotate, in degrees 520 */ 521 public native void rotate(float degrees); 522 523 /** 524 * Preconcat the current matrix with the specified rotation. 525 * 526 * @param degrees The amount to rotate, in degrees 527 * @param px The x-coord for the pivot point (unchanged by the rotation) 528 * @param py The y-coord for the pivot point (unchanged by the rotation) 529 */ 530 public final void rotate(float degrees, float px, float py) { 531 translate(px, py); 532 rotate(degrees); 533 translate(-px, -py); 534 } 535 536 /** 537 * Preconcat the current matrix with the specified skew. 538 * 539 * @param sx The amount to skew in X 540 * @param sy The amount to skew in Y 541 */ 542 public native void skew(float sx, float sy); 543 544 /** 545 * Preconcat the current matrix with the specified matrix. If the specified 546 * matrix is null, this method does nothing. 547 * 548 * @param matrix The matrix to preconcatenate with the current matrix 549 */ 550 public void concat(Matrix matrix) { 551 if (matrix != null) native_concat(mNativeCanvas, matrix.native_instance); 552 } 553 554 /** 555 * Completely replace the current matrix with the specified matrix. If the 556 * matrix parameter is null, then the current matrix is reset to identity. 557 * 558 * <strong>Note:</strong> it is recommended to use {@link #concat(Matrix)}, 559 * {@link #scale(float, float)}, {@link #translate(float, float)} and 560 * {@link #rotate(float)} instead of this method. 561 * 562 * @param matrix The matrix to replace the current matrix with. If it is 563 * null, set the current matrix to identity. 564 * 565 * @see #concat(Matrix) 566 */ 567 public void setMatrix(Matrix matrix) { 568 native_setMatrix(mNativeCanvas, 569 matrix == null ? 0 : matrix.native_instance); 570 } 571 572 /** 573 * Return, in ctm, the current transformation matrix. This does not alter 574 * the matrix in the canvas, but just returns a copy of it. 575 */ 576 @Deprecated 577 public void getMatrix(Matrix ctm) { 578 native_getCTM(mNativeCanvas, ctm.native_instance); 579 } 580 581 /** 582 * Return a new matrix with a copy of the canvas' current transformation 583 * matrix. 584 */ 585 @Deprecated 586 public final Matrix getMatrix() { 587 Matrix m = new Matrix(); 588 //noinspection deprecation 589 getMatrix(m); 590 return m; 591 } 592 593 /** 594 * Modify the current clip with the specified rectangle. 595 * 596 * @param rect The rect to intersect with the current clip 597 * @param op How the clip is modified 598 * @return true if the resulting clip is non-empty 599 */ 600 public boolean clipRect(RectF rect, Region.Op op) { 601 return native_clipRect(mNativeCanvas, rect.left, rect.top, rect.right, rect.bottom, 602 op.nativeInt); 603 } 604 605 /** 606 * Modify the current clip with the specified rectangle, which is 607 * expressed in local coordinates. 608 * 609 * @param rect The rectangle to intersect with the current clip. 610 * @param op How the clip is modified 611 * @return true if the resulting clip is non-empty 612 */ 613 public boolean clipRect(Rect rect, Region.Op op) { 614 return native_clipRect(mNativeCanvas, rect.left, rect.top, rect.right, rect.bottom, 615 op.nativeInt); 616 } 617 618 /** 619 * Intersect the current clip with the specified rectangle, which is 620 * expressed in local coordinates. 621 * 622 * @param rect The rectangle to intersect with the current clip. 623 * @return true if the resulting clip is non-empty 624 */ 625 public native boolean clipRect(RectF rect); 626 627 /** 628 * Intersect the current clip with the specified rectangle, which is 629 * expressed in local coordinates. 630 * 631 * @param rect The rectangle to intersect with the current clip. 632 * @return true if the resulting clip is non-empty 633 */ 634 public native boolean clipRect(Rect rect); 635 636 /** 637 * Modify the current clip with the specified rectangle, which is 638 * expressed in local coordinates. 639 * 640 * @param left The left side of the rectangle to intersect with the 641 * current clip 642 * @param top The top of the rectangle to intersect with the current 643 * clip 644 * @param right The right side of the rectangle to intersect with the 645 * current clip 646 * @param bottom The bottom of the rectangle to intersect with the current 647 * clip 648 * @param op How the clip is modified 649 * @return true if the resulting clip is non-empty 650 */ 651 public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) { 652 return native_clipRect(mNativeCanvas, left, top, right, bottom, op.nativeInt); 653 } 654 655 /** 656 * Intersect the current clip with the specified rectangle, which is 657 * expressed in local coordinates. 658 * 659 * @param left The left side of the rectangle to intersect with the 660 * current clip 661 * @param top The top of the rectangle to intersect with the current clip 662 * @param right The right side of the rectangle to intersect with the 663 * current clip 664 * @param bottom The bottom of the rectangle to intersect with the current 665 * clip 666 * @return true if the resulting clip is non-empty 667 */ 668 public native boolean clipRect(float left, float top, float right, float bottom); 669 670 /** 671 * Intersect the current clip with the specified rectangle, which is 672 * expressed in local coordinates. 673 * 674 * @param left The left side of the rectangle to intersect with the 675 * current clip 676 * @param top The top of the rectangle to intersect with the current clip 677 * @param right The right side of the rectangle to intersect with the 678 * current clip 679 * @param bottom The bottom of the rectangle to intersect with the current 680 * clip 681 * @return true if the resulting clip is non-empty 682 */ 683 public native boolean clipRect(int left, int top, int right, int bottom); 684 685 /** 686 * Modify the current clip with the specified path. 687 * 688 * @param path The path to operate on the current clip 689 * @param op How the clip is modified 690 * @return true if the resulting is non-empty 691 */ 692 public boolean clipPath(Path path, Region.Op op) { 693 return native_clipPath(mNativeCanvas, path.ni(), op.nativeInt); 694 } 695 696 /** 697 * Intersect the current clip with the specified path. 698 * 699 * @param path The path to intersect with the current clip 700 * @return true if the resulting is non-empty 701 */ 702 public boolean clipPath(Path path) { 703 return clipPath(path, Region.Op.INTERSECT); 704 } 705 706 /** 707 * Modify the current clip with the specified region. Note that unlike 708 * clipRect() and clipPath() which transform their arguments by the 709 * current matrix, clipRegion() assumes its argument is already in the 710 * coordinate system of the current layer's bitmap, and so not 711 * transformation is performed. 712 * 713 * @param region The region to operate on the current clip, based on op 714 * @param op How the clip is modified 715 * @return true if the resulting is non-empty 716 * 717 * @deprecated Unlike all other clip calls this API does not respect the 718 * current matrix. Use {@link #clipRect(Rect)} as an alternative. 719 */ 720 public boolean clipRegion(Region region, Region.Op op) { 721 return native_clipRegion(mNativeCanvas, region.ni(), op.nativeInt); 722 } 723 724 /** 725 * Intersect the current clip with the specified region. Note that unlike 726 * clipRect() and clipPath() which transform their arguments by the 727 * current matrix, clipRegion() assumes its argument is already in the 728 * coordinate system of the current layer's bitmap, and so not 729 * transformation is performed. 730 * 731 * @param region The region to operate on the current clip, based on op 732 * @return true if the resulting is non-empty 733 * 734 * @deprecated Unlike all other clip calls this API does not respect the 735 * current matrix. Use {@link #clipRect(Rect)} as an alternative. 736 */ 737 public boolean clipRegion(Region region) { 738 return clipRegion(region, Region.Op.INTERSECT); 739 } 740 741 public DrawFilter getDrawFilter() { 742 return mDrawFilter; 743 } 744 745 public void setDrawFilter(DrawFilter filter) { 746 long nativeFilter = 0; 747 if (filter != null) { 748 nativeFilter = filter.mNativeInt; 749 } 750 mDrawFilter = filter; 751 nativeSetDrawFilter(mNativeCanvas, nativeFilter); 752 } 753 754 public enum EdgeType { 755 756 /** 757 * Black-and-White: Treat edges by just rounding to nearest pixel boundary 758 */ 759 BW(0), //!< treat edges by just rounding to nearest pixel boundary 760 761 /** 762 * Antialiased: Treat edges by rounding-out, since they may be antialiased 763 */ 764 AA(1); 765 766 EdgeType(int nativeInt) { 767 this.nativeInt = nativeInt; 768 } 769 770 /** 771 * @hide 772 */ 773 public final int nativeInt; 774 } 775 776 /** 777 * Return true if the specified rectangle, after being transformed by the 778 * current matrix, would lie completely outside of the current clip. Call 779 * this to check if an area you intend to draw into is clipped out (and 780 * therefore you can skip making the draw calls). 781 * 782 * @param rect the rect to compare with the current clip 783 * @param type {@link Canvas.EdgeType#AA} if the path should be considered antialiased, 784 * since that means it may affect a larger area (more pixels) than 785 * non-antialiased ({@link Canvas.EdgeType#BW}). 786 * @return true if the rect (transformed by the canvas' matrix) 787 * does not intersect with the canvas' clip 788 */ 789 public boolean quickReject(RectF rect, EdgeType type) { 790 return native_quickReject(mNativeCanvas, rect); 791 } 792 793 /** 794 * Return true if the specified path, after being transformed by the 795 * current matrix, would lie completely outside of the current clip. Call 796 * this to check if an area you intend to draw into is clipped out (and 797 * therefore you can skip making the draw calls). Note: for speed it may 798 * return false even if the path itself might not intersect the clip 799 * (i.e. the bounds of the path intersects, but the path does not). 800 * 801 * @param path The path to compare with the current clip 802 * @param type {@link Canvas.EdgeType#AA} if the path should be considered antialiased, 803 * since that means it may affect a larger area (more pixels) than 804 * non-antialiased ({@link Canvas.EdgeType#BW}). 805 * @return true if the path (transformed by the canvas' matrix) 806 * does not intersect with the canvas' clip 807 */ 808 public boolean quickReject(Path path, EdgeType type) { 809 return native_quickReject(mNativeCanvas, path.ni()); 810 } 811 812 /** 813 * Return true if the specified rectangle, after being transformed by the 814 * current matrix, would lie completely outside of the current clip. Call 815 * this to check if an area you intend to draw into is clipped out (and 816 * therefore you can skip making the draw calls). 817 * 818 * @param left The left side of the rectangle to compare with the 819 * current clip 820 * @param top The top of the rectangle to compare with the current 821 * clip 822 * @param right The right side of the rectangle to compare with the 823 * current clip 824 * @param bottom The bottom of the rectangle to compare with the 825 * current clip 826 * @param type {@link Canvas.EdgeType#AA} if the path should be considered antialiased, 827 * since that means it may affect a larger area (more pixels) than 828 * non-antialiased ({@link Canvas.EdgeType#BW}). 829 * @return true if the rect (transformed by the canvas' matrix) 830 * does not intersect with the canvas' clip 831 */ 832 public boolean quickReject(float left, float top, float right, float bottom, 833 EdgeType type) { 834 return native_quickReject(mNativeCanvas, left, top, right, bottom); 835 } 836 837 /** 838 * Return the bounds of the current clip (in local coordinates) in the 839 * bounds parameter, and return true if it is non-empty. This can be useful 840 * in a way similar to quickReject, in that it tells you that drawing 841 * outside of these bounds will be clipped out. 842 * 843 * @param bounds Return the clip bounds here. If it is null, ignore it but 844 * still return true if the current clip is non-empty. 845 * @return true if the current clip is non-empty. 846 */ 847 public boolean getClipBounds(Rect bounds) { 848 return native_getClipBounds(mNativeCanvas, bounds); 849 } 850 851 /** 852 * Retrieve the bounds of the current clip (in local coordinates). 853 * 854 * @return the clip bounds, or [0, 0, 0, 0] if the clip is empty. 855 */ 856 public final Rect getClipBounds() { 857 Rect r = new Rect(); 858 getClipBounds(r); 859 return r; 860 } 861 862 /** 863 * Fill the entire canvas' bitmap (restricted to the current clip) with the 864 * specified RGB color, using srcover porterduff mode. 865 * 866 * @param r red component (0..255) of the color to draw onto the canvas 867 * @param g green component (0..255) of the color to draw onto the canvas 868 * @param b blue component (0..255) of the color to draw onto the canvas 869 */ 870 public void drawRGB(int r, int g, int b) { 871 native_drawRGB(mNativeCanvas, r, g, b); 872 } 873 874 /** 875 * Fill the entire canvas' bitmap (restricted to the current clip) with the 876 * specified ARGB color, using srcover porterduff mode. 877 * 878 * @param a alpha component (0..255) of the color to draw onto the canvas 879 * @param r red component (0..255) of the color to draw onto the canvas 880 * @param g green component (0..255) of the color to draw onto the canvas 881 * @param b blue component (0..255) of the color to draw onto the canvas 882 */ 883 public void drawARGB(int a, int r, int g, int b) { 884 native_drawARGB(mNativeCanvas, a, r, g, b); 885 } 886 887 /** 888 * Fill the entire canvas' bitmap (restricted to the current clip) with the 889 * specified color, using srcover porterduff mode. 890 * 891 * @param color the color to draw onto the canvas 892 */ 893 public void drawColor(int color) { 894 native_drawColor(mNativeCanvas, color); 895 } 896 897 /** 898 * Fill the entire canvas' bitmap (restricted to the current clip) with the 899 * specified color and porter-duff xfermode. 900 * 901 * @param color the color to draw with 902 * @param mode the porter-duff mode to apply to the color 903 */ 904 public void drawColor(int color, PorterDuff.Mode mode) { 905 native_drawColor(mNativeCanvas, color, mode.nativeInt); 906 } 907 908 /** 909 * Fill the entire canvas' bitmap (restricted to the current clip) with 910 * the specified paint. This is equivalent (but faster) to drawing an 911 * infinitely large rectangle with the specified paint. 912 * 913 * @param paint The paint used to draw onto the canvas 914 */ 915 public void drawPaint(Paint paint) { 916 native_drawPaint(mNativeCanvas, paint.mNativePaint); 917 } 918 919 /** 920 * Draw a series of points. Each point is centered at the coordinate 921 * specified by pts[], and its diameter is specified by the paint's stroke 922 * width (as transformed by the canvas' CTM), with special treatment for 923 * a stroke width of 0, which always draws exactly 1 pixel (or at most 4 924 * if antialiasing is enabled). The shape of the point is controlled by 925 * the paint's Cap type. The shape is a square, unless the cap type is 926 * Round, in which case the shape is a circle. 927 * 928 * @param pts Array of points to draw [x0 y0 x1 y1 x2 y2 ...] 929 * @param offset Number of values to skip before starting to draw. 930 * @param count The number of values to process, after skipping offset 931 * of them. Since one point uses two values, the number of 932 * "points" that are drawn is really (count >> 1). 933 * @param paint The paint used to draw the points 934 */ 935 public native void drawPoints(float[] pts, int offset, int count, Paint paint); 936 937 /** 938 * Helper for drawPoints() that assumes you want to draw the entire array 939 */ 940 public void drawPoints(float[] pts, Paint paint) { 941 drawPoints(pts, 0, pts.length, paint); 942 } 943 944 /** 945 * Helper for drawPoints() for drawing a single point. 946 */ 947 public native void drawPoint(float x, float y, Paint paint); 948 949 /** 950 * Draw a line segment with the specified start and stop x,y coordinates, 951 * using the specified paint. 952 * 953 * <p>Note that since a line is always "framed", the Style is ignored in the paint.</p> 954 * 955 * <p>Degenerate lines (length is 0) will not be drawn.</p> 956 * 957 * @param startX The x-coordinate of the start point of the line 958 * @param startY The y-coordinate of the start point of the line 959 * @param paint The paint used to draw the line 960 */ 961 public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { 962 native_drawLine(mNativeCanvas, startX, startY, stopX, stopY, paint.mNativePaint); 963 } 964 965 /** 966 * Draw a series of lines. Each line is taken from 4 consecutive values 967 * in the pts array. Thus to draw 1 line, the array must contain at least 4 968 * values. This is logically the same as drawing the array as follows: 969 * drawLine(pts[0], pts[1], pts[2], pts[3]) followed by 970 * drawLine(pts[4], pts[5], pts[6], pts[7]) and so on. 971 * 972 * @param pts Array of points to draw [x0 y0 x1 y1 x2 y2 ...] 973 * @param offset Number of values in the array to skip before drawing. 974 * @param count The number of values in the array to process, after 975 * skipping "offset" of them. Since each line uses 4 values, 976 * the number of "lines" that are drawn is really 977 * (count >> 2). 978 * @param paint The paint used to draw the points 979 */ 980 public native void drawLines(float[] pts, int offset, int count, Paint paint); 981 982 public void drawLines(float[] pts, Paint paint) { 983 drawLines(pts, 0, pts.length, paint); 984 } 985 986 /** 987 * Draw the specified Rect using the specified paint. The rectangle will 988 * be filled or framed based on the Style in the paint. 989 * 990 * @param rect The rect to be drawn 991 * @param paint The paint used to draw the rect 992 */ 993 public void drawRect(RectF rect, Paint paint) { 994 native_drawRect(mNativeCanvas, rect, paint.mNativePaint); 995 } 996 997 /** 998 * Draw the specified Rect using the specified Paint. The rectangle 999 * will be filled or framed based on the Style in the paint. 1000 * 1001 * @param r The rectangle to be drawn. 1002 * @param paint The paint used to draw the rectangle 1003 */ 1004 public void drawRect(Rect r, Paint paint) { 1005 drawRect(r.left, r.top, r.right, r.bottom, paint); 1006 } 1007 1008 1009 /** 1010 * Draw the specified Rect using the specified paint. The rectangle will 1011 * be filled or framed based on the Style in the paint. 1012 * 1013 * @param left The left side of the rectangle to be drawn 1014 * @param top The top side of the rectangle to be drawn 1015 * @param right The right side of the rectangle to be drawn 1016 * @param bottom The bottom side of the rectangle to be drawn 1017 * @param paint The paint used to draw the rect 1018 */ 1019 public void drawRect(float left, float top, float right, float bottom, Paint paint) { 1020 native_drawRect(mNativeCanvas, left, top, right, bottom, paint.mNativePaint); 1021 } 1022 1023 /** 1024 * Draw the specified oval using the specified paint. The oval will be 1025 * filled or framed based on the Style in the paint. 1026 * 1027 * @param oval The rectangle bounds of the oval to be drawn 1028 */ 1029 public void drawOval(RectF oval, Paint paint) { 1030 if (oval == null) { 1031 throw new NullPointerException(); 1032 } 1033 native_drawOval(mNativeCanvas, oval, paint.mNativePaint); 1034 } 1035 1036 /** 1037 * Draw the specified circle using the specified paint. If radius is <= 0, 1038 * then nothing will be drawn. The circle will be filled or framed based 1039 * on the Style in the paint. 1040 * 1041 * @param cx The x-coordinate of the center of the cirle to be drawn 1042 * @param cy The y-coordinate of the center of the cirle to be drawn 1043 * @param radius The radius of the cirle to be drawn 1044 * @param paint The paint used to draw the circle 1045 */ 1046 public void drawCircle(float cx, float cy, float radius, Paint paint) { 1047 native_drawCircle(mNativeCanvas, cx, cy, radius, paint.mNativePaint); 1048 } 1049 1050 /** 1051 * <p>Draw the specified arc, which will be scaled to fit inside the 1052 * specified oval.</p> 1053 * 1054 * <p>If the start angle is negative or >= 360, the start angle is treated 1055 * as start angle modulo 360.</p> 1056 * 1057 * <p>If the sweep angle is >= 360, then the oval is drawn 1058 * completely. Note that this differs slightly from SkPath::arcTo, which 1059 * treats the sweep angle modulo 360. If the sweep angle is negative, 1060 * the sweep angle is treated as sweep angle modulo 360</p> 1061 * 1062 * <p>The arc is drawn clockwise. An angle of 0 degrees correspond to the 1063 * geometric angle of 0 degrees (3 o'clock on a watch.)</p> 1064 * 1065 * @param oval The bounds of oval used to define the shape and size 1066 * of the arc 1067 * @param startAngle Starting angle (in degrees) where the arc begins 1068 * @param sweepAngle Sweep angle (in degrees) measured clockwise 1069 * @param useCenter If true, include the center of the oval in the arc, and 1070 close it if it is being stroked. This will draw a wedge 1071 * @param paint The paint used to draw the arc 1072 */ 1073 public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, 1074 Paint paint) { 1075 if (oval == null) { 1076 throw new NullPointerException(); 1077 } 1078 native_drawArc(mNativeCanvas, oval, startAngle, sweepAngle, 1079 useCenter, paint.mNativePaint); 1080 } 1081 1082 /** 1083 * Draw the specified round-rect using the specified paint. The roundrect 1084 * will be filled or framed based on the Style in the paint. 1085 * 1086 * @param rect The rectangular bounds of the roundRect to be drawn 1087 * @param rx The x-radius of the oval used to round the corners 1088 * @param ry The y-radius of the oval used to round the corners 1089 * @param paint The paint used to draw the roundRect 1090 */ 1091 public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { 1092 drawRoundRect(rect.left, rect.top, rect.right, rect.bottom, rx, ry, paint); 1093 } 1094 1095 /** 1096 * Draw the specified round-rect using the specified paint. The roundrect 1097 * will be filled or framed based on the Style in the paint. 1098 * 1099 * @param rx The x-radius of the oval used to round the corners 1100 * @param ry The y-radius of the oval used to round the corners 1101 * @param paint The paint used to draw the roundRect 1102 */ 1103 public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, 1104 Paint paint) { 1105 native_drawRoundRect(mNativeCanvas, left, top, right, bottom, rx, ry, paint.mNativePaint); 1106 } 1107 1108 /** 1109 * Draw the specified path using the specified paint. The path will be 1110 * filled or framed based on the Style in the paint. 1111 * 1112 * @param path The path to be drawn 1113 * @param paint The paint used to draw the path 1114 */ 1115 public void drawPath(Path path, Paint paint) { 1116 native_drawPath(mNativeCanvas, path.ni(), paint.mNativePaint); 1117 } 1118 1119 /** 1120 * @hide 1121 */ 1122 protected static void throwIfCannotDraw(Bitmap bitmap) { 1123 if (bitmap.isRecycled()) { 1124 throw new RuntimeException("Canvas: trying to use a recycled bitmap " + bitmap); 1125 } 1126 if (!bitmap.isPremultiplied() && bitmap.getConfig() == Bitmap.Config.ARGB_8888 && 1127 bitmap.hasAlpha()) { 1128 throw new RuntimeException("Canvas: trying to use a non-premultiplied bitmap " 1129 + bitmap); 1130 } 1131 } 1132 1133 /** 1134 * Draws the specified bitmap as an N-patch (most often, a 9-patches.) 1135 * 1136 * @param patch The ninepatch object to render 1137 * @param dst The destination rectangle. 1138 * @param paint The paint to draw the bitmap with. may be null 1139 * 1140 * @hide 1141 */ 1142 public void drawPatch(NinePatch patch, Rect dst, Paint paint) { 1143 patch.drawSoftware(this, dst, paint); 1144 } 1145 1146 /** 1147 * Draws the specified bitmap as an N-patch (most often, a 9-patches.) 1148 * 1149 * @param patch The ninepatch object to render 1150 * @param dst The destination rectangle. 1151 * @param paint The paint to draw the bitmap with. may be null 1152 * 1153 * @hide 1154 */ 1155 public void drawPatch(NinePatch patch, RectF dst, Paint paint) { 1156 patch.drawSoftware(this, dst, paint); 1157 } 1158 1159 /** 1160 * Draw the specified bitmap, with its top/left corner at (x,y), using 1161 * the specified paint, transformed by the current matrix. 1162 * 1163 * <p>Note: if the paint contains a maskfilter that generates a mask which 1164 * extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), 1165 * then the bitmap will be drawn as if it were in a Shader with CLAMP mode. 1166 * Thus the color outside of the original width/height will be the edge 1167 * color replicated. 1168 * 1169 * <p>If the bitmap and canvas have different densities, this function 1170 * will take care of automatically scaling the bitmap to draw at the 1171 * same density as the canvas. 1172 * 1173 * @param bitmap The bitmap to be drawn 1174 * @param left The position of the left side of the bitmap being drawn 1175 * @param top The position of the top side of the bitmap being drawn 1176 * @param paint The paint used to draw the bitmap (may be null) 1177 */ 1178 public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) { 1179 throwIfCannotDraw(bitmap); 1180 native_drawBitmap(mNativeCanvas, bitmap.ni(), left, top, 1181 paint != null ? paint.mNativePaint : 0, mDensity, mScreenDensity, bitmap.mDensity); 1182 } 1183 1184 /** 1185 * Draw the specified bitmap, scaling/translating automatically to fill 1186 * the destination rectangle. If the source rectangle is not null, it 1187 * specifies the subset of the bitmap to draw. 1188 * 1189 * <p>Note: if the paint contains a maskfilter that generates a mask which 1190 * extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), 1191 * then the bitmap will be drawn as if it were in a Shader with CLAMP mode. 1192 * Thus the color outside of the original width/height will be the edge 1193 * color replicated. 1194 * 1195 * <p>This function <em>ignores the density associated with the bitmap</em>. 1196 * This is because the source and destination rectangle coordinate 1197 * spaces are in their respective densities, so must already have the 1198 * appropriate scaling factor applied. 1199 * 1200 * @param bitmap The bitmap to be drawn 1201 * @param src May be null. The subset of the bitmap to be drawn 1202 * @param dst The rectangle that the bitmap will be scaled/translated 1203 * to fit into 1204 * @param paint May be null. The paint used to draw the bitmap 1205 */ 1206 public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) { 1207 if (dst == null) { 1208 throw new NullPointerException(); 1209 } 1210 throwIfCannotDraw(bitmap); 1211 native_drawBitmap(mNativeCanvas, bitmap.ni(), src, dst, 1212 paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity); 1213 } 1214 1215 /** 1216 * Draw the specified bitmap, scaling/translating automatically to fill 1217 * the destination rectangle. If the source rectangle is not null, it 1218 * specifies the subset of the bitmap to draw. 1219 * 1220 * <p>Note: if the paint contains a maskfilter that generates a mask which 1221 * extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), 1222 * then the bitmap will be drawn as if it were in a Shader with CLAMP mode. 1223 * Thus the color outside of the original width/height will be the edge 1224 * color replicated. 1225 * 1226 * <p>This function <em>ignores the density associated with the bitmap</em>. 1227 * This is because the source and destination rectangle coordinate 1228 * spaces are in their respective densities, so must already have the 1229 * appropriate scaling factor applied. 1230 * 1231 * @param bitmap The bitmap to be drawn 1232 * @param src May be null. The subset of the bitmap to be drawn 1233 * @param dst The rectangle that the bitmap will be scaled/translated 1234 * to fit into 1235 * @param paint May be null. The paint used to draw the bitmap 1236 */ 1237 public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) { 1238 if (dst == null) { 1239 throw new NullPointerException(); 1240 } 1241 throwIfCannotDraw(bitmap); 1242 native_drawBitmap(mNativeCanvas, bitmap.ni(), src, dst, 1243 paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity); 1244 } 1245 1246 /** 1247 * Treat the specified array of colors as a bitmap, and draw it. This gives 1248 * the same result as first creating a bitmap from the array, and then 1249 * drawing it, but this method avoids explicitly creating a bitmap object 1250 * which can be more efficient if the colors are changing often. 1251 * 1252 * @param colors Array of colors representing the pixels of the bitmap 1253 * @param offset Offset into the array of colors for the first pixel 1254 * @param stride The number of colors in the array between rows (must be 1255 * >= width or <= -width). 1256 * @param x The X coordinate for where to draw the bitmap 1257 * @param y The Y coordinate for where to draw the bitmap 1258 * @param width The width of the bitmap 1259 * @param height The height of the bitmap 1260 * @param hasAlpha True if the alpha channel of the colors contains valid 1261 * values. If false, the alpha byte is ignored (assumed to 1262 * be 0xFF for every pixel). 1263 * @param paint May be null. The paint used to draw the bitmap 1264 * 1265 * @deprecated Usage with a {@link #isHardwareAccelerated() hardware accelerated} canvas 1266 * requires an internal copy of color buffer contents every time this method is called. Using a 1267 * Bitmap avoids this copy, and allows the application to more explicitly control the lifetime 1268 * and copies of pixel data. 1269 */ 1270 @Deprecated 1271 public void drawBitmap(int[] colors, int offset, int stride, float x, float y, 1272 int width, int height, boolean hasAlpha, Paint paint) { 1273 // check for valid input 1274 if (width < 0) { 1275 throw new IllegalArgumentException("width must be >= 0"); 1276 } 1277 if (height < 0) { 1278 throw new IllegalArgumentException("height must be >= 0"); 1279 } 1280 if (Math.abs(stride) < width) { 1281 throw new IllegalArgumentException("abs(stride) must be >= width"); 1282 } 1283 int lastScanline = offset + (height - 1) * stride; 1284 int length = colors.length; 1285 if (offset < 0 || (offset + width > length) || lastScanline < 0 1286 || (lastScanline + width > length)) { 1287 throw new ArrayIndexOutOfBoundsException(); 1288 } 1289 // quick escape if there's nothing to draw 1290 if (width == 0 || height == 0) { 1291 return; 1292 } 1293 // punch down to native for the actual draw 1294 native_drawBitmap(mNativeCanvas, colors, offset, stride, x, y, width, height, hasAlpha, 1295 paint != null ? paint.mNativePaint : 0); 1296 } 1297 1298 /** 1299 * Legacy version of drawBitmap(int[] colors, ...) that took ints for x,y 1300 * 1301 * @deprecated Usage with a {@link #isHardwareAccelerated() hardware accelerated} canvas 1302 * requires an internal copy of color buffer contents every time this method is called. Using a 1303 * Bitmap avoids this copy, and allows the application to more explicitly control the lifetime 1304 * and copies of pixel data. 1305 */ 1306 @Deprecated 1307 public void drawBitmap(int[] colors, int offset, int stride, int x, int y, 1308 int width, int height, boolean hasAlpha, Paint paint) { 1309 // call through to the common float version 1310 drawBitmap(colors, offset, stride, (float)x, (float)y, width, height, 1311 hasAlpha, paint); 1312 } 1313 1314 /** 1315 * Draw the bitmap using the specified matrix. 1316 * 1317 * @param bitmap The bitmap to draw 1318 * @param matrix The matrix used to transform the bitmap when it is drawn 1319 * @param paint May be null. The paint used to draw the bitmap 1320 */ 1321 public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) { 1322 nativeDrawBitmapMatrix(mNativeCanvas, bitmap.ni(), matrix.ni(), 1323 paint != null ? paint.mNativePaint : 0); 1324 } 1325 1326 /** 1327 * @hide 1328 */ 1329 protected static void checkRange(int length, int offset, int count) { 1330 if ((offset | count) < 0 || offset + count > length) { 1331 throw new ArrayIndexOutOfBoundsException(); 1332 } 1333 } 1334 1335 /** 1336 * Draw the bitmap through the mesh, where mesh vertices are evenly 1337 * distributed across the bitmap. There are meshWidth+1 vertices across, and 1338 * meshHeight+1 vertices down. The verts array is accessed in row-major 1339 * order, so that the first meshWidth+1 vertices are distributed across the 1340 * top of the bitmap from left to right. A more general version of this 1341 * method is drawVertices(). 1342 * 1343 * @param bitmap The bitmap to draw using the mesh 1344 * @param meshWidth The number of columns in the mesh. Nothing is drawn if 1345 * this is 0 1346 * @param meshHeight The number of rows in the mesh. Nothing is drawn if 1347 * this is 0 1348 * @param verts Array of x,y pairs, specifying where the mesh should be 1349 * drawn. There must be at least 1350 * (meshWidth+1) * (meshHeight+1) * 2 + vertOffset values 1351 * in the array 1352 * @param vertOffset Number of verts elements to skip before drawing 1353 * @param colors May be null. Specifies a color at each vertex, which is 1354 * interpolated across the cell, and whose values are 1355 * multiplied by the corresponding bitmap colors. If not null, 1356 * there must be at least (meshWidth+1) * (meshHeight+1) + 1357 * colorOffset values in the array. 1358 * @param colorOffset Number of color elements to skip before drawing 1359 * @param paint May be null. The paint used to draw the bitmap 1360 */ 1361 public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, 1362 float[] verts, int vertOffset, int[] colors, int colorOffset, Paint paint) { 1363 if ((meshWidth | meshHeight | vertOffset | colorOffset) < 0) { 1364 throw new ArrayIndexOutOfBoundsException(); 1365 } 1366 if (meshWidth == 0 || meshHeight == 0) { 1367 return; 1368 } 1369 int count = (meshWidth + 1) * (meshHeight + 1); 1370 // we mul by 2 since we need two floats per vertex 1371 checkRange(verts.length, vertOffset, count * 2); 1372 if (colors != null) { 1373 // no mul by 2, since we need only 1 color per vertex 1374 checkRange(colors.length, colorOffset, count); 1375 } 1376 nativeDrawBitmapMesh(mNativeCanvas, bitmap.ni(), meshWidth, meshHeight, 1377 verts, vertOffset, colors, colorOffset, 1378 paint != null ? paint.mNativePaint : 0); 1379 } 1380 1381 public enum VertexMode { 1382 TRIANGLES(0), 1383 TRIANGLE_STRIP(1), 1384 TRIANGLE_FAN(2); 1385 1386 VertexMode(int nativeInt) { 1387 this.nativeInt = nativeInt; 1388 } 1389 1390 /** 1391 * @hide 1392 */ 1393 public final int nativeInt; 1394 } 1395 1396 /** 1397 * Draw the array of vertices, interpreted as triangles (based on mode). The 1398 * verts array is required, and specifies the x,y pairs for each vertex. If 1399 * texs is non-null, then it is used to specify the coordinate in shader 1400 * coordinates to use at each vertex (the paint must have a shader in this 1401 * case). If there is no texs array, but there is a color array, then each 1402 * color is interpolated across its corresponding triangle in a gradient. If 1403 * both texs and colors arrays are present, then they behave as before, but 1404 * the resulting color at each pixels is the result of multiplying the 1405 * colors from the shader and the color-gradient together. The indices array 1406 * is optional, but if it is present, then it is used to specify the index 1407 * of each triangle, rather than just walking through the arrays in order. 1408 * 1409 * @param mode How to interpret the array of vertices 1410 * @param vertexCount The number of values in the vertices array (and 1411 * corresponding texs and colors arrays if non-null). Each logical 1412 * vertex is two values (x, y), vertexCount must be a multiple of 2. 1413 * @param verts Array of vertices for the mesh 1414 * @param vertOffset Number of values in the verts to skip before drawing. 1415 * @param texs May be null. If not null, specifies the coordinates to sample 1416 * into the current shader (e.g. bitmap tile or gradient) 1417 * @param texOffset Number of values in texs to skip before drawing. 1418 * @param colors May be null. If not null, specifies a color for each 1419 * vertex, to be interpolated across the triangle. 1420 * @param colorOffset Number of values in colors to skip before drawing. 1421 * @param indices If not null, array of indices to reference into the 1422 * vertex (texs, colors) array. 1423 * @param indexCount number of entries in the indices array (if not null). 1424 * @param paint Specifies the shader to use if the texs array is non-null. 1425 */ 1426 public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset, 1427 float[] texs, int texOffset, int[] colors, int colorOffset, 1428 short[] indices, int indexOffset, int indexCount, Paint paint) { 1429 checkRange(verts.length, vertOffset, vertexCount); 1430 if (texs != null) { 1431 checkRange(texs.length, texOffset, vertexCount); 1432 } 1433 if (colors != null) { 1434 checkRange(colors.length, colorOffset, vertexCount / 2); 1435 } 1436 if (indices != null) { 1437 checkRange(indices.length, indexOffset, indexCount); 1438 } 1439 nativeDrawVertices(mNativeCanvas, mode.nativeInt, vertexCount, verts, 1440 vertOffset, texs, texOffset, colors, colorOffset, 1441 indices, indexOffset, indexCount, paint.mNativePaint); 1442 } 1443 1444 /** 1445 * Draw the text, with origin at (x,y), using the specified paint. The 1446 * origin is interpreted based on the Align setting in the paint. 1447 * 1448 * @param text The text to be drawn 1449 * @param x The x-coordinate of the origin of the text being drawn 1450 * @param y The y-coordinate of the origin of the text being drawn 1451 * @param paint The paint used for the text (e.g. color, size, style) 1452 */ 1453 public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { 1454 if ((index | count | (index + count) | 1455 (text.length - index - count)) < 0) { 1456 throw new IndexOutOfBoundsException(); 1457 } 1458 native_drawText(mNativeCanvas, text, index, count, x, y, paint.mBidiFlags, 1459 paint.mNativePaint, paint.mNativeTypeface); 1460 } 1461 1462 /** 1463 * Draw the text, with origin at (x,y), using the specified paint. The 1464 * origin is interpreted based on the Align setting in the paint. 1465 * 1466 * @param text The text to be drawn 1467 * @param x The x-coordinate of the origin of the text being drawn 1468 * @param y The y-coordinate of the origin of the text being drawn 1469 * @param paint The paint used for the text (e.g. color, size, style) 1470 */ 1471 public void drawText(String text, float x, float y, Paint paint) { 1472 native_drawText(mNativeCanvas, text, 0, text.length(), x, y, paint.mBidiFlags, 1473 paint.mNativePaint, paint.mNativeTypeface); 1474 } 1475 1476 /** 1477 * Draw the text, with origin at (x,y), using the specified paint. 1478 * The origin is interpreted based on the Align setting in the paint. 1479 * 1480 * @param text The text to be drawn 1481 * @param start The index of the first character in text to draw 1482 * @param end (end - 1) is the index of the last character in text to draw 1483 * @param x The x-coordinate of the origin of the text being drawn 1484 * @param y The y-coordinate of the origin of the text being drawn 1485 * @param paint The paint used for the text (e.g. color, size, style) 1486 */ 1487 public void drawText(String text, int start, int end, float x, float y, Paint paint) { 1488 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1489 throw new IndexOutOfBoundsException(); 1490 } 1491 native_drawText(mNativeCanvas, text, start, end, x, y, paint.mBidiFlags, 1492 paint.mNativePaint, paint.mNativeTypeface); 1493 } 1494 1495 /** 1496 * Draw the specified range of text, specified by start/end, with its 1497 * origin at (x,y), in the specified Paint. The origin is interpreted 1498 * based on the Align setting in the Paint. 1499 * 1500 * @param text The text to be drawn 1501 * @param start The index of the first character in text to draw 1502 * @param end (end - 1) is the index of the last character in text 1503 * to draw 1504 * @param x The x-coordinate of origin for where to draw the text 1505 * @param y The y-coordinate of origin for where to draw the text 1506 * @param paint The paint used for the text (e.g. color, size, style) 1507 */ 1508 public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { 1509 if (text instanceof String || text instanceof SpannedString || 1510 text instanceof SpannableString) { 1511 native_drawText(mNativeCanvas, text.toString(), start, end, x, y, 1512 paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface); 1513 } else if (text instanceof GraphicsOperations) { 1514 ((GraphicsOperations) text).drawText(this, start, end, x, y, 1515 paint); 1516 } else { 1517 char[] buf = TemporaryBuffer.obtain(end - start); 1518 TextUtils.getChars(text, start, end, buf, 0); 1519 native_drawText(mNativeCanvas, buf, 0, end - start, x, y, 1520 paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface); 1521 TemporaryBuffer.recycle(buf); 1522 } 1523 } 1524 1525 /** 1526 * Render a run of all LTR or all RTL text, with shaping. This does not run 1527 * bidi on the provided text, but renders it as a uniform right-to-left or 1528 * left-to-right run, as indicated by dir. Alignment of the text is as 1529 * determined by the Paint's TextAlign value. 1530 * 1531 * @param text the text to render 1532 * @param index the start of the text to render 1533 * @param count the count of chars to render 1534 * @param contextIndex the start of the context for shaping. Must be 1535 * no greater than index. 1536 * @param contextCount the number of characters in the context for shaping. 1537 * ContexIndex + contextCount must be no less than index 1538 * + count. 1539 * @param x the x position at which to draw the text 1540 * @param y the y position at which to draw the text 1541 * @param dir the run direction, either {@link #DIRECTION_LTR} or 1542 * {@link #DIRECTION_RTL}. 1543 * @param paint the paint 1544 * @hide 1545 */ 1546 public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, 1547 float x, float y, int dir, Paint paint) { 1548 1549 if (text == null) { 1550 throw new NullPointerException("text is null"); 1551 } 1552 if (paint == null) { 1553 throw new NullPointerException("paint is null"); 1554 } 1555 if ((index | count | text.length - index - count) < 0) { 1556 throw new IndexOutOfBoundsException(); 1557 } 1558 if (dir != DIRECTION_LTR && dir != DIRECTION_RTL) { 1559 throw new IllegalArgumentException("unknown dir: " + dir); 1560 } 1561 1562 native_drawTextRun(mNativeCanvas, text, index, count, 1563 contextIndex, contextCount, x, y, dir, paint.mNativePaint, paint.mNativeTypeface); 1564 } 1565 1566 /** 1567 * Render a run of all LTR or all RTL text, with shaping. This does not run 1568 * bidi on the provided text, but renders it as a uniform right-to-left or 1569 * left-to-right run, as indicated by dir. Alignment of the text is as 1570 * determined by the Paint's TextAlign value. 1571 * 1572 * @param text the text to render 1573 * @param start the start of the text to render. Data before this position 1574 * can be used for shaping context. 1575 * @param end the end of the text to render. Data at or after this 1576 * position can be used for shaping context. 1577 * @param x the x position at which to draw the text 1578 * @param y the y position at which to draw the text 1579 * @param dir the run direction, either 0 for LTR or 1 for RTL. 1580 * @param paint the paint 1581 * @hide 1582 */ 1583 public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, 1584 float x, float y, int dir, Paint paint) { 1585 1586 if (text == null) { 1587 throw new NullPointerException("text is null"); 1588 } 1589 if (paint == null) { 1590 throw new NullPointerException("paint is null"); 1591 } 1592 if ((start | end | end - start | text.length() - end) < 0) { 1593 throw new IndexOutOfBoundsException(); 1594 } 1595 1596 int flags = dir == 0 ? 0 : 1; 1597 1598 if (text instanceof String || text instanceof SpannedString || 1599 text instanceof SpannableString) { 1600 native_drawTextRun(mNativeCanvas, text.toString(), start, end, 1601 contextStart, contextEnd, x, y, flags, paint.mNativePaint, paint.mNativeTypeface); 1602 } else if (text instanceof GraphicsOperations) { 1603 ((GraphicsOperations) text).drawTextRun(this, start, end, 1604 contextStart, contextEnd, x, y, flags, paint); 1605 } else { 1606 int contextLen = contextEnd - contextStart; 1607 int len = end - start; 1608 char[] buf = TemporaryBuffer.obtain(contextLen); 1609 TextUtils.getChars(text, contextStart, contextEnd, buf, 0); 1610 native_drawTextRun(mNativeCanvas, buf, start - contextStart, len, 1611 0, contextLen, x, y, flags, paint.mNativePaint, paint.mNativeTypeface); 1612 TemporaryBuffer.recycle(buf); 1613 } 1614 } 1615 1616 /** 1617 * Draw the text in the array, with each character's origin specified by 1618 * the pos array. 1619 * 1620 * This method does not support glyph composition and decomposition and 1621 * should therefore not be used to render complex scripts. 1622 * 1623 * @param text The text to be drawn 1624 * @param index The index of the first character to draw 1625 * @param count The number of characters to draw, starting from index. 1626 * @param pos Array of [x,y] positions, used to position each 1627 * character 1628 * @param paint The paint used for the text (e.g. color, size, style) 1629 */ 1630 @Deprecated 1631 public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { 1632 if (index < 0 || index + count > text.length || count*2 > pos.length) { 1633 throw new IndexOutOfBoundsException(); 1634 } 1635 native_drawPosText(mNativeCanvas, text, index, count, pos, 1636 paint.mNativePaint); 1637 } 1638 1639 /** 1640 * Draw the text in the array, with each character's origin specified by 1641 * the pos array. 1642 * 1643 * This method does not support glyph composition and decomposition and 1644 * should therefore not be used to render complex scripts. 1645 * 1646 * @param text The text to be drawn 1647 * @param pos Array of [x,y] positions, used to position each character 1648 * @param paint The paint used for the text (e.g. color, size, style) 1649 */ 1650 @Deprecated 1651 public void drawPosText(String text, float[] pos, Paint paint) { 1652 if (text.length()*2 > pos.length) { 1653 throw new ArrayIndexOutOfBoundsException(); 1654 } 1655 native_drawPosText(mNativeCanvas, text, pos, paint.mNativePaint); 1656 } 1657 1658 /** 1659 * Draw the text, with origin at (x,y), using the specified paint, along 1660 * the specified path. The paint's Align setting determins where along the 1661 * path to start the text. 1662 * 1663 * @param text The text to be drawn 1664 * @param path The path the text should follow for its baseline 1665 * @param hOffset The distance along the path to add to the text's 1666 * starting position 1667 * @param vOffset The distance above(-) or below(+) the path to position 1668 * the text 1669 * @param paint The paint used for the text (e.g. color, size, style) 1670 */ 1671 public void drawTextOnPath(char[] text, int index, int count, Path path, 1672 float hOffset, float vOffset, Paint paint) { 1673 if (index < 0 || index + count > text.length) { 1674 throw new ArrayIndexOutOfBoundsException(); 1675 } 1676 native_drawTextOnPath(mNativeCanvas, text, index, count, 1677 path.ni(), hOffset, vOffset, 1678 paint.mBidiFlags, paint.mNativePaint); 1679 } 1680 1681 /** 1682 * Draw the text, with origin at (x,y), using the specified paint, along 1683 * the specified path. The paint's Align setting determins where along the 1684 * path to start the text. 1685 * 1686 * @param text The text to be drawn 1687 * @param path The path the text should follow for its baseline 1688 * @param hOffset The distance along the path to add to the text's 1689 * starting position 1690 * @param vOffset The distance above(-) or below(+) the path to position 1691 * the text 1692 * @param paint The paint used for the text (e.g. color, size, style) 1693 */ 1694 public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { 1695 if (text.length() > 0) { 1696 native_drawTextOnPath(mNativeCanvas, text, path.ni(), hOffset, vOffset, 1697 paint.mBidiFlags, paint.mNativePaint); 1698 } 1699 } 1700 1701 /** 1702 * Save the canvas state, draw the picture, and restore the canvas state. 1703 * This differs from picture.draw(canvas), which does not perform any 1704 * save/restore. 1705 * 1706 * <p> 1707 * <strong>Note:</strong> This forces the picture to internally call 1708 * {@link Picture#endRecording} in order to prepare for playback. 1709 * 1710 * @param picture The picture to be drawn 1711 */ 1712 public void drawPicture(Picture picture) { 1713 picture.endRecording(); 1714 int restoreCount = save(); 1715 picture.draw(this); 1716 restoreToCount(restoreCount); 1717 } 1718 1719 /** 1720 * Draw the picture, stretched to fit into the dst rectangle. 1721 */ 1722 public void drawPicture(Picture picture, RectF dst) { 1723 save(); 1724 translate(dst.left, dst.top); 1725 if (picture.getWidth() > 0 && picture.getHeight() > 0) { 1726 scale(dst.width() / picture.getWidth(), dst.height() / picture.getHeight()); 1727 } 1728 drawPicture(picture); 1729 restore(); 1730 } 1731 1732 /** 1733 * Draw the picture, stretched to fit into the dst rectangle. 1734 */ 1735 public void drawPicture(Picture picture, Rect dst) { 1736 save(); 1737 translate(dst.left, dst.top); 1738 if (picture.getWidth() > 0 && picture.getHeight() > 0) { 1739 scale((float) dst.width() / picture.getWidth(), 1740 (float) dst.height() / picture.getHeight()); 1741 } 1742 drawPicture(picture); 1743 restore(); 1744 } 1745 1746 /** 1747 * Releases the resources associated with this canvas. 1748 * 1749 * @hide 1750 */ 1751 public void release() { 1752 mFinalizer.dispose(); 1753 } 1754 1755 /** 1756 * Free up as much memory as possible from private caches (e.g. fonts, images) 1757 * 1758 * @hide 1759 */ 1760 public static native void freeCaches(); 1761 1762 /** 1763 * Free up text layout caches 1764 * 1765 * @hide 1766 */ 1767 public static native void freeTextLayoutCaches(); 1768 1769 private static native long initRaster(long nativeBitmapOrZero); 1770 private static native void copyNativeCanvasState(long nativeSrcCanvas, 1771 long nativeDstCanvas); 1772 private static native int native_saveLayer(long nativeCanvas, 1773 RectF bounds, 1774 long nativePaint, 1775 int layerFlags); 1776 private static native int native_saveLayer(long nativeCanvas, float l, 1777 float t, float r, float b, 1778 long nativePaint, 1779 int layerFlags); 1780 private static native int native_saveLayerAlpha(long nativeCanvas, 1781 RectF bounds, int alpha, 1782 int layerFlags); 1783 private static native int native_saveLayerAlpha(long nativeCanvas, float l, 1784 float t, float r, float b, 1785 int alpha, int layerFlags); 1786 1787 private static native void native_concat(long nativeCanvas, 1788 long nativeMatrix); 1789 private static native void native_setMatrix(long nativeCanvas, 1790 long nativeMatrix); 1791 private static native boolean native_clipRect(long nativeCanvas, 1792 float left, float top, 1793 float right, float bottom, 1794 int regionOp); 1795 private static native boolean native_clipPath(long nativeCanvas, 1796 long nativePath, 1797 int regionOp); 1798 private static native boolean native_clipRegion(long nativeCanvas, 1799 long nativeRegion, 1800 int regionOp); 1801 private static native void nativeSetDrawFilter(long nativeCanvas, 1802 long nativeFilter); 1803 private static native boolean native_getClipBounds(long nativeCanvas, 1804 Rect bounds); 1805 private static native void native_getCTM(long nativeCanvas, 1806 long nativeMatrix); 1807 private static native boolean native_quickReject(long nativeCanvas, 1808 RectF rect); 1809 private static native boolean native_quickReject(long nativeCanvas, 1810 long nativePath); 1811 private static native boolean native_quickReject(long nativeCanvas, 1812 float left, float top, 1813 float right, float bottom); 1814 private static native void native_drawRGB(long nativeCanvas, int r, int g, 1815 int b); 1816 private static native void native_drawARGB(long nativeCanvas, int a, int r, 1817 int g, int b); 1818 private static native void native_drawColor(long nativeCanvas, int color); 1819 private static native void native_drawColor(long nativeCanvas, int color, 1820 int mode); 1821 private static native void native_drawPaint(long nativeCanvas, 1822 long nativePaint); 1823 private static native void native_drawLine(long nativeCanvas, float startX, 1824 float startY, float stopX, 1825 float stopY, long nativePaint); 1826 private static native void native_drawRect(long nativeCanvas, RectF rect, 1827 long nativePaint); 1828 private static native void native_drawRect(long nativeCanvas, float left, 1829 float top, float right, 1830 float bottom, 1831 long nativePaint); 1832 private static native void native_drawOval(long nativeCanvas, RectF oval, 1833 long nativePaint); 1834 private static native void native_drawCircle(long nativeCanvas, float cx, 1835 float cy, float radius, 1836 long nativePaint); 1837 private static native void native_drawArc(long nativeCanvas, RectF oval, 1838 float startAngle, float sweep, 1839 boolean useCenter, 1840 long nativePaint); 1841 private static native void native_drawRoundRect(long nativeCanvas, 1842 float left, float top, float right, float bottom, 1843 float rx, float ry, long nativePaint); 1844 private static native void native_drawPath(long nativeCanvas, 1845 long nativePath, 1846 long nativePaint); 1847 private native void native_drawBitmap(long nativeCanvas, long nativeBitmap, 1848 float left, float top, 1849 long nativePaintOrZero, 1850 int canvasDensity, 1851 int screenDensity, 1852 int bitmapDensity); 1853 private native void native_drawBitmap(long nativeCanvas, long nativeBitmap, 1854 Rect src, RectF dst, 1855 long nativePaintOrZero, 1856 int screenDensity, 1857 int bitmapDensity); 1858 private static native void native_drawBitmap(long nativeCanvas, 1859 long nativeBitmap, 1860 Rect src, Rect dst, 1861 long nativePaintOrZero, 1862 int screenDensity, 1863 int bitmapDensity); 1864 private static native void native_drawBitmap(long nativeCanvas, int[] colors, 1865 int offset, int stride, float x, 1866 float y, int width, int height, 1867 boolean hasAlpha, 1868 long nativePaintOrZero); 1869 private static native void nativeDrawBitmapMatrix(long nativeCanvas, 1870 long nativeBitmap, 1871 long nativeMatrix, 1872 long nativePaint); 1873 private static native void nativeDrawBitmapMesh(long nativeCanvas, 1874 long nativeBitmap, 1875 int meshWidth, int meshHeight, 1876 float[] verts, int vertOffset, 1877 int[] colors, int colorOffset, 1878 long nativePaint); 1879 private static native void nativeDrawVertices(long nativeCanvas, int mode, int n, 1880 float[] verts, int vertOffset, float[] texs, int texOffset, 1881 int[] colors, int colorOffset, short[] indices, 1882 int indexOffset, int indexCount, long nativePaint); 1883 1884 private static native void native_drawText(long nativeCanvas, char[] text, 1885 int index, int count, float x, 1886 float y, int flags, long nativePaint, 1887 long nativeTypeface); 1888 private static native void native_drawText(long nativeCanvas, String text, 1889 int start, int end, float x, 1890 float y, int flags, long nativePaint, 1891 long nativeTypeface); 1892 1893 private static native void native_drawTextRun(long nativeCanvas, String text, 1894 int start, int end, int contextStart, int contextEnd, 1895 float x, float y, int flags, long nativePaint, long nativeTypeface); 1896 1897 private static native void native_drawTextRun(long nativeCanvas, char[] text, 1898 int start, int count, int contextStart, int contextCount, 1899 float x, float y, int flags, long nativePaint, long nativeTypeface); 1900 1901 private static native void native_drawPosText(long nativeCanvas, 1902 char[] text, int index, 1903 int count, float[] pos, 1904 long nativePaint); 1905 private static native void native_drawPosText(long nativeCanvas, 1906 String text, float[] pos, 1907 long nativePaint); 1908 private static native void native_drawTextOnPath(long nativeCanvas, 1909 char[] text, int index, 1910 int count, long nativePath, 1911 float hOffset, 1912 float vOffset, int bidiFlags, 1913 long nativePaint); 1914 private static native void native_drawTextOnPath(long nativeCanvas, 1915 String text, long nativePath, 1916 float hOffset, 1917 float vOffset, 1918 int flags, long nativePaint); 1919 private static native void finalizer(long nativeCanvas); 1920} 1921