gui_using_fonts.rst 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. .. _doc_gui_using_fonts:
  2. Using Fonts
  3. ===========
  4. Godot allows you to set specific fonts for different UI nodes.
  5. There are three different places where you can setup font usage.
  6. The first is the theme editor. Choose the node you want to set the
  7. font for and select the font tab. The second is in the inspector
  8. for control nodes under **Theme Overrides > Fonts**. Lastly, in
  9. the inspector settings for themes under **Default Font**.
  10. If no font override is specified anywhere,
  11. `Open Sans <https://fonts.google.com/specimen/Open+Sans>`__ SemiBold
  12. is used as the default project font.
  13. .. note::
  14. Since Godot 4.0, font sizes are no longer defined in the font itself but are
  15. instead defined in the node that uses the font. This is done in the
  16. **Theme Overrides > Font Sizes** section of the inspector.
  17. This allows changing the font size without having to duplicate the font
  18. resource for every different font size.
  19. There are 2 kinds of font files: *dynamic* (TTF/OTF/WOFF/WOFF2 formats) and
  20. *bitmap* (BMFont ``.fnt`` format or monospaced image). Dynamic fonts are the
  21. most commonly used option, as they can be resized and still look crisp at higher
  22. sizes. Thanks to their vector-based nature, they can also contain a lot more
  23. glyphs while keeping a reasonable file size compared to bitmap fonts. Dynamic
  24. fonts also support some advanced features that bitmap fonts cannot support, such
  25. as *ligatures* (several characters transforming into a single different design).
  26. .. tip::
  27. You can find freely licensed font files on websites such as `Google Fonts
  28. <https://fonts.google.com/>`__ and `Font Library
  29. <https://fontlibrary.org/>`__.
  30. Fonts are covered by copyright. Double-check the license of a font before
  31. using it, as not all fonts allow commercial use without purchasing a license.
  32. .. seealso::
  33. You can see how fonts work in action using the
  34. `BiDI and Font Features demo project <https://github.com/godotengine/godot-demo-projects/tree/master/gui/bidi_and_font_features>`__.
  35. Dynamic fonts
  36. -------------
  37. Godot supports the following dynamic font formats:
  38. - TrueType Font or Collection (``.ttf``, ``.ttc``)
  39. - OpenType Font or Collection (``.otf``, ``.otc``)
  40. - Web Open Font Format 1 (``.woff``)
  41. - Web Open Font Format 2 (``.woff2``, since Godot 3.5)
  42. While ``.woff`` and especially ``.woff2`` tend to result in smaller file sizes,
  43. there is no universally "better" font format. In most situations, it's
  44. recommended to use the font format that was shipped on the font developer's
  45. website.
  46. Bitmap fonts
  47. ------------
  48. Godot supports the BMFont (``.fnt``) bitmap font format. This is a format created
  49. by the `BMFont <https://www.angelcode.com/products/bmfont/>`__ program. Many
  50. BMFont-compatible programs also exist, like `BMGlyph <https://www.bmglyph.com/>`__.
  51. Alternatively, you can import any image to be used as a bitmap font. This is
  52. only supported for **monospaced** fonts (fonts where each character has the same
  53. width). To do so, select the image in the FileSystem dock, go to the
  54. Import dock, change its import type to **Font Data (Monospace Image Font)** then
  55. click **Reimport**:
  56. .. figure:: img/using_fonts_bitmap_font_from_image_import_options.webp
  57. :align: center
  58. :alt: Changing import type to Font Data (Monospace Image Font)
  59. Changing import type to **Font Data (Monospace Image Font)**
  60. The font's character set layout can be in any order, but orders that match
  61. standard Unicode are recommended as they'll require far less configuration to
  62. import. For example, the bitmap font below contains
  63. `ASCII <https://en.wikipedia.org/wiki/ASCII>`__ characters and follows standard ASCII ordering:
  64. .. figure:: img/using_fonts_monospace_bitmap_font_example.webp
  65. :align: center
  66. :alt: Bitmap font example
  67. Credit: `LibreQuake <https://github.com/MissLav/LibreQuake/blob/master/lq1/gfx-wad/CONCHARS.png>`__
  68. (scaled and cropped to exclude extended range)
  69. The following import options can be used to import the above font image
  70. successfully:
  71. .. figure:: img/using_fonts_bitmap_font_from_image_example_configuration.webp
  72. :align: center
  73. :alt: Import options to use for the above example font
  74. Import options to use for the above example font
  75. The **Character Ranges** option is an array that maps each position on the image
  76. (in tile coordinates, not pixels). The font atlas is traversed from left to
  77. right and top to bottom. Characters can be specified with decimal numbers
  78. (``127``), hexadecimal numbers (``0x007f``) or between *single* quotes
  79. (``'~'``). Ranges can be specified with a hyphen between characters.
  80. For instance, ``0-127`` (or ``0x0000-0x007f``) denotes the full ASCII range.
  81. As another example, ``' '-'~'`` is equivalent to ``32-127`` and denotes the range
  82. of *printable* (visible) ASCII characters.
  83. Make sure the **Character Ranges** option doesn't exceed the number of
  84. **Columns** × **Rows** defined. Otherwise, the font will fail to import.
  85. If your font image contains margins not used for font glyphs (such as
  86. attribution information), try adjusting **Image Margin**. This is a margin
  87. applied only once around the whole image.
  88. If your font image contains guides (in the form of lines between glyphs) or
  89. if spacing between characters appears incorrect, try adjusting **Character
  90. Margin**. This margin is applied for every imported glyph.
  91. Loading a font file
  92. -------------------
  93. To load a font file (dynamic or bitmap), use the resource dropdown's
  94. **Quick Load** or **Load** option next to a font property, then navigate to the
  95. font file in question:
  96. .. figure:: img/using_fonts_load_font.webp
  97. :align: center
  98. Loading a font file
  99. You can also drag-and-drop a font file from the FileSystem dock to the inspector
  100. property that accepts a Font resource.
  101. .. warning::
  102. In Godot 4.0 and later, texture filter and repeat properties are defined in
  103. the location where the texture is used, rather than on the texture itself.
  104. This also applies to fonts (both dynamic fonts and bitmap fonts).
  105. Fonts that have a pixel art appearance should have bilinear filtering disabled
  106. by changing the **Rendering > Textures > Canvas Textures > Default Texture Filter**
  107. project setting to **Nearest**.
  108. The font size must also be an integer multiple of the design size (which
  109. varies on a per-font basis), and the Control node using the font must be
  110. scaled by an integer multiple as well. Otherwise, the font may look blurry.
  111. Font sizes in Godot are specified in pixels (px), not points (pt). Keep this
  112. in mind when comparing font sizes across different software.
  113. The texture filter mode can also be set on individual nodes that inherit from CanvasItem
  114. by setting :ref:`CanvasItem.texture_filter <class_CanvasItem_property_texture_filter>`.
  115. Advanced font features
  116. ----------------------
  117. .. _doc_using_fonts_antialiasing:
  118. Antialiasing
  119. ^^^^^^^^^^^^
  120. You can adjust how the font should be smoothed out when rendering by adjusting
  121. *antialiasing* and *hinting*. These are different properties, with different use
  122. cases.
  123. Antialiasing controls how glyph edges should be smoothed out when rasterizing
  124. the font. The default antialiasing method (**Grayscale**) works well on every
  125. display technology. However, at small sizes, grayscale antialiasing may result
  126. in fonts looking blurry.
  127. The antialiasing sharpness can be improved by using LCD subpixel optimization,
  128. which exploits the subpixel patterns of most LCD displays by offsetting the font
  129. antialiasing on a per-channel basis (red/green/blue). The downside is that this
  130. can introduce "fringing" on edges, especially on display technologies that don't
  131. use standard RGB subpixels (such as OLED displays).
  132. In most games, it's recommended to stick to the default **Grayscale**
  133. antialiasing. For non-game applications, LCD subpixel optimization is worth
  134. exploring.
  135. .. figure:: img/using_fonts_antialiasing_comparison.webp
  136. :align: center
  137. :alt: Font antialiasing comparison
  138. From top to bottom: Disabled, Grayscale, LCD Subpixel (RGB)
  139. .. note::
  140. Antialiasing cannot be changed on :ref:`MSDF-rendered fonts <doc_using_fonts_msdf>`
  141. – these are always rendered with grayscale antialiasing.
  142. .. _doc_using_fonts_hinting:
  143. Hinting
  144. ^^^^^^^
  145. Hinting controls how aggressively glyph edges should be snapped to pixels when
  146. rasterizing the font. **None** results in the smoothest appearance, which can
  147. make the font look blurry at small sizes. **Light** (default) is sharper by
  148. snapping glyph edges to pixels on the Y axis only, while **Full** is even sharper
  149. by snapping glyph edges to pixels on both X and Y axes. Depending on personal
  150. preference, you may prefer using one hinting mode over the other.
  151. .. figure:: img/using_fonts_hinting_comparison.webp
  152. :align: center
  153. :alt: Font hinting comparison
  154. From top to bottom: None, Light, Full hinting
  155. .. note::
  156. If changing the hinting mode has no visible effect after clicking
  157. **Reimport**, it's usually because the font doesn't include hinting
  158. instructions. This can be resolved by looking for a version of the font file
  159. that includes hinting instructions, or enabling **Force Autohinter** in the
  160. Import dock. This will use `FreeType <https://freetype.org/>`__'s autohinter
  161. to automatically add hinting instructions to the imported font.
  162. .. _doc_using_fonts_subpixel_positioning:
  163. Subpixel positioning
  164. ^^^^^^^^^^^^^^^^^^^^
  165. Subpixel positioning can be adjusted. This is a `FreeType <https://freetype.org/>`__
  166. feature that allows glyphs to be rendered more closely to their intended form.
  167. The default setting of **Auto** automatically enables subpixel positioning at
  168. small sizes, but disables it at large font sizes to improve rasterization
  169. performance.
  170. You can force the subpixel positioning mode to **Disabled**, **One half of a
  171. pixel** or **One quarter of a pixel**. **One quarter of a pixel** provides the
  172. best quality, at the cost of longer rasterization times.
  173. Changing antialiasing, hinting and subpixel positioning has the most visible
  174. effect at smaller font sizes.
  175. .. warning::
  176. Fonts that have a pixel art appearance should have their subpixel positioning
  177. mode set to **Disabled**. Otherwise, the font may appear to have uneven pixel
  178. sizes.
  179. This step is not required for bitmap fonts, as subpixel positioning is only
  180. relevant for dynamic fonts (which are usually made of vector elements).
  181. .. _doc_using_fonts_mipmaps:
  182. Mipmaps
  183. ^^^^^^^
  184. By default, fonts do not have mipmaps generated to reduce memory usage and speed
  185. up rasterization. However, this can cause downscaled fonts to become grainy. This
  186. can be especially noticeable with :ref:`doc_3d_text` that doesn't have **Fixed
  187. Size** enabled. This can also occur when displaying text with a traditional rasterized
  188. (non-:ref:`MSDF <doc_using_fonts_msdf>`) font in a Control node that has its scale
  189. lower than ``(1, 1)``.
  190. After selecting a font in the FileSystem dock, you can enable the **Mipmaps** in
  191. the Import dock to improve downscaled font rendering appearance.
  192. Mipmaps can be enabled on MSDF fonts as well. This can improve font rencering
  193. quality a little at smaller-than-default sizes, but MSDF fonts are already
  194. resistant to graininess out of the box.
  195. .. _doc_using_fonts_msdf:
  196. MSDF font rendering
  197. ^^^^^^^^^^^^^^^^^^^
  198. Multi-channel signed distance field (MSDF) font rendering allows rendering fonts
  199. at any size, without having to re-rasterize them when their size changes.
  200. MSDF font rendering has 2 upsides over traditional font rasterization, which
  201. Godot uses by default:
  202. - The font will always look crisp, even at huge sizes.
  203. - There is less stuttering when rendering characters *at large font sizes* for
  204. the first time, as there is no rasterization performed.
  205. The downsides of MSDF font rendering are:
  206. - Higher baseline cost for font rendering. This is usually not noticeable on
  207. desktop platforms, but it can have an impact on low-end mobile devices.
  208. - Fonts at small sizes will not look as clear as rasterized fonts, due to the
  209. lack of hinting.
  210. - Rendering new glyphs for the first time *at small font sizes* may be more
  211. expensive compared to traditional rasterized fonts.
  212. :ref:`doc_using_fonts_font_prerendering` can be used to alleviate this.
  213. - LCD subpixel optimization cannot be enabled for MSDF fonts.
  214. - Fonts with self-intersecting outlines will not render correctly in MSDF mode.
  215. If you notice rendering issues on fonts downloaded from websites such as
  216. `Google Fonts <https://fonts.google.com>`__, try downloading the font from the
  217. font author's official website instead.
  218. .. _doc_using_fonts_emoji:
  219. Using emoji
  220. ^^^^^^^^^^^
  221. Godot has limited support for emoji fonts:
  222. - CBDT/CBLC (embedded PNGs) and SVG emoji fonts are supported.
  223. - COLR/CPAL emoji fonts (custom vector format) are **not** supported.
  224. - EMJC bitmap image compression (used by iOS' system emoji font) is **not** supported.
  225. This means that to support emoji on iOS, you must use a custom font that
  226. uses SVG or PNG bitmap compression instead.
  227. For Godot to be able to display emoji, the font used (or one of its
  228. :ref:`fallbacks <doc_using_fonts_font_fallbacks>`) needs to include them.
  229. Otherwise, emoji won't be displayed and placeholder "tofu" characters will
  230. appear instead:
  231. .. figure:: img/using_fonts_emoji_placeholder_characters.webp
  232. :align: center
  233. :alt: Default appearance when trying to use emoji in a label
  234. Default appearance when trying to use emoji in a label
  235. After adding a font to display emoji such as
  236. `Noto Color Emoji <https://fonts.google.com/noto/specimen/Noto+Color+Emoji>`__,
  237. you get the expected result:
  238. .. figure:: img/using_fonts_emoji_correct_characters.webp
  239. :align: center
  240. :alt: Correct appearance after adding an emoji font to the label
  241. Correct appearance after adding an emoji font to the label
  242. To use a regular font alongside emoji, it's recommended to specify a
  243. :ref:`fallback font <doc_using_fonts_font_fallbacks>` that points to the
  244. emoji font in the regular font's advanced import options. If you wish to use
  245. the default project font while displaying emoji, leave the **Base Font**
  246. property in FontVariation empty while adding a font fallback pointing to the
  247. emoji font:
  248. .. tip::
  249. Emoji fonts are quite large in size, so you may want to :ref:`load a system
  250. font <doc_using_fonts_system_fonts>` to provide emoji glyphs rather than
  251. bundling it with your project. This allows providing full emoji support in
  252. your project without increasing the size of its exported PCK. The downside
  253. is that emoji will look different depending on the platform, and loading
  254. system fonts is not supported on all platforms.
  255. It's possible to use a system font as a fallback font too.
  256. Using icon fonts
  257. ^^^^^^^^^^^^^^^^
  258. Tools like `Fontello <https://fontello.com/>`__ can be used to generate font
  259. files containing vectors imported from SVG files. This can be used to render
  260. custom vector elements as part of your text, or to create extruded 3D icons
  261. with :ref:`doc_3d_text` and TextMesh.
  262. .. note::
  263. Fontello currently does not support creating multicolored fonts (which Godot
  264. can render). As of November 2022, support for multicolored fonts in icon
  265. font generation tools remains scarce.
  266. Depending on your use cases, this may lead to better results compared to using
  267. the ``img`` tag in :ref:`RichTextLabel <doc_bbcode_in_richtextlabel>`. Unlike
  268. bitmap images (including SVGs which are rasterized on import by Godot),
  269. true vector data can be resized to any size without losing quality.
  270. After downloading the generated font file, load it in your Godot project then
  271. specify it as a custom font for a Label, RichTextLabel or Label3D node. Switch
  272. over to the Fontello web interface, then copy the character by selecting it then
  273. pressing :kbd:`Ctrl + C` (:kbd:`Cmd + C` on macOS). Paste the character in the
  274. **Text** property of your Label node. The character will appear as a placeholder
  275. glyph in the inspector, but it should appear correctly in the 2D/3D viewport.
  276. To use an icon font alongside a traditional font in the same Control, you can
  277. specify the icon font as a :ref:`fallback <doc_using_fonts_font_fallbacks>`.
  278. This works because icon fonts use the Unicode *private use area*, which is
  279. reserved for use by custom fonts and doesn't contain standard glyphs by design.
  280. .. note::
  281. Several modern icon fonts such as `Font Awesome 6 <https://fontawesome.com/download>`__
  282. have a desktop variant that uses *ligatures* to specify icons. This allows you to
  283. specify icons by entering their name directly in the **Text** property of any
  284. node that can display fonts. Once the icon's name is fully entered as text
  285. (such as ``house``), it will be replaced by the icon.
  286. While easier to use, this approach cannot be used with font fallbacks as the main
  287. font's characters will take priority over the fallback font's ligatures.
  288. .. _doc_using_fonts_font_fallbacks:
  289. Font fallbacks
  290. ^^^^^^^^^^^^^^
  291. Godot supports defining one or more fallbacks when the main font lacks a glyph
  292. to be displayed. There are 2 main use cases for defining font fallbacks:
  293. - Use a font that only supports Latin character sets, but use another font to
  294. be able to display text another character set such as Cyrillic.
  295. - Use a font to render text, and another font to render emoji or icons.
  296. Open the Advanced Import Settings dialog by double-clicking the font file in the
  297. FileSystem dock. You can also select the font in the FileSystem dock, go to the
  298. Import dock then choose **Advanced…** at the bottom:
  299. .. figure:: img/using_fonts_advanced_import_settings.webp
  300. :align: center
  301. Import dock
  302. In the dialog that appears, look for **Fallbacks** section
  303. on the sidebar on the right, click the **Array[Font] (size 0)** text to expand
  304. the property, then click **Add Element**:
  305. .. figure:: img/using_fonts_font_fallbacks_add.webp
  306. :align: center
  307. Adding font fallback
  308. Click the dropdown arrow on the new element, then choose a font file using the
  309. **Quick Load** or **Load** options:
  310. .. figure:: img/using_fonts_font_fallbacks_load.webp
  311. :align: center
  312. Loading font fallback
  313. It is possible to add fallback fonts while using the default project font. To do
  314. so, leave the **Base Font** property empty while adding one or more font
  315. fallbacks.
  316. .. note::
  317. Font fallbacks can also be defined on a local basis similar to
  318. :ref:`doc_using_fonts_opentype_font_features`, but this is not covered here
  319. for brevity reasons.
  320. .. _doc_using_fonts_variable_fonts:
  321. Variable fonts
  322. ^^^^^^^^^^^^^^
  323. Godot has full support for `variable fonts <https://variablefonts.io/>`__, which
  324. allow you to use a single font file to represent various font weights and styles
  325. (regular, bold, italic, …). This must be supported by the font file you're using.
  326. To use a variable font, create a :ref:`class_FontVariation` resource in the
  327. location where you intend to use the font, then load a font file within the
  328. FontVariation resource:
  329. .. figure:: img/using_fonts_font_variation_create.webp
  330. :align: center
  331. Creating a FontVariation resource
  332. .. figure:: img/using_fonts_font_variation_load.webp
  333. :align: center
  334. Loading a font file into the FontVariation resource
  335. Scroll down to the FontVariation's **Variation** section, then click the
  336. **Variation Coordinates** text to expand the list of axes that can be adjusted:
  337. .. figure:: img/using_fonts_font_variation_variable_font.webp
  338. :align: center
  339. List of variation axes
  340. The set of axes you can adjust depends on the font loaded. Some variable fonts
  341. only support one axis of adjustment (typically *weight* or *slant*), while
  342. others may support multiple axes of adjustment.
  343. For example, here's the `Inter V <https://rsms.me/inter/>`__ font with a
  344. *weight* of ``900`` and a *slant* of ``-10``:
  345. .. figure:: img/using_fonts_font_variation_variable_font_example.webp
  346. :align: center
  347. Variable font example (Inter V)
  348. .. tip::
  349. While variable font axis names and scales aren't standardized, some common
  350. conventions are usually followed by font designers. For instance, the
  351. *weight* axis typically uses ``400`` as the "regular" font weight and
  352. ``700`` as the "bold" font weight.
  353. You can save the FontVariation to a ``.tres`` resource file to reuse it in other
  354. places:
  355. .. figure:: img/using_fonts_font_variation_save_to_file.webp
  356. :align: center
  357. Saving FontVariation to an external resource file
  358. Faux bold and italic
  359. ^^^^^^^^^^^^^^^^^^^^
  360. When writing text in bold or italic, using font variants specifically designed
  361. for this looks better. Spacing between glyphs will be more consistent when using
  362. a bold font, and certain glyphs' shapes may change entirely in italic variants
  363. (compare "a" and *"a"*).
  364. However, real bold and italic fonts require shipping more font files, which
  365. increases distribution size. A single :ref:`variable font <doc_using_fonts_variable_fonts>`
  366. file can also be used, but this file will be larger than a single non-variable font.
  367. While file size is usually not an issue for desktop projects, it can be a concern
  368. for mobile/web projects that strive to keep distribution size as low as possible.
  369. To allow bold and italic fonts to be displayed without having to ship additional
  370. fonts (or use a variable font that is larger in size), Godot supports *faux*
  371. bold and italic.
  372. .. figure:: img/using_fonts_faux_bold_italic_vs_real_bold_italic.webp
  373. :align: center
  374. :alt: Faux bold/italic (top), real bold/italic (bottom). Normal font used: Open Sans SemiBold
  375. Faux bold/italic (top), real bold/italic (bottom). Normal font used: Open Sans SemiBold
  376. Faux bold and italic is automatically used in :ref:`class_RichTextLabel`'s bold
  377. and italic tags if no custom fonts are provided for bold and/or italic.
  378. To use faux bold, create a FontVariation resource in a property where a Font
  379. resource is expected. Set **Variation > Embolden** to a positive value to make a
  380. font bolder, or to a negative value to make it less bold. Recommended values are
  381. between ``0.5`` and ``1.2`` depending on the font.
  382. Faux italic is created by skewing the text, which is done by modifying the
  383. per-character transform. This is also provided in FontVariation using the
  384. **Variation > Transform** property. Setting the ``yx`` component of the
  385. character transform to a positive value will italicize the text. Recommended
  386. values are between ``0.2`` and ``0.4`` depending on the font.
  387. Adjusting font spacing
  388. ^^^^^^^^^^^^^^^^^^^^^^
  389. For stylistic purposes or for better readability, you may want to adjust how a
  390. font is presented in Godot.
  391. Create a FontVariation resource in a property where a Font resource is expected.
  392. There are 4 properties available in the **Variation > Extra Spacing** section,
  393. which accept positive and negative values:
  394. - **Glyph:** Additional spacing between every glyph.
  395. - **Space:** Additional spacing between words.
  396. - **Top:** Additional spacing above glyphs. This is used for multiline text,
  397. but also to calculate the minimum size of controls such as :ref:`class_Label`
  398. and :ref:`class_Button`.
  399. - **Top:** Additional spacing below glyphs. This is used for multiline text,
  400. but also to calculate the minimum size of controls such as :ref:`class_Label`
  401. and :ref:`class_Button`.
  402. The **Variation > Transform** property can also be adjusted to stretch
  403. characters horizontally or vertically. This is specifically done by adjusting
  404. the ``xx`` (horizontal scale) and ``yy`` (vertical scale) components. Remember
  405. to adjust glyph spacing to account for any changes, as glyph transform doesn't
  406. affect how much space each glyph takes in the text. Non-uniform scaling of this
  407. kind should be used sparingly, as fonts are generally not designed to be
  408. displayed with stretching.
  409. .. _doc_using_fonts_opentype_font_features:
  410. OpenType font features
  411. ^^^^^^^^^^^^^^^^^^^^^^
  412. Godot supports enabling OpenType font features, which are a standardized way to
  413. define alternate characters that can be toggled without having to swap font
  414. files entirely. Despite being named OpenType font features, these are also
  415. supported in TrueType (``.ttf``) and WOFF/WOFF2 font files.
  416. Support for OpenType features highly depends on the font used. Some fonts don't
  417. support any OpenType features, while other fonts can support dozens of
  418. toggleable features.
  419. There are 2 ways to use OpenType font featutres:
  420. **Globally on a font file**
  421. Open the Advanced Import Settings dialog by double-clicking the font file in the
  422. FileSystem dock. You can also select the font in the FileSystem dock, go to the
  423. Import dock then choose **Advanced…** at the bottom:
  424. .. figure:: img/using_fonts_advanced_import_settings.webp
  425. :align: center
  426. Import dock
  427. In the dialog that appears, look for the **Metadata Overrides > OpenType
  428. Features** section on the sidebar on the right, click the
  429. **Features (0 of N set)** text to expand the property, then click
  430. **Add Feature**:
  431. .. figure:: img/using_fonts_advanced_import_settings_opentype_features.webp
  432. :align: center
  433. OpenType feature overrides in Advanced Import Settings
  434. **In a specific font usage (FontVariation)**
  435. To use a font feature, create a FontVariation resource like you would do for a
  436. :ref:`variable font <doc_using_fonts_variable_fonts>`, then load a font file
  437. within the FontVariation resource:
  438. .. figure:: img/using_fonts_font_variation_create.webp
  439. :align: center
  440. Creating a FontVariation resource
  441. .. figure:: img/using_fonts_font_variation_load.webp
  442. :align: center
  443. Loading a font file into a FontVariation resource
  444. Scroll down to the FontVariation's **OpenType Features** section, click the
  445. **Features (0 of N set)** text to expand the property, then click **Add Feature**
  446. and select the desired feature in the dropdown:
  447. .. figure:: img/using_fonts_font_variation_opentype_features.webp
  448. :align: center
  449. Specifying OpenType features in a FontVariation resource
  450. For example, here's the `Inter <https://rsms.me/inter/>`__ font without the
  451. *Slashed Zero* feature (top), then with the *Slashed Zero* OpenType feature enabled
  452. (bottom):
  453. .. figure:: img/using_fonts_font_variation_slashed_zero.webp
  454. :align: center
  455. OpenType feature comparison (Inter)
  456. You can disable ligatures and/or kerning for a specific font by adding OpenType
  457. features, then unchecking them in the inspector:
  458. .. figure:: img/using_fonts_font_variation_disable_ligatures.webp
  459. :align: center
  460. Disabling ligatures and kerning for a font
  461. .. _doc_using_fonts_system_fonts:
  462. System fonts
  463. ^^^^^^^^^^^^
  464. .. warning::
  465. Loading system fonts is only supported on Windows, macOS, Linux, Android and iOS.
  466. System fonts are a different type of resource compared to imported fonts. They
  467. are never actually imported into the project, but are loaded at run-time. This
  468. has 2 benefits:
  469. - The fonts are not included within the exported PCK file, leading to a smaller
  470. file size for the exported project.
  471. - Since fonts are not included with the exported project, this avoids licensing
  472. issues that would occur if proprietary system fonts were distributed alongside
  473. the project.
  474. The engine automatically uses system fonts as fallback fonts, which makes it
  475. possible to display CJK characters and emoji without having to load a custom
  476. font. There are some restrictions that apply though, as mentioned in the
  477. :ref:`Using emoji <doc_using_fonts_emoji>` section.
  478. Create a SystemFont resource in the location where you desire to use the system font:
  479. .. figure:: img/using_fonts_system_font_create.webp
  480. :align: center
  481. Creating a SystemFont resource
  482. .. figure:: img/using_fonts_system_font_specify.webp
  483. :align: center
  484. Specifying a font name to use in a SystemFont resource
  485. You can either specify one or more font names explicitly (such as ``Arial``), or
  486. specify the name of a font *alias* that maps to a "standard" default font for
  487. the system:
  488. .. Android font information sourced from <https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/fonts.xml>
  489. +----------------+-----------------+----------------+-------------------------+-------------------------+
  490. | Font alias | Windows | macOS/iOS | Linux | Android |
  491. +================+=================+================+=========================+=========================+
  492. | ``sans-serif`` | Arial | Helvetica | *Handled by fontconfig* | Roboto / Noto Sans |
  493. +----------------+-----------------+----------------+-------------------------+-------------------------+
  494. | ``serif`` | Times New Roman | Times | *Handled by fontconfig* | Noto Serif |
  495. +----------------+-----------------+----------------+-------------------------+-------------------------+
  496. | ``monospace`` | Courier New | Courier | *Handled by fontconfig* | Droid Sans Mono |
  497. +----------------+-----------------+----------------+-------------------------+-------------------------+
  498. | ``cursive`` | Comic Sans MS | Apple Chancery | *Handled by fontconfig* | Dancing Script |
  499. +----------------+-----------------+----------------+-------------------------+-------------------------+
  500. | ``fantasy`` | Gabriola | Papyrus | *Handled by fontconfig* | Droid Sans Mono |
  501. +----------------+-----------------+----------------+-------------------------+-------------------------+
  502. On Android, Roboto is used for Latin/Cyrillic text and Noto Sans is used for
  503. other languages' glyphs such as CJK. On third-party Android distributions, the
  504. exact font selection may differ.
  505. If specifying more than one font, the first font that is found on the system
  506. will be used (from top to bottom). Font names and aliases are case-insensitive
  507. on all platforms.
  508. Like for font variations, you can save the SystemFont arrangement to a resource
  509. file to reuse it in other places.
  510. Remember that different system fonts have different metrics, which means that
  511. text that can fit within a rectangle on one platform may not be doing so on
  512. another platform. Always reserve some additional space during development so
  513. that labels can extend further if needed.
  514. .. note::
  515. Unlike Windows and macOS/iOS, the set of default fonts shipped on Linux
  516. depends on the distribution. This means that on different Linux
  517. distributions, different fonts may be displayed for a given system font name
  518. or alias.
  519. .. _doc_using_fonts_font_prerendering:
  520. Font prerendering
  521. ^^^^^^^^^^^^^^^^^
  522. When using traditional rasterized fonts, Godot caches glyphs on a per-font and
  523. per-size basis. This reduces stuttering, but it can still occur the first time a
  524. glyph is displayed when running the project. This can be especially noticeable
  525. at higher font sizes or on mobile devices.
  526. When using MSDF fonts, they only need to be rasterized once to a special signed
  527. distance field texture. This means caching can be done purely on a per-font
  528. basis, without taking the font size into consideration. However, the initial
  529. rendering of MSDF fonts is slower compared to a traditional rasterized font at a
  530. medium size.
  531. To avoid stuttering issues related to font rendering, it is possible to
  532. *prerender* certain glyphs. This can be done for all glyphs you intend to use
  533. (for optimal results), or only for common glyphs that are most likely to appear
  534. during gameplay (to reduce file size). Glyphs that aren't pre-rendered will be
  535. rasterizd on-the-fly as usual.
  536. .. note::
  537. In both cases (traditional and MSDF), font rasterization is done on the CPU.
  538. This means that the GPU performance doesn't affect how long it takes for fonts
  539. to be rasterized.
  540. Open the Advanced Import Settings dialog by double-clicking the font file in the
  541. FileSystem dock. You can also select the font in the FileSystem dock, go to the
  542. Import dock then choose **Advanced…** at the bottom:
  543. .. figure:: img/using_fonts_advanced_import_settings.webp
  544. :align: center
  545. Import dock
  546. Move to the **Pre-render Configurations** tab of the Advanced Import Settings dialog,
  547. then add a configuration by clicking the "plus" symbol:
  548. .. figure:: img/using_fonts_advanced_import_settings_prerender_new_configuration.webp
  549. :align: center
  550. :alt: Adding a new prerendering configuration in the Advanced Import Settings dialog
  551. Adding a new prerendering configuration in the Advanced Import Settings dialog
  552. After adding a configuration, make sure it is selected by clicking its name
  553. once. You can also rename the configuration by double-clicking it.
  554. There are 2 ways to add glyphs to be prerendered to a given configuration. It is
  555. possible to use both approaches in a cumulative manner:
  556. **Using text from translations**
  557. For most projects, this approach is the most convenient to use, as it
  558. automatically sources text from your language translations. The downside is that
  559. it can only be used if your project supports
  560. :ref:`internationalization <doc_internationalizing_games>`. Otherwise, stick to
  561. the "Using custom text" approach described below.
  562. After adding translations to the Project Settings, use the
  563. **Glyphs from the Translations** tab to check translations by double-clicking them,
  564. then click **Shape All Strings in the Translations and Add Glyphs** at the bottom:
  565. .. figure:: img/using_fonts_advanced_import_settings_prerender_translation.webp
  566. :align: center
  567. :alt: Enabling prerendering in the Advanced Import Settings dialog with the Glyphs from the Translations tab
  568. Enabling prerendering in the Advanced Import Settings dialog with the **Glyphs from the Translations** tab
  569. .. note::
  570. The list of prerendered glyphs is not automatically updated when
  571. translations are updated, so you need to repeat this process if your
  572. translations have changed significantly.
  573. **Using custom text**
  574. While it requires manually specifying text that will appear in the game, this is
  575. the most efficient approach for games which don't feature user text input. This
  576. approach is worth exploring for mobile games to reduce the file size of the
  577. distributed app.
  578. To use existing text as a baseline for prerendering, go to the **Glyphs from the
  579. Text** sub-tab of the Advanced Import Settings dialog, enter text in the window
  580. on the right, then click **Shape Text and Add Glyphs** at the bottom of the
  581. dialog:
  582. .. figure:: img/using_fonts_advanced_import_settings_prerender_text.webp
  583. :align: center
  584. :alt: Enabling prerendering in the Advanced Import Settings dialog, Glyphs from the Text tab
  585. Enabling prerendering in the Advanced Import Settings dialog with the **Glyphs from the Text** tab
  586. .. tip::
  587. If your project supports :ref:`internationalization <doc_internationalizing_games>`,
  588. you can paste the contents of your CSV or PO files in the above box to quickly
  589. prerender all possible characters that may be rendered during gameplay
  590. (excluding user-provided or non-translatable strings).
  591. **By enabling character sets**
  592. The second method requires less configuration and fewer updates if your game's
  593. text changes, and is more suited to text-heavy games or multiplayer games with
  594. chat. On the other hand, it may cause glyphs that never show up in the game to
  595. be prerendered, which is less efficient in terms of file size.
  596. To use existing text as a baseline for prerendering, go to the **Glyphs from the
  597. Character Map** sub-tab of the Advanced Import Settings dialog, then
  598. *dobule-click* character sets to be enabled on the right:
  599. .. figure:: img/using_fonts_advanced_import_settings_prerender_character_map.webp
  600. :align: center
  601. :alt: Enabling prerendering in the Advanced Import Settings dialog, Glyphs from the Character Map tab
  602. Enabling prerendering in the Advanced Import Settings dialog with the **Glyphs from the Character Map** tab
  603. To ensure full prerendering, the character sets you need to enable depend on
  604. which languages are supported in your game. For English, only **Basic Latin**
  605. needs to be enabled. Enabling **Latin-1 Supplement** as well allows fully
  606. covering many more languages, such as French, German and Spanish. For Russian,
  607. **Cyrillic** needs to be enabled, and so on.
  608. Default project font properties
  609. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  610. In the **GUI > Theme** section of the advanced Project Settings, you can choose
  611. how the default font should be rendered:
  612. - **Default Font Antialiasing:** Controls the
  613. :ref:`antialiasing <doc_using_fonts_antialiasing>` method used
  614. for the default project font.
  615. - **Default Font Hinting:** Controls the
  616. :ref:`hinting <doc_using_fonts_hinting>` method used for
  617. the default project font.
  618. - **Default Font Subpixel Positioning:** Controls the
  619. :ref:`subpixel positioning <doc_using_fonts_subpixel_positioning>`
  620. method for the default project font.
  621. - **Default Font Multichannel Signed Distance Field:** If ``true``, makes the
  622. default project font use :ref:`MSDF font rendering <doc_using_fonts_msdf>` instead
  623. of traditional rasterization.
  624. - **Default Font Generate Mipmaps:** If ``true``, enables
  625. :ref:`mipmap <doc_using_fonts_mipmaps>` generation and
  626. usage for the default project font.
  627. .. note::
  628. These project settings *only* affect the default project font (the one that
  629. is hardcoded in the engine binary).
  630. Custom fonts' properties are governed by their respective import options
  631. instead. You can use the **Import Defaults** section of the Project Settings
  632. dialog to override default import options for custom fonts.