class_font.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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/Font.xml.
  6. .. _class_Font:
  7. Font
  8. ====
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`BitmapFont<class_BitmapFont>`, :ref:`DynamicFont<class_DynamicFont>`
  11. Internationalized font and text drawing support.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. Font contains a Unicode-compatible character set, as well as the ability to draw it with variable width, ascent, descent and kerning. For creating fonts from TTF files (or other font formats), see the editor support for fonts.
  16. \ **Note:** If a :ref:`DynamicFont<class_DynamicFont>` doesn't contain a character used in a string, the character in question will be replaced with codepoint ``0xfffd`` if it's available in the :ref:`DynamicFont<class_DynamicFont>`. If this replacement character isn't available in the DynamicFont, the character will be hidden without displaying any replacement character in the string.
  17. \ **Note:** If a :ref:`BitmapFont<class_BitmapFont>` doesn't contain a character used in a string, the character in question will be hidden without displaying any replacement character in the string.
  18. \ **Note:** Unicode characters after ``0xffff`` (such as most emoji) are *not* supported on Windows. They will display as unknown characters instead. This will be resolved in Godot 4.0.
  19. .. rst-class:: classref-reftable-group
  20. Methods
  21. -------
  22. .. table::
  23. :widths: auto
  24. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`draw<class_Font_method_draw>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` string, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`int<class_int>` clip_w=-1, :ref:`Color<class_Color>` outline_modulate=Color( 1, 1, 1, 1 ) **)** |const| |
  26. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`float<class_float>` | :ref:`draw_char<class_Font_method_draw_char>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` char, :ref:`int<class_int>` next=-1, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` outline=false **)** |const| |
  28. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`float<class_float>` | :ref:`get_ascent<class_Font_method_get_ascent>` **(** **)** |const| |
  30. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_char_contours<class_Font_method_get_char_contours>` **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0 **)** |const| |
  32. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Vector2<class_Vector2>` | :ref:`get_char_size<class_Font_method_get_char_size>` **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0 **)** |const| |
  34. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`RID<class_RID>` | :ref:`get_char_texture<class_Font_method_get_char_texture>` **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const| |
  36. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Vector2<class_Vector2>` | :ref:`get_char_texture_size<class_Font_method_get_char_texture_size>` **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const| |
  38. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Vector2<class_Vector2>` | :ref:`get_char_tx_offset<class_Font_method_get_char_tx_offset>` **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const| |
  40. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Vector2<class_Vector2>` | :ref:`get_char_tx_size<class_Font_method_get_char_tx_size>` **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const| |
  42. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Rect2<class_Rect2>` | :ref:`get_char_tx_uv_rect<class_Font_method_get_char_tx_uv_rect>` **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const| |
  44. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`float<class_float>` | :ref:`get_descent<class_Font_method_get_descent>` **(** **)** |const| |
  46. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`float<class_float>` | :ref:`get_height<class_Font_method_get_height>` **(** **)** |const| |
  48. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Vector2<class_Vector2>` | :ref:`get_string_size<class_Font_method_get_string_size>` **(** :ref:`String<class_String>` string **)** |const| |
  50. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Vector2<class_Vector2>` | :ref:`get_wordwrap_string_size<class_Font_method_get_wordwrap_string_size>` **(** :ref:`String<class_String>` string, :ref:`float<class_float>` width **)** |const| |
  52. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`has_outline<class_Font_method_has_outline>` **(** **)** |const| |
  54. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`is_distance_field_hint<class_Font_method_is_distance_field_hint>` **(** **)** |const| |
  56. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`update_changes<class_Font_method_update_changes>` **(** **)** |
  58. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. .. rst-class:: classref-section-separator
  60. ----
  61. .. rst-class:: classref-descriptions-group
  62. Enumerations
  63. ------------
  64. .. _enum_Font_ContourPointTag:
  65. .. rst-class:: classref-enumeration
  66. enum **ContourPointTag**:
  67. .. _class_Font_constant_CONTOUR_CURVE_TAG_ON:
  68. .. rst-class:: classref-enumeration-constant
  69. :ref:`ContourPointTag<enum_Font_ContourPointTag>` **CONTOUR_CURVE_TAG_ON** = ``1``
  70. Contour point is on the curve.
  71. .. _class_Font_constant_CONTOUR_CURVE_TAG_OFF_CONIC:
  72. .. rst-class:: classref-enumeration-constant
  73. :ref:`ContourPointTag<enum_Font_ContourPointTag>` **CONTOUR_CURVE_TAG_OFF_CONIC** = ``0``
  74. Contour point isn't on the curve, but serves as a control point for a conic (quadratic) Bézier arc.
  75. .. _class_Font_constant_CONTOUR_CURVE_TAG_OFF_CUBIC:
  76. .. rst-class:: classref-enumeration-constant
  77. :ref:`ContourPointTag<enum_Font_ContourPointTag>` **CONTOUR_CURVE_TAG_OFF_CUBIC** = ``2``
  78. Contour point isn't on the curve, but serves as a control point for a cubic Bézier arc.
  79. .. rst-class:: classref-section-separator
  80. ----
  81. .. rst-class:: classref-descriptions-group
  82. Method Descriptions
  83. -------------------
  84. .. _class_Font_method_draw:
  85. .. rst-class:: classref-method
  86. void **draw** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` string, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`int<class_int>` clip_w=-1, :ref:`Color<class_Color>` outline_modulate=Color( 1, 1, 1, 1 ) **)** |const|
  87. Draw ``string`` into a canvas item using the font at a given position, with ``modulate`` color, and optionally clipping the width. ``position`` specifies the baseline, not the top. To draw from the top, *ascent* must be added to the Y axis.
  88. See also :ref:`CanvasItem.draw_string<class_CanvasItem_method_draw_string>`.
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_Font_method_draw_char:
  92. .. rst-class:: classref-method
  93. :ref:`float<class_float>` **draw_char** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` char, :ref:`int<class_int>` next=-1, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` outline=false **)** |const|
  94. Draw character ``char`` into a canvas item using the font at a given position, with ``modulate`` color, and optionally kerning if ``next`` is passed. clipping the width. ``position`` specifies the baseline, not the top. To draw from the top, *ascent* must be added to the Y axis. The width used by the character is returned, making this function useful for drawing strings character by character.
  95. If ``outline`` is ``true``, the outline of the character is drawn instead of the character itself.
  96. .. rst-class:: classref-item-separator
  97. ----
  98. .. _class_Font_method_get_ascent:
  99. .. rst-class:: classref-method
  100. :ref:`float<class_float>` **get_ascent** **(** **)** |const|
  101. Returns the font ascent (number of pixels above the baseline).
  102. .. rst-class:: classref-item-separator
  103. ----
  104. .. _class_Font_method_get_char_contours:
  105. .. rst-class:: classref-method
  106. :ref:`Dictionary<class_Dictionary>` **get_char_contours** **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0 **)** |const|
  107. Returns outline contours of the glyph as a ``Dictionary`` with the following contents:
  108. \ ``points`` - :ref:`PoolVector3Array<class_PoolVector3Array>`, containing outline points. ``x`` and ``y`` are point coordinates. ``z`` is the type of the point, using the :ref:`ContourPointTag<enum_Font_ContourPointTag>` values.
  109. \ ``contours`` - :ref:`PoolIntArray<class_PoolIntArray>`, containing indices the end points of each contour.
  110. \ ``orientation`` - :ref:`bool<class_bool>`, contour orientation. If ``true``, clockwise contours must be filled.
  111. .. rst-class:: classref-item-separator
  112. ----
  113. .. _class_Font_method_get_char_size:
  114. .. rst-class:: classref-method
  115. :ref:`Vector2<class_Vector2>` **get_char_size** **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0 **)** |const|
  116. Returns the size of a character, optionally taking kerning into account if the next character is provided. Note that the height returned is the font height (see :ref:`get_height<class_Font_method_get_height>`) and has no relation to the glyph height.
  117. .. rst-class:: classref-item-separator
  118. ----
  119. .. _class_Font_method_get_char_texture:
  120. .. rst-class:: classref-method
  121. :ref:`RID<class_RID>` **get_char_texture** **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const|
  122. Returns resource id of the cache texture containing the char.
  123. .. rst-class:: classref-item-separator
  124. ----
  125. .. _class_Font_method_get_char_texture_size:
  126. .. rst-class:: classref-method
  127. :ref:`Vector2<class_Vector2>` **get_char_texture_size** **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const|
  128. Returns size of the cache texture containing the char.
  129. .. rst-class:: classref-item-separator
  130. ----
  131. .. _class_Font_method_get_char_tx_offset:
  132. .. rst-class:: classref-method
  133. :ref:`Vector2<class_Vector2>` **get_char_tx_offset** **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const|
  134. Returns char offset from the baseline.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_Font_method_get_char_tx_size:
  138. .. rst-class:: classref-method
  139. :ref:`Vector2<class_Vector2>` **get_char_tx_size** **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const|
  140. Returns size of the char.
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _class_Font_method_get_char_tx_uv_rect:
  144. .. rst-class:: classref-method
  145. :ref:`Rect2<class_Rect2>` **get_char_tx_uv_rect** **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0, :ref:`bool<class_bool>` outline=false **)** |const|
  146. Returns rectangle in the cache texture containing the char.
  147. .. rst-class:: classref-item-separator
  148. ----
  149. .. _class_Font_method_get_descent:
  150. .. rst-class:: classref-method
  151. :ref:`float<class_float>` **get_descent** **(** **)** |const|
  152. Returns the font descent (number of pixels below the baseline).
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. _class_Font_method_get_height:
  156. .. rst-class:: classref-method
  157. :ref:`float<class_float>` **get_height** **(** **)** |const|
  158. Returns the total font height (ascent plus descent) in pixels.
  159. .. rst-class:: classref-item-separator
  160. ----
  161. .. _class_Font_method_get_string_size:
  162. .. rst-class:: classref-method
  163. :ref:`Vector2<class_Vector2>` **get_string_size** **(** :ref:`String<class_String>` string **)** |const|
  164. Returns the size of a string, taking kerning and advance into account. Note that the height returned is the font height (see :ref:`get_height<class_Font_method_get_height>`) and has no relation to the string.
  165. .. rst-class:: classref-item-separator
  166. ----
  167. .. _class_Font_method_get_wordwrap_string_size:
  168. .. rst-class:: classref-method
  169. :ref:`Vector2<class_Vector2>` **get_wordwrap_string_size** **(** :ref:`String<class_String>` string, :ref:`float<class_float>` width **)** |const|
  170. Returns the size that the string would have with word wrapping enabled with a fixed ``width``.
  171. .. rst-class:: classref-item-separator
  172. ----
  173. .. _class_Font_method_has_outline:
  174. .. rst-class:: classref-method
  175. :ref:`bool<class_bool>` **has_outline** **(** **)** |const|
  176. Returns ``true`` if the font has an outline.
  177. .. rst-class:: classref-item-separator
  178. ----
  179. .. _class_Font_method_is_distance_field_hint:
  180. .. rst-class:: classref-method
  181. :ref:`bool<class_bool>` **is_distance_field_hint** **(** **)** |const|
  182. .. container:: contribute
  183. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  184. .. rst-class:: classref-item-separator
  185. ----
  186. .. _class_Font_method_update_changes:
  187. .. rst-class:: classref-method
  188. void **update_changes** **(** **)**
  189. After editing a font (changing size, ascent, char rects, etc.). Call this function to propagate changes to controls that might use it.
  190. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  191. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  192. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  193. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`