# core/component/text (vanilla.js 0.4.0)

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

원시(plain) 텍스트 출력기 컴포넌트.

## Text extends Component

원시(plain) 텍스트 출력기 컴포넌트.
- 단일 폰트 / 단일 크기 / 단일 색상으로 텍스트를 1 라인 그리는 컴포넌트.
- 볼드 / 이탤릭 / 밑줄 / 취소선은 텍스트 전체에 일괄 적용된다.
- 마크업 태그는 해석하지 않는다 (그대로 출력).
  리치텍스트 (마크업 + segment 별 스타일) 가 필요하면 RichText 컴포넌트를 사용.
- 비활성화 상태 (isEnable() === false) 면 draw / 측정에서 건너뛴다.

예제: 글꼴을 불러와 한 줄 글 쓰기

```js
import { Engine, EngineConfiguration, Scene, Vector2, WorldNode, Text, TextAlign, FontAsset } from "./build/vanilla.js";

class MainScene extends Scene {
	async load(engine) {
		await super.load(engine);
		const fontAsset = new FontAsset();
		await fontAsset.loadFont("DOSGothic", "examples/assets/DOSGothic.woff");
		const labelNode = new WorldNode();
		labelNode.setContentSize(Vector2.create(400, 60));
		labelNode.setLocalPosition(Vector2.create(320, 180));
		const text = labelNode.addComponent(Text);
		text.setFont(fontAsset);
		text.setFontSize(32);
		text.setTextColor("#ffffff");
		text.setStrokeColor("#000000");
		text.setStrokeWidth(4);
		text.setTextAlign(TextAlign.center);
		text.setText("Hello, Vanilla");
		const root = this.getRoot();
		root.addChild(labelNode);
	}
}

const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());
```

- `constructor()` (constructor, since 0.2.1): 생성.
- `tick(timeDelta)` (method, since 0.2.1): 갱신.
  - `timeDelta` number: 지난 프레임부터의 시간. (초)
- `isTickNeeded()` (method, since 0.4.0): tick 이 할 일이 있는지. (그리기만 하므로 거짓, 하위 클래스가 tick 을 다시 정의하면 참)
  - returns boolean: tick 이 할 일이 있으면 참.
- `draw(graphic)` (method, since 0.2.1): 출력. (비활성화면 건너뜀)
  - `graphic` Graphic: 그래픽.
- `applyVisibleCharacterCount(text)` (method, since 0.3.0): 표시 글자 수만큼 앞에서 자르기. (글자 묶음 단위, 받침, 결합 부호, 이모지 묶음이 쪼개지지 않는다)
  - `text` string: 자를 글.
  - returns string: 앞에서 표시 글자 수만큼 자른 글. (표시 글자 수가 -1 이면 글 그대로)
- `drawWrappedText(graphic, contentSize, fullText)` (method, since 0.3.0): 여러 줄 텍스트 그리기. (자동 줄바꿈 + 명시적 개행 + 표시 글자 수)
  - textBaseline 은 줄 묶음의 세로 정렬로 쓴다. (top / middle / bottom)
  - `graphic` Graphic: 그래픽.
  - `contentSize` Vector2: 노드의 내용 크기.
  - `fullText` string: 그릴 온 글. (표시 글자 수로 자르기 전)
- `readWrappedLines(text, wrapWidth)` (method, since 0.4.0): 그릴 줄 배열 반환. (wrapTextToLines 의 결과를 기억해 두고 쓴다)
  - 글, 글꼴, 크기, 굵게, 기울임, 폭, 줄바꿈 방식이 바뀌거나 웹 글꼴이 받아지거나 올라갈 때만 다시 나눈다.
  - 돌려준 배열은 다음에 다시 나눌 때까지 이 컴포넌트가 들고 있으므로 고치지 않는다.
  - `text` string: 나눌 글.
  - `wrapWidth` number: 줄을 바꾸는 폭. (내용 크기 단위)
  - returns string[]: 나눈 줄 배열. (이 컴포넌트가 들고 있으므로 고치지 않는다)
