From 1ddac886a440f233e9e62030891dfbffaf2c1c36 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 28 May 2021 06:13:43 +0530 Subject: [PATCH] E-book viewer: Fix regression in 5.15 that caused incorrect display of font sizes that contain a period and use absolute units. Fixes #1929862 [Font size transformed incorrectly](https://bugs.launchpad.net/calibre/+bug/1929862) --- src/calibre/srv/fast_css_transform.cpp | 5 ++--- src/calibre/srv/tests/fast_css_transform.py | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/calibre/srv/fast_css_transform.cpp b/src/calibre/srv/fast_css_transform.cpp index bb4dbc171a..493f32d350 100644 --- a/src/calibre/srv/fast_css_transform.cpp +++ b/src/calibre/srv/fast_css_transform.cpp @@ -97,7 +97,7 @@ static const double base_font_size = 16.0, dpi = 96.0, pt_to_px = dpi / 72.0, pt static double convert_font_size(double val, double factor) { - return (factor == 0.0) ? val / base_font_size : (val * factor * pt_to_rem); + return (factor == 0.0) ? (val / base_font_size) : (val * factor * pt_to_rem); } static integer_type @@ -975,8 +975,7 @@ class Parser { } void handle_number() { - if (is_digit(ch)) { token_queue.add_char(ch); return; } - if (ch == '.' && is_digit(peek())) { pop_state(); enter_digits_mode(); return; } + if (is_digit(ch) || (ch == '.' && is_digit(peek()))) { token_queue.add_char(ch); return; } if (starting_comment()) { enter_comment_mode(); return; } if ((ch == 'e' || ch == 'E')) { char32_t next = peek(); diff --git a/src/calibre/srv/tests/fast_css_transform.py b/src/calibre/srv/tests/fast_css_transform.py index 890df2cd34..015536e1ee 100644 --- a/src/calibre/srv/tests/fast_css_transform.py +++ b/src/calibre/srv/tests/fast_css_transform.py @@ -50,6 +50,10 @@ class TestTransform(SimpleTest): u('a:url( "( )" /**/ )', 'a:url("( )")') u('a:url( "(/*)" )', 'a:url( "(/*)" )', url_callback=lambda x: x) + d('font-size: 19.28px', 'font-size: 1.205rem') + d('font-size:+19.28px', 'font-size:1.205rem') + d('font-size: .28in', 'font-size: 1.68rem') + d('font-size: +.28in', 'font-size: 1.68rem') d(r'f\ont-s\69z\65 : 16\px', 'font-size: 1rem') d('font -size: 16px', 'font -size: 16px') d('font-/* */size: 1/*x*/6/**/p/**/x !important', 'font-size: 1rem !important')