text_line.cpp 18 KB

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