void TestKoShapeFactory::testOdfElement() { KoShapeFactoryBase * factory = new KoPathShapeFactory(QStringList()); QVERIFY(factory->odfElements().front().second.contains("path")); QVERIFY(factory->odfElements().front().second.contains("line")); QVERIFY(factory->odfElements().front().second.contains("polyline")); QVERIFY(factory->odfElements().front().second.contains("polygon")); QVERIFY(factory->odfElements().front().first == KoXmlNS::draw); 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:koffice=\"http://www.koffice.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 << "<text:p text:style-name=\"P1\"><?opendocument cursor-position?></text:p>"; xmlstream << "<draw:path svg:d=\"M10,10L100,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(); // XXX: When loading is implemented, these no doubt have to be // sensibly filled. KoOdfStylesReader stylesReader; KoOdfLoadingContext odfContext(stylesReader, 0); KoShapeLoadingContext shapeContext(odfContext, 0); KoXmlElement textElement = bodyElement.firstChild().firstChild().toElement(); QVERIFY(textElement.tagName() == "p"); QCOMPARE(factory->supports(textElement, shapeContext), false); KoXmlElement pathElement = bodyElement.firstChild().lastChild().toElement(); QVERIFY(pathElement.tagName() == "path"); QCOMPARE(factory->supports(pathElement, shapeContext), true); KoShape *shape = factory->createDefaultShape(); QVERIFY(shape); QVERIFY(shape->loadOdf(pathElement, shapeContext)); delete shape; delete factory; }
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); }
//1.6: KWDocument::loadOasis bool KWOdfLoader::load(KoOdfReadStore &odfStore) { //debugWords << "========================> KWOdfLoader::load START"; QPointer<KoUpdater> updater; QPointer<KoUpdater> loadUpdater; if (m_document->progressUpdater()) { updater = m_document->progressUpdater()->startSubtask(1, "KWOdfLoader::load"); loadUpdater = m_document->progressUpdater()->startSubtask(5, "KWOdfLoader::loadOdf"); updater->setProgress(0); loadUpdater->setProgress(0); } KoXmlElement content = odfStore.contentDoc().documentElement(); KoXmlElement realBody(KoXml::namedItemNS(content, KoXmlNS::office, "body")); if (realBody.isNull()) { errorWords << "No office:body found!" << endl; m_document->setErrorMessage(i18n("Invalid OASIS OpenDocument file. No office:body tag found.")); return false; } KoXmlElement body = KoXml::namedItemNS(realBody, KoXmlNS::office, "text"); if (body.isNull()) { errorWords << "No office:text found!" << endl; KoXmlElement childElem; QString localName; forEachElement(childElem, realBody) localName = childElem.localName(); if (localName.isEmpty()) m_document->setErrorMessage(i18n("Invalid OASIS OpenDocument file. No tag found inside office:body.")); else m_document->setErrorMessage(i18n("This is not a word processing document, but %1. Please try opening it with the appropriate application.", KoDocument::tagNameToDocumentType(localName))); return false; } // Load attributes from the office:text. These are text:global and text:use-soft-page-breaks. QString textGlobal = body.attributeNS(KoXmlNS::text, "global"); bool isTextGlobal = (textGlobal == "true"); if (isTextGlobal) { m_document->setIsMasterDocument(true); } // FIXME: text:use-soft-page-breaks if (updater) updater->setProgress(20); KoOdfLoadingContext odfContext(odfStore.styles(), odfStore.store(), QLatin1String("calligrawords/styles/")); KoShapeLoadingContext sc(odfContext, m_document->resourceManager()); sc.setDocumentRdf(m_document->documentRdf()); // Load user defined variable declarations if (KoVariableManager *variableManager = m_document->inlineTextObjectManager()->variableManager()) { variableManager->loadOdf(body); } // Load all styles before the corresponding paragraphs try to use them! KWOdfSharedLoadingData *sharedData = new KWOdfSharedLoadingData(this); sc.addSharedData(KOTEXT_SHARED_LOADING_ID, sharedData); KoStyleManager *styleManager = m_document->resourceManager()->resource(KoText::StyleManager).value<KoStyleManager*>(); Q_ASSERT(styleManager); sharedData->loadOdfStyles(sc, styleManager); if (updater) updater->setProgress(40); loadMasterPageStyles(sc); // add page background frame set KWFrameSet *pageBackgroundFrameSet = new KWFrameSet(Words::BackgroundFrameSet); m_document->addFrameSet(pageBackgroundFrameSet); #if 0 //1.6: KWOasisLoader oasisLoader(this); // <text:page-sequence> oasis extension for DTP (2003-10-27 post by Daniel) m_processingType = (!KoXml::namedItemNS(body, KoXmlNS::text, "page-sequence").isNull()) ? DTP : WP; m_hasTOC = false; m_tabStop = MM_TO_POINT(15); const KoXmlElement *defaultParagStyle = styles.defaultStyle("paragraph"); if (defaultParagStyle) { KoStyleStack stack; stack.push(*defaultParagStyle); stack.setTypeProperties("paragraph"); QString tabStopVal = stack.property(KoXmlNS::style, "tab-stop-distance"); if (!tabStopVal.isEmpty()) m_tabStop = KoUnit::parseValue(tabStopVal); } m_initialEditing = 0; // TODO MAILMERGE // Variable settings // By default display real variable value if (!isReadWrite()) m_varColl->variableSetting()->setDisplayFieldCode(false); #endif // Load all styles before the corresponding paragraphs try to use them! #if 0 //1.6: if (m_frameStyleColl->loadOasisStyles(context) == 0) { // no styles loaded -> load default styles loadDefaultFrameStyleTemplates(); } if (m_tableStyleColl->loadOasisStyles(context, *m_styleColl, *m_frameStyleColl) == 0) { // no styles loaded -> load default styles loadDefaultTableStyleTemplates(); } static_cast<KWVariableSettings *>(m_varColl->variableSetting())->loadNoteConfiguration(styles.officeStyle()); loadDefaultTableTemplates(); //#else /* // We always needs at least one valid default paragraph style KoParagraphStyle *defaultParagraphStyle = m_document->styleManager()->defaultParagraphStyle(); //const KoXmlElement *defaultParagraphStyle = context.stylesReader().defaultStyle("paragraph"); //if(! defaultParagraphStyle) { KoParagraphStyle *parastyle = new KoParagraphStyle(); parastyle->setName("Standard"); m_document->styleManager()->add(parastyle); context.styleStack().setTypeProperties("paragraph"); // load all style attributes from "style:paragraph-properties" parastyle->loadOasis(context.styleStack()); // load the KoParagraphStyle from the stylestack KoCharacterStyle *charstyle = parastyle->characterStyle(); context.styleStack().setTypeProperties("text"); // load all style attributes from "style:text-properties" charstyle->loadOasis(context.styleStack()); // load the KoCharacterStyle from the stylestack //} */ #endif // load text:page-sequence KoXmlElement pageSequence = KoXml::namedItemNS(body, KoXmlNS::text, "page-sequence"); if (! pageSequence.isNull()) { KWPageManager *pageManager = m_document->pageManager(); KoXmlElement page; forEachElement(page, pageSequence) { if (page.namespaceURI() == KoXmlNS::text && page.localName() == "page") { QString master = page.attributeNS(KoXmlNS::text, "master-page-name", QString()); pageManager->appendPage(pageManager->pageStyle(master)); } } }
//1.6: KWDocument::loadOasis bool KWOdfLoader::load(KoOdfReadStore & odfStore) { emit sigProgress(0); //kDebug(32001) << "========================> KWOdfLoader::load START"; KoXmlElement content = odfStore.contentDoc().documentElement(); KoXmlElement realBody(KoXml::namedItemNS(content, KoXmlNS::office, "body")); if (realBody.isNull()) { kError(32001) << "No office:body found!" << endl; m_document->setErrorMessage(i18n("Invalid OASIS OpenDocument file. No office:body tag found.")); return false; } KoXmlElement body = KoXml::namedItemNS(realBody, KoXmlNS::office, "text"); if (body.isNull()) { kError(32001) << "No office:text found!" << endl; KoXmlElement childElem; QString localName; forEachElement(childElem, realBody) localName = childElem.localName(); if (localName.isEmpty()) m_document->setErrorMessage(i18n("Invalid OASIS OpenDocument file. No tag found inside office:body.")); else m_document->setErrorMessage(i18n("This is not a word processing document, but %1. Please try opening it with the appropriate application.", KoDocument::tagNameToDocumentType(localName))); return false; } // TODO check versions and mimetypes etc. bool hasMainText = false; KoXmlElement childElem; forEachElement(childElem, body) { if (childElem.namespaceURI() == KoXmlNS::text) { hasMainText = true; break; } } KoOdfLoadingContext odfContext(odfStore.styles(), odfStore.store(), m_document->componentData()); KoShapeLoadingContext sc(odfContext, m_document->dataCenterMap()); // Load all styles before the corresponding paragraphs try to use them! KWOdfSharedLoadingData * sharedData = new KWOdfSharedLoadingData(this); KoStyleManager *styleManager = dynamic_cast<KoStyleManager *>(m_document->dataCenterMap()["StyleManager"]); Q_ASSERT(styleManager); sharedData->loadOdfStyles(odfContext, styleManager); sc.addSharedData(KOTEXT_SHARED_LOADING_ID, sharedData); KoTextLoader * loader = new KoTextLoader(sc); Q_UNUSED(loader); KoOdfLoadingContext context(odfStore.styles(), odfStore.store(), m_document->componentData()); loadMasterPageStyles(context, hasMainText); #if 0 //1.6: KWOasisLoader oasisLoader(this); // <text:page-sequence> oasis extension for DTP (2003-10-27 post by Daniel) m_processingType = (!KoXml::namedItemNS(body, KoXmlNS::text, "page-sequence").isNull()) ? DTP : WP; m_hasTOC = false; m_tabStop = MM_TO_POINT(15); const KoXmlElement* defaultParagStyle = styles.defaultStyle("paragraph"); if (defaultParagStyle) { KoStyleStack stack; stack.push(*defaultParagStyle); stack.setTypeProperties("paragraph"); QString tabStopVal = stack.property(KoXmlNS::style, "tab-stop-distance"); if (!tabStopVal.isEmpty()) m_tabStop = KoUnit::parseValue(tabStopVal); } m_initialEditing = 0; // TODO MAILMERGE // Variable settings // By default display real variable value if (!isReadWrite()) m_varColl->variableSetting()->setDisplayFieldCode(false); #endif // Load all styles before the corresponding paragraphs try to use them! #if 0 //1.6: if (m_frameStyleColl->loadOasisStyles(context) == 0) { // no styles loaded -> load default styles loadDefaultFrameStyleTemplates(); } if (m_tableStyleColl->loadOasisStyles(context, *m_styleColl, *m_frameStyleColl) == 0) { // no styles loaded -> load default styles loadDefaultTableStyleTemplates(); } static_cast<KWVariableSettings *>(m_varColl->variableSetting())->loadNoteConfiguration(styles.officeStyle()); loadDefaultTableTemplates(); //#else /* // We always needs at least one valid default paragraph style KoParagraphStyle *defaultParagraphStyle = m_document->styleManager()->defaultParagraphStyle(); //const KoXmlElement* defaultParagraphStyle = context.stylesReader().defaultStyle("paragraph"); //if( ! defaultParagraphStyle ) { KoParagraphStyle *parastyle = new KoParagraphStyle(); parastyle->setName("Standard"); m_document->styleManager()->add(parastyle); context.styleStack().setTypeProperties( "paragraph" ); // load all style attributes from "style:paragraph-properties" parastyle->loadOasis(context.styleStack()); // load the KoParagraphStyle from the stylestack KoCharacterStyle *charstyle = parastyle->characterStyle(); context.styleStack().setTypeProperties( "text" ); // load all style attributes from "style:text-properties" charstyle->loadOasis(context.styleStack()); // load the KoCharacterStyle from the stylestack //} */ #endif // load text:page-sequence KoXmlElement pageSequence = KoXml::namedItemNS(body, KoXmlNS::text, "page-sequence"); if (! pageSequence.isNull()) { KWPageManager *pageManager = m_document->pageManager(); KoXmlElement page; forEachElement(page, pageSequence) { if (page.namespaceURI() == KoXmlNS::text && page.localName() == "page") { QString master = page.attributeNS(KoXmlNS::text, "master-page-name", QString()); pageManager->appendPage(pageManager->pageStyle(master)); } } }