[Libreoffice-commits] core.git: Branch 'feature/vba-export' - 25 commits - oox/source

Rosemary rosemaryseb8 at gmail.com
Fri Aug 14 04:27:26 PDT 2015


 oox/source/ole/vbaexport.cxx |  584 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 531 insertions(+), 53 deletions(-)

New commits:
commit 1e7a41a8618cd6bbabfb9f8c3d4a470d361944ef
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 11:36:05 2015 +0530

    termination of dir stream
    
    Change-Id: Iac2284fe0876afe244fad8f33fe88402dc48a704

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 9f54e03..93c228f 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -646,6 +646,8 @@ void exportDirStream(SvStream& rStrm)
     writePROJECTINFORMATION(rStrm);
     writePROJECTREFERENCES(rStrm);
     writePROJECTMODULES(rStrm);
+    rStrm.WriteUInt16(0x0010); // terminator
+    rStrm.WriteUInt32(0x00000000); // reserved
 }
 
 }
commit de136c316c4336b200405ba5fd141a7989371926
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 11:29:41 2015 +0530

    implementing the fifth module - sheet3
    
    Change-Id: I50abe3687e37fad43ffb93b360f82acf07d74331

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 4494093..9f54e03 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -637,6 +637,7 @@ void writePROJECTMODULES(SvStream& rStrm)
     writePROJECTMODULE(rStrm, "ThisWorkbook", "ThisWorkbook", 0x000004BD, "other");
     writePROJECTMODULE(rStrm, "Sheet1", "Sheet1", 0x00000325, "other");
     writePROJECTMODULE(rStrm, "Sheet2", "Sheet2", 0x00000325, "other");
+    writePROJECTMODULE(rStrm, "Sheet3", "Sheet3", 0x00000325, "other");
 }
 
 // section 2.3.4.2
commit add8a73eeb78970128a126c748e3f951d3b93bca
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 11:17:30 2015 +0530

    implementing the fourth module - sheet2
    
    Change-Id: Ib3ff765e3646ba381e6d01654147ba1fdda65377

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 65fc6d6..4494093 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -636,6 +636,7 @@ void writePROJECTMODULES(SvStream& rStrm)
     writePROJECTMODULE(rStrm, "Module1", "Module1", 0x00000379, "procedure");
     writePROJECTMODULE(rStrm, "ThisWorkbook", "ThisWorkbook", 0x000004BD, "other");
     writePROJECTMODULE(rStrm, "Sheet1", "Sheet1", 0x00000325, "other");
+    writePROJECTMODULE(rStrm, "Sheet2", "Sheet2", 0x00000325, "other");
 }
 
 // section 2.3.4.2
commit 526e371a9665ba63291df744b7b746791b05fd01
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 11:11:55 2015 +0530

    implementing the third module - sheet1
    
    Change-Id: I57633ce039163fa9145a3aa71b594c4b30999475

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 58c1207..65fc6d6 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -635,6 +635,7 @@ void writePROJECTMODULES(SvStream& rStrm)
     writePROJECTCOOKIE(rStrm);
     writePROJECTMODULE(rStrm, "Module1", "Module1", 0x00000379, "procedure");
     writePROJECTMODULE(rStrm, "ThisWorkbook", "ThisWorkbook", 0x000004BD, "other");
+    writePROJECTMODULE(rStrm, "Sheet1", "Sheet1", 0x00000325, "other");
 }
 
 // section 2.3.4.2
commit cfb7b30693f353fe46431ed7c5571c46792ce36f
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 11:05:35 2015 +0530

    implementing the second module
    
    Change-Id: I6a9e1fb07c990bcf65fa15e84e72cc410996cd73

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 1b82b8e..58c1207 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -634,6 +634,7 @@ void writePROJECTMODULES(SvStream& rStrm)
     rStrm.WriteUInt16(count); // Count
     writePROJECTCOOKIE(rStrm);
     writePROJECTMODULE(rStrm, "Module1", "Module1", 0x00000379, "procedure");
+    writePROJECTMODULE(rStrm, "ThisWorkbook", "ThisWorkbook", 0x000004BD, "other");
 }
 
 // section 2.3.4.2
commit c80ccce5ea8534b6a205778fba5e9010d31fda15
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 10:53:59 2015 +0530

    modified to implement more module records
    
    Conflicts:
    	oox/source/ole/vbaexport.cxx
    
    Change-Id: I292869ffd8b2e5aa5d2ba865c237ed1536db3fdb

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 578da98..1b82b8e 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -537,30 +537,33 @@ void writePROJECTCOOKIE(SvStream& rStrm)
 }
 
 // section 2.3.4.2.3.2.1
-void writeMODULENAME(SvStream& rStrm)
+void writeMODULENAME(SvStream& rStrm, const OUString name)
 {
     rStrm.WriteUInt16(0x0019); // id
-    rStrm.WriteUInt32(7); // sizeOfModuleName
-    exportString(rStrm, "Module1"); // ModuleName // TODO: dependent on the document
+    sal_Int32 n = name.getLength(); // sizeOfModuleName
+    rStrm.WriteUInt32(n);
+    exportString(rStrm, name); // ModuleName
 }
 
 // section 2.3.4.2.3.2.2
-void writeMODULENAMEUNICODE(SvStream& rStrm)
+void writeMODULENAMEUNICODE(SvStream& rStrm, const OUString name)
 {
     rStrm.WriteUInt16(0x0047); // id
-    rStrm.WriteUInt32(14); // sizeOfModuleName
-    exportUTF16String(rStrm, "Module1"); // ModuleName // TODO: dependent on the document
+    sal_Int32 n = name.getLength() * 2; // sizeOfModuleNameUnicode // TODO: better calculation for unicode string length
+    rStrm.WriteUInt32(n);
+    exportUTF16String(rStrm, name); // ModuleNameUnicode
 }
 
 // section 2.3.4.2.3.2.3
-void writeMODULESTREAMNAME(SvStream& rStrm)
+void writeMODULESTREAMNAME(SvStream& rStrm, const OUString streamName)
 {
     rStrm.WriteUInt16(0x001A); // id
-    rStrm.WriteUInt32(7); // sizeOfStreamName
-    exportString(rStrm, "Module1"); // StreamName // TODO: dependent on the document
+    sal_Int32 n = streamName.getLength(); // sizeOfStreamName
+    rStrm.WriteUInt32(n);
+    exportString(rStrm, streamName); // StreamName
     rStrm.WriteUInt16(0x0032); // reserved
-    rStrm.WriteUInt32(14); // sizeOfModuleStreamName
-    exportUTF16String(rStrm, "Module1"); // ModuleStreamName // TODO: dependent on the document
+    rStrm.WriteUInt32(n * 2); // sizeOfStreamNameUnicode // TODO: better calculation for unicode string length
+    exportUTF16String(rStrm, streamName); // StreamNameUnicode
 }
 
 // section 2.3.4.2.3.2.4
@@ -573,11 +576,11 @@ void writeMODULEDOCSTRING(SvStream& rStrm)
 }
 
 // section 2.3.4.2.3.2.5
-void writeMODULEOFFSET(SvStream& rStrm)
+void writeMODULEOFFSET(SvStream& rStrm, sal_uInt32 offset)
 {
     rStrm.WriteUInt16(0x0031); // id
     rStrm.WriteUInt32(0x00000004); // sizeOfTextOffset
-    rStrm.WriteUInt32(0x00000379); // TextOffset // TODO: dependent on the document
+    rStrm.WriteUInt32(offset); // TextOffset
 }
 
 // section 2.3.4.2.3.2.6
@@ -597,23 +600,26 @@ void writeMODULECOOKIE(SvStream& rStrm)
 }
 
 // section 2.3.4.2.3.2.8
-void writeMODULETYPE(SvStream& rStrm)
+void writeMODULETYPE(SvStream& rStrm, const OUString type)
 {
-    rStrm.WriteUInt16(0x0021); // id for procedural module
+    if(type == "procedure")
+        rStrm.WriteUInt16(0x0021); // id for a procedural module
+    else
+        rStrm.WriteUInt16(0x0022); // id for document, class or design module
     rStrm.WriteUInt32(0x00000000); // reserved
 }
 
 // section 2.3.4.2.3.2
-void writePROJECTMODULE(SvStream& rStrm)
+void writePROJECTMODULE(SvStream& rStrm, const OUString name, const OUString streamName, sal_uInt32 offset, const OUString type)
 {
-    writeMODULENAME(rStrm);
-    writeMODULENAMEUNICODE(rStrm);
-    writeMODULESTREAMNAME(rStrm);
+    writeMODULENAME(rStrm, name);
+    writeMODULENAMEUNICODE(rStrm, name);
+    writeMODULESTREAMNAME(rStrm, streamName);
     writeMODULEDOCSTRING(rStrm);
-    writeMODULEOFFSET(rStrm);
+    writeMODULEOFFSET(rStrm, offset);
     writeMODULEHELPCONTEXT(rStrm);
     writeMODULECOOKIE(rStrm);
-    writeMODULETYPE(rStrm);
+    writeMODULETYPE(rStrm, type);
     rStrm.WriteUInt16(0x002B); // terminator
     rStrm.WriteUInt32(0x00000000); // reserved
 }
@@ -621,12 +627,13 @@ void writePROJECTMODULE(SvStream& rStrm)
 // section 2.3.4.2.3
 void writePROJECTMODULES(SvStream& rStrm)
 {
+    // TODO: this whole part is document specific
     rStrm.WriteUInt16(0x000F); // id
     rStrm.WriteUInt32(0x00000002); // size of Count
     sal_Int16 count = 5; // Number of modules // TODO: this is dependent on the document
     rStrm.WriteUInt16(count); // Count
     writePROJECTCOOKIE(rStrm);
-    writePROJECTMODULE(rStrm);
+    writePROJECTMODULE(rStrm, "Module1", "Module1", 0x00000379, "procedure");
 }
 
 // section 2.3.4.2
commit 1ee216c754e4f622f2c6385837e2d4d4f30dcbfc
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 10:20:39 2015 +0530

    termination
    
    Change-Id: Ie442e2152a6afc739e36e585ae2fa12ad7b82116

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 4fb2a82..578da98 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -614,6 +614,8 @@ void writePROJECTMODULE(SvStream& rStrm)
     writeMODULEHELPCONTEXT(rStrm);
     writeMODULECOOKIE(rStrm);
     writeMODULETYPE(rStrm);
+    rStrm.WriteUInt16(0x002B); // terminator
+    rStrm.WriteUInt32(0x00000000); // reserved
 }
 
 // section 2.3.4.2.3
commit 646cb96b5c780b154a4005ade6d91c190e84cc4e
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 10:12:37 2015 +0530

    module type record
    
    Change-Id: Ie015931985a66f7fb2a47bc94d8215f64a667438

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 6f6c207..4fb2a82 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -596,6 +596,13 @@ void writeMODULECOOKIE(SvStream& rStrm)
     rStrm.WriteUInt16(0xFFFF); // HelpContext
 }
 
+// section 2.3.4.2.3.2.8
+void writeMODULETYPE(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x0021); // id for procedural module
+    rStrm.WriteUInt32(0x00000000); // reserved
+}
+
 // section 2.3.4.2.3.2
 void writePROJECTMODULE(SvStream& rStrm)
 {
@@ -606,6 +613,7 @@ void writePROJECTMODULE(SvStream& rStrm)
     writeMODULEOFFSET(rStrm);
     writeMODULEHELPCONTEXT(rStrm);
     writeMODULECOOKIE(rStrm);
+    writeMODULETYPE(rStrm);
 }
 
 // section 2.3.4.2.3
commit a7887aaaa79ad6666eabfe290518659b3a8588b1
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 10:06:25 2015 +0530

    module cookie record
    
    Change-Id: Idd2f52e6f48c9fe6e1fbaecdfc34535205f28c59

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index f9eff70..6f6c207 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -588,6 +588,14 @@ void writeMODULEHELPCONTEXT(SvStream& rStrm)
     rStrm.WriteUInt32(0x00000000); // HelpContext
 }
 
+// section 2.3.4.2.3.2.7
+void writeMODULECOOKIE(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x002C); // id
+    rStrm.WriteUInt32(0x00000002); // sizeOfHelpContext
+    rStrm.WriteUInt16(0xFFFF); // HelpContext
+}
+
 // section 2.3.4.2.3.2
 void writePROJECTMODULE(SvStream& rStrm)
 {
@@ -597,6 +605,7 @@ void writePROJECTMODULE(SvStream& rStrm)
     writeMODULEDOCSTRING(rStrm);
     writeMODULEOFFSET(rStrm);
     writeMODULEHELPCONTEXT(rStrm);
+    writeMODULECOOKIE(rStrm);
 }
 
 // section 2.3.4.2.3
