Conversion: Do not change viewport relative font sizes used for SVG text elements. Fixes #2058798 [unwanted changes of svg code during conversion](https://bugs.launchpad.net/calibre/+bug/2058798)

This commit is contained in:
Kovid Goyal 2024-04-01 12:11:49 +05:30
parent a227d5e3be
commit 5313a21464
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 18 additions and 1 deletions

View File

@ -428,10 +428,23 @@ class Stylizer:
no_important_properties = frozenset()
svg_text_tags = tuple(map(SVG, ('text', 'textPath', 'tref', 'tspan')))
def is_only_number(x: str) -> bool:
try:
float(x)
return True
except Exception:
return False
def is_svg_text_tag(x):
return getattr(x, 'tag', '') in svg_text_tags
class Style:
MS_PAT = re.compile(r'^\s*(mso-|panose-|text-underline|tab-interval)')
viewport_relative_font_size: str = ''
def __init__(self, element, stylizer):
self._element = element
@ -628,6 +641,8 @@ class Style:
base = self._profile.fbase
if 'font-size' in self._style:
size = self._style['font-size']
if is_svg_text_tag(self._element) and (size.endswith('px') or is_only_number(size)):
self.viewport_relative_font_size = size
result = normalize_fontsize(size, base)
else:
result = base

View File

@ -453,7 +453,9 @@ class CSSFlattener:
if dp.tag and dp.tag.endswith('}div') and len(dp) == 1 and not dp.text:
if stylizer.style(dp).cssdict().get('float', None) == 'left':
is_drop_cap = True
if not self.context.disable_font_rescaling and not is_drop_cap:
if style.viewport_relative_font_size:
cssdict['font-size'] = style.viewport_relative_font_size
elif not self.context.disable_font_rescaling and not is_drop_cap:
_sbase = self.sbase if self.sbase is not None else \
self.context.source.fbase
dyn_rescale = node.attrib.pop('data-calibre-rescale', None)