class_font.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Font:
  4. Font
  5. ====
  6. **Inherits:** :ref:`Resource<class_resource>` **<** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Internationalized font and text drawing support.
  11. Member Functions
  12. ----------------
  13. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`int<class_int>` | :ref:`create_from_fnt<class_Font_create_from_fnt>` **(** :ref:`String<class_string>` path **)** |
  15. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`set_height<class_Font_set_height>` **(** :ref:`float<class_float>` px **)** |
  17. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`float<class_float>` | :ref:`get_height<class_Font_get_height>` **(** **)** const |
  19. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | void | :ref:`set_ascent<class_Font_set_ascent>` **(** :ref:`float<class_float>` px **)** |
  21. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`float<class_float>` | :ref:`get_ascent<class_Font_get_ascent>` **(** **)** const |
  23. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`float<class_float>` | :ref:`get_descent<class_Font_get_descent>` **(** **)** const |
  25. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | void | :ref:`add_kerning_pair<class_Font_add_kerning_pair>` **(** :ref:`int<class_int>` char_a, :ref:`int<class_int>` char_b, :ref:`int<class_int>` kerning **)** |
  27. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`int<class_int>` | :ref:`get_kerning_pair<class_Font_get_kerning_pair>` **(** :ref:`int<class_int>` char_a, :ref:`int<class_int>` char_b **)** const |
  29. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | void | :ref:`add_texture<class_Font_add_texture>` **(** :ref:`Texture<class_texture>` texture **)** |
  31. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | void | :ref:`add_char<class_Font_add_char>` **(** :ref:`int<class_int>` character, :ref:`int<class_int>` texture, :ref:`Rect2<class_rect2>` rect, :ref:`Vector2<class_vector2>` align=Vector2(0,0), :ref:`float<class_float>` advance=-1 **)** |
  33. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`get_texture_count<class_Font_get_texture_count>` **(** **)** const |
  35. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Texture<class_texture>` | :ref:`get_texture<class_Font_get_texture>` **(** :ref:`int<class_int>` idx **)** const |
  37. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Vector2<class_vector2>` | :ref:`get_char_size<class_Font_get_char_size>` **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0 **)** const |
  39. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Vector2<class_vector2>` | :ref:`get_string_size<class_Font_get_string_size>` **(** :ref:`String<class_string>` string **)** const |
  41. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`set_distance_field_hint<class_Font_set_distance_field_hint>` **(** :ref:`bool<class_bool>` enable **)** |
  43. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`is_distance_field_hint<class_Font_is_distance_field_hint>` **(** **)** const |
  45. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`clear<class_Font_clear>` **(** **)** |
  47. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`draw<class_Font_draw>` **(** :ref:`RID<class_rid>` canvas_item, :ref:`Vector2<class_vector2>` pos, :ref:`String<class_string>` string, :ref:`Color<class_color>` modulate=Color(1,1,1,1), :ref:`int<class_int>` clip_w=-1 **)** const |
  49. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`float<class_float>` | :ref:`draw_char<class_Font_draw_char>` **(** :ref:`RID<class_rid>` canvas_item, :ref:`Vector2<class_vector2>` pos, :ref:`int<class_int>` char, :ref:`int<class_int>` next=-1, :ref:`Color<class_color>` modulate=Color(1,1,1,1) **)** const |
  51. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`set_fallback<class_Font_set_fallback>` **(** :ref:`Object<class_object>` fallback **)** |
  53. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Object<class_object>` | :ref:`get_fallback<class_Font_get_fallback>` **(** **)** const |
  55. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. Description
  57. -----------
  58. Font contains an 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. TODO check wikipedia for graph of ascent/baseline/descent/height/etc.
  59. Member Function Description
  60. ---------------------------
  61. .. _class_Font_create_from_fnt:
  62. - :ref:`int<class_int>` **create_from_fnt** **(** :ref:`String<class_string>` path **)**
  63. .. _class_Font_set_height:
  64. - void **set_height** **(** :ref:`float<class_float>` px **)**
  65. Set the total font height (ascent plus descent) in pixels.
  66. .. _class_Font_get_height:
  67. - :ref:`float<class_float>` **get_height** **(** **)** const
  68. Return the total font height (ascent plus descent) in pixels.
  69. .. _class_Font_set_ascent:
  70. - void **set_ascent** **(** :ref:`float<class_float>` px **)**
  71. Set the font ascent (number of pixels above the baseline).
  72. .. _class_Font_get_ascent:
  73. - :ref:`float<class_float>` **get_ascent** **(** **)** const
  74. Return the font ascent (number of pixels above the baseline).
  75. .. _class_Font_get_descent:
  76. - :ref:`float<class_float>` **get_descent** **(** **)** const
  77. Return the font descent (number of pixels below the baseline).
  78. .. _class_Font_add_kerning_pair:
  79. - void **add_kerning_pair** **(** :ref:`int<class_int>` char_a, :ref:`int<class_int>` char_b, :ref:`int<class_int>` kerning **)**
  80. Add a kerning pair to the :ref:`Font<class_font>` as a difference. Kerning pairs are special cases where a typeface advance is determined by the next character.
  81. .. _class_Font_get_kerning_pair:
  82. - :ref:`int<class_int>` **get_kerning_pair** **(** :ref:`int<class_int>` char_a, :ref:`int<class_int>` char_b **)** const
  83. Return a kerning pair as a difference. Kerning pairs are special cases where a typeface advance is determined by the next character.
  84. .. _class_Font_add_texture:
  85. - void **add_texture** **(** :ref:`Texture<class_texture>` texture **)**
  86. Add a texture to the :ref:`Font<class_font>`.
  87. .. _class_Font_add_char:
  88. - void **add_char** **(** :ref:`int<class_int>` character, :ref:`int<class_int>` texture, :ref:`Rect2<class_rect2>` rect, :ref:`Vector2<class_vector2>` align=Vector2(0,0), :ref:`float<class_float>` advance=-1 **)**
  89. Add a character to the font, where "character" is the unicode value, "texture" is the texture index, "rect" is the region in the texture (in pixels!), "align" is the (optional) alignment for the character and "advance" is the (optional) advance.
  90. .. _class_Font_get_texture_count:
  91. - :ref:`int<class_int>` **get_texture_count** **(** **)** const
  92. .. _class_Font_get_texture:
  93. - :ref:`Texture<class_texture>` **get_texture** **(** :ref:`int<class_int>` idx **)** const
  94. .. _class_Font_get_char_size:
  95. - :ref:`Vector2<class_vector2>` **get_char_size** **(** :ref:`int<class_int>` char, :ref:`int<class_int>` next=0 **)** const
  96. Return the size of a character, optionally taking kerning into account if the next character is provided.
  97. .. _class_Font_get_string_size:
  98. - :ref:`Vector2<class_vector2>` **get_string_size** **(** :ref:`String<class_string>` string **)** const
  99. Return the size of a string, taking kerning and advance into account.
  100. .. _class_Font_set_distance_field_hint:
  101. - void **set_distance_field_hint** **(** :ref:`bool<class_bool>` enable **)**
  102. .. _class_Font_is_distance_field_hint:
  103. - :ref:`bool<class_bool>` **is_distance_field_hint** **(** **)** const
  104. .. _class_Font_clear:
  105. - void **clear** **(** **)**
  106. Clear all the font data.
  107. .. _class_Font_draw:
  108. - void **draw** **(** :ref:`RID<class_rid>` canvas_item, :ref:`Vector2<class_vector2>` pos, :ref:`String<class_string>` string, :ref:`Color<class_color>` modulate=Color(1,1,1,1), :ref:`int<class_int>` clip_w=-1 **)** const
  109. Draw "string" into a canvas item using the font at a given "pos" position, with "modulate" color, and optionally clipping the width. "pos" specifies the baseline, not the top. To draw from the top, *ascent* must be added to the Y axis.
  110. .. _class_Font_draw_char:
  111. - :ref:`float<class_float>` **draw_char** **(** :ref:`RID<class_rid>` canvas_item, :ref:`Vector2<class_vector2>` pos, :ref:`int<class_int>` char, :ref:`int<class_int>` next=-1, :ref:`Color<class_color>` modulate=Color(1,1,1,1) **)** const
  112. Draw character "char" into a canvas item using the font at a given "pos" position, with "modulate" color, and optionally kerning if "next" is passed. clipping the width. "pos" 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.
  113. .. _class_Font_set_fallback:
  114. - void **set_fallback** **(** :ref:`Object<class_object>` fallback **)**
  115. .. _class_Font_get_fallback:
  116. - :ref:`Object<class_object>` **get_fallback** **(** **)** const