fix parsing length in html. Fixes #3781

This commit is contained in:
Yann Leboulanger 2009-02-16 10:15:44 +00:00
parent a2b534c040
commit 4ddcdcc40a
1 changed files with 9 additions and 8 deletions

View File

@ -319,27 +319,28 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
callback(frac, *args) callback(frac, *args)
return return
val = float(value[:-2]) def get_val():
sign = cmp(val,0) val = float(value[:-2])
# validate length sign = cmp(val,0)
val = sign*max(minl,min(abs(val*display_resolution),maxl)) # validate length
return sign*max(minl,min(abs(val*display_resolution),maxl))
if value.endswith('pt'): # points if value.endswith('pt'): # points
callback(val*display_resolution, *args) callback(get_val()*display_resolution, *args)
elif value.endswith('em'): # ems, the width of the element's font elif value.endswith('em'): # ems, the width of the element's font
attrs = self._get_current_attributes() attrs = self._get_current_attributes()
font_size = attrs.font.get_size() / pango.SCALE font_size = attrs.font.get_size() / pango.SCALE
callback(val*display_resolution*font_size, *args) callback(get_val()*display_resolution*font_size, *args)
elif value.endswith('ex'): # x-height, ~ the height of the letter 'x' elif value.endswith('ex'): # x-height, ~ the height of the letter 'x'
# FIXME: figure out how to calculate this correctly # FIXME: figure out how to calculate this correctly
# for now 'em' size is used as approximation # for now 'em' size is used as approximation
attrs = self._get_current_attributes() attrs = self._get_current_attributes()
font_size = attrs.font.get_size() / pango.SCALE font_size = attrs.font.get_size() / pango.SCALE
callback(val*display_resolution*font_size, *args) callback(get_val()*display_resolution*font_size, *args)
elif value.endswith('px'): # pixels elif value.endswith('px'): # pixels
callback(val, *args) callback(get_val(), *args)
else: else:
try: try: