ooo-build r14996 - in trunk: . scratch/sd-pptutil/src



Author: thorstenb
Date: Mon Jan  5 01:30:52 2009
New Revision: 14996
URL: http://svn.gnome.org/viewvc/ooo-build?rev=14996&view=rev

Log:
    * scratch/sd-pptutil/*: added ColorScheme & MasterStyle handlers,
    plus some more reasonably undocumented record types



Modified:
   trunk/ChangeLog
   trunk/scratch/sd-pptutil/src/globals.py
   trunk/scratch/sd-pptutil/src/record.py
   trunk/scratch/sd-pptutil/src/stream.py

Modified: trunk/scratch/sd-pptutil/src/globals.py
==============================================================================
--- trunk/scratch/sd-pptutil/src/globals.py	(original)
+++ trunk/scratch/sd-pptutil/src/globals.py	Mon Jan  5 01:30:52 2009
@@ -10,7 +10,7 @@
 #
 ########################################################################
 
-import sys, struct, math
+import sys, struct, math, zipfile, xmlpp, StringIO
 
 class ByteConvertError(Exception): pass
 
@@ -192,6 +192,58 @@
             code += bytes[i*2+1]
         if bytes[i*2] != '\x00':
             code += bytes[i*2]
-        text += unicode(code, 'utf-8')
+        try:    
+            text += unicode(code, 'utf-8')
+        except UnicodeDecodeError:
+            text += "<%d invalid chars>"%len(code)
     return text
 
+class StreamWrap(object):
+    def __init__ (self,printer):
+        self.printer = printer
+        self.buffer = ""
+    def write (self,string):
+        self.buffer += string
+    def flush (self):
+        for line in self.buffer.splitlines():
+            self.printer(line)
+
+def outputZipContent (bytes, printer, width=80):
+    printer("Zipped content:")
+    rawFile = StringIO.StringIO(bytes)
+    zipFile = zipfile.ZipFile(rawFile)
+    i = 0
+    # TODO: when 2.6/3.0 is in widespread use, change to infolist
+    # here, names might be ambiguous
+    for filename in zipFile.namelist():
+        if i > 0:
+            printer('-'*width)
+        i += 1
+        printer("")
+        printer(filename + ":")
+        printer('-'*width)
+
+        contents = zipFile.read(filename)
+        if filename.endswith(".xml") or contents.startswith("<?xml"):
+            wrapper = StreamWrap(printer)
+            xmlpp.pprint(contents,wrapper,1,80)
+            wrapper.flush()
+        else:
+            dumpBytes(contents)
+            
+    zipFile.close()
+
+def stringizeColorRef(colorRef, colorName="color"):
+    def split (packedColor):
+        return ((packedColor & 0xFF0000) // 0x10000, (packedColor & 0xFF00) / 0x100, (packedColor & 0xFF))
+    
+    colorValue = colorRef & 0xFFFFFF
+    if colorRef & 0xFE000000 == 0xFE000000 or colorRef & 0xFF000000 == 0:
+        colors = split(colorValue)
+        return "%s = (%d,%d,%d)"%(colorName, colors[0], colors[1], colors[2])
+    elif colorRef & 0x08000000 or colorRef & 0x10000000:
+        return "%s = schemecolor(%d)"%(colorName, colorValue)
+    elif colorRef & 0x04000000:
+        return "%s = colorschemecolor(%d)"%(colorName, colorValue)
+    else:
+        return "%s = <unidentified color>(%4.4Xh)"%(colorName, colorValue)

Modified: trunk/scratch/sd-pptutil/src/record.py
==============================================================================
--- trunk/scratch/sd-pptutil/src/record.py	(original)
+++ trunk/scratch/sd-pptutil/src/record.py	Mon Jan  5 01:30:52 2009
@@ -11,10 +11,7 @@
 #
 ########################################################################
 
-import StringIO
 import globals
-import zipfile
-import xmlpp
 
 # -------------------------------------------------------------------
 # record handler classes
@@ -130,6 +127,12 @@
     args += "ShapeText",
     return UniString(*args)
 
+class ZipRecord(BaseRecordHandler):
+    """Zipped content."""
+
+    def parseBytes (self):
+        globals.outputZipContent(self.readRemainingBytes(), self.appendLine, 61)
+
 # -------------------------------------------------------------------
 # special record handler: properties
 
@@ -196,6 +199,30 @@
 
 
 # -------------------------------------------------------------------
+# special record handler: color scheme atom
+
+class ColorScheme(BaseRecordHandler):
+    """Color scheme atom."""
+
+    def parseBytes (self):
+        self.appendLine(globals.stringizeColorRef(self.readUnsignedInt(4),
+                                                  "Background"))
+        self.appendLine(globals.stringizeColorRef(self.readUnsignedInt(4),
+                                                  "Text and lines"))
+        self.appendLine(globals.stringizeColorRef(self.readUnsignedInt(4),
+                                                  "Shadows"))
+        self.appendLine(globals.stringizeColorRef(self.readUnsignedInt(4),
+                                                  "Title text"))
+        self.appendLine(globals.stringizeColorRef(self.readUnsignedInt(4),
+                                                  "Fills"))
+        self.appendLine(globals.stringizeColorRef(self.readUnsignedInt(4),
+                                                  "Accent"))
+        self.appendLine(globals.stringizeColorRef(self.readUnsignedInt(4),
+                                                  "Accent and hyperlink"))
+        self.appendLine(globals.stringizeColorRef(self.readUnsignedInt(4),
+                                                  "Accent and followed hyperlink"))
+
+# -------------------------------------------------------------------
 # special record handlers: text style properties
 
 class TextStyles(BaseRecordHandler):
@@ -216,7 +243,9 @@
         while not self.isEmpty() and charPos < textLen:
             runLen = self.readUnsignedInt(4)
             charPos += runLen
-            self.parseParaStyle(runLen)
+            indentLevel = self.readUnsignedInt(2)
+            self.appendLine("para props for %d chars, indent: %d"%(runLen,indentLevel))
+            self.parseParaStyle()
             self.appendLine("-"*61)
             
         # 4 bytes: <count> characters of shape text this char run is meant for
@@ -226,7 +255,8 @@
         while not self.isEmpty() and charPos < textLen:
             runLen = self.readUnsignedInt(4)
             charPos += runLen
-            self.parseCharStyle(runLen)
+            self.appendLine("char props for %d chars"%runLen)
+            self.parseCharStyle()
             self.appendLine("-"*61)
             
     def appendParaProp (self, text):
@@ -235,12 +265,9 @@
     def appendCharProp (self, text):
         self.appendLine("char prop given: "+text)
 
-    def parseParaStyle (self, runLen):
-        indentLevel = self.readUnsignedInt(2)
+    def parseParaStyle (self):
         styleMask = self.readUnsignedInt(4)
 
-        self.appendLine("para props for %d chars, indent: %d"%(runLen,indentLevel))
-
         if styleMask & 0x000F:
             bulletFlags = self.readUnsignedInt(2)
             # filter bits not in flag field
@@ -317,11 +344,9 @@
             paraTextDirection = self.readUnsignedInt(2)
             self.appendParaProp("para text direction %4.4Xh"%paraTextDirection)
 
-    def parseCharStyle (self, runLen):
+    def parseCharStyle (self):
         styleMask = self.readUnsignedInt(4)
 
-        self.appendLine("char props for %d chars"%runLen)
-
         if styleMask & 0xFFFF:
             charFlags = self.readUnsignedInt(2)
             self.appendCharProp("char flags %4.4Xh"%charFlags)
@@ -356,6 +381,27 @@
             self.appendCharProp("char font position %d"%fontPosition)
 
 
+class MasterTextStyles(TextStyles):
+    """Master text style properties."""
+
+    def parseBytes (self):
+        self.appendLine("Master style for text type: %d"%self.recordInstance)
+        self.appendLine("-"*61)
+
+        # 2 bytes: number of indent levels following. each indent
+        # level has one para and one char prop entry, the para prop
+        # entry misses the indent specifier it has for StyleTextAtom.
+        numLevels = self.readUnsignedInt(2)
+        
+        for i in xrange(0, numLevels):
+            self.appendLine("para props for indent level: %d"%i)
+            self.parseParaStyle()
+            self.appendLine("-"*61)
+            self.appendLine("char props for indent level: %d"%i)
+            self.parseCharStyle()
+            self.appendLine("-"*61)
+            
+
 # -------------------------------------------------------------------
 # special record handlers: property atoms
 
@@ -394,6 +440,11 @@
             
 class LongPropertyHandler(BasePropertyHandler):
     """Long property."""
+
+    def output (self):
+        if self.propType in propData:
+            self.printer("%4.4Xh: %s = %d [\"%s\"]"%(self.propType, self.propEntry[0],
+                                                     self.propValue, self.propEntry[2]))
         
 class MsoArrayPropertyHandler(BasePropertyHandler):
     """MsoArray property."""
@@ -436,22 +487,16 @@
     """Color property."""   
 
     def split (self, packedColor):
-        return (packedColor & 0xFF0000) // 0x10000, (packedColor & 0xFF00) / 0x100, (packedColor & 0xFF)
+        return ((packedColor & 0xFF0000) // 0x10000, (packedColor & 0xFF00) / 0x100, (packedColor & 0xFF))
     
     def output (self):
         propEntry = ["<color atom>", None, "undocumented color property"]
         if self.propType in propData:
             propEntry = propData[self.propType]
-        colorValue = self.propValue & 0xFFFFFF
-        if self.propValue & 0xFE000000 == 0xFE000000:
-            self.printer("%4.4Xh: %s = (%d,%d,%d) [\"%s\"]"%(self.propType, propEntry[0], split(colorValue), propEntry[2]))
-        elif self.propValue & 0x08000000 or self.propValue & 0x10000000:
-            self.printer("%4.4Xh: %s = schemecolor(%d) [\"%s\"]"%(self.propType, propEntry[0], colorValue, propEntry[2]))
-        elif self.propValue & 0x04000000:
-            self.printer("%4.4Xh: %s = colorschemecolor(%d) [\"%s\"]"%(self.propType, propEntry[0], colorValue, propEntry[2]))
-        else:
-            self.printer("%4.4Xh: %s = <unidentified color>(%4.4Xh) [\"%s\"]"%(self.propType, propEntry[0], colorValue, propEntry[2]))
-
+        self.printer("%4.4Xh: %s [\"%s\"]"%(self.propType,
+                                            globals.stringizeColorRef(self.propValue,
+                                                                      propEntry[0]),
+                                            propEntry[2]))
 
 class CharPropertyHandler(BasePropertyHandler):
     """string property."""  
@@ -468,43 +513,7 @@
     """zip storage."""  
 
     def output (self):
-        class StreamWrap(object):
-            def __init__ (self,printer):
-                self.printer = printer
-                self.buffer = ""
-            def write (self,string):
-                self.buffer += string
-            def flush (self):
-                for line in self.buffer.splitlines():
-                    self.printer(line)
-            
-        self.printer("Zipped content:")
-        self.printer('='*61)
-        rawFile = StringIO.StringIO(self.bytes)
-        zipFile = zipfile.ZipFile(rawFile)
-        i = 0
-        # TODO: when 2.6/3.0 is in widespread use, change to infolist here
-        for filename in zipFile.namelist():
-            if i > 0:
-                self.printer('-'*61)
-            i += 1
-            self.printer(filename + ":")
-            self.printer('-'*61)
-
-            contents = zipFile.read(filename)
-            if filename.endswith(".xml") or contents.startswith("<?xml"):
-                wrapper = StreamWrap(self.printer)
-                xmlpp.pprint(contents,wrapper,1,80)
-                wrapper.flush()
-            else:
-                while len(contents):
-                    self.printer(contents[:60].replace('\n','').replace('\r',''))
-                    contents = contents[60:]
-#            content = zipFile.open(zipInfo)
-#            for line in content.readlines():
-#                self.printer(line)
-        zipFile.close()        
-
+        globals.outputZipContent(self.bytes, self.printer, 61)
 
 # -------------------------------------------------------------------
 # special record handler: properties

Modified: trunk/scratch/sd-pptutil/src/stream.py
==============================================================================
--- trunk/scratch/sd-pptutil/src/stream.py	(original)
+++ trunk/scratch/sd-pptutil/src/stream.py	Mon Jan  5 01:30:52 2009
@@ -66,10 +66,17 @@
  1034:  ["DFF_PST_ExObjListAtom"],              
  1035:  ["DFF_PST_PPDrawingGroup"],             
  1036:  ["DFF_PST_PPDrawing"],                  
+ 1038:  ["DFF_PST_Theme", record.ZipRecord],                  
+ 1039:  ["DFF_PST_ColorMapping"],                  
  1040:  ["DFF_PST_NamedShows"],                 
  1041:  ["DFF_PST_NamedShow"],                  
  1042:  ["DFF_PST_NamedShowSlides"],            
+ 1052:  ["DFF_PST_OriginalMainMasterId"],           
+ 1054:  ["DFF_PST_RoundTripContentMasterInfo", record.ZipRecord],           
  1055:  ["DFF_PST_RoundTripShapeId"],           
+ 1058:  ["DFF_PST_RoundTripContentMasterId"],           
+ 1059:  ["DFF_PST_RoundTripOArtTextStyles", record.ZipRecord],
+ 1064:  ["DFF_PST_RoundTripCustomTableStyles"],
  2000:  ["DFF_PST_List"],                       
  2005:  ["DFF_PST_FontCollection"],             
  2017:  ["DFF_PST_ListPlaceholder"],            
@@ -84,7 +91,7 @@
  2029:  ["DFF_PST_RunArrayAtom"],               
  2030:  ["DFF_PST_ArrayElementAtom"],           
  2031:  ["DFF_PST_Int4ArrayAtom"],              
- 2032:  ["DFF_PST_ColorSchemeAtom"],            
+ 2032:  ["DFF_PST_ColorSchemeAtom", record.ColorScheme],            
  3008:  ["DFF_PST_OEShape"],                    
  3009:  ["DFF_PST_ExObjRefAtom"],               
  3011:  ["DFF_PST_OEPlaceholderAtom"],          
@@ -99,7 +106,7 @@
  4000:  ["DFF_PST_TextCharsAtom", record.ShapeUniString],
  4001:  ["DFF_PST_StyleTextPropAtom", record.TextStyles],          
  4002:  ["DFF_PST_BaseTextPropAtom", record.TextStyles],           
- 4003:  ["DFF_PST_TxMasterStyleAtom"],          
+ 4003:  ["DFF_PST_TxMasterStyleAtom", record.MasterTextStyles],          
  4004:  ["DFF_PST_TxCFStyleAtom"],              
  4005:  ["DFF_PST_TxPFStyleAtom"],              
  4006:  ["DFF_PST_TextRulerAtom"],              



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]