diff --git a/dlib/gui_widgets/widgets.cpp b/dlib/gui_widgets/widgets.cpp index daac0c530..6627d4cc9 100644 --- a/dlib/gui_widgets/widgets.cpp +++ b/dlib/gui_widgets/widgets.cpp @@ -190,7 +190,7 @@ namespace dlib const std::string& name ) { - set_name(convert_mbstring_to_wstring(name)); + set_name(convert_to_utf32(name)); } void toggle_button:: @@ -327,7 +327,7 @@ namespace dlib const std::string& text ) { - set_text(convert_mbstring_to_wstring(text)); + set_text(convert_to_utf32(text)); } void label:: @@ -675,7 +675,7 @@ namespace dlib const std::string& text ) { - set_text(convert_mbstring_to_wstring(text)); + set_text(convert_to_utf32(text)); } void text_field:: @@ -1522,7 +1522,7 @@ namespace dlib const std::string& new_name ) { - set_tab_name(idx, convert_mbstring_to_wstring(new_name)); + set_tab_name(idx, convert_to_utf32(new_name)); } void tabbed_display:: @@ -1929,7 +1929,7 @@ namespace dlib const std::string& name ) { - set_name(convert_mbstring_to_wstring(name)); + set_name(convert_to_utf32(name)); } void named_rectangle:: @@ -3360,7 +3360,7 @@ namespace dlib char underline_ch ) { - set_menu_name(idx, convert_mbstring_to_wstring(name), underline_ch); + set_menu_name(idx, convert_to_utf32(name), underline_ch); } // ---------------------------------------------------------------------------------------- @@ -3945,7 +3945,7 @@ namespace dlib const std::string& str ) { - set_text(row, col, convert_mbstring_to_wstring(str)); + set_text(row, col, convert_to_utf32(str)); } // ---------------------------------------------------------------------------------------- @@ -4962,7 +4962,7 @@ namespace dlib const std::string& text ) { - set_text(convert_mbstring_to_wstring(text)); + set_text(convert_to_utf32(text)); } void text_box:: diff --git a/dlib/image_transforms/draw.h b/dlib/image_transforms/draw.h index 47961630f..c2f7165dd 100644 --- a/dlib/image_transforms/draw.h +++ b/dlib/image_transforms/draw.h @@ -309,7 +309,7 @@ namespace dlib << "\n\tstr.size(): " << (unsigned long)str.size()); if (last == string::npos) - last = str.size()-1; + last = str.size(); const rectangle rect(p, p); const font& f = *f_ptr; @@ -317,51 +317,51 @@ namespace dlib long y_offset = rect.top() + f.ascender() - 1; long pos = rect.left()+f.left_overflow(); - for (typename string::size_type i = first; i <= last; ++i) + convert_to_utf32(str.begin() + first, str.begin() + last, [&](unichar ch) { // ignore the '\r' character - if (str[i] == '\r') - continue; + if (ch == '\r') + return; // A combining character should be applied to the previous character, and we // therefore make one step back. If a combining comes right after a newline, // then there must be some kind of error in the string, and we don't combine. - if(is_combining_char(str[i]) && + if(is_combining_char(ch) && pos > rect.left() + static_cast(f.left_overflow())) { - pos -= f[str[i]].width(); + pos -= f[ch].width(); } - if (str[i] == '\n') + if (ch == '\n') { y_offset += f.height(); pos = rect.left()+f.left_overflow(); - continue; + return; } // only look at letters in the intersection area if (c.nr() + static_cast(f.height()) < y_offset) { // the string is now below our rectangle so we are done - break; + return; } else if (0 > pos - static_cast(f.left_overflow()) && - pos + static_cast(f[str[i]].width() + f.right_overflow()) < 0) + pos + static_cast(f[ch].width() + f.right_overflow()) < 0) { - pos += f[str[i]].width(); - continue; + pos += f[ch].width(); + return; } else if (c.nc() + static_cast(f.right_overflow()) < pos) { // keep looking because there might be a '\n' in the string that // will wrap us around and put us back into our rectangle. - continue; + return; } // at this point in the loop we know that f[str[i]] overlaps // horizontally with the intersection rectangle area. - const letter& l = f[str[i]]; + const letter& l = f[ch]; for (unsigned short i = 0; i < l.num_of_points(); ++i) { const long x = l[i].x + pos; @@ -375,10 +375,27 @@ namespace dlib } pos += l.width(); - } + }); } + template < + typename image_type, + typename pixel_type + > + void draw_string ( + image_type& c, + const dlib::point& p, + const char* str, + const pixel_type& color, + const std::shared_ptr& f_ptr = default_font::get_font(), + typename std::string::size_type first = 0, + typename std::string::size_type last = std::string::npos + ) + { + draw_string(c, p, std::string(str), color, f_ptr, first, last); + } + // ---------------------------------------------------------------------------------------- template < diff --git a/tools/imglab/src/metadata_editor.cpp b/tools/imglab/src/metadata_editor.cpp index bae1c9c3b..f3e0e49db 100644 --- a/tools/imglab/src/metadata_editor.cpp +++ b/tools/imglab/src/metadata_editor.cpp @@ -656,7 +656,7 @@ on_overlay_rect_selected( const image_display::overlay_rect& orect ) { - overlay_label.set_text(convert_to_utf32(orect.label)); + overlay_label.set_text(orect.label); display.set_default_overlay_rect_label(orect.label); display.set_default_overlay_rect_color(string_to_color(orect.label)); }