Font.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="Font" inherits="Resource" version="4.0">
  3. <brief_description>
  4. Font class is set of font data sources used to draw text.
  5. </brief_description>
  6. <description>
  7. Font contains a set of glyphs to represent Unicode characters, as well as the ability to draw it with variable width, ascent, descent and kerning.
  8. [b]Note:[/b] A character is a symbol that represents an item (letter, digit etc.) in an abstract way.
  9. [b]Note:[/b] A glyph is a bitmap or shape used to draw a one or more characters in a context-dependent manner. Glyph indices are bound to the specific font data source.
  10. [b]Note:[/b] If a non of the font data sources contain glyphs for a character used in a string, the character in question will be replaced with a box displaying its hexadecimal code.
  11. [codeblocks]
  12. [gdscript]
  13. var font = Font.new()
  14. font.add_data(load("res://BarlowCondensed-Bold.ttf"))
  15. $"Label".set("custom_fonts/font", font)
  16. $"Label".set("custom_fonts/font_size", 64)
  17. [/gdscript]
  18. [csharp]
  19. var font = new Font();
  20. font.AddData(ResourceLoader.Load&lt;FontData&gt;("res://BarlowCondensed-Bold.ttf"));
  21. GetNode("Label").Set("custom_fonts/font", font);
  22. GetNode("Label").Set("custom_font_sizes/font_size", 64);
  23. [/csharp]
  24. [/codeblocks]
  25. To control font substitution priority use [FontData] language and script support.
  26. Use language overrides to use same [Font] stack for multiple languages:
  27. [codeblocks]
  28. [gdscript]
  29. # Use Naskh font for Persian and Nastaʼlīq font for Urdu text.
  30. var font_data_fa = load("res://NotoNaskhArabicUI_Regular.ttf");
  31. font_data_fa.set_language_support_override("fa", true);
  32. font_data_fa.set_language_support_override("ur", false);
  33. var font_data_ur = load("res://NotoNastaliqUrdu_Regular.ttf");
  34. font_data_ur.set_language_support_override("fa", false);
  35. font_data_ur.set_language_support_override("ur", true);
  36. [/gdscript]
  37. [csharp]
  38. // Use Naskh font for Persian and Nastaʼlīq font for Urdu text.
  39. var fontDataFA = ResourceLoader.Load&lt;FontData&gt;("res://NotoNaskhArabicUI_Regular.ttf");
  40. fontDataFA.SetLanguageSupportOverride("fa", true);
  41. fontDataFA.SetLanguageSupportOverride("ur", false);
  42. var fontDataUR = ResourceLoader.Load&lt;FontData&gt;("res://NotoNastaliqUrdu_Regular.ttf");
  43. fontDataUR.SetLanguageSupportOverride("fa", false);
  44. fontDataUR.SetLanguageSupportOverride("ur", true);
  45. [/csharp]
  46. [/codeblocks]
  47. Use script overrides to specify supported scripts for bitmap font or for less common scripts not directly supported by TrueType format:
  48. [codeblocks]
  49. [gdscript]
  50. # Use specified font for Egyptian hieroglyphs.
  51. var font_data = load("res://unifont.ttf");
  52. font_data.set_script_support_override("Egyp", true);
  53. [/gdscript]
  54. [csharp]
  55. // Use specified font for Egyptian hieroglyphs.
  56. var fontData = ResourceLoader.Load&lt;FontData&gt;("res://unifont.ttf");
  57. fontData.SetScriptSupportOverride("Egyp", true);
  58. [/csharp]
  59. [/codeblocks]
  60. </description>
  61. <tutorials>
  62. </tutorials>
  63. <methods>
  64. <method name="add_data">
  65. <return type="void" />
  66. <argument index="0" name="data" type="FontData" />
  67. <description>
  68. Add font data source to the set.
  69. </description>
  70. </method>
  71. <method name="clear_data">
  72. <return type="void" />
  73. <description>
  74. Removes all font data sourcers for the set.
  75. </description>
  76. </method>
  77. <method name="draw_char" qualifiers="const">
  78. <return type="float" />
  79. <argument index="0" name="canvas_item" type="RID" />
  80. <argument index="1" name="pos" type="Vector2" />
  81. <argument index="2" name="char" type="int" />
  82. <argument index="3" name="next" type="int" default="0" />
  83. <argument index="4" name="size" type="int" default="16" />
  84. <argument index="5" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
  85. <argument index="6" name="outline_size" type="int" default="0" />
  86. <argument index="7" name="outline_modulate" type="Color" default="Color(1, 1, 1, 0)" />
  87. <description>
  88. Draw a single Unicode character [code]char[/code] into a canvas item using the font, at a given position, with [code]modulate[/code] color, and optionally kerning if [code]next[/code] is passed. [code]position[/code] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis.
  89. [b]Note:[/b] Do not use this function to draw strings character by character, use [method draw_string] or [TextLine] instead.
  90. </description>
  91. </method>
  92. <method name="draw_multiline_string" qualifiers="const">
  93. <return type="void" />
  94. <argument index="0" name="canvas_item" type="RID" />
  95. <argument index="1" name="pos" type="Vector2" />
  96. <argument index="2" name="text" type="String" />
  97. <argument index="3" name="align" type="int" enum="HAlign" default="0" />
  98. <argument index="4" name="width" type="float" default="-1" />
  99. <argument index="5" name="max_lines" type="int" default="-1" />
  100. <argument index="6" name="size" type="int" default="16" />
  101. <argument index="7" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
  102. <argument index="8" name="outline_size" type="int" default="0" />
  103. <argument index="9" name="outline_modulate" type="Color" default="Color(1, 1, 1, 0)" />
  104. <argument index="10" name="flags" type="int" default="99" />
  105. <description>
  106. Breaks [code]text[/code] to the lines using rules specified by [code]flags[/code] and draws it into a canvas item using the font, at a given position, with [code]modulate[/code] color, optionally clipping the width and aligning horizontally. [code]position[/code] specifies the baseline of the first line, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis.
  107. See also [method CanvasItem.draw_multiline_string].
  108. </description>
  109. </method>
  110. <method name="draw_string" qualifiers="const">
  111. <return type="void" />
  112. <argument index="0" name="canvas_item" type="RID" />
  113. <argument index="1" name="pos" type="Vector2" />
  114. <argument index="2" name="text" type="String" />
  115. <argument index="3" name="align" type="int" enum="HAlign" default="0" />
  116. <argument index="4" name="width" type="float" default="-1" />
  117. <argument index="5" name="size" type="int" default="16" />
  118. <argument index="6" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
  119. <argument index="7" name="outline_size" type="int" default="0" />
  120. <argument index="8" name="outline_modulate" type="Color" default="Color(1, 1, 1, 0)" />
  121. <argument index="9" name="flags" type="int" default="3" />
  122. <description>
  123. Draw [code]text[/code] into a canvas item using the font, at a given position, with [code]modulate[/code] color, optionally clipping the width and aligning horizontally. [code]position[/code] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis.
  124. See also [method CanvasItem.draw_string].
  125. </description>
  126. </method>
  127. <method name="get_ascent" qualifiers="const">
  128. <return type="float" />
  129. <argument index="0" name="size" type="int" default="16" />
  130. <description>
  131. Returns the average font ascent (number of pixels above the baseline).
  132. [b]Note:[/b] Real ascent of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the ascent of empty line).
  133. </description>
  134. </method>
  135. <method name="get_char_size" qualifiers="const">
  136. <return type="Vector2" />
  137. <argument index="0" name="char" type="int" />
  138. <argument index="1" name="next" type="int" default="0" />
  139. <argument index="2" name="size" type="int" default="16" />
  140. <description>
  141. Returns the size of a character, optionally taking kerning into account if the next character is provided.
  142. [b]Note:[/b] Do not use this function to calculate width of the string character by character, use [method get_string_size] or [TextLine] instead. The height returned is the font height (see also [method get_height]) and has no relation to the glyph height.
  143. </description>
  144. </method>
  145. <method name="get_data" qualifiers="const">
  146. <return type="FontData" />
  147. <argument index="0" name="idx" type="int" />
  148. <description>
  149. Returns the font data source at index [code]idx[/code]. If the index does not exist, returns [code]null[/code].
  150. </description>
  151. </method>
  152. <method name="get_data_count" qualifiers="const">
  153. <return type="int" />
  154. <description>
  155. Returns the number of font data sources.
  156. </description>
  157. </method>
  158. <method name="get_data_rid" qualifiers="const">
  159. <return type="RID" />
  160. <argument index="0" name="idx" type="int" />
  161. <description>
  162. Returns TextServer RID of the font data resources.
  163. </description>
  164. </method>
  165. <method name="get_descent" qualifiers="const">
  166. <return type="float" />
  167. <argument index="0" name="size" type="int" default="16" />
  168. <description>
  169. Returns the average font descent (number of pixels below the baseline).
  170. [b]Note:[/b] Real descent of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the descent of empty line).
  171. </description>
  172. </method>
  173. <method name="get_height" qualifiers="const">
  174. <return type="float" />
  175. <argument index="0" name="size" type="int" default="16" />
  176. <description>
  177. Returns the total average font height (ascent plus descent) in pixels.
  178. [b]Note:[/b] Real height of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the height of empty line).
  179. </description>
  180. </method>
  181. <method name="get_multiline_string_size" qualifiers="const">
  182. <return type="Vector2" />
  183. <argument index="0" name="text" type="String" />
  184. <argument index="1" name="width" type="float" default="-1" />
  185. <argument index="2" name="size" type="int" default="16" />
  186. <argument index="3" name="flags" type="int" default="96" />
  187. <description>
  188. Returns the size of a bounding box of a string broken into the lines, taking kerning and advance into account.
  189. See also [method draw_multiline_string].
  190. </description>
  191. </method>
  192. <method name="get_spacing" qualifiers="const">
  193. <return type="int" />
  194. <argument index="0" name="spacing" type="int" enum="TextServer.SpacingType" />
  195. <description>
  196. Returns the spacing for the given [code]type[/code] (see [enum TextServer.SpacingType]).
  197. </description>
  198. </method>
  199. <method name="get_string_size" qualifiers="const">
  200. <return type="Vector2" />
  201. <argument index="0" name="text" type="String" />
  202. <argument index="1" name="size" type="int" default="16" />
  203. <argument index="2" name="align" type="int" enum="HAlign" default="0" />
  204. <argument index="3" name="width" type="float" default="-1" />
  205. <argument index="4" name="flags" type="int" default="3" />
  206. <description>
  207. Returns the size of a bounding box of a string, taking kerning and advance into account.
  208. [b]Note:[/b] Real height of the string is context-dependent and can be significantly different from the value returned by [method get_height].
  209. See also [method draw_string].
  210. </description>
  211. </method>
  212. <method name="get_supported_chars" qualifiers="const">
  213. <return type="String" />
  214. <description>
  215. Returns a string containing all the characters available in the font.
  216. If a given character is included in more than one font data source, it appears only once in the returned string.
  217. </description>
  218. </method>
  219. <method name="get_underline_position" qualifiers="const">
  220. <return type="float" />
  221. <argument index="0" name="size" type="int" default="16" />
  222. <description>
  223. Return average pixel offset of the underline below the baseline.
  224. [b]Note:[/b] Real underline position of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate.
  225. </description>
  226. </method>
  227. <method name="get_underline_thickness" qualifiers="const">
  228. <return type="float" />
  229. <argument index="0" name="size" type="int" default="16" />
  230. <description>
  231. Return average thickness of the underline.
  232. [b]Note:[/b] Real underline thickness of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate.
  233. </description>
  234. </method>
  235. <method name="has_char" qualifiers="const">
  236. <return type="bool" />
  237. <argument index="0" name="char" type="int" />
  238. <description>
  239. Return [code]true[/code] if a Unicode [code]char[/code] is available in the font.
  240. </description>
  241. </method>
  242. <method name="remove_data">
  243. <return type="void" />
  244. <argument index="0" name="idx" type="int" />
  245. <description>
  246. Removes the font data source at index [code]idx[/code]. If the index does not exist, nothing happens.
  247. </description>
  248. </method>
  249. <method name="set_data">
  250. <return type="void" />
  251. <argument index="0" name="idx" type="int" />
  252. <argument index="1" name="data" type="FontData" />
  253. <description>
  254. Sets the font data source at index [code]idx[/code]. If the index does not exist, nothing happens.
  255. </description>
  256. </method>
  257. <method name="set_spacing">
  258. <return type="void" />
  259. <argument index="0" name="spacing" type="int" enum="TextServer.SpacingType" />
  260. <argument index="1" name="value" type="int" />
  261. <description>
  262. Sets the spacing for [code]type[/code] (see [enum TextServer.SpacingType]) to [code]value[/code] in pixels (not relative to the font size).
  263. </description>
  264. </method>
  265. <method name="update_changes">
  266. <return type="void" />
  267. <description>
  268. After editing a font (changing data sources, etc.). Call this function to propagate changes to controls that might use it.
  269. </description>
  270. </method>
  271. </methods>
  272. <members>
  273. <member name="spacing_bottom" type="int" setter="set_spacing" getter="get_spacing" default="0">
  274. Extra spacing at the bottom of the line in pixels.
  275. </member>
  276. <member name="spacing_top" type="int" setter="set_spacing" getter="get_spacing" default="0">
  277. Extra spacing at the top of the line in pixels.
  278. </member>
  279. <member name="variation_coordinates" type="Dictionary" setter="set_variation_coordinates" getter="get_variation_coordinates" default="{}">
  280. Default font [url=https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxisreg]variation coordinates[/url].
  281. </member>
  282. </members>
  283. </class>