commit f98a9b115592c2077ba7d1049833a45ed6774207
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 10:01:07 2015 +0530

    module help context record
    
    Change-Id: I671c1c436864b935dfec97fbde9441d2c5d3ae3c

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index f56c56c..f9eff70 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -580,6 +580,14 @@ void writeMODULEOFFSET(SvStream& rStrm)
     rStrm.WriteUInt32(0x00000379); // TextOffset // TODO: dependent on the document
 }
 
+// section 2.3.4.2.3.2.6
+void writeMODULEHELPCONTEXT(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x001E); // id
+    rStrm.WriteUInt32(0x00000004); // sizeOfHelpContext
+    rStrm.WriteUInt32(0x00000000); // HelpContext
+}
+
 // section 2.3.4.2.3.2
 void writePROJECTMODULE(SvStream& rStrm)
 {
@@ -588,6 +596,7 @@ void writePROJECTMODULE(SvStream& rStrm)
     writeMODULESTREAMNAME(rStrm);
     writeMODULEDOCSTRING(rStrm);
     writeMODULEOFFSET(rStrm);
+    writeMODULEHELPCONTEXT(rStrm);
 }
 
 // section 2.3.4.2.3
commit 8f5b020b6365503f05938e9dc83a866c053f3d73
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Aug 14 13:04:18 2015 +0200

    more todo
    
    Change-Id: Ib28b7493227c24c415649a9e55f274ecf1411c77

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 93f5297..f56c56c 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -577,7 +577,7 @@ void writeMODULEOFFSET(SvStream& rStrm)
 {
     rStrm.WriteUInt16(0x0031); // id
     rStrm.WriteUInt32(0x00000004); // sizeOfTextOffset
-    rStrm.WriteUInt32(0x00000379); // TextOffset
+    rStrm.WriteUInt32(0x00000379); // TextOffset // TODO: dependent on the document
 }
 
 // section 2.3.4.2.3.2
commit f6a3ef22d73099d30216efb05ebf5cf20cf99202
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 09:54:15 2015 +0530

    module offset record
    
    Change-Id: I7b2c25e518248cbe28762c1392b1372ff8e61bff

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index f86cb87..93f5297 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -572,6 +572,14 @@ void writeMODULEDOCSTRING(SvStream& rStrm)
     rStrm.WriteUInt32(0x00000000); // sizeOfDocStringUnicode
 }
 
+// section 2.3.4.2.3.2.5
+void writeMODULEOFFSET(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x0031); // id
+    rStrm.WriteUInt32(0x00000004); // sizeOfTextOffset
+    rStrm.WriteUInt32(0x00000379); // TextOffset
+}
+
 // section 2.3.4.2.3.2
 void writePROJECTMODULE(SvStream& rStrm)
 {
@@ -579,6 +587,7 @@ void writePROJECTMODULE(SvStream& rStrm)
     writeMODULENAMEUNICODE(rStrm);
     writeMODULESTREAMNAME(rStrm);
     writeMODULEDOCSTRING(rStrm);
+    writeMODULEOFFSET(rStrm);
 }
 
 // section 2.3.4.2.3
commit be4fd6ca2cb0067798e3e92341708f1a79f893aa
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 09:45:30 2015 +0530

    module doc string record
    
    Change-Id: Ia67dcb4f68379eb923787792e15bc9aaeac308e3

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 3138ce2..f86cb87 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -563,12 +563,22 @@ void writeMODULESTREAMNAME(SvStream& rStrm)
     exportUTF16String(rStrm, "Module1"); // ModuleStreamName // TODO: dependent on the document
 }
 
+// section 2.3.4.2.3.2.4
+void writeMODULEDOCSTRING(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x001C); // id
+    rStrm.WriteUInt32(0x00000000); // sizeOfDocString
+    rStrm.WriteUInt16(0x0048); // reserved
+    rStrm.WriteUInt32(0x00000000); // sizeOfDocStringUnicode
+}
+
 // section 2.3.4.2.3.2
 void writePROJECTMODULE(SvStream& rStrm)
 {
     writeMODULENAME(rStrm);
     writeMODULENAMEUNICODE(rStrm);
     writeMODULESTREAMNAME(rStrm);
+    writeMODULEDOCSTRING(rStrm);
 }
 
 // section 2.3.4.2.3
commit 673e65ca8c723c0941b607daa6c4e117f402cd52
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Aug 14 13:01:15 2015 +0200

    add todo
    
    Change-Id: I8a97f7cf2ee576bfe00ec127a5cf5af90796082b

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 930b590..3138ce2 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -557,10 +557,10 @@ void writeMODULESTREAMNAME(SvStream& rStrm)
 {
     rStrm.WriteUInt16(0x001A); // id
     rStrm.WriteUInt32(7); // sizeOfStreamName
-    exportString(rStrm, "Module1"); // StreamName
+    exportString(rStrm, "Module1"); // StreamName // TODO: dependent on the document
     rStrm.WriteUInt16(0x0032); // reserved
     rStrm.WriteUInt32(14); // sizeOfModuleStreamName
-    exportUTF16String(rStrm, "Module1"); // ModuleStreamName
+    exportUTF16String(rStrm, "Module1"); // ModuleStreamName // TODO: dependent on the document
 }
 
 // section 2.3.4.2.3.2
commit 9023ae977b2df43f5c8d69b0e833502baf219bf3
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 09:37:28 2015 +0530

    module stream name record
    
    Change-Id: I1c12d5427c4808b496fb0e087c100dc93a5695c1

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index cc3b71d..930b590 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -552,11 +552,23 @@ void writeMODULENAMEUNICODE(SvStream& rStrm)
     exportUTF16String(rStrm, "Module1"); // ModuleName // TODO: dependent on the document
 }
 
+// section 2.3.4.2.3.2.3
+void writeMODULESTREAMNAME(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x001A); // id
+    rStrm.WriteUInt32(7); // sizeOfStreamName
+    exportString(rStrm, "Module1"); // StreamName
+    rStrm.WriteUInt16(0x0032); // reserved
+    rStrm.WriteUInt32(14); // sizeOfModuleStreamName
+    exportUTF16String(rStrm, "Module1"); // ModuleStreamName
+}
+
 // section 2.3.4.2.3.2
 void writePROJECTMODULE(SvStream& rStrm)
 {
     writeMODULENAME(rStrm);
     writeMODULENAMEUNICODE(rStrm);
+    writeMODULESTREAMNAME(rStrm);
 }
 
 // section 2.3.4.2.3
