SVG、XML 和字体系列

标签 svg font-family

我希望获得有关在 SVG 中设置文本格式的最佳方式的更多信息 w3提供了这个 http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#text_methods

但没有指定如何构建字体堆栈,我尝试像 css 一样处理以下 xml 代码(正如一些人建议的那样),但我没有运气。

font-family:Times New Roman;
-inkscape-font-specification:Times New Roman

问题。如何根据 css 为 svg 构建字体堆栈?

(我对 font-face 或 svg 字体不太感兴趣,因为从我读到的内容来看,我相信它们目前还没有得到广泛的支持。)

我尝试在 xml 中以这些模式格式化文本,但没有成功;

 font-family:Verdana,Times New Roman;
 font-family:'Verdana,"Times New Roman"';
 font-family:Verdana,"Times New Roman";
 font-family:'Verdana,Times New Roman';

编辑 我也从w3找到了这个 http://www.w3.org/TR/SVG/text.html#FontPropertiesUsedBySVG 它告诉我遵循 css,按照 http://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#font-specification 但像 css (font-family:"Times New Roman",Times,serif;) 一样放入它是行不通的。

最佳答案

font-family 属性与 CSS 定义相同,因此您可以根据需要指定字体堆栈。

使用属性的示例:

<svg xmlns="http://www.w3.org/2000/svg">
  <text x="10" y="100" 
   font-family="'Times New Roman', Times, serif" font-size="48">
    Some text
  </text>
</svg>

或者更好的是,使用类:

<svg xmlns="http://www.w3.org/2000/svg">
  <style>
    .seriftext {
      font-family: 'Times New Roman', Times, serif;
      font-size: 48px;
    }
  </style>
  <text x="10" y="100" class="seriftext">
    Some text
  </text>
</svg>

关于SVG、XML 和字体系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10728892/

相关文章:

javascript - 如何让这个 svg 圆圈出现在我的 d3 路径上方而不是下方?

css - sass 中的 $experimental-support-for-svg 是什么,为什么需要它?

css - 实现倾斜背景布局的最佳方式是什么?

jquery fullcalendar 如何在不破坏布局的情况下增加字体大小或更改字体系列

c# - 为什么 new FontFamily ("Invalid font") 不抛出异常?

html - CSS @font-face 的问题

javascript - SVG Morph Javascript逻辑

css - SVG:使用 CSS 设置 <text> 内容

C# 在知道字体名称时获取字体系列

css - 将 CSS font-family 设置为安全的手写字体