update PPTC examples into impress

This commit is contained in:
tsuky_chen
2024-02-17 01:01:29 +08:00
parent dd1644b3f4
commit 396cfcf8fa
14 changed files with 621 additions and 61 deletions

View File

@@ -149,63 +149,120 @@ 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_right_position = options.get("examine_right_position", False)
examine_image_size = options.get("examine_image_size", True)
examine_bullets = options.get("examine_bullets", True)
examine_background_color = options.get("examine_background_color", True)
examine_note = options.get("examine_note", True)
# compare the number of slides
if len(prs1.slides) != len(prs2.slides) and examine_number_of_slides:
print("0")
return 0
# compare the content of each slide
for slide1, slide2 in zip(prs1.slides, prs2.slides):
def get_slide_background_color(slide):
background = slide.background
if background.fill.background():
return background.fill.fore_color.rgb
else:
return None
if get_slide_background_color(slide1) != get_slide_background_color(slide2) and examine_background_color:
print("background color not the same")
return 0
def get_slide_notes(slide):
notes_slide = slide.notes_slide
if notes_slide:
return notes_slide.notes_text_frame.text
else:
return None
if get_slide_notes(slide1) != get_slide_notes(slide2) and examine_note:
print("notes not the same")
return 0
# check if the shapes are the same
for shape1, shape2 in zip(slide1.shapes, slide2.shapes):
if examine_bottom_position and shape1.top != shape2.top:
if hasattr(shape1, "text") and hasattr(shape2, "text") and shape1.text == shape2.text and shape1.text == "Product Comparison":
if shape1.top >= shape2.top:
return 0
if examine_right_position and shape1.left != shape2.left:
if not hasattr(shape1, "text") and not hasattr(shape2, "text"):
if shape1.left >= shape2.left:
return 0
if (shape1.left != shape2.left or shape1.top != shape2.top or shape1.width != shape2.width or shape1.height != shape2.height) and examine_shape:
print("1")
return 0
if examine_image_size:
if shape1.shape_type == 13 and shape2.shape_type == 13:
if shape1.width != shape2.width or shape1.height != shape2.height:
return 0
elif shape1.left != shape2.left or shape1.top != shape2.top or shape1.width != shape2.width or shape1.height != shape2.height:
return 0
if hasattr(shape1, "text") and hasattr(shape2, "text"):
if shape1.text != shape2.text and examine_text:
print("2")
return 0
# check if the paragraphs are the same
for para1, para2 in zip(shape1.text_frame.paragraphs, shape2.text_frame.paragraphs):
if para1.alignment != para2.alignment and examine_alignment:
print(para1.alignment)
print(para2.alignment)
print("3")
return 0
# check if the runs are the same
if para1.text != para2.text and examine_text:
print("4")
return 0
if para1.level != para2.level and examine_indent:
print("5")
return 0
for run1, run2 in zip(para1.runs, para2.runs):
# check if the font properties are the same
print(run1.font.name)
print(run2.font.name)
if run1.font.name != run2.font.name and examine_font_name:
print("6")
return 0
if run1.font.size != run2.font.size and examine_font_size:
print("7")
print(run1.font.size)
print(run2.font.size)
return 0
if run1.font.bold != run2.font.bold and examine_font_bold:
print("8")
return 0
if run1.font.italic != run2.font.italic and examine_font_italic:
print("9")
return 0
if hasattr(run1.font.color, "rgb") and hasattr(run2.font.color, "rgb"):
if run1.font.color.rgb != run2.font.color.rgb and examine_color_rgb:
print("10")
return 0
if run1.font.underline != run2.font.underline and examine_font_underline:
print("11")
return 0
if run1.font._element.attrib.get('strike', 'noStrike') != run2.font._element.attrib.get(
'strike', 'noStrike') and examine_strike_through:
print("12")
return 0
def _extract_bullets(xml_data):
@@ -237,9 +294,10 @@ def compare_pptx_files(file1_path, file2_path, **options):
return bullets
if _extract_bullets(run1.part.blob.decode('utf-8')) != _extract_bullets(
run2.part.blob.decode('utf-8')) and examine_bullets:
return 0
if examine_bullets and _extract_bullets(run1.part.blob.decode('utf-8')) != _extract_bullets(run2.part.blob.decode('utf-8')):
return 0
# fixme: Actually there are more properties to be compared, we can add them later via parsing the xml data
@@ -464,6 +522,6 @@ if __name__ == '__main__':
# 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",
r"D:\NJU\HKUNLP\Desktop-Env\DesktopEnv\cache\08aced46-45a2-48d7-993b-ed3fb5b32302\22_6_Gold.pptx",
r"D:\NJU\HKUNLP\Desktop-Env\DesktopEnv\cache\08aced46-45a2-48d7-993b-ed3fb5b32302\22_6.pptx",
examine_shape=False))