Skip to content

Commit 71fb255

Browse files
committed
Comment out _get_character_percentage_dict function
1 parent 9f58cf0 commit 71fb255

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

anybadge.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -468,44 +468,48 @@ def _get_approx_string_width(text, font_width, fixed_width=False):
468468

469469
return int(size)
470470

471-
472-
def _get_character_percentage_dict(font_path, font_size):
473-
"""Get the dictionary used to estimate variable width font text lengths.
474-
475-
Args:
476-
font_path(str): Path to valid font file.
477-
font_size(int): Font size to use.
478-
479-
Returns: dict
480-
481-
This function can be used to calculate the dictionary used in the
482-
``get_approx_string_width`` function.
483-
484-
Examples:
485-
>>> _get_character_percentage_dict('/Library/Fonts/Verdana.ttf', 9) # doctest: +ELLIPSIS
486-
{"lij|' ": 40, '![]fI.,:;/\\\\t': 50, '`-(){}r"': 60, '*^zcsJkvxy': 70, ...
487-
"""
488-
from PIL import ImageFont
489-
490-
# List of groups in size order, smallest to largest
491-
char_width_groups = [
492-
"lij|' ",
493-
'![]fI.,:;/\\t',
494-
'`-(){}r"',
495-
'*^zcsJkvxy',
496-
'aebdhnopqug#$L+<>=?_~FZT' + digits,
497-
'BSPEAKVXY&UwNRCHD',
498-
'QGOMm%W@',
499-
]
500-
501-
def get_largest_in_group(group):
502-
"""Get the widest character from the group."""
503-
return max([ImageFont.truetype(font_path, font_size).getsize(c)[0] for c in group])
504-
505-
largest = char_width_groups[-1]
506-
font_width = get_largest_in_group(largest)
507-
return {group: int((get_largest_in_group(group) / font_width) * 100)
508-
for group in char_width_groups}
471+
# This is a helper function that can be used to generate alternate dictionaries
472+
# for the _get_approx_string_width function. The function is not needed for
473+
# normal operation of this package, and since it depends on the PIL package,
474+
# which is not included in the dependencies the function will remain commented out.
475+
#
476+
# def _get_character_percentage_dict(font_path, font_size):
477+
# """Get the dictionary used to estimate variable width font text lengths.
478+
#
479+
# Args:
480+
# font_path(str): Path to valid font file.
481+
# font_size(int): Font size to use.
482+
#
483+
# Returns: dict
484+
#
485+
# This function can be used to calculate the dictionary used in the
486+
# ``get_approx_string_width`` function.
487+
#
488+
# Examples:
489+
# >>> _get_character_percentage_dict('/Library/Fonts/Verdana.ttf', 9) # doctest: +ELLIPSIS
490+
# {"lij|' ": 40, '![]fI.,:;/\\\\t': 50, '`-(){}r"': 60, '*^zcsJkvxy': 70, ...
491+
# """
492+
# from PIL import ImageFont
493+
#
494+
# # List of groups in size order, smallest to largest
495+
# char_width_groups = [
496+
# "lij|' ",
497+
# '![]fI.,:;/\\t',
498+
# '`-(){}r"',
499+
# '*^zcsJkvxy',
500+
# 'aebdhnopqug#$L+<>=?_~FZT' + digits,
501+
# 'BSPEAKVXY&UwNRCHD',
502+
# 'QGOMm%W@',
503+
# ]
504+
#
505+
# def get_largest_in_group(group):
506+
# """Get the widest character from the group."""
507+
# return max([ImageFont.truetype(font_path, font_size).getsize(c)[0] for c in group])
508+
#
509+
# largest = char_width_groups[-1]
510+
# font_width = get_largest_in_group(largest)
511+
# return {group: int((get_largest_in_group(group) / font_width) * 100)
512+
# for group in char_width_groups}
509513

510514

511515
def parse_args():

0 commit comments

Comments
 (0)