/** * For testing purposes only. DO NOT USE IN PRODUCTION. */ public static Bitmap renderPath(Path path) { RectF bounds = new RectF(); path.computeBounds(bounds, false); Bitmap bitmap = Bitmap.createBitmap((int) bounds.right, (int) bounds.bottom, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new LPaint(); paint.setAntiAlias(true); paint.setColor(Color.BLUE); canvas.drawPath(path, paint); return bitmap; } }
public static float getPathHeight(Path path) { RectF rect = new RectF(); path.computeBounds(rect, true); return rect.height(); }
public static float getPathWidth(Path path) { RectF rect = new RectF(); path.computeBounds(rect, true); return rect.width(); }
@Override public void getBounds(RectF outBounds, Matrix parentMatrix, boolean applyParents) { path.reset(); for (int i = 0; i < paths.size(); i++) { path.addPath(paths.get(i).getPath(), parentMatrix); } path.computeBounds(outBounds, false); // Add padding to account for rounding errors. outBounds.set( outBounds.left - 1, outBounds.top - 1, outBounds.right + 1, outBounds.bottom + 1 ); }
@Override public void getBounds(RectF outBounds, Matrix parentMatrix, boolean applyParents) { path.reset(); for (int i = 0; i < paths.size(); i++) { this.path.addPath(paths.get(i).getPath(), parentMatrix); } path.computeBounds(outBounds, false); // Add padding to account for rounding errors. outBounds.set( outBounds.left - 1, outBounds.top - 1, outBounds.right + 1, outBounds.bottom + 1 ); }
public static void setPathRotation(Path path, float rotation) { RectF rect = new RectF(); path.computeBounds(rect, true); setPathRotation(path, rotation, rect.centerX(), rect.centerY()); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mFontPath.computeBounds(mPathBounds, true); }
public static void setPathScaleX(Path path, float scale) { RectF rect = new RectF(); path.computeBounds(rect, true); setPathScaleX(path, scale, rect.centerX(), rect.centerY()); }
public static void setPathScaleY(Path path, float scale) { RectF rect = new RectF(); path.computeBounds(rect, true); setPathScaleY(path, scale, rect.centerX(), rect.centerY()); }
PathInfo(Path path, float width, float height) { this.path = path; float tmpWidth = width; float tmpHeight = height; RectF bounds = new RectF(); path.computeBounds(bounds, true); if(width <= 0 && height <= 0) { tmpWidth = (float) Math.ceil(bounds.width()); tmpHeight = (float) Math.ceil(bounds.height()); path.offset(-1 * (float) Math.floor(bounds.left), -1 * (float) Math.round(bounds.top)); } this.width = tmpWidth; this.height = tmpHeight; }
public static void setPathWidth(Path path, float width) { RectF src = new RectF(); path.computeBounds(src, true); Matrix resizeMatrix = new Matrix(); RectF bounds = new RectF(src.left, src.top, src.left + width, src.bottom); resizeMatrix.setRectToRect(src, bounds, Matrix.ScaleToFit.FILL); path.transform(resizeMatrix); }
@Override public void getBounds(RectF outBounds, Matrix parentMatrix, boolean applyParents) { L.beginSection("StrokeContent#getBounds"); path.reset(); for (int i = 0; i < pathGroups.size(); i++) { PathGroup pathGroup = pathGroups.get(i); for (int j = 0; j < pathGroup.paths.size(); j++) { path.addPath(pathGroup.paths.get(j).getPath(), parentMatrix); } } path.computeBounds(rect, false); float width = ((FloatKeyframeAnimation) widthAnimation).getFloatValue(); rect.set(rect.left - width / 2f, rect.top - width / 2f, rect.right + width / 2f, rect.bottom + width / 2f); outBounds.set(rect); // Add padding to account for rounding errors. outBounds.set( outBounds.left - 1, outBounds.top - 1, outBounds.right + 1, outBounds.bottom + 1 ); L.endSection("StrokeContent#getBounds"); }
public static void setPathHeight(Path path, float height) { RectF src = new RectF(); path.computeBounds(src, true); Matrix resizeMatrix = new Matrix(); RectF bounds = new RectF(src.left, src.top, src.right, src.top + height); resizeMatrix.setRectToRect(src, bounds, Matrix.ScaleToFit.FILL); path.transform(resizeMatrix); }
public static void resizePath(Path path, float width, float height) { RectF bounds = new RectF(0, 0, width, height); RectF src = new RectF(); path.computeBounds(src, true); Matrix resizeMatrix = new Matrix(); resizeMatrix.setRectToRect(src, bounds, Matrix.ScaleToFit.FILL); path.transform(resizeMatrix); }
/** * Update the TextSize */ private void updateTextSize(@NonNull Rect viewBounds) { float textSize = (float) viewBounds.height() * (mRespectFontBounds ? 1 : 2); mIconBrush.getPaint().setTextSize(textSize); String textValue = mIcon != null ? String.valueOf(mIcon.getCharacter()) : String.valueOf(mPlainIcon); mIconBrush.getPaint().getTextPath(textValue, 0, textValue.length(), 0, viewBounds.height(), mPath); mPath.computeBounds(mPathBounds, true); if (!mRespectFontBounds) { float deltaWidth = ((float) mPaddingBounds.width() / mPathBounds.width()); float deltaHeight = ((float) mPaddingBounds.height() / mPathBounds.height()); float delta = (deltaWidth < deltaHeight) ? deltaWidth : deltaHeight; textSize *= delta; mIconBrush.getPaint().setTextSize(textSize); mIconBrush.getPaint().getTextPath(textValue, 0, textValue.length(), 0, viewBounds.height(), mPath); mPath.computeBounds(mPathBounds, true); } }
case MaskModeAdd: default: path.computeBounds(tempMaskBoundsRect, false);
@Override public void draw(Canvas canvas, Matrix parentMatrix, int parentAlpha) { if (hidden) { return; } L.beginSection("GradientFillContent#draw"); path.reset(); for (int i = 0; i < paths.size(); i++) { path.addPath(paths.get(i).getPath(), parentMatrix); } path.computeBounds(boundsRect, false); Shader shader; if (type == GradientType.Linear) { shader = getLinearGradient(); } else { shader = getRadialGradient(); } shaderMatrix.set(parentMatrix); shader.setLocalMatrix(shaderMatrix); paint.setShader(shader); if (colorFilterAnimation != null) { paint.setColorFilter(colorFilterAnimation.getValue()); } int alpha = (int) ((parentAlpha / 255f * opacityAnimation.getValue() / 100f) * 255); paint.setAlpha(clamp(alpha, 0, 255)); canvas.drawPath(path, paint); L.endSection("GradientFillContent#draw"); }
private void drawCharacterAsGlyph( FontCharacter character, Matrix parentMatrix, float fontScale, DocumentData documentData, Canvas canvas) { List<ContentGroup> contentGroups = getContentsForCharacter(character); for (int j = 0; j < contentGroups.size(); j++) { Path path = contentGroups.get(j).getPath(); path.computeBounds(rectF, false); matrix.set(parentMatrix); matrix.preTranslate(0, (float) -documentData.baselineShift * Utils.dpScale()); matrix.preScale(fontScale, fontScale); path.transform(matrix); if (documentData.strokeOverFill) { drawGlyph(path, fillPaint, canvas); drawGlyph(path, strokePaint, canvas); } else { drawGlyph(path, strokePaint, canvas); drawGlyph(path, fillPaint, canvas); } } }
public static boolean isTouched(Path path, float x, float y) { Region region = new Region(); RectF rectF = new RectF(); path.computeBounds(rectF, true); region.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom)); int offset = 10; return region.contains((int) x, (int) y) || region.contains((int) x + offset, (int) y + offset) || region.contains((int) x + offset, (int) y - offset) || region.contains((int) x - offset, (int) y - offset) || region.contains((int) x - offset, (int) y + offset); }
@GetExtraAccessibilityNodeAt static int getExtraAccessibilityNodeAt( int x, int y, @Prop(resType = ResType.STRING) CharSequence text, @FromBoundsDefined Layout textLayout, @FromBoundsDefined ClickableSpan[] clickableSpans) { final Spanned spanned = (Spanned) text; for (int i = 0; i < clickableSpans.length; i++) { final ClickableSpan span = clickableSpans[i]; final int start = spanned.getSpanStart(span); final int end = spanned.getSpanEnd(span); textLayout.getSelectionPath(start, end, sTempPath); sTempPath.computeBounds(sTempRectF, /* unused */true); if (sTempRectF.contains(x, y)) { return i; } } return INVALID_ID; } }