[ooo-build-commit] scratch/mso-dumper
Kohei Yoshida
kohei at kemper.freedesktop.org
Mon Oct 12 11:04:04 PDT 2009
scratch/mso-dumper/src/globals.py | 14 +---
scratch/mso-dumper/src/xlsrecord.py | 124 ++++++++++++++++++++++++++++++++++--
scratch/mso-dumper/src/xlsstream.py | 6 -
3 files changed, 127 insertions(+), 17 deletions(-)
New commits:
commit 3618f8453f5868741153a923168999748211e05c
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Mon Oct 12 14:02:28 2009 -0400
[xls-dump] added handlers for FONT and XF records.
* scratch/mso-dumper/src/globals.py:
* scratch/mso-dumper/src/xlsrecord.py:
* scratch/mso-dumper/src/xlsstream.py:
diff --git a/scratch/mso-dumper/src/globals.py b/scratch/mso-dumper/src/globals.py
index 3e725c4..e2f9969 100644
--- a/scratch/mso-dumper/src/globals.py
+++ b/scratch/mso-dumper/src/globals.py
@@ -153,34 +153,32 @@ def getUnicodeRichExtText (bytes):
def getRichText (bytes, textLen=None):
"""parse a string of the rich-text format that Excel uses."""
- flags = bytes[0]
+ strm = ByteStream(bytes)
+ flags = strm.readUnsignedInt(1)
if type(flags) == type('c'):
flags = ord(flags)
is16Bit = (flags & 0x01)
isFarEast = (flags & 0x04)
isRich = (flags & 0x08)
- i = 1
formatRuns = 0
if isRich:
- formatRuns = getSignedInt(bytes[i:i+2])
- i += 2
+ formatRuns = strm.readUnsignedInt(2)
extInfo = 0
if isFarEast:
- extInfo = getSignedInt(bytes[i:i+4])
- i += 4
+ extInfo = strm.readUnsignedInt(4)
extraBytes = 0
if textLen == None:
extraBytes = formatRuns*4 + extInfo
textLen = len(bytes) - extraBytes - i
- totalByteLen = i + textLen + extraBytes
+ totalByteLen = strm.getCurrentPos() + textLen + extraBytes
if is16Bit:
return ("<16-bit strings not supported yet>", totalByteLen)
- text = toTextBytes(bytes[i:i+textLen])
+ text = toTextBytes(strm.readBytes(textLen))
return (text, totalByteLen)
diff --git a/scratch/mso-dumper/src/xlsrecord.py b/scratch/mso-dumper/src/xlsrecord.py
index 4d27dd2..b38640c 100644
--- a/scratch/mso-dumper/src/xlsrecord.py
+++ b/scratch/mso-dumper/src/xlsrecord.py
@@ -5,6 +5,19 @@ import globals, formula
# -------------------------------------------------------------------
# record handler classes
+def getValueOrUnknown (list, idx):
+ listType = type(list)
+ if listType == type([]):
+ # list
+ if idx < len(list):
+ return list[idx]
+ elif listType == type({}):
+ # dictionary
+ if list.has_key(idx):
+ return list[idx]
+
+ return '(unknown)'
+
class BaseRecordHandler(globals.ByteStream):
def __init__ (self, header, size, bytes, strmData):
@@ -759,9 +772,7 @@ class PhoneticInfo(BaseRecordHandler):
@staticmethod
def getPhoneticType (flag):
- if flag < len(PhoneticInfo.phoneticType):
- return PhoneticInfo.phoneticType[flag]
- return '(unknown)'
+ return getValueOrUnknown(PhoneticInfo.phoneticType, flag)
alignType = [
'general alignment', # 0x00
@@ -772,9 +783,7 @@ class PhoneticInfo(BaseRecordHandler):
@staticmethod
def getAlignType (flag):
- if flag < len(PhoneticInfo.alignType):
- return PhoneticInfo.alignType[flag]
- return '(unknown)'
+ return getValueOrUnknown(PhoneticInfo.alignType, flag)
def parseBytes (self):
fontIdx = self.readUnsignedInt(2)
@@ -796,6 +805,109 @@ class PhoneticInfo(BaseRecordHandler):
return
+
+class Font(BaseRecordHandler):
+
+ fontFamilyNames = [
+ 'not applicable', # 0x00
+ 'roman', # 0x01
+ 'swiss', # 0x02
+ 'modern', # 0x03
+ 'script', # 0x04
+ 'decorative' # 0x05
+ ]
+
+ @staticmethod
+ def getFontFamily (code):
+ return getValueOrUnknown(Font.fontFamilyNames, code)
+
+ scriptNames = [
+ 'normal script',
+ 'superscript',
+ 'subscript'
+ ]
+
+ @staticmethod
+ def getScriptName (code):
+ return getValueOrUnknown(Font.scriptNames, code)
+
+
+ underlineTypes = {
+ 0x00: 'no underline',
+ 0x01: 'single underline',
+ 0x02: 'double underline',
+ 0x21: 'single accounting',
+ 0x22: 'double accounting'
+ }
+
+ @staticmethod
+ def getUnderlineStyleName (val):
+ return getValueOrUnknown(Font.underlineTypes, val)
+
+ charSetNames = {
+ 0x00: 'ANSI_CHARSET',
+ 0x01: 'DEFAULT_CHARSET',
+ 0x02: 'SYMBOL_CHARSET',
+ 0x4D: 'MAC_CHARSET',
+ 0x80: 'SHIFTJIS_CHARSET',
+ 0x81: 'HANGEUL_CHARSET',
+ 0x81: 'HANGUL_CHARSET',
+ 0x82: 'JOHAB_CHARSET',
+ 0x86: 'GB2312_CHARSET',
+ 0x88: 'CHINESEBIG5_CHARSET',
+ 0xA1: 'GREEK_CHARSET',
+ 0xA2: 'TURKISH_CHARSET',
+ 0xA3: 'VIETNAMESE_CHARSET',
+ 0xB1: 'HEBREW_CHARSET',
+ 0xB2: 'ARABIC_CHARSET',
+ 0xBA: 'BALTIC_CHARSET',
+ 0xCC: 'RUSSIAN_CHARSET',
+ 0xDD: 'THAI_CHARSET',
+ 0xEE: 'EASTEUROPE_CHARSET'
+ }
+
+ @staticmethod
+ def getCharSetName (code):
+ return getValueOrUnknown(Font.charSetNames, code)
+
+ def parseBytes (self):
+ height = self.readUnsignedInt(2)
+ flags = self.readUnsignedInt(2)
+ colorId = self.readUnsignedInt(2)
+
+ boldStyle = self.readUnsignedInt(2)
+ boldStyleName = '(unknown)'
+ if boldStyle == 400:
+ boldStyleName = 'normal'
+ elif boldStyle == 700:
+ boldStyleName = 'bold'
+
+ superSub = self.readUnsignedInt(2)
+ ulStyle = self.readUnsignedInt(1)
+ fontFamily = self.readUnsignedInt(1)
+ charSet = self.readUnsignedInt(1)
+ reserved = self.readUnsignedInt(1)
+ nameLen = self.readUnsignedInt(1)
+ fontName, nameLen = globals.getRichText(self.readRemainingBytes(), nameLen)
+ self.appendLine("font height: %d"%height)
+ self.appendLine("color ID: %d"%colorId)
+ self.appendLine("bold style: %s (%d)"%(boldStyleName, boldStyle))
+ self.appendLine("script type: %s"%Font.getScriptName(superSub))
+ self.appendLine("underline type: %s"%Font.getUnderlineStyleName(ulStyle))
+ self.appendLine("character set: %s"%Font.getCharSetName(charSet))
+ self.appendLine("font family: %s"%Font.getFontFamily(fontFamily))
+ self.appendLine("font name: %s (%d)"%(fontName, nameLen))
+
+
+class XF(BaseRecordHandler):
+
+ def parseBytes (self):
+ fontId = self.readUnsignedInt(2)
+ numId = self.readUnsignedInt(2)
+ self.appendLine("font ID: %d"%fontId)
+ self.appendLine("number format ID: %d"%numId)
+
+
# -------------------------------------------------------------------
# SX - Pivot Table
diff --git a/scratch/mso-dumper/src/xlsstream.py b/scratch/mso-dumper/src/xlsstream.py
index bef9c42..c0cea93 100644
--- a/scratch/mso-dumper/src/xlsstream.py
+++ b/scratch/mso-dumper/src/xlsstream.py
@@ -38,7 +38,7 @@ recData = {
0x002A: ["PRINTHEADERS", "Print Row/Column Labels"],
0x002B: ["PRINTGRIDLINES", "Print Gridlines Flag"],
0x002F: ["FILEPASS", "File Is Password-Protected", xlsrecord.FilePass],
- 0x0031: ["FONT", "Font and Character Formatting"],
+ 0x0031: ["FONT", "Font and Character Formatting", xlsrecord.Font],
0x003C: ["CONTINUE", "Continues Long Records"],
0x003D: ["WINDOW1", "Window Information"],
0x0040: ["BACKUP", "Save Backup Version of the File"],
@@ -129,7 +129,7 @@ recData = {
0x00DD: ["SCENPROTECT", "Scenario Protection"],
0x00DE: ["OLESIZE", "Size of OLE Object"],
0x00DF: ["UDDESC", "Description String for Chart Autoformat"],
- 0x00E0: ["XF", "Extended Format"],
+ 0x00E0: ["XF", "Extended Format", xlsrecord.XF],
0x00E1: ["INTERFACEHDR", "Beginning of User Interface Records"],
0x00E2: ["INTERFACEEND", "End of User Interface Records"],
0x00E3: ["SXVS", "View Source", xlsrecord.SXViewSource],
@@ -185,7 +185,7 @@ recData = {
0x0221: ["ARRAY", "Array-Entered Formula", xlsrecord.Array],
0x0223: ["EXTERNNAME", "Externally Referenced Name"],
0x0225: ["DEFAULTROWHEIGHT", "Default Row Height"],
- 0x0231: ["FONT", "Font Description"],
+ 0x0231: ["FONT", "Font Description", xlsrecord.Font],
0x0236: ["TABLE", "Data Table"],
0x023E: ["WINDOW2", "Sheet Window Information"],
0x027E: ["RK", "Cell with Encoded Integer or Floating-Point", xlsrecord.RK],
More information about the ooo-build-commit
mailing list