| 757 | } |
| 758 | |
| 759 | int grtext_GetTextLineWidth(const char *str) { |
| 760 | int line_width = 0, max_width = 0; |
| 761 | int rgb_define_mode = 0; |
| 762 | int strsize = strlen(str); |
| 763 | int line_idx = 0; |
| 764 | |
| 765 | for (int i = 0; i < strsize; i++) { |
| 766 | int width; |
| 767 | char ch = str[i], ch2 = str[i + 1]; |
| 768 | |
| 769 | // note that if we hit the GR_COLOR_CHAR then the next three values should |
| 770 | // not count when defining the width of the line. |
| 771 | if (rgb_define_mode == 3) |
| 772 | rgb_define_mode = 0; |
| 773 | else if (ch == GR_COLOR_CHAR) |
| 774 | rgb_define_mode = 1; |
| 775 | if (!rgb_define_mode) { |
| 776 | if (ch == '\t') { // tab char |
| 777 | int space_width; |
| 778 | space_width = (CHAR_WIDTH(Grtext_font, ' ') + Grtext_spacing) * Grtext_tabspace; |
| 779 | line_width = (line_width + space_width) / space_width * space_width; |
| 780 | } else if (ch == GRTEXT_FORMAT_CHAR) { |
| 781 | if ((i + 1) >= strsize) |
| 782 | break; |
| 783 | line_width = ((int)str[i + 1] * GRTEXT_FORMAT_SCALAR); |
| 784 | i++; |
| 785 | } else if (ch == '\n') { |
| 786 | if (line_width > max_width) { |
| 787 | max_width = line_width; |
| 788 | } |
| 789 | line_width = 0; |
| 790 | } else { |
| 791 | width = CHAR_WIDTH(Grtext_font, ch); |
| 792 | line_width += (width + Grtext_spacing + CHAR_SPACING(Grtext_font, ch, ch2)); |
| 793 | } |
| 794 | } else |
| 795 | rgb_define_mode++; |
| 796 | } |
| 797 | |
| 798 | if (line_width > max_width) { |
| 799 | max_width = line_width; |
| 800 | } |
| 801 | return (max_width) ? max_width - Grtext_spacing : 0; |
| 802 | } |
| 803 | |
| 804 | // returns width of text using a font template |
| 805 | int grtext_GetTextLineWidthTemplate(const tFontTemplate *ft, const char *str) { |
no test coverage detected