diff --git a/cmake/FindCAN_Stack.cmake b/cmake/FindCAN_Stack.cmake index 1639cad..12a009a 100644 --- a/cmake/FindCAN_Stack.cmake +++ b/cmake/FindCAN_Stack.cmake @@ -3,7 +3,7 @@ include(FetchContent) FetchContent_Declare( CAN_Stack GIT_REPOSITORY https://github.com/Open-Agriculture/AgIsoStack-plus-plus.git - GIT_TAG 29dab887a48bb204aae983b06052d52b0f2314d5 + GIT_TAG 80a1823e62ab65eb660cf1c1f9231d5fd9c7fc7f ) FetchContent_MakeAvailable(CAN_Stack) endif() diff --git a/src/InputStringComponent.cpp b/src/InputStringComponent.cpp index 7f23756..e9ab834 100644 --- a/src/InputStringComponent.cpp +++ b/src/InputStringComponent.cpp @@ -82,13 +82,28 @@ void InputStringComponent::paint(Graphics &g) fontHeight = 8; } + String decodedValue(value); + + if ((value.length() >= 2) && + (0xFF == static_cast(value.at(0))) && + (0xFE == static_cast(value.at(1)))) + { + // String is UTF-16 encoded. + if (0 != (value.length() % 2)) + { + // If the length attribute does not indicate an even number of bytes the last byte is ignored + value.pop_back(); + } + decodedValue = String::createStringFromData(value.c_str(), value.size()); + } + if (get_option(Options::AutoWrap)) // TODO need to figure out proper font clipping { - g.drawFittedText(value, 0, 0, get_width(), get_height(), convert_justification(get_horizontal_justification(), get_vertical_justification()), static_cast(std::floor((static_cast(get_height()) + 0.1f) / fontHeight)), 0.8f); + g.drawFittedText(decodedValue, 0, 0, get_width(), get_height(), convert_justification(get_horizontal_justification(), get_vertical_justification()), static_cast(std::floor((static_cast(get_height()) + 0.1f) / fontHeight)), 0.8f); } else { - g.drawFittedText(value, 0, 0, get_width(), get_height(), convert_justification(get_horizontal_justification(), get_vertical_justification()), static_cast(std::floor((static_cast(get_height()) + 0.1f) / fontHeight)), 0.8f); + g.drawFittedText(decodedValue, 0, 0, get_width(), get_height(), convert_justification(get_horizontal_justification(), get_vertical_justification()), static_cast(std::floor((static_cast(get_height()) + 0.1f) / fontHeight)), 0.8f); } // If disabled, try and show that by drawing some semi-transparent grey diff --git a/src/OutputStringComponent.cpp b/src/OutputStringComponent.cpp index ebf9da0..cd88549 100644 --- a/src/OutputStringComponent.cpp +++ b/src/OutputStringComponent.cpp @@ -81,13 +81,28 @@ void OutputStringComponent::paint(Graphics &g) fontHeight = 8; } + String decodedValue(value); + + if ((value.length() >= 2) && + (0xFF == static_cast(value.at(0))) && + (0xFE == static_cast(value.at(1)))) + { + // String is UTF-16 encoded, font type is ignored. + if (0 != (value.length() % 2)) + { + // If the length attribute does not indicate an even number of bytes the last byte is ignored + value.pop_back(); + } + decodedValue = String::createStringFromData(value.c_str(), value.size()); + } + if (get_option(Options::AutoWrap)) // TODO need to figure out proper font clipping { - g.drawFittedText(value, 0, 0, get_width(), get_height(), convert_justification(get_horizontal_justification(), get_vertical_justification()), static_cast(std::floor((static_cast(get_height()) + 0.1f) / fontHeight)), 0.8f); + g.drawFittedText(decodedValue, 0, 0, get_width(), get_height(), convert_justification(get_horizontal_justification(), get_vertical_justification()), static_cast(std::floor((static_cast(get_height()) + 0.1f) / fontHeight)), 0.8f); } else { - g.drawFittedText(value, 0, 0, get_width(), get_height(), convert_justification(get_horizontal_justification(), get_vertical_justification()), static_cast(std::floor((static_cast(get_height()) + 0.1f) / fontHeight)), 0.8f); + g.drawFittedText(decodedValue, 0, 0, get_width(), get_height(), convert_justification(get_horizontal_justification(), get_vertical_justification()), static_cast(std::floor((static_cast(get_height()) + 0.1f) / fontHeight)), 0.8f); } }