make the separating x optional when specifying the width without the height

This commit is contained in:
Johannes 'josch' Schauer 2016-02-17 18:16:17 +01:00
parent 86552a78dc
commit 00c73a6691

View file

@ -1058,11 +1058,16 @@ def parse_pagesize_rectarg(string):
if papersizes.get(string.lower()): if papersizes.get(string.lower()):
string = papersizes[string.lower()] string = papersizes[string.lower()]
if 'x' not in string: if 'x' not in string:
raise argparse.ArgumentTypeError("size must contain 'x' character") # if there is no separating "x" in the string, then the string is
# interpreted as the width
w = parse_num(string, "width")
h = None
else:
w, h = string.split('x', 1) w, h = string.split('x', 1)
w = parse_num(w, "width")
h = parse_num(h, "height")
if transposed: if transposed:
w, h = h, w w, h = h, w
w, h = parse_num(w, "width"), parse_num(h, "height")
if w is None and h is None: if w is None and h is None:
raise argparse.ArgumentTypeError("at least one dimension must be " raise argparse.ArgumentTypeError("at least one dimension must be "
"specified") "specified")
@ -1076,11 +1081,16 @@ def parse_imgsize_rectarg(string):
if papersizes.get(string.lower()): if papersizes.get(string.lower()):
string = papersizes[string.lower()] string = papersizes[string.lower()]
if 'x' not in string: if 'x' not in string:
raise argparse.ArgumentTypeError("size must contain 'x' character") # if there is no separating "x" in the string, then the string is
# interpreted as the width
w = parse_imgsize_num(string, "width")
h = None
else:
w, h = string.split('x', 1) w, h = string.split('x', 1)
w = parse_imgsize_num(w, "width")
h = parse_imgsize_num(h, "height")
if transposed: if transposed:
w, h = h, w w, h = h, w
w, h = parse_imgsize_num(w, "width"), parse_imgsize_num(h, "height")
if w is None and h is None: if w is None and h is None:
raise argparse.ArgumentTypeError("at least one dimension must be " raise argparse.ArgumentTypeError("at least one dimension must be "
"specified") "specified")
@ -1435,10 +1445,13 @@ allowed units are cm (centimeter), mm (millimeter), and in (inch).
Any size argument of the format LxL in the options below specifies the width Any size argument of the format LxL in the options below specifies the width
and height of a rectangle where the first L represents the width and the second and height of a rectangle where the first L represents the width and the second
L represents the height with an optional unit following each value as described L represents the height with an optional unit following each value as described
above. Either width or height may be omitted but in that case the separating x above. Either width or height may be omitted. If the height is omitted, the
must still be present. Instead of giving the width and height explicitly, you separating x can be omitted as well. Omitting the width requires to prefix the
may also specify some (case-insensitive) common page sizes such as letter and height with the separating x. The missing dimension will be chosen so to not
A4. See the epilogue at the bottom for a complete list of the valid sizes. change the image aspect ratio. Instead of giving the width and height
explicitly, you may also specify some (case-insensitive) common page sizes such
as letter and A4. See the epilogue at the bottom for a complete list of the
valid sizes.
The --fit option scales to fit the image into a rectangle that is either The --fit option scales to fit the image into a rectangle that is either
derived from the the --imgsize option or otherwise from the --pagesize option. derived from the the --imgsize option or otherwise from the --pagesize option.