[Libreoffice-commits] .: 3 commits - src/docdirstream.py src/docrecord.py src/docsprm.py test/parstyles.rtf
Miklos Vajna
vmiklos at kemper.freedesktop.org
Tue Nov 13 01:52:43 PST 2012
src/docdirstream.py | 7 ++
src/docrecord.py | 132 ++++++++++++++++++++++++++++++++++++++++++++++++----
src/docsprm.py | 84 +++++++++++++++++++++++++++++++++
test/parstyles.rtf | 10 +++
4 files changed, 223 insertions(+), 10 deletions(-)
New commits:
commit b9e772aad9c8f0a25d4986a427e2281175090174
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Tue Nov 13 10:52:06 2012 +0100
fix typo and add par styles test
diff --git a/src/docrecord.py b/src/docrecord.py
index 2352dde..9931173 100755
--- a/src/docrecord.py
+++ b/src/docrecord.py
@@ -842,7 +842,7 @@ class LPUpxTapx(DOCDirStream):
uPXPadding = UPXPadding(self)
uPXPadding.pad()
self.pos = uPXPadding.pos
- print '</lPUpxChpx>'
+ print '</lPUpxTapx>'
class StkCharLpUpxGrLpUpxRM(DOCDirStream):
"""The StkCharLPUpxGrLPUpxRM structure specifies revision-marking information and formatting for character styles."""
diff --git a/test/parstyles.rtf b/test/parstyles.rtf
new file mode 100755
index 0000000..93e3201
--- /dev/null
+++ b/test/parstyles.rtf
@@ -0,0 +1,10 @@
+{\rtf1
+{\fonttbl
+{\f0 Times New Roman;}
+}
+{\stylesheet
+{\s15\qc\sbasedon0\snext15 Center;}
+}
+{Hello world!\par }
+{\s15\qc This is centered.\par }
+}
commit 4b9d33f73b96e78298198d15f2b76a72fbbd3736
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Tue Nov 13 09:57:33 2012 +0100
dump STSH part 2: the remaining parts
diff --git a/src/docdirstream.py b/src/docdirstream.py
index 1e21832..cbb7d21 100755
--- a/src/docdirstream.py
+++ b/src/docdirstream.py
@@ -52,6 +52,13 @@ class DOCDirStream:
pos = self.pos
return struct.unpack("<I", bytes[pos:pos+4])[0]
+ def getuInt64(self, bytes = None, pos = None):
+ if not bytes:
+ bytes = self.bytes
+ if not pos:
+ pos = self.pos
+ return struct.unpack("<Q", bytes[pos:pos+8])[0]
+
def getString(self):
bytes = []
while True:
diff --git a/src/docrecord.py b/src/docrecord.py
index abaed0e..2352dde 100755
--- a/src/docrecord.py
+++ b/src/docrecord.py
@@ -102,7 +102,6 @@ class Sprm(DOCDirStream):
3: 4,
4: 2,
5: 2,
- # 6: variable,
7: 3,
}
@@ -114,12 +113,16 @@ class Sprm(DOCDirStream):
self.sgc = (self.sprm & 0x1c00) >> 10 # 11-13th bits
self.spra = (self.sprm & 0xe000) >> 13 # 14-16th bits
- if self.operandSizeMap[self.spra] == 1:
+ if self.getOperandSize() == 1:
self.operand = self.getuInt8()
- elif self.operandSizeMap[self.spra] == 2:
+ elif self.getOperandSize() == 2:
self.operand = self.getuInt16()
- elif self.operandSizeMap[self.spra] == 4:
+ elif self.getOperandSize() == 3:
+ self.operand = self.getuInt32() & 0x0fff
+ elif self.getOperandSize() == 4:
self.operand = self.getuInt32()
+ elif self.getOperandSize() == 7:
+ self.operand = self.getuInt64() & 0x0fffffff
else:
self.operand = "todo"
@@ -134,12 +137,17 @@ class Sprm(DOCDirStream):
nameMap = {
1: docsprm.parMap,
2: docsprm.chrMap,
+ 5: docsprm.tblMap,
}
print '<sprm value="%s" name="%s" ispmd="%s" fSpec="%s" sgc="%s" spra="%s" operandSize="%s" operand="%s"/>' % (
hex(self.sprm), nameMap[self.sgc][self.sprm], hex(self.ispmd), hex(self.fSpec), sgcmap[self.sgc], hex(self.spra), self.getOperandSize(), hex(self.operand)
)
def getOperandSize(self):
+ if self.spra == 6: # variable
+ if self.sprm == 0xd634:
+ return 7
+ raise Exception()
return self.operandSizeMap[self.spra]
class Prl(DOCDirStream):
@@ -753,6 +761,25 @@ class UpxChpx(DOCDirStream):
print '</grpprlChpx>'
print '</upxChpx>'
+class UpxTapx(DOCDirStream):
+ """The UpxTapx structure specifies the table formatting properties that differ from the parent"""
+ def __init__(self, lPUpxTapx):
+ DOCDirStream.__init__(self, lPUpxTapx.bytes)
+ self.lPUpxTapx = lPUpxTapx
+ self.pos = lPUpxTapx.pos
+
+ def dump(self):
+ print '<upxTapx type="UpxTapx" offset="%d">' % self.pos
+ size = self.lPUpxTapx.cbUpx
+ pos = 0
+ print '<grpprlTapx offset="%d" size="%d bytes">' % (self.pos, size)
+ while size - pos > 0:
+ prl = Prl(self.bytes, self.pos + pos)
+ prl.dump()
+ pos += prl.getSize()
+ print '</grpprlTapx>'
+ print '</upxTapx>'
+
class UPXPadding:
"""The UPXPadding structure specifies the padding that is used to pad the UpxPapx/Chpx/Tapx structures if any of them are an odd number of bytes in length."""
def __init__(self, parent):
@@ -799,6 +826,37 @@ class LPUpxChpx(DOCDirStream):
self.pos = uPXPadding.pos
print '</lPUpxChpx>'
+class LPUpxTapx(DOCDirStream):
+ """The LPUpxTapx structure specifies table formatting properties."""
+ def __init__(self, stkParaGRLPUPX):
+ DOCDirStream.__init__(self, stkParaGRLPUPX.bytes)
+ self.pos = stkParaGRLPUPX.pos
+
+ def dump(self):
+ print '<lPUpxTapx type="LPUpxTapx" offset="%d">' % self.pos
+ self.printAndSet("cbUpx", self.getuInt16())
+ self.pos += 2
+ upxTapx = UpxTapx(self)
+ upxTapx.dump()
+ self.pos += self.cbUpx
+ uPXPadding = UPXPadding(self)
+ uPXPadding.pad()
+ self.pos = uPXPadding.pos
+ print '</lPUpxChpx>'
+
+class StkCharLpUpxGrLpUpxRM(DOCDirStream):
+ """The StkCharLPUpxGrLPUpxRM structure specifies revision-marking information and formatting for character styles."""
+ def __init__(self, stkCharGRLPUPX):
+ DOCDirStream.__init__(self, stkCharGRLPUPX.bytes)
+ self.pos = stkCharGRLPUPX.pos
+
+ def dump(self):
+ print '<stkCharLpUpxGrLpUpxRM type="StkCharLpUpxGrLpUpxRM" offset="%d">' % self.pos
+ self.printAndSet("cbStkCharUpxGrLpUpxRM", self.getuInt16())
+ if self.cbStkCharUpxGrLpUpxRM != 0:
+ print '<todo what="StkCharLpUpxGrLpUpxRM: cbStkCharUpxGrLpUpxRM != 0 not implemented"/>'
+ print '</stkCharLpUpxGrLpUpxRM>'
+
class StkParaLpUpxGrLpUpxRM(DOCDirStream):
"""The StkParaLPUpxGrLPUpxRM structure specifies revision-marking information and formatting for paragraph styles."""
def __init__(self, stkParaGRLPUPX):
@@ -812,6 +870,57 @@ class StkParaLpUpxGrLpUpxRM(DOCDirStream):
print '<todo what="StkParaLpUpxGrLpUpxRM: cbStkParaUpxGrLpUpxRM != 0 not implemented"/>'
print '</stkParaLpUpxGrLpUpxRM>'
+class StkListGRLPUPX(DOCDirStream):
+ """The StkListGRLPUPX structure that specifies the formatting properties for a list style."""
+ def __init__(self, grLPUpxSw):
+ DOCDirStream.__init__(self, grLPUpxSw.bytes)
+ self.grLPUpxSw = grLPUpxSw
+ self.pos = grLPUpxSw.pos
+
+ def dump(self):
+ print '<stkListGRLPUPX type="StkListGRLPUPX" offset="%d">' % self.pos
+ lpUpxPapx = LPUpxPapx(self)
+ lpUpxPapx.dump()
+ self.pos = lpUpxPapx.pos
+ print '</stkListGRLPUPX>'
+
+class StkTableGRLPUPX(DOCDirStream):
+ """The StkTableGRLPUPX structure that specifies the formatting properties for a table style."""
+ def __init__(self, grLPUpxSw):
+ DOCDirStream.__init__(self, grLPUpxSw.bytes)
+ self.grLPUpxSw = grLPUpxSw
+ self.pos = grLPUpxSw.pos
+
+ def dump(self):
+ print '<stkTableGRLPUPX type="StkTableGRLPUPX" offset="%d">' % self.pos
+ lpUpxTapx = LPUpxTapx(self)
+ lpUpxTapx.dump()
+ self.pos = lpUpxTapx.pos
+ lpUpxPapx = LPUpxPapx(self)
+ lpUpxPapx.dump()
+ self.pos = lpUpxPapx.pos
+ lpUpxChpx = LPUpxChpx(self)
+ lpUpxChpx.dump()
+ self.pos = lpUpxChpx.pos
+ print '</stkTableGRLPUPX>'
+
+class StkCharGRLPUPX(DOCDirStream):
+ """The StkCharGRLPUPX structure that specifies the formatting properties for a character style."""
+ def __init__(self, grLPUpxSw):
+ DOCDirStream.__init__(self, grLPUpxSw.bytes)
+ self.grLPUpxSw = grLPUpxSw
+ self.pos = grLPUpxSw.pos
+
+ def dump(self):
+ print '<stkCharGRLPUPX type="StkCharGRLPUPX" offset="%d">' % self.pos
+ lpUpxChpx = LPUpxChpx(self)
+ lpUpxChpx.dump()
+ self.pos = lpUpxChpx.pos
+ stkCharLpUpxGrLpUpxRM = StkCharLpUpxGrLpUpxRM(self)
+ stkCharLpUpxGrLpUpxRM.dump()
+ self.pos = stkCharLpUpxGrLpUpxRM.pos
+ print '</stkCharGRLPUPX>'
+
class StkParaGRLPUPX(DOCDirStream):
"""The StkParaGRLPUPX structure that specifies the formatting properties for a paragraph style."""
def __init__(self, grLPUpxSw):
@@ -841,7 +950,10 @@ class GrLPUpxSw(DOCDirStream):
def dump(self):
stkMap = {
- 1: StkParaGRLPUPX
+ 1: StkParaGRLPUPX,
+ 2: StkCharGRLPUPX,
+ 3: StkTableGRLPUPX,
+ 4: StkListGRLPUPX
}
child = stkMap[self.std.stdf.stdfBase.stk](self)
child.dump()
@@ -878,9 +990,10 @@ class LPStd(DOCDirStream):
def dump(self):
self.printAndSet("cbStd", self.getuInt16())
self.pos += 2
- std = STD(self)
- std.dump()
- self.pos = std.pos
+ if self.cbStd > 0:
+ std = STD(self)
+ std.dump()
+ self.pos = std.pos
class STSH(DOCDirStream):
"""The STSH structure specifies the stylesheet for a document."""
@@ -895,12 +1008,11 @@ class STSH(DOCDirStream):
self.lpstshi.dump()
self.pos = self.lpstshi.pos
for i in range(self.lpstshi.stshi.stshif.cstd):
- print '<rglpstd index="%d" type="LPStd">' % i
+ print '<rglpstd index="%d" type="LPStd" offset="%d">' % (i, self.pos)
lpstd = LPStd(self)
lpstd.dump()
self.pos = lpstd.pos
print '</rglpstd>'
- break # FIXME
print '</stsh>'
# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab:
commit 2b17879905f1899ed5d4bfa89f67998f9fb8ac3c
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Tue Nov 13 10:14:23 2012 +0100
add table sprms
diff --git a/src/docsprm.py b/src/docsprm.py
index 5255cd6..54c9798 100755
--- a/src/docsprm.py
+++ b/src/docsprm.py
@@ -1,5 +1,89 @@
#!/usr/bin/env python
+# see 2.6.3 of the spec
+tblMap = {
+ 0x5400: "sprmTJc90",
+ 0x9601: "sprmTDxaLeft",
+ 0x9602: "sprmTDxaGapHalf",
+ 0x3403: "sprmTFCantSplit90",
+ 0x3404: "sprmTTableHeader",
+ 0xD605: "sprmTTableBorders80",
+ 0x9407: "sprmTDyaRowHeight",
+ 0xD608: "sprmTDefTable",
+ 0xD609: "sprmTDefTableShd80",
+ 0x740A: "sprmTTlp",
+ 0x560B: "sprmTFBiDi",
+ 0xD60C: "sprmTDefTableShd3rd",
+ 0x360D: "sprmTPc",
+ 0x940E: "sprmTDxaAbs",
+ 0x940F: "sprmTDyaAbs",
+ 0x9410: "sprmTDxaFromText",
+ 0x9411: "sprmTDyaFromText",
+ 0xD612: "sprmTDefTableShd",
+ 0xD613: "sprmTTableBorders",
+ 0xF614: "sprmTTableWidth",
+ 0x3615: "sprmTFAutofit",
+ 0xD616: "sprmTDefTableShd2nd",
+ 0xF617: "sprmTWidthBefore",
+ 0xF618: "sprmTWidthAfter",
+ 0x3619: "sprmTFKeepFollow",
+ 0xD61A: "sprmTBrcTopCv",
+ 0xD61B: "sprmTBrcLeftCv",
+ 0xD61C: "sprmTBrcBottomCv",
+ 0xD61D: "sprmTBrcRightCv",
+ 0x941E: "sprmTDxaFromTextRight",
+ 0x941F: "sprmTDyaFromTextBottom",
+ 0xD620: "sprmTSetBrc80",
+ 0x7621: "sprmTInsert",
+ 0x5622: "sprmTDelete",
+ 0x7623: "sprmTDxaCol",
+ 0x5624: "sprmTMerge",
+ 0x5625: "sprmTSplit",
+ 0x7629: "sprmTTextFlow",
+ 0xD62B: "sprmTVertMerge",
+ 0xD62C: "sprmTVertAlign",
+ 0xD62D: "sprmTSetShd",
+ 0xD62E: "sprmTSetShdOdd",
+ 0xD62F: "sprmTSetBrc",
+ 0xD632: "sprmTCellPadding",
+ 0xD633: "sprmTCellSpacingDefault",
+ 0xD634: "sprmTCellPaddingDefault",
+ 0xD635: "sprmTCellWidth",
+ 0xF636: "sprmTFitText",
+ 0xD639: "sprmTFCellNoWrap",
+ 0x563A: "sprmTIstd",
+ 0xD63E: "sprmTCellPaddingStyle",
+ 0xD642: "sprmTCellFHideMark",
+ 0xD660: "sprmTSetShdTable",
+ 0xF661: "sprmTWidthIndent",
+ 0xD662: "sprmTCellBrcType",
+ 0x5664: "sprmTFBiDi90",
+ 0x3465: "sprmTFNoAllowOverlap",
+ 0x3466: "sprmTFCantSplit",
+ 0xD667: "sprmTPropRMark",
+ 0x3668: "sprmTWall",
+ 0x7469: "sprmTIpgp",
+ 0xD66A: "sprmTCnf",
+ 0xD670: "sprmTDefTableShdRaw",
+ 0xD671: "sprmTDefTableShdRaw2nd",
+ 0xD672: "sprmTDefTableShdRaw3rd",
+ 0x7479: "sprmTRsid",
+ 0x347C: "sprmTCellVertAlignStyle",
+ 0x347D: "sprmTCellNoWrapStyle",
+ 0xD47F: "sprmTCellBrcTopStyle",
+ 0xD680: "sprmTCellBrcBottomStyle",
+ 0xD681: "sprmTCellBrcLeftStyle",
+ 0xD682: "sprmTCellBrcRightStyle",
+ 0xD683: "sprmTCellBrcInsideHStyle",
+ 0xD684: "sprmTCellBrcInsideVStyle",
+ 0xD685: "sprmTCellBrcTL2BRStyle",
+ 0xD686: "sprmTCellBrcTR2BLStyle",
+ 0xD687: "sprmTCellShdStyle",
+ 0x3488: "sprmTCHorzBands",
+ 0x3489: "sprmTCVertBands",
+ 0x548A: "sprmTJc",
+ }
+
# see 2.6.2 of the spec
parMap = {
0x4600: "sprmPIstd",
More information about the Libreoffice-commits
mailing list