精图规范1.0----23 扩展性 Extensibility

previous  next   contents   elements   attributes   properties   index  


04 September 2001

23 扩展性 Extensibility



内容 Contents


 

23.1 外部命名空间和私有数据 Foreign namespaces and private data

精图允许在其内容的任何地方包含外部命名空间中的元素。一般来说,精图用户代理将包含文档对象模型中未知的元素,否则将忽略这些未知的元素。(一个值得注意的例外在嵌入外部对象类型中描述.) SVG allows inclusion of elements from foreign namespaces anywherewith the SVG content. In general, the SVG user agent will include the unknownelements in the DOM but will otherwise ignore unknown elements. (The notableexception is described under Embedding ForeignObject Types.)

另外,精图允许在任何精图元素中包含来自外部命名空间的属性。精图用户代理将包含文档对象模型中未知的属性,否则将忽略这些未知的属性。 Additionally, SVG allows inclusion of attributes from foreignnamespaces on any SVG element. The SVG user agent will include unknownattributes in the DOM but with otherwise ignore unknown attributes.

精图包含外部命名空间的这种能力可以用于下列目的:SVG's ability to include foreign namespaces can be used for thefollowing purposes:

  • 保持特定应用的信息,这样创作应用可以在精图内容中保存模型级的数据,以便达到“往返”的目的(即写入,读回一个文件而不丢失高级的信息)。 Application-specific information so that authoring applications can include model-level data in the SVG content to serve their "roundtripping" purposes (i.e., the ability to write, then read a file without loss of higher-level information).
  • 用于扩展的补充数据。例如,假设需要对二维图形在第三维进行拉伸扩展。当使用拉伸扩展时,也许需要一些参数。这些参数可以通过在精图内容中插入来自一个拉伸扩展命名空间中的元素来实现。Supplemental data for extensibility. For example, suppose you have an extrusion extension which takes any 2D graphics and extrudes it in three dimensions. When applying the extrusion extension, you probably will need to set some parameters. The parameters can be included in the SVG content by inserting elements from an extrusion extension namespace.

举例来说,一个商业的图形创作应用也许需要包含一些私有的数据在它所创建的精图文档中,以便可以将数据读回重新恰当地装配图表(在这个例子中为一个饼图):To illustrate, a business graphics authoring application might wantto include some private data within an SVG document so that it could properlyreassemble the chart (a pie chart in this case) upon reading it back in:

 
<?xml version="1.0" standalone="yes"?>
<svg width="4in" height="3in"
     xmlns = 'http://www.w3.org/2000/svg'>
  <defs>
    <myapp:piechart xmlns:myapp="http://example.org/myapp"
                    title="Sales by Region">
      <myapp:pieslice label="Northern Region" value="1.23"/>
      <myapp:pieslice label="Eastern Region" value="2.53"/>
      <myapp:pieslice label="Southern Region" value="3.89"/>
      <myapp:pieslice label="Western Region" value="2.04"/>
      <!-- Other private data goes here -->
    </myapp:piechart>
  </defs>
  <desc>This chart includes private data in another namespace
  </desc>
  <!-- In here would be the actual SVG graphics elements which
       draw the pie chart -->
</svg>



23.2 嵌入外部对象类型 Embedding foreign object types

精图的一种目标是提供一种机制,使得其他XML语言处理器可以对精图的某个区域进行渲染,这些渲染主要针对精图内容树中给定的当前活动点的变换和合成参数。一个这种特别的例子为提供由CSS或XSL格式化的XML内容的框架使得动态回流的文本(针对精图变换和合成)可以插入到某些精图内容的中间。另一个例子是插入一个 MathML 表达式到精图绘画当中。One goal for SVG is toprovide a mechanism by which other XML language processors can render into anarea within an SVG drawing, with those renderings subject to the varioustransformations and compositing parameters that are currently active at a givenpoint within the SVG content tree. One particular example of this is to providea frame for XML content styled with CSS or XSL so that dynamically reflowingtext (subject to SVG transformations and compositing) could be inserted intothe middle of some SVG content. Another example is inserting a MathML expression into an SVG drawing.

外部对象元素'foreignObject' 允许包含外部命名空间,此命名空间中存在通过不同的用户代理绘制的图形内容。所包含的外部图形内容是针对精图的变换与合成的。The 'foreignObject' element allowsfor inclusion of a foreign namespace which has its graphical content drawn by adifferent user agent. The included foreign graphical content is subject to SVGtransformations and compositing.

