1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2 
3 /* libstaroffice
4  * Version: MPL 2.0 / LGPLv2.1+
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9  *
10  * Major Contributor(s):
11  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
12  * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
13  *
14  * For minor contributions see the git repository.
15  *
16  * Alternatively, the contents of this file may be used under the terms
17  * of the GNU Lesser General Public License Version 2.1 or later
18  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19  * applicable instead of those above.
20  *
21  * For further information visit http://libstoff.sourceforge.net
22  */
23 
24 
25 #ifndef STOFFDOCUMENT_HXX
26 #define STOFFDOCUMENT_HXX
27 
28 #ifdef _WINDLL
29 #ifdef BUILD_STOFF
30 #define STOFFLIB __declspec(dllexport)
31 #else
32 #define STOFFLIB __declspec(dllimport)
33 #endif
34 #else // !DLL_EXPORT
35 #ifdef LIBSTAROFFICE_VISIBILITY
36 #define STOFFLIB __attribute__((visibility("default")))
37 #else
38 #define STOFFLIB
39 #endif
40 #endif
41 
42 namespace librevenge
43 {
44 class RVNGBinaryData;
45 class RVNGDrawingInterface;
46 class RVNGPresentationInterface;
47 class RVNGSpreadsheetInterface;
48 class RVNGTextInterface;
49 class RVNGInputStream;
50 }
51 
52 /**
53 This class provides all the functions an application would need to parse StarOffice documents.
54 */
55 class STOFFDocument
56 {
57 public:
58   /** an enum which defines if we have confidence that a file is supported */
59   enum Confidence {
60     STOFF_C_NONE=0/**< not supported */,
61     STOFF_C_UNSUPPORTED_ENCRYPTION /** encryption not supported*/,
62     STOFF_C_SUPPORTED_ENCRYPTION /** encryption supported */,
63     STOFF_C_EXCELLENT /** supported */
64   };
65   /** an enum to define the kind of document */
66   enum Kind {
67     STOFF_K_UNKNOWN=0 /**< unknown*/,
68     STOFF_K_BITMAP /** bitmap/image */,
69     STOFF_K_CHART /** chart */,
70     STOFF_K_DATABASE /** database */,
71     STOFF_K_DRAW /** vectorized graphic: .sda*/,
72     STOFF_K_MATH /** math*/,
73     STOFF_K_PRESENTATION /** presentation*/,
74     STOFF_K_SPREADSHEET /** spreadsheet: .sdc */,
75     STOFF_K_TEXT /** word processing file*/,
76     STOFF_K_GRAPHIC /** gallery graphic: .sdg */
77   };
78   /** an enum which defines the result of the file parsing */
79   enum Result {
80     STOFF_R_OK=0 /**< conversion ok*/,
81     STOFF_R_FILE_ACCESS_ERROR /** problem when accessing file*/,
82     STOFF_R_OLE_ERROR /** problem when reading the OLE structure*/,
83     STOFF_R_PARSE_ERROR /** problem when parsing the file*/,
84     STOFF_R_PASSWORD_MISSMATCH_ERROR /** problem when using the given password*/,
85     STOFF_R_UNKNOWN_ERROR /** unknown error*/
86   };
87 
88   /** Analyzes the content of an input stream to see if it can be parsed
89       \param input The input stream
90       \param kind The document kind ( filled if the file is supported )
91       \return A confidence value which represents the likelyhood that the content from
92       the input stream can be parsed */
93   static STOFFLIB Confidence isFileFormatSupported(librevenge::RVNGInputStream *input, Kind &kind);
94 
95   // ------------------------------------------------------------
96   // the different main parsers
97   // ------------------------------------------------------------
98 
99   /** Parses the input stream content. It will make callbacks to the functions provided by a
100      librevenge::RVNGTextInterface class implementation when needed. This is often commonly called the
101      'main parsing routine'.
102      \param input The input stream
103      \param documentInterface A RVNGTextInterface implementation
104      \param password The file password
105 
106    \note Reserved for future use. Actually, it only returns false */
107   static STOFFLIB Result parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *documentInterface, char const *password=nullptr);
108 
109   /** Parses the input stream content. It will make callbacks to the functions provided by a
110      librevenge::RVNGDrawingInterface class implementation when needed. This is often commonly called the
111      'main parsing routine'.
112      \param input The input stream
113      \param documentInterface A RVNGDrawingInterface implementation
114      \param password The file password
115 
116      \note Reserved for future use. Actually, it only returns false. */
117   static STOFFLIB Result parse(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *documentInterface, char const *password=nullptr);
118 
119   /** Parses the input stream content. It will make callbacks to the functions provided by a
120      librevenge::RVNGPresentationInterface class implementation when needed. This is often commonly called the
121      'main parsing routine'.
122      \param input The input stream
123      \param documentInterface A RVNGPresentationInterface implementation
124      \param password The file password
125 
126      \note Reserved for future use. Actually, it only returns false. */
127   static STOFFLIB Result parse(librevenge::RVNGInputStream *input, librevenge::RVNGPresentationInterface *documentInterface, char const *password=nullptr);
128 
129   /** Parses the input stream content. It will make callbacks to the functions provided by a
130      librevenge::RVNGSpreadsheetInterface class implementation when needed. This is often commonly called the
131      'main parsing routine'.
132      \param input The input stream
133      \param documentInterface A RVNGSpreadsheetInterface implementation
134      \param password The file password
135 
136    \note Can only convert some basic documents: retrieving more cells' contents but no formating. */
137   static STOFFLIB Result parse(librevenge::RVNGInputStream *input, librevenge::RVNGSpreadsheetInterface *documentInterface, char const *password=nullptr);
138 
139   // ------------------------------------------------------------
140   // decoders of the embedded zones created by libstoff
141   // ------------------------------------------------------------
142 
143   /** Parses the graphic contained in the binary data and called documentInterface to reconstruct
144     a graphic. The input is normally send to a librevenge::RVNGXXXInterface with mimeType="image/stoff-odg",
145     ie. it must correspond to a picture created by the STOFFGraphicEncoder class via
146     a STOFFPropertyEncoder.
147 
148    \param binary a list of librevenge::RVNGDrawingInterface stored in a documentInterface,
149    \param documentInterface the RVNGDrawingInterface which will convert the graphic is some specific format.
150 
151    \note Reserved for future use. Actually, it only returns false. */
152   static STOFFLIB bool decodeGraphic(librevenge::RVNGBinaryData const &binary, librevenge::RVNGDrawingInterface *documentInterface);
153 
154   /** Parses the spreadsheet contained in the binary data and called documentInterface to reconstruct
155     a spreadsheet. The input is normally send to a librevenge::RVNGXXXInterface with mimeType="image/stoff-ods",
156     ie. it must correspond to a spreadsheet created by the STOFFSpreadsheetInterface class via
157     a STOFFPropertyEncoder.
158 
159    \param binary a list of librevenge::RVNGSpreadsheetInterface stored in a documentInterface,
160    \param documentInterface the RVNGSpreadsheetInterface which will convert the spreadsheet is some specific format.
161 
162    \note Reserved for future use. Actually, it only returns false. */
163   static STOFFLIB bool decodeSpreadsheet(librevenge::RVNGBinaryData const &binary, librevenge::RVNGSpreadsheetInterface *documentInterface);
164 
165   /** Parses the text contained in the binary data and called documentInterface to reconstruct
166     a text. The input is normally send to a librevenge::RVNGXXXInterface with mimeType="image/stoff-odt",
167     ie. it must correspond to a text created by the STOFFTextInterface class via
168     a STOFFPropertyEncoder.
169 
170    \param binary a list of librevenge::RVNGTextInterface stored in a documentInterface,
171    \param documentInterface the RVNGTextInterface which will convert the text is some specific format.
172 
173    \note Reserved for future use. Actually, it only returns false. */
174   static STOFFLIB bool decodeText(librevenge::RVNGBinaryData const &binary, librevenge::RVNGTextInterface *documentInterface);
175 };
176 
177 #endif /* STOFFDOCUMENT_HXX */
178 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
179