From 623dabed7fbee383bd6f6f2c8182176bca020f17 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 25 Feb 2015 10:35:36 +0530 Subject: [PATCH] PDF Output: Fix incorrect rendering of text in elements that use font-variant:small-caps and also have children. Fixes #1425094 [small caps not rendering with line breaks](https://bugs.launchpad.net/calibre/+bug/1425094) --- .../ebooks/conversion/plugins/pdf_output.py | 47 ------------------- 1 file changed, 47 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/pdf_output.py b/src/calibre/ebooks/conversion/plugins/pdf_output.py index 7773359051..56c8d94e32 100644 --- a/src/calibre/ebooks/conversion/plugins/pdf_output.py +++ b/src/calibre/ebooks/conversion/plugins/pdf_output.py @@ -260,50 +260,3 @@ class PDFOutput(OutputFormatPlugin): if close: out_stream.close() - - def specialize_css_for_output(self, log, opts, item, stylizer): - ''' Qt WebKit (4.8.x) cannot handle font-variant: small-caps. It tries to fake the small caps, - which is ok, but the faking continues on to subsequent text that should not be in small-caps. - So we workaround the problem by faking small caps ourselves. A minimal example that Qt chokes on: - -

Some Small-caps Text

-

Some non small-caps text with enough text for at least one - full line and justification enabled. Both of these are needed for the example to work.

- ''' - from calibre.ebooks.oeb.base import XHTML - import itertools, string - if not hasattr(item.data, 'xpath'): - return - ws = unicode(string.whitespace) - - def fake_small_caps(elem): - spans = [] - for lowercase, textiter in itertools.groupby(elem.text, lambda x:x not in ws and icu_lower(x)==x): - text = ''.join(textiter) - if lowercase: - text = icu_upper(text) - span = elem.makeelement(XHTML('span')) - span.text = text - style = stylizer.style(span) - if lowercase: - style.set('font-size', '0.65em') - spans.append(span) - elem.text = None - elem[0:] = spans - - def process_elem(elem, parent_fv=None): - children = tuple(elem) - style = stylizer.style(elem) - fv = style.drop('font-variant') - if not fv or fv.lower() == 'inherit': - fv = parent_fv - if fv and fv.lower() in {'smallcaps', 'small-caps'}: - if elem.text: - fake_small_caps(elem) - for child in children: - if hasattr(getattr(child, 'tag', None), 'lower'): - process_elem(child, parent_fv=fv) - - for body in item.data.xpath('//*[local-name()="body"]'): - process_elem(body) -