Exemplo n.º 1
0
 InitOnce()
 {
     KoToolRegistry * toolRegistry = KoToolRegistry::instance();
     toolRegistry->add( new KPrPlaceholderToolFactory() );
     KoShapeRegistry * registry = KoShapeRegistry::instance();
     registry->addFactory( new KPrPlaceholderShapeFactory() );
 }
Exemplo n.º 2
0
void SvgShapeFactory::addToRegistry()
{
    KoShapeRegistry *registry = KoShapeRegistry::instance();
    if (!registry->contains(QString(SVGSHAPEFACTORYID))) {
        registry->addFactory(new SvgShapeFactory);
    }
}
Exemplo n.º 3
0
KoShape* StencilShapeFactory::
createFromOdf(KoStore* store, KoDocumentResourceManager* documentRes) const
{
    KoOdfReadStore odfStore(store);
    QString errorMessage;
    if (! odfStore.loadAndParse(errorMessage)) {
        kError() << "loading and parsing failed:" << errorMessage << endl;
        return 0;
    }

    KoXmlElement content = odfStore.contentDoc().documentElement();
    KoXmlElement realBody(KoXml::namedItemNS(content, KoXmlNS::office, "body"));
    if (realBody.isNull()) {
        kError() << "No body tag found!" << endl;
        return 0;
    }

    KoXmlElement body = KoXml::namedItemNS(realBody, KoXmlNS::office, "drawing");
    if (body.isNull()) {
        kError() << "No office:drawing tag found!" << endl;
        return 0;
    }

    KoXmlElement page = KoXml::namedItemNS(body, KoXmlNS::draw, "page");
    if (page.isNull()) {
        kError() << "No page found!" << endl;
        return 0;
    }

    KoXmlElement shapeElement = KoXml::namedItemNS(page, KoXmlNS::draw, "g");
    if (shapeElement.isNull()) {
        shapeElement = KoXml::namedItemNS(page, KoXmlNS::draw, "custom-shape");
        if (shapeElement.isNull()) {
            kError() << "draw:g or draw:custom-shape element not found!" << endl;
            return 0;
        }
    }

    KoOdfLoadingContext loadingContext(odfStore.styles(), odfStore.store());
    KoShapeLoadingContext context(loadingContext, documentRes);

    KoShapeRegistry* registry = KoShapeRegistry::instance();
    foreach (const QString & id, registry->keys()) {
        KoShapeFactoryBase* shapeFactory = registry->value(id);
        shapeFactory->newDocumentResourceManager(documentRes);
    }

    return KoShapeRegistry::instance()->createShapeFromOdf(shapeElement, context);
}
Exemplo n.º 4
0
void TestKoShapeRegistry::testCreateFramedShapes()
{
    QBuffer xmldevice;
    xmldevice.open(QIODevice::WriteOnly);
    QTextStream xmlstream(&xmldevice);

    xmlstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    xmlstream << "<office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:config=\"urn:oasis:names:tc:opendocument:xmlns:config:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:calligra=\"http://www.calligra.org/2005/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">";
    xmlstream << "<office:body>";
    xmlstream << "<office:text>";
    xmlstream << "<draw:path svg:d=\"M0,0L100,100\"></draw:path>";
    xmlstream << "</office:text>";
    xmlstream << "</office:body>";
    xmlstream << "</office:document-content>";
    xmldevice.close();

    KoXmlDocument doc;
    QString errorMsg;
    int errorLine = 0;
    int errorColumn = 0;

    QCOMPARE(doc.setContent(&xmldevice, true, &errorMsg, &errorLine, &errorColumn), true);
    QCOMPARE(errorMsg.isEmpty(), true);
    QCOMPARE(errorLine, 0);
    QCOMPARE(errorColumn, 0);

    KoXmlElement contentElement = doc.documentElement();
    KoXmlElement bodyElement = contentElement.firstChild().toElement();

    KoShapeRegistry * registry = KoShapeRegistry::instance();

    // XXX: When loading is implemented, these no doubt have to be
    // sensibly filled.
    KoOdfStylesReader stylesReader;
    KoOdfLoadingContext odfContext(stylesReader, 0);
    KoShapeLoadingContext shapeContext(odfContext, 0);

    KoShape * shape = registry->createShapeFromOdf(bodyElement, shapeContext);
    QVERIFY(shape == 0);

    KoXmlElement pathElement = bodyElement.firstChild().firstChild().toElement();
    shape = registry->createShapeFromOdf(pathElement, shapeContext);
    QVERIFY(shape != 0);
    QVERIFY(shape->shapeId() == KoPathShapeId);
}
Exemplo n.º 5
0
DocBase::DocBase(QWidget *parentWidget, QObject* parent, bool singleViewMode)
    : KoDocument(parentWidget, parent, singleViewMode)
    , d(new Private)
{
    d->resourceManager = new KoResourceManager();
    d->map = new Map(this, CURRENT_SYNTAX_VERSION);

    // Document Url for FILENAME function and page header/footer.
    d->map->calculationSettings()->setFileName(url().prettyUrl());

    KoShapeRegistry *registry = KoShapeRegistry::instance();
    foreach (const QString &id, registry->keys()) {
        KoShapeFactoryBase *shapeFactory = registry->value(id);
        shapeFactory->newDocumentResourceManager(d->resourceManager);
    }

    d->configLoadFromFile = false;

    documents().append(this);

    d->sheetAccessModel = new SheetAccessModel(d->map);
}