示例#1
0
def merge_styles(document, from_file, target=None, pretty=True):
    source = Document(from_file)
    document.delete_styles()
    document.merge_styles_from(source)
    doc_type = document.get_type()
    # Enhance Presentation merge
    if doc_type in {"presentation", "presentation-template"}:
        printinfo("merging presentation styles...")
        merge_presentation_styles(document, source)
    document.save(target=target, pretty=pretty)
    printinfo("Done (0 error, 0 warning).")
示例#2
0
def merge_presentation_styles(document, source):
    # Apply master page found
    source_body = source.body
    first_page = source_body.get_draw_page()
    print(first_page.serialize())
    master_page_name = first_page.master_page
    print(master_page_name)
    first_master_page = document.get_style("master-page", master_page_name)
    printinfo("master page used:", first_master_page.display_name)
    body = document.get_body
    for page in body.get_draw_pages():
        page.set_style_attribute(first_page.get_style())
        page.set_master_page(first_page.get_master_page())
        page.set_presentation_page_layout(
            first_page.get_presentation_page_layout())
    # Adjust layout -- will obviously work only if content is separated from
    # style: use of master pages, layout, etc.
    for presentation_class in ODF_CLASSES:
        first_frame = source_body.get_frame(
            presentation_class=presentation_class)
        if first_frame is None:
            continue
        # Mimic frame style
        position = first_frame.get_position()
        size = first_frame.size
        style = first_frame.style
        presentation_style = first_frame.get_presentation_style()
        for page in body.get_draw_pages():
            for frame in page.get_frames(
                    presentation_class=presentation_class):
                frame.position = position
                frame.size = size
                frame.set_style_attribute(style)
                frame.set_presentation_style(presentation_style)
        # Mimic list style (XXX only first level)
        if presentation_class == "outline":
            list_style = find_presentation_list_style(source_body)
            for page in body.get_draw_pages():
                for frame in page.get_frames(presentation_class="outline"):
                    for lst in frame.get_lists():
                        lst.set_style_attribute(list_style)
示例#3
0
def delete_styles(document, target, pretty=True):
    n = document.delete_styles()
    document.save(target=target, pretty=pretty)
    printinfo(n, "styles removed (0 error, 0 warning).")