commit fd9caa16e51d9b8b8f63a337d1d48e32219011a1
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Aug 14 12:58:49 2015 +0200

    add more todo
    
    Change-Id: Ie6c6fd5ecfad5f7dd21e72104ab19f41fd051ec1

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 9b68e90..cc3b71d 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -541,7 +541,7 @@ void writeMODULENAME(SvStream& rStrm)
 {
     rStrm.WriteUInt16(0x0019); // id
     rStrm.WriteUInt32(7); // sizeOfModuleName
-    exportString(rStrm, "Module1"); // ModuleName
+    exportString(rStrm, "Module1"); // ModuleName // TODO: dependent on the document
 }
 
 // section 2.3.4.2.3.2.2
@@ -549,7 +549,7 @@ void writeMODULENAMEUNICODE(SvStream& rStrm)
 {
     rStrm.WriteUInt16(0x0047); // id
     rStrm.WriteUInt32(14); // sizeOfModuleName
-    exportUTF16String(rStrm, "Module1"); // ModuleName
+    exportUTF16String(rStrm, "Module1"); // ModuleName // TODO: dependent on the document
 }
 
 // section 2.3.4.2.3.2
commit cdaa7abf5f4a76922e31093ff4b261028a922033
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 09:16:39 2015 +0530

    module name unicode record
    
    Change-Id: I7da5defad290fe7884ea9f074a558645283d9146

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 6029c15..9b68e90 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -544,10 +544,19 @@ void writeMODULENAME(SvStream& rStrm)
     exportString(rStrm, "Module1"); // ModuleName
 }
 
+// section 2.3.4.2.3.2.2
+void writeMODULENAMEUNICODE(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x0047); // id
+    rStrm.WriteUInt32(14); // sizeOfModuleName
+    exportUTF16String(rStrm, "Module1"); // ModuleName
+}
+
 // section 2.3.4.2.3.2
 void writePROJECTMODULE(SvStream& rStrm)
 {
     writeMODULENAME(rStrm);
+    writeMODULENAMEUNICODE(rStrm);
 }
 
 // section 2.3.4.2.3
commit 31a36ebed2de5c1304d2dbb17c9c977bf4c194db
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 09:11:35 2015 +0530

    module name record
    
    Conflicts:
    	oox/source/ole/vbaexport.cxx
    
    Change-Id: I2b468bc0ae28ed0dbc7f2a188b04ee9728f2b1e9

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 8e3c6c2..6029c15 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -536,13 +536,29 @@ void writePROJECTCOOKIE(SvStream& rStrm)
     rStrm.WriteUInt16(0xFFFF); // cookie
 }
 
+// section 2.3.4.2.3.2.1
+void writeMODULENAME(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x0019); // id
+    rStrm.WriteUInt32(7); // sizeOfModuleName
+    exportString(rStrm, "Module1"); // ModuleName
+}
+
+// section 2.3.4.2.3.2
+void writePROJECTMODULE(SvStream& rStrm)
+{
+    writeMODULENAME(rStrm);
+}
+
 // section 2.3.4.2.3
 void writePROJECTMODULES(SvStream& rStrm)
 {
     rStrm.WriteUInt16(0x000F); // id
     rStrm.WriteUInt32(0x00000002); // size of Count
-    rStrm.WriteUInt16(5); // Count // TODO: this is dependent on the document
+    sal_Int16 count = 5; // Number of modules // TODO: this is dependent on the document
+    rStrm.WriteUInt16(count); // Count
     writePROJECTCOOKIE(rStrm);
+    writePROJECTMODULE(rStrm);
 }
 
 // section 2.3.4.2
commit 20094a298fdcbea67c55cd06af3deaf9fa4b32f5
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Aug 14 12:09:53 2015 +0200

    add more todo
    
    Change-Id: I04faf290770d06c7ec8eb54a1ae777271b105ad5

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 2746ddf..8e3c6c2 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -541,7 +541,7 @@ void writePROJECTMODULES(SvStream& rStrm)
 {
     rStrm.WriteUInt16(0x000F); // id
     rStrm.WriteUInt32(0x00000002); // size of Count
-    rStrm.WriteUInt16(5); // Count
+    rStrm.WriteUInt16(5); // Count // TODO: this is dependent on the document
     writePROJECTCOOKIE(rStrm);
 }
 
commit dca2553b4b0269684ad67a1cebd63f17bb2cc5b0
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 08:56:37 2015 +0530

    project modules record - project cookie record
    
    Change-Id: I20cc81818560bcfa2cefe9c050836e9c856f44ec

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 246a234..2746ddf 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -528,11 +528,29 @@ void writePROJECTREFERENCES(SvStream& rStrm)
     writeREFERENCE(rStrm, "Office", "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library");
 }
 
+// section 2.3.4.2.3.1
+void writePROJECTCOOKIE(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x0013); // id
+    rStrm.WriteUInt32(0x00000002); // size
+    rStrm.WriteUInt16(0xFFFF); // cookie
+}
+
+// section 2.3.4.2.3
+void writePROJECTMODULES(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x000F); // id
+    rStrm.WriteUInt32(0x00000002); // size of Count
+    rStrm.WriteUInt16(5); // Count
+    writePROJECTCOOKIE(rStrm);
+}
+
 // section 2.3.4.2
 void exportDirStream(SvStream& rStrm)
 {
     writePROJECTINFORMATION(rStrm);
     writePROJECTREFERENCES(rStrm);
+    writePROJECTMODULES(rStrm);
 }
 
 }
commit 316855b90897ea214e99fffdd077b24a81c78e1b
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 08:37:43 2015 +0530

    next reference record
    
    Conflicts:
    	oox/source/ole/vbaexport.cxx
    
    Change-Id: Ie7efdc2cabac43ea06ca9ba84b634fc2cb1ddd54

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 85c4352..246a234 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -488,38 +488,44 @@ void writePROJECTINFORMATION(SvStream& rStrm)
 }
 
 // section 2.3.4.2.2.2
