I'm no longer printing richtext using tprinter, but on my previous systems I used it a lot. Here are some things you may be able to use:
Code: Select all
nFrom := 0
a := ::oprn:Inch2Pix( ::ntop, ::nLeft ) //print region
b := ::oprn:Inch2Pix( ::nRight, ::nBottom )
RESetSelection( aoRtf[i]:hWnd, nFrom, -1)
nLen := Len( aoRtf[ i ]:GetSel() ) -1
aRet := REPrintBox( aoRtf[i]:hWnd, iif( ::isPreview, ::oPrn:hDCOut, ::oPrn:hDC ),.t., a[1 ], a[2], b[1], b[2], nFrom )
nFrom := aRet[ 1 ]
::nLastLine := ::oPrn:Pix2Inch( aRet[ 2 ], 0 )[1]
Notice how RePrintBox returns an array with the last printed pos in the RTF as the 1st element, and the line pos on the page that it printed on. You will need this in case you run into the next page. In case it helps you, below is the full method that did the printing. Keep in mind that it prints from an array of multiple rtfs and that printing all the rtfs may take multiple pages.
Code: Select all
*-------------------------------------------------------------------------------------------------------------------------------
METHOD PrintBodyWithAttributes() CLASS PathologyTranscription
local cTitle := "Pathology Transcription " + hb_TokenUpper( Trim( ::oPat:Last ) + " " + ;
Trim( ::oPat:last2 ) + ", " + ::oPat: name )
local nFrom := 0
local a := ::oprn:Inch2Pix( ::ntop, ::nLeft )
local b := ::oprn:Inch2Pix( ::nRight, ::nBottom )
local isdone := .f.
local aoRtf := ::aRtfTranscriptions
local i := 1
local aRet, Elem
local nLen := 0
local aFont, nColor
local nTotPage := 0
::nLastLine := ::oPrn:Pix2Inch( a[ 1 ], 0 )[1]
While !isdone
while i < _MAX_AREAS +1 .and. aoRtf[ i ] == Nil
i++
End
if i > _MAX_AREAS
exit
endif
RESetSelection( aoRtf[i]:hWnd, nFrom, -1)
nLen := Len( aoRtf[ i ]:GetSel() ) -1
aRet := REPrintBox( aoRtf[i]:hWnd, iif( ::isPreview, ::oPrn:hDCOut, ::oPrn:hDC ),.t., a[1 ], a[2], b[1], b[2], nFrom )
nFrom := aRet[ 1 ]
DO CASE
CASE nFrom < nlen //did not finish, must run over to next page
ntotPage++ ;aoRtf[i]:nPrintedPages++
::oprn:InchSay( 10.53, 7.5, "Page " + Str( nTotPage, 2 ), ::aFonts[ 1 ],,,, PAD_RIGHT )
::oprn:InchSay( 10.0, 4.25, "Continues on page " + str( nTotPage + 1, 2 ) + "...", ::ofont,,,, 2 )
::oprn:endPage() ;::oprn:Startpage()
a := ::oPrn:Inch2Pix( .60, 0.15 ) ;b := ::oprn:Inch2Pix( 10.5, 8.15 ) //Main Boxed area
::oprn:Box( a[ 1 ], a[ 2 ], b[ 1 ], b[ 2 ] ) //draw box around main area
::oprn:InchSay( 0.30, 0.50, "...continuation from page " + Str( nTotPage, 2 ), ::oFont )
::PrintForm( .f. )
::FillHeader1( .f. )
a := ::oprn:Inch2Pix( ::ntop, ::nLeft ) //new print region
b := ::oprn:Inch2Pix( ::nRight, ::nBottom ) //area for text
CASE i == 4
isdone := .t.
CASE i < len( aoRtf )
if !empty( aoRtf[ i ]:GetText() )
/*(aFont := REGetCharFormat( aoRtf[i]:hWnd, @nColor )
logfile( "f:\mp\trace.log", { ::oprn:Pix2Inch( aFont[ LF_HEIGHT ], 0 )[1], aoRtf[i]:GetLineFromChar( nFrom ) -nTmp } )
::nLastLine := ( ( ( aoRtf[i]:GetLineFromChar( nFrom ) - nTmp ) + 1 ) * ;
Max( ::oprn:Pix2Inch( aFont[ LF_HEIGHT ], 0 )[1], 0.10 ) ) + ;
iif( ntotPage > 0, 1.00, 4.69 ) */
::nLastLine := ::oPrn:Pix2Inch( aRet[ 2 ], 0 )[1]
::nlastline += 0.32 //couple of blank lines
Endif
i++ ;nFrom := 0
a := ::oprn:Inch2Pix( ::nLastLine, ::nLeft ) //new print region
// nTmp := 0
OTHERWISE //unknown problems --get the hell out
isdone := .t.
END
End
::oprn:InchSay( 10.53, 7.5, "Page " + Str( nTotPage+1, 2 ), ::aFonts[ 1 ],,,, PAD_RIGHT )
::nLastLine := ::oPrn:Pix2Inch( aRet[ 2 ], 0 )[ 1 ]
return nil
The key here is understanding how REPrintBox() works.
Hope that helps.
Reinaldo.