more refactoring, renaming, unifying
This commit is contained in:
parent
1426214175
commit
489f467bce
@ -1,3 +1,3 @@
|
|||||||
# main package
|
# main package
|
||||||
|
|
||||||
__version__ = '1.9.1'
|
__version__ = '2.0'
|
||||||
|
|||||||
@ -2,6 +2,7 @@ from optparse import OptionParser
|
|||||||
import os
|
import os
|
||||||
import codecs
|
import codecs
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
from reportlab.lib.pagesizes import LETTER, A4
|
from reportlab.lib.pagesizes import LETTER, A4
|
||||||
from reportlab.lib.units import cm
|
from reportlab.lib.units import cm
|
||||||
@ -138,26 +139,15 @@ def generate_sample(options):
|
|||||||
sample.save(filename='sample.png')
|
sample.save(filename='sample.png')
|
||||||
|
|
||||||
|
|
||||||
def generate(options, data_path, f):
|
def parse_papersize(spec):
|
||||||
size = options.size.upper()
|
|
||||||
if size == 'SLEEVED' or options.sleeved:
|
|
||||||
dominionCardWidth, dominionCardHeight = (9.4 * cm, 6.15 * cm)
|
|
||||||
print 'Using sleeved card size, %.2fcm x %.2fcm' % (dominionCardWidth / cm, dominionCardHeight / cm)
|
|
||||||
elif size in ['NORMAL', 'UNSLEEVED']:
|
|
||||||
dominionCardWidth, dominionCardHeight = (9.1 * cm, 5.9 * cm)
|
|
||||||
print 'Using normal card size, %.2fcm x%.2fcm' % (dominionCardWidth / cm, dominionCardHeight / cm)
|
|
||||||
else:
|
|
||||||
dominionCardWidth, dominionCardHeight = parseDimensions(size)
|
|
||||||
print 'Using custom card size, %.2fcm x %.2fcm' % (dominionCardWidth / cm, dominionCardHeight / cm)
|
|
||||||
|
|
||||||
papersize = None
|
papersize = None
|
||||||
if not options.papersize:
|
if not spec:
|
||||||
if os.path.exists("/etc/papersize"):
|
if os.path.exists("/etc/papersize"):
|
||||||
papersize = open("/etc/papersize").readline().upper()
|
papersize = open("/etc/papersize").readline().upper()
|
||||||
else:
|
else:
|
||||||
papersize = 'LETTER'
|
papersize = 'LETTER'
|
||||||
else:
|
else:
|
||||||
papersize = options.papersize.upper()
|
papersize = spec.upper()
|
||||||
|
|
||||||
if papersize == 'A4':
|
if papersize == 'A4':
|
||||||
print "Using A4 sized paper."
|
print "Using A4 sized paper."
|
||||||
@ -169,6 +159,33 @@ def generate(options, data_path, f):
|
|||||||
paperwidth, paperheight = parseDimensions(papersize)
|
paperwidth, paperheight = parseDimensions(papersize)
|
||||||
print 'Using custom paper size, %.2fcm x %.2fcm' % (paperwidth / cm, paperheight / cm)
|
print 'Using custom paper size, %.2fcm x %.2fcm' % (paperwidth / cm, paperheight / cm)
|
||||||
|
|
||||||
|
return paperwidth, paperheight
|
||||||
|
|
||||||
|
|
||||||
|
def parse_cardsize(spec, sleeved):
|
||||||
|
spec = spec.upper()
|
||||||
|
if spec == 'SLEEVED' or sleeved:
|
||||||
|
dominionCardWidth, dominionCardHeight = (9.4 * cm, 6.15 * cm)
|
||||||
|
print 'Using sleeved card size, %.2fcm x %.2fcm' % (dominionCardWidth / cm,
|
||||||
|
dominionCardHeight / cm)
|
||||||
|
elif spec in ['NORMAL', 'UNSLEEVED']:
|
||||||
|
dominionCardWidth, dominionCardHeight = (9.1 * cm, 5.9 * cm)
|
||||||
|
print 'Using normal card size, %.2fcm x%.2fcm' % (dominionCardWidth / cm,
|
||||||
|
dominionCardHeight / cm)
|
||||||
|
else:
|
||||||
|
dominionCardWidth, dominionCardHeight = parseDimensions(spec)
|
||||||
|
print 'Using custom card size, %.2fcm x %.2fcm' % (dominionCardWidth / cm,
|
||||||
|
dominionCardHeight / cm)
|
||||||
|
return dominionCardWidth, dominionCardHeight
|
||||||
|
|
||||||
|
|
||||||
|
def generate(options, data_path, f):
|
||||||
|
|
||||||
|
add_opt(options, 'data_path', data_path)
|
||||||
|
|
||||||
|
dominionCardWidth, dominionCardHeight = parse_cardsize(options.size, options.sleeved)
|
||||||
|
paperwidth, paperheight = parse_papersize(options.papersize)
|
||||||
|
|
||||||
cardlist = None
|
cardlist = None
|
||||||
if options.cardlist:
|
if options.cardlist:
|
||||||
print options.cardlist
|
print options.cardlist
|
||||||
@ -178,9 +195,9 @@ def generate(options, data_path, f):
|
|||||||
cardlist.add(line.strip())
|
cardlist.add(line.strip())
|
||||||
|
|
||||||
if options.orientation == "vertical":
|
if options.orientation == "vertical":
|
||||||
tabWidth, tabBaseHeight = dominionCardHeight, dominionCardWidth
|
dividerWidth, dividerBaseHeight = dominionCardHeight, dominionCardWidth
|
||||||
else:
|
else:
|
||||||
tabWidth, tabBaseHeight = dominionCardWidth, dominionCardHeight
|
dividerWidth, dividerBaseHeight = dominionCardWidth, dominionCardHeight
|
||||||
|
|
||||||
if options.tab_name_align == "center":
|
if options.tab_name_align == "center":
|
||||||
options.tab_name_align = "centre"
|
options.tab_name_align = "centre"
|
||||||
@ -195,47 +212,46 @@ def generate(options, data_path, f):
|
|||||||
# fixed for Avery 8867 for now
|
# fixed for Avery 8867 for now
|
||||||
minmarginwidth = 0.86 * cm # was 0.76
|
minmarginwidth = 0.86 * cm # was 0.76
|
||||||
minmarginheight = 1.37 * cm # was 1.27
|
minmarginheight = 1.37 * cm # was 1.27
|
||||||
tabLabelHeight = 1.07 * cm # was 1.27
|
labelHeight = 1.07 * cm # was 1.27
|
||||||
tabLabelWidth = 4.24 * cm # was 4.44
|
labelWidth = 4.24 * cm # was 4.44
|
||||||
horizontalBorderSpace = 0.96 * cm # was 0.76
|
horizontalBorderSpace = 0.96 * cm # was 0.76
|
||||||
verticalBorderSpace = 0.20 * cm # was 0.01
|
verticalBorderSpace = 0.20 * cm # was 0.01
|
||||||
tabBaseHeight = 0
|
dividerBaseHeight = 0
|
||||||
tabWidth = tabLabelWidth
|
dividerWidth = labelWidth
|
||||||
fixedMargins = True
|
fixedMargins = True
|
||||||
else:
|
else:
|
||||||
minmarginwidth, minmarginheight = parseDimensions(
|
minmarginwidth, minmarginheight = parseDimensions(
|
||||||
options.minmargin)
|
options.minmargin)
|
||||||
if options.tab_side == "full":
|
if options.tab_side == "full":
|
||||||
tabLabelWidth = tabWidth
|
labelWidth = dividerWidth
|
||||||
else:
|
else:
|
||||||
tabLabelWidth = options.tabwidth * cm
|
labelWidth = options.tabwidth * cm
|
||||||
tabLabelHeight = .9 * cm
|
labelHeight = .9 * cm
|
||||||
horizontalBorderSpace = 0 * cm
|
horizontalBorderSpace = 0 * cm
|
||||||
verticalBorderSpace = 0 * cm
|
verticalBorderSpace = 0 * cm
|
||||||
|
|
||||||
tabHeight = tabBaseHeight + tabLabelHeight
|
dividerHeight = dividerBaseHeight + labelHeight
|
||||||
|
|
||||||
# note: this is convenient, but somewhat inaccurate as the border space
|
add_opt(options, 'dividerWidth', dividerWidth)
|
||||||
# isn't actually part of the tab width
|
add_opt(options, 'dividerHeight', dividerHeight)
|
||||||
add_opt(options, 'dividerWidth', tabWidth)
|
add_opt(options, 'dividerWidthReserved', dividerWidth + horizontalBorderSpace)
|
||||||
add_opt(options, 'dividerHeight', tabHeight)
|
add_opt(options, 'dividerHeightReserved', dividerHeight + verticalBorderSpace)
|
||||||
add_opt(options, 'totalTabWidth', tabWidth + horizontalBorderSpace)
|
add_opt(options, 'labelWidth', labelWidth)
|
||||||
add_opt(options, 'totalTabHeight', tabHeight + verticalBorderSpace)
|
add_opt(options, 'labelHeight', labelHeight)
|
||||||
add_opt(options, 'labelWidth', tabLabelWidth)
|
|
||||||
add_opt(options, 'labelHeight', tabLabelHeight)
|
|
||||||
|
|
||||||
# as we don't draw anything in the final border, it shouldn't count towards how many tabs we can fit
|
# as we don't draw anything in the final border, it shouldn't count towards how many tabs we can fit
|
||||||
# so it gets added back in to the page size here
|
# so it gets added back in to the page size here
|
||||||
numTabsVerticalP = int(
|
numTabsVerticalP = int(
|
||||||
(paperheight - 2 * minmarginheight + verticalBorderSpace) / options.totalTabHeight)
|
(paperheight - 2 * minmarginheight + verticalBorderSpace) / options.dividerHeightReserved)
|
||||||
numTabsHorizontalP = int(
|
numTabsHorizontalP = int(
|
||||||
(paperwidth - 2 * minmarginwidth + horizontalBorderSpace) / options.totalTabWidth)
|
(paperwidth - 2 * minmarginwidth + horizontalBorderSpace) / options.dividerWidthReserved)
|
||||||
numTabsVerticalL = int(
|
numTabsVerticalL = int(
|
||||||
(paperwidth - 2 * minmarginwidth + verticalBorderSpace) / options.totalTabHeight)
|
(paperwidth - 2 * minmarginwidth + verticalBorderSpace) / options.dividerHeightReserved)
|
||||||
numTabsHorizontalL = int(
|
numTabsHorizontalL = int(
|
||||||
(paperheight - 2 * minmarginheight + horizontalBorderSpace) / options.totalTabWidth)
|
(paperheight - 2 * minmarginheight + horizontalBorderSpace) / options.dividerWidthReserved)
|
||||||
|
|
||||||
if numTabsVerticalL * numTabsHorizontalL > numTabsVerticalP * numTabsHorizontalP and not fixedMargins:
|
if ((numTabsVerticalL * numTabsHorizontalL >
|
||||||
|
numTabsVerticalP * numTabsHorizontalP) and not fixedMargins):
|
||||||
add_opt(options, 'numTabsVertical', numTabsVerticalL)
|
add_opt(options, 'numTabsVertical', numTabsVerticalL)
|
||||||
add_opt(options, 'numTabsHorizontal', numTabsHorizontalL)
|
add_opt(options, 'numTabsHorizontal', numTabsHorizontalL)
|
||||||
add_opt(options, 'paperheight', paperwidth)
|
add_opt(options, 'paperheight', paperwidth)
|
||||||
@ -252,8 +268,8 @@ def generate(options, data_path, f):
|
|||||||
|
|
||||||
print "Paper dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(options.paperwidth / cm,
|
print "Paper dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(options.paperwidth / cm,
|
||||||
options.paperheight / cm)
|
options.paperheight / cm)
|
||||||
print "Tab dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(options.totalTabWidth / cm,
|
print "Tab dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(options.dividerWidthReserved / cm,
|
||||||
options.totalTabHeight / cm)
|
options.dividerHeightReserved / cm)
|
||||||
print '{} dividers horizontally, {} vertically'.format(options.numTabsHorizontal,
|
print '{} dividers horizontally, {} vertically'.format(options.numTabsHorizontal,
|
||||||
options.numTabsVertical)
|
options.numTabsVertical)
|
||||||
|
|
||||||
@ -261,10 +277,10 @@ def generate(options, data_path, f):
|
|||||||
# dynamically max margins
|
# dynamically max margins
|
||||||
add_opt(options, 'horizontalMargin',
|
add_opt(options, 'horizontalMargin',
|
||||||
(options.paperwidth -
|
(options.paperwidth -
|
||||||
options.numTabsHorizontal * options.totalTabWidth) / 2)
|
options.numTabsHorizontal * options.dividerWidthReserved) / 2)
|
||||||
add_opt(options, 'verticalMargin',
|
add_opt(options, 'verticalMargin',
|
||||||
(options.paperheight -
|
(options.paperheight -
|
||||||
options.numTabsVertical * options.totalTabHeight) / 2)
|
options.numTabsVertical * options.dividerHeightReserved) / 2)
|
||||||
else:
|
else:
|
||||||
add_opt(options, 'horizontalMargin', minmarginwidth)
|
add_opt(options, 'horizontalMargin', minmarginwidth)
|
||||||
add_opt(options, 'verticalMargin', minmarginheight)
|
add_opt(options, 'verticalMargin', minmarginheight)
|
||||||
|
|||||||
@ -62,7 +62,7 @@ class DividerDrawer(object):
|
|||||||
self.canvas.save()
|
self.canvas.save()
|
||||||
|
|
||||||
def add_inline_images(self, text, fontsize):
|
def add_inline_images(self, text, fontsize):
|
||||||
path = 'images'
|
path = os.path.join(self.options.data_path, 'images')
|
||||||
replace = '<img src='"'%s/coin_small_\\1.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
replace = '<img src='"'%s/coin_small_\\1.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||||
path, fontsize * 1.2)
|
path, fontsize * 1.2)
|
||||||
text = re.sub('(\d)\s(c|C)oin(s)?', replace, text)
|
text = re.sub('(\d)\s(c|C)oin(s)?', replace, text)
|
||||||
@ -103,7 +103,7 @@ class DividerDrawer(object):
|
|||||||
if cropmarksleft or cropmarksright:
|
if cropmarksleft or cropmarksright:
|
||||||
self.canvas.line(-2 * cmw, 0, -cmw, 0)
|
self.canvas.line(-2 * cmw, 0, -cmw, 0)
|
||||||
self.canvas.line(-2 * cmw,
|
self.canvas.line(-2 * cmw,
|
||||||
self.tabBaseHeight, -cmw, self.tabBaseHeight)
|
self.dividerHeight, -cmw, self.dividerHeight)
|
||||||
if y > 0:
|
if y > 0:
|
||||||
self.canvas.line(-2 * cmw,
|
self.canvas.line(-2 * cmw,
|
||||||
self.options.dividerHeight, -cmw, self.options.dividerHeight)
|
self.options.dividerHeight, -cmw, self.options.dividerHeight)
|
||||||
@ -150,10 +150,10 @@ class DividerDrawer(object):
|
|||||||
potHeight = y - 3
|
potHeight = y - 3
|
||||||
potSize = 11
|
potSize = 11
|
||||||
|
|
||||||
self.canvas.drawImage(os.path.join('images', 'coin_small.png'),
|
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'coin_small.png'),
|
||||||
x, coinHeight, 16, 16, preserveAspectRatio=True, mask='auto')
|
x, coinHeight, 16, 16, preserveAspectRatio=True, mask='auto')
|
||||||
if card.potcost:
|
if card.potcost:
|
||||||
self.canvas.drawImage(os.path.join('images', 'potion.png'), x + 17,
|
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'potion.png'), x + 17,
|
||||||
potHeight, potSize, potSize, preserveAspectRatio=True,
|
potHeight, potSize, potSize, preserveAspectRatio=True,
|
||||||
mask=[255, 255, 255, 255, 255, 255])
|
mask=[255, 255, 255, 255, 255, 255])
|
||||||
width += potSize
|
width += potSize
|
||||||
@ -166,7 +166,7 @@ class DividerDrawer(object):
|
|||||||
def drawSetIcon(self, setImage, x, y):
|
def drawSetIcon(self, setImage, x, y):
|
||||||
# set image
|
# set image
|
||||||
self.canvas.drawImage(
|
self.canvas.drawImage(
|
||||||
os.path.join('images', setImage), x, y, 14, 12, mask='auto')
|
os.path.join(self.options.data_path, 'images', setImage), x, y, 14, 12, mask='auto')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def nameWidth(self, name, fontSize):
|
def nameWidth(self, name, fontSize):
|
||||||
@ -203,7 +203,7 @@ class DividerDrawer(object):
|
|||||||
# draw banner
|
# draw banner
|
||||||
img = card.getType().getNoCoinTabImageFile()
|
img = card.getType().getNoCoinTabImageFile()
|
||||||
if not self.options.no_tab_artwork and img:
|
if not self.options.no_tab_artwork and img:
|
||||||
self.canvas.drawImage(os.path.join('images', img), 1, 0,
|
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', img), 1, 0,
|
||||||
self.options.labelWidth -
|
self.options.labelWidth -
|
||||||
2, self.options.labelHeight - 1,
|
2, self.options.labelHeight - 1,
|
||||||
preserveAspectRatio=False, anchor='n', mask='auto')
|
preserveAspectRatio=False, anchor='n', mask='auto')
|
||||||
@ -392,7 +392,8 @@ class DividerDrawer(object):
|
|||||||
self.canvas.translate(self.options.horizontalMargin, self.options.verticalMargin)
|
self.canvas.translate(self.options.horizontalMargin, self.options.verticalMargin)
|
||||||
if useExtra:
|
if useExtra:
|
||||||
self.canvas.translate(self.options.back_offset, self.options.back_offset_height)
|
self.canvas.translate(self.options.back_offset, self.options.back_offset_height)
|
||||||
self.canvas.translate(x * self.options.totalTabWidth, y * self.options.totalTabHeight)
|
self.canvas.translate(x * self.options.dividerWidthReserved,
|
||||||
|
y * self.options.dividerHeightReserved)
|
||||||
|
|
||||||
# actual drawing
|
# actual drawing
|
||||||
if not self.options.tabs_only:
|
if not self.options.tabs_only:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user