Java Code Examples for org.w3c.css.sac.LexicalUnit#SAC_PERCENTAGE

The following examples show how to use org.w3c.css.sac.LexicalUnit#SAC_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: OverflowClipReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static CSSRectangleValue getRectangle
  ( CSSRectangleType type, LexicalUnit value ) {
  final CSSNumericValue[] list = new CSSNumericValue[ 4 ];
  for ( int index = 0; index < 4; index++ ) {
    if ( value == null ) {
      return null;
    }
    CSSNumericValue nval = CSSValueFactory.createLengthValue( value );
    if ( nval != null ) {
      list[ index ] = nval;
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
      list[ index ] = CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
    } else {
      return null;
    }
    value = CSSValueFactory.parseComma( value );
  }

  return new CSSRectangleValue( type, list[ 0 ], list[ 1 ], list[ 2 ], list[ 3 ] );
}
 
Example 2
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 3
Source File: CropReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static CSSRectangleValue getRectangle
  ( CSSRectangleType type, LexicalUnit value ) {
  final CSSNumericValue[] list = new CSSNumericValue[ 4 ];
  for ( int index = 0; index < 4; index++ ) {
    if ( value == null ) {
      return null;
    }
    CSSNumericValue nval = CSSValueFactory.createLengthValue( value );
    if ( nval != null ) {
      list[ index ] = nval;
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
      list[ index ] = CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
    } else {
      return null;
    }
    value = CSSValueFactory.parseComma( value );
  }

  return new CSSRectangleValue( type, list[ 0 ], list[ 1 ], list[ 2 ], list[ 3 ] );
}
 
Example 4
Source File: TextIndentReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {

    CSSValue cssvalue = null;
    if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
      cssvalue = CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
    } else {
      cssvalue = CSSValueFactory.createLengthValue( value );
    }

    value = value.getNextLexicalUnit();
    if ( value != null ) {
      if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
        return null;
      }
      if ( value.getStringValue().equalsIgnoreCase( "hanging" ) ) {
        return new CSSValueList( new CSSValue[] { cssvalue, new CSSConstant( "hanging" ) } );
      } else {
        return null;
      }
    }

    return new CSSValueList( new CSSValue[] { cssvalue } );
  }
 
Example 5
Source File: SpacingLimitReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private CSSValue parseSingleSpacingValue( final LexicalUnit value ) {
  if ( value == null ) {
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( value.getStringValue().equalsIgnoreCase( "normal" ) ) {
      return SpacingLimitReadHandler.NORMAL;
    }
    return null;
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }

  return CSSValueFactory.createLengthValue( value );
}
 
Example 6
Source File: AbstractWidthReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseWidth( final LexicalUnit value ) {
  if ( allowPercentages &&
    value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  } else if ( allowAuto &&
    value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) {
      return CSSAutoValue.getInstance();
    }
    return null;
  } else {
    return CSSValueFactory.createLengthValue( value );
  }
}
 
Example 7
Source File: FitPositionReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseSecondPosition( final LexicalUnit value,
                                        final CSSValue firstValue ) {
  if ( value == null ) {
    return CENTER;
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( "left".equalsIgnoreCase( value.getStringValue() ) ) {
      return LEFT;
    } else if ( "center".equalsIgnoreCase( value.getStringValue() ) ) {
      return CENTER;
    } else if ( "right".equalsIgnoreCase( value.getStringValue() ) ) {
      return RIGHT;
    } else if ( "top".equalsIgnoreCase( value.getStringValue() ) ) {
      return TOP;
    } else if ( "bottom".equalsIgnoreCase( value.getStringValue() ) ) {
      return BOTTOM;
    }
    return null; // ignore this rule, it contains errors.
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  } else if ( CSSValueFactory.isLengthValue( value ) ) {
    return CSSValueFactory.createLengthValue( value );
  }
  return CENTER;
}
 
Example 8
Source File: FitPositionReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseFirstPosition( final LexicalUnit value ) {
  if ( value == null ) {
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( "left".equalsIgnoreCase( value.getStringValue() ) ) {
      return LEFT;
    } else if ( "center".equalsIgnoreCase( value.getStringValue() ) ) {
      return CENTER;
    } else if ( "right".equalsIgnoreCase( value.getStringValue() ) ) {
      return RIGHT;
    } else if ( "top".equalsIgnoreCase( value.getStringValue() ) ) {
      return TOP;
    } else if ( "bottom".equalsIgnoreCase( value.getStringValue() ) ) {
      return BOTTOM;
    }

    // ignore this rule.
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }
  if ( CSSValueFactory.isLengthValue( value ) ) {
    return CSSValueFactory.createLengthValue( value );
  }
  // contains errors, we ignore this rule.
  return null;
}
 
Example 9
Source File: ColumnGapReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) {
      return CSSAutoValue.getInstance();
    }
    return null;
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
  }
  return CSSValueFactory.createLengthValue( value );
}
 
Example 10
Source File: VerticalAlignReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue lookupValue( final LexicalUnit value ) {
  CSSValue constant = super.lookupValue( value );
  if ( constant != null ) {
    return constant;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }

  return CSSValueFactory.createLengthValue( value );
}
 
Example 11
Source File: AlignmentAdjustReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue lookupValue( final LexicalUnit value ) {
  CSSValue constant = super.lookupValue( value );
  if ( constant != null ) {
    return constant;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }

  return CSSValueFactory.createLengthValue( value );

}
 
