Movatterモバイル変換


[0]ホーム

URL:


Chapter 8: Coordinate Systems, Transformations and Units

8.1. Introduction

All SVG content is drawn insideSVG viewports.Every SVG viewport defines a drawing region characterized by a size(width, height), and an origin, measured in abstractuser units.

Note that the term SVG viewport is distinct from the"viewport"term used in CSS.

Theinitial viewport is a top-levelSVG viewport that establishes a mapping between the coordinate system usedby the containing environment (for example, CSS pixels in web browsers)anduser units. Establishing an initial viewport is described in moredetail inThe initial viewport.

SVG viewports are only established by elements. SeeEstablishing a new SVG viewport for informationon which elements generate viewports.

Each SVG viewport generates aviewport coordinate systemand auser coordinate system, initially identical.Providing aviewBox on a viewport's element transforms the user coordinate systemrelative to the viewport coordinate system as described inTheviewBox attribute. Child elements of a viewport canfurther modify theuser coordinate system, for example by specifyingthetransform property.

SVG viewports can be nested. Percentage units are resolved with referenceto the width and height of the nearest ancestral SVG viewport. Hence, nestingSVG viewports provides an opportunity to redefine the meaning of percentageunits and provide a new reference rectangle for "fitting" a graphic relativeto a particular rectangular area.

The width, height and origin of SVG viewports is established by a negotiationprocess between the SVG document fragment generating the SVG viewport, and theparent of that fragment (whether real or implicit). SeeEstablishing a new SVG viewport for adescription of this negotiation process.

By default, a nested SVG viewport'sviewport coordinate system is equivalent to the localcoordinate system of the parent element, translated by the origin of the SVG viewport'selement. However, atransform property on an SVG viewport's element will modifytheviewport coordinate system relative to the parent element's user coordinate system.

Abstractly, all SVG viewports are embedded in thecanvas,a drawing region that is infinitely large in all relevant dimensions.

8.2. Computing the equivalent transform of an SVG viewport

This process converts the min-x, min-y, width and height values of a viewBox attribute,the position and size of the element on which the viewBox attribute is defined,and the value of the preserveAspectRatio attribute on that element into a translation anda scale that is applied to content contained by the element.

  1. Letvb-x,vb-y,vb-width,vb-height be the min-x, min-y, width and height values of the viewBox attribute respectively.
  2. Lete-x,e-y,e-width,e-height be the position and size of the element respectively.
  3. Letalign be the align value of preserveAspectRatio, or 'xMidYMid' if preserveAspectRatio is not defined.
  4. LetmeetOrSlice be the meetOrSlice value of preserveAspectRatio, or 'meet' if preserveAspectRatio is not defined or if meetOrSlice is missing from this value.
  5. Initializescale-x toe-width/vb-width.
  6. Initializescale-y toe-height/vb-height.
  7. Ifalign is not 'none' andmeetOrSlice is 'meet', set the larger ofscale-x andscale-y to the smaller.
  8. Otherwise, ifalign is not 'none' andmeetOrSlice is 'slice', set the smaller ofscale-x andscale-y to the larger.
  9. Initializetranslate-x toe-x - (vb-x * scale-x).
  10. Initializetranslate-y toe-y - (vb-y * scale-y)
  11. Ifalign contains 'xMid', add (e-width -vb-width *scale-x) / 2 totranslate-x.
  12. Ifalign contains 'xMax', add (e-width -vb-width *scale-x) totranslate-x.
  13. Ifalign contains 'yMid', add (e-height -vb-height *scale-y) / 2 totranslate-y.
  14. Ifalign contains 'yMax', add (e-height -vb-height *scale-y) totranslate-y.

The transform applied to content contained by the element is given bytranslate(translate-x,translate-y) scale(scale-x,scale-y).

8.3. The initial viewport

The initial viewport's width, must be the value of thewidthpresentation attribute on theoutermost svg element, unless thefollowing conditions are met:

Under these conditions, the viewport's width must be established via thepositioning properties.

Similarly, if there arepositioning propertiesspecified on the referencing element or on theoutermost svg element that aresufficient to establish the height of the viewport, then thesepositioning properties must establish the viewport's height;otherwise, the initial viewport's height must be the value of theheightpresentation attribute on theoutermost svg element.

If thewidth orheightpresentation attributes on theoutermost svg elementare inuser units (i.e., no unitidentifier has been provided), then the value is assumed to beequivalent to the same number of "px" units (seeUnits).

In the following example, an SVG graphic is embedded inlinewithin a parent XML document which is formatted using CSSlayout rules. Since CSS positioning properties are not providedon theoutermost svg element,thewidth="100px" andheight="200px" attributesdetermine the size of the initial viewport:

<?xml version="1.0" standalone="yes"?><parent xmlns="http://some.url">   <!-- SVG graphic -->   <svg xmlns='http://www.w3.org/2000/svg'      width="100px" height="200px">      <path d="M100,100 Q200,400,300,100"/>      <!-- rest of SVG graphic would go here -->   </svg></parent>

8.4. The initial coordinate system

For theoutermost svg element, the SVG useragent must determine an initialviewport coordinate system and aninitialuser coordinate system such that thetwo coordinates systems are identical. The origin of bothcoordinate systems must be at the origin of the SVG viewport, and oneunit in the initial coordinate system must equal oneCSS 2.1 px([CSS2], section 4.3.2)in the SVG viewport.In stand-alone SVG documents and in SVG document fragments embedded(by reference or inline) within parent documents where the parent'slayout is determined by CSS [CSS2],the initial viewportcoordinate system (and therefore the initial user coordinatesystem) must have its origin at the top/left of the viewport, withthe positive x-axis pointing towards the right, the positivey-axis pointing down, and text rendered with an "upright"orientation, which means glyphs are oriented such that Romancharacters and full-size ideographic characters for Asianscripts have the top edge of the corresponding glyphs orientedupwards and the right edge of the corresponding glyphs orientedto the right.

If the SVG implementation is part of a user agent whichsupports styling documents using CSS 2.1 compatiblepx units, then the SVG user agent should set itsinitial value for the size of apx unit in real worldunits to match the value used for other styling operations;otherwise, if the user agent can determine the size of apx unit from its environment, it should use thatvalue; otherwise, it should choose an appropriate size for onepx unit. In all cases, the size of apx mustbe in conformance withthe rules described in CSS 2.1([CSS2], section 4.3.2).

Example InitialCoords belowshows that the initial coordinate system has the origin at thetop/left with the x-axis pointing to the right and the y-axispointing down. The initial user coordinate system has one userunit equal to the parent (implicit or explicit) user agent's"pixel".

<?xml version="1.0" standalone="no"?><svg width="300px" height="100px" version="1.1"     xmlns="http://www.w3.org/2000/svg">  <desc>Example InitialCoords - SVG's initial coordinate system</desc>  <g fill="none" stroke="black" stroke-width="3" >    <line x1="0" y1="1.5" x2="300" y2="1.5" />    <line x1="1.5" y1="0" x2="1.5" y2="100" />  </g>  <g fill="red" stroke="none" >    <rect x="0" y="0" width="3" height="3" />    <rect x="297" y="0" width="3" height="3" />    <rect x="0" y="97" width="3" height="3" />  </g>  <g font-size="14" font-family="Verdana" >    <text x="10" y="20">(0,0)</text>    <text x="240" y="20">(300,0)</text>    <text x="10" y="90">(0,100)</text>  </g></svg>
Example InitialCoords — SVG's initial coordinate system

Example InitialCoords

View this example as SVG (SVG-enabled browsers only)

8.5. The ‘transform’ property

User agents must support thetransform property and presentation attributeas defined in [css-transforms-1].

8.6. The‘viewBox’ attribute

NameValueInitial valueAnimatable
viewBox[<min-x>,?<min-y>,?<width>,?<height>]As if not specified.yes
<min-x>, <min-y>, <width>, <height> =<number>

Transform on thesvg element is a bit special due to theviewBox attribute. The transform should be applied as if thesvg had a parent element with that transform set.

RESOLUTION: transform property applies conceptually to the outside of the 'svg' element and there is no difference betweenpresentation attribute and style property (in terms of the visual result).

TheviewBox attribute, in conjunction with thepreserveAspectRatio attribute, provides the capability tostretch an SVG viewport to fit a particular container element.

The value of theviewBox attribute is a list of fournumbers<min-x>,<min-y>,<width> and<height>, separated bywhitespace and/or a comma, that specify a rectangle in userspace that should be mapped to the bounds of the SVG viewportestablished by the given element, taking into account thepreserveAspectRatio attribute.The presence of theviewBox attribute results in a transformationbeing applied to the viewport coordinate system as described inComputing the equivalent transform of an SVG viewport.

A negative value for<width> or<height> is an error and invalidatestheviewBox attribute. A value of zero disables rendering of theelement.

Example ViewBox illustratesthe use of theviewBox attributeon theoutermost svg element to specify thatthe SVG content should stretch to fit bounds of theSVG viewport.

