mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
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:
parent
6305d5c647
commit
d5a37ea0f5
Binary file not shown.
@ -26,6 +26,7 @@ font_dict = (style, computed=false) ->
|
|||||||
'font-weight':style.getPropertyValue('font-weight'),
|
'font-weight':style.getPropertyValue('font-weight'),
|
||||||
'font-style':style.getPropertyValue('font-style'),
|
'font-style':style.getPropertyValue('font-style'),
|
||||||
'font-stretch':style.getPropertyValue('font-stretch'),
|
'font-stretch':style.getPropertyValue('font-stretch'),
|
||||||
|
'text-transform':style.getPropertyValue('text-transform'),
|
||||||
}
|
}
|
||||||
|
|
||||||
font_usage = (node) ->
|
font_usage = (node) ->
|
||||||
|
@ -191,6 +191,7 @@ class StatsCollector(object):
|
|||||||
must_use_qt()
|
must_use_qt()
|
||||||
self.parser = CSSParser(loglevel=logging.CRITICAL, log=logging.getLogger('calibre.css'))
|
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.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.loop = QEventLoop()
|
||||||
self.view = QWebView()
|
self.view = QWebView()
|
||||||
@ -337,6 +338,16 @@ class StatsCollector(object):
|
|||||||
for font in font_usage:
|
for font in font_usage:
|
||||||
text = set()
|
text = set()
|
||||||
for t in font['text']:
|
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 |= frozenset(t)
|
||||||
text.difference_update(exclude)
|
text.difference_update(exclude)
|
||||||
if not text:
|
if not text:
|
||||||
@ -374,4 +385,5 @@ if __name__ == '__main__':
|
|||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
default_log.filter_level = default_log.DEBUG
|
default_log.filter_level = default_log.DEBUG
|
||||||
ebook = get_container(sys.argv[-1], default_log)
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user