- `wrapTextToLines(text, maxWidth)` (method, since 0.3.0): 텍스트를 폭에 맞춰 줄 배열로 나누기.
  - "word": 공백 단위로 채우고, 한 단어가 폭을 넘으면 글자 단위로 강제 분할.
    (공백 없는 CJK 문장은 통째로 한 단어이므로 자연히 글자 단위가 된다)
  - "char": 처음부터 글자 단위.
  - 명시적 개행(\n)은 항상 지켜진다.
  - `text` string: 나눌 글.
  - `maxWidth` number: 줄을 바꾸는 폭. (내용 크기 단위, 0 이하면 줄바꿈 문자로만 나눈다)
  - returns string[]: 나눈 줄 배열. (잴 캔버스가 없으면 줄바꿈 문자로만 나눈다)
- `wrapLinesWithoutGraphic(maximumWidth)` (method, since 0.4.0): Graphic 없이 나눈 줄 목록. (지금 글과 글꼴, 폭으로 나눈다, 잴 캔버스가 없으면 null)
  - 그리기 전에 줄 수가 필요한 레이아웃(창의 내용 놓기 같은)이 쓴다. (러스트 판 wrap_lines_without_graphic 과 같은 쓰임)
  - `maximumWidth` number: 줄을 바꾸는 폭. (내용 크기 단위, 0 이하면 줄바꿈 문자로만 나눈다)
  - returns string[] | null: 나눈 줄 배열. (잴 캔버스가 없으면 null)
- `measureWrappedSize()` (method, since 0.3.0): 줄바꿈 반영 크기 측정. (레이아웃 용)
  - returns object: { width, height, lineCount }
- `drawPlainText(graphic, contentSize, text)` (method, since 0.2.1): 일반 텍스트 그리기.
  - `graphic` Graphic: 그래픽.
  - `contentSize` Vector2: 노드의 내용 크기.
  - `text` string: 그릴 한 줄 글. (표시 글자 수로 자른 것)
- `measurePlainTextWidth(text)` (method, since 0.2.1): 일반 텍스트의 픽셀 너비 측정. (오프스크린 컨텍스트 사용)
  - `text` string: 잴 글.
  - returns number: 정한 크기로 잰 글 너비. (내용 크기 단위)
- `measureText(text = this.#text, fontSize = this.#fontSize)` (method, since 0.4.0): 글의 너비 재기. (이 글자의 글꼴, 굵게, 기울임으로, 주지 않으면 지금 글과 정한 크기로)
  - 글꼴 문자열과 글이 같으면 다시 재지 않는다. (measureTextMetrics 의 캐시, 웹 글꼴이 받아지면 비운다)
  - 문서가 없으면 0.
  - `text` string: 잴 글. (주지 않으면 지금 글)
  - `fontSize` number: 글자 크기. (주지 않으면 정한 크기)
  - returns number: 글 너비. (내용 크기 단위, 글이 비었거나 문서가 없으면 0)
- `measureTextWithoutSpacing(text, fontSize)` (method, since 0.4.0): 글자 간격을 더하지 않은 글 너비. (measureText 와 drawTextLine 의 바탕)
  - `text` string: 잴 글.
  - `fontSize` number: 글자 크기.
  - returns number: 글자 간격을 빼고 잰 너비. (문서가 없으면 0)
- `drawTextLine(graphic, text, x, y, textAlign, fontSize, isStroke)` (method, since 0.4.0): 한 줄 글 그리기. (글자 간격이 0 이면 한 번에, 아니면 글자 묶음마다 간격을 더한 자리에)
  - 자리(k) = 자리(k-1) + (앞 글자 묶음과 이 묶음을 붙인 너비) - (이 묶음만의 너비) + 글자 간격. 짝 커닝은 그대로 남는다.
  - 글 전체 너비는 글자 묶음 수 x 글자 간격을 더한 값이다. (CSS letter-spacing 처럼 마지막 글자 뒤에도 더한다) 정렬은 이 너비로 잡는다.
  - 오른쪽에서 왼쪽으로 쓰는 글은 글자 간격 없이 그린다.
  - `graphic` Graphic: 그래픽. (글꼴, 색, 정렬, 세로 기준이 이미 정해진 것)
  - `text` string: 그릴 한 줄 글.
  - `x` number: 정렬의 기준 X.
  - `y` number: 세로 기준 Y.
  - `textAlign` string: 실제 가로 정렬. ("left", "right", "center")
  - `fontSize` number: 글자 크기. (자리 재기용)
  - `isStroke` boolean: 참이면 바깥선, 거짓이면 채움.
