From 61d85f6c22a0b5acdc33d5b02e76e44d012b41a1 Mon Sep 17 00:00:00 2001 From: Kiryl Date: Wed, 29 Sep 2021 20:22:47 +0300 Subject: [PATCH] Change Law -> Live --- src/book_solver.py | 4 ++-- src/css_reader.py | 25 ++++++++++++------------- src/epub_converter.py | 2 +- src/html_docx_preprocessor.py | 6 +++--- src/livecarta_config.py | 4 ++-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/book_solver.py b/src/book_solver.py index f4294d1..26b61c2 100644 --- a/src/book_solver.py +++ b/src/book_solver.py @@ -129,7 +129,7 @@ class BookSolver: content_dict = self.get_converted_book() self.write_to_json(content_dict) self.send_json_content_to_server(content_dict) - self.logger_object.log(f'End of the conversion to LawCarta format. Check {self.output_path}.') + self.logger_object.log(f'End of the conversion to LiveCarta format. Check {self.output_path}.') except Exception as exc: self.status_wrapper.set_error() @@ -142,7 +142,7 @@ class BookSolver: with open('tmp.json') as f: d = json.load(f) self.send_json_content_to_server(d) - self.logger_object.log(f'End of the conversion to LawCarta format. Check {self.output_path}.') + self.logger_object.log(f'End of the conversion to LiveCarta format. Check {self.output_path}.') except Exception as exc: self.status_wrapper.set_error() diff --git a/src/css_reader.py b/src/css_reader.py index 4ea7514..94b98fe 100644 --- a/src/css_reader.py +++ b/src/css_reader.py @@ -30,7 +30,7 @@ list_types = ['circle', 'disc', 'armenian', 'decimal', def convert_font_size(value): if 'pt' in value: - if int(value.replace('pt', '')) == LiveCartaConfig.LAWCARTA_DEFAULT_FONT_SIZE: + if int(value.replace('pt', '')) == LiveCartaConfig.LIVECARTA_DEFAULT_FONT_SIZE: return '' else: return value.replace('pt', 'px') @@ -252,6 +252,7 @@ class TagStyleConverter: if item[0] in ['text-indent', 'margin-left']: item[1] = convert_indents(item[1]) clean_style += item[0] + ': ' + item[1] + '; ' + print(clean_style, '\n') margin_left_regexp = re.compile( r'(margin-left:( *-*\w+);*)') @@ -266,24 +267,22 @@ class TagStyleConverter: filter(str.isdigit, str(has_margin_left.group(2)))))) if has_text_indent: - if has_text_indent.group(1): - num_ti = abs(int("".join( - filter(str.isdigit, str(has_text_indent.group(2)))))) - clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' + - str(abs(num_ml - num_ti)) + 'px; ') - clean_style = clean_style.replace(has_margin_left.group(1), '') - return clean_style + num_ti = abs(int("".join( + filter(str.isdigit, str(has_text_indent.group(2)))))) + clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' + + str(abs(num_ml - num_ti)) + 'px; ') + clean_style = clean_style.replace(has_margin_left.group(1), '') + return clean_style clean_style = clean_style.replace(has_margin_left.group(1), 'text-indent: ' + str(abs(num_ml)) + 'px; ') return clean_style elif has_text_indent: - if has_text_indent.group(1): - clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' + - str(abs(int("".join( - filter(str.isdigit, str(has_text_indent.group(2))))))) + 'px; ') - return clean_style + clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' + + str(abs(int("".join( + filter(str.isdigit, str(has_text_indent.group(2))))))) + 'px; ') + return clean_style return clean_style def preprocess_style(self): diff --git a/src/epub_converter.py b/src/epub_converter.py index baafcf0..8dec743 100644 --- a/src/epub_converter.py +++ b/src/epub_converter.py @@ -455,7 +455,7 @@ if __name__ == "__main__": logger_object = BookLogger(name=f'epub', main_logger=logger, book_id=0) - json_converter = EpubConverter('../epub/Cook.epub', + json_converter = EpubConverter('../epub/9781641053532.epub', logger=logger_object) tmp = json_converter.convert_to_dict() diff --git a/src/html_docx_preprocessor.py b/src/html_docx_preprocessor.py index c1acb5c..56d3a50 100644 --- a/src/html_docx_preprocessor.py +++ b/src/html_docx_preprocessor.py @@ -53,7 +53,7 @@ class HTMLDocxPreprocessor: def convert_pt_to_px(cls, value): value = float(value) if value == LiveCartaConfig.WORD_DEFAULT_FONT_SIZE: - return LiveCartaConfig.LAWCARTA_DEFAULT_FONT_SIZE + return LiveCartaConfig.LIVECARTA_DEFAULT_FONT_SIZE else: return value @@ -73,7 +73,7 @@ class HTMLDocxPreprocessor: size = size.group(1) new_size = cls.convert_pt_to_px(size) - if new_size == LiveCartaConfig.LAWCARTA_DEFAULT_FONT_SIZE: + if new_size == LiveCartaConfig.LIVECARTA_DEFAULT_FONT_SIZE: return "" return re.sub(size + "pt", str(new_size) + "px", style) @@ -635,7 +635,7 @@ class HTMLDocxPreprocessor: def process_html(self, access, html_path, book_id): """ - Process html code to satisfy LawCarta formatting. + Process html code to satisfy LiveCarta formatting. """ try: self.logger_object.log(f'Processing TOC and headers.') diff --git a/src/livecarta_config.py b/src/livecarta_config.py index 65a5426..694befd 100644 --- a/src/livecarta_config.py +++ b/src/livecarta_config.py @@ -9,8 +9,8 @@ class LiveCartaConfig: DEFAULT_ALIGN_STYLE = 'left' ALIGN_STYLES = ['justify', 'right', 'center', 'left'] WORD_DEFAULT_FONT_SIZE = 11 - LAWCARTA_DEFAULT_FONT_SIZE = 18 - FONT_CONVERT_RATIO = LAWCARTA_DEFAULT_FONT_SIZE / WORD_DEFAULT_FONT_SIZE + LIVECARTA_DEFAULT_FONT_SIZE = 18 + FONT_CONVERT_RATIO = LIVECARTA_DEFAULT_FONT_SIZE / WORD_DEFAULT_FONT_SIZE font_correspondence_table = { "Arial": "arial,helvetica,sans-serif", "Comic Sans MS": "comic sans ms,cursive",