-void writeREFERENCENAME(SvStream& rStrm)
+void writeREFERENCENAME(SvStream& rStrm, const OUString name)
 {
     rStrm.WriteUInt16(0x0016); // id
-    rStrm.WriteUInt32(6); // sizeOfName
-    exportString(rStrm, "stdole"); // name // TODO: find out where these values are coming from
+    sal_Int32 size = name.getLength();
+    rStrm.WriteUInt32(size); // sizeOfName
+    exportString(rStrm, name); // name
     rStrm.WriteUInt16(0x003E); // reserved
-    rStrm.WriteUInt32(12); // sizeOfNameUnicode
-    exportUTF16String(rStrm, "stdole"); // nameUnicode // TODO find out where these values are coming from
+    sal_Int32 unicodesize = size * 2;
+    rStrm.WriteUInt32(unicodesize); // sizeOfNameUnicode
+    exportUTF16String(rStrm, name); // nameUnicode
 }
 
 // section 2.3.4.2.2.5
-void writeREFERENCEREGISTERED(SvStream& rStrm)
+void writeREFERENCEREGISTERED(SvStream& rStrm, const OUString libid)
 {
     rStrm.WriteUInt16(0x000D); // id
-    rStrm.WriteUInt32(104); // size of sizeOfLibid, Libid, reserved 1 and reserved 2
-    rStrm.WriteUInt32(94); // sizeOfLibid
-    exportString(rStrm, "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\SysWOW64\\stdole2.tlb#OLE Automation");
+    sal_Int32 sizeOfLibid = libid.getLength();
+    sal_Int32 size = sizeOfLibid + 10; // size of Libid, sizeOfLibid(4 bytes), reserved 1(4 bytes) and reserved 2(2 bytes)
+    rStrm.WriteUInt32(size); // size
+    rStrm.WriteUInt32(sizeOfLibid); // sizeOfLibid
+    exportString(rStrm, libid); // Libid
     rStrm.WriteUInt32(0x00000000); // reserved 1
     rStrm.WriteUInt16(0x0000); // reserved 2
 }
 
 // section 2.3.4.2.2.1
-void writeREFERENCE(SvStream& rStrm)
+void writeREFERENCE(SvStream& rStrm, const OUString name, const OUString libid)
 {
-    writeREFERENCENAME(rStrm);
-    writeREFERENCEREGISTERED(rStrm);
+    writeREFERENCENAME(rStrm, name);
+    writeREFERENCEREGISTERED(rStrm, libid);
 }
 
 // section 2.3.4.2.2
 void writePROJECTREFERENCES(SvStream& rStrm)
 {
-    writeREFERENCE(rStrm);
+    // TODO: find out where these references are coming from
+    writeREFERENCE(rStrm, "stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\SysWOW64\\stdole2.tlb#OLE Automation");
+    writeREFERENCE(rStrm, "Office", "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library");
 }
 
 // section 2.3.4.2
commit 102189505d8b3fc69e4e8eac2a4482f73046fd19
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 06:57:13 2015 +0530

    reference registered record
    
    Change-Id: I72a038f0e2ef4e7cd430de8e8c835a6147113e29

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 761254501..85c4352 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -498,10 +498,22 @@ void writeREFERENCENAME(SvStream& rStrm)
     exportUTF16String(rStrm, "stdole"); // nameUnicode // TODO find out where these values are coming from
 }
 
+// section 2.3.4.2.2.5
+void writeREFERENCEREGISTERED(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x000D); // id
+    rStrm.WriteUInt32(104); // size of sizeOfLibid, Libid, reserved 1 and reserved 2
+    rStrm.WriteUInt32(94); // sizeOfLibid
+    exportString(rStrm, "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\SysWOW64\\stdole2.tlb#OLE Automation");
+    rStrm.WriteUInt32(0x00000000); // reserved 1
+    rStrm.WriteUInt16(0x0000); // reserved 2
+}
+
 // section 2.3.4.2.2.1
 void writeREFERENCE(SvStream& rStrm)
 {
     writeREFERENCENAME(rStrm);
+    writeREFERENCEREGISTERED(rStrm);
 }
 
 // section 2.3.4.2.2
commit 064c42135cdb0f939b3611335abb126f46073db3
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Aug 14 11:58:17 2015 +0200

    add two todo for later
    
    Change-Id: I8781f3e86584d61613245a5654fe7c6afab9a5da

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index f762e86..761254501 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -492,10 +492,10 @@ void writeREFERENCENAME(SvStream& rStrm)
 {
     rStrm.WriteUInt16(0x0016); // id
     rStrm.WriteUInt32(6); // sizeOfName
-    exportString(rStrm, "stdole"); // name
+    exportString(rStrm, "stdole"); // name // TODO: find out where these values are coming from
     rStrm.WriteUInt16(0x003E); // reserved
     rStrm.WriteUInt32(12); // sizeOfNameUnicode
-    exportUTF16String(rStrm, "stdole"); // nameUnicode
+    exportUTF16String(rStrm, "stdole"); // nameUnicode // TODO find out where these values are coming from
 }
 
 // section 2.3.4.2.2.1
commit 57e1a8e8fa08c1fdae37e0f1a6597bac22ac3de9
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Aug 14 01:18:51 2015 +0530

    reference name 1
    
    Change-Id: I1aa7233126df0a3dc6bb849646aab35f17e72a2e

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 601be68..f762e86 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -378,47 +378,45 @@ VbaExport::VbaExport(css::uno::Reference<css::frame::XModel> xModel):
 
 namespace {
 
-//section 2.3.4.2.1.11
-void writePROJECTCONSTANTS(SvStream& rStrm)
+// section 2.3.4.2.1.1
+void writePROJECTSYSKIND(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x000C); // id
-    rStrm.WriteUInt32(0x00000000); // sizeOfConstants
-    rStrm.WriteUInt16(0x003C); // Reserved
-    rStrm.WriteUInt32(0x00000000); // sizeOfConstantsUnicode
+    rStrm.WriteUInt16(0x0001); // id
+    rStrm.WriteUInt32(0x00000004); // size
+    rStrm.WriteUInt32(0x00000001); // SysKind, hard coded to 32-bin windows for now
 }
 
-//section 2.3.4.2.1.10
-void writePROJECTVERSION(SvStream& rStrm)
+// section 2.3.4.2.1.2
+void writePROJECTLCID(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x0009); // id
-    rStrm.WriteUInt32(0x00000004); // Reserved
-    rStrm.WriteUInt32(1467127224); // VersionMajor // TODO: where is this magic number comming from
-    rStrm.WriteUInt16(5); // VersionMinor // TODO: where is this magic number coming from
+    rStrm.WriteUInt16(0x0002); // id
+    rStrm.WriteUInt32(0x00000004); // size
+    rStrm.WriteUInt32(0x00000409); // Lcid
 }
 
