Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions android/CHANGELOG.ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
`kr.devslab:dds-android-tokens`, `kr.devslab:dds-compose`, 그리고 0.7.0부터 `kr.devslab:dds-compose-testing`은 한 버전을 쓰고, 웹 패키지와는
버전이 따로다(D-048). 릴리스는 `android-v<버전>` 태그로 낸다.

## 0.12.1 — 2026-11-19

**고침**

- **`keepWords()`가 한국어 단어만 묶는다.** 지금까지는 글자 종류와 상관없이 모든 단어의 모든 글자 사이에 결합 문자를
넣었다. 힌디어(와 태국어)에서는 모음 기호가 자음과 떨어져 점선 동그라미 위에 그려졌고, 띄어쓰기가 없는 일본어·
중국어에서는 줄을 끊을 자리가 없어져 긴 문구가 넘치는 자리에서 아무 데서나 잘렸다(送/る). 이제 한글이 든 단어만
묶고, 결합 문자는 온전한 글자 사이에만 넣는다(글자와 그 결합 기호는 떨어지지 않는다). 한국어 줄바꿈은 그대로다.
줄바꿈되는 글을 그리는 DDS 부품이 모두 이 함수를 쓰므로 버튼·탭·입력칸·배너가 함께 고쳐진다.

## 0.12.0 — 2026-11-19

**새 기능**
Expand Down
11 changes: 11 additions & 0 deletions android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
`kr.devslab:dds-android-tokens`, `kr.devslab:dds-compose` and (from 0.7.0) `kr.devslab:dds-compose-testing` share one version,
separate from the web packages (D-048). Releases are cut by an `android-v<version>` tag.

## 0.12.1 — 2026-11-19

**Fixed**

- **`keepWords()` joins Korean words only.** It put a word joiner between every two characters of every word, whatever
the script. In Hindi (and Thai) that drew each vowel sign apart from its consonant, on a dotted circle; in Japanese
and Chinese, which have no spaces, it left a line no break point, so a long label broke wherever it ran out of room
(送/る). Now only a word that contains Hangul is joined, and the joiner goes between whole characters (a letter keeps
its combining marks). Korean text wraps as before. Every DDS component that draws wrapping text uses this function,
so buttons, tabs, fields and banners are fixed with it.

## 0.12.0 — 2026-11-19

