开发者

How could I write this SVG file more compact?

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: TableWi开发者_如何转开发thCharisW..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>


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" :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