Java Code Examples for org.w3c.dom.css.CSSPrimitiveValue#CSS_PERCENTAGE

The following examples show how to use org.w3c.dom.css.CSSPrimitiveValue#CSS_PERCENTAGE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractColorManager.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a color component from a lexical unit.
 */
protected Value createColorComponent( LexicalUnit lu ) throws DOMException
{
	switch ( lu.getLexicalUnitType( ) )
	{
		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 createInvalidRGBComponentUnitDOMException( lu
			.getLexicalUnitType( ) );
}
 
Example 2
Source File: ContainerArea.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: PDFAbstractLM.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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_PT :
				return (int) ( v * 1000 );
			case CSSPrimitiveValue.CSS_NUMBER :
				return (int) v;
			case CSSPrimitiveValue.CSS_PERCENTAGE :

				return (int) ( referenceLength * v/100.0 );
		}
	}
	return 0;
}
 
Example 4
Source File: Layout.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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_PT :
				return (int) ( v * 1000 );
			case CSSPrimitiveValue.CSS_NUMBER :
				return (int) v;
			case CSSPrimitiveValue.CSS_PERCENTAGE :

				return (int) ( referenceLength * v / 100.0 );
		}
	}
	return 0;
}
 
Example 5
Source File: PropertyUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: PropertyUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static float getPercentageValue( CSSValue value )
{
	if ( value != null && ( value instanceof FloatValue ) )
	{
		FloatValue fv = (FloatValue) value;
		float v = fv.getFloatValue( );
		if ( CSSPrimitiveValue.CSS_PERCENTAGE == fv.getPrimitiveType( ) )
		{
			return v / 100.0f;
		}
	}
	return 0.0f;
}
 
Example 7
Source File: FontSizeManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Implements {@link
 * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
 */
public Value computeValue(CSSStylableElement elt, CSSEngine engine,
		int idx, Value value) {
	CSSContext ctx = engine.getCSSContext();

	float fs = ctx.getMediumFontSize();
	// absolute size
	if (value == CSSValueConstants.XX_SMALL_VALUE) {
		return new FloatValue( CSSPrimitiveValue.CSS_PT,
				fs / 1.2f / 1.2f / 1.2f);
	}
	if (value == CSSValueConstants.X_SMALL_VALUE) {
		return new FloatValue( CSSPrimitiveValue.CSS_PT,
				fs / 1.2f / 1.2f);
	}
	if (value == CSSValueConstants.SMALL_VALUE) {
		return new FloatValue( CSSPrimitiveValue.CSS_PT, fs / 1.2f );
	}
	if (value == CSSValueConstants.MEDIUM_VALUE) {
		return new FloatValue( CSSPrimitiveValue.CSS_PT, fs );
	}
	if (value == CSSValueConstants.LARGE_VALUE) {
		return new FloatValue( CSSPrimitiveValue.CSS_PT, fs * 1.2f );
	}
	if (value == CSSValueConstants.X_LARGE_VALUE) {
		return new FloatValue( CSSPrimitiveValue.CSS_PT,
				fs * 1.2f * 1.2f);
	}
	if (value == CSSValueConstants.XX_LARGE_VALUE) {
		return new FloatValue( CSSPrimitiveValue.CSS_PT,
				fs * 1.2f * 1.2f * 1.2f);
	}

	float scale = 1.0f;
	boolean doParentRelative = false;

	// relative size
	if (value == CSSValueConstants.SMALLER_VALUE) {
		doParentRelative = true;
		scale = 1.0f / 1.2f;
	} else if (value == CSSValueConstants.LARGER_VALUE) {
		doParentRelative = true;
		scale = 1.2f;
	} else if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
		// relative length && percentage
		switch (value.getPrimitiveType()) {
		case CSSPrimitiveValue.CSS_EMS:
			doParentRelative = true;
			scale = value.getFloatValue();
			break;
		case CSSPrimitiveValue.CSS_EXS:
			doParentRelative = true;
			scale = value.getFloatValue() * 0.5f;
			break;
		case CSSPrimitiveValue.CSS_PERCENTAGE:
			doParentRelative = true;
			scale = value.getFloatValue() * 0.01f;
			break;
		}
	}
	if (doParentRelative) {
		CSSStylableElement parent = (CSSStylableElement) elt.getParent();
		if (parent != null) {
			IStyle style = parent.getComputedStyle();
			if (style != null) {
				Value fontSize = (Value)style.getProperty(IStyle.STYLE_FONT_SIZE);
				if (fontSize != null) {
					fs = fontSize.getFloatValue();
					return new FloatValue( fontSize.getPrimitiveType( ), fs * scale );
				}
			}
		}
		return new FloatValue( CSSPrimitiveValue.CSS_PT, fs * scale );
	}
	
	if(value.getPrimitiveType() == CSSPrimitiveValue.CSS_NUMBER)
	{
		return super.computeValue( elt, engine, idx, new FloatValue(
				CSSPrimitiveValue.CSS_PT,
				value.getFloatValue()));
	}
	return super.computeValue(elt, engine, idx, value);
}
 
Example 8
Source File: AbstractLengthManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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( ) );
}
 
Example 9
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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, "" );
}