[Libreoffice-commits] libmspub.git: 2 commits - build/win32 src/lib

Fridrich Å trba fridrich.strba at bluewin.ch
Fri May 10 04:03:11 PDT 2013


 build/win32/libmspub.dsp        |    8 +++
 build/win32/libmspub.vcproj     |    8 +++
 build/win32/libmspub.vcxproj    |    2 
 src/lib/MSPUBInternalStream.cpp |  102 ++++++++++++++++++++++++++++++++++++++++
 src/lib/MSPUBInternalStream.h   |   76 +++++++++++++++++++++++++++++
 src/lib/MSPUBParser.cpp         |    9 ++-
 src/lib/Makefile.am             |    2 
 src/lib/libmspub_utils.cpp      |   16 ------
 src/lib/libmspub_utils.h        |    3 -
 9 files changed, 204 insertions(+), 22 deletions(-)

New commits:
commit b7371ac25d7a5df50ad7c60964c98256d3a0b7b1
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Fri May 10 12:58:41 2013 +0200

    Don't depend on a particular external WPXInputStream implementation

diff --git a/build/win32/libmspub.dsp b/build/win32/libmspub.dsp
index 4421e1b..5654ab4 100644
--- a/build/win32/libmspub.dsp
+++ b/build/win32/libmspub.dsp
@@ -111,6 +111,10 @@ SOURCE=..\..\src\lib\MSPUBDocument.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\src\lib\MSPUBInternalStream.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\src\lib\MSPUBParser.cpp
 # End Source File
 # Begin Source File
@@ -235,6 +239,10 @@ SOURCE=..\..\src\lib\MSPUBDocument.h
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\src\lib\MSPUBInteernalStream.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\src\lib\MSPUBParser.h
 # End Source File
 # Begin Source File
diff --git a/build/win32/libmspub.vcproj b/build/win32/libmspub.vcproj
index b88d14c..4196582 100644
--- a/build/win32/libmspub.vcproj
+++ b/build/win32/libmspub.vcproj
@@ -197,6 +197,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\lib\MSPUBInternalStream.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\lib\MSPUBParser.cpp"
 				>
 			</File>
@@ -322,6 +326,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\lib\MSPUBInternalStream.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\lib\MSPUBParser.h"
 				>
 			</File>
diff --git a/build/win32/libmspub.vcxproj b/build/win32/libmspub.vcxproj
index c233331..3076a81 100644
--- a/build/win32/libmspub.vcxproj
+++ b/build/win32/libmspub.vcxproj
@@ -32,6 +32,7 @@
     <ClInclude Include="..\..\src\lib\MSPUBConstants.h" />
     <ClInclude Include="..\..\src\lib\MSPUBContentChunkType.h" />
     <ClInclude Include="..\..\src\lib\MSPUBDocument.h" />
+    <ClInclude Include="..\..\src\lib\MSPUBInternalStream.h" />
     <ClInclude Include="..\..\src\lib\MSPUBParser.h" />
     <ClInclude Include="..\..\src\lib\MSPUBParser2k.h" />
     <ClInclude Include="..\..\src\lib\MSPUBParser97.h" />
@@ -58,6 +59,7 @@
     <ClCompile Include="..\..\src\lib\libmspub_utils.cpp" />
     <ClCompile Include="..\..\src\lib\MSPUBCollector.cpp" />
     <ClCompile Include="..\..\src\lib\MSPUBDocument.cpp" />
+    <ClCompile Include="..\..\src\lib\MSPUBInternalStream.cpp" />
     <ClCompile Include="..\..\src\lib\MSPUBParser.cpp" />
     <ClCompile Include="..\..\src\lib\MSPUBParser2k.cpp" />
     <ClCompile Include="..\..\src\lib\MSPUBParser97.cpp" />