<?xml version="1.0" standalone="no"?><svg width="300px" height="200px"     viewBox="0 0 1500 1000" preserveAspectRatio="none"     xmlns="http://www.w3.org/2000/svg">  <desc>Example ViewBox - uses the viewBox   attribute to automatically create an initial user coordinate   system which causes the graphic to scale to fit into the   SVG viewport no matter what size the SVG viewport is.</desc>  <!-- This rectangle goes from (0,0) to (1500,1000) in user coordinate system.       Because of the viewBox attribute above,       the rectangle will end up filling the entire area       reserved for the SVG content. -->  <rect x="0" y="0" width="1500" height="1000"        fill="yellow" stroke="blue" stroke-width="12"  />  <!-- A large, red triangle -->  <path fill="red"  d="M 750,100 L 250,900 L 1250,900 z"/>  <!-- A text string that spans most of the SVG viewport -->  <text x="100" y="600" font-size="200" font-family="Verdana" >    Stretch to fit  </text></svg>
Example ViewBox
Rendered into
SVG viewport with
width=300px,
height=200px
     Rendered into
SVG viewport with
width=150px,
height=200px
Example ViewBox - stretch to fit 300 by 200     Example ViewBox - stretch to fit 150 by 200

Viewthis example as SVG (SVG-enabled browsers only)
 

The effect of theviewBoxattribute is that the user agent automatically supplies theappropriate transformation matrix to map the specifiedrectangle in user coordinate system to the bounds of a designated region(often, the SVG viewport). To achieve the effect of the example onthe left, with SVG viewport dimensions of 300 by 200 pixels, theuser agent needs to automatically insert a transformation whichscales both X and Y by 0.2. The effect is equivalent to havingan SVG viewport of size 300px by 200px and the followingsupplemental transformation in the document, as follows:

<?xml version="1.0" standalone="no"?><svg width="300px" height="200px"     xmlns="http://www.w3.org/2000/svg"><g transform="scale(0.2)">    <!-- Rest of document goes here --></g></svg>

To achieve the effect of the example on the right, withSVG viewport dimensions of 150 by 200 pixels, the user agent needsto automatically insert a transformation which scales X by 0.1and Y by 0.2. The effect is equivalent to having an SVG viewport ofsize 150px by 200px and the following supplementaltransformation in the document, as follows:

<?xml version="1.0" standalone="no"?><svg width="150px" height="200px"     xmlns="http://www.w3.org/2000/svg"><g transform="scale(0.1 0.2)">    <!-- Rest of document goes here --></g></svg>

Note that in some cases the user agent will need to supply atranslate transformation in addition to ascale transformation. For example, on anoutermost svg element, atranslate transformation will be needed if theviewBox attributes specifiesvalues other than zero for<min-x> or<min-y>.

If bothtransform (orpatternTransform)andviewBox are applied to an element two new coordinatesystems are established.transform establishes the first newcoordinate system for the element.viewBoxestablishes a second coordinate system for all descendants ofthe element. The first coordinate system is post-multiplied by thesecond coordinate system.

Unlike thetransform property,the automatic transformation that is createddue to aviewBox does not affectthe‘x’,‘y’,‘width’ and‘height’ attributes (or in the case ofthemarker element, themarkerWidth andmarkerHeight attributes) on theelement with theviewBoxattribute. Thus, in the example above which shows ansvg element which haswidth andheight presentation attributesand aviewBox attribute,thewidth andheightrepresent values in the coordinate system that existsbefore theviewBox transformation is applied. Onthe other hand, like thetransform property, it doesestablish a new coordinate system for all other attributes andfor descendant elements.

8.7. The‘preserveAspectRatio’attribute

NameValueInitial valueAnimatable
preserveAspectRatio<align><meetOrSlice>?xMidYMid meetyes
<align> =    none    | xMinYMin | xMidYMin | xMaxYMin    | xMinYMid | xMidYMid | xMaxYMid    | xMinYMax | xMidYMax | xMaxYMax
<meetOrSlice> = meet | slice

Indicates whether or not to force uniform scaling. Applies to all elements that establish a new SVG viewport (seeelements that establish SVG viewports), plus theimage,marker,pattern andview elements

In some cases, typically when using theviewBox attribute, it is desirable that the graphics stretch tofit non-uniformly to take up theentire SVG viewport. In other cases, it is desirable that uniformscaling be used for the purposes of preserving the aspect ratioof the graphics.

For elements that establish a new SVG viewport (seeelements thatestablish SVG viewports), plus themarker,pattern andview elements,preserveAspectRatio only applies whena value has been provided forviewBoxon the same element. For these elements, if attributeviewBox is not provided, thenpreserveAspectRatio is ignored.

Forimage elements,preserveAspectRatio indicates howreferenced images should be fitted with respect to thereference rectangle and whether the aspect ratio of thereferenced image should be preserved with respect to thecurrent user coordinate system.

The<align> parameterindicates whether to force uniform scaling and, if so, thealignment method to use in case the aspect ratio of theviewBox doesn't match the aspect ratio of the SVG viewport. The<align> parameter must be oneof the following strings:

The<meetOrSlice>parameter is optional and, if provided, is separated from the<align> value by one ormore spaces and then must be one of the following strings:

Example PreserveAspectRatioillustrates the various options onpreserveAspectRatio.The example creates several new SVG viewports byincludingsvg sub-elements embeddedinside theoutermost svg element (seeEstablishing a newSVG viewport).

<svg width="450px" height="300px" xmlns="http://www.w3.org/2000/svg">  <desc>Example PreserveAspectRatio - illustrates preserveAspectRatio attribute</desc>  <style type="text/css">    text { font-size: 9; }    rect { fill: none; stroke: blue; }  </style>  <defs>    <g>      <rect x='.5' y='.5' width='29' height='39'/>      <circle cx='15' cy='20' r='10'  fill='yellow'/>      <circle cx='12' cy='17' r='1.5' fill='black'/>      <circle cx='17' cy='17' r='1.5' fill='black'/>      <path d='M 10 24 A 8 8 0 0 0 20 24' stroke='black' stroke-width='2'/>    </g>  </defs>  <rect x="1" y="1" width="448" height="298"/>  <text x="10" y="30">SVG to fit</text>  <g transform="translate(20,40)"><use href="#smile" /></g>  <text x="10" y="110">Viewport 1</text>  <g transform="translate(10,120)"><rect x='.5' y='.5' width='49' height='29'/></g>  <text x="10" y="180">Viewport 2</text>  <g transform="translate(20,190)"><rect x='.5' y='.5' width='29' height='59'/></g>  <g transform="translate(100, 60)">    <text x="0" y="-30">--------------- meet ---------------</text>    <g>      <text y="-10">xMin*</text>      <rect x='.5' y='.5' width='49' height='29'/>      <svg preserveAspectRatio="xMinYMin meet" viewBox="0 0 30 40" width="50" height="30"><use href="#smile" />      </svg>    </g>    <g transform="translate(70,0)">      <text y="-10">xMid*</text>      <rect x='.5' y='.5' width='49' height='29'/>      <svg preserveAspectRatio="xMidYMid meet" viewBox="0 0 30 40" width="50" height="30"><use href="#smile" />      </svg>    </g>    <g transform="translate(0,70)">      <text y="-10">xMax*</text>      <rect x='.5' y='.5' width='49' height='29'/>      <svg preserveAspectRatio="xMaxYMax meet" viewBox="0 0 30 40" width="50" height="30">        <use href="#smile" />      </svg>    </g>  </g>  <g transform="translate(250, 60)">    <text x="0" y="-30">---------- meet ----------</text>    <g>      <text y="-10">*YMin</text>      <rect  x='.5' y='.5' width='29' height='59'/>      <svg preserveAspectRatio="xMinYMin meet" viewBox="0 0 30 40" width="30" height="60"><use href="#smile" />      </svg>    </g>    <g transform="translate(50, 0)">      <text y="-10">*YMid</text>      <rect x='.5' y='.5' width='29' height='59'/>      <svg preserveAspectRatio="xMidYMid meet" viewBox="0 0 30 40" width="30" height="60"><use href="#smile" />      </svg>    </g>    <g transform="translate(100, 0)">      <text y="-10">*YMax</text>      <rect x='.5' y='.5' width='29' height='59'/>      <svg preserveAspectRatio="xMaxYMax meet" viewBox="0 0 30 40" width="30" height="60"><use href="#smile" />      </svg>    </g>  </g>  <g transform="translate(100, 220)">    <text x="0" y="-30">---------- slice ----------</text>    <g>      <text y="-10">xMin*</text>      <rect x='.5' y='.5' width='29' height='59'/>      <svg preserveAspectRatio="xMinYMin slice" viewBox="0 0 30 40" width="30" height="60"><use href="#smile" />      </svg>    </g>    <g transform="translate(50,0)">      <text y="-10">xMid*</text>      <rect x='.5' y='.5' width='29' height='59'/>      <svg preserveAspectRatio="xMidYMid slice" viewBox="0 0 30 40" width="30" height="60"><use href="#smile" />      </svg>    </g>    <g transform="translate(100,0)">      <text y="-10">xMax*</text>      <rect x='.5' y='.5' width='29' height='59'/>      <svg preserveAspectRatio="xMaxYMax slice" viewBox="0 0 30 40" width="30" height="60"><use href="#smile" />      </svg>    </g>  </g>  <g transform="translate(250, 220)">    <text x="0" y="-30">--------------- slice ---------------</text>    <g>      <text y="-10">*YMin</text>      <rect x='.5' y='.5' width='49' height='29'/>      <svg preserveAspectRatio="xMinYMin slice" viewBox="0 0 30 40"           width="50" height="30"><use href="#smile" />      </svg>    </g>    <g transform="translate(70,0)">      <text y="-10">*YMid</text>      <rect x='.5' y='.5' width='49' height='29'/>      <svg preserveAspectRatio="xMidYMid slice" viewBox="0 0 30 40" width="50" height="30"><use href="#smile" />      </svg>    </g>    <g transform="translate(140,0)">      <text y="-10">*YMax</text>      <rect x='.5' y='.5' width='49' height='29'/>      <svg preserveAspectRatio="xMaxYMax slice" viewBox="0 0 30 40" width="50" height="30"><use href="#smile" />      </svg>    </g>  </g></svg>
Example PreserveAspectRatio — demonstrate available options

