public double ptLength ( TermLengthOrPercent spec , double whole ) { float nval = spec . getValue ( ) ; if ( spec . isPercentage ( ) ) { return ( whole * nval ) / 100 ; } else if ( spec instanceof TermCalc ) { final CalcArgs args = ( ( TermCalc ) spec ) . getArgs ( ) ; return args . evaluate ( getPtEval ( ) . setWhole ( whole ) ) ; } else { final TermLength . Unit unit = spec . getUnit ( ) ; if ( unit == null ) return 0 ; switch ( unit ) { case pt : return nval ; case in : return nval * 72 ; case cm : return ( nval * 72 ) / 2.54 ; case mm : return ( nval * 72 ) / 25.4 ; case q : return ( nval * 72 ) / ( 2.54 * 40.0 ) ; case pc : return nval * 12 ; case px : return ( nval * 72 ) / dpi ; case em : return ( em * nval * 72 ) / dpi ; //em is in pixels case rem : return ( rem * nval * 72 ) / dpi ; case ex : return ( ex * nval * 72 ) / dpi ; case ch : return ( ch * nval * 72 ) / dpi ; case vw : return ( viewport . getVisibleRect ( ) . getWidth ( ) * nval * 72 ) / ( 100.0 * dpi ) ; case vh : return ( viewport . getVisibleRect ( ) . getHeight ( ) * nval * 72 ) / ( 100.0 * dpi ) ; case vmin : return ( Math . min ( viewport . getVisibleRect ( ) . getWidth ( ) , viewport . getVisibleRect ( ) . getHeight ( ) ) * nval * 72 ) / ( 100.0 * dpi ) ; case vmax : return ( Math . max ( viewport . getVisibleRect ( ) . getWidth ( ) , viewport . getVisibleRect ( ) . getHeight ( ) ) * nval * 72 ) / ( 100.0 * dpi ) ; default : return 0 ; } } }
Converts a length from a CSS length or percentage to pt .