Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added command-line parameters to override the default x-width and y-width settings #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions tools/rM2svg
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import argparse


__prog_name__ = "rM2svg"
__version__ = "0.0.1beta"
__version__ = "0.0.2beta"


# Size
x_width = 1404
y_width = 1872

# Mappings
stroke_colour = {
0: "black",
Expand Down Expand Up @@ -56,8 +52,26 @@ def main():
parser.add_argument('--version',
action='version',
version='%(prog)s {version}'.format(version=__version__))
parser.add_argument("-x",
"--x_width",
help="Set width of document in pixels.",
metavar="N",
)
parser.add_argument("-y",
"--y_width",
help="Set height of document in pixels.",
metavar="N",
)
args = parser.parse_args()

if (args.x_width):
x_width = args.x_width
print(x_width)

if (args.y_width):
y_width = args.y_width
print(y_width)

if not os.path.exists(args.input):
parser.error('The file "{}" does not exist!'.format(args.input))

Expand All @@ -70,15 +84,15 @@ def main():
3: "yellow"
}

lines2svg(args.input, args.output, args.singlefile, args.coloured_annotations)
lines2svg(args.input, args.output, args.singlefile, args.coloured_annotations, args.x_width, args.y_width)


def abort(msg):
print(msg, file=sys.stderr)
sys.exit(1)


def lines2svg(input_file, output_name, singlefile, coloured_annotations=False):
def lines2svg(input_file, output_name, singlefile, coloured_annotations=False, x_width=1404, y_width=1872):
# Read the file in memory. Consider optimising by reading chunks.
with open(input_file, 'rb') as f:
data = f.read()
Expand Down Expand Up @@ -116,7 +130,7 @@ def lines2svg(input_file, output_name, singlefile, coloured_annotations=False):
if singlefile:
output.write('<g id="p{}" style="display:{}">'.format(page, 'none' if page != 0 else 'inline')) # Opening page group, visible only for the first page.
else:
output = open("{}_{:02}.svg".format(output_name, page+1), 'w')
output = open("{}_{:03}.svg".format(output_name, page+1), 'w')
output.write('<svg xmlns="http://www.w3.org/2000/svg" height="{}" width="{}">\n'.format(y_width, x_width)) # BEGIN page

fmt = '<BBH' # TODO might be 'I'
Expand Down