This commit is contained in:
Kovid Goyal 2011-09-29 22:10:40 -06:00
parent 0772f7d62b
commit d44734d9fe

View File

@ -452,24 +452,26 @@ class BlockAttr(StyleObject, LRFObject):
@classmethod @classmethod
def to_css(cls, obj, inline=False): def to_css(cls, obj, inline=False):
ans = '' ans = ''
def item(line): def item(line):
ans += '' if inline else '\t' ans = '' if inline else '\t'
ans += line ans += line
ans += ' ' if inline else '\n' ans += ' ' if inline else '\n'
return ans
if hasattr(obj, 'sidemargin'): if hasattr(obj, 'sidemargin'):
margin = str(obj.sidemargin) + 'px' margin = str(obj.sidemargin) + 'px'
item('margin-left: %(m)s; margin-right: %(m)s;'%dict(m=margin)) ans += item('margin-left: %(m)s; margin-right: %(m)s;'%dict(m=margin))
if hasattr(obj, 'topskip'): if hasattr(obj, 'topskip'):
item('margin-top: %dpx;'%obj.topskip) ans += item('margin-top: %dpx;'%obj.topskip)
if hasattr(obj, 'footskip'): if hasattr(obj, 'footskip'):
item('margin-bottom: %dpx;'%obj.footskip) ans += item('margin-bottom: %dpx;'%obj.footskip)
if hasattr(obj, 'framewidth'): if hasattr(obj, 'framewidth'):
item('border: solid %dpx'%obj.framewidth) ans += item('border: solid %dpx'%obj.framewidth)
if hasattr(obj, 'framecolor') and obj.framecolor.a < 255: if hasattr(obj, 'framecolor') and obj.framecolor.a < 255:
item('border-color: %s;'%obj.framecolor.to_html()) ans += item('border-color: %s;'%obj.framecolor.to_html())
if hasattr(obj, 'bgcolor') and obj.bgcolor.a < 255: if hasattr(obj, 'bgcolor') and obj.bgcolor.a < 255:
item('background-color: %s;'%obj.bgcolor.to_html()) ans += item('background-color: %s;'%obj.bgcolor.to_html())
return ans return ans
@ -480,39 +482,41 @@ class TextCSS(object):
@classmethod @classmethod
def to_css(cls, obj, inline=False): def to_css(cls, obj, inline=False):
ans = '' ans = ''
def item(line): def item(line):
ans += '' if inline else '\t' ans = '' if inline else '\t'
ans += line ans += line
ans += ' ' if inline else '\n' ans += ' ' if inline else '\n'
return ans
fs = getattr(obj, 'fontsize', None) fs = getattr(obj, 'fontsize', None)
if fs is not None: if fs is not None:
item('font-size: %fpt;'%(int(fs)/10.)) ans += item('font-size: %fpt;'%(int(fs)/10.))
fw = getattr(obj, 'fontweight', None) fw = getattr(obj, 'fontweight', None)
if fw is not None: if fw is not None:
item('font-weight: %s;'%('bold' if int(fw) >= 700 else 'normal')) ans += item('font-weight: %s;'%('bold' if int(fw) >= 700 else 'normal'))
fn = getattr(obj, 'fontfacename', None) fn = getattr(obj, 'fontfacename', None)
if fn is not None: if fn is not None:
fn = cls.FONT_MAP[fn] fn = cls.FONT_MAP[fn]
item('font-family: %s;'%fn) ans += item('font-family: %s;'%fn)
fg = getattr(obj, 'textcolor', None) fg = getattr(obj, 'textcolor', None)
if fg is not None: if fg is not None:
fg = fg.to_html() fg = fg.to_html()
item('color: %s;'%fg) ans += item('color: %s;'%fg)
bg = getattr(obj, 'textbgcolor', None) bg = getattr(obj, 'textbgcolor', None)
if bg is not None: if bg is not None:
bg = bg.to_html() bg = bg.to_html()
item('background-color: %s;'%bg) ans += item('background-color: %s;'%bg)
al = getattr(obj, 'align', None) al = getattr(obj, 'align', None)
if al is not None: if al is not None:
al = dict(head='left', center='center', foot='right') al = dict(head='left', center='center', foot='right')
item('text-align: %s;'%al) ans += item('text-align: %s;'%al)
lh = getattr(obj, 'linespace', None) lh = getattr(obj, 'linespace', None)
if lh is not None: if lh is not None:
item('text-align: %fpt;'%(int(lh)/10.)) ans += item('text-align: %fpt;'%(int(lh)/10.))
pi = getattr(obj, 'parindent', None) pi = getattr(obj, 'parindent', None)
if pi is not None: if pi is not None:
item('text-indent: %fpt;'%(int(pi)/10.)) ans += item('text-indent: %fpt;'%(int(pi)/10.))
return ans return ans