Here you can find the source of getFontSizeInPoints(String fontSizeWithUnit)
public static Integer getFontSizeInPoints(String fontSizeWithUnit)
//package com.java2s; /*/*from ww w.ja va 2s . co m*/ * (c) Copyright 2010-2011 AgileBirds * * This file is part of OpenFlexo. * * OpenFlexo is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * OpenFlexo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with OpenFlexo. If not, see <http://www.gnu.org/licenses/>. * */ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.ParsePosition; public class Main { public static Integer getFontSizeInPoints(String fontSizeWithUnit) { fontSizeWithUnit = fontSizeWithUnit.trim(); DecimalFormat formatter = new DecimalFormat(); DecimalFormatSymbols formatterSymbol = new DecimalFormatSymbols(); formatterSymbol.setDecimalSeparator('.'); formatter.setDecimalFormatSymbols(formatterSymbol); ParsePosition position = new ParsePosition(0); Number size = formatter.parse(fontSizeWithUnit, position); if (size == null) return null; String unit = "px"; if (position.getIndex() < fontSizeWithUnit.length()) unit = fontSizeWithUnit.substring(position.getIndex()).trim().toLowerCase(); if ("px".equals(unit)) return new Double(size.doubleValue() * (92 / 72)).intValue(); //Round to transform px to points, 92 dpi usually, 1 inch = 72 points if ("pt".equals(unit)) return new Double(size.doubleValue()).intValue(); //Don't handle % or em return null; } }