Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61754911
transformSVG2TranskriptionField.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, May 8, 18:43
Size
2 KB
Mime Type
text/x-python
Expires
Fri, May 10, 18:43 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17502835
Attached To
rNIETZSCHEPYTHON nietzsche-python
transformSVG2TranskriptionField.py
View Options
#!/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
Log In to Comment