| 5659 | } |
| 5660 | |
| 5661 | ImVec2 ImFontCalcTextSizeEx(ImFont* font, float size, float max_width, float wrap_width, const char* text_begin, const char* text_end_display, const char* text_end, const char** out_remaining, ImVec2* out_offset, ImDrawTextFlags flags) |
| 5662 | { |
| 5663 | if (!text_end) |
| 5664 | text_end = text_begin + ImStrlen(text_begin); // FIXME-OPT: Need to avoid this. |
| 5665 | if (!text_end_display) |
| 5666 | text_end_display = text_end; |
| 5667 | |
| 5668 | ImFontBaked* baked = font->GetFontBaked(size); |
| 5669 | const float line_height = size; |
| 5670 | const float scale = line_height / baked->Size; |
| 5671 | |
| 5672 | ImVec2 text_size = ImVec2(0, 0); |
| 5673 | float line_width = 0.0f; |
| 5674 | |
| 5675 | const bool word_wrap_enabled = (wrap_width > 0.0f); |
| 5676 | const char* word_wrap_eol = NULL; |
| 5677 | |
| 5678 | const char* s = text_begin; |
| 5679 | while (s < text_end_display) |
| 5680 | { |
| 5681 | // Word-wrapping |
| 5682 | if (word_wrap_enabled) |
| 5683 | { |
| 5684 | // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature. |
| 5685 | if (!word_wrap_eol) |
| 5686 | word_wrap_eol = ImFontCalcWordWrapPositionEx(font, size, s, text_end, wrap_width - line_width, flags); |
| 5687 | |
| 5688 | if (s >= word_wrap_eol) |
| 5689 | { |
| 5690 | if (text_size.x < line_width) |
| 5691 | text_size.x = line_width; |
| 5692 | text_size.y += line_height; |
| 5693 | line_width = 0.0f; |
| 5694 | s = ImTextCalcWordWrapNextLineStart(s, text_end, flags); // Wrapping skips upcoming blanks |
| 5695 | if (flags & ImDrawTextFlags_StopOnNewLine) |
| 5696 | break; |
| 5697 | word_wrap_eol = NULL; |
| 5698 | continue; |
| 5699 | } |
| 5700 | } |
| 5701 | |
| 5702 | // Decode and advance source |
| 5703 | const char* prev_s = s; |
| 5704 | unsigned int c = (unsigned int)*s; |
| 5705 | if (c < 0x80) |
| 5706 | s += 1; |
| 5707 | else |
| 5708 | s += ImTextCharFromUtf8(&c, s, text_end); |
| 5709 | |
| 5710 | if (c == '\n') |
| 5711 | { |
| 5712 | text_size.x = ImMax(text_size.x, line_width); |
| 5713 | text_size.y += line_height; |
| 5714 | line_width = 0.0f; |
| 5715 | if (flags & ImDrawTextFlags_StopOnNewLine) |
| 5716 | break; |
| 5717 | continue; |
| 5718 | } |
no test coverage detected