@Test public void parseLength() { Assert.assertEquals(9, css.parsePxInCmMmPcToPt("12"), 0); Assert.assertEquals(576, css.parsePxInCmMmPcToPt("8inch"), 0); Assert.assertEquals(576, css.parsePxInCmMmPcToPt("8", CSS.Value.IN), 0); }
public float parsePxInCmMmPcToPt(final String length, final String defaultMetric) { int pos = determinePositionBetweenValueAndUnit(length); if (pos == 0) return 0f; float f = Float.parseFloat(length.substring(0, pos) + "f"); String unit = length.substring(pos); if (unit.startsWith(CSS.Value.IN) || (unit.equals("") && defaultMetric.equals(CSS.Value.IN))) { f *= 72f; } else if (unit.startsWith(CSS.Value.CM) || (unit.equals("") && defaultMetric.equals(CSS.Value.CM))) { f = (f / 2.54f) * 72f; } else if (unit.startsWith(CSS.Value.MM) || (unit.equals("") && defaultMetric.equals(CSS.Value.MM))) { f = (f / 25.4f) * 72f; } else if (unit.startsWith(CSS.Value.PC) || (unit.equals("") && defaultMetric.equals(CSS.Value.PC))) { f *= 12f; } else if (unit.startsWith(CSS.Value.PX) || (unit.equals("") && defaultMetric.equals(CSS.Value.PX))) { f *= 0.75f; } return f; }
CssUtils { public float parsePxInCmMmPcToPt(final String length, final String defaultMetric) { int pos = determinePositionBetweenValueAndUnit(length); if (pos == 0) return 0f; float f = Float.parseFloat(length.substring(0, pos) + "f"); String unit = length.substring(pos); if (unit.startsWith(CSS.Value.IN) || (unit.equals("") && defaultMetric.equals(CSS.Value.IN))) { f *= 72f; } else if (unit.startsWith(CSS.Value.CM) || (unit.equals("") && defaultMetric.equals(CSS.Value.CM))) { f = (f / 2.54f) * 72f; } else if (unit.startsWith(CSS.Value.MM) || (unit.equals("") && defaultMetric.equals(CSS.Value.MM))) { f = (f / 25.4f) * 72f; } else if (unit.startsWith(CSS.Value.PC) || (unit.equals("") && defaultMetric.equals(CSS.Value.PC))) { f *= 12f; } else if (unit.startsWith(CSS.Value.PX) || (unit.equals("") && defaultMetric.equals(CSS.Value.PX))) { f *= 0.75f; } return f; } }
CssUtils { public float parsePxInCmMmPcToPt(final String length, final String defaultMetric) { int pos = determinePositionBetweenValueAndUnit(length); if (pos == 0) return 0f; float f = Float.parseFloat(length.substring(0, pos) + "f"); String unit = length.substring(pos); if (unit.startsWith(CSS.Value.IN) || (unit.equals("") && defaultMetric.equals(CSS.Value.IN))) { f *= 72f; } else if (unit.startsWith(CSS.Value.CM) || (unit.equals("") && defaultMetric.equals(CSS.Value.CM))) { f = (f / 2.54f) * 72f; } else if (unit.startsWith(CSS.Value.MM) || (unit.equals("") && defaultMetric.equals(CSS.Value.MM))) { f = (f / 25.4f) * 72f; } else if (unit.startsWith(CSS.Value.PC) || (unit.equals("") && defaultMetric.equals(CSS.Value.PC))) { f *= 12f; } else if (unit.startsWith(CSS.Value.PX) || (unit.equals("") && defaultMetric.equals(CSS.Value.PX))) { f *= 0.75f; } return f; } private  CssUtils(); }
CssUtils { public float parsePxInCmMmPcToPt(final String length, final String defaultMetric) { int pos = determinePositionBetweenValueAndUnit(length); if (pos == 0) return 0f; float f = Float.parseFloat(length.substring(0, pos) + "f"); String unit = length.substring(pos); if (unit.startsWith(CSS.Value.IN) || (unit.equals("") && defaultMetric.equals(CSS.Value.IN))) { f *= 72f; } else if (unit.startsWith(CSS.Value.CM) || (unit.equals("") && defaultMetric.equals(CSS.Value.CM))) { f = (f / 2.54f) * 72f; } else if (unit.startsWith(CSS.Value.MM) || (unit.equals("") && defaultMetric.equals(CSS.Value.MM))) { f = (f / 25.4f) * 72f; } else if (unit.startsWith(CSS.Value.PC) || (unit.equals("") && defaultMetric.equals(CSS.Value.PC))) { f *= 12f; } else if (unit.startsWith(CSS.Value.PX) || (unit.equals("") && defaultMetric.equals(CSS.Value.PX))) { f *= 0.75f; } return f; } private  CssUtils(); static CssUtils getInstance(); Map<String, String> parseBoxValues(final java.lang.String box,
                                             final java.lang.String pre, final java.lang.String post); Map<String, String> parseBoxValues(final String box,
                                              final String pre, final String post, String preKey); Map<String, String> parseBorder(final String border); Map<String, String> parseBorder(final String border, final String borderKey); String stripDoubleSpacesAndTrim(final String str); String stripDoubleSpacesTrimAndToLowerCase(final String str); Map<String, String> processBackground(final String background); Map<String, String> processListStyle(final String listStyle); Map<String, String> processFont(final String font); float checkMetricStyle(final Tag t, final String style); Float checkMetricStyle(final Map<String,String> css, final String style); boolean isMetricValue(final String value); boolean isRelativeValue(final String value); boolean isNumericValue(final String value); float parseValueToPt(final String value, final float baseValue); float parseRelativeValue(final String relativeValue, final float baseValue); float parsePxInCmMmPcToPt(final String length, final String defaultMetric); float parsePxInCmMmPcToPt(final String length); int determinePositionBetweenValueAndUnit(final String string); float getLeftAndRightMargin(final Tag t, final float pageWidth); String extractUrl(final String url); float validateTextHeight(final Map<String, String> css,
			float textHeight); float calculateMarginTop(final String value, final float largestFont, final MarginMemory configuration); float calculateMarginTop(final float value, final MarginMemory configuration); String trimAndRemoveQuoutes(String s); String[] splitComplexCssStyle(String s); }
