new upstream release 0.3.1

f41
David Tardon 11 years ago
parent 683332197b
commit 749ea021ae

1
.gitignore vendored

@ -4,3 +4,4 @@
/libmwaw-0.1.10.tar.xz
/libmwaw-0.1.11.tar.xz
/libmwaw-0.2.0.tar.xz
/libmwaw-0.3.1.tar.xz

@ -0,0 +1,266 @@
From 7b7cf183a7ad454706aa0f1657c851c578ec476e Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Sun, 25 May 2014 15:51:54 +0200
Subject: [PATCH 1/2] librevenge-stream is optional: don't depend on it
---
src/lib/MWAWStringStream.cxx | 153 +++++++++++++++++++++++++++++++++++++++++++
src/lib/MWAWStringStream.hxx | 50 ++++++++++++++
src/lib/Makefile.am | 2 +
src/lib/WingzParser.cxx | 3 +-
4 files changed, 207 insertions(+), 1 deletion(-)
create mode 100644 src/lib/MWAWStringStream.cxx
create mode 100644 src/lib/MWAWStringStream.hxx
diff --git a/src/lib/MWAWStringStream.cxx b/src/lib/MWAWStringStream.cxx
new file mode 100644
index 0000000..efea071
--- /dev/null
+++ b/src/lib/MWAWStringStream.cxx
@@ -0,0 +1,153 @@
+/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
+
+/* libmwaw
+* Version: MPL 2.0 / LGPLv2+
+*
+* The contents of this file are subject to the Mozilla Public License Version
+* 2.0 (the "License"); you may not use this file except in compliance with
+* the License or as specified alternatively below. You may obtain a copy of
+* the License at http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS" basis,
+* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+* for the specific language governing rights and limitations under the
+* License.
+*
+* Alternatively, the contents of this file may be used under the terms of
+* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
+* in which case the provisions of the LGPLv2+ are applicable
+* instead of those above.
+*/
+
+#include <cstring>
+#include <vector>
+
+#include <librevenge-stream/librevenge-stream.h>
+
+#include "MWAWStringStream.hxx"
+
+class MWAWStringStreamPrivate
+{
+public:
+ MWAWStringStreamPrivate(const unsigned char *data, unsigned dataSize);
+ ~MWAWStringStreamPrivate();
+ std::vector<unsigned char> buffer;
+ long offset;
+private:
+ MWAWStringStreamPrivate(const MWAWStringStreamPrivate &);
+ MWAWStringStreamPrivate &operator=(const MWAWStringStreamPrivate &);
+};
+
+MWAWStringStreamPrivate::MWAWStringStreamPrivate(const unsigned char *data, unsigned dataSize) :
+ buffer(dataSize),
+ offset(0)
+{
+ std::memcpy(&buffer[0], data, dataSize);
+}
+
+MWAWStringStreamPrivate::~MWAWStringStreamPrivate()
+{
+}
+
+MWAWStringStream::MWAWStringStream(const unsigned char *data, const unsigned int dataSize) :
+ librevenge::RVNGInputStream(),
+ d(new MWAWStringStreamPrivate(data, dataSize))
+{
+}
+
+MWAWStringStream::~MWAWStringStream()
+{
+ delete d;
+}
+
+const unsigned char *MWAWStringStream::read(unsigned long numBytes, unsigned long &numBytesRead)
+{
+ numBytesRead = 0;
+
+ if (numBytes == 0)
+ return 0;
+
+ long numBytesToRead;
+
+ if ((unsigned long)d->offset+numBytes < d->buffer.size())
+ numBytesToRead = (long) numBytes;
+ else
+ numBytesToRead = (long) d->buffer.size() - d->offset;
+
+ numBytesRead = (unsigned long) numBytesToRead; // about as paranoid as we can be..
+
+ if (numBytesToRead == 0)
+ return 0;
+
+ long oldOffset = d->offset;
+ d->offset += numBytesToRead;
+
+ return &d->buffer[size_t(oldOffset)];
+
+}
+
+long MWAWStringStream::tell()
+{
+ return d->offset;
+}
+
+int MWAWStringStream::seek(long offset, librevenge::RVNG_SEEK_TYPE seekType)
+{
+ if (seekType == librevenge::RVNG_SEEK_CUR)
+ d->offset += offset;
+ else if (seekType == librevenge::RVNG_SEEK_SET)
+ d->offset = offset;
+ else if (seekType == librevenge::RVNG_SEEK_END)
+ d->offset += d->buffer.size();
+
+ if (d->offset < 0) {
+ d->offset = 0;
+ return 1;
+ }
+ if ((long)d->offset > (long)d->buffer.size()) {
+ d->offset = (long) d->buffer.size();
+ return 1;
+ }
+
+ return 0;
+}
+
+bool MWAWStringStream::isEnd()
+{
+ if ((long)d->offset >= (long)d->buffer.size())
+ return true;
+
+ return false;
+}
+
+bool MWAWStringStream::isStructured()
+{
+ return false;
+}
+
+unsigned MWAWStringStream::subStreamCount()
+{
+ return 0;
+}
+
+const char *MWAWStringStream::subStreamName(unsigned)
+{
+ return 0;
+}
+
+bool MWAWStringStream::existsSubStream(const char *)
+{
+ return false;
+}
+
+librevenge::RVNGInputStream *MWAWStringStream::getSubStreamById(unsigned)
+{
+ return 0;
+}
+
+librevenge::RVNGInputStream *MWAWStringStream::getSubStreamByName(const char *)
+{
+ return 0;
+}
+
+// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
diff --git a/src/lib/MWAWStringStream.hxx b/src/lib/MWAWStringStream.hxx
new file mode 100644
index 0000000..9a6aa02
--- /dev/null
+++ b/src/lib/MWAWStringStream.hxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
+
+/* libmwaw
+* Version: MPL 2.0 / LGPLv2+
+*
+* The contents of this file are subject to the Mozilla Public License Version
+* 2.0 (the "License"); you may not use this file except in compliance with
+* the License or as specified alternatively below. You may obtain a copy of
+* the License at http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS" basis,
+* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+* for the specific language governing rights and limitations under the
+* License.
+*
+* Alternatively, the contents of this file may be used under the terms of
+* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
+* in which case the provisions of the LGPLv2+ are applicable
+* instead of those above.
+*/
+
+#include <librevenge-stream/librevenge-stream.h>
+
+class MWAWStringStreamPrivate;
+
+class MWAWStringStream: public librevenge::RVNGInputStream
+{
+public:
+ MWAWStringStream(const unsigned char *data, const unsigned int dataSize);
+ ~MWAWStringStream();
+
+ const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead);
+ long tell();
+ int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType);
+ bool isEnd();
+
+ bool isStructured();
+ unsigned subStreamCount();
+ const char *subStreamName(unsigned);
+ bool existsSubStream(const char *name);
+ librevenge::RVNGInputStream *getSubStreamByName(const char *name);
+ librevenge::RVNGInputStream *getSubStreamById(unsigned);
+
+private:
+ MWAWStringStreamPrivate *d;
+ MWAWStringStream(const MWAWStringStream &); // copy is not allowed
+ MWAWStringStream &operator=(const MWAWStringStream &); // assignment is not allowed
+};
+
+// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index eb17bad..f7934b4 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -223,6 +223,8 @@ libmwaw_@MWAW_MAJOR_VERSION@_@MWAW_MINOR_VERSION@_la_SOURCES = \
MWAWSpreadsheetEncoder.hxx \
MWAWSpreadsheetListener.cxx \
MWAWSpreadsheetListener.hxx \
+ MWAWStringStream.cxx \
+ MWAWStringStream.hxx \
MWAWSubDocument.cxx \
MWAWSubDocument.hxx \
MWAWTable.cxx \
diff --git a/src/lib/WingzParser.cxx b/src/lib/WingzParser.cxx
index 4813816..93dde7d 100644
--- a/src/lib/WingzParser.cxx
+++ b/src/lib/WingzParser.cxx
@@ -49,6 +49,7 @@
#include "MWAWPictMac.hxx"
#include "MWAWPrinter.hxx"
#include "MWAWSpreadsheetListener.hxx"
+#include "MWAWStringStream.hxx"
#include "MWAWSubDocument.hxx"
#include "WingzParser.hxx"
@@ -2496,7 +2497,7 @@ bool WingzParser::decodeEncrypted()
// finally replace the actual input with a new input
shared_ptr<librevenge::RVNGInputStream> newInput
- (new librevenge::RVNGStringStream(buffer, (unsigned int)length));
+ (new MWAWStringStream(buffer, (unsigned int)length));
delete [] buffer;
getParserState()->m_input.reset(new MWAWInputStream(newInput, false));
return true;
--
1.9.0