diff --git a/src/lib/MSPUBInternalStream.cpp b/src/lib/MSPUBInternalStream.cpp
new file mode 100644
index 0000000..594e184
--- /dev/null
+++ b/src/lib/MSPUBInternalStream.cpp
@@ -0,0 +1,102 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* libvisio
+ * Version: MPL 1.1 / GPLv2+ / LGPLv2+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Fridrich Strba <fridrich.strba at bluewin.ch>
+ * Copyright (C) 2011 Eilidh McAdam <tibbylickle at gmail.com>
+ *
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
+ * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
+ * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
+ * instead of those above.
+ */
+
+
+#include <string.h>
+#include "MSPUBInternalStream.h"
+
+
+libmspub::MSPUBInternalStream::MSPUBInternalStream(const unsigned char *buffer, size_t bufferLength) :
+  WPXInputStream(),
+  m_offset(0),
+  m_buffer(bufferLength)
+{
+  memcpy(&m_buffer[0], buffer, bufferLength);
+}
+
+const unsigned char *libmspub::MSPUBInternalStream::read(unsigned long numBytes, unsigned long &numBytesRead)
+{
+  numBytesRead = 0;
+
+  if (numBytes == 0)
+    return 0;
+
+  int numBytesToRead;
+
+  if ((m_offset+numBytes) < m_buffer.size())
+    numBytesToRead = numBytes;
+  else
+    numBytesToRead = m_buffer.size() - m_offset;
+
+  numBytesRead = numBytesToRead;
+
+  if (numBytesToRead == 0)
+    return 0;
+
+  long oldOffset = m_offset;
+  m_offset += numBytesToRead;
+
+  return &m_buffer[oldOffset];
+}
+
+int libmspub::MSPUBInternalStream::seek(long offset, WPX_SEEK_TYPE seekType)
+{
+  if (seekType == WPX_SEEK_CUR)
+    m_offset += offset;
+  else if (seekType == WPX_SEEK_SET)
+    m_offset = offset;
+
+  if (m_offset < 0)
+  {
+    m_offset = 0;
+    return 1;
+  }
+  if ((long)m_offset > (long)m_buffer.size())
+  {
+    m_offset = m_buffer.size();
+    return 1;
+  }
+
+  return 0;
+}
+
+long libmspub::MSPUBInternalStream::tell()
+{
+  return m_offset;
+}
+
+bool libmspub::MSPUBInternalStream::atEOS()
+{
+  if ((long)m_offset >= (long)m_buffer.size())
+    return true;
+
+  return false;
+}
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/MSPUBInternalStream.h b/src/lib/MSPUBInternalStream.h
new file mode 100644
index 0000000..2f648cd
--- /dev/null
+++ b/src/lib/MSPUBInternalStream.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* libvisio
+ * Version: MPL 1.1 / GPLv2+ / LGPLv2+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Fridrich Strba <fridrich.strba at bluewin.ch>
+ * Copyright (C) 2011 Eilidh McAdam <tibbylickle at gmail.com>
+ *
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
+ * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
+ * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
+ * instead of those above.
+ */
+
+
+#ifndef __MSPUBINTERNALSTREAM_H__
+#define __MSPUBINTERNALSTREAM_H__
+
+#include <stddef.h>
+#include <vector>
+#include <libwpd-stream/libwpd-stream.h>
+
+namespace libmspub
+{
+
+class MSPUBInternalStream : public WPXInputStream
+{
+public:
+  MSPUBInternalStream(const unsigned char *buffer, size_t bufferLength);
+  ~MSPUBInternalStream() {}
+
+  bool isOLEStream()
+  {
+    return false;
+  }
+  WPXInputStream *getDocumentOLEStream(const char *)
+  {
+    return 0;
+  }
+
+  const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead);
+  int seek(long offset, WPX_SEEK_TYPE seekType);
+  long tell();
+  bool atEOS();
+  unsigned long getSize() const
+  {
+    return m_buffer.size();
+  };
+
+private:
+  volatile long m_offset;
+  std::vector<unsigned char> m_buffer;
+  MSPUBInternalStream(const MSPUBInternalStream &);
+  MSPUBInternalStream &operator=(const MSPUBInternalStream &);
+};
+
+} // namespace libmspub
+
+#endif
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index ff2a135..77437d4 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -39,6 +39,7 @@
 #include "MSPUBBlockType.h"
 #include "MSPUBContentChunkType.h"
 #include "MSPUBConstants.h"
+#include "MSPUBInternalStream.h"
 #include "EscherContainerType.h"
 #include "EscherFieldIds.h"
 #include "libmspub_utils.h"
