StyledTextPrinter peculiarities

I am trying to work through StyledTextPrinter. The first annoying thing was that it did not scale when changing MaxHorizontalResolution and MaxVerticalResolution. Then I discovered that unassuming statement in the PrinterSetup LR page :

OK. So now I copy the RTFData to an invisible TextArea in which I change the size of the styleruns to change the scale.

But that is not all. I wanted to change the line spacing. I tried to change the RTFData with some RTF code that controls line spacing, but it is not supported by TextArea. So the best I found was to keep one line, delete all others, and print it, then proceed to the next one and set the exact place where it should print. The result was not what I expected, based on what a DrawString would do.

I just ran a few experiments, and here it is : instead of printing the text baseline at the coordinates, DrawBlock uses sort of a Left and Top of the outer limits of the text. In other words, the text line is below the y coordinate by about 0.75 the TextAscent.

In conclusion StyledTextPrinter.DrawBlock does not print at all the same way as DrawString in termes of y coordinates.

If I really want lines to be even with different font sizes, I will have to compensate for that, which would have not been necessary with DrawString.

Continuing my little exploration of printing the content of a styled TextArea…

DrawBlock is really not very good. Not only does it not position printing the same way as DrwaString, but if different font sizes are used line spacing becomes quite inconsistent. On top of it, I could not quite make sure, but it seems resolutions is limited to 72 dpi. In an age where printers seldom go lower than 600dpi, that is quite insufficient.

I ended up replacing DrawBlock by my own method, where I use DrawString and set the line spacing myself. The result is much nicer.

You have my sympathies! I have spent hours adding or subtracting a point here and there to line up DrawBlocks and DrawStrings to get a decent-looking printed document.

To add to the fun, alignments and line spacings come out differently between Windows and OS X Cocoa so to get the same printed output it is necessary to make a small adjustment to each item in the print method.

Resolution is not limited to 72 dpi.
Do you use TextArea.LineSpacing ?

[quote=175108:@Richard Corlett]You have my sympathies! I have spent hours adding or subtracting a point here and there to line up DrawBlocks and DrawStrings to get a decent-looking printed document.

To add to the fun, alignments and line spacings come out differently between Windows and OS X Cocoa so to get the same printed output it is necessary to make a small adjustment to each item in the print method.[/quote]

I have now solved the alignment problem : drawString all the way :slight_smile:

Indeed the very same fonts in Mac OS X and Windows have very different vertical spacing.

[quote=175121:@Benoit Griveau]Resolution is not limited to 72 dpi.
Do you use TextArea.LineSpacing ?[/quote]

From what I see with a 20x lens, there is a striking difference between Drawstring and Drawblock in terms of rendition. I know for a fact fonts can resolve some 600 dpi on regular paper, as I provide fonts containing patern characters for testing see http://micr-fonts.com/MICRfont/micr-fonts-macintosh.html

Drawblock simply does not pass the test. The same test characters resolve with DrawString, not with DrawBlock.

TextArea.LineSpacing allows only a minimum setting of 1. Absolute point line spacing is not available. So fonts with high heading and descenders appear much too spaced. Worse, line spacing in a TextArea depends on the fonts and their size. So in the same textArea, lines are not even. This maybe OK on screen, it is extremely ugly in print.