add eval libreoffice writer compare font & subscript & page number

This commit is contained in:
tsuky_chen
2023-12-31 02:33:39 +08:00
parent c937e31b18
commit 52af1b6dd4
5 changed files with 127 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
from .table import compare_table
from .table import check_sheet_list, check_xlsx_freeze, check_zoom
from .docs import find_default_font, contains_page_break, compare_docx_files, compare_docx_tables, compare_line_spacing, compare_insert_equation
from .docs import compare_font_names, compare_subscript_contains, has_page_numbers_in_footers

View File

@@ -100,7 +100,7 @@ def compare_line_spacing(docx_file1, docx_file2):
def compare_insert_equation(docx_file1, docx_file2):
if not compare_docx_files(docx_file1, docx_file2):
return False
return 0
doc1 = Document(docx_file1)
doc2 = Document(docx_file2)
@@ -109,9 +109,42 @@ def compare_insert_equation(docx_file1, docx_file2):
for para1, para2 in zip(doc1.paragraphs, doc2.paragraphs):
for run1, run2 in zip(para1.runs, para2.runs):
if run1.element.xpath('.//w:object') and run2.element.xpath('.//w:object'):
return True
return False
return 1
return 0
def compare_font_names(expected_font, docx_file):
doc = Document(docx_file)
for paragraph in doc.paragraphs:
for run in paragraph.runs:
font_name = run.font.name
if font_name != expected_font:
return 0
return 1
def compare_subscript_contains(docx_file1, docx_file2):
doc1 = Document(docx_file1)
doc2 = Document(docx_file2)
for para1, para2 in zip(doc1.paragraphs, doc2.paragraphs):
for run1, run2 in zip(para1.runs, para2.runs):
# check if two paras both contain subscript
if run1.font.subscript and run2.font.subscript:
return 1
return 0
def has_page_numbers_in_footers(docx_file):
doc = Document(docx_file)
for section in doc.sections:
footer = section.footer
if footer is None:
return 0
footer_text = footer.paragraphs[0].text if footer.paragraphs else ''
if not any(char.isdigit() for char in footer_text):
# if no digit in footer, then no page number
return 0
return 1
# file1 = 'path/to/file1.docx'