mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DOCX Input: Leave undefined text colors in the input document as undefined (currentColor in CSS). Fixes #1888897 [Text color mangling converting from DOCX to EPUB/AZW3](https://bugs.launchpad.net/calibre/+bug/1888897)
This commit is contained in:
parent
22acded7a2
commit
d0a5b4b2a5
@ -46,7 +46,7 @@ def binary_property(parent, name, XPath, get):
|
|||||||
return True if val in {'on', '1', 'true'} else False
|
return True if val in {'on', '1', 'true'} else False
|
||||||
|
|
||||||
|
|
||||||
def simple_color(col, auto='black'):
|
def simple_color(col, auto='currentColor'):
|
||||||
if not col or col == 'auto' or len(col) != 6:
|
if not col or col == 'auto' or len(col) != 6:
|
||||||
return auto
|
return auto
|
||||||
return '#'+col
|
return '#'+col
|
||||||
|
@ -333,7 +333,7 @@ class Styles(object):
|
|||||||
def cascade(self, layers):
|
def cascade(self, layers):
|
||||||
self.body_font_family = 'serif'
|
self.body_font_family = 'serif'
|
||||||
self.body_font_size = '10pt'
|
self.body_font_size = '10pt'
|
||||||
self.body_color = 'black'
|
self.body_color = 'currentColor'
|
||||||
|
|
||||||
def promote_property(char_styles, block_style, prop):
|
def promote_property(char_styles, block_style, prop):
|
||||||
vals = {getattr(s, prop) for s in char_styles}
|
vals = {getattr(s, prop) for s in char_styles}
|
||||||
@ -359,10 +359,12 @@ class Styles(object):
|
|||||||
# The default text decoration is 'none'
|
# The default text decoration is 'none'
|
||||||
s.text_decoration = inherit
|
s.text_decoration = inherit
|
||||||
|
|
||||||
def promote_most_common(block_styles, prop, default):
|
def promote_most_common(block_styles, prop, default, inherit_means=None):
|
||||||
c = Counter()
|
c = Counter()
|
||||||
for s in block_styles:
|
for s in block_styles:
|
||||||
val = getattr(s, prop)
|
val = getattr(s, prop)
|
||||||
|
if val is inherit and inherit_means is not None:
|
||||||
|
val = inherit_means
|
||||||
if val is not inherit:
|
if val is not inherit:
|
||||||
c[val] += 1
|
c[val] += 1
|
||||||
val = None
|
val = None
|
||||||
@ -370,6 +372,8 @@ class Styles(object):
|
|||||||
val = c.most_common(1)[0][0]
|
val = c.most_common(1)[0][0]
|
||||||
for s in block_styles:
|
for s in block_styles:
|
||||||
oval = getattr(s, prop)
|
oval = getattr(s, prop)
|
||||||
|
if oval is inherit and inherit_means is not None:
|
||||||
|
oval = inherit_means
|
||||||
if oval is inherit:
|
if oval is inherit:
|
||||||
if default != val:
|
if default != val:
|
||||||
setattr(s, prop, default)
|
setattr(s, prop, default)
|
||||||
@ -387,7 +391,7 @@ class Styles(object):
|
|||||||
if fs is not None:
|
if fs is not None:
|
||||||
self.body_font_size = '%.3gpt' % fs
|
self.body_font_size = '%.3gpt' % fs
|
||||||
|
|
||||||
color = promote_most_common(block_styles, 'color', self.body_color)
|
color = promote_most_common(block_styles, 'color', self.body_color, inherit_means='currentColor')
|
||||||
if color is not None:
|
if color is not None:
|
||||||
self.body_color = color
|
self.body_color = color
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user