0

我已经找到了如何使用 Raphael JS 拖动对象。

但是现在,我想知道是否可以调整动态打印文本的大小并使用 Raphael JS 获取此“对象”的新宽度/高度。

这是我想要完成的第一个视图:

$(function() {
var R = Raphael("holder", 400, 400);
$("#typetext").keyup(function() {
    var textValue = $(this).val();
    R.clear();
    var c = R.print(100, 100, textValue, R.getFont("Arial"), 60).attr({
        fill: "#ff0000",
        cursor: "move"
    });
    var start = function() {
        this.odx = 0;
        this.ody = 0;
        this.animate({
            "fill-opacity": 0.2
        }, 500);
    },
        move = function(dx, dy) {
            this.translate(dx - this.odx, dy - this.ody);
            this.odx = dx;
            this.ody = dy;
        },
        up = function() {
            this.animate({
                "fill-opacity": 1
            }, 500);
        };
    c.drag(move, start, up);
}); 
});​

演示:http: //jsfiddle.net/ZuYcG/

任何建议将不胜感激!

编辑:这个小提琴给出了我需要做什么的想法,但带有印刷文本。

EDIT2:打印文本由SVG结构中的路径定义,似乎无法获得路径的宽度和高度......

4

1 回答 1

2

不可能“重新打印”,因为将不同的像素高度提供给使用的路径生成例程print。但是,如果您有兴趣将文本缩放在某些合理的范围内,则可以获取路径的边界框,然后对其进行缩放以确保它在画布的宽度和高度范围内。

var bbox = c.getBBox();
if ( bbox.x + bbox.width > $(R.canvas).width() )
{
    var scale = ( $(R.canvas).width() - bbox.x) / bbox.width;
    c.scale( scale, scale, bbox.x, bbox.y  );
}

这里展示的功能。

于 2012-12-10T18:27:58.687 回答