Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 拉斐尔';s`getFont`方法不';t工作(?)_Javascript_Svg_Raphael - Fatal编程技术网

Javascript 拉斐尔';s`getFont`方法不';t工作(?)

Javascript 拉斐尔';s`getFont`方法不';t工作(?),javascript,svg,raphael,Javascript,Svg,Raphael,我在使用Raphael.js的print方法创建文本时遇到一些问题。更准确地说,print方法需要的getFont方法返回一个未定义的值。我把一把非常简单的小提琴放在一起,试图找出问题的根源,但到目前为止运气不好。相同的小提琴代码如下: <div id="canvas" style="width:500px; height:300px; outline: 1px solid #000;"></div>​ 创建画布,甚至绘制路径(尽管font的值未定义),但返回的font

我在使用Raphael.js的
print
方法创建文本时遇到一些问题。更准确地说,
print
方法需要的
getFont
方法返回一个
未定义的值。我把一把非常简单的小提琴放在一起,试图找出问题的根源,但到目前为止运气不好。相同的小提琴代码如下:

<div id="canvas" style="width:500px; height:300px; outline: 1px solid #000;"></div>​
创建画布,甚至绘制路径(尽管font的值未定义),但返回的font对象未定义。我也试过使用“Arial”字体。毕竟,这两种字体是标准的,所以我们不是在讨论自定义字体


你知道为什么会这样吗?

拉斐尔的
打印方法要求你使用Cufon字体文件。从
getFont
上的文档:

按给定参数查找已注册字体中的字体对象

并进一步阅读
注册方

将给定字体添加到Raphaël的已注册字体集。应该是 用作Cufón字体文件中的内部调用

有点扭曲

因此,如果您想/需要使用
print
方法,您必须转换并提供正确格式的字体文件,请阅读有关cufon的内容


如果您想使用系统字体(或webfonts),您可以使用非常容易使用的方法,并且可以使用CSS等样式设置文本。

您知道getFont需要cufon字体吗?请看:stackoverflow.com/questions/4402329/can-i-use-print-in-raphael-without-cufonI不是,不是。SVG和raphael.js也很新:)请写一个答案,这样我就可以批准它。一旦我不再使用手机,我会尽快回答。你让cufon工作了吗?
var canvas, font, text;

canvas = new Raphael(document.getElementById("canvas", 500, 300));
font = canvas.getFont("Arial");
text = canvas.print(0, 0, "Some text", font, 24).attr({ "fill": "#C00" });​