Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / solenv / gdb / libreoffice / tl.py
blob6e7a7c25e3208a05a232fb1aff9bf3716d7b231c
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['nLen']:
22 return self._value()
23 else:
24 return self.val['nVal']
26 def _value(self):
27 len = self.val['nLen']
28 digits = self.val['nNum']
29 dsize = digits.dereference().type.sizeof * 8
30 num = 0
31 # The least significant byte is on index 0
32 for i in reversed(range(0, len)):
33 num <<= dsize
34 num += digits[i]
35 return num
37 class ColorPrinter(object):
38 '''Prints color as rgb(r, g, b) or rgba(r, g, b, a)'''
40 def __init__(self, typename, val):
41 self.val = val
43 def to_string(self):
44 r = self.val['R']
45 g = self.val['G']
46 b = self.val['B']
47 t = self.val['T']
48 if t:
49 return "rgba(%d, %d, %d, %d)" % (r, g, b, 255 - t)
50 else:
51 return "rgb(%d, %d, %d)" % (r, g, b)
53 class DateTimeImpl(object):
55 def __init__(self, date, time):
56 self.date = date
57 self.time = time
59 def __str__(self):
60 result = ''
61 if self.date:
62 result += str(self.date)
63 if self.time:
64 result += ' '
65 if self.time:
66 result += str(self.time)
67 return result
69 @staticmethod
70 def parse(val):
71 return DateTimeImpl(DateImpl.parse(val), TimeImpl.parse(val))
73 class DateTimePrinter(object):
74 '''Prints date and time'''
76 def __init__(self, typename, val):
77 self.val = val
79 def to_string(self):
80 return str(DateTimeImpl.parse(self.val))
82 class DateImpl(DateTimeImpl):
84 def __init__(self, year, month, day):
85 super(DateImpl, self).__init__(self, None)
86 self.year = year
87 self.month = month
88 self.day = day
90 def __str__(self):
91 return "%d-%d-%d" % (self.year, self.month, self.day)
93 @staticmethod
94 def parse(val):
95 date = val['mnDate']
96 y = date / 10000
97 if date < 0:
98 date = -date
99 m = (date / 100) % 100
100 d = date % 100
101 return DateImpl(y, m, d)
103 class DatePrinter(object):
104 '''Prints date'''
106 def __init__(self, typename, val):
107 self.val = val
109 def to_string(self):
110 return str(DateImpl.parse(self.val))
112 class TimeImpl(DateTimeImpl):
114 def __init__(self, hour, minute, second, nanosecond = 0):
115 super(TimeImpl, self).__init__(None, self)
116 self.hour = hour
117 self.minute = minute
118 self.second = second
119 self.nanosecond = nanosecond
121 def __str__(self):
122 decimal = ''
123 if self.nanosecond != 0:
124 decimal = '.%09d' % self.nanosecond
125 return "%02d:%02d:%02d%s" % (self.hour, self.minute, self.second, decimal)
127 @staticmethod
128 def parse(val):
129 time = val['nTime']
130 h = time / 10000000000000
131 m = (time / 100000000000) % 100
132 s = (time / 1000000000) % 100
133 ns = time % 1000000000
134 return TimeImpl(h, m, s, ns)
136 class TimePrinter(object):
137 '''Prints time'''
139 def __init__(self, typename, val):
140 self.val = val
142 def to_string(self):
143 return str(TimeImpl.parse(self.val))
145 class PointPrinter(object):
146 '''Prints a Point.'''
148 def __init__(self, typename, value):
149 self.typename = typename
150 self.value = value
152 def to_string(self):
153 return "%s" % (self.typename)
155 def children(self):
156 x = self.value['mnA']
157 y = self.value['mnB']
158 children = [('x', x), ('y', y)]
159 return children.__iter__()
161 class SizePrinter(object):
162 '''Prints a Size.'''
164 def __init__(self, typename, value):
165 self.typename = typename
166 self.value = value
168 def to_string(self):
169 return "%s" % (self.typename)
171 def children(self):
172 width = self.value['mnA']
173 height = self.value['mnB']
174 children = [('width', width), ('height', height)]
175 return children.__iter__()
177 class RectanglePrinter(object):
178 '''Prints a Rectangle.'''
180 def __init__(self, typename, value):
181 self.typename = typename
182 self.value = value
184 def to_string(self):
185 return "%s" % (self.typename)
187 def children(self):
188 left = self.value['mnLeft']
189 top = self.value['mnTop']
190 right = self.value['mnRight']
191 bottom = self.value['mnBottom']
192 children = [('left', left), ('top', top), ('right', right), ('bottom', bottom)]
193 return children.__iter__()
195 printer = None
197 def build_pretty_printers():
198 global printer
200 printer = printing.Printer('libreoffice/tl')
202 # various types
203 printer.add('BigInt', BigIntPrinter)
204 printer.add('Color', ColorPrinter)
205 printer.add('DateTime', DateTimePrinter)
206 printer.add('Date', DatePrinter)
207 printer.add('Time', TimePrinter)
208 printer.add('Point', PointPrinter)
209 printer.add('Size', SizePrinter)
210 printer.add('Rectangle', RectanglePrinter)
212 def register_pretty_printers(obj):
213 printing.register_pretty_printer(printer, obj)
215 build_pretty_printers()
217 # vim:set shiftwidth=4 softtabstop=4 expandtab: