core/component/shadowtext
그림자를 깐 한 줄 글.
Single-line text with a shadow.
ShadowTextextends Component
그림자를 깐 한 줄 글.
- 글자 노드 두 벌(같은 글을 검게 밑에, 글을 위에)로 그림자를 깔면 둘이 따로 비쳐, 노드를 흐리게 할 때 흐린 글 사이로 밑의 그림자가 보인다. 이 컴포넌트는 그림자 위에 글을 얹은 모습을 캔버스 한 장에 구워 그 한 장을 그리므로, 노드의 불투명도가 글과 그림자에 한 장째로 먹는다.
- 가로 정렬과 놓는 자리는 Graphic.drawTextEntry 와 같은 셈이다. 세로는 노드의 가운데다.
- 글이 노드 너비를 넘으면 처음 크기에서 최소 비율(setFitMinimumRatio)까지 줄여 맞춘다.
- 그리는 배율(기기의 DPR, 뷰 배율), 글, 꼴, 노드 너비가 바뀌거나 웹 글꼴의 조각이 새로 받아지면 다시 굽는다.
- 그림자는 캔버스의 그림자로 칠해 번지게 할 수 있다. 번지는 만큼 구운 캔버스의 가장자리를 넓힌다.
- 기울임, 밑줄, 취소선(setItalic, setUnderline, setStrikethrough): 선의 자리, 두께는 Text 의 가운데 기준선과 같고, 선도 글과 함께 구워 그림자가 깔린다.
- 글 방향은 "ltr", "rtl", "auto"(글의 첫 강한 글자로) 이다.
Single-line text with a shadow.
- Laying a shadow with two text nodes (the same text in black below, the text on top) makes the two show through separately, so when the node is faded the shadow beneath shows through the faded text. This component bakes the look of the text placed over the shadow into one canvas and draws that single sheet, so the node's opacity applies to the text and shadow as one sheet.
- Horizontal alignment and placement use the same calculation as Graphic.drawTextEntry. Vertically it is the node's center.
- If the text exceeds the node width, it shrinks from the initial size down to the minimum ratio (setFitMinimumRatio) to fit.
- Rebakes when the draw scale (device DPR, view scale), text, style or node width changes, or when a new web font chunk is downloaded.
- The shadow can be painted with the canvas shadow so that it blurs. The baked canvas edge is widened by the blur amount.
- Italic, underline, strikethrough (setItalic, setUnderline, setStrikethrough): the line position and thickness are the same as Text's middle baseline, and the lines are baked together with the text so the shadow lies beneath them too.
- Text direction is "ltr", "rtl", "auto" (by the first strong character of the text).
import { Engine, EngineConfiguration, Scene, Vector2, WorldNode, ShadowText, 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 titleNode = new WorldNode();
titleNode.setContentSize(Vector2.create(400, 60));
titleNode.setLocalPosition(Vector2.create(320, 180));
const shadowText = titleNode.addComponent(ShadowText);
shadowText.setFontFace(fontAsset.fontFace);
shadowText.setTextStyle(40, true, "#ffffff");
shadowText.setShadow("#000000", 0.8, 3, 4);
shadowText.setText("Vanilla Engine");
const root = this.getRoot();
root.addChild(titleNode);
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());그리는 사각형을 rect 에 적기. (오버라이드: 정렬로 놓은 글에 그림자의 번짐과 내림을 더한 사각형, 화면 밖 거르기와 하위 트리 그리기 경계가 쓴다)
- 가로는 처음 글꼴 크기로 잰 글 너비(넘쳐 줄여도 이보다 좁다)를 정렬대로 놓고, 글꼴 크기의 반과 번짐의 두 배만큼 양옆에 더한다. "start" 와 "end" 는 그릴 때의 방향으로 왼쪽이나 오른쪽이 되므로 둘 다 품는다.
- 세로는 내용 높이의 가운데에서 위아래로 글꼴 크기의 1.5 배와 번짐의 두 배씩, 아래는 그림자 내림만큼 더 잡는다. (밑줄, 취소선도 이 안) (캔버스 shadowBlur 는 표준 편차 blur / 2 의 가우스라 꼬리가 1.5 배까지 간다, 굽는 칸의 여유와 같이 두 배)
- 글이 없으면 크기 0. 잴 수 없으면 false. (거르지 않는다)
Writes the drawn rectangle to rect. (Override: the aligned text grown by the shadow's blur and offset; used by off-screen culling and subtree draw bounds)
- Horizontally, the text width measured at the initial font size (fitting only makes it narrower) is placed by alignment and grown by half the font size plus twice the blur on both sides. "start" and "end" become left or right depending on the direction at draw time, so both are covered.
- Vertically, from the middle of the content height up and down by 1.5 times the font size plus twice the blur, and further down by the shadow offset. (Underline and strikethrough fit inside) (Canvas shadowBlur is a Gaussian with standard deviation blur / 2 whose tail reaches 1.5 times; twice, matching the bake padding)
- Size 0 when there is no text. 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)
import { WorldNode, ShadowText, Rect, Vector2 } from "./build/vanilla.js";
const node = new WorldNode();
node.setContentSize(Vector2.create(120, 30));
const shadowText = node.addComponent(ShadowText);
shadowText.setText("SCORE");
shadowText.setShadow("#000000", 0.8, 3, 4);
const drawnRect = Rect.zero();
const isKnown = shadowText.calculateDrawnRect(drawnRect);
console.log(isKnown, drawnRect.size.y > 30);노드에서 떨어짐. (나눠 쓰던 구운 그림을 놓는다)
Detached from a node. (releases the shared baked image)
- nodeComponentNode
- 떨어지는 노드.The node being detached.
굽기. (글을 한 번 칠하면 캔버스가 그 밑에 그림자를 먼저 칠한다)
- 텍스처 캐시가 캔버스마다 한 번 올리므로 구울 때마다 새 캔버스를 만든다. (앞의 것은 수거되며 텍스처도 함께 수거된다)
Bake. (painting the text once makes the canvas paint the shadow beneath it first)
- Creates a new canvas on every bake, since the texture cache uploads once per canvas. (the previous one is collected, and its texture is collected with it)
- graphicGraphic
- 그래픽. (처음 크기의 글 너비를 잰다)Graphics. (measures the text width at the initial size)
- textstring
- 구울 글.Text to bake.
- fitWidthnumber
- 맞출 너비. (0 이하면 맞추지 않는다)Width to fit. (no fitting if 0 or less)
- bakeScalenumber
- 굽는 배율. (Graphic.calculateTextBakeScale)Bake scale. (Graphic.calculateTextBakeScale)
- textDirectionstring
- 굽는 방향. ("ltr" 또는 "rtl")Bake direction. ("ltr" or "rtl")
- fontFaceFontFace | null
- 글꼴. (null 이면 시스템 글꼴)Font. (system font if null)
글 너비 재기. (처음 크기로, Text 와 같은 재기, 내용 크기 단위)
Measures the text width. (at the initial size, same measurement as Text, in content-size units)
- graphicGraphic
- 그래픽. (글 재기 캐시를 쓴다)Graphics. (uses its text measure cache)
반환Returnsnumber 글 너비. (내용 크기 단위, 글이 비었으면 0)Text width. (content size units, 0 if the text is empty)
글 설정.
Sets the text.
- textstring
- 보일 한 줄 글.Single line of text to show.
짝Counterpart: vanilla-engine ShadowText.set_text
글꼴 설정. (null 이면 시스템 글꼴)
Sets the font. (system font if null)
- fontFaceFontFace | null
- 글꼴. (null 이면 시스템 글꼴)Font. (system font if null)
글꼴 반환.
Returns the font.
반환ReturnsFontFace | null 글꼴. (null 이면 시스템 글꼴)Font. (system font if null)
글의 꼴 설정. (처음 크기, 굵기, 색)
Sets the text style. (initial size, weight, color)
- fontSizenumber
- 처음 글자 크기. (내용 크기 단위, 넘치면 줄여 굽는다)Initial font size. (content size units, baked smaller when it overflows)
- isBoldboolean
- 굵게 할지.Whether bold.
- textColorColor | string
- 글 색. (Color 나 "#rrggbb" 같은 색 글, 알파가 글자 불투명도)Text colour. (a Color or a colour string such as "#rrggbb", the alpha is the text opacity)
짝Counterpart: vanilla-engine ShadowText.set_text_style
처음 글자 크기 반환.
Returns the initial font size.
반환Returnsnumber 처음 글자 크기.Initial font size.
짝Counterpart: vanilla-engine ShadowText.get_font_size
가로 정렬 설정.
Sets the horizontal alignment.
- textAlignstring
- "left", "center", "right", "start", "end"
짝Counterpart: vanilla-engine ShadowText.set_text_align
가로 정렬 반환.
Returns the horizontal alignment.
반환Returnsstring 가로 정렬. ("left", "center", "right", "start", "end")Horizontal alignment. ("left", "center", "right", "start", "end")
짝Counterpart: vanilla-engine ShadowText.get_text_align
글 방향 설정. ("ltr", "rtl", "auto")
Sets the text direction. ("ltr", "rtl", "auto")
- textDirectionstring
- 글 방향. ("ltr", "rtl", "auto", 그 밖의 값은 "ltr" 로 굽는다)Text direction. ("ltr", "rtl", "auto", other values bake as "ltr")
짝Counterpart: vanilla-engine ShadowText.set_text_direction
글 방향 반환.
Returns the text direction.
반환Returnsstring 글 방향. ("ltr", "rtl", "auto")Text direction. ("ltr", "rtl", "auto")
짝Counterpart: vanilla-engine ShadowText.get_text_direction
굽는 실제 방향. ("rtl" 이면 오른쪽에서 왼쪽, "auto" 는 글의 첫 강한 글자로, 그 밖은 "ltr")
Actual baking direction. ("rtl" is right to left, "auto" uses the first strong character of the text, anything else is "ltr")
반환Returnsstring "ltr" 또는 "rtl"."ltr" or "rtl".
굵게 여부.
Whether bold.
반환Returnsboolean 굵게면 참.True if bold.
짝Counterpart: vanilla-engine ShadowText.is_bold
기울임 설정.
Sets italic.
- isItalicboolean
- 기울일지. (true 일 때만 기울인다)Whether italic. (italic only when true)
짝Counterpart: vanilla-engine ShadowText.set_italic
기울임 여부.
Whether italic.
반환Returnsboolean 기울임이면 참.True if italic.
짝Counterpart: vanilla-engine ShadowText.is_italic
밑줄 설정.
Sets underline.
- isUnderlineboolean
- 밑줄을 그을지. (true 일 때만 긋는다)Whether to underline. (only when true)
짝Counterpart: vanilla-engine ShadowText.set_underline
밑줄 여부.
Whether underlined.
반환Returnsboolean 밑줄이면 참.True if underlined.
짝Counterpart: vanilla-engine ShadowText.is_underline
취소선 설정.
Sets strikethrough.
- isStrikethroughboolean
- 취소선을 그을지. (true 일 때만 긋는다)Whether to strike through. (only when true)
짝Counterpart: vanilla-engine ShadowText.set_strikethrough
취소선 여부.
Whether strikethrough.
반환Returnsboolean 취소선이면 참.True if struck through.
짝Counterpart: vanilla-engine ShadowText.is_strikethrough
그림자 설정. (색, 불투명도, 글 아래로 내려가는 만큼, 번지는 만큼)
Sets the shadow. (color, opacity, offset below the text, blur amount)
- shadowColorColor | string
- 그림자 색. (Color 나 "#rrggbb" 같은 색 글, 알파는 읽지 않는다)Shadow colour. (a Color or a colour string such as "#rrggbb", the alpha is not read)
- shadowOpacitynumber
- 그림자 불투명도. (0 ~ 1)Shadow opacity. (0 ~ 1)
- shadowOffsetnumber
- 그림자가 글 아래로 내려가는 만큼. (내용 크기 단위)How far the shadow drops below the text. (content size units)
- shadowBlurnumber
- 0 이면 번지지 않는다.No blur if 0.
짝Counterpart: vanilla-engine ShadowText.set_shadow
넘칠 때 줄이는 가장 작은 비율 설정. (1 이면 줄이지 않는다)
Sets the minimum ratio to shrink to on overflow. (no shrinking if 1)
- fitMinimumRationumber
- 넘칠 때 줄이는 가장 작은 비율. (0.01 ~ 1 로 자른다, 1 이면 줄이지 않는다)Smallest ratio to shrink to when overflowing. (clamped to 0.01 ~ 1, no shrinking if 1)
짝Counterpart: vanilla-engine ShadowText.set_fit_minimum_ratio
넘칠 때 줄이는 가장 작은 비율 반환.
Returns the minimum ratio to shrink to on overflow.
반환Returnsnumber 넘칠 때 줄이는 가장 작은 비율.Smallest ratio to shrink to when overflowing.
짝Counterpart: vanilla-engine ShadowText.get_fit_minimum_ratio
구운 캔버스 반환. (아직 굽지 않았으면 null)
Returns the baked canvas. (null if not baked yet)
반환ReturnsHTMLCanvasElement | null 구운 캔버스. (아직 굽지 않았으면 null)The baked canvas. (null if not baked yet)