# core/component/text (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/component/text/

텍스트 컴포넌트. (노드 content_size 영역 안에 정렬해 글자를 그린다)
- 한 줄, 그리고 줄바꿈 문자나 word_wrap_width 가 있으면 여러 줄로 그린다.
- 나눈 줄과 줄 폭은 글, 폰트 문자열, 줄바꿈 폭, 등록된 글꼴이 바뀔 때만 다시 센다.
- 화면 밖 거르기는 정렬, 넘침, 줄바꿈 결과로 셈한 글 사각형으로 판정한다. (원본도 Text.calculateDrawnRect 로 거른다)
- 밑줄 / 취소선은 원본처럼 글자 색 선을 긋는다. (두께 max(1, 글자 크기 / 16), 자리는 원본 computeUnderlineOffsetY / computeStrikethroughOffsetY)
- 줄바꿈 방식(set_wrap_mode): Word 는 공백 단위로 채우고, 넘치는 조각에 낱말이 여럿이면(공백 없이 쓰는 한중일, 태국어 등) 낱말 사이에서,
  그래도 넘치는 낱말은 글자 묶음 단위로 나눈다. Character 는 처음부터 글자 묶음 단위. (원본 "word" / "char", 셈의 차례가 원본과 같다)
  글자 묶음은 UAX #29(unicode-segmentation), 낱말은 ICU 사전(icu_segmenter)으로 찾는다. 원본 Intl.Segmenter 도 ICU(ICU4C)의 같은 규칙과 사전이다.
  한중일은 ICU4X 가 가장 긴 낱말부터 고르고 ICU4C 는 낱말 값의 합이 가장 작은 나누기를 골라 달라서, 데스크탑은 ICU4C 의 셈을 옮겨 같은 사전(cjdict)으로 나눈다.
- 기울임은 폰트 문자열에 italic 을 넣는다. 기울인 얼굴이 없으면 글자 캐시가 브라우저와 같은 가짜 기울임(기울기 1/4)으로 굽는다.
- 글자 방향(set_text_direction, 원본 setTextDirection): Inherit 면 그리는 때의 Graphic 방향을 따른다. 정렬 Start / End 가 그 방향으로 풀리고,
  글자 캐시가 그 문단 방향으로 양방향 정렬과 모양 짓기(아랍어 글자 잇기)를 한다.
- 글자 수만큼 보이기(set_visible_character_count, 타자기 연출)는 앞에서부터 글자 묶음 단위로 자른다. (받침, 결합 부호, 이모지 묶음이 쪼개지지 않는다)
  여러 줄이면 줄마다 남은 수만큼 그리고, 남은 수가 0 이 되면 다음 줄부터 그리지 않는다.
- 한 줄 글을 너비에 맞추기(set_fit_width): 원본처럼 넘치면 처음 크기에서 최소 비율까지 0.1 단위로 줄여 그린다. 줄인 크기는 줄을 나눌 때(update_layout) 재므로
  Graphic 이 있어야 안다. (get_fitted_font_size 는 마지막으로 잰 값, calculate_fitted_font_size 는 그 자리에서 잰다) 그리는 사각형은 줄인 글의 너비를 따른다.

예제: 글자 묶음 단위로 세고 자르기

```rust
use vanilla::{count_graphemes, slice_graphemes, split_graphemes};

let text = "e\u{301}xy";
assert_eq!(text.chars().count(), 4);
assert_eq!(count_graphemes(text), 3);
assert_eq!(split_graphemes(text), vec!["e\u{301}", "x", "y"]);
assert_eq!(slice_graphemes(text, 2), "e\u{301}x");
assert_eq!(slice_graphemes(text, 9), text);
```

## TextWrappedSize (struct) (Clone, Copy, Debug, Default, PartialEq)

줄바꿈 반영 크기. (원본 measureWrappedSize 의 { width, height, lineCount })

예제: 줄바꿈 폭으로 나눈 글의 크기

```rust
use vanilla::{Graphic, Text, TextWrappedSize};

fn measure_description(graphic: &mut Graphic) -> TextWrappedSize {
	let mut text = Text::create_with_text("A long description that wraps", 20.0);
	text.set_word_wrap_width(240.0);
	let wrapped_size = text.measure_wrapped_size(graphic);
	assert_eq!(wrapped_size.height, wrapped_size.line_count as f64 * 20.0 * text.get_line_spacing());
	wrapped_size
}
```

