001package com.hfg.xml.msofficexml.xlsx.spreadsheetDrawing;
002
003
004import com.hfg.graphics.units.GfxSize2D;
005import com.hfg.graphics.units.GfxUnits;
006import com.hfg.xml.XMLName;
007import com.hfg.xml.XMLTag;
008import com.hfg.xml.msofficexml.docx.drawingml.DmlShapeType;
009import com.hfg.xml.msofficexml.xlsx.CellRef;
010import com.hfg.xml.msofficexml.xlsx.Xlsx;
011import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXMLTag;
012
013//------------------------------------------------------------------------------
014/**
015 Base class for Office Open XML spreadsheet drawing anchor tags.
016 <div>
017 @author J. Alex Taylor, hairyfatguy.com
018 </div>
019 */
020//------------------------------------------------------------------------------
021// com.hfg XML/HTML Coding Library
022//
023// This library is free software; you can redistribute it and/or
024// modify it under the terms of the GNU Lesser General Public
025// License as published by the Free Software Foundation; either
026// version 2.1 of the License, or (at your option) any later version.
027//
028// This library is distributed in the hope that it will be useful,
029// but WITHOUT ANY WARRANTY; without even the implied warranty of
030// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
031// Lesser General Public License for more details.
032//
033// You should have received a copy of the GNU Lesser General Public
034// License along with this library; if not, write to the Free Software
035// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
036//
037// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
038// jataylor@hairyfatguy.com
039//------------------------------------------------------------------------------
040
041public abstract class SsDrawDrawingAnchor extends SsmlXMLTag
042{
043   //---------------------------------------------------------------------------
044   public SsDrawDrawingAnchor(XMLName inName, Xlsx inParentDoc)
045   {
046      super(inName, inParentDoc);
047
048      // The client data is just a stub for now.
049      XMLTag clientDataTag = new XMLTag(SsDrawXML.CLIENT_DATA);
050      addSubtag(clientDataTag);
051   }
052
053   //---------------------------------------------------------------------------
054   public SsDrawShape setShape(DmlShapeType inShapeType, GfxSize2D inSize2D)
055   {
056      SsDrawShape shape = new SsDrawShape(getParentDoc());
057      addSubtag(shape);
058
059      shape.getShapeProperties().getOrCreateTransform().setWidth(inSize2D.getWidth()).setHeight(inSize2D.getHeight());
060      shape.getShapeProperties().getOrCreateTransform().setOffsetX(inSize2D.getWidth()).setOffsetY(inSize2D.getHeight()); // TODO: Necessary?
061      shape.getShapeProperties().getOrCreatePresetGeometry().setShape(inShapeType);
062      shape.getOrCreateStyle();
063
064      return shape;
065   }
066
067   //---------------------------------------------------------------------------
068   protected static void attachLocationSubtags(XMLTag inTag, CellRef inCellRef, GfxSize2D inOffsets)
069   {
070      XMLTag colTag = new XMLTag(SsDrawXML.COL);
071      colTag.setContent(inCellRef.getColIndex());
072      inTag.addSubtag(colTag);
073
074      XMLTag colOffsetTag = new XMLTag(SsDrawXML.COL_OFFSET);
075      colOffsetTag.setContent(inOffsets != null ? inOffsets.getWidth().toInt(GfxUnits.dxa) : 0);
076      inTag.addSubtag(colOffsetTag);
077
078      XMLTag rowTag = new XMLTag(SsDrawXML.ROW);
079      rowTag.setContent(inCellRef.getRowIndex());
080      inTag.addSubtag(rowTag);
081
082      XMLTag rowOffsetTag = new XMLTag(SsDrawXML.ROW_OFFSET);
083      rowOffsetTag.setContent(inOffsets != null ? inOffsets.getHeight().toInt(GfxUnits.dxa) : 0);
084      inTag.addSubtag(rowOffsetTag);
085   }
086
087}