[ooo-build-commit] .: scratch/mso-dumper
Kohei Yoshida
kohei at kemper.freedesktop.org
Tue Mar 23 13:17:41 PDT 2010
scratch/mso-dumper/src/globals.py | 12 ++++++++++++
scratch/mso-dumper/src/msodraw.py | 33 ++++++++++++++++++++++++++++-----
scratch/mso-dumper/src/xlsmodel.py | 34 ++++++++++++++++++++++++++++++++--
scratch/mso-dumper/src/xlsrecord.py | 34 ++++++++++++++++++++++++++++------
4 files changed, 100 insertions(+), 13 deletions(-)
New commits:
commit 953ceca3d0c05d02cbe968061fc0c7911e8fbd9a
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Tue Mar 23 16:12:20 2010 -0400
[mso-dumper] Output drawing objects in cXML mode.
For now, only display their positions and sizes, so that we can
at least test against disappearing objects.
* scratch/mso-dumper/src/globals.py:
* scratch/mso-dumper/src/msodraw.py:
* scratch/mso-dumper/src/xlsmodel.py:
* scratch/mso-dumper/src/xlsrecord.py:
diff --git a/scratch/mso-dumper/src/globals.py b/scratch/mso-dumper/src/globals.py
index 61631d8..bcabcf4 100644
--- a/scratch/mso-dumper/src/globals.py
+++ b/scratch/mso-dumper/src/globals.py
@@ -31,6 +31,18 @@ class ByteConvertError(Exception): pass
class ByteStreamError(Exception): pass
+
+class ModelBase(object):
+
+ class HostAppType:
+ Word = 0
+ Excel = 1
+ PowerPoint = 2
+
+ def __init__ (self, hostApp):
+ self.hostApp = hostApp
+
+
class Params(object):
"""command-line parameters."""
def __init__ (self):
diff --git a/scratch/mso-dumper/src/msodraw.py b/scratch/mso-dumper/src/msodraw.py
index 07808e7..9a5105d 100644
--- a/scratch/mso-dumper/src/msodraw.py
+++ b/scratch/mso-dumper/src/msodraw.py
@@ -25,7 +25,7 @@
#
########################################################################
-import globals
+import globals, xlsmodel
import sys
def indent (level):
@@ -63,8 +63,8 @@ class RecordHeader:
Type.FDG: 'OfficeArtFDG',
Type.FDGGBlock: 'OfficeArtFDGGBlock',
Type.FOPT: 'OfficeArtFOPT',
- Type.FClientAnchor: 'msofbtClientAnchor',
- Type.FClientData: 'msofbtClientData',
+ Type.FClientAnchor: 'OfficeArtClientAnchor',
+ Type.FClientData: 'OfficeArtClientData',
Type.FSP: 'OfficeArtFSP',
Type.FSPGR: 'OfficeArtFSPGR',
Type.FConnectorRule: 'OfficeArtFConnectorRule',
@@ -499,7 +499,7 @@ class SplitMenuColorContainer:
msocr.appendLines(recHdl, rh)
-class FClientAnchor:
+class FClientAnchorXLS:
"""Excel-specific anchor data"""
def __init__ (self, strm):
@@ -519,6 +519,10 @@ class FClientAnchor:
recHdl.appendLine(" dX1: %d dY1: %d"%(self.dx1, self.dy1))
recHdl.appendLine(" dX2: %d dY2: %d"%(self.dx2, self.dy2))
+ def fillModel (self, model, sheet):
+ obj = xlsmodel.Shape(self.col1, self.row1, self.dx1, self.dy1, self.col2, self.row2, self.dx2, self.dy2)
+ sheet.addShape(obj)
+
# ----------------------------------------------------------------------------
recData = {
@@ -528,7 +532,7 @@ recData = {
RecordHeader.Type.FDGGBlock: FDGGBlock,
RecordHeader.Type.FConnectorRule: FConnectorRule,
RecordHeader.Type.FDGSL: FDGSL,
- RecordHeader.Type.FClientAnchor: FClientAnchor,
+ RecordHeader.Type.FClientAnchor: FClientAnchorXLS,
RecordHeader.Type.SplitMenuColorContainer: SplitMenuColorContainer
}
@@ -577,3 +581,22 @@ class MSODrawHandler(globals.ByteStream):
# unknown object
bytes = self.readBytes(rh.recLen)
self.parent.appendLine(globals.getRawBytes(bytes, True, False))
+
+
+ def fillModel (self, model):
+ sheet = model.getCurrentSheet()
+ while not self.isEndOfRecord():
+ rh = RecordHeader(self)
+ if rh.recVer == 0xF:
+ # container
+ continue
+
+ if rh.recType == RecordHeader.Type.FClientAnchor and \
+ model.hostApp == globals.ModelBase.HostAppType.Excel:
+ obj = FClientAnchorXLS(self)
+ obj.fillModel(model, sheet)
+ else:
+ # unknown object
+ bytes = self.readBytes(rh.recLen)
+
+
diff --git a/scratch/mso-dumper/src/xlsmodel.py b/scratch/mso-dumper/src/xlsmodel.py
index 977c14a..876572e 100644
--- a/scratch/mso-dumper/src/xlsmodel.py
+++ b/scratch/mso-dumper/src/xlsmodel.py
@@ -33,8 +33,9 @@ class ModelType:
Unknown = 999
-class ModelBase(object):
+class ModelBase(globals.ModelBase):
def __init__ (self, modelType=ModelType.Unknown):
+ globals.ModelBase.__init__(self, globals.ModelBase.HostAppType.Excel)
self.modelType = modelType
@@ -186,6 +187,17 @@ class WorkbookGlobal(SheetBase):
return self.__dbRanges[sheetID]
+class Shape(object):
+ def __init__ (self, col1, row1, dx1, dy1, col2, row2, dx2, dy2):
+ self.col1 = col1
+ self.row1 = row1
+ self.dx1 = dx1
+ self.dy1 = dy1
+ self.col2 = col2
+ self.row2 = row2
+ self.dx2 = dx2
+ self.dy2 = dy2
+
class Worksheet(SheetBase):
class OrderedRangeList(object):
@@ -220,6 +232,10 @@ class Worksheet(SheetBase):
self.__firstFreeCell = None
self.__hiddenRows = Worksheet.OrderedRangeList()
self.__rowHeights = Worksheet.OrderedRangeList()
+ self.__shapes = []
+
+ def addShape (self, obj):
+ self.__shapes.append(obj)
def setFirstDefinedCell (self, col, row):
self.__firstDefinedCell = formula.CellAddress(col, row)
@@ -277,7 +293,7 @@ class Worksheet(SheetBase):
self.__appendAutoFilterNode(wb, nd) # autofilter (if exists)
self.__appendHiddenRowsNode(wb, nd) # hidden rows
self.__appendRowHeightNode(wb, nd) # row heights
-
+ self.__appendShapesNode(wb, nd) # drawing objects
return nd
def __appendRowHeightNode (self, wb, baseNode):
@@ -329,6 +345,20 @@ class Worksheet(SheetBase):
else:
elem.appendChild(arrowObj.createDOM(wb, cellRange))
+ def __appendShapesNode (self, wb, baseNode):
+ n = len(self.__shapes)
+ if n == 0:
+ # no drawing objects on this sheet.
+ return
+
+ elem = baseNode.appendElement('shapes')
+ for obj in self.__shapes:
+ objElem = elem.appendElement('shape')
+ objElem.setAttr('range', "(col=%d,row=%d)-(col=%d,row=%d)"%(obj.col1,obj.row1,obj.col2,obj.row2))
+ objElem.setAttr('offset-begin', "(dx=%d,dy=%d)"%(obj.dx1,obj.dy1))
+ objElem.setAttr('offset-end', "(dx=%d,dy=%d)"%(obj.dx2,obj.dy2))
+
+
class CellBase(object):
diff --git a/scratch/mso-dumper/src/xlsrecord.py b/scratch/mso-dumper/src/xlsrecord.py
index cd0961e..756197d 100644
--- a/scratch/mso-dumper/src/xlsrecord.py
+++ b/scratch/mso-dumper/src/xlsrecord.py
@@ -2763,21 +2763,43 @@ somewhere in the MSDN website. In case of multiple MSODRAWING records in a
single worksheet stream, they need to be treated as if they are lumped
together.
"""
+ def __parseBytes (self):
+ self.msodHdl = msodraw.MSODrawHandler(self.bytes, self)
def parseBytes (self):
- msodHdl = msodraw.MSODrawHandler(self.bytes, self)
- msodHdl.parseBytes()
+ self.__parseBytes()
+ self.msodHdl.parseBytes()
+
+ def fillModel (self, model):
+ self.__parseBytes()
+ self.msodHdl.fillModel(model)
class MSODrawingGroup(BaseRecordHandler):
+ def __parseBytes (self):
+ self.msodHdl = msodraw.MSODrawHandler(self.bytes, self)
+
def parseBytes (self):
- msoHdl = msodraw.MSODrawHandler(self.bytes, self)
- msoHdl.parseBytes()
+ self.__parseBytes()
+ self.msodHdl.parseBytes()
+
+ def fillModel (self, model):
+ self.__parseBytes()
+ self.msodHdl.fillModel(model)
class MSODrawingSelection(BaseRecordHandler):
+ def __parseBytes (self):
+ self.msodHdl = msodraw.MSODrawHandler(self.bytes, self)
+
+
def parseBytes (self):
- msoHdl = msodraw.MSODrawHandler(self.bytes, self)
- msoHdl.parseBytes()
+ self.__parseBytes()
+ self.msodHdl.parseBytes()
+
+ def fillModel (self, model):
+ self.__parseBytes()
+ self.msodHdl.fillModel(model)
+
More information about the ooo-build-commit
mailing list