Java Code Examples for org.w3c.dom.css.CSSPrimitiveValue#CSS_EMS
The following examples show how to use
org.w3c.dom.css.CSSPrimitiveValue#CSS_EMS .
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: AbstractLengthManager.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * 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; }
Example 2
Source File: FontSizeManager.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * 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 3
Source File: AbstractLengthManager.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * 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 4
Source File: FloatValue.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * 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, "" ); }