2017-10-11 119 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到图像,它应该显示该文本的正确字体