SVG坐标系-点与像素 [英] SVG Coordinate System - points vs. pixels

查看:241
本文介绍了SVG坐标系-点与像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通读 SVG 1.1规范,我试图理解用于定义初始视口的单位与整个文档其余部分所使用的单位之间的关系.

Reading through the SVG 1.1 specification, I'm trying to understand the relationship between the units used to define the initial viewport, and the units used throughout the rest of the document.

如果最初使用点定义视口
<svg width="800pt" height="1002pt" viewBox="0 0 800 1002" version="1.1">
而文档的其余部分没有单位标识符,是否也假定为磅,还是默认为某些值?根据规范的这一部分:

If a viewport is initially defined using points
<svg width="800pt" height="1002pt" viewBox="0 0 800 1002" version="1.1">
and the rest of the document has no unit identifiers, is it assumed points as well, or does it default to something? As per this part of the spec:

当坐标或长度值是没有单位标识符的数字(例如"25")时,则假定给定的坐标或长度以用户为单位(即当前用户坐标系中的值).

When a coordinate or length value is a number without a unit identifier (e.g., "25"), then the given coordinate or length is assumed to be in user units (i.e., a value in the current user coordinate system).

有问题的SVG文档的d值为M 50.91 9.82 L 51.98 10.04 C 53.51 12.71 52.60 16.03 52.75 18.97的路径.我读到,移至(50.91pt,9.82pt),在(51.98pt,10.04pt)上画一条线,然后在(52.60pt,16.03pt)上绘制三次贝塞尔曲线.

The SVG document in question has a path with a d value of M 50.91 9.82 L 51.98 10.04 C 53.51 12.71 52.60 16.03 52.75 18.97. I read that as move to (50.91pt, 9.82pt), draw a line to (51.98pt, 10.04pt), and then draw a cubic bezier curve to (52.60pt, 16.03pt).

这是正确的吗?

推荐答案

您是正确的.如果初始宽度/高度以磅为单位定义,并且与视图框声明(确定用户单位与实际尺寸之间的比例)匹配,则其余文档的默认单位为1pt.

You are correct. If the initial width/height is defined in points, and matches the viewbox declaration (which establishes ratio between user units and real sizes), then the default unit for the rest of the doc will be 1pt.

cf: http://www.w3.org/TR/SVG/coords.html#SVGInitialUserCoordinateSystem

(但是,我应该指出,您对三次贝塞尔曲线的解释是不正确的-目标点是52.75、18.97(又名前两组坐标指定了控制点,而不是目标点.另请注意,大写字母"C"表示绝对坐标(相对于小"c"是相对坐标).

(However, I should point out that your interpretation of the cubic bezier curve is not correct - the destination point is 52.75, 18.97 (aka the first two sets of coordinates specify control points, not destination point. Also note that the capital "C" denotes absolute coordinates (vs. small "c" being relative)).

(同样,只是好奇-但是为什么要选择像素还是像素呢?除非您打算对文本做一些有趣的事情,否则这似乎有点不寻常.)

(Also, just being curious - but why are you picking points vs. pixels? That seems a little unusual unless you're planning to do interesting things with text.)

这篇关于SVG坐标系-点与像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