外部对象元素'foreignObject' 的内容被假定来自一个不同命名空间。任何包含在 'foreignObject' 中的精图元素将不被绘制,除非为具有一个适当的xmlns 属性的(参见 "XML中的命名空间" [XML-NS]) 精图子文档以递归方式被嵌入的这种情况。当一个精图文档片断被嵌入另一个非精图文档片断中,而此非精图文档片断又被嵌入一个精图片断中,就会出现这种情况(例如,一个精图片断包含一个XHTML文档片断,而此文档片断又包含另一精图文档片断)。The contents of 'foreignObject' areassumed to be from a different namespace. Any SVG elements within a 'foreignObject' will not be drawn, except in thesituation where a properly defined SVG subdocument with a proper xmlns (see "Namespaces in XML" [XML-NS]) attribute specificationis embedded recursively. One situation where this can occur is when an SVGdocument fragment is embedded within another non-SVG document fragment, whichin turn is embedded within an SVG document fragment (e.g., an SVG documentfragment contains an XHTML document fragment which in turn contains yet anotherSVG document fragment).

通常,一个 'foreignObject' 元素将被用来与 'switch' 元素进行协作,而requiredExtensions 属性用于提供对用户代理的支持进行适当的检查并且在用户代理不提供支持的情况下提供一种替换的渲染方式。Usually, a 'foreignObject' will beused in conjunction with the 'switch' element and the requiredExtensions attribute to provide properchecking for user agent support and provide an alternate rendering in case useragent support is not available.



