Board index » delphi » Newbie: Justification of text using the printer object

Newbie: Justification of text using the printer object

This seems like it should be an easy thing to do, but I want to be able to
right and left justify lines of text I send to the printer using
Canvas.TextOut.  I know I can measure the width of the string I am printing,
but I can't figure out how to dynamically add spaces to the line to line the
text up on the right and left.

Am I going about this the wrong way?  I definitely don't want to use a
third-party reporting tool like ReportSmith.

Thanks,

David Montgomery

 

Re:Newbie: Justification of text using the printer object


Quote
des...@nexus.interealm.com (David Montgomery) wrote:
>This seems like it should be an easy thing to do, but I want to be able to
>right and left justify lines of text I send to the printer using
>Canvas.TextOut.  I know I can measure the width of the string I am printing,
>but I can't figure out how to dynamically add spaces to the line to line the
>text up on the right and left.
>Am I going about this the wrong way?  I definitely don't want to use a
>third-party reporting tool like ReportSmith.

To right Justify the instead of spaces try moving your x position by
PageWidth - TextWidth.

Left Justfiy use minimum x

Full justify: I would try to take
        space = PageWidth - TextWidth (not counting spaces in the text)

then position each word with the the following amount of space after
each word.
        Between Word Space = space / (number of words -1)

Farley

Re:Newbie: Justification of text using the printer object


Hi David,

Check out my Web site at

http://www.mbrindle.fl.net.au

I have a MbPrint unit (with full source) that allows full ,left,
right, centre justification.

The library is very complete and includes a 56 page document in word
format.

It will be on the web site some time over the next 48 hours. I am just
setting up my component download area.

Mark

Re:Newbie: Justification of text using the printer object


Quote
des...@nexus.interealm.com (David Montgomery) wrote:
>This seems like it should be an easy thing to do, but I want to be able to
>right and left justify lines of text I send to the printer using
>Canvas.TextOut.  I know I can measure the width of the string I am printing,
>but I can't figure out how to dynamically add spaces to the line to line the
>text up on the right and left.

>Am I going about this the wrong way?  I definitely don't want to use a
>third-party reporting tool like ReportSmith.

>Thanks,

>David Montgomery

David,

Try your browser on:

http://www.borland.com/TechInfo/delphi/devcorn/techtips/printform.html

Has all you ever wanted to know about writing a printer previewer/driver.
Its code is a little clumsy at times. And the shading mechanism is wrong,
but 90% works.

Jim

Other Threads