diff --git a/qsomap.py b/qsomap.py index 28a355a..ffe13e0 100755 --- a/qsomap.py +++ b/qsomap.py @@ -10,6 +10,7 @@ import random import argparse LABEL_MIN_FONT_SIZE = 2 +LABEL_MAX_FONT_SIZE = 40 def map_azimuthal_equidistant(lat, lon, ref_lat, ref_lon, R=1): @@ -347,23 +348,35 @@ def svg_add_country_names(doc, simplegeodata, map_radius): 'fill': v['label_color'] } + label = v['name'] + # rotate text by 90 degrees if polygon is higher than wide if h > w: - font_size = h / len(v['name']) + font_size = h / len(label) rotate = True else: - font_size = w / len(v['name']) + font_size = w / len(label) rotate = False if font_size < LABEL_MIN_FONT_SIZE: - print('.', end='', flush=True) - continue # too small + # try again with 2-letter country code + label = k + font_size = min(LABEL_MIN_FONT_SIZE*2, + (h if rotate else w) / len(label)) + + if font_size < LABEL_MIN_FONT_SIZE: + print('.', end='', flush=True) + continue # too small + else: + print('!', end='', flush=True) else: print('#', end='', flush=True) + font_size = min(LABEL_MAX_FONT_SIZE, font_size) + kwargs['font-size'] = font_size - txt = doc.text(v['name'], (center_x, center_y), + txt = doc.text(label, (center_x, center_y), **kwargs) if rotate: