我怎样才能把这个SVG文件写得更紧凑呢?
这段代码是否可以写得更紧凑?我有一张桌子,我想旋转它。然而我正在使用四个不同的对象:TableWithCharisW..S
<?xml version="1.0"?>
<svg width="704" height="702" xmlns="http://www.w3.org/2000/svg">
<defs>
<!-- objects -->
<rect id="Chair" width="40" height="40" />
<rect id="Table" width="130" height="65" />
<g id="TableWithChairs">
<use xlink:href="#Table" />
<use xlink:href="#Chair" x="12.5" y="70" />
<use xlink:href="#Chair" x="77.5" y="70" />
</g>
<use id="TableWithChairsW" xlink:href="#TableWithChairs" transform="rotate(90) translate(0, -65)" />
<use id="TableWithChairsN" xlink:href="#TableWithChairs" transform="rotate(180) translate(-130, -65)" />
<use id="TableWithChairsE" xlink:href="#TableWithChairs" transform="rotate(-90) translate(-130, 0)" />
<use id="TableWithChairsS" xlink:href="#TableWithChairs" />
</defs>
<!-- room background -->
<rect x="0" y="0" width="704" height="702" fill="white"/>
<!-- tables vertical -->
<use xlink:href="#TableWithChairsE" x="497" y="117" />
<use xlink:href="#TableWithChairsE" x="497" y="247" />
<use xlink:href="#TableWithChairsW" x="142" y="117" />
<use xlink:href="#TableWithChairsW" x="142" y="247" />
<!-- tables horizontal -->
<use xlink:href="#TableWithChairsN" x="207" y="117" />
<use xlink:href="#TableWithChairsN" x="337" y="117" />
<use xlink:href="#TableWithChairsS" x="207" y="312" />
<use xlink:href="#TableWithChairsS" x="337" y="312" />
</svg>
Is it possible to write this code more compact? I have a table, which I would like to rotate. Yet I'm using four different objects: TableWithCharisW..S
<?xml version="1.0"?>
<svg width="704" height="702" xmlns="http://www.w3.org/2000/svg">
<defs>
<!-- objects -->
<rect id="Chair" width="40" height="40" />
<rect id="Table" width="130" height="65" />
<g id="TableWithChairs">
<use xlink:href="#Table" />
<use xlink:href="#Chair" x="12.5" y="70" />
<use xlink:href="#Chair" x="77.5" y="70" />
</g>
<use id="TableWithChairsW" xlink:href="#TableWithChairs" transform="rotate(90) translate(0, -65)" />
<use id="TableWithChairsN" xlink:href="#TableWithChairs" transform="rotate(180) translate(-130, -65)" />
<use id="TableWithChairsE" xlink:href="#TableWithChairs" transform="rotate(-90) translate(-130, 0)" />
<use id="TableWithChairsS" xlink:href="#TableWithChairs" />
</defs>
<!-- room background -->
<rect x="0" y="0" width="704" height="702" fill="white"/>
<!-- tables vertical -->
<use xlink:href="#TableWithChairsE" x="497" y="117" />
<use xlink:href="#TableWithChairsE" x="497" y="247" />
<use xlink:href="#TableWithChairsW" x="142" y="117" />
<use xlink:href="#TableWithChairsW" x="142" y="247" />
<!-- tables horizontal -->
<use xlink:href="#TableWithChairsN" x="207" y="117" />
<use xlink:href="#TableWithChairsN" x="337" y="117" />
<use xlink:href="#TableWithChairsS" x="207" y="312" />
<use xlink:href="#TableWithChairsS" x="337" y="312" />
</svg>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果去掉E、W、N、S这4个中间阶段,直接将transform属性放在垂直和水平表格的标签上,会更紧凑。但它的模块化程度也较低,并且更难以理解,因此您可能不想这样做。我认为没有一种方法可以使其更加紧凑,而又不会失去每次旋转仅一次的优点(除非您将缩短长名称视为“使其更加紧凑”:-)
It would be more compact if you get rid of the 4 intermediate stages E, W, N, S and just put the transform attribute directly on the tags for the vertical and horizontal tables. But it would also be less modular and more difficult to understand, so you may not want to do it. I don't think there's a way to make it more compact without losing the advantages of doing each of the rotations only once (except if you count shortening the long names as "making it more compact" :-)