Example PreserveAspectRatio

8.8. Establishing a new SVG viewport

Including ansvg element inside SVG contentcreates a new SVG viewport into which all containedgraphics are drawn; this implicitly establishes botha new viewport coordinate system and a new user coordinate system.Additionally, there is a new meaning for percentage units therein,because a new SVG viewport has been established(seeUnits).

The bounds of the new SVG viewport are defined by the‘x’,‘y’,‘width’ and‘height’ attributes on the elementestablishing the new SVG viewport, such as ansvg element. Both the newviewport coordinate system and the new user coordinate systemhave their origins at (‘x’,‘y’), where‘x’ and‘y’represent the value of the corresponding attributes on theelement establishing the SVG viewport. The orientation of the newviewport coordinate system and the new user coordinate systemcorrespond to the orientation of the current user coordinatesystem for the element establishing the SVG viewport. A single unitin the new viewport coordinate system and the new usercoordinate system are the same size as a single unit in thecurrent user coordinate system for the element establishing the SVGviewport.

Here is an example:

<?xml version="1.0" standalone="no"?><svg width="4in" height="3in"     xmlns="http://www.w3.org/2000/svg">  <desc>This SVG drawing embeds another one,    thus establishing a new SVG viewport  </desc>  <!-- The following statement establishing a new SVG viewport       and renders SVG drawing B into that SVG viewport -->  <svg x="25%" y="25%" width="50%" height="50%">     <!-- drawing B goes here -->  </svg></svg>

For an extensive example of creating new SVG viewports, seeExamplePreserveAspectRatio.

The following elements establish new SVG viewports:

For historical reasons, thepattern andmarker elements do not create a new viewport, despite accepting aviewBox attribute. Neither do theclipPath ormask elements. Percentage lengths within the content of these elements are not proportional to the dimensions of the graphical effect region.

TheforeignObject element establishes a newCSS containing block for its child content. The same is true for avideo,audio, orcanvas element when its fallback content is being rendered. This has some effects similar to a new viewport, resetting the scope of layout for child content. However, in order to render SVG elements that are descendents offoreignObject, a newsvg element must establish an SVG document fragment and SVG viewport.

Animage oriframe element creates a newdocument viewport for the referenced document. If the referenced document is a SVG file, it will of course establish its own SVG viewport.

Whether a new SVG viewport also establishes a new additionalclipping path is determined by the value of theoverflow property on the elementthat establishes the new SVG viewport.

8.9. Units

SVG follows the description and definition of common values andunits from the CSS Values and Units Module[css-values] for attributes,presentation attributes and CSS properties. Each attribute and propertymust specify the used component value type. Subsequent or extendingspecifications published by the CSS WG or SVG WG may extend basic datatypes or add new data types.

For<percentage> values that are defined to be relativeto the size of SVG viewport:

Example Units belowillustrates some of the processing rules for different types ofunits.

<?xml version="1.0" standalone="no"?><svg width="400px" height="200px" viewBox="0 0 4000 2000"     xmlns="http://www.w3.org/2000/svg">  <title>Example Units</title>  <desc>Illustrates various units options</desc>  <!-- Frame the picture -->  <rect x="5" y="5" width="3990" height="1990"        fill="none" stroke="blue" stroke-width="10"/>  <g fill="blue" stroke="red" font-family="Verdana" font-size="150">    <!-- Absolute unit specifiers -->    <g transform="translate(400,0)">      <text x="-50" y="300" fill="black" stroke="none">Abs. units:</text>      <rect x="0" y="400" width="4in" height="2in" stroke-width=".4in"/>      <rect x="0" y="750" width="384" height="192" stroke-width="38.4"/>      <g transform="scale(2)">        <rect x="0" y="600" width="4in" height="2in" stroke-width=".4in"/>      </g>    </g>    <!-- Relative unit specifiers -->    <g transform="translate(1600,0)">      <text x="-50" y="300" fill="black" stroke="none">Rel. units:</text>      <rect x="0" y="400" width="2.5em" height="1.25em" stroke-width=".25em"/>      <rect x="0" y="750" width="375" height="187.5" stroke-width="37.5"/>      <g transform="scale(2)">        <rect x="0" y="600" width="2.5em" height="1.25em" stroke-width=".25em"/>      </g>    </g>    <!-- Percentages -->    <g transform="translate(2800,0)">      <text x="-50" y="300" fill="black" stroke="none">Percentages:</text>      <rect x="0" y="400" width="10%" height="10%" stroke-width="1%"/>      <rect x="0" y="750" width="400" height="200" stroke-width="31.62"/>      <g transform="scale(2)">        <rect x="0" y="600" width="10%" height="10%" stroke-width="1%"/>      </g>    </g>  </g></svg>
Example Units — demonstrate available options

Example Units

The three rectangles on the left demonstrate the use of oneof the absolute unit identifiers, the "in" unit (inch). CSS defines 1inch to be equal to 96 pixels. Therefore, the topmost rectangle, which isspecified in inches, is exactly the same size as the middlerectangle, which is specified in user units such that there are96 user units for each corresponding inch in the topmostrectangle. The bottom rectangle of the group illustrateswhat happens when values specified in inches are scaled.

The three rectangles in the middle demonstrate the use ofone of the relative unit identifiers, the "em" unit. Becausethefont-size property has been setto150 on the outermostg element, each "em" unit isequal to 150 user units. The topmost rectangle, which isspecified in "em" units, is exactly the same size as the middlerectangle, which is specified in user units such that there are150 user units for each corresponding "em" unit in the topmostrectangle. The bottom rectangle of the group illustrates whathappens when values specified in "em" units are scaled.

The three rectangles on the right demonstrate the use ofpercentages. Note that the width and height of the SVG viewport inthe user coordinate system for the SVG viewport element (in thiscase, theoutermost svg element) are 4000 and2000, respectively, because processing theviewBox attribute results in atransformed user coordinate system. The topmost rectangle,which is specified in percentage units, is exactly the samesize as the middle rectangle, which is specified in equivalentuser units. In particular, note that thestroke-width property in themiddle rectangle is set to 1% of thesqrt((actual-width)**2 +(actual-height)**2) / sqrt(2), which in thiscase is .01*sqrt(4000*4000+2000*2000)/sqrt(2), or 31.62. Thebottom rectangle of the group illustrates what happens whenvalues specified in percentage units are scaled.

8.10. Bounding boxes

bounding box

The bounding box (or "bbox") of an element is the tightest fitting rectangle aligned with the axes of that element's user coordinate system that entirely encloses it and its descendants.

Three kinds of bounding boxes can be computed for an element:

  1. Theobject bounding box is the bounding box that contains only an element's geometric shape. Forbasic shapes, this is the area that is filled. Unless otherwise specified, this is what is meant by the unqualified term "bounding box".
  2. Thestroke bounding box is the bounding box that contains an element's geometric shape and itsstroke shape.
  3. Thedecorated bounding box is the bounding box that contains an element's geometric shape, itsstroke shape and itsmarkers.

Note that the values of theopacity,visibility,fill,fill-opacity,fill-rule,stroke-dasharrayandstroke-dashoffset properties on an element have no effect on thebounding box of an element.

For curved shapes, the bounding box must enclose all portions of the shapealong the edge, not just end points. Note that control points for a curve whichare not defined as lying along the line of the resulting curve (e.g., the secondcoordinate pair of a Cubic Bézier command) must not contribute to the dimensionsof the bounding box (though those points may fall within the area of thebounding box, if they lie within the shape itself, or along or close to thecurve). For example, control points of a curve that are at a further distancethan the curve edge, from the non-enclosing side of the curve edge, must beexcluded from the bounding box.

Image showing the object bounding box of a quadratic Bézier curve.

