<commit_before><commit_msg>Added a script to convert all texts to paths<commit_after>#!/usr/bin/python2

# Sozi - A presentation tool using the SVG standard
#
# Copyright (C) 2010-2013 <NAME>
#
# This program is dual licensed under the terms of the MIT license
# or the GNU General Public License (GPL) version 3.
# A copy of both licenses is provided in the doc/ folder of the
# official release of Sozi.
# 
# See http://sozi.baierouge.fr/wiki/en:license for details.

from optparse import OptionParser
from lxml import etree
import subprocess, shutil

if __name__ == '__main__':
    option_parser = OptionParser()

    option_parser.description = "Convert all texts to paths"
    option_parser.usage = "sozi2pdf.py [options] input_file.svg"
    
    option_parser.add_option("-o", "--output", type="string", dest="output",
        help="The target SVG file name")
        
    options, args = option_parser.parse_args()

    if len(args) == 0:
        option_parser.print_usage(sys.stderr)
        sys.exit()
    
    # Set input and output file name
    input_file_name = args[0]
    
    if options.output is not None:
        output_file_name = options.output
    else:
        output_file_name = os.path.basename(input_file_name)
        output_file_name = os.path.splitext(output_file_name)[0] + "-texts2paths.svg"        
    
    shutil.copy(input_file_name, output_file_name)
    
    # Get text elements from the original document
    input_file = open(input_file_name)
    tree = etree.parse(input_file)
    texts = tree.getroot().xpath("//*[local-name() = $name]", name="text")
    input_file.close()
    
    # Use Inkscape to convert each text element to a path
    command = ["inkscape"]
    for t in texts:
        command += ["--verb=EditDeselect", "--select=" + t.get("id"), "--verb=ObjectToPath"]
    command += ["--verb=FileSave", "--verb=FileClose", output_file_name]
    
    subprocess.call(command)
{'fraction_non_alphanumeric': 0.11388455538221529, 'fraction_numerical': 0.0078003120124804995, 'mean_word_length': 3.210065645514223, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3201344', 'n_tokens_mistral': 611, 'n_tokens_neox': 603, 'n_words': 171}