Issues with TextOut() on strings containing leading spaces

  • Hi,

    we discovered some issues with function TextOut() when strings with leading spaces shall be printed:

    1. If the string to be printed with Canvas->TextOut() contains leading blanks, only the first blank is displayed with the background color set in Canvas->Brush->Color and the remaining string is displayed with the standard background color (white).
      Conclusion: It is not possible to print a string with leading spaces in a different color than white.
    2. If the Canvas->Font->Style (FontStyle) contains fsUnderline then the first (underlined) blank of the leading blanks is printed at a wrong position (much too below with a wrong Y position). The following blanks then are displayed at the correct position.
      To workaround this issue we decided to replace the leading blanks by non-breakable blanks (U+00A0) which are displayed at the correct position. But this resolution has a drawback concerning the alignment of the printed lines if the widths of the "usual" blank (U+0020) and the non-breakable blank (U+00A0) are different.

    These issues were evaluated with wPDF V4.75.1 used with C++ Builder 10.3.1.

    Maybe they could be fixed in the next relase of wPDF!?

    Best regards,

    Michael

    • Offizieller Beitrag

    Hi,

    The standard textout calculates a lot of parameters itself which makes it highly dependent on windows.

    I recommend for best pdf and printing to use baseline alignment and if you need background provide a correct rectangle to exttextout api.

    Wptools also draws its own underline, since this makes it possible to draw underlines at the correct position even for different fonts.

    Julian

  • Thank you very much for your suggestions.

    But they are more or less just workarounds for these issues. Why should I have to deal with things like correct position and length of the underline and the correct line width if the used font already does it sufficiently? Also using a separate rectangle to be able to use a different background color is not really a simple solution.

    Printing the first blank on the wrong position (which does not only happen with underlined fonts, it also can be observed when using a different background color) did not appear with wPDF V4.38. The next version I used is V4.71.1 and there the bug can be observed.

    It seems that wPDF handles leading spaces in a not correctly special way. Using non-breakable spaces instead of "normal" spaces works reasonably, but it is also just a workaround.

    Maybe your advice to use baseline alignment does help, but I didn't find any property or function to set this. How do I use "baseline alignment"?


    If I use the standard TexOut() function on e.g., a Metafile canvas which I use to display a preview of the pdf, the background color is set as expected over the whole string regardless if there are leading spaces or not. The background color bug does only appear in the pdf created by wPDF and it does not make any sense to me that the behaviour of wPDF's TextOut() is different.

    Best regards,

    Michael