- `pub width: f64` (field, since 0.4.0): 가장 넓은 줄의 너비. (픽셀)
  - returns f64
- `pub height: f64` (field, since 0.4.0): 높이. (줄 수 * 글자 크기 * 줄 간격)
  - returns f64
- `pub line_count: usize` (field, since 0.4.0): 줄 수. (글이 비었으면 0)
  - returns usize

## Text (struct) (Default, Component, TypewriterTarget)

텍스트 컴포넌트. (원본 Text, 노드 content_size 영역 안에 정렬해 글자를 그린다)

예제: 노드에 글 붙이기

```rust
use vanilla::{Colors, NodeTree, Text, TextAlign, Vector2};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let label_id = node_tree.create_child(root_id, "label");
node_tree[label_id].set_content_size(Vector2::create(300.0, 60.0));
let text = node_tree.add_component(label_id, Text::create_with_text("Hello", 24.0)).expect("text");
text.set_text_color(Colors::VANILLA);
text.set_text_align(TextAlign::Left);
text.set_stroke_width(2.0);
assert_eq!(text.get_text(), "Hello");
assert_eq!(text.build_font_string(), "24px default");
```

- `pub fn new() -> Text` (constructor, since 0.3.2): 생성. (기본값은 원본과 같다: 32px, 흰색, 가운데 정렬, 가운데 기준선, 줄 간격 1.25)
  - returns Text: 빈 글의 텍스트 컴포넌트. (폰트 이름 default, Word 줄바꿈, 외곽선 없음)
- `pub fn create_with_text(text: &str, font_size: f64) -> Text` (static, since 0.3.2): 글과 크기로 생성.
  - `text` &str: 처음 글.
  - `font_size` f64: 글자 크기. (픽셀)
  - returns Text: 컴포넌트. (그 밖은 new 와 같다)
- `pub fn build_font_string(&self) -> String` (method, since 0.3.2): Canvas2D font 꼴 문자열 만들기.
  - returns String: 폰트 문자열. (예: `italic bold 32px default`, 기울임과 굵게는 켰을 때만 든다)
- `pub fn build_font_string_with_size(&self, font_size: f64) -> String` (method, since 0.4.0): 크기를 주어 Canvas2D font 꼴 문자열 만들기. (이 글자의 폰트 이름, 굵게, 기울임으로)
  - `font_size` f64: 글자 크기. (픽셀)
  - returns String: 폰트 문자열.

  예제: 굵게, 기울임, 폰트 이름이 든 문자열

  ```rust
  use vanilla::Text;
  
  let mut text = Text::new();
  text.set_bold(true);
  text.set_italic(true);
  text.set_font_family("GameFont");
  assert_eq!(text.build_font_string(), "italic bold 32px GameFont");
  assert_eq!(text.build_font_string_with_size(12.5), "italic bold 12.5px GameFont");
  ```

- `pub fn wrap_text_to_lines(&self, graphic: &Graphic, text: &str, maximum_width: f64) -> Vec<String>` (method, since 0.3.2): 폭에 맞춰 줄 나누기. (원본 wrapTextToLines, 줄바꿈 문자는 늘 지킨다, 재는 폰트는 Graphic 의 현재 폰트 문자열)
  - Word: 공백 단위로 채운다. 넘치는 조각에 낱말이 여럿이면(공백 없이 쓰는 글) 낱말 사이에서 나눠 지금 줄의 남은 자리부터 채우고,
    한 낱말이 폭을 넘으면 글자 묶음 단위로 나눈다. (공백 없는 한중일 문장도 낱말 사이에서 나뉜다)
  - Character: 처음부터 글자 묶음 단위로 나눈다.
  - `graphic` &Graphic: 잴 Graphic. (지금 폰트 문자열로 잰다)
  - `text` &str: 나눌 글.
  - `maximum_width` f64: 줄 최대 폭. (픽셀, 0 이하면 줄바꿈 문자로만 나눈다)
  - returns Vec<String>: 줄 목록. (빈 문단은 빈 줄)

  예제: 이 글자의 폰트로 줄 나누기

  ```rust
  use vanilla::{Graphic, Text};
  
  fn wrap_description(graphic: &mut Graphic, text: &Text) -> Vec<String> {
  	graphic.set_font_string(&text.build_font_string());
  	text.wrap_text_to_lines(graphic, text.get_text(), 200.0)
  }
  ```

