mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
More work on fast CSS transforms
This commit is contained in:
parent
7eac81456d
commit
d8d5e8edcb
@ -263,7 +263,7 @@ class Token {
|
||||
if (num > 0) {
|
||||
out.resize(out.size() + num);
|
||||
for (int i = 0; i < num; i++) out[i + out.size() - num] = buf[i];
|
||||
} else throw std::runtime_error("Failed to convert character to hexedecimal escape");
|
||||
} else throw std::logic_error("Failed to convert character to hexedecimal escape");
|
||||
} else out.push_back(ch);
|
||||
}
|
||||
|
||||
@ -586,8 +586,7 @@ class TokenQueue {
|
||||
if (!it->is_significant()) continue;
|
||||
if (key_found) {
|
||||
if (colon_found) {
|
||||
if (process_values) process_values(it);
|
||||
break;
|
||||
if (process_values && process_values(it)) changed = true;;
|
||||
} else {
|
||||
if (!it->is_delimiter(':')) break; // no colon found
|
||||
colon_found = true;
|
||||
@ -727,7 +726,8 @@ class TokenQueue {
|
||||
if (process_declaration()) changed = true;
|
||||
}
|
||||
if (changed && queue.size()) {
|
||||
out.resize(queue[0].get_output_position());
|
||||
const size_t pos = queue[0].get_output_position();
|
||||
out.resize(pos ? pos - 1: 0);
|
||||
for (auto tok : queue) tok.serialize(out);
|
||||
}
|
||||
return_tokens_to_pool();
|
||||
|
@ -6,14 +6,21 @@
|
||||
import ast
|
||||
|
||||
from calibre.srv.tests.base import SimpleTest
|
||||
from calibre_extensions.fast_css_transform import parse_css_number, transform_properties
|
||||
|
||||
|
||||
class TestTransform(SimpleTest):
|
||||
|
||||
def test_number_parsing(self):
|
||||
from calibre_extensions.fast_css_transform import parse_css_number
|
||||
for x in '.314 -.314 0.314 0 2 +2 -1 1e2 -3.14E+2 2e-2'.split():
|
||||
self.ae(parse_css_number(x), ast.literal_eval(x))
|
||||
self.ae(parse_css_number('2em'), 2)
|
||||
self.ae(parse_css_number('.3em'), 0.3)
|
||||
self.ae(parse_css_number('3x3'), 3)
|
||||
|
||||
def test_basic_css_transforms(self):
|
||||
def d(src, expected, is_declaration=True, url_callback=None):
|
||||
self.ae(transform_properties(src, is_declaration=is_declaration, url_callback=url_callback), expected)
|
||||
|
||||
# d('font-size: 16px', 'font-size: 1rem')
|
||||
# d('color: red', 'color: red')
|
||||
|
Loading…
x
Reference in New Issue
Block a user