控制点生成算法

14 篇文章 0 订阅

首先看在SVGElementsManager中的两个函数


 public Rectangle2D getSensitiveBounds(Element shape) {

        Rectangle2D bounds = null;

        if (shape != null) {

           
            BridgeContext ctxt = handle.getCanvas().getBridgeContext();

            if (ctxt != null) {

                GraphicsNode gnode = null;

                try {
                    gnode = ctxt.getGraphicsNode(shape);
                } catch (Exception e) {
                }
                ;

                if (gnode != null) {

                    try {
                        AffineTransform transform = gnode.getTransform();
                      
                        bounds = gnode.getSensitiveBounds();

                        if (transform != null) {

                            bounds = transform.createTransformedShape(bounds).getBounds2D();
                        }
                    } catch (Exception e) {
                    }
                }
            }
        }
        return bounds;
    }

    public Rectangle2D getSensitiveBoundsWithoutTF(Element shape) {

        Rectangle2D bounds = null;

        if (shape != null) {

            BridgeContext ctxt = handle.getCanvas().getBridgeContext();

            if (ctxt != null) {

                GraphicsNode gnode = null;

                try {
                    gnode = ctxt.getGraphicsNode(shape);
                } catch (Exception e) {
                }
                ;

                if (gnode != null) {

                    try {

                        bounds = gnode.getSensitiveBounds();

                    } catch (Exception e) {
                    }
                }
            }
        }
        return bounds;
    }

简单说就是getSensitiveBounds函数是将仿射变换也叠加到坐标产生的边界。

看下面的矩形元素

<rect x="50" width="152" height="79" y="100" style="fill:none;stroke:#000000;stroke-width:1.0" />

用这两个函数得到的都是java.awt.geom.Rectangle2D$Float[x=50,y=100,w=152.0,h=79]

当矩形元素为下面

<rect x="50" width="152" height="79" y="100" style="fill:none;stroke:#000000;stroke-width:1.0" transform="rotate(41.47143 126.0 139.5)"/>

用getSensitiveBounds函数得到的是

[x=42.189758556672416,y=58.86669987156454,w=167.62048288665517,h=161.2666002568709]

用getSensitiveBoundsWithoutTF函数得到的是

java.awt.geom.Rectangle2D$Float[x=50,y=100,w=152.0,h=79]

如下图所示:


黑色边线代表的是<rect x="50" width="152" height="79" y="100" style="fill:none;stroke:#000000;stroke-width:1.0" transform="rotate(41.47143 126.0 139.5)"/>这个矩形元素,蓝色边线代表是getSensitiveBoundsWithoutTF返回的边界,紫色边线代表的是getSensitiveBounds返回的边界。


下面在讲绘图中如何得到控制点的边界;

       先以单个元素为例。使用getSensitiveBoundsWithoutTF返回一个矩形边界area。假设有八个控制点,则根据area可以得到蓝色虚线边界的八个控制点,而我们进行操作时,实际要得到的是如下在黑色矩形上的控制点。这时就要对每个方向对应的控制点再做仿射变换:


控制点的计算逻辑如下,point为该方向关联的点。当元素的transform属性中有matrix时,要用getSensitiveBounds取边界,然后控制点方向才不会乱。



     

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值