src/reportlab/platypus/paraparser.py
changeset 4315 7c65c6e52b13
parent 4277 838129322a55
child 4330 617ffa6bbdc8
equal deleted inserted replaced
4314:27d3ed39ad3e 4315:7c65c6e52b13
    89     if s.endswith('%'):
    89     if s.endswith('%'):
    90         return _PCT(_convnum(s[:-1],allowRelative=allowRelative))
    90         return _PCT(_convnum(s[:-1],allowRelative=allowRelative))
    91     else:
    91     else:
    92         return _num(s,unit,allowRelative)
    92         return _num(s,unit,allowRelative)
    93 
    93 
    94 class _PCT:
    94 class _PCT(float):
    95     def __init__(self,v):
    95     def __new__(cls,v):
    96         self._value = v*0.01
    96         self = float.__new__(cls,v*0.01)
       
    97         self._normalizer = 1.0
       
    98         self._value = v
       
    99         return self
    97 
   100 
    98     def normalizedValue(self,normalizer):
   101     def normalizedValue(self,normalizer):
    99         normalizer = normalizer or getattr(self,'_normalizer')
   102         if not normalizer:
   100         return normalizer*self._value
   103             normaliser = self._normalizer
       
   104         r = _PCT(normalizer*self._value)
       
   105         r._value = self._value
       
   106         r._normalizer = normalizer
       
   107         return r
   101 
   108 
   102 def fontSizeNormalize(frag,attr,default):
   109 def fontSizeNormalize(frag,attr,default):
   103     if not hasattr(frag,attr): return default
   110     if not hasattr(frag,attr): return default
   104     v = _numpct(getattr(frag,attr),allowRelative=True)
   111     v = _numpct(getattr(frag,attr),allowRelative=True)
   105     return (v[1]+frag.fontSize) if isinstance(v,tuple) else v.normalizedValue(frag.fontSize) if isinstance(v,_PCT) else v
   112     return (v[1]+frag.fontSize) if isinstance(v,tuple) else v.normalizedValue(frag.fontSize) if isinstance(v,_PCT) else v