public static float parseLength ( String string ) { // TODO: Evaluate the effect of this. // It may change the default behavour of the methd if this is changed. // return parseLength(string, Markup.DEFAULT_FONT_SIZE); int pos = 0 ; int length = string . length ( ) ; boolean ok = true ; while ( ok && pos < length ) { switch ( string . charAt ( pos ) ) { case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : pos ++ ; break ; default : ok = false ; } } if ( pos == 0 ) return 0f ; if ( pos == length ) return Float . parseFloat ( string + "f" ) ; float f = Float . parseFloat ( string . substring ( 0 , pos ) + "f" ) ; string = string . substring ( pos ) ; // inches if ( string . startsWith ( "in" ) ) { return f * 72f ; } // centimeters if ( string . startsWith ( "cm" ) ) { return ( f / 2.54f ) * 72f ; } // millimeters if ( string . startsWith ( "mm" ) ) { return ( f / 25.4f ) * 72f ; } // picas if ( string . startsWith ( "pc" ) ) { return f * 12f ; } // default: we assume the length was measured in points return f ; }
Parses a length .