2010-10-12 298 views
-1

我正在使用SVG的Web应用程序。使用谷歌字体apis

该计划是使用Google Webfonts API让用户选择他们的字体类型,然后在SVG中呈现其名称。问题是,当我使用Google API访问字体时,它不起作用(恢复为Serif字体)。然而,当我下载谷歌字体,然后直接在我的Web应用程序中引用,它的工作原理... 有人可以请阐明如何让这个web应用程序的工作。

这是迄今为止代码:

js.onclick=function() 

    { 
     var val=document.getElementById("txt").value 
     var newText = svgDoc.createElementNS("http://www.w3.org/2000/svg","text"); 
     newText.setAttribute("id", "txxt") 
     newText.setAttribute("x",275); 
     newText.setAttribute("y",250); 
     newText.setAttribute("font-size","50px"); 
     newText.setAttribute("fill","olive"); 
     newText.setAttribute("xlink:href",'http://fonts.googleapis.com/css?family=Josefin+Sans+Std+Light&subset=latin'); 
     newText.setAttribute("font-family",'JosefinSansStd-Light'); 
     var textNode = document.createTextNode(val); 
     newText.appendChild(textNode); 
     svgRoot.appendChild(newText) 
} 
+0

为什么所有的降薪呢? – Frank 2010-10-12 07:27:07

+0

我的猜测:拼写错误的标题(“Probelm in using google font apis”) – jsalonen 2010-10-12 11:29:10

回答

0

基本上所有Google API的做法都与CSS中的@ font-face相同,但是可以简单地从不同的字体提供者加载字体。而CSS @ font-face只能应用于文本。

+0

谢谢Maris。我们只使用纯文本。 – Zain 2010-10-12 07:06:04

-1

我认为你需要做的是周围的其他方式...即谷歌的作品上的文字,而不是SVG图像,所以你需要有原始文本为Google字体工作。

+0

SVG不是_just images_,它们可以像HTML一样包含CSS和JavaScript。 – Frank 2010-10-12 07:05:25

+0

感谢Sohnee,我们使用文本框来插入简单文本,然后使用Google字体API将其转换为所选字体,然后在我们的Web应用程序中使用JS将该文本转换为SVG。任何帮助? – Zain 2010-10-12 07:07:17