[Libreoffice-commits] .: src/xlsrecord.py src/xlsstream.py
Kohei Yoshida
kohei at kemper.freedesktop.org
Fri Dec 14 15:46:33 PST 2012
src/xlsrecord.py | 230 ++++++++++++++++++++++++++++++-------------------------
src/xlsstream.py | 2
2 files changed, 130 insertions(+), 102 deletions(-)
New commits:
commit ca2e8bee5d40ec5bb0107bb4cfa489add35e0890
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Dec 14 18:47:23 2012 -0500
Handler for SxDXF record. Not complete yet.
Re-used the DXFN parser code from CF.
diff --git a/src/xlsrecord.py b/src/xlsrecord.py
index 40d808d..b81af59 100644
--- a/src/xlsrecord.py
+++ b/src/xlsrecord.py
@@ -148,6 +148,125 @@ records."""
self.hasMoreThan255 = False
self.values = []
+
+class DXFN(object):
+
+ def __init__ (self, strm):
+ bits = strm.readUnsignedInt(4)
+ self.alchNinch = (bits & 0x00000001) != 0 # whether the value of dxfalc.alc MUST be ignored.
+ self.alcvNinch = (bits & 0x00000002) != 0 # whether the value of dxfalc.alcv MUST be ignored.
+ self.wrapNinch = (bits & 0x00000004) != 0 # whether the value of dxfalc.fWrap MUST be ignored.
+ self.trotNinch = (bits & 0x00000008) != 0 # whether the value of dxfalc.trot MUST be ignored.
+ self.kintoNinch = (bits & 0x00000010) != 0 # whether the value of dxfalc.fJustLast MUST be ignored.
+ self.cIndentNinch = (bits & 0x00000020) != 0 # whether the values of dxfalc.cIndent and dxfalc.iIndent MUST be ignored.
+ self.fShrinkNinch = (bits & 0x00000040) != 0 # whether the value of dxfalc.fShrinkToFit MUST be ignored.
+ self.fMergeCellNinch = (bits & 0x00000080) != 0 # whether the value of dxfalc.fMergeCell MUST be ignored.
+ self.lockedNinch = (bits & 0x00000100) != 0 # whether the value of dxfprot.fLocked MUST be ignored.
+ self.hiddenNinch = (bits & 0x00000200) != 0 # whether the value of dxfprot.fHidden MUST be ignored.
+ self.glLeftNinch = (bits & 0x00000400) != 0 # whether the values of dxfbdr.dgLeft and dxfbdr.icvLeft MUST be ignored .
+ self.glRightNinch = (bits & 0x00000800) != 0 # whether the values of dxfbdr.dgRight and dxfbdr.icvRight MUST be ignored.
+ self.glTopNinch = (bits & 0x00001000) != 0 # whether the values of dxfbdr.dgTop and dxfbdr.icvTop MUST be ignored.
+ self.glBottomNinch = (bits & 0x00002000) != 0 # whether the values of dxfbdr.dgBottom and dxfbdr.icvBottom MUST be ignored.
+ self.glDiagDownNinch = (bits & 0x00004000) != 0 # whether the value of dxfbdr.bitDiagDown MUST be ignored.
+ self.glDiagUpNinch = (bits & 0x00008000) != 0 # whether the value of dxfbdr.bitDiagUp MUST be ignored.
+ self.flsNinch = (bits & 0x00010000) != 0 # whether the value of dxfpat.fls MUST be ignored.
+ self.icvFNinch = (bits & 0x00020000) != 0 # whether the value of dxfpat.icvForeground MUST be ignored.
+ self.icvBNinch = (bits & 0x00040000) != 0 # whether the value of dxfpat.icvBackground MUST be ignored.
+ self.ifmtNinch = (bits & 0x00080000) != 0 # whether the value of dxfnum.ifmt MUST be ignored.
+ self.fIfntNinch = (bits & 0x00100000) != 0 # whether the value of dxffntd.ifnt MUST be ignored.
+ self.V = (bits & 0x00200000) != 0 # (unused)
+ self.W = (bits & 0x01C00000) != 0 # (reserved; 3-bits)
+ self.ibitAtrNum = (bits & 0x02000000) != 0 # whether number formatting information is part of this structure.
+ self.ibitAtrFnt = (bits & 0x04000000) != 0 # whether font information is part of this structure.
+ self.ibitAtrAlc = (bits & 0x08000000) != 0 # whether alignment information is part of this structure.
+ self.ibitAtrBdr = (bits & 0x10000000) != 0 # whether border formatting information is part of this structure.
+ self.ibitAtrPat = (bits & 0x20000000) != 0 # whether pattern information is part of this structure.
+ self.ibitAtrProt = (bits & 0x40000000) != 0 # whether rotation information is part of this structure.
+ self.iReadingOrderNinch = (bits & 0x80000000) != 0 # whether the value of dxfalc.iReadingOrder MUST be ignored.
+ bits = strm.readUnsignedInt(2)
+ self.fIfmtUser = (bits & 0x0001) != 0 # When set to 1, dxfnum contains a format string.
+ self.f = (bits & 0x0002) != 0 # (unused)
+ self.fNewBorder = (bits & 0x0004) != 0 # 0=border formats to all cells; 1=border formats to the range outline only
+ self.fZeroInited = (bits & 0x8000) != 0 # whether the value of dxfalc.iReadingOrder MUST be taken into account.
+
+ if self.ibitAtrNum:
+ # DXFNum (number format)
+ if self.fIfmtUser:
+ # DXFNumUser (string)
+ sizeDXFNumUser = strm.readUnsignedInt(2)
+ strBytes = strm.readBytes(sizeDXFNumUser)
+ text, textLen = globals.getRichText(strBytes)
+ self.numFmtName = text
+ else:
+ # DXFNumIFmt
+ strm.readBytes(1) # ignored
+ self.numFmtID = strm.readUnsignedInt(1)
+
+ if self.ibitAtrFnt:
+ # DXFFntD (font information)
+ nameLen = strm.readUnsignedInt(1)
+ if nameLen > 0:
+ # Note the text length may double in case of a double-byte string.
+ curPos = strm.getCurrentPos()
+ self.fontName, nameLen = globals.getRichText(strm.readRemainingBytes(), nameLen)
+ self.setCurrentPos(curPos) # Move back to the pre-text position.
+ self.moveForward(realLen) # Move for exactly the bytes read.
+
+ if 63 - nameLen < 0:
+ raise RecordError
+
+ strm.readBytes(63 - nameLen) # Ignore these bytes.
+ self.fontAttrs = strm.readBytes(16) # I'll process this later.
+ self.fontColor = strm.readUnsignedInt(4)
+ strm.readUnsignedInt(4) # ignored
+ tsNinch = strm.readUnsignedInt(4)
+ sssNinch = strm.readUnsignedInt(4) != 0
+ ulsNinch = strm.readUnsignedInt(4) != 0
+ blsNinch = strm.readUnsignedInt(4) != 0
+ strm.readUnsignedInt(4) # ignored
+ ich = strm.readUnsignedInt(4)
+ cch = strm.readUnsignedInt(4)
+ iFnt = strm.readUnsignedInt(2)
+
+ if self.ibitAtrAlc:
+ # DXFALC (text alignment properties)
+ strm.readUnsignedInt(8)
+
+ if self.ibitAtrBdr:
+ # DXFBdr (border properties)
+ strm.readUnsignedInt(8)
+
+ if self.ibitAtrPat:
+ # DXFPat (pattern and colors)
+ strm.readUnsignedInt(4)
+
+ if self.ibitAtrProt:
+ # DXFProt (protection attributes)
+ strm.readUnsignedInt(2)
+
+ def appendLines (self, hdl):
+ # (TODO: This is not complete)
+ if self.ibitAtrNum:
+ if self.fIfmtUser:
+ hdl.appendLine("number format to use: %s (name)"%self.numFmtName)
+ else:
+ hdl.appendLine("number format to use: %d (ID)"%self.numFmtID)
+
+ if self.fNewBorder:
+ s = "only outline of the range"
+ else:
+ s = "all cells in the range"
+ hdl.appendLineString("border formats applied", s)
+
+
+class DXFN12NoCB(object):
+
+ def __init__ (self, strm):
+ self.dxfn = DXFN(strm)
+
+ def appendLines (self, hdl):
+ self.dxfn.appendLines(hdl)
+
class BaseRecordHandler(globals.ByteStream):
def __init__ (self, header, size, bytes, strmData):
@@ -640,105 +759,11 @@ class CF(BaseRecordHandler):
self.compFunction = self.readUnsignedInt(1)
sizeFormula1 = self.readUnsignedInt(2)
sizeFormula2 = self.readUnsignedInt(2)
- self.__parseDXFN()
+ self.rgbdxf = DXFN(self)
self.formula1 = self.readBytes(sizeFormula1)
self.formula2 = self.readBytes(sizeFormula2)
- def __parseDXFN (self):
-
- bits = self.readUnsignedInt(4)
- self.alchNinch = (bits & 0x00000001) != 0 # whether the value of dxfalc.alc MUST be ignored.
- self.alcvNinch = (bits & 0x00000002) != 0 # whether the value of dxfalc.alcv MUST be ignored.
- self.wrapNinch = (bits & 0x00000004) != 0 # whether the value of dxfalc.fWrap MUST be ignored.
- self.trotNinch = (bits & 0x00000008) != 0 # whether the value of dxfalc.trot MUST be ignored.
- self.kintoNinch = (bits & 0x00000010) != 0 # whether the value of dxfalc.fJustLast MUST be ignored.
- self.cIndentNinch = (bits & 0x00000020) != 0 # whether the values of dxfalc.cIndent and dxfalc.iIndent MUST be ignored.
- self.fShrinkNinch = (bits & 0x00000040) != 0 # whether the value of dxfalc.fShrinkToFit MUST be ignored.
- self.fMergeCellNinch = (bits & 0x00000080) != 0 # whether the value of dxfalc.fMergeCell MUST be ignored.
- self.lockedNinch = (bits & 0x00000100) != 0 # whether the value of dxfprot.fLocked MUST be ignored.
- self.hiddenNinch = (bits & 0x00000200) != 0 # whether the value of dxfprot.fHidden MUST be ignored.
- self.glLeftNinch = (bits & 0x00000400) != 0 # whether the values of dxfbdr.dgLeft and dxfbdr.icvLeft MUST be ignored .
- self.glRightNinch = (bits & 0x00000800) != 0 # whether the values of dxfbdr.dgRight and dxfbdr.icvRight MUST be ignored.
- self.glTopNinch = (bits & 0x00001000) != 0 # whether the values of dxfbdr.dgTop and dxfbdr.icvTop MUST be ignored.
- self.glBottomNinch = (bits & 0x00002000) != 0 # whether the values of dxfbdr.dgBottom and dxfbdr.icvBottom MUST be ignored.
- self.glDiagDownNinch = (bits & 0x00004000) != 0 # whether the value of dxfbdr.bitDiagDown MUST be ignored.
- self.glDiagUpNinch = (bits & 0x00008000) != 0 # whether the value of dxfbdr.bitDiagUp MUST be ignored.
- self.flsNinch = (bits & 0x00010000) != 0 # whether the value of dxfpat.fls MUST be ignored.
- self.icvFNinch = (bits & 0x00020000) != 0 # whether the value of dxfpat.icvForeground MUST be ignored.
- self.icvBNinch = (bits & 0x00040000) != 0 # whether the value of dxfpat.icvBackground MUST be ignored.
- self.ifmtNinch = (bits & 0x00080000) != 0 # whether the value of dxfnum.ifmt MUST be ignored.
- self.fIfntNinch = (bits & 0x00100000) != 0 # whether the value of dxffntd.ifnt MUST be ignored.
- self.V = (bits & 0x00200000) != 0 # (unused)
- self.W = (bits & 0x01C00000) != 0 # (reserved; 3-bits)
- self.ibitAtrNum = (bits & 0x02000000) != 0 # whether number formatting information is part of this structure.
- self.ibitAtrFnt = (bits & 0x04000000) != 0 # whether font information is part of this structure.
- self.ibitAtrAlc = (bits & 0x08000000) != 0 # whether alignment information is part of this structure.
- self.ibitAtrBdr = (bits & 0x10000000) != 0 # whether border formatting information is part of this structure.
- self.ibitAtrPat = (bits & 0x20000000) != 0 # whether pattern information is part of this structure.
- self.ibitAtrProt = (bits & 0x40000000) != 0 # whether rotation information is part of this structure.
- self.iReadingOrderNinch = (bits & 0x80000000) != 0 # whether the value of dxfalc.iReadingOrder MUST be ignored.
- bits = self.readUnsignedInt(2)
- self.fIfmtUser = (bits & 0x0001) != 0 # When set to 1, dxfnum contains a format string.
- self.f = (bits & 0x0002) != 0 # (unused)
- self.fNewBorder = (bits & 0x0004) != 0 # 0=border formats to all cells; 1=border formats to the range outline only
- self.fZeroInited = (bits & 0x8000) != 0 # whether the value of dxfalc.iReadingOrder MUST be taken into account.
-
- if self.ibitAtrNum:
- # DXFNum (number format)
- if self.fIfmtUser:
- # DXFNumUser (string)
- sizeDXFNumUser = self.readUnsignedInt(2)
- strBytes = self.readBytes(sizeDXFNumUser)
- text, textLen = globals.getRichText(strBytes)
- self.numFmtName = text
- else:
- # DXFNumIFmt
- self.readUnsignedInt(1) # ignored
- self.numFmtID = self.readUnsignedInt(1)
-
- if self.ibitAtrFnt:
- # DXFFntD (font information)
- nameLen = self.readUnsignedInt(1)
- if nameLen > 0:
- # Note the text length may double in case of a double-byte string.
- curPos = self.getCurrentPos()
- self.fontName, nameLen = globals.getRichText(self.readRemainingBytes(), nameLen)
- self.setCurrentPos(curPos) # Move back to the pre-text position.
- self.moveForward(realLen) # Move for exactly the bytes read.
-
- if 63 - nameLen < 0:
- raise RecordError
-
- self.readUnsignedInt(63 - nameLen) # Ignore these bytes.
- self.fontAttrs = self.readBytes(16) # I'll process this later.
- self.fontColor = self.readUnsignedInt(4)
- self.readUnsignedInt(4) # ignored
- tsNinch = self.readUnsignedInt(4)
- sssNinch = self.readUnsignedInt(4) != 0
- ulsNinch = self.readUnsignedInt(4) != 0
- blsNinch = self.readUnsignedInt(4) != 0
- self.readUnsignedInt(4) # ignored
- ich = self.readUnsignedInt(4)
- cch = self.readUnsignedInt(4)
- iFnt = self.readUnsignedInt(2)
-
- if self.ibitAtrAlc:
- # DXFALC (text alignment properties)
- self.readUnsignedInt(8)
-
- if self.ibitAtrBdr:
- # DXFBdr (border properties)
- self.readUnsignedInt(8)
-
- if self.ibitAtrPat:
- # DXFPat (pattern and colors)
- self.readUnsignedInt(4)
-
- if self.ibitAtrProt:
- # DXFProt (protection attributes)
- self.readUnsignedInt(2)
-
conditionType = {
0x01: "use comparison function",
0x02: "use 1st formula"
@@ -766,12 +791,7 @@ class CF(BaseRecordHandler):
compFuncText = globals.getValueOrUnknown(CF.compFunction, self.compFunction)
self.appendLine("comparison function: %s (0x%2.2X)"%(compFuncText, self.compFunction))
- # DXFN structure (TODO: This is not complete)
- if self.ibitAtrNum:
- if self.fIfmtUser:
- self.appendLine("number format to use: %s (name)"%self.numFmtName)
- else:
- self.appendLine("number format to use: %d (ID)"%self.numFmtID)
+ self.rgbdxf.appendLines(self)
# formulas
@@ -3072,6 +3092,14 @@ class SXDtr(BaseRecordHandler):
self.appendLine("")
self.appendMultiLine("The month value must be 1 if the day of month value is 0.")
+class SxDXF(BaseRecordHandler):
+
+ def __parseBytes (self):
+ self.dxf = DXFN12NoCB(self)
+
+ def parseBytes (self):
+ self.__parseBytes()
+ self.dxf.appendLines(self)
class SXFDBType(BaseRecordHandler):
diff --git a/src/xlsstream.py b/src/xlsstream.py
index bb9d2c0..322582d 100644
--- a/src/xlsstream.py
+++ b/src/xlsstream.py
@@ -171,7 +171,7 @@ recData = {
0x00F0: ["SXRULE", "PivotTable Rule Data"],
0x00F1: ["SXEX", "PivotTable View Extended Information", xlsrecord.SXEx],
0x00F2: ["SXFILT", "PivotTable Rule Filter"],
- 0x00F4: ["SxDXF", "PivotTable Differential Formatting"],
+ 0x00F4: ["SxDXF", "PivotTable Differential Formatting", xlsrecord.SxDXF],
0x00F6: ["SXNAME", "PivotTable Name"],
0x00F7: ["SXSELECT", "PivotTable Selection Information"],
0x00F8: ["SXPAIR", "PivotTable Name Pair"],
More information about the Libreoffice-commits
mailing list