From 8b16b2c12e241919984558134e7af7f571c26d65 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 2 Mar 2020 09:41:54 +0100 Subject: [PATCH] Fixing wxString::Format encoding mismatches (part 1) --- src/slic3r/GUI/AboutDialog.cpp | 47 +++++++++++---------- src/slic3r/GUI/BackgroundSlicingProcess.cpp | 4 +- src/slic3r/GUI/BonjourDialog.cpp | 6 +-- src/slic3r/GUI/ConfigSnapshotDialog.cpp | 2 +- src/slic3r/GUI/ConfigWizard.cpp | 20 ++++----- src/slic3r/GUI/DoubleSlider.cpp | 6 +-- 6 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/slic3r/GUI/AboutDialog.cpp b/src/slic3r/GUI/AboutDialog.cpp index a4453c73e..30892d9c9 100644 --- a/src/slic3r/GUI/AboutDialog.cpp +++ b/src/slic3r/GUI/AboutDialog.cpp @@ -36,7 +36,9 @@ void AboutDialogLogo::onRepaint(wxEvent &event) // CopyrightsDialog // ----------------------------------------- CopyrightsDialog::CopyrightsDialog() - : DPIDialog(NULL, wxID_ANY, wxString::Format("%s - %s", SLIC3R_APP_NAME, _(L("Portions copyright"))), + : DPIDialog(NULL, wxID_ANY, wxString::FromUTF8((boost::format("%1% - %2%") + % SLIC3R_APP_NAME + % _utf8(L("Portions copyright"))).str()), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { this->SetFont(wxGetApp().normal_font()); @@ -196,7 +198,7 @@ void CopyrightsDialog::onCloseDialog(wxEvent &) } AboutDialog::AboutDialog() - : DPIDialog(NULL, wxID_ANY, wxString::Format(_(L("About %s")), SLIC3R_APP_NAME), wxDefaultPosition, + : DPIDialog(NULL, wxID_ANY, wxString::FromUTF8((boost::format(_utf8(L("About %s"))) % SLIC3R_APP_NAME).str()), wxDefaultPosition, wxDefaultSize, /*wxCAPTION*/wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { SetFont(wxGetApp().normal_font()); @@ -253,32 +255,33 @@ AboutDialog::AboutDialog() int size[] = {fs,fs,fs,fs,fs,fs,fs}; m_html->SetFonts(font.GetFaceName(), font.GetFaceName(), size); m_html->SetBorders(2); - const wxString copyright_str = _(L("Copyright")); + const std::string copyright_str = _utf8(L("Copyright")); // TRN "Slic3r _is licensed under the_ License" - const wxString is_lecensed_str = _(L("is licensed under the")); - const wxString license_str = _(L("GNU Affero General Public License, version 3")); - const wxString based_on_str = _(L("PrusaSlicer is based on Slic3r by Alessandro Ranellucci and the RepRap community.")); - const wxString contributors_str = _(L("Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Joseph Lenox, Y. Sapir, Mike Sheldrake, Vojtech Bubnik and numerous others.")); - const auto text = wxString::Format( + const std::string is_lecensed_str = _utf8(L("is licensed under the")); + const std::string license_str = _utf8(L("GNU Affero General Public License, version 3")); + const std::string based_on_str = _utf8(L("PrusaSlicer is based on Slic3r by Alessandro Ranellucci and the RepRap community.")); + const std::string contributors_str = _utf8(L("Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Joseph Lenox, Y. Sapir, Mike Sheldrake, Vojtech Bubnik and numerous others.")); + const auto text = wxString::FromUTF8( + (boost::format( "" - "" - "" - "%s © 2016-2019 Prusa Research.
" - "%s © 2011-2018 Alessandro Ranellucci.
" - "Slic3r %s " - "%s." + "" + "" + "%4% © 2016-2019 Prusa Research.
" + "%5% © 2011-2018 Alessandro Ranellucci.
" + "Slic3r %6% " + "%7%." "

" - "%s" + "%8%" "

" - "%s" + "%9%" "
" "" - "", bgr_clr_str, text_clr_str, text_clr_str, - copyright_str, copyright_str, - is_lecensed_str, - license_str, - based_on_str, - contributors_str); + "") % bgr_clr_str % text_clr_str % text_clr_str + % copyright_str % copyright_str + % is_lecensed_str + % license_str + % based_on_str + % contributors_str).str()); m_html->SetPage(text); vsizer->Add(m_html, 1, wxEXPAND | wxBOTTOM, 10); m_html->Bind(wxEVT_HTML_LINK_CLICKED, &AboutDialog::onLinkClicked, this); diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index c3cbba395..f22d54e2b 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -219,9 +219,9 @@ void BackgroundSlicingProcess::thread_proc() // Canceled, this is all right. assert(m_print->canceled()); } catch (const std::bad_alloc& ex) { - wxString errmsg = wxString::Format(_(L("%s has encountered an error. It was likely caused by running out of memory. " + wxString errmsg = wxString::FromUTF8((boost::format(_utf8(L("%s has encountered an error. It was likely caused by running out of memory. " "If you are sure you have enough RAM on your system, this may also be a bug and we would " - "be glad if you reported it.")), SLIC3R_APP_NAME); + "be glad if you reported it."))) % SLIC3R_APP_NAME).str()); error = std::string(errmsg.ToUTF8()) + "\n\n" + std::string(ex.what()); } catch (std::exception &ex) { error = ex.what(); diff --git a/src/slic3r/GUI/BonjourDialog.cpp b/src/slic3r/GUI/BonjourDialog.cpp index 0e05a517c..42750885c 100644 --- a/src/slic3r/GUI/BonjourDialog.cpp +++ b/src/slic3r/GUI/BonjourDialog.cpp @@ -215,14 +215,14 @@ void BonjourDialog::on_reply(BonjourReplyEvent &e) void BonjourDialog::on_timer(wxTimerEvent &) { - const auto search_str = _(L("Searching for devices")); + const auto search_str = _utf8(L("Searching for devices")); if (timer_state > 0) { const std::string dots(timer_state, '.'); - label->SetLabel(wxString::Format("%s %s", search_str, dots)); + label->SetLabel(wxString::FromUTF8((boost::format("%1% %2%") % search_str % dots).str())); timer_state = (timer_state) % 3 + 1; } else { - label->SetLabel(wxString::Format("%s: %s", search_str, _(L("Finished"))+".")); + label->SetLabel(wxString::FromUTF8((boost::format("%1%: %2%") % search_str % (_utf8(L("Finished"))+".")).str())); timer->Stop(); } } diff --git a/src/slic3r/GUI/ConfigSnapshotDialog.cpp b/src/slic3r/GUI/ConfigSnapshotDialog.cpp index fbc1794ee..b49e994a9 100644 --- a/src/slic3r/GUI/ConfigSnapshotDialog.cpp +++ b/src/slic3r/GUI/ConfigSnapshotDialog.cpp @@ -72,7 +72,7 @@ static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_eve } if (! compatible) { - text += "

