computeBounds ( )源码实例Demo

android.graphics.Path#computeBounds ( )源码实例Demo

下面列出了android.graphics.Path#computeBounds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: UltimateAndroid   文件: PathInfo.java
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;
}
 
源代码2 项目: android_9.0.0_r45   文件: GestureOverlayView.java
public void setGesture(Gesture gesture) {
    if (mCurrentGesture != null) {
        clear(false);
    }

    setCurrentColor(mCertainGestureColor);
    mCurrentGesture = gesture;

    final Path path = mCurrentGesture.toPath();
    final RectF bounds = new RectF();
    path.computeBounds(bounds, true);

    // TODO: The path should also be scaled to fit inside this view
    mPath.rewind();
    mPath.addPath(path, -bounds.left + (getWidth() - bounds.width()) / 2.0f,
            -bounds.top + (getHeight() - bounds.height()) / 2.0f);

    mResetGesture = true;

    invalidate();
}
 
源代码3 项目: UltimateAndroid   文件: PathInfo.java
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;
}
 
源代码4 项目: mil-sym-android   文件: Shape2.java
@Override
public Rectangle getBounds()
{
    RectF rectf=new RectF();
    if(_Shape instanceof GeneralPath)
    {
        Path path=((GeneralPath)_Shape).getPath();
        path.computeBounds(rectf, true);
        int width=(int)rectf.right-(int)rectf.left;
        int height=(int)rectf.bottom-(int)rectf.top;
        Rectangle rect=new Rectangle((int)rectf.left,(int)rectf.top,width,height);        
        return rect;
    }
    else
        return this.getBounds();
}
 
源代码5 项目: microMathematics   文件: SVGAndroidRenderer.java
@Override
public boolean doTextContainer(TextContainer obj)
{
   if (obj instanceof SVG.TextPath)
   {
      // Since we cheat a bit with our textPath rendering, we need
      // to cheat a bit with our bbox calculation.
      SVG.TextPath  tpath = (SVG.TextPath) obj;
      SVG.SvgObject  ref = obj.document.resolveIRI(tpath.href);
      if (ref == null) {
         error("TextPath path reference '%s' not found", tpath.href);
         return false;
      }
      SVG.Path  pathObj = (SVG.Path) ref;
      Path      path = (new PathConverter(pathObj.d)).getPath();
      if (pathObj.transform != null)
         path.transform(pathObj.transform);
      RectF     pathBounds = new RectF();
      path.computeBounds(pathBounds, true);
      bbox.union(pathBounds);
      return false;
   }
   return true;
}
 
源代码6 项目: starcor.xul   文件: SVGAndroidRenderer.java
@Override
public boolean doTextContainer(TextContainer obj)
{
   if (obj instanceof SVG.TextPath)
   {
      // Since we cheat a bit with our textPath rendering, we need
      // to cheat a bit with our bbox calculation.
      SVG.TextPath  tpath = (SVG.TextPath) obj;
      SVG.SvgObject  ref = obj.document.resolveIRI(tpath.href);
      if (ref == null) {
         error("TextPath path reference '%s' not found", tpath.href);
         return false;
      }
      SVG.Path  pathObj = (SVG.Path) ref;
      Path      path = (new PathConverter(pathObj.d)).getPath();
      if (pathObj.transform != null)
         path.transform(pathObj.transform);
      RectF     pathBounds = new RectF();
      path.computeBounds(pathBounds, true);
      bbox.union(pathBounds);
      return false;
   }
   return true;
}
 
源代码7 项目: android_9.0.0_r45   文件: Gesture.java
/**
 * Creates a bitmap of the gesture with a transparent background.
 * 
 * @param width
 * @param height
 * @param inset
 * @param color
 * @return the bitmap
 */
public Bitmap toBitmap(int width, int height, int inset, int color) {
    final Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);

    final Paint paint = new Paint();
    paint.setAntiAlias(BITMAP_RENDERING_ANTIALIAS);
    paint.setDither(BITMAP_RENDERING_DITHER);
    paint.setColor(color);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(BITMAP_RENDERING_WIDTH);

    final Path path = toPath();
    final RectF bounds = new RectF();
    path.computeBounds(bounds, true);

    final float sx = (width - 2 * inset) / bounds.width();
    final float sy = (height - 2 * inset) / bounds.height();
    final float scale = sx > sy ? sy : sx;
    paint.setStrokeWidth(2.0f / scale);

    path.offset(-bounds.left + (width - bounds.width() * scale) / 2.0f,
            -bounds.top + (height - bounds.height() * scale) / 2.0f);

    canvas.translate(inset, inset);
    canvas.scale(scale, scale);

    canvas.drawPath(path, paint);

    return bitmap;
}
 
