我最近开始使用Google Dart(www.dartlang.org)并玩弄SVG。
我试图使用viewBox将生成的SVG缩放以适应<div>
。
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;
但是没有进行任何缩放操作。 我该如何解决这个问题?