Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-channel SDF font generation and rendering support. #44772

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ Comment: YUV2RGB
Copyright: 2008-2011, Robin Watts
License: BSD-2-clause

Files: ./thirdparty/msdfgen/
Comment: Multi-channel signed distance field generator
Copyright: 2016, Viktor Chlumsky
License: MIT

Files: ./thirdparty/nanosvg/
Comment: NanoSVG
Copyright: 2013-2014, Mikko Mononen
Expand Down
1 change: 1 addition & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ opts.Add(BoolVariable("builtin_certs", "Use the built-in SSL certificates bundle
opts.Add(BoolVariable("builtin_embree", "Use the built-in Embree library", True))
opts.Add(BoolVariable("builtin_enet", "Use the built-in ENet library", True))
opts.Add(BoolVariable("builtin_freetype", "Use the built-in FreeType library", True))
opts.Add(BoolVariable("builtin_msdfgen", "Use the built-in MSDFgen library", True))
opts.Add(BoolVariable("builtin_glslang", "Use the built-in glslang library", True))
opts.Add(BoolVariable("builtin_graphite", "Use the built-in Graphite library", True))
opts.Add(BoolVariable("builtin_harfbuzz", "Use the built-in HarfBuzz library", True))
Expand Down
14 changes: 14 additions & 0 deletions doc/classes/CanvasItem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@
Draws a [Mesh] in 2D, using the provided texture. See [MeshInstance2D] for related documentation.
</description>
</method>
<method name="draw_msdf_texture_rect_region">
<return type="void" />
<argument index="0" name="texture" type="Texture2D" />
<argument index="1" name="rect" type="Rect2" />
<argument index="2" name="src_rect" type="Rect2" />
<argument index="3" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<argument index="4" name="outline" type="float" default="0.0" />
<argument index="5" name="pixel_range" type="float" default="4.0" />
<description>
Draws a textured rectangle region of the multi-channel signed distance field texture at a given position, optionally modulated by a color.
If [code]outline[/code] is positive, each alpha channel value of pixel in region is set to maximum value of true distance in the [code]outline[/code] radius.
Value of the [code]pixel_range[/code] should the same that was used during distance field texture generation.
</description>
</method>
<method name="draw_multiline">
<return type="void" />
<argument index="0" name="points" type="PackedVector2Array" />
Expand Down
157 changes: 134 additions & 23 deletions doc/classes/FontData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
<tutorials>
</tutorials>
<methods>
<method name="add_to_cache">
<return type="void" />
<argument index="0" name="var_id" type="String" />
<argument index="1" name="size" type="int" default="16" />
<argument index="2" name="outline_size" type="int" default="0" />
<description>
Adds new cache entry for specific variation and size. Use [method preload_range] to populate it with glpyhs.
Note: New cache entry is created automaticaly when it's first accessed.
</description>
</method>
<method name="bitmap_add_char">
<return type="void" />
<argument index="0" name="char" type="int" />
Expand All @@ -33,11 +43,17 @@
</method>
<method name="bitmap_add_texture">
<return type="void" />
<argument index="0" name="texture" type="Texture" />
<argument index="0" name="texture" type="Texture2D" />
<description>
Adds a texture to the bitmap font.
</description>
</method>
<method name="clear_cache">
<return type="void" />
<description>
Removes all loaded font sizes and variations from cache.
</description>
</method>
<method name="draw_glyph" qualifiers="const">
<return type="Vector2" />
<argument index="0" name="canvas" type="RID" />
Expand Down Expand Up @@ -65,6 +81,12 @@
Note: Glyph index is bound to the font data, use only glyphs indices returned by [method TextServer.shaped_text_get_glyphs] or [method get_glyph_index] for this font data.
</description>
</method>
<method name="get_antialiased" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code], if font 8-bit anitialiased glyph rendering is supported and enabled.
</description>
</method>
<method name="get_ascent" qualifiers="const">
<return type="float" />
<argument index="0" name="size" type="int" />
Expand All @@ -85,6 +107,24 @@
Returns the font descent (number of pixels below the baseline).
</description>
</method>
<method name="get_disable_distance_field_shader" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if distance field rendering shader is disabled.
</description>
</method>
<method name="get_distance_field_hint" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code], if fonts supports and uses distance field rendering.
</description>
</method>
<method name="get_force_autohinter" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if auto-hinting is supported and preffered over font built-in hinting.
</description>
</method>
<method name="get_glyph_advance" qualifiers="const">
<return type="Vector2" />
<argument index="0" name="index" type="int" />
Expand Down Expand Up @@ -112,13 +152,27 @@
Note: Glyph index is bound to the font data, use only glyphs indices returned by [method TextServer.shaped_text_get_glyphs] or [method get_glyph_index] for this font data.
</description>
</method>
<method name="get_glyph_size" qualifiers="const">
<return type="Vector2" />
<argument index="0" name="index" type="int" />
<argument index="1" name="size" type="int" />
<description>
Returns size of a glyph in pixels.
</description>
</method>
<method name="get_height" qualifiers="const">
<return type="float" />
<argument index="0" name="size" type="int" />
<description>
Returns the total font height (ascent plus descent) in pixels.
</description>
</method>
<method name="get_hinting" qualifiers="const">
<return type="int" enum="TextServer.Hinting" />
<description>
Returns the font hinitng mode.
</description>
</method>
<method name="get_language_support_override" qualifiers="const">
<return type="bool" />
<argument index="0" name="language" type="String" />
Expand All @@ -132,6 +186,18 @@
Returns list of language support overrides.
</description>
</method>
<method name="get_msdf_px_range" qualifiers="const">
<return type="float" />
<description>
Return the width of the range around the shape between the minimum and maximum representable signed distance.
</description>
</method>
<method name="get_oversampling" qualifiers="const">
<return type="float" />
<description>
Returns the font oversampling factor.
</description>
</method>
<method name="get_script_support_override" qualifiers="const">
<return type="bool" />
<argument index="0" name="script" type="String" />
Expand Down Expand Up @@ -216,8 +282,7 @@
<method name="load_memory">
<return type="void" />
<argument index="0" name="data" type="PackedByteArray" />
<argument index="1" name="type" type="String" />
<argument index="2" name="base_size" type="int" default="16" />
<argument index="1" name="base_size" type="int" default="16" />
<description>
Creates new font from the data in memory.
Note: For non-scalable fonts [code]base_size[/code] is ignored, use [method get_base_size] to check actual font size.
Expand All @@ -241,6 +306,15 @@
Creates new, empty bitmap font.
</description>
</method>
<method name="preload_range">
<return type="void" />
<argument index="0" name="start" type="int" />
<argument index="1" name="end" type="int" />
<argument index="2" name="glyphs" type="bool" />
<description>
Pre-renders character or glyph in range for all font sizes and variations in the cahce.
</description>
</method>
<method name="remove_language_support_override">
<return type="void" />
<argument index="0" name="language" type="String" />
Expand All @@ -255,6 +329,49 @@
Removes script support override.
</description>
</method>
<method name="save_cache" qualifiers="const">
<return type="int" enum="Error" />
<argument index="0" name="path" type="String" />
<argument index="1" name="flags" type="int" default="0" />
<description>
Saves rendered glyph textures, properties and font source data to file.
</description>
</method>
<method name="set_antialiased">
<return type="void" />
<argument index="0" name="antialiased" type="bool" />
<description>
If set to [code]true[/code], 8-bit antialiased glyph rendering is used, otherwise 1-bit rendering is used.
</description>
</method>
<method name="set_disable_distance_field_shader">
<return type="void" />
<argument index="0" name="disable" type="bool" />
<description>
If set to [code]true[/code], disables distance field rendering shader and renders raw MSDF RGBA values instead.
</description>
</method>
<method name="set_distance_field_hint">
<return type="void" />
<argument index="0" name="distance_field" type="bool" />
<description>
If set to [code]true[/code], MSDF font rendering is used.
</description>
</method>
<method name="set_force_autohinter">
<return type="void" />
<argument index="0" name="enabled" type="bool" />
<description>
If set to [code]true[/code] auto-hinting is preffered over font built-in hinting.
</description>
</method>
<method name="set_hinting">
<return type="void" />
<argument index="0" name="hinting" type="int" enum="TextServer.Hinting" />
<description>
Sets font hinitng mode.
</description>
</method>
<method name="set_language_support_override">
<return type="void" />
<argument index="0" name="language" type="String" />
Expand All @@ -263,6 +380,20 @@
Adds override for [method is_language_supported].
</description>
</method>
<method name="set_msdf_px_range">
<return type="void" />
<argument index="0" name="range" type="float" />
<description>
Sets the width of the range around the shape between the minimum and maximum representable signed distance.
</description>
</method>
<method name="set_oversampling">
<return type="void" />
<argument index="0" name="value" type="float" />
<description>
Sets oversampling factor, if set to [code]0.0[/code] global oversampling factor is used instead.
</description>
</method>
<method name="set_script_support_override">
<return type="void" />
<argument index="0" name="script" type="String" />
Expand All @@ -289,29 +420,9 @@
</method>
</methods>
<members>
<member name="antialiased" type="bool" setter="set_antialiased" getter="get_antialiased" default="false">
If [code]true[/code], the font is rendered with anti-aliasing.
</member>
<member name="data_path" type="String" setter="set_data_path" getter="get_data_path" default="&quot;&quot;">
The path to the font data file. If font data was loaded from memory location is set to [code]"(Memory)"[/code].
</member>
<member name="distance_field_hint" type="bool" setter="set_distance_field_hint" getter="get_distance_field_hint" default="false">
If [code]true[/code], distance field hint is enabled.
</member>
<member name="extra_spacing_glyph" type="int" setter="set_spacing" getter="get_spacing" default="0">
Extra spacing for each glyph in pixels.
This can be a negative number to make the distance between glyphs smaller.
</member>
<member name="extra_spacing_space" type="int" setter="set_spacing" getter="get_spacing" default="0">
Extra spacing for the space character in pixels.
This can be a negative number to make the distance between words smaller.
</member>
<member name="force_autohinter" type="bool" setter="set_force_autohinter" getter="get_force_autohinter" default="false">
If [code]true[/code], default autohinter is used for font hinting.
</member>
<member name="hinting" type="int" setter="set_hinting" getter="get_hinting" enum="TextServer.Hinting" default="0">
The font hinting mode used by FreeType. See [enum TextServer.Hinting] for options.
</member>
</members>
<constants>
<constant name="SPACING_GLYPH" value="0" enum="SpacingType">
Expand Down
Loading