- start using argparse instead of optionparser
- make all code conform to pep8 once more - add a unit test to check for pep8 compliance - delete old ez_setup
This commit is contained in:
1 parent
669fa4c7e6
commit
b70bd37d80
11 files changed
+859
-979
No files matched your search
+338
-223
@@ -1,8 +1,8 @@
|
||||
from optparse import OptionParser
|
||||
import os
|
||||
import codecs
|
||||
import json
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
import reportlab.lib.pagesizes as pagesizes
|
||||
from reportlab.lib.units import cm
|
||||
@@ -12,7 +12,8 @@ from draw import DividerDrawer
|
||||
|
||||
LOCATION_CHOICES = ["tab", "body-top", "hide"]
|
||||
NAME_ALIGN_CHOICES = ["left", "right", "centre", "edge"]
|
||||
TAB_SIDE_CHOICES = ["left", "right", "left-alternate", "right-alternate", "full"]
|
||||
TAB_SIDE_CHOICES = ["left", "right", "left-alternate", "right-alternate",
|
||||
"full"]
|
||||
TEXT_CHOICES = ["card", "rules", "blank"]
|
||||
|
||||
|
||||
@@ -21,154 +22,259 @@ def add_opt(options, option, value):
|
||||
setattr(options, option, value)
|
||||
|
||||
|
||||
def parse_opts(argstring):
|
||||
parser = OptionParser()
|
||||
parser.add_option("--back_offset", type="float", dest="back_offset", default=0,
|
||||
help="Points to offset the back page to the right; needed for some printers")
|
||||
parser.add_option("--back_offset_height", type="float", dest="back_offset_height", default=0,
|
||||
help="Points to offset the back page upward; needed for some printers")
|
||||
parser.add_option("--orientation", type="choice", choices=["horizontal", "vertical"],
|
||||
dest="orientation", default="horizontal",
|
||||
help="horizontal or vertical, default:horizontal")
|
||||
parser.add_option("--sleeved", action="store_true",
|
||||
dest="sleeved", help="use --size=sleeved instead")
|
||||
parser.add_option("--size", type="string", dest="size", default='normal',
|
||||
help="'<%f>x<%f>' (size in cm), or 'normal' = '9.1x5.9', or 'sleeved' = '9.4x6.15'")
|
||||
parser.add_option("--minmargin", type="string", dest="minmargin", default="1x1",
|
||||
help="'<%f>x<%f>' (size in cm, left/right, top/bottom), default: 1x1")
|
||||
parser.add_option("--papersize", type="string", dest="papersize", default=None,
|
||||
help="'<%f>x<%f>' (size in cm), or 'A4', or 'LETTER'")
|
||||
parser.add_option("--front", type="choice", choices=TEXT_CHOICES,
|
||||
dest="text_front", default="card",
|
||||
help="Text to print on the front of the divider. choices: card, rules, blank;"
|
||||
" 'card' will print the text from the game card;"
|
||||
" 'rules' will print additional rules for the game card;"
|
||||
" 'blank' will not print text on the divider;"
|
||||
" default:card")
|
||||
parser.add_option("--back", type="choice", choices=TEXT_CHOICES + ["none"],
|
||||
dest="text_back", default="rules",
|
||||
help="Text to print on the back of the divider. choices: card, rules, blank, none;"
|
||||
" 'card' will print the text from the game card;"
|
||||
" 'rules' will print additional rules for the game card;"
|
||||
" 'blank' will not print text on the divider;"
|
||||
" 'none' will prevent the back pages from printing;"
|
||||
" default:rules")
|
||||
parser.add_option("--tab_name_align", type="choice", choices=NAME_ALIGN_CHOICES + ["center"],
|
||||
dest="tab_name_align", default="left",
|
||||
help="Alignment of text on the tab. choices: left, right, centre (or center), edge."
|
||||
" The edge option will align the card name to the outside edge of the"
|
||||
" tab, so that when using tabs on alternating sides,"
|
||||
" the name is less likely to be hidden by the tab in front"
|
||||
" (edge will revert to left when tab_side is full since there is no edge in that case);"
|
||||
" default:left")
|
||||
parser.add_option("--tab_side", type="choice", choices=TAB_SIDE_CHOICES,
|
||||
dest="tab_side", default="right-alternate",
|
||||
help="Alignment of tab. choices: left, right, left-alternate, right-alternate, full;"
|
||||
" left/right forces all tabs to left/right side;"
|
||||
" left-alternate will start on the left and then toggle between left and right for the tabs;"
|
||||
" right-alternate will start on the right and then toggle between right and left for the tabs;" # noqa
|
||||
" full will force all label tabs to be full width of the divider"
|
||||
" default:right-alternate")
|
||||
parser.add_option("--tabwidth", type="float", default=4,
|
||||
help="width in cm of stick-up tab (ignored if tab_side is full or tabs-only is used)")
|
||||
parser.add_option("--cost", action="append", type="choice",
|
||||
choices=LOCATION_CHOICES, default=[],
|
||||
help="where to display the card cost; may be set to"
|
||||
" 'hide' to indicate it should not be displayed, or"
|
||||
" given multiple times to show it in multiple"
|
||||
" places; valid values are: %s; defaults to 'tab'"
|
||||
% ", ".join("'%s'" % x for x in LOCATION_CHOICES))
|
||||
parser.add_option("--set_icon", action="append", type="choice",
|
||||
choices=LOCATION_CHOICES, default=[],
|
||||
help="where to display the set icon; may be set to"
|
||||
" 'hide' to indicate it should not be displayed, or"
|
||||
" given multiple times to show it in multiple"
|
||||
" places; valid values are: %s; defaults to 'tab'"
|
||||
% ", ".join("'%s'" % x for x in LOCATION_CHOICES))
|
||||
parser.add_option("--expansions", action="append", type="string",
|
||||
help="subset of dominion expansions to produce tabs for")
|
||||
parser.add_option("--cropmarks", action="store_true", dest="cropmarks",
|
||||
help="print crop marks on both sides, rather than tab outlines on one")
|
||||
parser.add_option("--linewidth", type="float", default=.1,
|
||||
help="width of lines for card outlines/crop marks")
|
||||
parser.add_option("--write_json", action="store_true", dest="write_json",
|
||||
help="write json version of card definitions and extras")
|
||||
parser.add_option("--tabs-only", action="store_true", dest="tabs_only",
|
||||
help="draw only tabs to be printed on labels, no divider outlines")
|
||||
parser.add_option("--order", type="choice", choices=["expansion", "global", "colour"], dest="order",
|
||||
help="sort order for the cards, whether by expansion or globally alphabetical")
|
||||
parser.add_option("--expansion_dividers", action="store_true", dest="expansion_dividers",
|
||||
help="add dividers describing each expansion set")
|
||||
parser.add_option("--base_cards_with_expansion", action="store_true",
|
||||
help='print the base cards as part of the expansion; ie, a divider for "Silver"'
|
||||
' will be printed as both a "Dominion" card and as an "Intrigue" card; if this'
|
||||
' option is not given, all base cards are placed in their own "Base" expansion')
|
||||
parser.add_option("--centre_expansion_dividers", action="store_true", dest="centre_expansion_dividers",
|
||||
help='centre the tabs on expansion dividers')
|
||||
parser.add_option("--num_pages", type="int", default=-1,
|
||||
help="stop generating after this many pages, -1 for all")
|
||||
parser.add_option("--language", default='en_us', help="language of card texts")
|
||||
parser.add_option("--include_blanks", action="store_true",
|
||||
help="include a few dividers with extra text")
|
||||
parser.add_option("--exclude_events", action="store_true",
|
||||
default=False, help="exclude individual dividers for events")
|
||||
parser.add_option("--exclude_landmarks", action="store_true",
|
||||
default=False, help="exclude individual dividers for landmarks")
|
||||
parser.add_option("--special_card_groups", action="store_true",
|
||||
default=False, help="group some cards under special dividers (e.g. Shelters, Prizes)")
|
||||
parser.add_option("--exclude_prizes", action="store_true",
|
||||
default=False, help="exclude individual dividers for prizes (cornucopia)")
|
||||
parser.add_option("--cardlist", type="string", dest="cardlist", default=None,
|
||||
help="Path to file that enumerates each card to be printed on its own line.")
|
||||
parser.add_option("--no-tab-artwork", action="store_true", dest="no_tab_artwork",
|
||||
help="don't show background artwork on tabs")
|
||||
parser.add_option("--use-text-set-icon", action="store_true", dest="use_text_set_icon",
|
||||
help="use text/letters to represent a card's set instead of the set icon")
|
||||
parser.add_option("--no-page-footer", action="store_true", dest="no_page_footer",
|
||||
help="don't print the set name at the bottom of the page.")
|
||||
parser.add_option("--horizontal_gap", type=float, default=0.,
|
||||
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")
|
||||
def parse_opts(arglist):
|
||||
parser = argparse.ArgumentParser(description="Generate Dominion Dividers")
|
||||
parser.add_argument('--outfile', default="dominion_dividers.pdf")
|
||||
parser.add_argument(
|
||||
"--back_offset",
|
||||
type=float,
|
||||
dest="back_offset",
|
||||
default=0,
|
||||
help="Points to offset the back page to the right; needed for some printers")
|
||||
parser.add_argument(
|
||||
"--back_offset_height",
|
||||
type=float,
|
||||
dest="back_offset_height",
|
||||
default=0,
|
||||
help="Points to offset the back page upward; needed for some printers")
|
||||
parser.add_argument("--orientation",
|
||||
choices=["horizontal", "vertical"],
|
||||
dest="orientation",
|
||||
default="horizontal",
|
||||
help="horizontal or vertical, default:horizontal")
|
||||
parser.add_argument("--sleeved",
|
||||
action="store_true",
|
||||
dest="sleeved",
|
||||
help="use --size=sleeved instead")
|
||||
parser.add_argument(
|
||||
"--size",
|
||||
dest="size",
|
||||
default='normal',
|
||||
help="'<%f>x<%f>' (size in cm), or 'normal' = '9.1x5.9', or 'sleeved' = '9.4x6.15'")
|
||||
parser.add_argument(
|
||||
"--minmargin",
|
||||
dest="minmargin",
|
||||
default="1x1",
|
||||
help="'<%f>x<%f>' (size in cm, left/right, top/bottom), default: 1x1")
|
||||
parser.add_argument("--papersize",
|
||||
dest="papersize",
|
||||
default=None,
|
||||
help="'<%f>x<%f>' (size in cm), or 'A4', or 'LETTER'")
|
||||
parser.add_argument(
|
||||
"--front",
|
||||
choices=TEXT_CHOICES,
|
||||
dest="text_front",
|
||||
default="card",
|
||||
help="Text to print on the front of the divider. choices: card, rules, blank;"
|
||||
" 'card' will print the text from the game card;"
|
||||
" 'rules' will print additional rules for the game card;"
|
||||
" 'blank' will not print text on the divider;"
|
||||
" default:card")
|
||||
parser.add_argument(
|
||||
"--back",
|
||||
choices=TEXT_CHOICES + ["none"],
|
||||
dest="text_back",
|
||||
default="rules",
|
||||
help="Text to print on the back of the divider. choices: card, rules, blank, none;"
|
||||
" 'card' will print the text from the game card;"
|
||||
" 'rules' will print additional rules for the game card;"
|
||||
" 'blank' will not print text on the divider;"
|
||||
" 'none' will prevent the back pages from printing;"
|
||||
" default:rules")
|
||||
parser.add_argument(
|
||||
"--tab_name_align",
|
||||
choices=NAME_ALIGN_CHOICES + ["center"],
|
||||
dest="tab_name_align",
|
||||
default="left",
|
||||
help="Alignment of text on the tab. choices: left, right, centre (or center), edge."
|
||||
" The edge option will align the card name to the outside edge of the"
|
||||
" tab, so that when using tabs on alternating sides,"
|
||||
" the name is less likely to be hidden by the tab in front"
|
||||
" (edge will revert to left when tab_side is full since there is no edge in that case);"
|
||||
" default:left")
|
||||
parser.add_argument(
|
||||
"--tab_side",
|
||||
choices=TAB_SIDE_CHOICES,
|
||||
dest="tab_side",
|
||||
default="right-alternate",
|
||||
help="Alignment of tab. choices: left, right, left-alternate, right-alternate, full;"
|
||||
" left/right forces all tabs to left/right side;"
|
||||
" left-alternate will start on the left and then toggle between left and right for the tabs;"
|
||||
" right-alternate will start on the right and then toggle between right and left for the tabs;" # noqa
|
||||
" full will force all label tabs to be full width of the divider"
|
||||
" default:right-alternate")
|
||||
parser.add_argument(
|
||||
"--tabwidth",
|
||||
type=float,
|
||||
default=4,
|
||||
help="width in cm of stick-up tab (ignored if tab_side is full or tabs-only is used)")
|
||||
parser.add_argument("--cost",
|
||||
action="append",
|
||||
choices=LOCATION_CHOICES,
|
||||
default=[],
|
||||
help="where to display the card cost; may be set to"
|
||||
" 'hide' to indicate it should not be displayed, or"
|
||||
" given multiple times to show it in multiple"
|
||||
" places; valid values are: %s; defaults to 'tab'" %
|
||||
", ".join("'%s'" % x for x in LOCATION_CHOICES))
|
||||
parser.add_argument("--set_icon",
|
||||
action="append",
|
||||
choices=LOCATION_CHOICES,
|
||||
default=[],
|
||||
help="where to display the set icon; may be set to"
|
||||
" 'hide' to indicate it should not be displayed, or"
|
||||
" given multiple times to show it in multiple"
|
||||
" places; valid values are: %s; defaults to 'tab'" %
|
||||
", ".join("'%s'" % x for x in LOCATION_CHOICES))
|
||||
parser.add_argument(
|
||||
"--expansions",
|
||||
action="append",
|
||||
help="subset of dominion expansions to produce tabs for")
|
||||
parser.add_argument(
|
||||
"--cropmarks",
|
||||
action="store_true",
|
||||
dest="cropmarks",
|
||||
help="print crop marks on both sides, rather than tab outlines on one")
|
||||
parser.add_argument("--linewidth",
|
||||
type=float,
|
||||
default=.1,
|
||||
help="width of lines for card outlines/crop marks")
|
||||
parser.add_argument(
|
||||
"--write_json",
|
||||
action="store_true",
|
||||
dest="write_json",
|
||||
help="write json version of card definitions and extras")
|
||||
parser.add_argument(
|
||||
"--tabs-only",
|
||||
action="store_true",
|
||||
dest="tabs_only",
|
||||
help="draw only tabs to be printed on labels, no divider outlines")
|
||||
parser.add_argument(
|
||||
"--order",
|
||||
choices=["expansion", "global", "colour"],
|
||||
dest="order",
|
||||
help="sort order for the cards, whether by expansion or globally alphabetical")
|
||||
parser.add_argument("--expansion_dividers",
|
||||
action="store_true",
|
||||
dest="expansion_dividers",
|
||||
help="add dividers describing each expansion set")
|
||||
parser.add_argument(
|
||||
"--base_cards_with_expansion",
|
||||
action="store_true",
|
||||
help='print the base cards as part of the expansion; ie, a divider for "Silver"'
|
||||
' will be printed as both a "Dominion" card and as an "Intrigue" card; if this'
|
||||
' option is not given, all base cards are placed in their own "Base" expansion')
|
||||
parser.add_argument("--centre_expansion_dividers",
|
||||
action="store_true",
|
||||
dest="centre_expansion_dividers",
|
||||
help='centre the tabs on expansion dividers')
|
||||
parser.add_argument(
|
||||
"--num_pages",
|
||||
type=int,
|
||||
default=-1,
|
||||
help="stop generating after this many pages, -1 for all")
|
||||
parser.add_argument("--language",
|
||||
default='en_us',
|
||||
help="language of card texts")
|
||||
parser.add_argument("--include_blanks",
|
||||
action="store_true",
|
||||
help="include a few dividers with extra text")
|
||||
parser.add_argument("--exclude_events",
|
||||
action="store_true",
|
||||
help="exclude individual dividers for events")
|
||||
parser.add_argument("--exclude_landmarks",
|
||||
action="store_true",
|
||||
help="exclude individual dividers for landmarks")
|
||||
parser.add_argument(
|
||||
"--special_card_groups",
|
||||
action="store_true",
|
||||
help="group some cards under special dividers (e.g. Shelters, Prizes)")
|
||||
parser.add_argument(
|
||||
"--exclude_prizes",
|
||||
action="store_true",
|
||||
help="exclude individual dividers for prizes (cornucopia)")
|
||||
parser.add_argument(
|
||||
"--cardlist",
|
||||
dest="cardlist",
|
||||
help="Path to file that enumerates each card to be printed on its own line.")
|
||||
parser.add_argument("--no-tab-artwork",
|
||||
action="store_true",
|
||||
dest="no_tab_artwork",
|
||||
help="don't show background artwork on tabs")
|
||||
parser.add_argument(
|
||||
"--use-text-set-icon",
|
||||
action="store_true",
|
||||
dest="use_text_set_icon",
|
||||
help="use text/letters to represent a card's set instead of the set icon")
|
||||
parser.add_argument(
|
||||
"--no-page-footer",
|
||||
action="store_true",
|
||||
dest="no_page_footer",
|
||||
help="don't print the set name at the bottom of the page.")
|
||||
parser.add_argument("--horizontal_gap",
|
||||
type=float,
|
||||
default=0.,
|
||||
help="horizontal gap between dividers in centimeters")
|
||||
parser.add_argument("--vertical_gap",
|
||||
type=float,
|
||||
default=0.,
|
||||
help="vertical gap between dividers in centimeters")
|
||||
parser.add_argument("--count",
|
||||
action="store_true",
|
||||
dest="count",
|
||||
help="Display card count on body of the divider.")
|
||||
parser.add_argument(
|
||||
"--wrapper",
|
||||
action="store_true",
|
||||
dest="wrapper",
|
||||
help="Draw wrapper for cards instead of a divider for the cards")
|
||||
parser.add_argument(
|
||||
"--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_argument("--sleeved_thick",
|
||||
action="store_true",
|
||||
dest="sleeved_thick",
|
||||
help="same as --size=sleeved --thickness 3.2")
|
||||
parser.add_argument("--sleeved_thin",
|
||||
action="store_true",
|
||||
dest="sleeved_thin",
|
||||
help="same as --size=sleeved --thickness 2.4")
|
||||
parser.add_argument(
|
||||
"--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_argument("--notch",
|
||||
action="store_true",
|
||||
dest="notch",
|
||||
help="same as --notch_length thickness 1.5")
|
||||
|
||||
options, args = parser.parse_args(argstring)
|
||||
options = parser.parse_args(arglist)
|
||||
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
|
||||
options.sleeved = True
|
||||
|
||||
if options.sleeved_thin:
|
||||
options.thickness = 2.4
|
||||
options.sleeved = True
|
||||
|
||||
options.sleeved = True
|
||||
|
||||
if options.notch:
|
||||
options.notch_length = 1.5
|
||||
|
||||
return options, args
|
||||
|
||||
return options
|
||||
|
||||
|
||||
def parseDimensions(dimensionsStr):
|
||||
@@ -202,7 +308,8 @@ def parse_papersize(spec):
|
||||
except AttributeError:
|
||||
try:
|
||||
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)
|
||||
except ValueError:
|
||||
paperwidth, paperheight = pagesizes.LETTER
|
||||
return paperwidth, paperheight
|
||||
@@ -212,16 +319,16 @@ 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)
|
||||
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)
|
||||
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)
|
||||
print 'Using custom card size, %.2fcm x %.2fcm' % (
|
||||
dominionCardWidth / cm, dominionCardHeight / cm)
|
||||
return dominionCardWidth, dominionCardHeight
|
||||
|
||||
|
||||
@@ -250,7 +357,6 @@ def read_write_card_data(options):
|
||||
|
||||
|
||||
class CardSorter(object):
|
||||
|
||||
def __init__(self, order, baseCards):
|
||||
self.order = order
|
||||
if order == "global":
|
||||
@@ -280,7 +386,8 @@ class CardSorter(object):
|
||||
return int(card.isExpansion()), self.baseIndex(card.name), card.name
|
||||
|
||||
def by_expansion_sort_key(self, card):
|
||||
return card.cardset, int(card.isExpansion()), self.baseIndex(card.name), card.name
|
||||
return card.cardset, int(card.isExpansion()), self.baseIndex(
|
||||
card.name), card.name
|
||||
|
||||
def colour_sort_key(self, card):
|
||||
return card.getType().getTypeNames(), card.name
|
||||
@@ -291,12 +398,14 @@ class CardSorter(object):
|
||||
|
||||
def filter_sort_cards(cards, options):
|
||||
|
||||
cardSorter = CardSorter(options.order,
|
||||
[card.name for card in cards if card.cardset.lower() == 'base'])
|
||||
cardSorter = CardSorter(
|
||||
options.order,
|
||||
[card.name for card in cards if card.cardset.lower() == 'base'])
|
||||
if options.base_cards_with_expansion:
|
||||
cards = [card for card in cards if card.cardset.lower() != 'base']
|
||||
else:
|
||||
cards = [card for card in cards if not cardSorter.isBaseExpansionCard(card)]
|
||||
cards = [card for card in cards
|
||||
if not cardSorter.isBaseExpansionCard(card)]
|
||||
|
||||
if options.special_card_groups:
|
||||
# Load the card groups file
|
||||
@@ -305,24 +414,29 @@ 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 = [] # 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
|
||||
|
||||
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:
|
||||
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
|
||||
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
|
||||
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]
|
||||
@@ -333,21 +447,22 @@ def filter_sort_cards(cards, options):
|
||||
cards = new_cards
|
||||
|
||||
if options.expansions:
|
||||
options.expansions = [o.lower()
|
||||
for o in options.expansions]
|
||||
reverseMapping = {
|
||||
v: k for k, v in Card.language_mapping.iteritems()}
|
||||
options.expansions = [o.lower() for o in options.expansions]
|
||||
reverseMapping = {v: k for k, v in Card.language_mapping.iteritems()}
|
||||
options.expansions = [
|
||||
reverseMapping.get(e, e) for e in options.expansions]
|
||||
reverseMapping.get(e, e) for e in options.expansions
|
||||
]
|
||||
filteredCards = []
|
||||
knownExpansions = set()
|
||||
for c in cards:
|
||||
knownExpansions.add(c.cardset)
|
||||
if next((e for e in options.expansions if c.cardset.startswith(e)), None):
|
||||
if next((e for e in options.expansions
|
||||
if c.cardset.startswith(e)), None):
|
||||
filteredCards.append(c)
|
||||
unknownExpansions = set(options.expansions) - knownExpansions
|
||||
if unknownExpansions:
|
||||
print "Error - unknown expansion(s): %s" % ", ".join(unknownExpansions)
|
||||
print "Error - unknown expansion(s): %s" % ", ".join(
|
||||
unknownExpansions)
|
||||
|
||||
cards = filteredCards
|
||||
|
||||
@@ -398,8 +513,6 @@ def filter_sort_cards(cards, options):
|
||||
if holder and count > 0:
|
||||
holder.setCardCount(count)
|
||||
cards = filteredCards
|
||||
|
||||
|
||||
|
||||
if options.cardlist:
|
||||
cardlist = set()
|
||||
@@ -414,11 +527,14 @@ def filter_sort_cards(cards, options):
|
||||
for c in cards:
|
||||
if cardSorter.isBaseExpansionCard(c):
|
||||
continue
|
||||
cardnamesByExpansion.setdefault(
|
||||
c.cardset, []).append(c.name.strip())
|
||||
cardnamesByExpansion.setdefault(c.cardset,
|
||||
[]).append(c.name.strip())
|
||||
for exp, names in cardnamesByExpansion.iteritems():
|
||||
c = Card(
|
||||
exp, exp, ("Expansion",), None, ' | '.join(sorted(names)), count=len(names))
|
||||
c = Card(exp,
|
||||
exp, ("Expansion", ),
|
||||
None,
|
||||
' | '.join(sorted(names)),
|
||||
count=len(names))
|
||||
cards.append(c)
|
||||
|
||||
cards.sort(key=cardSorter)
|
||||
@@ -428,7 +544,8 @@ def filter_sort_cards(cards, options):
|
||||
|
||||
def calculate_layout(options, cards=[]):
|
||||
|
||||
dominionCardWidth, dominionCardHeight = parse_cardsize(options.size, options.sleeved)
|
||||
dominionCardWidth, dominionCardHeight = parse_cardsize(options.size,
|
||||
options.sleeved)
|
||||
paperwidth, paperheight = parse_papersize(options.papersize)
|
||||
|
||||
if options.orientation == "vertical":
|
||||
@@ -441,24 +558,23 @@ def calculate_layout(options, cards=[]):
|
||||
|
||||
if options.tab_side == "full" and options.tab_name_align == "edge":
|
||||
# This case does not make sense since there are two tab edges in this case. So picking left edge.
|
||||
print >>sys.stderr, "** Warning: Aligning card name as 'left' for 'full' tabs **"
|
||||
print >> sys.stderr, "** Warning: Aligning card name as 'left' for 'full' tabs **"
|
||||
options.tab_name_align = "left"
|
||||
|
||||
fixedMargins = False
|
||||
if options.tabs_only:
|
||||
# fixed for Avery 8867 for now
|
||||
minmarginwidth = 0.86 * cm # was 0.76
|
||||
minmarginheight = 1.37 * cm # was 1.27
|
||||
labelHeight = 1.07 * cm # was 1.27
|
||||
labelWidth = 4.24 * cm # was 4.44
|
||||
horizontalBorderSpace = 0.96 * cm # was 0.76
|
||||
verticalBorderSpace = 0.20 * cm # was 0.01
|
||||
minmarginwidth = 0.86 * cm # was 0.76
|
||||
minmarginheight = 1.37 * cm # was 1.27
|
||||
labelHeight = 1.07 * cm # was 1.27
|
||||
labelWidth = 4.24 * cm # was 4.44
|
||||
horizontalBorderSpace = 0.96 * cm # was 0.76
|
||||
verticalBorderSpace = 0.20 * cm # was 0.01
|
||||
dividerBaseHeight = 0
|
||||
dividerWidth = labelWidth
|
||||
fixedMargins = True
|
||||
else:
|
||||
minmarginwidth, minmarginheight = parseDimensions(
|
||||
options.minmargin)
|
||||
minmarginwidth, minmarginheight = parseDimensions(options.minmargin)
|
||||
if options.tab_side == "full":
|
||||
labelWidth = dividerWidth
|
||||
else:
|
||||
@@ -468,18 +584,20 @@ def calculate_layout(options, cards=[]):
|
||||
verticalBorderSpace = options.vertical_gap * cm
|
||||
|
||||
dividerHeight = dividerBaseHeight + labelHeight
|
||||
|
||||
dividerWidthReserved = dividerWidth + horizontalBorderSpace
|
||||
|
||||
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)
|
||||
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
|
||||
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)
|
||||
@@ -495,16 +613,20 @@ def calculate_layout(options, cards=[]):
|
||||
# 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
|
||||
numDividersVerticalP = int(
|
||||
(paperheight - 2 * minmarginheight + verticalBorderSpace) / options.dividerHeightReserved)
|
||||
(paperheight - 2 * minmarginheight + verticalBorderSpace) /
|
||||
options.dividerHeightReserved)
|
||||
numDividersHorizontalP = int(
|
||||
(paperwidth - 2 * minmarginwidth + horizontalBorderSpace) / options.dividerWidthReserved)
|
||||
(paperwidth - 2 * minmarginwidth + horizontalBorderSpace) /
|
||||
options.dividerWidthReserved)
|
||||
numDividersVerticalL = int(
|
||||
(paperwidth - 2 * minmarginwidth + verticalBorderSpace) / options.dividerHeightReserved)
|
||||
(paperwidth - 2 * minmarginwidth + verticalBorderSpace) /
|
||||
options.dividerHeightReserved)
|
||||
numDividersHorizontalL = int(
|
||||
(paperheight - 2 * minmarginheight + horizontalBorderSpace) / options.dividerWidthReserved)
|
||||
(paperheight - 2 * minmarginheight + horizontalBorderSpace) /
|
||||
options.dividerWidthReserved)
|
||||
|
||||
if ((numDividersVerticalL * numDividersHorizontalL >
|
||||
numDividersVerticalP * numDividersHorizontalP) and not fixedMargins):
|
||||
if ((numDividersVerticalL * numDividersHorizontalL > numDividersVerticalP *
|
||||
numDividersHorizontalP) and not fixedMargins):
|
||||
add_opt(options, 'numDividersVertical', numDividersVerticalL)
|
||||
add_opt(options, 'numDividersHorizontal', numDividersHorizontalL)
|
||||
add_opt(options, 'paperheight', paperwidth)
|
||||
@@ -522,17 +644,17 @@ def calculate_layout(options, cards=[]):
|
||||
if not fixedMargins:
|
||||
# dynamically max margins
|
||||
add_opt(options, 'horizontalMargin',
|
||||
(options.paperwidth -
|
||||
options.numDividersHorizontal * options.dividerWidthReserved + horizontalBorderSpace) / 2)
|
||||
(options.paperwidth - options.numDividersHorizontal *
|
||||
options.dividerWidthReserved + horizontalBorderSpace) / 2)
|
||||
add_opt(options, 'verticalMargin',
|
||||
(options.paperheight -
|
||||
options.numDividersVertical * options.dividerHeightReserved + verticalBorderSpace) / 2)
|
||||
(options.paperheight - options.numDividersVertical *
|
||||
options.dividerHeightReserved + verticalBorderSpace) / 2)
|
||||
else:
|
||||
add_opt(options, 'horizontalMargin', minmarginwidth)
|
||||
add_opt(options, 'verticalMargin', minmarginheight)
|
||||
|
||||
|
||||
def generate(options, data_path, f):
|
||||
def generate(options, data_path):
|
||||
|
||||
add_opt(options, 'data_path', data_path)
|
||||
|
||||
@@ -543,26 +665,19 @@ def generate(options, data_path, f):
|
||||
|
||||
calculate_layout(options, cards)
|
||||
|
||||
print "Paper dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(options.paperwidth / cm,
|
||||
options.paperheight / cm)
|
||||
print "Tab dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(options.dividerWidthReserved / cm,
|
||||
options.dividerHeightReserved / cm)
|
||||
print '{} dividers horizontally, {} vertically'.format(options.numDividersHorizontal,
|
||||
options.numDividersVertical)
|
||||
print "Margins: {:.2f}cm h, {:.2f}cm v\n".format(options.horizontalMargin / cm,
|
||||
options.verticalMargin / cm)
|
||||
|
||||
|
||||
if not f:
|
||||
f = "dominion_dividers.pdf"
|
||||
print "Paper dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(
|
||||
options.paperwidth / cm, options.paperheight / cm)
|
||||
print "Tab dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(
|
||||
options.dividerWidthReserved / cm, options.dividerHeightReserved / cm)
|
||||
print '{} dividers horizontally, {} vertically'.format(
|
||||
options.numDividersHorizontal, options.numDividersVertical)
|
||||
print "Margins: {:.2f}cm h, {:.2f}cm v\n".format(
|
||||
options.horizontalMargin / cm, options.verticalMargin / cm)
|
||||
|
||||
dd = DividerDrawer()
|
||||
dd.draw(f, cards, options)
|
||||
dd.draw(cards, options)
|
||||
|
||||
|
||||
def main(argstring, data_path):
|
||||
options, args = parse_opts(argstring)
|
||||
fname = None
|
||||
if args:
|
||||
fname = args[0]
|
||||
return generate(options, data_path, fname)
|
||||
def main(arglist, data_path):
|
||||
options = parse_opts(arglist)
|
||||
return generate(options, data_path)
|
||||
+32
-33
@@ -2,6 +2,7 @@ import json
|
||||
import os
|
||||
from reportlab.lib.units import cm
|
||||
|
||||
|
||||
def getType(typespec):
|
||||
return cardTypes[tuple(typespec)]
|
||||
|
||||
@@ -101,7 +102,6 @@ class Card(object):
|
||||
return promoTextIcons[cardName.lower()]
|
||||
return None
|
||||
|
||||
|
||||
def __init__(self, name, cardset, types, cost, description='', potcost=0, debtcost=0, extra='', count=-1):
|
||||
self.name = name.strip()
|
||||
self.cardset = cardset.strip()
|
||||
@@ -115,13 +115,13 @@ class Card(object):
|
||||
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
|
||||
@@ -147,11 +147,10 @@ class Card(object):
|
||||
|
||||
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)
|
||||
if setImage is None and self.cardset not in ['base', 'extra'] and not self.isExpansion():
|
||||
@@ -215,47 +214,47 @@ class CardType(object):
|
||||
cardTypes = [
|
||||
CardType(('Action',), 'action.png'),
|
||||
CardType(('Action', 'Attack'), 'action.png'),
|
||||
CardType(('Action', 'Attack', 'Prize'), 'action.png',1),
|
||||
CardType(('Action', 'Attack', 'Prize'), 'action.png', 1),
|
||||
CardType(('Action', 'Reaction'), 'reaction.png'),
|
||||
CardType(('Action', 'Victory'), 'action-victory.png',12),
|
||||
CardType(('Action', 'Duration'), 'duration.png',5),
|
||||
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',1),
|
||||
CardType(('Action', 'Ruins'), 'ruins.png',10, 0, 1),
|
||||
CardType(('Action', 'Shelter'), 'action-shelter.png',6),
|
||||
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',5),
|
||||
CardType(('Action', 'Reserve'), 'reserve.png',5),
|
||||
CardType(('Action', 'Reserve', 'Victory'), 'reserve-victory.png',12),
|
||||
CardType(('Action', 'Traveller'), 'action.png',5),
|
||||
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',1),
|
||||
CardType(('Event',), 'event.png',1),
|
||||
CardType(('Prize',), 'action.png', 1),
|
||||
CardType(('Event',), 'event.png', 1),
|
||||
CardType(('Reaction',), 'reaction.png'),
|
||||
CardType(('Reaction', 'Shelter'), 'reaction-shelter.png',6),
|
||||
CardType(('Treasure',), 'treasure.png',10, 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',12),
|
||||
CardType(('Treasure', 'Prize'), 'treasure.png',1, 3, 0),
|
||||
CardType(('Treasure', 'Reaction'), 'treasure-reaction.png',10, 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',12),
|
||||
CardType(('Victory', 'Reaction'), 'victory-reaction.png',12, 0, 1),
|
||||
CardType(('Victory', 'Shelter'), 'victory-shelter.png',6),
|
||||
CardType(('Victory', 'Castle'), 'victory.png',12),
|
||||
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(('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',1),
|
||||
CardType(('Landmarks',), 'landmark.png',0)
|
||||
CardType(('Landmark',), 'landmark.png', 1),
|
||||
CardType(('Landmarks',), 'landmark.png', 0)
|
||||
]
|
||||
|
||||
cardTypes = dict(((c.getTypeNames(), c) for c in cardTypes))
|
||||
+296
-193
@@ -20,7 +20,6 @@ def split(l, n):
|
||||
|
||||
|
||||
class DividerDrawer(object):
|
||||
|
||||
def __init__(self):
|
||||
self.odd = True
|
||||
self.canvas = None
|
||||
@@ -29,91 +28,91 @@ class DividerDrawer(object):
|
||||
try:
|
||||
dirn = os.path.join(self.options.data_path, 'fonts')
|
||||
self.fontNameRegular = 'MinionPro-Regular'
|
||||
pdfmetrics.registerFont(
|
||||
TTFont(self.fontNameRegular, os.path.join(dirn, 'MinionPro-Regular.ttf')))
|
||||
pdfmetrics.registerFont(TTFont(self.fontNameRegular, os.path.join(
|
||||
dirn, 'MinionPro-Regular.ttf')))
|
||||
self.fontNameBold = 'MinionPro-Bold'
|
||||
pdfmetrics.registerFont(
|
||||
TTFont(self.fontNameBold, os.path.join(dirn, 'MinionPro-Bold.ttf')))
|
||||
pdfmetrics.registerFont(TTFont(self.fontNameBold, os.path.join(
|
||||
dirn, 'MinionPro-Bold.ttf')))
|
||||
self.fontNameOblique = 'MinionPro-Oblique'
|
||||
pdfmetrics.registerFont(
|
||||
TTFont(self.fontNameOblique, os.path.join(dirn, 'MinionPro-It.ttf')))
|
||||
pdfmetrics.registerFont(TTFont(self.fontNameOblique, os.path.join(
|
||||
dirn, 'MinionPro-It.ttf')))
|
||||
except:
|
||||
print >>sys.stderr, "Warning, Minion Pro Font ttf file not found! Falling back on Times"
|
||||
print >> sys.stderr, "Warning, Minion Pro Font ttf file not found! Falling back on Times"
|
||||
self.fontNameRegular = 'Times-Roman'
|
||||
self.fontNameBold = 'Times-Bold'
|
||||
self.fontNameOblique = 'Times-Oblique'
|
||||
|
||||
def getOutline(self, card, isExpansionDivider = False):
|
||||
|
||||
dividerWidth = self.options.dividerWidth
|
||||
dividerHeight = self.options.dividerHeight
|
||||
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
|
||||
|
||||
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 = []
|
||||
result = []
|
||||
started = False
|
||||
for x,y in delta:
|
||||
for x, y in delta:
|
||||
if not started:
|
||||
last_x = x
|
||||
last_y = y
|
||||
started = True
|
||||
last_x = x
|
||||
last_y = y
|
||||
started = True
|
||||
else:
|
||||
result.append( (last_x , last_y, last_x + x, last_y + y) )
|
||||
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
|
||||
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)
|
||||
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
|
||||
@@ -123,10 +122,10 @@ class DividerDrawer(object):
|
||||
# | |
|
||||
# AA+-------+BB N+-------+O
|
||||
# | |
|
||||
# + +CC. . . . . . . . . . . . . . . . . .M+ +
|
||||
# + +CC. . . . . . . . . . . . . . . . . .M+ +
|
||||
# | |
|
||||
# + +DD. . . . . . . . . . . . . . . . . .L+ +
|
||||
# | |
|
||||
# | |
|
||||
# FF+-------+EE K+-------+J
|
||||
# | |
|
||||
# | Reverse Side |
|
||||
@@ -135,89 +134,105 @@ class DividerDrawer(object):
|
||||
# A+-------+B +I
|
||||
# | |
|
||||
# + C+---------------------+D G+----+H
|
||||
# | |
|
||||
# + E+-------------------+F +
|
||||
# | |
|
||||
# + 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
|
||||
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.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):
|
||||
|
||||
def draw(self, cards, options):
|
||||
self.options = options
|
||||
|
||||
self.registerFonts()
|
||||
self.canvas = canvas.Canvas(
|
||||
fname, pagesize=(options.paperwidth, options.paperheight))
|
||||
options.outfile,
|
||||
pagesize=(options.paperwidth, options.paperheight))
|
||||
self.drawDividers(cards)
|
||||
self.canvas.save()
|
||||
|
||||
def add_inline_images(self, text, fontsize):
|
||||
path = os.path.join(self.options.data_path, 'images')
|
||||
replace = '<img src='"'%s/coin_small_\\1.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/coin_small_\\1.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('(\d+)\s(c|C)oin(s)?', replace, text)
|
||||
replace = '<img src='"'%s/coin_small_question.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/coin_small_question.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('\?\s(c|C)oin(s)?', replace, text)
|
||||
replace = '<img src='"'%s/coin_small_empty.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/coin_small_empty.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('empty\s(c|C)oin(s)?', replace, text)
|
||||
replace = '<img src='"'%s/victory_emblem.png'"' width=%d height='"'120%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.5)
|
||||
replace = '<img src=' "'%s/victory_emblem.png'" ' width=%d height=' "'120%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.5)
|
||||
text = re.sub('\<VP\>', replace, text)
|
||||
replace = '<img src='"'%s/debt_\\1.png'"' width=%d height='"'105%%'"' valign='"'middle'"'/> ' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/debt_\\1.png'" ' width=%d height=' "'105%%'" ' valign=' "'middle'" '/> '
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('(\d+)\sDebt', replace, text)
|
||||
replace = '<img src='"'%s/debt.png'"' width=%d height='"'105%%'"' valign='"'middle'"'/> ' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/debt.png'" ' width=%d height=' "'105%%'" ' valign=' "'middle'" '/> '
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('Debt', replace, text)
|
||||
replace = '<img src='"'%s/potion_small.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/potion_small.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('Potion', replace, text)
|
||||
return text
|
||||
|
||||
def drawOutline(self, card, 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)
|
||||
@@ -233,7 +248,7 @@ class DividerDrawer(object):
|
||||
self.getOutline(card, isExpansionDivider=True)
|
||||
else:
|
||||
self.getOutline(card)
|
||||
|
||||
|
||||
elif self.options.cropmarks and not self.options.wrapper:
|
||||
cmw = 0.5 * cm
|
||||
|
||||
@@ -245,11 +260,11 @@ class DividerDrawer(object):
|
||||
self.canvas.scale(-1, 1)
|
||||
if cropmarksleft or cropmarksright:
|
||||
self.canvas.line(-2 * cmw, 0, -cmw, 0)
|
||||
self.canvas.line(-2 * cmw,
|
||||
self.options.dividerBaseHeight, -cmw, self.options.dividerBaseHeight)
|
||||
self.canvas.line(-2 * cmw, self.options.dividerBaseHeight,
|
||||
-cmw, self.options.dividerBaseHeight)
|
||||
if y > 0:
|
||||
self.canvas.line(-2 * cmw,
|
||||
self.options.dividerHeight, -cmw, self.options.dividerHeight)
|
||||
self.canvas.line(-2 * cmw, self.options.dividerHeight,
|
||||
-cmw, self.options.dividerHeight)
|
||||
if mirror:
|
||||
self.canvas.restoreState()
|
||||
|
||||
@@ -275,33 +290,42 @@ class DividerDrawer(object):
|
||||
self.canvas.line(leftLine, -2 * cmw, leftLine, -cmw)
|
||||
if y == self.options.numDividersVertical - 1:
|
||||
self.canvas.line(rightLine, self.options.dividerHeight + cmw,
|
||||
rightLine, self.options.dividerHeight + 2 * cmw)
|
||||
rightLine,
|
||||
self.options.dividerHeight + 2 * cmw)
|
||||
self.canvas.line(middleLine, self.options.dividerHeight + cmw,
|
||||
middleLine, self.options.dividerHeight + 2 * cmw)
|
||||
middleLine,
|
||||
self.options.dividerHeight + 2 * cmw)
|
||||
if cropmarksleft:
|
||||
self.canvas.line(leftLine, self.options.dividerHeight + cmw,
|
||||
leftLine, self.options.dividerHeight + 2 * cmw)
|
||||
self.canvas.line(
|
||||
leftLine, self.options.dividerHeight + cmw, 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)
|
||||
|
||||
# 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.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
|
||||
@@ -312,27 +336,51 @@ class DividerDrawer(object):
|
||||
potSize = 11
|
||||
|
||||
if card.debtcost:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'debt.png'),
|
||||
x, coinHeight, 16, 16, preserveAspectRatio=True,
|
||||
mask=[255, 255, 255, 255, 255, 255])
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', 'debt.png'),
|
||||
x,
|
||||
coinHeight,
|
||||
16,
|
||||
16,
|
||||
preserveAspectRatio=True,
|
||||
mask=[255, 255, 255, 255, 255, 255])
|
||||
cost = str(card.debtcost)
|
||||
if card.cost != "" and int(card.cost) > 0:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'coin_small.png'), x + 17,
|
||||
coinHeight, 16, 16, preserveAspectRatio=True,
|
||||
mask=[255, 255, 255, 255, 255, 255])
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images',
|
||||
'coin_small.png'),
|
||||
x + 17,
|
||||
coinHeight,
|
||||
16,
|
||||
16,
|
||||
preserveAspectRatio=True,
|
||||
mask=[255, 255, 255, 255, 255, 255])
|
||||
self.canvas.setFont(self.fontNameBold, 12)
|
||||
self.canvas.drawCentredString(x + 8 + 17, costHeight, str(card.cost))
|
||||
self.canvas.drawCentredString(x + 8 + 17, costHeight,
|
||||
str(card.cost))
|
||||
self.canvas.setFillColorRGB(0, 0, 0)
|
||||
width += 16
|
||||
self.canvas.setFillColorRGB(1, 1, 1)
|
||||
else:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'coin_small.png'),
|
||||
x, coinHeight, 16, 16, preserveAspectRatio=True, mask='auto')
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images',
|
||||
'coin_small.png'),
|
||||
x,
|
||||
coinHeight,
|
||||
16,
|
||||
16,
|
||||
preserveAspectRatio=True,
|
||||
mask='auto')
|
||||
cost = str(card.cost)
|
||||
if card.potcost:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'potion.png'), x + 17,
|
||||
potHeight, potSize, potSize, preserveAspectRatio=True,
|
||||
mask=[255, 255, 255, 255, 255, 255])
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', 'potion.png'),
|
||||
x + 17,
|
||||
potHeight,
|
||||
potSize,
|
||||
potSize,
|
||||
preserveAspectRatio=True,
|
||||
mask=[255, 255, 255, 255, 255, 255])
|
||||
width += potSize
|
||||
|
||||
self.canvas.setFont(self.fontNameBold, 12)
|
||||
@@ -343,17 +391,24 @@ class DividerDrawer(object):
|
||||
def drawSetIcon(self, setImage, x, y):
|
||||
# set image
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', setImage), x, y, 14, 12, mask='auto')
|
||||
os.path.join(self.options.data_path, 'images', setImage),
|
||||
x,
|
||||
y,
|
||||
14,
|
||||
12,
|
||||
mask='auto')
|
||||
|
||||
def nameWidth(self, name, fontSize):
|
||||
w = 0
|
||||
name_parts = name.split()
|
||||
for i, part in enumerate(name_parts):
|
||||
if i != 0:
|
||||
w += pdfmetrics.stringWidth(' ', self.fontNameRegular, fontSize)
|
||||
w += pdfmetrics.stringWidth(part[0], self.fontNameRegular, fontSize)
|
||||
w += pdfmetrics.stringWidth(part[1:],
|
||||
self.fontNameRegular, fontSize - 2)
|
||||
w += pdfmetrics.stringWidth(' ', self.fontNameRegular,
|
||||
fontSize)
|
||||
w += pdfmetrics.stringWidth(part[0], self.fontNameRegular,
|
||||
fontSize)
|
||||
w += pdfmetrics.stringWidth(part[1:], self.fontNameRegular,
|
||||
fontSize - 2)
|
||||
return w
|
||||
|
||||
def drawTab(self, card, rightSide, wrapper="no"):
|
||||
@@ -363,29 +418,30 @@ class DividerDrawer(object):
|
||||
translate_x = self.options.dividerWidth / 2 - self.options.labelWidth / 2
|
||||
translate_y = self.options.dividerHeight - self.options.labelHeight
|
||||
elif not rightSide:
|
||||
translate_x = self.options.dividerWidth - self.options.labelWidth
|
||||
translate_x = self.options.dividerWidth - self.options.labelWidth
|
||||
translate_y = self.options.dividerHeight - self.options.labelHeight
|
||||
else:
|
||||
translate_x = 0
|
||||
translate_y = self.options.dividerHeight - self.options.labelHeight
|
||||
|
||||
if wrapper == "back":
|
||||
translate_y = self.options.labelHeight
|
||||
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
|
||||
translate_x = self.options.dividerWidth
|
||||
else:
|
||||
translate_x = self.options.labelWidth
|
||||
|
||||
translate_x = self.options.labelWidth
|
||||
|
||||
if wrapper == "front":
|
||||
translate_y = translate_y + self.options.dividerHeight + 2.0 * card.getStackHeight(self.options.thickness)
|
||||
|
||||
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
|
||||
@@ -397,17 +453,24 @@ class DividerDrawer(object):
|
||||
# draw banner
|
||||
img = card.getType().getNoCoinTabImageFile()
|
||||
if not self.options.no_tab_artwork and img:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', img), 1, 0,
|
||||
self.options.labelWidth -
|
||||
2, self.options.labelHeight - 1,
|
||||
preserveAspectRatio=False, anchor='n', mask='auto')
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', img),
|
||||
1,
|
||||
0,
|
||||
self.options.labelWidth - 2,
|
||||
self.options.labelHeight - 1,
|
||||
preserveAspectRatio=False,
|
||||
anchor='n',
|
||||
mask='auto')
|
||||
|
||||
# draw cost
|
||||
if not card.isExpansion() and not card.isBlank() and not card.isLandmark() and not card.isType('Trash'):
|
||||
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,
|
||||
card.getType().getTabCostHeightOffset())
|
||||
textInset += self.drawCost(
|
||||
card, textInset, textHeight,
|
||||
card.getType().getTabCostHeightOffset())
|
||||
else:
|
||||
textInset = 6
|
||||
else:
|
||||
@@ -424,7 +487,8 @@ class DividerDrawer(object):
|
||||
if setText is None:
|
||||
setText = ""
|
||||
|
||||
self.canvas.drawCentredString(self.options.labelWidth - 10, textHeight + 2, setText)
|
||||
self.canvas.drawCentredString(self.options.labelWidth - 10,
|
||||
textHeight + 2, setText)
|
||||
textInsetRight = 15
|
||||
else:
|
||||
setImage = card.setImage()
|
||||
@@ -469,13 +533,16 @@ class DividerDrawer(object):
|
||||
h -= h / 2
|
||||
|
||||
words = line.split()
|
||||
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"))
|
||||
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
|
||||
w = self.options.labelWidth / 2 - self.nameWidth(
|
||||
line, fontSize) / 2
|
||||
else:
|
||||
w = textInset
|
||||
|
||||
@@ -483,7 +550,9 @@ class DividerDrawer(object):
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
if text != ' ':
|
||||
self.canvas.drawString(w, h, text)
|
||||
return pdfmetrics.stringWidth(text, self.fontNameRegular, fontSize)
|
||||
return pdfmetrics.stringWidth(text, self.fontNameRegular,
|
||||
fontSize)
|
||||
|
||||
for i, word in enumerate(words):
|
||||
if i != 0:
|
||||
w += drawWordPiece(' ', fontSize)
|
||||
@@ -501,55 +570,65 @@ class DividerDrawer(object):
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
if text != ' ':
|
||||
self.canvas.drawRightString(w, h, text)
|
||||
return -pdfmetrics.stringWidth(text, self.fontNameRegular, fontSize)
|
||||
return -pdfmetrics.stringWidth(text, self.fontNameRegular,
|
||||
fontSize)
|
||||
|
||||
for i, word in enumerate(words):
|
||||
w += drawWordPiece(word[1:], fontSize - 2)
|
||||
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.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
|
||||
textHeight = card.getStackHeight(
|
||||
self.options.thickness) / 2 - textHeight / 2
|
||||
h = textHeight
|
||||
words = name.split()
|
||||
w = self.options.labelWidth / 2 - self.nameWidth(name, fontSize) / 2
|
||||
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)
|
||||
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", 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.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))
|
||||
|
||||
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 - usedHeight - 0.5 * cm)
|
||||
@@ -563,11 +642,12 @@ class DividerDrawer(object):
|
||||
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)
|
||||
self.drawCardCount(card, Image_x,
|
||||
totalHeight - usedHeight - 0.5 * cm)
|
||||
drewTopIcon = True
|
||||
|
||||
|
||||
if drewTopIcon:
|
||||
usedHeight += 15
|
||||
|
||||
@@ -578,7 +658,7 @@ class DividerDrawer(object):
|
||||
elif divider_text == "rules":
|
||||
# Add the extra rules text to the divider
|
||||
if card.extra:
|
||||
descriptions = (card.extra,)
|
||||
descriptions = (card.extra, )
|
||||
else:
|
||||
# Asked for rules and they don't exist, so don't print anything
|
||||
return
|
||||
@@ -622,10 +702,16 @@ 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", divider_text2="rules"):
|
||||
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
|
||||
@@ -640,16 +726,19 @@ class DividerDrawer(object):
|
||||
|
||||
# apply the transforms to get us to the corner of the current card
|
||||
self.canvas.resetTransforms()
|
||||
self.canvas.translate(self.options.horizontalMargin, self.options.verticalMargin)
|
||||
self.canvas.translate(self.options.horizontalMargin,
|
||||
self.options.verticalMargin)
|
||||
if isBack:
|
||||
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.dividerWidthReserved,
|
||||
y * self.options.dividerHeightReserved)
|
||||
|
||||
# actual drawing
|
||||
if not self.options.tabs_only:
|
||||
self.drawOutline(card, x, y, rightSide, isBack, card.getType().getTypeNames() == ('Expansion',))
|
||||
|
||||
self.drawOutline(card, x, y, rightSide, isBack,
|
||||
card.getType().getTypeNames() == ('Expansion', ))
|
||||
|
||||
if self.options.wrapper:
|
||||
wrap = "front"
|
||||
else:
|
||||
@@ -659,7 +748,7 @@ class DividerDrawer(object):
|
||||
self.drawText(card, divider_text, wrapper=wrap)
|
||||
if self.options.wrapper:
|
||||
self.drawTab(card, rightSide, wrapper="back")
|
||||
self.drawText(card, divider_text2, wrapper="back")
|
||||
self.drawText(card, divider_text2, wrapper="back")
|
||||
|
||||
def drawSetNames(self, pageCards):
|
||||
# print sets for this page
|
||||
@@ -671,7 +760,8 @@ class DividerDrawer(object):
|
||||
minFontsize = 6
|
||||
fontname = self.fontNameRegular
|
||||
font = pdfmetrics.getFont(fontname)
|
||||
fontHeightRelative = (font.face.ascent + abs(font.face.descent)) / 1000.0
|
||||
fontHeightRelative = (
|
||||
font.face.ascent + abs(font.face.descent)) / 1000.0
|
||||
|
||||
canFit = False
|
||||
|
||||
@@ -685,8 +775,8 @@ class DividerDrawer(object):
|
||||
'width': self.options.paperheight}]
|
||||
|
||||
for layout in layouts:
|
||||
availableMargin = layout[
|
||||
'totalMarginHeight'] - layout['minMarginHeight']
|
||||
availableMargin = layout['totalMarginHeight'] - layout[
|
||||
'minMarginHeight']
|
||||
fontsize = availableMargin / fontHeightRelative
|
||||
fontsize = min(maxFontsize, fontsize)
|
||||
if fontsize >= minFontsize:
|
||||
@@ -699,11 +789,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()
|
||||
@@ -725,7 +815,8 @@ class DividerDrawer(object):
|
||||
|
||||
def drawDividers(self, cards):
|
||||
# split into pages
|
||||
cards = split(cards, self.options.numDividersVertical * self.options.numDividersHorizontal)
|
||||
cards = split(cards, self.options.numDividersVertical *
|
||||
self.options.numDividersHorizontal)
|
||||
|
||||
# Starting with tabs on the left or the right?
|
||||
if self.options.tab_side in ["right-alternate", "right"]:
|
||||
@@ -738,14 +829,21 @@ class DividerDrawer(object):
|
||||
# remember whether we start with odd or even divider for tab
|
||||
# location
|
||||
pageStartOdd = self.odd
|
||||
if not self.options.no_page_footer and (not self.options.tabs_only and self.options.order != "global"):
|
||||
if not self.options.no_page_footer and (
|
||||
not self.options.tabs_only and
|
||||
self.options.order != "global"):
|
||||
self.drawSetNames(pageCards)
|
||||
for i, card in enumerate(pageCards):
|
||||
# print card
|
||||
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, divider_text2=self.options.text_back)
|
||||
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()
|
||||
@@ -760,10 +858,15 @@ class DividerDrawer(object):
|
||||
self.odd = pageStartOdd
|
||||
for i, card in enumerate(pageCards):
|
||||
# print card
|
||||
x = (self.options.numDividersHorizontal - 1 - i) % self.options.numDividersHorizontal
|
||||
x = (self.options.numDividersHorizontal - 1 - i
|
||||
) % self.options.numDividersHorizontal
|
||||
y = i / self.options.numDividersHorizontal
|
||||
self.canvas.saveState()
|
||||
self.drawDivider(card, x, self.options.numDividersVertical - 1 - y, isBack=True, divider_text=self.options.text_back)
|
||||
self.drawDivider(card,
|
||||
x,
|
||||
self.options.numDividersVertical - 1 - y,
|
||||
isBack=True,
|
||||
divider_text=self.options.text_back)
|
||||
self.canvas.restoreState()
|
||||
self.odd = not self.odd
|
||||
self.canvas.showPage()
|
||||
|
||||
Reference in new issue
Block a user