update pptc as libreoffice impress

This commit is contained in:
tsuky_chen
2024-02-15 01:51:34 +08:00
15 changed files with 442 additions and 140 deletions

View File

@@ -139,6 +139,7 @@ def compare_pptx_files(file1_path, file2_path, **options):
examine_number_of_slides = options.get("examine_number_of_slides", True)
examine_shape = options.get("examine_shape", True)
examine_text = options.get("examine_text", True)
examine_indent = options.get("examine_indent", True)
examine_font_name = options.get("examine_font_name", True)
examine_font_size = options.get("examine_font_size", True)
examine_font_bold = options.get("examine_font_bold", True)
@@ -148,6 +149,7 @@ def compare_pptx_files(file1_path, file2_path, **options):
examine_strike_through = options.get("examine_strike_through", True)
examine_alignment = options.get("examine_alignment", True)
examine_bottom_position = options.get("examine_bottom_position", False)
examine_bullets = options.get("examine_bullets", True)
# compare the number of slides
if len(prs1.slides) != len(prs2.slides) and examine_number_of_slides:
@@ -174,6 +176,12 @@ def compare_pptx_files(file1_path, file2_path, **options):
if para1.alignment != para2.alignment and examine_alignment:
return 0
# check if the runs are the same
if para1.text != para2.text and examine_text:
return 0
if para1.level != para2.level and examine_indent:
return 0
for run1, run2 in zip(para1.runs, para2.runs):
# check if the font properties are the same
@@ -200,7 +208,40 @@ def compare_pptx_files(file1_path, file2_path, **options):
'strike', 'noStrike') and examine_strike_through:
return 0
# fixme: Actually there are more properties to be compared, but we cannot get them through pptx
def _extract_bullets(xml_data):
root = ET.fromstring(xml_data)
namespaces = {
'a': 'http://schemas.openxmlformats.org/drawingml/2006/main',
'p': 'http://schemas.openxmlformats.org/presentationml/2006/main',
}
bullets = []
for paragraph in root.findall('.//a:p', namespaces):
pPr = paragraph.find('a:pPr', namespaces)
if pPr is not None:
lvl = pPr.get('lvl')
buChar = pPr.find('a:buChar', namespaces)
char = buChar.get('char') if buChar is not None else "No Bullet"
buClr = pPr.find('a:buClr/a:srgbClr', namespaces)
color = buClr.get('val') if buClr is not None else "No Color"
else:
lvl = "No Level"
char = "No Bullet"
color = "No Color"
text = "".join(t.text for t in paragraph.findall('.//a:t', namespaces))
bullets.append((lvl, char, text, color))
return bullets
if _extract_bullets(run1.part.blob.decode('utf-8')) != _extract_bullets(
run2.part.blob.decode('utf-8')) and examine_bullets:
return 0
# fixme: Actually there are more properties to be compared, we can add them later via parsing the xml data
return 1
@@ -422,6 +463,7 @@ if __name__ == '__main__':
# r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\550ce7e7-747b-495f-b122-acdc4d0b8e54\New_Club_Spring_2018_Training_Gold.pptx"))
# print(evaluate_presentation_fill_to_rgb_distance(r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\3b27600c-3668-4abd-8f84-7bcdebbccbdb\lec17-gui-events.pptx", {"rgb": (0, 0, 255)}))
# print(check_auto_saving_time(r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\2cd43775-7085-45d8-89fa-9e35c0a915cf\registrymodifications.xcu", {"minutes": 3}))
print(compare_pptx_files(r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\a669ef01-ded5-4099-9ea9-25e99b569840\Writing-Outlines.pptx",
r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\a669ef01-ded5-4099-9ea9-25e99b569840\Writing-Outlines_Gold.pptx",
examine_shape=False))
print(compare_pptx_files(
r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\a669ef01-ded5-4099-9ea9-25e99b569840\Writing-Outlines.pptx",
r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\a669ef01-ded5-4099-9ea9-25e99b569840\Writing-Outlines_Gold.pptx",
examine_shape=False))