[Libreoffice-commits] mso-dumper.git: 4 commits - msodumper/docdirstream.py msodumper/emfrecord.py msodumper/wmfrecord.py

Miklos Vajna vmiklos at collabora.co.uk
Sun Apr 13 10:13:16 PDT 2014


 msodumper/docdirstream.py |   14 ++++
 msodumper/emfrecord.py    |  132 ++++++++++++++++++++++++++++++++++++++++++++--
 msodumper/wmfrecord.py    |   42 ++++++++++++++
 3 files changed, 183 insertions(+), 5 deletions(-)

New commits:
commit 253852226a367057fbe99a51f2a906a48ece57eb
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sun Apr 13 19:12:26 2014 +0200

    dump EmrCreatebrushindirect

diff --git a/msodumper/emfrecord.py b/msodumper/emfrecord.py
index 82bbcd3..8875c9e 100644
--- a/msodumper/emfrecord.py
+++ b/msodumper/emfrecord.py
@@ -81,6 +81,56 @@ class EmrRestoredc(EMFRecord):
         assert self.pos - posOrig == self.Size
 
 
+class EmrCreatebrushindirect(EMFRecord):
+    """Defines a logical brush with a LogBrushEx object."""
+    def __init__(self, parent):
+        EMFRecord.__init__(self, parent)
+
+    def dump(self):
+        posOrig = self.pos
+        self.printAndSet("Type", self.readuInt32())
+        self.printAndSet("Size", self.readuInt32(), hexdump=False)
+        self.printAndSet("ihBrush", self.readuInt32(), hexdump=False)
+        LogBrushEx(self, "LogBrush").dump()
+        assert self.pos - posOrig == self.Size
+
+
+# The HatchStyle enumeration is an extension to the WMF HatchStyle enumeration.
+EmfHatchStyle = {
+    0x0006: "HS_SOLIDCLR",
+    0x0007: "HS_DITHEREDCLR",
+    0x0008: "HS_SOLIDTEXTCLR",
+    0x0009: "HS_DITHEREDTEXTCLR",
+    0x000A: "HS_SOLIDBKCLR",
+    0x000B: "HS_DITHEREDBKCLR"
+}
+HatchStyle = dict(wmfrecord.HatchStyle.items() + EmfHatchStyle.items())
+
+
+class LogBrushEx(EMFRecord):
+    """The LogBrushEx object defines the style, color, and pattern of a device-independent brush."""
+    def __init__(self, parent, name):
+        EMFRecord.__init__(self, parent)
+        self.name = name
+
+    def dump(self):
+        posOrig = self.pos
+        print '<%s>' % self.name
+        self.printAndSet("BrushStyle", self.readuInt32(), dict=wmfrecord.BrushStyle)
+        wmfrecord.ColorRef(self, "Color").dump()
+        self.printAndSet("BrushHatch", self.readuInt32(), dict=HatchStyle)
+        print '</%s>' % self.name
+        self.parent.pos = self.pos
+
+
+ModifyWorldTransformMode = {
+    0x01: "MWT_IDENTITY",
+    0x02: "MWT_LEFTMULTIPLY",
+    0x03: "MWT_RIGHTMULTIPLY",
+    0x04: "MWT_SET"
+}
+
+
 class EmrModifyworldtransform(EMFRecord):
     """Modifies the current world-space to page-space transform."""
     def __init__(self, parent):
@@ -91,7 +141,8 @@ class EmrModifyworldtransform(EMFRecord):
         self.printAndSet("Type", self.readuInt32())
         self.printAndSet("Size", self.readuInt32(), hexdump=False)
         XForm(self, "Xform").dump()
-        #assert self.pos - posOrig == self.Size
+        self.printAndSet("ModifyWorldTransformMode", self.readuInt32(), dict=ModifyWorldTransformMode)
+        assert self.pos - posOrig == self.Size
 
 
 class XForm(EMFRecord):
