Search in sources :

Example 1 with PropertyDeclaration

use of org.xhtmlrenderer.css.sheet.PropertyDeclaration in project servoy-client by Servoy.

the class ServoyStyleRule method getValues.

public String[] getValues(String attributeName) {
    CSSName cssName = CSSName.getByPropertyName(attributeName);
    if (cssName != null && cascadedStyle.hasProperty(cssName)) {
        List values = cascadedStyle.propertiesByName(cssName);
        if (values != null) {
            String[] cssValues = new String[values.size()];
            for (int i = 0; i < values.size(); i++) {
                CSSPrimitiveValue value = ((PropertyDeclaration) values.get(i)).getValue();
                cssValues[i] = getCssValue(value);
            }
            return cssValues;
        }
    }
    return null;
}
Also used : CSSName(org.xhtmlrenderer.css.constants.CSSName) List(java.util.List) ArrayList(java.util.ArrayList) CSSPrimitiveValue(org.w3c.dom.css.CSSPrimitiveValue) PropertyDeclaration(org.xhtmlrenderer.css.sheet.PropertyDeclaration)

Example 2 with PropertyDeclaration

use of org.xhtmlrenderer.css.sheet.PropertyDeclaration in project servoy-client by Servoy.

the class ImageLoader method paintBackgroundImage.

private static void paintBackgroundImage(Graphics graphics, IStyleRule styleRule, IApplication application, String url, Dimension parentSize) {
    int start = url.indexOf(MediaURLStreamHandler.MEDIA_URL_DEF);
    if (start != -1) {
        String name = url.substring(start + MediaURLStreamHandler.MEDIA_URL_DEF.length());
        if (name.endsWith("')") || name.endsWith("\")"))
            name = name.substring(0, name.length() - 2);
        if (name.endsWith(")"))
            name = name.substring(0, name.length() - 1);
        Media media = application.getFlattenedSolution().getMedia(name);
        if (media != null) {
            byte[] imageData = media.getMediaData();
            if (styleRule.hasAttribute(CSSName.BACKGROUND_SIZE.toString())) {
                PropertyDeclaration declaration = ((ServoyStyleRule) styleRule).getPropertyDeclaration(CSSName.BACKGROUND_SIZE.toString());
                if (declaration.getValue() instanceof PropertyValue && ((PropertyValue) declaration.getValue()).getValues() != null && ((PropertyValue) declaration.getValue()).getValues().size() == 2) {
                    boolean autoWidth = "auto".equals(((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(0)).getCssText());
                    boolean autoHeight = "auto".equals(((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(1)).getCssText());
                    Boolean fixedWidth = null;
                    if (autoWidth && !autoHeight) {
                        fixedWidth = Boolean.FALSE;
                    } else if (autoHeight && !autoWidth) {
                        fixedWidth = Boolean.TRUE;
                    }
                    int width = getImageSize(parentSize.width, ((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(0)).getCssText());
                    int height = getImageSize(parentSize.height, ((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(1)).getCssText());
                    imageData = resize(imageData, width, height, autoWidth || autoHeight, fixedWidth);
                }
            }
            Image image = ImageLoader.getBufferedImage(imageData, -1, -1, false);
            int offsetWidth = 0;
            int offsetHeight = 0;
            int imageWidth = image.getWidth(null);
            int imageHeight = image.getHeight(null);
            if (styleRule.hasAttribute(CSSName.BACKGROUND_POSITION.toString())) {
                PropertyDeclaration declaration = ((ServoyStyleRule) styleRule).getPropertyDeclaration(CSSName.BACKGROUND_POSITION.toString());
                if (declaration.getValue() instanceof PropertyValue && ((PropertyValue) declaration.getValue()).getValues() != null && ((PropertyValue) declaration.getValue()).getValues().size() == 2) {
                    offsetWidth = getImagePosition(parentSize.width, imageWidth, ((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(0)).getCssText());
                    offsetHeight = getImagePosition(parentSize.height, imageHeight, ((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(1)).getCssText());
                }
            }
            boolean hRepeat = true;
            boolean vRepeat = true;
            if (styleRule.hasAttribute(CSSName.BACKGROUND_REPEAT.toString())) {
                String repeat = styleRule.getValue(CSSName.BACKGROUND_REPEAT.toString());
                hRepeat = false;
                vRepeat = false;
                if ("repeat".equals(repeat) || "repeat-x".equals(repeat))
                    hRepeat = true;
                if ("repeat".equals(repeat) || "repeat-y".equals(repeat))
                    vRepeat = true;
            }
            if (hRepeat) {
                offsetWidth = adjustRepeatCoordinate(offsetWidth, imageWidth);
            }
            if (vRepeat) {
                offsetHeight = adjustRepeatCoordinate(offsetHeight, imageHeight);
            }
            if (!hRepeat && !vRepeat) {
                graphics.drawImage(image, offsetWidth, offsetHeight, null);
            } else if (hRepeat && vRepeat) {
                for (int x = offsetWidth; x < parentSize.width; x += imageWidth) {
                    for (int y = offsetHeight; y < parentSize.height; y += imageHeight) {
                        graphics.drawImage(image, x, y, null);
                    }
                }
            } else if (hRepeat) {
                for (int x = offsetWidth; x < parentSize.width; x += imageWidth) {
                    graphics.drawImage(image, x, offsetHeight, null);
                }
            } else if (vRepeat) {
                for (int y = offsetHeight; y < parentSize.height; y += imageHeight) {
                    graphics.drawImage(image, offsetWidth, y, null);
                }
            }
        }
    }
}
Also used : Media(com.servoy.j2db.persistence.Media) PropertyValue(org.xhtmlrenderer.css.parser.PropertyValue) CSSPrimitiveValue(org.w3c.dom.css.CSSPrimitiveValue) PropertyDeclaration(org.xhtmlrenderer.css.sheet.PropertyDeclaration) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) RenderedImage(java.awt.image.RenderedImage) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 3 with PropertyDeclaration

use of org.xhtmlrenderer.css.sheet.PropertyDeclaration in project servoy-client by Servoy.

the class ServoyStyleSheet method getFont.

public Font getFont(IStyleRule a) {
    if (hasFont(a)) {
        // $NON-NLS-1$
        String family = "SansSerif";
        int size = 12;
        int style = Font.PLAIN;
        ServoyStyleRule rule = (ServoyStyleRule) a;
        if (a.hasAttribute(CSSName.FONT_FAMILY.toString())) {
            PropertyDeclaration declaration = rule.getPropertyDeclaration(CSSName.FONT_FAMILY.toString());
            if (declaration != null) {
                family = ((PropertyValue) declaration.getValue()).getStringArrayValue()[0];
            }
        }
        if (a.hasAttribute(CSSName.FONT_WEIGHT.toString())) {
            PropertyDeclaration declaration = rule.getPropertyDeclaration(CSSName.FONT_WEIGHT.toString());
            if (declaration != null) {
                if (// $NON-NLS-1$
                declaration.getValue().getCssText().contains("bold") || Utils.getAsFloat(declaration.getValue().getCssText()) > 400) {
                    style |= Font.BOLD;
                }
            }
        }
        if (a.hasAttribute(CSSName.FONT_STYLE.toString())) {
            PropertyDeclaration declaration = rule.getPropertyDeclaration(CSSName.FONT_STYLE.toString());
            if (declaration != null) {
                if (// $NON-NLS-1$
                declaration.getValue().getCssText().contains("italic")) {
                    style |= Font.ITALIC;
                }
            }
        }
        if (a.hasAttribute(CSSName.FONT_SIZE.toString())) {
            PropertyDeclaration declaration = rule.getPropertyDeclaration(CSSName.FONT_SIZE.toString());
            if (declaration != null) {
                float fontSize = ss.getLength(declaration.getValue().getCssText());
                if (fontSize > 0) {
                    if (// $NON-NLS-1$
                    declaration.getValue().getCssText().endsWith("px")) {
                        fontSize = 4 * fontSize / 3;
                    }
                    size = Math.round(fontSize);
                }
            }
        }
        return PersistHelper.createFont(family, style, size);
    }
    return null;
}
Also used : PropertyValue(org.xhtmlrenderer.css.parser.PropertyValue) PropertyDeclaration(org.xhtmlrenderer.css.sheet.PropertyDeclaration)

Aggregations

PropertyDeclaration (org.xhtmlrenderer.css.sheet.PropertyDeclaration)3 CSSPrimitiveValue (org.w3c.dom.css.CSSPrimitiveValue)2 PropertyValue (org.xhtmlrenderer.css.parser.PropertyValue)2 Media (com.servoy.j2db.persistence.Media)1 GradientPaint (java.awt.GradientPaint)1 Image (java.awt.Image)1 Paint (java.awt.Paint)1 BufferedImage (java.awt.image.BufferedImage)1 RenderedImage (java.awt.image.RenderedImage)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CSSName (org.xhtmlrenderer.css.constants.CSSName)1