- `pub fn wrap_text_to_lines_with(&self, text: &str, maximum_width: f64, measure_width: &dyn Fn(&str) -> f64) -> Vec<String>` (method, since 0.4.0): 폭에 맞춰 줄 나누기. (재는 함수를 받는다. wrap_text_to_lines 의 셈, Graphic 없이 시험하거나 다른 글꼴로 잴 때)
  - `text` &str: 나눌 글.
  - `maximum_width` f64: 줄 최대 폭. (measure_width 와 같은 단위, 0 이하면 줄바꿈 문자로만 나눈다)
  - `measure_width` &dyn Fn(&str) -> f64: 글을 받아 너비를 돌려주는 함수.
  - returns Vec<String>: 줄 목록. (빈 문단은 빈 줄)

  예제: 글자마다 폭 10 으로 재어 나누기

  ```rust
  use vanilla::{Text, TextWrapMode};
  
  let measure_width = |line_text: &str| -> f64 {
  	line_text.chars().count() as f64 * 10.0
  };
  let mut text = Text::new();
  assert_eq!(text.wrap_text_to_lines_with("aaa bbb ccc", 75.0, &measure_width), vec!["aaa bbb", "ccc"]);
  assert_eq!(text.wrap_text_to_lines_with("a\n\nb", 0.0, &measure_width), vec!["a", "", "b"]);
  text.set_wrap_mode(TextWrapMode::Character);
  assert_eq!(text.wrap_text_to_lines_with("abcdef", 25.0, &measure_width), vec!["ab", "cd", "ef"]);
  ```

- `pub fn wrap_lines_without_graphic(&self, maximum_width: f64) -> Option<Vec<String>>` (method, since 0.4.0): Graphic 없이 나눈 줄 목록. (지금 글과 폰트 문자열, 폭으로 나눈다, 글꼴이 없어 잴 수 없으면 None)
  - 그리기 전에 줄 수가 필요한 레이아웃(창의 내용 놓기 같은)이 쓴다. (textstringtexturecache::measure_text_without_graphic)
  - `maximum_width` f64: 줄 최대 폭. (픽셀, 0 이하면 줄바꿈 문자로만 나눈다)
  - returns Option<Vec<String>>: 줄 목록. 데스크탑에서 이 스레드에 글꼴을 등록한 글자 캐시가 없거나 고를 얼굴이 없으면 None.

  예제: 글꼴을 등록한 뒤 Graphic 없이 줄 나누기

  ```rust
  use vanilla::core::textstringtexturecache::TextStringTextureCache;
  use vanilla::platform::find_fallback_font_file;
  use vanilla::Text;
  
  let text = Text::create_with_text("one two three four five", 20.0);
  assert!(text.wrap_lines_without_graphic(100.0).is_none());
  if let Some(source) = find_fallback_font_file("A", 400, false, false) {
  	let mut text_string_texture_cache = TextStringTextureCache::new();
  	text_string_texture_cache.set_default_font(false, std::fs::read(&source.path).expect("font file")).expect("font");
  	let line_list = text.wrap_lines_without_graphic(100.0).expect("lines");
  	assert!(line_list.len() > 1);
  }
  ```

- `pub fn measure_wrapped_size(&self, graphic: &mut Graphic) -> TextWrappedSize` (method, since 0.4.0): 줄바꿈 반영 크기 재기. (원본 measureWrappedSize, 레이아웃 용. 줄바꿈 폭이 없으면 줄바꿈 문자로만 나눈다)
  - `graphic` &mut Graphic: 잴 Graphic. (상태는 되돌려 둔다)
  - returns TextWrappedSize: 크기. (글이 비었으면 모두 0)