源代码8 项目: FontDrawable   文件: FontDrawable.java
private void applyPadding(Path path, RectF textBounds, Rect paddingBounds) {
    final Rect viewBounds = getBounds();
    float deltaWidth = ((float) paddingBounds.width() / textBounds.width());
    float deltaHeight = ((float) paddingBounds.height() / textBounds.height());
    float attenuate = (deltaWidth < deltaHeight) ? deltaWidth : deltaHeight;
    float textSize = paint.getTextSize();
    textSize *= attenuate;
    paint.setTextSize(textSize);
    paint.getTextPath(String.valueOf(fontCode), 0, 1, 0, viewBounds.height(), path);
    path.computeBounds(textBounds, true);
}
 
源代码9 项目: InDoorSurfaceView   文件: PathUnit.java
public PathUnit(List<PointF> list) {
    int i = 0;
    path = new Path();
    for (PointF point : list) {
        if (i == 0) path.moveTo(point.x, point.y);
        path.lineTo(point.x, point.y);
        i++;
    }
    RectF rectF = new RectF();
    path.computeBounds(rectF, true);
    region = new Region();
    region.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
}
 
源代码10 项目: cidrawing   文件: DrawElement.java
/**
 * Return the actual bounding box of the graphics without transformation
 *
 * @return
 */
public RectF getOuterBoundingBox() {
    if (boundingBox != null) {
        Path path = new Path();
        path.addRect(boundingBox, Path.Direction.CW);
        path.transform(getDisplayMatrix());
        RectF box = new RectF();
        path.computeBounds(box, true);
        return box;
    }
    return new RectF();
}
 
源代码11 项目: cidrawing   文件: ShapeUtils.java
/**
 * Creates a simple region from the given path.
 *
 * @param path given path
 * @return region object
 */
public static Region createRegionFromPath(Path path) {
    Region region = new Region();
    if (path != null) {
        RectF box = new RectF();
        path.computeBounds(box, true);
        region.setPath(path, new Region((int) box.left, (int) box.top, (int) box.right, (int) box.bottom));
    }
    return region;
}
 
源代码12 项目: android_9.0.0_r45   文件: DisplayCutout.java
private static void toRectAndAddToRegion(Path p, Region inoutRegion, Rect inoutRect) {
    final RectF rectF = new RectF();
    p.computeBounds(rectF, false /* unused */);
    rectF.round(inoutRect);
    inoutRegion.op(inoutRect, Op.UNION);
}
 
