All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.xml.msofficexml.docx.drawingml.DmlTransform Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.xml.msofficexml.docx.drawingml;


import com.hfg.graphics.units.GfxSize;
import com.hfg.graphics.units.GfxUnits;
import com.hfg.graphics.units.Pixels;
import com.hfg.xml.XMLTag;

public class DmlTransform extends XMLTag
{
   private XMLTag mOffsetTag;
   private DmlExtents mExtentsTag;

   //---------------------------------------------------------------------------
   public DmlTransform()
   {
      super(DmlXML.TRANSFORM_2D);
      init();
   }

   //---------------------------------------------------------------------------
   private void init()
   {
      setOffsetX(new Pixels(0));
      setOffsetY(new Pixels(0));

      // TODO: Temp for testing
//      setWidth(new Pixels(200));
//      setHeight(new Pixels(300));
   }

   // TODO: setRotate()
   //---------------------------------------------------------------------------
   public DmlTransform setFlipHoriz(boolean inValue)
   {
      getOffset().setAttribute(DmlXML.FLIP_HORIZ_ATT, inValue ? "1" : "0");
      return this;
   }

   //---------------------------------------------------------------------------
   public DmlTransform setFlipVert(boolean inValue)
   {
      getOffset().setAttribute(DmlXML.FLIP_VERT_ATT, inValue ? "1" : "0");
      return this;
   }

   //---------------------------------------------------------------------------
   public DmlTransform setOffsetX(GfxSize inValue)
   {
      getOffset().setAttribute(DmlXML.X_ATT, inValue.toInt(GfxUnits.emus));
      return this;
   }

   //---------------------------------------------------------------------------
   public DmlTransform setOffsetY(GfxSize inValue)
   {
      getOffset().setAttribute(DmlXML.Y_ATT, inValue.toInt(GfxUnits.emus));
      return this;
   }

   //---------------------------------------------------------------------------
   public DmlTransform setWidth(GfxSize inValue)
   {
      getExtents().setAttribute(DmlXML.CX_ATT, inValue.toInt(GfxUnits.emus));
      return this;
   }

   //---------------------------------------------------------------------------
   public DmlTransform setHeight(GfxSize inValue)
   {
      getExtents().setAttribute(DmlXML.CY_ATT, inValue.toInt(GfxUnits.emus));
      return this;
   }


   //---------------------------------------------------------------------------
   /**
    * Returns the offset tag if one exists or else instantiates a new one.
    * @return the offset tag for this transform tag
    */
   private XMLTag getOffset()
   {
      if (null == mOffsetTag)
      {
         // Check if it has been added via addSubtag()...
         mOffsetTag = getOptionalSubtagByName(DmlXML.OFFSET);
         if (null == mOffsetTag)
         {
            mOffsetTag = new XMLTag(DmlXML.OFFSET);
            addSubtag(0, mOffsetTag);
         }
      }

      return mOffsetTag;
   }

   //---------------------------------------------------------------------------
   /**
    * Returns the extents tag if one exists or else instantiates a new one.
    * @return the extents tag for this transform tag
    */
   private XMLTag getExtents()
   {
      if (null == mExtentsTag)
      {
         // Check if it has been added via addSubtag()...
         mExtentsTag = getOptionalSubtagByName(DmlXML.EXTENTS);
         if (null == mExtentsTag)
         {
            mExtentsTag = new DmlExtents();
            addSubtag(1, mExtentsTag);
         }
      }

      return mExtentsTag;
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy