1 /* This file is part of the KDE project 2 Copyright (C) 2004-2006 David Faure <faure@kde.org> 3 Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net> 4 Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org> 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Library General Public 8 License version 2 as published by the Free Software Foundation. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this library; see the file COPYING.LIB. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef KOODFSTYLESREADER_H 22 #define KOODFSTYLESREADER_H 23 24 #include <QHash> 25 #include <QList> 26 27 #include <KoXmlReader.h> 28 29 #include "koodf_export.h" 30 #include "KoOdfNumberStyles.h" 31 #include "KoOdfNotesConfiguration.h" 32 33 class KoOdfLineNumberingConfiguration; 34 class KoOdfBibliographyConfiguration; 35 36 /** 37 * Repository of styles used during loading of OASIS/OOo file 38 */ 39 class KOODF_EXPORT KoOdfStylesReader 40 { 41 public: 42 /// constructor 43 KoOdfStylesReader(); 44 /// destructor 45 ~KoOdfStylesReader(); 46 47 /// Look into @p doc for styles and remember them 48 /// @param doc document to look into 49 /// @param stylesDotXml true when loading styles.xml, false otherwise 50 void createStyleMap(const KoXmlDocument &doc, bool stylesDotXml); 51 52 /** 53 * Look up a style by name. 54 * This method can find styles defined by the tags "style:page-layout", 55 * "style:presentation-page-layout", or "style:font-face". 56 * Do NOT use this method for style:style styles. 57 * 58 * @param name the style name 59 * @return the dom element representing the style, or an empty QString if it wasn't found. 60 */ 61 const KoXmlElement* findStyle(const QString &name) const; 62 63 /** 64 * Looks up a style:style by name. 65 * Searches in the list of custom styles first and then in the lists of automatic styles. 66 * @param name the style name 67 * @param family the style family (for a style:style, use 0 otherwise) 68 * @return the dom element representing the style, or an empty QString if it wasn't found. 69 */ 70 const KoXmlElement* findStyle(const QString &name, const QString &family) const; 71 72 /** 73 * Looks up a style:style by name. 74 * 75 * Searches in the list of custom styles first and then in the lists of automatic styles. 76 * 77 * @param name the style name 78 * @param family the style family (for a style:style, use 0 otherwise) 79 * @param stylesDotXml if true search the styles.xml auto-styles otherwise the content.xml ones 80 * 81 * @return the dom element representing the style, or an empty QString if it wasn't found. 82 */ 83 const KoXmlElement* findStyle(const QString &name, const QString &family, bool stylesDotXml) const; 84 85 /// Similar to findStyle but for custom styles only. 86 const KoXmlElement *findStyleCustomStyle(const QString &name, const QString &family) const; 87 88 /** 89 * Similar to findStyle but for auto-styles only. 90 * \note Searches in styles.xml only! 91 * \see findStyle() 92 */ 93 const KoXmlElement *findAutoStyleStyle(const QString &name, const QString &family) const; 94 95 /** 96 * Similar to findStyle but for auto-styles only. 97 * \note Searches in content.xml only! 98 * \see findStyle() 99 */ 100 const KoXmlElement *findContentAutoStyle(const QString &name, const QString &family) const; 101 102 /// @return the default style for a given family ("graphic","paragraph","table" etc.) 103 /// Returns 0 if no default style for this family is available 104 KoXmlElement *defaultStyle(const QString &family) const; 105 106 /// @return the office:style element 107 KoXmlElement officeStyle() const; 108 109 /// @return the draw:layer-set element 110 KoXmlElement layerSet() const; 111 112 /// @return master pages ("style:master-page" elements), hashed by name 113 QHash<QString, KoXmlElement*> masterPages() const; 114 115 /// @return all presentation page layouts ("presentation-page-layout" elements), hashed by name 116 QHash<QString, KoXmlElement*> presentationPageLayouts() const; 117 118 /// @return all table templates("table-template" elements), template names may be duplicated 119 QList<KoXmlElement *> tableTemplates() const; 120 121 /** 122 * Get the draw styles for a specified type. 123 * 124 * @param drawType The type of the wanted drawStyles 125 * Available types: gradient(returns gradient, linearGradient, radialGradient and conicalGradient styles), 126 * hatch, fill-image, marker, stroke-dash, opacity 127 * @return draw styles of the specified type, hashed by name 128 */ 129 QHash<QString, KoXmlElement*> drawStyles(const QString &drawType) const; 130 131 /// @return all custom styles ("style:style" elements) for a given family, hashed by name 132 QHash<QString, KoXmlElement*> customStyles(const QString& family) const; 133 134 /** 135 * Returns all auto-styles defined in styles.xml, if \p stylesDotXml is \c true , 136 * or all in content.xml, if \p stylesDotXml is \c false . 137 * \return all auto-styles ("style:style" elements) for a given family, hashed by name 138 */ 139 QHash<QString, KoXmlElement*> autoStyles(const QString& family, bool stylesDotXml = false) const; 140 141 typedef QHash<QString, QPair<KoOdfNumberStyles::NumericStyleFormat, KoXmlElement*> > DataFormatsMap; 142 /// Value (date/time/number...) formats found while parsing styles. Used e.g. for fields. 143 /// Key: format name. Value: 144 DataFormatsMap dataFormats() const; 145 146 /** 147 * Return the notes configuration for the given note class (footnote or endnote). 148 * 149 * Note that ODF supports different notes configurations for sections, but we don't 150 * support that yet. 151 */ 152 KoOdfNotesConfiguration globalNotesConfiguration(KoOdfNotesConfiguration::NoteClass noteClass) const; 153 154 /** 155 * return the line numbering configuration for this document. 156 */ 157 KoOdfLineNumberingConfiguration lineNumberingConfiguration() const; 158 159 /** 160 * return the bibliography configuration for this document. 161 */ 162 KoOdfBibliographyConfiguration globalBibliographyConfiguration() const; 163 164 private: 165 enum TypeAndLocation { 166 CustomInStyles, ///< custom style located in styles.xml 167 AutomaticInContent, ///< auto-style located in content.xml 168 AutomaticInStyles ///< auto-style located in styles.xml 169 }; 170 /// Add styles to styles map 171 void insertStyles(const KoXmlElement &styles, TypeAndLocation typeAndLocation = CustomInStyles); 172 173 void insertOfficeStyles(const KoXmlElement &styles); 174 void insertStyle(const KoXmlElement &style, TypeAndLocation typeAndLocation); 175 176 KoOdfStylesReader(const KoOdfStylesReader &); // forbidden 177 KoOdfStylesReader& operator=(const KoOdfStylesReader &); // forbidden 178 179 class Private; 180 Private * const d; 181 }; 182 183 #endif /* KOODFSTYLESREADER_H */ 184