源代码13 项目: OXChart   文件: PieChart.java
/**计算各种绘制坐标*/
    private void evaluatorData(float animPre){
        paintLabel.setTextSize(tagTextSize);
        float tagTextLead = FontUtil.getFontLeading(paintLabel);
        float tagTextHeight = FontUtil.getFontHeight(paintLabel);
        float oneStartAngle = startAngle;
        for(int i = 0; i < dataList.size(); i++) {
            PieChartBean bean = dataList.get(i);
           /* if(bean.getNum() == 0 && !showZeroPart){
                continue;
            }*/
            /**1、绘制扇形*/
            float arcLeft = centerPoint.x - chartRaidus;  //扇形半径
            float arcTop = centerPoint.y - chartRaidus;
            float arcRight = centerPoint.x + chartRaidus;
            float arcBottom = centerPoint.y + chartRaidus;

//            float percentage = 360.0f / total * bean.getNum();
            float percentage = (bean.getNum()==0?0:(360.0f / total * bean.getNum())*animPre);
            bean.setArcRect(new RectF(arcLeft, arcTop, arcRight, arcBottom));
            bean.setStartAngle(oneStartAngle);
            bean.setSweepAngle(percentage);

            /**2、计算扇形区域*/
            arcLeft = centerPoint.x - chartSize;
            arcTop = centerPoint.y - chartSize;
            arcRight = centerPoint.x + chartSize;
            arcBottom = centerPoint.y + chartSize;
            Path allPath = new Path();
            allPath.moveTo(centerPoint.x, centerPoint.y);//添加原始点
            float ovalX = centerPoint.x + (float) (chartRaidus * Math.cos(Math.toRadians(oneStartAngle)));
            float ovalY = centerPoint.y + (float) (chartRaidus * Math.sin(Math.toRadians(oneStartAngle)));
            allPath.lineTo(ovalX, ovalY);
            RectF touchOval = new RectF(arcLeft, arcTop, arcRight, arcBottom);
            allPath.addArc(touchOval, oneStartAngle, percentage);
            allPath.lineTo(centerPoint.x, centerPoint.y);
            allPath.close();
            RectF r = new RectF();
            allPath.computeBounds(r, true);
            Region region = new Region();
            region.setPath(allPath, new Region((int) r.left, (int) r.top, (int) r.right, (int) r.bottom));
            bean.setRegion(region);

            if(MODUL_CHART == tagModul) {
                /**3、绘制直线*/
                //确定直线的起始和结束的点的位置
                float startX = centerPoint.x + (float) (chartRaidus * Math.cos(Math.toRadians(oneStartAngle + percentage / 2)));
                float startY = centerPoint.y + (float) (chartRaidus * Math.sin(Math.toRadians(oneStartAngle + percentage / 2)));
                float endX = centerPoint.x + (float) ((chartRaidus + lineLenth - 20) * Math.cos(Math.toRadians(oneStartAngle + percentage / 2)));
                float endY = centerPoint.y + (float) ((chartRaidus + lineLenth - 20) * Math.sin(Math.toRadians(oneStartAngle + percentage / 2)));
                boolean isRight = true;
                float lineAngle = oneStartAngle + percentage / 2;
                if (lineAngle > 90 && lineAngle < 270) {
                    isRight = false;
                }
//            LogUtil.i(TAG, "直线坐标:start=("+startX+","+startY +")  end=("+endX+","+endY+")"+"   lineAngle="+lineAngle+"  isRight="+isRight);
                List<PointF> tagLinePoints = new ArrayList<>();
                tagLinePoints.add(new PointF(startX, startY));
                tagLinePoints.add(new PointF(endX, endY));
                float textX = isRight ? (endX + 20) : (endX - 20);
                tagLinePoints.add(new PointF(textX, endY));
                bean.setTagLinePoints(tagLinePoints);

                /**3、绘制指示标签*/
                String tagText = "";
                paintLabel.setTextSize(tagTextSize);
                if (tagType == PieChartLayout.TAG_TYPE.TYPE_NUM) {
                    tagText = bean.getNum() + "";
                } else if (tagType == PieChartLayout.TAG_TYPE.TYPE_PERCENT) {
                    DecimalFormat decimalFormat = new DecimalFormat("0.0%");
                    tagText = (total==0?"/":decimalFormat.format(((float) bean.getNum() / (float) total)));
                }
                float textW = FontUtil.getFontlength(paintLabel, tagText);
                textX = isRight ? textX + textSpace : (textX - textW - textSpace);
                float textY = endY - tagTextHeight / 2 + tagTextLead;
                bean.setTagStr(tagText);
                bean.setTagTextPoint(new PointF(textX, textY));
            }

            /*开始角度累加*/
            oneStartAngle += percentage;
        }

    }
 
RNLinearTextGradientSpan(
  float[] locations,
  int[] colors,
  float[] start,
  float[] end,
  boolean useViewFrame,
  Layout layout,
  int textStart,
  int textEnd,
  float maxWidth,
  float maxHeight,
  String text
) {
  if (
    start != null &&
    end != null &&
    colors != null &&
    locations != null &&
    text != null &&
    !YogaConstants.isUndefined(maxWidth) &&
    maxWidth != 0 &&
    maxHeight != 0 &&
    layout != null
  ) {
    Path path = new Path();
    RectF bounds = new RectF();
    layout.getSelectionPath(textStart, textEnd, path);
    path.computeBounds(bounds, true);

    if (layout.getLineForOffset(textEnd - 1) != layout.getLineForOffset(textEnd)) {
      RectF lastSymbolBounds = new RectF();
      layout.getSelectionPath(textEnd - 1, textEnd, path);
      path.computeBounds(lastSymbolBounds, true);

      if (lastSymbolBounds.contains(bounds) && bounds.contains(lastSymbolBounds)) {
        layout.getSelectionPath(textStart, textEnd - 1, path);
        path.computeBounds(bounds, true);
      }
    }

    float width = useViewFrame ? maxWidth : bounds.width();
    float height = useViewFrame ? maxHeight : bounds.height();
    float x0 = (useViewFrame ? 0 : bounds.left) + start[0] * width;
    float y0 = (useViewFrame ? 0 : bounds.top) + start[1] * height;
    float x1 = (useViewFrame ? 0 : bounds.left) + end[0] * width;
    float y1 = (useViewFrame ? 0 : bounds.top) + end[1] * height;

    mGradient = new LinearGradient(x0, y0, x1, y1, colors, locations, Shader.TileMode.CLAMP);
  }
}
 