- `setFitWidth(width, minimumRatio = 0.55)` (method, since 0.4.0): 한 줄 글을 너비에 맞추기 설정. (넘치면 처음 크기에서 최소 비율까지 줄여 그린다)
  - 언어마다 글의 길이가 달라 칸을 넘칠 때, 칸을 넓힐 수 없는 곳(단추, 줄 이름, 제목)에 쓴다.
  - 정한 크기(getFontSize)는 그대로 두고 그릴 때의 크기(getFittedFontSize)만 줄인다. 글이나 글꼴이 바뀌면 다시 맞춘다.
  - 최소 비율까지 줄여도 넘치면 넘친 채로 그린다. 화면 밖 거르기는 넘친 너비까지 본다. (calculateDrawnRect)
  - 줄을 바꾸는 글(setWordWrapWidth, 줄바꿈 문자)은 맞추지 않는다.
  - width 가 0 이하면 맞추지 않는다. (기본)
  - `width` number: 맞출 너비. (내용 크기 단위, 음수는 0, 0 이면 맞추지 않는다)
  - `minimumRatio` number: 0 ~ 1, 기본 0.55.

  예제: 칸을 넘치는 글을 줄여 맞추기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2, WorldNode, Text } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	async load(engine) {
  		await super.load(engine);
  		const buttonNode = new WorldNode();
  		buttonNode.setContentSize(Vector2.create(160, 48));
  		buttonNode.setLocalPosition(Vector2.create(320, 180));
  		const text = buttonNode.addComponent(Text);
  		text.setFontSize(32);
  		text.setText("Start a new adventure");
  		text.setFitWidth(160, 0.5);
  		const fittedFontSize = text.getFittedFontSize();
  		console.log(fittedFontSize);
  		const root = this.getRoot();
  		root.addChild(buttonNode);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `getFitWidth()` (method, since 0.4.0): 맞출 너비 반환. (0 이면 맞추지 않는다)
  - returns number: 맞출 너비. (0 이면 맞추지 않는다)
- `getFitMinimumRatio()` (method, since 0.4.0): 맞출 때 줄이는 가장 작은 비율 반환.
  - returns number: 맞출 때 줄이는 가장 작은 비율. (0 ~ 1)
- `getFittedFontSize()` (method, since 0.4.0): 그릴 때의 크기 반환. (맞출 너비를 넘치면 줄인 크기, 0.1 단위로 내림, 아니면 정한 크기)
  - returns number: 그릴 때의 글자 크기.
- `calculateFittedFontSize()` (method, since 0.4.0): 그릴 때의 크기를 그 자리에서 재어 반환. (맞출 너비를 넘치면 줄인 크기, 러스트 판 calculate_fitted_font_size 와 같은 쓰임)
  - 이 판은 Graphic 없이 잴 수 있어 getFittedFontSize 와 같은 값이다. (글이나 글꼴이 바뀌었으면 다시 잰다)
  - returns number: 그릴 때의 글자 크기.
- `writeGeometryKey(geometryKey)` (method, since 0.4.0): 그리기 입력을 기하 캐시 열쇠에 적기. (글, 글꼴, 크기, 색, 정렬, 줄바꿈, 표시 글자 수, 맞춤 너비, 내용 크기)
  - 웹 글꼴이 받아져 다시 구울 글은 글 캐시가 엔트리를 버리므로 Graphic 이 알아채 다시 셈한다.
  - draw 나 그 아래 그리기 함수를 덮어쓴 하위 클래스(RichText 등)는 무엇을 읽는지 모르므로 false. (그 클래스가 이 함수도 덮어써 알린다)
  - `geometryKey` GeometryKey: 입력을 적을 열쇠.
  - returns boolean: 입력을 적었으면 참.
- `calculateDrawnRect(rect)` (method, since 0.4.0): 그리는 사각형을 rect 에 적기. (노드 내용 영역의 왼쪽 위가 원점, 화면 밖 거르기가 쓴다, 알면 true)
  - 한 줄 글: 정렬로 놓은 글의 너비(맞춘 크기, 넘쳐도 그 너비)에 외곽선과 글꼴 크기의 반만큼을 양옆에 더하고,
    세로는 베이스라인 자리에서 위아래로 글꼴 크기의 1.5 배씩 넉넉히 잡는다.
  - 줄을 바꾸는 글: 나눈 줄 가운데 가장 넓은 줄로 가로를 잡고, 세로는 줄 묶음(줄 수 × 줄 높이)에 글꼴 크기만큼씩 넉넉히 잡는다.
  - 글이 비었으면 그리는 것이 없으므로 크기 0 을 적고 true. (draw 도 그리지 않는다, 빈 글 라벨이 든 하위 트리도 건너뛸 수 있다)
  - 잴 수 없으면 false. (거르지 않는다)
  - `rect` Rect: 그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)
  - returns boolean: 적었으면 참. (잴 수 없으면 거짓)