23.3 外部对象元素'foreignObject'  The 'foreignObject' element

 
<!ENTITY % foreignObjectExt "" >
<!ELEMENT foreignObject (#PCDATA %ceExt;%foreignObjectExt;)* >
<!ATTLIST foreignObject
  %stdAttrs;
  %testAttrs;
  %langSpaceAttrs;
  externalResourcesRequired %Boolean; #IMPLIED
  class %ClassList; #IMPLIED
  style %StyleSheet; #IMPLIED
  %PresentationAttributes-All;
  transform %TransformList; #IMPLIED
  %graphicsElementEvents;
  x %Coordinate; #IMPLIED
  y %Coordinate; #IMPLIED
  width %Length; #REQUIRED
  height %Length; #REQUIRED
  %StructuredText; >

属性定义:Attribute definitions:

x = "<coordinate>"

矩形区域的第一顶点的x轴坐标,与'foreignObject' 的内容相联系的图形将被渲染到此矩形区域中。The x-axiscoordinate of one corner of the rectangular region into which the graphicsassociated with the contents of the 'foreignObject'will be rendered.
如果不指定此属性,其效果等同于值为"0"的情况。If the attribute is not specified, the effect is as if a value of"0" were specified.
Animatable:yes.

y = "<coordinate>"

矩形区域的第一顶点的y轴坐标,此矩形区域用来安放所引用文档的图形。The y-axis coordinate of one corner of the rectangular region intowhich the referenced document is placed.
如果不指定此属性,其效果等同于值为"0"的情况。If the attribute is not specified, the effect is as if a value of"0" were specified.
Animatable:yes.

width = "<length>"

用于安放所引用文档的图形的矩形区域的宽度。The width of the rectangular region into which the referenceddocument is placed.
一个负值是一个错误(参见 错误处理)。而零值则导致元素不被渲染。A negative value isan error (see Errorprocessing). A value of zero disables rendering of the element.
Animatable:yes.

height = "<length>"

用于安放所引用文档的图形的矩形区域的高度。The height of the rectangular region into which the referenceddocument is placed.
一个负值是一个错误(参见 错误处理)。而零值则导致元素不被渲染。A negative value isan error (see Errorprocessing). A value of zero disables rendering of the element.
Animatable:yes.

 

其他地方已经定义的属性Attributes defined elsewhere:

%stdAttrs;,%langSpaceAttrs;,class, transform,%graphicsElementEvents;,%testAttrs;, externalResourcesRequired,style, %PresentationAttributes-All;.



23.4 一个例子 An example

这里是一个例子 Hereis an example:

 
<?xml version="1.0" standalone="yes"?>
<svg width="4in" height="3in"
 xmlns = 'http://www.w3.org/2000/svg'>
  <desc>This example uses the 'switch' element to provide a 
        fallback graphical representation of an paragraph, if 
        XMHTML is not supported.</desc>
  <!-- The 'switch' element will process the first child element
       whose testing attributes evaluate to true.-->
  <switch>
 
    <!-- Process the embedded XHTML if the requiredExtensions attribute
         evaluates to true (i.e., the user agent supports XHTML
         embedded within SVG). -->
    <foreignObject width="100" height="50"
                   requiredExtensions="http://example.com/SVGExtensions/EmbeddedXHTML">
      <!-- XHTML content goes here -->
      <html xmlns="http://www.w3.org/1999/xhtml">
      <body>
        <p>Here is a paragraph that requires word wrap</p>
      </body>
      </html>
    </foreignObject>
 
    <!-- Else, process the following alternate SVG.
         Note that there are no testing attributes on the 'text' element.
         If no testing attributes are provided, it is as if there
         were testing attributes and they evaluated to true.-->
    <text font-size="10" font-family="Verdana">
      <tspan x="10" y="10">Here is a paragraph that</tspan>
      <tspan x="10" y="20">requires word wrap.</tspan>
    </text>
 
  </switch>
</svg>

不要求精图用户代理支持求助其他任何用户代理来处理嵌入外部对象类型的能力;但是,所有兼容精图用户代理需要支持'switch' 元素并且必须能够渲染这些出现在 'switch' 里面作为可选择的元素之一的有效精图元素。It is not required that SVG user agent support the ability to invokeother arbitrary user agents to handle embedded foreign object types; however,all conforming SVG user agents would need to support the 'switch'element and must be able to render valid SVG elements when they appear as oneof the alternatives within a 'switch' element.

最终,自然期望商业网页浏览器将支持精图嵌入来自其他使用CSS或格式化的XML语法的能力,这CSS或XSL格式化的内容是针对精图变换和合成的。当前,不要求这种能力。Ultimately, it is expected that commercial Web browsers will supportthe ability for SVG to embed content from other XML grammars which use CSS orXSL to format their content, with the resulting CSS- or XSL-formatted contentsubject to SVG transformations and compositing. At this time, such a capabilityis not a requirement.



23.5 增加私有的元素和属性到DTD中 Addingprivate elements and attributes to the DTD

精图DTD允许使用内部的DTD子集对精图语言进行扩展,在内部的DTD子集中,可以对大多数精图元素增加定制的元素和属性。The SVG DTDallows for extending the SVG language within the internal DTD subset. Withinthe internal DTD subset, you have the ability to add custom elements andattributes to most SVG elements.

对于大多数精图元素DTD定义一个扩展项。例如,在DTD中定义'view' 元素如下:The DTD defines an extension entity for most of SVG elements. Forexample, the 'view' element is defined in the DTD as follows:

 
<!ENTITY % viewExt "" >
<!ELEMENT view (%descTitleMetadata;%viewExt;) >
<!ATTLIST view
  %stdAttrs;
  externalResourcesRequired %Boolean; #IMPLIED
  viewBox %ViewBoxSpec; #IMPLIED
  preserveAspectRatio %PreserveAspectRatioSpec; 'xMidYMid meet'
  zoomAndPan (disable | magnify) 'magnify' 
  viewTarget CDATA #IMPLIED >

viewExt 可以在内部DTD子集中定义,它可以增加定制的元素和定制的属性到给定文档的 'view' 元素中。例如,下面的扩展使得'view' 元素具有增加的子元素'customNS:customElement' 和一个增加的属性 customNS:customAttr:  The entityviewExt can be defined in the internal DTD subset to add custom sub-elementor custom attributes to the 'view' element within a given document. Forexample, the following extends the 'view' element with an additional child element 'customNS:customElement' and an additional attribute customNS:customAttr:

 
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" 
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"
[
<!ENTITY % viewExt "| customNS:customElement" >
<!ATTLIST view
  xmlns:customNS CDATA #FIXED "http://www.example.org/customNS"
  customNS:customAttr CDATA #IMPLIED >
 
<!ELEMENT customNS:customElement EMPTY>
<!ATTLIST customNS:customElement
  xmlns:customNS CDATA #FIXED "http://www.example.org/customNS"
  info CDATA #IMPLIED>
]>
<svg width="8cm" height="4cm"
     xmlns="http://www.w3.org/2000/svg">
  <desc>Extend the 'view' element via the internal DTD subset</desc>
 
  <!-- Presumably, some great graphics would go here. -->
 
  <view viewBox="100 110 20 30" customNS:customAttr="123">
    <customNS:customElement info="abc"/>
  </view>
</svg>



23.6 文档对象模型接口 DOM interfaces

下面将定义接口: SVGForeignObjectElement. Thefollowing interfaces are defined below: SVGForeignObjectElement.

 

接口 SVGForeignObjectElement  Interface SVGForeignObjectElement

接口 SVGForeignObjectElement  与外部对象元素'foreignObject' 相对应。The SVGForeignObjectElement interface corresponds tothe 'foreignObject' element.


IDL 定义 IDLDefinition

 
interface SVGForeignObjectElement : 
                SVGElement,
                SVGTests,
                SVGLangSpace,
                SVGExternalResourcesRequired,
                SVGStylable,
                SVGTransformable,
                events::EventTarget { 
 
  readonly attribute SVGAnimatedLength x;
  readonly attribute SVGAnimatedLength y;
  readonly attribute SVGAnimatedLength width;
  readonly attribute SVGAnimatedLength height;
};

 

属性 Attributes

readonly SVGAnimatedLength x

与给定的外部对象元素'foreignObject'  的属性 x 相对应。Corresponds to attribute x on the given 'foreignObject'element.

readonly SVGAnimatedLength y

与给定的外部对象元素'foreignObject'  的属性 y 相对应。Corresponds to attribute y on the given 'foreignObject'element.

readonly SVGAnimatedLength width

与给定的外部对象元素'foreignObject'  的属性 width 相对应。Corresponds to attribute width on the given 'foreignObject'element.

readonly SVGAnimatedLength height

与给定的外部对象元素'foreignObject'  的属性height 相对应。Corresponds to attribute height on the given 'foreignObject'element.


previous  next   contents   elements   attributes   properties   index  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值