class_dynamicfont.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/DynamicFont.xml.
  6. .. _class_DynamicFont:
  7. DynamicFont
  8. ===========
  9. **Inherits:** :ref:`Font<class_Font>` **<** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. DynamicFont renders vector font files at runtime.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. DynamicFont renders vector font files dynamically at runtime instead of using a prerendered texture atlas like :ref:`BitmapFont<class_BitmapFont>`. This trades the faster loading time of :ref:`BitmapFont<class_BitmapFont>`\ s for the ability to change font parameters like size and spacing during runtime. :ref:`DynamicFontData<class_DynamicFontData>` is used for referencing the font file paths. DynamicFont also supports defining one or more fallback fonts, which will be used when displaying a character not supported by the main font.
  15. DynamicFont uses the `FreeType <https://www.freetype.org/>`__ library for rasterization. Supported formats are TrueType (``.ttf``), OpenType (``.otf``), Web Open Font Format 1 (``.woff``), and Web Open Font Format 2 (``.woff2``).
  16. ::
  17. var dynamic_font = DynamicFont.new()
  18. dynamic_font.font_data = load("res://BarlowCondensed-Bold.ttf")
  19. dynamic_font.size = 64
  20. $"Label".set("custom_fonts/font", dynamic_font)
  21. \ **Note:** DynamicFont doesn't support features such as kerning, right-to-left typesetting, ligatures, text shaping, variable fonts and optional font features yet. If you wish to "bake" an optional font feature into a TTF font file, you can use `FontForge <https://fontforge.org/>`__ to do so. In FontForge, use **File > Generate Fonts**, click **Options**, choose the desired features then generate the font.
  22. .. rst-class:: classref-introduction-group
  23. Tutorials
  24. ---------
  25. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
  26. .. rst-class:: classref-reftable-group
  27. Properties
  28. ----------
  29. .. table::
  30. :widths: auto
  31. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  32. | :ref:`int<class_int>` | :ref:`extra_spacing_bottom<class_DynamicFont_property_extra_spacing_bottom>` | ``0`` |
  33. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  34. | :ref:`int<class_int>` | :ref:`extra_spacing_char<class_DynamicFont_property_extra_spacing_char>` | ``0`` |
  35. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  36. | :ref:`int<class_int>` | :ref:`extra_spacing_space<class_DynamicFont_property_extra_spacing_space>` | ``0`` |
  37. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  38. | :ref:`int<class_int>` | :ref:`extra_spacing_top<class_DynamicFont_property_extra_spacing_top>` | ``0`` |
  39. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  40. | :ref:`DynamicFontData<class_DynamicFontData>` | :ref:`font_data<class_DynamicFont_property_font_data>` | |
  41. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  42. | :ref:`Color<class_Color>` | :ref:`outline_color<class_DynamicFont_property_outline_color>` | ``Color( 1, 1, 1, 1 )`` |
  43. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  44. | :ref:`int<class_int>` | :ref:`outline_size<class_DynamicFont_property_outline_size>` | ``0`` |
  45. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  46. | :ref:`int<class_int>` | :ref:`size<class_DynamicFont_property_size>` | ``16`` |
  47. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`use_filter<class_DynamicFont_property_use_filter>` | ``false`` |
  49. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  50. | :ref:`bool<class_bool>` | :ref:`use_mipmaps<class_DynamicFont_property_use_mipmaps>` | ``false`` |
  51. +-----------------------------------------------+------------------------------------------------------------------------------+-------------------------+
  52. .. rst-class:: classref-reftable-group
  53. Methods
  54. -------
  55. .. table::
  56. :widths: auto
  57. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`add_fallback<class_DynamicFont_method_add_fallback>` **(** :ref:`DynamicFontData<class_DynamicFontData>` data **)** |
  59. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`String<class_String>` | :ref:`get_available_chars<class_DynamicFont_method_get_available_chars>` **(** **)** |const| |
  61. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`DynamicFontData<class_DynamicFontData>` | :ref:`get_fallback<class_DynamicFont_method_get_fallback>` **(** :ref:`int<class_int>` idx **)** |const| |
  63. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`int<class_int>` | :ref:`get_fallback_count<class_DynamicFont_method_get_fallback_count>` **(** **)** |const| |
  65. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`int<class_int>` | :ref:`get_spacing<class_DynamicFont_method_get_spacing>` **(** :ref:`int<class_int>` type **)** |const| |
  67. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`remove_fallback<class_DynamicFont_method_remove_fallback>` **(** :ref:`int<class_int>` idx **)** |
  69. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`set_fallback<class_DynamicFont_method_set_fallback>` **(** :ref:`int<class_int>` idx, :ref:`DynamicFontData<class_DynamicFontData>` data **)** |
  71. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`set_spacing<class_DynamicFont_method_set_spacing>` **(** :ref:`int<class_int>` type, :ref:`int<class_int>` value **)** |
  73. +-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. .. rst-class:: classref-section-separator
  75. ----
  76. .. rst-class:: classref-descriptions-group
  77. Enumerations
  78. ------------
  79. .. _enum_DynamicFont_SpacingType:
  80. .. rst-class:: classref-enumeration
  81. enum **SpacingType**:
  82. .. _class_DynamicFont_constant_SPACING_TOP:
  83. .. rst-class:: classref-enumeration-constant
  84. :ref:`SpacingType<enum_DynamicFont_SpacingType>` **SPACING_TOP** = ``0``
  85. Spacing at the top.
  86. .. _class_DynamicFont_constant_SPACING_BOTTOM:
  87. .. rst-class:: classref-enumeration-constant
  88. :ref:`SpacingType<enum_DynamicFont_SpacingType>` **SPACING_BOTTOM** = ``1``
  89. Spacing at the bottom.
  90. .. _class_DynamicFont_constant_SPACING_CHAR:
  91. .. rst-class:: classref-enumeration-constant
  92. :ref:`SpacingType<enum_DynamicFont_SpacingType>` **SPACING_CHAR** = ``2``
  93. Spacing for each character.
  94. .. _class_DynamicFont_constant_SPACING_SPACE:
  95. .. rst-class:: classref-enumeration-constant
  96. :ref:`SpacingType<enum_DynamicFont_SpacingType>` **SPACING_SPACE** = ``3``
  97. Spacing for the space character.
  98. .. rst-class:: classref-section-separator
  99. ----
  100. .. rst-class:: classref-descriptions-group
  101. Property Descriptions
  102. ---------------------
  103. .. _class_DynamicFont_property_extra_spacing_bottom:
  104. .. rst-class:: classref-property
  105. :ref:`int<class_int>` **extra_spacing_bottom** = ``0``
  106. .. rst-class:: classref-property-setget
  107. - void **set_spacing** **(** :ref:`int<class_int>` type, :ref:`int<class_int>` value **)**
  108. - :ref:`int<class_int>` **get_spacing** **(** :ref:`int<class_int>` type **)** |const|
  109. Extra spacing at the bottom in pixels.
  110. .. rst-class:: classref-item-separator
  111. ----
  112. .. _class_DynamicFont_property_extra_spacing_char:
  113. .. rst-class:: classref-property
  114. :ref:`int<class_int>` **extra_spacing_char** = ``0``
  115. .. rst-class:: classref-property-setget
  116. - void **set_spacing** **(** :ref:`int<class_int>` type, :ref:`int<class_int>` value **)**
  117. - :ref:`int<class_int>` **get_spacing** **(** :ref:`int<class_int>` type **)** |const|
  118. Extra spacing for each character in pixels.
  119. This can be a negative number to make the distance between characters smaller.
  120. .. rst-class:: classref-item-separator
  121. ----
  122. .. _class_DynamicFont_property_extra_spacing_space:
  123. .. rst-class:: classref-property
  124. :ref:`int<class_int>` **extra_spacing_space** = ``0``
  125. .. rst-class:: classref-property-setget
  126. - void **set_spacing** **(** :ref:`int<class_int>` type, :ref:`int<class_int>` value **)**
  127. - :ref:`int<class_int>` **get_spacing** **(** :ref:`int<class_int>` type **)** |const|
  128. Extra spacing for the space character (in addition to :ref:`extra_spacing_char<class_DynamicFont_property_extra_spacing_char>`) in pixels.
  129. This can be a negative number to make the distance between words smaller.
  130. .. rst-class:: classref-item-separator
  131. ----
  132. .. _class_DynamicFont_property_extra_spacing_top:
  133. .. rst-class:: classref-property
  134. :ref:`int<class_int>` **extra_spacing_top** = ``0``
  135. .. rst-class:: classref-property-setget
  136. - void **set_spacing** **(** :ref:`int<class_int>` type, :ref:`int<class_int>` value **)**
  137. - :ref:`int<class_int>` **get_spacing** **(** :ref:`int<class_int>` type **)** |const|
  138. Extra spacing at the top in pixels.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _class_DynamicFont_property_font_data:
  142. .. rst-class:: classref-property
  143. :ref:`DynamicFontData<class_DynamicFontData>` **font_data**
  144. .. rst-class:: classref-property-setget
  145. - void **set_font_data** **(** :ref:`DynamicFontData<class_DynamicFontData>` value **)**
  146. - :ref:`DynamicFontData<class_DynamicFontData>` **get_font_data** **(** **)**
  147. The font data.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_DynamicFont_property_outline_color:
  151. .. rst-class:: classref-property
  152. :ref:`Color<class_Color>` **outline_color** = ``Color( 1, 1, 1, 1 )``
  153. .. rst-class:: classref-property-setget
  154. - void **set_outline_color** **(** :ref:`Color<class_Color>` value **)**
  155. - :ref:`Color<class_Color>` **get_outline_color** **(** **)**
  156. The font outline's color.
  157. \ **Note:** It's recommended to leave this at the default value so that you can adjust it in individual controls. For example, if the outline is made black here, it won't be possible to change its color using a Label's font outline modulate theme item.
  158. .. rst-class:: classref-item-separator
  159. ----
  160. .. _class_DynamicFont_property_outline_size:
  161. .. rst-class:: classref-property
  162. :ref:`int<class_int>` **outline_size** = ``0``
  163. .. rst-class:: classref-property-setget
  164. - void **set_outline_size** **(** :ref:`int<class_int>` value **)**
  165. - :ref:`int<class_int>` **get_outline_size** **(** **)**
  166. The font outline's thickness in pixels (not relative to the font size).
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _class_DynamicFont_property_size:
  170. .. rst-class:: classref-property
  171. :ref:`int<class_int>` **size** = ``16``
  172. .. rst-class:: classref-property-setget
  173. - void **set_size** **(** :ref:`int<class_int>` value **)**
  174. - :ref:`int<class_int>` **get_size** **(** **)**
  175. The font size in pixels.
  176. .. rst-class:: classref-item-separator
  177. ----
  178. .. _class_DynamicFont_property_use_filter:
  179. .. rst-class:: classref-property
  180. :ref:`bool<class_bool>` **use_filter** = ``false``
  181. .. rst-class:: classref-property-setget
  182. - void **set_use_filter** **(** :ref:`bool<class_bool>` value **)**
  183. - :ref:`bool<class_bool>` **get_use_filter** **(** **)**
  184. If ``true``, filtering is used. This makes the font blurry instead of pixelated when scaling it if font oversampling is disabled or ineffective. It's recommended to enable this when using the font in a control whose size changes over time, unless a pixel art aesthetic is desired.
  185. .. rst-class:: classref-item-separator
  186. ----
  187. .. _class_DynamicFont_property_use_mipmaps:
  188. .. rst-class:: classref-property
  189. :ref:`bool<class_bool>` **use_mipmaps** = ``false``
  190. .. rst-class:: classref-property-setget
  191. - void **set_use_mipmaps** **(** :ref:`bool<class_bool>` value **)**
  192. - :ref:`bool<class_bool>` **get_use_mipmaps** **(** **)**
  193. If ``true``, mipmapping is used. This improves the font's appearance when downscaling it if font oversampling is disabled or ineffective.
  194. .. rst-class:: classref-section-separator
  195. ----
  196. .. rst-class:: classref-descriptions-group
  197. Method Descriptions
  198. -------------------
  199. .. _class_DynamicFont_method_add_fallback:
  200. .. rst-class:: classref-method
  201. void **add_fallback** **(** :ref:`DynamicFontData<class_DynamicFontData>` data **)**
  202. Adds a fallback font.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_DynamicFont_method_get_available_chars:
  206. .. rst-class:: classref-method
  207. :ref:`String<class_String>` **get_available_chars** **(** **)** |const|
  208. Returns a string containing all the characters available in the main and all the fallback fonts.
  209. If a given character is included in more than one font, it appears only once in the returned string.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_DynamicFont_method_get_fallback:
  213. .. rst-class:: classref-method
  214. :ref:`DynamicFontData<class_DynamicFontData>` **get_fallback** **(** :ref:`int<class_int>` idx **)** |const|
  215. Returns the fallback font at index ``idx``.
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_DynamicFont_method_get_fallback_count:
  219. .. rst-class:: classref-method
  220. :ref:`int<class_int>` **get_fallback_count** **(** **)** |const|
  221. Returns the number of fallback fonts.
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_DynamicFont_method_get_spacing:
  225. .. rst-class:: classref-method
  226. :ref:`int<class_int>` **get_spacing** **(** :ref:`int<class_int>` type **)** |const|
  227. Returns the spacing for the given ``type`` (see :ref:`SpacingType<enum_DynamicFont_SpacingType>`).
  228. .. rst-class:: classref-item-separator
  229. ----
  230. .. _class_DynamicFont_method_remove_fallback:
  231. .. rst-class:: classref-method
  232. void **remove_fallback** **(** :ref:`int<class_int>` idx **)**
  233. Removes the fallback font at index ``idx``.
  234. .. rst-class:: classref-item-separator
  235. ----
  236. .. _class_DynamicFont_method_set_fallback:
  237. .. rst-class:: classref-method
  238. void **set_fallback** **(** :ref:`int<class_int>` idx, :ref:`DynamicFontData<class_DynamicFontData>` data **)**
  239. Sets the fallback font at index ``idx``.
  240. .. rst-class:: classref-item-separator
  241. ----
  242. .. _class_DynamicFont_method_set_spacing:
  243. .. rst-class:: classref-method
  244. void **set_spacing** **(** :ref:`int<class_int>` type, :ref:`int<class_int>` value **)**
  245. Sets the spacing for ``type`` (see :ref:`SpacingType<enum_DynamicFont_SpacingType>`) to ``value`` in pixels (not relative to the font size).
  246. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  247. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  248. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  249. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`