Movatterモバイル変換


[0]ホーム

URL:


Chapter 3: Rendering Model

The SVG 2 rendering model will follow the rules defined by theCompositing and Blending specification.

Resolution:Seattle/Paris 2012 F2F day 3.

Owner: Nikos (Action 3332).

Status: Done.

3.1. Introduction

Implementations of SVG must implement the rendering model as described in thischapter, as modified in the appendix onconformancerequirementswhich describessituations where an implementation may deviate.In practice variability is allowed based on limitations of the output device(e.g. only a limited range of colors might be supported) and because of practicallimitations in implementing a precise mathematical model (e.g. for realisticperformance curves are approximated by straight lines, the approximation needonly be sufficiently precise to match the conformance requirements).

The appendix onconformancerequirements describes the extent to which an actualimplementation may deviate from this description. In practicean actual implementationmaydeviate slightly because oflimitations of the output device (e.g. only a limited range ofcolors might be supported) and because of practical limitationsin implementing a precise mathematical model (e.g. forrealistic performance curves are approximated by straightlines, the approximation need only be sufficiently precise tomatch the conformance requirements).

3.2. The rendering tree

The components of the final rendered representation of an SVG document do not have a one-to-one relationship with the underlying elements in the document model. The appearance of the graphic instead reflects a parallel structure, the rendering tree, in which some elements are excluded and others are repeated.

Many elements in the SVG namespace do not directly represent a component of the graphical document. Instead, they define graphical effects, metadata, content to be used to represent other elements, or alternatives to be displayed under certain conditions. In dynamic documents, certain components of the graphic may be rendered or not, depending on interaction or animation. These non-rendered elements are not directly included in therendering tree.

Because SVG supports the reuse of graphical sub-components, some elements are rendered multiple times. The individual renderings may have context-dependent styling and may be rasterized at different scales or transformations.

3.2.1. Definitions

rendering tree

The rendering tree is the set of elements being rendered in anSVG document fragment. It is generated from the document tree by excludingnon-rendered elements and inserting additional fragments forre-used graphics. Graphics are painted and composited in rendering-tree order, subject to re-ordering based on thepaint-order property. Note that elements that have no visual paint may still be in the rendering tree.

rendered element

An element that has a direct representation in therendering tree for the current document. Includes a renderedinstance of an element in ause-element shadow tree. Does not include elements that affect rendering as the source definition of re-used graphics but are not directly rendered themselves. SeeRendered versus non-rendered elements

non-rendered element

An element that does not have a direct representation in therendering tree for the current document. It may nonetheless affect the rendering tree as re-used graphics or graphical effects. SeeRendered versus non-rendered elements.

re-used graphics

Graphical components that are included in the rendering tree but do not have a single direct equivalent element in the document model. They may be represented through shadow DOM elements (as in graphics re-used with ause element), or as image fragments generated as part of a graphical effect (as in patterns or masks).

never-rendered element

Any element type that isnever directly rendered, regardless of context ordisplay style value. It includes the following elements:clipPath,defs,desc,linearGradient,marker,mask,metadata,pattern,radialGradient,script,style andtitle; it also includes asymbol element that is not theinstance root of ause-element shadow tree.

renderable element

Any element type thatcan have a direct representation in therendering tree, as a graphic, container, text, audio, or animation. It includes the following elements:a,audio,canvas,circle,ellipse,foreignObject,g,iframe,image,line,path,polygon,polyline,rect,svg,switch,text,textPath,tspan,unknown,use andvideo; it also includes asymbol element thatis theinstance root of ause-element shadow tree.

A renderable element may or may not be rendered in a given document or point in time.

3.2.2. Rendered versus non-rendered elements

At any given time, every SVG element (orelement instance in ause-element shadow tree) is either rendered or non-rendered. Whether an element is currently rendered or not affects not only its visual display but also interactivity and geometric calculations.

An element isnot rendered in any of these four situations:

Non-rendered elements:

Non-rendered elements are not represented in the document accessibility tree. Nonetheless, they remain part of the document model, and participate instyle inheritance and cascade.

3.2.3. Controlling visibility: the effect of the ‘display’ and ‘visibility’properties

SVG uses two properties to toggle the visible display of elements that are normally rendered:display andvisibility. Although they have a similar visible effect in static documents, they are conceptually distinct.