@@ -327,7 +378,7 @@ RecordType = {
     0x00000024: ['EMR_MODIFYWORLDTRANSFORM', EmrModifyworldtransform],
     0x00000025: ['EMR_SELECTOBJECT'],
     0x00000026: ['EMR_CREATEPEN'],
-    0x00000027: ['EMR_CREATEBRUSHINDIRECT'],
+    0x00000027: ['EMR_CREATEBRUSHINDIRECT', EmrCreatebrushindirect],
     0x00000028: ['EMR_DELETEOBJECT'],
     0x00000029: ['EMR_ANGLEARC'],
     0x0000002A: ['EMR_ELLIPSE'],
diff --git a/msodumper/wmfrecord.py b/msodumper/wmfrecord.py
index cd0b353..5cfcb1d 100644
--- a/msodumper/wmfrecord.py
+++ b/msodumper/wmfrecord.py
@@ -8,6 +8,32 @@
 from docdirstream import DOCDirStream
 
 
+# The BrushStyle Enumeration specifies the different possible brush types that can be used in graphics operations.
+BrushStyle = {
+    0x0000: "BS_SOLID",
+    0x0001: "BS_NULL",
+    0x0002: "BS_HATCHED",
+    0x0003: "BS_PATTERN",
+    0x0004: "BS_INDEXED",
+    0x0005: "BS_DIBPATTERN",
+    0x0006: "BS_DIBPATTERNPT",
+    0x0007: "BS_PATTERN8X8",
+    0x0008: "BS_DIBPATTERN8X8",
+    0x0009: "BS_MONOPATTERN"
+}
+
+
+# The HatchStyle Enumeration specifies the hatch pattern.
+HatchStyle = {
+    0x0000: "HS_HORIZONTAL",
+    0x0001: "HS_VERTICAL",
+    0x0002: "HS_FDIAGONAL",
+    0x0003: "HS_BDIAGONAL",
+    0x0004: "HS_CROSS",
+    0x0005: "HS_DIAGCROSS"
+}
+
+
 class WMFRecord(DOCDirStream):
     def __init__(self, parent):
         DOCDirStream.__init__(self, parent.bytes)
@@ -67,4 +93,20 @@ class PointL(WMFRecord):
         print '</%s>' % self.name
         self.parent.pos = self.pos
 
+
+class ColorRef(WMFRecord):
+    """The ColorRef Object defines the RGB color."""
+    def __init__(self, parent, name):
+        WMFRecord.__init__(self, parent)
+        self.name = name
+
+    def dump(self):
+        print '<%s type="ColorRef">' % self.name
+        self.printAndSet("Red", self.readuInt8(), hexdump=False)
+        self.printAndSet("Green", self.readuInt8(), hexdump=False)
+        self.printAndSet("Blue", self.readuInt8(), hexdump=False)
+        self.printAndSet("Reserved", self.readuInt8(), hexdump=False)
+        print '</%s>' % self.name
+        self.parent.pos = self.pos
+
 # vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab:
commit 9f04fbec4e1c7c9b98712537970854cd7d56ad35
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sun Apr 13 18:40:31 2014 +0200

    dump EmrModifyworldtransform

diff --git a/msodumper/docdirstream.py b/msodumper/docdirstream.py
index 61b0723..c9aa3d5 100644
--- a/msodumper/docdirstream.py
+++ b/msodumper/docdirstream.py
@@ -32,7 +32,7 @@ class DOCDirStream:
                 attrs += ' name="%s"' % dict[value]
             else:
                 attrs += ' name="%s"' % default
-        if hexdump:
+        if hexdump and type(value) != float:
             value = hex(value)
         if offset:
             attrs += ' offset="%s"' % hex(self.pos)
@@ -109,6 +109,18 @@ class DOCDirStream:
         self.pos += 4
         return ret
 
+    def getFloat32(self, bytes=None, pos=None):
+        if not bytes:
+            bytes = self.bytes
+        if not pos:
+            pos = self.pos
+        return struct.unpack("<f", bytes[pos:pos + 4])[0]
+
+    def readFloat32(self):
+        ret = self.getFloat32()
+        self.pos += 4
+        return ret
+
     def getuInt64(self, bytes=None, pos=None):
         if not bytes:
             bytes = self.bytes
diff --git a/msodumper/emfrecord.py b/msodumper/emfrecord.py
index 7f88277..82bbcd3 100644
--- a/msodumper/emfrecord.py
+++ b/msodumper/emfrecord.py
@@ -81,6 +81,37 @@ class EmrRestoredc(EMFRecord):
         assert self.pos - posOrig == self.Size
 
 
+class EmrModifyworldtransform(EMFRecord):
+    """Modifies the current world-space to page-space transform."""
+    def __init__(self, parent):
+        EMFRecord.__init__(self, parent)
+
+    def dump(self):
+        posOrig = self.pos
+        self.printAndSet("Type", self.readuInt32())
+        self.printAndSet("Size", self.readuInt32(), hexdump=False)
+        XForm(self, "Xform").dump()
+        #assert self.pos - posOrig == self.Size
+
+
+class XForm(EMFRecord):
+    """The XForm object defines a two-dimensional, linear transform matrix."""
+    def __init__(self, parent, name):
+        EMFRecord.__init__(self, parent)
+        self.name = name
+
+    def dump(self):
+        print '<%s>' % self.name
+        self.printAndSet("M11", self.readFloat32())
+        self.printAndSet("M12", self.readFloat32())
+        self.printAndSet("M21", self.readFloat32())
+        self.printAndSet("M22", self.readFloat32())
+        self.printAndSet("Dx", self.readFloat32())
+        self.printAndSet("Dy", self.readFloat32())
+        print '</%s>' % self.name
+        self.parent.pos = self.pos
+
+
 # The ICMMode enumeration defines values that specify when to turn on and off ICM (Image Color Management).
 ICMMode = {
     0x01: "ICM_OFF",
commit fa8053884928ea362801833d68752422c1d10dc0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sun Apr 13 18:30:49 2014 +0200

    dump EmrSeticmmode

diff --git a/msodumper/emfrecord.py b/msodumper/emfrecord.py
index 905f743..7f88277 100644
--- a/msodumper/emfrecord.py
+++ b/msodumper/emfrecord.py
@@ -81,6 +81,28 @@ class EmrRestoredc(EMFRecord):
         assert self.pos - posOrig == self.Size
 
 
+# The ICMMode enumeration defines values that specify when to turn on and off ICM (Image Color Management).
+ICMMode = {
+    0x01: "ICM_OFF",
+    0x02: "ICM_ON",
+    0x03: "ICM_QUERY",
+    0x04: "ICM_DONE_OUTSIDEDC"
+}
+
+
+class EmrSeticmmode(EMFRecord):
+    """Specifies ICM to be enabled, disabled, or queried on the playback device context."""
+    def __init__(self, parent):
+        EMFRecord.__init__(self, parent)
+
+    def dump(self):
+        posOrig = self.pos
+        self.printAndSet("Type", self.readuInt32())
+        self.printAndSet("Size", self.readuInt32(), hexdump=False)
+        self.printAndSet("ICMMode", self.readuInt32(), dict=ICMMode)
+        assert self.pos - posOrig == self.Size
+
+
 class EmrComment(EMFRecord):
     """The EMR_COMMENT record contains arbitrary private data."""
     def __init__(self, parent):
@@ -271,7 +293,7 @@ RecordType = {
     0x00000021: ['EMR_SAVEDC', EmrSavedc],
     0x00000022: ['EMR_RESTOREDC', EmrRestoredc],
     0x00000023: ['EMR_SETWORLDTRANSFORM'],
-    0x00000024: ['EMR_MODIFYWORLDTRANSFORM'],
+    0x00000024: ['EMR_MODIFYWORLDTRANSFORM', EmrModifyworldtransform],
     0x00000025: ['EMR_SELECTOBJECT'],
     0x00000026: ['EMR_CREATEPEN'],
     0x00000027: ['EMR_CREATEBRUSHINDIRECT'],
@@ -332,7 +354,7 @@ RecordType = {
     0x0000005F: ['EMR_EXTCREATEPEN'],
     0x00000060: ['EMR_POLYTEXTOUTA'],
     0x00000061: ['EMR_POLYTEXTOUTW'],
-    0x00000062: ['EMR_SETICMMODE'],
+    0x00000062: ['EMR_SETICMMODE', EmrSeticmmode],
     0x00000063: ['EMR_CREATECOLORSPACE'],
     0x00000064: ['EMR_SETCOLORSPACE'],
     0x00000065: ['EMR_DELETECOLORSPACE'],
commit 34ab55e38c8d5ca736055b7d1c6b4e11d51bdc8c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sun Apr 13 18:24:54 2014 +0200

    dump EmrComment

diff --git a/msodumper/emfrecord.py b/msodumper/emfrecord.py
index 01a9353..905f743 100644
--- a/msodumper/emfrecord.py
+++ b/msodumper/emfrecord.py
@@ -81,6 +81,26 @@ class EmrRestoredc(EMFRecord):
         assert self.pos - posOrig == self.Size
 
 
+class EmrComment(EMFRecord):
+    """The EMR_COMMENT record contains arbitrary private data."""
+    def __init__(self, parent):
+        EMFRecord.__init__(self, parent)
+
+    def dump(self):
+        self.printAndSet("Type", self.readuInt32())
+        self.printAndSet("Size", self.readuInt32(), hexdump=False)
+        self.printAndSet("DataSize", self.readuInt32(), hexdump=False)
+        commentIdentifier = self.getuInt32()
+        if commentIdentifier == 0x00000000:  # EMR_COMMENT_EMFSPOOL
+            print '<todo what="EmrComment::dump(): handle EMR_COMMENT_EMFSPOOL"/>'
+        elif commentIdentifier == 0x2B464D45:  # EMR_COMMENT_EMFPLUS
+            print '<todo what="EmrComment::dump(): handle EMR_COMMENT_EMFPLUS"/>'
+        elif commentIdentifier == 0x43494447:  # EMR_COMMENT_PUBLIC
+            print '<todo what="EmrComment::dump(): handle EMR_COMMENT_PUBLIC"/>'
+        else:
+            print '<todo what="EmrComment::dump(): handle EMR_COMMENT"/>'
+
+
 class EmrSetviewportorgex(EMFRecord):
     """Defines the viewport origin."""
     def __init__(self, parent):
@@ -284,7 +304,7 @@ RecordType = {
     0x00000042: ['EMR_WIDENPATH'],
     0x00000043: ['EMR_SELECTCLIPPATH'],
     0x00000044: ['EMR_ABORTPATH'],
-    0x00000046: ['EMR_COMMENT'],
+    0x00000046: ['EMR_COMMENT', EmrComment],
     0x00000047: ['EMR_FILLRGN'],
     0x00000048: ['EMR_FRAMERGN'],
     0x00000049: ['EMR_INVERTRGN'],


More information about the Libreoffice-commits mailing list