1. What is drawingML?
    DrawingML is the language for defining graphical objects such as pictures, shapes, charts, and diagrams within ooxml documents. It also specifies package-wide appearance characteristics, i.e., the package's theme. DrawingML is not a standalone markup language; it supports and appears within wordprocessingML, spreadsheetML, and presentationML documents. DrawingML is distinct from SVG and VML. SVG (scaleable vector graphics) is a graphics file format for two-dimensional graphics in XML. It is used mostly on the web and in desktop publishing. VML is a competing language for vector graphic files. It is now largely deprecated in favor of SVG. According to the ECMA OOXML specification, "The DrawingML format is a newer and richer format created with the goal of eventually replacing any uses of VML in the Office Open XML formats. VML is a transitional format; it is included in Office Open XML for legacy reasons only." VML is still used extensively within Microsoft Word for certain graphic comnponents, in particular for things as shapes and text boxes.
  2. DrawingML sample
    Open Microsoft Excel 2010 and insert a picture on the worksheet.  The inserted picture has been sized to extend from cell B2 (top left) to cell G16 (lower right).

    Set the position properties.

    Set the height and width of the picture.


    Now we  can go into the detail.
    At first,unzip the saved XLSX file and extract the corresponding drawing file (by default its name will be drawing1.xml) after resolving the relationship from the sheet relationship part.
    The content of  drawing1.xml

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <xdr:wsDr xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
    <xdr:twoCellAnchor editAs="oneCell">
    <xdr:from>
    <xdr:col>2</xdr:col>
    <xdr:colOff>9525</xdr:colOff>
    <xdr:row>3</xdr:row>
    <xdr:rowOff>28575</xdr:rowOff>
    </xdr:from>
    <xdr:to>
    <xdr:col>4</xdr:col>
    <xdr:colOff>57150</xdr:colOff>
    <xdr:row>6</xdr:row>
    <xdr:rowOff>95250</xdr:rowOff>
    </xdr:to>
    <xdr:pic>
    <xdr:nvPicPr>
    <xdr:cNvPr id="1025" name="Picture 1" descr="logo"/>
    <xdr:cNvPicPr>
    <a:picLocks noChangeAspect="1" noChangeArrowheads="1"/>
    </xdr:cNvPicPr>
    </xdr:nvPicPr>
    <xdr:blipFill>
    <a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId1"/>
    <a:srcRect/>
    <a:stretch>
    <a:fillRect/>
    </a:stretch>
    </xdr:blipFill>
    <xdr:spPr bwMode="auto">
    <a:xfrm>
    <a:off x="1228725" y="514350"/>
    <a:ext cx="1266825" cy="552450"/>
    </a:xfrm>
    <a:prstGeom prst="rect">
    <a:avLst/>
    </a:prstGeom>
    <a:noFill/>
    </xdr:spPr>
    </xdr:pic>
    <xdr:clientData/>
    </xdr:twoCellAnchor>
    </xdr:wsDr>

    In the XML fragment of –
    <xdr:wsDr xmlns:xdr=http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing…>
    <xdr:twoCellAnchor editAs="oneCell">

    The attribute “editAs” specifies how the drawing object is moved/resized when the rows and columns are resized. 

    <xdr:colOffand <xdr:rowOffelements determines the actual placement of the drawing within the spreadsheet along with row and column information.

    avLst (List of Shape Adjust Values)
    This element specifies the adjust values that are applied to the specified shape. An adjust value is simply a guide that has a value based formula specified. That is, no calculation takes place for an adjust value guide. Instead, this guide specifies a parameter value that is used for calculations within the shape guides.
  3. Export shapes in DrawingML



    The main entry is the function of XclObjAny::SaveXml() in xcl97,cxx in sc module.
    here is the snapshot:
    void XclObjAny::SaveXml( XclExpXmlStream& rStrm )

    {
    if( !mxShape.is() )
    return;

    sax_fastparser::FSHelperPtr pDrawing = rStrm.GetCurrentStream();

    ShapeExport aDML( XML_xdr, pDrawing, NULL, &rStrm, DrawingML::DOCUMENT_XLSX );

    pDrawing->startElement( FSNS( XML_xdr, XML_twoCellAnchor ), // OOXTODO: oneCellAnchor, absoluteAnchor
    XML_editAs, GetEditAs( *this ),
    FSEND );
    Reference< XPropertySet > xPropSet( mxShape, UNO_QUERY );
    if (xPropSet.is())
    {
    WriteFromTo( rStrm, *this );
    aDML.WriteShape( mxShape );
    }

    pDrawing->singleElement( FSNS( XML_xdr, XML_clientData),
    // OOXTODO: XML_fLocksWithSheet
    // OOXTODO: XML_fPrintsWithSheet
    FSEND );
    pDrawing->endElement( FSNS( XML_xdr, XML_twoCellAnchor ) );
    }

    The function of WriteFromTo() write the size/position information of a shape, the real shape info is written in aDML.WriteShape().
    There is a table to make sure how to export different shape type. It is defined in oox moduel.

    static const NameToConvertMapType& lcl_GetConverters()
    {
    static bool shape_map_inited = false;
    static NameToConvertMapType shape_converters;
    if( shape_map_inited )
    {
    return shape_converters;
    }

    shape_converters[ "com.sun.star.drawing.ClosedBezierShape" ] = &ShapeExport::WriteClosedBezierShape;
    shape_converters[ "com.sun.star.drawing.ConnectorShape" ] = &ShapeExport::WriteConnectorShape;
    shape_converters[ "com.sun.star.drawing.CustomShape" ] = &ShapeExport::WriteCustomShape;
    shape_converters[ "com.sun.star.drawing.EllipseShape" ] = &ShapeExport::WriteEllipseShape;
    shape_converters[ "com.sun.star.drawing.GraphicObjectShape" ] = &ShapeExport::WriteGraphicObjectShape;
    shape_converters[ "com.sun.star.drawing.LineShape" ] = &ShapeExport::WriteLineShape;
    shape_converters[ "com.sun.star.drawing.OpenBezierShape" ] = &ShapeExport::WriteOpenBezierShape;
    shape_converters[ "com.sun.star.drawing.RectangleShape" ] = &ShapeExport::WriteRectangleShape;
    shape_converters[ "com.sun.star.drawing.TextShape" ] = &ShapeExport::WriteTextShape;
    shape_converters[ "com.sun.star.presentation.DateTimeShape" ] = &ShapeExport::WriteTextShape;
    shape_converters[ "com.sun.star.presentation.FooterShape" ] = &ShapeExport::WriteTextShape;
    shape_converters[ "com.sun.star.presentation.HeaderShape" ] = &ShapeExport::WriteTextShape;
    shape_converters[ "com.sun.star.presentation.NotesShape" ] = &ShapeExport::WriteTextShape;
    shape_converters[ "com.sun.star.presentation.OutlinerShape" ] = &ShapeExport::WriteTextShape;
    shape_converters[ "com.sun.star.presentation.SlideNumberShape" ] = &ShapeExport::WriteTextShape;
    shape_converters[ "com.sun.star.presentation.TitleTextShape" ] = &ShapeExport::WriteTextShape;
    shape_map_inited = true;

    return shape_converters;
    }
    And a lot of shape use ShapeExport& ShapeExport::WriteCustomShape( Reference< XShape > xShape ) to export the real content.

  • No labels