CssUtils { public float parsePxInCmMmPcToPt(final String length, final String defaultMetric) { int pos = determinePositionBetweenValueAndUnit(length); if (pos == 0) return 0f; float f = Float.parseFloat(length.substring(0, pos) + "f"); String unit = length.substring(pos); if (unit.startsWith(CSS.Value.IN) || (unit.equals("") && defaultMetric.equals(CSS.Value.IN))) { f *= 72f; } else if (unit.startsWith(CSS.Value.CM) || (unit.equals("") && defaultMetric.equals(CSS.Value.CM))) { f = (f / 2.54f) * 72f; } else if (unit.startsWith(CSS.Value.MM) || (unit.equals("") && defaultMetric.equals(CSS.Value.MM))) { f = (f / 25.4f) * 72f; } else if (unit.startsWith(CSS.Value.PC) || (unit.equals("") && defaultMetric.equals(CSS.Value.PC))) { f *= 12f; } else if (unit.startsWith(CSS.Value.PX) || (unit.equals("") && defaultMetric.equals(CSS.Value.PX))) { f *= 0.75f; } return f; } private  CssUtils(); static CssUtils getInstance(); Map<String, String> parseBoxValues(final java.lang.String box,
                                             final java.lang.String pre, final java.lang.String post); Map<String, String> parseBoxValues(final String box,
                                              final String pre, final String post, String preKey); Map<String, String> parseBorder(final String border); Map<String, String> parseBorder(final String border, final String borderKey); String stripDoubleSpacesAndTrim(final String str); String stripDoubleSpacesTrimAndToLowerCase(final String str); Map<String, String> processBackground(final String background); Map<String, String> processListStyle(final String listStyle); Map<String, String> processFont(final String font); float checkMetricStyle(final Tag t, final String style); Float checkMetricStyle(final Map<String,String> css, final String style); boolean isMetricValue(final String value); boolean isRelativeValue(final String value); boolean isNumericValue(final String value); float parseValueToPt(final String value, final float baseValue); float parseRelativeValue(final String relativeValue, final float baseValue); float parsePxInCmMmPcToPt(final String length, final String defaultMetric); float parsePxInCmMmPcToPt(final String length); int determinePositionBetweenValueAndUnit(final String string); float getLeftAndRightMargin(final Tag t, final float pageWidth); String extractUrl(final String url); float validateTextHeight(final Map<String, String> css,
			float textHeight); float calculateMarginTop(final String value, final float largestFont, final MarginMemory configuration); float calculateMarginTop(final float value, final MarginMemory configuration); String trimAndRemoveQuoutes(String s); String[] splitComplexCssStyle(String s); static final int DEFAULT_FONT_SIZE_PT; }