You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/manuals/font.md
+67-38Lines changed: 67 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,27 @@ Fonts added to your project are automatically converted into a texture format th
16
16
- Bitmap
17
17
- Distance field
18
18
19
+
## Offline or Runtime fonts
20
+
21
+
By default, the conversion to rasterized glyph images happens at build time (offline). This has the drawback that each font needs to rasterize all possible glyphs in the build stage, producing potentially very large textures that consume memory and also increase the bundle size.
22
+
23
+
By using "runtime fonts", the .ttf fonts will be bundled as-is, and the rasterization will happen on-demand at runtime. This minimizes both runtime memory usage and the bundle size.
24
+
25
+
## Text layout support (e.g. Right-to-left)
26
+
27
+
The runtime fonts also have the benefit of supporting full text layout, e.g. right-to-left.
28
+
We currently use the libraries [HarfBuzz](https://github.com/harfbuzz/harfbuzz), [SheenBidi](https://github.com/Tehreer/SheenBidi), [libunibreak](https://github.com/adah1972/libunibreak) and [SkriBidi](https://github.com/memononen/Skribidi).
29
+
30
+
See [Enabling Runtime Fonts](/manuals/font#enabling-runtime-fonts)
31
+
32
+
## Font collection
33
+
34
+
The `.fontc` file format is also known as a font collection. In offline mode, only one font is associated with it.
35
+
When using runtime fonts, you can associate more than one font file (.ttf) with the font collection.
36
+
37
+
This allows for using the a font collection when rendering multiple texts in different languages, while also keeping the memory foot print low.
38
+
E.g. loading a collection with the japanese font, then associate that font with the current main font, followed by unloading the japanese font collection.
39
+
19
40
## Creating a font
20
41
21
42
To create a font for use in Defold, create a new Font file by selecting <kbd>File ▸ New...</kbd> from the menu, then select <kbd>Font</kbd>. You can also <kbd>right click</kbd> a location in the *Assets* browser and select <kbd>New... ▸ Font</kbd>.
@@ -81,6 +102,8 @@ Shadow support is enabled by the built-in font material shaders and handles both
81
102
*Characters*
82
103
: Which characters to include in the font. By default this field include the ASCII printable characters (character codes 32-126). You can add or remove characters from this field to include more or less characters in the font..
83
104
105
+
For runtime fonts, this text acts as a cache prewarming with the correct glyphs. This happens during load time. See `font.prewarm_text()`.
106
+
84
107
::: sidenote
85
108
The ASCII printable characters are:
86
109
space ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ \` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
@@ -163,23 +186,29 @@ For example - to generate a gradient in a shader fragment, simply write:
163
186
164
187
For more information about shader uniforms, see the [Shader manual](/manuals/shader).
165
188
166
-
## Runtime generation
189
+
## Enabling Runtime Fonts
167
190
168
191
It is possible to use runtime generation for SDF type fonts, when using TrueType (.ttf) fonts.
169
192
This approach can greatly reduce the download size and runtime memory consumption of a Defold game.
170
-
The small downside is a very small delay for each glyph generated at runtime.
193
+
The small downside is the asynchronous nature of generating each glyph.
194
+
195
+
* Enable the feature by setting `font.runtime_generation` in game.project.
171
196
172
-
Enable the feature by setting `font.runtime_generation` in game.project.
197
+
* Add an [App Manifest](/manuals/app-manifest) and enable the `Use full text layout system` option.
198
+
This builds a custom engine that has this feature enabled.
173
199
174
200
::: sidenote
175
201
This feature is currently experimental, but with the intention to be used as the default workflow in the future.
176
202
:::
177
203
178
204
::: important
179
-
This setting affects all .ttf fonts in the project.
205
+
The `font.runtime_generation` setting affects all .ttf fonts in the project.
180
206
:::
181
207
182
-
### Prewarming glyph cache
208
+
209
+
### Font Scripting
210
+
211
+
#### Prewarming glyph cache
183
212
184
213
In order to make the runtime fonts easier to use, they support prewarming of the glyph cache.
185
214
This means the font will generate the glyphs listed in *Characters* in the font.
@@ -188,53 +217,53 @@ This means the font will generate the glyphs listed in *Characters* in the font.
188
217
If `All Chars` is selected, there will be no prewarming as it defeats the purpose of not having to generate all glyphs at the same time.
189
218
:::
190
219
191
-
### Font Scripting
220
+
If the `Characters` field of the `.fontc` file is set, this is used as a text, to figure out which glyphs needs to be updated in the glyph cache.
221
+
222
+
It is also possible to manually update the glyph cache by calling `font.prewarm_text(font_collection, text, callback)`. It provides a callback to let you know when all the missing glyphs have been added to the glyph cache, and it's safe to present the text on screen.
223
+
224
+
### Adding/removing fonts to a font collection
192
225
193
-
For runtime fonts, it's possible to add or removed sub fonts.
226
+
For runtime fonts, it's possible to add or remove fonts (.ttf) to a font collection.
194
227
This is useful when a large font has been split up into multiple files for different character sets (e.g. CJK)
195
228
196
229
::: important
197
-
Adding a subfont doesn't automatically load or render all the glyphs.
230
+
Adding a font to a font collection doesn't automatically load or render all the glyphs.
0 commit comments