How to right justify text on a printer (Windows)?

How to right justify text on a printer (Windows)?

Postby dpaterso » Tue Feb 14, 2006 1:16 pm

This is driving me insane!

Does anyone have a routine that will right justify text on a printer.

I am using the 'Courier New' font which does not appear to be a proportional font but still do not seem to get it right.

In the 'old' DOS days we would say:

@ 0, 80 - Len( cVar1 ) Say cVar1
@ 1, 80 - Len( cVar2 ) Say cVar2

but this does not work in windows.

I have been pulling my hair out the whole morning with this (type) of code:

...

Define Font oFont;
Name 'Courier New';
Size 15, 50

Print oPrn Name 'Report' From User

If Empty( oPrn:hDC )
oPrn:End( )
Return ( NIL )EndIf

oPrn:SetFont( oFont )

nRowStep := oPrn:nVertRes( ) / 66 // 66 rows
nColStep := oPrn:nHorzRes( ) / 80 // 80 cols

oPrn:SetPortrait( )

Page

nRow += nRowStep
oPrn:Say( nRow, ( nColStep * 80 ) - (nColStep * ( Len( 'D' ) ) ), 'D' )

nRow += nRowStep
oPrn:Say( nRow, ( nColStep * 80 ) - (nColStep * ( Len( 'DD' ) ) ), 'DD' )

EndPage

EndPrint

oPrn:End( )

etc. etc.

If you keep repeating the lines above the text 'creeps' to the left.

Any ideas?

Regards,

Dale.
dpaterso
 
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa

Re: How to right justify text on a printer (Windows)?

Postby Enrico Maria Giordano » Tue Feb 14, 2006 2:17 pm

Have a look at the eighth parameter of TPrinter:Say() method (nPad).

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby manuramos » Tue Feb 14, 2006 7:06 pm

RPAD not run efectively in many situations, Try this:

nRightMargin := xxx pixels
oPrn:Say( nTop,nRightMargin-oPrn:GetTextWidth( cText , oFont ),cText,oFont )

You could build a function to only right justify all cTexts. (excuse my english)
Nos Gusta Programar
manuramos
 
Posts: 219
Joined: Mon Dec 26, 2005 7:25 pm
Location: Jerez de la Frontera (Spain)

Right Justify to Printer

Postby E. Bartzokas » Tue Feb 14, 2006 11:12 pm

Try this:

LPAD(myvariable, 12) for character strings

(your variable can be a field name of course, and the number 12 is how many spaces will be added infront of the variable/field.
Same way as it is required to use: Str(nNumber, 12,2) for numbers

I hope I gave you an idea to help you.

Regards
Evans
User avatar
E. Bartzokas
 
Posts: 114
Joined: Tue Feb 14, 2006 8:13 am
Location: Corinth, Greece

Postby James Bott » Wed Feb 15, 2006 12:23 am

Code: Select all  Expand view  RUN
#include "fivewin.ch"

function main()
   local oPrn,oFont, nRow:=0,nRowStep:=1,nColStep:=1, aText, I

   Print oPrn Name 'Report' preview

   If Empty( oPrn:hDC )
   oPrn:End( )
   Return ( NIL )
   EndIf

   Define Font oFont;
   Name 'Courier New';
   Size 15, 10 of oPrn

   oPrn:SetFont( oFont )

   nRowStep := oPrn:nVertRes( ) / 66 // 66 rows
   nColStep := oPrn:nHorzRes( ) / 80 // 80 cols

   oPrn:SetPortrait( )

   aText:= {"D","very long text","shorter","123456789","cat"}

      Page

      for I:= 1 to 5

         nRow += nRowStep
         //oPrn:Say( nRow, ( nColStep * 80  ) - (nColStep * ( Len( "D" ) ) ), "D" )
         // Last parameter: 0= left justify, 1= right justify, 2= Center justify
         oPrn:Say( nRow, ( nColStep * 20 ),aText[i],,,,,1)

      next

      EndPage

   EndPrint

   oPrn:End( )

   oFont:end()

return nil
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Enrico Maria Giordano » Wed Feb 15, 2006 7:53 am

James Bott wrote:
Code: Select all  Expand view  RUN
EndPrint

oPrn:End( )


You don't have to issue the latter as it is included in the function called by EndPrint command (PrintEnd()).

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 49 guests