Page MenuHomec4science

transformSVG2TranskriptionField.py
No OneTemporary

File Metadata

Created
Wed, May 8, 18:43

transformSVG2TranskriptionField.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" This program can be used to transform a svg file according to the dimension of its transkription field.
"""
# Copyright (C) University of Basel 2019 {{{1
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/> 1}}}
import sys
import getopt
from os.path import exists
from svgpathtools import svg_to_paths
import xml.etree.ElementTree as ET
from datatypes.transkriptionField import TranskriptionField
__author__ = "Christian Steiner"
__maintainer__ = __author__
__copyright__ = 'University of Basel'
__email__ = "christian.steiner@unibas.ch"
__status__ = "Development"
__version__ = "0.0.1"
def usage():
"""Prints information on how to use this script
"""
print('transformSVG2TranskriptionField.py [-m|--multipage={0|1}] svg-input-file [svg-output-file]')
def main(argv):
try:
opts, args = getopt.getopt(argv, "hm:", ["help", "multipage="])
except getopt.GetoptError:
usage()
return 2
multipage = -1
for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
return 0
elif opt in ('-m', '--multipage'):
multipage = int(arg)
if len(args) == 0:
usage()
return 2
file_name = args[0]
target_file_name = None
if not exists(file_name):
print('File \"{}\" does not exist!'.format(file_name))
return 2
if(len(args) > 1):
target_file_name = args[1]
transkriptionField = TranskriptionField(file_name, multipage_index=multipage)
print('Document\'s width: {}, height: {}'.format(transkriptionField.documentWidth, transkriptionField.documentHeight))
print('Transkription field: width = {}, height = {}'.format(transkriptionField.width, transkriptionField.height))
transkriptionField.shrink_svg_to_transkription_field(target_file_name)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))

Event Timeline