2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.apache.pdfbox.pdmodel.interactive.measurement;
19 import org.apache.pdfbox.cos.COSBase;
20 import org.apache.pdfbox.cos.COSDictionary;
21 import org.apache.pdfbox.cos.COSName;
22 import org.apache.pdfbox.pdmodel.common.COSObjectable;
25 * This class represents a number format dictionary.
27 * @version $Revision: 1.0$
30 public class PDNumberFormatDictionary implements COSObjectable
34 * The type of the dictionary.
36 public static final String TYPE = "NumberFormat";
39 * Constant indicating that the label specified by U is a suffix to the value.
41 public static final String LABEL_SUFFIX_TO_VALUE = "S";
43 * Constant indicating that the label specified by U is a postfix to the value.
45 public static final String LABEL_PREFIX_TO_VALUE = "P";
48 * Constant for showing a fractional value as decimal to the precision specified by the D entry.
50 public static final String FRACTIONAL_DISPLAY_DECIMAL = "D";
52 * Constant for showing a fractional value as a fraction with denominator specified by the D entry.
54 public static final String FRACTIONAL_DISPLAY_FRACTION = "F";
56 * Constant for showing a fractional value without fractional part; round to the nearest whole unit.
58 public static final String FRACTIONAL_DISPLAY_ROUND = "R";
60 * Constant for showing a fractional value without fractional part; truncate to achieve whole units.
62 public static final String FRACTIONAL_DISPLAY_TRUNCATE = "T";
64 private COSDictionary numberFormatDictionary;
69 public PDNumberFormatDictionary()
71 this.numberFormatDictionary = new COSDictionary();
72 this.numberFormatDictionary.setName(COSName.TYPE, TYPE);
78 * @param dictionary the corresponding dictionary
80 public PDNumberFormatDictionary(COSDictionary dictionary)
82 this.numberFormatDictionary = dictionary;
88 public COSBase getCOSObject()
90 return this.numberFormatDictionary;
94 * This will return the dictionary.
96 * @return the number format dictionary
98 public COSDictionary getDictionary()
100 return this.numberFormatDictionary;
104 * This will return the type of the number format dictionary.
105 * It must be "NumberFormat"
109 public String getType()
115 * This will return the label for the units.
117 * @return the label for the units
119 public String getUnits()
121 return this.getDictionary().getString("U");
125 * This will set the label for the units.
127 * @param units the label for the units
129 public void setUnits(String units)
131 this.getDictionary().setString("U", units);
135 * This will return the conversion factor.
137 * @return the conversion factor
139 public float getConversionFactor()
141 return this.getDictionary().getFloat("C");
145 * This will set the conversion factor.
147 * @param conversionFactor the conversion factor
149 public void setConversionFactor(float conversionFactor)
151 this.getDictionary().setFloat("C", conversionFactor);
155 * This will return the value for the manner to display a fractional value.
157 * @return the manner to display a fractional value
159 public String getFractionalDisplay()
161 return this.getDictionary().getString("F", FRACTIONAL_DISPLAY_DECIMAL);
165 * This will set the value for the manner to display a fractional value.
166 * Allowed values are "D", "F", "R" and "T"
167 * @param fractionalDisplay the manner to display a fractional value
169 public void setFractionalDisplay(String fractionalDisplay)
171 if ((fractionalDisplay == null)
172 || FRACTIONAL_DISPLAY_DECIMAL.equals(fractionalDisplay)
173 || FRACTIONAL_DISPLAY_FRACTION.equals(fractionalDisplay)
174 || FRACTIONAL_DISPLAY_ROUND.equals(fractionalDisplay)
175 || FRACTIONAL_DISPLAY_TRUNCATE.equals(fractionalDisplay))
177 this.getDictionary().setString("F", fractionalDisplay);
181 throw new IllegalArgumentException("Value must be \"D\", \"F\", \"R\", or \"T\", (or null).");
186 * This will return the precision or denominator of a fractional amount.
188 * @return the precision or denominator
190 public int getDenominator()
192 return this.getDictionary().getInt("D");
196 * This will set the precision or denominator of a fractional amount.
198 * @param denominator the precision or denominator
200 public void setDenominator(int denominator)
202 this.getDictionary().setInt("D", denominator);
206 * This will return the value indication if the denominator of the fractional value is reduced/truncated .
210 public boolean isFD()
212 return this.getDictionary().getBoolean("FD", false);
216 * This will set the value indication if the denominator of the fractional value is reduced/truncated .
217 * The denominator may not be reduced/truncated if true
220 public void setFD(boolean fd)
222 this.getDictionary().setBoolean("FD", fd);
226 * This will return the text to be used between orders of thousands in display of numerical values.
228 * @return thousands separator
230 public String getThousandsSeparator()
232 return this.getDictionary().getString("RT", ",");
236 * This will set the text to be used between orders of thousands in display of numerical values.
238 * @param thousandsSeparator thousands separator
240 public void setThousandsSeparator(String thousandsSeparator)
242 this.getDictionary().setString("RT", thousandsSeparator);
246 * This will return the text to be used as the decimal point in displaying numerical values.
248 * @return decimal separator
250 public String getDecimalSeparator()
252 return this.getDictionary().getString("RD", ".");
256 * This will set the text to be used as the decimal point in displaying numerical values.
258 * @param decimalSeparator decimal separator
260 public void setDecimalSeparator(String decimalSeparator)
262 this.getDictionary().setString("RD", decimalSeparator);
266 * This will return the text to be concatenated to the left of the label specified by U.
267 * @return label prefix
269 public String getLabelPrefixString()
271 return this.getDictionary().getString("PS", " ");
275 * This will set the text to be concatenated to the left of the label specified by U.
276 * @param labelPrefixString label prefix
278 public void setLabelPrefixString(String labelPrefixString)
280 this.getDictionary().setString("PS", labelPrefixString);
284 * This will return the text to be concatenated after the label specified by U.
286 * @return label suffix
288 public String getLabelSuffixString()
290 return this.getDictionary().getString("SS", " ");
294 * This will set the text to be concatenated after the label specified by U.
296 * @param labelSuffixString label suffix
298 public void setLabelSuffixString(String labelSuffixString)
300 this.getDictionary().setString("SS", labelSuffixString);
304 * This will return a value indicating the ordering of the label specified by U to the calculated unit value.
306 * @return label position
308 public String getLabelPositionToValue()
310 return this.getDictionary().getString("O", LABEL_SUFFIX_TO_VALUE);
314 * This will set the value indicating the ordering of the label specified by U to the calculated unit value.
315 * Possible values are "S" and "P"
317 * @param labelPositionToValue label position
319 public void setLabelPositionToValue(String labelPositionToValue)
321 if ((labelPositionToValue == null)
322 || LABEL_PREFIX_TO_VALUE.equals(labelPositionToValue)
323 || LABEL_SUFFIX_TO_VALUE.equals(labelPositionToValue))
325 this.getDictionary().setString("O", labelPositionToValue);
329 throw new IllegalArgumentException("Value must be \"S\", or \"P\" (or null).");