简体   繁体   English

如何使用SVG符号viewBox正确缩放SVG字体的字形

[英]How to properly scale a glyph of an SVG font using an SVG symbol viewBox

I'm utilizing the Bravura music font. 我正在使用Bravura音乐字体。

Here's its font-face definition: 这是它的字体定义:

<font-face 
    font-family="Bravura"
    font-weight="400"
    font-stretch="normal"
    units-per-em="2048"
    panose-1="5 6 0 0 0 0 0 0 0 0"
    ascent="1638"
    descent="-410"
    bbox="-889 -4080 4749 4120"
    underline-thickness="102"
    underline-position="-102"
    unicode-range="U+0020-1D1DD"
  />

I'm trying to wrap my head around font metrics. 我试图把我的头围绕字体指标。 I've studied the explanation on this site : But I'm still unclear. 我已经研究了该站点上的解释:但是我仍然不清楚。

My goal is to translate the glyphs into a properly scaled SVG path using an SVG symbol viewBox attribute. 我的目标是使用SVG符号viewBox属性将字形转换为适当缩放的SVG路径。

So the EM square (which is an imaginary square enclosing each glyph) is 2048x2048 units (defined by units-per-em). 因此EM正方形(包围每个字形的假想正方形)为2048x2048单位(由单位/ em定义)。 A unit is 1/72 of an inch. 单位是1/72英寸。 My monitor DPI is 96x96 我的显示器DPI是96x96

Converting this to pixels = 2048 * 96/72 = 2730 1/3 x 2730 1/3 将其转换为像素= 2048 * 96/72 = 2730 1/3 x 2730 1/3

(Let me know if I'm off here) (让我知道我是否在这里)

So each font should natively fit into a 2730 1/3 x 2730 1/3 square? 那么每种字体本来都应该适合2730 1/3 x 2730 1/3平方?

How does the bounding box #s fit into this process? 边界框如何适合此过程? Are the bbox units in glyph-units as well? bbox单位也是字形单位吗? ( 1/72 in ) 1/72 in

Should the bbox value below be directly inputted into the viewBox attribute of a symbol? 是否应该将下面的bbox值直接输入到符号的viewBox属性中?

Do I need to consider ascent and descent values? 我需要考虑上升和下降值吗?

Here is a jsfiddle somewhat demonstrating my issue: http://jsfiddle.net/1wqa384u/5/ 这是一个jsfiddle,多少证明了我的问题: http : //jsfiddle.net/1wqa384u/5/

Any resources or help appreciated. 任何资源或帮助表示赞赏。

The em box encompasses the ascent and decent. em框包含上升和下降的位置。 Notice that ascent-descent=2048 . 请注意, ascent-descent=2048

As for your main question, I think you are confusing yourself a bit. 关于您的主要问题,我认为您有些困惑。 The viewBox tells the browser how to scale the symbol to fit the size specified by the <use> that references it. viewBox告诉浏览器如何缩放符号以适合引用它的<use>指定的大小。

So if I understand what you want correctly, your symbol viewBox should just be "0 0 2048 2048" . 因此,如果我正确理解了您想要的内容,则符号viewBox应该只是"0 0 2048 2048"

You should then be able to draw it at, say 12pt, by referencing it like so: 然后,您应该可以像这样引用它,以12pt的比例绘制它:

<use xlink:href="#mysymbol" x="100" y="100" width="12pt" height="12pt"/>

You shouldn't have to worry about doing your own DPI conversion. 您不必担心自己进行DPI转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM