mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Conversion: Add support for the CSS text-transform property when subsetting embedded fonts
This commit is contained in:
parent
1365b44d33
commit
1fbec2919f
@ -15,6 +15,8 @@ from calibre.ebooks.oeb.base import css_text, urlnormalize
|
|||||||
from calibre.utils.fonts.subset import subset
|
from calibre.utils.fonts.subset import subset
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
font_properties = ('font-family', 'src', 'font-weight', 'font-stretch', 'font-style', 'text-transform')
|
||||||
|
|
||||||
|
|
||||||
def get_font_properties(rule, default=None):
|
def get_font_properties(rule, default=None):
|
||||||
'''
|
'''
|
||||||
@ -24,8 +26,7 @@ def get_font_properties(rule, default=None):
|
|||||||
'''
|
'''
|
||||||
props = {}
|
props = {}
|
||||||
s = rule.style
|
s = rule.style
|
||||||
for q in ('font-family', 'src', 'font-weight', 'font-stretch',
|
for q in font_properties:
|
||||||
'font-style'):
|
|
||||||
g = 'uri' if q == 'src' else 'value'
|
g = 'uri' if q == 'src' else 'value'
|
||||||
try:
|
try:
|
||||||
val = s.getProperty(q).propertyValue[0]
|
val = s.getProperty(q).propertyValue[0]
|
||||||
@ -299,13 +300,20 @@ class SubsetFonts:
|
|||||||
if matches:
|
if matches:
|
||||||
return matches[0]
|
return matches[0]
|
||||||
|
|
||||||
def find_chars(self, elem):
|
def find_chars(self, elem, style):
|
||||||
ans = set()
|
ans = set()
|
||||||
|
transform = lambda x: x # noqa
|
||||||
|
tt = style.get('text-transform')
|
||||||
|
if tt:
|
||||||
|
if tt in ('uppercase', 'capitalize'):
|
||||||
|
transform = str.upper
|
||||||
|
elif tt == 'lowercase':
|
||||||
|
transform = str.lower
|
||||||
if elem.text:
|
if elem.text:
|
||||||
ans |= set(elem.text)
|
ans |= set(transform(elem.text))
|
||||||
for child in elem:
|
for child in elem:
|
||||||
if child.tail:
|
if child.tail:
|
||||||
ans |= set(child.tail)
|
ans |= set(transform(child.tail))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def find_usage_in(self, elem, inherited_style):
|
def find_usage_in(self, elem, inherited_style):
|
||||||
@ -314,6 +322,6 @@ class SubsetFonts:
|
|||||||
self.find_usage_in(child, style)
|
self.find_usage_in(child, style)
|
||||||
font = self.used_font(style)
|
font = self.used_font(style)
|
||||||
if font:
|
if font:
|
||||||
chars = self.find_chars(elem)
|
chars = self.find_chars(elem, style)
|
||||||
if chars:
|
if chars:
|
||||||
font['chars'] |= chars
|
font['chars'] |= chars
|
||||||
|
Loading…
x
Reference in New Issue
Block a user