DrawingML Basics
Open XML Developer Workshop
Disclaimer
The information contained in this slide deck represents the current view of Microsoft Corporation on the issues discussed as of the date of
publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the
part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.
This slide deck is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE
INFORMATION IN THIS DOCUMENT.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this slide
deck may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic,
mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft
Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this
slide deck. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this slide deck does not give
you any license to these patents, trademarks, copyrights, or other intellectual property.
Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events
depicted herein are fictitious, and no association with any real company, organization, product, domain name, email address, logo,
person, place or event is intended or should be inferred.
© 2006 Microsoft Corporation. All rights reserved.
Microsoft, 2007 Microsoft Office System, .NET Framework 3.0, Visual Studio, and Windows Vista are either registered trademarks or
trademarks of Microsoft Corporation in the United States and/or other countries.
The names of actual companies and products mentioned herein may be the trademarks of their respective owners.
Open XML Developer Workshop
Tip of a Large Iceberg
Open XML Developer Workshop
SHAPES, PICTURES, GRAPHIC
FRAMES, CHARTS
Open XML Developer Workshop
DrawingML General Concepts
5 Main types of objects
Shape
Group Shape
Connector
Picture
Graphic Frame
General-purpose container
Used for Charts, Diagrams, Tables
Most widely used elements are Property elements
Non-Visible Properties (nvPrs): union of common nvPrs and object
specific nvPrs
Visible Properties: object specific
Open XML Developer Workshop
DrawingML Coordinate System
Measured in EMU (English Metrical Unit)
914,400 EMU per inch
12,700 EMU in a point
360,000 EMU per cm
Open XML Developer Workshop
SHAPES
Open XML Developer Workshop
Shapes
spTree
Preset geometry
nvGrpSpPr
Pick the preset shape
Specify the adjust values for the shape
grpSpPr
sp
nvSpPr
spPr
xfrm
geo
fillProperties
lineProperties
effectProperties
scene3D
sp3D
bwMode
Text geometry
Pick the preset text shape
Specify the adjust values for the text shape
Custom geometry
Not covered in this course
Open XML Developer Workshop
style
txBody
Shape Line and Fill Properties
Dash Line and Solid Fill
<a:ln>
<a:solidFill>
<a:srgbClr val="4F81BD" />
</a:solidFill>
<a:prstDash val="sysDash" />
</a:ln>
Line
Fill
Dashed Line
BLIP (Binary Large Image or Pictures) Fill
<a:blipFill>
<a:blip r:embed="rId2" />
<a:stretch>
<a:fillRect />
</a:stretch>
</a:blipFill>
Gradient Fill
<a:gradFill flip="none" rotWithShape="1">
<a:gsLst>
<a:gs pos="0">
<a:srgbClr val="DDEBCF" />
</a:gs>
<a:gs pos="50000">
<a:srgbClr val="9CB86E" />
</a:gs>
...
</a:gsLst>
<a:lin ang="4200000" scaled="0" />
<a:tileRect />
</a:gradFill>
Open XML Developer Workshop
Indicates relationship id
to image data
Gradient stop and color
DEMO
DrawingML Text
Text is largely modeled after Word’s design
Similar structures
Similar naming conventions
Different schemas
We can apply all graphic
effects to text
Effect
Some limited to runs
Some limited to paragraph
Text
<p:spPr>
...
<a:effectLst>
<a:reflection blurRad="6350" stA="50000"
endA="300" endPos="90000" dir="5400000“
sy="-100000" algn="bl" />
</a:effectLst>
</p:spPr>
<p:txBody>
<a:bodyPr wrap="none" rtlCol="0">
<a:spAutoFit />
</a:bodyPr>
<a:lstStyle />
<a:p>
<a:r>
<a:rPr b="1”>
<a:solidFill>
<a:srgbClr val="FF0000" />
</a:solidFill>
</a:rPr>
<a:t>Reflective Text</a:t>
</a:r>
</a:p>
</p:txBody>
Open XML Developer Workshop
3-D
Adjust
Material
types
Apply 3-D
Bevels
<a:scene3d>
<a:camera prst="isometricRightUp" />
<a:lightRig rig="threePt" dir="t" />
</a:scene3d>
<a:sp3d extrusionH="152400" />
Before
3-D Scene Definition
Apply 3-D
Scene Above
DEMO
Open XML Developer Workshop
PICTURES
Open XML Developer Workshop
Pictures vs. Shapes
1.
2.
3.
4.
5.
6.
Two overlaid fills allowed
Borders grow outward
Lock aspect ratio flag
Cannot have text attached
Can have shape properties
Picture specific UI enabled
Open XML Developer Workshop
1.
2.
3.
4.
5.
6.
Single fill allowed
Borders grow in/outward
Must be done by app
Can have text attached
Can have shape properties
Shape specific UI enabled
Defining a Picture
Define a Picture:
<p:pic/>
Source image rel. id
<a:blip r:embed=“rId2”/>
Acts similar to a shape
<p:spPr/>
Non-Visual picture
properties convey picture
specific save properties
<p:nvPicPr/>
<p:pic>
<p:nvPicPr>
<p:cNvPr id="4" name="lake.jpeg" />
<p:cNvPicPr>
<a:picLocks noChangeAspect="1" />
</p:cNvPicPr>
<p:nvPr />
</p:nvPicPr>
<p:blipFill>
<a:blip r:embed="rId2" />
<a:stretch>
<a:fillRect />
</a:stretch>
</p:blipFill>
<p:spPr>
<a:xfrm>
<a:off x="762000" y="571500" />
<a:ext cx="7620000" cy="5715000" />
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst />
</a:prstGeom>
</p:spPr>
</p:pic>
Similar for Audio & Video
Open XML Developer Workshop
Picture Properties
1. Multiple Fills
Allows for two fills to be
applied such as a picture
and a color fill
2. Picture Borders
Because of the nature of
pictures the borders
grow outwards rather
than in/outwards
3. Lock Aspect Ratio
Resizing a picture can be
done with or without the
aspect ratio locked
Open XML Developer Workshop
GRAPHIC OBJECTS AND CHARTS
Open XML Developer Workshop
Graphic Objects
Graphic element represents a single graphical object
GraphicData element and Uri attribute
Specifies the namespace for the embedded content
Tells the consumer how to interpret the graphicData
Ability to render is application specific
Office supports a set of specific URI values:
Graphic
Object
http://schemas.openxmlformats.org/drawingml/2006/chart
http://schemas.openxmlformats.org/drawingml/2006/diagrams
…
URI means <graphic>
<a:graphicData uri="http://schemas.../drawingml/2006/chart">
chart
<c:chart xmlns:c="http://schemas.../drawingml/2006/chart"
follows
xmlns:r="http://schemas.../officeDocument/2006/relationships"
r:id="rd123232" />
</a:graphicData>
DEMO
</graphic>
Open XML Developer Workshop
Charts Overview
Visualization of information
Can be reused across applications / formats
Rich chart types
11 types
2-dimensional and 3-dimensional
DEMO
ChartSwapping
Open XML Developer Workshop
Elements of a Chart
Graphic Object definition
References separate XML chart part
Defined in DrawingML namespace
Chart XML Part
Visual representation of data.
Includes a cache of data for chart.
Includes formatting using DrawingML.
Graphic Object
rId
Data Relationship
External relationship to file, or
Internal relationship to embedded spreadsheet
Spreadsheets point to their own data.
Chart Drawing
Contains shapes and pictures drawn on chart
Open XML Developer Workshop
1
n
XML Chart Part
rId
n
0,1
1
rId
1
Data Source
Chart Drawing
Main Elements of the Chart Part XML
Namespace
"http://schemas.openxmlformats.org/drawingml/2006/chart"
<chartSpace>
<chart>
<view3D/>
<plotArea>
<layOut/>
<barChart>
<ser>
<cat/>
<val/>
</ser>
</barChart>
<catAx/>
<valAx/>
</plotArea>
<legend/>
</chart>
</chartSpace>
Element
Description
<chartSpace/>
Root node includes chart.
<chart/>
Root element for the chart.
<view3D/>
If the chart is 3D, specifies the 3D view.
<plotArea/>
Defines a layout and contains an element that
defines the type of chart.
<*Chart/>
The type of chart (Bar, Pie, etc.)
<ser/>
Defines a series of data in the chart
<cat/>
Category (axis) cache data (strings)
<val/>
Values cache data (numbers).
<legend/>
Specifies the legend.
<catAx/>
<valAx/>
Bar Chart specific values
Open XML Developer Workshop
Chart Data Cache Structure
Chart XML fragment
<barChart>
<!-- pears -->
<ser>
<cat/>
<val/>
</ser>
<!-- apples -->
<ser>
<cat/>
<val/>
</ser>
<!-- lemons -->
<ser>
<cat/>
<val/>
</ser>
</barChart>
Your code writes this
XML to set chart data!
Series <ser>
Pears Apples Lemons
Categories
<cat>
East
4.3
2.4
2
West
2.5
4.4
2
North
3.5
1.8
3
South
4.5
2.8
5
Open XML Developer Workshop
Values
<val>
Specifying Series Data Points
Strings or numbers
Literals or references
Point values
String Reference
String Literal
<c:strLit>
<c:ptCount val="4" />
<c:pt idx="0">
<c:v>East</c:v>
</c:pt>
<c:pt idx="1">
<c:v>West</c:v>
</c:pt>
<c:pt idx="2">
<c:v>North</c:v>
</c:pt>
<c:pt idx="3">
<c:v>South</c:v>
</c:pt>
</c:strLit>
<c:strRef>
<!-- ref formula -->
<c:f>Sheet1!$A$2:$A$5</c:f>
<!-- data cache -->
<c:strCache>
<c:ptCount val="4" />
<c:pt idx="0">
<c:v>East</c:v>
</c:pt>
<c:pt idx="1">
<c:v>West</c:v>
</c:pt>
<c:pt idx="2">
<c:v>North</c:v>
</c:pt>
<c:pt idx="3">
<c:v>South</c:v>
</c:pt>
</c:strCache>
</c:strRef>
Open XML Developer Workshop
Number Reference
<c:numRef>
<!-- ref formula -->
<c:f>Sheet1!$B$2:$B$5</c:f>
<!-- data cache -->
<c:numCache>
<c:ptCount val="4" />
<c:pt idx="0">
<c:v>4.3</c:v>
</c:pt>
<c:pt idx="1">
<c:v>2.5</c:v>
</c:pt>
<c:pt idx="2">
<c:v>3.5</c:v>
</c:pt>
<c:pt idx="3">
<c:v>4.5</c:v>
</c:pt>
</c:numCache>
</c:numRef>
INSERTING DRAWING OBJECTS
INTO DOCUMENTS
Open XML Developer Workshop
Inserting DrawingML Objects Overview
Drawing Types Allowed
Charts
Diagrams
Locked Canvases
Viewed but not edited by host
Pictures
The core DrawingML is the
same in all hosts
Location varies by host
Wordprocessing: main body
Spreadsheet: drawing part
Presentation: slide
Packaging (“shim”) varies
Open XML Developer Workshop
DEMO
Drawings in WordprocessingML
Shim defines
anchor and
flow
Graphic
object
<w:p>
<w:r>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="5943600" cy="3119120" />
<wp:effectExtent l="57150" t="19050" r="38100" b="5080" />
<wp:docPr id="1" name="Chart 1" />
<wp:cNvGraphicFramePr />
<a:graphic xmlns:a=http://schemas.../drawingml/2006/main>
...
</a:graphic>
</wp:inline>
</w:drawing>
</w:r>
</w:p>
Open XML Developer Workshop
Drawings in SpreadsheetML
Shim defines
anchor and
non-visual
properties
Graphic
object
<xdr:wsDr
xmlns:xdr="http://schemas.../drawingml/2006/spreadsheetDrawing"
xmlns:a="http://schemas.../drawingml/2006/main">
<xdr:twoCellAnchor>
<xdr:from>
...
</xdr:from>
<xdr:to>
...
</xdr:to>
<xdr:graphicFrame>
<xdr:nvGraphicFramePr>
<xdr:cNvPr id="2" name="MySalesChart" />
<xdr:cNvGraphicFramePr />
</xdr:nvGraphicFramePr>
<xdr:xfrm>
<a:off x="0" y="0" />
<a:ext cx="0" cy="0" />
</xdr:xfrm>
<a:graphic>
...
</a:graphic>
</xdr:graphicFrame>
<xdr:clientData />
</xdr:twoCellAnchor>
</xdr:wsDr>
Open XML Developer Workshop
Drawings in PresentationML
No shim. The
shape is in the
tree
Graphic
object
<p:spTree>
<p:nvGrpSpPr>
...
</p:nvGrpSpPr>
<p:grpSpPr>
...
</p:grpSpPr>
<p:graphicFrame>
<p:nvGraphicFramePr>
<p:cNvPr id="4" name="slide3Chart" />
<p:cNvGraphicFramePr />
<p:nvPr />
</p:nvGraphicFramePr>
<p:xfrm>
<a:off x="762000" y="2362200" />
...
</p:xfrm>
<a:graphic>
...
</a:graphic>
</p:graphicFrame>
</p:spTree>
Open XML Developer Workshop
Inserting Drawings in WordprocessingML
Documents
Open XML Developer Workshop
Object Positioning (Anchoring)
Two ways to anchor in WordprocessingML:
In line with text (<inline>) - The object is displayed within the regular
text stream (modifying line height, etc. to accommodate it)
Floating (<anchor>) – The object is absolutely positioned within the
document and text flow is modified as needed around it
The type of anchoring is specified by the main element
<w:p>
<w:r>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
...
<wp:cNvGraphicFramePr />
<a:graphic xmlns:a="http://schemas.../drawingml/2006/main">
<a:graphicData
...
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
Open XML Developer Workshop
WordprocessingML Inline Objects
The most basic type of DrawingML object placement is in
line with text
The object is displayed like a large character glyph
Open XML Developer Workshop
WordprocessingML Floating Objects
Floating objects are positioned on the page independent
of text
They can be positioned:
Absolutely (e.g. 1” inside the top margin)
Relatively (e.g. centered within the page margins)
9525
EMUs
inside the
column
<wp:positionH relativeFrom="column">
<wp:posOffset>9525</wp:posOffset>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>635</wp:posOffset>
</wp:positionV>
Open XML Developer Workshop
635 EMUs
below the
paragraph
Floating Object Text Wrapping in WordML
Five ways to specify how text flows around the object
Element
Example
Description
wrapNone
The object is positioned on the document and text is
not displaced around it
wrapSquare
The object is positioned on the document and an
implied rectangle determines the wrapping extents
wrapTight
A wrapping polygon, defined and stored in the file,
determines the text wrapping extents
wrapThrough
Similar to tight wrapping – but any indents in the wrap
polygon can be filled with text
Text cannot wrap around either side of the object
wrapTopAndBot
tom
DEMO
WP Anchoring
Open XML Developer Workshop
Shapes created in WordprocessingML use VML
VML
Namespace
VML Elements
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<w:document
xmlns:w=http://schemas.openxmlformats.org/wordprocessingml/2006/main
xmlns:v="urn:schemas-microsoft-com:vml"
...>
<w:body>
<w:p>
<w:r>
<w:pict>
<v:shapetype id="_x0000_t12" coordsize="21600,21600" o:spt="12“
path="m10800,l8280,8259,,8259r6720,5146l4200,21600r6600,5019l17400,21600,14880,13405,21600,8259r-8280,xe">
<v:stroke joinstyle="miter"/>
<v:path gradientshapeok="t" o:connecttype="custom"
o:connectlocs="10800,0;0,8259;4200,21600;
17400,21600;21600,8259"
textboxrect="6720,8259,14880,15628"/>
</v:shapetype>
<v:shape id="_x0000_s1026" type="#_x0000_t12“
style="width:47.25pt;
height:44.9pt;mso-position-horizontal-relative:char;msoposition-vertical-relative:line" fillcolor="#c6d9f1 [671]“
strokecolor="#4f81bd [3204]">
<w10:wrap type="none"/>
<w10:anchorlock/>
</v:shape>
</w:pict>
</w:r>
</w:p>
Open XML Developer Workshop
Inserting DrawingML into Spreadsheet
Documents
Open XML Developer Workshop
Graphical Objects in SpreadsheetML
Worksheet Drawings stored in Drawing Part
Linked by Relationship ID.
Root element: <xdr:wsDr/>
Sheet
Anchoring properties (3 types)
Absolute: <xdr:absoluteAnchor/>
One cell: <xdr:oneCellAnchor/>
Two cell: <xdr:twoCellAnchor/>
rId
1
1
Drawing Part
Drawing elements
DEMO
Charts
Shapes
Open XML Developer Workshop
Absolute Anchoring
<xdr:absoluteAnchor>
<xdr:pos x=“2276475" y=“1552575" />
<xdr:ext cx=“1238250" cy=“1123950"/>
Don’t move or size with
cells
Position explicitly
specified
Measured in EMUs
Extents explicitly
specified
Measured in EMUs
Open XML Developer Workshop
One Cell Anchoring
<xdr:oneCellAnchor>
<xdr:from>
<xdr:col>3</xdr:col>
<xdr:colOff>447675</xdr:colOff>
<xdr:row>8</xdr:row>
<xdr:rowOff>28575</xdr:rowOff>
</xdr:from>
<xdr:ext cx=“1238250" cy=“1123950"/>
...
Move with cells
Position locked to single
cell
Position explicitly
specified
Measured in EMUs
Extents explicitly
specified
Measured in EMUs
Open XML Developer Workshop
Two Cell Anchoring
<xdr:twoCellAnchor>
<xdr:from>
<xdr:col>3</xdr:col>
<xdr:colOff>447675</xdr:colOff>
<xdr:row>8</xdr:row>
<xdr:rowOff>28575</xdr:rowOff>
</xdr:from>
<xdr:to>
<xdr:col>5</xdr:col>
<xdr:colOff>466725</xdr:colOff>
<xdr:row>14</xdr:row>
<xdr:rowOff>9525</xdr:rowOff>
</xdr:to>
Move and size with cells
Position locked to cell
range
From position specified
Measured in EMUs
To position specified
Measured in EMUs
Sizing based on cell
range
DEMO
Open XML Developer Workshop
Open XML Developer Workshop