English 中文(简体)
SVG、XML & 字体家庭
原标题:SVG, XML & font-family

I m hoping to get a little more information on the best way to format text within SVG The w3 offers this http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#text_methods

但没有具体说明如何建立字体堆叠, 我尝试将以下的 xml 代码处理成 cs (如某些建议), 但我没有运气 。

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

< pengener\\ 问题。 我如何才能为 svg 按 cs 为 svg 构建字体堆叠?

(我对字体脸或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 ;

EDIT I ve also found this from w3 http://www.w3.org/TR/SVG/text.html#FontPropertiesUsedBySVG which tells me to follow css, as per http://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#font-specification but putting it in like css (font-family:"Times New Roman",Times,serif;) doesn t work.

问题回答

字体家族属性与 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>

检查 Inkscape 生成的 xml 输出 。 Inkscape 生成了“ font- family: Sans” 的错误字体- 家庭值 。 我猜这应该是“ sans- Serif ”, 但是在破折线上被截断了 。 此值被附加到样式字符串的末尾, 这样您在查看文本编辑器中的 xml 时可能看不到它 。 如果您编辑样式字符串以设置自己的字体- family 定义, 但不删除错误的定义( 因为你还没有看到它), 没有什么变化 。

 <!--this wont work. Two font-family specs (scroll to the end).-->       
    style="font-family:arial,sans-serif;font-size:40px;font-style:normal;font-family:Sans"

    <!--this wont work either. Well you ll get the default Serif font-->
    style="font-family:Sans;font-size:40px;font-style:normal;font-weight:normal;"

    <!--this will work-->
    style="font-family:arial,sans-serif;font-size:40px;font-style:normal;font-weight:normal;"

    <!--so will this-->
    style="font-family:Arial,Sans-Serif;font-size:40px;font-style:normal;font-weight:normal;"

    <!--and this-->
    style="font-family:tahoma,arial,Sans-Serif;font-size:40px;font-style:normal;font-weight:normal;"

 <!--this too-->
style="font-family:Times New Roman, Serif;font-size:40px;font-style:normal;font-weight:normal;"

示例:

<text
   style="font-family:Times New Roman, Serif;font-size:40px;font-style:normal;font-weight:normal;">
    <tspan
     x="60"
     y="60">
    The rain in spain
    </tspan>
</text>          




相关问题
How to simplify SVG code?

Is it possible to simplify / clean up svg code by replacing the use-tags with standard svg elements? Maybe an inkscape plugin? Haven t found anything... Background: I m converting some svgs to javafx ...

How to link from SVG?

What I tried is this <a xlink:target="http://ponyoverflow.com"> <text class="text" x="20" y="718" text-anchor="start">Mail Order Ponies</text> </a> and variations with href ...

Ruby Support for SVG

Is there some library or helper to produce SVG graphics with Ruby? I googled a bit and found many, but all seem to be dusty and very incomplete… Does anyone know about some nice, reliable alternative?

Mangling IDs and References to IDs in XML

I m trying to compose xml elements into each other, and the problem I am having is when there s the same IDs. Basically what I need to do is mangle all the IDs in an xml file, as well as the ...

热门标签