KWin replaces any non-printable character with a space. This check does not handle surrogate pairs correctly. Additionally, translators sometimes insert non-printable soft-hyphens into titles, which also cause KWin to display a space instead.
This code adds the missing surrogate handling, and (to fix both issues), also removes non-printable characters instead of replacing them with a space.
Also moved the changed test after these changes, so that changes in non-printable characters do not cause unneeded redraws.