Browse Source

Allow user specified line splitting in titles

Titles can be split at specified points with '\n' within the title
string. Titles segments which are still too long will still be split
over multiple lines in the normal way.
pull/102/head
James Dominy 11 years ago
parent
commit
e62d6d23d2
  1. 19
      pygal/util.py

19
pygal/util.py

@ -408,13 +408,14 @@ def split_title(title, width, title_fs):
if not title:
return titles
size = reverse_text_len(width, title_fs * 1.1)
title = title.strip()
while len(title) > size:
title_part = title[:size]
i = title_part.rfind(' ')
if i == -1:
i = len(title_part)
titles.append(title_part[:i])
title = title[i:].strip()
titles.append(title)
title_lines = title.split("\n")
for title_line in title_lines:
while len(title_line) > size:
title_part = title_line[:size]
i = title_part.rfind(' ')
if i == -1:
i = len(title_part)
titles.append(title_part[:i])
title_line = title_line[i:].strip()
titles.append(title_line)
return titles

Loading…
Cancel
Save