2017-10-11 118 views
0
<script type="text/javascript" src="snap.svg-min.js"></script> <style> @font-face { font-family: Avenir; src: url("/AvenirNextCondensed-DemiBold.otf") format("opentype"); } </style> <script> window.onload = function(){ //Start with a simple raphaelJs drawing var s = Snap('#svg', 200,200); var r = s.rect(4,4,192,192,100,100).attr({ stroke: '#1A171B', 'strokeWidth': 4, fill: 'FFDD00', 'opacity': 1.0 }); var t1 = s.text((200/2),(200/2)+20, "150"); t1.attr({ 'font-size': 110, 'font-family': 'Avenir', fill:'#3D3C3F', 'text-anchor':'middle' }); var t2 = s.text((200/2),(200/2)+75, "ex"); t2.attr({ 'font-size': 80, 'font-family': 'Avenir', fill:'#3D3C3F', 'text-anchor':'middle' }); document.getElementById('img').src = s.toDataURL(); } </script> <svg id="svg"></svg> <img id="img"></img> 

你好PNG,snapsvg與自定義字體

的「SVG」與正確的字體家庭繪畫,但「IMG」沒有。 在此處查看結果:http://pictos.kagwalmina.fr/index3.html

是我的代碼誰錯了,或者它是一個錯誤?

感謝您的幫助。

+0

也許自定義字體不工作,您可以嘗試使用標準字體嗎? –

+0

更多解釋你的問題。您在「svg到png」轉換過程中遇到字體問題? – RashFlash

+0

你好。是的,我在「svg到png」轉換過程中遇到了這個問題。 – Kagwalmina

回答

0

爲了使自定義字體作品,請務必將它們添加你的「SVG」使用「DEFS」標籤

例子裏面:

<defs> 
    <font-face font-family="Knewave"> 
     <font-face-src> 
     <font-face-uri link:href="path_to_font/css/fonts/Knewave-Regular.ttf"> 
     </font-face-uri> 
     </font-face-src> 
    </font-face> 
</defs> 

而現在,當您轉換您的SVG到圖像,它應該顯示該文本的正確字體