font-family:Verdana,Times New Roman;
font-family:'Verdana,"Times New Roman"';
font-family:Verdana,"Times New Roman";
font-family:'Verdana,Times New Roman';
检查 Inkscape 生成的 xml 输出。 Inkscape 生成错误的字体系列值“font-family:Sans”。我猜这应该是“Sans-Serif”,但在破折号处被截断了。此值附加到样式字符串的末尾,因此当您在文本编辑器中查看 xml 时可能看不到它。如果您编辑样式字符串以放置您自己的字体系列定义,但不删除不正确的定义(因为您还没有看到它),什么都不会改变。
<!--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>
【讨论】:
我相信我们可能需要强调,在 Steve Mc 的回答中,字体堆栈是用文本元素的 de 'style' 属性编写的名称,即使它包含空格。这与我们过去在 CSS 中所做的不同。 “Times new Roman”可能是一种不适合用于测试的字体,因为至少当 Firefox 可以找到其他任何东西时,它会默认使用这个字体。我试过“Arial Black”。
【解决方案2】:
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>
【讨论】:
嘿 Erik,谢谢,我添加了一些在 xml 中指定字体堆栈的尝试,但没有一个有效,当我“设置”它们时,它们甚至在 Inkscape 中消失了。你有正确格式的例子吗?