下面列出了怎么用org.w3c.dom.css.CSSValue的API类实例代码及写法,或者点击链接到github查看源代码。
private void applyCSSPropertyFont(final Object element, final Grid grid, final CSSValue value, String target) throws Exception {
if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
final CSSValueList valueList = (CSSValueList) value;
final int length = valueList.getLength();
for (int i = 0; i < length; i++) {
final CSSValue value2 = valueList.item(i);
if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
final String cssProp = CSS2FontHelper.getCSSFontPropertyName((CSSPrimitiveValue) value2);
if (cssProp.equals("font-family")) {
applyCSSPropertyFamily(element, grid, value2, target);
} else if (cssProp.equals("font-size")) {
applyCSSPropertySize(element, grid, value2, target);
} else if (cssProp.equals("font-weight") && ("bold".equals(value2.getCssText()) || "bolder".equals(value2.getCssText()))) {
applyCSSPropertyWeight(element, grid, value2, target);
} else if (cssProp.equals("font-style") && ("italic".equals(value2.getCssText()) || "oblique".equals(value2.getCssText()))) {
applyCSSPropertyStyle(element, grid, value2, target);
}
}
}
}
}
private boolean applyCSSPropertyWeight(final Object element, final Grid grid, final CSSValue value, String target) throws Exception {
if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
final FontData fd = CSSEngineHelper.getFontData(grid);
boolean modified = false;
if ("bold".equals(value.getCssText()) || "bolder".equals(value.getCssText())) {
modified = (fd.getStyle() & SWT.BOLD) != SWT.BOLD;
if (modified) {
fd.setStyle(fd.getStyle() | SWT.BOLD);
}
} else {
modified = (fd.getStyle() & SWT.BOLD) == SWT.BOLD;
if (modified) {
fd.setStyle(fd.getStyle() | ~SWT.BOLD);
}
}
if (modified) {
applyFont(grid, fd, target);
}
}
return true;
}
private boolean applyCSSPropertyStyle(final Object element, final Control widget, final CSSValue value) throws Exception {
if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
final FontData fd = CSSEngineHelper.getFontData(widget);
boolean modified = false;
if ("italic".equals(value.getCssText()) || "oblique".equals(value.getCssText())) {
modified = (fd.getStyle() & SWT.ITALIC) != SWT.ITALIC;
if (modified) {
fd.setStyle(fd.getStyle() | SWT.ITALIC);
}
} else {
modified = (fd.getStyle() & SWT.ITALIC) == SWT.ITALIC;
if (modified) {
fd.setStyle(fd.getStyle() | ~SWT.ITALIC);
}
}
if (modified) {
applyFont(widget, fd);
}
}
return true;
}
private void applyCSSPropertyFont(final Control widget, final CSSValue value, final boolean picker) throws Exception {
if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
final CSSValueList valueList = (CSSValueList) value;
final int length = valueList.getLength();
for (int i = 0; i < length; i++) {
final CSSValue value2 = valueList.item(i);
if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
final String cssProp = CSS2FontHelper.getCSSFontPropertyName((CSSPrimitiveValue) value2);
if (cssProp.equals("font-family")) {
applyCSSPropertyFamily(widget, value2, picker);
} else if (cssProp.equals("font-size")) {
applyCSSPropertySize(widget, value2, picker);
} else if (cssProp.equals("font-weight") && ("bold".equals(value2.getCssText()) || "bolder".equals(value2.getCssText()))) {
applyCSSPropertyWeight(widget, value2, picker);
} else if (cssProp.equals("font-style") && ("italic".equals(value2.getCssText()) || "oblique".equals(value2.getCssText()))) {
applyCSSPropertyStyle(widget, value2, picker);
}
}
}
}
}
@Override
public boolean applyCSSProperty(Object element, String property,
CSSValue value, String pseudo, CSSEngine engine) throws Exception {
final PShelf s = (PShelf)((PShelfElement)element).getNativeWidget();
final AbstractRenderer r = s.getRenderer();
if( r instanceof CSSShelfRenderer ) {
if( ! scheduled.containsKey(s) ) {
scheduled.put(s, Boolean.TRUE);
// Queue the changes
s.getDisplay().asyncExec(() -> {
if (!s.isDisposed() && !r.isDisposed()) {
scheduled.remove(s);
((CSSShelfRenderer) r).reinitialize();
}
});
}
}
return true;
}
private boolean isNullValue( CSSValue value )
{
if ( value == null )
{
return true;
}
if ( value instanceof DataFormatValue )
{
return true;
}
String cssText = value.getCssText( );
return "none".equalsIgnoreCase( cssText )
|| "transparent".equalsIgnoreCase( cssText );
}
private ColorDefinition getColor( CSSValue value )
{
if ( value != null && value instanceof RGBColorValue )
{
RGBColorValue color = (RGBColorValue) value;
try
{
return goFactory.createColorDefinition( Math.round( color.getRed( )
.getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) ),
Math.round( color.getGreen( )
.getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) ),
Math.round( color.getBlue( )
.getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) ) );
}
catch ( RuntimeException ex )
{
logger.log( Level.WARNING.intValue( ),
"invalid color: {0}" + value.toString( ) ); //$NON-NLS-1$
}
}
return null;
}
/**
* Build the Text-Decoration style string.
*
* @param styleBuffer
* The <code>StringBuffer</code> to which the result is output.
* @param linethrough
* The line-through value.
* @param underline
* The underline value.
* @param overline
* The overline value.
*/
public static void buildTextDecoration( StringBuffer styleBuffer,
IStyle style )
{
CSSValue linethrough = style.getProperty(IStyle.STYLE_TEXT_LINETHROUGH);
CSSValue underline = style.getProperty(IStyle.STYLE_TEXT_UNDERLINE);
CSSValue overline = style.getProperty(IStyle.STYLE_TEXT_OVERLINE);
if (linethrough == IStyle.LINE_THROUGH_VALUE || underline == IStyle.UNDERLINE_VALUE || overline == IStyle.OVERLINE_VALUE)
{
styleBuffer.append( " text-decoration:" ); //$NON-NLS-1$
if (IStyle.LINE_THROUGH_VALUE == linethrough )
{
addPropValue( styleBuffer, "line-through" );
}
if ( IStyle.UNDERLINE_VALUE == underline)
{
addPropValue( styleBuffer, "underline" );
}
if ( IStyle.OVERLINE_VALUE == overline)
{
addPropValue( styleBuffer, "overline" );
}
styleBuffer.append( ';' );
}
}
/**
* Handles the Text-Align property of the row content.
*/
public void handleRowAlign( IRowContent row )
{
// The method getStyle( ) will nevel return a null value;
IStyle style = row.getStyle( );
// Build the Vertical-Align property of the row content
CSSValue vAlign = style.getProperty( IStyle.STYLE_VERTICAL_ALIGN );
if ( null == vAlign || IStyle.BASELINE_VALUE == vAlign )
{
// The default vertical-align value of cell is top. And the cell can
// inherit the valign from parent row.
vAlign = IStyle.TOP_VALUE;
}
writer.attribute( HTMLTags.ATTR_VALIGN, vAlign.getCssText( ) );
// Build the Text-Align property.
CSSValue hAlign = style.getProperty( IStyle.STYLE_TEXT_ALIGN );
if ( null != hAlign )
{
writer.attribute( HTMLTags.ATTR_ALIGN, hAlign.getCssText( ) );
}
}
/**
* Build the style of row content.
*/
public void buildRowStyle( IRowContent row, StringBuffer styleBuffer )
{
buildSize( styleBuffer, HTMLTags.ATTR_HEIGHT, row.getHeight( ) ); //$NON-NLS-1$
// The method getStyle( ) will nevel return a null value;
IStyle style = row.getStyle( );
// output the none value of the display
CSSValue display = style.getProperty( IStyle.STYLE_DISPLAY );
if ( IStyle.NONE_VALUE == display )
{
styleBuffer.append( " display: none;" );
}
style = getElementStyle( row );
if ( style == null )
{
return;
}
AttributeBuilder.buildFont( styleBuffer, style );
AttributeBuilder.buildBackground( styleBuffer, style, reportEmitter );
AttributeBuilder.buildText( styleBuffer, style );
AttributeBuilder.buildVisual( styleBuffer, style );
}
/**
* Handles the vertical align property of the element content.
*/
public void handleCellVAlign( ICellContent cell )
{
// The method getStyle( ) will nevel return a null value;
IStyle style = cell.getStyle( );
// Build the Vertical-Align property.
CSSValue vAlign = style.getProperty( IStyle.STYLE_VERTICAL_ALIGN );
if( null == vAlign )
{
IStyle cellMergedStyle = new CellMergedStyle( cell );
vAlign = cellMergedStyle.getProperty( IStyle.STYLE_VERTICAL_ALIGN );
}
if ( IStyle.BASELINE_VALUE == vAlign )
{
vAlign = IStyle.TOP_VALUE;
}
if ( null != vAlign )
{
// The default vertical-align value has already been outputted on
// the parent row.
writer.attribute( HTMLTags.ATTR_VALIGN, vAlign.getCssText( ) );
}
}
/**
* Close the vertical-align box tag if the element needs implementing the
* vertical-align.
*/
public void handleVerticalAlignEnd( IContent element )
{
IStyle style = element.getStyle( );
CSSValue vAlign = style.getProperty( IStyle.STYLE_VERTICAL_ALIGN );
CSSValue canShrink = style.getProperty( IStyle.STYLE_CAN_SHRINK );
DimensionType height = element.getHeight( );
if ( vAlign != null
&& vAlign != IStyle.BASELINE_VALUE && height != null
&& canShrink != IStyle.TRUE_VALUE )
{
writer.closeTag( HTMLTags.TAG_TD );
writer.closeTag( HTMLTags.TAG_TR );
writer.closeTag( HTMLTags.TAG_TABLE );
}
}
@Override
protected BirtStyle clone() {
BirtStyle result = new BirtStyle(this.cssEngine);
result.propertyOverride = new CSSValue[ BirtStyle.NUMBER_OF_STYLES ];
for(int i = 0; i < NUMBER_OF_STYLES; ++i ) {
CSSValue value = getProperty( i );
if( value != null ) {
if( value instanceof DataFormatValue ) {
value = StyleManagerUtils.cloneDataFormatValue((DataFormatValue)value);
}
result.propertyOverride[ i ] = value;
}
}
return result;
}
protected boolean isNullValue( CSSValue value )
{
if ( value == null )
{
return true;
}
if ( value instanceof DataFormatValue )
{
return true;
}
if ( value instanceof FloatValue )
{
return false;
}
String cssText = value.getCssText( );
return "none".equalsIgnoreCase( cssText )
|| "transparent".equalsIgnoreCase( cssText );
}
/**
* to check whether there are horizontal page breaks in the table.
*
* @param table
* @return
*/
public static boolean hasHorzPageBreak( ITableContent table )
{
int count = table.getColumnCount( );
for ( int i = 0; i < count; i++ )
{
IColumn column = table.getColumn( i );
IStyle style = column.getStyle( );
CSSValue pageBreak = style.getProperty( IStyle.STYLE_PAGE_BREAK_BEFORE );
if ( i > 0 && IStyle.ALWAYS_VALUE == pageBreak )
{
return true;
}
pageBreak = style.getProperty( IStyle.STYLE_PAGE_BREAK_AFTER );
if ( i < count - 1 && IStyle.ALWAYS_VALUE == pageBreak )
{
return true;
}
}
return false;
}
public static float convertFontSize( CSSValue fontSize )
{
int size = PropertyUtil.getDimensionValue( fontSize );
float fsize = 0f;
try
{
fsize = size / 1000f;
}
catch ( NumberFormatException e )
{
logger.log( Level.WARNING, e.getMessage( ), e );
}
return fsize;
}
protected void handlePageBreakInterval( )
{
GroupDesign groupDesign = (GroupDesign) design;
if ( groupDesign.getGroupLevel( ) == listingExecutor.pageBreakLevel )
{
if ( listingExecutor.softBreakBefore )
{
IStyle style = content.getStyle( );
if ( style != null )
{
CSSValue pageBreak = style
.getProperty( IStyle.STYLE_PAGE_BREAK_BEFORE );
if ( pageBreak == null
|| IStyle.AUTO_VALUE.equals( pageBreak ) )
{
style.setProperty( IStyle.STYLE_PAGE_BREAK_BEFORE,
IStyle.SOFT_VALUE );
}
}
listingExecutor.softBreakBefore = false;
listingExecutor.addAfterBreak = true;
listingExecutor.pageRowCount = 0;
}
listingExecutor.next( );
if ( listingExecutor.needSoftBreakAfter( ) )
{
listingExecutor.softBreakBefore = true;
}
}
}
public CSSValue getPropertyCSSValue( String propertyName )
{
int index = getPropertyIndex( propertyName );
if ( index != -1 )
{
return getProperty( index );
}
return null;
}
/**
* Return a POI style created by combining a POI style with a BIRT style, where the BIRT style overrides the values in the POI style.
* @param source
* The POI style that represents the base style.
* @param birtExtraStyle
* The BIRT style to overlay on top of the POI style.
* @return
* A POI style representing the combination of source and birtExtraStyle.
*/
public CellStyle getStyleWithExtraStyle( CellStyle source, IStyle birtExtraStyle ) {
BirtStyle birtStyle = birtStyleFromCellStyle( source );
for(int i = 0; i < BirtStyle.NUMBER_OF_STYLES; ++i ) {
CSSValue value = birtExtraStyle.getProperty( i );
if( value != null ) {
birtStyle.setProperty( i , value );
}
}
CellStyle newStyle = getStyle( birtStyle );
return newStyle;
}
private boolean applyCSSPropertyFamily(final Object element, final Control widget, final CSSValue value) throws Exception {
if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
final FontData fd = CSSEngineHelper.getFontData(widget);
final boolean modified = !fd.getName().equals(value.getCssText());
if (modified) {
fd.setName(value.getCssText());
applyFont(widget, fd);
}
}
return true;
}
/**
* Test whether two BIRT styles are equivalent, as far as their font definitions are concerned.
* <br/>
* Every attribute tested in this method must be used in the construction of the font in createFont.
* @param style1
* The first BIRT style to be compared.
* @param style2
* The second BIRT style to be compared.
* @return
* true if style1 and style2 would produce identical Fonts if passed to createFont.
*/
public static boolean fontsEquivalent(BirtStyle style1, BirtStyle style2) {
for( int i = 0; i < COMPARE_CSS_PROPERTIES.length; ++i ) {
int prop = COMPARE_CSS_PROPERTIES[ i ];
CSSValue value1 = style1.getProperty( prop );
CSSValue value2 = style2.getProperty( prop );
if( ! StyleManagerUtils.objectsEqual( value1, value2 ) ) {
return false;
}
}
return true;
}
public CSSValue getProperty(int index) {
CSSValue v = inlineStyle.getProperty(index);
if ( v != null)
{
return v;
}
if ( style != null)
{
return style.getProperty(index);
}
return null;
}
public void setProperty( int index, CSSValue value )
{
style.setProperty( index, value );
if ( AbstractContent.this.computedStyle != null )
{
AbstractContent.this.computedStyle = null;
}
}
public void setValues( BorderStyleInfo[] stylesInfo,
CSSValue borderStyle, CSSValue borderWidth, CSSValue borderColor )
{
this.borderColor = borderColor;
this.borderStyle = borderStyle;
this.borderWidth = borderWidth;
for ( int i = 0; i < stylesInfo.length; i++ )
{
styles[i] = stylesInfo[i].style;
}
}
public void setCssText( int index, String cssText )
{
if ( cssText != null )
{
CSSValue value = engine.parsePropertyValue( index, cssText );
setProperty( index, value );
}
else
{
setProperty( index, null );
}
}
@Override
protected PPr getPPr(BlockBox blockBox, Map<String, CSSValue> cssMap) {
// if the paragraph has an ID, use the preserved existing pPr
String id = blockBox.getElement().getAttribute("id");
if (id==null ) {
log.debug("no id on p " );
} else {
log.debug("processing p with id " + id);
Object o = wordMLPackage.getUserData(id);
if (o==null) {
log.debug("no #Pr UserData on p with id " + id);
} else if (o instanceof PPrNone) {
return null;
} else {
return((PPr)o);
// (TODO unless the user has changed the style)
}
}
// A new p the user has created
PPr pPr = Context.getWmlObjectFactory().createPPr();
populatePPr(pPr, blockBox, cssMap);
return pPr;
}
@Override
protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
throws Exception {
if (!(control instanceof TabbedPropertyTitle) || value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE
|| property == null || !cssPropertyToSWTProperty.containsKey(property)) {
return;
}
TabbedPropertyTitle title = (TabbedPropertyTitle) control;
title.setColor(cssPropertyToSWTProperty.get(property), CSSSWTColorHelper.getRGBA(value));
}
private void applyAlignment( BlockContainerArea area )
{
IContent content = area.getContent( );
if ( content == null )
{
return;
}
CSSValue align = content.getComputedStyle( ).getProperty(
IStyle.STYLE_TEXT_ALIGN );
// bidi_hcg: handle empty or justify align in RTL direction as right
// alignment
boolean isRightAligned = BidiAlignmentResolver.isRightAligned( content,
align, false );
// single line
if ( isRightAligned || IStyle.CENTER_VALUE.equals( align ) )
{
Iterator iter = area.getChildren( );
while ( iter.hasNext( ) )
{
AbstractArea child = (AbstractArea) iter.next( );
int spacing = area.getContentWidth( )
- child.getAllocatedWidth( );
if ( spacing > 0 )
{
if ( isRightAligned )
{
child.setAllocatedX( spacing + area.getOffsetX( ) );
}
else if ( IStyle.CENTER_VALUE.equals( align ) )
{
child.setAllocatedX( spacing / 2 + area.getOffsetX( ) );
}
}
}
}
}
private void writeRunBorder( String borderStyle, String color,
CSSValue borderWidth )
{
writer.openTag( "w:bdr" );
writeBorderProperty( borderStyle, color, borderWidth, 0 );
writer.closeTag( "w:bdr" );
}
/**
* Handles the alignment property of the container content.
*/
public void handleContainerAlign( IContainerContent container )
{
// The method getStyle( ) will nevel return a null value;
IStyle style = container.getStyle( );
// Container doesn't support vertical-align.
// Build the Text-Align property.
CSSValue hAlign = style.getProperty( IStyle.STYLE_TEXT_ALIGN );
if ( null != hAlign )
{
writer.attribute( HTMLTags.ATTR_ALIGN, hAlign.getCssText( ) );
}
}