Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
LineBreaker
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 breakOpportunities
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Text;
6
7/**
8 * UAX #14 line breaking via ICU's `IntlBreakIterator::createLineInstance`.
9 *
10 * Returns positions where a soft wrap may occur (in addition to mandatory
11 * line terminators). Locale-sensitive: CJK locales apply kinsoku rules
12 * forbidding certain leading / trailing punctuation, while Latin locales
13 * mainly key off whitespace and hyphenation points.
14 *
15 * The line-break engine is structural — it doesn't measure text width or
16 * decide which opportunities to actually break on. The layout consumer
17 * iterates opportunities and chooses based on the box's available width.
18 */
19final class LineBreaker
20{
21    /**
22     * Enumerate line-break opportunities for `$text`. The `$locale` is a
23     * BCP 47 language tag (e.g. `"en"`, `"ja"`, `"zh-Hans"`). Default is
24     * `"en"`. Unknown locales fall back to the ICU root locale, which
25     * applies generic UAX #14 with no language-specific tailoring.
26     */
27    public function breakOpportunities(string $text, string $locale = 'en'): LineBreakIterator
28    {
29        return new LineBreakIterator($text, $locale);
30    }
31}