software_keyboard: Check for UTF-8 config flag

This commit is contained in:
Zach Hilman 2018-11-18 23:14:48 -05:00
parent 56cf5b7b17
commit ea680bea60
2 changed files with 22 additions and 8 deletions

View file

@ -120,14 +120,27 @@ void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) {
std::vector<u8> output_sub(SWKBD_OUTPUT_BUFFER_SIZE); std::vector<u8> output_sub(SWKBD_OUTPUT_BUFFER_SIZE);
status = RESULT_SUCCESS; status = RESULT_SUCCESS;
const u64 size = text->size() * 2 + 8; if (config.utf_8) {
std::memcpy(output_sub.data(), &size, sizeof(u64)); const u64 size = text->size() + 8;
std::memcpy(output_sub.data() + 8, text->data(), const auto new_text = Common::UTF16ToUTF8(*text);
std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 8));
output_main[0] = config.text_check; std::memcpy(output_sub.data(), &size, sizeof(u64));
std::memcpy(output_main.data() + 4, text->data(), std::memcpy(output_sub.data() + 8, new_text.data(),
std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); std::min(new_text.size(), SWKBD_OUTPUT_BUFFER_SIZE - 8));
output_main[0] = config.text_check;
std::memcpy(output_main.data() + 4, new_text.data(),
std::min(new_text.size(), SWKBD_OUTPUT_BUFFER_SIZE - 4));
} else {
const u64 size = text->size() * 2 + 8;
std::memcpy(output_sub.data(), &size, sizeof(u64));
std::memcpy(output_sub.data() + 8, text->data(),
std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 8));
output_main[0] = config.text_check;
std::memcpy(output_main.data() + 4, text->data(),
std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4));
}
complete = !config.text_check; complete = !config.text_check;
final_data = output_main; final_data = output_main;

View file

@ -33,7 +33,8 @@ struct KeyboardConfig {
u32_le length_limit; u32_le length_limit;
INSERT_PADDING_BYTES(4); INSERT_PADDING_BYTES(4);
u32_le is_password; u32_le is_password;
INSERT_PADDING_BYTES(6); INSERT_PADDING_BYTES(5);
bool utf_8;
bool draw_background; bool draw_background;
u32_le initial_string_offset; u32_le initial_string_offset;
u32_le initial_string_size; u32_le initial_string_size;