add eval libreoffice writer font & page break

This commit is contained in:
tsuky_chen
2023-12-30 16:32:15 +08:00
parent 86ce9e1497
commit 24f33dc9bf
5 changed files with 87 additions and 8 deletions

View File

@@ -1,2 +1,3 @@
from .table import compare_table, compare_with_sparklines, compare_with_charts
from .table import check_sheet_list, check_xlsx_freeze
from .docs import find_default_font, contains_page_break

View File

@@ -0,0 +1,44 @@
import xml.etree.ElementTree as ET
from docx import Document
from lxml import etree
def find_default_font(expected, config_file_path):
"""Find the default font in LibreOffice Writer."""
default_font = None
try:
tree = ET.parse(config_file_path)
root = tree.getroot()
# Define the XML namespace used in the file
namespace = {'oor': 'http://openoffice.org/2001/registry'}
# Search for the node containing the default font setting for LibreOffice Writer
for elem in root.findall('.//item[@oor:path="/org.openoffice.Office.Writer/DefaultFont"]', namespace):
for prop in elem.findall('.//prop[@oor:name="Standard"]', namespace):
for value in prop.findall('value', namespace):
default_font = value.text
except Exception as e:
print(f"Error: {e}")
return 1 if default_font == expected else 0
def contains_page_break(docx_file):
doc = Document(docx_file)
namespaces = {'w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'}
for paragraph in doc.paragraphs:
for run in paragraph.runs:
br_elems = run.element.findall('.//w:br', namespaces)
for br in br_elems:
if br is not None and '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}type' in br.attrib and br.attrib['{http://schemas.openxmlformats.org/wordprocessingml/2006/main}type'] == 'page':
return 1
return 0
# Replace 'your_document.docx' with the path to your document
# result = contains_page_break('your_document.docx')
# print(result)
#config_path = "/home/[username]/.config/libreoffice/4/user/registrymodifications.xcu"
#print(find_default_font("Ani", config_path))

View File

@@ -19,8 +19,9 @@
"type": "open",
"parameters": {
"path": "Desktop/OrderId_Month_Chart.xlsx"
]
},
}
}
],
"trajectory": "trajectories/2bd59342-0664-4ccb-ba87-79379096cc08",
"related_apps": [
"libreoffice calc"
@@ -38,4 +39,4 @@
"dest": "OrderId_Month_Chart.xlsx"
}
}
}
}

View File

@@ -8,5 +8,12 @@
"related_apps": [
"libreoffice_writer"
],
"evaluator": "evaluation_dir"
}
"evaluator": {
"func": "contains_page_break",
"result": {
"type": "vm_file",
"path": "Desktop/Insert_Blank_Page.docx",
"dest": "Insert_Blank_Page.docx"
}
}
}

View File

@@ -3,10 +3,36 @@
"snapshot": "libreoffice_writer",
"instruction": "Make Times New Roman the default Font",
"source": "https://ask.libreoffice.org/t/how-do-i-make-times-new-roman-the-default-font-in-lo/64604",
"config": [],
"config": [
{
"type": "download",
"parameters": {
"files": [
{
"url": "https://drive.usercontent.google.com/download?id=1rwhniaClEkF8XFzdfaNUA6GmAiy4syMZ&export=download&authuser=0&confirm=t&uuid=6fdd5b04-85f4-45e1-ad74-368f8f2a82ab&at=APZUnTUP-JxPxLfNls6jXWghblQ5:1701766091851",
"path": "Desktop/Set_Default_Font.docx"
}
]
}
},
{
"type": "open",
"parameters": {
"path": "Desktop/Set_Default_Font.docx"
}
}
],
"trajectory": "trajectories/",
"related_apps": [
"libreoffice_writer"
],
"evaluator": "evaluation_dir"
}
"evaluator": {
"func": "find_default_font",
"expected": "Times New Roman",
"result": {
"type": "vm_file",
"path": "/home/[your-username]/.config/libreoffice/4/user/registrymodifications.xcu",
"dest": "registrymodifications.xcu"
}
}
}