| 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 |
#ifndef WKSCONTENTLISTENER_H |
| 26 |
#define WKSCONTENTLISTENER_H |
| 27 |
|
| 28 |
#include <vector> |
| 29 |
|
| 30 |
#include <librevenge/librevenge.h> |
| 31 |
|
| 32 |
#include "libwps_internal.h" |
| 33 |
|
| 34 |
#include "WPSEntry.h" |
| 35 |
#include "WPSGraphicStyle.h" |
| 36 |
|
| 37 |
#include "WPSListener.h" |
| 38 |
|
| 39 |
class WPSCellFormat; |
| 40 |
class WKSChart; |
| 41 |
struct WPSColumnFormat; |
| 42 |
class WPSGraphicShape; |
| 43 |
class WPSGraphicStyle; |
| 44 |
class WPSList; |
| 45 |
class WPSPageSpan; |
| 46 |
struct WPSParagraph; |
| 47 |
struct WPSRowFormat; |
| 48 |
struct WPSTabStop; |
| 49 |
|
| 50 |
struct WKSContentParsingState; |
| 51 |
struct WKSDocumentParsingState; |
| 52 |
|
| 53 |
class WKSContentListener final : public WPSListener |
| 54 |
{ |
| 55 |
public: |
| 56 |
|
| 57 |
struct FormulaInstruction |
| 58 |
{ |
| 59 |
enum What { F_Operator, F_Function, F_Cell, F_CellList, F_Long, F_Double, F_Text }; |
| 60 |
|
| 61 |
FormulaInstruction() |
| 62 |
: m_type(F_Text) |
| 63 |
, m_content() |
| 64 |
, m_longValue(0) |
| 65 |
, m_doubleValue(0) |
| 66 |
, m_fileName() |
| 67 |
{ |
| 68 |
for (auto &pos : m_position) pos=Vec2i(0,0); |
| 69 |
for (auto &pos : m_positionRelative) pos=Vec2b(false,false); |
| 70 |
for (auto &id : m_sheetId) id=-1; |
| 71 |
} |
| 72 |
|
| 73 |
librevenge::RVNGPropertyList getPropertyList() const; |
| 74 |
|
| 75 |
friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst); |
| 76 |
|
| 77 |
What m_type; |
| 78 |
|
| 79 |
std::string m_content; |
| 80 |
|
| 81 |
double m_longValue; |
| 82 |
|
| 83 |
double m_doubleValue; |
| 84 |
|
| 85 |
Vec2i m_position[2]; |
| 86 |
|
| 87 |
Vec2b m_positionRelative[2]; |
| 88 |
|
| 89 |
librevenge::RVNGString m_sheetName[2]; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
int m_sheetId[2]; |
| 95 |
|
| 96 |
librevenge::RVNGString m_fileName; |
| 97 |
}; |
| 98 |
|
| 99 |
struct CellContent |
| 100 |
{ |
| 101 |
|
| 102 |
enum ContentType { C_NONE, C_TEXT, C_NUMBER, C_FORMULA, C_UNKNOWN }; |
| 103 |
|
| 104 |
CellContent() |
| 105 |
: m_contentType(C_UNKNOWN) |
| 106 |
, m_value(0.0) |
| 107 |
, m_valueSet(false) |
| 108 |
, m_textEntry() |
| 109 |
, m_formula() { } |
| 110 |
CellContent(CellContent const &)=default; |
| 111 |
CellContent &operator=(CellContent const &)=default; |
| 112 |
|
| 113 |
~CellContent() {} |
| 114 |
|
| 115 |
friend std::ostream &operator<<(std::ostream &o, CellContent const &cell); |
| 116 |
|
| 117 |
|
| 118 |
bool empty() const |
| 119 |
{ |
| 120 |
if (m_contentType == C_NUMBER) return false; |
| 121 |
if (m_contentType == C_TEXT && !m_textEntry.valid()) return false; |
| 122 |
if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false; |
| 123 |
return true; |
| 124 |
} |
| 125 |
|
| 126 |
void setValue(double value) |
| 127 |
{ |
| 128 |
m_value = value; |
| 129 |
m_valueSet = true; |
| 130 |
} |
| 131 |
|
| 132 |
bool isValueSet() const |
| 133 |
{ |
| 134 |
return m_valueSet; |
| 135 |
} |
| 136 |
|
| 137 |
bool hasText() const |
| 138 |
{ |
| 139 |
return m_textEntry.valid(); |
| 140 |
} |
| 141 |
|
| 142 |
static bool double2Date(double val, int &Y, int &M, int &D); |
| 143 |
|
| 144 |
static bool double2Time(double val, int &H, int &M, int &S); |
| 145 |
|
| 146 |
|
| 147 |
ContentType m_contentType; |
| 148 |
|
| 149 |
double m_value; |
| 150 |
|
| 151 |
bool m_valueSet; |
| 152 |
|
| 153 |
WPSEntry m_textEntry; |
| 154 |
|
| 155 |
std::vector<FormulaInstruction> m_formula; |
| 156 |
}; |
| 157 |
|
| 158 |
WKSContentListener(std::vector<WPSPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface); |
| 159 |
~WKSContentListener() final; |
| 160 |
|
| 161 |
void setDocumentLanguage(int lcid) final; |
| 162 |
void setMetaData(const librevenge::RVNGPropertyList &list); |
| 163 |
|
| 164 |
void startDocument(); |
| 165 |
void endDocument(); |
| 166 |
void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType); |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
void insertCharacter(uint8_t character) final; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
void insertUnicode(uint32_t character) final; |
| 176 |
|
| 177 |
void insertUnicodeString(librevenge::RVNGString const &str) final; |
| 178 |
|
| 179 |
void insertTab() final; |
| 180 |
void insertEOL(bool softBreak=false) final; |
| 181 |
void insertBreak(const uint8_t breakType) final; |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
void setFont(const WPSFont &font) final; |
| 186 |
|
| 187 |
WPSFont const &getFont() const final; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
bool isParagraphOpened() const final; |
| 192 |
|
| 193 |
void setParagraph(const WPSParagraph ¶) final; |
| 194 |
|
| 195 |
WPSParagraph const &getParagraph() const final; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
void insertField(WPSField const &field) final; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
void insertComment(WPSSubDocumentPtr &subDocument); |
| 204 |
|
| 205 |
void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData, |
| 206 |
std::string const &type="image/pict", WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle()); |
| 207 |
|
| 208 |
void insertObject(WPSPosition const &pos, const WPSEmbeddedObject &obj, |
| 209 |
WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle()); |
| 210 |
|
| 211 |
void insertPicture(WPSPosition const &pos, WPSGraphicShape const &shape, WPSGraphicStyle const &style); |
| 212 |
|
| 213 |
void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument, |
| 214 |
WPSGraphicStyle const &frameStyle=WPSGraphicStyle::emptyStyle()); |
| 215 |
|
| 216 |
bool openGroup(WPSPosition const &pos) final; |
| 217 |
|
| 218 |
void closeGroup() final; |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
void openSheet(std::vector<WPSColumnFormat> const &columns, librevenge::RVNGString const &name=""); |
| 223 |
|
| 224 |
void closeSheet(); |
| 225 |
|
| 226 |
void openSheetRow(WPSRowFormat const &f, int numRepeated=1); |
| 227 |
|
| 228 |
void closeSheetRow(); |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
void openSheetCell(WPSCell const &cell, CellContent const &content, int numRepeated=1); |
| 234 |
|
| 235 |
void closeSheetCell(); |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
void insertChart(WPSPosition const &pos, WKSChart const &chart, |
| 240 |
WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle()); |
| 241 |
protected: |
| 242 |
void _openPageSpan(); |
| 243 |
void _closePageSpan(); |
| 244 |
|
| 245 |
void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos); |
| 246 |
bool _openFrame(WPSPosition const &pos, WPSGraphicStyle const &style); |
| 247 |
void _closeFrame(); |
| 248 |
|
| 249 |
void _startSubDocument(); |
| 250 |
void _endSubDocument(); |
| 251 |
|
| 252 |
void _openParagraph(); |
| 253 |
void _closeParagraph(); |
| 254 |
void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false); |
| 255 |
void _resetParagraphState(const bool isListElement=false); |
| 256 |
|
| 257 |
void _openSpan(); |
| 258 |
void _closeSpan(); |
| 259 |
|
| 260 |
void _flushText(); |
| 261 |
void _flushDeferredTabs(); |
| 262 |
|
| 263 |
void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList); |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
std::shared_ptr<WKSContentParsingState> _pushParsingState(); |
| 269 |
|
| 270 |
void _popParsingState(); |
| 271 |
|
| 272 |
protected: |
| 273 |
std::shared_ptr<WKSDocumentParsingState> m_ds; |
| 274 |
std::shared_ptr<WKSContentParsingState> m_ps; |
| 275 |
std::vector<std::shared_ptr<WKSContentParsingState> > m_psStack; |
| 276 |
librevenge::RVNGSpreadsheetInterface *m_documentInterface; |
| 277 |
|
| 278 |
private: |
| 279 |
WKSContentListener(const WKSContentListener &) = delete; |
| 280 |
WKSContentListener &operator=(const WKSContentListener &) = delete; |
| 281 |
}; |
| 282 |
|
| 283 |
#endif |
| 284 |
|