Fixed issue where anchors not reporting correct position

This commit is contained in:
Zen-CODE 2014-06-14 16:42:55 +02:00
parent 436205b751
commit e10cf0180d
1 changed files with 10 additions and 6 deletions

View File

@ -66,6 +66,7 @@ class MarkupLabel(MarkupLabelBase):
def __init__(self, *largs, **kwargs):
self._style_stack = {}
self._refs = {}
self._anchors = {}
super(MarkupLabel, self).__init__(*largs, **kwargs)
self._internal_size = 0, 0
self._cached_lines = []
@ -133,6 +134,7 @@ class MarkupLabel(MarkupLabelBase):
spop = self._pop_style
opts = options = self.options
options['_ref'] = None
options['_anchor'] = None
options['script'] = 'normal'
shorten = options['shorten']
# if shorten, then don't split lines to fit uw, because it will be
@ -209,12 +211,7 @@ class MarkupLabel(MarkupLabelBase):
elif item == '[/ref]':
spop('_ref')
elif not clipped and item[:8] == '[anchor=':
ref = item[8:-1]
if len(lines):
x, y = lines[-1].x, lines[-1].y
else:
x = y = 0
self._anchors[ref] = x, y
options['_anchor'] = item[8:-1]
elif not clipped:
item = item.replace('&bl;', '[').replace(
'&br;', ']').replace('&', '&')
@ -392,6 +389,7 @@ class MarkupLabel(MarkupLabelBase):
halign = options['halign']
valign = options['valign']
refs = self._refs
anchors = self._anchors
self._render_begin()
if valign == 'bottom':
@ -433,6 +431,12 @@ class MarkupLabel(MarkupLabelBase):
if not ref in refs:
refs[ref] = []
refs[ref].append((x, y, x + word.lw, y + word.lh))
# Should we record anchors?
anchor = options['_anchor']
if anchor is not None:
if not anchor in anchors:
anchors[anchor] = (x, y)
x += word.lw
y += lh