内联形状

Inline shape

Word 允许将图形对象作为内联对象放入文档中。内联形状作为 <w:drawing> 元素出现,是 <w:r> 元素的子元素。

Word allows a graphical object to be placed into a document as an inline object. An inline shape appears as a <w:drawing> element as a child of a <w:r> element.

候选协议——内联形状访问

Candidate protocol -- inline shape access

以下交互式会话说明了访问内联形状的协议:

The following interactive session illustrates the protocol for accessing an inline shape:

>>> inline_shapes = document.body.inline_shapes
>>> inline_shape = inline_shapes[0]
>>> assert inline_shape.type == MSO_SHAPE_TYPE.PICTURE

资源

Resources

MS API

MS API

Document 上的 Shapes 和 InlineShapes 属性保存对 MS API 中图片等内容的引用。

  • 高度和宽度

  • 边框

  • 阴影

  • 超链接

  • PictureFormat(提供亮度、颜色、裁剪、透明度、对比度)

  • ScaleHeight 和 ScaleWidth

  • HasChart

  • HasSmartArt

  • 类型(图表、LockedCanvas、图片、SmartArt 等)

The Shapes and InlineShapes properties on Document hold references to things like pictures in the MS API.

  • Height and Width

  • Borders

  • Shadow

  • Hyperlink

  • PictureFormat (providing brightness, color, crop, transparency, contrast)

  • ScaleHeight and ScaleWidth

  • HasChart

  • HasSmartArt

  • Type (Chart, LockedCanvas, Picture, SmartArt, etc.)

规范参考

Spec references

  • 17.3.3.9 drawing (DrawingML Object)

  • 20.4.2.8 inline (Inline DrawingML Object)

  • 20.4.2.7 extent (Drawing Object Size)

最小 XML

Minimal XML

此 XML 代表了我对 Word 将加载的最小内联形状容器的最佳猜测:

<w:r>
  <w:drawing>
    <wp:inline>
      <wp:extent cx="914400" cy="914400"/>
      <wp:docPr id="1" name="Picture 1"/>
      <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
        <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">

          <!-- 可能不需要在这里放任何东西 -->

        </a:graphicData>
      </a:graphic>
    </wp:inline>
  </w:drawing>
</w:r>

This XML represents my best guess of the minimal inline shape container that Word will load

<w:r>
  <w:drawing>
    <wp:inline>
      <wp:extent cx="914400" cy="914400"/>
      <wp:docPr id="1" name="Picture 1"/>
      <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
        <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">

          <!-- might not have to put anything here for a start -->

        </a:graphicData>
      </a:graphic>
    </wp:inline>
  </w:drawing>
</w:r>

样本 XML

Specimen XML

CT_Drawing (<w:drawing>) 元素可以出现在运行中,例如作为 <w:t> 元素的对等元素。此元素包含 DrawingML 对象。WordprocessingML 绘图在 ISO/IEC 规范的第 20.4 节中进行了讨论。

此 XML 表示内联形状,该形状单独插入段落中。图形对象本身的细节已删除:

<w:p>
  <w:r>
    <w:rPr/>
      <w:noProof/>
    </w:rPr>
    <w:drawing>
      <wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="1BDE1558" wp14:editId="31E593BB">
        <wp:extent cx="859536" cy="343814"/>
        <wp:effectExtent l="0" t="0" r="4445" b="12065"/>
        <wp:docPr id="1" name="Picture 1"/>
        <wp:cNvGraphicFramePr>
          <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/>
        </wp:cNvGraphicFramePr>
        <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
          <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">

            <!-- 图形对象(例如 pic:pic)放在此处 -->

          </a:graphicData>
        </a:graphic>
      </wp:inline>
    </w:drawing>
  </w:r>
</w:p>

架构定义

Schema definitions

<xsd:complexType name="CT_Drawing">
  <xsd:choice minOccurs="1" maxOccurs="unbounded">
    <xsd:element ref="wp:anchor" minOccurs="0"/>
    <xsd:element ref="wp:inline" minOccurs="0"/>
  </xsd:choice>
</xsd:complexType>

<xsd:complexType name="CT_Inline">
  <xsd:sequence>
    <xsd:element name="extent"            type="a:CT_PositiveSize2D"/>
    <xsd:element name="effectExtent"      type="CT_EffectExtent"                      minOccurs="0"/>
    <xsd:element name="docPr"             type="a:CT_NonVisualDrawingProps"/>
    <xsd:element name="cNvGraphicFramePr" type="a:CT_NonVisualGraphicFrameProperties" minOccurs="0"/>
    <xsd:element name="graphic"           type="CT_GraphicalObject"/>
  </xsd:sequence>
  <xsd:attribute name="distT" type="ST_WrapDistance"/>
  <xsd:attribute name="distB" type="ST_WrapDistance"/>
  <xsd:attribute name="distL" type="ST_WrapDistance"/>
  <xsd:attribute name="distR" type="ST_WrapDistance"/>
</xsd:complexType>

<xsd:complexType name="CT_PositiveSize2D">
  <xsd:attribute name="cx" type="ST_PositiveCoordinate" use="required"/>
  <xsd:attribute name="cy" type="ST_PositiveCoordinate" use="required"/>
</xsd:complexType>

<xsd:complexType name="CT_EffectExtent">
  <xsd:attribute name="l" type="a:ST_Coordinate" use="required"/>
  <xsd:attribute name="t" type="a:ST_Coordinate" use="required"/>
  <xsd:attribute name="r" type="a:ST_Coordinate" use="required"/>
  <xsd:attribute name="b" type="a:ST_Coordinate" use="required"/>
</xsd:complexType>

<xsd:complexType name="CT_NonVisualDrawingProps">
  <xsd:sequence>
    <xsd:element name="hlinkClick" type="CT_Hyperlink"              minOccurs="0"/>
    <xsd:element name="hlinkHover" type="CT_Hyperlink"              minOccurs="0"/>
    <xsd:element name="extLst"     type="CT_OfficeArtExtensionList" minOccurs="0"/>
  </xsd:sequence>
  <xsd:attribute name="id"     type="ST_DrawingElementId" use="required"/>
  <xsd:attribute name="name"   type="xsd:string"          use="required"/>
  <xsd:attribute name="descr"  type="xsd:string"          default=""/>
  <xsd:attribute name="hidden" type="xsd:boolean"         default="false"/>
  <xsd:attribute name="title"  type="xsd:string"          default=""/>
</xsd:complexType>

<xsd:complexType name="CT_NonVisualGraphicFrameProperties">
  <xsd:sequence>
    <xsd:element name="graphicFrameLocks" type="CT_GraphicalObjectFrameLocking" minOccurs="0"/>
    <xsd:element name="extLst"            type="CT_OfficeArtExtensionList"      minOccurs="0"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="CT_GraphicalObject">
  <xsd:sequence>
    <xsd:element name="graphicData" type="CT_GraphicalObjectData"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="CT_GraphicalObjectData">
  <xsd:sequence>
    <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="strict"/>
  </xsd:sequence>
  <xsd:attribute name="uri" type="xsd:token" use="required"/>
</xsd:complexType>