Skip to content

Commit

Permalink
Add rendering of UTF-16 Strings
Browse files Browse the repository at this point in the history
Previously, UTF-16 strings were not tolerated in the object pool.
Now they will properly get rendered (in theory).
  • Loading branch information
ad3154 committed Nov 7, 2024
1 parent 591e53a commit 9aa8fc1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmake/FindCAN_Stack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
19 changes: 17 additions & 2 deletions src/InputStringComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,28 @@ void InputStringComponent::paint(Graphics &g)
fontHeight = 8;
}

String decodedValue(value);

if ((value.length() >= 2) &&
(0xFF == static_cast<std::uint8_t>(value.at(0))) &&
(0xFE == static_cast<std::uint8_t>(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<int>(std::floor((static_cast<float>(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<int>(std::floor((static_cast<float>(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<int>(std::floor((static_cast<float>(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<int>(std::floor((static_cast<float>(get_height()) + 0.1f) / fontHeight)), 0.8f);
}

// If disabled, try and show that by drawing some semi-transparent grey
Expand Down
19 changes: 17 additions & 2 deletions src/OutputStringComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,28 @@ void OutputStringComponent::paint(Graphics &g)
fontHeight = 8;
}

String decodedValue(value);

if ((value.length() >= 2) &&
(0xFF == static_cast<std::uint8_t>(value.at(0))) &&
(0xFE == static_cast<std::uint8_t>(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<int>(std::floor((static_cast<float>(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<int>(std::floor((static_cast<float>(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<int>(std::floor((static_cast<float>(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<int>(std::floor((static_cast<float>(get_height()) + 0.1f) / fontHeight)), 0.8f);
}
}

Expand Down

0 comments on commit 9aa8fc1

Please sign in to comment.