Package org.xhtmlrenderer.css.parser

Examples of org.xhtmlrenderer.css.parser.PropertyValue


       
        boolean keepGoing = false;
       
        ListIterator i = values.listIterator();
        while (i.hasNext()) {
            PropertyValue value = (PropertyValue)i.next();
            int type = value.getPrimitiveType();
            if (type == CSSPrimitiveValue.CSS_IDENT) {
                // The parser will have given us ident values as they appear
                // (case-wise) in the CSS text since we might be creating
                // a font-family list out of them.  Here we want the normalized
                // (lowercase) version though.
                String lowerCase = value.getStringValue().toLowerCase();
                value = new PropertyValue(CSSPrimitiveValue.CSS_IDENT, lowerCase, lowerCase);
                IdentValue ident = checkIdent(cssName, value);
                if (ident == IdentValue.NORMAL) { // skip to avoid double set false positives
                    continue;
                }
                if (PrimitivePropertyBuilders.FONT_STYLES.get(ident.FS_ID)) {
                    if (fontStyle != null) {
                        throw new CSSParseException("font-style cannot be set twice", -1);
                    }
                    fontStyle = new PropertyDeclaration(CSSName.FONT_STYLE, value, important, origin);
                } else if (PrimitivePropertyBuilders.FONT_VARIANTS.get(ident.FS_ID)) {
                    if (fontVariant != null) {
                        throw new CSSParseException("font-variant cannot be set twice", -1);
                    }
                    fontVariant = new PropertyDeclaration(CSSName.FONT_VARIANT, value, important, origin);
                } else if (PrimitivePropertyBuilders.FONT_WEIGHTS.get(ident.FS_ID)) {
                    if (fontWeight != null) {
                        throw new CSSParseException("font-weight cannot be set twice", -1);
                    }
                    fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, value, important, origin);
                } else {
                    keepGoing = true;
                    break;
                }
            } else if (type == CSSPrimitiveValue.CSS_NUMBER && value.getFloatValue() > 0) {
                if (fontWeight != null) {
                    throw new CSSParseException("font-weight cannot be set twice", -1);
                }
               
                IdentValue weight = Conversions.getNumericFontWeight(value.getFloatValue());
                if (weight == null) {
                    throw new CSSParseException(value + " is not a valid font weight", -1);
                }
               
                PropertyValue replacement = new PropertyValue(
                        CSSPrimitiveValue.CSS_IDENT, weight.toString(), weight.toString());
                replacement.setIdentValue(weight);
               
                fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, replacement, important, origin);
            } else {
                keepGoing = true;
                break;
            }
        }
       
        if (keepGoing) {
            i.previous();
            PropertyValue value = (PropertyValue)i.next();
           
            if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                String lowerCase = value.getStringValue().toLowerCase();
                value = new PropertyValue(CSSPrimitiveValue.CSS_IDENT, lowerCase, lowerCase);
            }
           
            PropertyBuilder fontSizeBuilder = CSSName.getPropertyBuilder(CSSName.FONT_SIZE);
            List l = fontSizeBuilder.buildDeclarations(
                    CSSName.FONT_SIZE, Collections.singletonList(value), origin, important);
           
            fontSize = (PropertyDeclaration)l.get(0);
           
            if (i.hasNext()) {
                value = (PropertyValue)i.next();
                if (value.getOperator() == Token.TK_VIRGULE) {
                    PropertyBuilder lineHeightBuilder = CSSName.getPropertyBuilder(CSSName.LINE_HEIGHT);
                    l = lineHeightBuilder.buildDeclarations(
                            CSSName.LINE_HEIGHT, Collections.singletonList(value), origin, important);
                    lineHeight = (PropertyDeclaration)l.get(0);
                } else {
                    i.previous();
                }
            }
           
            if (i.hasNext()) {
                List families = new ArrayList();
                while (i.hasNext()) {
                    families.add(i.next());
                }
                PropertyBuilder fontFamilyBuilder = CSSName.getPropertyBuilder(CSSName.FONT_FAMILY);
                l = fontFamilyBuilder.buildDeclarations(
                        CSSName.FONT_FAMILY, families, origin, important);
                fontFamily = (PropertyDeclaration)l.get(0);
            }
        }
       
        if (fontStyle == null) {
            fontStyle = new PropertyDeclaration(
                    CSSName.FONT_STYLE, new PropertyValue(IdentValue.NORMAL), important, origin);
        }
       
        if (fontVariant == null) {
            fontVariant = new PropertyDeclaration(
                    CSSName.FONT_VARIANT, new PropertyValue(IdentValue.NORMAL), important, origin);
        }
       
        if (fontWeight == null) {
            fontWeight = new PropertyDeclaration(
                    CSSName.FONT_WEIGHT, new PropertyValue(IdentValue.NORMAL), important, origin);
        }
       
        if (fontSize == null) {
            throw new CSSParseException("A font-size value is required", -1);
        }
       
        if (lineHeight == null) {
            lineHeight = new PropertyDeclaration(
                    CSSName.LINE_HEIGHT, new PropertyValue(IdentValue.NORMAL), important, origin);
        }
       
        // XXX font-family should be reset too (although does this really make sense?)
       
        result = new ArrayList(ALL.length);