- `calculateWrappedDrawnRect(rect, contentSize, text)` (method, since 0.4.0): 줄을 바꾸는 글의 그리는 사각형을 rect 에 적기. (calculateDrawnRect 가 부른다)
  - `rect` Rect: 그리는 사각형을 적을 곳.
  - `contentSize` Vector2: 노드의 내용 크기.
  - `text` string: 줄을 바꾸는 글.
  - returns boolean: 늘 참.
- `getMeasuredLineCount()` (method, since 0.4.0): 마지막으로 나눈 줄의 수. (그린 뒤 글, 글꼴, 줄바꿈 폭이 그대로일 때만, 아니면 -1)
  - 줄은 그릴 때 나눈다. 그린 결과를 읽어 다시 놓는 레이아웃이 쓴다. 줄바꿈 폭(setWordWrapWidth)이 없는 여러 줄 글은 노드 폭으로 나누므로 -1 이다.
  - 한 줄 글은 1.
  - returns number: 나눈 줄의 수. (모르면 -1)
- `computeUnderlineStartX(drawX, textWidth, textAlign = this.#textAlign)` (method, since 0.2.1): 밑줄 시작 X 좌표 계산. (textAlign 기준 캔버스 fillText 의 cursor 위치 보정)
  - `drawX` number: 글을 그린 X 좌표. (정렬의 기준점)
  - `textWidth` number: 글 너비.
  - `textAlign` string: 실제 정렬. (기본은 이 글자의 정렬, "start" 는 왼쪽, "end" 는 오른쪽으로 본다)
  - returns number: 밑줄을 시작할 X 좌표.
- `computeUnderlineOffsetY(fontSize)` (method, since 0.2.1): 밑줄 Y 오프셋. (baseline 기준 텍스트 아래쪽으로의 거리)
  - `fontSize` number: 글자 크기.
  - returns number: 그린 Y 에서 밑줄까지 아래로의 거리. (세로 정렬에 따라 다르다)
- `computeStrikethroughOffsetY(fontSize)` (method, since 0.2.1): 취소선 Y 오프셋.
  - `fontSize` number: 글자 크기.
  - returns number: 그린 Y 에서 취소선까지 아래로의 거리. (위쪽이면 음수)
- `strokeHorizontalLine(graphic, x, y, width, lineWidth = 1)` (method, since 0.2.1): 가로 라인 stroke.
  - `graphic` Graphic: 그래픽.
  - `x` number: 시작 X 좌표.
  - `y` number: Y 좌표.
  - `width` number: 선 길이.
  - `lineWidth` number: 선 굵기. (기본 1)
- `getIntrinsicContentSize()` (method, since 0.2.1): 텍스트의 자연 크기 반환. (UIKit 의 intrinsicContentSize 와 동일 사상)
  - 비활성화 상태면 (-1, -1) 반환 (가이드 영향 없음).
  - 측정 불가 (document 없음 등) 면 (-1, -1).
  - returns Vector2: 자연 크기. (글 너비와 글자 크기, 글이 비었으면 너비 0, 잴 수 없거나 비활성이면 (-1, -1))
- `setFont(font)` (method, since 0.2.1): 폰트 설정.
  - `font` FontFace | FontAsset: 글꼴. (FontFace 나 FontAsset, null 이나 undefined 면 시스템 글꼴, 그 밖의 꼴은 무시한다)