-//section 2.3.4.2.1.9
-void writePROJECTLIBFLAGS(SvStream& rStrm)
+// section 2.3.4.2.1.3
+void writePROJECTLCIDINVOKE(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x0008); // id
+    rStrm.WriteUInt16(0x0014); // id
     rStrm.WriteUInt32(0x00000004); // size
-    rStrm.WriteUInt32(0x00000000); // ProjectLibFlags
+    rStrm.WriteUInt32(0x00000409); // LcidInvoke
 }
 
-//section 2.3.4.2.1.8
-void writePROJECTHELPCONTEXT(SvStream& rStrm)
+// section 2.3.4.2.1.4
+void writePROJECTCODEPAGE(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x0007); // id
-    rStrm.WriteUInt32(0x00000004); // size
-    rStrm.WriteUInt32(0x00000000); // HelpContext
+    rStrm.WriteUInt16(0x0003); // id
+    rStrm.WriteUInt32(0x00000002); // size
+    rStrm.WriteUInt16(CODEPAGE_MS); // CodePage
 }
 
-//section 2.3.4.2.1.7
-void writePROJECTHELPFILEPATH(SvStream& rStrm)
+//section 2.3.4.2.1.5
+void writePROJECTNAME(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x0006); // id
-    rStrm.WriteUInt32(0x00000000); // sizeOfHelpFile1
-    rStrm.WriteUInt16(0x003D); // Reserved
-    rStrm.WriteUInt32(0x00000000); // sizeOfHelpFile2
+    rStrm.WriteUInt16(0x0004); // id
+    sal_uInt32 sizeOfProjectName = 0x0000000a; // for project name "VBAProject"
+    rStrm.WriteUInt32(sizeOfProjectName); // sizeOfProjectName
+    exportString(rStrm, "VBAProject"); // ProjectName
 }
 
 //section 2.3.4.2.1.6
@@ -430,46 +428,47 @@ void writePROJECTDOCSTRING(SvStream& rStrm)
     rStrm.WriteUInt32(0x00000000); // sizeOfDocStringUnicode, MUST be even
 }
 
-//section 2.3.4.2.1.5
-void writePROJECTNAME(SvStream& rStrm)
+//section 2.3.4.2.1.7
+void writePROJECTHELPFILEPATH(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x0004); // id
-    sal_uInt32 sizeOfProjectName = 0x0000000a; // for project name "VBAProject"
-    rStrm.WriteUInt32(sizeOfProjectName); // sizeOfProjectName
-    //characters of "VBAProject" in MBCS character encodings
-    exportString(rStrm, "VBAProject");
+    rStrm.WriteUInt16(0x0006); // id
+    rStrm.WriteUInt32(0x00000000); // sizeOfHelpFile1
+    rStrm.WriteUInt16(0x003D); // Reserved
+    rStrm.WriteUInt32(0x00000000); // sizeOfHelpFile2
 }
 
-// section 2.3.4.2.1.4
-void writePROJECTCODEPAGE(SvStream& rStrm)
+//section 2.3.4.2.1.8
+void writePROJECTHELPCONTEXT(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x0003); // id
-    rStrm.WriteUInt32(0x00000002); // size
-    rStrm.WriteUInt16(CODEPAGE_MS); // CodePage
+    rStrm.WriteUInt16(0x0007); // id
+    rStrm.WriteUInt32(0x00000004); // size
+    rStrm.WriteUInt32(0x00000000); // HelpContext
 }
 
-// section 2.3.4.2.1.3
-void writePROJECTLCIDINVOKE(SvStream& rStrm)
+//section 2.3.4.2.1.9
+void writePROJECTLIBFLAGS(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x0014); // id
+    rStrm.WriteUInt16(0x0008); // id
     rStrm.WriteUInt32(0x00000004); // size
-    rStrm.WriteUInt32(0x00000409); // LcidInvoke
+    rStrm.WriteUInt32(0x00000000); // ProjectLibFlags
 }
 
-// section 2.3.4.2.1.2
-void writePROJECTLCID(SvStream& rStrm)
+//section 2.3.4.2.1.10
+void writePROJECTVERSION(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x0002); // id
-    rStrm.WriteUInt32(0x00000004); // size
-    rStrm.WriteUInt32(0x00000409); // Lcid
+    rStrm.WriteUInt16(0x0009); // id
+    rStrm.WriteUInt32(0x00000004); // Reserved
+    rStrm.WriteUInt32(1467127224); // VersionMajor // TODO: where is this magic number comming from
+    rStrm.WriteUInt16(5); // VersionMinor // TODO: where is this magic number coming from
 }
 
-// section 2.3.4.2.1.1
-void writePROJECTSYSKIND(SvStream& rStrm)
+//section 2.3.4.2.1.11
+void writePROJECTCONSTANTS(SvStream& rStrm)
 {
-    rStrm.WriteUInt16(0x0001); // id
-    rStrm.WriteUInt32(0x00000004); // size
-    rStrm.WriteUInt32(0x00000001); // SysKind, hard coded to 32-bin windows for now
+    rStrm.WriteUInt16(0x000C); // id
+    rStrm.WriteUInt32(0x00000000); // sizeOfConstants
+    rStrm.WriteUInt16(0x003C); // Reserved
+    rStrm.WriteUInt32(0x00000000); // sizeOfConstantsUnicode
 }
 
 // section 2.3.4.2.1
@@ -488,10 +487,34 @@ void writePROJECTINFORMATION(SvStream& rStrm)
     writePROJECTCONSTANTS(rStrm);
 }
 
+// section 2.3.4.2.2.2
+void writeREFERENCENAME(SvStream& rStrm)
+{
+    rStrm.WriteUInt16(0x0016); // id
+    rStrm.WriteUInt32(6); // sizeOfName
+    exportString(rStrm, "stdole"); // name
+    rStrm.WriteUInt16(0x003E); // reserved
+    rStrm.WriteUInt32(12); // sizeOfNameUnicode
+    exportUTF16String(rStrm, "stdole"); // nameUnicode
+}
+
+// section 2.3.4.2.2.1
+void writeREFERENCE(SvStream& rStrm)
+{
+    writeREFERENCENAME(rStrm);
+}
+
+// section 2.3.4.2.2
+void writePROJECTREFERENCES(SvStream& rStrm)
+{
+    writeREFERENCE(rStrm);
+}
+
 // section 2.3.4.2
 void exportDirStream(SvStream& rStrm)
 {
     writePROJECTINFORMATION(rStrm);
+    writePROJECTREFERENCES(rStrm);
 }
 
 }
