Skip to content

Commit ebe6c80

Browse files
peterhorvath111lgritz
authored andcommitted
fix(IBA): fix incorrect vertical alignment in text render (#4500)
The `y` argument in `OIIO::ImageBufAlgo::render_text()` should represent the top and bottom edge of the text if vertical alignment is set to `TextAlignY::Top` and `TextAlignY::Bottom`. However currently the rendered text is off. The current code adjusts y to point to the top of the text box before rendering the text, but it has to be adjusted to point to the baseline of the text. Tests There is a existing test case, testing vertical alignment, but the reference image seems wrong and has now been updated. See the "Topleft" and "Rightbot" texts. | Current | Fixed | | -------- | ------- | | ![image](https://github.com/user-attachments/assets/e9e135bf-21d1-43a9-ace9-05b0e99af084) | ![image](https://github.com/user-attachments/assets/970dee6a-5337-4382-bcc2-16f474bba160) | Note: The testsuite contains a reference image for freetype v2.4.11 (aligned-freetype2.4.11.tif). I don't have that version built, and haven't been able to update the image. I'm wondering if this is still used or could be removed. I guess CI will tell. --------- Signed-off-by: peter.horvath <peter.horvath@autodesk.com>
1 parent 4b98fff commit ebe6c80

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/libOpenImageIO/imagebufalgo_draw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,9 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
11041104
if (alignx == TextAlignX::Center)
11051105
x -= (textroi.width() / 2 + textroi.xbegin);
11061106
if (aligny == TextAlignY::Top)
1107-
y += textroi.height();
1107+
y -= textroi.ybegin;
11081108
if (aligny == TextAlignY::Bottom)
1109-
y -= textroi.height();
1109+
y -= textroi.yend;
11101110
if (aligny == TextAlignY::Center)
11111111
y -= (textroi.height() / 2 + textroi.ybegin);
11121112

-1.06 KB
Binary file not shown.

0 commit comments

Comments
 (0)