bump product version to 5.0.4.1
[LibreOffice.git] / solenv / gdb / libreoffice / tl.py
blob87e4924e0d996c27adb24273feeddf7a6fe0afd6
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import gdb
12 from libreoffice.util import printing
14 class BigIntPrinter(object):
15 '''Prints big integer'''
17 def __init__(self, typename, val):
18 self.val = val
20 def to_string(self):
21 if self.val['bIsSet']:
22 if self.val['bIsBig']:
23 return self._value()
24 else:
25 return self.val['nVal']
26 else:
27 return "unset %s" % self.typename
29 def _value(self):
30 len = self.val['nLen']
31 digits = self.val['nNum']
32 dsize = digits.dereference().type.sizeof * 8
33 num = 0
34 # The least significant byte is on index 0
35 for i in reversed(range(0, len)):
36 num <<= dsize
37 num += digits[i]
38 return num
40 class ColorPrinter(object):
41 '''Prints color as rgb(r, g, b) or rgba(r, g, b, a)'''
43 def __init__(self, typename, val):
44 self.val = val
46 def to_string(self):
47 color = self.val['mnColor']
48 b = color & 0xff
49 g = (color >> 8) & 0xff
50 r = (color >> 16) & 0xff
51 a = (color >> 24) & 0xff
52 if a:
53 return "rgba(%d, %d, %d, %d)" % (r, g, b, a)
54 else:
55 return "rgb(%d, %d, %d)" % (r, g, b)
57 class FractionPrinter(object):
58 '''Prints fraction'''
60 def __init__(self, typename, val):
61 self.typename = typename
62 self.val = val
64 def to_string(self):
65 impl = self.val['mpImpl'].dereference()
66 numerator = impl['value']['num']
67 denominator = impl['value']['den']
68 if impl['valid']:
69 return "%d/%d" % (numerator, denominator)
70 else:
71 return "invalid %s %d/%d" % (self.typename, numerator, denominator)
73 class DateTimeImpl(object):
75 def __init__(self, date, time):
76 self.date = date
77 self.time = time
79 def __str__(self):
80 result = ''
81 if self.date:
82 result += str(self.date)
83 if self.time:
84 result += ' '
85 if self.time:
86 result += str(self.time)
87 return result
89 @staticmethod
90 def parse(val):
91 return DateTimeImpl(DateImpl.parse(val), TimeImpl.parse(val))
93 class DateTimePrinter(object):
94 '''Prints date and time'''
96 def __init__(self, typename, val):
97 self.val = val
99 def to_string(self):
100 return str(DateTimeImpl.parse(self.val))
102 class DateImpl(DateTimeImpl):
104 def __init__(self, year, month, day):
105 super(DateImpl, self).__init__(self, None)
106 self.year = year
107 self.month = month
108 self.day = day
110 def __str__(self):
111 return "%d-%d-%d" % (self.year, self.month, self.day)
113 @staticmethod
114 def parse(val):
115 date = val['nDate']
116 d = date % 100
117 m = (date / 100) % 100
118 y = date / 10000
119 return DateImpl(y, m, d)
121 class DatePrinter(object):
122 '''Prints date'''
124 def __init__(self, typename, val):
125 self.val = val
127 def to_string(self):
128 return str(DateImpl.parse(self.val))
130 class TimeImpl(DateTimeImpl):
132 def __init__(self, hour, minute, second, nanosecond = 0):
133 super(TimeImpl, self).__init__(None, self)
134 self.hour = hour
135 self.minute = minute
136 self.second = second
137 self.nanosecond = nanosecond
139 def __str__(self):
140 decimal = ''
141 if self.nanosecond != 0:
142 decimal = '.%09d' % self.nanosecond
143 return "%02d:%02d:%02d%s" % (self.hour, self.minute, self.second, decimal)
145 @staticmethod
146 def parse(val):
147 time = val['nTime']
148 h = time / 10000000000000
149 m = (time / 100000000000) % 100
150 s = (time / 1000000000) % 100
151 ns = time % 1000000000
152 return TimeImpl(h, m, s, ns)
154 class TimePrinter(object):
155 '''Prints time'''
157 def __init__(self, typename, val):
158 self.val = val
160 def to_string(self):
161 return str(TimeImpl.parse(self.val))
163 class PointPrinter(object):
164 '''Prints a Point.'''
166 def __init__(self, typename, value):
167 self.typename = typename
168 self.value = value
170 def to_string(self):
171 return "%s" % (self.typename)
173 def children(self):
174 x = self.value['nA']
175 y = self.value['nB']
176 children = [('x', x), ('y', y)]
177 return children.__iter__()
179 class SizePrinter(object):
180 '''Prints a Size.'''
182 def __init__(self, typename, value):
183 self.typename = typename
184 self.value = value
186 def to_string(self):
187 return "%s" % (self.typename)
189 def children(self):
190 width = self.value['nA']
191 height = self.value['nB']
192 children = [('width', width), ('height', height)]
193 return children.__iter__()
195 class RectanglePrinter(object):
196 '''Prints a Rectangle.'''
198 def __init__(self, typename, value):
199 self.typename = typename
200 self.value = value
202 def to_string(self):
203 return "%s" % (self.typename)
205 def children(self):
206 left = self.value['nLeft']
207 top = self.value['nTop']
208 right = self.value['nRight']
209 bottom = self.value['nBottom']
210 children = [('left', left), ('top', top), ('right', right), ('bottom', bottom)]
211 return children.__iter__()
213 printer = None
215 def build_pretty_printers():
216 global printer
218 printer = printing.Printer('libreoffice/tl')
220 # various types
221 printer.add('BigInt', BigIntPrinter)
222 printer.add('Color', ColorPrinter)
223 printer.add('Fraction', FractionPrinter)
224 printer.add('DateTime', DateTimePrinter)
225 printer.add('Date', DatePrinter)
226 printer.add('Time', TimePrinter)
227 printer.add('Point', PointPrinter)
228 printer.add('Size', SizePrinter)
229 printer.add('Rectangle', RectanglePrinter)
231 def register_pretty_printers(obj):
232 printing.register_pretty_printer(printer, obj)
234 build_pretty_printers()
236 # vim:set shiftwidth=4 softtabstop=4 expandtab: