Skip to content

Commit

Permalink
Added SDF font.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Dec 12, 2024
1 parent 5295bb6 commit 5a17a69
Show file tree
Hide file tree
Showing 41 changed files with 2,910 additions and 1,419 deletions.
25 changes: 24 additions & 1 deletion Assets/Script/Lib/Dora/en/Dora.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6296,6 +6296,21 @@ class Label extends Node {
*/
spacing: number;

/**
* The color of the outline, only works with SDF label.
*/
outlineColor: Color;

/**
* The width of the outline, only works with SDF label.
*/
outlineWidth: number;

/**
* The smooth value of the text, only works with SDF label, default is (0.7, 0.7).
*/
smooth: Vec2;

/**
* The text to be rendered.
*/
Expand Down Expand Up @@ -6353,13 +6368,21 @@ interface LabelClass {
*/
readonly AutomaticWidth: number;

/**
* Creates a new Label object with the specified font string.
* @param fontStr The font string to use for the label. Should be in the format "fontName;fontSize;sdf", where `sdf` should be "true" or "false" and can be omitted as default is false.
* @returns The new Label object. Returns `null` if the font could not be loaded.
*/
(this: void, fontStr: string): Label | null;

/**
* Creates a new Label object with the specified font name and font size.
* @param fontName The name of the font to use for the label. Can be a font file path with or without a file extension.
* @param fontSize The size of the font to use for the label.
* @param sdf [optional] Whether to use SDF rendering or not. With SDF rendering, the outline feature will be enabled. (Default is false)
* @returns The new Label object. Returns `null` if the font could not be loaded.
*/
(this: void, fontName: string, fontSize: number): Label | null;
(this: void, fontName: string, fontSize: number, sdf?: boolean): Label | null;
}

const labelClass: LabelClass;
Expand Down
19 changes: 18 additions & 1 deletion Assets/Script/Lib/Dora/en/Label.d.tl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local Node = require("Node").Type
local BlendFunc = require("BlendFunc").Type
local SpriteEffect = require("SpriteEffect").Type
local Sprite = require("Sprite").Type
local Color = require("Color").Type
local Vec2 = require("Vec2").Type

-- A node for rendering text using a TrueType font.
local record Label
Expand Down Expand Up @@ -31,6 +33,15 @@ local record Label
-- The gap in pixels between characters.
spacing: number

-- The width of the outline, only works with SDF label.
outlineWidth: number

-- The color of the outline, only works with SDF label.
outlineColor: Color

-- The smooth value of the text, only works with SDF label, default is (0.7, 0.7).
smooth: Vec2

-- The text to be rendered.
text: string

Expand Down Expand Up @@ -66,12 +77,18 @@ local record LabelClass
-- The value to use for automatic width calculation
const AutomaticWidth: number

-- Creates a new Label object with the specified font string.
-- @param fontStr (string) The font string to use for the label. Should be in the format "fontName;fontSize;sdf", where `sdf` should be "true" or "false" and can be omitted as default is false.
-- @return (Label | nil) The new Label object, or `nil` if the font could not be loaded.
metamethod __call: function(self: LabelClass, fontStr: string): Label | nil

-- Creates a new Label object with the specified font name and font size.
-- @param fontName (string) The name of the font to use for the label.
-- Can be font file path with or without file extension.
-- @param fontSize (integer) The size of the font to use for the label.
-- @param sdf (boolean) [optional] Whether to use SDF rendering or not. With SDF rendering, the outline feature will be enabled. (Default is false)
-- @return (Label | nil) The new Label object, or `nil` if the font could not be loaded.
metamethod __call: function(self: LabelClass, fontName: string, fontSize: integer): Label | nil
metamethod __call: function(self: LabelClass, fontName: string, fontSize: integer, sdf?: boolean): Label | nil
end

local labelClass: LabelClass
Expand Down
25 changes: 25 additions & 0 deletions Assets/Script/Lib/Dora/en/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ class Label extends Node {
*/
fontSize: number;

/**
* Whether to use SDF rendering or not. With SDF rendering, the outline feature will be enabled.
*/
sdf?: boolean;

/**
* The alpha threshold value. Pixels with alpha values below this value will not be drawn.
* Only works with `label.effect = SpriteEffect("builtin:vs_sprite", "builtin:fs_spritealphatest")`.
Expand All @@ -676,6 +681,26 @@ class Label extends Node {
*/
spacing?: number;

/**
* The color of the outline, only works with SDF label.
*/
outlineColor?: number;

/**
* The width of the outline, only works with SDF label.
*/
outlineWidth?: number;

/**
* The smooth lower value of the text, only works with SDF label, default is 0.7.
*/
smoothLower?: number;

/**
* The smooth upper value of the text, only works with SDF label, default is 0.7.
*/
smoothUpper?: number;

/**
* The text to be rendered.
*/
Expand Down
25 changes: 24 additions & 1 deletion Assets/Script/Lib/Dora/zh-Hans/Dora.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6297,6 +6297,21 @@ class Label extends Node {
*/
spacing: number;

/**
* 描边颜色,仅适用于SDF标签。
*/
outlineColor: Color;

/**
* 描边宽度,仅适用于SDF标签
*/
outlineWidth: number;

/**
* 文本的平滑值,仅适用于SDF标签,默认是 (0.7, 0.7)。
*/
smooth: Vec2;

/**
* 要渲染的文本。
*/
Expand Down Expand Up @@ -6354,13 +6369,21 @@ interface LabelClass {
*/
readonly AutomaticWidth: number;

/**
* 使用指定的字体字符串创建新的 Label 对象。
* @param fontStr 用于创建 Label 对象的字体字符串。应该以 "fontName;fontSize;sdf" 的格式表示,其中 `sdf` 应该是 "true" 或 "false",并且可以省略,默认是 false。
* @returns 新的 Label 对象,如果创建失败则返回 `null`。
*/
(this: void, fontStr: string): Label | null;

/**
* 使用指定的字体名称和字体大小创建新的 Label 对象。
* @param fontName 用于创建 Label 对象的字体名称。可以是带有或不带有文件扩展名的字体文件路径。
* @param fontSize 用于创建 Label 对象的字体大小。
* @param sdf [可选] 是否启用SDF渲染。启用SDF渲染后,描边功能将生效。(默认是false)
* @returns 新的 Label 对象,如果创建失败则返回 `null`。
*/
(this: void, fontName: string, fontSize: number): Label | null;
(this: void, fontName: string, fontSize: number, sdf?: boolean): Label | null;
}

const labelClass: LabelClass;
Expand Down
19 changes: 18 additions & 1 deletion Assets/Script/Lib/Dora/zh-Hans/Label.d.tl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local Node = require("Node").Type
local BlendFunc = require("BlendFunc").Type
local SpriteEffect = require("SpriteEffect").Type
local Sprite = require("Sprite").Type
local Color = require("Color").Type
local Vec2 = require("Vec2").Type

-- 使用TrueType字体渲染文本的场景节点类。
local record Label
Expand Down Expand Up @@ -31,6 +33,15 @@ local record Label
-- 文本行之间的像素间隔。
spacing: number

-- 描边颜色,仅适用于SDF标签。
outlineColor: Color

-- 描边宽度,仅适用于SDF标签。
outlineWidth: number

-- 文本的平滑值,仅适用于SDF标签,默认是 (0.7, 0.7)。
smooth: Vec2

-- 要渲染的文本。
text: string

Expand Down Expand Up @@ -66,12 +77,18 @@ local record LabelClass
-- 用于自动计算宽度的设置常量。
const AutomaticWidth: number

-- 使用指定的字体字符串创建新的文本标签对象。
-- @param fontStr (string) 用于标签的字体字符串。应该以 "fontName;fontSize;sdf" 的格式表示,其中 `sdf` 应该是 "true" 或 "false",并且可以省略,默认是 false
-- @return (Label | nil) 新的文本标签对象,如果创建失败则返回 `nil`。
metamethod __call: function(self: LabelClass, fontStr: string): Label | nil

-- 使用指定的字体名称和字体大小创建新的文本标签对象。
-- @param fontName (string) 用于标签的字体名称。
-- 可以是带有或是不带文件扩展名的字体文件路径。
-- @param fontSize (integer) 用于标签的字体大小。
-- @param sdf (boolean) [optional] 是否启用SDF渲染。启用SDF渲染后,描边功能将生效。(默认是false)
-- @return (Label | nil) 新的文本标签对象,如果创建失败则返回 `nil`。
metamethod __call: function(self: LabelClass, fontName: string, fontSize: integer): Label | nil
metamethod __call: function(self: LabelClass, fontName: string, fontSize: integer, sdf?: boolean): Label | nil
end

local labelClass: LabelClass
Expand Down
25 changes: 25 additions & 0 deletions Assets/Script/Lib/Dora/zh-Hans/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ class Label extends Node {
*/
fontSize: number;

/**
* 是否启用SDF渲染。启用SDF渲染后,描边功能将生效。
*/
sdf?: boolean;

/**
* 要渲染的文本。
*/
Expand Down Expand Up @@ -681,6 +686,26 @@ class Label extends Node {
*/
spacing?: number;

/**
* 描边颜色,仅适用于SDF标签。
*/
outlineColor?: number;

/**
* 描边宽度,仅适用于SDF标签。
*/
outlineWidth?: number;

/**
* 文本的 lower 平滑值,仅适用于SDF标签,默认是 0.7。
*/
smoothLower?: number;

/**
* 文本的 upper 平滑值,仅适用于SDF标签,默认是 0.7。
*/
smoothUpper?: number;

/**
* 用于渲染文本的混合函数。
*/
Expand Down
Loading

0 comments on commit 5a17a69

Please sign in to comment.