源代码15 项目: microMathematics   文件: SVGAndroidRenderer.java
private Box  calculatePathBounds(Path path)
{
   RectF  pathBounds = new RectF();
   path.computeBounds(pathBounds, true);
   return new Box(pathBounds.left, pathBounds.top, pathBounds.width(), pathBounds.height());
}
 
源代码16 项目: CustomShapeImageView   文件: SVGParser.java
private void doLimits(Path path) {
    path.computeBounds(rect, false);
    doLimits(rect.left, rect.top);
    doLimits(rect.right, rect.bottom);
}
 
源代码17 项目: UltimateAndroid   文件: SVGParser.java
private void doLimits(Path path) {
    path.computeBounds(rect, false);
    doLimits(rect.left, rect.top);
    doLimits(rect.right, rect.bottom);
}
 
源代码18 项目: FontDrawable   文件: FontDrawable.java
private RectF createTextBounds(Path path) {
    RectF textBounds = new RectF();
    path.computeBounds(textBounds, true);
    return textBounds;
}
 
源代码19 项目: UltimateAndroid   文件: SVGParser.java
private void doLimits(Path path) {
    path.computeBounds(rect, false);
    doLimits(rect.left, rect.top);
    doLimits(rect.right, rect.bottom);
}
 
源代码20 项目: sinovoice-pathfinder   文件: StrokeView.java
@Override
	public boolean onTouchEvent(MotionEvent event) {
		int action = event.getAction();
		if (action == MotionEvent.ACTION_DOWN) {
			stopUpTimer();

			mCurX = (int) event.getX();
			mCurY = (int) event.getY();
			mPrevX = mCurX;
			mPrevY = mCurY;
			StrokeMgr.instance().addStroke((short) mCurX, (short) mCurY);

			if (StrokeMgr.instance().isBrush) {
				drawPenScript(mCurX - 1, mCurY);
				drawPenScript(mCurX - 1, mCurY - 1);
				drawPenScript(mCurX, mCurY - 1);
				drawPenScript(mCurX, mCurY);
			}

			mPath = new Path();
			mPath.moveTo(mCurX, mCurY);

			invalidate();

			return true;
		}

		int N = event.getHistorySize();
		int x = 0;
		int y = 0;
		for (int i = 0; i < N; i++) {
			x = (int) event.getHistoricalX(i);
			y = (int) event.getHistoricalY(i);
			drawPoint(mCurX, mCurY, x, y);
			mCurX = x;
			mCurY = y;
			StrokeMgr.instance().addStroke((short) mCurX, (short) mCurY);
		}

		x = (int) event.getX();
		y = (int) event.getY();
		drawPoint(mCurX, mCurY, x, y);
		mCurX = x;
		mCurY = y;
		StrokeMgr.instance().addStroke((short) mCurX, (short) mCurY);

		if (action == MotionEvent.ACTION_MOVE) {
			mPath.computeBounds(mRectF, true);
			mRect.set(((int) mRectF.left - mScriptWidth),
					((int) mRectF.top - mScriptWidth),
					((int) mRectF.right + mScriptWidth),
					((int) mRectF.bottom + mScriptWidth));
//			Log.v(TAG, "action move, " + mRect.left + ", " + mRect.right + ", " + mRect.top + ", " + mRect.bottom);
			
			if (StrokeMgr.instance().isBrush) {
				drawPenScript(mCurX, mCurY);
			}

		} else if (action == MotionEvent.ACTION_UP) {
			StrokeMgr.instance().addStroke((short) -1, (short) 0);

			mPath.computeBounds(mRectF, true);
			mRect.set(((int) mRectF.left - mScriptWidth),
					((int) mRectF.top - mScriptWidth),
					((int) mRectF.right + mScriptWidth),
					((int) mRectF.bottom + mScriptWidth));

//			Log.v(TAG, "action up, " + mRect.left + ", " + mRect.right + ", " + mRect.top + ", " + mRect.bottom);
			
			PathInfo pathInfo = new PathInfo(mPath, mRect);
			mPathInfo.add(pathInfo);

			fadePoints();

			mCurX = -1;
			mCurY = 0;

			if (StrokeMgr.instance().isBrush) {
				drawPenScript(mCurX, mCurY);
			}

			startUpTimer();
		}
		
		invalidate(mRect);

		return true;
	}