1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
/*
* This file is part of Office 2007 Filters for Calligra
*
* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: Suresh Chande suresh.chande@nokia.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef MSOOXMLTHEMESREADER_H
#define MSOOXMLTHEMESREADER_H
#include <QHash>
#include <QColor>
#include <QMap>
#include <KoGenStyles.h>
#include "MsooXmlCommonReader.h"
#include "MsooXmlImport.h"
namespace MSOOXML
{
class DrawingMLColorSchemeItem;
class DrawingMLColorSchemeSystemItem;
//! @todo add other classes inheriting DrawingMLColorSchemeItemBase
class KOMSOOXML_EXPORT DrawingMLColorSchemeItemBase
{
public:
DrawingMLColorSchemeItemBase();
virtual ~DrawingMLColorSchemeItemBase();
DrawingMLColorSchemeItem* toColorItem();
DrawingMLColorSchemeSystemItem* toSystemItem();
virtual QColor value() const = 0;
virtual DrawingMLColorSchemeItemBase* clone() const = 0;
};
class KOMSOOXML_EXPORT DrawingMLColorSchemeItem : public DrawingMLColorSchemeItemBase
{
public:
DrawingMLColorSchemeItem();
virtual QColor value() const { return color; }
QColor color;
DrawingMLColorSchemeItem* clone() const { return new DrawingMLColorSchemeItem(*this); }
};
class KOMSOOXML_EXPORT DrawingMLColorSchemeSystemItem : public DrawingMLColorSchemeItemBase
{
public:
DrawingMLColorSchemeSystemItem();
virtual QColor value() const;
QColor lastColor;
QString systemColor; //!< ST_SystemColorVal (§20.1.10.58).;
DrawingMLColorSchemeSystemItem* clone() const { return new DrawingMLColorSchemeSystemItem(*this); }
};
typedef QHash<QString, DrawingMLColorSchemeItemBase*> DrawingMLColorSchemeItemHash;
//! Implements color scheme, based on hash. All items are owned by this object.
class KOMSOOXML_EXPORT DrawingMLColorScheme : public DrawingMLColorSchemeItemHash
{
public:
DrawingMLColorScheme();
~DrawingMLColorScheme();
DrawingMLColorSchemeItemBase* value(const QString& name) const {
return DrawingMLColorSchemeItemHash::value(name);
}
/*! @return color value for index. Needed because while PPTX uses lookup by
name: value(QString&), XLSX uses lookup by index. When index is
invalid, 0 is returned. */
DrawingMLColorSchemeItemBase* value(int index) const;
DrawingMLColorScheme(const DrawingMLColorScheme& scheme);
DrawingMLColorScheme& operator=(const DrawingMLColorScheme& scheme);
//! Name of the color scheme
QString name;
};
//! Font set for majorFont and minorFont.
//! @todo add more support for latin, ea and cs: charser, panose, pitchfamily attributes (21.1.2.3.3)
class KOMSOOXML_EXPORT DrawingMLFontSet
{
public:
DrawingMLFontSet();
//! A (script->typeface) hash with font definitions (20.1.4.1.16.)
QHash<QString, QString> typefacesForScripts;
//! Specifies that a Latin font be used for a specific run of text.
QString latinTypeface;
//! The possible values for this attribute are defined by the ST_TextTypeface simple type
//! (§20.1.10.81).
QString eaTypeface;
//! The possible values for this attribute are defined by the ST_TextTypeface simple type
//! (§20.1.10.81).
QString csTypeface;
};
//! Defines the font scheme within the theme
//! The font scheme consists of a pair of major and minor fonts for which to use in a document.s
class KOMSOOXML_EXPORT DrawingMLFontScheme
{
public:
DrawingMLFontScheme();
DrawingMLFontSet majorFonts;
DrawingMLFontSet minorFonts;
QString name;
};
class KOMSOOXML_EXPORT DrawingMLFillBase
{
public:
virtual ~DrawingMLFillBase();
// This function will create the fill style and fill the appropriate styles
// and filePath if needed.
// Number is used to index to correct style, color is the color which should be used when making the styles
virtual void writeStyles(KoGenStyles& styles, KoGenStyle *graphicStyle, QColor color) = 0;
virtual DrawingMLFillBase* clone() const = 0;
};
class KOMSOOXML_EXPORT DrawingMLSolidFill : public DrawingMLFillBase
{
public:
void writeStyles(KoGenStyles& styles, KoGenStyle *graphicStyle, QColor color);
DrawingMLSolidFill* clone() const { return new DrawingMLSolidFill(*this); }
};
class KOMSOOXML_EXPORT DrawingMLBlipFill : public DrawingMLFillBase
{
public:
explicit DrawingMLBlipFill(const QString &filePath);
void writeStyles(KoGenStyles& styles, KoGenStyle *graphicStyle, QColor color);
DrawingMLBlipFill* clone() const { return new DrawingMLBlipFill(*this); }
private:
QString m_filePath;
};
class KOMSOOXML_EXPORT DrawingMLGradientFill : public DrawingMLFillBase
{
public:
// Simplified gradient constructor
DrawingMLGradientFill(QVector<qreal> shadeModifier, QVector<qreal> tintModifier, QVector<qreal> satModifier,
QVector<int> alphaModifier, QVector<int> gradPositions, QString gradAngle);
void writeStyles(KoGenStyles& styles, KoGenStyle *graphicStyle, QColor color);
DrawingMLGradientFill* clone() const { return new DrawingMLGradientFill(*this); }
private:
QVector<qreal> m_shadeModifier;
QVector<qreal> m_tintModifier;
QVector<qreal> m_satModifier;
QVector<int> m_alphaModifier;
QVector<int> m_gradPosition;
QString m_gradAngle;
};
class KOMSOOXML_EXPORT DrawingMLFormatScheme
{
public:
DrawingMLFormatScheme();
~DrawingMLFormatScheme();
QString name;
DrawingMLFormatScheme(const DrawingMLFormatScheme& format);
DrawingMLFormatScheme& operator=(const DrawingMLFormatScheme& format);
QMap<int, DrawingMLFillBase*> fillStyles;
// Stores the three line styles for use within a theme.
QList<KoGenStyle> lnStyleLst;
};
//! Defines a single DrawingML theme.
//! @todo support objectDefaults and extraClrSchemeLst
class KOMSOOXML_EXPORT DrawingMLTheme
{
public:
DrawingMLTheme();
QString name;
DrawingMLColorScheme colorScheme;
DrawingMLFontScheme fontScheme;
DrawingMLFormatScheme formatScheme;
};
//! Context for MsooXmlThemesReader::read()
class KOMSOOXML_EXPORT MsooXmlThemesReaderContext : public MsooXmlReaderContext
{
public:
MsooXmlThemesReaderContext(DrawingMLTheme& t, MSOOXML::MsooXmlRelationships* rel, MSOOXML::MsooXmlImport* imp,
QString pathName, QString fileName);
DrawingMLTheme * const theme;
MSOOXML::MsooXmlRelationships* relationships;
MSOOXML::MsooXmlImport* import;
QString path;
QString file;
};
//! A class reading MSOOXML themes markup - theme/theme1.xml.
/*! @todo generalize for other MSOOXML subformats.
*/
class KOMSOOXML_EXPORT MsooXmlThemesReader : public MSOOXML::MsooXmlCommonReader
{
public:
//! Creates MsooXmlThemesReader object.
//! On successful reading, @a theme will be written with theme definition.
explicit MsooXmlThemesReader(KoOdfWriters *writers);
virtual ~MsooXmlThemesReader();
//! Reads/parses the file. The output goes mainly to KoGenStyles* KoOdfWriters::mainStyles
virtual KoFilter::ConversionStatus read(MsooXmlReaderContext* context = 0);
protected:
KoFilter::ConversionStatus readInternal();
KoFilter::ConversionStatus read_theme();
KoFilter::ConversionStatus read_themeElements();
//! @todo no CASE
KoFilter::ConversionStatus read_objectDefaults();
KoFilter::ConversionStatus read_custClrLst();
KoFilter::ConversionStatus read_extraClrSchemeLst();
KoFilter::ConversionStatus read_extraClrScheme();
KoFilter::ConversionStatus read_clrScheme();
KoFilter::ConversionStatus read_color(); //!< helper
DrawingMLColorSchemeItemBase* m_currentColor_local; //!< used by *Clr()
KoFilter::ConversionStatus read_fmtScheme();
KoFilter::ConversionStatus read_fontScheme();
KoFilter::ConversionStatus read_clrMap();
KoFilter::ConversionStatus fillStyleReadHelper(int& index);
KoFilter::ConversionStatus read_bgFillStyleLst();
KoFilter::ConversionStatus read_fillStyleLst();
KoFilter::ConversionStatus read_majorFont();
KoFilter::ConversionStatus read_minorFont();
KoFilter::ConversionStatus read_lnStyleLst();
//! Used for skipping a subtree - just reads and shows each element.
//! called by BIND_READ_SKIP() macro.
KoFilter::ConversionStatus read_SKIP();
#include "MsooXmlDrawingMLShared.h"
KoFilter::ConversionStatus read_srgbClr_local();
KoFilter::ConversionStatus read_sysClr_local();
private:
void init();
MsooXmlThemesReaderContext* m_context;
typedef KoFilter::ConversionStatus(MsooXmlThemesReader::*ReadMethod)();
QHash<QString, ReadMethod> m_readMethods;
QHash<QString, QString> m_colorSchemeIndices;
bool m_clrScheme_initialized;
bool m_color_initialized;
MSOOXML::MsooXmlRelationships* m_relationships;
MSOOXML::MsooXmlImport* m_import;
QString m_path;
QString m_file;
};
} // namespace MSOOXML
#endif //MSOOXMLTHEMESREADER_H
|