Exemplo n.º 1
0
void KoPAPage::loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext )
{
    QString master = element.attributeNS (KoXmlNS::draw, "master-page-name" );
    KoPAMasterPage *masterPage = loadingContext.masterPageByName(master);
    if (masterPage)
        setMasterPage(masterPage);
#ifndef NDEBUG
    else
        kWarning(30010) << "Loading didn't provide a page under name; " << master;
#endif
    KoStyleStack& styleStack = loadingContext.odfLoadingContext().styleStack();
    int pageProperties = UseMasterBackground | DisplayMasterShapes | DisplayMasterBackground;
    if ( styleStack.hasProperty( KoXmlNS::draw, "fill" ) ) {
        KoPAPageBase::loadOdfPageTag( element, loadingContext );
        pageProperties = DisplayMasterShapes;
    }
    m_pageProperties = pageProperties;
    QString name;
    if ( element.hasAttributeNS( KoXmlNS::draw, "name" ) ) {
        name = element.attributeNS( KoXmlNS::draw, "name" );
        loadingContext.addPage( name, this );
    }
    if ( element.hasAttributeNS( KoXmlNS::koffice, "name" ) ) {
        name = element.attributeNS( KoXmlNS::koffice, "name" );
    }
    setName( name );
}
Exemplo n.º 2
0
bool RectangleShape::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context)
{
    loadOdfAttributes(element, context, OdfMandatories | OdfGeometry | OdfAdditionalAttributes | OdfCommonChildElements);

    if (element.hasAttributeNS(KoXmlNS::svg, "rx") && element.hasAttributeNS(KoXmlNS::svg, "ry")) {
        qreal rx = KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "rx", "0"));
        qreal ry = KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "ry", "0"));
        m_cornerRadiusX = rx / (0.5 * size().width()) * 100;
        m_cornerRadiusY = ry / (0.5 * size().height()) * 100;
    } else {
        QString cornerRadius = element.attributeNS(KoXmlNS::draw, "corner-radius", "");
        if (! cornerRadius.isEmpty()) {
            qreal radius = KoUnit::parseValue(cornerRadius);
            m_cornerRadiusX = qMin<qreal>(radius / (0.5 * size().width()) * 100, qreal(100));
            m_cornerRadiusY = qMin<qreal>(radius / (0.5 * size().height()) * 100, qreal(100));
        }
    }

    updatePath(size());
    updateHandles();

    loadOdfAttributes(element, context, OdfTransformation);
    loadText(element, context);

    return true;
}
Exemplo n.º 3
0
void KoPathShape::applyViewboxTransformation(const KoXmlElement & element)
{
    // apply viewbox transformation
    QRectF viewBox = loadOdfViewbox(element);
    if (! viewBox.isEmpty()) {
        // load the desired size
        QSizeF size;
        size.setWidth(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "width", QString())));
        size.setHeight(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "height", QString())));

        // load the desired position
        QPointF pos;
        pos.setX(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "x", QString())));
        pos.setY(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "y", QString())));

        // create matrix to transform original path data into desired size and position
        QMatrix viewMatrix;
        viewMatrix.translate(-viewBox.left(), -viewBox.top());
        viewMatrix.scale(size.width() / viewBox.width(), size.height() / viewBox.height());
        viewMatrix.translate(pos.x(), pos.y());

        // transform the path data
        map(viewMatrix);
    }
}
Exemplo n.º 4
0
bool KoPathShape::loadOdf(const KoXmlElement & element, KoShapeLoadingContext &context)
{
    loadOdfAttributes(element, context, OdfMandatories | OdfAdditionalAttributes | OdfCommonChildElements);

    // first clear the path data from the default path
    clear();

    if (element.localName() == "line") {
        QPointF start;
        start.setX(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "x1", "")));
        start.setY(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "y1", "")));
        QPointF end;
        end.setX(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "x2", "")));
        end.setY(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "y2", "")));
        moveTo(start);
        lineTo(end);
    } else if (element.localName() == "polyline" || element.localName() == "polygon") {
        QString points = element.attributeNS(KoXmlNS::draw, "points").simplified();
        points.replace(',', ' ');
        points.remove('\r');
        points.remove('\n');
        bool firstPoint = true;
        const QStringList coordinateList = points.split(' ');
        for (QStringList::ConstIterator it = coordinateList.constBegin(); it != coordinateList.constEnd(); ++it) {
            QPointF point;
            point.setX((*it).toDouble());
            ++it;
            point.setY((*it).toDouble());
            if (firstPoint) {
                moveTo(point);
                firstPoint = false;
            } else
                lineTo(point);
        }
        if (element.localName() == "polygon")
            close();
    } else { // path loading
        KoPathShapeLoader loader(this);
        loader.parseSvg(element.attributeNS(KoXmlNS::svg, "d"), true);
        loadNodeTypes(element);
    }

    applyViewboxTransformation(element);
    QPointF pos = normalize();
    setTransformation(QMatrix());

    if (element.hasAttributeNS(KoXmlNS::svg, "x") || element.hasAttributeNS(KoXmlNS::svg, "y")) {
        pos.setX(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "x", QString())));
        pos.setY(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "y", QString())));
    }

    setPosition(pos);

    loadOdfAttributes(element, context, OdfTransformation);

    return true;
}
Exemplo n.º 5
0
bool KoInlineNote::loadOdf(const KoXmlElement & element, KoShapeLoadingContext &context, KoStyleManager *styleManager, KoChangeTracker *changeTracker)
{
    QTextDocument *document = new QTextDocument();
    QTextCursor cursor(document);
    KoTextDocument textDocument(document);
    textDocument.setStyleManager(styleManager);
    d->styleManager = styleManager;
    textDocument.setChangeTracker(changeTracker);

    KoTextLoader loader(context);

    if (element.namespaceURI() == KoXmlNS::text && element.localName() == "note") {

        QString className = element.attributeNS(KoXmlNS::text, "note-class");
        if (className == "footnote") {
            d->type = Footnote;
        }
        else if (className == "endnote") {
            d->type = Endnote;
        }
        else {
            delete document;
            return false;
        }

        d->id = element.attributeNS(KoXmlNS::text, "id");
        for (KoXmlNode node = element.firstChild(); !node.isNull(); node = node.nextSibling()) {
            setAutoNumbering(false);
            KoXmlElement ts = node.toElement();
            if (ts.namespaceURI() != KoXmlNS::text)
                continue;
            if (ts.localName() == "note-body") {
                loader.loadBody(ts, cursor);
            } else if (ts.localName() == "note-citation") {
                d->label = ts.attributeNS(KoXmlNS::text, "label");
                if (d->label.isEmpty()) {
                    setAutoNumbering(true);
                    d->label = ts.text();
                }
            }
        }
    }
    else if (element.namespaceURI() == KoXmlNS::office && element.localName() == "annotation") {
        d->author = element.attributeNS(KoXmlNS::text, "dc-creator");
        d->date = QDateTime::fromString(element.attributeNS(KoXmlNS::text, "dc-date"), Qt::ISODate);
        loader.loadBody(element, cursor); // would skip author and date, and do just the <text-p> and <text-list> elements
    }
    else {
        delete document;
        return false;
    }

    d->text = QTextDocumentFragment(document);
    delete document;
    return true;
}
Exemplo n.º 6
0
bool Ko3dScene::Lightsource::loadOdf(const KoXmlElement &lightElement)
{
    m_diffuseColor = QColor(lightElement.attributeNS(KoXmlNS::dr3d, "diffuse-color", "#ffffff"));
    QString direction = lightElement.attributeNS(KoXmlNS::dr3d, "direction");
    m_direction = odfToVector3D(direction);
    m_enabled = (lightElement.attributeNS(KoXmlNS::dr3d, "enabled") == "true");
    m_specular = (lightElement.attributeNS(KoXmlNS::dr3d, "specular") == "true");

    return true;
}
Exemplo n.º 7
0
bool KoEnhancedPathShape::loadOdf( const KoXmlElement & element, KoShapeLoadingContext &context )
{
    reset();

    KoXmlElement child;
    forEachElement( child, element )
    {
        if( child.localName() == "enhanced-geometry" && child.namespaceURI() == KoXmlNS::draw )
        {
            // load the viewbox
            QRectF viewBox = loadOdfViewbox( child );
            if( ! viewBox.isEmpty() )
                m_viewBox = viewBox;

            // load the modifiers
            QString modifiers = child.attributeNS( KoXmlNS::draw, "modifiers", "" );
            if( ! modifiers.isEmpty() )
            {
                addModifiers( modifiers );
            }

            KoXmlElement grandChild;
            forEachElement( grandChild, child )
            {
                if( grandChild.namespaceURI() != KoXmlNS::draw )
                    continue;
                if( grandChild.localName() == "equation" )
                {
                    QString name = grandChild.attributeNS( KoXmlNS::draw, "name" );
                    QString formula = grandChild.attributeNS( KoXmlNS::draw, "formula" );
                    addFormula( name, formula );
                }
                else if( grandChild.localName() == "handle" )
                {
                    KoEnhancedPathHandle * handle = new KoEnhancedPathHandle( this );
                    if( handle->loadOdf( grandChild ) )
                    {
                        m_enhancedHandles.append( handle );
                        evaluateHandles();
                    }
                    else
                        delete handle;
                }

            }
            // load the enhanced path data
            QString path = child.attributeNS( KoXmlNS::draw, "enhanced-path", "" );
#ifndef NWORKAROUND_ODF_BUGS
            KoOdfWorkaround::fixEnhancedPath(path, child, context);
#endif
            if ( !path.isEmpty() ) {
                parsePathData( path );
            }
        }
    }
Exemplo n.º 8
0
bool KPrPageLayout::loadOdf( const KoXmlElement &element, const QRectF & pageRect )
{
    if ( element.hasAttributeNS( KoXmlNS::style, "display-name" ) ) {
        m_name = element.attributeNS( KoXmlNS::style, "display-name" );
    }
    else {
        m_name = element.attributeNS( KoXmlNS::style, "name" );
    }

    KoXmlElement child;
    forEachElement( child, element ) {
        if ( child.tagName() == "placeholder" && child.namespaceURI() == KoXmlNS::presentation ) {
            KPrPlaceholder * placeholder = new KPrPlaceholder;
            if ( placeholder->loadOdf( child, pageRect ) ) {
                m_placeholders.append( placeholder );
                if ( placeholder->presentationObject() == "handout" ) {
                    m_layoutType = Handout;
                }
            }
            else {
                warnStage << "loading placeholder failed";
                delete placeholder;
            }
        }
        else {
            warnStage << "unknown tag" << child.namespaceURI() << child.tagName() << "when loading page layout";
        }
    }

    bool retval = true;
    if ( m_placeholders.isEmpty() ) {
        warnStage << "no placeholder for page layout" << m_name << "found";
        retval = false;
    }
    else {
        /* 
         * do fixups for wrong saved data from OO somehow they save negative values for width and height somethimes
         * <style:presentation-page-layout style:name="AL10T12">
         *   <presentation:placeholder presentation:object="title" svg:x="2.057cm" svg:y="1.743cm" svg:width="23.911cm" svg:height="3.507cm"/>
         *   <presentation:placeholder presentation:object="outline" svg:x="2.057cm" svg:y="5.838cm" svg:width="11.669cm" svg:height="13.23cm"/>
         *   <presentation:placeholder presentation:object="object" svg:x="14.309cm" svg:y="5.838cm" svg:width="-0.585cm" svg:height="6.311cm"/>
         *   <presentation:placeholder presentation:object="object" svg:x="14.309cm" svg:y="12.748cm" svg:width="-0.585cm" svg:height="-0.601cm"/>
         * </style:presentation-page-layout>
         */
        QList<KPrPlaceholder *>::iterator it( m_placeholders.begin() );
        KPrPlaceholder * last = *it;
        ++it;
        for ( ; it != m_placeholders.end(); ++it ) {
            ( *it )->fix( last->rect( QSizeF( 1, 1 ) ) );
            last = *it;
        }
    }
    return retval;
}
Exemplo n.º 9
0
bool KoOdfLoadingContext::parseManifest(const KoXmlDocument &manifestDocument)
{
    // First find the manifest:manifest node.
    KoXmlNode  n = manifestDocument.firstChild();
    kDebug(30006) << "Searching for manifest:manifest " << n.toElement().nodeName();
    for (; !n.isNull(); n = n.nextSibling()) {
        if (!n.isElement()) {
            kDebug(30006) << "NOT element";
            continue;
        } else {
            kDebug(30006) << "element";
        }

        kDebug(30006) << "name:" << n.toElement().localName()
                      << "namespace:" << n.toElement().namespaceURI();

        if (n.toElement().localName() == "manifest"
            && n.toElement().namespaceURI() == KoXmlNS::manifest)
        {
            kDebug(30006) << "found manifest:manifest";
            break;
        }
    }
    if (n.isNull()) {
        kDebug(30006) << "Could not find manifest:manifest";
        return false;
    }

    // Now loop through the children of the manifest:manifest and
    // store all the manifest:file-entry elements.
    const KoXmlElement  manifestElement = n.toElement();
    for (n = manifestElement.firstChild(); !n.isNull(); n = n.nextSibling()) {

        if (!n.isElement())
            continue;

        KoXmlElement el = n.toElement();
        if (!(el.localName() == "file-entry" && el.namespaceURI() == KoXmlNS::manifest))
            continue;

        QString fullPath  = el.attributeNS(KoXmlNS::manifest, "full-path", QString());
        QString mediaType = el.attributeNS(KoXmlNS::manifest, "media-type", QString(""));
        QString version   = el.attributeNS(KoXmlNS::manifest, "version", QString());

        // Only if fullPath is valid, should we store this entry.
        // If not, we don't bother to find out exactly what is wrong, we just skip it.
        if (!fullPath.isNull()) {
            d->manifestEntries.insert(fullPath,
                                      new KoOdfManifestEntry(fullPath, mediaType, version));
        }
    }

    return true;
}
Exemplo n.º 10
0
bool Rotate::loadOdf(const KoXmlElement &objectElement, KoShapeLoadingContext &context)
{
    // Load style information.
    loadOdfAttributes(objectElement, context, OdfObjectAttributes);
    Object3D::loadOdf(objectElement, context);

    QString dummy;
    m_path = objectElement.attributeNS(KoXmlNS::svg, "d", "");
    m_viewBox = objectElement.attributeNS(KoXmlNS::svg, "viewBox", "");

    kDebug(31000) << "Rotate:" << m_path;
    return true;
}
Exemplo n.º 11
0
bool KPrPlaceholderShapeFactory::supports(const KoXmlElement & e) const
{
    // check parent if placeholder is set to true
    KoXmlNode parent = e.parentNode();
    if ( !parent.isNull() ) {
        KoXmlElement element = parent.toElement();
        if ( !element.isNull() ) {
            kDebug(33001) << "placeholder:" << ( element.attributeNS( KoXmlNS::presentation, "placeholder", "false" ) == "true" ); 
            return ( element.attributeNS( KoXmlNS::presentation, "placeholder", "false" ) == "true" );
        }
    }
    return false;
}
Exemplo n.º 12
0
bool PageVariable::loadOdf(const KoXmlElement & element, KoShapeLoadingContext & context)
{
    Q_UNUSED(context);
    const QString localName(element.localName());
    if (localName == "page-count") {
        m_type = PageCount;

        m_numberFormat.loadOdf(element);
    } else if (localName == "page-number") {
        m_type = PageNumber;

        // The text:select-page attribute is used to display the number of the previous or the following
        // page rather than the number of the current page.
        QString pageselect = element.attributeNS(KoXmlNS::text, "select-page", QString());
        if (pageselect == "previous")
            m_pageselect = KoTextPage::PreviousPage;
        else if (pageselect == "next")
            m_pageselect = KoTextPage::NextPage;
        else // "current"
            m_pageselect = KoTextPage::CurrentPage;

        // The value of a page number field can be adjusted by a specified number, allowing the display
        // of page numbers of following or preceding pages. The adjustment amount is specified using
        // the text:page-adjust attribute.
        m_pageadjust = element.attributeNS(KoXmlNS::text, "page-adjust", QString()).toInt();

        m_numberFormat.loadOdf(element);

        // The text:fixed attribute specifies whether or not the value of a field element is fixed. If
        // the value of a field is fixed, the value of the field element to which this attribute is
        // attached is preserved in all future edits of the document. If the value of the field is not
        // fixed, the value of the field may be replaced by a new value when the document is edited.
        m_fixed = element.attributeNS(KoXmlNS::text, "fixed", QString()) == "true";
    } else if (localName == "page-continuation-string") {
        m_type = PageContinuation;

        // This attribute specifies whether to check for a previous or next page and if the page exists, the
        // continuation text is printed.
        QString pageselect = element.attributeNS(KoXmlNS::text, "select-page", QString());
        if (pageselect == "previous")
            m_pageselect = KoTextPage::PreviousPage;
        else if (pageselect == "next")
            m_pageselect = KoTextPage::NextPage;
        else
            m_pageselect = KoTextPage::CurrentPage;

        // The text to display
        m_continuation = element.text();
    }
    return true;
}
Exemplo n.º 13
0
bool Sphere::loadOdf(const KoXmlElement &objectElement, KoShapeLoadingContext &context)
{
    // Load style information.
    loadOdfAttributes(objectElement, context, OdfObjectAttributes);
    Object3D::loadOdf(objectElement, context);

    // These strange default values come from the default values in OOo and LO.
    QString dummy;
    dummy = objectElement.attributeNS(KoXmlNS::dr3d, "center", "(0 0 0)");
    m_center = odfToVector3D(dummy);
    dummy = objectElement.attributeNS(KoXmlNS::dr3d, "size", "(5000.0 5000.0 5000.0)");
    m_size = odfToVector3D(dummy);

    kDebug(31000) << "Sphere:" << m_center << m_size;
    return true;
}
Exemplo n.º 14
0
bool Cube::loadOdf(const KoXmlElement &objectElement, KoShapeLoadingContext &context)
{
    // Load style information.
    loadOdfAttributes(objectElement, context, OdfObjectAttributes);
    Object3D::loadOdf(objectElement, context);

    // These strange default values come from the default values in OOo and LO.
    QString dummy;
    dummy = objectElement.attributeNS(KoXmlNS::dr3d, "min-edge", "(-2500.0 -2500.0 -2500.0)");
    m_minEdge = odfToVector3D(dummy);
    dummy = objectElement.attributeNS(KoXmlNS::dr3d, "max-edge", "(2500.0 2500.0 2500.0)");
    m_maxEdge = odfToVector3D(dummy);

    kDebug(31000) << "Cube:" << m_minEdge << m_maxEdge;
    return true;
}
Exemplo n.º 15
0
bool KoTextInlineRdf::loadOdf(const KoXmlElement &e)
{
    d->id = e.attribute("id", QString());
    d->subject = e.attributeNS(KoXmlNS::xhtml, "about");
    d->predicate = e.attributeNS(KoXmlNS::xhtml, "property");
    d->dt = e.attributeNS(KoXmlNS::xhtml, "datatype");
    QString content = e.attributeNS(KoXmlNS::xhtml, "content");
    //
    // Content / triple object explicitly set through an attribute
    //
    if (e.hasAttributeNS(KoXmlNS::xhtml, "content")) {
        d->isObjectAttriuteUsed = true;
        d->object = content;
    }
    return true;
}
Exemplo n.º 16
0
bool KoTextOnShapeContainer::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context)
{
    Q_D(KoTextOnShapeContainer);
    if (d->textShape == 0)
        return false; // probably because the factory was not found.

    KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(d->textShape->userData());
    Q_ASSERT(shapeData); // would be a bug in kotext

    QString styleName = element.attributeNS(KoXmlNS::draw, "style-name");
    if (!styleName.isEmpty()) {
        KoStyleStack &styleStack = context.odfLoadingContext().styleStack();
        styleStack.save();
        context.odfLoadingContext().fillStyleStack(element, KoXmlNS::draw, "style-name", "graphic");
        styleStack.setTypeProperties("graphic");
        QString valign = styleStack.property(KoXmlNS::draw, "textarea-vertical-align");
        if (valign == "top") {
            shapeData->setVerticalAlignment(Qt::AlignTop);
        } else if (valign == "middle") {
            shapeData->setVerticalAlignment(Qt::AlignVCenter);
        } else if (valign == "bottom") {
            shapeData->setVerticalAlignment(Qt::AlignBottom);
        }
        styleStack.restore();
    }

    return shapeData->loadOdf(element, context);
}
Exemplo n.º 17
0
QList<KoEventAction*> KoEventActionRegistry::createEventActionsFromOdf(const KoXmlElement & e, KoShapeLoadingContext & context) const
{
    QList<KoEventAction *> eventActions;

    if (e.namespaceURI() == KoXmlNS::office && e.tagName() == "event-listeners") {
        KoXmlElement element;
        forEachElement(element, e) {
            if (element.tagName() == "event-listener") {
                if (element.namespaceURI() == KoXmlNS::presentation) {
                    QString action(element.attributeNS(KoXmlNS::presentation, "action", QString()));
                    QHash<QString, KoEventActionFactory *>::const_iterator it(d->presentationEventActions.find(action));

                    if (it != d->presentationEventActions.constEnd()) {
                        KoEventAction * eventAction = it.value()->createEventAction();
                        if (eventAction) {
                            if (eventAction->loadOdf(element, context)) {
                                eventActions.append(eventAction);
                            } else {
                                delete eventAction;
                            }
                        }
                    } else {
                        kWarning(30006) << "presentation:event-listerer action = " << action << "not supported";
                    }
                } else if (element.namespaceURI() == KoXmlNS::script) {
                    // TODO
                } else {
                    kWarning(30006) << "element" << e.namespaceURI() << e.tagName() << "not supported";
                }
            } else {
                kWarning(30006) << "element" << e.namespaceURI() << e.tagName() << "not supported";
            }
        }
    } else {
Exemplo n.º 18
0
void KoStyleStack::push(const KoXmlElement& style)
{
    m_stack.append(style);
#ifdef DEBUG_STYLESTACK
    kDebug(30003) << "pushed" << style.attributeNS(m_styleNSURI, "name", QString()) << " -> count=" << m_stack.count();
#endif
}
Exemplo n.º 19
0
// Font size is a bit special. "115%" applies to "the fontsize of the parent style".
// This can be generalized though (hasPropertyThatCanBePercentOfParent() ? :)
qreal KoStyleStack::fontSize(const qreal defaultFontPointSize) const
{
    const QString name = "font-size";
    qreal percent = 1;
    QList<KoXmlElement>::ConstIterator it = m_stack.end(); // reverse iterator

    while (it != m_stack.begin()) {
        --it;
        KoXmlElement properties = KoXml::namedItemNS(*it, m_styleNSURI, m_propertiesTagName).toElement();
        if (properties.hasAttributeNS(m_foNSURI, name)) {
            const QString value = properties.attributeNS(m_foNSURI, name, QString());
            if (value.endsWith('%')) {
                //sebsauer, 20070609, the specs don't say that we have to calc them together but
                //just that we are looking for a valid parent fontsize. So, let's only take the
                //first percent definition into account and keep on to seek for a valid parent,
                //percent *= value.left( value.length() - 1 ).toDouble() / 100.0;
                if (percent == 1)
                    percent = value.left(value.length() - 1).toDouble() / 100.0;
            } else
                return percent * KoUnit::parseValue(value);   // e.g. 12pt
        }
    }

    //if there was no valid parent, we return the default fontsize together with an optional calculated percent-value.
    return percent * defaultFontPointSize;
}
Exemplo n.º 20
0
bool Object3D::loadOdf(const KoXmlElement &objectElement, KoShapeLoadingContext &context)
{
    Q_UNUSED(context);

    m_transform3D = objectElement.attributeNS(KoXmlNS::dr3d, "transform", "");

    return true;
}
Exemplo n.º 21
0
bool KoStyleStack::isUserStyle(const KoXmlElement& e, const QString& family) const
{
    if (e.attributeNS(m_styleNSURI, "family", QString()) != family)
        return false;
    const KoXmlElement parent = e.parentNode().toElement();
    //kDebug(30003) <<"tagName=" << e.tagName() <<" parent-tagName=" << parent.tagName();
    return parent.localName() == "styles" /*&& parent.namespaceURI() == KoXmlNS::office*/;
}
Exemplo n.º 22
0
bool EnhancedPathHandle::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context)
{
    if (element.localName() != "handle" || element.namespaceURI() != KoXmlNS::draw) {
        return false;
    }

    QString position = element.attributeNS(KoXmlNS::draw, "handle-position");
#ifndef NWORKAROUND_ODF_BUGS
    KoOdfWorkaround::fixEnhancedPathPolarHandlePosition(position, element, context);
#endif
    QStringList tokens = position.simplified().split(' ');
    if (tokens.count() != 2) {
        return false;
    }

    setPosition(m_parent->parameter(tokens[0]), m_parent->parameter(tokens[1]));

    // check if we have a polar handle
    if (element.hasAttributeNS(KoXmlNS::draw, "handle-polar")) {
        QString polar = element.attributeNS(KoXmlNS::draw, "handle-polar");
        QStringList tokens = polar.simplified().split(' ');
        if (tokens.count() == 2) {
            setPolarCenter(m_parent->parameter(tokens[0]), m_parent->parameter(tokens[1]));

            QString minRadius = element.attributeNS(KoXmlNS::draw, "handle-radius-range-minimum");
            QString maxRadius = element.attributeNS(KoXmlNS::draw, "handle-radius-range-maximum");
            if (!minRadius.isEmpty() && !maxRadius.isEmpty()) {
                setRadiusRange(m_parent->parameter(minRadius), m_parent->parameter(maxRadius));
            }
        }
    } else {
        QString minX = element.attributeNS(KoXmlNS::draw, "handle-range-x-minimum");
        QString maxX = element.attributeNS(KoXmlNS::draw, "handle-range-x-maximum");
        if (!minX.isEmpty() && ! maxX.isEmpty()) {
            setRangeX(m_parent->parameter(minX), m_parent->parameter(maxX));
        }

        QString minY = element.attributeNS(KoXmlNS::draw, "handle-range-y-minimum");
        QString maxY = element.attributeNS(KoXmlNS::draw, "handle-range-y-maximum");
        if (!minY.isEmpty() && ! maxY.isEmpty()) {
            setRangeY(m_parent->parameter(minY), m_parent->parameter(maxY));
        }
    }

    return hasPosition();
}
Exemplo n.º 23
0
bool KPrAnimSet::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context)
{
    bool retval = false;

    QString attributeName(element.attributeNS(KoXmlNS::smil, "attributeName", QString()));
    if (attributeName == "visibility") {
        m_visible = element.attributeNS(KoXmlNS::smil, "to", "hidden") == "visible";
        retval = true;
        kDebug(33003) << "animate visibility for shape with id" << m_visible;
    }
    else {
        kWarning(33003) << "attributeName" << attributeName << "not yet supported";
    }
    KPrAnimationBase::loadOdf(element, context);

    return retval;
}
Exemplo n.º 24
0
bool StarShapeFactory::supports(const KoXmlElement &e, KoShapeLoadingContext &context) const
{
    Q_UNUSED(context);
    if (e.localName() == "regular-polygon" && e.namespaceURI() == KoXmlNS::draw) {
        return true;
    }
    return (e.localName() == "custom-shape" && e.namespaceURI() == KoXmlNS::draw
            && e.attributeNS(KoXmlNS::draw, "engine", "") == "calligra:star");
}
Exemplo n.º 25
0
bool KoInlineNote::loadOdf(const KoXmlElement & element)
{
    if (element.namespaceURI() != KoXmlNS::text || element.localName() != "note")
        return false;

    QString className = element.attributeNS(KoXmlNS::text, "note-class");
    if (className == "footnote")
        d->type = Footnote;
    else if (className == "endnote")
        d->type = Endnote;
    else
        return false;

    d->id = element.attributeNS(KoXmlNS::text, "id");
    for (KoXmlNode node = element.firstChild(); !node.isNull(); node = node.nextSibling()) {
        setAutoNumbering(false);
        KoXmlElement ts = node.toElement();
        if (ts.namespaceURI() != KoXmlNS::text)
            continue;
        if (ts.localName() == "note-body") {
            d->text = "";
            KoXmlNode node = ts.firstChild();
            while (!node.isNull()) {
                KoXmlElement commentElement = node.toElement();
                if (!commentElement.isNull()) {
                    if (commentElement.localName() == "p" && commentElement.namespaceURI() == KoXmlNS::text) {
                        if (!d->text.isEmpty())
                            d->text.append('\n');
                        d->text.append(commentElement.text());
                    }
                }
                node = node.nextSibling();
            }
        } else if (ts.localName() == "note-citation") {
            d->label = ts.attributeNS(KoXmlNS::text, "label");
            if (d->label.isEmpty()) {
                setAutoNumbering(true);
                d->label = ts.text();
            }
        }
    }

    return true;
}
Exemplo n.º 26
0
bool KPrDeclarations::loadOdf(const KoXmlElement &body, KoPALoadingContext &context)
{
    Q_UNUSED(context);

    KoXmlElement element;
    forEachElement( element, body ) {
        if (element.namespaceURI() == KoXmlNS::presentation) {
            if (element.tagName() == "header-decl") {
                const QString name = element.attributeNS(KoXmlNS::presentation, "name", QString());
                m_declarations[Header].insert(name, element.text());
            }
            else if(element.tagName() == "footer-decl") {
                const QString name = element.attributeNS(KoXmlNS::presentation, "name", QString());
                m_declarations[Footer].insert(name, element.text());
            }
            else if(element.tagName() == "date-time-decl") {
                QMap<QString, QVariant> data;
                const QString name = element.attributeNS(KoXmlNS::presentation, "name", QString());
                data["fixed"] = element.attributeNS(KoXmlNS::presentation, "source", "fixed") == "fixed";

                QString styleName = element.attributeNS(KoXmlNS::style, "data-style-name", "");
                if (!styleName.isEmpty()) {
                    KoOdfStylesReader::DataFormatsMap::const_iterator it = context.odfLoadingContext().stylesReader().dataFormats().constFind(styleName);
                    if (it != context.odfLoadingContext().stylesReader().dataFormats().constEnd()) {

                        QString formatString = (*it).first.prefix + (*it).first.formatStr + (*it).first.suffix;
                        data["format"] = formatString;
                    }
                }
                else {
                    data["format"] = QString("");
                    data["fixed value"] = element.text();
                }

                m_declarations[DateTime].insert(name, data);
            }
        }
        else if (element.tagName() == "page" && element.namespaceURI() == KoXmlNS::draw) {
            break;
        }
    }
    return true;
}
Exemplo n.º 27
0
void KoChangeTracker::loadOdfChanges(const KoXmlElement& element)
{
    KoXmlElement tag;
    forEachElement(tag, element) {
        if (! tag.isNull()) {
            const QString localName = tag.localName();
            if (localName == "changed-region") {
                KoChangeTrackerElement *changeElement;
                KoXmlElement region;
                forEachElement(region, tag) {
                    if (!region.isNull()) {
                        if (region.localName() == "insertion") {
                            changeElement = new KoChangeTrackerElement(tag.attributeNS(KoXmlNS::text,"id"),KoGenChange::insertChange);
                        } else if (region.localName() == "format-change") {
                            changeElement = new KoChangeTrackerElement(tag.attributeNS(KoXmlNS::text,"id"),KoGenChange::formatChange);
                        } else if (region.localName() == "deletion") {
                            changeElement = new KoChangeTrackerElement(tag.attributeNS(KoXmlNS::text,"id"),KoGenChange::deleteChange);
                        }
                        KoXmlElement metadata = region.namedItemNS(KoXmlNS::office,"change-info").toElement();
                        if (!metadata.isNull()) {
                            KoXmlElement date = metadata.namedItem("dc-date").toElement();
                            if (!date.isNull()) {
                                changeElement->setDate(date.text());
                            }
                            KoXmlElement creator = metadata.namedItem("dc-creator").toElement();
                            if (!date.isNull()) {
                                changeElement->setCreator(creator.text());
                            }
                            //TODO load comments
/*                            KoXmlElement extra = metadata.namedItem("dc-").toElement();
                            if (!date.isNull()) {
                                kDebug() << "creator: " << creator.text();
                                changeElement->setCreator(creator.text());
                            }*/
                        }
                        d->m_changes.insert( d->m_changeId, changeElement);
                        d->m_loadedChanges.insert(tag.attributeNS(KoXmlNS::text,"id"), d->m_changeId++);
                    }
                }
            }
        }
    }
Exemplo n.º 28
0
void KoPAMasterPage::loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext )
{
    KoPAPageBase::loadOdfPageTag( element, loadingContext );
    if ( element.hasAttributeNS( KoXmlNS::style, "display-name" ) ) {
        setName( element.attributeNS( KoXmlNS::style, "display-name" ) );
    }
    else {
        setName( element.attributeNS( KoXmlNS::style, "name" ) );
    }
    QString pageLayoutName = element.attributeNS( KoXmlNS::style, "page-layout-name" );
    const KoOdfStylesReader& styles = loadingContext.odfLoadingContext().stylesReader();
    const KoXmlElement* masterPageStyle = styles.findStyle( pageLayoutName );
    KoPageLayout pageLayout;

    if ( masterPageStyle ) {
        pageLayout.loadOdf( *masterPageStyle );
    }

    setPageLayout( pageLayout );
}
Exemplo n.º 29
0
KoOasisSettings::Items KoOasisSettings::NamedMap::entry(const QString& entryName) const
{
    KoXmlElement entry;
    forEachElement(entry, m_element) {
        if (entry.localName() == "config-item-map-entry" &&
                entry.namespaceURI() == m_settings->m_configNsUri &&
                entry.attributeNS(m_settings->m_configNsUri, "name", QString()) == entryName) {
            return Items(entry, m_settings);
        }
    }
    return Items(KoXmlElement(), m_settings);
}
Exemplo n.º 30
0
KoOasisSettings::NamedMap KoOasisSettings::Items::namedMap(const QString& itemMapName) const
{
    KoXmlElement configItem;
    forEachElement(configItem, m_element) {
        if (configItem.localName() == "config-item-map-named" &&
                configItem.namespaceURI() == m_settings->m_configNsUri &&
                configItem.attributeNS(m_settings->m_configNsUri, "name", QString()) == itemMapName) {
            return NamedMap(configItem, m_settings);
        }
    }
    return NamedMap(KoXmlElement(), m_settings);
}