1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.xmerge.util; 25 26 27 /** 28 * <p>Helper class providing static methods to convert data to/from 29 * twips</p> 30 * 31 * @author Martin Maher 32 */ 33 public class TwipsConverter { 34 35 /** 36 * <p>Convert from twips to cm's</p> 37 * 38 * @param value The <code>short</code> to be converted. 39 * 40 * @return float containing the converted 41 */ twips2cm(int value)42 public static float twips2cm(int value) { 43 44 float inches = (float) value/1440; 45 float cm = (float) inches*(float)2.54; 46 47 return cm; 48 } 49 50 51 52 /** 53 * <p>Convert from cm's to twips</p> 54 * 55 * @param value <code>byte</code> array containing the LE representation 56 * of the value. 57 * 58 * @return int containing the converted value. 59 */ cm2twips(float value)60 public static int cm2twips(float value) { 61 62 int twips = (int) ((value/2.54)*1440); 63 64 return twips; 65 } 66 67 /** 68 * <p>Convert from twips to cm's</p> 69 * 70 * @param value The <code>short</code> to be converted. 71 * 72 * @return float containing the converted 73 */ twips2inches(int value)74 public static float twips2inches(int value) { 75 76 return (float) value/1440; 77 } 78 79 80 81 /** 82 * <p>Convert from cm's to twips</p> 83 * 84 * @param value <code>byte</code> array containing the LE representation 85 * of the value. 86 * 87 * @return int containing the converted value. 88 */ inches2twips(float value)89 public static int inches2twips(float value) { 90 91 return (int) (value*1440); 92 } 93 94 95 } 96