bitmap_font_adv.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*************************************************************************/
  2. /* bitmap_font_adv.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "bitmap_font_adv.h"
  31. /*************************************************************************/
  32. /* hb_bmp_font_t HarfBuzz Bitmap font interface */
  33. /*************************************************************************/
  34. struct hb_bmp_font_t {
  35. BitmapFontDataAdvanced *face = nullptr;
  36. float font_size = 0.0;
  37. bool unref = false; /* Whether to destroy bm_face when done. */
  38. };
  39. static hb_bmp_font_t *_hb_bmp_font_create(BitmapFontDataAdvanced *p_face, float p_font_size, bool p_unref) {
  40. hb_bmp_font_t *bm_font = reinterpret_cast<hb_bmp_font_t *>(calloc(1, sizeof(hb_bmp_font_t)));
  41. if (!bm_font) {
  42. return nullptr;
  43. }
  44. bm_font->face = p_face;
  45. bm_font->font_size = p_font_size;
  46. bm_font->unref = p_unref;
  47. return bm_font;
  48. }
  49. static void _hb_bmp_font_destroy(void *data) {
  50. hb_bmp_font_t *bm_font = reinterpret_cast<hb_bmp_font_t *>(data);
  51. free(bm_font);
  52. }
  53. static hb_bool_t hb_bmp_get_nominal_glyph(hb_font_t *font, void *font_data, hb_codepoint_t unicode, hb_codepoint_t *glyph, void *user_data) {
  54. const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
  55. if (!bm_font->face) {
  56. return false;
  57. }
  58. if (!bm_font->face->has_char(unicode)) {
  59. if (bm_font->face->has_char(0xF000u + unicode)) {
  60. *glyph = 0xF000u + unicode;
  61. return true;
  62. } else {
  63. return false;
  64. }
  65. }
  66. *glyph = unicode;
  67. return true;
  68. }
  69. static hb_position_t hb_bmp_get_glyph_h_advance(hb_font_t *font, void *font_data, hb_codepoint_t glyph, void *user_data) {
  70. const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
  71. if (!bm_font->face) {
  72. return 0;
  73. }
  74. if (!bm_font->face->has_char(glyph)) {
  75. return 0;
  76. }
  77. return bm_font->face->get_advance(glyph, bm_font->font_size).x * 64;
  78. }
  79. static hb_position_t hb_bmp_get_glyph_v_advance(hb_font_t *font, void *font_data, hb_codepoint_t glyph, void *user_data) {
  80. const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
  81. if (!bm_font->face) {
  82. return 0;
  83. }
  84. if (!bm_font->face->has_char(glyph)) {
  85. return 0;
  86. }
  87. return -bm_font->face->get_advance(glyph, bm_font->font_size).y * 64;
  88. }
  89. static hb_position_t hb_bmp_get_glyph_h_kerning(hb_font_t *font, void *font_data, hb_codepoint_t left_glyph, hb_codepoint_t right_glyph, void *user_data) {
  90. const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
  91. if (!bm_font->face) {
  92. return 0;
  93. }
  94. if (!bm_font->face->has_char(left_glyph)) {
  95. return 0;
  96. }
  97. if (!bm_font->face->has_char(right_glyph)) {
  98. return 0;
  99. }
  100. return bm_font->face->get_kerning(left_glyph, right_glyph, bm_font->font_size).x * 64;
  101. }
  102. static hb_bool_t hb_bmp_get_glyph_v_origin(hb_font_t *font, void *font_data, hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y, void *user_data) {
  103. const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
  104. if (!bm_font->face) {
  105. return false;
  106. }
  107. if (!bm_font->face->has_char(glyph)) {
  108. return false;
  109. }
  110. *x = bm_font->face->get_advance(glyph, bm_font->font_size).x * 32;
  111. *y = bm_font->face->get_ascent(bm_font->font_size) * 64;
  112. return true;
  113. }
  114. static hb_bool_t hb_bmp_get_glyph_extents(hb_font_t *font, void *font_data, hb_codepoint_t glyph, hb_glyph_extents_t *extents, void *user_data) {
  115. const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
  116. if (!bm_font->face) {
  117. return false;
  118. }
  119. if (!bm_font->face->has_char(glyph)) {
  120. return false;
  121. }
  122. extents->x_bearing = 0;
  123. extents->y_bearing = 0;
  124. extents->width = bm_font->face->get_size(glyph, bm_font->font_size).x * 64;
  125. extents->height = bm_font->face->get_size(glyph, bm_font->font_size).y * 64;
  126. return true;
  127. }
  128. static hb_bool_t hb_bmp_get_font_h_extents(hb_font_t *font, void *font_data, hb_font_extents_t *metrics, void *user_data) {
  129. const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(font_data);
  130. if (!bm_font->face) {
  131. return false;
  132. }
  133. metrics->ascender = bm_font->face->get_ascent(bm_font->font_size);
  134. metrics->descender = bm_font->face->get_descent(bm_font->font_size);
  135. metrics->line_gap = 0;
  136. return true;
  137. }
  138. static hb_font_funcs_t *funcs = nullptr;
  139. void hb_bmp_create_font_funcs() {
  140. funcs = hb_font_funcs_create();
  141. hb_font_funcs_set_font_h_extents_func(funcs, hb_bmp_get_font_h_extents, nullptr, nullptr);
  142. //hb_font_funcs_set_font_v_extents_func (funcs, hb_bmp_get_font_v_extents, nullptr, nullptr);
  143. hb_font_funcs_set_nominal_glyph_func(funcs, hb_bmp_get_nominal_glyph, nullptr, nullptr);
  144. //hb_font_funcs_set_variation_glyph_func (funcs, hb_bmp_get_variation_glyph, nullptr, nullptr);
  145. hb_font_funcs_set_glyph_h_advance_func(funcs, hb_bmp_get_glyph_h_advance, nullptr, nullptr);
  146. hb_font_funcs_set_glyph_v_advance_func(funcs, hb_bmp_get_glyph_v_advance, nullptr, nullptr);
  147. //hb_font_funcs_set_glyph_h_origin_func(funcs, hb_bmp_get_glyph_h_origin, nullptr, nullptr);
  148. hb_font_funcs_set_glyph_v_origin_func(funcs, hb_bmp_get_glyph_v_origin, nullptr, nullptr);
  149. hb_font_funcs_set_glyph_h_kerning_func(funcs, hb_bmp_get_glyph_h_kerning, nullptr, nullptr);
  150. //hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_bmp_get_glyph_v_kerning, nullptr, nullptr);
  151. hb_font_funcs_set_glyph_extents_func(funcs, hb_bmp_get_glyph_extents, nullptr, nullptr);
  152. //hb_font_funcs_set_glyph_contour_point_func (funcs, hb_bmp_get_glyph_contour_point, nullptr, nullptr);
  153. //hb_font_funcs_set_glyph_name_func (funcs, hb_bmp_get_glyph_name, nullptr, nullptr);
  154. //hb_font_funcs_set_glyph_from_name_func (funcs, hb_bmp_get_glyph_from_name, nullptr, nullptr);
  155. hb_font_funcs_make_immutable(funcs);
  156. }
  157. void hb_bmp_free_font_funcs() {
  158. if (funcs != nullptr) {
  159. hb_font_funcs_destroy(funcs);
  160. funcs = nullptr;
  161. }
  162. }
  163. static void _hb_bmp_font_set_funcs(hb_font_t *p_font, BitmapFontDataAdvanced *p_face, int p_size, bool p_unref) {
  164. hb_font_set_funcs(p_font, funcs, _hb_bmp_font_create(p_face, p_size, p_unref), _hb_bmp_font_destroy);
  165. }
  166. hb_font_t *hb_bmp_font_create(BitmapFontDataAdvanced *p_face, int p_size, hb_destroy_func_t p_destroy) {
  167. hb_font_t *font;
  168. hb_face_t *face = hb_face_create(nullptr, 0);
  169. font = hb_font_create(face);
  170. hb_face_destroy(face);
  171. _hb_bmp_font_set_funcs(font, p_face, p_size, false);
  172. return font;
  173. }
  174. /*************************************************************************/
  175. /* BitmapFontDataAdvanced */
  176. /*************************************************************************/
  177. Error BitmapFontDataAdvanced::load_from_file(const String &p_filename, int p_base_size) {
  178. _THREAD_SAFE_METHOD_
  179. //fnt format used by angelcode bmfont
  180. //http://www.angelcode.com/products/bmfont/
  181. FileAccess *f = FileAccess::open(p_filename, FileAccess::READ);
  182. ERR_FAIL_COND_V_MSG(!f, ERR_FILE_NOT_FOUND, "Can't open font: " + p_filename + ".");
  183. while (true) {
  184. String line = f->get_line();
  185. int delimiter = line.find(" ");
  186. String type = line.substr(0, delimiter);
  187. int pos = delimiter + 1;
  188. Map<String, String> keys;
  189. while (pos < line.size() && line[pos] == ' ') {
  190. pos++;
  191. }
  192. while (pos < line.size()) {
  193. int eq = line.find("=", pos);
  194. if (eq == -1) {
  195. break;
  196. }
  197. String key = line.substr(pos, eq - pos);
  198. int end = -1;
  199. String value;
  200. if (line[eq + 1] == '"') {
  201. end = line.find("\"", eq + 2);
  202. if (end == -1) {
  203. break;
  204. }
  205. value = line.substr(eq + 2, end - 1 - eq - 1);
  206. pos = end + 1;
  207. } else {
  208. end = line.find(" ", eq + 1);
  209. if (end == -1) {
  210. end = line.size();
  211. }
  212. value = line.substr(eq + 1, end - eq);
  213. pos = end;
  214. }
  215. while (pos < line.size() && line[pos] == ' ') {
  216. pos++;
  217. }
  218. keys[key] = value;
  219. }
  220. if (type == "info") {
  221. if (keys.has("size")) {
  222. base_size = keys["size"].to_int();
  223. }
  224. } else if (type == "common") {
  225. if (keys.has("lineHeight")) {
  226. height = keys["lineHeight"].to_int();
  227. }
  228. if (keys.has("base")) {
  229. ascent = keys["base"].to_int();
  230. }
  231. } else if (type == "page") {
  232. if (keys.has("file")) {
  233. String base_dir = p_filename.get_base_dir();
  234. String file = base_dir.plus_file(keys["file"]);
  235. if (RenderingServer::get_singleton() != nullptr) {
  236. Ref<Texture2D> tex = ResourceLoader::load(file);
  237. if (tex.is_null()) {
  238. ERR_PRINT("Can't load font texture!");
  239. } else {
  240. ERR_FAIL_COND_V_MSG(tex.is_null(), ERR_FILE_CANT_READ, "It's not a reference to a valid Texture object.");
  241. textures.push_back(tex);
  242. }
  243. }
  244. }
  245. } else if (type == "char") {
  246. Character c;
  247. char32_t idx = 0;
  248. if (keys.has("id")) {
  249. idx = keys["id"].to_int();
  250. }
  251. if (keys.has("x")) {
  252. c.rect.position.x = keys["x"].to_int();
  253. }
  254. if (keys.has("y")) {
  255. c.rect.position.y = keys["y"].to_int();
  256. }
  257. if (keys.has("width")) {
  258. c.rect.size.width = keys["width"].to_int();
  259. }
  260. if (keys.has("height")) {
  261. c.rect.size.height = keys["height"].to_int();
  262. }
  263. if (keys.has("xoffset")) {
  264. c.align.x = keys["xoffset"].to_int();
  265. }
  266. if (keys.has("yoffset")) {
  267. c.align.y = keys["yoffset"].to_int();
  268. }
  269. if (keys.has("page")) {
  270. c.texture_idx = keys["page"].to_int();
  271. }
  272. if (keys.has("xadvance")) {
  273. c.advance.x = keys["xadvance"].to_int();
  274. }
  275. if (keys.has("yadvance")) {
  276. c.advance.x = keys["yadvance"].to_int();
  277. }
  278. if (c.advance.x < 0) {
  279. c.advance.x = c.rect.size.width + 1;
  280. }
  281. if (c.advance.y < 0) {
  282. c.advance.y = c.rect.size.height + 1;
  283. }
  284. char_map[idx] = c;
  285. } else if (type == "kerning") {
  286. KerningPairKey kpk;
  287. float k = 0.0;
  288. if (keys.has("first")) {
  289. kpk.A = keys["first"].to_int();
  290. }
  291. if (keys.has("second")) {
  292. kpk.B = keys["second"].to_int();
  293. }
  294. if (keys.has("amount")) {
  295. k = keys["amount"].to_int();
  296. }
  297. kerning_map[kpk] = k;
  298. }
  299. if (f->eof_reached()) {
  300. break;
  301. }
  302. }
  303. if (base_size == 0) {
  304. base_size = height;
  305. }
  306. if (hb_handle) {
  307. hb_font_destroy(hb_handle);
  308. }
  309. hb_handle = hb_bmp_font_create(this, base_size, nullptr);
  310. valid = true;
  311. memdelete(f);
  312. return OK;
  313. }
  314. Error BitmapFontDataAdvanced::bitmap_new(float p_height, float p_ascent, int p_base_size) {
  315. height = p_height;
  316. ascent = p_ascent;
  317. base_size = p_base_size;
  318. if (base_size == 0) {
  319. base_size = height;
  320. }
  321. char_map.clear();
  322. textures.clear();
  323. kerning_map.clear();
  324. if (hb_handle) {
  325. hb_font_destroy(hb_handle);
  326. }
  327. hb_handle = hb_bmp_font_create(this, base_size, nullptr);
  328. valid = true;
  329. return OK;
  330. }
  331. void BitmapFontDataAdvanced::bitmap_add_texture(const Ref<Texture> &p_texture) {
  332. ERR_FAIL_COND(!valid);
  333. ERR_FAIL_COND_MSG(p_texture.is_null(), "It's not a reference to a valid Texture object.");
  334. textures.push_back(p_texture);
  335. }
  336. void BitmapFontDataAdvanced::bitmap_add_char(char32_t p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance) {
  337. ERR_FAIL_COND(!valid);
  338. Character chr;
  339. chr.rect = p_rect;
  340. chr.texture_idx = p_texture_idx;
  341. if (p_advance < 0) {
  342. chr.advance.x = chr.rect.size.x;
  343. } else {
  344. chr.advance.x = p_advance;
  345. }
  346. chr.align = p_align;
  347. char_map[p_char] = chr;
  348. }
  349. void BitmapFontDataAdvanced::bitmap_add_kerning_pair(char32_t p_A, char32_t p_B, int p_kerning) {
  350. ERR_FAIL_COND(!valid);
  351. KerningPairKey kpk;
  352. kpk.A = p_A;
  353. kpk.B = p_B;
  354. if (p_kerning == 0 && kerning_map.has(kpk)) {
  355. kerning_map.erase(kpk);
  356. } else {
  357. kerning_map[kpk] = p_kerning;
  358. }
  359. }
  360. float BitmapFontDataAdvanced::get_height(int p_size) const {
  361. ERR_FAIL_COND_V(!valid, 0.f);
  362. return height * (float(p_size) / float(base_size));
  363. }
  364. float BitmapFontDataAdvanced::get_ascent(int p_size) const {
  365. ERR_FAIL_COND_V(!valid, 0.f);
  366. return ascent * (float(p_size) / float(base_size));
  367. }
  368. float BitmapFontDataAdvanced::get_descent(int p_size) const {
  369. ERR_FAIL_COND_V(!valid, 0.f);
  370. return (height - ascent) * (float(p_size) / float(base_size));
  371. }
  372. float BitmapFontDataAdvanced::get_underline_position(int p_size) const {
  373. ERR_FAIL_COND_V(!valid, 0.f);
  374. return 2 * (float(p_size) / float(base_size));
  375. }
  376. float BitmapFontDataAdvanced::get_underline_thickness(int p_size) const {
  377. ERR_FAIL_COND_V(!valid, 0.f);
  378. return 1 * (float(p_size) / float(base_size));
  379. }
  380. void BitmapFontDataAdvanced::set_distance_field_hint(bool p_distance_field) {
  381. distance_field_hint = p_distance_field;
  382. }
  383. bool BitmapFontDataAdvanced::get_distance_field_hint() const {
  384. return distance_field_hint;
  385. }
  386. float BitmapFontDataAdvanced::get_base_size() const {
  387. return base_size;
  388. }
  389. hb_font_t *BitmapFontDataAdvanced::get_hb_handle(int p_size) {
  390. _THREAD_SAFE_METHOD_
  391. ERR_FAIL_COND_V(!valid, nullptr);
  392. return hb_handle;
  393. }
  394. bool BitmapFontDataAdvanced::has_char(char32_t p_char) const {
  395. _THREAD_SAFE_METHOD_
  396. ERR_FAIL_COND_V(!valid, false);
  397. return char_map.has(p_char);
  398. }
  399. String BitmapFontDataAdvanced::get_supported_chars() const {
  400. _THREAD_SAFE_METHOD_
  401. ERR_FAIL_COND_V(!valid, String());
  402. String chars;
  403. const uint32_t *k = nullptr;
  404. while ((k = char_map.next(k))) {
  405. chars += char32_t(*k);
  406. }
  407. return chars;
  408. }
  409. Vector2 BitmapFontDataAdvanced::get_advance(uint32_t p_char, int p_size) const {
  410. _THREAD_SAFE_METHOD_
  411. ERR_FAIL_COND_V(!valid, Vector2());
  412. const Character *c = char_map.getptr(p_char);
  413. ERR_FAIL_COND_V(c == nullptr, Vector2());
  414. return c->advance * (float(p_size) / float(base_size));
  415. }
  416. Vector2 BitmapFontDataAdvanced::get_align(uint32_t p_char, int p_size) const {
  417. _THREAD_SAFE_METHOD_
  418. ERR_FAIL_COND_V(!valid, Vector2());
  419. const Character *c = char_map.getptr(p_char);
  420. ERR_FAIL_COND_V(c == nullptr, Vector2());
  421. return c->align * (float(p_size) / float(base_size));
  422. }
  423. Vector2 BitmapFontDataAdvanced::get_size(uint32_t p_char, int p_size) const {
  424. _THREAD_SAFE_METHOD_
  425. ERR_FAIL_COND_V(!valid, Vector2());
  426. const Character *c = char_map.getptr(p_char);
  427. ERR_FAIL_COND_V(c == nullptr, Vector2());
  428. return c->rect.size * (float(p_size) / float(base_size));
  429. }
  430. float BitmapFontDataAdvanced::get_font_scale(int p_size) const {
  431. return float(p_size) / float(base_size);
  432. }
  433. Vector2 BitmapFontDataAdvanced::get_kerning(uint32_t p_char, uint32_t p_next, int p_size) const {
  434. _THREAD_SAFE_METHOD_
  435. ERR_FAIL_COND_V(!valid, Vector2());
  436. KerningPairKey kpk;
  437. kpk.A = p_char;
  438. kpk.B = p_next;
  439. const Map<KerningPairKey, int>::Element *E = kerning_map.find(kpk);
  440. if (E) {
  441. return Vector2(-E->get() * (float(p_size) / float(base_size)), 0.f);
  442. } else {
  443. return Vector2();
  444. }
  445. }
  446. Vector2 BitmapFontDataAdvanced::draw_glyph(RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const {
  447. _THREAD_SAFE_METHOD_
  448. if (p_index == 0) {
  449. return Vector2();
  450. }
  451. ERR_FAIL_COND_V(!valid, Vector2());
  452. const Character *c = char_map.getptr(p_index);
  453. ERR_FAIL_COND_V(c == nullptr, Vector2());
  454. ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), Vector2());
  455. if (c->texture_idx != -1) {
  456. Point2i cpos = p_pos;
  457. cpos += (c->align + Vector2(0, -ascent)) * (float(p_size) / float(base_size));
  458. Size2i csize = c->rect.size * (float(p_size) / float(base_size));
  459. if (RenderingServer::get_singleton() != nullptr) {
  460. //if (distance_field_hint) { // Not implemented.
  461. // RenderingServer::get_singleton()->canvas_item_set_distance_field_mode(p_canvas, true);
  462. //}
  463. RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), textures[c->texture_idx]->get_rid(), c->rect, p_color, false, false);
  464. //if (distance_field_hint) {
  465. // RenderingServer::get_singleton()->canvas_item_set_distance_field_mode(p_canvas, false);
  466. //}
  467. }
  468. }
  469. return c->advance * (float(p_size) / float(base_size));
  470. }
  471. Vector2 BitmapFontDataAdvanced::draw_glyph_outline(RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const {
  472. _THREAD_SAFE_METHOD_
  473. if (p_index == 0) {
  474. return Vector2();
  475. }
  476. ERR_FAIL_COND_V(!valid, Vector2());
  477. const Character *c = char_map.getptr(p_index);
  478. ERR_FAIL_COND_V(c == nullptr, Vector2());
  479. ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), Vector2());
  480. // Not supported, return advance for compatibility.
  481. return c->advance * (float(p_size) / float(base_size));
  482. }
  483. BitmapFontDataAdvanced::~BitmapFontDataAdvanced() {
  484. if (hb_handle) {
  485. hb_font_destroy(hb_handle);
  486. }
  487. }