001package com.hfg.xml.msofficexml.docx.drawingml;
002
003
004import com.hfg.graphics.units.GfxSize;
005import com.hfg.graphics.units.GfxUnits;
006import com.hfg.graphics.units.Pixels;
007import com.hfg.xml.XMLTag;
008
009public class DmlTransform extends XMLTag
010{
011   private XMLTag mOffsetTag;
012   private DmlExtents mExtentsTag;
013
014   //---------------------------------------------------------------------------
015   public DmlTransform()
016   {
017      super(DmlXML.TRANSFORM_2D);
018      init();
019   }
020
021   //---------------------------------------------------------------------------
022   private void init()
023   {
024      setOffsetX(new Pixels(0));
025      setOffsetY(new Pixels(0));
026
027      // TODO: Temp for testing
028//      setWidth(new Pixels(200));
029//      setHeight(new Pixels(300));
030   }
031
032   // TODO: setRotate()
033   //---------------------------------------------------------------------------
034   public DmlTransform setFlipHoriz(boolean inValue)
035   {
036      getOffset().setAttribute(DmlXML.FLIP_HORIZ_ATT, inValue ? "1" : "0");
037      return this;
038   }
039
040   //---------------------------------------------------------------------------
041   public DmlTransform setFlipVert(boolean inValue)
042   {
043      getOffset().setAttribute(DmlXML.FLIP_VERT_ATT, inValue ? "1" : "0");
044      return this;
045   }
046
047   //---------------------------------------------------------------------------
048   public DmlTransform setOffsetX(GfxSize inValue)
049   {
050      getOffset().setAttribute(DmlXML.X_ATT, inValue.toInt(GfxUnits.emus));
051      return this;
052   }
053
054   //---------------------------------------------------------------------------
055   public DmlTransform setOffsetY(GfxSize inValue)
056   {
057      getOffset().setAttribute(DmlXML.Y_ATT, inValue.toInt(GfxUnits.emus));
058      return this;
059   }
060
061   //---------------------------------------------------------------------------
062   public DmlTransform setWidth(GfxSize inValue)
063   {
064      getExtents().setAttribute(DmlXML.CX_ATT, inValue.toInt(GfxUnits.emus));
065      return this;
066   }
067
068   //---------------------------------------------------------------------------
069   public DmlTransform setHeight(GfxSize inValue)
070   {
071      getExtents().setAttribute(DmlXML.CY_ATT, inValue.toInt(GfxUnits.emus));
072      return this;
073   }
074
075
076   //---------------------------------------------------------------------------
077   /**
078    * Returns the offset tag if one exists or else instantiates a new one.
079    * @return the offset tag for this transform tag
080    */
081   private XMLTag getOffset()
082   {
083      if (null == mOffsetTag)
084      {
085         // Check if it has been added via addSubtag()...
086         mOffsetTag = getOptionalSubtagByName(DmlXML.OFFSET);
087         if (null == mOffsetTag)
088         {
089            mOffsetTag = new XMLTag(DmlXML.OFFSET);
090            addSubtag(0, mOffsetTag);
091         }
092      }
093
094      return mOffsetTag;
095   }
096
097   //---------------------------------------------------------------------------
098   /**
099    * Returns the extents tag if one exists or else instantiates a new one.
100    * @return the extents tag for this transform tag
101    */
102   private XMLTag getExtents()
103   {
104      if (null == mExtentsTag)
105      {
106         // Check if it has been added via addSubtag()...
107         mExtentsTag = getOptionalSubtagByName(DmlXML.EXTENTS);
108         if (null == mExtentsTag)
109         {
110            mExtentsTag = new DmlExtents();
111            addSubtag(1, mExtentsTag);
112         }
113      }
114
115      return mExtentsTag;
116   }
117
118}