2010-10-12 102 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