" + wxString::Format(_(L("Incompatible with this %s")), SLIC3R_APP_NAME) + "

"; + text += "

" + wxString::FromUTF8((boost::format(_utf8(L("Incompatible with this %s"))) % SLIC3R_APP_NAME).str()) + "

"; } else if (! snapshot_active) text += "

" + _(L("Activate")) + "

"; diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index 69f11c9cf..0e034b33b 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -215,7 +215,7 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, wxSt const auto &variant = model.variants[i]; const auto label = model.technology == ptFFF - ? wxString::Format("%s %s %s", variant.name, _(L("mm")), _(L("nozzle"))) + ? from_u8((boost::format("%1% %2% %3%") % variant.name % _utf8(L("mm")) % _utf8(L("nozzle"))).str()) : from_u8(model.name); if (i == 1) { @@ -422,17 +422,17 @@ void ConfigWizardPage::append_spacer(int space) // Wizard pages PageWelcome::PageWelcome(ConfigWizard *parent) - : ConfigWizardPage(parent, wxString::Format( + : ConfigWizardPage(parent, wxString::FromUTF8((boost::format( #ifdef __APPLE__ - _(L("Welcome to the %s Configuration Assistant")) + _utf8(L("Welcome to the %s Configuration Assistant")) #else - _(L("Welcome to the %s Configuration Wizard")) + _utf8(L("Welcome to the %s Configuration Wizard")) #endif - , SLIC3R_APP_NAME), _(L("Welcome"))) - , welcome_text(append_text(wxString::Format( - _(L("Hello, welcome to %s! This %s helps you with the initial configuration; just a few settings and you will be ready to print.")), - SLIC3R_APP_NAME, - _(ConfigWizard::name())) + ) % SLIC3R_APP_NAME).str()), _(L("Welcome"))) + , welcome_text(append_text(wxString::FromUTF8((boost::format( + _utf8(L("Hello, welcome to %s! This %s helps you with the initial configuration; just a few settings and you will be ready to print."))) + % SLIC3R_APP_NAME + % _utf8(ConfigWizard::name())).str()) )) , cbox_reset(append( new wxCheckBox(this, wxID_ANY, _(L("Remove user profiles - install from scratch (a snapshot will be taken beforehand)"))) @@ -478,7 +478,7 @@ PagePrinters::PagePrinters(ConfigWizard *parent, continue; } - const auto picker_title = family.empty() ? wxString() : wxString::Format(_(L("%s Family")), family); + const auto picker_title = family.empty() ? wxString() : wxString::FromUTF8((boost::format(_utf8(L("%s Family"))) % family).str()); auto *picker = new PrinterPicker(this, vendor, picker_title, MAX_COLS, *appconfig, filter); picker->Bind(EVT_PRINTER_PICK, [this, appconfig](const PrinterPickerEvent &evt) { diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp index f3694e4e7..911d0f532 100644 --- a/src/slic3r/GUI/DoubleSlider.cpp +++ b/src/slic3r/GUI/DoubleSlider.cpp @@ -530,7 +530,7 @@ wxString Control::get_label(int tick) const const wxString str = m_values.empty() ? wxNumberFormatter::ToString(m_label_koef*value, 2, wxNumberFormatter::Style_None) : wxNumberFormatter::ToString(m_values[value], 2, wxNumberFormatter::Style_None); - return wxString::Format("%s\n(%d)", str, m_values.empty() ? value : value+1); + return from_u8((boost::format("%1%\n(%2%)") % str % (m_values.empty() ? value : value+1)).str()); } void Control::draw_tick_text(wxDC& dc, const wxPoint& pos, int tick, bool right_side/*=true*/) const @@ -952,8 +952,8 @@ wxString Control::get_tooltip(int tick/*=-1*/) return _(L("Discard all custom changes")); if (m_focus == fiCogIcon) return m_mode == t_mode::MultiAsSingle ? - wxString::Format(_(L("Jump to height %s or " - "Set extruder sequence for the entire print")), " (Shift + G)\n") : + wxString::FromUTF8((boost::format(_utf8(L("Jump to height %s or " + "Set extruder sequence for the entire print"))) % " (Shift + G)\n").str()) : _(L("Jump to height")) + " (Shift + G)"; if (m_focus == fiColorBand) return m_mode != t_mode::SingleExtruder ? "" :