Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.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 如何将google字体中的草书字体(字体名称中带有空格)包含到画布元素中_Javascript_Html_Css_Google Fonts - Fatal编程技术网

Javascript 如何将google字体中的草书字体(字体名称中带有空格)包含到画布元素中

Javascript 如何将google字体中的草书字体(字体名称中带有空格)包含到画布元素中,javascript,html,css,google-fonts,Javascript,Html,Css,Google Fonts,这是我的代码,在加载脚本之前,我在头部加载了字体 这是代码 var canvas=document.getElementById('myCanvas'); var context=canvas.getContext('2d'); context.fillStyle=“#ffffff”; fillRect(0,05001000); context.beginPath(); context.fillStyle=“#000000”; context.font=“30px Pacifico,草书”;

这是我的代码,在加载脚本之前,我在头部加载了字体 这是代码

var canvas=document.getElementById('myCanvas');
var context=canvas.getContext('2d');
context.fillStyle=“#ffffff”;
fillRect(0,05001000);
context.beginPath();
context.fillStyle=“#000000”;
context.font=“30px Pacifico,草书”;
context.fillText(“Hello World”,canvas.width/2,canvas.height/2)

问题是如何将谷歌字体中的草书字体(字体名称中带有空格)包含到画布元素中

事实证明,提问者不需要在使用的字体中留空格,并且给出的代码运行良好(除了缺少img)

但是,如果有人登陆这里想知道如何在字体名称中包含google字体中带有空格的字体,下面是一个示例:

<link href='https://fonts.googleapis.com/css?family=PT Serif Caption' rel='stylesheet'>


i、 e.只包含空格,不需要翻译成任何内容。

那么什么是
img
?你不需要在字体中提到
草书,名字就是
Pacifico
。唯一的实际问题似乎是
img
不存在。否则代码就可以工作了。您的img不会被声明。画什么img?我刚刚发布了一小部分代码,img运行良好,很抱歉发布了一半代码,但我只是想我可能会显示相关的细节,因为实际的字体名称是{'Pacifico',cursive},当我尝试Pacifico时,它不起作用