From 0a4ce079e837d55e8ce4bb59e073466250047e56 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 11 Nov 2020 16:05:30 +0100 Subject: [PATCH] escape_ampersand function and changed order of printer names and pictures in config wizard --- src/libslic3r/Config.cpp | 17 +++++++++++++++++ src/libslic3r/Config.hpp | 2 ++ src/slic3r/GUI/ConfigWizard.cpp | 7 ++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 25ef93430..03ce0ad40 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -192,6 +192,23 @@ bool unescape_strings_cstyle(const std::string &str, std::vector &o } } +std::string escape_ampersand(const std::string& str) +{ + // Allocate a buffer 2 times the input string length, + // so the output will fit even if all input characters get escaped. + std::vector out(str.size() * 6, 0); + char* outptr = out.data(); + for (size_t i = 0; i < str.size(); ++i) { + char c = str[i]; + if (c == '&') { + (*outptr++) = '&'; + (*outptr++) = '&'; + } else + (*outptr++) = c; + } + return std::string(out.data(), outptr - out.data()); +} + std::vector ConfigOptionDef::cli_args(const std::string &key) const { std::vector args; diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index d683e55b8..6ef6f143c 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -34,6 +34,8 @@ extern std::string escape_strings_cstyle(const std::vector &strs); extern bool unescape_string_cstyle(const std::string &str, std::string &out); extern bool unescape_strings_cstyle(const std::string &str, std::vector &out); +extern std::string escape_ampersand(const std::string& str); + /// Specialization of std::exception to indicate that an unknown config option has been encountered. class UnknownOptionException : public Slic3r::RuntimeError { public: diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index 5976d2844..6b509a86d 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -27,6 +27,7 @@ #include #include "libslic3r/Utils.hpp" +#include "libslic3r/Config.hpp" #include "GUI.hpp" #include "GUI_App.hpp" #include "GUI_Utils.hpp" @@ -273,8 +274,8 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, wxSt const size_t odd_items = titles.size() % cols; for (size_t i = 0; i < titles.size() - odd_items; i += cols) { - for (size_t j = i; j < i + cols; j++) { printer_grid->Add(titles[j], 0, wxBOTTOM, 3); } for (size_t j = i; j < i + cols; j++) { printer_grid->Add(bitmaps[j], 0, wxBOTTOM, 20); } + for (size_t j = i; j < i + cols; j++) { printer_grid->Add(titles[j], 0, wxBOTTOM, 3); } for (size_t j = i; j < i + cols; j++) { printer_grid->Add(variants_panels[j]); } // Add separator space to multiliners @@ -285,10 +286,10 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, wxSt if (odd_items > 0) { const size_t rem = titles.size() - odd_items; - for (size_t i = rem; i < titles.size(); i++) { printer_grid->Add(titles[i], 0, wxBOTTOM, 3); } - for (size_t i = 0; i < cols - odd_items; i++) { printer_grid->AddSpacer(1); } for (size_t i = rem; i < titles.size(); i++) { printer_grid->Add(bitmaps[i], 0, wxBOTTOM, 20); } for (size_t i = 0; i < cols - odd_items; i++) { printer_grid->AddSpacer(1); } + for (size_t i = rem; i < titles.size(); i++) { printer_grid->Add(titles[i], 0, wxBOTTOM, 3); } + for (size_t i = 0; i < cols - odd_items; i++) { printer_grid->AddSpacer(1); } for (size_t i = rem; i < titles.size(); i++) { printer_grid->Add(variants_panels[i]); } } }