void KoSectionStyle::loadOdf(const KoXmlElement *element, KoOdfLoadingContext &context) { if (element->hasAttributeNS(KoXmlNS::style, "display-name")) d->name = element->attributeNS(KoXmlNS::style, "display-name", QString()); if (d->name.isEmpty()) // if no style:display-name is given us the style:name d->name = element->attributeNS(KoXmlNS::style, "name", QString()); context.styleStack().save(); // Load all parents - only because we don't support inheritance. QString family = element->attributeNS(KoXmlNS::style, "family", "section"); context.addStyles(element, family.toLocal8Bit().constData()); // Load all parents - only because we don't support inheritance. context.styleStack().setTypeProperties("section"); // load all style attributes from "style:section-properties" KoStyleStack &styleStack = context.styleStack(); // in 1.6 this was defined at KoParagLayout::loadOasisParagLayout(KoParagLayout&, KoOasisContext&) if (styleStack.hasProperty(KoXmlNS::style, "writing-mode")) { // http://www.w3.org/TR/2004/WD-xsl11-20041216/#writing-mode QString writingMode = styleStack.property(KoXmlNS::style, "writing-mode"); setTextProgressionDirection(KoText::directionFromString(writingMode)); } // Indentation (margin) bool hasMarginLeft = styleStack.hasProperty(KoXmlNS::fo, "margin-left"); bool hasMarginRight = styleStack.hasProperty(KoXmlNS::fo, "margin-right"); if (hasMarginLeft) setLeftMargin(KoUnit::parseValue(styleStack.property(KoXmlNS::fo, "margin-left"))); if (hasMarginRight) setRightMargin(KoUnit::parseValue(styleStack.property(KoXmlNS::fo, "margin-right"))); // The fo:background-color attribute specifies the background color of a paragraph. if (styleStack.hasProperty(KoXmlNS::fo, "background-color")) { const QString bgcolor = styleStack.property(KoXmlNS::fo, "background-color"); QBrush brush = background(); if (bgcolor == "transparent") brush.setStyle(Qt::NoBrush); else { if (brush.style() == Qt::NoBrush) brush.setStyle(Qt::SolidPattern); brush.setColor(bgcolor); // #rrggbb format } setBackground(brush); } styleStack.restore(); }
bool KoColorBackground::loadStyle(KoOdfLoadingContext & context, const QSizeF &) { KoStyleStack &styleStack = context.styleStack(); if (! styleStack.hasProperty(KoXmlNS::draw, "fill")) return false; QString fillStyle = styleStack.property(KoXmlNS::draw, "fill"); if (fillStyle == "solid" || fillStyle == "hatch") { QBrush brush = KoOdfGraphicStyles::loadOdfFillStyle(styleStack, fillStyle, context.stylesReader()); d->color = brush.color(); d->style = brush.style(); return true; } return false; }
void KoTableRowStyle::loadOdf(const KoXmlElement *element, KoOdfLoadingContext &context) { if (element->hasAttributeNS(KoXmlNS::style, "display-name")) d->name = element->attributeNS(KoXmlNS::style, "display-name", QString()); if (d->name.isEmpty()) // if no style:display-name is given us the style:name d->name = element->attributeNS(KoXmlNS::style, "name", QString()); QString masterPage = element->attributeNS(KoXmlNS::style, "master-page-name", QString()); if (! masterPage.isEmpty()) { setMasterPageName(masterPage); } context.styleStack().save(); QString family = element->attributeNS(KoXmlNS::style, "family", "table-row"); context.addStyles(element, family.toLocal8Bit().constData()); // Load all parents - only because we don't support inheritance. context.styleStack().setTypeProperties("table-row"); // load all style attributes from "style:table-column-properties" loadOdfProperties(context.styleStack()); // load the KoTableRowStyle from the stylestack context.styleStack().restore(); }
bool KoFormulaShape::loadEmbeddedDocument( KoStore *store, const KoXmlElement &objectElement, const KoOdfLoadingContext &odfLoadingContext) { if ( !objectElement.hasAttributeNS( KoXmlNS::xlink, "href" ) ) { kError() << "Object element has no valid xlink:href attribute"; return false; } QString url = objectElement.attributeNS( KoXmlNS::xlink, "href" ); // It can happen that the url is empty e.g. when it is a // presentation:placeholder. if ( url.isEmpty() ) { return true; } QString tmpURL; if ( url[0] == '#' ) url = url.mid( 1 ); #define INTERNAL_PROTOCOL "intern" #define STORE_PROTOCOL "tar" if (KUrl::isRelativeUrl( url )) { if ( url.startsWith( "./" ) ) tmpURL = QString( INTERNAL_PROTOCOL ) + ":/" + url.mid( 2 ); else tmpURL = QString( INTERNAL_PROTOCOL ) + ":/" + url; } else tmpURL = url; QString path = tmpURL; if ( tmpURL.startsWith( INTERNAL_PROTOCOL ) ) { path = store->currentDirectory(); if ( !path.isEmpty() && !path.endsWith( '/' ) ) path += '/'; QString relPath = KUrl( tmpURL ).path(); path += relPath.mid( 1 ); // remove leading '/' } if ( !path.endsWith( '/' ) ) path += '/'; const QString mimeType = odfLoadingContext.mimeTypeForPath( path ); //kDebug(35001) << "path for manifest file=" << path << "mimeType=" << mimeType; if ( mimeType.isEmpty() ) { //kDebug(35001) << "Manifest doesn't have media-type for" << path; return false; } const bool isOdf = mimeType.startsWith( "application/vnd.oasis.opendocument" ); if ( !isOdf ) { tmpURL += "/maindoc.xml"; //kDebug(35001) << "tmpURL adjusted to" << tmpURL; } //kDebug(35001) << "tmpURL=" << tmpURL; QString errorMsg; KoDocumentEntry e = KoDocumentEntry::queryByMimeType( mimeType ); if ( e.isEmpty() ) { return false; } bool res = true; if ( tmpURL.startsWith( STORE_PROTOCOL ) || tmpURL.startsWith( INTERNAL_PROTOCOL ) || KUrl::isRelativeUrl( tmpURL ) ) { if ( isOdf ) { store->pushDirectory(); Q_ASSERT( tmpURL.startsWith( INTERNAL_PROTOCOL ) ); QString relPath = KUrl( tmpURL ).path().mid( 1 ); store->enterDirectory( relPath ); res = m_document->loadOasisFromStore( store ); store->popDirectory(); } else { if ( tmpURL.startsWith( INTERNAL_PROTOCOL ) ) tmpURL = KUrl( tmpURL ).path().mid( 1 ); res = m_document->loadFromStore( store, tmpURL ); } m_document->setStoreInternal( true ); } else { // Reference to an external document. Hmmm... m_document->setStoreInternal( false ); KUrl url( tmpURL ); if ( !url.isLocalFile() ) { //QApplication::restoreOverrideCursor(); // For security reasons we need to ask confirmation if the // url is remote. int result = KMessageBox::warningYesNoCancel( 0, i18n( "This document contains an external link to a remote document\n%1", tmpURL ), i18n( "Confirmation Required" ), KGuiItem( i18n( "Download" ) ), KGuiItem( i18n( "Skip" ) ) ); if ( result == KMessageBox::Cancel ) { //d->m_parent->setErrorMessage("USER_CANCELED"); return false; } if ( result == KMessageBox::Yes ) res = m_document->openUrl( url ); // and if == No, res will still be false so we'll use a kounavail below } else res = m_document->openUrl( url ); } if ( !res ) { QString errorMessage = m_document->errorMessage(); return false; } tmpURL.clear(); return res; }
bool KoPatternBackground::loadStyle(KoOdfLoadingContext &context, const QSizeF &) { Q_D(KoPatternBackground); KoStyleStack &styleStack = context.styleStack(); if (! styleStack.hasProperty(KoXmlNS::draw, "fill")) return false; QString fillStyle = styleStack.property(KoXmlNS::draw, "fill"); if (fillStyle != "bitmap") return false; QString styleName = styleStack.property(KoXmlNS::draw, "fill-image-name"); KoXmlElement* e = context.stylesReader().drawStyles("fill-image")[styleName]; if (! e) return false; const QString href = e->attributeNS(KoXmlNS::xlink, "href", QString()); if (href.isEmpty()) return false; delete d->imageData; d->imageData = d->imageCollection->createImageData(href, context.store()); if (! d->imageData) return false; // read the pattern repeat style QString style = styleStack.property(KoXmlNS::style, "repeat"); if (style == "stretch") d->repeat = Stretched; else if (style == "no-repeat") d->repeat = Original; else d->repeat = Tiled; if (style != "stretch") { // optional attributes which can override original image size if (styleStack.hasProperty(KoXmlNS::draw, "fill-image-height")) { QString height = styleStack.property(KoXmlNS::draw, "fill-image-height"); if (height.endsWith('%')) d->targetImageSizePercent.setHeight(height.remove('%').toDouble()); else d->targetImageSize.setHeight(KoUnit::parseValue(height)); } if (styleStack.hasProperty(KoXmlNS::draw, "fill-image-width")) { QString width = styleStack.property(KoXmlNS::draw, "fill-image-width"); if (width.endsWith('%')) d->targetImageSizePercent.setWidth(width.remove('%').toDouble()); else d->targetImageSize.setWidth(KoUnit::parseValue(width)); } } if (style == "repeat") { 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"); if (align == "top-left") d->refPoint = TopLeft; else if (align == "top") d->refPoint = Top; else if (align == "top-right") d->refPoint = TopRight; else if (align == "left") d->refPoint = Left; else if (align == "center") d->refPoint = Center; else if (align == "right") d->refPoint = Right; else if (align == "bottom-left") d->refPoint = BottomLeft; else if (align == "bottom") d->refPoint = Bottom; else if (align == "bottom-right") d->refPoint = BottomRight; } if (styleStack.hasProperty(KoXmlNS::draw, "fill-image-ref-point-x")) { QString pointX = styleStack.property(KoXmlNS::draw, "fill-image-ref-point-x"); d->refPointOffsetPercent.setX(pointX.remove('%').toDouble()); } if (styleStack.hasProperty(KoXmlNS::draw, "fill-image-ref-point-y")) { QString pointY = styleStack.property(KoXmlNS::draw, "fill-image-ref-point-y"); d->refPointOffsetPercent.setY(pointY.remove('%').toDouble()); } if (styleStack.hasProperty(KoXmlNS::draw, "tile-repeat-offset")) { QString repeatOffset = styleStack.property(KoXmlNS::draw, "tile-repeat-offset"); QStringList tokens = repeatOffset.split('%'); if (tokens.count() == 2) { QString direction = tokens[1].simplified(); if (direction == "horizontal") d->tileRepeatOffsetPercent.setX(tokens[0].toDouble()); else if (direction == "vertical") d->tileRepeatOffsetPercent.setY(tokens[0].toDouble()); } } } return true; }
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; }