use of org.w3c.dom.css.CSSValue in project webtools.sourceediting by eclipse.
the class CSSFontFaceRuleTest method _testInsertText3.
public void _testInsertText3() throws IOException {
ICSSModel model = getModel();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFaceRuleTest.css"));
CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
CSSRuleList ruleList = sheet.getCssRules();
assertEquals(3, ruleList.getLength());
CSSRule rule;
CSSStyleDeclaration declaration;
CSSValue value;
CSSValueList valueList;
// rule 3
rule = ruleList.item(2);
assertEquals(CSSRule.FONT_FACE_RULE, rule.getType());
assertTrue(rule instanceof CSSFontFaceRule);
declaration = ((CSSFontFaceRule) rule).getStyle();
assertEquals(5, declaration.getLength());
value = declaration.getPropertyCSSValue("src");
assertTrue(value instanceof CSSValueList);
valueList = (CSSValueList) value;
assertEquals(4, valueList.getLength());
checkPrimitiveString(valueList.item(0), new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Alabama Italic"));
checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_URI, "http://www.fonts.org/A/alabama-italic"));
checkPrimitiveString(valueList.item(3), new PrimitiveString(ICSSPrimitiveValue.CSS_FORMAT, "truetype"));
value = declaration.getPropertyCSSValue("panose-1");
assertTrue(value instanceof CSSValueList);
valueList = (CSSValueList) value;
assertEquals(10, valueList.getLength());
checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 2));
checkPrimitiveNumber(valueList.item(1), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 4));
checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 5));
checkPrimitiveNumber(valueList.item(3), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 2));
checkPrimitiveNumber(valueList.item(4), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 5));
checkPrimitiveNumber(valueList.item(5), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 4));
checkPrimitiveNumber(valueList.item(6), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 5));
checkPrimitiveNumber(valueList.item(7), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 9));
checkPrimitiveNumber(valueList.item(8), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 3));
checkPrimitiveNumber(valueList.item(9), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 3));
value = declaration.getPropertyCSSValue("font-family");
assertTrue(value instanceof CSSValueList);
valueList = (CSSValueList) value;
assertEquals(3, valueList.getLength());
checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Alabama"));
checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "serif"));
value = declaration.getPropertyCSSValue("font-weight");
assertTrue(value instanceof CSSValueList);
valueList = (CSSValueList) value;
assertEquals(5, valueList.getLength());
checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 300));
checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 400));
checkPrimitiveString(valueList.item(3), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
checkPrimitiveNumber(valueList.item(4), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 500));
value = declaration.getPropertyCSSValue("font-style");
assertTrue(value instanceof CSSValueList);
valueList = (CSSValueList) value;
assertEquals(3, valueList.getLength());
checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "italic"));
checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "oblique"));
}
use of org.w3c.dom.css.CSSValue in project webtools.sourceediting by eclipse.
the class CSSFontFaceRuleTest method testInsertRule.
public void testInsertRule() {
final String RULE = "@font-face { font-family: \"Swiss 721\"; src: url(swiss721.pfr); /* The expanded Swiss 721 */ font-stretch: expanded; }";
CSSStyleSheet sheet = getStyleSheet();
assertEquals(0, sheet.insertRule(RULE, 0));
CSSRuleList ruleList = sheet.getCssRules();
CSSRule rule = ruleList.item(0);
assertTrue(rule instanceof CSSFontFaceRule);
CSSStyleDeclaration declaration = ((CSSFontFaceRule) rule).getStyle();
assertEquals(3, declaration.getLength());
CSSValue value;
CSSPrimitiveValue primitiveValue;
value = declaration.getPropertyCSSValue("font-family");
assertTrue(value instanceof CSSPrimitiveValue);
primitiveValue = (CSSPrimitiveValue) value;
assertEquals(CSSPrimitiveValue.CSS_STRING, primitiveValue.getPrimitiveType());
assertEquals("Swiss 721", primitiveValue.getStringValue());
value = declaration.getPropertyCSSValue("src");
assertTrue(value instanceof CSSPrimitiveValue);
primitiveValue = (CSSPrimitiveValue) value;
assertEquals(CSSPrimitiveValue.CSS_URI, primitiveValue.getPrimitiveType());
assertEquals("swiss721.pfr", primitiveValue.getStringValue());
value = declaration.getPropertyCSSValue("font-stretch");
assertTrue(value instanceof CSSPrimitiveValue);
primitiveValue = (CSSPrimitiveValue) value;
assertEquals(CSSPrimitiveValue.CSS_IDENT, primitiveValue.getPrimitiveType());
assertEquals("expanded", primitiveValue.getStringValue());
}
use of org.w3c.dom.css.CSSValue in project webtools.sourceediting by eclipse.
the class CSSStyleRuleTest method testInsertTextStrings.
public void testInsertTextStrings() throws IOException {
ICSSModel model = getModel();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSStyleRuleTest.css"));
CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
CSSRuleList ruleList = sheet.getCssRules();
assertEquals(3, ruleList.getLength());
CSSRule rule;
CSSStyleDeclaration declaration;
CSSValue value;
rule = ruleList.item(1);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
assertEquals(11, declaration.getLength());
// 01
value = declaration.getPropertyCSSValue("STRING");
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "string"));
// 02
value = declaration.getPropertyCSSValue("URI");
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_URI, "http://www.ibm.com/"));
// 03
value = declaration.getPropertyCSSValue("IDENT");
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "left"));
// 04
value = declaration.getPropertyCSSValue("HASH");
checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_HASH, "#abcdef"));
// 05
value = declaration.getPropertyCSSValue("URANGE");
checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_URANGE, "U+20A7"));
// 06
value = declaration.getPropertyCSSValue("SLASH");
checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_SLASH, "/"));
// 07
value = declaration.getPropertyCSSValue("COMMA");
checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
// 08
value = declaration.getPropertyCSSValue("INHERIT_PRIMITIVE");
checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE, "inherit"));
// 09
value = declaration.getPropertyCSSValue("ATTR");
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_ATTR, "KEY"));
// 10
value = declaration.getPropertyCSSValue("FORMAT");
checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_FORMAT, "truedoc"));
// 11
value = declaration.getPropertyCSSValue("LOCAL");
checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Excelsior Roman"));
}
use of org.w3c.dom.css.CSSValue in project nebula.widgets.nattable by eclipse.
the class NatTableCSSHelper method resolvePainterRepresentation.
/**
* Resolves the painter representations out of the given {@link CSSValue}.
*
* @param value
* The {@link CSSValue} to resolve.
* @return The list of string representations for painters.
*/
public static List<String> resolvePainterRepresentation(CSSValue value) {
List<String> painterValues = new ArrayList<>();
if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
CSSValueList valueList = (CSSValueList) value;
int length = valueList.getLength();
for (int i = 0; i < length; i++) {
CSSValue value2 = valueList.item(i);
if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
painterValues.add(value2.getCssText().toLowerCase());
}
}
} else if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
painterValues.add(value.getCssText().toLowerCase());
}
return painterValues;
}
use of org.w3c.dom.css.CSSValue in project nebula.widgets.nattable by eclipse.
the class NatTableCSSHelper method storeBorderStyle.
/**
* Convert and store the values of the given {@link CSSValueList} to the
* given {@link BorderStyle}.
*
* @param valueList
* The {@link CSSValueList} with the values to convert.
* @param borderStyle
* The {@link BorderStyle} to store the converted values to.
* @param engine
* The {@link CSSEngine} needed for conversion.
* @param display
* The display needed for color conversion.
* @throws Exception
* if the value conversion fails
*/
public static void storeBorderStyle(CSSValueList valueList, BorderStyle borderStyle, CSSEngine engine, Display display) throws Exception {
int length = valueList.getLength();
for (int i = 0; i < length; i++) {
CSSValue value2 = valueList.item(i);
if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value2;
short type = primitiveValue.getPrimitiveType();
switch(type) {
case CSSPrimitiveValue.CSS_IDENT:
if (CSS2ColorHelper.isColorName(primitiveValue.getStringValue())) {
borderStyle.setColor((Color) engine.convert(value2, Color.class, display));
} else if (isLineStyle(primitiveValue.getStringValue().toUpperCase())) {
borderStyle.setLineStyle(LineStyleEnum.valueOf(primitiveValue.getStringValue().toUpperCase()));
} else {
borderStyle.setBorderMode(BorderModeEnum.valueOf(primitiveValue.getStringValue().toUpperCase()));
}
break;
case CSSPrimitiveValue.CSS_RGBCOLOR:
borderStyle.setColor((Color) engine.convert(value2, Color.class, display));
break;
case CSSPrimitiveValue.CSS_PT:
case CSSPrimitiveValue.CSS_NUMBER:
case CSSPrimitiveValue.CSS_PX:
borderStyle.setThickness((int) ((CSSPrimitiveValue) value2).getFloatValue(CSSPrimitiveValue.CSS_PT));
break;
}
}
}
}
Aggregations