我最近开始使用 Google Dart (www.dartlang.org) 并使用 SVG。我正在尝试<div>
使用 viewBox 缩放生成的 SVG 以适应。
StackOverflow 上的人已经给了我很多帮助。
我现在可以像这样缩放路径:Dart create and transform an SVG path
但似乎 viewBox 是为适应比例而设计的,使用它可以让我免于单独缩放 svg 中的所有路径。这就是我想使用 viewBox 的原因。
我尝试了以下方法:
// get bounding box of the created svg
Rect bb = path.getBBox();
// create a viewBox for the svg to fit in the div
var viewBox = svg.viewBox.baseVal
..x = bb.x
..y = bb.y
..width = bb.width
..height = bb.height;
// center the image inside the div
svg.preserveAspectRatio.baseVal
..meetOrSlice = PreserveAspectRatio.SVG_MEETORSLICE_MEET
..align = PreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID;
但是没有缩放发生。我将如何解决这个问题?