Skip to content

Commit

Permalink
fix: Windows newline shows invalid character in text render (#4501)
Browse files Browse the repository at this point in the history
Newline in strings on Windows is encoded as '\r\n', that is currently
not handled by the text render code and so carriage return (\r) shows up
in the rendered text. As a fix we simply ignore this character.
We came across this issue while exporting user specified text from DCCs
to render on Windows.

I'm not sure how to make a proper test case for this. Current tests
specify a command as a string that is passed to oiiotool as arguments
and executed in the command line. But adding a newline to the text
breaks the command.

Signed-off-by: Peter Horvath <[email protected]>
Signed-off-by: peter.horvath <[email protected]>
  • Loading branch information
peterhorvath111 authored Oct 25, 2024
1 parent 0c24aad commit 6eb9538
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libOpenImageIO/imagebufalgo_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,11 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
// Glyph by glyph, fill in our textimg buffer
int origx = x;
for (auto ch : utext) {
// on Windows a newline is encoded as '\r\n'
// we simply ignore carriage return here
if (ch == '\r') {
continue;
}
if (ch == '\n') {
x = origx;
y += fontsize;
Expand Down

0 comments on commit 6eb9538

Please sign in to comment.