svg - 在 Web 浏览器中将 SVG 的字体大小与常规文本匹配
问题描述
我试图让我的 svg 文件的字体大小与我的常规文本的字体大小相匹配。我已经设法让字体本身匹配,两者都使用 Steve Matteson 的 Open Sans,但是大小不同。我的 svg 文件始终呈现比我的常规文本稍大的字体。
当我创建 svg 文件(在 Inkscape 中)时,我将字体大小设置为 22.4px;我还将常规文本的字体大小设置为 22.4 像素。我对此进行了一些研究,并意识到 svg 的渲染非常复杂,并且浏览器具有许多默认样式,但我无法深入研究导致这种字体大小差异的确切原因。(我尝试了浏览器重置代码,但这没有帮助;问题仍然与没有重置的情况完全相同)。
这是一个屏幕截图,比较了上面的常规文本和下面的 svg。您可以看到 svg 的字体大小稍大(在比较文本中的数字“1”与 svg.
HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Font Comparison Test</title>
<!-- Open Sans font by Steve Matteson -->
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans+Condensed:wght@300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<p>
Einige suchen dieselbe in der fortlaufenden Zahlenreihe
von 1 bis 16 und legen den Gliedern dieser Reihe die Töne
auf folgende Weise unter :
</p>
<!-- First graph, series 1 - 16 -->
<img src="svg/1.1 English series 1 - 16.svg" style="width: auto; height: auto;">
</body>
</html>
CSS:
body{
font-family: 'Open Sans Condensed', sans-serif;
background-color: #162e2e;
color: #dfddfe; /* Font colour */
font-size: 22.4px; /* 1.4 = 22.4 px? */
font-weight: 400; /* important for font styling */
}
SVG:
<svg
width="167mm"
height="17mm"
viewBox="0 0 167 17"
version="1.1"
id="svg127"
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-17.407795,-14.122843)">
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:7.90222216px;line-height:1.25;font-family:'Open Sans Condensed';-inkscape-font-specification:'Open Sans Condensed, ';letter-spacing:0px;word-spacing:0px;fill:#dfddfe;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="18.06776"
y="21.276409"
id="text4998-2-0"><tspan
sodipodi:role="line"
x="18.06776"
y="21.276409"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Open Sans Condensed';-inkscape-font-specification:'Times New Roman, ';stroke-width:0.26458332"
id="tspan5000-5-1">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16</tspan></text>
解决方案
推荐阅读
- webpack - 如何配置 Quasar SPA / Webpack 开发服务器以在子文件夹中启动以使用 Apache 进行代理?
- vba - 在自动编号字段上使用 DMax 命名 MkDir 创建的文件夹
- docker - 如何解决在 docker run 命令期间挂载卷时权限被拒绝的问题?
- javascript - Phoenix 1.4 服务器正在交付默认 HTML 而不是请求的 JS 文件
- node.js - 如何修复每个文件上的“npm WARN tar ENOENT:没有这样的文件或目录”
- python - 如何使for循环完成,然后才触发scrapy函数
- python - 在 numpy 中快速找到对称对
- vb.net - 即使使用另一个全屏应用程序也能保持图像打开
- python-3.6 - 如何删除“builtin_function_or_method”对象不能解释为整数错误
- azure - 为什么我可以在 Azure Cloud Shell Bash 中创建新文件和目录,但不能在 PowerShell 中创建?