/src/libmwaw/src/lib/ClarisWksBMParser.cxx
Line | Count | Source |
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 | | #include <algorithm> |
35 | | #include <cstring> |
36 | | #include <iomanip> |
37 | | #include <iostream> |
38 | | #include <limits> |
39 | | #include <map> |
40 | | #include <sstream> |
41 | | |
42 | | #include <librevenge/librevenge.h> |
43 | | |
44 | | #include "MWAWFont.hxx" |
45 | | #include "MWAWFontConverter.hxx" |
46 | | #include "MWAWGraphicListener.hxx" |
47 | | #include "MWAWHeader.hxx" |
48 | | #include "MWAWPosition.hxx" |
49 | | #include "MWAWPictMac.hxx" |
50 | | #include "MWAWPrinter.hxx" |
51 | | #include "MWAWSection.hxx" |
52 | | |
53 | | #include "ClarisWksDatabase.hxx" |
54 | | #include "ClarisWksDocument.hxx" |
55 | | #include "ClarisWksGraph.hxx" |
56 | | #include "ClarisWksPresentation.hxx" |
57 | | #include "ClarisWksSpreadsheet.hxx" |
58 | | #include "ClarisWksStruct.hxx" |
59 | | #include "ClarisWksStyleManager.hxx" |
60 | | #include "ClarisWksTable.hxx" |
61 | | #include "ClarisWksText.hxx" |
62 | | |
63 | | #include "ClarisWksBMParser.hxx" |
64 | | |
65 | | /** Internal: the structures of a ClarisWksBMParser */ |
66 | | namespace ClarisWksBMParserInternal |
67 | | { |
68 | | |
69 | | //////////////////////////////////////// |
70 | | //! Internal: the state of a ClarisWksBMParser |
71 | | struct State { |
72 | | //! constructor |
73 | | State() |
74 | 309k | { |
75 | 309k | } |
76 | | }; |
77 | | } |
78 | | |
79 | | //////////////////////////////////////////////////////////// |
80 | | // constructor/destructor, ... |
81 | | //////////////////////////////////////////////////////////// |
82 | | ClarisWksBMParser::ClarisWksBMParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
83 | 124k | : MWAWGraphicParser(input, rsrcParser, header) |
84 | 124k | , m_state() |
85 | 124k | , m_document() |
86 | 124k | { |
87 | 124k | init(); |
88 | 124k | } |
89 | | |
90 | | ClarisWksBMParser::~ClarisWksBMParser() |
91 | 124k | { |
92 | 124k | } |
93 | | |
94 | | void ClarisWksBMParser::init() |
95 | 124k | { |
96 | 124k | resetGraphicListener(); |
97 | 124k | setAsciiName("main-1"); |
98 | | |
99 | 124k | m_state.reset(new ClarisWksBMParserInternal::State); |
100 | 124k | m_document.reset(new ClarisWksDocument(*this)); |
101 | | // reduce the margin (in case, the page is not defined) |
102 | 124k | getPageSpan().setMargins(0.1); |
103 | 124k | } |
104 | | |
105 | | //////////////////////////////////////////////////////////// |
106 | | // interface with the different parser |
107 | | //////////////////////////////////////////////////////////// |
108 | | bool ClarisWksBMParser::checkHeader(MWAWHeader *header, bool strict) |
109 | 185k | { |
110 | 185k | *m_state = ClarisWksBMParserInternal::State(); |
111 | 185k | if (!m_document->checkHeader(header, strict)) |
112 | 58 | return false; |
113 | 185k | return getParserState()->m_kind==MWAWDocument::MWAW_K_PAINT; |
114 | 185k | } |
115 | | |
116 | | //////////////////////////////////////////////////////////// |
117 | | // the parser |
118 | | //////////////////////////////////////////////////////////// |
119 | | void ClarisWksBMParser::parse(librevenge::RVNGDrawingInterface *docInterface) |
120 | 60.7k | { |
121 | 60.7k | if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException()); |
122 | 60.7k | bool ok = true; |
123 | 60.7k | try { |
124 | | // create the asciiFile |
125 | 60.7k | ascii().setStream(getInput()); |
126 | 60.7k | ascii().open(asciiName()); |
127 | | |
128 | 60.7k | checkHeader(nullptr); |
129 | 60.7k | ok = m_document->createZones(); |
130 | | // check that we have at least read the main zone |
131 | 60.7k | if (ok) { |
132 | 56.2k | auto zMap = m_document->getZone(1); |
133 | 56.2k | ok = zMap && zMap->m_fileType==4; |
134 | 56.2k | } |
135 | 60.7k | if (ok) { |
136 | 22.7k | createDocument(docInterface); |
137 | | |
138 | 22.7k | MWAWPageSpan const &page=getPageSpan(); |
139 | 22.7k | MWAWPosition pos(MWAWVec2f(float(page.getMarginLeft()),float(page.getMarginRight())), |
140 | 22.7k | MWAWVec2f(float(page.getPageWidth()),float(page.getPageLength())), librevenge::RVNG_INCH); |
141 | 22.7k | pos.setRelativePosition(MWAWPosition::Page); |
142 | 22.7k | pos.m_wrapping = MWAWPosition::WNone; |
143 | 22.7k | m_document->sendZone(1, getGraphicListener(), pos); |
144 | 22.7k | } |
145 | 60.7k | ascii().reset(); |
146 | 60.7k | } |
147 | 60.7k | catch (...) { |
148 | 18 | MWAW_DEBUG_MSG(("ClarisWksBMParser::parse: exception catched when parsing\n")); |
149 | 18 | ok = false; |
150 | 18 | } |
151 | | |
152 | 60.7k | resetGraphicListener(); |
153 | 60.7k | if (!ok) throw(libmwaw::ParseException()); |
154 | 60.7k | } |
155 | | |
156 | | //////////////////////////////////////////////////////////// |
157 | | // create the document |
158 | | //////////////////////////////////////////////////////////// |
159 | | void ClarisWksBMParser::createDocument(librevenge::RVNGDrawingInterface *documentInterface) |
160 | 22.7k | { |
161 | 22.7k | if (!documentInterface) return; |
162 | 22.7k | if (getGraphicListener()) { |
163 | 0 | MWAW_DEBUG_MSG(("ClarisWksBMParser::createDocument: listener already exist\n")); |
164 | 0 | return; |
165 | 0 | } |
166 | | |
167 | 22.7k | m_document->m_graphParser->computePositions(); |
168 | | |
169 | | // |
170 | 22.7k | std::vector<MWAWPageSpan> pageList; |
171 | 22.7k | m_document->updatePageSpanList(pageList); |
172 | 22.7k | MWAWGraphicListenerPtr listen(new MWAWGraphicListener(*getParserState(), pageList, documentInterface)); |
173 | 22.7k | setGraphicListener(listen); |
174 | 22.7k | listen->setDocumentMetaData(m_document->getDocumentMetaData()); |
175 | 22.7k | listen->startDocument(); |
176 | 22.7k | } |
177 | | |
178 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |