Make better package (#132)
* make domdiv a better behaved python package (see #131) * move code from __init__.py to main.py to make import quicker and make version work without dependencies * update languages import to use pkg_resources, fix tests * update readmes * change font lookup, font readme notes
5
.gitignore
vendored
@ -1,8 +1,9 @@
|
||||
fonts
|
||||
domdiv/fonts/*.otf
|
||||
domdiv/fonts/*.ttf
|
||||
*.pdf
|
||||
*.pyc
|
||||
generated
|
||||
dominiontabs.egg-info
|
||||
*.egg-info
|
||||
build
|
||||
dist
|
||||
*~
|
||||
|
||||
17
.project
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>domtabs</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.python.pydev.PyDevBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.python.pydev.pythonNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||
<path>/domtabs</path>
|
||||
</pydev_pathproperty>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">venv_default</pydev_property>
|
||||
</pydev_project>
|
||||
@ -1,3 +1,4 @@
|
||||
include card_db/*/*.json
|
||||
include images/*.png
|
||||
recursive-include domdiv/card_db *.json
|
||||
include domdiv/images/*.png
|
||||
include domdiv/fonts/*.ttf
|
||||
|
||||
|
||||
40
README.md
@ -4,21 +4,33 @@
|
||||
|
||||
## Introduction
|
||||
|
||||
This is a script to generate card dividers for storing cards for the game [Dominion](https://boardgamegeek.com/boardgame/36218/dominion). If you are just looking go generate some dominion dividers, there is no need to install this script as I host a [live version of this generator code](http://domtabs.sandflea.org). However, if you want to use arguments that I don't expose on that page, or change the code, or contribute to the project the full generation code (not the web interface or the fonts) is included here, and contributions are more than welcome.
|
||||
This is a script and library to generate card dividers for storing cards for the game [Dominion](https://boardgamegeek.com/boardgame/36218/dominion). If you are just looking go generate some dominion dividers, there is no need to install this script as I host a [live version of this generator code](http://domtabs.sandflea.org). However, if you want to use arguments that I don't expose on that page, or change the code, or contribute to the project the full generation code (not the web interface or the fonts) is included here, and contributions are more than welcome.
|
||||
|
||||
Again, to generate tabs go to the ***[Online Generator](http://domtabs.sandflea.org)***.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
#### Python Packages
|
||||
You need the python packages for reportlab (http://www.reportlab.com/software/opensource/rl-toolkit/download/) and PIL (http://www.pythonware.com/products/pil/) installed. You can install them manually or use the included setup.py via 'python setup.py install' (perhaps run via 'sudo' if not in a virtual env) which should install everything for you.
|
||||
|
||||
#### Fonts
|
||||
I believe I cannot distribute one font (Minion Pro) dominion\_tabs uses as they are commercially sold by Adobe. However, the font files are included with every install of the free Adobe Reader. For example, on Windows 7 they are in C:\Program Files (x86)\Adobe\Reader 9.0\Resource\Font called `MinionPro-Regular.otf`, `MinionPro-Bold.otf` and `MinionPro-It.otf`.
|
||||
|
||||
Sadly, these fonts use features of the otf format that are not support by the reportlab package. Thus, they need to first be converted to ttf (TrueType) format. I used the open source package fontforge to do the conversion. Included as 'convert.ff' is a script for fontforge to do the conversion, on Mac OS X with fontforge installed through macports you can just run `./convert.ff MinionPro-Regular.otf`, `./convert.ff MinionPro-Bold.otf` and `./convert.ff MinionPro-It.otf`. With other fontforge installations, you'll need to change the first line of convert.ff to point to your fontforge executable. I have not done this step under Windows - I imagine it may be possible with a cygwin install of fontforge or some such method. Copy these converted files to a subdirectory called `fonts` in the dominion_tabs directory.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
#### Python Packages
|
||||
You need the python packages for reportlab (http://www.reportlab.com/software/opensource/rl-toolkit/download/) and PIL (http://www.pythonware.com/products/pil/) installed. You can install them manually or use the included setup.py via 'python setup.py install' (perhaps run via 'sudo' if not in a virtual env) which should install everything for you.
|
||||
|
||||
#### Fonts
|
||||
I believe I cannot distribute one font (Minion Pro) domdiv uses as they are owned by Adobe with a License that I understand to disallow redistribution.
|
||||
|
||||
However, it appears you can download them here:
|
||||
- http://fontsgeek.com/fonts/Minion-Pro-Regular
|
||||
- http://fontsgeek.com/fonts/Minion-Pro-Italic
|
||||
- http://fontsgeek.com/fonts/Minion-Pro-Bold
|
||||
|
||||
Alternatively, the font files are included with every install of the free Adobe Reader. For example, on Windows 7 they are in C:\Program Files (x86)\Adobe\Reader 9.0\Resource\Font called `MinionPro-Regular.otf`, `MinionPro-Bold.otf` and `MinionPro-It.otf`.
|
||||
|
||||
Sadly, all these fonts use features that are not support by the reportlab package. Thus, they need to first be converted to ttf (TrueType) format. I used the open source package fontforge to do the conversion. Included as 'convert.ff' is a script for fontforge to do the conversion, on Mac OS X with fontforge installed through macports or homebrew you can just run `./convert.ff MinionPro-Regular.otf`, `./convert.ff MinionPro-Bold.otf` and `./convert.ff MinionPro-It.otf`. With other fontforge installations, you'll need to change the first line of convert.ff to point to your fontforge executable. I have not done this step under Windows - I imagine it may be possible with a cygwin install of fontforge or some such method.
|
||||
|
||||
Copy the converted `.ttf` files to the `fonts` directory in the `domdiv` package/directory, then perform the package install below.
|
||||
|
||||
## Install/Running
|
||||
Once the prerequisites exist, just run `python dominion_dividers.py <outfile>` to produce a pdf file of dominion tabs. You can use a `-h` flag to see various options, such as changing to vertical tabs.
|
||||
|
||||
Feel free to comment on boardgamegeek at <http://boardgamegeek.com/filepage/59848/horizontal-double-sided-dominion-tabs-for-all-expa> or file issues on github (<https://github.com/sumpfork/dominiontabs/issues>).
|
||||
Run `python setup.py install`. This should install the needed prerequisites and make a script called `dominion_dividers` available in your python script directory. Run `dominion_dividers <outfile>` to get a pdf of all dividers with the default options, or run `dominion_dividers --help` to see the (extensive) list of options.
|
||||
|
||||
## Using as a library
|
||||
The library will be installed as `domdiv` with the main entry point being `domdiv.main.generate(options)`. It takes a `Namespace` of options as generated by python's `argparser` module. You can either use `domdiv.main.parse_opts(cmdline_args)` to get such an object by passing in a list of command line options (like `sys.argv`), or directly create an appropriate object by assigning the correct values to its attributes, starting from an empty class or an actual argparse `Namespace` object.
|
||||
|
||||
Feel free to comment on boardgamegeek at <http://boardgamegeek.com/filepage/59848/horizontal-double-sided-dominion-tabs-for-all-expa> or file issues on github (<https://github.com/sumpfork/dominiontabs/issues>).
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
# main package
|
||||
|
||||
__version__ = '2.2'
|
||||
1044
domdiv/__init__.py
150
domdiv/draw.py
@ -2,6 +2,8 @@ import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
import pkg_resources
|
||||
|
||||
from reportlab.lib.units import cm
|
||||
from reportlab.pdfbase import pdfmetrics
|
||||
from reportlab.lib.styles import getSampleStyleSheet
|
||||
@ -25,25 +27,40 @@ class DividerDrawer(object):
|
||||
self.odd = True
|
||||
self.canvas = None
|
||||
|
||||
def registerFonts(self):
|
||||
dirn = os.path.join(self.options.data_path, 'fonts')
|
||||
regularMpath = os.path.join(dirn, 'MinionPro-Regular.ttf')
|
||||
boldMpath = os.path.join(dirn, 'MinionPro-Bold.ttf')
|
||||
obliqueMpath = os.path.join(dirn, 'MinionPro-It.ttf')
|
||||
@staticmethod
|
||||
def get_image_filepath(fname):
|
||||
return pkg_resources.resource_filename('domdiv', os.path.join('images', fname))
|
||||
|
||||
if os.path.isfile(regularMpath) and os.path.isfile(boldMpath) and os.path.isfile(obliqueMpath):
|
||||
self.fontNameRegular = 'MinionPro-Regular'
|
||||
pdfmetrics.registerFont(TTFont(self.fontNameRegular, regularMpath))
|
||||
self.fontNameBold = 'MinionPro-Bold'
|
||||
pdfmetrics.registerFont(TTFont(self.fontNameBold, boldMpath))
|
||||
self.fontNameOblique = 'MinionPro-Oblique'
|
||||
pdfmetrics.registerFont(TTFont(self.fontNameOblique, obliqueMpath))
|
||||
else:
|
||||
print >> sys.stderr, "Warning, Minion Pro Font ttf file(s) not found! Falling back on Times. Tried:"
|
||||
print >> sys.stderr, regularMpath + ' ' + boldMpath + ' & ' + obliqueMpath
|
||||
self.fontNameRegular = 'Times-Roman'
|
||||
self.fontNameBold = 'Times-Bold'
|
||||
self.fontNameOblique = 'Times-Oblique'
|
||||
def registerFonts(self):
|
||||
# the following are filenames from both an Adobe Reader install and a download from fontsgeek
|
||||
fontfilenames = ['MinionPro-Regular.ttf',
|
||||
'MinionPro-Bold.ttf',
|
||||
'MinionPro-It.ttf',
|
||||
'Minion Pro Regular.ttf',
|
||||
'Minion Pro Bold.ttf',
|
||||
'Minion Pro Italic.ttf']
|
||||
# first figure out which, if any, are present
|
||||
fontpaths = [os.path.join('fonts', fname) for fname in fontfilenames]
|
||||
fontpaths = [fpath for fpath in fontpaths if pkg_resources.resource_exists('domdiv', fpath)]
|
||||
self.font_mapping = {'Regular': [fpath for fpath in fontpaths if 'Regular' in fpath],
|
||||
'Bold': [fpath for fpath in fontpaths if 'Bold' in fpath],
|
||||
'Italic': [fpath for fpath in fontpaths if 'It' in fpath]}
|
||||
# then make sure that we have at least one for each type
|
||||
for fonttype in self.font_mapping:
|
||||
if not len(self.font_mapping[fonttype]):
|
||||
print >> sys.stderr, ("Warning, Minion Pro ttf file for {} missing from domdiv/fonts!",
|
||||
" Falling back on Times font for everything.").format(fonttype)
|
||||
self.font_mapping = {'Regular': 'Times-Roman',
|
||||
'Bold': 'Times-Bold',
|
||||
'Italic': 'Times-Oblique'}
|
||||
break
|
||||
else:
|
||||
# and finally register and tag one for each type
|
||||
ftag = 'MinionPro-{}'.format(fonttype)
|
||||
pdfmetrics.registerFont(TTFont(ftag,
|
||||
pkg_resources.resource_filename('domdiv',
|
||||
self.font_mapping[fonttype][0])))
|
||||
self.font_mapping[fonttype] = ftag
|
||||
|
||||
def wantCentreTab(self, card):
|
||||
return (card.isExpansion() and self.options.centre_expansion_dividers) or self.options.tab_side == "centre"
|
||||
@ -209,45 +226,44 @@ class DividerDrawer(object):
|
||||
|
||||
def add_inline_images(self, text, fontsize):
|
||||
# Coins
|
||||
path = os.path.join(self.options.data_path, 'images')
|
||||
replace = '<img src=' "'%s/coin_small_\\1.png'" ' width=%d height=' "'200%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 2.4)
|
||||
replace = '<img src=' "'{}'" ' width={} height=' "'200%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace.format(DividerDrawer.get_image_filepath('coin_small_1.png'), fontsize * 2.4)
|
||||
text = re.sub('(\d+)\s*\<\*COIN\*\>', replace, text)
|
||||
replace = '<img src=' "'%s/coin_small_\\1.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
replace = '<img src=' "'{}'" ' width={} height=' "'100%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace.format(DividerDrawer.get_image_filepath('coin_small_1.png'), 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'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
replace = '<img src=' "'{}'" ' width={} height=' "'100%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace.format(DividerDrawer.get_image_filepath('coin_small_question.png'), 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'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
replace = '<img src=' "'{}'" ' width={} height=' "'100%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace.format(DividerDrawer.get_image_filepath('coin_small_empty.png'), fontsize * 1.2)
|
||||
text = re.sub('empty\s(c|C)oin(s)?', replace, text)
|
||||
text = re.sub('\_\s(c|C)oin(s)?', replace, text)
|
||||
|
||||
# VP
|
||||
replace = '<img src=' "'%s/victory_emblem.png'" ' width=%d height=' "'120%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.5)
|
||||
replace = '<img src=' "'{}'" ' width={} height=' "'120%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace.format(DividerDrawer.get_image_filepath('victory_emblem.png'), fontsize * 1.5)
|
||||
text = re.sub('(?:\s+|\<)VP(?:\s+|\>|\.|$)', replace, text)
|
||||
replace = '<font size=%d>\\1</font> '
|
||||
replace += '<img src=' "'%s/victory_emblem.png'" ' width=%d height=' "'200%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (fontsize * 1.5, path, fontsize * 2.5)
|
||||
replace = '<font size={}>\\1</font> '
|
||||
replace += '<img src=' "'{}'" ' width={} height=' "'200%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace.format(fontsize * 1.5, DividerDrawer.get_image_filepath('victory_emblem.png'), fontsize * 2.5)
|
||||
text = re.sub('(\d+)\s*\<\*VP\*\>', replace, text)
|
||||
|
||||
# Debt
|
||||
replace = '<img src=' "'%s/debt_\\1.png'" ' width=%d height=' "'105%%'" ' valign=' "'middle'" '/> '
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
replace = '<img src=' "'{}'" ' width={} height=' "'105%'" ' valign=' "'middle'" '/> '
|
||||
replace = replace.format(DividerDrawer.get_image_filepath('debt_1.png'), fontsize * 1.2)
|
||||
text = re.sub('(\d+)\sDebt', replace, text)
|
||||
replace = '<img src=' "'%s/debt.png'" ' width=%d height=' "'105%%'" ' valign=' "'middle'" '/> '
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
replace = '<img src=' "{}" ' width={} height=' "'105%'" ' valign=' "'middle'" '/> '
|
||||
replace = replace.format(DividerDrawer.get_image_filepath('debt.png'), fontsize * 1.2)
|
||||
text = re.sub('Debt', replace, text)
|
||||
|
||||
# Potion
|
||||
replace = '<font size=%d>\\1</font> '
|
||||
replace += '<img src=' "'%s/potion_small.png'" ' width=%d height=' "'140%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (fontsize * 1.5, path, fontsize * 2.0)
|
||||
replace = '<font size={}>\\1</font> '
|
||||
replace += '<img src=' "'{}'" ' width={} height=' "'140%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace.format(fontsize * 1.5, DividerDrawer.get_image_filepath('potion_small.png'), fontsize * 2.0)
|
||||
text = re.sub('(\d+)\s*\<\*POTION\*\>', replace, text)
|
||||
replace = '<img src=' "'%s/potion_small.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
replace = '<img src=' "'{}'" ' width={} height=' "'100%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace.format(DividerDrawer.get_image_filepath('potion_small.png'), fontsize * 1.2)
|
||||
text = re.sub('Potion', replace, text)
|
||||
|
||||
return text.strip()
|
||||
@ -373,24 +389,24 @@ class DividerDrawer(object):
|
||||
width += 16
|
||||
x -= 16
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', 'card.png'),
|
||||
DividerDrawer.get_image_filepath('card.png'),
|
||||
x,
|
||||
countHeight,
|
||||
16,
|
||||
16,
|
||||
preserveAspectRatio=True,
|
||||
mask='auto')
|
||||
self.canvas.setFont(self.fontNameBold, 10)
|
||||
self.canvas.setFont(self.font_mapping['Bold'], 10)
|
||||
self.canvas.drawCentredString(x + 8, countHeight + 4, str(value))
|
||||
|
||||
# now draw the number of sets
|
||||
if count > 1:
|
||||
count_string = u"{}\u00d7".format(count)
|
||||
width_string = stringWidth(count_string, self.fontNameRegular, 10)
|
||||
width_string = stringWidth(count_string, self.font_mapping['Regular'], 10)
|
||||
width_string -= 1 # adjust to make it closer to image
|
||||
width += width_string
|
||||
x -= width_string
|
||||
self.canvas.setFont(self.fontNameRegular, 10)
|
||||
self.canvas.setFont(self.font_mapping['Regular'], 10)
|
||||
self.canvas.drawString(x, countHeight + 4, count_string)
|
||||
|
||||
return width + 1
|
||||
@ -409,14 +425,14 @@ class DividerDrawer(object):
|
||||
(card.potcost and int(card.cost) == 0))):
|
||||
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', 'coin_small.png'),
|
||||
DividerDrawer.get_image_filepath('coin_small.png'),
|
||||
x,
|
||||
coinHeight,
|
||||
16,
|
||||
16,
|
||||
preserveAspectRatio=True,
|
||||
mask='auto')
|
||||
self.canvas.setFont(self.fontNameBold, 12)
|
||||
self.canvas.setFont(self.font_mapping['Bold'], 12)
|
||||
self.canvas.drawCentredString(x + 8, costHeight, str(card.cost))
|
||||
self.canvas.setFillColorRGB(0, 0, 0)
|
||||
x += 17
|
||||
@ -424,7 +440,7 @@ class DividerDrawer(object):
|
||||
|
||||
if card.debtcost:
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', 'debt.png'),
|
||||
DividerDrawer.get_image_filepath('debt.png'),
|
||||
x,
|
||||
coinHeight,
|
||||
16,
|
||||
@ -432,7 +448,7 @@ class DividerDrawer(object):
|
||||
preserveAspectRatio=True,
|
||||
mask=[170, 255, 170, 255, 170, 255])
|
||||
self.canvas.setFillColorRGB(1, 1, 1)
|
||||
self.canvas.setFont(self.fontNameBold, 12)
|
||||
self.canvas.setFont(self.font_mapping['Bold'], 12)
|
||||
self.canvas.drawCentredString(x + 8, costHeight, str(card.debtcost))
|
||||
self.canvas.setFillColorRGB(0, 0, 0)
|
||||
x += 17
|
||||
@ -440,7 +456,7 @@ class DividerDrawer(object):
|
||||
|
||||
if card.potcost:
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', 'potion.png'),
|
||||
DividerDrawer.get_image_filepath('potion.png'),
|
||||
x,
|
||||
potHeight,
|
||||
potSize,
|
||||
@ -455,7 +471,7 @@ class DividerDrawer(object):
|
||||
# set image
|
||||
w = 2
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', setImage),
|
||||
DividerDrawer.get_image_filepath(setImage),
|
||||
x,
|
||||
y,
|
||||
14,
|
||||
@ -468,11 +484,11 @@ class DividerDrawer(object):
|
||||
name_parts = name.split()
|
||||
for i, part in enumerate(name_parts):
|
||||
if i != 0:
|
||||
w += pdfmetrics.stringWidth(' ', self.fontNameRegular,
|
||||
w += pdfmetrics.stringWidth(' ', self.font_mapping['Regular'],
|
||||
fontSize)
|
||||
w += pdfmetrics.stringWidth(part[0], self.fontNameRegular,
|
||||
w += pdfmetrics.stringWidth(part[0], self.font_mapping['Regular'],
|
||||
fontSize)
|
||||
w += pdfmetrics.stringWidth(part[1:], self.fontNameRegular,
|
||||
w += pdfmetrics.stringWidth(part[1:], self.font_mapping['Regular'],
|
||||
fontSize - 2)
|
||||
return w
|
||||
|
||||
@ -519,7 +535,7 @@ class DividerDrawer(object):
|
||||
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),
|
||||
DividerDrawer.get_image_filepath(img),
|
||||
1,
|
||||
0,
|
||||
self.options.labelWidth - 2,
|
||||
@ -548,7 +564,7 @@ class DividerDrawer(object):
|
||||
if self.options.use_text_set_icon:
|
||||
setImageHeight = card.getType().getTabTextHeightOffset()
|
||||
setText = card.setTextIcon()
|
||||
self.canvas.setFont(self.fontNameOblique, 8)
|
||||
self.canvas.setFont(self.font_mapping['Italic'], 8)
|
||||
if setText is None:
|
||||
setText = ""
|
||||
|
||||
@ -611,10 +627,10 @@ class DividerDrawer(object):
|
||||
w = textInset
|
||||
|
||||
def drawWordPiece(text, fontSize):
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
self.canvas.setFont(self.font_mapping['Regular'], fontSize)
|
||||
if text != ' ':
|
||||
self.canvas.drawString(w, h, text)
|
||||
return pdfmetrics.stringWidth(text, self.fontNameRegular,
|
||||
return pdfmetrics.stringWidth(text, self.font_mapping['Regular'],
|
||||
fontSize)
|
||||
|
||||
for i, word in enumerate(words):
|
||||
@ -638,10 +654,10 @@ class DividerDrawer(object):
|
||||
words.reverse()
|
||||
|
||||
def drawWordPiece(text, fontSize):
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
self.canvas.setFont(self.font_mapping['Regular'], fontSize)
|
||||
if text != ' ':
|
||||
self.canvas.drawRightString(w, h, text)
|
||||
return -pdfmetrics.stringWidth(text, self.fontNameRegular,
|
||||
return -pdfmetrics.stringWidth(text, self.font_mapping['Regular'],
|
||||
fontSize)
|
||||
|
||||
for i, word in enumerate(words):
|
||||
@ -655,7 +671,7 @@ class DividerDrawer(object):
|
||||
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)
|
||||
self.canvas.setFont(self.font_mapping['Regular'], fontSize)
|
||||
|
||||
textHeight = fontSize - 2
|
||||
textHeight = card.getStackHeight(
|
||||
@ -666,10 +682,10 @@ class DividerDrawer(object):
|
||||
fontSize) / 2
|
||||
|
||||
def drawWordPiece(text, fontSize):
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
self.canvas.setFont(self.font_mapping['Regular'], fontSize)
|
||||
if text != ' ':
|
||||
self.canvas.drawString(w, h, text)
|
||||
return pdfmetrics.stringWidth(text, self.fontNameRegular,
|
||||
return pdfmetrics.stringWidth(text, self.font_mapping['Regular'],
|
||||
fontSize)
|
||||
|
||||
for i, word in enumerate(words):
|
||||
@ -737,7 +753,7 @@ class DividerDrawer(object):
|
||||
# use all the available space, even if it is not centered on the card
|
||||
fontSize = 8
|
||||
failover = False
|
||||
width = stringWidth(card.types_name, self.fontNameRegular, fontSize)
|
||||
width = stringWidth(card.types_name, self.font_mapping['Regular'], fontSize)
|
||||
while width > textWidth:
|
||||
fontSize -= .01
|
||||
if fontSize < 6 and not failover:
|
||||
@ -746,11 +762,11 @@ class DividerDrawer(object):
|
||||
w = left_margin + (textWidth2 / 2)
|
||||
fontSize = 8
|
||||
failover = True
|
||||
width = stringWidth(card.types_name, self.fontNameRegular, fontSize)
|
||||
width = stringWidth(card.types_name, self.font_mapping['Regular'], fontSize)
|
||||
|
||||
# Print out the text in the right spot
|
||||
h = totalHeight - usedHeight - 0.5 * cm
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
self.canvas.setFont(self.font_mapping['Regular'], fontSize)
|
||||
if card.types_name != ' ':
|
||||
self.canvas.drawCentredString(w, h, card.types_name)
|
||||
drewTopIcon = True
|
||||
@ -873,7 +889,7 @@ class DividerDrawer(object):
|
||||
# calculate the text height, font size, and orientation
|
||||
maxFontsize = 12
|
||||
minFontsize = 6
|
||||
fontname = self.fontNameRegular
|
||||
fontname = self.font_mapping['Regular']
|
||||
font = pdfmetrics.getFont(fontname)
|
||||
fontHeightRelative = (
|
||||
font.face.ascent + abs(font.face.descent)) / 1000.0
|
||||
|
||||
4
domdiv/fonts/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
#### Fonts
|
||||
I believe I cannot distribute one font (Minion Pro) domdiv uses as they are commercially sold by Adobe. However, the font files are included with every install of the free Adobe Reader. For example, on Windows 7 they are in C:\Program Files (x86)\Adobe\Reader 9.0\Resource\Font called `MinionPro-Regular.otf`, `MinionPro-Bold.otf` and `MinionPro-It.otf`.
|
||||
|
||||
Sadly, these fonts use features of the otf format that are not support by the reportlab package. Thus, they need to first be converted to ttf (TrueType) format. I used the open source package fontforge to do the conversion. Included as 'convert.ff' is a script for fontforge to do the conversion, on Mac OS X with fontforge installed through macports you can just run `./convert.ff MinionPro-Regular.otf`, `./convert.ff MinionPro-Bold.otf` and `./convert.ff MinionPro-It.otf`. With other fontforge installations, you'll need to change the first line of convert.ff to point to your fontforge executable. I have not done this step under Windows - I imagine it may be possible with a cygwin install of fontforge or some such method. Copy these converted files to this subdirectory.
|
||||
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 925 KiB After Width: | Height: | Size: 925 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 9.1 KiB |
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.7 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.7 KiB |
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 65 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 218 KiB After Width: | Height: | Size: 218 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |