manetta
5 years ago
9 changed files with 72 additions and 43 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,30 +1,55 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
from .wrap_single_line import wrap_single_line |
from .wrap_single_line import wrap_single_line |
||||
|
from .utils import translate, merge |
||||
|
|
||||
def make_column(text, linewidth=50, height=200, use_hyphenator=None): |
def make_column(text, line_width=50, height=200, use_hyphenator=None, line_offset=0): |
||||
|
|
||||
lines = [] |
lines = [] |
||||
remaining = text |
remaining = text |
||||
|
|
||||
while remaining and len(lines) < height: |
while remaining and len(lines) < height: |
||||
# print('remaining:', remaining) |
|
||||
|
|
||||
if callable(linewidth): |
if callable(line_width): |
||||
width = linewidth(len(lines), height) |
width = line_width(len(lines), height) |
||||
else: |
else: |
||||
width = linewidth |
width = line_width |
||||
|
|
||||
|
if callable(line_offset): |
||||
|
offset = line_offset(len(lines), height) |
||||
|
else: |
||||
|
offset = line_offset |
||||
|
|
||||
|
line, remaining = wrap_single_line(remaining, width, use_hyphenator=use_hyphenator, replace_whitespace=False, drop_whitespace=True) |
||||
|
|
||||
|
line = list(line) |
||||
|
|
||||
|
if offset != 0: |
||||
|
line = [None for _ in range(offset)] + line |
||||
|
|
||||
line, remaining = wrap_single_line(remaining, width, use_hyphenator=use_hyphenator, replace_whitespace=False) |
|
||||
lines.append(line) |
lines.append(line) |
||||
|
|
||||
return lines, remaining |
return lines, remaining |
||||
|
|
||||
# def position_column(column_count, width, text): |
def make_multi_column(text, height=200, column_width=40, column_count=2, column_gap=5, use_hyphenator=None, space_char=None): |
||||
# def f (x, y, width, height, mark, blank): |
# todo: vertical offset? |
||||
# for i in range(column_count): |
|
||||
# lines, remaining = make_column(linewidth, height, text) |
remaining = text |
||||
|
i = 0 |
||||
|
|
||||
|
columns = [] |
||||
|
|
||||
|
while remaining and i < column_count: |
||||
|
column, remaining = make_column(remaining, line_width=column_width, height=height, use_hyphenator=use_hyphenator) |
||||
|
if i > 0: |
||||
|
offset = (column_width + column_gap) * i |
||||
|
column = translate(column, x=offset, y=0) |
||||
|
columns.append(column) |
||||
|
i += 1 |
||||
|
|
||||
|
width = (column_width + column_gap) * column_count |
||||
|
lines = merge(width, height, space_char, columns) |
||||
|
return lines, remaining |
||||
|
|
||||
# return f |
|
||||
|
|
||||
if __name__ == '__main__': |
if __name__ == '__main__': |
||||
print(make_column('Hello world!', linewidth=25, height=10)) |
print(make_column('Hello world!', line_width=25, height=10)) |
Loading…
Reference in new issue