See the CSS 2.1 specification for the definitionsofdisplay andvisibility.[CSS2]

Settingdisplay tonone results in the element not being rendered. When applied tographics elements,text content elements, andcontainer elements that are normally rendered, settingdisplay tonone results in the element (and all its descendents) not becoming part of therendering tree. Note thatdisplay is not an inherited property.

Elements that have any otherdisplay value thannone are rendered as normal.

Thedisplay property only applies torenderable elements. Settingdisplay: none on an element that isnever directly rendered ornot rendered based on conditional processing has no effect.

Thedisplay property affects the direct processing of a given element, but it does not prevent it from being referenced by other elements. For example, settingdisplay: none on apath element will prevent that element from getting rendered directly onto the canvas, but thepath element can still be referenced by atextPath element and its geometry will be used in text-on-a-path processing.

When applied to agraphics element oruse element, settingvisibility tohidden orcollapse results in the element not being painted. It is, however, still part of therendering tree. It may be sensitive to pointer events (depending on the value ofpointer-events), may receive focus (depending on the value oftabindex), contributes to bounding box calculations and clipping paths, and does affect text layout.

Thevisibility property only directly affects the rendering ofgraphics elements,text content elements, and thea element when it is a child oftext content element. Sincevisibility is an inherited property, however, although it has no effect on ause element orcontainer element itself, its inherited value can affect descendant elements.

3.2.4. Re-used graphics

Graphical content defined in one part of the document (or in another document) may be used to render other elements. There are two types of re-used graphics from a rendering perspective:

Shadow DOM elements are rendered in the same way as normal elements, as if the host element (e.g., theuse element) was a container and the shadow content was its descendents. Style and geometry properties on the shadow DOM elements are resolved independently from those on theircorresponding element in the source document. Thedisplay property has its normal effect on shadow elements, except for special rules that apply to thesymbol element.

For blending purposes, theuse element forms anon-isolated group.

In contrast, graphical effects elements generate a self-contained SVG fragment which is rendered independently as astacking context and anisolated group. The canvas for this fragment is scaled The graphical effect element's child content is rendered and composited into this canvas. The flattened canvas as a whole is treated as a vector image when compositing and blending with other paint layers

Thedisplay property on any child content of a graphical effects element has its normal effect when set tonone, excluding that subtree from being used in rendering. However, the graphical effect is not altered by a value ofdisplay: none on the graphical effect element or an ancestor.

3.3. The painters model

SVG uses a "painters model" of rendering.Paintis applied in successive operations to the output device suchthat each operation paints onto some area of the output device,possibly obscuring paint that has previously been layed down.After each object or group is painted, it becomes part of the backgroundfor the next painting operation.SVG 2 supports advanced blending modes and compositing operations thatcontrol how each painting operation interacts with the background.The rules governing these painting operations are outlined in theCompositing and Blending Specification.

3.4. Rendering order

Elements in SVG are positioned in three dimensions. In addition to theirposition on the x and y axis of theSVG viewport, SVG elements are alsopositioned on the z axis. The position on the z-axis defines the order thatthey are painted.

Along the z axis, elements are grouped intostacking contexts.

3.4.1. Establishing a stacking context in SVG

A new stacking context must be established at an SVG element for its descendants if:

Stacking contexts are conceptual tools used to describe theorder in which elements must be painted one on top of the other when thedocument is rendered, and for determining which element is highest whendetermining the target of a pointer event. Stacking contexts donot affect the position of elements in the DOM tree, and their presence orabsence does not affect an element's position, size or orientation in thecanvas' X-Y plane - only the order in which it is painted.

Stacking contexts can contain further stacking contexts. A stacking context isatomic from the point of view of its parent stacking context; elements inancestor stacking contexts may not come between any of its elements.

Each element belongs to one stacking context. Elements in a stacking contextmust be stacked according to document order.

With the exception of theforeignObject element, the back to frontstacking order for a stacking context created by an SVG element is:

  1. the background and borders of the element forming the stacking context, if any
  2. descendants, in tree order

Since theforeignObject element creates a "fixed position containing block" inCSS terms, the normative rules for the stacking order of the stacking contextcreated byforeignObject elements are the rules in Appendix E of CSS 2.1.

3.5. How elements are rendered

