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: if not title:
return titles return titles
size = reverse_text_len(width, title_fs * 1.1) size = reverse_text_len(width, title_fs * 1.1)
title = title.strip() title_lines = title.split("\n")
while len(title) > size: for title_line in title_lines:
title_part = title[:size] while len(title_line) > size:
i = title_part.rfind(' ') title_part = title_line[:size]
if i == -1: i = title_part.rfind(' ')
i = len(title_part) if i == -1:
titles.append(title_part[:i]) i = len(title_part)
title = title[i:].strip() titles.append(title_part[:i])
titles.append(title) title_line = title_line[i:].strip()
titles.append(title_line)
return titles return titles

Loading…
Cancel
Save