- `pub fn calculate_intrinsic_content_size(&self, graphic: &Graphic) -> Vector2` (method, since 0.4.0): 글의 자연 크기. (원본 getIntrinsicContentSize: 한 줄 너비와 글자 크기, 글이 없으면 (0, 글자 크기), 꺼져 있으면 (-1, -1))
  - `graphic` &Graphic: 잴 Graphic.
  - returns Vector2: (너비, 글자 크기). (픽셀)
- `pub fn calculate_text_bounds(graphic: &Graphic, text_component: &Text) -> Rect` (static, since 0.4.0): 글이 차지하는 영역. (원본 Text.calculateTextBounds: 굵게, 기울임 없이 잰 너비와 실제 글리프의 위아래 높이)
  - `graphic` &Graphic: 잴 Graphic.
  - `text_component` &Text: 잴 컴포넌트. (폰트 이름, 글자 크기, 글을 쓴다)
  - returns Rect: (0, 0, 너비, 위아래 높이) 사각형. (픽셀)
- `pub fn set_fit_width(&mut self, width: f64, minimum_ratio: f64)` (method, since 0.4.0): 한 줄 글을 너비에 맞추기 설정. (넘치면 처음 크기에서 최소 비율까지 줄여 그린다, 원본 setFitWidth)
  - 칸을 넓힐 수 없는 곳(단추, 줄 이름, 제목)에서 언어마다 길이가 다른 글이 넘칠 때 쓴다.
  - 정한 크기(get_font_size)는 그대로 두고 그릴 때의 크기만 줄인다. 최소 비율로도 넘치면 넘친 채로 그리고, 화면 밖 거르기도 넘친 너비까지 본다.
  - 줄을 바꾸는 글은 맞추지 않는다. width 가 0 이하면 맞추지 않는다. (기본) minimum_ratio 는 0 ~ 1 (원본 기본 0.55)
  - `width` f64: 맞출 너비. (픽셀, 음수는 0)
  - `minimum_ratio` f64: 줄이는 가장 작은 비율. (0 ~ 1 로 자른다)

  예제: 단추 이름을 200 픽셀에 맞추기

  ```rust
  use vanilla::{Graphic, Text};
  
  fn fit_button_label(graphic: &mut Graphic) {
  	let mut text = Text::create_with_text("Start a new adventure", 32.0);
  	text.set_fit_width(200.0, 0.55);
  	let fitted_font_size = text.calculate_fitted_font_size(graphic);
  	assert!(fitted_font_size <= 32.0);
  	assert_eq!(text.get_font_size(), 32.0);
  }
  ```

- `pub fn get_fit_width(&self) -> f64` (method, since 0.4.0): 맞출 너비 반환. (0 이면 맞추지 않는다)
  - returns f64: 맞출 너비. (픽셀)
- `pub fn get_fit_minimum_ratio(&self) -> f64` (method, since 0.4.0): 맞출 때 줄이는 가장 작은 비율 반환.
  - returns f64: 비율. (0 ~ 1, 기본 0.55)
- `pub fn get_fitted_font_size(&self) -> f64` (method, since 0.4.0): 그릴 때의 크기 반환. (마지막으로 그리거나 잰 때의 값, 맞춰 줄였으면 줄인 크기)
  - returns f64: 크기. (픽셀, 줄을 다시 셀 일이 남았으면 정한 크기)
- `pub fn get_measured_line_count(&self) -> Option<usize>` (method, since 0.4.0): 마지막으로 나눈 줄의 수. (그린 뒤 글, 폰트, 줄바꿈 폭이 그대로일 때만, 아니면 None)
  - 줄은 그릴 때 Graphic 의 글꼴로 나눈다. Graphic 이 없는 레이아웃(창의 내용 놓기 같은)이 그린 결과를 읽어 다시 놓을 때 쓴다.
  - 줄바꿈 폭(set_word_wrap_width)을 주지 않은 여러 줄 글은 노드 폭으로 나누므로 None 이다.
  - returns Option<usize>: 줄 수. 아직 나누지 않았거나, 그 뒤 바뀌었거나, 노드 폭으로 나눈 글이면 None.
- `pub fn set_font_family(&mut self, font_family: &str)` (method, since 0.3.2): 폰트 이름 설정. (Graphic 에 등록한 이름, 없으면 기본 폰트)
  - `font_family` &str: 폰트 이름.
