src/docdraw.py | 86 ------------------------------------------------------- src/docrecord.py | 6 +-- src/msodraw.py | 85 ++++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 73 insertions(+), 104 deletions(-)
New commits: commit d6204e27511e62cb9c0325efcc8995b68934d9b3 Author: Miklos Vajna <[email protected]> Date: Mon Dec 10 11:46:36 2012 +0100 merge docdraw into msodraw diff --git a/src/docdraw.py b/src/docdraw.py deleted file mode 100644 index 8425498..0000000 --- a/src/docdraw.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -import struct -import globals -import docsprm -import msodraw - -class OfficeArtContainer(globals.ByteStream): - def __init__(self, parent, name, type): - self.bytes = parent.bytes - self.size = len(self.bytes) - self.pos = 0 - self.name = name - self.type = type - self.pos = parent.pos - self.parent = parent - - def dumpXml(self, recHdl, rh = None): - recHdl.appendLine('<%s type="%s">' % (self.name, self.type)) - if rh: - self.rh = rh - else: - self.rh = msodraw.RecordHeader(self) - self.rh.dumpXml(self) - base = self.pos - while (self.rh.recLen - (self.pos - base)) > 0: - rh = msodraw.RecordHeader(self) - rh.dumpXml(self) - saved = self.pos - if rh.recType in recMap: - child = recMap[rh.recType](self) - child.dumpXml(self, rh) - else: - recHdl.appendLine('<todo what="%s: recType = %s unhandled (size: %d bytes)"/>' % (self.type, hex(rh.recType), rh.recLen)) - self.pos = saved + rh.recLen - recHdl.appendLine('</%s>' % self.name) - self.parent.pos = self.pos - - def appendLine(self, line): - self.parent.appendLine(line) - -class OfficeArtDggContainer(OfficeArtContainer): - """The OfficeArtDggContainer record type specifies the container for all the OfficeArt file records that contain document-wide data.""" - def __init__(self, officeArtContent, name): - OfficeArtContainer.__init__(self, officeArtContent, name, "OfficeArtDggContainer") - -class OfficeArtDgContainer(OfficeArtContainer): - """The OfficeArtDgContainer record specifies the container for all the file records for the objects in a drawing.""" - def __init__(self, officeArtContent, name): - OfficeArtContainer.__init__(self, officeArtContent, name, "OfficeArtDgContainer") - -class OfficeArtSpContainer(OfficeArtContainer): - """The OfficeArtSpContainer record specifies a shape container.""" - def __init__(self, parent): - OfficeArtContainer.__init__(self, parent, "shape", "OfficeArtSpContainer") - -class OfficeArtSpgrContainer(OfficeArtContainer): - """The OfficeArtSpgrContainer record specifies a container for groups of shapes.""" - def __init__(self, officeArtDgContainer): - OfficeArtContainer.__init__(self, officeArtDgContainer, "groupShape", "OfficeArtSpgrContainer") - -recMap = { - 0xf003: OfficeArtSpgrContainer, - 0xf004: OfficeArtSpContainer, - 0xf006: msodraw.FDGGBlock, - 0xf008: msodraw.FDG, - 0xf009: msodraw.FSPGR, - 0xf00a: msodraw.FSP, - 0xf00b: msodraw.FOPT, - 0xf011: msodraw.FClientData, - 0xf11e: msodraw.SplitMenuColorContainer, - } - -# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab: diff --git a/src/docrecord.py b/src/docrecord.py index 4e7beb9..cc53b04 100644 --- a/src/docrecord.py +++ b/src/docrecord.py @@ -9,7 +9,7 @@ import struct import globals from docdirstream import DOCDirStream import docsprm -import docdraw +import msodraw class FcCompressed(DOCDirStream): """The FcCompressed structure specifies the location of text in the WordDocument Stream.""" @@ -1575,7 +1575,7 @@ class OfficeArtWordDrawing(DOCDirStream): def dump(self): print '<officeArtWordDrawing type="OfficeArtWordDrawing" pos="%d">' % self.pos self.printAndSet("dgglbl", self.readuInt8()) - docdraw.OfficeArtDgContainer(self, "container").dumpXml(self) + msodraw.DgContainer(self, "container").dumpXml(self) print '</officeArtWordDrawing>' self.officeArtContent.pos = self.pos @@ -1589,7 +1589,7 @@ class OfficeArtContent(DOCDirStream): def dump(self): print '<officeArtContent type="OfficeArtContent" offset="%d" size="%d bytes">' % (self.pos, self.size) - docdraw.OfficeArtDggContainer(self, "DrawingGroupData").dumpXml(self) + msodraw.DggContainer(self, "DrawingGroupData").dumpXml(self) print '<Drawings type="main" offset="%d">' % self.pos OfficeArtWordDrawing(self).dump() print '</Drawings>' diff --git a/src/msodraw.py b/src/msodraw.py index 5154767..1a4707e 100644 --- a/src/msodraw.py +++ b/src/msodraw.py @@ -690,26 +690,18 @@ class FClientAnchorSheet: # ---------------------------------------------------------------------------- -recData = { - RecordHeader.Type.FDG: FDG, - RecordHeader.Type.FSPGR: FSPGR, - RecordHeader.Type.FSP: FSP, - RecordHeader.Type.FOPT: FOPT, - RecordHeader.Type.FDGGBlock: FDGGBlock, - RecordHeader.Type.FConnectorRule: FConnectorRule, - RecordHeader.Type.FDGSL: FDGSL, - RecordHeader.Type.FClientAnchor: FClientAnchorSheet, - RecordHeader.Type.FClientData: FClientData, - RecordHeader.Type.SplitMenuColorContainer: SplitMenuColorContainer -} - class MSODrawHandler(globals.ByteStream): - def __init__ (self, bytes, parent): - """The 'parent' instance must have appendLine() method that takes one string argument.""" + def __init__ (self, bytes, parent, name = None, type = None): + """The 'parent' instance must have appendLine() method that takes one string argument. + The optional parameters are used by dumpXml() only.""" globals.ByteStream.__init__(self, bytes) self.parent = parent + if name and type: + self.name = name + self.type = type + self.pos = parent.pos def parseBytes (self): while not self.isEndOfRecord(): @@ -746,5 +738,68 @@ class MSODrawHandler(globals.ByteStream): # unknown object bytes = self.readBytes(rh.recLen) + def dumpXml (self, recHdl, rh = None): + recHdl.appendLine('<%s type="%s">' % (self.name, self.type)) + if rh: + self.rh = rh + else: + self.rh = RecordHeader(self) + self.rh.dumpXml(self) + base = self.pos + while (self.rh.recLen - (self.pos - base)) > 0: + rh = RecordHeader(self) + rh.dumpXml(self) + saved = self.pos + if rh.recType in recData: + child = recData[rh.recType](self) + child.dumpXml(self, rh) + else: + recHdl.appendLine('<todo what="%s: recType = %s unhandled (size: %d bytes)"/>' % (self.type, hex(rh.recType), rh.recLen)) + self.pos = saved + rh.recLen + recHdl.appendLine('</%s>' % self.name) + self.parent.pos = self.pos + + def appendLine(self, line): + self.parent.appendLine(line) + + +class DggContainer(MSODrawHandler): + """The OfficeArtDggContainer record type specifies the container for all the OfficeArt file records that contain document-wide data.""" + def __init__(self, officeArtContent, name): + MSODrawHandler.__init__(self, officeArtContent.bytes, officeArtContent, name, "OfficeArtDggContainer") + + +class DgContainer(MSODrawHandler): + """The OfficeArtDgContainer record specifies the container for all the file records for the objects in a drawing.""" + def __init__(self, officeArtContent, name): + MSODrawHandler.__init__(self, officeArtContent.bytes, officeArtContent, name, "OfficeArtDgContainer") + + +class SpContainer(MSODrawHandler): + """The OfficeArtSpContainer record specifies a shape container.""" + def __init__(self, parent): + MSODrawHandler.__init__(self, parent.bytes, parent, "shape", "OfficeArtSpContainer") + + +class SpgrContainer(MSODrawHandler): + """The OfficeArtSpgrContainer record specifies a container for groups of shapes.""" + def __init__(self, officeArtDgContainer): + MSODrawHandler.__init__(self, officeArtDgContainer.bytes, officeArtDgContainer, "groupShape", "OfficeArtSpgrContainer") + + +recData = { + RecordHeader.Type.spgrContainer: SpgrContainer, + RecordHeader.Type.spContainer: SpContainer, + RecordHeader.Type.FDG: FDG, + RecordHeader.Type.FSPGR: FSPGR, + RecordHeader.Type.FSP: FSP, + RecordHeader.Type.FOPT: FOPT, + RecordHeader.Type.FDGGBlock: FDGGBlock, + RecordHeader.Type.FConnectorRule: FConnectorRule, + RecordHeader.Type.FDGSL: FDGSL, + RecordHeader.Type.FClientAnchor: FClientAnchorSheet, + RecordHeader.Type.FClientData: FClientData, + RecordHeader.Type.SplitMenuColorContainer: SplitMenuColorContainer +} # vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab: commit eaf1a03aed1a724d5e103bcd544142426208f4c3 Author: Miklos Vajna <[email protected]> Date: Mon Dec 10 11:29:49 2012 +0100 docdraw: get rid of unnecessary seeks diff --git a/src/docdraw.py b/src/docdraw.py index de46109..8425498 100644 --- a/src/docdraw.py +++ b/src/docdraw.py @@ -27,26 +27,19 @@ class OfficeArtContainer(globals.ByteStream): else: self.rh = msodraw.RecordHeader(self) self.rh.dumpXml(self) - pos = self.pos - while (self.rh.recLen - (pos - self.pos)) > 0: - posOrig = self.pos - self.pos = pos + base = self.pos + while (self.rh.recLen - (self.pos - base)) > 0: rh = msodraw.RecordHeader(self) rh.dumpXml(self) - self.pos = posOrig - pos += msodraw.RecordHeader.size + saved = self.pos if rh.recType in recMap: - posOrig = self.pos - self.pos = pos child = recMap[rh.recType](self) child.dumpXml(self, rh) - self.pos = posOrig else: recHdl.appendLine('<todo what="%s: recType = %s unhandled (size: %d bytes)"/>' % (self.type, hex(rh.recType), rh.recLen)) - pos += rh.recLen + self.pos = saved + rh.recLen recHdl.appendLine('</%s>' % self.name) - assert pos == self.pos + self.rh.recLen - self.parent.pos = pos + self.parent.pos = self.pos def appendLine(self, line): self.parent.appendLine(line) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