The path'M20,50 L35,100 H120 V50 Q70,10 20,50' is shown in light blue. On the left, a correct object bounding box of the path is shown. Note that it does not include the top-most control point of the curve, but it does include all of the blue shape, even the parts that lie outside of the convex hull of the control points.

Even if an element is not in therendering tree – due to it being'display: none', within adefselement, not usually rendered like asymbol element or notcurrently present in the document tree – it still has a bounding box.A call togetBBoxon the element will return the same rectangle as if the element wererendered. However, an element that is not in therendering treedoes not contribute to the bounding box of any ancestor element.

The following example defines a number of elements. The expectedobject bounding box for each element with an ID is shown below.

<svg xmlns="http://www.w3.org/2000/svg">  <title>Bounding Box Calculation</title>  <desc>Examples of elements with different bounding box results based on context.</desc>  <defs>     <rect x="20" y="20" width="40" height="40" fill="blue" />  </defs>  <g>    <use href="#rect-1" x="10" y="10" />    <g display="none">      <rect x="10" y="10" width="100" height="100" fill="red" />    </g>  </g></svg>
Element IDBounding Box Result
"defs-1"{0, 0, 0, 0}
"rect-1"{20, 20, 40, 40}
"group-1"{30, 30, 40, 40}
"use-1"{30, 30, 40, 40}
"group-2"{10, 10, 100, 100}
"rect-2"{10, 10, 100, 100}

Fortext content elements, for the purposes of the bounding boxcalculation, each glyph must be treated as a separate graphics element.The calculations must assume that all glyphs occupy thefull glyph cell.Thefull glyph cell must have widthequal to the horizontal advance and height equal to the EM box for horizontaltext. For vertical text that is typeset sideways, thefull glyph cell musthave width equal to the EM box and height equal to the horizontal advance.For other vertical text, thefull glyph cell must have width equal to theEM box and height equal to the vertical advance, or height equal to the heightof the EM box if no vertical advance is defined in the font.For example, for horizontal text, the calculations must assume that each glyphextends vertically to the full ascent and descent values for the font.

Because declarative or scripted animation can change the shape, size, andposition of an element, the bounding box is mutable. Thus, the bounding boxfor an element shall reflect the current values for the element at the snapshotin time at which the bounding box is requested, whether through a script callor as part of a declarative or linking syntax.

An element which has zero width, zero height, or both (such as avertical or horizontal line, or arect element with a zerowidth orheight) still has a bounding box, with apositive value for the positive dimension, or with'0'for both the width and height if no positive dimension is specified. Similarly,subpaths segments of apath element with zero width and height must beincluded in that element's geometry for the sake of the bounding box.

An element with no position specified (such as apath element with a value ofnone for thed property) is positioned at thepoint (0,0) for the purposes of calculating a bounding box.

Note that elements whose DOM object does not derive fromSVGGraphicsElement(such as gradient elements) do not have a bounding box, and thus have nointerface to request a bounding box.

Elements in therendering tree which reference unresolved resources shallstill have a bounding box, defined by the position and dimensions specified intheir attributes, or by theinitial value for those attributes if novalues are supplied. For example, the element<use href="#bad" x="10" y="10"/>would have a bounding box with an x and y of 10 and a width and height of 0.

The following algorithm defines how to compute a bounding box for a givenelement. The inputs to the algorithm are:

The algorithm to compute the bounding box is as follows, depending on the type ofelement:

ashape
atext content element
ana element within atext content element
  1. Letbox be a rectangle initialized to (0, 0, 0, 0).
  2. Letfill-shape be theequivalent path ofelement if it is ashape, or a shape that includes each of the glyph cells corresponding to the text within the elements otherwise.
  3. Iffill is true, then setbox to the tightest rectangle in the coordinate systemspace that containsfill-shape.

    The values of thefill,fill-opacity andfill-rule properties do not affectfill-shape.

  4. Ifstroke is true and the element'sstroke is anything other thannone, then setbox to be the union ofbox and the tightest rectangle in coordinate systemspace that contains thestroke shape of the element, with the assumption that the element has no dash pattern.

    The values of thestroke-opacity,stroke-dasharray andstroke-dashoffset do not affect the calculation of the stroke shape.

  5. Ifmarkers is true, then for each markermarker rendered on the element:
    1. For each descendantgraphics elementchild of themarker element that definesmarker's content:
      1. Ifchild has an ancestor element within themarker that is'display: none', has a failingconditional processing attribute, or is not ana,g,svg orswitch element, then continue to the next descendantgraphics element.
      2. Otherwise, setbox to be the union ofbox and the result of invoking the algorithm to compute a bounding box withchild as the element,space as the target coordinate space, true forfill,stroke andmarkers, andclipped forclipped.
  6. Ifclipped is true and the value ofclip-path onelement is notnone, then setbox to be the tightest rectangle in coordinate systemspace that contains the intersection ofbox and the clipping path.
  7. Returnbox.
acontainer element
use
  1. Letbox be a rectangle initialized to (0, 0, 0, 0).
  2. Letparent be thecontainer element if it is one, or the root of theuse element's shadow tree otherwise.
  3. For each descendantgraphics elementchild ofparent:
    1. Ifchild isnot rendered then continue to the next descendantgraphics element.
    2. Otherwise, setbox to be the union ofbox and the result of invoking the algorithm to compute a bounding box withchild as the element and the same values forspace,fill,stroke,markers andclipped as the corresponding algorithm input values.
  4. Ifclipped is true:
    • If the value ofclip-path onelement is notnone, then setbox to be the tightest rectangle in coordinate systemspace that contains the intersection ofbox and the clipping path.
    • If theoverflow property applies to theelement and does not have a value ofvisible, then setbox to be the tightest rectangle in coordinate systemspace that contains the intersection ofbox and the element's overflow bounds.
    • If theclip property applies to theelement and does not have a value ofauto, then setbox to be the tightest rectangle in coordinate systemspace that contains the intersection ofbox and the rectangle specified byclip.
  5. Returnbox.
canvas
foreignObject
iframe
image
video
  1. Letbox be the tightest rectangle in coordinate spacespace that contains thepositioning rectangle defined by the‘x’,‘y’,‘width’ and‘height’ geometric properties of the element.

    Thefill,stroke andmarkers input arguments to this algorithm do not affect the bounding box returned for these elements.

  2. Ifclipped is true and the value ofclip-path onelement is notnone, then setbox to be the tightest rectangle in coordinate systemspace that contains the intersection ofbox and the clipping path.
  3. Returnbox.

The unionbox with a value of (0, 0, 0, 0) and an empty shapeisbox.

Theobject bounding box,stroke bounding box ordecorated bounding boxof an element is the result of invoking the bounding box computation algorithmabove with the following arguments:element is the element itself;space is the element's user coordinate system;fill is true;stroke is true if we are computing thestroke bounding box ordecorated bounding box, and false othwerise;markers is true if we are computing thedecorated bounding box, and false otherwise; andclipped is false.

8.11. Object bounding box units

The following elements offer the option of expressingcoordinate values and lengths as fractions (and, in some cases,percentages) of theobject bounding box,by setting a specified attribute to'objectBoundingBox'on the given element:

ElementAttributeEffect
linearGradientgradientUnitsIndicates that the attributes which specify the gradient vector (x1,y1,x2,y2) represent fractions or percentages of the bounding box of the element to which the gradient is applied.
radialGradientgradientUnitsIndicates that the attributes which specify the center (cx,cy), the radius (r) and focus (fx,fy) represent fractions or percentages of the bounding box of the element to which the gradient is applied.
patternpatternUnitsIndicates that the attributes which define how to tile the pattern (x,y,width,height) are established using the bounding box of the element to which the pattern is applied.
patternpatternContentUnitsIndicates that the user coordinate system for the contents of the pattern is established using the bounding box of the element to which the pattern is applied.
clipPathclipPathUnitsIndicates that the user coordinate system for the contents of theclipPath element is established using the bounding box of the element to which the clipping path is applied.
maskmaskUnitsIndicates that the attributes which define the masking region (x,y,width,height) is established using the bounding box of the element to which the mask is applied.
maskmaskContentUnitsIndicates that the user coordinate system for the contents of themask element are established using the bounding box of the element to which the mask is applied.
filterfilterUnitsIndicates that the attributes which define thefilter effects region (x,y,width,height) represent fractions or percentages of the bounding box of the element to which the filter is applied.
filterprimitiveUnitsIndicates that the various length values within the filter primitives represent fractions or percentages of the bounding box of the element to which the filter is applied.

In the discussion that follows, the termapplicable elementis the element to which the given effect applies. For gradients andpatterns, the applicable element is thegraphics elementwhich has itsfill orstroke property referencing thegiven gradient or pattern. (For special rules concerningtext elements, see the discussion ofobjectbounding box units and text elements.) For clipping paths,masks and filters, the applicable element can be either acontainer element or agraphics element.

When keywordobjectBoundingBox is used, then theeffect is as if a supplemental transformation matrix wereinserted into the list of nested transformation matrices tocreate a new user coordinate system.

First, the (minx,miny) and(maxx,maxy) coordinates aredetermined by the extends of theobject bounding box ofthe applicable element.

