add eval libreoffice writer compare image & centering & check file existence

This commit is contained in:
tsuky_chen
2023-12-31 03:17:53 +08:00
parent 52af1b6dd4
commit f04e625ad9
5 changed files with 112 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
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
from .docs import compare_font_names, compare_subscript_contains, has_page_numbers_in_footers
from .docs import is_first_line_centered, check_file_exists, compare_contains_image

View File

@@ -146,6 +146,30 @@ def has_page_numbers_in_footers(docx_file):
return 0
return 1
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
def is_first_line_centered(docx_file):
doc = Document(docx_file)
first_paragraph = doc.paragraphs[0]
# check if the first line is center justified
return 1 if first_paragraph.paragraph_format.alignment == WD_PARAGRAPH_ALIGNMENT.CENTER else 0
import os
def check_file_exists(directory, filename):
file_path = os.path.join(directory, filename)
return 1 if os.path.isfile(file_path) else 0
def compare_contains_image(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):
if ('graphicData' in run1._element.xml and 'graphicData' not in run2._element.xml) or ('graphicData' not in run1._element.xml and 'graphicData' in run2._element.xml):
return 0
return 1
# file1 = 'path/to/file1.docx'
# file2 = 'path/to/file2.docx'