Fixed mangling of UTF characters when converted implicitely to

wxString on Windows through the + operator.
This commit is contained in:
bubnikv 2018-06-07 22:10:23 +02:00
parent 92875709e1
commit 7dfe2e2595
6 changed files with 30 additions and 27 deletions

View File

@ -29,7 +29,7 @@ if(WIN32)
# -D_ITERATOR_DEBUG_LEVEL) # -D_ITERATOR_DEBUG_LEVEL)
endif() endif()
add_definitions(-DwxUSE_UNICODE -D_UNICODE -DUNICODE) add_definitions(-DwxUSE_UNICODE -D_UNICODE -DUNICODE -DWXINTL_NO_GETTEXT_MACRO)
add_library(libslic3r STATIC add_library(libslic3r STATIC
${LIBDIR}/libslic3r/BoundingBox.cpp ${LIBDIR}/libslic3r/BoundingBox.cpp

View File

@ -308,6 +308,8 @@ enum ConfigMenuIDs {
ConfigMenuCnt, ConfigMenuCnt,
}; };
static wxString dots("", wxConvUTF8);
void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_language_change) void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_language_change)
{ {
auto local_menu = new wxMenu(); auto local_menu = new wxMenu();
@ -315,12 +317,12 @@ void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_l
const auto config_wizard_tooltip = wxString::Format(_(L("Run %s")), ConfigWizard::name()); const auto config_wizard_tooltip = wxString::Format(_(L("Run %s")), ConfigWizard::name());
// Cmd+, is standard on OS X - what about other operating systems? // Cmd+, is standard on OS X - what about other operating systems?
local_menu->Append(config_id_base + ConfigMenuWizard, ConfigWizard::name() + "\u2026", config_wizard_tooltip); local_menu->Append(config_id_base + ConfigMenuWizard, ConfigWizard::name() + dots, config_wizard_tooltip);
local_menu->Append(config_id_base + ConfigMenuSnapshots, _(L("Configuration Snapshots"))+"\u2026", _(L("Inspect / activate configuration snapshots"))); local_menu->Append(config_id_base + ConfigMenuSnapshots, _(L("Configuration Snapshots"))+dots, _(L("Inspect / activate configuration snapshots")));
local_menu->Append(config_id_base + ConfigMenuTakeSnapshot, _(L("Take Configuration Snapshot")), _(L("Capture a configuration snapshot"))); local_menu->Append(config_id_base + ConfigMenuTakeSnapshot, _(L("Take Configuration Snapshot")), _(L("Capture a configuration snapshot")));
// local_menu->Append(config_id_base + ConfigMenuUpdate, _(L("Check for updates")), _(L("Check for configuration updates"))); // local_menu->Append(config_id_base + ConfigMenuUpdate, _(L("Check for updates")), _(L("Check for configuration updates")));
local_menu->AppendSeparator(); local_menu->AppendSeparator();
local_menu->Append(config_id_base + ConfigMenuPreferences, _(L("Preferences"))+"\u2026\tCtrl+,", _(L("Application preferences"))); local_menu->Append(config_id_base + ConfigMenuPreferences, _(L("Preferences"))+dots+"\tCtrl+,", _(L("Application preferences")));
local_menu->Append(config_id_base + ConfigMenuLanguage, _(L("Change Application Language"))); local_menu->Append(config_id_base + ConfigMenuLanguage, _(L("Change Application Language")));
local_menu->AppendSeparator(); local_menu->AppendSeparator();
local_menu->Append(config_id_base + ConfigMenuFlashFirmware, _(L("Flash printer firmware")), _(L("Upload a firmware image into an Arduino based printer"))); local_menu->Append(config_id_base + ConfigMenuFlashFirmware, _(L("Flash printer firmware")), _(L("Upload a firmware image into an Arduino based printer")));
@ -841,7 +843,7 @@ void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFl
Line line = { "", "" }; Line line = { "", "" };
line.widget = [config](wxWindow* parent){ line.widget = [config](wxWindow* parent){
g_wiping_dialog_button = new wxButton(parent, wxID_ANY, _(L("Purging volumes")) + "\u2026", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); g_wiping_dialog_button = new wxButton(parent, wxID_ANY, _(L("Purging volumes")) + dots, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(g_wiping_dialog_button); sizer->Add(g_wiping_dialog_button);
g_wiping_dialog_button->Bind(wxEVT_BUTTON, ([parent](wxCommandEvent& e) g_wiping_dialog_button->Bind(wxEVT_BUTTON, ([parent](wxCommandEvent& e)

View File

@ -5,6 +5,9 @@
#include <vector> #include <vector>
#include "Config.hpp" #include "Config.hpp"
#include <wx/intl.h>
#include <wx/string.h>
class wxApp; class wxApp;
class wxWindow; class wxWindow;
class wxFrame; class wxFrame;
@ -30,6 +33,12 @@ class PresetUpdater;
class DynamicPrintConfig; class DynamicPrintConfig;
class TabIface; class TabIface;
#define _(s) Slic3r::translate((s))
inline wxString translate(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)); }
inline wxString translate(const wchar_t *s) { return wxGetTranslation(s); }
inline wxString translate(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)); }
inline wxString translate(const std::wstring &s) { return wxGetTranslation(s.c_str()); }
// !!! If you needed to translate some wxString, // !!! If you needed to translate some wxString,
// !!! please use _(L(string)) // !!! please use _(L(string))
// !!! _() - is a standard wxWidgets macro to translate // !!! _() - is a standard wxWidgets macro to translate

View File

@ -2,12 +2,7 @@
#include <wx/dcbuffer.h> #include <wx/dcbuffer.h>
#include "RammingChart.hpp" #include "RammingChart.hpp"
#include "GUI.hpp"
//! macro used to mark string used at localization,
//! return same string
#define L(s) s
wxDEFINE_EVENT(EVT_WIPE_TOWER_CHART_CHANGED, wxCommandEvent); wxDEFINE_EVENT(EVT_WIPE_TOWER_CHART_CHANGED, wxCommandEvent);
@ -83,7 +78,7 @@ void Chart::draw() {
int text_height = 0; int text_height = 0;
dc.GetTextExtent(label,&text_width,&text_height); dc.GetTextExtent(label,&text_width,&text_height);
dc.DrawText(label,wxPoint(0.5*(m_rect.GetRight()+m_rect.GetLeft())-text_width/2.f, m_rect.GetBottom()+25)); dc.DrawText(label,wxPoint(0.5*(m_rect.GetRight()+m_rect.GetLeft())-text_width/2.f, m_rect.GetBottom()+25));
label = _(L("Volumetric speed")) + " (" + _(L("mm")) + "\u00B3/" + _(L("s")) + ")"; label = _(L("Volumetric speed")) + " (" + _(L("mm")) + wxString("³", wxConvUTF8) + _(L("s")) + ")";
dc.GetTextExtent(label,&text_width,&text_height); dc.GetTextExtent(label,&text_width,&text_height);
dc.DrawRotatedText(label,wxPoint(0,0.5*(m_rect.GetBottom()+m_rect.GetTop())+text_width/2.f),90); dc.DrawRotatedText(label,wxPoint(0,0.5*(m_rect.GetBottom()+m_rect.GetTop())+text_width/2.f),90);
} }

View File

@ -32,6 +32,8 @@
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
static wxString dots("", wxConvUTF8);
// sub new // sub new
void Tab::create_preset_tab(PresetBundle *preset_bundle) void Tab::create_preset_tab(PresetBundle *preset_bundle)
{ {
@ -1261,7 +1263,7 @@ void TabFilament::build()
optgroup->append_single_option_line("filament_density"); optgroup->append_single_option_line("filament_density");
optgroup->append_single_option_line("filament_cost"); optgroup->append_single_option_line("filament_cost");
optgroup = page->new_optgroup(_(L("Temperature ")) +" (\u00B0C)"); // degree sign optgroup = page->new_optgroup(_(L("Temperature ")) + wxString("°", wxConvUTF8));
Line line = { _(L("Extruder")), "" }; Line line = { _(L("Extruder")), "" };
line.append_option(optgroup->get_option("first_layer_temperature")); line.append_option(optgroup->get_option("first_layer_temperature"));
line.append_option(optgroup->get_option("temperature")); line.append_option(optgroup->get_option("temperature"));
@ -1319,7 +1321,7 @@ void TabFilament::build()
optgroup->append_single_option_line("filament_toolchange_delay"); optgroup->append_single_option_line("filament_toolchange_delay");
line = { _(L("Ramming")), "" }; line = { _(L("Ramming")), "" };
line.widget = [this](wxWindow* parent){ line.widget = [this](wxWindow* parent){
auto ramming_dialog_btn = new wxButton(parent, wxID_ANY, _(L("Ramming settings"))+"\u2026", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); auto ramming_dialog_btn = new wxButton(parent, wxID_ANY, _(L("Ramming settings"))+dots, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(ramming_dialog_btn); sizer->Add(ramming_dialog_btn);
@ -1441,7 +1443,7 @@ void TabPrinter::build()
Line line{ _(L("Bed shape")), "" }; Line line{ _(L("Bed shape")), "" };
line.widget = [this](wxWindow* parent){ line.widget = [this](wxWindow* parent){
auto btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+"\u2026", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); auto btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont(Slic3r::GUI::small_font); // btn->SetFont(Slic3r::GUI::small_font);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("printer_empty.png")), wxBITMAP_TYPE_PNG)); btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("printer_empty.png")), wxBITMAP_TYPE_PNG));
@ -1540,7 +1542,7 @@ void TabPrinter::build()
optgroup = page->new_optgroup(_(L("OctoPrint upload"))); optgroup = page->new_optgroup(_(L("OctoPrint upload")));
auto octoprint_host_browse = [this, optgroup] (wxWindow* parent) { auto octoprint_host_browse = [this, optgroup] (wxWindow* parent) {
auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+"\u2026", wxDefaultPosition, wxDefaultSize, wxBU_LEFT); auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG)); btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn); sizer->Add(btn);
@ -1589,7 +1591,7 @@ void TabPrinter::build()
Line cafile_line = optgroup->create_single_option_line("octoprint_cafile"); Line cafile_line = optgroup->create_single_option_line("octoprint_cafile");
auto octoprint_cafile_browse = [this, optgroup] (wxWindow* parent) { auto octoprint_cafile_browse = [this, optgroup] (wxWindow* parent) {
auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+"\u2026", wxDefaultPosition, wxDefaultSize, wxBU_LEFT); auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG)); btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn); sizer->Add(btn);
@ -2211,7 +2213,7 @@ void Tab::update_ui_from_settings()
wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn) wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn)
{ {
*checkbox = new wxCheckBox(parent, wxID_ANY, _(L("All"))); *checkbox = new wxCheckBox(parent, wxID_ANY, _(L("All")));
*btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+"\u2026", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); *btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
(*btn)->SetBitmap(wxBitmap(from_u8(Slic3r::var("printer_empty.png")), wxBITMAP_TYPE_PNG)); (*btn)->SetBitmap(wxBitmap(from_u8(Slic3r::var("printer_empty.png")), wxBITMAP_TYPE_PNG));

View File

@ -1,15 +1,10 @@
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#include "WipeTowerDialog.hpp" #include "WipeTowerDialog.hpp"
#include "GUI.hpp"
#include <wx/sizer.h> #include <wx/sizer.h>
//! macro used to mark string used at localization,
//! return same string
#define L(s) s
RammingDialog::RammingDialog(wxWindow* parent,const std::string& parameters) RammingDialog::RammingDialog(wxWindow* parent,const std::string& parameters)
: wxDialog(parent, wxID_ANY, _(L("Ramming customization")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE/* | wxRESIZE_BORDER*/) : wxDialog(parent, wxID_ANY, _(L("Ramming customization")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE/* | wxRESIZE_BORDER*/)
{ {
@ -81,7 +76,7 @@ RammingPanel::RammingPanel(wxWindow* parent, const std::string& parameters)
auto gsizer_param = new wxFlexGridSizer(2, 5, 15); auto gsizer_param = new wxFlexGridSizer(2, 5, 15);
gsizer_param->Add(new wxStaticText(this, wxID_ANY, wxString(_(L("Total ramming time")) + " (" + _(L("s")) + "):")), 0, wxALIGN_CENTER_VERTICAL); gsizer_param->Add(new wxStaticText(this, wxID_ANY, wxString(_(L("Total ramming time")) + " (" + _(L("s")) + "):")), 0, wxALIGN_CENTER_VERTICAL);
gsizer_param->Add(m_widget_time); gsizer_param->Add(m_widget_time);
gsizer_param->Add(new wxStaticText(this, wxID_ANY, wxString(_(L("Total rammed volume")) + " (" + _(L("mm")) + "\u00B3):")), 0, wxALIGN_CENTER_VERTICAL); gsizer_param->Add(new wxStaticText(this, wxID_ANY, wxString(_(L("Total rammed volume")) + " (" + _(L("mm")) + wxString("³):", wxConvUTF8))), 0, wxALIGN_CENTER_VERTICAL);
gsizer_param->Add(m_widget_volume); gsizer_param->Add(m_widget_volume);
gsizer_param->AddSpacer(20); gsizer_param->AddSpacer(20);
gsizer_param->AddSpacer(20); gsizer_param->AddSpacer(20);
@ -220,7 +215,7 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector<float>& matrix, con
// collect and format sizer // collect and format sizer
format_sizer(m_sizer_advanced, m_page_advanced, m_gridsizer_advanced, format_sizer(m_sizer_advanced, m_page_advanced, m_gridsizer_advanced,
wxString::Format(_(L("Here you can adjust required purging volume (mm%s) for any given pair of tools.")), "\u00B3"), _(L("Here you can adjust required purging volume (mm³) for any given pair of tools.")),
_(L("Extruder changed to"))); _(L("Extruder changed to")));
// Hide preview page before new page creating // Hide preview page before new page creating
@ -243,7 +238,7 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector<float>& matrix, con
// collect and format sizer // collect and format sizer
format_sizer(m_sizer_simple, m_page_simple, gridsizer_simple, format_sizer(m_sizer_simple, m_page_simple, gridsizer_simple,
_(L("Total purging volume is calculated by summing two values below, depending on which tools are loaded/unloaded.")), _(L("Total purging volume is calculated by summing two values below, depending on which tools are loaded/unloaded.")),
wxString::Format(_(L("Volume to purge (mm%s) when the filament is being")), "\u00B3"), 50); _(L("Volume to purge (mm³) when the filament is being")), 50);
m_sizer = new wxBoxSizer(wxVERTICAL); m_sizer = new wxBoxSizer(wxVERTICAL);
m_sizer->Add(m_page_simple, 0, wxEXPAND | wxALL, 25); m_sizer->Add(m_page_simple, 0, wxEXPAND | wxALL, 25);