Debian Codegraph @

src/lib/MWAWParser.cxx

raw
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 ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
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 #include "MWAWFont.hxx"
35 #include "MWAWFontConverter.hxx"
36 #include "MWAWGraphicListener.hxx"
37 #include "MWAWGraphicStyle.hxx"
38 #include "MWAWList.hxx"
39 #include "MWAWPresentationListener.hxx"
40 #include "MWAWSpreadsheetListener.hxx"
41 #include "MWAWTextListener.hxx"
42
43 #include "MWAWParser.hxx"
44
45 MWAWParserState::MWAWParserState(MWAWParserState::Type type, MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
46 : m_type(type)
47 , m_kind(MWAWDocument::MWAW_K_TEXT)
48 , m_input(input)
49 , m_header(header)
50 , m_rsrcParser(rsrcParser)
51 , m_pageSpan()
52 , m_fontConverter()
53 , m_fontManager()
54 , m_graphicListener()
55 , m_listManager()
56 , m_presentationListener()
57 , m_spreadsheetListener()
58 , m_textListener()
59 , m_version(0)
60 , m_asciiFile(input)
61 {
62 if (header) {
63 m_version=header->getMajorVersion();
64 m_kind=header->getKind();
65 }
66 m_fontConverter.reset(new MWAWFontConverter);
67 m_fontManager.reset(new MWAWFontManager(m_fontConverter));
68 m_listManager.reset(new MWAWListManager(m_fontManager));
69 }
70
71 MWAWParserState::~MWAWParserState()
72 {
73 if (getMainListener()) try {
74 /* must never happen, only sanity check....
75
76 Ie. the parser which creates a listener, must delete it.
77 */
78 MWAW_DEBUG_MSG(("MWAWParserState::~MWAWParserState: the listener is NOT closed, call enddocument without any subdoc\n"));
79 getMainListener()->endDocument(false);
80 }
81 catch (const libmwaw::ParseException &) {
82 MWAW_DEBUG_MSG(("MWAWParserState::~MWAWParserState: endDocument FAILS\n"));
83 /* must never happen too...
84
85 Ie. the different parsers are responsable to create enough pages,
86 if we have exception here, this will indicate a second error in code
87 */
88 }
89 }
90
91 MWAWListenerPtr MWAWParserState::getMainListener()
92 {
93 switch (m_type) {
94 case Graphic:
95 return m_graphicListener;
96 case Presentation:
97 return m_presentationListener;
98 case Spreadsheet:
99 return m_spreadsheetListener;
100 case Text:
101 return m_textListener;
102 #if !defined(__clang__)
103 default:
104 MWAW_DEBUG_MSG(("MWAWParserState::getMainListener unexpected document type\n"));
105 #endif
106 }
107 return MWAWListenerPtr();
108 }
109
110 MWAWParser::MWAWParser(MWAWParserState::Type type, MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
111 : m_parserState(new MWAWParserState(type, input, rsrcParser, header))
112 , m_asciiName("")
113 {
114 }
115
116 MWAWParser::~MWAWParser()
117 {
118 }
119
120 MWAWListenerPtr MWAWParser::getMainListener()
121 {
122 return m_parserState->getMainListener();
123 }
124
125 void MWAWParser::setGraphicListener(MWAWGraphicListenerPtr &listener)
126 {
127 m_parserState->m_graphicListener=listener;
128 }
129
130 void MWAWParser::resetGraphicListener()
131 {
132 if (getGraphicListener()) getGraphicListener()->endDocument();
133 m_parserState->m_graphicListener.reset();
134 }
135
136 void MWAWParser::setPresentationListener(MWAWPresentationListenerPtr &listener)
137 {
138 m_parserState->m_presentationListener=listener;
139 }
140
141 void MWAWParser::resetPresentationListener()
142 {
143 if (getPresentationListener()) getPresentationListener()->endDocument();
144 m_parserState->m_presentationListener.reset();
145 }
146
147 void MWAWParser::setSpreadsheetListener(MWAWSpreadsheetListenerPtr &listener)
148 {
149 m_parserState->m_spreadsheetListener=listener;
150 }
151
152 void MWAWParser::resetSpreadsheetListener()
153 {
154 if (getSpreadsheetListener()) getSpreadsheetListener()->endDocument();
155 m_parserState->m_spreadsheetListener.reset();
156 }
157
158 void MWAWParser::setTextListener(MWAWTextListenerPtr &listener)
159 {
160 m_parserState->m_textListener=listener;
161 }
162
163 void MWAWParser::resetTextListener()
164 {
165 if (getTextListener()) getTextListener()->endDocument();
166 m_parserState->m_textListener.reset();
167 }
168
169 ////////////////////////////////////////////////////////////
170 //
171 ////////////////////////////////////////////////////////////
172
173 MWAWGraphicParser::~MWAWGraphicParser()
174 {
175 }
176
177 MWAWPresentationParser::~MWAWPresentationParser()
178 {
179 }
180
181 MWAWSpreadsheetParser::~MWAWSpreadsheetParser()
182 {
183 }
184
185 MWAWTextParser::~MWAWTextParser()
186 {
187 }
188 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: