Add card counts and wrapper/slipcase features (#65)

This adds card counts and the option to print wrappers (aka slipcases).
It fixes issues #45, #47, and #48.
This commit is contained in:
Wendel Voigt authored and Peter committed 2016-07-06 14:16:06 -07:00
1 parent 7b9e2361ae
commit 669fa4c7e6
9 files changed
+574 -134

No files matched your search

+120 -16
View File
@@ -130,12 +130,44 @@ def parse_opts(argstring):
help="horizontal gap between dividers in centimeters")
parser.add_option("--vertical_gap", type=float, default=0.,
help="vertical gap between dividers in centimeters")
parser.add_option("--count", action="store_true", dest="count",
default=False, help="Display card count on body of the divider.")
parser.add_option("--wrapper", action="store_true", dest="wrapper",
help="Draw wrapper for cards instead of a divider for the cards")
parser.add_option("--thickness", type=float, default=2.0,
help="Thickness of a stack of 60 cards (Copper) in centimeters."
" Typically unsleeved cards are 2.0, thin sleeved cards are 2.4, and thick sleeved cards are 3.2."
" This is only valid with the --wrapper option."
" default:2.0")
parser.add_option("--sleeved_thick", action="store_true",
dest="sleeved_thick", help="same as --size=sleeved --thickness 3.2")
parser.add_option("--sleeved_thin", action="store_true",
dest="sleeved_thin", help="same as --size=sleeved --thickness 2.4")
parser.add_option("--notch_length", type=float, default=0.0,
help="Length of thumb notch on wrapper in centimeters."
" This can make it easier to remove the cards from the wrapper."
" This is only valid with the --wrapper option."
" default:0.0 (i.e., no notch on wrapper)")
parser.add_option("--notch", action="store_true",
dest="notch", help="same as --notch_length thickness 1.5")
options, args = parser.parse_args(argstring)
if not options.cost:
options.cost = ['tab']
if not options.set_icon:
options.set_icon = ['tab']
if options.sleeved_thick:
options.thickness = 3.2
options.sleeved = True
if options.sleeved_thin:
options.thickness = 2.4
options.sleeved = True
if options.notch:
options.notch_length = 1.5
return options, args
@@ -273,12 +305,27 @@ def filter_sort_cards(cards, options):
with codecs.open(card_groups_file, 'r', 'utf-8') as cardgroup_file:
card_groups = json.load(cardgroup_file)
# pull out any cards which are a subcard, and rename the master card
new_cards = []
all_subcards = []
for subs in [card_groups[x]["subcards"] for x in card_groups]:
all_subcards += subs
new_cards = [] # holds the cards that are to be kept
all_subcards = [] # holds names of cards that will be removed
subcard_parent = {} # holds reverse map of subcard name to group name
subcard_count = {} # holds total card count of the subcards for a group
# Initialize each of the new card groups
for group in card_groups:
subcard_count[group] = 0
for subs in card_groups[group]["subcards"]:
all_subcards.append(subs) # add card names to the list for removal
subcard_parent[subs] = group # create the reverse mapping of subgroup to group
# go through the cards and add up the number of subgroup cards
for card in cards:
if card.name in all_subcards:
subcard_count[ subcard_parent[card.name] ] += card.getCardCount()
# fix up the group card holders count & name, and weed out the subgroup cards
for card in cards:
if card.name in card_groups.keys():
card.count += subcard_count[card.name]
card.name = card_groups[card.name]["new_name"]
elif card.name in all_subcards:
continue
@@ -305,13 +352,54 @@ def filter_sort_cards(cards, options):
cards = filteredCards
if options.exclude_events:
cards = [card for card in cards if not card.isEvent() or card.name == 'Events']
filteredCards = []
count = 0
holder = False
for c in cards:
if c.isType('Events'): # Language Independant by using Type
holder = c
filteredCards.append(c)
elif c.isEvent():
count += c.getCardCount()
else:
filteredCards.append(c)
if holder and count > 0:
holder.setCardCount(count)
cards = filteredCards
if options.exclude_landmarks:
cards = [card for card in cards if not card.isLandmark() or card.name == 'Landmarks']
filteredCards = []
count = 0
holder = False
for c in cards:
if c.isType('Landmarks'): # Language Independant, use Type
holder = c
filteredCards.append(c)
elif c.isLandmark():
count += c.getCardCount()
else:
filteredCards.append(c)
if holder and count > 0:
holder.setCardCount(count)
cards = filteredCards
if options.exclude_prizes:
cards = [card for card in cards if not card.isPrize()]
filteredCards = []
count = 0
holder = False
for c in cards:
if c.isType('Prizes'): # Language Independant, use Type
holder = c
filteredCards.append(c)
elif c.isPrize():
count += c.getCardCount()
else:
filteredCards.append(c)
if holder and count > 0:
holder.setCardCount(count)
cards = filteredCards
if options.cardlist:
cardlist = set()
@@ -330,7 +418,7 @@ def filter_sort_cards(cards, options):
c.cardset, []).append(c.name.strip())
for exp, names in cardnamesByExpansion.iteritems():
c = Card(
exp, exp, ("Expansion",), None, ' | '.join(sorted(names)))
exp, exp, ("Expansion",), None, ' | '.join(sorted(names)), count=len(names))
cards.append(c)
cards.sort(key=cardSorter)
@@ -338,7 +426,7 @@ def filter_sort_cards(cards, options):
return cards
def calculate_layout(options):
def calculate_layout(options, cards=[]):
dominionCardWidth, dominionCardHeight = parse_cardsize(options.size, options.sleeved)
paperwidth, paperheight = parse_papersize(options.papersize)
@@ -380,14 +468,29 @@ def calculate_layout(options):
verticalBorderSpace = options.vertical_gap * cm
dividerHeight = dividerBaseHeight + labelHeight
dividerWidthReserved = dividerWidth + horizontalBorderSpace
dividerHeightReserved = dividerHeight + verticalBorderSpace
if options.wrapper:
max_card_stack_height = max(c.getStackHeight(options.thickness) for c in cards)
dividerHeightReserved = (dividerHeightReserved * 2) + (max_card_stack_height * 2)
print "Max Card Stack Height: {:.2f}cm ".format(max_card_stack_height)
# Notch measurements
notch_height = 0.25 * cm # thumb notch height
notch_width1 = options.notch_length * cm # thumb notch width: top away from tab
notch_width2 = 0.00 * cm # thumb notch width: bottom on side of tab
add_opt(options, 'dividerWidth', dividerWidth)
add_opt(options, 'dividerHeight', dividerHeight)
add_opt(options, 'dividerBaseHeight', dividerBaseHeight)
add_opt(options, 'dividerWidthReserved', dividerWidth + horizontalBorderSpace)
add_opt(options, 'dividerHeightReserved', dividerHeight + verticalBorderSpace)
add_opt(options, 'dividerWidthReserved', dividerWidthReserved)
add_opt(options, 'dividerHeightReserved', dividerHeightReserved)
add_opt(options, 'labelWidth', labelWidth)
add_opt(options, 'labelHeight', labelHeight)
add_opt(options, 'notch_height', notch_height)
add_opt(options, 'notch_width1', notch_width1)
add_opt(options, 'notch_width2', notch_width2)
# 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
@@ -433,7 +536,12 @@ def generate(options, data_path, f):
add_opt(options, 'data_path', data_path)
calculate_layout(options)
cards = read_write_card_data(options)
assert cards, "No cards after reading"
cards = filter_sort_cards(cards, options)
assert cards, "No cards after filtering/sorting"
calculate_layout(options, cards)
print "Paper dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(options.paperwidth / cm,
options.paperheight / cm)
@@ -444,10 +552,6 @@ def generate(options, data_path, f):
print "Margins: {:.2f}cm h, {:.2f}cm v\n".format(options.horizontalMargin / cm,
options.verticalMargin / cm)
cards = read_write_card_data(options)
assert cards, "No cards after reading"
cards = filter_sort_cards(cards, options)
assert cards, "No cards after filtering/sorting"
if not f:
f = "dominion_dividers.pdf"
+58 -30
View File
@@ -1,6 +1,6 @@
import json
import os
from reportlab.lib.units import cm
def getType(typespec):
return cardTypes[tuple(typespec)]
@@ -101,7 +101,8 @@ class Card(object):
return promoTextIcons[cardName.lower()]
return None
def __init__(self, name, cardset, types, cost, description='', potcost=0, debtcost=0, extra=''):
def __init__(self, name, cardset, types, cost, description='', potcost=0, debtcost=0, extra='', count=-1):
self.name = name.strip()
self.cardset = cardset.strip()
self.types = types
@@ -110,6 +111,20 @@ class Card(object):
self.debtcost = debtcost
self.description = description
self.extra = extra
if count < 0:
self.count = getType(self.types).getTypeDefaultCardCount()
else:
self.count = count
def getCardCount(self):
return self.count
def setCardCount(self, value):
self.count = value
def getStackHeight(self, thickness):
# return height of the stacked cards in cm. Using hight in cm of a stack of 60 Copper cards as thickness.
return self.count * cm * (thickness / 60.0) + 2
def getType(self):
return getType(self.types)
@@ -122,16 +137,20 @@ class Card(object):
+ ' ' + self.cost + ' ' + self.description + ' ' + self.extra
def isExpansion(self):
return self.getType().getTypeNames() == ('Expansion',)
return 'Expansion' in self.getType().getTypeNames()
def isEvent(self):
return self.getType().getTypeNames() == ('Event',)
return 'Event' in self.getType().getTypeNames()
def isLandmark(self):
return self.getType().getTypeNames() == ('Landmark',)
return 'Landmark' in self.getType().getTypeNames()
def isPrize(self):
return 'Prize' in self.getType().getTypeNames()
def isType(self, what):
return what in self.getType().getTypeNames()
def setImage(self):
setImage = Card.getSetImage(self.cardset, self.name)
@@ -164,11 +183,15 @@ class BlankCard(Card):
class CardType(object):
def __init__(self, typeNames, tabImageFile, tabTextHeightOffset=0, tabCostHeightOffset=-1):
def __init__(self, typeNames, tabImageFile, defaultCardCount=10, tabTextHeightOffset=0, tabCostHeightOffset=-1):
self.typeNames = typeNames
self.tabImageFile = tabImageFile
self.tabTextHeightOffset = tabTextHeightOffset
self.tabCostHeightOffset = tabCostHeightOffset
self.defaultCardCount = defaultCardCount
def getTypeDefaultCardCount(self):
return self.defaultCardCount
def getTypeNames(self):
return self.typeNames
@@ -192,42 +215,47 @@ class CardType(object):
cardTypes = [
CardType(('Action',), 'action.png'),
CardType(('Action', 'Attack'), 'action.png'),
CardType(('Action', 'Attack', 'Prize'), 'action.png'),
CardType(('Action', 'Attack', 'Prize'), 'action.png',1),
CardType(('Action', 'Reaction'), 'reaction.png'),
CardType(('Action', 'Victory'), 'action-victory.png'),
CardType(('Action', 'Duration'), 'duration.png'),
CardType(('Action', 'Victory'), 'action-victory.png',12),
CardType(('Action', 'Duration'), 'duration.png',5),
CardType(('Action', 'Duration', 'Reaction'), 'duration-reaction.png'),
CardType(('Action', 'Attack', 'Duration'), 'duration.png'),
CardType(('Action', 'Looter'), 'action.png'),
CardType(('Action', 'Prize'), 'action.png'),
CardType(('Action', 'Ruins'), 'ruins.png', 0, 1),
CardType(('Action', 'Shelter'), 'action-shelter.png'),
CardType(('Action', 'Prize'), 'action.png',1),
CardType(('Action', 'Ruins'), 'ruins.png',10, 0, 1),
CardType(('Action', 'Shelter'), 'action-shelter.png',6),
CardType(('Action', 'Attack', 'Duration'), 'duration.png'),
CardType(('Action', 'Attack', 'Looter'), 'action.png'),
CardType(('Action', 'Attack', 'Traveller'), 'action.png'),
CardType(('Action', 'Reserve'), 'reserve.png'),
CardType(('Action', 'Reserve', 'Victory'), 'reserve-victory.png'),
CardType(('Action', 'Traveller'), 'action.png'),
CardType(('Action', 'Attack', 'Traveller'), 'action.png',5),
CardType(('Action', 'Reserve'), 'reserve.png',5),
CardType(('Action', 'Reserve', 'Victory'), 'reserve-victory.png',12),
CardType(('Action', 'Traveller'), 'action.png',5),
CardType(('Action', 'Gathering'), 'action.png'),
CardType(('Action', 'Treasure'), 'action-treasure.png'),
CardType(('Prize',), 'action.png'),
CardType(('Event',), 'event.png'),
CardType(('Prize',), 'action.png',1),
CardType(('Event',), 'event.png',1),
CardType(('Reaction',), 'reaction.png'),
CardType(('Reaction', 'Shelter'), 'reaction-shelter.png'),
CardType(('Treasure',), 'treasure.png', 3, 0),
CardType(('Reaction', 'Shelter'), 'reaction-shelter.png',6),
CardType(('Treasure',), 'treasure.png',10, 3, 0),
CardType(('Treasure', 'Attack'), 'treasure.png'),
CardType(('Treasure', 'Victory'), 'treasure-victory.png'),
CardType(('Treasure', 'Prize'), 'treasure.png', 3, 0),
CardType(('Treasure', 'Reaction'), 'treasure-reaction.png', 0, 1),
CardType(('Treasure', 'Victory'), 'treasure-victory.png',12),
CardType(('Treasure', 'Prize'), 'treasure.png',1, 3, 0),
CardType(('Treasure', 'Reaction'), 'treasure-reaction.png',10, 0, 1),
CardType(('Treasure', 'Reserve'), 'reserve-treasure.png'),
CardType(('Victory',), 'victory.png'),
CardType(('Victory', 'Reaction'), 'victory-reaction.png', 0, 1),
CardType(('Victory', 'Shelter'), 'victory-shelter.png'),
CardType(('Victory', 'Castle'), 'victory.png'),
CardType(('Curse',), 'curse.png', 3),
CardType(('Expansion',), 'expansion.png', 4),
CardType(('Victory',), 'victory.png',12),
CardType(('Victory', 'Reaction'), 'victory-reaction.png',12, 0, 1),
CardType(('Victory', 'Shelter'), 'victory-shelter.png',6),
CardType(('Victory', 'Castle'), 'victory.png',12),
CardType(('Curse',), 'curse.png', 30, 3),
CardType(('Trash',), 'action.png', 1),
CardType(('Prizes',), 'action.png',0),
CardType(('Events',), 'event.png',0),
CardType(('Shelters',), 'shelter.png',0),
CardType(('Expansion',), 'expansion.png',0, 4),
CardType(('Blank',), ''),
CardType(('Landmark',), 'landmark.png')
CardType(('Landmark',), 'landmark.png',1),
CardType(('Landmarks',), 'landmark.png',0)
]
cardTypes = dict(((c.getTypeNames(), c) for c in cardTypes))
+262 -59
View File
@@ -43,42 +43,150 @@ class DividerDrawer(object):
self.fontNameBold = 'Times-Bold'
self.fontNameOblique = 'Times-Oblique'
def getOutline(self, card, isExpansionDivider = False):
dividerWidth = self.options.dividerWidth
dividerHeight = self.options.dividerHeight
dividerBaseHeight = self.options.dividerBaseHeight
tabLabelWidth = self.options.labelWidth
notch_height = self.options.notch_height # thumb notch height
notch_width1 = self.options.notch_width1 # thumb notch width: top away from tab
notch_width2 = self.options.notch_width2 # thumb notch width: bottom on side of tab
theTabHeight = dividerHeight - dividerBaseHeight
theTabWidth = self.options.labelWidth
if isExpansionDivider:
side_2_tab = (dividerWidth - theTabWidth) / 2
else:
side_2_tab = 0
nonTabWidth = dividerWidth - tabLabelWidth - side_2_tab
def DeltaXYtoLines(delta):
result = []
started = False
for x,y in delta:
if not started:
last_x = x
last_y = y
started = True
else:
result.append( (last_x , last_y, last_x + x, last_y + y) )
last_x = last_x + x
last_y = last_y + y
return result
self.canvas.saveState()
if not self.options.wrapper:
# Normal Card Outline
# + F+-------------------+E
# | |
# H+-----------------------+G D+-----+C
# | |
# | Generic Divider |
# | Tab Centered or to the Side |
# | |
# A+-------------------------------------------------+B
# delta x delta y
delta = [ ( 0 , 0 ), # to A
( dividerWidth , 0 ), #A to B
( 0 , dividerBaseHeight ), #B to C
( -side_2_tab , 0 ), #C to D
( 0 , theTabHeight ), #D to E
( -theTabWidth , 0 ), #E to F
( 0 , -theTabHeight ), #F to G
( -nonTabWidth , 0 ), #G to H
( 0 , -dividerBaseHeight )] #H to A
self.canvas.lines(DeltaXYtoLines(delta))
else:
# Card Wrapper Outline
notch_width3 = notch_width1 # thumb notch width: bottom away from tab
stackHeight = card.getStackHeight(self.options.thickness)
body_minus_notches = dividerBaseHeight - (2.0 * notch_height)
tab_2_notch = dividerWidth - theTabWidth - side_2_tab - notch_width1
if (tab_2_notch < 0):
tab_2_notch = dividerWidth - theTabWidth - side_2_tab
notch_width1 = 0
# + U+-------------------+T +
# | |
# + V+. . . . . . . . . .+S +
# | |
# + X+---------------------+W . . . . . . . . R+----+Q
# | |
# Z+-------+Y +P
# | |
# | Generic Wrapper |
# | Normal Side |
# | |
# AA+-------+BB N+-------+O
# | |
# + +CC. . . . . . . . . . . . . . . . . .M+ +
# | |
# + +DD. . . . . . . . . . . . . . . . . .L+ +
# | |
# FF+-------+EE K+-------+J
# | |
# | Reverse Side |
# | rotated 180 |
# | |
# A+-------+B +I
# | |
# + C+---------------------+D G+----+H
# | |
# + E+-------------------+F +
#
# delta x delta y
delta = [ ( 0 , theTabHeight+notch_height), # to A
( notch_width1, 0 ), #A to B
( 0 , -notch_height ), #B to C
( tab_2_notch , 0 ), #C to D
( 0 , -theTabHeight ), #D to E
( theTabWidth , 0 ), #E to F
( 0 , theTabHeight ), #F to G
( side_2_tab , 0 ), #G to H
( 0 , notch_height ), #H to I
( 0 , body_minus_notches ), #I to J
(-notch_width2, 0 ), #J to K
( 0 , notch_height ), #K to L
( 0 , stackHeight ), #L to M
( 0 , notch_height ), #M to N
( notch_width2, 0 ), #N to O
( 0 , body_minus_notches ), #O to P
( 0 , notch_height ), #P to Q
(-side_2_tab , 0 ), #Q to R
( 0 , stackHeight ), #R to S
( 0 , theTabHeight ), #S to T
(-theTabWidth , 0 ), #T to U
( 0 , -theTabHeight ), #U to V
( 0 , -stackHeight ), #V to W
(-tab_2_notch , 0 ), #W to X
( 0 , -notch_height ), #X to Y
(-notch_width1, 0 ), #Y to Z
( 0 , -body_minus_notches ), #Z to AA
( notch_width3, 0 ), #AA to BB
( 0 , -notch_height ), #BB to CC
( 0 , -stackHeight ), #CC to DD
( 0 , -notch_height ), #DD to EE
(-notch_width3, 0 ), #EE to FF
( 0 , -body_minus_notches )] #FF to A
self.canvas.lines(DeltaXYtoLines(delta))
self.canvas.setStrokeGray(0.9)
self.canvas.line(dividerWidth-side_2_tab, dividerHeight + dividerBaseHeight + stackHeight , dividerWidth-side_2_tab-theTabWidth , dividerHeight + dividerBaseHeight + stackHeight )
self.canvas.line(dividerWidth-side_2_tab, dividerHeight + dividerBaseHeight + 2*stackHeight , dividerWidth-side_2_tab-theTabWidth , dividerHeight + dividerBaseHeight + 2*stackHeight )
self.canvas.line(notch_width1 , dividerHeight , dividerWidth - notch_width2, dividerHeight )
self.canvas.line(notch_width1 , dividerHeight + stackHeight , dividerWidth - notch_width2, dividerHeight + stackHeight )
self.canvas.restoreState()
def draw(self, fname, cards, options):
self.options = options
self.registerFonts()
dividerWidth = options.dividerWidth
dividerHeight = options.dividerHeight
dividerBaseHeight = options.dividerBaseHeight
tabLabelWidth = options.labelWidth
self.tabOutline = [(0, 0, dividerWidth, 0),
(dividerWidth, 0, dividerWidth, dividerHeight),
(dividerWidth, dividerHeight,
dividerWidth - tabLabelWidth, dividerHeight),
(dividerWidth - tabLabelWidth,
dividerHeight, dividerWidth - tabLabelWidth,
dividerBaseHeight),
(dividerWidth - tabLabelWidth,
dividerBaseHeight, 0, dividerBaseHeight),
(0, dividerBaseHeight, 0, 0)]
self.expansionTabOutline = [(0, 0, dividerWidth, 0),
(dividerWidth, 0, dividerWidth,
dividerBaseHeight),
(dividerWidth, dividerBaseHeight,
dividerWidth / 2 + tabLabelWidth / 2, dividerBaseHeight),
(dividerWidth / 2 + tabLabelWidth / 2, dividerBaseHeight,
dividerWidth / 2 + tabLabelWidth / 2, dividerHeight),
(dividerWidth / 2 + tabLabelWidth / 2, dividerHeight,
dividerWidth / 2 - tabLabelWidth / 2, dividerHeight),
(dividerWidth / 2 - tabLabelWidth / 2, dividerHeight,
dividerWidth / 2 - tabLabelWidth / 2, dividerBaseHeight),
(dividerWidth / 2 - tabLabelWidth / 2, dividerBaseHeight,
0, dividerBaseHeight),
(0, dividerBaseHeight, 0, 0)]
self.canvas = canvas.Canvas(
fname, pagesize=(options.paperwidth, options.paperheight))
self.drawDividers(cards)
@@ -109,7 +217,7 @@ class DividerDrawer(object):
text = re.sub('Potion', replace, text)
return text
def drawOutline(self, x, y, rightSide, isBack=False, isExpansionDivider=False):
def drawOutline(self, card, x, y, rightSide, isBack=False, isExpansionDivider=False):
# draw outline or cropmarks
self.canvas.saveState()
self.canvas.setLineWidth(self.options.linewidth)
@@ -122,11 +230,11 @@ class DividerDrawer(object):
# don't draw outline on back, in case lines don't line up with
# front
if isExpansionDivider and self.options.centre_expansion_dividers:
outline = self.expansionTabOutline
self.getOutline(card, isExpansionDivider=True)
else:
outline = self.tabOutline
self.canvas.lines(outline)
elif self.options.cropmarks:
self.getOutline(card)
elif self.options.cropmarks and not self.options.wrapper:
cmw = 0.5 * cm
# Horizontal-line cropmarks
@@ -175,7 +283,25 @@ class DividerDrawer(object):
leftLine, self.options.dividerHeight + 2 * cmw)
self.canvas.restoreState()
def drawCardCount(self, card, x, y, offset=-1):
if card.count < 1:
return 0
# base width is 16 (for image) + 2 (1 pt border on each side)
width = 18
cardIconHeight = y + offset
countHeight = cardIconHeight - 4
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'card.png'),
x, countHeight, 16, 16, preserveAspectRatio=True, mask='auto')
self.canvas.setFont(self.fontNameBold, 10)
count = str(card.count)
self.canvas.drawCentredString(x + 8, countHeight + 4, count)
return width
def drawCost(self, card, x, y, costOffset=-1):
# base width is 16 (for image) + 2 (1 pt border on each side)
width = 18
@@ -230,18 +356,36 @@ class DividerDrawer(object):
self.fontNameRegular, fontSize - 2)
return w
def drawTab(self, card, rightSide):
def drawTab(self, card, rightSide, wrapper="no"):
# draw tab flap
self.canvas.saveState()
if card.isExpansion() and self.options.centre_expansion_dividers:
self.canvas.translate(self.options.dividerWidth / 2 - self.options.labelWidth / 2,
self.options.dividerHeight - self.options.labelHeight)
translate_x = self.options.dividerWidth / 2 - self.options.labelWidth / 2
translate_y = self.options.dividerHeight - self.options.labelHeight
elif not rightSide:
self.canvas.translate(self.options.dividerWidth - self.options.labelWidth,
self.options.dividerHeight - self.options.labelHeight)
translate_x = self.options.dividerWidth - self.options.labelWidth
translate_y = self.options.dividerHeight - self.options.labelHeight
else:
self.canvas.translate(0, self.options.dividerHeight - self.options.labelHeight)
translate_x = 0
translate_y = self.options.dividerHeight - self.options.labelHeight
if wrapper == "back":
translate_y = self.options.labelHeight
if card.isExpansion() and self.options.centre_expansion_dividers:
translate_x = self.options.dividerWidth / 2 + self.options.labelWidth / 2
elif not rightSide:
translate_x = self.options.dividerWidth
else:
translate_x = self.options.labelWidth
if wrapper == "front":
translate_y = translate_y + self.options.dividerHeight + 2.0 * card.getStackHeight(self.options.thickness)
self.canvas.translate(translate_x, translate_y)
if wrapper == "back":
self.canvas.rotate(180)
# allow for 3 pt border on each side
textWidth = self.options.labelWidth - 6
textHeight = 7
@@ -259,7 +403,7 @@ class DividerDrawer(object):
preserveAspectRatio=False, anchor='n', mask='auto')
# draw cost
if not card.isExpansion() and not card.isBlank() and not card.isLandmark():
if not card.isExpansion() and not card.isBlank() and not card.isLandmark() and not card.isType('Trash'):
if 'tab' in self.options.cost:
textInset = 4
textInset += self.drawCost(card, textInset, textHeight,
@@ -325,9 +469,11 @@ class DividerDrawer(object):
h -= h / 2
words = line.split()
if (not self.options.tab_name_align == "right") and (self.options.tab_name_align == "centre" or
rightSide or
not self.options.tab_name_align == "edge"):
NotRightEdge = ( not self.options.tab_name_align == "right"
and (self.options.tab_name_align == "centre" or rightSide or not self.options.tab_name_align == "edge"))
if wrapper == "back" and not self.options.tab_name_align == "centre":
NotRightEdge = not NotRightEdge
if NotRightEdge:
if self.options.tab_name_align == "centre":
w = self.options.labelWidth / 2 - self.nameWidth(line, fontSize) / 2
else:
@@ -361,23 +507,67 @@ class DividerDrawer(object):
w += drawWordPiece(word[0], fontSize)
if i != len(words) - 1:
w += drawWordPiece(' ', fontSize)
if wrapper == "front" and card.getCardCount() >= 5:
# Print smaller version of name on the top wrapper edge
self.canvas.translate(0 , -card.getStackHeight(self.options.thickness)) # move into area used by the wrapper
fontSize = 8 # use the smallest font
self.canvas.setFont(self.fontNameRegular, fontSize)
textHeight = fontSize - 2
textHeight = card.getStackHeight(self.options.thickness) / 2 - textHeight / 2
h = textHeight
words = name.split()
w = self.options.labelWidth / 2 - self.nameWidth(name, fontSize) / 2
def drawWordPiece(text, fontSize):
self.canvas.setFont(self.fontNameRegular, fontSize)
if text != ' ':
self.canvas.drawString(w, h, text)
return pdfmetrics.stringWidth(text, self.fontNameRegular, fontSize)
for i, word in enumerate(words):
if i != 0:
w += drawWordPiece(' ', fontSize)
w += drawWordPiece(word[0], fontSize)
w += drawWordPiece(word[1:], fontSize - 2)
self.canvas.restoreState()
def drawText(self, card, divider_text="card"):
def drawText(self, card, divider_text="card", wrapper="no"):
self.canvas.saveState()
usedHeight = 0
totalHeight = self.options.dividerHeight - self.options.labelHeight
# Figure out if any translation needs to be done
if wrapper == "back":
self.canvas.translate(self.options.dividerWidth, self.options.dividerHeight)
self.canvas.rotate(180)
if wrapper == "front":
self.canvas.translate( 0 , self.options.dividerHeight + card.getStackHeight(self.options.thickness))
if wrapper == "front" or wrapper == "back":
if self.options.notch_width1 > 0:
usedHeight += self.options.notch_height
drewTopIcon = False
if 'body-top' in self.options.cost and not card.isExpansion():
self.drawCost(card, cm / 4.0, totalHeight - 0.5 * cm)
self.drawCost(card, cm / 4.0, totalHeight - usedHeight - 0.5 * cm)
drewTopIcon = True
Image_x = self.options.dividerWidth - 16
if 'body-top' in self.options.set_icon and not card.isExpansion():
setImage = card.setImage()
if setImage:
self.drawSetIcon(setImage, self.options.dividerWidth - 16,
totalHeight - 0.5 * cm - 3)
self.drawSetIcon(setImage, Image_x,
totalHeight - usedHeight - 0.5 * cm - 3)
Image_x -= 16
drewTopIcon = True
if self.options.count:
self.drawCardCount(card, Image_x, totalHeight - usedHeight - 0.5 * cm)
drewTopIcon = True
if drewTopIcon:
usedHeight += 15
@@ -432,8 +622,10 @@ class DividerDrawer(object):
h -= p.height
p.drawOn(self.canvas, textHorizontalMargin, h)
h -= spacerHeight
self.canvas.restoreState()
def drawDivider(self, card, x, y, isBack=False, divider_text="card"):
def drawDivider(self, card, x, y, isBack=False, divider_text="card", divider_text2="rules"):
# figure out whether the tab should go on the right side or not
if self.options.tab_side == "right":
rightSide = isBack
@@ -456,11 +648,18 @@ class DividerDrawer(object):
# actual drawing
if not self.options.tabs_only:
self.drawOutline(
x, y, rightSide, isBack, card.getType().getTypeNames() == ('Expansion',))
self.drawTab(card, rightSide)
self.drawOutline(card, x, y, rightSide, isBack, card.getType().getTypeNames() == ('Expansion',))
if self.options.wrapper:
wrap = "front"
else:
wrap = "no"
self.drawTab(card, rightSide, wrapper=wrap)
if not self.options.tabs_only:
self.drawText(card, divider_text)
self.drawText(card, divider_text, wrapper=wrap)
if self.options.wrapper:
self.drawTab(card, rightSide, wrapper="back")
self.drawText(card, divider_text2, wrapper="back")
def drawSetNames(self, pageCards):
# print sets for this page
@@ -500,7 +699,11 @@ class DividerDrawer(object):
return
self.canvas.setFont(fontname, fontsize)
xPos = layout['width'] / 2
# Place at the very edge of the margin
yPos = layout['minMarginHeight']
sets = []
for c in pageCards:
setTitle = c.cardset.title()
@@ -542,13 +745,13 @@ class DividerDrawer(object):
x = i % self.options.numDividersHorizontal
y = i / self.options.numDividersHorizontal
self.canvas.saveState()
self.drawDivider(card, x, self.options.numDividersVertical - 1 - y, isBack=False, divider_text=self.options.text_front)
self.drawDivider(card, x, self.options.numDividersVertical - 1 - y, isBack=False, divider_text=self.options.text_front, divider_text2=self.options.text_back)
self.canvas.restoreState()
self.odd = not self.odd
self.canvas.showPage()
if pageNum + 1 == self.options.num_pages:
break
if self.options.tabs_only or self.options.text_back == "none":
if self.options.tabs_only or self.options.text_back == "none" or self.options.wrapper:
# Don't print the sheets with the back of the dividers
continue
if not self.options.no_page_footer and self.options.order != "global":