core/component/text
원시(plain) 텍스트 출력기 컴포넌트.
Plain text renderer component.
Textextends Component
원시(plain) 텍스트 출력기 컴포넌트.
- 단일 폰트 / 단일 크기 / 단일 색상으로 텍스트를 1 라인 그리는 컴포넌트.
- 볼드 / 이탤릭 / 밑줄 / 취소선은 텍스트 전체에 일괄 적용된다.
- 마크업 태그는 해석하지 않는다 (그대로 출력). 리치텍스트 (마크업 + segment 별 스타일) 가 필요하면 RichText 컴포넌트를 사용.
- 비활성화 상태 (isEnable() === false) 면 draw / 측정에서 건너뛴다.
Plain text renderer component.
- Component that draws 1 line of text in a single font / single size / single color.
- Bold / italic / underline / strikethrough apply to the whole text at once.
- Does not interpret markup tags (outputs them as is). Use the RichText component if rich text (markup + per-segment style) is needed.
- When disabled (isEnable() === false), skipped in draw / measurement.
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());텍스트가 출력되는 영역을 Rect로 반환. (호환용)
Returns the area where the text is drawn as a Rect. (for compatibility)
- graphicGraphic
- 그래픽. (쓰지 않는다)Graphics. (unused)
- textComponentText
- 잴 글자 컴포넌트.Text component to measure.
반환ReturnsRect 글 너비와 실제 높이의 사각형. (굵게, 기울임은 보지 않는다, 잴 수 없으면 빈 사각형)Rect of the text width and actual height. (ignores bold and italic, an empty rect if it cannot be measured)
짝Counterpart: vanilla-engine Text.calculate_text_bounds
갱신.
Update.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
tick 이 할 일이 있는지. (그리기만 하므로 거짓, 하위 클래스가 tick 을 다시 정의하면 참)
Whether tick has work to do. (false since it only draws, true if a subclass redefines tick)
반환Returnsboolean tick 이 할 일이 있으면 참.True if tick has work to do.
표시 글자 수만큼 앞에서 자르기. (글자 묶음 단위, 받침, 결합 부호, 이모지 묶음이 쪼개지지 않는다)
Truncates from the start to the display character count. (in grapheme clusters, so final consonants, combining marks and emoji clusters are not split)
- textstring
- 자를 글.Text to slice.
반환Returnsstring 앞에서 표시 글자 수만큼 자른 글. (표시 글자 수가 -1 이면 글 그대로)Text cut from the front to the visible character count. (the text as is if the visible character count is -1)
여러 줄 텍스트 그리기. (자동 줄바꿈 + 명시적 개행 + 표시 글자 수)
- textBaseline 은 줄 묶음의 세로 정렬로 쓴다. (top / middle / bottom)
Draws multi-line text. (automatic word wrap + explicit line breaks + display character count)
- textBaseline is used as the vertical alignment of the line block. (top / middle / bottom)
- graphicGraphic
- 그래픽.Graphics.
- contentSizeVector2
- 노드의 내용 크기.The node's content size.
- fullTextstring
- 그릴 온 글. (표시 글자 수로 자르기 전)Whole text to draw. (before cutting to the visible character count)
그릴 줄 배열 반환. (wrapTextToLines 의 결과를 기억해 두고 쓴다)
- 글, 글꼴, 크기, 굵게, 기울임, 폭, 줄바꿈 방식이 바뀌거나 웹 글꼴이 받아지거나 올라갈 때만 다시 나눈다.
- 돌려준 배열은 다음에 다시 나눌 때까지 이 컴포넌트가 들고 있으므로 고치지 않는다.
Returns the array of lines to draw. (remembers and reuses the result of wrapTextToLines)
- Re-splits only when the text, font, size, bold, italic, width or wrap mode changes, or when a web font is downloaded or uploaded.
- The returned array is held by this component until the next split, so do not modify it.
- textstring
- 나눌 글.Text to split.
- wrapWidthnumber
- 줄을 바꾸는 폭. (내용 크기 단위)Width at which lines wrap. (content size units)
반환Returnsstring[] 나눈 줄 배열. (이 컴포넌트가 들고 있으므로 고치지 않는다)Array of wrapped lines. (held by this component so do not modify)
텍스트를 폭에 맞춰 줄 배열로 나누기.
- "word": 공백 단위로 채우고, 한 단어가 폭을 넘으면 글자 단위로 강제 분할. (공백 없는 CJK 문장은 통째로 한 단어이므로 자연히 글자 단위가 된다)
- "char": 처음부터 글자 단위.
- 명시적 개행(\n)은 항상 지켜진다.
Splits text into an array of lines to fit the width.
- "word": fills by space units, and force-splits by character when one word exceeds the width. (a CJK sentence without spaces is one whole word, so it naturally becomes character units)
- "char": character units from the start.
- Explicit line breaks (\n) are always kept.
- textstring
- 나눌 글.Text to split.
- maxWidthnumber
- 줄을 바꾸는 폭. (내용 크기 단위, 0 이하면 줄바꿈 문자로만 나눈다)Width at which lines wrap. (content size units, splits only at line breaks if 0 or less)
반환Returnsstring[] 나눈 줄 배열. (잴 캔버스가 없으면 줄바꿈 문자로만 나눈다)Array of wrapped lines. (split only at line breaks if there is no measuring canvas)
짝Counterpart: vanilla-engine Text.wrap_text_to_lines
Graphic 없이 나눈 줄 목록. (지금 글과 글꼴, 폭으로 나눈다, 잴 캔버스가 없으면 null)
- 그리기 전에 줄 수가 필요한 레이아웃(창의 내용 놓기 같은)이 쓴다. (러스트 판 wrap_lines_without_graphic 과 같은 쓰임)
List of lines split without Graphic. (splits by the current text, font and width; null if there is no canvas to measure with)
- Used by layouts that need the line count before drawing (such as placing window content). (same use as wrap_lines_without_graphic in the Rust version)
- maximumWidthnumber
- 줄을 바꾸는 폭. (내용 크기 단위, 0 이하면 줄바꿈 문자로만 나눈다)Width at which lines wrap. (content size units, splits only at line breaks if 0 or less)
반환Returnsstring[] | null 나눈 줄 배열. (잴 캔버스가 없으면 null)Array of wrapped lines. (null if there is no measuring canvas)
짝Counterpart: vanilla-engine Text.wrap_lines_without_graphic
줄바꿈 반영 크기 측정. (레이아웃 용)
Measures the size with word wrap applied. (for layout)
반환Returnsobject { width, height, lineCount }
짝Counterpart: vanilla-engine Text.measure_wrapped_size
일반 텍스트 그리기.
Draws plain text.
- graphicGraphic
- 그래픽.Graphics.
- contentSizeVector2
- 노드의 내용 크기.The node's content size.
- textstring
- 그릴 한 줄 글. (표시 글자 수로 자른 것)Single line of text to draw. (already cut to the visible character count)
일반 텍스트의 픽셀 너비 측정. (오프스크린 컨텍스트 사용)
Measures the pixel width of plain text. (uses an offscreen context)
- textstring
- 잴 글.Text to measure.
반환Returnsnumber 정한 크기로 잰 글 너비. (내용 크기 단위)Text width measured at the set size. (content size units)
글의 너비 재기. (이 글자의 글꼴, 굵게, 기울임으로, 주지 않으면 지금 글과 정한 크기로)
- 글꼴 문자열과 글이 같으면 다시 재지 않는다. (measureTextMetrics 의 캐시, 웹 글꼴이 받아지면 비운다)
- 문서가 없으면 0.
Measures the width of text. (with this text's font, bold and italic; if not given, the current text and the set size)
- Does not remeasure if the font string and text are the same. (measureTextMetrics cache, cleared when a web font is downloaded)
- 0 if there is no document.
- textstring
- 잴 글. (주지 않으면 지금 글)Text to measure. (the current text if omitted)
- fontSizenumber
- 글자 크기. (주지 않으면 정한 크기)Font size. (the set size if omitted)
반환Returnsnumber 글 너비. (내용 크기 단위, 글이 비었거나 문서가 없으면 0)Text width. (content size units, 0 if the text is empty or there is no document)
짝Counterpart: vanilla-engine Text.measure_text
글자 간격을 더하지 않은 글 너비. (measureText 와 drawTextLine 의 바탕)
Text width without letter spacing added. (the base of measureText and drawTextLine)
- textstring
- 잴 글.Text to measure.
- fontSizenumber
- 글자 크기.Font size.
반환Returnsnumber 글자 간격을 빼고 잰 너비. (문서가 없으면 0)Width measured without letter spacing. (0 if there is no document)
한 줄 글 그리기. (글자 간격이 0 이면 한 번에, 아니면 글자 묶음마다 간격을 더한 자리에)
- 자리(k) = 자리(k-1) + (앞 글자 묶음과 이 묶음을 붙인 너비) - (이 묶음만의 너비) + 글자 간격. 짝 커닝은 그대로 남는다.
- 글 전체 너비는 글자 묶음 수 x 글자 간격을 더한 값이다. (CSS letter-spacing 처럼 마지막 글자 뒤에도 더한다) 정렬은 이 너비로 잡는다.
- 오른쪽에서 왼쪽으로 쓰는 글은 글자 간격 없이 그린다.
Draws a single line of text. (in one go if the letter spacing is 0, otherwise at positions with the spacing added per grapheme cluster)
- position(k) = position(k-1) + (width of the previous cluster and this cluster joined) - (width of this cluster alone) + letter spacing. Pair kerning is kept.
- The total text width is the cluster count x letter spacing added to the width. (like CSS letter-spacing, it is also added after the last character) Alignment uses this width.
- Right-to-left text is drawn without letter spacing.
- graphicGraphic
- 그래픽. (글꼴, 색, 정렬, 세로 기준이 이미 정해진 것)Graphic. (with font, color, alignment and vertical baseline already set)
- textstring
- 그릴 한 줄 글.Single line of text to draw.
- xnumber
- 정렬의 기준 X.Alignment reference X.
- ynumber
- 세로 기준 Y.Vertical reference Y.
- textAlignstring
- 실제 가로 정렬. ("left", "right", "center")Actual horizontal alignment. ("left", "right", "center")
- fontSizenumber
- 글자 크기. (자리 재기용)Font size. (for measuring positions)
- isStrokeboolean
- 참이면 바깥선, 거짓이면 채움.Outline if true, fill if false.
한 줄 글을 너비에 맞추기 설정. (넘치면 처음 크기에서 최소 비율까지 줄여 그린다)
- 언어마다 글의 길이가 달라 칸을 넘칠 때, 칸을 넓힐 수 없는 곳(단추, 줄 이름, 제목)에 쓴다.
- 정한 크기(getFontSize)는 그대로 두고 그릴 때의 크기(getFittedFontSize)만 줄인다. 글이나 글꼴이 바뀌면 다시 맞춘다.
- 최소 비율까지 줄여도 넘치면 넘친 채로 그린다. 화면 밖 거르기는 넘친 너비까지 본다. (calculateDrawnRect)
- 줄을 바꾸는 글(setWordWrapWidth, 줄바꿈 문자)은 맞추지 않는다.
- width 가 0 이하면 맞추지 않는다. (기본)
Sets fitting single-line text to a width. (if it overflows, draws it shrunk from the initial size down to the minimum ratio)
- Used where the text overflows its box because text length differs per language and the box cannot be widened (buttons, row labels, titles).
- Keeps the set size (getFontSize) and shrinks only the draw size (getFittedFontSize). Refits when the text or font changes.
- If it still overflows after shrinking to the minimum ratio, draws it overflowing. Off-screen culling considers the overflowing width. (calculateDrawnRect)
- Text that wraps (setWordWrapWidth, line break characters) is not fitted.
- No fitting if width is 0 or less. (default)
- widthnumber
- 맞출 너비. (내용 크기 단위, 음수는 0, 0 이면 맞추지 않는다)Width to fit. (content size units, negative becomes 0, no fitting if 0)
- minimumRationumber
- 0 ~ 1, 기본 0.55.0 ~ 1, default 0.55.
짝Counterpart: vanilla-engine Text.set_fit_width
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());맞출 너비 반환. (0 이면 맞추지 않는다)
Returns the width to fit. (no fitting if 0)
반환Returnsnumber 맞출 너비. (0 이면 맞추지 않는다)Width to fit. (no fitting if 0)
짝Counterpart: vanilla-engine Text.get_fit_width
맞출 때 줄이는 가장 작은 비율 반환.
Returns the minimum ratio to shrink to when fitting.
반환Returnsnumber 맞출 때 줄이는 가장 작은 비율. (0 ~ 1)Smallest ratio to shrink to when fitting. (0 ~ 1)
짝Counterpart: vanilla-engine Text.get_fit_minimum_ratio
그릴 때의 크기 반환. (맞출 너비를 넘치면 줄인 크기, 0.1 단위로 내림, 아니면 정한 크기)
Returns the draw size. (the shrunk size if it exceeds the fit width, rounded down to 0.1 units; otherwise the set size)
반환Returnsnumber 그릴 때의 글자 크기.Font size used when drawing.
짝Counterpart: vanilla-engine Text.get_fitted_font_size
그릴 때의 크기를 그 자리에서 재어 반환. (맞출 너비를 넘치면 줄인 크기, 러스트 판 calculate_fitted_font_size 와 같은 쓰임)
- 이 판은 Graphic 없이 잴 수 있어 getFittedFontSize 와 같은 값이다. (글이나 글꼴이 바뀌었으면 다시 잰다)
Measures and returns the draw size on the spot. (the shrunk size if it exceeds the fit width; same use as calculate_fitted_font_size in the Rust version)
- This version can measure without Graphic, so it is the same value as getFittedFontSize. (remeasures if the text or font has changed)
반환Returnsnumber 그릴 때의 글자 크기.Font size used when drawing.
짝Counterpart: vanilla-engine Text.calculate_fitted_font_size
그리기 입력을 기하 캐시 열쇠에 적기. (글, 글꼴, 크기, 색, 정렬, 줄바꿈, 표시 글자 수, 맞춤 너비, 내용 크기)
- 웹 글꼴이 받아져 다시 구울 글은 글 캐시가 엔트리를 버리므로 Graphic 이 알아채 다시 셈한다.
- draw 나 그 아래 그리기 함수를 덮어쓴 하위 클래스(RichText 등)는 무엇을 읽는지 모르므로 false. (그 클래스가 이 함수도 덮어써 알린다)
Writes the draw inputs to the geometry cache key. (text, font, size, colors, alignment, wrapping, visible character count, fit width, content size)
- When a web font loads and text must be baked again, the text cache drops the entry, so Graphic notices and recomputes.
- A subclass that overrides draw or the drawing functions under it (RichText etc.) returns false because what it reads is unknown. (that class overrides this function too to report them)
- geometryKeyGeometryKey
- 입력을 적을 열쇠.Key to write the inputs to.
반환Returnsboolean 입력을 적었으면 참.True if the inputs were written.
그리는 사각형을 rect 에 적기. (노드 내용 영역의 왼쪽 위가 원점, 화면 밖 거르기가 쓴다, 알면 true)
- 한 줄 글: 정렬로 놓은 글의 너비(맞춘 크기, 넘쳐도 그 너비)에 외곽선과 글꼴 크기의 반만큼을 양옆에 더하고, 세로는 베이스라인 자리에서 위아래로 글꼴 크기의 1.5 배씩 넉넉히 잡는다.
- 줄을 바꾸는 글: 나눈 줄 가운데 가장 넓은 줄로 가로를 잡고, 세로는 줄 묶음(줄 수 × 줄 높이)에 글꼴 크기만큼씩 넉넉히 잡는다.
- 글이 비었으면 그리는 것이 없으므로 크기 0 을 적고 true. (draw 도 그리지 않는다, 빈 글 라벨이 든 하위 트리도 건너뛸 수 있다)
- 잴 수 없으면 false. (거르지 않는다)
Writes the drawn rectangle to rect. (origin at the top-left of the node content area, used by off-screen culling, true if known)
- Single-line text: adds the outline and half the font size on both sides of the aligned text width (fitted size, that width even when overflowing), and vertically allows a generous 1.5 times the font size above and below the baseline position.
- Wrapping text: takes the widest of the split lines horizontally, and vertically adds a generous font size on each side of the line block (line count × line height).
- If the text is empty nothing is drawn, so a size of 0 is written and true is returned. (draw draws nothing either, so a subtree holding an empty label can be skipped)
- false if it cannot be measured. (not culled)
- rectRect
- 그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)
반환Returnsboolean 적었으면 참. (잴 수 없으면 거짓)True if written. (False if it cannot be measured)
줄을 바꾸는 글의 그리는 사각형을 rect 에 적기. (calculateDrawnRect 가 부른다)
Writes the drawn rectangle of wrapping text to rect. (called by calculateDrawnRect)
- rectRect
- 그리는 사각형을 적을 곳.Rect to write the drawn area into.
- contentSizeVector2
- 노드의 내용 크기.The node's content size.
- textstring
- 줄을 바꾸는 글.Text that wraps.
반환Returnsboolean 늘 참.Always true.
마지막으로 나눈 줄의 수. (그린 뒤 글, 글꼴, 줄바꿈 폭이 그대로일 때만, 아니면 -1)
- 줄은 그릴 때 나눈다. 그린 결과를 읽어 다시 놓는 레이아웃이 쓴다. 줄바꿈 폭(setWordWrapWidth)이 없는 여러 줄 글은 노드 폭으로 나누므로 -1 이다.
- 한 줄 글은 1.
Number of lines from the last split. (only while the text, font and wrap width are unchanged since drawing; otherwise -1)
- Lines are split when drawing. Used by layouts that read the drawn result and re-place. Multi-line text without a wrap width (setWordWrapWidth) splits by the node width, so it is -1.
- 1 for single-line text.
반환Returnsnumber 나눈 줄의 수. (모르면 -1)Number of wrapped lines. (-1 if unknown)
짝Counterpart: vanilla-engine Text.get_measured_line_count
밑줄 시작 X 좌표 계산. (textAlign 기준 캔버스 fillText 의 cursor 위치 보정)
Calculates the underline start X coordinate. (corrects the cursor position of canvas fillText based on textAlign)
- drawXnumber
- 글을 그린 X 좌표. (정렬의 기준점)X coordinate where the text was drawn. (the alignment anchor)
- textWidthnumber
- 글 너비.Text width.
- textAlignstring
- 실제 정렬. (기본은 이 글자의 정렬, "start" 는 왼쪽, "end" 는 오른쪽으로 본다)Actual alignment. (defaults to this text's alignment; "start" is treated as left, "end" as right)
반환Returnsnumber 밑줄을 시작할 X 좌표.X coordinate where the underline starts.
밑줄 Y 오프셋. (baseline 기준 텍스트 아래쪽으로의 거리)
Underline Y offset. (distance below the text from the baseline)
- fontSizenumber
- 글자 크기.Font size.
반환Returnsnumber 그린 Y 에서 밑줄까지 아래로의 거리. (세로 정렬에 따라 다르다)Downward distance from the drawn Y to the underline. (depends on the vertical alignment)
취소선 Y 오프셋.
Strikethrough Y offset.
- fontSizenumber
- 글자 크기.Font size.
반환Returnsnumber 그린 Y 에서 취소선까지 아래로의 거리. (위쪽이면 음수)Downward distance from the drawn Y to the strikethrough. (negative if above)
가로 라인 stroke.
Horizontal line stroke.
- graphicGraphic
- 그래픽.Graphics.
- xnumber
- 시작 X 좌표.Start X coordinate.
- ynumber
- Y 좌표.Y coordinate.
- widthnumber
- 선 길이.Line length.
- lineWidthnumber
- 선 굵기. (기본 1)Line width. (default 1)
텍스트의 자연 크기 반환. (UIKit 의 intrinsicContentSize 와 동일 사상)
- 비활성화 상태면 (-1, -1) 반환 (가이드 영향 없음).
- 측정 불가 (document 없음 등) 면 (-1, -1).
Returns the natural size of the text. (same idea as UIKit's intrinsicContentSize)
- Returns (-1, -1) when disabled (no effect on guides).
- (-1, -1) if it cannot be measured (no document, etc.).
반환ReturnsVector2 자연 크기. (글 너비와 글자 크기, 글이 비었으면 너비 0, 잴 수 없거나 비활성이면 (-1, -1))Intrinsic size. (text width and font size, width 0 if the text is empty, (-1, -1) if it cannot be measured or is disabled)
폰트 설정.
Sets the font.
- fontFontFace | FontAsset
- 글꼴. (FontFace 나 FontAsset, null 이나 undefined 면 시스템 글꼴, 그 밖의 꼴은 무시한다)Font. (a FontFace or FontAsset, the system font if null or undefined, other types are ignored)
폰트 반환.
Returns the font.
반환ReturnsFontFace 글꼴. (null 이면 시스템 글꼴)Font. (system font if null)
자동 줄바꿈 폭 설정. (0 이면 한 줄)
Sets the automatic word wrap width. (single line if 0)
- wordWrapWidthnumber
- 자동 줄바꿈 폭. (내용 크기 단위, 음수는 0, 0 이면 한 줄)Automatic wrap width. (content size units, negative becomes 0, a single line if 0)
짝Counterpart: vanilla-engine RichText.set_word_wrap_width
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());자동 줄바꿈 폭 반환.
Returns the automatic word wrap width.
반환Returnsnumber 자동 줄바꿈 폭. (0 이면 한 줄)Automatic wrap width. (a single line if 0)
짝Counterpart: vanilla-engine RichText.get_word_wrap_width
줄바꿈 방식 설정. ("word" | "char")
Sets the wrap mode. ("word" | "char")
- wrapModestring
- "word" 면 공백 단위(넘치는 단어는 글자 단위), "char" 면 글자 단위."word" wraps at spaces (an overflowing word wraps by character), "char" wraps by character.
짝Counterpart: vanilla-engine RichText.set_wrap_mode
줄바꿈 방식 반환.
Returns the wrap mode.
반환Returnsstring 줄바꿈 방식. ("word" 또는 "char")Wrap mode. ("word" or "char")
짝Counterpart: vanilla-engine RichText.get_wrap_mode
줄 간격 배율 설정.
Sets the line spacing multiplier.
- lineSpacingnumber
- 줄 간격 배율. (글자 크기에 곱한다, 0.1 보다 작으면 0.1, 처음은 1.25)Line spacing scale. (multiplied by the font size, 0.1 if less than 0.1, initially 1.25)
짝Counterpart: vanilla-engine RichText.set_line_spacing
줄 간격 배율 반환.
Returns the line spacing multiplier.
반환Returnsnumber 줄 간격 배율.Line spacing scale.
짝Counterpart: vanilla-engine RichText.get_line_spacing
글자 간격 설정. (CSS letter-spacing, 언리얼 UMG 글자 간격과 같은 뜻)
Sets the letter spacing. (same meaning as CSS letter-spacing and Unreal UMG letter spacing)
- letterSpacingnumber
- 글자 묶음마다 뒤에 더하는 간격. (픽셀, 음수는 좁힘, 처음은 0)Spacing added after each grapheme cluster. (pixels, negative narrows, initially 0)
짝Counterpart: vanilla-engine RichText.set_letter_spacing
글자 간격 반환.
Returns the letter spacing.
반환Returnsnumber 글자 간격. (픽셀, 처음은 0)Letter spacing. (pixels, initially 0)
짝Counterpart: vanilla-engine RichText.get_letter_spacing
표시 글자 수 설정. (-1 이면 전체, 타자기 연출용. 글자 묶음 단위)
Sets the display character count. (-1 for all, for typewriter effects. In grapheme clusters)
- visibleCharacterCountnumber
- 표시 글자 수. (글자 묶음 단위, 내림, -1 보다 작으면 -1, -1 이면 전체)Visible character count. (in graphemes, floored, -1 if less than -1, everything if -1)
짝Counterpart: vanilla-engine RichText.set_visible_character_count
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());표시 글자 수 반환.
Returns the display character count.
반환Returnsnumber 표시 글자 수. (-1 이면 전체)Visible character count. (everything if -1)
짝Counterpart: vanilla-engine RichText.get_visible_character_count
텍스트 설정. (같은 글이면 아무것도 하지 않는다)
Sets the text. (does nothing if the text is the same)
- textstring
- 보일 글. (줄바꿈 문자에서 줄을 바꾼다)Text to show. (breaks lines at line break characters)
짝Counterpart: vanilla-engine Text.set_text
텍스트 크기 설정.
Sets the text size.
- fontSizenumber
- 글자 크기. (내용 크기 단위, 처음은 32)Font size. (content size units, initially 32)
짝Counterpart: vanilla-engine RichText.set_font_size
텍스트 크기 반환.
Returns the text size.
반환Returnsnumber 정한 글자 크기.The set font size.
짝Counterpart: vanilla-engine RichText.get_font_size
텍스트 색상 설정.
Sets the text color.
- colorColor | string | CanvasGradient | CanvasPattern
- 글 색. (Color 나 "#rrggbb(aa)", "rgb(a)(...)" 글, null 이나 undefined 면 투명, 그 밖의 값은 무시한다)Text color. (a Color or a "#rrggbb(aa)" or "rgb(a)(...)" string, transparent if null or undefined, other values are ignored)
짝Counterpart: vanilla-engine RichText.set_text_color
텍스트 색상 반환.
Returns the text color.
반환ReturnsColor 글 색.Text color.
짝Counterpart: vanilla-engine RichText.get_text_color
텍스트 외곽선 색상 설정.
Sets the text outline color.
- colorColor | string | CanvasGradient | CanvasPattern
- 외곽선 색. (Color 나 "#rrggbb(aa)", "rgb(a)(...)" 글, null 이나 undefined 면 투명, 그 밖의 값은 무시한다)Stroke color. (a Color or a "#rrggbb(aa)" or "rgb(a)(...)" string, transparent if null or undefined, other values are ignored)
짝Counterpart: vanilla-engine RichText.set_stroke_color
텍스트 외곽선 색상 반환.
Returns the text outline color.
반환ReturnsColor 외곽선 색.Stroke color.
짝Counterpart: vanilla-engine RichText.get_stroke_color
텍스트 외곽선 두께 설정.
Sets the text outline thickness.
- widthnumber
- 외곽선 두께. (내용 크기 단위, 0 이하면 외곽선을 그리지 않는다)Stroke width. (content size units, no stroke if 0 or less)
짝Counterpart: vanilla-engine RichText.set_stroke_width
외곽선 두께 반환.
Returns the outline thickness.
반환Returnsnumber 외곽선 두께.Stroke width.
짝Counterpart: vanilla-engine RichText.get_stroke_width
볼드 여부 설정.
Sets whether bold.
- boldboolean
- 굵게 할지. (true 일 때만 굵게)Whether bold. (bold only when true)
짝Counterpart: vanilla-engine RichText.set_bold
볼드 여부 반환.
Returns whether bold.
반환Returnsboolean 굵게면 참.True if bold.
짝Counterpart: vanilla-engine RichText.is_bold
이탤릭 여부 설정.
Sets whether italic.
- italicboolean
- 기울일지. (true 일 때만 기울인다)Whether italic. (italic only when true)
짝Counterpart: vanilla-engine RichText.set_italic
이탤릭 여부 반환.
Returns whether italic.
반환Returnsboolean 기울임이면 참.True if italic.
짝Counterpart: vanilla-engine RichText.is_italic
밑줄 여부 설정.
Sets whether underlined.
- underlineboolean
- 밑줄을 그을지. (true 일 때만 긋는다)Whether to underline. (only when true)
짝Counterpart: vanilla-engine RichText.set_underline
밑줄 여부 반환.
Returns whether underlined.
반환Returnsboolean 밑줄이면 참.True if underlined.
짝Counterpart: vanilla-engine RichText.is_underline
취소선 여부 설정.
Sets whether strikethrough.
- strikethroughboolean
- 취소선을 그을지. (true 일 때만 긋는다)Whether to strike through. (only when true)
짝Counterpart: vanilla-engine RichText.set_strikethrough
취소선 여부 반환.
Returns whether strikethrough.
반환Returnsboolean 취소선이면 참.True if struck through.
짝Counterpart: vanilla-engine RichText.is_strikethrough
폰트 가로 정렬 설정.
Sets the font horizontal alignment.
- align"left" | "center" | "right" | "start" | "end"
- 가로 정렬. ("start", "end" 는 글 방향을 따른다, 처음은 "center")Horizontal alignment. ("start" and "end" follow the text direction, initially "center")
짝Counterpart: vanilla-engine RichText.set_text_align
폰트 가로 정렬 반환.
Returns the font horizontal alignment.
반환Returnsstring 가로 정렬. ("left", "center", "right", "start", "end")Horizontal alignment. ("left", "center", "right", "start", "end")
짝Counterpart: vanilla-engine RichText.get_text_align
글자 방향 설정. ("inherit" | "ltr" | "rtl" | "auto", Graphic.setTextDirection 과 같다)
- "inherit" 면 그리는 때의 Graphic 방향을 따른다. (기본)
- 정렬 "start" / "end" 가 이 방향에 따라 왼쪽, 오른쪽이 된다. (오른쪽에서 왼쪽 언어의 화면은 "rtl" 과 "start")
Sets the text direction. ("inherit" | "ltr" | "rtl" | "auto", same as Graphic.setTextDirection)
- "inherit" follows the Graphic direction at draw time. (default)
- Alignment "start" / "end" becomes left or right according to this direction. (screens in right-to-left languages use "rtl" and "start")
- textDirection"inherit" | "ltr" | "rtl" | "auto"
- 글자 방향. (처음은 "inherit")Text direction. (initially "inherit")
짝Counterpart: vanilla-engine RichText.set_text_direction
글자 방향 반환.
Returns the text direction.
반환Returnsstring 글자 방향. ("inherit", "ltr", "rtl", "auto")Text direction. ("inherit", "ltr", "rtl", "auto")
짝Counterpart: vanilla-engine RichText.get_text_direction
폰트 세로 정렬 설정.
Sets the font vertical alignment.
- baseline"top" | "middle" | "bottom" | "alphabetic" | "hanging" | "ideographic"
- 세로 정렬. (여러 줄 글은 줄 묶음의 세로 자리로 쓴다, 처음은 "middle")Vertical alignment. (for multi-line text, used as the vertical position of the line block, initially "middle")
짝Counterpart: vanilla-engine RichText.set_text_baseline
폰트 세로 정렬 반환.
Returns the font vertical alignment.
반환Returnsstring 세로 정렬.Vertical alignment.
짝Counterpart: vanilla-engine RichText.get_text_baseline
함수Functions
글자 묶음으로 나누기. (Intl.Segmenter 가 없으면 코드 포인트 단위)
Splits into graphemes. (by code point if Intl.Segmenter is unavailable)
- textstring
- 나눌 글.Text to split.
반환Returnsstring[] 글자 묶음 목록.List of graphemes.
짝Counterpart: vanilla-engine split_graphemes
단어로 나누기. (Intl.Segmenter 가 없으면 글 통째로 한 조각)
Splits into words. (the whole text as one piece if Intl.Segmenter is unavailable)
- textstring
- 나눌 글.Text to split.
반환Returnsstring[] 단어마다 한 조각. (단어가 아닌 조각은 앞 단어에 붙인다, 줄바꿈 없는 빈칸으로 이은 단어는 한 조각)One piece per word. (non-word pieces attach to the preceding word; words joined by non-breaking spaces are one piece)
짝Counterpart: vanilla-engine split_words
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"));글자 묶음 수. (표시 글자 수가 세는 단위, 받침, 결합 부호, 이모지 묶음을 한 자로)
Grapheme cluster count. (the unit the display character count counts; final consonants, combining marks and emoji clusters count as one character)
- textstring
- 셀 글.Text to count.
반환Returnsnumber 글자 묶음 수.Number of graphemes.
짝Counterpart: vanilla-engine count_graphemes
앞에서 글자 묶음 count 개까지의 글. (글이 짧으면 글 전체)
Text up to the first count grapheme clusters. (the whole text if it is shorter)
- textstring
- 자를 글.Text to slice.
- countnumber
- 남길 글자 묶음 수.Number of graphemes to keep.
반환Returnsstring 앞에서 count 개까지의 글. (글이 짧으면 글 그대로)Text up to the first count graphemes. (the text as is if shorter)
짝Counterpart: vanilla-engine slice_graphemes
TextAlignenum
텍스트 수평 설정. (CanvasTextAlign)
Sets the horizontal text alignment. (CanvasTextAlign)
| 이름Name | 값Value | 설명Description |
|---|---|---|
left | left | 왼쪽 맞춤. (내용 왼쪽 끝에 놓는다)Left aligned. (placed at the left edge of the content) |
center | center | 가운데 맞춤. (내용 가로 가운데에 놓는다)Center aligned. (placed at the horizontal center of the content) |
right | right | 오른쪽 맞춤. (내용 오른쪽 끝에 놓는다)Right aligned. (placed at the right edge of the content) |
start | start | 글 방향의 시작 쪽 맞춤. ("ltr" 은 왼쪽, "rtl" 은 오른쪽)Aligned to the start side of the text direction. (left for "ltr", right for "rtl") |
end | end | 글 방향의 끝 쪽 맞춤. ("ltr" 은 오른쪽, "rtl" 은 왼쪽)Aligned to the end side of the text direction. (right for "ltr", left for "rtl") |
TextBaselineenum
텍스트 수직 설정. (CanvasTextBaseline)
Sets the vertical text alignment. (CanvasTextBaseline)
| 이름Name | 값Value | 설명Description |
|---|---|---|
top | top | 글의 위 끝 기준. (내용 위 끝에 놓는다)Top of the text. (placed at the top edge of the content) |
middle | middle | 글의 가운데 기준. (내용 세로 가운데에 놓는다)Middle of the text. (placed at the vertical center of the content) |
bottom | bottom | 글의 아래 끝 기준. (내용 아래 끝에 놓는다)Bottom of the text. (placed at the bottom edge of the content) |
ideographic | ideographic | 표의 문자 기준선. (내용 아래 끝에 놓는다)Ideographic baseline. (placed at the bottom edge of the content) |
hanging | hanging | 매달린 기준선. (내용 위 끝에 놓는다)Hanging baseline. (placed at the top edge of the content) |
alphabetic | alphabetic | 알파벳 기준선. (내용 아래 끝에 놓는다)Alphabetic baseline. (placed at the bottom edge of the content) |