@@ -270,7 +271,7 @@ bool libmspub::MSPUBParser::parseEscherDelay(WPXInputStream *input)
       {
         // Reconstruct BMP header
         // cf. http://en.wikipedia.org/wiki/BMP_file_format , accessed 2012-5-31
-        WPXStringStream buf(img.getDataBuffer(), img.size());
+        MSPUBInternalStream buf(img.getDataBuffer(), img.size());
         if (img.size() < 0x2E + 4)
         {
           ++m_lastAddedImage;
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index a7f6be6..4913493 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -18,6 +18,7 @@ libmspub_ at MSPUB_MAJOR_VERSION@_ at MSPUB_MINOR_VERSION@_la_DEPENDENCIES = @LIBMSPUB
 libmspub_ at MSPUB_MAJOR_VERSION@_ at MSPUB_MINOR_VERSION@_la_LDFLAGS = $(version_info) -export-dynamic -no-undefined
 libmspub_ at MSPUB_MAJOR_VERSION@_ at MSPUB_MINOR_VERSION@_la_SOURCES = \
 	MSPUBCollector.cpp \
+	MSPUBInternalStream.cpp \
 	MSPUBDocument.cpp \
 	MSPUBParser.cpp \
 	MSPUBParser2k.cpp \
@@ -40,6 +41,7 @@ libmspub_ at MSPUB_MAJOR_VERSION@_ at MSPUB_MINOR_VERSION@_la_SOURCES = \
 	MSPUBCollector.h \
 	MSPUBConstants.h \
 	MSPUBContentChunkType.h \
+	MSPUBInternalStream.h \
 	MSPUBParser.h \
 	MSPUBParser2k.h \
 	MSPUBSVGGenerator.h \
commit a92bbba4d1995752eb71532b5e7a24094732ede5
Author: David Tardon <dtardon at redhat.com>
Date:   Fri May 10 12:42:49 2013 +0200

    rhbz#960037 drop string-based readU* functions

diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index 6404db8..ff2a135 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -270,7 +270,7 @@ bool libmspub::MSPUBParser::parseEscherDelay(WPXInputStream *input)
       {
         // Reconstruct BMP header
         // cf. http://en.wikipedia.org/wiki/BMP_file_format , accessed 2012-5-31
-        const unsigned char *buf = img.getDataBuffer();
+        WPXStringStream buf(img.getDataBuffer(), img.size());
         if (img.size() < 0x2E + 4)
         {
           ++m_lastAddedImage;
@@ -278,8 +278,10 @@ bool libmspub::MSPUBParser::parseEscherDelay(WPXInputStream *input)
           input->seek(info.contentsOffset + info.contentsLength, WPX_SEEK_SET);
           continue;
         }
-        unsigned short bitsPerPixel = readU16(buf, 0x0E);
-        unsigned numPaletteColors = readU32(buf, 0x20);
+        buf.seek(0x0E, WPX_SEEK_SET);
+        unsigned short bitsPerPixel = readU16(&buf);
+        buf.seek(0x20, WPX_SEEK_SET);
+        unsigned numPaletteColors = readU32(&buf);
         if (numPaletteColors == 0 && bitsPerPixel <= 8)
         {
           numPaletteColors = 1;
diff --git a/src/lib/libmspub_utils.cpp b/src/lib/libmspub_utils.cpp
index d61db1d..d217139 100644
--- a/src/lib/libmspub_utils.cpp
+++ b/src/lib/libmspub_utils.cpp
@@ -288,22 +288,6 @@ uint8_t libmspub::readU8(WPXInputStream *input)
   throw EndOfStreamException();
 }
 
-uint16_t libmspub::readU16(const unsigned char *input, unsigned offset)
-{
-  uint16_t p0 = (uint16_t)(*(input + offset));
-  uint16_t p1 = (uint16_t)(*(input + offset + 1));
-  return (uint16_t)(p0|(p1<<8));
-}
-
-uint32_t libmspub::readU32(const unsigned char *input, unsigned offset)
-{
-  uint32_t p0 = (uint32_t)(*(input + offset));
-  uint32_t p1 = (uint32_t)(*(input + offset + 1));
-  uint32_t p2 = (uint32_t)(*(input + offset + 2));
-  uint32_t p3 = (uint32_t)(*(input + offset + 3));
-  return (uint32_t)(p0|(p1<<8)|(p2<<16)|(p3<<24));
-}
-
 uint16_t libmspub::readU16(WPXInputStream *input)
 {
   uint16_t p0 = (uint16_t)readU8(input);
diff --git a/src/lib/libmspub_utils.h b/src/lib/libmspub_utils.h
index c0ba308..37db8bf 100644
--- a/src/lib/libmspub_utils.h
+++ b/src/lib/libmspub_utils.h
@@ -94,9 +94,6 @@ namespace libmspub
 const char *mimeByImgType(ImgType type);
 const char *windowsCharsetNameByOriginalCharset(const char *name);
 
-uint16_t readU16(const unsigned char *input, unsigned offset);
-uint32_t readU32(const unsigned char *input, unsigned offset);
-
 uint8_t readU8(WPXInputStream *input);
 uint16_t readU16(WPXInputStream *input);
 uint32_t readU32(WPXInputStream *input);


More information about the Libreoffice-commits mailing list