001package com.hfg.xml.msofficexml.xlsx.spreadsheetml;
002
003
004import com.hfg.graphics.TextUtil;
005import com.hfg.graphics.units.GfxSize;
006import com.hfg.graphics.units.GfxUnits;
007import com.hfg.graphics.units.Points;
008import com.hfg.xml.msofficexml.xlsx.Xlsx;
009
010//------------------------------------------------------------------------------
011/**
012 Represents an Office Open XML sheet format properties (<ssml:sheetFormatPr>) tag.
013
014 @author J. Alex Taylor, hairyfatguy.com
015 */
016//------------------------------------------------------------------------------
017// com.hfg XML/HTML Coding Library
018//
019// This library is free software; you can redistribute it and/or
020// modify it under the terms of the GNU Lesser General Public
021// License as published by the Free Software Foundation; either
022// version 2.1 of the License, or (at your option) any later version.
023//
024// This library is distributed in the hope that it will be useful,
025// but WITHOUT ANY WARRANTY; without even the implied warranty of
026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
027// Lesser General Public License for more details.
028//
029// You should have received a copy of the GNU Lesser General Public
030// License along with this library; if not, write to the Free Software
031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
032//
033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
034// jataylor@hairyfatguy.com
035//------------------------------------------------------------------------------
036
037public class SsmlSheetFormatProperties extends SsmlXMLTag
038{
039
040   //##########################################################################
041   // CONSTRUCTORS
042   //##########################################################################
043
044   //---------------------------------------------------------------------------
045   public SsmlSheetFormatProperties(Xlsx inXlsx)
046   {
047      super(SsmlXML.SHEET_FORMAT_PROPS, inXlsx);
048
049      setDefaults();
050   }
051
052   //---------------------------------------------------------------------------
053   private void setDefaults()
054   {
055      setBaseColWidth(10);
056      setDefaultRowHeight(new Points(13));
057   }
058
059   //##########################################################################
060   // PUBLIC METHODS
061   //##########################################################################
062
063
064   //---------------------------------------------------------------------------
065   /**
066    Specifies the number of characters of the maximum digit width of the normal style's font.
067    This value does not include margin padding or extra padding for gridlines. It is only the number of characters.
068    <div>
069    From 18.3.1.81 of the Ecma-376 Office Open XML specification
070    </div>
071    @param inValue width in number of characters of maximum digit width.
072    @return this properties object to allow method chaining.
073    */
074   public SsmlSheetFormatProperties setBaseColWidth(int inValue)
075   {
076      setAttribute(SsmlXML.BASE_COL_WIDTH_ATT, inValue);
077      return this;
078   }
079
080   //---------------------------------------------------------------------------
081   /**
082    Specifies the number of characters of the maximum digit width of the normal style's font.
083    This value does not include margin padding or extra padding for gridlines. It is only the number of characters.
084    <div>
085    From 18.3.1.81 of the Ecma-376 Office Open XML specification
086    </div>
087    @param inValue width in number of characters of maximum digit width.
088    @return this properties object to allow method chaining.
089    */
090   public SsmlSheetFormatProperties setBaseColWidth(float inValue)
091   {
092      setAttribute(SsmlXML.BASE_COL_WIDTH_ATT, inValue);
093      return this;
094   }
095
096   //---------------------------------------------------------------------------
097   /**
098    Specifies the number of characters of the maximum digit width of the normal style's font.
099    This value does not include margin padding or extra padding for gridlines. It is only the number of characters.
100    <div>
101    From 18.3.1.81 of the Ecma-376 Office Open XML specification
102    </div>
103    @param inValue width in a user-specified system of measure.
104    @return this properties object to allow method chaining.
105    */
106   public SsmlSheetFormatProperties setBaseColWidth(GfxSize inValue)
107   {
108
109      float maxDigitWidth = (float) TextUtil.getStringRect("9", getParentDoc().getStylesPart().getCellFormats().get(0).getFont().toFont()).getWidth();
110
111      // Truncate(({pixels}-5)/{Maximum Digit Width} * 100+0.5)/100
112      float width = (float) Math.nextDown((inValue.to(GfxUnits.pixels) - 5) / maxDigitWidth * 100f + 0.5) / 100f;
113
114      return setBaseColWidth(width);
115   }
116
117
118   //---------------------------------------------------------------------------
119   /**
120    Sets the default column width measured as the number of characters of the maximum digit width of the normal style's font.
121    <div>
122    From 18.3.1.81 of the Ecma-376 Office Open XML specification
123    </div>
124    @param inValue width in number of characters of maximum digit width.
125    @return this properties object to allow method chaining.
126    */
127   public SsmlSheetFormatProperties setDefaultColWidth(int inValue)
128   {
129      setAttribute(SsmlXML.DEFAULT_COL_WIDTH_ATT, inValue);
130      return this;
131   }
132
133   //---------------------------------------------------------------------------
134   /**
135    Sets the default column width measured as the number of characters of the maximum digit width of the normal style's font.
136    <div>
137    From 18.3.1.81 of the Ecma-376 Office Open XML specification
138    </div>
139    @param inValue width in number of characters of maximum digit width.
140    @return this properties object to allow method chaining.
141    */
142   public SsmlSheetFormatProperties setDefaultColWidth(float inValue)
143   {
144      setAttribute(SsmlXML.DEFAULT_COL_WIDTH_ATT, inValue);
145      return this;
146   }
147
148   //---------------------------------------------------------------------------
149   /**
150    Sets the default column width measured as the number of characters of the maximum digit width of the normal style's font.
151    <div>
152    From 18.3.1.81 of the Ecma-376 Office Open XML specification
153    </div>
154    @param inValue width in a user-specified system of measure.
155    @return this properties object to allow method chaining.
156    */
157   public SsmlSheetFormatProperties setDefaultColWidth(GfxSize inValue)
158   {
159      float digitWidth = (float) TextUtil.getStringRect("9", getParentDoc().getStylesPart().getCellFormats().get(0).getFont().toFont()).getWidth();
160
161      float pixels = inValue.to(GfxUnits.pixels) - 5;
162
163      return setDefaultColWidth(pixels / digitWidth);
164   }
165
166
167   //---------------------------------------------------------------------------
168   /**
169    Sets the default row height (in points).
170    <div>
171    From 18.3.1.81 of the Ecma-376 Office Open XML specification
172    </div>
173    @param inValue row height in points.
174    @return this properties object to allow method chaining.
175    */
176   public SsmlSheetFormatProperties setDefaultRowHeight(int inValue)
177   {
178      setAttribute(SsmlXML.DEFAULT_ROW_HEIGHT_ATT, inValue);
179      return this;
180   }
181
182   //---------------------------------------------------------------------------
183   /**
184    Sets the default row height (in points).
185    <div>
186    From 18.3.1.81 of the Ecma-376 Office Open XML specification
187    </div>
188    @param inValue row height in points.
189    @return this properties object to allow method chaining.
190    */
191   public SsmlSheetFormatProperties setDefaultRowHeight(float inValue)
192   {
193      setAttribute(SsmlXML.DEFAULT_ROW_HEIGHT_ATT, inValue);
194      return this;
195   }
196
197   //---------------------------------------------------------------------------
198   /**
199    Sets the default row height.
200    <div>
201    From 18.3.1.81 of the Ecma-376 Office Open XML specification
202    </div>
203    @param inValue height in a user-specified system of measure.
204    @return this properties object to allow method chaining.
205    */
206   public SsmlSheetFormatProperties setDefaultRowHeight(GfxSize inValue)
207   {
208      setAttribute(SsmlXML.DEFAULT_ROW_HEIGHT_ATT, inValue.to(GfxUnits.points));
209
210      return this;
211   }
212
213
214   //---------------------------------------------------------------------------
215   public SsmlSheetFormatProperties setCustomHeight(boolean inValue)
216   {
217      setAttribute(SsmlXML.CUSTOM_HEIGHT_ATT, inValue);
218
219      return this;
220   }
221
222
223   //---------------------------------------------------------------------------
224   public SsmlSheetFormatProperties setZeroHeight(boolean inValue)
225   {
226      setAttribute(SsmlXML.ZERO_HEIGHT_ATT, inValue);
227
228      return this;
229   }
230
231
232   //---------------------------------------------------------------------------
233   public SsmlSheetFormatProperties setThickTop(boolean inValue)
234   {
235      setAttribute(SsmlXML.THICK_TOP_ATT, inValue);
236
237      return this;
238   }
239
240
241   //---------------------------------------------------------------------------
242   public SsmlSheetFormatProperties setThickBottom(boolean inValue)
243   {
244      setAttribute(SsmlXML.THICK_BOTTOM_ATT, inValue);
245
246      return this;
247   }
248}