rewrite inline image replacement (#135)
* rewrite inline image replacement * make a note about `python setup.py develop` * Tweak to the VP size
This commit is contained in:
parent
f47d9ee17b
commit
732a4c79bf
@ -33,4 +33,8 @@ Run `python setup.py install`. This should install the needed prerequisites and
|
|||||||
## Using as a library
|
## 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.
|
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.
|
||||||
|
|
||||||
|
## Developing
|
||||||
|
|
||||||
|
You can use `python setup.py develop` to install the `dominion_dividers` script so that it calls your checked out code, enabling you to run edited code without having to perform an install every time.
|
||||||
|
|
||||||
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>).
|
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>).
|
||||||
|
|||||||
@ -225,46 +225,52 @@ class DividerDrawer(object):
|
|||||||
self.canvas.save()
|
self.canvas.save()
|
||||||
|
|
||||||
def add_inline_images(self, text, fontsize):
|
def add_inline_images(self, text, fontsize):
|
||||||
|
def replace_image_tag(text,
|
||||||
|
fontsize,
|
||||||
|
tag_pattern,
|
||||||
|
fname_replace,
|
||||||
|
fontsize_multiplier,
|
||||||
|
height_percent,
|
||||||
|
text_fontsize_multiplier=None):
|
||||||
|
replace = '<img src="{fpath}" width={width} height="{height_percent}%" valign="middle" /> '
|
||||||
|
offset = 0
|
||||||
|
for match in re.finditer(tag_pattern, text):
|
||||||
|
tag = match.group(0)
|
||||||
|
fname = re.sub(tag_pattern, fname_replace, tag)
|
||||||
|
if text_fontsize_multiplier is not None:
|
||||||
|
font_replace = re.sub(tag_pattern,
|
||||||
|
'<font size={}>\\1</font>'.format(fontsize * text_fontsize_multiplier),
|
||||||
|
tag)
|
||||||
|
replace = font_replace + replace
|
||||||
|
replace = replace.format(fpath=DividerDrawer.get_image_filepath(fname),
|
||||||
|
width=fontsize * fontsize_multiplier,
|
||||||
|
height_percent=height_percent)
|
||||||
|
text = text[:match.start() + offset] + replace + text[match.end() + offset:]
|
||||||
|
offset += len(replace) - len(match.group(0))
|
||||||
|
return text
|
||||||
# Coins
|
# Coins
|
||||||
replace = '<img src=' "'{}'" ' width={} height=' "'200%'" ' valign=' "'middle'" '/>'
|
replace_specs = [
|
||||||
replace = replace.format(DividerDrawer.get_image_filepath('coin_small_1.png'), fontsize * 2.4)
|
# Coins
|
||||||
text = re.sub('(\d+)\s*\<\*COIN\*\>', replace, text)
|
(r'(\d+)\s\<\*COIN\*\>', 'coin_small_\\1.png', 2.4, 200),
|
||||||
replace = '<img src=' "'{}'" ' width={} height=' "'100%'" ' valign=' "'middle'" '/>'
|
(r'(\d+)\s(c|C)oin(s)?', 'coin_small_\\1.png', 1.2, 100),
|
||||||
replace = replace.format(DividerDrawer.get_image_filepath('coin_small_1.png'), fontsize * 1.2)
|
(r'\?\s(c|C)oin(s)?', 'coin_small_question.png', 1.2, 100),
|
||||||
text = re.sub('(\d+)\s(c|C)oin(s)?', replace, text)
|
(r'(empty|\_)\s(c|C)oin(s)?', 'coin_small_empty.png', 1.2, 100),
|
||||||
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=' "'{}'" ' 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
|
# VP
|
||||||
replace = '<img src=' "'{}'" ' width={} height=' "'120%'" ' valign=' "'middle'" '/>'
|
(r'(?:\s+|\<)VP(?:\s+|\>|\.|$)', 'victory_emblem.png', 1.25, 100),
|
||||||
replace = replace.format(DividerDrawer.get_image_filepath('victory_emblem.png'), fontsize * 1.5)
|
(r'(\d+)\s*\<\*VP\*\>', 'victory_emblem.png', 2, 160, 1.3),
|
||||||
text = re.sub('(?:\s+|\<)VP(?:\s+|\>|\.|$)', replace, text)
|
|
||||||
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
|
# Debt
|
||||||
replace = '<img src=' "'{}'" ' width={} height=' "'105%'" ' valign=' "'middle'" '/> '
|
(r'(\d+)\sDebt', 'debt_\\1.png', 1.2, 105),
|
||||||
replace = replace.format(DividerDrawer.get_image_filepath('debt_1.png'), fontsize * 1.2)
|
(r'Debt', 'debt.png', 1.2, 105),
|
||||||
text = re.sub('(\d+)\sDebt', replace, text)
|
|
||||||
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
|
# Potion
|
||||||
replace = '<font size={}>\\1</font> '
|
(r'(\d+)\s*\<\*POTION\*\>', 'potion_small.png', 2, 140, 1.5),
|
||||||
replace += '<img src=' "'{}'" ' width={} height=' "'140%'" ' valign=' "'middle'" '/>'
|
(r'Potion', 'potion_small.png', 1.2, 100)
|
||||||
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=' "'{}'" ' width={} height=' "'100%'" ' valign=' "'middle'" '/>'
|
for args in replace_specs:
|
||||||
replace = replace.format(DividerDrawer.get_image_filepath('potion_small.png'), fontsize * 1.2)
|
text = replace_image_tag(text, fontsize, *args)
|
||||||
text = re.sub('Potion', replace, text)
|
|
||||||
|
|
||||||
return text.strip()
|
return text.strip()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user