From 46d8dcb6649ccd0ccb4fb4de6ccd3f4742e87994 Mon Sep 17 00:00:00 2001 From: Gijs Date: Sat, 8 May 2021 17:47:15 +0200 Subject: [PATCH] Made single column example try to import Hyphenator from PyHyphen, but fallback if it isn't available. --- asciiWriter/examples/single_column_page.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/asciiWriter/examples/single_column_page.py b/asciiWriter/examples/single_column_page.py index 5f3df49..91ff3ff 100644 --- a/asciiWriter/examples/single_column_page.py +++ b/asciiWriter/examples/single_column_page.py @@ -2,7 +2,6 @@ from asciiWriter.text import make_column, make_multi_column from asciiWriter.utils import merge, print_lines, make_lines, translate -# from hyphen import Hyphenator import math from os.path import join, dirname @@ -15,7 +14,6 @@ height = 500 text = open(join(dirname(__file__), 'data', 'language.txt')).read() # Import a hyphenator -#h_en = Hyphenator('en_US') # Make an empty layers list layers = [] @@ -34,8 +32,12 @@ def cos_width (line_nr, _): return math.floor(half_amplitude + math.cos(line_nr / period) * half_amplitude) # Transform the text into a column -# lines, remaining = make_column(text, height=height, use_hyphenator=h_en, line_width=sin_width, line_offset=cos_width) -lines, remaining = make_column(text, height=height, line_width=sin_width, line_offset=cos_width) +try: + from hyphen import Hyphenator + h_en = Hyphenator('en_US') + lines, remaining = make_column(text, height=height, use_hyphenator=h_en, line_width=sin_width, line_offset=cos_width) +except ImportError: + lines, remaining = make_column(text, height=height, line_width=sin_width, line_offset=cos_width) # Transform the text into multiple columns # lines, remaining = make_multi_column(text, height=height-3, use_hyphenator=h_en)