Then, coordinate (0,0) in the new user coordinate system ismapped to the (minx,miny) corner of the tight bounding boxwithin the user coordinate system of the applicable element andcoordinate (1,1) in the new user coordinate system is mapped tothe (maxx,maxy) corner of the tight bounding box of theapplicable element. In most situations, the followingtransformation matrix produces the correct effect:

[ (maxx-minx) 0 0 (maxy-miny) minx miny ]

When percentages are used with attributes that define thegradient vector, the pattern tile, the filter region or themasking region, a percentage represents the same value as thecorresponding decimal value (e.g., 50% means the same as 0.5).If percentages are used within the content of apattern,clipPath,mask orfilter element, these valuesare treated according to the processing rules for percentagesas defined inUnits.

Any numeric value can be specified for values expressed as afraction or percentage of object bounding box units. Inparticular, fractions less are zero or greater than one andpercentages less than 0% or greater than 100% can bespecified.

KeywordobjectBoundingBoxshould not be used when the geometry of the applicable elementhas no width or no height, such as the case of a horizontal orvertical line, even when the line has actual thickness whenviewed due to having a non-zero stroke width since stroke widthis ignored for bounding box calculations. When the geometry ofthe applicable element has no width or height andobjectBoundingBox is specified, thenthe given effect (e.g., a gradient or a filter) will beignored.

8.12. Intrinsic sizing properties of SVG content

To enable inclusion of SVG in host documents formatted with CSS, aconcrete object size must be calculated.Theconcrete object size must be calculated using theDefault Sizing Algorithmdefined in CSS Images 3 [css-images-3],with the following inputs:

Thespecified size must be determined from the used values for thewidth andheight sizing properties of thesvgelement.

Theintrinsic dimensions must also be determined from thewidthandheight sizing properties. If eitherwidth orheight arenot specified, the used value is the initial value'auto'.'auto' and percentage lengths must not be used todetermine anintrinsic width orintrinsic height.

With bitmap image formats, theintrinsic dimensions are fixed inthe image file, and the specified size is defined in the host document as neededto scale the image.SVG, being inherently scalable, adapts theintrinsic width andintrinsic height to be the width and height of thespecified size.Therefore, when specified as a length, thewidth andheight sizing properties of thesvg element control theintrinsic dimensions of the SVG image and thespecified size thatis used when placing the SVG image in a host document.

Theintrinsic aspect ratio must be calculated using the followingalgorithm. If the algorithm returns null, then there is no intrinsic aspect ratio.

  1. If thewidth andheight sizing properties on thesvg element are both absolute values:
    1. return width / height
  2. If anSVG View is active:
    1. letviewbox be the viewbox defined by the active SVG View
    2. returnviewbox.width /viewbox.height
  3. If theviewBox on thesvg element is correctly specified:
    1. letviewbox be the viewbox defined by theviewBox attribute on thesvg element
    2. returnviewbox.width /viewbox.height
  4. return null

The behaviour defined in this section is specific to CSS, but may be adaptedto other host contexts. In all host contexts, theintrinsic aspect ratio,where available, must be respected when sizing the SVG viewport.

Examples:

Example: Intrinsic Aspect Ratio 1
<svg xmlns="http://www.w3.org/2000/svg"     width="10cm" height="5cm">  ...</svg>

In this example the intrinsic aspect ratio of theSVG viewport is 2:1. Theintrinsic width is 10cm and the intrinsic height is 5cm.

Example: Intrinsic Aspect Ratio 2
<svg xmlns="http://www.w3.org/2000/svg"     width="100%" height="50%" viewBox="0 0 200 200">  ...</svg>

In this example the intrinsic aspect ratio of the outermostSVG viewport is1:1. An aspect ratio calculation in this case allows embedding in anobject within a containing block that is only constrained in one direction.

Example: Intrinsic Aspect Ratio 3
<svg xmlns="http://www.w3.org/2000/svg"     width="10cm" viewBox="0 0 200 200">  ...</svg>

In this case the intrinsic aspect ratio is 1:1.

Example: Intrinsic Aspect Ratio 4
<svg xmlns="http://www.w3.org/2000/svg"     width="75%" height="10cm" viewBox="0 0 200 200">  ...</svg>

In this example, the intrinsic aspect ratio is 1:1.

Add more examples for the new auto value? E.g some of theexamplesprovided by David Vest.

8.13. Vector effects

