void KoTableRowStyle::loadOdfProperties(KoStyleStack &styleStack) { // The fo:background-color attribute specifies the background color of a cell. if (styleStack.hasProperty(KoXmlNS::fo, "background-color")) { const QString bgcolor = styleStack.property(KoXmlNS::fo, "background-color"); QBrush brush = background(); if (bgcolor == "transparent") setBackground(Qt::NoBrush); else { if (brush.style() == Qt::NoBrush) brush.setStyle(Qt::SolidPattern); brush.setColor(bgcolor); // #rrggbb format setBackground(brush); } } // minimum row height if (styleStack.hasProperty(KoXmlNS::style, "min-row-height")) { setMinimumRowHeight(KoUnit::parseValue(styleStack.property(KoXmlNS::style, "min-row-height"))); } // optimal row height if (styleStack.hasProperty(KoXmlNS::style, "use-optimal-row-height")) { setUseOptimalHeight(styleStack.property(KoXmlNS::style, "use-optimal-row-height") == "true"); } // row height if (styleStack.hasProperty(KoXmlNS::style, "row-height")) { setRowHeight(KoUnit::parseValue(styleStack.property(KoXmlNS::style, "row-height"))); } // The fo:keep-together specifies if a row is allowed to break in the middle of the row. if (styleStack.hasProperty(KoXmlNS::fo, "keep-together")) { setKeepTogether(styleStack.property(KoXmlNS::fo, "keep-together") != "auto"); } // The fo:break-before and fo:break-after attributes insert a page or column break before or after a column. if (styleStack.hasProperty(KoXmlNS::fo, "break-before")) { setBreakBefore(KoText::textBreakFromString(styleStack.property(KoXmlNS::fo, "break-before"))); } if (styleStack.hasProperty(KoXmlNS::fo, "break-after")) { setBreakAfter(KoText::textBreakFromString(styleStack.property(KoXmlNS::fo, "break-after"))); } }
QBrush Surface::loadOdfPatternStyle(const KoStyleStack &styleStack, KoOdfLoadingContext &context, const QSizeF &size) { QString styleName = styleStack.property(KoXmlNS::draw, "fill-image-name"); KoXmlElement* e = context.stylesReader().drawStyles("fill-image")[styleName]; if (! e) return QBrush(); const QString href = e->attributeNS(KoXmlNS::xlink, "href", QString()); if (href.isEmpty()) return QBrush(); QString strExtension; const int result = href.lastIndexOf("."); if (result >= 0) { strExtension = href.mid(result + 1); // As we are using KoPicture, the extension should be without the dot. } QString filename(href); KoImageData data; data.setImage(href, context.store()); if (data.errorCode() != KoImageData::Success) return QBrush(); // read the pattern repeat style QString style = styleStack.property(KoXmlNS::style, "repeat"); kDebug(35001) << "pattern style =" << style; QSize imageSize = data.image().size(); if (style == "stretch") { imageSize = size.toSize(); } else { // optional attributes which can override original image size if (styleStack.hasProperty(KoXmlNS::draw, "fill-image-height") && styleStack.hasProperty(KoXmlNS::draw, "fill-image-width")) { QString height = styleStack.property(KoXmlNS::draw, "fill-image-height"); qreal newHeight = 0.0; if (height.endsWith('%')) newHeight = 0.01 * height.remove('%').toDouble() * imageSize.height(); else newHeight = KoUnit::parseValue(height); QString width = styleStack.property(KoXmlNS::draw, "fill-image-width"); qreal newWidth = 0.0; if (width.endsWith('%')) newWidth = 0.01 * width.remove('%').toDouble() * imageSize.width(); else newWidth = KoUnit::parseValue(width); if (newHeight > 0.0) imageSize.setHeight(static_cast<int>(newHeight)); if (newWidth > 0.0) imageSize.setWidth(static_cast<int>(newWidth)); } } kDebug(35001) << "shape size =" << size; kDebug(35001) << "original image size =" << data.image().size(); kDebug(35001) << "resulting image size =" << imageSize; QBrush resultBrush(QPixmap::fromImage(data.image()).scaled(imageSize)); if (style == "repeat") { QTransform matrix; if (styleStack.hasProperty(KoXmlNS::draw, "fill-image-ref-point")) { // align pattern to the given size QString align = styleStack.property(KoXmlNS::draw, "fill-image-ref-point"); kDebug(35001) << "pattern align =" << align; if (align == "top-left") matrix.translate(0, 0); else if (align == "top") matrix.translate(0.5*size.width(), 0); else if (align == "top-right") matrix.translate(size.width(), 0); else if (align == "left") matrix.translate(0, 0.5*size.height()); else if (align == "center") matrix.translate(0.5*size.width(), 0.5*size.height()); else if (align == "right") matrix.translate(size.width(), 0.5*size.height()); else if (align == "bottom-left") matrix.translate(0, size.height()); else if (align == "bottom") matrix.translate(0.5*size.width(), size.height()); else if (align == "bottom-right") matrix.translate(size.width(), size.height()); } if (styleStack.hasProperty(KoXmlNS::draw, "fill-image-ref-point-x")) { QString pointX = styleStack.property(KoXmlNS::draw, "fill-image-ref-point-x"); matrix.translate(0.01 * pointX.remove('%').toDouble() * imageSize.width(), 0); } if (styleStack.hasProperty(KoXmlNS::draw, "fill-image-ref-point-y")) { QString pointY = styleStack.property(KoXmlNS::draw, "fill-image-ref-point-y"); matrix.translate(0, 0.01 * pointY.remove('%').toDouble() * imageSize.height()); } resultBrush.setTransform(matrix); } return resultBrush; }