下面列出了org.w3c.dom.css.CSSPrimitiveValue#CSS_PC 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Converts the current value into centimeters.
*/
protected static float toCentimeters( int type, float value )
{
switch ( type )
{
case CSSPrimitiveValue.CSS_CM :
return value;
case CSSPrimitiveValue.CSS_MM :
return ( value / 10 );
case CSSPrimitiveValue.CSS_IN :
return ( value * 2.54f );
case CSSPrimitiveValue.CSS_PT :
return ( value * 2.54f / 72 );
case CSSPrimitiveValue.CSS_PC :
return ( value * 2.54f / 6 );
default :
throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
}
}
/**
* Converts the current value into inches.
*/
protected static float toInches( int type, float value )
{
switch ( type )
{
case CSSPrimitiveValue.CSS_CM :
return ( value / 2.54f );
case CSSPrimitiveValue.CSS_MM :
return ( value / 25.4f );
case CSSPrimitiveValue.CSS_IN :
return value;
case CSSPrimitiveValue.CSS_PT :
return ( value / 72 );
case CSSPrimitiveValue.CSS_PC :
return ( value / 6 );
default :
throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
}
}
/**
* Converts the current value into millimeters.
*/
protected static float toMillimeters( int unit, float value )
{
switch ( unit )
{
case CSSPrimitiveValue.CSS_CM :
return ( value * 10 );
case CSSPrimitiveValue.CSS_MM :
return value;
case CSSPrimitiveValue.CSS_IN :
return ( value * 25.4f );
case CSSPrimitiveValue.CSS_PT :
return ( value * 25.4f / 72 );
case CSSPrimitiveValue.CSS_PC :
return ( value * 25.4f / 6 );
default :
throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
}
}
/**
* Converts the current value into points.
*/
protected static float toPoints( int unit, float value )
{
switch ( unit )
{
case CSSPrimitiveValue.CSS_CM :
return ( value * 72 / 2.54f );
case CSSPrimitiveValue.CSS_MM :
return ( value * 72 / 25.4f );
case CSSPrimitiveValue.CSS_IN :
return ( value * 72 );
case CSSPrimitiveValue.CSS_PT :
return value;
case CSSPrimitiveValue.CSS_PC :
return ( value * 12 );
default :
throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
}
}
/**
* Converts the current value into picas.
*/
protected static float toPicas( int unit, float value )
{
switch ( unit )
{
case CSSPrimitiveValue.CSS_CM :
return ( value * 6 / 2.54f );
case CSSPrimitiveValue.CSS_MM :
return ( value * 6 / 25.4f );
case CSSPrimitiveValue.CSS_IN :
return ( value * 6 );
case CSSPrimitiveValue.CSS_PT :
return ( value / 12 );
case CSSPrimitiveValue.CSS_PC :
return value;
default :
throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
}
}
private int getSize( CSSValue value )
{
// Copied from
// org.eclipse.birt.report.engine.layout.pdf.util.PropertyUtil.getDimensionValueConsiderDpi()
if ( value != null && ( value instanceof FloatValue ) )
{
FloatValue fv = (FloatValue) value;
float v = fv.getFloatValue( );
switch ( fv.getPrimitiveType( ) )
{
case CSSPrimitiveValue.CSS_CM :
return (int) ( v * 72 / 2.54 );
case CSSPrimitiveValue.CSS_IN :
return (int) ( v * 72 );
case CSSPrimitiveValue.CSS_MM :
return (int) ( v * 7.2 / 2.54 );
case CSSPrimitiveValue.CSS_PC :
return (int) ( v * 12 );
case CSSPrimitiveValue.CSS_PX :
return (int) ( v / dpi * 72f );
case CSSPrimitiveValue.CSS_PT :
return (int) v;
case CSSPrimitiveValue.CSS_NUMBER :
return (int) ( v / 1000 );
}
}
return 0;
}
/**
* Returns the dimension value in inches.
*/
public static double getDimensionValue( CSSValue value, int dpi )
{
if ( value != null && ( value instanceof FloatValue ) )
{
FloatValue fv = (FloatValue) value;
float v = fv.getFloatValue( );
switch ( fv.getPrimitiveType( ) )
{
case CSSPrimitiveValue.CSS_CM :
return ( v / 2.54 );
case CSSPrimitiveValue.CSS_IN :
return ( v );
case CSSPrimitiveValue.CSS_MM :
return ( v / 25.4 );
case CSSPrimitiveValue.CSS_PC :
return ( v * 12 * 1000 );
case CSSPrimitiveValue.CSS_PX :
return ( v / dpi );
case CSSPrimitiveValue.CSS_PT :
return ( v / 72 );
case CSSPrimitiveValue.CSS_NUMBER :
return v;
}
}
return 0;
}
/**
* Implements {@link
* ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
*/
public Value computeValue( CSSStylableElement elt, CSSEngine engine,
int idx, Value value )
{
if ( value.getCssValueType( ) == CSSValue.CSS_PRIMITIVE_VALUE )
{
switch ( value.getPrimitiveType( ) )
{
case CSSPrimitiveValue.CSS_NUMBER :
case CSSPrimitiveValue.CSS_PX :
case CSSPrimitiveValue.CSS_MM :
case CSSPrimitiveValue.CSS_CM :
case CSSPrimitiveValue.CSS_IN :
case CSSPrimitiveValue.CSS_PT :
case CSSPrimitiveValue.CSS_PC :
return value;
case CSSPrimitiveValue.CSS_EMS :
float v = value.getFloatValue( );
Value fontSize = (Value) elt.getComputedStyle( )
.getProperty( IStyle.STYLE_FONT_SIZE );
float fs = fontSize.getFloatValue( );
return new FloatValue( fontSize.getPrimitiveType( ), v * fs );
case CSSPrimitiveValue.CSS_EXS :
v = value.getFloatValue( );
fontSize = (Value) elt.getComputedStyle( )
.getProperty( IStyle.STYLE_FONT_SIZE );
fs = fontSize.getFloatValue( );
return new FloatValue( fontSize.getPrimitiveType( ), v
* fs * 0.5f );
}
}
return value;
}
protected int getDimensionValue( CSSValue value, int referenceLength )
{
if ( value != null && ( value instanceof FloatValue ) )
{
FloatValue fv = (FloatValue) value;
float v = fv.getFloatValue( );
switch ( fv.getPrimitiveType( ) )
{
case CSSPrimitiveValue.CSS_CM :
return (int) ( v * 72000 / 2.54 );
case CSSPrimitiveValue.CSS_IN :
return (int) ( v * 72000 );
case CSSPrimitiveValue.CSS_MM :
return (int) ( v * 7200 / 2.54 );
case CSSPrimitiveValue.CSS_PC :
return (int) ( v * 12 * 1000 );
case CSSPrimitiveValue.CSS_PX :
float dpi = getResolution( );
return (int) ( v / dpi * 72000f );
case CSSPrimitiveValue.CSS_PT :
return (int) ( v * 1000 );
case CSSPrimitiveValue.CSS_NUMBER :
return (int) v;
case CSSPrimitiveValue.CSS_PERCENTAGE :
return (int) ( referenceLength * v / 100.0 );
}
}
return 0;
}
public static int getDimensionValueConsiderDpi( CSSValue value,
IContent content )
{
if ( value != null && ( value instanceof FloatValue ) )
{
FloatValue fv = (FloatValue) value;
float v = fv.getFloatValue( );
switch ( fv.getPrimitiveType( ) )
{
case CSSPrimitiveValue.CSS_CM :
return (int) ( v * 72000 / 2.54 );
case CSSPrimitiveValue.CSS_IN :
return (int) ( v * 72000 );
case CSSPrimitiveValue.CSS_MM :
return (int) ( v * 7200 / 2.54 );
case CSSPrimitiveValue.CSS_PC :
return (int) ( v * 12 * 1000 );
case CSSPrimitiveValue.CSS_PX :
ReportDesignHandle designHandle = content
.getReportContent( ).getDesign( ).getReportDesign( );
int dpi = designHandle.getImageDPI( );
if ( dpi == 0 )
{
dpi = 96;
}
return (int) ( v / dpi * 72000f );
case CSSPrimitiveValue.CSS_PT :
return (int) ( v * 1000 );
case CSSPrimitiveValue.CSS_NUMBER :
return (int) v;
}
}
return 0;
}
private static int getDimensionValue( CSSValue value, int dpi,
int referenceLength )
{
if ( value != null && ( value instanceof FloatValue ) )
{
FloatValue fv = (FloatValue) value;
float v = fv.getFloatValue( );
switch ( fv.getPrimitiveType( ) )
{
case CSSPrimitiveValue.CSS_CM :
return (int) ( v * 72000 / 2.54 );
case CSSPrimitiveValue.CSS_IN :
return (int) ( v * 72000 );
case CSSPrimitiveValue.CSS_MM :
return (int) ( v * 7200 / 2.54 );
case CSSPrimitiveValue.CSS_PC :
return (int) ( v * 12 * 1000 );
case CSSPrimitiveValue.CSS_PX :
return (int) ( v / dpi * 72000f );
case CSSPrimitiveValue.CSS_PT :
return (int) ( v * 1000 );
case CSSPrimitiveValue.CSS_NUMBER :
return (int) v;
case CSSPrimitiveValue.CSS_PERCENTAGE :
return (int) ( referenceLength * v / 100.0 );
}
}
return 0;
}
/**
* Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
*/
public Value createValue( LexicalUnit lu, CSSEngine engine )
throws DOMException
{
switch ( lu.getLexicalUnitType( ) )
{
case LexicalUnit.SAC_EM :
return new FloatValue( CSSPrimitiveValue.CSS_EMS, lu
.getFloatValue( ) );
case LexicalUnit.SAC_EX :
return new FloatValue( CSSPrimitiveValue.CSS_EXS, lu
.getFloatValue( ) );
case LexicalUnit.SAC_PIXEL :
return new FloatValue( CSSPrimitiveValue.CSS_PX, lu
.getFloatValue( ) );
case LexicalUnit.SAC_CENTIMETER :
return new FloatValue( CSSPrimitiveValue.CSS_CM, lu
.getFloatValue( ) );
case LexicalUnit.SAC_MILLIMETER :
return new FloatValue( CSSPrimitiveValue.CSS_MM, lu
.getFloatValue( ) );
case LexicalUnit.SAC_INCH :
return new FloatValue( CSSPrimitiveValue.CSS_IN, lu
.getFloatValue( ) );
case LexicalUnit.SAC_POINT :
return new FloatValue( CSSPrimitiveValue.CSS_PT, lu
.getFloatValue( ) );
case LexicalUnit.SAC_PICA :
return new FloatValue( CSSPrimitiveValue.CSS_PC, lu
.getFloatValue( ) );
case LexicalUnit.SAC_INTEGER :
return new FloatValue( CSSPrimitiveValue.CSS_NUMBER, lu
.getIntegerValue( ) );
case LexicalUnit.SAC_REAL :
return new FloatValue( CSSPrimitiveValue.CSS_NUMBER, lu
.getFloatValue( ) );
case LexicalUnit.SAC_PERCENTAGE :
return new FloatValue( CSSPrimitiveValue.CSS_PERCENTAGE, lu
.getFloatValue( ) );
}
throw createInvalidLexicalUnitDOMException( lu.getLexicalUnitType( ) );
}
/**
* Converts the actual float value to the given unit type.
*/
public static float convertFloatValue( short unitType, FloatValue value )
{
switch ( unitType )
{
case CSSPrimitiveValue.CSS_NUMBER :
case CSSPrimitiveValue.CSS_PERCENTAGE :
case CSSPrimitiveValue.CSS_EMS :
case CSSPrimitiveValue.CSS_EXS :
case CSSPrimitiveValue.CSS_DIMENSION :
case CSSPrimitiveValue.CSS_PX :
if ( value.getPrimitiveType( ) == unitType )
{
return value.getFloatValue( );
}
break;
case CSSPrimitiveValue.CSS_CM :
return toCentimeters( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_MM :
return toMillimeters( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_IN :
return toInches( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_PT :
return toPoints( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_PC :
return toPicas( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_DEG :
return toDegrees( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_RAD :
return toRadians( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_GRAD :
return toGradians( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_MS :
return toMilliseconds( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_S :
return toSeconds( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_HZ :
return toHertz( unitType, value.getFloatValue( ) );
case CSSPrimitiveValue.CSS_KHZ :
return tokHertz( unitType, value.getFloatValue( ) );
}
throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
}