diff --git a/libs/odf/CMakeLists.txt b/libs/odf/CMakeLists.txt index 6527f2ed3b..ed635ddacd 100644 --- a/libs/odf/CMakeLists.txt +++ b/libs/odf/CMakeLists.txt @@ -1,39 +1,38 @@ 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 - KoOdfLineNumberingConfiguration.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/KoOdfLineNumberingConfiguration.cpp b/libs/odf/KoOdfLineNumberingConfiguration.cpp deleted file mode 100644 index 973c611541..0000000000 --- a/libs/odf/KoOdfLineNumberingConfiguration.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/* This file is part of the KDE project - - Copyright (C) 2010 KO GmbH - - 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 "KoOdfLineNumberingConfiguration.h" - -#include -#include "KoXmlNS.h" -#include "KoUnit.h" -#include "KoXmlWriter.h" -#include "KoXmlReader.h" -#include "KoOdfNumberDefinition.h" - -class Q_DECL_HIDDEN KoOdfLineNumberingConfiguration::Private -{ -public: - bool lineNumberingEnabled; - KoOdfNumberDefinition numberFormat; - QString textStyle; - int increment; - Position position; - int offset; - bool countEmptyLines; - bool countLinesInTextBoxes; - bool restartNumberingOnEveryPage; - QString separator; - int separatorIncrement; -}; - -KoOdfLineNumberingConfiguration::KoOdfLineNumberingConfiguration() - : d(new Private()) -{ - d->lineNumberingEnabled = false; - d->increment = 1; - d->position = Left; - d->offset = 10; - d->countEmptyLines = false; - d->countLinesInTextBoxes = false; - d->separatorIncrement = 5; -} - -KoOdfLineNumberingConfiguration::~KoOdfLineNumberingConfiguration() -{ - delete d; -} - -KoOdfLineNumberingConfiguration::KoOdfLineNumberingConfiguration(const KoOdfLineNumberingConfiguration &other) - : QObject(), d(new Private()) -{ - d->lineNumberingEnabled = other.d->lineNumberingEnabled; - d->numberFormat = other.d->numberFormat; - d->textStyle = other.d->textStyle; - d->increment = other.d->increment; - d->position = other.d->position; - d->offset = other.d->offset; - d->countEmptyLines = other.d->countEmptyLines; - d->countLinesInTextBoxes = other.d->countLinesInTextBoxes; - d->restartNumberingOnEveryPage = other.d->restartNumberingOnEveryPage; - d->separator = other.d->separator; - d->separatorIncrement = other.d->separatorIncrement; -} - -KoOdfLineNumberingConfiguration &KoOdfLineNumberingConfiguration::operator=(const KoOdfLineNumberingConfiguration &other) -{ - d->lineNumberingEnabled = other.d->lineNumberingEnabled; - d->numberFormat = other.d->numberFormat; - d->textStyle = other.d->textStyle; - d->increment = other.d->increment; - d->position = other.d->position; - d->offset = other.d->offset; - d->countEmptyLines = other.d->countEmptyLines; - d->countLinesInTextBoxes = other.d->countLinesInTextBoxes; - d->restartNumberingOnEveryPage = other.d->restartNumberingOnEveryPage; - d->separator = other.d->separator; - d->separatorIncrement = other.d->separatorIncrement; - - return *this; -} - - -void KoOdfLineNumberingConfiguration::loadOdf(const KoXmlElement &element) -{ - d->lineNumberingEnabled = element.attributeNS(KoXmlNS::text, "number-lines", "true") == "true"; - d->numberFormat.loadOdf(element); - d->textStyle = element.attributeNS(KoXmlNS::text, "style-name", QString()); - d->increment = KoUnit::parseValue(element.attributeNS(KoXmlNS::text, "increment", "1")); - - QString position = element.attributeNS(KoXmlNS::text, "position", "left"); - if (position == "left") { - d->position = Left; - } - else if (position == "right") { - d->position = Right; - } - else if (position == "inner") { - d->position = Inner; - } - else if (position == "outer") { - d->position = Outer; - } - - d->offset = KoUnit::parseValue(element.attributeNS(KoXmlNS::text, "offset", "10")); - d->countEmptyLines = element.attributeNS(KoXmlNS::text, "count-empty-lines", "false") == "true"; - d->countLinesInTextBoxes = element.attributeNS(KoXmlNS::text, "count-in-text-boxes", "false") == "true"; - d->restartNumberingOnEveryPage = element.attributeNS(KoXmlNS::text, "restart-on-page", "false") == "true"; - - if(element.hasChildNodes()) { - KoXmlNode node = element.firstChild(); - while(!node.isNull()) { - if(node.isElement()) { - KoXmlElement nodeElement = node.toElement(); - if(nodeElement.localName() == "linenumber-separator") { - d->separator = nodeElement.text(); - d->separatorIncrement = KoUnit::parseValue(element.attributeNS(KoXmlNS::text, "increment", "10")); - break; - } - } - node = node.nextSibling(); - } - } - - -} - -void KoOdfLineNumberingConfiguration::saveOdf(KoXmlWriter *writer) const -{ - writer->addAttribute("text:number-lines", "true"); - d->numberFormat.saveOdf(writer); - if (!d->textStyle.isEmpty()) { - writer->addAttribute("text:style-name", d->textStyle); - } - writer->addAttribute("text:increment", d->increment); - switch(d->position) { - case Left: - break; // this is default, don't save - case Right: - writer->addAttribute("text:position", "right"); - break; - case Inner: - writer->addAttribute("text:position", "inner"); - break; - case Outer: - writer->addAttribute("text:position", "outer"); - break; - } - if (d->offset != 10) { writer->addAttribute("text:offset", d->offset); } - if (d->countEmptyLines) { writer->addAttribute("text:count-empty-lines", d->countEmptyLines); } - if (d->countLinesInTextBoxes) { writer->addAttribute("text:count-in-text-boxes", d->countLinesInTextBoxes); } - if (d->restartNumberingOnEveryPage) { writer->addAttribute("text:restart-on-page", d->restartNumberingOnEveryPage); } - if (!d->separator.isNull()) { - writer->startElement("txt:linenumber-separator"); - if (d->separatorIncrement != 10) { writer->addAttribute("text:increment", d->separatorIncrement); } - writer->addTextNode(d->separator); - writer->endElement(); - } -} - -bool KoOdfLineNumberingConfiguration::enabled() const -{ - return d->lineNumberingEnabled; -} - -void KoOdfLineNumberingConfiguration::setEnabled(bool enabled) -{ - d->lineNumberingEnabled = enabled; -} - -KoOdfNumberDefinition KoOdfLineNumberingConfiguration::numberFormat() const -{ - return d->numberFormat; -} - -void KoOdfLineNumberingConfiguration::setNumberFormat(const KoOdfNumberDefinition &numberFormat) -{ - d->numberFormat = numberFormat; -} - -QString KoOdfLineNumberingConfiguration::textStyle() const -{ - return d->textStyle; -} - -void KoOdfLineNumberingConfiguration::setTextStyle(const QString &textStyle) -{ - d->textStyle = textStyle; -} - -int KoOdfLineNumberingConfiguration::increment() const -{ - return d->increment; -} - -void KoOdfLineNumberingConfiguration::setIncrement(int increment) -{ - d->increment = increment; -} - -KoOdfLineNumberingConfiguration::Position KoOdfLineNumberingConfiguration::position() const -{ - return d->position; -} - -void KoOdfLineNumberingConfiguration::setPosition(KoOdfLineNumberingConfiguration::Position position) -{ - d->position = position; -} - -int KoOdfLineNumberingConfiguration::offset() const -{ - return d->offset; -} - -void KoOdfLineNumberingConfiguration::setOffset(int offset) -{ - d->offset = offset; -} - -bool KoOdfLineNumberingConfiguration::countEmptyLines() const -{ - return d->countEmptyLines; -} - -void KoOdfLineNumberingConfiguration::setCountEmptyLines(bool countEmptyLines) -{ - d->countEmptyLines = countEmptyLines; -} - -bool KoOdfLineNumberingConfiguration::countLinesInTextBoxes() const -{ - return d->countLinesInTextBoxes; -} - -void KoOdfLineNumberingConfiguration::setCountLinesInTextBoxes(bool countLinesInTextBoxes) -{ - d->countLinesInTextBoxes = countLinesInTextBoxes; -} - -bool KoOdfLineNumberingConfiguration::restartNumberingOnEveryPage() const -{ - return d->restartNumberingOnEveryPage; -} - -void KoOdfLineNumberingConfiguration::setRestartNumberingOnEveryPage(bool restartNumberingOnEveryPage) -{ - d->restartNumberingOnEveryPage = restartNumberingOnEveryPage; -} - -QString KoOdfLineNumberingConfiguration::separator() const -{ - return d->separator; -} - -void KoOdfLineNumberingConfiguration::setSeparator(const QString &separator) -{ - d->separator = separator; -} - -int KoOdfLineNumberingConfiguration::separatorIncrement() const -{ - return d->separatorIncrement; -} - -void KoOdfLineNumberingConfiguration::setSeparatorIncrement(int separatorIncrement) -{ - d->separatorIncrement = separatorIncrement; -} - diff --git a/libs/odf/KoOdfLineNumberingConfiguration.h b/libs/odf/KoOdfLineNumberingConfiguration.h deleted file mode 100644 index d151c68985..0000000000 --- a/libs/odf/KoOdfLineNumberingConfiguration.h +++ /dev/null @@ -1,179 +0,0 @@ -/* This file is part of the KDE project - - Copyright (C) 2010 KO GmbH - - 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 KOODFLINENUMBERINGCONFIGURATION_H -#define KOODFLINENUMBERINGCONFIGURATION_H - -#include -#include - -#include "KoXmlReaderForward.h" -#include "kritaodf_export.h" - -class KoXmlWriter; -class KoOdfNumberDefinition; - -/** - * Implement section 14.9.1: Line Numbering Configuration. - * - * A document can contain none or one line numbering configuration element - * within the element. If the - * element is not present, a default line numbering configuration is used. The default line numbering - * may vary on the office application software, but every document saved by an application that - * supports line numbering should contain a line numbering configuration element. - * - * The attributes that may be associated with the - * element are: - *
    - *
  • Line numbering enable - *
  • Number format - *
  • Text style - *
  • Increment - *
  • Position - *
  • Offset - *
  • Count empty lines - *
  • Count line in text boxes - *
  • Restart numbering on every page - *
- * The following element may be included in the element: - *
  • Separator - */ -class KRITAODF_EXPORT KoOdfLineNumberingConfiguration : public QObject -{ - Q_OBJECT -public: - - KoOdfLineNumberingConfiguration(); - ~KoOdfLineNumberingConfiguration() override; - KoOdfLineNumberingConfiguration(const KoOdfLineNumberingConfiguration &other); - KoOdfLineNumberingConfiguration &operator=(const KoOdfLineNumberingConfiguration &other); - - - /** - * load the line numbering configuration element - */ - void loadOdf(const KoXmlElement &element); - - /** - * save the line number configuration element - */ - void saveOdf(KoXmlWriter * writer) const; - - /** - * The text:number-lines attribute controls whether or not lines are numbered. - */ - bool enabled() const; - void setEnabled(bool enabled); - - /** - * See section 12.2 for detailed information on number format attributes. The attributes - * described in section 12.2 can also be associated with the - * element. - */ - KoOdfNumberDefinition numberFormat() const; - void setNumberFormat(const KoOdfNumberDefinition &numberFormat); - - /** - * The text:style-name attribute specifies the text style for all line numbers. The value - * of this attribute is the name of the text style that is applied to all line numbers. - */ - QString textStyle() const; - void setTextStyle(const QString &textStyle); - - /** - * The text:increment attribute causes line numbers that are a multiple of the given increment to - * be numbered. For example, if the increment is 5, only lines number 5, 10, 15, and so on are - * numbered. - */ - int increment() const; - void setIncrement(int increment); - - /** - * The text:position attribute determines whether the line numbers are printed on the left, right, - * inner, or outer margins. - */ - enum Position { - Left, - Right, - Inner, - Outer - }; - - Position position() const; - void setPosition(Position position); - - /** - * The text:offset attribute determines the distance between the line number and the margin. - */ - int offset() const; - void setOffset(int offset); - - /** - * The text:count-empty-lines attribute determines whether or not empty lines are included in - * the line count. If the value of this attribute is true, empty lines are included in the line count. - */ - bool countEmptyLines() const; - void setCountEmptyLines(bool countEmptyLines); - - /** - * The text:count-in-text-boxes attribute determines whether or not text in text boxes is - * included in the line count. If the value of this attribute is true, text within text boxes is included in - * the line count. - */ - bool countLinesInTextBoxes() const; - void setCountLinesInTextBoxes(bool countLinesInTextBoxes); - - /** - * The text:restart-on-page attribute determines whether or not the line count is reset to 1 at - * the start of every page. - * - * If the value of this attribute is true, the line count is reset to 1 at the beginning of every page, - * resulting in page -specific numbering of lines. The default value of this attribute is false, - * resulting in document-specific numbering of lines. - */ - bool restartNumberingOnEveryPage() const; - void setRestartNumberingOnEveryPage(bool restartNumberingOnEveryPage); - - /** - * The element contains the text that is displayed as a - * separator. A separator is text that is displayed instead of a line number for lines where no number - * is displayed. - * - * This element is contained in the line numbering configuration element. If the element is not - * present, no separator is displayed. - * - * The element's text:increment attribute causes the separator to appear on lines that are a - * multiple of the given increment. For example, if the increment is 2, only lines 2, 4, 6, and so on get - * a separator, provided that no number is displayed already. - */ - QString separator() const; - void setSeparator(const QString &separator); - - int separatorIncrement() const; - void setSeparatorIncrement(int separatorIncrement); - -private: - - class Private; - Private * const d; - -}; - -Q_DECLARE_METATYPE(KoOdfLineNumberingConfiguration*) - -#endif // KOODFLINENUMBERINGCONFIGURATION_H diff --git a/libs/odf/KoOdfStylesReader.cpp b/libs/odf/KoOdfStylesReader.cpp index 7a9521ff1b..c980ae942a 100644 --- a/libs/odf/KoOdfStylesReader.cpp +++ b/libs/odf/KoOdfStylesReader.cpp @@ -1,403 +1,391 @@ /* 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 "KoOdfLineNumberingConfiguration.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; - KoOdfLineNumberingConfiguration lineNumberingConfiguration; - }; 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; } } - -KoOdfLineNumberingConfiguration KoOdfStylesReader::lineNumberingConfiguration() const -{ - return d->lineNumberingConfiguration; -} - - 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); } - } else if (ns == KoXmlNS::text && localName == "linenumbering-configuration") { - d->lineNumberingConfiguration.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 957e64d68e..a1f8e1fd15 100644 --- a/libs/odf/KoOdfStylesReader.h +++ b/libs/odf/KoOdfStylesReader.h @@ -1,178 +1,170 @@ /* 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" -class KoOdfLineNumberingConfiguration; -class KoOdfBibliographyConfiguration; - /** * 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; - /** - * return the line numbering configuration for this document. - */ - KoOdfLineNumberingConfiguration lineNumberingConfiguration() 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 */