Individualgraphics elements are treated as if they are anon-isolated group,the components (fill, stroke, etc) that make up a graphic element(SeePainting shapes and text) beingmembers of that group. SeeHow groups are rendered.

3.6. How groups are rendered

Grouping elements, such as theg element (seecontainer elements) create acompositing group.Similarly, ause element creates a compositing group for its shadow content.TheCompositing and Blendingspecification normatively describes how to rendercompositing groups.In SVG, effects may be applied to a group. For example, opacity, filtersor masking. These effects are applied to the rendered result of the groupimmediately before any transforms on the group are applied, which are appliedimmediately before the group is blended and composited with thegroup backdrop. Applying any such effects to a group makes thatgroup isolated.

Thus, rendering acompositing group follows the following steps:
If the group is isolated:

  1. Theinitial backdrop is set to a new buffer initialised withrgba(0,0,0,0)
  2. The contents of the group that aregraphics elements org elements are renderedin order, onto theinitial backdrop
  3. filters and other effects that modify the group canvas are applied

    To provide for high quality rendering, filterprimitives and other bitmap effects must be applied in theoperating coordinate space.

  4. Group transforms are applied
  5. The group canvas is blended and composited with thegroup backdrop
else (the group is not isolated):
  1. Theinitial backdrop is set to thegroup backdrop
  2. The contents of the group that aregraphics elements org elements are renderedin order, onto theinitial backdrop. The group transforms are applied to each elementas they are rendered.

3.6.1. Object and group opacity: theeffect of the ‘opacity’ property

See the CSS Color Module Level 3 for the definitionofopacity. [css-color-3]

Theopacity property specifies how opaque a givengraphical element or container element will be when it ispainted to the canvas. When applied to a container element,this is known asgroup opacity, and when applied toan individual rendering element, it is known asobjectopacity. The principle for these two operations howeveris the same.

There are several other opacity-related properties in SVG:

These four opacity properties are involved in intermediate rendering operations.Object and group opacity however can be thought of as a post-processing operation.Conceptually, the object or group to whichopacity appliesis rendered into an RGBA offscreen image. The offscreen image as whole is then blendedinto the canvas with the specifiedopacity value used uniformlyacross the offscreen image.Thus, the presence ofopacity causes the group to beisolated.

Theopacity property applies to the following SVG elements:svg,g,symbol,marker,a,switch,use,unknown andgraphics elements.

The following example illustrates various usage of theopacityproperty on objects and groups.

<svg xmlns="http://www.w3.org/2000/svg"     width="600" height="175" viewBox="0 0 1200 350">  <!-- Background blue rectangle -->  <rect x="100" y="100" width="1000" height="150" fill="blue"/>  <!-- Red circles going from opaque to nearly transparent -->  <circle cx="200" cy="100" r="50" fill="red" opacity="1"/>  <circle cx="400" cy="100" r="50" fill="red" opacity=".8"/>  <circle cx="600" cy="100" r="50" fill="red" opacity=".6"/>  <circle cx="800" cy="100" r="50" fill="red" opacity=".4"/>  <circle cx="1000" cy="100" r="50" fill="red" opacity=".2"/>  <!-- Opaque group, opaque circles -->  <g opacity="1">    <circle cx="182.5" cy="250" r="50" fill="red" opacity="1"/>    <circle cx="217.5" cy="250" r="50" fill="green" opacity="1"/>  </g>  <!-- Group opacity: .5, opacity circles -->  <g opacity=".5">    <circle cx="382.5" cy="250" r="50" fill="red" opacity="1"/>    <circle cx="417.5" cy="250" r="50" fill="green" opacity="1"/>  </g>  <!-- Opaque group, semi-transparent green over red -->  <g opacity="1">    <circle cx="582.5" cy="250" r="50" fill="red" opacity=".5"/>    <circle cx="617.5" cy="250" r="50" fill="green" opacity=".5"/>  </g>  <!-- Opaque group, semi-transparent red over green -->  <g opacity="1">    <circle cx="817.5" cy="250" r="50" fill="green" opacity=".5"/>    <circle cx="782.5" cy="250" r="50" fill="red" opacity=".5"/>  </g>  <!-- Group opacity .5, semi-transparent green over red -->  <g opacity=".5">    <circle cx="982.5" cy="250" r="50" fill="red" opacity=".5"/>    <circle cx="1017.5" cy="250" r="50" fill="green" opacity=".5"/>  </g></svg>
Image showing different groups of circles blended into the background.

