[Libreoffice-commits] libvisio.git: 2 commits - src/lib src/test
David Tardon
dtardon at redhat.com
Mon Dec 12 19:31:42 UTC 2016
src/lib/VSDContentCollector.cpp | 47 ++++++++++++++++++++++++++++++++---
src/lib/libvisio_utils.h | 2 +
src/test/Makefile.am | 2 +
src/test/data/bitmaps.vsd |binary
src/test/data/bitmaps2.vsd |binary
src/test/importtest.cpp | 51 +++++++++++++++++++++++++++++++++++++++
src/test/xmldrawinggenerator.cpp | 1
7 files changed, 99 insertions(+), 4 deletions(-)
New commits:
commit da0d4a764f0e5862a2ed930b27b9c440ec397b90
Author: David Tardon <dtardon at redhat.com>
Date: Mon Dec 12 19:59:22 2016 +0100
add test for correct bmp output
Change-Id: I7443f4408c3733542020aeab3a888baf48a231d1
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index 54fbf78..7791453 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -21,6 +21,8 @@ test_SOURCES = \
EXTRA_DIST = \
data/bgcolor.vsdx \
+ data/bitmaps.vsd \
+ data/bitmaps2.vsd \
data/color-boxes.vsdx \
data/fdo86664.vsdx \
data/fdo86729-ms1252.vsd \
diff --git a/src/test/data/bitmaps.vsd b/src/test/data/bitmaps.vsd
new file mode 100644
index 0000000..8b14f2e
Binary files /dev/null and b/src/test/data/bitmaps.vsd differ
diff --git a/src/test/data/bitmaps2.vsd b/src/test/data/bitmaps2.vsd
new file mode 100644
index 0000000..810d30e
Binary files /dev/null and b/src/test/data/bitmaps2.vsd differ
diff --git a/src/test/importtest.cpp b/src/test/importtest.cpp
index 1cbfc9d..418551f 100644
--- a/src/test/importtest.cpp
+++ b/src/test/importtest.cpp
@@ -94,6 +94,21 @@ void assertXPathNoAttribute(xmlDocPtr doc, const librevenge::RVNGString &xpath,
xmlXPathFreeObject(xpathobject);
}
+void assertBmpDataOffset(xmlDocPtr doc, const librevenge::RVNGString &xpath, const unsigned expectedValue)
+{
+ const librevenge::RVNGBinaryData bitmap(getXPath(doc, xpath, "binary-data"));
+ librevenge::RVNGString message("BMP at '");
+ message.append(xpath);
+ message.append("': wrong data offset.");
+ librevenge::RVNGInputStream *const input = bitmap.getDataStream();
+ CPPUNIT_ASSERT(input);
+ CPPUNIT_ASSERT_EQUAL(0, input->seek(10, librevenge::RVNG_SEEK_SET));
+ unsigned long numBytesRead = 0;
+ const unsigned char *const bytes = input->read(4, numBytesRead);
+ CPPUNIT_ASSERT_EQUAL(4ul, numBytesRead);
+ const unsigned actualValue = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(message.cstr(), expectedValue, actualValue);
+}
#if 0 // keep for future use
/// Same as the assertXPathContent(), but don't assert: return the string instead.
@@ -164,6 +179,8 @@ class ImportTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testVsdxCharBgColor);
#endif
CPPUNIT_TEST(testVsdTextBlockWithoutBgColor);
+ CPPUNIT_TEST(testBmpFileHeader);
+ CPPUNIT_TEST(testBmpFileHeader2);
CPPUNIT_TEST_SUITE_END();
void testVsdxMetadataTitle();
@@ -174,6 +191,8 @@ class ImportTest : public CPPUNIT_NS::TestFixture
void testVsdxImportBgColorFromTheme();
void testVsdxCharBgColor();
void testVsdTextBlockWithoutBgColor();
+ void testBmpFileHeader();
+ void testBmpFileHeader2();
xmlBufferPtr m_buffer;
xmlDocPtr m_doc;
@@ -294,6 +313,38 @@ void ImportTest::testVsdTextBlockWithoutBgColor()
assertXPathNoAttribute(m_doc, "/document/page/layer[5]/textObject/paragraph[1]/span", "background-color");
}
+void ImportTest::testBmpFileHeader()
+{
+ m_doc = parse("bitmaps.vsd", m_buffer);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[1]", 62);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[2]", 62);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[3]", 62);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[4]", 118);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[5]", 118);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[6]", 54);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[7]", 1078);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[8]", 1078);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[9]", 1078);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[10]", 54);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[11]", 1078);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[12]", 1078);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[13]", 1078);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[14]", 54);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[15]", 54);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[16]", 54);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[17]", 54);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[18]", 54);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[19]", 54);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[20]", 54);
+}
+
+void ImportTest::testBmpFileHeader2()
+{
+ m_doc = parse("bitmaps2.vsd", m_buffer);
+ assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[1]", 62);
+ assertBmpDataOffset(m_doc, "/document/page/layer/drawGraphicObject[1]", 330);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest);
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/test/xmldrawinggenerator.cpp b/src/test/xmldrawinggenerator.cpp
index 771caff..cad7e2e 100644
--- a/src/test/xmldrawinggenerator.cpp
+++ b/src/test/xmldrawinggenerator.cpp
@@ -35,6 +35,7 @@ void XmlDrawingGenerator::startDocument(const librevenge::RVNGPropertyList &prop
xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:draw"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"));
xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:fo"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"));
xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:librevenge"), BAD_CAST("urn:x-documentliberation:xmlns:librevenge:0.0"));
+ xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:office"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:office:1.0"));
xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:style"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:style:1.0"));
xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:svg"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"));
xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:meta"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:meta:1.0"));
commit 2e5496881e0b14da3a8c0acf5de6be0f49f80350
Author: David Tardon <dtardon at redhat.com>
Date: Mon Dec 12 15:23:55 2016 +0100
emit bmps with color palette correctly
Change-Id: I731ab9629fdc08c54b43cdcb21a81633bd89f569
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index 3178937..eb9a366 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -7,6 +7,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <cassert>
#include <string.h> // for memcpy
#include <set>
#include <stack>
@@ -68,6 +69,43 @@ void computeRounding(double &prevX, double &prevY, double x0, double y0, double
prevY = y0;
}
+unsigned computeBMPDataOffset(librevenge::RVNGInputStream *const input, const unsigned long maxLength)
+{
+ assert(input);
+
+ using namespace libvisio;
+
+ // determine header size
+ unsigned headerSize = readU32(input);
+ if (headerSize > maxLength)
+ headerSize = 40; // assume v.3 bitmap header size
+ unsigned off = headerSize;
+
+ // determine palette size
+ input->seek(10, librevenge::RVNG_SEEK_CUR);
+ unsigned bpp = readU16(input);
+ // sanitize bpp
+ if (bpp > 32)
+ bpp = 32;
+ const unsigned allowedBpp[] = {1, 4, 8, 16, 24, 32};
+ size_t bppIdx = 0;
+ while (bppIdx < VSD_NUM_ELEMENTS(allowedBpp) && bpp < allowedBpp[bppIdx])
+ ++bppIdx;
+ if (bpp < allowedBpp[bppIdx])
+ bpp = allowedBpp[bppIdx];
+ input->seek(16, librevenge::RVNG_SEEK_CUR);
+ unsigned paletteColors = readU32(input);
+ if (bpp < 16 && paletteColors == 0)
+ paletteColors = 1 << bpp;
+ assert(maxLength >= off);
+ if (paletteColors > 0 && (paletteColors < (maxLength - off) / 4))
+ off += 4 * paletteColors;
+
+ off += 14; // file header size
+
+ return off;
+}
+
} // anonymous namespace
libvisio::VSDContentCollector::VSDContentCollector(
@@ -1402,10 +1440,11 @@ void libvisio::VSDContentCollector::_handleForeignData(const librevenge::RVNGBin
m_currentForeignData.append((unsigned char)0x00);
m_currentForeignData.append((unsigned char)0x00);
- m_currentForeignData.append((unsigned char)0x36);
- m_currentForeignData.append((unsigned char)0x00);
- m_currentForeignData.append((unsigned char)0x00);
- m_currentForeignData.append((unsigned char)0x00);
+ const unsigned dataOff = computeBMPDataOffset(binaryData.getDataStream(), binaryData.size());
+ m_currentForeignData.append((unsigned char)(dataOff & 0xff));
+ m_currentForeignData.append((unsigned char)((dataOff >> 8) & 0xff));
+ m_currentForeignData.append((unsigned char)((dataOff >> 16) & 0xff));
+ m_currentForeignData.append((unsigned char)((dataOff >> 24) & 0xff));
}
m_currentForeignData.append(binaryData);
diff --git a/src/lib/libvisio_utils.h b/src/lib/libvisio_utils.h
index c6c3a03..2a4880e 100644
--- a/src/lib/libvisio_utils.h
+++ b/src/lib/libvisio_utils.h
@@ -70,6 +70,8 @@ typedef unsigned __int64 uint64_t;
#define VSD_DEBUG(M)
#endif
+#define VSD_NUM_ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
+
namespace libvisio
{
More information about the Libreoffice-commits
mailing list