Example 12
Source File: BaselineShiftReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue lookupValue( final LexicalUnit value ) {
  CSSValue constant = super.lookupValue( value );
  if ( constant != null ) {
    return constant;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }

  return CSSValueFactory.createLengthValue( value );

}
 
Example 13
Source File: DropInitialAfterAdjustReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue lookupValue( final LexicalUnit value ) {
  CSSValue constant = super.lookupValue( value );
  if ( constant != null ) {
    return constant;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }

  return CSSValueFactory.createLengthValue( value );

}
 
Example 14
Source File: DropInitialSizeReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) {
      return CSSAutoValue.getInstance();
    }
    return null;
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) {
    return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() );
  }
  return CSSValueFactory.createLengthValue( value );
}
 
Example 15
Source File: BackgroundPositionReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseSecondPosition( final LexicalUnit value,
                                        final CSSValue firstValue ) {
  if ( value == null ) {
    return CENTER;
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( "left".equalsIgnoreCase( value.getStringValue() ) ) {
      return LEFT;
    } else if ( "center".equalsIgnoreCase( value.getStringValue() ) ) {
      return CENTER;
    } else if ( "right".equalsIgnoreCase( value.getStringValue() ) ) {
      return RIGHT;
    } else if ( "top".equalsIgnoreCase( value.getStringValue() ) ) {
      return TOP;
    } else if ( "bottom".equalsIgnoreCase( value.getStringValue() ) ) {
      return BOTTOM;
    }
    return null; // ignore this rule, it contains errors.
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  } else if ( CSSValueFactory.isLengthValue( value ) ) {
    return CSSValueFactory.createLengthValue( value );
  }
  return CENTER;
}
 
Example 16
Source File: FontSizeReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue lookupValue( final LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
  }
  CSSValue constant = super.lookupValue( value );
  if ( constant != null ) {
    return constant;
  }
  return CSSValueFactory.createLengthValue( value );
}
 
Example 17
Source File: TextKashidaSpaceReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  if ( value.getLexicalUnitType() != LexicalUnit.SAC_PERCENTAGE ) {
    return null;
  }
  return CSSNumericValue.createValue
    ( CSSNumericType.PERCENTAGE, value.getFloatValue() );
}
 
Example 18
Source File: BackgroundPositionReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseFirstPosition( final LexicalUnit value ) {
  if ( value == null ) {
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( "left".equalsIgnoreCase( value.getStringValue() ) ) {
      return LEFT;
    } else if ( "center".equalsIgnoreCase( value.getStringValue() ) ) {
      return CENTER;
    } else if ( "right".equalsIgnoreCase( value.getStringValue() ) ) {
      return RIGHT;
    } else if ( "top".equalsIgnoreCase( value.getStringValue() ) ) {
      return TOP;
    } else if ( "bottom".equalsIgnoreCase( value.getStringValue() ) ) {
      return BOTTOM;
    }

    // ignore this rule.
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }
  if ( CSSValueFactory.isLengthValue( value ) ) {
    return CSSValueFactory.createLengthValue( value );
  }
  // contains errors, we ignore this rule.
  return null;
}
 
Example 19
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 20
Source File: BackgroundSizeReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  ArrayList values = new ArrayList();

  while ( value != null ) {
    CSSValue firstValue;
    if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
      if ( value.getStringValue().equalsIgnoreCase( "round" ) ) {
        values.add( createList( CSSAutoValue.getInstance(),
          CSSAutoValue.getInstance(),
          BackgroundSize.ROUND ) );

        value = CSSValueFactory.parseComma( value );
        continue;
      }

      if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) {
        firstValue = CSSAutoValue.getInstance();
      } else {
        return null;
      }
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
      firstValue = CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
    } else {
      firstValue = CSSValueFactory.createLengthValue( value );
      if ( firstValue == null ) {
        return null;
      }
    }

    value = value.getNextLexicalUnit();
    if ( value == null ) {
      values.add( createList( firstValue,
        CSSAutoValue.getInstance(),
        BackgroundSize.ROUND ) );
      continue;
    }

    CSSValue secondValue;
    if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
      if ( value.getStringValue().equalsIgnoreCase( "round" ) ) {
        values.add( createList( firstValue,
          CSSAutoValue.getInstance(),
          BackgroundSize.ROUND ) );
        value = CSSValueFactory.parseComma( value );
        continue;
      } else if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) {
        secondValue = CSSAutoValue.getInstance();
      } else {
        return null;
      }
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA ) {
      values.add( createList( firstValue,
        CSSAutoValue.getInstance(),
        BackgroundSize.ROUND ) );
      value = value.getNextLexicalUnit();
      continue;
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
      secondValue = CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
    } else {
      secondValue = CSSValueFactory.createLengthValue( value );
      if ( secondValue == null ) {
        return null;
      }
    }

    value = value.getNextLexicalUnit();
    if ( value == null ) {
      values.add( createList( firstValue,
        secondValue,
        BackgroundSize.NO_ROUND ) );
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA ) {
      values.add( createList( firstValue,
        secondValue,
        BackgroundSize.NO_ROUND ) );
      value = value.getNextLexicalUnit();
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
      if ( value.getStringValue().equalsIgnoreCase( "round" ) == false ) {
        return null;
      }
      values.add( createList( firstValue,
        secondValue,
        BackgroundSize.ROUND ) );
      value = CSSValueFactory.parseComma( value );
    } else {
      return null;
    }
  }

  return new CSSValueList( values );
}