File indexing completed on 2025-01-12 10:34:38

0001 /* This file is part of the KDE project
0002 
0003    SPDX-FileCopyrightText: 2012-2014 Inge Wallin <inge@lysator.liu.se>
0004 
0005    SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef ODFREADER_H
0009 #define ODFREADER_H
0010 
0011 // Qt
0012 #include <QHash>
0013 #include <QString>
0014 
0015 // Calligra
0016 #include <KoXmlStreamReader.h>
0017 
0018 // this library
0019 #include "koodfreader_export.h"
0020 #include "OdfReaderInternals.h"
0021 
0022 
0023 class QSizeF;
0024 
0025 class KoXmlWriter;
0026 class KoStore;
0027 
0028 class OdfReaderBackend;
0029 class OdfReaderContext;
0030 
0031 class OdfTextReader;
0032 class OdfDrawReader;
0033 
0034 
0035 /** @brief Read the XML tree of the content of an ODF file.
0036  *
0037  * The OdfReader is used to traverse (read) the contents of an ODF file using
0038  * an XML stream reader.  For reading a specific type of ODF, e.g. a text
0039  * document, you should create a new class, OdtReader that inherits this
0040  * class.
0041  *
0042  * For every XML element that the reading process comes across it will call a
0043  * specific function in a backend class: @see OdfReaderBackend.
0044  *
0045  * Before the reading process is started the ODF file will be
0046  * analyzed to collect some data that may be needed during the
0047  * read: metadata, manifest and styles are examples of this. This
0048  * data is stored in the so called reading context, which is kept in
0049  * an instance of the OdfReaderContext class.
0050  *
0051  * The context will be passed around to the backend in every call to a
0052  * backend callback function.
0053  *
0054  * In addition to the pre-analyzed data from the ODF file, the context
0055  * can be used to keep track of data that is used in the backend
0056  * processing such as internal links, lists of embedded data such as
0057  * pictures.
0058  */
0059 class KOODFREADER_EXPORT OdfReader
0060 {
0061  public:
0062     OdfReader();
0063     virtual ~OdfReader();
0064 
0065     OdfTextReader *textReader() const;
0066     void setTextReader(OdfTextReader *textReader);
0067 
0068     OdfDrawReader *drawReader() const;
0069     void setDrawReader(OdfDrawReader *drawReader);
0070 
0071     bool analyzeContent(OdfReaderContext *context);
0072 
0073     bool readContent(OdfReaderBackend *backend, OdfReaderContext *context);
0074 
0075  protected:
0076     // All readElement*() are named after the full qualifiedName of
0077     // the element in ODF that they handle.
0078 
0079     // ODF document level functions
0080     DECLARE_READER_FUNCTION(OfficeBody);
0081 
0082     // ONE of these should be reimplemented by each subclass, respectively.
0083     virtual DECLARE_READER_FUNCTION(OfficeText);
0084     virtual DECLARE_READER_FUNCTION(OfficeSpreadsheet);
0085     virtual DECLARE_READER_FUNCTION(OfficePresentation);
0086 
0087     // ----------------------------------------------------------------
0088     // Other functions
0089 
0090     void readUnknownElement(KoXmlStreamReader &reader);
0091 
0092 
0093  protected:
0094     OdfReaderBackend  *m_backend;
0095     OdfReaderContext  *m_context;
0096 
0097     // Helper readers
0098     OdfTextReader     *m_textReader;
0099     OdfDrawReader     *m_drawReader;
0100 };
0101 
0102 #endif // ODFREADER_H