Font subsetting: Implement support for text-transform. See #1568555 (Subsets of fonts with CSS set to uppercase or small-caps variants)

This commit is contained in:
Kovid Goyal 2016-04-11 05:13:42 +05:30
parent 6305d5c647
commit d5a37ea0f5
3 changed files with 14 additions and 1 deletions

Binary file not shown.

View File

@ -26,6 +26,7 @@ font_dict = (style, computed=false) ->
'font-weight':style.getPropertyValue('font-weight'),
'font-style':style.getPropertyValue('font-style'),
'font-stretch':style.getPropertyValue('font-stretch'),
'text-transform':style.getPropertyValue('text-transform'),
}
font_usage = (node) ->

View File

@ -191,6 +191,7 @@ class StatsCollector(object):
must_use_qt()
self.parser = CSSParser(loglevel=logging.CRITICAL, log=logging.getLogger('calibre.css'))
self.first_letter_pat = regex.compile(r'^[\p{Ps}\p{Ps}\p{Pe}\p{Pi}\p{Pf}\p{Po}]+', regex.VERSION1 | regex.UNICODE)
self.capitalize_pat = regex.compile(r'[\p{L}\p{N}]', regex.VERSION1 | regex.UNICODE)
self.loop = QEventLoop()
self.view = QWebView()
@ -337,6 +338,16 @@ class StatsCollector(object):
for font in font_usage:
text = set()
for t in font['text']:
tt = font['text-transform']
if tt != 'none':
if tt == 'uppercase':
t = icu_upper(t)
elif tt == 'lowercase':
t = icu_lower(t)
elif tt == 'capitalize':
m = self.capitalize_pat.search(t)
if m is not None:
t += icu_upper(m.group())
text |= frozenset(t)
text.difference_update(exclude)
if not text:
@ -374,4 +385,5 @@ if __name__ == '__main__':
from calibre.utils.logging import default_log
default_log.filter_level = default_log.DEBUG
ebook = get_container(sys.argv[-1], default_log)
print (StatsCollector(ebook, do_embed=True).font_stats)
from pprint import pprint
pprint(StatsCollector(ebook, do_embed=True).font_stats)