@ -1,43 +0,0 @@
From 5da59d9aa9298136d447e4014aef207f00cdc82b Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Sun, 3 Nov 2013 12:26:26 +0100
Subject: [PATCH 1/8] std::isfinite is C++11
---
configure.ac | 10 ++++++++++
src/lib/CWDbaseContent.cxx | 5 +++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/lib/CWDbaseContent.cxx b/src/lib/CWDbaseContent.cxx
index f27148d..7198103 100644
--- a/src/lib/CWDbaseContent.cxx
+++ b/src/lib/CWDbaseContent.cxx
@@ -33,7 +33,6 @@
#include <time.h>
-#include <cmath>
#include <cstring>
#include <ctime>
#include <iomanip>
@@ -41,6 +40,8 @@
#include <set>
#include <sstream>
+#include <boost/math/special_functions/fpclassify.hpp>
+
#include <libwpd/libwpd.h>
#include "MWAWContentListener.hxx"
@@ -969,7 +970,7 @@ void CWDbaseContent::send(double val, CWStyleManager::CellFormat const &format)
if (type>=10&&type<=11) type += 4;
else if (type>=14) type=16;
}
- if (type <= 0 || type >=16 || type==10 || type==11 || !std::isfinite(val)) {
+ if (type <= 0 || type >=16 || type==10 || type==11 || !boost::math::isfinite(val)) {
s << val;
listener->insertUnicodeString(s.str().c_str());
return;
--
1.9.0

@ -0,0 +1,54 @@
From ead2223f2d3d4742df84f37c6cea9c73b71257c5 Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Sun, 25 May 2014 16:07:21 +0200
Subject: [PATCH 2/2] librevenge-stream is optional: don't depend on it
---
src/lib/MWAWInputStream.cxx | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/lib/MWAWInputStream.cxx b/src/lib/MWAWInputStream.cxx
index 91b713b..0d60f67 100644
--- a/src/lib/MWAWInputStream.cxx
+++ b/src/lib/MWAWInputStream.cxx
@@ -43,6 +43,7 @@
#include "MWAWDebug.hxx"
#include "MWAWInputStream.hxx"
+#include "MWAWStringStream.hxx"
MWAWInputStream::MWAWInputStream(shared_ptr<librevenge::RVNGInputStream> inp, bool inverted)
: m_stream(inp), m_streamSize(0), m_inverseRead(inverted), m_readLimit(-1), m_prevLimits(),
@@ -517,7 +518,7 @@ bool MWAWInputStream::unBinHex()
MWAW_DEBUG_MSG(("MWAWInputStream::unBinHex: can not read the resource fork\n"));
}
else {
- shared_ptr<librevenge::RVNGInputStream> rsrc(new librevenge::RVNGStringStream(data, (unsigned int)numBytesRead));
+ shared_ptr<librevenge::RVNGInputStream> rsrc(new MWAWStringStream(data, (unsigned int)numBytesRead));
m_resourceFork.reset(new MWAWInputStream(rsrc,false));
}
}
@@ -532,7 +533,7 @@ bool MWAWInputStream::unBinHex()
MWAW_DEBUG_MSG(("MWAWInputStream::unBinHex: can not read the data fork\n"));
return false;
}
- m_stream.reset(new librevenge::RVNGStringStream(data, (unsigned int)numBytesRead));
+ m_stream.reset(new MWAWStringStream(data, (unsigned int)numBytesRead));
}
return true;
@@ -692,9 +693,9 @@ bool MWAWInputStream::unMacMIME(MWAWInputStream *inp,
return false;
}
if (wh==1)
- dataInput.reset(new librevenge::RVNGStringStream(data, (unsigned int)numBytesRead));
+ dataInput.reset(new MWAWStringStream(data, (unsigned int)numBytesRead));
else if (wh==2)
- rsrcInput.reset(new librevenge::RVNGStringStream(data, (unsigned int)numBytesRead));
+ rsrcInput.reset(new MWAWStringStream(data, (unsigned int)numBytesRead));
else { // the finder info
if (entrySize < 8) {
MWAW_DEBUG_MSG(("MWAWInputStream::unMacMIME: finder info size is odd\n"));
--
1.9.0

@ -1,52 +0,0 @@
From cde8d7c47cdea327f8153ab72cde650f1b36f7f8 Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Sun, 3 Nov 2013 12:59:29 +0100
Subject: [PATCH 2/8] use correct type
---
src/lib/HMWJGraph.cxx | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/lib/HMWJGraph.cxx b/src/lib/HMWJGraph.cxx
index fca366c..dd83ace 100644
--- a/src/lib/HMWJGraph.cxx
+++ b/src/lib/HMWJGraph.cxx
@@ -2668,7 +2668,7 @@ bool HMWJGraph::sendGroup(HMWJGraphInternal::Group const &group, MWAWPosition po
return true;
}
- std::multimap<long, int>::const_iterator fIt;
+ std::map<long, int>::const_iterator fIt;
int numFrames = int(m_state->m_framesList.size());
for (size_t c=0; c<group.m_childsList.size(); ++c) {
long fId=group.m_childsList[c];
@@ -2690,7 +2690,7 @@ bool HMWJGraph::sendGroup(HMWJGraphInternal::Group const &group, MWAWPosition po
bool HMWJGraph::canCreateGraphic(HMWJGraphInternal::Group const &group)
{
- std::multimap<long, int>::const_iterator fIt;
+ std::map<long, int>::const_iterator fIt;
int page = group.m_page;
int numFrames = int(m_state->m_framesList.size());
for (size_t c=0; c<group.m_childsList.size(); ++c) {
@@ -2726,7 +2726,7 @@ void HMWJGraph::sendGroup(HMWJGraphInternal::Group const &group, MWAWGraphicList
if (!listener) return;
group.m_parsed=true;
MWAWInputStreamPtr &input= m_parserState->m_input;
- std::multimap<long, int>::const_iterator fIt;
+ std::map<long, int>::const_iterator fIt;
int numFrames = int(m_state->m_framesList.size());
for (size_t c=0; c<group.m_childsList.size(); ++c) {
long fId=group.m_childsList[c];
@@ -2784,7 +2784,7 @@ void HMWJGraph::sendGroupChild(HMWJGraphInternal::Group const &group, MWAWPositi
Box2f partialBdBox;
MWAWPosition partialPos(pos);
MWAWInputStreamPtr &input= m_parserState->m_input;
- std::multimap<long, int>::const_iterator fIt;
+ std::map<long, int>::const_iterator fIt;
int numFrames = int(m_state->m_framesList.size());
for (size_t c=0; c<numChilds; ++c) {
long fId=group.m_childsList[c];
--
1.9.0

@ -1,619 +0,0 @@
From ad5f5d5c5feaac3c1351609c79aaa7d2802d5a55 Mon Sep 17 00:00:00 2001
From: osnola <alonso@loria.fr>
Date: Mon, 4 Nov 2013 18:35:36 +0100
Subject: [PATCH 3/8] Correct some cppcheck errors + change code to avoid
calling isfinite...
---
configure.ac | 10 -------
src/conv/csv/mwaw2csv.cpp | 2 +-
src/conv/raw/mwaw2raw.cpp | 2 +-
src/conv/text/mwaw2text.cpp | 2 +-
src/lib/CWDbaseContent.cxx | 19 +++++++------
src/lib/CWDbaseContent.hxx | 6 ++--
src/lib/CWGraph.cxx | 30 ++++++++++----------
src/lib/CWGraph.hxx | 2 +-
src/lib/HMWKGraph.cxx | 12 ++++----
src/lib/MSKGraph.cxx | 2 +-
src/lib/MSKGraph.hxx | 2 +-
src/lib/MSKParser.cxx | 18 ++----------
src/lib/MSKParser.hxx | 2 --
src/lib/MSWTextStyles.cxx | 2 +-
src/lib/MWAWDocument.cxx | 6 ++--
src/lib/MWAWInputStream.cxx | 4 ++-
src/lib/MWAWInputStream.hxx | 2 +-
src/lib/MWAWOLEParser.cxx | 2 +-
src/lib/MWAWOLEStream.cxx | 2 +-
src/lib/MWAWPropertyHandler.cxx | 63 +++++++++++++++++++++--------------------
20 files changed, 84 insertions(+), 106 deletions(-)
diff --git a/src/conv/csv/mwaw2csv.cpp b/src/conv/csv/mwaw2csv.cpp
index 0937a46..ed3799d 100644
--- a/src/conv/csv/mwaw2csv.cpp
+++ b/src/conv/csv/mwaw2csv.cpp
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
CSVGenerator documentGenerator(output);
error = MWAWDocument::parse(&input, &documentGenerator);
}
- catch(MWAWDocument::Result err)
+ catch(MWAWDocument::Result const &err)
{
error=err;
}
diff --git a/src/conv/raw/mwaw2raw.cpp b/src/conv/raw/mwaw2raw.cpp
index 5e365f1..8e6a92c 100644
--- a/src/conv/raw/mwaw2raw.cpp
+++ b/src/conv/raw/mwaw2raw.cpp
@@ -90,7 +90,7 @@ int main(int argc, char *argv[])
{
error=MWAWDocument::parse(&input, &documentGenerator);
}
- catch (MWAWDocument::Result err)
+ catch (MWAWDocument::Result const &err)
{
error=err;
}
diff --git a/src/conv/text/mwaw2text.cpp b/src/conv/text/mwaw2text.cpp
index edb980d..2b561bf 100644
--- a/src/conv/text/mwaw2text.cpp
+++ b/src/conv/text/mwaw2text.cpp
@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
{
MWAWDocument::parse(&input, &documentGenerator);
}
- catch (MWAWDocument::Result err)
+ catch (MWAWDocument::Result const &err)
{
error=err;
}
diff --git a/src/lib/CWDbaseContent.cxx b/src/lib/CWDbaseContent.cxx
index 7198103..2c2d971 100644
--- a/src/lib/CWDbaseContent.cxx
+++ b/src/lib/CWDbaseContent.cxx
@@ -518,7 +518,7 @@ bool CWDbaseContent::readRecordSSV1(Vec2i const &id, long pos, CWDbaseContent::R
break;
}
record.m_resType=Record::R_Double;
- if (input->readDouble(record.m_resDouble))
+ if (input->readDouble(record.m_resDouble, record.m_resDoubleNaN))
f << record.m_resDouble << ",";
else {
MWAW_DEBUG_MSG(("CWDbaseContent::readRecordSSV1: can not read a float\n"));
@@ -572,7 +572,7 @@ bool CWDbaseContent::readRecordSSV1(Vec2i const &id, long pos, CWDbaseContent::R
f << "###int" << rType << "[res],";
break;
case 2:
- if (input->checkPosition(resPos+10) && input->readDouble(record.m_resDouble)) {
+ if (input->checkPosition(resPos+10) && input->readDouble(record.m_resDouble, record.m_resDoubleNaN)) {
record.m_resType=Record::R_Double;
f << "=" << record.m_resDouble << ",";
break;
@@ -674,7 +674,7 @@ bool CWDbaseContent::readRecordSS(Vec2i const &id, long pos, CWDbaseContent::Rec
break;
}
record.m_resType=Record::R_Double;
- if (input->readDouble(record.m_resDouble))
+ if (input->readDouble(record.m_resDouble, record.m_resDoubleNaN))
f << record.m_resDouble << ",";
else {
MWAW_DEBUG_MSG(("CWDbaseContent::readRecordSS: can not read a float\n"));
@@ -736,7 +736,7 @@ bool CWDbaseContent::readRecordSS(Vec2i const &id, long pos, CWDbaseContent::Rec
f << "###int" << rType << "[res],";
break;
case 2:
- if (remainSz>=10 && input->readDouble(record.m_resDouble)) {
+ if (remainSz>=10 && input->readDouble(record.m_resDouble, record.m_resDoubleNaN)) {
record.m_resType=Record::R_Double;
f << "=" << record.m_resDouble << ",";
break;
@@ -858,7 +858,7 @@ bool CWDbaseContent::readRecordDB(Vec2i const &id, long pos, CWDbaseContent::Rec
f << "###";
break;
}
- if (input->readDouble(record.m_resDouble)) {
+ if (input->readDouble(record.m_resDouble, record.m_resDoubleNaN)) {
record.m_resType=Record::R_Double;
f << record.m_resDouble << ",";
} else {
@@ -929,7 +929,7 @@ bool CWDbaseContent::send(Vec2i const &pos)
switch(record.m_resType) {
case Record::R_Long:
if (format.m_format)
- send(double(record.m_resLong), format);
+ send(double(record.m_resLong), false, format);
else {
std::stringstream s;
s << record.m_resLong;
@@ -937,7 +937,7 @@ bool CWDbaseContent::send(Vec2i const &pos)
}
break;
case Record::R_Double:
- send(record.m_resDouble, format);
+ send(record.m_resDouble, record.m_resDoubleNaN, format);
break;
case Record::R_String:
if (record.m_resString.valid()) {
@@ -959,7 +959,7 @@ bool CWDbaseContent::send(Vec2i const &pos)
return true;
}
-void CWDbaseContent::send(double val, CWStyleManager::CellFormat const &format)
+void CWDbaseContent::send(double val, bool isNotANumber, CWStyleManager::CellFormat const &format)
{
MWAWContentListenerPtr listener=m_parserState->m_listener;
if (!listener)
@@ -970,7 +970,8 @@ void CWDbaseContent::send(double val, CWStyleManager::CellFormat const &format)
if (type>=10&&type<=11) type += 4;
else if (type>=14) type=16;
}
- if (type <= 0 || type >=16 || type==10 || type==11 || !boost::math::isfinite(val)) {
+ // note: if val*0!=0, val is a NaN so better so simply print NaN
+ if (type <= 0 || type >=16 || type==10 || type==11 || isNotANumber) {
s << val;
listener->insertUnicodeString(s.str().c_str());
return;
diff --git a/src/lib/CWDbaseContent.hxx b/src/lib/CWDbaseContent.hxx
index 36596e9..04177fe 100644
--- a/src/lib/CWDbaseContent.hxx
+++ b/src/lib/CWDbaseContent.hxx
@@ -78,7 +78,7 @@ protected:
//! different result type
enum Type { R_Unknown, R_Long, R_Double, R_String };
//! contructor
- Record() : m_style(-1), m_resType(R_Unknown), m_resLong(0), m_resDouble(0), m_resString(), m_format(0), m_font(3,9), m_justify(0), m_borders(0) {
+ Record() : m_style(-1), m_resType(R_Unknown), m_resLong(0), m_resDouble(0), m_resDoubleNaN(false), m_resString(), m_format(0), m_font(3,9), m_justify(0), m_borders(0) {
}
//! the style if known
@@ -89,6 +89,8 @@ protected:
long m_resLong;
//! the result id double
double m_resDouble;
+ //! a flag to know if a double result is nan or not
+ bool m_resDoubleNaN;
//! the result entry if string
MWAWEntry m_resString;
//! the format ( in a v1-3 spreadsheet)
@@ -123,7 +125,7 @@ protected:
bool readRecordDB(Vec2i const &where, long pos, Record &record);
//! send a double with a corresponding cell format
- void send(double val, CWStyleManager::CellFormat const &format);
+ void send(double val, bool isNotaNumber, CWStyleManager::CellFormat const &format);
//! the file version
int m_version;
diff --git a/src/lib/CWGraph.cxx b/src/lib/CWGraph.cxx
index 6f34628..01109f6 100644
--- a/src/lib/CWGraph.cxx
+++ b/src/lib/CWGraph.cxx
@@ -311,7 +311,7 @@ struct ZonePict : public Zone {
struct Bitmap : public CWStruct::DSET {
//! constructor
Bitmap(CWStruct::DSET const &dset = CWStruct::DSET()) :
- DSET(dset), m_bitmapType(-1), m_size(0,0), m_entry(), m_colorMap() {
+ DSET(dset), m_bitmapType(-1), m_bitmapSize(0,0), m_entry(), m_colorMap() {
}
//! operator<<
@@ -324,7 +324,7 @@ struct Bitmap : public CWStruct::DSET {
//! the bitmap type
int m_bitmapType;
//! the bitmap size
- Vec2i m_size;
+ Vec2i m_bitmapSize;
//! the bitmap entry
MWAWEntry m_entry;
//! the color map
@@ -666,7 +666,7 @@ void CWGraph::askToSend(int number, bool asGraphic, MWAWPosition const& pos)
////////////////////////////////////////////////////////////
// Intermediate level
////////////////////////////////////////////////////////////
-bool CWGraph::getSurfaceColor(CWGraphInternal::Style const style, MWAWColor &col) const
+bool CWGraph::getSurfaceColor(CWGraphInternal::Style const &style, MWAWColor &col) const
{
if (!style.hasSurfaceColor())
return false;
@@ -814,7 +814,7 @@ shared_ptr<CWStruct::DSET> CWGraph::readBitmapZone
dim[j] = (int) input->readLong(2);
f << "sz=" << dim[1] << "x" << dim[0] << ",";
if (dim[0] > 0 && dim[1] > 0) {
- bitmap->m_size = Vec2i(dim[1]+2, dim[0]+2);
+ bitmap->m_bitmapSize = Vec2i(dim[1]+2, dim[0]+2);
sizeSet = true;
}
ascFile.addDelimiter(input->tell(),']');
@@ -852,7 +852,7 @@ shared_ptr<CWStruct::DSET> CWGraph::readBitmapZone
for (int j = 0; j < 2; j++)
dim[j] = (int) input->readLong(2);
if (i == N-1 && !sizeSet)
- bitmap->m_size = Vec2i(dim[0]+2, dim[1]+2);
+ bitmap->m_bitmapSize = Vec2i(dim[0]+2, dim[1]+2);
f << "dim?=" << dim[0] << "x" << dim[1] << ",";
for (int j = 3; j < 6; j++) {
@@ -1993,18 +1993,18 @@ bool CWGraph::readBitmapData(CWGraphInternal::Bitmap &zone)
return false;
}
/* Fixme: this code can not works for the packed bitmap*/
- long numColors = zone.m_size[0]*zone.m_size[1];
+ long numColors = zone.m_bitmapSize[0]*zone.m_bitmapSize[1];
int numBytes = numColors ? int(sz/numColors) : 0;
if (sz != numBytes*numColors) {
// check for different row alignement: 2 and 4
for (int align=2; align <= 4; align*=2) {
- int diffToAlign=align-(zone.m_size[0]%align);
+ int diffToAlign=align-(zone.m_bitmapSize[0]%align);
if (diffToAlign==align) continue;
- numColors = (zone.m_size[0]+diffToAlign)*zone.m_size[1];
+ numColors = (zone.m_bitmapSize[0]+diffToAlign)*zone.m_bitmapSize[1];
numBytes = numColors ? int(sz/numColors) : 0;
if (sz == numBytes*numColors) {
- zone.m_size[0]+=diffToAlign;
- MWAW_DEBUG_MSG(("CWGraph::readBitmapData: increase width to %d\n",zone.m_size[0]));
+ zone.m_bitmapSize[0]+=diffToAlign;
+ MWAW_DEBUG_MSG(("CWGraph::readBitmapData: increase width to %d\n",zone.m_bitmapSize[0]));
break;
}
}
@@ -2048,7 +2048,7 @@ void CWGraph::checkNumberAccrossPages(CWGraphInternal::Group &group) const
void CWGraph::updateInformation(CWGraphInternal::Group &group) const
{
- if (group.m_blockToSendList.size() || group.m_idLinkedZonesMap.size())
+ if (!group.m_blockToSendList.empty() || !group.m_idLinkedZonesMap.empty())
return;
std::set<int> forbiddenZone;
@@ -2633,19 +2633,19 @@ bool CWGraph::sendBitmap(CWGraphInternal::Bitmap &bitmap, bool asGraphic, MWAWPo
MWAWPictBitmapColor *bmapColor = 0;
bool indexed = false;
if (numColors > 2) {
- bmapIndexed = new MWAWPictBitmapIndexed(bitmap.m_size);
+ bmapIndexed = new MWAWPictBitmapIndexed(bitmap.m_bitmapSize);
bmapIndexed->setColors(bitmap.m_colorMap);
bmap.reset(bmapIndexed);
indexed = true;
} else
- bmap.reset((bmapColor=new MWAWPictBitmapColor(bitmap.m_size)));
+ bmap.reset((bmapColor=new MWAWPictBitmapColor(bitmap.m_bitmapSize)));
//! let go
int fSz = bitmap.m_bitmapType;
MWAWInputStreamPtr &input= m_parserState->m_input;
input->seek(bitmap.m_entry.begin(), WPX_SEEK_SET);
- for (int r = 0; r < bitmap.m_size[1]; r++) {
- for (int c = 0; c < bitmap.m_size[0]; c++) {
+ for (int r = 0; r < bitmap.m_bitmapSize[1]; r++) {
+ for (int c = 0; c < bitmap.m_bitmapSize[0]; c++) {
long val = (long) input->readULong(fSz);
if (indexed) {
bmapIndexed->set(c,r,(int)val);
diff --git a/src/lib/CWGraph.hxx b/src/lib/CWGraph.hxx
index 0655464..bdb2bd5 100644
--- a/src/lib/CWGraph.hxx
+++ b/src/lib/CWGraph.hxx
@@ -98,7 +98,7 @@ public:
(CWStruct::DSET const &zone, MWAWEntry const &entry, bool &complete);
//! return the surface color which corresponds to some ids (if possible)
- bool getSurfaceColor(CWGraphInternal::Style const style, MWAWColor &col) const;
+ bool getSurfaceColor(CWGraphInternal::Style const &style, MWAWColor &col) const;
protected:
//! set the slide list ( for presentation )
void setSlideList(std::vector<int> const &slideList);
diff --git a/src/lib/HMWKGraph.cxx b/src/lib/HMWKGraph.cxx
index 2ad56d2..ab8b904 100644
--- a/src/lib/HMWKGraph.cxx
+++ b/src/lib/HMWKGraph.cxx
@@ -292,7 +292,7 @@ std::string Group::print() const
//! Internal: the picture of a HMWKGraph
struct PictureFrame : public Frame {
//! constructor
- PictureFrame(Frame const &orig) : Frame(orig), m_type(0), m_dim(0,0), m_borderDim(0,0) {
+ PictureFrame(Frame const &orig) : Frame(orig), m_pictureType(0), m_dim(0,0), m_borderDim(0,0) {
for (int i = 0; i < 7; ++i) m_values[i] = 0;
}
//! destructor
@@ -307,7 +307,7 @@ struct PictureFrame : public Frame {
//! print local data
std::string print() const {
std::stringstream s;
- if (m_type) s << "type?=" << m_type << ",";
+ if (m_pictureType) s << "type?=" << m_pictureType << ",";
if (m_dim[0] || m_dim[1])
s << "dim?=" << m_dim << ",";
if (m_borderDim[0] > 0 || m_borderDim[1] > 0)
@@ -319,7 +319,7 @@ struct PictureFrame : public Frame {
}
//! a type
- int m_type;
+ int m_pictureType;
//! a dim?
Vec2i m_dim;
//! the border dim?
@@ -422,7 +422,7 @@ private:
//! Internal: the textbox of a HMWKGraph
struct TextBox : public Frame {
//! constructor
- TextBox(Frame const &orig, bool isComment) : Frame(orig), m_commentBox(isComment), m_textFileId(-1), m_linkedIdList(), m_isLinked(false), m_extra("") {
+ TextBox(Frame const &orig, bool isComment) : Frame(orig), m_commentBox(isComment), m_textFileId(-1), m_linkedIdList(), m_isLinked(false) {
for (int i = 0; i < 2; ++i) m_dim[i] = 0;
}
//! destructor
@@ -517,8 +517,6 @@ struct TextBox : public Frame {
std::vector<long> m_linkedIdList;
//! a flag to know if this textbox is linked to a previous box
bool m_isLinked;
- //! extra data
- std::string m_extra;
};
bool TableCell::sendContent(MWAWContentListenerPtr, MWAWTable &table)
@@ -1603,7 +1601,7 @@ shared_ptr<HMWKGraphInternal::PictureFrame> HMWKGraph::readPictureFrame(shared_p
picture.reset(new HMWKGraphInternal::PictureFrame(header));
libmwaw::DebugFile &asciiFile = zone->ascii();
libmwaw::DebugStream f;
- picture->m_type = (int) input->readLong(2); // 0 or 4 : or maybe wrapping
+ picture->m_pictureType = (int) input->readLong(2); // 0 or 4 : or maybe wrapping
for (int i = 0; i < 5; ++i) // always 0
picture->m_values[i] = (int) input->readLong(2);
float bDim[2];
diff --git a/src/lib/MSKGraph.cxx b/src/lib/MSKGraph.cxx
index fa876a1..dd873c1 100644
--- a/src/lib/MSKGraph.cxx
+++ b/src/lib/MSKGraph.cxx
@@ -2729,7 +2729,7 @@ void MSKGraph::sendAll(int zoneId, bool mainZone)
}
}
-void MSKGraph::sendObjects(MSKGraph::SendData what)
+void MSKGraph::sendObjects(MSKGraph::SendData const &what)
{
MWAWContentListenerPtr listener=m_parserState->m_listener;
if (!listener) {
diff --git a/src/lib/MSKGraph.hxx b/src/lib/MSKGraph.hxx
index 29ee53a..f9518e4 100644
--- a/src/lib/MSKGraph.hxx
+++ b/src/lib/MSKGraph.hxx
@@ -110,7 +110,7 @@ public:
Vec2i m_size;
};
/** sends all the object of a page, frame, ... */
- void sendObjects(SendData const what);
+ void sendObjects(SendData const &what);
/** try to update positions knowing pages and lines height */
void computePositions(int zoneId, std::vector<int> &linesHeight, std::vector<int> &pagesHeight);
diff --git a/src/lib/MSKParser.cxx b/src/lib/MSKParser.cxx
index 16b7d84..c527e90 100644
--- a/src/lib/MSKParser.cxx
+++ b/src/lib/MSKParser.cxx
@@ -36,27 +36,13 @@
#include "MSKParser.hxx"
-/** Internal: the structures of a MSKParser */
-namespace MSKParserInternal
-{
-////////////////////////////////////////
-//! Internal: the state of a MSK3Parser
-struct State {
- //! constructor
- State() {
- }
-};
-}
-
MSKParser::MSKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header) :
- MWAWParser(input, rsrcParser, header), m_state(new MSKParserInternal::State),
- m_input(input), m_asciiFile(input)
+ MWAWParser(input, rsrcParser, header), m_input(input), m_asciiFile(input)
{
}
MSKParser::MSKParser(MWAWInputStreamPtr input, MWAWParserStatePtr parserState) :
- MWAWParser(parserState), m_state(new MSKParserInternal::State),
- m_input(input), m_asciiFile(input)
+ MWAWParser(parserState), m_input(input), m_asciiFile(input)
{
}
diff --git a/src/lib/MSKParser.hxx b/src/lib/MSKParser.hxx
index eb29d1b..88244b9 100644
--- a/src/lib/MSKParser.hxx
+++ b/src/lib/MSKParser.hxx
@@ -94,8 +94,6 @@ public:
return m_asciiFile;
}
protected:
- //! the state
- shared_ptr<MSKParserInternal::State> m_state;
//! the input which can be an OLE in MSWorks 4 file
MWAWInputStreamPtr m_input;
//! the debug file of the actual input
diff --git a/src/lib/MSWTextStyles.cxx b/src/lib/MSWTextStyles.cxx
index 93a6e62..2bba921 100644
--- a/src/lib/MSWTextStyles.cxx
+++ b/src/lib/MSWTextStyles.cxx
@@ -386,6 +386,7 @@ bool MSWTextStyles::readParagraph(MSWStruct::Paragraph &para, int dataSz)
int const vers = version();
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
libmwaw::DebugStream f;
+ int numFont=0;
while (long(input->tell()) < endPos) {
long actPos = input->tell();
/* 5-16: basic paragraph properties
@@ -403,7 +404,6 @@ bool MSWTextStyles::readParagraph(MSWStruct::Paragraph &para, int dataSz)
}
bool done = false;
long dSz = endPos-actPos;
- int numFont=0;
switch(wh) {
case 0:
done = (actPos+1==endPos||(dataSz==2 && actPos+2==endPos));
diff --git a/src/lib/MWAWDocument.cxx b/src/lib/MWAWDocument.cxx
index ef9d280..182de89 100644
--- a/src/lib/MWAWDocument.cxx
+++ b/src/lib/MWAWDocument.cxx
@@ -522,9 +522,9 @@ void GraphicExporter::endElement(const char *psName)
m_output->endTextObject();
#ifdef DEBUG
else if (strcmp(psName, "SetStyle") && strcmp(psName, "Rectangle") &&
- strcmp(psName, "Rectangle") && strcmp(psName, "Ellipse") &&
- strcmp(psName, "Polygon") && strcmp(psName, "Polyline") &&
- strcmp(psName, "Path") && strcmp(psName, "GraphicObject")) {
+ strcmp(psName, "Ellipse") && strcmp(psName, "Polygon") &&
+ strcmp(psName, "Polyline") && strcmp(psName, "Path") &&
+ strcmp(psName, "GraphicObject")) {
MWAW_DEBUG_MSG(("GraphicExporter::endElement: called with unexpected name %s\n", psName));
}
#endif
diff --git a/src/lib/MWAWInputStream.cxx b/src/lib/MWAWInputStream.cxx
index c4dc2b6..9b2e28c 100644
--- a/src/lib/MWAWInputStream.cxx
+++ b/src/lib/MWAWInputStream.cxx
@@ -229,7 +229,7 @@ uint8_t MWAWInputStream::readU8(WPXInputStream *stream)
return *(uint8_t const *)(p);
}
-bool MWAWInputStream::readDouble(double &res)
+bool MWAWInputStream::readDouble(double &res, bool &isNotANumber)
{
if (!m_stream) return false;
long pos=tell();
@@ -244,6 +244,7 @@ bool MWAWInputStream::readDouble(double &res)
}
exp -= 0x3fff;
+ isNotANumber=false;
unsigned long mantisse = (unsigned long) readULong(4);
if ((mantisse & 0x80000000) == 0) {
if (readULong(4) != 0) return false;
@@ -251,6 +252,7 @@ bool MWAWInputStream::readDouble(double &res)
if (exp == -0x3fff && mantisse == 0) return true; // ok zero
if (exp == 0x4000 && (mantisse & 0xFFFFFFL)==0) { // ok Nan
res=std::numeric_limits<double>::quiet_NaN();
+ isNotANumber = true;
return true;
}
return false;
diff --git a/src/lib/MWAWInputStream.hxx b/src/lib/MWAWInputStream.hxx
index 818451a..bc29165 100644
--- a/src/lib/MWAWInputStream.hxx
+++ b/src/lib/MWAWInputStream.hxx
@@ -139,7 +139,7 @@ public:
//! return a int8, int16, int32 readed from actualPos
long readLong(int num);
//! try to read a double (ppc)
- bool readDouble(double &res);
+ bool readDouble(double &res, bool &isNotANumber);
/**! reads numbytes data, WITHOUT using any endian or section consideration
* \return a pointer to the read elements
diff --git a/src/lib/MWAWOLEParser.cxx b/src/lib/MWAWOLEParser.cxx
index a14aee1..70d6dd6 100644
--- a/src/lib/MWAWOLEParser.cxx
+++ b/src/lib/MWAWOLEParser.cxx
@@ -622,7 +622,7 @@ bool MWAWOLEParser::readCompObj(MWAWInputStreamPtr ip, std::string const &oleNam
if (clsName)
f << "'" << clsName << "'";
else {
- MWAW_DEBUG_MSG(("MWAWOLEParser::readCompObj: unknown clsid=%ld\n", clsData[0]));
+ MWAW_DEBUG_MSG(("MWAWOLEParser::readCompObj: unknown clsid=%ld\n", (long) clsData[0]));
f << "unknCLSID='" << std::hex << clsData[0] << "'";
}
} else {
diff --git a/src/lib/MWAWOLEStream.cxx b/src/lib/MWAWOLEStream.cxx
index 6ffebea..9abdd90 100644
--- a/src/lib/MWAWOLEStream.cxx
+++ b/src/lib/MWAWOLEStream.cxx
@@ -454,7 +454,7 @@ void DirEntry::load( unsigned char *buffer, unsigned len )
m_name="R";
m_macRootEntry=true;
} else {
- for( unsigned j=0; ( buffer[j]) && (j<name_len); j+= 2 )
+ for( unsigned j=0; j<name_len && buffer[j]; j+= 2 )
m_name.append( 1, char(buffer[j]) );
}
diff --git a/src/lib/MWAWPropertyHandler.cxx b/src/lib/MWAWPropertyHandler.cxx
index a81f5fe..e4737f4 100644
--- a/src/lib/MWAWPropertyHandler.cxx
+++ b/src/lib/MWAWPropertyHandler.cxx
@@ -410,39 +410,40 @@ protected:
if (!readString(input, key)) return false;
if (!readString(input, val)) return false;
- // check if the val can be a double, ...
- if (!val.empty() && (val[0]=='-' || val[0]=='.' || (val[0]>='0' && val[0]<='9'))) {
- std::istringstream iss(val);
- double res = 0.0;
- iss >> res;
- if (!iss.fail()) {
- if (iss.eof() || iss.peek() == std::char_traits<char>::eof()) {
- list.insert(key.c_str(), res);
- return true;
- }
- std::string remain;
- iss >> remain;
- if (iss.peek() == std::char_traits<char>::eof()) {
- if (remain=="pt") {
- list.insert(key.c_str(), res/72., WPX_INCH);
- return true;
- }
- if (remain=="in") {
- list.insert(key.c_str(), res, WPX_INCH);
- return true;
- }
- if (remain=="%") {
- list.insert(key.c_str(), res/100., WPX_PERCENT);
- return true;
- }
- if (remain=="*") {
- list.insert(key.c_str(), res/1440., WPX_INCH);
- return true;
- }
- }
+ std::string number(""), remain("");
+ // check if the val can be a double, first isolate the potential numbering part ...
+ for (size_t s=0; s<val.size(); ++s) {
+ char c=(char) val[s];
+ if (c=='-' || c=='.' || c=='e' || c=='E' || (c>='0' && c<='9')) {
+ number+=c;
+ continue;
}
+ remain=val.substr(s);
+ break;
+ }
+ if (number.empty()) {
+ list.insert(key.c_str(), val.c_str());
+ return true;
+ }
+ std::istringstream iss(number);
+ double res = 0.0;
+ iss >> res;
+ if (iss.fail() || iss.peek()!=std::char_traits<char>::eof()) {
+ list.insert(key.c_str(), val.c_str());
+ return true;
}
- list.insert(key.c_str(), val.c_str());
+ if (remain.empty())
+ list.insert(key.c_str(), res);
+ else if (remain=="pt")
+ list.insert(key.c_str(), res/72., WPX_INCH);
+ else if (remain=="in")
+ list.insert(key.c_str(), res, WPX_INCH);
+ else if (remain=="%")
+ list.insert(key.c_str(), res/100., WPX_PERCENT);
+ else if (remain=="*")
+ list.insert(key.c_str(), res/1440., WPX_INCH);
+ else
+ list.insert(key.c_str(), val.c_str());
return true;
}
--
1.9.0

@ -1,29 +0,0 @@
From d1dc868e2530d3301b401e45662392a173de1557 Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Wed, 20 Nov 2013 09:03:23 +0100
Subject: [PATCH 4/8] avoid leak
(cherry picked from commit 454a6ce3062da9d273978868088bf07b68cd9fa2)
Signed-off-by: osnola <alonso@loria.fr>
---
src/lib/MSKGraph.cxx | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/lib/MSKGraph.cxx b/src/lib/MSKGraph.cxx
index dd873c1..7c1a9f6 100644
--- a/src/lib/MSKGraph.cxx
+++ b/src/lib/MSKGraph.cxx
@@ -1550,7 +1550,10 @@ int MSKGraph::getEntryPicture(int zoneId, MWAWEntry &zone, bool autoSend, int or
MSKGraphInternal::Chart *chart = new MSKGraphInternal::Chart(pict);
int chartId = m_state->m_chartId++;
if (!m_tableParser->readChart(chartId, chart->m_style))
+ {
+ delete chart;
return -1;
+ }
m_tableParser->setChartZoneId(chartId, int(m_state->m_zonesList.size()));
chart->m_chartId = chartId;
res.reset(chart);
--
1.9.0

@ -1,183 +0,0 @@
From b814213e898e9f394fac3dc07102baae1aba5304 Mon Sep 17 00:00:00 2001
From: osnola <alonso@loria.fr>
Date: Sun, 1 Dec 2013 09:38:52 +0100
Subject: [PATCH 5/8] ClarisWorks parser: try to reconstruct compressed bitmap
...
(cherry picked from commit ecbabfcc912700602abba3c56543845d1cd243a8)
Signed-off-by: osnola <alonso@loria.fr>
Conflicts:
src/lib/CWGraph.cxx
---
src/lib/CWGraph.cxx | 89 ++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 67 insertions(+), 22 deletions(-)
diff --git a/src/lib/CWGraph.cxx b/src/lib/CWGraph.cxx
index 01109f6..52f2a5c 100644
--- a/src/lib/CWGraph.cxx
+++ b/src/lib/CWGraph.cxx
@@ -311,20 +311,24 @@ struct ZonePict : public Zone {
struct Bitmap : public CWStruct::DSET {
//! constructor
Bitmap(CWStruct::DSET const &dset = CWStruct::DSET()) :
- DSET(dset), m_bitmapType(-1), m_bitmapSize(0,0), m_entry(), m_colorMap() {
+ DSET(dset), m_numBytesPerPixel(0), m_bitmapSize(0,0), m_bitmapRowSize(0), m_entry(), m_colorMap()
+ {
}
//! operator<<
friend std::ostream &operator<<(std::ostream &o, Bitmap const &bt) {
o << static_cast<CWStruct::DSET const &>(bt);
- if (bt.m_bitmapType >= 0) o << "type=" << bt.m_bitmapType << ",";
+ if (bt.m_numBytesPerPixel > 0) o << "type=" << bt.m_numBytesPerPixel << ",";
+ else if (bt.m_numBytesPerPixel < 0) o << "type=1/" << (-bt.m_numBytesPerPixel) << ",";
return o;
}
- //! the bitmap type
- int m_bitmapType;
+ //! the number of bite by pixel
+ int m_numBytesPerPixel;
//! the bitmap size
Vec2i m_bitmapSize;
+ //! the bitmap row size in the file ( with potential alignement)
+ int m_bitmapRowSize;
//! the bitmap entry
MWAWEntry m_entry;
//! the color map
@@ -1992,33 +1996,52 @@ bool CWGraph::readBitmapData(CWGraphInternal::Bitmap &zone)
MWAW_DEBUG_MSG(("CWGraph::readBitmapData: file is too short\n"));
return false;
}
- /* Fixme: this code can not works for the packed bitmap*/
- long numColors = zone.m_bitmapSize[0]*zone.m_bitmapSize[1];
- int numBytes = numColors ? int(sz/numColors) : 0;
- if (sz != numBytes*numColors) {
+
+ long numPixels = zone.m_bitmapSize[0]*zone.m_bitmapSize[1];
+ if (numPixels<=0) {
+ MWAW_DEBUG_MSG(("CWGraph::readBitmapData: unexpected empty size\n"));
+ return false;
+ }
+
+ int numBytesPerPixel = int(sz/numPixels);
+ int bitmapRowSize=zone.m_bitmapSize[0]*numBytesPerPixel;
+ if (sz < numPixels) {
+ int nHalfPixel=(zone.m_bitmapSize[0]+1)/2;
+ for (int align=1; align <= 4; align*=2) {
+ int diffToAlign=align==1 ? 0 : align-(nHalfPixel%align);
+ if (diffToAlign==align) continue;
+ if (sz == (nHalfPixel+diffToAlign)*zone.m_bitmapSize[1]) {
+ bitmapRowSize=(nHalfPixel+diffToAlign);
+ numBytesPerPixel=-2;
+ break;
+ }
+ }
+ }
+ else if (sz > numBytesPerPixel*numPixels) {
// check for different row alignement: 2 and 4
for (int align=2; align <= 4; align*=2) {
int diffToAlign=align-(zone.m_bitmapSize[0]%align);
if (diffToAlign==align) continue;
- numColors = (zone.m_bitmapSize[0]+diffToAlign)*zone.m_bitmapSize[1];
- numBytes = numColors ? int(sz/numColors) : 0;
- if (sz == numBytes*numColors) {
- zone.m_bitmapSize[0]+=diffToAlign;
- MWAW_DEBUG_MSG(("CWGraph::readBitmapData: increase width to %d\n",zone.m_bitmapSize[0]));
+ numPixels = (zone.m_bitmapSize[0]+diffToAlign)*zone.m_bitmapSize[1];
+ numBytesPerPixel = int(sz/numPixels);
+ if (sz == numBytesPerPixel*numPixels) {
+ bitmapRowSize=(zone.m_bitmapSize[0]+diffToAlign)*numBytesPerPixel;
break;
}
}
}
- if (sz != numBytes*numColors) {
+
+ if (sz != bitmapRowSize*zone.m_bitmapSize[1]) {
MWAW_DEBUG_MSG(("CWGraph::readBitmapData: unexpected size\n"));
return false;
}
- zone.m_bitmapType = numBytes;
+ zone.m_numBytesPerPixel = numBytesPerPixel;
+ zone.m_bitmapRowSize = bitmapRowSize;
zone.m_entry.setBegin(pos+4);
zone.m_entry.setEnd(endPos);
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
libmwaw::DebugStream f;
- f << "Entries(BitmapData):nBytes=" << numBytes;
+ f << "Entries(BitmapData):[" << numBytesPerPixel << "]";
ascFile.addPos(pos);
ascFile.addNote(f.str().c_str());
ascFile.skipZone(pos+4, endPos-1);
@@ -2615,9 +2638,13 @@ bool CWGraph::sendBitmap(int number, bool asGraphic, MWAWPosition const &pos)
bool CWGraph::sendBitmap(CWGraphInternal::Bitmap &bitmap, bool asGraphic, MWAWPosition pos)
{
- if (!bitmap.m_entry.valid() || !bitmap.m_bitmapType)
+ if (!bitmap.m_entry.valid() || !bitmap.m_numBytesPerPixel)
return false;
-
+ int bytesPerPixel = bitmap.m_numBytesPerPixel;
+ if (bytesPerPixel<0 && (bytesPerPixel!=-2 && bytesPerPixel!=-4)) {
+ MWAW_DEBUG_MSG(("CWGraph::sendBitmap: unknown group of color\n"));
+ return false;
+ }
if (asGraphic) {
if (!m_parserState->m_graphicListener ||
!m_parserState->m_graphicListener->isDocumentStarted()) {
@@ -2637,21 +2664,38 @@ bool CWGraph::sendBitmap(CWGraphInternal::Bitmap &bitmap, bool asGraphic, MWAWPo
bmapIndexed->setColors(bitmap.m_colorMap);
bmap.reset(bmapIndexed);
indexed = true;
- } else
+ }
+ else {
+ if (bytesPerPixel<0) {
+ MWAW_DEBUG_MSG(("CWGraph::sendBitmap: unexpected mode for compressed bitmap. Bitmap ignored.\n"));
+ return false;
+ }
bmap.reset((bmapColor=new MWAWPictBitmapColor(bitmap.m_bitmapSize)));
+ }
+ bool const isCompressed = bytesPerPixel<0;
+ int const numColorByData= isCompressed ? -bytesPerPixel : 1;
+ long const colorMask= !isCompressed ? 0 : numColorByData==2 ? 0xF : 0x3;
+ int const numColorBytes = isCompressed ? 8/numColorByData : 8*bytesPerPixel;
//! let go
- int fSz = bitmap.m_bitmapType;
MWAWInputStreamPtr &input= m_parserState->m_input;
input->seek(bitmap.m_entry.begin(), WPX_SEEK_SET);
for (int r = 0; r < bitmap.m_bitmapSize[1]; r++) {
+ long rPos=input->tell();
+ int numRead=0;
+ long read=0;
for (int c = 0; c < bitmap.m_bitmapSize[0]; c++) {
- long val = (long) input->readULong(fSz);
+ if (numRead==0) {
+ read=(long) input->readULong(isCompressed ? 1 : bytesPerPixel);
+ numRead=numColorByData;
+ }
+ --numRead;
+ long val=!isCompressed ? read : (read>>(numColorBytes*numRead))&colorMask;
if (indexed) {
bmapIndexed->set(c,r,(int)val);
continue;
}
- switch(fSz) {
+ switch (bytesPerPixel) {
case 1:
bmapColor->set(c,r, MWAWColor((unsigned char)val,(unsigned char)val,(unsigned char)val));
break;
@@ -2671,6 +2715,7 @@ bool CWGraph::sendBitmap(CWGraphInternal::Bitmap &bitmap, bool asGraphic, MWAWPo
}
}
}
+ input->seek(rPos+bitmap.m_bitmapRowSize, WPX_SEEK_SET);
}
WPXBinaryData data;
--
1.9.0

@ -1,34 +0,0 @@
From 018676e577356f7cd933680c1caf710f15a54c8d Mon Sep 17 00:00:00 2001
From: osnola <alonso@loria.fr>
Date: Tue, 4 Feb 2014 19:27:53 +0100
Subject: [PATCH 6/8] ClarisWorks parser: use the page size to define the
bitmap final size when converting a paint document...
---
src/lib/CWGraph.cxx | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/lib/CWGraph.cxx b/src/lib/CWGraph.cxx
index 52f2a5c..8a6e946 100644
--- a/src/lib/CWGraph.cxx
+++ b/src/lib/CWGraph.cxx
@@ -2722,8 +2722,14 @@ bool CWGraph::sendBitmap(CWGraphInternal::Bitmap &bitmap, bool asGraphic, MWAWPo
std::string type;
if (!bmap->getBinary(data,type)) return false;
if (pos.size()[0] <= 0 || pos.size()[1] <= 0) {
- MWAW_DEBUG_MSG(("CWGraph::sendBitmap: can not find bitmap size\n"));
- pos.setSize(Vec2f(0,0));
+ if (m_mainParser->getHeader() &&
+ m_mainParser->getHeader()->getKind()==MWAWDocument::MWAW_K_PAINT) // fixme
+ pos.setSize(Vec2f(0.9f*float(m_mainParser->getPageWidth()),
+ 0.9f*float(m_mainParser->getPageLength())));
+ else {
+ MWAW_DEBUG_MSG(("CWGraph::sendBitmap: can not find bitmap size\n"));
+ pos.setSize(Vec2f(0,0));
+ }
}
if (asGraphic) {
MWAWGraphicStyle style;
--
1.9.0

@ -1,99 +0,0 @@
From 0b8b5c98904ea0d0f337e897cca32ca7b088b646 Mon Sep 17 00:00:00 2001
From: osnola <alonso@loria.fr>
Date: Sun, 16 Feb 2014 11:36:32 +0100
Subject: [PATCH 7/8] MacWrite/MacWrite II parser: try to accept more files,
ie. files with "odd" PrintInfo...
---
src/lib/MWParser.cxx | 15 +++++++++------
src/lib/MWProParser.cxx | 14 +++++++++++---
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/src/lib/MWParser.cxx b/src/lib/MWParser.cxx
index fd0b60a..c422406 100644
--- a/src/lib/MWParser.cxx
+++ b/src/lib/MWParser.cxx
@@ -736,7 +736,7 @@ bool MWParser::checkHeader(MWAWHeader *header, bool /*strict*/)
f << "FileHeader: vers=" << vers << ",";
- if (version() <= 3) fHeader.m_dataPos = (int) input->readULong(2);
+ if (vers <= 3) fHeader.m_dataPos = (int) input->readULong(2);
for (int i = 0; i < 3; i++) {
int numParag = (int) input->readLong(2);
@@ -748,7 +748,7 @@ bool MWParser::checkHeader(MWAWHeader *header, bool /*strict*/)
}
}
- if (version() <= 3) {
+ if (vers <= 3) {
input->seek(6, WPX_SEEK_CUR); // unknown
if (input->readLong(1)) f << "hasFooter(?);";
if (input->readLong(1)) f << "hasHeader(?),";
@@ -768,9 +768,12 @@ bool MWParser::checkHeader(MWAWHeader *header, bool /*strict*/)
//
input->seek(headerSize, WPX_SEEK_SET);
- if (!readPrintInfo())
- return false;
- long testPos = version() <= 3 ? fHeader.m_dataPos : fHeader.m_freeListPos;
+ if (!readPrintInfo()) {
+ input->seek(headerSize+0x78, WPX_SEEK_SET);
+ for (int i=0; i<3; ++i)
+ if (!readWindowsInfo(i) && i==2) return false;
+ }
+ long testPos = vers <= 3 ? fHeader.m_dataPos : fHeader.m_freeListPos;
input->seek(testPos, WPX_SEEK_SET);
if (long(input->tell()) != testPos)
return false;
@@ -780,7 +783,7 @@ bool MWParser::checkHeader(MWAWHeader *header, bool /*strict*/)
// ok, we can finish initialization
if (header)
- header->reset(MWAWDocument::MWAW_T_MACWRITE, version());
+ header->reset(MWAWDocument::MWAW_T_MACWRITE, vers);
ascii().addPos(0);
ascii().addNote(f.str().c_str());
diff --git a/src/lib/MWProParser.cxx b/src/lib/MWProParser.cxx
index 8dbdbe4..c81837e 100644
--- a/src/lib/MWProParser.cxx
+++ b/src/lib/MWProParser.cxx
@@ -688,14 +688,22 @@ bool MWProParser::checkHeader(MWAWHeader *header, bool strict)
setVersion(vers);
f << "vers=" << vers << ",";
if (strict) {
- if (!readPrintInfo())
- return false;
if (vers) {
input->seek(0xdd, WPX_SEEK_SET);
// "MP" seems always in this position
if (input->readULong(2) != 0x4d50)
return false;
}
+ else if (!readPrintInfo()) { // last chance, check DocHeader
+ input->seek(4+0x78, WPX_SEEK_SET);
+ if (input->readULong(2)) return false;
+ val=(int) input->readULong(2);
+ if ((val&0x0280)!=0x0280) return false;
+ for (int i=0; i<4; ++i) {
+ val=(int) input->readLong(1);
+ if (val<-1 || val>1) return false;
+ }
+ }
}
@@ -1441,7 +1449,7 @@ bool MWProParser::sendText(shared_ptr<MWProParserInternal::TextZone> zone, bool
}
std::vector<int> pageBreaks=listenerState.getPageBreaksPos();
for (size_t i = 0; i < pageBreaks.size(); i++) {
- if (pageBreaks[i] >= zone->m_textLength) {
+ if (pageBreaks[i]<=0 && pageBreaks[i] >= zone->m_textLength) {
MWAW_DEBUG_MSG(("MWProParser::sendText: page breaks seems bad\n"));
break;
}
--
1.9.0

@ -1,25 +0,0 @@
From 228ae77a4f5308326b597f0c883ddb61545a8014 Mon Sep 17 00:00:00 2001
From: Stephan Bergmann <sbergman@redhat.com>
Date: Thu, 24 Apr 2014 11:58:13 +0200
Subject: [PATCH 8/8] Correct a potential out-of-bounds problem...
---
src/lib/MSKGraph.cxx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lib/MSKGraph.cxx b/src/lib/MSKGraph.cxx
index 7c1a9f6..f32d7c6 100644
--- a/src/lib/MSKGraph.cxx
+++ b/src/lib/MSKGraph.cxx
@@ -728,7 +728,7 @@ void State::initPatterns(int vers)
0x55ff, 0x55ff, 0x55ff, 0x55ff, 0x55ff, 0xeeff, 0x55ff, 0xbbff, 0x77ff, 0xddff, 0x77ff, 0xddff, 0x7fff, 0xf7ff, 0x7fff, 0xf7ff,
0x7fff, 0xffff, 0xf7ff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff
};
- m_rsrcPatternsMap.insert(std::map<long, Patterns>::value_type(4003,Patterns(28, values4003)));
+ m_rsrcPatternsMap.insert(std::map<long, Patterns>::value_type(4003,Patterns(22, values4003)));
static uint16_t const (values4004[]) = {
0xf0f0, 0xf0f0, 0x0f0f, 0x0f0f, 0xcccc, 0x3333, 0xcccc, 0x3333, 0x3333, 0xcccc, 0x3333, 0xcccc
};
--
1.9.0

@ -1,8 +1,8 @@
%global apiversion 0.2
%global apiversion 0.3
Name: libmwaw
Version: 0.2.0
Release: 5%{?dist}
Version: 0.3.1
Release: 1%{?dist}
Summary: An import library for many old mac document formats
Group: System Environment/Libraries
@ -10,20 +10,14 @@ License: LGPLv2+ or MPLv2.0
URL: http://sourceforge.net/projects/libmwaw/
Source: http://downloads.sourceforge.net/%{name}/%{name}-%{version}.tar.xz
BuildRequires: automake
BuildRequires: boost-devel
BuildRequires: doxygen
BuildRequires: help2man
BuildRequires: pkgconfig(libwpd-0.9)
BuildRequires: pkgconfig(libwpg-0.2)
Patch0: 0001-std-isfinite-is-C-11.patch
Patch1: 0002-use-correct-type.patch
Patch2: 0003-Correct-some-cppcheck-errors-change-code-to-avoid-ca.patch
Patch3: 0004-avoid-leak.patch
Patch4: 0005-ClarisWorks-parser-try-to-reconstruct-compressed-bit.patch
Patch5: 0006-ClarisWorks-parser-use-the-page-size-to-define-the-b.patch
Patch6: 0007-MacWrite-MacWrite-II-parser-try-to-accept-more-files.patch
Patch7: 0008-Correct-a-potential-out-of-bounds-problem.patch
BuildRequires: pkgconfig(librevenge-0.0)
Patch0: 0001-librevenge-stream-is-optional-don-t-depend-on-it.patch
Patch1: 0002-librevenge-stream-is-optional-don-t-depend-on-it.patch
%description
libmwaw contains import filters for many old mac documents, mostly text
@ -62,6 +56,7 @@ Supported output formats are CSV, XHTML, text and raw.
%autosetup -p1
%build
automake
%configure --disable-static --disable-werror --disable-zip --enable-docs
sed -i \
-e 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' \
@ -73,6 +68,7 @@ export LD_LIBRARY_PATH=`pwd`/src/lib/.libs${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}
help2man -N -n 'convert Mac spreadsheet into CSV' -o mwaw2csv.1 ./src/conv/csv/.libs/mwaw2csv
help2man -N -n 'debug the conversion library' -o mwaw2raw.1 ./src/conv/raw/.libs/mwaw2raw
help2man -N -n 'convert Mac text document into HTML' -o mwaw2html.1 ./src/conv/html/.libs/mwaw2html
help2man -N -n 'convert Mac drawing into SVG' -o mwaw2svg.1 ./src/conv/svg/.libs/mwaw2svg
help2man -N -n 'convert Mac text document into plain text' -o mwaw2text.1 ./src/conv/text/.libs/mwaw2text
%install
@ -107,13 +103,18 @@ install -m 0644 mwaw2*.1 %{buildroot}/%{_mandir}/man1
%{_bindir}/mwaw2csv
%{_bindir}/mwaw2html
%{_bindir}/mwaw2raw
%{_bindir}/mwaw2svg
%{_bindir}/mwaw2text
%{_mandir}/man1/mwaw2csv.1*
%{_mandir}/man1/mwaw2html.1*
%{_mandir}/man1/mwaw2raw.1*
%{_mandir}/man1/mwaw2svg.1*
%{_mandir}/man1/mwaw2text.1*
%changelog
* Mon May 26 2014 David Tardon <dtardon@redhat.com> - 0.3.1-1
- new upstream release
* Fri May 23 2014 David Tardon <dtardon@redhat.com> - 0.2.0-5
- rebuild for boost 1.55.0

@ -1 +1 @@
bcec7fb6cda6d6d233f305d98acfc0cf libmwaw-0.2.0.tar.xz
0f5d08a835145c599c900b7b6cef1e3b libmwaw-0.3.1.tar.xz

Loading…
Cancel
Save