LibreOffice Module xmerge (master) 1
TwipsConverter.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19package org.openoffice.xmerge.util;
20
24public class TwipsConverter {
25
33 public static float twips2cm(int value) {
34 float inches = (float) value/1440;
35 float cm = inches*(float)2.54;
36 return cm;
37 }
38
46 private static int cm2twips(float value) {
47 int twips = (int) ((value/2.54)*1440);
48 return twips;
49 }
50
58 private static int inches2twips(float value) {
59 return (int) (value*1440);
60 }
61
71 public static int convert2twips(String value, int defaultValue) {
72 int posi;
73
74 if ((posi = value.indexOf("cm")) != -1) {
75 float cm = Float.parseFloat(value.substring(0,posi));
76 return cm2twips(cm);
77 } else if ((posi = value.indexOf("inch")) != -1) {
78 float inches = Float.parseFloat(value.substring(0,posi));
79 return inches2twips(inches);
80 }
81
82 return defaultValue;
83 }
84}
Helper class providing static methods to convert data to/from twips.
static int convert2twips(String value, int defaultValue)
Convert String to twips.
static int inches2twips(float value)
Convert from cm's to twips.
static float twips2cm(int value)
Convert from twips to cm's.
static int cm2twips(float value)
Convert from cm's to twips.
Any value
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int