Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / gdb / libreoffice / basegfx.py
blobec564b99c90306ec23b2c1b9d4bd4b8f39909b21
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
11 import six
13 from libreoffice.util import printing
15 class B2DRangePrinter(object):
16 '''Prints a B2DRange object.'''
18 def __init__(self, typename, value):
19 self.typename = typename
20 self.value = value
21 # inject children() func dynamically
22 if not self._isEmpty():
23 self.children = self._children
25 def to_string(self):
26 if self._isEmpty():
27 return "empty %s" % (self.typename)
28 else:
29 return "%s" % (self.typename)
31 def _isEmpty(self):
32 return (self.value['maRangeX']['mnMinimum'] > self.value['maRangeX']['mnMaximum']
33 or self.value['maRangeY']['mnMinimum'] > self.value['maRangeY']['mnMaximum'])
35 def _children(self):
36 left = self.value['maRangeX']['mnMinimum']
37 top = self.value['maRangeY']['mnMinimum']
38 right = self.value['maRangeX']['mnMaximum']
39 bottom = self.value['maRangeY']['mnMaximum']
40 children = [('left', left), ('top', top), ('right', right), ('bottom', bottom)]
41 return children.__iter__()
43 class B2DPolygonPrinter(object):
44 '''Prints a B2DPolygon object.'''
46 def __init__(self, typename, value):
47 self.typename = typename
48 self.value = value
49 # inject children() func dynamically
50 if not self._isEmpty():
51 self.children = self._children
53 def to_string(self):
54 if self._isEmpty():
55 return "empty %s" % (self.typename)
56 else:
57 return "%s %s" % ('bezier curve' if self._hasCurves() else 'straight line',
58 self.typename)
60 def _count(self):
61 return int(gdb.parse_and_eval(
62 '((basegfx::B2DPolygon*)%d)->count()' % self.value.address))
64 def _isEmpty(self):
65 return self._count() == 0
67 def _hasCurves(self):
68 return int(gdb.parse_and_eval(
69 '((basegfx::B2DPolygon*)%d)->areControlPointsUsed()' % self.value.address)) != 0
71 def _children(self):
72 if self._hasCurves():
73 return self._bezierIterator(self._count(), self.value)
74 else:
75 return self._plainIterator(self._count(), self.value)
77 class _plainIterator(six.Iterator):
78 def __init__(self, count, value):
79 self.count = count
80 self.value = value
81 self.index = 0
83 def __iter__(self):
84 return self
86 def __next__(self):
87 if self.index >= self.count:
88 raise StopIteration()
89 currPoint = gdb.parse_and_eval(
90 '((basegfx::B2DPolygon*)%d)->getB2DPoint(%d)' % (
91 self.value.address, self.index))
92 currPoint = gdb.parse_and_eval(
93 '((basegfx::B2DPolygon*)%d)->getB2DPoint(%d)' % (
94 self.value.address, self.index))
95 self.index += 1
96 return ('point %d' % (self.index-1),
97 '(%15f, %15f)' % (currPoint['mfX'], currPoint['mfY']))
99 class _bezierIterator(six.Iterator):
100 def __init__(self, count, value):
101 self.count = count
102 self.value = value
103 self.index = 0
105 def __iter__(self):
106 return self
108 def __next__(self):
109 if self.index >= self.count:
110 raise StopIteration()
111 currPoint = gdb.parse_and_eval(
112 '((basegfx::B2DPolygon*)%d)->getB2DPoint(%d)' % (
113 self.value.address, self.index))
114 prevControl = gdb.parse_and_eval(
115 '((basegfx::B2DPolygon*)%d)->getPrevControlPoint(%d)' % (
116 self.value.address, self.index))
117 nextControl = gdb.parse_and_eval(
118 '((basegfx::B2DPolygon*)%d)->getNextControlPoint(%d)' % (
119 self.value.address, self.index))
120 self.index += 1
121 return ('point %d' % (self.index-1),
122 'p: (%15f, %15f) c-1: (%15f, %15f) c1: (%15f, %15f)' %
123 (currPoint['mfX'], currPoint['mfY'],
124 prevControl['mfX'], prevControl['mfY'],
125 nextControl['mfX'], nextControl['mfY']))
127 class B2DPolyPolygonPrinter(object):
128 '''Prints a B2DPolyPolygon object.'''
130 def __init__(self, typename, value):
131 self.typename = typename
132 self.value = value
134 def to_string(self):
135 if self._isEmpty():
136 return "empty %s" % (self.typename)
137 else:
138 return "%s %s with %d sub-polygon(s)" % ('closed' if self._isClosed() else 'open',
139 self.typename,
140 self._count())
142 def _count(self):
143 return int(gdb.parse_and_eval(
144 '((basegfx::B2DPolyPolygon*)%d)->count()' % self.value.address))
146 def _isClosed(self):
147 return int(gdb.parse_and_eval(
148 '((basegfx::B2DPolyPolygon*)%d)->isClosed()' % self.value.address)) != 0
150 def _isEmpty(self):
151 return self._count() == 0
153 printer = None
155 def build_pretty_printers():
156 global printer
158 printer = printing.Printer('libreoffice/basegfx')
160 # basic types
161 printer.add('basegfx::B2DRange', B2DRangePrinter)
162 printer.add('basegfx::B2DPolygon', B2DPolygonPrinter)
163 printer.add('basegfx::B2DPolyPolygon', B2DPolyPolygonPrinter)
165 def register_pretty_printers(obj):
166 printing.register_pretty_printer(printer, obj)
168 build_pretty_printers()
170 # vim:set shiftwidth=4 softtabstop=4 expandtab: