Search in sources :

Example 1 with CSSStylableElement

use of io.sf.carte.doc.dom4j.CSSStylableElement in project xwiki-platform by xwiki.

the class PdfExportImpl method applyInlineStyle.

/**
 * Recursively inline the computed style that applies to a DOM Element into the {@code style} attribute of that
 * Element.
 *
 * @param element the Element whose style should be inlined
 */
private void applyInlineStyle(Element element) {
    for (int i = 0; i < element.nodeCount(); i++) {
        org.dom4j.Node node = element.node(i);
        if (node instanceof CSSStylableElement) {
            CSSStylableElement styleElement = (CSSStylableElement) node;
            CSSStyleDeclaration style = styleElement.getComputedStyle();
            if (style != null && StringUtils.isNotEmpty(style.getCssText())) {
                styleElement.addAttribute("style", style.getCssText());
            }
        }
        if (node instanceof Element) {
            applyInlineStyle((Element) node);
        }
    }
}
Also used : CSSStylableElement(io.sf.carte.doc.dom4j.CSSStylableElement) Element(org.dom4j.Element) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSStylableElement(io.sf.carte.doc.dom4j.CSSStylableElement)

Aggregations

CSSStylableElement (io.sf.carte.doc.dom4j.CSSStylableElement)1 Element (org.dom4j.Element)1 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)1