mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
MOBI Output: Allow setting of background color on tables. Fixes #797580 (Private bug)
This commit is contained in:
parent
93dcb24eb5
commit
f56abca9df
@ -443,11 +443,15 @@ class MobiMLizer(object):
|
|||||||
tag = 'span' if tag == 'td' else 'div'
|
tag = 'span' if tag == 'td' else 'div'
|
||||||
|
|
||||||
if tag == 'table':
|
if tag == 'table':
|
||||||
|
col = style.backgroundColor
|
||||||
|
if col:
|
||||||
|
elem.set('bgcolor', col)
|
||||||
css = style.cssdict()
|
css = style.cssdict()
|
||||||
if 'border' in css or 'border-width' in css:
|
if 'border' in css or 'border-width' in css:
|
||||||
elem.set('border', '1')
|
elem.set('border', '1')
|
||||||
if tag in TABLE_TAGS:
|
if tag in TABLE_TAGS:
|
||||||
for attr in ('rowspan', 'colspan', 'width', 'border', 'scope'):
|
for attr in ('rowspan', 'colspan', 'width', 'border', 'scope',
|
||||||
|
'bgcolor'):
|
||||||
if attr in elem.attrib:
|
if attr in elem.attrib:
|
||||||
istate.attrib[attr] = elem.attrib[attr]
|
istate.attrib[attr] = elem.attrib[attr]
|
||||||
if tag == 'q':
|
if tag == 'q':
|
||||||
|
@ -473,6 +473,7 @@ class Style(object):
|
|||||||
self._width = None
|
self._width = None
|
||||||
self._height = None
|
self._height = None
|
||||||
self._lineHeight = None
|
self._lineHeight = None
|
||||||
|
self._bgcolor = None
|
||||||
stylizer._styles[element] = self
|
stylizer._styles[element] = self
|
||||||
|
|
||||||
def set(self, prop, val):
|
def set(self, prop, val):
|
||||||
@ -533,6 +534,44 @@ class Style(object):
|
|||||||
def pt_to_px(self, value):
|
def pt_to_px(self, value):
|
||||||
return (self._profile.dpi / 72.0) * value
|
return (self._profile.dpi / 72.0) * value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def backgroundColor(self):
|
||||||
|
'''
|
||||||
|
Return the background color by parsing both the background-color and
|
||||||
|
background shortcut properties. Note that inheritance/default values
|
||||||
|
are not used.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def validate_color(col):
|
||||||
|
return cssutils.profile.validateWithProfile('color',
|
||||||
|
col,
|
||||||
|
profiles=[cssutils.profiles.Profiles.CSS_LEVEL_2])[1]
|
||||||
|
|
||||||
|
if self._bgcolor is None:
|
||||||
|
val = self._style.get('background-color', None)
|
||||||
|
if val and validate_color(val):
|
||||||
|
col = val
|
||||||
|
else:
|
||||||
|
val = self._style.get('background', None)
|
||||||
|
if val is not None:
|
||||||
|
try:
|
||||||
|
style = cssutils.parseStyle('background: '+val)
|
||||||
|
val = style.getProperty('background').cssValue
|
||||||
|
try:
|
||||||
|
val = list(val)
|
||||||
|
except:
|
||||||
|
# val is CSSPrimitiveValue
|
||||||
|
val = [val]
|
||||||
|
for c in val:
|
||||||
|
c = c.cssText
|
||||||
|
if validate_color(c):
|
||||||
|
col = c
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self._bgcolor = col
|
||||||
|
return self._bgcolor
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fontSize(self):
|
def fontSize(self):
|
||||||
def normalize_fontsize(value, base):
|
def normalize_fontsize(value, base):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user