Each group of red and green circles is first renderedto an offscreen image before being blended with the backgroundblue rectangle as a whole, with the givenopacity values.

In the example, the top row of circles have differing opacities,ranging from 1.0 to 0.2. The bottom row illustrates fiveg elements,each of which contains overlapping red and green circles, as follows:

3.7. Types of graphics elements

SVG supports three fundamental types ofgraphics elementsthat can be rendered onto the canvas:

3.7.1. Painting shapes and text

Shapes and text can befilled (i.e., apply paint to theinterior of the shape) andstroked (i.e., apply paintalong the outline of the shape).

For certain types of shapes,markersymbols (which themselves can consist of any combination of shapes,text and images) can be drawn at positions along theshape boundary. Each marker symbolis painted as if its graphical content were expanded into theSVG document tree just after the shape object which is usingthe given marker symbol. The graphical contents of a markersymbol are rendered using the same methods as graphicselements. Marker symbols are not applicable to text.

The order in which fill, stroke and markers are painted is determinedby thepaint-order property. The default is thatfill is painted first, then the stroke, and then themarker symbols. The marker symbols are rendered in order alongthe outline of the shape, from the start of the shape to theend of the shape.

The fill and stroke operations are entirely independent;for instance, each fill or stroke operation has its own opacity setting.

SVG supports numerous built-in types of paint which canbe used in fill and stroke operations. These are described inPaint Servers.

3.7.2. Painting raster images

When a raster image is rendered, the original samples are"resampled" using standard algorithms to produce samples at thepositions required on the output device. Resamplingrequirements are discussed underconformance requirements.

As in HTML [HTML, 10.4.2],all animated images with the same absolute URL and the same imagedata are expected to be rendered synchronised to the same timeline as a group,with the timeline starting at the time of the least recent addition to thegroup.

When a user agent is to restart the animation for an img element showing ananimated image, all animated images with the same absolute URL and the sameimage data in that img element's node document are expected to restart theiranimation from the beginning.

3.8. Filtering painted regions

SVG allows any painting operation to be filtered. (SeeFilter Effects.)

In this case the result must be as though the paintoperations had been applied to an intermediate canvasinitialized to transparent black, of a size determined by therules given inFilter Effects thenfiltered by the processes defined inFilter Effects.

3.9. Clipping and masking

SVG supports the following clipping/masking features:

Both, clipping and masking, are specified in the module CSS Masking[css-masking-1].

3.10. Parent compositing

SVG document fragments can be semi-opaque.

In accordance with theCompositing and Blending specification,thesvg element always creates anisolated group.When an SVG document is a top-level document,meaning it is not embedded in another document,the rootsvg elementis considered to be thepage group and is composited witha backdrop of white with 100% opacity.In all other cases, the SVG document or document fragment is composited into the parentdocument with opacity preserved.

3.11. The effect of the ‘overflow’property

See the Cascading Style Sheets Level 2 Revision 1 (CSS 2.1)Specification [CSS2] for the definition ofoverflow.

A summary of the behavior of theoverflow property in SVG.
elementinitialua stylesheetautovisiblehiddenscroll
document root svgvisiblen/avisible | scrollvisiblehiddenscroll
other svgvisiblehiddenvisible | scrollvisiblehiddenscroll
textvisiblehiddenvisiblevisiblehiddenhidden
patternvisiblehiddenvisiblevisiblehiddenhidden
markervisiblehiddenvisiblevisiblehiddenhidden
symbolvisiblehiddenvisiblevisiblehiddenhidden
imagevisiblehiddenvisiblevisiblehiddenhidden
iframevisiblehiddenvisible | scrollvisiblehiddenscroll
foreignObjectvisiblehiddenvisible | scrollvisiblehiddenscroll

Theoverflow property has the same parameter values and has thesame meaningas defined in CSS 2.1([CSS2], section 11.1.1);however, the following additional points apply:

Although the initial value foroverflow is auto. In the User Agent style sheet,overflow is overriden for thesvg element when it is not the rootelement of a stand-alone document, thepattern element, and themarker element to be hidden by default.

[8]ページ先頭

©2009-2025 Movatter.jp