- `pub fn get_font_family(&self) -> &str` (method, since 0.3.2): 폰트 이름 반환.
  - returns &str: 폰트 이름. (기본 default)
- `pub fn set_word_wrap_width(&mut self, word_wrap_width: f64)` (method, since 0.3.2): 줄바꿈 폭 설정. (0 이면 줄바꿈 문자로만 나눈다)
  - `word_wrap_width` f64: 줄바꿈 폭. (픽셀, 0 이하면 줄바꿈 문자로만 나눈다)
- `pub fn get_word_wrap_width(&self) -> f64` (method, since 0.3.2): 줄바꿈 폭 반환.
  - returns f64: 줄바꿈 폭. (픽셀)
- `pub fn calculate_fitted_font_size(&mut self, graphic: &mut Graphic) -> f64` (method, since 0.4.0): 그릴 때의 크기를 그 자리에서 재어 반환. (맞출 너비를 넘치면 줄인 크기)
  - `graphic` &mut Graphic: 잴 Graphic.
  - returns f64: 크기. (픽셀)
- `pub fn measure_text(&self, graphic: &Graphic, text: &str, font_size: f64) -> f64` (method, since 0.4.0): 글의 너비 재기. (이 글자의 폰트 이름, 굵게, 기울임과 주어진 크기로, 원본 measureText)
  - 글자 캐시가 폰트 문자열과 글이 같으면 다시 재지 않는다. (TextStringTextureCache.measure_text)
  - `graphic` &Graphic: 잴 Graphic.
  - `text` &str: 잴 글.
  - `font_size` f64: 잴 크기. (픽셀)
  - returns f64: 너비. (픽셀, 빈 글은 0)
- `pub fn set_wrap_mode(&mut self, wrap_mode: TextWrapMode)` (method, since 0.4.0): 줄바꿈 방식 설정. (기본 Word)
  - `wrap_mode` TextWrapMode: 줄바꿈 방식.
- `pub fn get_wrap_mode(&self) -> TextWrapMode` (method, since 0.4.0): 줄바꿈 방식 반환.
  - returns TextWrapMode: 줄바꿈 방식.
- `pub fn set_line_spacing(&mut self, line_spacing: f64)` (method, since 0.3.2): 줄 간격 설정. (글자 크기의 배수)
  - `line_spacing` f64: 줄 간격. (글자 크기의 배수, 기본 1.25)
- `pub fn get_line_spacing(&self) -> f64` (method, since 0.3.2): 줄 간격 반환.
  - returns f64: 줄 간격. (글자 크기의 배수)
- `pub fn set_letter_spacing(&mut self, letter_spacing: f64)` (method, since 0.4.0): 글자 간격 설정. (CSS letter-spacing, 언리얼 UMG 글자 간격과 같은 뜻. 원본 setLetterSpacing)
  - `letter_spacing` f64: 글자 묶음마다 뒤에 더하는 간격. (픽셀, 음수는 좁힘, 기본 0)

  예제: 글자 간격 정하기

  ```rust
  use vanilla::Text;
  
  let mut text = Text::new();
  assert_eq!(text.get_letter_spacing(), 0.0);
  text.set_letter_spacing(2.5);
  assert_eq!(text.get_letter_spacing(), 2.5);
  ```

- `pub fn get_letter_spacing(&self) -> f64` (method, since 0.4.0): 글자 간격 반환.
  - returns f64: 글자 간격. (픽셀, 기본 0)
- `pub fn set_visible_character_count(&mut self, visible_character_count: i32)` (method, since 0.3.2): 보일 글자 수 설정. (-1 이면 전체, 타자기 연출용. -1 아래는 -1 로 맞춘다)
  - `visible_character_count` i32: 보일 글자 묶음 수. (-1 이면 전체)
- `pub fn get_visible_character_count(&self) -> i32` (method, since 0.3.2): 보일 글자 수 반환.
  - returns i32: 보일 글자 묶음 수. (-1 이면 전체)
- `pub fn set_text(&mut self, text: &str)` (method, since 0.3.2): 글 설정.
  - `text` &str: 글. (줄바꿈 문자로 여러 줄)
