mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
12e9769b4b
commit
584eacdee4
@ -25,6 +25,8 @@
|
|||||||
#include <frozen/unordered_map.h>
|
#include <frozen/unordered_map.h>
|
||||||
#include <frozen/string.h>
|
#include <frozen/string.h>
|
||||||
#include "../utils/cpp_binding.h"
|
#include "../utils/cpp_binding.h"
|
||||||
|
#define STB_SPRINTF_IMPLEMENTATION
|
||||||
|
#include "../utils/stb_sprintf.h"
|
||||||
|
|
||||||
// character classes {{{
|
// character classes {{{
|
||||||
static inline bool
|
static inline bool
|
||||||
@ -242,7 +244,7 @@ class Token {
|
|||||||
out.push_back('\\');
|
out.push_back('\\');
|
||||||
if (is_whitespace(ch) || is_hex_digit(ch)) {
|
if (is_whitespace(ch) || is_hex_digit(ch)) {
|
||||||
char buf[8];
|
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) {
|
if (num > 0) {
|
||||||
out.resize(out.size() + num);
|
out.resize(out.size() + num);
|
||||||
for (int i = 0; i < num; i++) out[i + out.size() - num] = buf[i];
|
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);
|
double new_val = convert_font_size(val, lit->second);
|
||||||
if (val == new_val) return false;
|
if (val == new_val) return false;
|
||||||
char txt[128];
|
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");
|
if (num <= 0) throw std::runtime_error("Failed to format font size");
|
||||||
set_ascii_text(txt, num);
|
set_ascii_text(txt, num);
|
||||||
return true;
|
return true;
|
||||||
|
@ -50,6 +50,7 @@ class TestTransform(SimpleTest):
|
|||||||
u('a:url( "( )" /**/ )', 'a:url("( )")')
|
u('a:url( "( )" /**/ )', 'a:url("( )")')
|
||||||
u('a:url( "(/*)" )', 'a:url( "(/*)" )', url_callback=lambda x: x)
|
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:+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')
|
||||||
|
1879
src/calibre/utils/stb_sprintf.h
Normal file
1879
src/calibre/utils/stb_sprintf.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user