- `getFontFace()` (method, since 0.2.1): 폰트 반환.
  - returns FontFace: 글꼴. (null 이면 시스템 글꼴)
- `setWordWrapWidth(wordWrapWidth)` (method, since 0.3.0): 자동 줄바꿈 폭 설정. (0 이면 한 줄)
  - `wordWrapWidth` number: 자동 줄바꿈 폭. (내용 크기 단위, 음수는 0, 0 이면 한 줄)

  예제: 폭을 정해 여러 줄로 쓰기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2, WorldNode, Text, TextAlign, TextBaseline } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	async load(engine) {
  		await super.load(engine);
  		const messageNode = new WorldNode();
  		messageNode.setContentSize(Vector2.create(360, 200));
  		messageNode.setLocalPosition(Vector2.create(320, 180));
  		const text = messageNode.addComponent(Text);
  		text.setFontSize(24);
  		text.setTextAlign(TextAlign.left);
  		text.setTextBaseline(TextBaseline.top);
  		text.setWordWrapWidth(360);
  		text.setWrapMode("word");
  		text.setLineSpacing(1.4);
  		text.setText("The old bridge creaks under your feet.\nSomething moves in the water below.");
  		const root = this.getRoot();
  		root.addChild(messageNode);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `getWordWrapWidth()` (method, since 0.3.0): 자동 줄바꿈 폭 반환.
  - returns number: 자동 줄바꿈 폭. (0 이면 한 줄)
- `setWrapMode(wrapMode)` (method, since 0.3.0): 줄바꿈 방식 설정. ("word" | "char")
  - `wrapMode` string: "word" 면 공백 단위(넘치는 단어는 글자 단위), "char" 면 글자 단위.
- `getWrapMode()` (method, since 0.3.0): 줄바꿈 방식 반환.
  - returns string: 줄바꿈 방식. ("word" 또는 "char")
- `setLineSpacing(lineSpacing)` (method, since 0.3.0): 줄 간격 배율 설정.
  - `lineSpacing` number: 줄 간격 배율. (글자 크기에 곱한다, 0.1 보다 작으면 0.1, 처음은 1.25)
- `getLineSpacing()` (method, since 0.3.0): 줄 간격 배율 반환.
  - returns number: 줄 간격 배율.
- `setLetterSpacing(letterSpacing)` (method, since 0.4.0): 글자 간격 설정. (CSS letter-spacing, 언리얼 UMG 글자 간격과 같은 뜻)
  - `letterSpacing` number: 글자 묶음마다 뒤에 더하는 간격. (픽셀, 음수는 좁힘, 처음은 0)
- `getLetterSpacing()` (method, since 0.4.0): 글자 간격 반환.
  - returns number: 글자 간격. (픽셀, 처음은 0)
- `setVisibleCharacterCount(visibleCharacterCount)` (method, since 0.3.0): 표시 글자 수 설정. (-1 이면 전체, 타자기 연출용. 글자 묶음 단위)
  - `visibleCharacterCount` number: 표시 글자 수. (글자 묶음 단위, 내림, -1 보다 작으면 -1, -1 이면 전체)

  예제: 한 글자씩 드러내기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2, WorldNode, Text } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	async load(engine) {
  		await super.load(engine);
  		const labelNode = new WorldNode();
  		labelNode.setContentSize(Vector2.create(480, 60));
  		labelNode.setLocalPosition(Vector2.create(320, 180));
  		this.text = labelNode.addComponent(Text);
  		this.text.setFontSize(28);
  		this.text.setText("Welcome to the village.");
  		this.text.setVisibleCharacterCount(0);
  		this.elapsedTime = 0;
  		const root = this.getRoot();
  		root.addChild(labelNode);
  	}
  
  	tick(timeDelta) {
  		super.tick(timeDelta);
  		this.elapsedTime += timeDelta;
  		const visibleCharacterCount = Math.floor(this.elapsedTime * 12);
  		this.text.setVisibleCharacterCount(visibleCharacterCount);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `getVisibleCharacterCount()` (method, since 0.3.0): 표시 글자 수 반환.
  - returns number: 표시 글자 수. (-1 이면 전체)
- `setText(text)` (method, since 0.2.1): 텍스트 설정. (같은 글이면 아무것도 하지 않는다)
  - `text` string: 보일 글. (줄바꿈 문자에서 줄을 바꾼다)
- `getText()` (method, since 0.2.1): 텍스트 반환.
  - returns string: 글.
- `setFontSize(fontSize)` (method, since 0.2.1): 텍스트 크기 설정.
  - `fontSize` number: 글자 크기. (내용 크기 단위, 처음은 32)
- `getFontSize()` (method, since 0.2.1): 텍스트 크기 반환.
  - returns number: 정한 글자 크기.
- `setTextColor(color)` (method, since 0.2.1): 텍스트 색상 설정.
  - `color` Color | string | CanvasGradient | CanvasPattern: 글 색. (Color 나 "#rrggbb(aa)", "rgb(a)(...)" 글, null 이나 undefined 면 투명, 그 밖의 값은 무시한다)
- `getTextColor()` (method, since 0.2.1): 텍스트 색상 반환.
  - returns Color: 글 색.
- `setStrokeColor(color)` (method, since 0.2.1): 텍스트 외곽선 색상 설정.
  - `color` Color | string | CanvasGradient | CanvasPattern: 외곽선 색. (Color 나 "#rrggbb(aa)", "rgb(a)(...)" 글, null 이나 undefined 면 투명, 그 밖의 값은 무시한다)
- `getStrokeColor()` (method, since 0.2.1): 텍스트 외곽선 색상 반환.
  - returns Color: 외곽선 색.
- `setStrokeWidth(width)` (method, since 0.2.1): 텍스트 외곽선 두께 설정.
  - `width` number: 외곽선 두께. (내용 크기 단위, 0 이하면 외곽선을 그리지 않는다)
- `getStrokeWidth()` (method, since 0.2.1): 외곽선 두께 반환.
  - returns number: 외곽선 두께.
- `setBold(bold)` (method, since 0.2.1): 볼드 여부 설정.
  - `bold` boolean: 굵게 할지. (true 일 때만 굵게)
- `isBold()` (method, since 0.2.1): 볼드 여부 반환.
  - returns boolean: 굵게면 참.
- `setItalic(italic)` (method, since 0.2.1): 이탤릭 여부 설정.
  - `italic` boolean: 기울일지. (true 일 때만 기울인다)
- `isItalic()` (method, since 0.2.1): 이탤릭 여부 반환.
  - returns boolean: 기울임이면 참.
- `setUnderline(underline)` (method, since 0.2.1): 밑줄 여부 설정.
  - `underline` boolean: 밑줄을 그을지. (true 일 때만 긋는다)
- `isUnderline()` (method, since 0.2.1): 밑줄 여부 반환.
  - returns boolean: 밑줄이면 참.
- `setStrikethrough(strikethrough)` (method, since 0.2.1): 취소선 여부 설정.
  - `strikethrough` boolean: 취소선을 그을지. (true 일 때만 긋는다)
- `isStrikethrough()` (method, since 0.2.1): 취소선 여부 반환.
  - returns boolean: 취소선이면 참.
- `setTextAlign(align)` (method, since 0.2.1): 폰트 가로 정렬 설정.
  - `align` "left" | "center" | "right" | "start" | "end": 가로 정렬. ("start", "end" 는 글 방향을 따른다, 처음은 "center")
- `getTextAlign()` (method, since 0.2.1): 폰트 가로 정렬 반환.
  - returns string: 가로 정렬. ("left", "center", "right", "start", "end")
- `setTextDirection(textDirection)` (method, since 0.3.2): 글자 방향 설정. ("inherit" | "ltr" | "rtl" | "auto", Graphic.setTextDirection 과 같다)
  - "inherit" 면 그리는 때의 Graphic 방향을 따른다. (기본)
  - 정렬 "start" / "end" 가 이 방향에 따라 왼쪽, 오른쪽이 된다. (오른쪽에서 왼쪽 언어의 화면은 "rtl" 과 "start")
  - `textDirection` "inherit" | "ltr" | "rtl" | "auto": 글자 방향. (처음은 "inherit")
- `getTextDirection()` (method, since 0.3.2): 글자 방향 반환.
  - returns string: 글자 방향. ("inherit", "ltr", "rtl", "auto")
- `setTextBaseline(baseline)` (method, since 0.2.1): 폰트 세로 정렬 설정.
  - `baseline` "top" | "middle" | "bottom" | "alphabetic" | "hanging" | "ideographic": 세로 정렬. (여러 줄 글은 줄 묶음의 세로 자리로 쓴다, 처음은 "middle")
- `getTextBaseline()` (method, since 0.2.1): 폰트 세로 정렬 반환.
  - returns string: 세로 정렬.
- `static calculateTextBounds(graphic, textComponent)` (static, since 0.2.1): 텍스트가 출력되는 영역을 Rect로 반환. (호환용)
  - `graphic` Graphic: 그래픽. (쓰지 않는다)
  - `textComponent` Text: 잴 글자 컴포넌트.
  - returns Rect: 글 너비와 실제 높이의 사각형. (굵게, 기울임은 보지 않는다, 잴 수 없으면 빈 사각형)

## Functions and constants

- `splitGraphemes(text)` (method, since 0.3.2): 글자 묶음으로 나누기. (Intl.Segmenter 가 없으면 코드 포인트 단위)
  - `text` string: 나눌 글.
  - returns string[]: 글자 묶음 목록.
- `splitWords(text)` (method, since 0.3.2): 단어로 나누기. (Intl.Segmenter 가 없으면 글 통째로 한 조각)
  - `text` string: 나눌 글.
  - returns string[]: 단어마다 한 조각. (단어가 아닌 조각은 앞 단어에 붙인다, 줄바꿈 없는 빈칸으로 이은 단어는 한 조각)

  예제: 글자 묶음과 단어로 나누기

  ```js
  import { splitGraphemes, splitWords, countGraphemes, sliceGraphemes } from "./build/vanilla.js";
  
  const text = "Cafe\u0301 au lait";
  const graphemes = splitGraphemes(text);
  console.log(graphemes.length, text.length);
  console.log(countGraphemes(text));
  console.log(sliceGraphemes(text, 4));
  console.log(splitWords("Hello, world. Bye"));
  ```

- `countGraphemes(text)` (method, since 0.4.0): 글자 묶음 수. (표시 글자 수가 세는 단위, 받침, 결합 부호, 이모지 묶음을 한 자로)
  - `text` string: 셀 글.
  - returns number: 글자 묶음 수.
- `sliceGraphemes(text, count)` (method, since 0.4.0): 앞에서 글자 묶음 count 개까지의 글. (글이 짧으면 글 전체)
  - `text` string: 자를 글.
  - `count` number: 남길 글자 묶음 수.
  - returns string: 앞에서 count 개까지의 글. (글이 짧으면 글 그대로)

## TextAlign (enum)

텍스트 수평 설정. (CanvasTextAlign)

- `left` = `left`: 왼쪽 맞춤. (내용 왼쪽 끝에 놓는다)
- `center` = `center`: 가운데 맞춤. (내용 가로 가운데에 놓는다)
- `right` = `right`: 오른쪽 맞춤. (내용 오른쪽 끝에 놓는다)
- `start` = `start`: 글 방향의 시작 쪽 맞춤. ("ltr" 은 왼쪽, "rtl" 은 오른쪽)
- `end` = `end`: 글 방향의 끝 쪽 맞춤. ("ltr" 은 오른쪽, "rtl" 은 왼쪽)

## TextBaseline (enum)

텍스트 수직 설정. (CanvasTextBaseline)

- `top` = `top`: 글의 위 끝 기준. (내용 위 끝에 놓는다)
- `middle` = `middle`: 글의 가운데 기준. (내용 세로 가운데에 놓는다)
- `bottom` = `bottom`: 글의 아래 끝 기준. (내용 아래 끝에 놓는다)
- `ideographic` = `ideographic`: 표의 문자 기준선. (내용 아래 끝에 놓는다)
- `hanging` = `hanging`: 매달린 기준선. (내용 위 끝에 놓는다)
- `alphabetic` = `alphabetic`: 알파벳 기준선. (내용 아래 끝에 놓는다)
