To print richt text with tprinter class, I've decided to implement an algorithm where I parse the richtext detecting rtf tokens and printing every time a font change happens. To this end, when achange is detected I do a "selection" of the text and then with REGetCharFormat I get the font and color.
But ortf:SetSel() does not seem to work properly. ReGetCharFormat always return the last font and color of text in the rtf control.
Here is a piece of the code showing at least part of the logic:
- Code: Select all Expand view RUN
local cRtf := RESaveAsRTF( ::ortf:hWnd, SF_RTF )
...
While nStart < len( cRtf )
nLast := FindEndOfText( cRtf, nStart )
::oRtf:SetSel( nStart, nLast )
cLine := SubStr( cRtf, nStart, nLast - nStart )
nStart := nLast + 1
nStart := FindEndOfTokens( cRtf, nStart )
aFont := REGetCharFormat( ::ortf:hWnd, @nColor )
nPad := ::oRtf:GetAlign()
oRtfFont := tFont():New( aFont[ LF_FACENAME ], ;
aFont[ LF_WIDTH ], ;
aFont[ LF_HEIGHT ], .f.,;
aFont[ LF_WEIGHT ] == FW_BOLD,,,;
aFont[ LF_WEIGHT ],;
aFont[ LF_ITALIC ],;
aFont[ LF_UNDERLINE ],,,,,, ::oPrn, aFont[ LF_PITCHANDFAMILY ] )
nChrsPerLine:= Int( ( ::oPrn:nHorzRes() - ( ::oPrn:nHorzRes() / 8.5 ) ) / max( oRtfFont:nWidth, 10 ) )
cLine := StrTran( cLine, "\par", "" )
nTotLns := MlCount( cLine, nchrsPerLine, 5, .t. )
For i:= 1 to nTotLns
::oprn:InchSay( nLine, nLeftMargin, MemoLine( cLine, nChrsPerLine, i, 5, .t. ), ;
oRtfFont,, nColor,, iif( nPad == 3, 2, 0 ) )
nLine += 0.16
...
It prints the text just fine. But it prints all text using the last font and color on the rtf control. I'm quite sure I'm doing something wrong with SetSel() or it is just not the function I need.
I still need to implement justification (npad above) and how to continue printing at the exact position that the last char was printed, but I'll get to that later. Right now, I only need to solve the setsel() problem.
Please help.
Reinaldo.