text_line.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /**************************************************************************/
  2. /* text_line.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "text_line.h"
  31. #include "text_line.compat.inc"
  32. void TextLine::_bind_methods() {
  33. ClassDB::bind_method(D_METHOD("clear"), &TextLine::clear);
  34. ClassDB::bind_method(D_METHOD("duplicate"), &TextLine::duplicate);
  35. ClassDB::bind_method(D_METHOD("set_direction", "direction"), &TextLine::set_direction);
  36. ClassDB::bind_method(D_METHOD("get_direction"), &TextLine::get_direction);
  37. ClassDB::bind_method(D_METHOD("get_inferred_direction"), &TextLine::get_inferred_direction);
  38. ADD_PROPERTY(PropertyInfo(Variant::INT, "direction", PROPERTY_HINT_ENUM, "Auto,Left-to-right,Right-to-left"), "set_direction", "get_direction");
  39. // If compiling the editor with TextServerFallback only,
  40. // `--doctool` would change the default value to `TextServer::DIRECTION_LTR`.
  41. // Force it so that it's consistent regardless of the backend.
  42. ADD_PROPERTY_DEFAULT("direction", TextServer::DIRECTION_AUTO);
  43. ClassDB::bind_method(D_METHOD("set_orientation", "orientation"), &TextLine::set_orientation);
  44. ClassDB::bind_method(D_METHOD("get_orientation"), &TextLine::get_orientation);
  45. ADD_PROPERTY(PropertyInfo(Variant::INT, "orientation", PROPERTY_HINT_ENUM, "Horizontal,Orientation"), "set_orientation", "get_orientation");
  46. ClassDB::bind_method(D_METHOD("set_preserve_invalid", "enabled"), &TextLine::set_preserve_invalid);
  47. ClassDB::bind_method(D_METHOD("get_preserve_invalid"), &TextLine::get_preserve_invalid);
  48. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "preserve_invalid"), "set_preserve_invalid", "get_preserve_invalid");
  49. ClassDB::bind_method(D_METHOD("set_preserve_control", "enabled"), &TextLine::set_preserve_control);
  50. ClassDB::bind_method(D_METHOD("get_preserve_control"), &TextLine::get_preserve_control);
  51. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "preserve_control"), "set_preserve_control", "get_preserve_control");
  52. ClassDB::bind_method(D_METHOD("set_bidi_override", "override"), &TextLine::set_bidi_override);
  53. ClassDB::bind_method(D_METHOD("add_string", "text", "font", "font_size", "language", "meta"), &TextLine::add_string, DEFVAL(""), DEFVAL(Variant()));
  54. ClassDB::bind_method(D_METHOD("add_object", "key", "size", "inline_align", "length", "baseline"), &TextLine::add_object, DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(1), DEFVAL(0.0));
  55. ClassDB::bind_method(D_METHOD("resize_object", "key", "size", "inline_align", "baseline"), &TextLine::resize_object, DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(0.0));
  56. ClassDB::bind_method(D_METHOD("has_object", "key"), &TextLine::has_object);
  57. ClassDB::bind_method(D_METHOD("set_width", "width"), &TextLine::set_width);
  58. ClassDB::bind_method(D_METHOD("get_width"), &TextLine::get_width);
  59. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "width"), "set_width", "get_width");
  60. ClassDB::bind_method(D_METHOD("set_horizontal_alignment", "alignment"), &TextLine::set_horizontal_alignment);
  61. ClassDB::bind_method(D_METHOD("get_horizontal_alignment"), &TextLine::get_horizontal_alignment);
  62. ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment");
  63. ClassDB::bind_method(D_METHOD("tab_align", "tab_stops"), &TextLine::tab_align);
  64. ClassDB::bind_method(D_METHOD("set_flags", "flags"), &TextLine::set_flags);
  65. ClassDB::bind_method(D_METHOD("get_flags"), &TextLine::get_flags);
  66. ADD_PROPERTY(PropertyInfo(Variant::INT, "flags", PROPERTY_HINT_FLAGS, "Kashida Justification,Word Justification,Trim Edge Spaces After Justification,Justify Only After Last Tab,Constrain Ellipsis"), "set_flags", "get_flags");
  67. ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &TextLine::set_text_overrun_behavior);
  68. ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &TextLine::get_text_overrun_behavior);
  69. ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis (6+ Characters),Word Ellipsis (6+ Characters),Ellipsis (Always),Word Ellipsis (Always)"), "set_text_overrun_behavior", "get_text_overrun_behavior");
  70. ClassDB::bind_method(D_METHOD("set_ellipsis_char", "char"), &TextLine::set_ellipsis_char);
  71. ClassDB::bind_method(D_METHOD("get_ellipsis_char"), &TextLine::get_ellipsis_char);
  72. ADD_PROPERTY(PropertyInfo(Variant::STRING, "ellipsis_char"), "set_ellipsis_char", "get_ellipsis_char");
  73. ClassDB::bind_method(D_METHOD("get_objects"), &TextLine::get_objects);
  74. ClassDB::bind_method(D_METHOD("get_object_rect", "key"), &TextLine::get_object_rect);
  75. ClassDB::bind_method(D_METHOD("get_size"), &TextLine::get_size);
  76. ClassDB::bind_method(D_METHOD("get_rid"), &TextLine::get_rid);
  77. ClassDB::bind_method(D_METHOD("get_line_ascent"), &TextLine::get_line_ascent);
  78. ClassDB::bind_method(D_METHOD("get_line_descent"), &TextLine::get_line_descent);
  79. ClassDB::bind_method(D_METHOD("get_line_width"), &TextLine::get_line_width);
  80. ClassDB::bind_method(D_METHOD("get_line_underline_position"), &TextLine::get_line_underline_position);
  81. ClassDB::bind_method(D_METHOD("get_line_underline_thickness"), &TextLine::get_line_underline_thickness);
  82. ClassDB::bind_method(D_METHOD("draw", "canvas", "pos", "color", "oversampling"), &TextLine::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(0.0));
  83. ClassDB::bind_method(D_METHOD("draw_outline", "canvas", "pos", "outline_size", "color", "oversampling"), &TextLine::draw_outline, DEFVAL(1), DEFVAL(Color(1, 1, 1)), DEFVAL(0.0));
  84. ClassDB::bind_method(D_METHOD("hit_test", "coords"), &TextLine::hit_test);
  85. }
  86. void TextLine::_shape() const {
  87. // When a shaped text is invalidated by an external source, we want to reshape it.
  88. if (!TS->shaped_text_is_ready(rid)) {
  89. dirty = true;
  90. }
  91. if (dirty) {
  92. if (!tab_stops.is_empty()) {
  93. TS->shaped_text_tab_align(rid, tab_stops);
  94. }
  95. BitField<TextServer::TextOverrunFlag> overrun_flags = TextServer::OVERRUN_NO_TRIM;
  96. if (overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) {
  97. overrun_flags = TextServer::get_overrun_flags_from_behavior(overrun_behavior);
  98. if (alignment == HORIZONTAL_ALIGNMENT_FILL) {
  99. TS->shaped_text_fit_to_width(rid, width, flags);
  100. overrun_flags.set_flag(TextServer::OVERRUN_JUSTIFICATION_AWARE);
  101. TS->shaped_text_set_custom_ellipsis(rid, (el_char.length() > 0) ? el_char[0] : 0x2026);
  102. TS->shaped_text_overrun_trim_to_width(rid, width, overrun_flags);
  103. } else {
  104. TS->shaped_text_set_custom_ellipsis(rid, (el_char.length() > 0) ? el_char[0] : 0x2026);
  105. TS->shaped_text_overrun_trim_to_width(rid, width, overrun_flags);
  106. }
  107. } else if (alignment == HORIZONTAL_ALIGNMENT_FILL) {
  108. TS->shaped_text_fit_to_width(rid, width, flags);
  109. }
  110. dirty = false;
  111. }
  112. }
  113. RID TextLine::get_rid() const {
  114. return rid;
  115. }
  116. void TextLine::clear() {
  117. TS->shaped_text_clear(rid);
  118. }
  119. Ref<TextLine> TextLine::duplicate() const {
  120. Ref<TextLine> copy;
  121. copy.instantiate();
  122. if (rid.is_valid()) {
  123. TS->free_rid(copy->rid);
  124. copy->rid = TS->shaped_text_duplicate(rid);
  125. }
  126. copy->dirty = true;
  127. copy->width = width;
  128. copy->flags = flags;
  129. copy->alignment = alignment;
  130. copy->el_char = el_char;
  131. copy->overrun_behavior = overrun_behavior;
  132. copy->tab_stops = tab_stops;
  133. return copy;
  134. }
  135. void TextLine::set_preserve_invalid(bool p_enabled) {
  136. TS->shaped_text_set_preserve_invalid(rid, p_enabled);
  137. dirty = true;
  138. }
  139. bool TextLine::get_preserve_invalid() const {
  140. return TS->shaped_text_get_preserve_invalid(rid);
  141. }
  142. void TextLine::set_preserve_control(bool p_enabled) {
  143. TS->shaped_text_set_preserve_control(rid, p_enabled);
  144. dirty = true;
  145. }
  146. bool TextLine::get_preserve_control() const {
  147. return TS->shaped_text_get_preserve_control(rid);
  148. }
  149. void TextLine::set_direction(TextServer::Direction p_direction) {
  150. TS->shaped_text_set_direction(rid, p_direction);
  151. dirty = true;
  152. }
  153. TextServer::Direction TextLine::get_direction() const {
  154. return TS->shaped_text_get_direction(rid);
  155. }
  156. TextServer::Direction TextLine::get_inferred_direction() const {
  157. return TS->shaped_text_get_inferred_direction(rid);
  158. }
  159. void TextLine::set_orientation(TextServer::Orientation p_orientation) {
  160. TS->shaped_text_set_orientation(rid, p_orientation);
  161. dirty = true;
  162. }
  163. TextServer::Orientation TextLine::get_orientation() const {
  164. return TS->shaped_text_get_orientation(rid);
  165. }
  166. void TextLine::set_bidi_override(const Array &p_override) {
  167. TS->shaped_text_set_bidi_override(rid, p_override);
  168. dirty = true;
  169. }
  170. bool TextLine::add_string(const String &p_text, const Ref<Font> &p_font, int p_font_size, const String &p_language, const Variant &p_meta) {
  171. ERR_FAIL_COND_V(p_font.is_null(), false);
  172. bool res = TS->shaped_text_add_string(rid, p_text, p_font->get_rids(), p_font_size, p_font->get_opentype_features(), p_language, p_meta);
  173. dirty = true;
  174. return res;
  175. }
  176. bool TextLine::add_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align, int p_length, float p_baseline) {
  177. bool res = TS->shaped_text_add_object(rid, p_key, p_size, p_inline_align, p_length, p_baseline);
  178. dirty = true;
  179. return res;
  180. }
  181. bool TextLine::resize_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align, float p_baseline) {
  182. _shape();
  183. return TS->shaped_text_resize_object(rid, p_key, p_size, p_inline_align, p_baseline);
  184. }
  185. bool TextLine::has_object(Variant p_key) const {
  186. _shape();
  187. return TS->shaped_text_has_object(rid, p_key);
  188. }
  189. Array TextLine::get_objects() const {
  190. return TS->shaped_text_get_objects(rid);
  191. }
  192. Rect2 TextLine::get_object_rect(Variant p_key) const {
  193. Vector2 ofs;
  194. float length = TS->shaped_text_get_width(rid);
  195. if (width > 0) {
  196. switch (alignment) {
  197. case HORIZONTAL_ALIGNMENT_FILL:
  198. case HORIZONTAL_ALIGNMENT_LEFT:
  199. break;
  200. case HORIZONTAL_ALIGNMENT_CENTER: {
  201. if (length <= width) {
  202. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  203. ofs.x += Math::floor((width - length) / 2.0);
  204. } else {
  205. ofs.y += Math::floor((width - length) / 2.0);
  206. }
  207. } else if (TS->shaped_text_get_inferred_direction(rid) == TextServer::DIRECTION_RTL) {
  208. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  209. ofs.x += width - length;
  210. } else {
  211. ofs.y += width - length;
  212. }
  213. }
  214. } break;
  215. case HORIZONTAL_ALIGNMENT_RIGHT: {
  216. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  217. ofs.x += width - length;
  218. } else {
  219. ofs.y += width - length;
  220. }
  221. } break;
  222. }
  223. }
  224. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  225. ofs.y += TS->shaped_text_get_ascent(rid);
  226. } else {
  227. ofs.x += TS->shaped_text_get_ascent(rid);
  228. }
  229. Rect2 rect = TS->shaped_text_get_object_rect(rid, p_key);
  230. rect.position += ofs;
  231. return rect;
  232. }
  233. void TextLine::set_horizontal_alignment(HorizontalAlignment p_alignment) {
  234. if (alignment != p_alignment) {
  235. if (alignment == HORIZONTAL_ALIGNMENT_FILL || p_alignment == HORIZONTAL_ALIGNMENT_FILL) {
  236. alignment = p_alignment;
  237. dirty = true;
  238. } else {
  239. alignment = p_alignment;
  240. }
  241. }
  242. }
  243. HorizontalAlignment TextLine::get_horizontal_alignment() const {
  244. return alignment;
  245. }
  246. void TextLine::tab_align(const Vector<float> &p_tab_stops) {
  247. tab_stops = p_tab_stops;
  248. dirty = true;
  249. }
  250. void TextLine::set_flags(BitField<TextServer::JustificationFlag> p_flags) {
  251. if (flags != p_flags) {
  252. flags = p_flags;
  253. dirty = true;
  254. }
  255. }
  256. BitField<TextServer::JustificationFlag> TextLine::get_flags() const {
  257. return flags;
  258. }
  259. void TextLine::set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior) {
  260. if (overrun_behavior != p_behavior) {
  261. overrun_behavior = p_behavior;
  262. dirty = true;
  263. }
  264. }
  265. TextServer::OverrunBehavior TextLine::get_text_overrun_behavior() const {
  266. return overrun_behavior;
  267. }
  268. void TextLine::set_ellipsis_char(const String &p_char) {
  269. String c = p_char;
  270. if (c.length() > 1) {
  271. WARN_PRINT("Ellipsis must be exactly one character long (" + itos(c.length()) + " characters given).");
  272. c = c.left(1);
  273. }
  274. if (el_char == c) {
  275. return;
  276. }
  277. el_char = c;
  278. dirty = true;
  279. }
  280. String TextLine::get_ellipsis_char() const {
  281. return el_char;
  282. }
  283. void TextLine::set_width(float p_width) {
  284. if (width == p_width) {
  285. return;
  286. }
  287. width = p_width;
  288. if (alignment == HORIZONTAL_ALIGNMENT_FILL || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) {
  289. dirty = true;
  290. }
  291. }
  292. float TextLine::get_width() const {
  293. return width;
  294. }
  295. Size2 TextLine::get_size() const {
  296. _shape();
  297. return TS->shaped_text_get_size(rid);
  298. }
  299. float TextLine::get_line_ascent() const {
  300. _shape();
  301. return TS->shaped_text_get_ascent(rid);
  302. }
  303. float TextLine::get_line_descent() const {
  304. _shape();
  305. return TS->shaped_text_get_descent(rid);
  306. }
  307. float TextLine::get_line_width() const {
  308. _shape();
  309. return TS->shaped_text_get_width(rid);
  310. }
  311. float TextLine::get_line_underline_position() const {
  312. _shape();
  313. return TS->shaped_text_get_underline_position(rid);
  314. }
  315. float TextLine::get_line_underline_thickness() const {
  316. _shape();
  317. return TS->shaped_text_get_underline_thickness(rid);
  318. }
  319. void TextLine::draw(RID p_canvas, const Vector2 &p_pos, const Color &p_color, float p_oversampling) const {
  320. _shape();
  321. Vector2 ofs = p_pos;
  322. float length = TS->shaped_text_get_width(rid);
  323. if (width > 0) {
  324. switch (alignment) {
  325. case HORIZONTAL_ALIGNMENT_FILL:
  326. case HORIZONTAL_ALIGNMENT_LEFT:
  327. break;
  328. case HORIZONTAL_ALIGNMENT_CENTER: {
  329. if (length <= width) {
  330. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  331. ofs.x += Math::floor((width - length) / 2.0);
  332. } else {
  333. ofs.y += Math::floor((width - length) / 2.0);
  334. }
  335. } else if (TS->shaped_text_get_inferred_direction(rid) == TextServer::DIRECTION_RTL) {
  336. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  337. ofs.x += width - length;
  338. } else {
  339. ofs.y += width - length;
  340. }
  341. }
  342. } break;
  343. case HORIZONTAL_ALIGNMENT_RIGHT: {
  344. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  345. ofs.x += width - length;
  346. } else {
  347. ofs.y += width - length;
  348. }
  349. } break;
  350. }
  351. }
  352. float clip_l;
  353. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  354. ofs.y += TS->shaped_text_get_ascent(rid);
  355. clip_l = MAX(0, p_pos.x - ofs.x);
  356. } else {
  357. ofs.x += TS->shaped_text_get_ascent(rid);
  358. clip_l = MAX(0, p_pos.y - ofs.y);
  359. }
  360. return TS->shaped_text_draw(rid, p_canvas, ofs, clip_l, clip_l + width, p_color, p_oversampling);
  361. }
  362. void TextLine::draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outline_size, const Color &p_color, float p_oversampling) const {
  363. _shape();
  364. Vector2 ofs = p_pos;
  365. float length = TS->shaped_text_get_width(rid);
  366. if (width > 0) {
  367. switch (alignment) {
  368. case HORIZONTAL_ALIGNMENT_FILL:
  369. case HORIZONTAL_ALIGNMENT_LEFT:
  370. break;
  371. case HORIZONTAL_ALIGNMENT_CENTER: {
  372. if (length <= width) {
  373. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  374. ofs.x += Math::floor((width - length) / 2.0);
  375. } else {
  376. ofs.y += Math::floor((width - length) / 2.0);
  377. }
  378. } else if (TS->shaped_text_get_inferred_direction(rid) == TextServer::DIRECTION_RTL) {
  379. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  380. ofs.x += width - length;
  381. } else {
  382. ofs.y += width - length;
  383. }
  384. }
  385. } break;
  386. case HORIZONTAL_ALIGNMENT_RIGHT: {
  387. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  388. ofs.x += width - length;
  389. } else {
  390. ofs.y += width - length;
  391. }
  392. } break;
  393. }
  394. }
  395. float clip_l;
  396. if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
  397. ofs.y += TS->shaped_text_get_ascent(rid);
  398. clip_l = MAX(0, p_pos.x - ofs.x);
  399. } else {
  400. ofs.x += TS->shaped_text_get_ascent(rid);
  401. clip_l = MAX(0, p_pos.y - ofs.y);
  402. }
  403. return TS->shaped_text_draw_outline(rid, p_canvas, ofs, clip_l, clip_l + width, p_outline_size, p_color, p_oversampling);
  404. }
  405. int TextLine::hit_test(float p_coords) const {
  406. _shape();
  407. return TS->shaped_text_hit_test_position(rid, p_coords);
  408. }
  409. TextLine::TextLine(const String &p_text, const Ref<Font> &p_font, int p_font_size, const String &p_language, TextServer::Direction p_direction, TextServer::Orientation p_orientation) {
  410. rid = TS->create_shaped_text(p_direction, p_orientation);
  411. if (p_font.is_valid()) {
  412. TS->shaped_text_add_string(rid, p_text, p_font->get_rids(), p_font_size, p_font->get_opentype_features(), p_language);
  413. }
  414. }
  415. TextLine::TextLine() {
  416. rid = TS->create_shaped_text();
  417. }
  418. TextLine::~TextLine() {
  419. TS->free_rid(rid);
  420. }