1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import gdb
from libreoffice.util import printing
class BigIntPrinter(object):
'''Prints big integer'''
def __init__(self, typename, val):
self.val = val
def to_string(self):
if self.val['nLen']:
return self._value()
else:
return self.val['nVal']
def _value(self):
len = self.val['nLen']
digits = self.val['nNum']
dsize = digits.dereference().type.sizeof * 8
num = 0
# The least significant byte is on index 0
for i in reversed(range(0, len)):
num <<= dsize
num += digits[i]
return num
class ColorPrinter(object):
'''Prints color as rgb(r, g, b) or rgba(r, g, b, a)'''
def __init__(self, typename, val):
self.val = val
def to_string(self):
r = self.val['R']
g = self.val['G']
b = self.val['B']
t = self.val['T']
if t:
return "rgba(%d, %d, %d, %d)" % (r, g, b, 255 - t)
else:
return "rgb(%d, %d, %d)" % (r, g, b)
class DateTimeImpl(object):
def __init__(self, date, time):
self.date = date
self.time = time
def __str__(self):
result = ''
if self.date:
result += str(self.date)
if self.time:
result += ' '
if self.time:
result += str(self.time)
return result
@staticmethod
def parse(val):
return DateTimeImpl(DateImpl.parse(val), TimeImpl.parse(val))
class DateTimePrinter(object):
'''Prints date and time'''
def __init__(self, typename, val):
self.val = val
def to_string(self):
return str(DateTimeImpl.parse(self.val))
class DateImpl(DateTimeImpl):
def __init__(self, year, month, day):
super(DateImpl, self).__init__(self, None)
self.year = year
self.month = month
self.day = day
def __str__(self):
return "%d-%d-%d" % (self.year, self.month, self.day)
@staticmethod
def parse(val):
date = val['mnDate']
y = date / 10000
if date < 0:
date = -date
m = (date / 100) % 100
d = date % 100
return DateImpl(y, m, d)
class DatePrinter(object):
'''Prints date'''
def __init__(self, typename, val):
self.val = val
def to_string(self):
return str(DateImpl.parse(self.val))
class TimeImpl(DateTimeImpl):
def __init__(self, hour, minute, second, nanosecond = 0):
super(TimeImpl, self).__init__(None, self)
self.hour = hour
self.minute = minute
self.second = second
self.nanosecond = nanosecond
def __str__(self):
decimal = ''
if self.nanosecond != 0:
decimal = '.%09d' % self.nanosecond
return "%02d:%02d:%02d%s" % (self.hour, self.minute, self.second, decimal)
@staticmethod
def parse(val):
time = val['nTime']
h = time / 10000000000000
m = (time / 100000000000) % 100
s = (time / 1000000000) % 100
ns = time % 1000000000
return TimeImpl(h, m, s, ns)
class TimePrinter(object):
'''Prints time'''
def __init__(self, typename, val):
self.val = val
def to_string(self):
return str(TimeImpl.parse(self.val))
class PointPrinter(object):
'''Prints a Point.'''
def __init__(self, typename, value):
self.typename = typename
self.value = value
def to_string(self):
return "%s" % (self.typename)
def children(self):
x = self.value['mnA']
y = self.value['mnB']
children = [('x', x), ('y', y)]
return children.__iter__()
class SizePrinter(object):
'''Prints a Size.'''
def __init__(self, typename, value):
self.typename = typename
self.value = value
def to_string(self):
return "%s" % (self.typename)
def children(self):
width = self.value['mnA']
height = self.value['mnB']
children = [('width', width), ('height', height)]
return children.__iter__()
class RectanglePrinter(object):
'''Prints a Rectangle.'''
def __init__(self, typename, value):
self.typename = typename
self.value = value
def to_string(self):
return "%s" % (self.typename)
def children(self):
left = self.value['mnLeft']
top = self.value['mnTop']
right = self.value['mnRight']
bottom = self.value['mnBottom']
children = [('left', left), ('top', top), ('right', right), ('bottom', bottom)]
return children.__iter__()
printer = None
def build_pretty_printers():
global printer
printer = printing.Printer('libreoffice/tl')
# various types
printer.add('BigInt', BigIntPrinter)
printer.add('Color', ColorPrinter)
printer.add('DateTime', DateTimePrinter)
printer.add('Date', DatePrinter)
printer.add('Time', TimePrinter)
printer.add('Point', PointPrinter)
printer.add('Size', SizePrinter)
printer.add('Rectangle', RectanglePrinter)
def register_pretty_printers(obj):
printing.register_pretty_printer(printer, obj)
build_pretty_printers()
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|