1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.compose.ui.text.style
18 
19 import kotlin.jvm.JvmInline
20 
21 /**
22  * Automatic hyphenation configuration.
23  *
24  * Hyphenation is a dash-like punctuation mark used to join two-words into one or separate
25  * syl-lab-les of a word.
26  *
27  * Automatic hyphenation is added between syllables at appropriate hyphenation points, following
28  * language rules.
29  *
30  * However, user can override automatic break point selection, suggesting line break opportunities
31  * (see Suggesting line break opportunities below).
32  *
33  * Suggesting line break opportunities:
34  * - <code>\u2010</code> ("hard" hyphen) Indicates a visible line break opportunity. Even if the
35  *   line is not actually broken at that point, the hyphen is still rendered.
36  * - <code>\u00AD</code> ("soft" hyphen) This character is not rendered visibly; instead, it marks a
37  *   place where the word can be broken if hyphenation is necessary.
38  *
39  * The default configuration for [Hyphens] = [Hyphens.None]
40  */
41 @JvmInline
42 value class Hyphens private constructor(internal val value: Int) {
43     companion object {
44         /**
45          * Lines will break with no hyphenation.
46          *
47          * "Hard" hyphens will still be respected. However, no automatic hyphenation will be
48          * attempted. If a word must be broken due to being longer than a line, it will break at any
49          * character and will not attempt to break at a syllable boundary.
50          * <pre>
51          * +---------+
52          * | Experim |
53          * | ental   |
54          * +---------+
55          * </pre>
56          */
57         val None = Hyphens(1)
58 
59         /**
60          * The words will be automatically broken at appropriate hyphenation points.
61          *
62          * However, suggested line break opportunities (see Suggesting line break opportunities
63          * above) will override automatic break point selection when present.
64          * <pre>
65          * +---------+
66          * | Experi- |
67          * | mental  |
68          * +---------+
69          * </pre>
70          */
71         val Auto = Hyphens(2)
72 
73         /**
74          * This represents an unset value, a usual replacement for "null" when a primitive value is
75          * desired.
76          */
77         val Unspecified = Hyphens(Int.MIN_VALUE)
78     }
79 
toStringnull80     override fun toString() =
81         when (this) {
82             None -> "Hyphens.None"
83             Auto -> "Hyphens.Auto"
84             Unspecified -> "Hyphens.Unspecified"
85             else -> "Invalid"
86         }
87 }
88