- `pub fn get_text(&self) -> &str` (method, since 0.3.2): 글 반환.
  - returns &str: 글.
- `pub fn set_font_size(&mut self, font_size: f64)` (method, since 0.3.2): 글자 크기 설정. (픽셀)
  - `font_size` f64: 글자 크기. (픽셀, 기본 32)
- `pub fn get_font_size(&self) -> f64` (method, since 0.3.2): 글자 크기 반환.
  - returns f64: 글자 크기. (픽셀, 맞춰 줄인 크기가 아니라 정한 크기)
- `pub fn set_text_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 글자 색 설정.
  - `color` impl Into<Color>: 글자 색. (기본 흰색)
- `pub fn get_text_color(&self) -> Color` (method, since 0.3.2): 글자 색 반환.
  - returns Color: 글자 색.
- `pub fn set_stroke_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 외곽선 색 설정.
  - `color` impl Into<Color>: 외곽선 색. (기본 흰색)
- `pub fn get_stroke_color(&self) -> Color` (method, since 0.3.2): 외곽선 색 반환.
  - returns Color: 외곽선 색.
- `pub fn set_stroke_width(&mut self, stroke_width: f64)` (method, since 0.3.2): 외곽선 두께 설정. (0 이면 외곽선 없음)
  - `stroke_width` f64: 외곽선 두께. (픽셀, 기본 0)
- `pub fn get_stroke_width(&self) -> f64` (method, since 0.3.2): 외곽선 두께 반환.
  - returns f64: 외곽선 두께. (픽셀)
- `pub fn set_bold(&mut self, is_bold: bool)` (method, since 0.3.2): 굵게 설정.
  - `is_bold` bool: true 면 굵게.
- `pub fn is_bold(&self) -> bool` (method, since 0.3.2): 굵게 여부.
  - returns bool: 굵게면 true.
- `pub fn set_italic(&mut self, is_italic: bool)` (method, since 0.3.2): 기울임 설정. (폰트 문자열에 italic 을 넣는다)
  - `is_italic` bool: true 면 기울임.
- `pub fn is_italic(&self) -> bool` (method, since 0.3.2): 기울임 여부.
  - returns bool: 기울임이면 true.
- `pub fn set_underline(&mut self, is_underline: bool)` (method, since 0.4.0): 밑줄 설정.
  - `is_underline` bool: true 면 밑줄을 긋는다.
- `pub fn is_underline(&self) -> bool` (method, since 0.4.0): 밑줄 여부.
  - returns bool: 밑줄을 그으면 true.
- `pub fn set_strikethrough(&mut self, is_strikethrough: bool)` (method, since 0.4.0): 취소선 설정.
  - `is_strikethrough` bool: true 면 취소선을 긋는다.
- `pub fn is_strikethrough(&self) -> bool` (method, since 0.4.0): 취소선 여부.
  - returns bool: 취소선을 그으면 true.
- `pub fn set_text_align(&mut self, text_align: TextAlign)` (method, since 0.3.2): 가로 정렬 설정.
  - `text_align` TextAlign: 가로 정렬. (기본 Center)
- `pub fn get_text_align(&self) -> TextAlign` (method, since 0.3.2): 가로 정렬 반환.
  - returns TextAlign: 가로 정렬.
- `pub fn set_text_direction(&mut self, text_direction: TextDirection)` (method, since 0.4.0): 글자 방향 설정. (Inherit | Ltr | Rtl | Auto, 원본 setTextDirection)
  - Inherit 면 그리는 때의 Graphic 방향을 따른다. (기본)
  - 정렬 Start / End 가 이 방향에 따라 왼쪽, 오른쪽이 된다. (오른쪽에서 왼쪽 언어의 화면은 Rtl 과 Start)
  - `text_direction` TextDirection: 글자 방향.
- `pub fn get_text_direction(&self) -> TextDirection` (method, since 0.4.0): 글자 방향 반환.
  - returns TextDirection: 글자 방향. (기본 Inherit)
- `pub fn set_text_baseline(&mut self, text_baseline: TextBaseline)` (method, since 0.3.2): 세로 기준선 설정.
  - `text_baseline` TextBaseline: 세로 기준선. (기본 Middle)
- `pub fn get_text_baseline(&self) -> TextBaseline` (method, since 0.3.2): 세로 기준선 반환.
  - returns TextBaseline: 세로 기준선.

## Functions and constants

- `pub fn split_graphemes(text: &str) -> Vec<&str>` (method, since 0.4.0): 글자 묶음으로 나누기. (원본 splitGraphemes, UAX #29 확장 글자 묶음: 받침, 성조, 결합 부호, 이모지 묶음이 앞 글자에서 떨어지지 않는다)
  - `text` &str: 나눌 글.
  - returns Vec<&str>: 글자 묶음 목록. (text 를 빌린 조각)
- `pub fn count_graphemes(text: &str) -> usize` (method, since 0.4.0): 글자 묶음 수. (표시 글자 수가 세는 단위)
  - `text` &str: 셀 글.
  - returns usize: 글자 묶음 수.
- `pub fn slice_graphemes(text: &str, count: usize) -> &str` (method, since 0.4.0): 앞에서 글자 묶음 count 개까지의 글. (원본 sliceGraphemes, 글이 짧으면 글 전체)
  - `text` &str: 글.
  - `count` usize: 남길 글자 묶음 수.
  - returns &str: 앞 조각. (text 를 빌린다)
- `pub fn find_grapheme_prefix_length(text: &str, count: usize) -> usize` (method, since 0.4.0): 앞에서 글자 묶음 count 개까지의 바이트 길이. (글이 짧으면 글 전체 길이)
  - `text` &str: 글.
  - `count` usize: 글자 묶음 수.
  - returns usize: 바이트 길이.
- `pub fn split_words(text: &str) -> Vec<String>` (method, since 0.4.0): 낱말로 나누기. (원본 splitWords, 줄바꿈 용)
  - 태국어, 라오어, 크메르어, 버마어, 한중일처럼 공백 없이 쓰는 글자도 낱말 사이를 찾는다. (ICU4X 사전 낱말 나누기, 한중일 덩어리는 크롬의 ICU4C CjkBreakEngine 과 같은 셈으로 다시 나눈다)
    브라우저(ICU4C)처럼 한글이 이어진 덩어리는 따로 한 낱말로 본다. ("Rust로" → "Rust", "로". ICU4X 는 한글과 라틴 글자를 한 낱말로 잇는다)
    웹은 원본처럼 브라우저의 Intl.Segmenter 로 나눈다. (없는 브라우저면 원본처럼 통째로 한 조각)
  - 문장 부호처럼 낱말이 아닌 조각은 앞 낱말에 붙인다. (줄 맨 앞에 문장 부호가 오지 않게) 맨 앞의 것은 첫 낱말 앞에 붙인다.
  - 줄바꿈 없는 빈칸(U+00A0)으로 이은 낱말 사이는 나누지 않는다. (이름과 값, 숫자와 단위처럼 함께 있어야 하는 것)
  - `text` &str: 나눌 글.
  - returns Vec<String>: 낱말 조각 목록. (조각을 이으면 원래 글이다)

  예제: 문장 부호는 앞 낱말에, 줄바꿈 없는 빈칸은 잇는다

  ```rust
  use vanilla::split_words;
  
  assert_eq!(split_words("Hello, world!"), vec!["Hello, ", "world!"]);
  assert_eq!(split_words("HP\u{00A0}100 MP"), vec!["HP\u{00A0}100 ", "MP"]);
  ```

- `pub fn segment_words(text: &str) -> Vec<(&str, bool)>` (method, since 0.4.0): 낱말 조각으로 나누기. ((조각, 낱말인지) 목록, ICU 낱말 경계에 한글 덩어리 경계를 더한다)
  - `text` &str: 나눌 글.
  - returns Vec<(&str, bool)>: (조각, 낱말인지) 목록. (조각을 이으면 원래 글이다)

## TextWrapMode (enum) (Clone, Copy, Debug, PartialEq, Eq)

줄바꿈 방식. (원본 wrapMode "word" / "char")

- `Word`: 공백 단위로 채우고, 한 단어가 폭을 넘으면 글자 단위로 나눈다. (공백 없는 한중일 문장은 통째로 한 단어라 글자 단위가 된다)
- `Character`: 처음부터 글자 단위로 나눈다.
