1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ 2 3 /* libmwaw 4 * Version: MPL 2.0 / LGPLv2+ 5 * 6 * The contents of this file are subject to the Mozilla Public License Version 7 * 2.0 (the "License"); you may not use this file except in compliance with 8 * the License or as specified alternatively below. You may obtain a copy of 9 * the License at http://www.mozilla.org/MPL/ 10 * 11 * Software distributed under the License is distributed on an "AS IS" basis, 12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 * for the specific language governing rights and limitations under the 14 * License. 15 * 16 * Major Contributor(s): 17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com) 18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net) 19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) 20 * Copyright (C) 2006, 2007 Andrew Ziem 21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr) 22 * 23 * 24 * All Rights Reserved. 25 * 26 * For minor contributions see the git repository. 27 * 28 * Alternatively, the contents of this file may be used under the terms of 29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), 30 * in which case the provisions of the LGPLv2+ are applicable 31 * instead of those above. 32 */ 33 34 #ifndef MWAW_PRESENTATION_LISTENER_H 35 #define MWAW_PRESENTATION_LISTENER_H 36 37 #include <vector> 38 39 #include <librevenge/librevenge.h> 40 41 #include "libmwaw_internal.hxx" 42 43 #include "MWAWGraphicStyle.hxx" 44 45 #include "MWAWListener.hxx" 46 47 class MWAWGraphicShape; 48 49 namespace MWAWPresentationListenerInternal 50 { 51 struct GraphicState; 52 struct State; 53 } 54 55 /** This class contains code needed to write a presention document. 56 57 \note All units are specified in librevenge::RVNG_POINT 58 */ 59 class MWAWPresentationListener final : public MWAWListener 60 { 61 public: 62 /** constructor */ 63 MWAWPresentationListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, librevenge::RVNGPresentationInterface *documentInterface); 64 /** destructor */ 65 ~MWAWPresentationListener() final; 66 67 /** returns the listener type */ getType() const68 Type getType() const final 69 { 70 return Presentation; 71 } 72 73 /** sets the documents metadata */ 74 void setDocumentMetaData(librevenge::RVNGPropertyList const &metadata) final; 75 /** sets the documents language */ 76 void setDocumentLanguage(std::string const &locale) final; 77 /** starts a new document */ 78 void startDocument() final; 79 /** ends the actual document */ 80 void endDocument(bool delayed=true) final; 81 82 // ------ general information -------- 83 /** returns true if a text zone is opened */ 84 bool canWriteText() const final; 85 /** returns true if a document is opened */ 86 bool isDocumentStarted() const final; 87 88 /** function called to add a subdocument and modify the origin*/ 89 void handleSubDocument(MWAWVec2f const &orig, MWAWSubDocumentPtr const &subDocument, libmwaw::SubDocumentType subDocumentType); 90 /** function called to add a subdocument */ handleSubDocument(MWAWSubDocumentPtr const & subDocument,libmwaw::SubDocumentType subDocumentType)91 void handleSubDocument(MWAWSubDocumentPtr const &subDocument, libmwaw::SubDocumentType subDocumentType) final 92 { 93 handleSubDocument(MWAWVec2f(0,0), subDocument, subDocumentType); 94 } 95 /** returns try if a subdocument is open */ 96 bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const final; 97 /** store the position and the style (which will be needed further to insert a textbox or a table with openTable) */ 98 bool openFrame(MWAWPosition const &pos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle()) final; 99 /** close a frame */ 100 void closeFrame() final; 101 /** open a group */ 102 bool openGroup(MWAWPosition const &pos) final; 103 /** close a group */ 104 void closeGroup() final; 105 /** open a layer */ 106 bool openLayer(librevenge::RVNGString const &name); 107 /** close a layer */ 108 void closeLayer(); 109 110 // ------ page -------- 111 /** opens a master page */ 112 bool openMasterPage(MWAWPageSpan &masterPage); 113 /** close a master page */ closeMasterPage()114 void closeMasterPage() 115 { 116 _closePageSpan(true); 117 } 118 /** returns true if a page is opened */ 119 bool isPageSpanOpened() const final; 120 /** returns the current page span 121 122 \note this forces the opening of a new page if no page is opened.*/ 123 MWAWPageSpan const &getPageSpan() final; 124 125 // ------ header/footer -------- 126 /** insert a header */ 127 bool insertHeader(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) final; 128 /** insert a footer */ 129 bool insertFooter(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) final; 130 /** returns true if the header/footer is open */ 131 bool isHeaderFooterOpened() const final; 132 133 // ------ text data ----------- 134 //! adds a basic character, .. 135 void insertChar(uint8_t character) final; 136 /** insert a character using the font converter to find the utf8 137 character */ 138 void insertCharacter(unsigned char c) final; 139 /** insert a character using the font converter to find the utf8 140 character and if needed, input to read extra character. 141 142 \return the number of extra character read 143 */ 144 int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1) final; 145 /** adds an unicode character. 146 * By convention if \a character=0xfffd(undef), no character is added */ 147 void insertUnicode(uint32_t character) final; 148 //! adds a unicode string 149 void insertUnicodeString(librevenge::RVNGString const &str) final; 150 151 //! adds a tab 152 void insertTab() final; 153 //! adds an end of line ( by default an hard one) 154 void insertEOL(bool softBreak=false) final; 155 156 // ------ text format ----------- 157 //! sets the font 158 void setFont(MWAWFont const &font) final; 159 //! returns the actual font 160 MWAWFont const &getFont() const final; 161 162 // ------ paragraph format ----------- 163 //! returns true if a paragraph or a list is opened 164 bool isParagraphOpened() const final; 165 //! sets the paragraph 166 void setParagraph(MWAWParagraph const ¶graph) final; 167 //! returns the actual paragraph 168 MWAWParagraph const &getParagraph() const final; 169 170 // ------- fields ---------------- 171 //! adds a field type 172 void insertField(MWAWField const &field) final; 173 174 // ------- link ---------------- 175 //! open a link 176 void openLink(MWAWLink const &link) final; 177 //! close a link 178 void closeLink() final; 179 180 // ------- subdocument ----------------- 181 /** adds a picture with potential various representationin given position */ 182 void insertPicture(MWAWPosition const &pos, MWAWEmbeddedObject const &picture, 183 MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle()) final; 184 /** adds a shape picture in given position */ 185 void insertShape(MWAWPosition const &pos, MWAWGraphicShape const &shape, MWAWGraphicStyle const &style) final; 186 /** adds a textbox in given position */ 187 void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr const &subDocument, MWAWGraphicStyle const &style) final; 188 /** adds a group: ie. next insertion will be done relative to this bdbox[0] position */ 189 void insertGroup(MWAWBox2f const &bdbox, MWAWSubDocumentPtr const &subDocument); 190 /** insert a slide note */ 191 void insertSlideNote(MWAWPosition const &pos, MWAWSubDocumentPtr &subDocument); 192 /** insert a note 193 194 \note as RVNGPresentationInterface does not accept note, note can only be inserted in a text zone (and are inserted between --) */ 195 void insertNote(MWAWNote const ¬e, MWAWSubDocumentPtr &subDocument) final; 196 /** adds comment 197 198 \note as RVNGPresentationInterface does not accept comment, comment can only be inserted in a text zone (and are inserted between --) */ 199 void insertComment(MWAWSubDocumentPtr &subDocument) final; 200 201 // ------- table ----------------- 202 203 /** adds a table in given position */ 204 void insertTable(MWAWPosition const &pos, MWAWTable &table, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle()); 205 /** open a table (using the last parameters of openFrame for the position ) */ 206 void openTable(MWAWTable const &table) final; 207 /** open a table in a given position */ 208 void openTable(MWAWPosition const &pos, MWAWTable const &table, MWAWGraphicStyle const &style); 209 /** closes this table */ 210 void closeTable() final; 211 /** open a row with given height ( if h < 0.0, set min-row-height = -h )*/ 212 void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false) final; 213 /** closes this row */ 214 void closeTableRow() final; 215 /** open a cell */ 216 void openTableCell(MWAWCell const &cell) final; 217 /** close a cell */ 218 void closeTableCell() final; 219 /** add empty cell */ 220 void addEmptyTableCell(MWAWVec2i const &pos, MWAWVec2i span=MWAWVec2i(1,1)) final; 221 222 // ------- section --------------- 223 224 /** returns true if we can add open a section, add page break, ... */ canOpenSectionAddBreak() const225 bool canOpenSectionAddBreak() const final 226 { 227 return false; 228 } 229 //! returns true if a section is opened isSectionOpened() const230 bool isSectionOpened() const final 231 { 232 return false; 233 } 234 //! returns the actual section 235 MWAWSection const &getSection() const final; 236 //! open a section if possible 237 bool openSection(MWAWSection const §ion) final; 238 //! close a section closeSection()239 bool closeSection() final 240 { 241 return false; 242 } 243 //! inserts a break type: ColumBreak, PageBreak, .. 244 void insertBreak(BreakType breakType) final; 245 246 protected: 247 //! does open a new page (low level) 248 void _openPageSpan(bool sendHeaderFooters=true); 249 //! does close a page (low level) 250 void _closePageSpan(bool masterPage=false); 251 252 void _startSubDocument(); 253 void _endSubDocument(); 254 255 /** adds in propList the frame parameters. 256 257 \note if there is some gradient, first draw a rectangle to print the gradient and them update propList */ 258 void _handleFrameParameters(librevenge::RVNGPropertyList &propList, MWAWPosition const &pos, MWAWGraphicStyle const &style); 259 260 void _openParagraph(); 261 void _closeParagraph(); 262 void _resetParagraphState(const bool isListElement=false); 263 264 /** open a list level */ 265 void _openListElement(); 266 /** close a list level */ 267 void _closeListElement(); 268 /** update the list so that it corresponds to the actual level */ 269 void _changeList(); 270 /** low level: find a list id which corresponds to actual list and a change of level. 271 272 \note called when the list id is not set 273 */ 274 int _getListId() const; 275 276 void _openSpan(); 277 void _closeSpan(); 278 279 void _flushText(); 280 281 /** creates a new parsing state (copy of the actual state) 282 * 283 * \return the old one */ 284 std::shared_ptr<MWAWPresentationListenerInternal::State> _pushParsingState(); 285 //! resets the previous parsing state 286 void _popParsingState(); 287 288 protected: 289 //! the actual global state 290 std::shared_ptr<MWAWPresentationListenerInternal::GraphicState> m_ds; 291 //! the actual local parse state 292 std::shared_ptr<MWAWPresentationListenerInternal::State> m_ps; 293 //! stack of local state 294 std::vector<std::shared_ptr<MWAWPresentationListenerInternal::State> > m_psStack; 295 //! the parser state 296 MWAWParserState &m_parserState; 297 //! the document interface 298 librevenge::RVNGPresentationInterface *m_documentInterface; 299 300 private: 301 MWAWPresentationListener(const MWAWPresentationListener &) = delete; 302 MWAWPresentationListener &operator=(const MWAWPresentationListener &) = delete; 303 }; 304 305 #endif 306 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: 307