For a string with trailing spaces, freetype ignores the last space in boundary calculations

Issue #243 closed
Lenard Lindstrom
created an issue

For non-rotated horizontal text, a string of one space, " ", will produce a zero width rectangle or surface. A string of two spaces produces a rectangle or surface of only one space in width.

Fix: include the advance of a terminating space of a string in the calculation of the text boundary. Normally only the bitmap width of the last character in a string is used when determining the text boundary. This avoids boundary padding, empty rows or columns. But a space is nothing but padding; its bitmap has width and height of zero. So make an exception for the trailing space and use its advance to extend the boundary.

An test for the bug will be included in the unit tests.

Comments (3)

  1. Lenard Lindstrom reporter

    Close Issue #243

    Issue #243: For a string with trailing spaces, freetype ignores the last space in boundary calculations

    After the layout loop, determine if the last character in the text string is a space by checking if its bitmap is width 0. If so, update the text boundaries — min_x, max_x, min_y, max_y — with the current pen position, which already includes the space's advance.

    Also update change the Font.render_to example in the freetype module doc page to reflect the removal of this "feature".

    → <<cset c080fc971853>>

  2. Log in to comment