E-book viewer: Fix font sizes specified in absolute units not being honored in locales where the decimal separator is not the period. Fixes #1932152 [The e-book viewer ignores font-size property when using some absolute lenght units](https://bugs.launchpad.net/calibre/+bug/1932152)

This commit is contained in:
Kovid Goyal 2021-06-16 21:55:51 +05:30
parent 12e9769b4b
commit 584eacdee4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 1885 additions and 2 deletions

View File

@ -25,6 +25,8 @@
#include <frozen/unordered_map.h>
#include <frozen/string.h>
#include "../utils/cpp_binding.h"
#define STB_SPRINTF_IMPLEMENTATION
#include "../utils/stb_sprintf.h"
// character classes {{{
static inline bool
@ -242,7 +244,7 @@ class Token {
out.push_back('\\');
if (is_whitespace(ch) || is_hex_digit(ch)) {
char buf[8];
int num = std::snprintf(buf, sizeof(buf), "%x ", (unsigned int)ch);
int num = stbsp_snprintf(buf, sizeof(buf), "%x ", (unsigned int)ch);
if (num > 0) {
out.resize(out.size() + num);
for (int i = 0; i < num; i++) out[i + out.size() - num] = buf[i];
@ -446,7 +448,8 @@ class Token {
double new_val = convert_font_size(val, lit->second);
if (val == new_val) return false;
char txt[128];
int num = std::snprintf(txt, sizeof(txt), "%grem", new_val);
// stbsp_snprintf is locale independent unlike std::snprintf
int num = stbsp_snprintf(txt, sizeof(txt), "%grem", new_val);
if (num <= 0) throw std::runtime_error("Failed to format font size");
set_ascii_text(txt, num);
return true;

View File

@ -50,6 +50,7 @@ class TestTransform(SimpleTest):
u('a:url( "( )" /**/ )', 'a:url("( )")')
u('a:url( "(/*)" )', 'a:url( "(/*)" )', url_callback=lambda x: x)
d('font-size: 197583965730245.28px', 'font-size: 1.2349e+13rem')
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')

File diff suppressed because it is too large Load Diff