commit 9f11d60e14e964d71be8699cee3557492638b101
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Aug 14 11:41:35 2015 +0200

    implement VBA Compression algorithm
    
    Change-Id: I0c60244f27d27cf0c97199ff5bf392d157164aa5

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 6cdf5a1..601be68 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -46,6 +46,328 @@ void exportUTF16String(SvStream& rStrm, const OUString& rString)
     }
 }
 
+class VBACompressionChunk
+{
+public:
+
+    VBACompressionChunk(SvStream& rCompressedStream, const sal_uInt8* pData, sal_Size nChunkSize);
+
+    void write();
+
+private:
+    SvStream& mrCompressedStream;
+    const sal_uInt8* mpUncompressedData;
+    sal_uInt8* mpCompressedChunkStream;
+
+    // same as DecompressedChunkEnd in the spec
+    sal_Size mnChunkSize;
+
+    // CompressedCurrent according to the spec
+    sal_uInt64 mnCompressedCurrent;
+
+    // CompressedEnd according to the spec
+    sal_uInt64 mnCompressedEnd;
+
+    // DecompressedCurrent according to the spec
+    sal_uInt64 mnDecompressedCurrent;
+
+    // DecompressedEnd according to the spec
+    sal_uInt64 mnDecompressedEnd;
+
+    // Start of the current decompressed chunk
+    sal_uInt64 mnChunkStart;
+
+    void PackCompressedChunkSize(size_t nSize, sal_uInt16& rHeader);
+
+    void PackCompressedChunkFlag(bool bCompressed, sal_uInt16& rHeader);
+
+    void PackCompressedChunkSignature(sal_uInt16& rHeader);
+
+    void compressTokenSequence();
+
+    void compressToken(size_t index, sal_uInt8& nFlagByte);
+
+    void SetFlagBit(size_t index, bool bVal, sal_uInt8& rFlag);
+
+    sal_uInt16 CopyToken(size_t nLength, size_t nOffset);
+
+    void match(size_t& rLength, size_t& rOffset);
+
+    void CopyTokenHelp(sal_uInt16& rLengthMask, sal_uInt16& rOffsetMask,
+            sal_uInt16& rBitCount, sal_uInt16& rMaximumLength);
+
+    void writeRawChunk();
+};
+
+VBACompressionChunk::VBACompressionChunk(SvStream& rCompressedStream, const sal_uInt8* pData, sal_Size nChunkSize):
+    mrCompressedStream(rCompressedStream),
+    mpUncompressedData(pData),
+    mnChunkSize(nChunkSize)
+{
+}
+
+// section 2.4.1.3.7
+void VBACompressionChunk::write()
+{
+    mnChunkStart = mrCompressedStream.Tell();
+
+    // we need to fill these two bytes later
+    mrCompressedStream.WriteUInt16(0x0);
+
+    mnDecompressedCurrent = 0;
+    mnCompressedCurrent = 2;
+    mnCompressedEnd = 4098;
+    mnDecompressedEnd = std::min<sal_uInt64>(4096, mnChunkSize);
+
+    // if that stream becomes larger than 4096 bytes then
+    // we use the uncompressed stream
+    sal_uInt8 pCompressedChunkStream[4098];
+    mpCompressedChunkStream = pCompressedChunkStream;
+
+    while (mnDecompressedCurrent < mnDecompressedEnd
+            && mnCompressedCurrent < mnCompressedEnd)
+    {
+        // compress token sequence
+        compressTokenSequence();
+    }
+
+    bool bCompressedFlag = true;
+    if (mnDecompressedCurrent < mnDecompressedEnd)
+    {
+        writeRawChunk();
+        bCompressedFlag = false;
+    }
+    else
+    {
+        // copy the compressed stream to our output stream
+        mrCompressedStream.Write(pCompressedChunkStream, mnCompressedCurrent);
+    }
+
+    // handle header bytes
+    size_t nSize = mnCompressedCurrent;
+    sal_uInt16 nHeader = 0;
+    PackCompressedChunkSize(nSize, nHeader);
+    PackCompressedChunkFlag(bCompressedFlag, nHeader);
+    PackCompressedChunkSignature(nHeader);
+
+    // overwrite the two bytes
+    sal_uInt64 nEnd = mrCompressedStream.Tell();
+    mrCompressedStream.Seek(mnChunkStart);
+    mrCompressedStream.WriteUInt16(nHeader);
+    mrCompressedStream.Seek(nEnd);
+}
+
+// section 2.4.1.3.13
+void VBACompressionChunk::PackCompressedChunkSize(size_t nSize, sal_uInt16& rHeader)
+{
+    sal_uInt16 nTemp1 = rHeader & 0xF000;
+    sal_uInt16 nTemp2 = nSize - 3;
+    rHeader = nTemp1 | nTemp2;
+}
+
+// section 2.4.1.3.16
+void VBACompressionChunk::PackCompressedChunkFlag(bool bCompressed, sal_uInt16& rHeader)
+{
+    sal_uInt16 nTemp1 = rHeader & 0x7FFF;
+    sal_uInt16 nTemp2 = ((sal_uInt16)bCompressed) << 15;
+    rHeader = nTemp1 | nTemp2;
+}
+
+// section 2.4.1.3.14
+void VBACompressionChunk::PackCompressedChunkSignature(sal_uInt16& rHeader)
+{
+    sal_Int32 nTemp = rHeader & 0x8FFFF;
+    rHeader = nTemp | 0x3000;
+}
+
+// section 2.4.1.3.8
+void VBACompressionChunk::compressTokenSequence()
+{
+    sal_uInt64 nFlagByteIndex = mnCompressedCurrent;
+    sal_uInt8 nFlagByte = 0;
+    ++mnCompressedCurrent;
+    for (size_t index = 0; index <= 7; ++index)
+    {
+        if (mnDecompressedCurrent < mnDecompressedEnd
+                && mnCompressedCurrent < mnCompressedEnd)
+        {
+            compressToken(index, nFlagByte);
+        }
+    }
+    mpCompressedChunkStream[nFlagByteIndex] = nFlagByte;
+}
+
+void setUInt16(sal_uInt8* pBuffer, size_t nPos, sal_uInt16 nVal)
+{
+    pBuffer[nPos] = nVal & 0xFFFF;
+    pBuffer[nPos+1] = (nVal & 0xFFFF0000) >> 8;
+}
+
+// section 2.4.1.3.9
+void VBACompressionChunk::compressToken(size_t index, sal_uInt8& nFlagByte)
+{
+    size_t nLength = 0;
+    size_t nOffset = 0;
+    match(nLength, nOffset);
+    if (nOffset != 0)
+    {
+        if (mnCompressedCurrent + 1 < mnCompressedEnd)
+        {
+            sal_uInt16 nToken = CopyToken(nLength, nOffset);
+            setUInt16(mpCompressedChunkStream, mnCompressedCurrent, nToken);
+            SetFlagBit(index, 1, nFlagByte);
+            mnCompressedCurrent += 2;
+            mnDecompressedCurrent += nLength;
+        }
+        else
+        {
+            mnCompressedCurrent = mnCompressedEnd;
+        }
+    }
+    else
+    {
+        if (mnCompressedCurrent + 1 < mnCompressedEnd)
+        {
+            mpCompressedChunkStream[mnCompressedCurrent] = mpUncompressedData[mnDecompressedCurrent];
+            ++mnCompressedCurrent;
+            ++mnDecompressedCurrent;
+        }
+        else
+        {
+            mnCompressedCurrent = mnCompressedEnd;
+        }
+    }
+}
+
+// section 2.4.1.3.18
+void VBACompressionChunk::SetFlagBit(size_t index, bool bVal, sal_uInt8& rFlag)
+{
+    size_t nTemp1 = ((int)bVal) << index;
+    sal_uInt8 nTemp2 = rFlag & (~nTemp1);
+    rFlag = nTemp2 | nTemp1;
+}
+
+// section 2.4.1.3.19.3
+sal_uInt16 VBACompressionChunk::CopyToken(size_t nLength, size_t nOffset)
+{
+    sal_uInt16 nLengthMask = 0;
+    sal_uInt16 nOffsetMask = 0;
+    sal_uInt16 nBitCount = 0;
+    sal_uInt16 nMaxLength;
+    CopyTokenHelp(nLengthMask, nOffsetMask, nBitCount, nMaxLength);
+    sal_uInt16 nTemp1 = nOffset -1;
+    sal_uInt16 nTemp2 = 16 - nBitCount;
+    sal_uInt16 nTemp3 = nLength - 3;
+    sal_uInt16 nToken = (nTemp1 << nTemp2) | nTemp3;
+    return nToken;
+}
+
+// section 2.4.1.3.19.4
+void VBACompressionChunk::match(size_t& rLength, size_t& rOffset)
+{
+    size_t nBestLen = 0;
+    sal_Int32 nCandidate = mnDecompressedCurrent - 1;
+    sal_Int32 nBestCandidate = nCandidate;
+    while (nCandidate >= 0)
+    {
+        sal_Int32 nC = nCandidate;
+        sal_Int32 nD = mnDecompressedCurrent;
+        size_t nLen = 0;
+        while (nD < static_cast<sal_Int32>(mnChunkSize) // TODO: check if this needs to be including a minus -1
+                && mpUncompressedData[nC] == mpUncompressedData[nD])
+        {
+            ++nLen;
+            ++nC;
+            ++nD;
+        }
+        if (nLen > nBestLen)
+        {
+            nBestLen = nLen;
+            nBestCandidate = nCandidate;
+        }
+        --nCandidate;
+    }
+
+    if (nBestLen >= 3)
+    {
+        sal_uInt16 nMaximumLength = 0;
+        sal_uInt16 nLengthMask, nOffsetMask, nBitCount;
+        CopyTokenHelp(nLengthMask, nOffsetMask, nBitCount, nMaximumLength);
+        rLength = std::min<sal_uInt16>(nMaximumLength, nBestLen);
+        rOffset = mnDecompressedCurrent - nBestCandidate;
+    }
+    else
+    {
+        rLength = 0;
+        rOffset = 0;
+    }
+}
+
+// section 2.4.1.3.19.1
+void VBACompressionChunk::CopyTokenHelp(sal_uInt16& rLengthMask, sal_uInt16& rOffsetMask,
+        sal_uInt16& rBitCount, sal_uInt16& rMaximumLength)
+{
+    sal_uInt16 nDifference = mnDecompressedCurrent;
+    sal_uInt16 nBitCount = std::ceil(std::log2(nDifference));
+    rBitCount = std::max<sal_uInt16>(nBitCount, 4);
+    rLengthMask = 0xffff >> rBitCount;
+    rOffsetMask = ~rLengthMask;
+    rMaximumLength = rLengthMask + 3;
+}
+
+// section 2.4.1.3.10
+void VBACompressionChunk::writeRawChunk()
+{
+    // we need to use up to 4096 bytes of the original stream
+    // and fill the rest with padding
+    mrCompressedStream.Write(mpUncompressedData, mnChunkSize);
+    sal_Size nPadding = 4096 - mnChunkSize;
+    for (size_t i = 0; i < nPadding; ++i)
+    {
+        mrCompressedStream.WriteUInt8(0);
+    }
+}
+
+class VBACompression
+{
+public:
+    VBACompression(SvStream& rCompressedStream,
+            SvMemoryStream& rUncompressedStream);
+
+    void write();
+
+private:
+    SvStream& mrCompressedStream;
+    SvMemoryStream& mrUncompressedStream;
+};
+
+VBACompression::VBACompression(SvStream& rCompressedStream,
+        SvMemoryStream& rUncompressedStream):
+    mrCompressedStream(rCompressedStream),
+    mrUncompressedStream(rUncompressedStream)
+{
+}
+
+// section 2.4.1.3.6
+void VBACompression::write()
+{
+    // section 2.4.1.1.1
+    mrCompressedStream.WriteUInt8(0x01); // signature byte of a compressed container
+    bool bStreamNotEnded = true;
+    const sal_uInt8* pData = (const sal_uInt8*)mrUncompressedStream.GetData();
+    sal_Size nSize = mrUncompressedStream.GetEndOfData();
+    sal_Size nRemainingSize = nSize;
+    while(bStreamNotEnded)
+    {
+        sal_Size nChunkSize = nRemainingSize > 4096 ? 4096 : nRemainingSize;
+        VBACompressionChunk aChunk(mrCompressedStream, &pData[nSize - nRemainingSize], nChunkSize);
+
+        // update the uncompressed chunk start marker
+        nRemainingSize -= nChunkSize;
+        bStreamNotEnded = nRemainingSize != 0;
+    }
+}
+
 }
 
 VbaExport::VbaExport(css::uno::Reference<css::frame::XModel> xModel):


More information about the Libreoffice-commits mailing list