**New**
Expand Down
4 changes: 2 additions & 2 deletions android/README.ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ dependencies {

```kotlin
dependencies {
implementation("kr.devslab:dds-compose:0.12.0")
androidTestImplementation("kr.devslab:dds-compose-testing:0.12.0")
implementation("kr.devslab:dds-compose:0.12.1")
androidTestImplementation("kr.devslab:dds-compose-testing:0.12.1")
}
```

Expand Down
4 changes: 2 additions & 2 deletions android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ dependencies {

```kotlin
dependencies {
implementation("kr.devslab:dds-compose:0.12.0")
androidTestImplementation("kr.devslab:dds-compose-testing:0.12.0")
implementation("kr.devslab:dds-compose:0.12.1")
androidTestImplementation("kr.devslab:dds-compose-testing:0.12.1")
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.devslab.dds.compose.theme

import java.text.BreakIterator
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.semantics.text
import androidx.compose.ui.semantics.clearAndSetSemantics
Expand Down Expand Up @@ -134,30 +135,55 @@ internal val LocalDdsTypography = staticCompositionLocalOf<DdsTypography> {

/**
* Android breaks Korean between any two syllables. This joins the characters
* of each word so a line breaks only at spaces — the same result as the web's
* `word-break: keep-all`.
* of each Korean word so a line breaks only at spaces — the same result as the
* web's `word-break: keep-all`.
*
* Use it for short Korean UI text (titles, buttons, notices). Do not use it
* on a string with no spaces that may be longer than the line: it could then
* Only a word that contains Hangul is joined, and the joiner goes between
* whole characters as a reader sees them (a letter keeps its combining marks):
* - Devanagari, Thai and Arabic shape a letter together with its neighbours,
* and a joiner between them draws the marks apart on dotted circles;
* - Japanese and Chinese have no spaces, so joining every character would
* leave the line no break point at all;
* - a Latin or Cyrillic word already breaks only at its spaces.
*
* Use it for short UI text (titles, buttons, notices). Do not use it on a
* Korean string with no spaces that may be longer than the line: it could then
* not wrap at all.
*/
public fun String.keepWords(): String {
if (isEmpty()) return this
if (isEmpty() || none(::isHangul)) return this
val out = StringBuilder(length * 2)
var i = 0
while (i < length) {
// Step by code point, so an emoji or a rare ideograph (a surrogate pair) is never split.
val codePoint = codePointAt(i)
val next = i + Character.charCount(codePoint)
out.appendCodePoint(codePoint)
if (next < length && !Character.isWhitespace(codePoint) && !Character.isWhitespace(codePointAt(next))) {
out.append(WORD_JOINER)
}
i = next
var wordStart = 0
while (wordStart < length) {
var wordEnd = wordStart
while (wordEnd < length && !Character.isWhitespace(this[wordEnd])) wordEnd++
if (wordEnd > wordStart) out.appendWord(substring(wordStart, wordEnd))
while (wordEnd < length && Character.isWhitespace(this[wordEnd])) out.append(this[wordEnd++])
wordStart = wordEnd
}
return out.toString()
}

private fun isHangul(char: Char): Boolean = Character.UnicodeScript.of(char.code) == Character.UnicodeScript.HANGUL

/** [word] (no whitespace in it), with a joiner between its characters when it is a Korean word. */
private fun StringBuilder.appendWord(word: String) {
if (word.none(::isHangul)) {
append(word)
return
}
// By grapheme cluster, so a surrogate pair, a letter with its combining marks and decomposed Hangul stay whole.
val clusters = BreakIterator.getCharacterInstance().apply { setText(word) }
var start = clusters.first()
var end = clusters.next()
while (end != BreakIterator.DONE) {
if (start > 0) append(WORD_JOINER)
append(word, start, end)
start = end
end = clusters.next()
}
}

/** U+2060 WORD JOINER: invisible, zero width, forbids a line break on either side. */
private const val WORD_JOINER: Char = 0x2060.toChar()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,32 @@ class BrandTest {
val emoji = String(Character.toChars(0x1F600))
assertEquals("확$j$emoji", "확$emoji".keepWords())
}

@Test
fun keepWordsJoinsLatinDigitsAndPunctuationToTheKoreanWordTheyBelongTo() {
val j = 0x2060.toChar()
assertEquals("Q${j}R${j}로 보${j}내${j}기", "QR로 보내기".keepWords())
assertEquals("5${j}명${j}까${j}지", "5명까지".keepWords())
assertEquals("괜${j}찮${j}아${j}.", "괜찮아.".keepWords())
}

@Test
fun keepWordsLeavesTextWithoutHangulAsItIs() {
// Devanagari, Thai and Arabic shape a letter with the marks and letters next to it: a joiner between them
// draws the marks apart on dotted circles. Japanese and Chinese have no spaces, so joining every character
// would leave no break point at all. Latin words already break only at spaces.
for (text in listOf("मेरे कार्ड", "นามบัตรของฉัน", "بطاقاتي", "連絡先ファイルを送る (Quick Share)", "收到的名片", "My cards", "Мои визитки")) {
assertEquals(text, text.keepWords())
}
}

@Test
fun keepWordsNeverSeparatesALetterFromItsCombiningMark() {
val j = 0x2060.toChar()
// Decomposed Hangul (conjoining jamo) and a combining accent stay with their base.
val decomposed = java.text.Normalizer.normalize("한글", java.text.Normalizer.Form.NFD)
val parts = java.text.Normalizer.normalize("한", java.text.Normalizer.Form.NFD) to java.text.Normalizer.normalize("글", java.text.Normalizer.Form.NFD)
assertEquals(parts.first + j + parts.second, decomposed.keepWords())
assertEquals("카${j}페${j}é", "카페é".keepWords())
}
}
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ kotlin.code.style=official
# Android releases are versioned apart from the web packages (docs/decisions.md D-048).
# The release workflow overrides VERSION_NAME from the android-v* tag.
GROUP=kr.devslab
VERSION_NAME=0.12.0
VERSION_NAME=0.12.1