diff --git a/libs/odf/CMakeLists.txt b/libs/odf/CMakeLists.txt index ed635ddacd..ce9ce1000d 100644 --- a/libs/odf/CMakeLists.txt +++ b/libs/odf/CMakeLists.txt @@ -1,38 +1,37 @@ add_subdirectory( tests ) set(kritaodf_LIB_SRCS KoOdfManifestEntry.cpp KoDocumentInfo.cpp KoGenStyle.cpp KoGenStyles.cpp KoFontFace.cpp KoOdfLoadingContext.cpp KoOdfStylesReader.cpp KoOdfNumberStyles.cpp KoOdfReadStore.cpp KoOdfWriteStore.cpp KoStyleStack.cpp KoOdfGraphicStyles.cpp KoDocumentBase.cpp KoEmbeddedDocumentSaver.cpp KoBorder.cpp KoShadowStyle.cpp KoPageLayout.cpp KoPageFormat.cpp KoUnit.cpp - KoOdfNotesConfiguration.cpp KoOdfNumberDefinition.cpp KoElementReference.cpp OdfDebug.cpp ) add_library(kritaodf SHARED ${kritaodf_LIB_SRCS}) generate_export_header(kritaodf BASE_NAME kritaodf) target_link_libraries(kritaodf kritaversion kritaplugin kritastore KF5::CoreAddons KF5::ConfigCore KF5::I18n Qt5::PrintSupport Qt5::Gui Qt5::Xml) set_target_properties(kritaodf PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION} ) install(TARGETS kritaodf ${INSTALL_TARGETS_DEFAULT_ARGS} ) diff --git a/libs/odf/KoOdfNotesConfiguration.cpp b/libs/odf/KoOdfNotesConfiguration.cpp deleted file mode 100644 index 4b1f35bcaa..0000000000 --- a/libs/odf/KoOdfNotesConfiguration.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/* This file is part of the KDE project - - Copyright (C) 2010 Boudewijn Rempt - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ -#include "KoOdfNotesConfiguration.h" - -#include -#include "KoXmlNS.h" -#include "KoXmlWriter.h" -#include "KoXmlReader.h" -#include "KoOdfNumberDefinition.h" - -class Q_DECL_HIDDEN KoOdfNotesConfiguration::Private -{ -public: - KoOdfNotesConfiguration::NoteClass noteClass; - QString citationTextStyleName; - QString citationBodyTextStyleName; - QString defaultNoteParagraphStyleName; - void *citationTextStyle; - void *citationBodyTextStyle; - void *defaultNoteParagraphStyle; - QString masterPageName; - int startValue; - KoOdfNumberDefinition numberFormat; - KoOdfNotesConfiguration::NumberingScheme numberingScheme; - KoOdfNotesConfiguration::FootnotesPosition footnotesPosition; - QString footnotesContinuationForward; - QString footnotesContinuationBackward; - -}; - -KoOdfNotesConfiguration::KoOdfNotesConfiguration(NoteClass noteClass) - : d(new Private()) -{ - d->noteClass = noteClass; - d->startValue = 1; - d->numberingScheme = BeginAtDocument; - d->footnotesPosition = Page; - - d->defaultNoteParagraphStyle = 0; - d->citationTextStyle = 0; - d->citationBodyTextStyle = 0; - - if (noteClass == KoOdfNotesConfiguration::Footnote) { - d->numberFormat.setFormatSpecification(KoOdfNumberDefinition::Numeric); - d->defaultNoteParagraphStyleName = "Footnote"; - d->citationTextStyleName = "Footnote_20_Symbol"; - d->citationBodyTextStyleName = "Footnote_20_anchor"; - } else { - d->numberFormat.setFormatSpecification(KoOdfNumberDefinition::RomanLowerCase); - d->defaultNoteParagraphStyleName = "Endnote"; - d->citationTextStyleName = "Endnote_20_Symbol"; - d->citationBodyTextStyleName = "Endnote_20_anchor"; - } -} - -KoOdfNotesConfiguration::~KoOdfNotesConfiguration() -{ - delete d; -} - -KoOdfNotesConfiguration::KoOdfNotesConfiguration(const KoOdfNotesConfiguration &other) - : QObject(), d(new Private()) -{ - d->noteClass = other.d->noteClass; - d->citationTextStyleName = other.d->citationTextStyleName; - d->citationBodyTextStyleName = other.d->citationBodyTextStyleName; - d->defaultNoteParagraphStyleName = other.d->defaultNoteParagraphStyleName; - d->citationTextStyle = other.d->citationTextStyle; - d->citationBodyTextStyle = other.d->citationBodyTextStyle; - d->defaultNoteParagraphStyle = other.d->defaultNoteParagraphStyle; - d->masterPageName = other.d->masterPageName; - d->startValue = other.d->startValue; - d->numberFormat = other.d->numberFormat; - d->numberingScheme = other.d->numberingScheme; - d->footnotesPosition = other.d->footnotesPosition; - d->footnotesContinuationForward = other.d->footnotesContinuationForward; - d->footnotesContinuationBackward = other.d->footnotesContinuationBackward; - -} - -KoOdfNotesConfiguration &KoOdfNotesConfiguration::operator=(const KoOdfNotesConfiguration &other) -{ - d->noteClass = other.d->noteClass; - d->citationTextStyleName = other.d->citationTextStyleName; - d->citationBodyTextStyleName = other.d->citationBodyTextStyleName; - d->defaultNoteParagraphStyleName = other.d->defaultNoteParagraphStyleName; - d->citationTextStyle = other.d->citationTextStyle; - d->citationBodyTextStyle = other.d->citationBodyTextStyle; - d->defaultNoteParagraphStyle = other.d->defaultNoteParagraphStyle; - d->masterPageName = other.d->masterPageName; - d->startValue = other.d->startValue; - d->numberFormat = other.d->numberFormat; - d->numberingScheme = other.d->numberingScheme; - d->footnotesPosition = other.d->footnotesPosition; - d->footnotesContinuationForward = other.d->footnotesContinuationForward; - d->footnotesContinuationBackward = other.d->footnotesContinuationBackward; - - return *this; -} - - -void KoOdfNotesConfiguration::loadOdf(const KoXmlElement &element) -{ - d->citationTextStyleName = element.attributeNS(KoXmlNS::text, "citation-style-name", d->citationTextStyleName); - d->citationBodyTextStyleName = element.attributeNS(KoXmlNS::text, "citation-body-style-name", d->citationBodyTextStyleName); - d->defaultNoteParagraphStyleName = element.attributeNS(KoXmlNS::text, "default-style-name", d->defaultNoteParagraphStyleName); - d->masterPageName = element.attributeNS(KoXmlNS::text, "master-page-name", d->masterPageName); - d->startValue = qMax(1, element.attributeNS(KoXmlNS::text, "start-value", QString::number(d->startValue)).toInt()); - - d->numberFormat.loadOdf(element); - - QString numberingScheme = element.attributeNS(KoXmlNS::text, "start-numbering-at", "document"); - if (numberingScheme == "document") { - d->numberingScheme = BeginAtDocument; - } - else if (numberingScheme == "chapter") { - d->numberingScheme = BeginAtChapter; - } - else if (numberingScheme == "page") { - d->numberingScheme = BeginAtPage; - } - - QString footnotesPosition = element.attributeNS(KoXmlNS::text, "footnotes-position", "page"); - if (footnotesPosition == "text") { - d->footnotesPosition = Text; - } - else if (footnotesPosition == "page") { - d->footnotesPosition = Page; - } - else if (footnotesPosition == "section") { - d->footnotesPosition = Section; - } - else if (footnotesPosition == "document") { - d->footnotesPosition = Document; - } - - for (KoXmlNode node = element.firstChild(); !node.isNull(); node = node.nextSibling()) { - KoXmlElement child = node.toElement(); - if (child.namespaceURI() == KoXmlNS::text) { - if (child.localName() == "note-continuation-notice-forward") { - d->footnotesContinuationForward = child.text(); - } else if (child.localName() == "note-continuation-notice-backward") { - d->footnotesContinuationBackward = child.text(); - } - } - } -} - -void KoOdfNotesConfiguration::saveOdf(KoXmlWriter *writer) const -{ - writer->startElement("text:notes-configuration"); - - if (d->noteClass == Footnote) { - writer->addAttribute("text:note-class", "footnote"); - } - else if (d->noteClass == Endnote) { - writer->addAttribute("text:note-class", "endnote"); - } - if (!d->citationTextStyleName.isNull()) {writer->addAttribute("text:citation-style-name", d->citationTextStyleName); } - if (!d->citationBodyTextStyleName.isNull()) {writer->addAttribute("text:citation-body-style-name", d->citationBodyTextStyleName); } - if (!d->defaultNoteParagraphStyleName.isNull()) {writer->addAttribute("text:default-style-name", d->defaultNoteParagraphStyleName); } - if (!d->masterPageName.isNull()) {writer->addAttribute("text:master-page-name", d->masterPageName); } - if (d->startValue != 0) { writer->addAttribute("text:start-value", d->startValue); } - - d->numberFormat.saveOdf(writer); - switch(d->numberingScheme) { - case BeginAtDocument: - writer->addAttribute("text:start-numbering-at", "document"); - break; - case BeginAtChapter: - writer->addAttribute("text:start-numbering-at", "chapter"); - break; - case BeginAtPage: - writer->addAttribute("text:start-numbering-at", "page"); - break; - } - switch(d->footnotesPosition) { - case Text: - writer->addAttribute("text:footnotes-position", "text"); - break; - case Page: - writer->addAttribute("text:footnotes-position", "page"); - break; - case Section: - writer->addAttribute("text:footnotes-position", "section"); - break; - case Document: - writer->addAttribute("text:footnotes-position", "document"); - break; - } - if (!d->footnotesContinuationForward.isNull()) { - writer->startElement("text:note-continuation-notice-forward", false); - writer->addTextNode(d->footnotesContinuationForward); - writer->endElement(); - } - if (!d->footnotesContinuationBackward.isNull()) { - writer->startElement("text:note-continuation-notice-backward", false); - writer->addTextNode(d->footnotesContinuationBackward); - writer->endElement(); - } - - writer->endElement(); //text:notes-configuration -} - - -KoOdfNotesConfiguration::NoteClass KoOdfNotesConfiguration::noteClass() const -{ - return d->noteClass; -} - - -void *KoOdfNotesConfiguration::citationTextStyle() const -{ - return d->citationTextStyle; -} - -QString KoOdfNotesConfiguration::citationTextStyleName() const -{ - return d->citationTextStyleName; -} - -void KoOdfNotesConfiguration::setCitationTextStyle(void *citationTextStyle) -{ - d->citationTextStyle = citationTextStyle; -} - -void *KoOdfNotesConfiguration::citationBodyTextStyle() const -{ - return d->citationBodyTextStyle; -} - -QString KoOdfNotesConfiguration::citationBodyTextStyleName() const -{ - return d->citationBodyTextStyleName; -} - -void KoOdfNotesConfiguration::setCitationBodyTextStyle(void *citationBodyTextStyle) -{ - d->citationBodyTextStyle = citationBodyTextStyle; -} - -void *KoOdfNotesConfiguration::defaultNoteParagraphStyle() const -{ - return d->defaultNoteParagraphStyle; -} - -QString KoOdfNotesConfiguration::defaultNoteParagraphStyleName() const -{ - return d->defaultNoteParagraphStyleName; -} - -void KoOdfNotesConfiguration::setDefaultNoteParagraphStyle(void *defaultNoteParagraphStyle) -{ - d->defaultNoteParagraphStyle = defaultNoteParagraphStyle; -} - -QString KoOdfNotesConfiguration::masterPage() const -{ - return d->masterPageName; -} - -void KoOdfNotesConfiguration::setMasterPage(const QString &masterPage) -{ - d->masterPageName = masterPage; -} - -int KoOdfNotesConfiguration::startValue() const -{ - return d->startValue; -} - -void KoOdfNotesConfiguration::setStartValue(int startValue) -{ - d->startValue = qMax(1, startValue); -} - - -KoOdfNumberDefinition KoOdfNotesConfiguration::numberFormat() const -{ - return d->numberFormat; -} - -void KoOdfNotesConfiguration::setNumberFormat(const KoOdfNumberDefinition &numberFormat) -{ - d->numberFormat = numberFormat; -} - -KoOdfNotesConfiguration::NumberingScheme KoOdfNotesConfiguration::numberingScheme() const -{ - return d->numberingScheme; -} - -void KoOdfNotesConfiguration::setNumberingScheme(NumberingScheme numberingScheme) -{ - d->numberingScheme = numberingScheme; -} - -KoOdfNotesConfiguration::FootnotesPosition KoOdfNotesConfiguration::footnotesPosition() const -{ - return d->footnotesPosition; -} - -void KoOdfNotesConfiguration::setFootnotesPosition(FootnotesPosition footnotesPosition) -{ - d->footnotesPosition = footnotesPosition; -} - -QString KoOdfNotesConfiguration::footnoteContinuationForward() const -{ - return d->footnotesContinuationForward; -} - -void KoOdfNotesConfiguration::setFootnoteContinuationForward(const QString &footnoteContinuationForward) -{ - d->footnotesContinuationForward = footnoteContinuationForward; -} - -QString KoOdfNotesConfiguration::footnoteContinuationBackward() const -{ - return d->footnotesContinuationBackward; -} - -void KoOdfNotesConfiguration::setFootnoteContinuationBackward(const QString &footnoteContinuationBackward) -{ - d->footnotesContinuationBackward = footnoteContinuationBackward; -} diff --git a/libs/odf/KoOdfNotesConfiguration.h b/libs/odf/KoOdfNotesConfiguration.h deleted file mode 100644 index f19d18ccc7..0000000000 --- a/libs/odf/KoOdfNotesConfiguration.h +++ /dev/null @@ -1,189 +0,0 @@ -/* This file is part of the KDE project - - Copyright (C) 2010 Boudewijn Rempt - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ -#ifndef KOODFNOTESCONFIGURATION_H -#define KOODFNOTESCONFIGURATION_H - -#include -#include - -#include "KoXmlReaderForward.h" -#include "kritaodf_export.h" - -class KoXmlWriter; -class KoOdfNumberDefinition; - -/** - * load and save the notes-configuration element from the text: namespace. - * - * @see 14.9.2 Notes Configuration Element - * A document in OpenDocument format contains at most one notes configuration element for every - * notes class used in the document. If there is no note configuration element, a default note - * configuration is used. - * The attributes that may be associated with the element are: - * - * • Note class - * • Citation text style - * • Citation body text style - * • Default footnote paragraph style - * • Master page - * • Start value - * • Number format - * • Numbering scheme - * • Footnote position - * - * The following element may be included in the element: - * - * • Footnote continuation notice (forward and backward) - */ -class KRITAODF_EXPORT KoOdfNotesConfiguration : public QObject -{ - Q_OBJECT -public: - - /** - * Note class - * The note class attribute determines which note elements this notes configuration applies to. - */ - enum NoteClass { - Footnote, - Endnote - }; - - KoOdfNotesConfiguration(NoteClass noteClass); - ~KoOdfNotesConfiguration() override; - KoOdfNotesConfiguration(const KoOdfNotesConfiguration &other); - KoOdfNotesConfiguration &operator=(const KoOdfNotesConfiguration &other); - - - /** - * load the notes-configuration element - */ - void loadOdf(const KoXmlElement &element); - - /** - * save the notes-configuration element - */ - void saveOdf(KoXmlWriter * writer) const; - - - NoteClass noteClass() const; - - /** - * Citation Text Style - * The text:citation-style attribute specifies the text style to use for the footnote citation - * within the footnote. - */ - QString citationTextStyleName() const; - void *citationTextStyle() const; - void setCitationTextStyle(void *citationTextStyle); - - /** - * Citation Body Text Style - * The text:citation-body-style-name attribute specifies the text style to use for the - * footnote citation in the text flow. - */ - QString citationBodyTextStyleName() const; - void *citationBodyTextStyle() const; - void setCitationBodyTextStyle(void *citationBodyTextStyle); - - /** - * Default Note Paragraph Style - * The default footnote paragraph style is only used for footnotes that are inserted into an existing - * document. It is not used for footnotes that already exist. - */ - QString defaultNoteParagraphStyleName() const; - void *defaultNoteParagraphStyle() const; - void setDefaultNoteParagraphStyle(void *defaultNoteParagraphStyle); - - /** - * Master Page - * To display the footnotes at the end of the document, the pages that contain the footnotes must be - * instances of the master page specified by the text:master-page-name attribute. - */ - QString masterPage() const; - void setMasterPage(const QString &masterPage); - - /** - * Start Value - * The start:value attribute specifies the value at which the footnote numbering starts. - */ - int startValue() const; - void setStartValue(int startValue); - - /** - * Number Format - * See section 12.2 for information on the number format for footnotes. - */ - KoOdfNumberDefinition numberFormat() const; - void setNumberFormat(const KoOdfNumberDefinition &numberFormat); - - /** - * Numbering Scheme - * The text:start-numbering-at attribute specifies if footnote numbers start with a new - * number at the beginning of the document or at the beginning of each chapter or page. - */ - enum NumberingScheme { - BeginAtDocument, - BeginAtChapter, - BeginAtPage - }; - - NumberingScheme numberingScheme() const; - void setNumberingScheme(NumberingScheme numberingScheme); - - /** - * Footnotes Position - * • The text:footnotes-position attribute specifies one of the following positions for footnotes: - * • text: At the page where the footnote citation is located, immediately below the page's text. - * • page: The bottom of the page where the footnote citation is located. - * • section: The end of the section - * • document: The end of the document. - */ - enum FootnotesPosition { - Text, - Page, - Section, - Document - }; - - FootnotesPosition footnotesPosition() const; - void setFootnotesPosition(FootnotesPosition footnotesPosition); - - /** - * Footnote Continuation - * The footnote continuation elements specify: - * • Text displayed at the end of a footnote that is continued on the next page - * • Text displayed before the continued text - */ - QString footnoteContinuationForward() const; - void setFootnoteContinuationForward(const QString &footnoteContinuationForward); - - QString footnoteContinuationBackward() const; - void setFootnoteContinuationBackward(const QString &footnoteContinuationBackward); - -private: - - class Private; - Private * const d; - -}; - -Q_DECLARE_METATYPE(KoOdfNotesConfiguration*) - -#endif // KOODFNOTESCONFIGURATION_H diff --git a/libs/odf/KoOdfStylesReader.cpp b/libs/odf/KoOdfStylesReader.cpp index c980ae942a..a8c46fe809 100644 --- a/libs/odf/KoOdfStylesReader.cpp +++ b/libs/odf/KoOdfStylesReader.cpp @@ -1,391 +1,367 @@ /* This file is part of the KDE project Copyright (C) 2004-2006 David Faure Copyright (C) 2007 Jan Hambrecht Copyright (C) 2008 Thorsten Zachmann This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KoOdfStylesReader.h" #include "KoXmlNS.h" -#include "KoOdfNotesConfiguration.h" #include "KoOdfNumberDefinition.h" #include "KoXmlReader.h" #include class Q_DECL_HIDDEN KoOdfStylesReader::Private { public: Private() - : globalFootnoteConfiguration(KoOdfNotesConfiguration::Footnote) - , globalEndnoteConfiguration(KoOdfNotesConfiguration::Endnote) { } QHash < QString /*family*/, QHash < QString /*name*/, KoXmlElement* > > customStyles; // auto-styles in content.xml QHash < QString /*family*/, QHash < QString /*name*/, KoXmlElement* > > contentAutoStyles; // auto-styles in styles.xml QHash < QString /*family*/, QHash < QString /*name*/, KoXmlElement* > > stylesAutoStyles; QHash < QString /*family*/, KoXmlElement* > defaultStyles; QHash < QString /*name*/, KoXmlElement* > styles; // page-layout, font-face etc. QHash < QString /*name*/, KoXmlElement* > masterPages; QHash < QString /*name*/, KoXmlElement* > presentationPageLayouts; QHash < QString /*drawType*/, QHash< QString /*name*/, KoXmlElement* > > drawStyles; QList tableTemplates; KoXmlElement officeStyle; KoXmlElement layerSet; DataFormatsMap dataFormats; - // XXX: there can also be notes configuration objects _per_ section. - KoOdfNotesConfiguration globalFootnoteConfiguration; - KoOdfNotesConfiguration globalEndnoteConfiguration; - }; KoOdfStylesReader::KoOdfStylesReader() : d(new Private) { } KoOdfStylesReader::~KoOdfStylesReader() { typedef QHash AutoStylesMap; Q_FOREACH (const AutoStylesMap& map, d->customStyles) qDeleteAll(map); Q_FOREACH (const AutoStylesMap& map, d->contentAutoStyles) qDeleteAll(map); Q_FOREACH (const AutoStylesMap& map, d->stylesAutoStyles) qDeleteAll(map); Q_FOREACH (const DataFormatsMap::mapped_type& dataFormat, d->dataFormats) delete dataFormat.second; qDeleteAll(d->defaultStyles); qDeleteAll(d->styles); qDeleteAll(d->masterPages); qDeleteAll(d->presentationPageLayouts); qDeleteAll(d->tableTemplates); Q_FOREACH (const AutoStylesMap& map, d->drawStyles) { qDeleteAll(map); } delete d; } void KoOdfStylesReader::createStyleMap(const KoXmlDocument& doc, bool stylesDotXml) { const KoXmlElement docElement = doc.documentElement(); // We used to have the office:version check here, but better let the apps do that KoXmlElement fontStyles = KoXml::namedItemNS(docElement, KoXmlNS::office, "font-face-decls"); if (!fontStyles.isNull()) { //debugOdf <<"Starting reading in font-face-decls..."; insertStyles(fontStyles, stylesDotXml ? AutomaticInStyles : AutomaticInContent); }// else // debugOdf <<"No items found"; //debugOdf <<"Starting reading in office:automatic-styles. stylesDotXml=" << stylesDotXml; KoXmlElement autoStyles = KoXml::namedItemNS(docElement, KoXmlNS::office, "automatic-styles"); if (!autoStyles.isNull()) { insertStyles(autoStyles, stylesDotXml ? AutomaticInStyles : AutomaticInContent); }// else // debugOdf <<"No items found"; //debugOdf <<"Reading in master styles"; KoXmlNode masterStyles = KoXml::namedItemNS(docElement, KoXmlNS::office, "master-styles"); if (!masterStyles.isNull()) { KoXmlElement master; forEachElement(master, masterStyles) { if (master.localName() == "master-page" && master.namespaceURI() == KoXmlNS::style) { const QString name = master.attributeNS(KoXmlNS::style, "name", QString()); debugOdf << "Master style: '" << name << "' loaded"; d->masterPages.insert(name, new KoXmlElement(master)); } else if (master.localName() == "layer-set" && master.namespaceURI() == KoXmlNS::draw) { debugOdf << "Master style: layer-set loaded"; d->layerSet = master; } else // OASIS docu mentions style:handout-master and draw:layer-set here warnOdf << "Unknown tag " << master.tagName() << " in office:master-styles"; } } debugOdf << "Starting reading in office:styles"; const KoXmlElement officeStyle = KoXml::namedItemNS(docElement, KoXmlNS::office, "styles"); if (!officeStyle.isNull()) { d->officeStyle = officeStyle; insertOfficeStyles(officeStyle); } //debugOdf <<"Styles read in."; } QHash KoOdfStylesReader::customStyles(const QString& family) const { if (family.isNull()) return QHash(); return d->customStyles.value(family); } QHash KoOdfStylesReader::autoStyles(const QString& family, bool stylesDotXml) const { if (family.isNull()) return QHash(); return stylesDotXml ? d->stylesAutoStyles.value(family) : d->contentAutoStyles.value(family); } KoOdfStylesReader::DataFormatsMap KoOdfStylesReader::dataFormats() const { return d->dataFormats; } -KoOdfNotesConfiguration KoOdfStylesReader::globalNotesConfiguration(KoOdfNotesConfiguration::NoteClass noteClass) const -{ - switch (noteClass) { - case (KoOdfNotesConfiguration::Endnote): - return d->globalEndnoteConfiguration; - case (KoOdfNotesConfiguration::Footnote): - default: - return d->globalFootnoteConfiguration; - } -} - void KoOdfStylesReader::insertOfficeStyles(const KoXmlElement& styles) { KoXmlElement e; forEachElement(e, styles) { const QString localName = e.localName(); const QString ns = e.namespaceURI(); if ((ns == KoXmlNS::svg && ( localName == "linearGradient" || localName == "radialGradient")) || (ns == KoXmlNS::draw && ( localName == "gradient" || localName == "hatch" || localName == "fill-image" || localName == "marker" || localName == "stroke-dash" || localName == "opacity")) || (ns == KoXmlNS::calligra && ( localName == "conicalGradient")) ) { QString drawType = localName; if (drawType.endsWith("Gradient")) { drawType = "gradient"; } const QString name = e.attributeNS(KoXmlNS::draw, "name", QString()); Q_ASSERT(!name.isEmpty()); KoXmlElement* ep = new KoXmlElement(e); d->drawStyles[drawType].insert(name, ep); }else if(ns == KoXmlNS::table && localName == "table-template") { d->tableTemplates.append(new KoXmlElement(e)); } else { insertStyle(e, CustomInStyles); } } } void KoOdfStylesReader::insertStyles(const KoXmlElement& styles, TypeAndLocation typeAndLocation) { //debugOdf <<"Inserting styles from" << styles.tagName(); KoXmlElement e; forEachElement(e, styles) insertStyle(e, typeAndLocation); } void KoOdfStylesReader::insertStyle(const KoXmlElement& e, TypeAndLocation typeAndLocation) { const QString localName = e.localName(); const QString ns = e.namespaceURI(); const QString name = e.attributeNS(KoXmlNS::style, "name", QString()); if ((ns == KoXmlNS::style && localName == "style") || (ns == KoXmlNS::text && localName == "list-style")) { const QString family = localName == "list-style" ? "list" : e.attributeNS(KoXmlNS::style, "family", QString()); if (typeAndLocation == AutomaticInContent) { QHash& dict = d->contentAutoStyles[ family ]; if (dict.contains(name)) { debugOdf << "Auto-style: '" << name << "' already exists"; delete dict.take(name); } dict.insert(name, new KoXmlElement(e)); //debugOdf <<"Style: '" << name <<"' loaded as a style auto style"; } else if (typeAndLocation == AutomaticInStyles) { QHash& dict = d->stylesAutoStyles[ family ]; if (dict.contains(name)) { debugOdf << "Auto-style: '" << name << "' already exists"; delete dict.take(name); } dict.insert(name, new KoXmlElement(e)); //debugOdf <<"Style: '" << name <<"' loaded as a style auto style"; } else { QHash& dict = d->customStyles[ family ]; if (dict.contains(name)) { debugOdf << "Style: '" << name << "' already exists"; delete dict.take(name); } dict.insert(name, new KoXmlElement(e)); //debugOdf <<"Style: '" << name <<"' loaded"; } } else if (ns == KoXmlNS::style && ( localName == "page-layout" || localName == "font-face")) { if (d->styles.contains(name)) { debugOdf << "Style: '" << name << "' already exists"; delete d->styles.take(name); } d->styles.insert(name, new KoXmlElement(e)); } else if (localName == "presentation-page-layout" && ns == KoXmlNS::style) { if (d->presentationPageLayouts.contains(name)) { debugOdf << "Presentation page layout: '" << name << "' already exists"; delete d->presentationPageLayouts.take(name); } d->presentationPageLayouts.insert(name, new KoXmlElement(e)); } else if (localName == "default-style" && ns == KoXmlNS::style) { const QString family = e.attributeNS(KoXmlNS::style, "family", QString()); if (!family.isEmpty()) d->defaultStyles.insert(family, new KoXmlElement(e)); } else if (ns == KoXmlNS::number && ( localName == "number-style" || localName == "currency-style" || localName == "percentage-style" || localName == "boolean-style" || localName == "text-style" || localName == "date-style" || localName == "time-style")) { QPair numberStyle = KoOdfNumberStyles::loadOdfNumberStyle(e); d->dataFormats.insert(numberStyle.first, qMakePair(numberStyle.second, new KoXmlElement(e))); - } else if (ns == KoXmlNS::text && localName == "notes-configuration") { - if (e.attributeNS(KoXmlNS::text, "note-class", "footnote") == "footnote") { - d->globalFootnoteConfiguration.loadOdf(e); - } else { - d->globalEndnoteConfiguration.loadOdf(e); - } } } KoXmlElement *KoOdfStylesReader::defaultStyle(const QString &family) const { return d->defaultStyles[family]; } KoXmlElement KoOdfStylesReader::officeStyle() const { return d->officeStyle; } KoXmlElement KoOdfStylesReader::layerSet() const { return d->layerSet; } QHash KoOdfStylesReader::masterPages() const { return d->masterPages; } QHash KoOdfStylesReader::presentationPageLayouts() const { return d->presentationPageLayouts; } QHash KoOdfStylesReader::drawStyles(const QString &drawType) const { return d->drawStyles.value(drawType); } const KoXmlElement* KoOdfStylesReader::findStyle(const QString& name) const { return d->styles[ name ]; } const KoXmlElement* KoOdfStylesReader::findStyle(const QString& styleName, const QString& family) const { const KoXmlElement* style = findStyleCustomStyle(styleName, family); if (!style) style = findAutoStyleStyle(styleName, family); if (!style) style = findContentAutoStyle(styleName, family); return style; } const KoXmlElement* KoOdfStylesReader::findStyle(const QString& styleName, const QString& family, bool stylesDotXml) const { const KoXmlElement* style = findStyleCustomStyle(styleName, family); if (!style && !stylesDotXml) { style = findContentAutoStyle(styleName, family); } if (!style && stylesDotXml) { style = findAutoStyleStyle(styleName, family); } return style; } const KoXmlElement* KoOdfStylesReader::findStyleCustomStyle(const QString& styleName, const QString& family) const { const KoXmlElement* style = d->customStyles.value(family).value(styleName); if (style && !family.isEmpty()) { const QString styleFamily = style->attributeNS(KoXmlNS::style, "family", QString()); if (styleFamily != family) { warnOdf << "KoOdfStylesReader: was looking for style " << styleName << " in family " << family << " but got " << styleFamily << endl; } } return style; } const KoXmlElement* KoOdfStylesReader::findAutoStyleStyle(const QString& styleName, const QString& family) const { const KoXmlElement* style = d->stylesAutoStyles.value(family).value(styleName); if (style) { const QString styleFamily = style->attributeNS(KoXmlNS::style, "family", QString()); if (styleFamily != family) { warnOdf << "KoOdfStylesReader: was looking for style " << styleName << " in family " << family << " but got " << styleFamily << endl; } } return style; } const KoXmlElement* KoOdfStylesReader::findContentAutoStyle(const QString& styleName, const QString& family) const { const KoXmlElement* style = d->contentAutoStyles.value(family).value(styleName); if (style) { const QString styleFamily = style->attributeNS(KoXmlNS::style, "family", QString()); if (styleFamily != family) { warnOdf << "KoOdfStylesReader: was looking for style " << styleName << " in family " << family << " but got " << styleFamily << endl; } } return style; } QList KoOdfStylesReader::tableTemplates() const { return d->tableTemplates; } diff --git a/libs/odf/KoOdfStylesReader.h b/libs/odf/KoOdfStylesReader.h index a1f8e1fd15..86144e1a07 100644 --- a/libs/odf/KoOdfStylesReader.h +++ b/libs/odf/KoOdfStylesReader.h @@ -1,170 +1,161 @@ /* This file is part of the KDE project Copyright (C) 2004-2006 David Faure Copyright (C) 2007 Jan Hambrecht Copyright (C) 2008 Thorsten Zachmann This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KOODFSTYLESREADER_H #define KOODFSTYLESREADER_H #include #include #include #include "kritaodf_export.h" #include "KoOdfNumberStyles.h" -#include "KoOdfNotesConfiguration.h" /** * Repository of styles used during loading of OASIS/OOo file */ class KRITAODF_EXPORT KoOdfStylesReader { public: /// constructor KoOdfStylesReader(); /// destructor ~KoOdfStylesReader(); /// Look into @p doc for styles and remember them /// @param doc document to look into /// @param stylesDotXml true when loading styles.xml, false otherwise void createStyleMap(const KoXmlDocument &doc, bool stylesDotXml); /** * Look up a style by name. * This method can find styles defined by the tags "style:page-layout", * "style:presentation-page-layout", or "style:font-face". * Do NOT use this method for style:style styles. * * @param name the style name * @return the dom element representing the style, or an empty QString if it wasn't found. */ const KoXmlElement* findStyle(const QString &name) const; /** * Looks up a style:style by name. * Searches in the list of custom styles first and then in the lists of automatic styles. * @param name the style name * @param family the style family (for a style:style, use 0 otherwise) * @return the dom element representing the style, or an empty QString if it wasn't found. */ const KoXmlElement* findStyle(const QString &name, const QString &family) const; /** * Looks up a style:style by name. * * Searches in the list of custom styles first and then in the lists of automatic styles. * * @param name the style name * @param family the style family (for a style:style, use 0 otherwise) * @param stylesDotXml if true search the styles.xml auto-styles otherwise the content.xml ones * * @return the dom element representing the style, or an empty QString if it wasn't found. */ const KoXmlElement* findStyle(const QString &name, const QString &family, bool stylesDotXml) const; /// Similar to findStyle but for custom styles only. const KoXmlElement *findStyleCustomStyle(const QString &name, const QString &family) const; /** * Similar to findStyle but for auto-styles only. * \note Searches in styles.xml only! * \see findStyle() */ const KoXmlElement *findAutoStyleStyle(const QString &name, const QString &family) const; /** * Similar to findStyle but for auto-styles only. * \note Searches in content.xml only! * \see findStyle() */ const KoXmlElement *findContentAutoStyle(const QString &name, const QString &family) const; /// @return the default style for a given family ("graphic","paragraph","table" etc.) /// Returns 0 if no default style for this family is available KoXmlElement *defaultStyle(const QString &family) const; /// @return the office:style element KoXmlElement officeStyle() const; /// @return the draw:layer-set element KoXmlElement layerSet() const; /// @return master pages ("style:master-page" elements), hashed by name QHash masterPages() const; /// @return all presentation page layouts ("presentation-page-layout" elements), hashed by name QHash presentationPageLayouts() const; /// @return all table templates("table-template" elements), template names may be duplicated QList tableTemplates() const; /** * Get the draw styles for a specified type. * * @param drawType The type of the wanted drawStyles * Available types: gradient(returns gradient, linearGradient, radialGradient and conicalGradient styles), * hatch, fill-image, marker, stroke-dash, opacity * @return draw styles of the specified type, hashed by name */ QHash drawStyles(const QString &drawType) const; /// @return all custom styles ("style:style" elements) for a given family, hashed by name QHash customStyles(const QString& family) const; /** * Returns all auto-styles defined in styles.xml, if \p stylesDotXml is \c true , * or all in content.xml, if \p stylesDotXml is \c false . * \return all auto-styles ("style:style" elements) for a given family, hashed by name */ QHash autoStyles(const QString& family, bool stylesDotXml = false) const; typedef QHash > DataFormatsMap; /// Value (date/time/number...) formats found while parsing styles. Used e.g. for fields. /// Key: format name. Value: DataFormatsMap dataFormats() const; - /** - * Return the notes configuration for the given note class (footnote or endnote). - * - * Note that ODF supports different notes configurations for sections, but we don't - * support that yet. - */ - KoOdfNotesConfiguration globalNotesConfiguration(KoOdfNotesConfiguration::NoteClass noteClass) const; - private: enum TypeAndLocation { CustomInStyles, ///< custom style located in styles.xml AutomaticInContent, ///< auto-style located in content.xml AutomaticInStyles ///< auto-style located in styles.xml }; /// Add styles to styles map void insertStyles(const KoXmlElement &styles, TypeAndLocation typeAndLocation = CustomInStyles); void insertOfficeStyles(const KoXmlElement &styles); void insertStyle(const KoXmlElement &style, TypeAndLocation typeAndLocation); KoOdfStylesReader(const KoOdfStylesReader &); // forbidden KoOdfStylesReader& operator=(const KoOdfStylesReader &); // forbidden class Private; Private * const d; }; #endif /* KOODFSTYLESREADER_H */