SVG 2 Requirement:SVG 2 will have constrained transformations based on SVG 1.2 Tiny.
Resolution:Add vector effects extension proposal to SVG 2 specification.
Purpose:To include non-scaling features (non-scaling part of the object, and non-scaling entire object
Owner:Satoru Takagi (ACTION-3619)

Sometimes it is of interest to let the outline of an object keep itsoriginal width or to let the position of an object fix no matter whichtransforms are applied to it. For example, in a map with a 2px wide linerepresenting roads it is of interest to keep the roads 2px wide even when theuser zooms into the map, or introductory notes on the graphic chart in whichpanning is possible.

To offer such effects regarding special coordinate transformations andgraphic drawings, SVG Tiny 1.2 introduced thevector-effect property.Although SVG Tiny 1.2 introduced only non-scaling stroke behavior, this versionintroduces a number of additional effects. Furthermore, since these effectscan be specified in combination, they show more various effects. And, futureversions of the SVG language will allow for more powerful vector effectsthrough this property.

Values ofvector-effect other thannon-scaling-stroke andnone are at risk of being dropped from SVG 2 due to a lack of implementations. Feedback from implementers is requested, regarding the practicality of implementing them as currently specified, during the implementation period.

Name:vector-effect
Value:none | [ non-scaling-stroke | non-scaling-size | non-rotation | fixed-position ]+ [ viewport | screen ]?
Initial:none
Applies to:graphics elements anduse
Inherited:no
Percentages:N/A
Media:visual
Computed value:as specified
Animatable:yes
none
Specifies that no vector effect shall be applied, i.e. the default rendering behaviour from SVG 1.1 is used which is to first fill the geometry of a shape with a specified paint, then stroke the outline with a specified paint.
non-scaling-stroke
Please refer tothis description of vector effect on painting.
non-scaling-size
Specifies specialuser coordinate system toward this element and its descendant by constrained transformations with the following characteristics. The scale of theuser coordinate system do not change in spite of change ofCTMs from a host coordinate space. However, it does not specify the suppression of rotation and skew. Also, it does not specify the fixation of placement ofuser coordinate system. Since non-scaling-size suppresses scaling ofuser coordinate system, it also has the characteristic of non-scaling-stroke. The transformation formula and the example behavior are indicated to the following chapter.
non-rotation
Specifies specialuser coordinate system toward this element and its descendant by constrained transformations with the following characteristics. The rotation and skew of theuser coordinate system is suppressd in spite of change ofCTMs from a host coordinate space. However, it does not specify the suppression of scaling. Also, it does not specify the fixation of placement ofuser coordinate system. The transformation formula and the example behavior are indicated to the following chapter.
fixed-position
Specifies specialuser coordinate system toward this element and its descendant by constrained transformations with the following characteristics. The placement ofuser coordinate system is fixed in spite of change ofCTMs from a host coordinate space. However, it does not specify the suppression of rotation, skew and scaling. When the element that has fixed-position effect and also hastransform property, that property is consumed for this effect. The shift componentse andf of matrix oftransform property are used to transfer the origin of fixeduser coordinate system. The transformation formula and the example behavior are indicated to the following chapter.

These values can be enumerated. Thereby, the effect which has thesecharacteristics simultaneously can be specified.

The following two values assists the above-mentioned values. They show thehost coordinate space of constrained transformations. Especially it haseffective for the element belonging to nested viewport coordinate system suchas nested contents or nestedsvg elements. An initial value in caseit is not specified isviewport.

viewport
Specifies immediateviewport coordinate system as the host coordinate space. When that element belongs to nestedviewport coordinate system, vector effects are applied towardviewport coordinate system to which that element belongs directly. That is, that vector effect is not effective for change ofCTM on ancestralviewport coordinate system.
screen
It specifies the coordinate system of content which under the immediate control ofuser agent. So to speak, it is "scrren" whichuser agent has. ("screen coordinate space" in SVGT1.2) Even if that element belongs to nested viewport coordinate system, that vector effect is always effective for change ofCTM of the any hierarchy. If the SVG implementation is part of auser agent which supports CSS compatible px units, it is a coordinate system on CSS pixel of rootmost content. Generally, the pixel (or dot) of a device and pixel of CSS are not always equal by influences of the zoom function whichuser agent itself has, and variation of dpi. (seeresolution [CSS Values and Units Module Level 3]) Accordingly, this value does not specify constrained transformations toward the such a device coordinate system.

Note: Future versions of SVG may allow ways to specify the device coordinate system.

8.13.1. Computing the vector effects

This section shows the list of transformation formulas regardingcombinations of the values for clarification of the behavior of vector effectsexcludingnon-scaling-stroke which has clearimplications.

Thevector-effect property has no effect on transformationsperformed in a3d rendering context.

The normal coordinate transformation formula fromuser coordinate systemtoviewport coordinate system is as follows.

xviewportyviewport1=CTMxuserspaceyuserspace1CTM=actmcctmectmbctmdctmfctm001
<circle vector-effect="veValue" transform="translate(xoyo)" cx="xf" cy="yf" r=".."/>

When thevector-effect is added to an element like the above, thetransformation formula for user coordinate to the device coordinate changes asfollows. Here,xf andyf are usercoordinate of the corresponding element and its descendant. And,xo andyo are matrix elemente andf of the transform attribute which thecorresponding element has. In addition,|det(CTM)| is absolute value ofthe determinants ofCTM. When this value becomes 0 andnon-scaling-size is appointed,vector-effect becomes invalidity namelynone.

detCTM=actmdctm-bctmcctm
veValueFormula
non-scaling-size
xviewportyviewport1=CTM001+CTMdetCTM100010000xfyf1
non-rotation
xviewportyviewport1=CTM001+detCTM100010000xfyf1
non-scaling-sizenon-rotation
xviewportyviewport1=CTM001+100010000xfyf1
fixed-position
xviewportyviewport1=xoyo1+CTM100010000xfyf1
fixed-positionnon-scaling-size
xviewportyviewport1=xoyo1+CTMdetCTM100010000xfyf1
fixed-positionnon-rotation
xviewportyviewport1=xoyo1+detCTM100010000xfyf1
fixed-positionnon-scaling-sizenon-rotation
xviewportyviewport1=xoyo1+100010000xfyf1

8.13.2. Computing the vector effects for nested viewport coordinate systems

Below is normal coordinate transformation formula for nested viewportcoordinate systems without vector effects.xviewport(UA) andyviewport(UA) are coordinates which under the immediatecontrol ofuser agent.CTMthis isCTM for thetransformation matrix fromuser coordinate system of an target graphictoviewport coordinate system to which it belongs.CTMparent isCTM for the transformation matrix fromaforementionedviewport coordinate system toviewport coordinate systemof the parent of that. And,CTMroot isCTM forrootmost viewport coordinate system (UA).

xviewport(UA)yviewport(UA)1=CTMroot...CTMparentCTMthisxuserspaceyuserspace1

When applying seven formulas of the preceding section to nested viewportcoordinate systems, the application way of those formulas changes as followsby whetherviewport orscreen is specified as the additional value ofvector-effect.

Whenviewport value is specified,user agent computes coordinates combining either of seven formulas ofthe preceding chapter, and the following formulas.

xviewport(UA)yviewport(UA)1=CTMroot...CTMparentxviewportyviewport1CTM=CTMthis

Whenscreen value is specified,user agent computes coordinates combining either of seven formulas ofthe preceding chapter, and the following formulas.

xviewport(UA)yviewport(UA)1=xviewportyviewport1CTM=CTMroot...CTMparentCTMthis

8.13.3. Examples of vector effects

Below is an example of thenon-scaling-strokevector-effect.

<?xml version="1.0"?><svg xmlns="http://www.w3.org/2000/svg"     width="6cm" height="4cm" viewBox="0 0 600 400"     viewport-fill="rgb(255,150,200)">  <desc>Example non-scaling stroke</desc>  <rect x="1" y="1" width="598" height="398" fill="none" stroke="black"/>  <g transform="scale(9,1)">    <line stroke="black" stroke-width="5" x1="10" y1="50" x2="10" y2="350"/>    <line vector-effect="non-scaling-stroke" stroke="black" stroke-width="5"        x1="32" y1="50" x2="32" y2="350"/>    <line vector-effect="none" stroke="black" stroke-width="5"        x1="55" y1="50" x2="55" y2="350"/>  </g></svg>

Below is an example of thenonevector-effect (no vector effect).

Before changing CTMAfter changing CTM
Image showing none vector effectImage showing none vector effect

Source code

<svg xmlns="http://www.w3.org/2000/svg" viewBox="-50,-50,500,500" height="500" width="500">  <rect x="-50" y="-50" width="500" height="500" stroke="orange" stroke-width="3" fill="none"/>  <!-- Nested user coordinate system is transformed by this transform attribute -->  <g transform="matrix(2.1169438081370817,0.3576047954311102,-0.3576047954311102,1.4700998667618626,0,0)                translate(-50,-50)">    <svg viewBox="-50,-50,500,500" height="500" width="500">      <!-- Graph paper on the this svg's base user coordinate system -->      <g stroke="green" stroke-width="1" fill="none">        <circle cx="0" cy="0" r="10"/>        <circle cx="150" cy="150" r="7"/>        <path fill="green" stroke="none" d="M0,-3 L30,-3 25,-10 50,0 25,10 30,3 0,3z"/>        <line x1="-100" y1="-100" x2="600" y2="-100" stroke-dasharray="5,5"/>        <line x1="-100" y1="000" x2="600" y2="000"/>        <line x1="-100" y1="100" x2="600" y2="100" stroke-dasharray="5,5"/>        <line x1="-100" y1="200" x2="600" y2="200" stroke-dasharray="5,5"/>        <line x1="-100" y1="300" x2="600" y2="300" stroke-dasharray="5,5"/>        <line x1="-100" y1="400" x2="600" y2="400" stroke-dasharray="5,5"/>        <line x1="-100" y1="500" x2="600" y2="500" stroke-dasharray="5,5"/>        <line y1="-100" x1="-100" y2="600" x2="-100" stroke-dasharray="5,5"/>        <line y1="-100" x1="000" y2="600" x2="000"/>        <line y1="-100" x1="100" y2="600" x2="100" stroke-dasharray="5,5"/>        <line y1="-100" x1="200" y2="600" x2="200" stroke-dasharray="5,5"/>        <line y1="-100" x1="300" y2="600" x2="300" stroke-dasharray="5,5"/>        <line y1="-100" x1="400" y2="600" x2="400" stroke-dasharray="5,5"/>        <line y1="-100" x1="500" y2="600" x2="500" stroke-dasharray="5,5"/>      </g>      <!-- Figure having vector effect -->      <!-- A thick red right arrow and small rectangle on this figure's nested           user coordinate system origin -->      <path vector-effect="none"            stroke="red" stroke-width="3" fill="none"            transform="matrix(1,0,0,1,150,150)"            d="M-50,-50 L50,-50 50,-100 150,0 50,100 50,50 -50,50 -50,-50z M5 0 L0 -5 -5 0 0 5z"/>    </svg>  </g></svg>

Below is an example of thenon-scaling-size.

Before changing CTMAfter changing CTM
Image showing appearance before the effect of the vector effect showing upImage showing non-scaling-size vector effect
<path vector-effect="non-scaling-size"      stroke="red" stroke-width="3" fill="none"      transform="matrix(1,0,0,1,150,150)"      d="M-50,-50 L50,-50 50,-100 150,0 50,100 50,50 -50,50 -50,-50z M5 0 L0 -5 -5 0 0 5z"/>

Below is an example of thenon-rotation.

Before changing CTMAfter changing CTM
Image showing appearance before the effect of the vector effect showing upImage showing non-rotation vector effect
<path vector-effect="non-rotation"      stroke="red" stroke-width="3" fill="none"      transform="matrix(1,0,0,1,150,150)"      d="M-50,-50 L50,-50 50,-100 150,0 50,100 50,50 -50,50 -50,-50z M5 0 L0 -5 -5 0 0 5z"/>

Below is an example of thenon-scaling-sizenon-rotation.

Before changing CTMAfter changing CTM
Image showing appearance before the effect of the vector effect showing upImage showing non-scaling-size non-rotation vector effect
<path vector-effect="non-scaling-size non-rotation"      stroke="red" stroke-width="3" fill="none"      transform="matrix(1,0,0,1,150,150)"      d="M-50,-50 L50,-50 50,-100 150,0 50,100 50,50 -50,50 -50,-50z M5 0 L0 -5 -5 0 0 5z"/>

Below is an example of thefixed-position.

Before changing CTMAfter changing CTM
Image showing appearance before the effect of the vector effect showing upImage showing fixed-position vector effect
<path vector-effect="fixed-position"      stroke="red" stroke-width="3" fill="none"      transform="matrix(1,0,0,1,150,150)"      d="M-50,-50 L50,-50 50,-100 150,0 50,100 50,50 -50,50 -50,-50z M5 0 L0 -5 -5 0 0 5z"/>

Below is an example of thenon-scaling-sizefixed-position.

Before changing CTMAfter changing CTM
Image showing appearance before the effect of the vector effect showing upImage showing non-scaling-size fixed-position vector effect
<path vector-effect="non-scaling-size fixed-position"      stroke="red" stroke-width="3" fill="none"      transform="matrix(1,0,0,1,150,150)"      d="M-50,-50 L50,-50 50,-100 150,0 50,100 50,50 -50,50 -50,-50z M5 0 L0 -5 -5 0 0 5z"/>

Below is an example of thenon-rotationfixed-position.

Before changing CTMAfter changing CTM
Image showing appearance before the effect of the vector effect showing upImage showing non-rotation fixed-position vector effect
<path vector-effect="non-rotation fixed-position"      stroke="red" stroke-width="3" fill="none"      transform="matrix(1,0,0,1,150,150)"      d="M-50,-50 L50,-50 50,-100 150,0 50,100 50,50 -50,50 -50,-50z M5 0 L0 -5 -5 0 0 5z"/>

Below is an example of thenon-scaling-sizenon-rotationfixed-position.

Before changing CTMAfter changing CTM
Image showing appearance before the effect of the vector effect showing upImage showing non-scaling-size non-rotation fixed-position vector effect
<path vector-effect="non-scaling-size non-rotation fixed-position"      stroke="red" stroke-width="3" fill="none"      transform="matrix(1,0,0,1,150,150)"      d="M-50,-50 L50,-50 50,-100 150,0 50,100 50,50 -50,50 -50,-50z M5 0 L0 -5 -5 0 0 5z"/>

8.14. DOM interfaces

8.14.1. Interface SVGTransform

TheSVGTransform interface is used to represent<transform-function>values that appear in thetransform propertyand its presentation attributes‘transform’,gradientTransform andpatternTransform. AnSVGTransformrepresents a single component in a transform list,such as a singlescale(…)ormatrix(…) value.

AnSVGTransform object can be designated asread only,which means that attempts to modify the object will result in an exceptionbeing thrown, as described below.

AnSVGTransform object can beassociatedwith a particular element. The associated element is used todetermine which element's‘transform’presentation attribute to update if the objectreflectsthat attribute. Unless otherwise described, anSVGTransform object isnot associated with any element.

EverySVGTransform object operates in one oftwo modes. It can:

  1. reflect an element of a presentation attribute value (being exposed through the methods on thebaseVal member of anSVGAnimatedTransformList),
  2. be detached, which is the case forSVGTransform objects created withcreateSVGTransform andcreateSVGTransformFromMatrix.

AnSVGTransform object maintains an internal<transform-function>value, which is called itsvalue.It also maintains aDOMMatrix object,which is called itsmatrix object,which is the object returned from thematrixIDL attribute. AnSVGTransform object'smatrix objectis always kept synchronized with itsvalue.

[Exposed=Window]interfaceSVGTransform {  // Transform Types  const unsigned shortSVG_TRANSFORM_UNKNOWN = 0;  const unsigned shortSVG_TRANSFORM_MATRIX = 1;  const unsigned shortSVG_TRANSFORM_TRANSLATE = 2;  const unsigned shortSVG_TRANSFORM_SCALE = 3;  const unsigned shortSVG_TRANSFORM_ROTATE = 4;  const unsigned shortSVG_TRANSFORM_SKEWX = 5;  const unsigned shortSVG_TRANSFORM_SKEWY = 6;  readonly attribute unsigned shorttype;  [SameObject] readonly attributeDOMMatrixmatrix;  readonly attribute floatangle;  voidsetMatrix(DOMMatrixReadOnly matrix);  voidsetTranslate(float tx, float ty);  voidsetScale(float sx, float sy);  voidsetRotate(float angle, float cx, float cy);  voidsetSkewX(float angle);  voidsetSkewY(float angle);};

The numeric transform type constants defined onSVGTransform are usedto represent the type of anSVGTransform'svalue.Their meanings are as follows:

ConstantMeaning
SVG_TRANSFORM_MATRIXAmatrix(…) value.
SVG_TRANSFORM_TRANSLATEAtranslate(…) value.
SVG_TRANSFORM_SCALEAscale(…) value.
SVG_TRANSFORM_ROTATEArotate(…) value.
SVG_TRANSFORM_SKEWXAskewX(…) value.
SVG_TRANSFORM_SKEWYAskewY(…) value.
SVG_TRANSFORM_UNKNOWNSome other type of value.

The use of numeric transform type constants is an anti-pattern andnew constant values will not be introduced for any transform types supported bySVGTransform. If other types of transforms are supported and used, theSVGTransformuses theSVG_TRANSFORM_UNKNOWNtype. See below for details on how the other properties of anSVGTransformoperate with these types of transforms.

Thetype IDL attribute representsthe type of transform item that theSVGTransform'svalue is.On gettingtype, the following stepsare run:

  1. If theSVGTransform'svalue is amatrix(…),translate(…),scale(…),rotate(…),skewX(…) orskewY(…) function, then return the corresponding constant value from the transform type table above.
  2. Otherwise, returnSVG_TRANSFORM_UNKNOWN.

    For example, for ascaleX(…) ortranslate3d(…) transform,SVG_TRANSFORM_UNKNOWN would be returned.

Thematrix IDL attributerepresents the transform as a 4x4 homogeneous matrix, and on gettingreturns theSVGTransform'smatrix object.When thematrix object is first created, itsvalues are set to match theSVGTransform's transformfunctionvalue, and is set toreflects the SVGTransform.

See theCSS Transformsspecification for a description of how the different transform function typescorrespond to particular matrix values.

Theangle IDL attributerepresents the angle parameter of arotate(…),skewX(…) orskewY(…) transform function.On getting, the following steps are run:

  1. If theSVGTransform object'svalue is arotate(…),skewX(…) orskewY(…) function, return its angle argument in degrees.
  2. Otherwise, return 0.

ThesetMatrix method is usedto set theSVGTransform to a given matrix value. WhensetMatrix(matrix) is called, the following steps are run:

  1. If theSVGTransform object isread only, thenthrow aNoModificationAllowedError.
  2. Ifmatrix would return true from itsis2d method, then set theSVGTransform object'svalue to amatrix(…) value that represents the same matrix asmatrix.
  3. Otherwise, set theSVGTransform object'svalue to amatrix3d(…) value that represents the same matrix asmatrix.
  4. Copy the matrix component values frommatrix into theSVGTransform object'smatrix object.
  5. If theSVGTransform objectreflects an element of a presentation attribute value, thenreserialize the reflected attribute.

ThesetTranslate,setScale,setRotate,setSkewX andsetSkewY methods are usedto set theSVGTransform to a new transform functionvalue. When one of these methods is called,the following steps are run:

  1. If theSVGTransform object isread only, thenthrow aNoModificationAllowedError.
  2. Set theSVGTransform object'svalue to a new transform function value, depending on which method was called:
    setTranslate(tx,ty)
    the new transform function value istranslate(tx,ty)
    setScale(sx,sy)
    the new transform function value isscale(sx,sy)
    setRotate(angle,cx,cy)
    the new transform function value isrotate(angle,cx,cy)
    setSkewX(angle)
    the new transform function value isskewX(angle)
    setSkewY(angle)
    the new transform function value isskewY(angle)
  3. Set the components of theSVGTransform object'smatrix object to match the new transform functionvalue.
  4. If theSVGTransform objectreflects an element of a presentation attribute value, thenreserialize the reflected attribute.

This specification imposes additional requirements on the behavior ofDOMMatrixobjects beyond those described in theGeometry Interfacesspecification, so that they can be used to reflect presentation attributesthat take transform values.

EveryDOMMatrix object operates in one of two modes.It can:

  1. reflect anSVGTransform (being exposed through thematrix IDL attribute on anSVGTransform), or
  2. be detached, which is the case forDOMMatrix objects created using their constructor or withcreateSVGMatrix.

ADOMMatrix can be designated asread only,which means that attempts to modify the object will result in an exceptionbeing thrown. When assigning to any of a read onlyDOMMatrix'sIDL attributes, or when invoking any of its mutable transform methods,aNoModificationAllowedError exception will bethrowninstead of updating the internal value.

Note that this applies only to the read-writeDOMMatrixinterface; theDOMMatrixReadOnly interface, which is not used for reflectingtransform, will already throw an exception if an attempt is made to modify it.

When assigning to any of a writableDOMMatrix'sIDL attributes, or when invoking any of its mutable transform methods,the following steps are run after updating the internal matrix value:

  1. If theDOMMatrixreflects an SVGTransform, then:
    1. If theDOMMatrix would return true from itsis2d method, then set theSVGTransform object'svalue to amatrix(…) value that represents the same matrix as theDOMMatrix.
    2. Otherwise, set theSVGTransform object'svalue to amatrix3d(…) value that represents the same matrix as theDOMMatrix.
    3. If theSVGTransform objectreflects an element of a presentation attribute value, thenreserialize the reflected attribute.

8.14.2. Interface SVGTransformList

TheSVGTransformList interface is alist interfacewhose elements areSVGTransform objects. AnSVGTransformListrepresents a value that thetransform property can take, namelyeither a<transform-list>or the keywordnone.

[Exposed=Window]interfaceSVGTransformList {  readonly attribute unsigned longlength;  readonly attribute unsigned longnumberOfItems;  voidclear();SVGTransforminitialize(SVGTransform newItem);  getterSVGTransformgetItem(unsigned long index);SVGTransforminsertItemBefore(SVGTransform newItem, unsigned long index);SVGTransformreplaceItem(SVGTransform newItem, unsigned long index);SVGTransformremoveItem(unsigned long index);SVGTransformappendItem(SVGTransform newItem);setter void (unsigned long index,SVGTransform newItem);// Additional methods not common to other list interfaces.SVGTransformcreateSVGTransformFromMatrix(DOMMatrixReadOnly matrix);SVGTransform?consolidate();};

ThecreateSVGTransformFromMatrixmethod is used to create a newSVGTransform object from a matrix object.When the createSVGTransformFromMatrix(matrix) method is called,the following steps are run:

  1. Lettransform be a newly createdSVGTransform object that isdetached.
  2. Follow the steps that would be run if thesetMatrix method ontransform were called, passingmatrix as its argument.
  3. Returntransform.

Theconsolidatemethod is used to convert the transform list into an equivalenttransformation using a single transform function. When theconsolidate() method is called, the following steps are run:

  1. If theSVGTransformList object isread only, thenthrow aNoModificationAllowedError.
  2. If the list is empty, return null.
  3. Detach and then remove all elements in the list.
  4. Lettransform be a newly createdSVGTransform object.
  5. Letmatrix be the matrix value obtained by beginning with an identity matrix, and then post-multiplying the value of thematrix object for eachSVGTransform in the list, in order.
  6. Set the components oftransform'smatrix object to the component values inmatrix.
  7. Iftransform'smatrix object would return true from itsis2d method, then settransform'svalue to amatrix(…) value that represents the same matrix as thematrix object.
  8. Otherwise, settransform'svalue to amatrix3d(…) value that represents the same matrix as thematrix object.
  9. Attachtransform to thisSVGTransformList.
  10. Appendtransform to this list.
  11. If the listreflects a presentation attribute, thenreserialize the reflected attribute.
  12. Returntransform.

The behavior of all other interface members ofSVGLengthList aredefined inList interfaces.

8.14.3. Interface SVGAnimatedTransformList

AnSVGAnimatedTransformList object is used toreflect thetransform property and its corresponding presentation attribute(which, depending on the element, is‘transform’,gradientTransform orpatternTransform).

[Exposed=Window]interfaceSVGAnimatedTransformList {  [SameObject] readonly attributeSVGTransformListbaseVal;  [SameObject] readonly attributeSVGTransformListanimVal;};

ThebaseVal andanimVal IDL attributesrepresent the value of the reflected presentation attribute.On gettingbaseVal oranimVal, anSVGTransformList object is returned that reflects the givenpresentation attribute.

8.14.4. Interface SVGPreserveAspectRatio

TheSVGPreserveAspectRatio interface is used to representvalues for thepreserveAspectRatio attribute.

AnSVGPreserveAspectRatio object can be designated asread only,which means that attempts to modify the object will result in an exceptionbeing thrown, as described below.

EverySVGPreserveAspectRatio objectreflects the base value of areflectedpreserveAspectRatioattribute (being exposed through the methods on thebaseVal oranimVal member ofanSVGAnimatedPreserveAspectRatio).

[Exposed=Window]interfaceSVGPreserveAspectRatio {  // Alignment Types  const unsigned shortSVG_PRESERVEASPECTRATIO_UNKNOWN = 0;  const unsigned shortSVG_PRESERVEASPECTRATIO_NONE = 1;  const unsigned shortSVG_PRESERVEASPECTRATIO_XMINYMIN = 2;  const unsigned shortSVG_PRESERVEASPECTRATIO_XMIDYMIN = 3;  const unsigned shortSVG_PRESERVEASPECTRATIO_XMAXYMIN = 4;  const unsigned shortSVG_PRESERVEASPECTRATIO_XMINYMID = 5;  const unsigned shortSVG_PRESERVEASPECTRATIO_XMIDYMID = 6;  const unsigned shortSVG_PRESERVEASPECTRATIO_XMAXYMID = 7;  const unsigned shortSVG_PRESERVEASPECTRATIO_XMINYMAX = 8;  const unsigned shortSVG_PRESERVEASPECTRATIO_XMIDYMAX = 9;  const unsigned shortSVG_PRESERVEASPECTRATIO_XMAXYMAX = 10;  // Meet-or-slice Types  const unsigned shortSVG_MEETORSLICE_UNKNOWN = 0;  const unsigned shortSVG_MEETORSLICE_MEET = 1;  const unsigned shortSVG_MEETORSLICE_SLICE = 2;  attribute unsigned shortalign;  attribute unsigned shortmeetOrSlice;};

The numeric alignment type constants defined onSVGPreserveAspectRatioare used to represent the alignment keyword values thatpreserveAspectRatiocan take. Their meanings are as follows:

ConstantMeaning
SVG_PRESERVEASPECTRATIO_NONEThenone keyword.
SVG_PRESERVEASPECTRATIO_XMINYMINThexMinYMin keyword.
SVG_PRESERVEASPECTRATIO_XMIDYMINThexMidYMin keyword.
SVG_PRESERVEASPECTRATIO_XMAXYMINThexMaxYMin keyword.
SVG_PRESERVEASPECTRATIO_XMINYMIDThexMinYMid keyword.
SVG_PRESERVEASPECTRATIO_XMIDYMIDThexMidYMid keyword.
SVG_PRESERVEASPECTRATIO_XMAXYMIDThexMaxYMid keyword.
SVG_PRESERVEASPECTRATIO_XMINYMAXThexMinYMax keyword.
SVG_PRESERVEASPECTRATIO_XMIDYMAXThexMidYMax keyword.
SVG_PRESERVEASPECTRATIO_XMAXYMAXThexMaxYMax keyword.
SVG_PRESERVEASPECTRATIO_UNKNOWNSome other type of value.

Similarly, the numeric meet-or-slice type constants defined onSVGPreserveAspectRatio are used to represent the meet-or-slicekeyword values thatpreserveAspectRatio can take. Theirmeanings are as follows:

ConstantMeaning
SVG_MEETORSLICE_MEETThemeet keyword.
SVG_MEETORSLICE_SLICETheslice keyword.
SVG_MEETORSLICE_UNKNOWNSome other type of value.

Thealign IDL attributerepresents the alignment keyword part of thepreserveAspectRatiovalue. On getting, the following steps are run:

  1. Letvaluereflect the base value of apreserveAspectRatio attribute.value is the current non-animated value of the attribute (using the attribute'sinitial value if it is not present or invalid).
  2. Return the constant value as specified in the alignment constant table above for the alignment keyword invalue.

On settingalign, thefollowing steps are run:

  1. If theSVGPreserveAspectRatio isread only, thenthrow aNoModificationAllowedError.
  2. Ifvalue isSVG_PRESERVEASPECTRATIO_UNKNOWN or does not have a corresponding entry in the alignment keyword table above, then return.
  3. Letstring be the corresponding keyword in the alignment keyword table above forvalue.
  4. Append a single U+0020 SPACE character tostring.
  5. Letmeet or slice be the value that would be returned from themeetOrSlice member on thisSVGPreserveAspectRatio.
  6. Append tostring the corresponding keyword in the meet-or-slice keyword table above formeet or slice.
  7. Set the reflectedpreserveAspectRatio attribute tostring.

ThemeetOrSlice IDL attributerepresents the alignment keyword part of thepreserveAspectRatiovalue. On getting, the following steps are run:

  1. Letvalue be apreserveAspectRatio value thatreflects the base value of apreserveAspectRatio attributevalue is the current non-animated value of the attribute.
  2. If the meet-or-slice value is not present invalue, then returnSVG_MEETORSLICE_MEET.
  3. Otherwise, the meet-or-slice value is present. Return the constant value as specified in the meet-or-slice constant table above for the meet-or-slice keyword invalue.

On settingmeetOrSlice, thefollowing steps are run:

  1. If theSVGPreserveAspectRatio isread only, thenthrow aNoModificationAllowedError.
  2. Ifvalue isSVG_MEETORSLICE_UNKNOWN or does not have a corresponding entry in the meet-or-slice keyword table above, then return.
  3. Letalign be the value that would be returned from thealign member on thisSVGPreserveAspectRatio.
  4. Letstring be the corresponding keyword in the alignment keyword table above foralign.
  5. Append a single U+0020 SPACE character tostring.
  6. Append tostring the corresponding keyword in the meet-or-slice keyword table above forvalue.
  7. Set the reflectedpreserveAspectRatio attribute tostring.

8.14.5. Interface SVGAnimatedPreserveAspectRatio

AnSVGAnimatedPreserveAspectRatio object is used toreflectthepreserveAspectRatio attribute.

[Exposed=Window]interfaceSVGAnimatedPreserveAspectRatio {  [SameObject] readonly attributeSVGPreserveAspectRatiobaseVal;  [SameObject] readonly attributeSVGPreserveAspectRatioanimVal;};

ThebaseVal andanimVal IDLattributes represent the current non-animated value of the reflectedpreserveAspectRatioattribute. On gettingbaseValoranimVal,anSVGPreserveAspectRatio object is returned thatreflects the base value of thepreserveAspectRatioattribute on the SVG element that the object with the reflcting IDL attributeof typeSVGAnimatedPreserveAspectRatio was obtained from.


[8]ページ先頭

©2009-2025 Movatter.jp