View Full Code Here


                        throw new CSSParseException(value.getCssText() + " is not a border width, style, or color", -1);
                    }
                }
               
                if (! haveBorderWidth) {
                    addAll(result, props[0], new PropertyValue(IdentValue.FS_INITIAL_VALUE), origin, important);
                }
               
                if (! haveBorderStyle) {
                    addAll(result, props[1], new PropertyValue(IdentValue.FS_INITIAL_VALUE), origin, important);
                }
               
                if (! haveBorderColor) {
                    addAll(result, props[2], new PropertyValue(IdentValue.FS_INITIAL_VALUE), origin, important);
                }
               
                return result;
            }
        }
View Full Code Here

            if (type == CSSPrimitiveValue.CSS_RGBCOLOR) {
                return value;
            } else {
                FSRGBColor color = Conversions.getColor(value.getStringValue());
                if (color != null) {
                    return new PropertyValue(color);
                }
               
                IdentValue ident = IdentValue.valueOf(value.getCssText());
                if (ident == null || ident != IdentValue.TRANSPARENT) {
                    return null;
View Full Code Here

       
        PropertyDeclaration horizontalSpacing = null;
        PropertyDeclaration verticalSpacing = null;
       
        if (values.size() == 1) {
            PropertyValue value = (PropertyValue)values.get(0);
            checkLengthType(cssName, value);
            if (value.getFloatValue() < 0.0f) {
                throw new CSSParseException("border-spacing may not be negative", -1);
            }
            horizontalSpacing = new PropertyDeclaration(
                    CSSName.FS_BORDER_SPACING_HORIZONTAL, value, important, origin);
            verticalSpacing = new PropertyDeclaration(
                    CSSName.FS_BORDER_SPACING_VERTICAL, value, important, origin);           
        } else { /* values.size() == 2 */
            PropertyValue horizontal = (PropertyValue)values.get(0);
            checkLengthType(cssName, horizontal);
            if (horizontal.getFloatValue() < 0.0f) {
                throw new CSSParseException("border-spacing may not be negative", -1);
            }
            horizontalSpacing = new PropertyDeclaration(
                    CSSName.FS_BORDER_SPACING_HORIZONTAL, horizontal, important, origin);
           
            PropertyValue vertical = (PropertyValue)values.get(1);
            checkLengthType(cssName, vertical);
            if (vertical.getFloatValue() < 0.0f) {
                throw new CSSParseException("border-spacing may not be negative", -1);
            }
            verticalSpacing = new PropertyDeclaration(
                    CSSName.FS_BORDER_SPACING_VERTICAL, vertical, important, origin);           
        }
View Full Code Here

        PropertyDeclaration listStyleType = null;
        PropertyDeclaration listStylePosition = null;
        PropertyDeclaration listStyleImage = null;
       
        for (Iterator i = values.iterator(); i.hasNext(); ) {
            PropertyValue value = (PropertyValue)i.next();
            checkInheritAllowed(value, false);
            short type = value.getPrimitiveType();
            if (type == CSSPrimitiveValue.CSS_IDENT) {
                IdentValue ident = checkIdent(CSSName.LIST_STYLE_SHORTHAND, value);
               
                if (ident == IdentValue.NONE) {
                    if (listStyleType == null) {
View Full Code Here

            checkIdentLengthOrPercentType(cssName, first);
            if (second == null) {
                if (isLength(first) || first.getPrimitiveType() == CSSPrimitiveValue.CSS_PERCENTAGE) {
                    List responseValues = new ArrayList(2);
                    responseValues.add(first);
                    responseValues.add(new PropertyValue(
                            CSSPrimitiveValue.CSS_PERCENTAGE, 50.0f, "50%"));
                    return Collections.singletonList(new PropertyDeclaration(
                                CSSName.BACKGROUND_POSITION,
                                new PropertyValue(responseValues), important, origin));
                }
            } else {
                checkIdentLengthOrPercentType(cssName, second);
            }


            IdentValue firstIdent = null;
            if (first.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                firstIdent = checkIdent(cssName, first);
                checkValidity(cssName, getAllowed(), firstIdent);
            }

            IdentValue secondIdent = null;
            if (second == null) {
                secondIdent = IdentValue.CENTER;
            } else if (second.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                secondIdent = checkIdent(cssName, second);
                checkValidity(cssName, getAllowed(), secondIdent);
            }

            if (firstIdent == null && secondIdent == null) {
                return Collections.singletonList(new PropertyDeclaration(
                        CSSName.BACKGROUND_POSITION, new PropertyValue(values), important, origin));
            } else if (firstIdent != null && secondIdent != null) {
                if (firstIdent == IdentValue.TOP || firstIdent == IdentValue.BOTTOM ||
                        secondIdent == IdentValue.LEFT || secondIdent == IdentValue.RIGHT) {
                    IdentValue temp = firstIdent;
                    firstIdent = secondIdent;
                    secondIdent = temp;
                }

                checkIdentPosition(cssName, firstIdent, secondIdent);

                return createTwoPercentValueResponse(
                        getPercentForIdent(firstIdent),
                        getPercentForIdent(secondIdent),
                        important,
                        origin);
            } else {
                checkIdentPosition(cssName, firstIdent, secondIdent);

                List responseValues = new ArrayList(2);

                if (firstIdent == null) {
                    responseValues.add(first);
                    responseValues.add(createValueForIdent(secondIdent));
                } else {
                    responseValues.add(createValueForIdent(firstIdent));
                    responseValues.add(second);
                }

                return Collections.singletonList(new PropertyDeclaration(
                        CSSName.BACKGROUND_POSITION,
                        new PropertyValue(responseValues), important, origin));
            }
        }
View Full Code Here

            return percent;
        }

        private PropertyValue createValueForIdent(IdentValue ident) {
            float percent = getPercentForIdent(ident);
            return new PropertyValue(
                    CSSPrimitiveValue.CSS_PERCENTAGE, percent, percent + "%");
        }
View Full Code Here

                    CSSPrimitiveValue.CSS_PERCENTAGE, percent, percent + "%");
        }

        private List createTwoPercentValueResponse(
                float percent1, float percent2, boolean important, int origin) {
            PropertyValue value1 = new PropertyValue(
                    CSSPrimitiveValue.CSS_PERCENTAGE, percent1, percent1 + "%");
            PropertyValue value2 = new PropertyValue(
                    CSSPrimitiveValue.CSS_PERCENTAGE, percent2, percent2 + "%");

            List values = new ArrayList(2);
            values.add(value1);
            values.add(value2);

            PropertyDeclaration result = new PropertyDeclaration(
                    CSSName.BACKGROUND_POSITION,
                    new PropertyValue(values), important, origin);

            return Collections.singletonList(result);
        }
View Full Code Here

    }

    private void initFontFromComponent(BlockBox root) {
        if (isDefaultFontFromComponent()) {
            CalculatedStyle style = root.getStyle();
            PropertyValue fontFamilyProp = new PropertyValue(CSSPrimitiveValue.CSS_STRING, getFont().getFamily(),
                    getFont().getFamily());
            fontFamilyProp.setStringArrayValue(new String[] { fontFamilyProp.getStringValue() });
            style.setDefaultValue(CSSName.FONT_FAMILY, new StringValue(CSSName.FONT_FAMILY, fontFamilyProp));
            style.setDefaultValue(CSSName.FONT_SIZE, new LengthValue(style, CSSName.FONT_SIZE,
                    new PropertyValue(CSSPrimitiveValue.CSS_PX, getFont().getSize(), Integer
                            .toString(getFont().getSize()))));
            Color c = getForeground();
            style.setDefaultValue(CSSName.COLOR, new ColorValue(CSSName.COLOR,
                    new PropertyValue(new FSRGBColor(c.getRed(), c.getGreen(), c.getBlue()))));

            if (getFont().isBold()) {
                style.setDefaultValue(CSSName.FONT_WEIGHT, IdentValue.BOLD);
            }
View Full Code Here

            // after a string).  Seems wrong per the spec, but FF (at least)
            // does it in standards mode so we do too.
            List consecutiveIdents = new ArrayList();
            List normalized = new ArrayList(values.size());
            for (Iterator i = values.iterator(); i.hasNext(); ) {
                PropertyValue value = (PropertyValue)i.next();

                Token operator = value.getOperator();
                if (operator != null && operator != Token.TK_COMMA) {
                    throw new CSSParseException("Invalid font-family definition", -1);
                }

                if (operator != null) {
                    if (consecutiveIdents.size() > 0) {
                        normalized.add(concat(consecutiveIdents, ' '));
                        consecutiveIdents.clear();
                    }
                }

                checkInheritAllowed(value, false);
                short type = value.getPrimitiveType();
                if (type == CSSPrimitiveValue.CSS_STRING) {
                    if (consecutiveIdents.size() > 0) {
                        normalized.add(concat(consecutiveIdents, ' '));
                        consecutiveIdents.clear();
                    }
                    normalized.add(value.getStringValue());
                } else if (type == CSSPrimitiveValue.CSS_IDENT) {
                    consecutiveIdents.add(value.getStringValue());
                } else {
                    throw new CSSParseException("Invalid font-family definition", -1);
                }
            }
            if (consecutiveIdents.size() > 0) {
                normalized.add(concat(consecutiveIdents, ' '));
            }

            String text = concat(normalized, ',');
            PropertyValue result = new PropertyValue(
                    CSSPrimitiveValue.CSS_STRING, text, text)// HACK cssText can be wrong
            result.setStringArrayValue((String[]) normalized.toArray(new String[normalized.size()]));

            return Collections.singletonList(
                    new PropertyDeclaration(cssName, result, important, origin));
        }
View Full Code Here

TOP

Related Classes of org.xhtmlrenderer.css.parser.PropertyValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.