How to use the pyphen.language_fallback function in pyphen

To help you get started, we’ve selected a few pyphen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kozea / WeasyPrint / weasyprint / text.py View on Github external
first_line, text, layout, resume_at, space_collapse, style)
            elif second_line:
                # Text may have been split elsewhere by Pango earlier
                resume_at = second_line.start_index
            else:
                # Second line is none
                resume_at = first_line.length + 1
    elif first_line_text:
        # We found something on the first line but we did not find a word on
        # the next line, no need to hyphenate, we can keep the current layout
        return first_line_metrics(
            first_line, text, layout, resume_at, space_collapse, style)

    # Step #4: Try to hyphenize
    hyphens = style.hyphens
    lang = style.lang and pyphen.language_fallback(style.lang)
    total, left, right = style.hyphenate_limit_chars
    hyphenated = False
    soft_hyphen = u'\u00ad'

    # Automatic hyphenation possible and next word is long enough
    if hyphens != 'none' and len(next_word) >= total:
        first_line_width, _ = get_size(first_line, style)
        space = max_width - first_line_width
        if style.hyphenate_limit_zone.unit == '%':
            limit_zone = max_width * style.hyphenate_limit_zone.value / 100.
        else:
            limit_zone = style.hyphenate_limit_zone.value

        if space > limit_zone or space < 0:
            # Manual hyphenation: check that the line ends with a soft hyphen
            # and add the missing hyphen

pyphen

Pure Python module to hyphenate text

(GPL-2.0 OR LGPL-2.0 OR MPL-1…
Latest version published 24 days ago

Package Health Score

79 / 100
Full package analysis