trichview.support
Re: Line numbering |
Author |
Message |
Sergey Tkachenko |
Posted: 09/24/2004 20:47:54 Sorry for delay. The code below works correctly only if there are no non-text items and no paragraphs with justify alignment. Set RVPrint.ClipMargins to False, because clipping affects drawing in OnPagePostPaint (will be fixed in the next update). You need to process two events - TRVStyle.OnDrawStyleText and TRVPrint.OnPagePostPaint. Code in OnDrawStyleText must be executed only when printing (Currently, there is no reliable way to determine if this event is called for drawing on screen or for printing). So, if you display document on screen, use different RVStyle for printing ( call after AssignSource: RVStyle2.TextStyles := RVStyle1.TextStyles; RVStyle2.ParaStyles := RVStyle1.ParaStyles; RVStyle2.ListStyles := RVStyle1.ListStyles; RVPrint.rv.RVStyle := RVStyle2 ) YCoordList: TRVIntegerList; (TRVIntegerList is defined in RVClasses.pas) procedure TForm3.RVStyle1DrawStyleText(Sender: TRVStyle; const s: String; Canvas: TCanvas; StyleNo, SpaceBefore, Left, Top, Width, Height: Integer; DrawState: TRVTextDrawStates; var DoDefault: Boolean); begin if (rvtsItemStart in DrawState) or TCustomRVData(Sender.RVData).IsFromNewLine(Sender.ItemNo) then begin if YCoordList=nil then YCoordList := TRVIntegerList.Create; YCoordList.Add(Top); end; end; procedure TForm3.RVPrint1PagePostpaint(Sender: TRVPrint; PageNo: Integer; Canvas: TCanvas; Preview: Boolean; PageRect, PrintAreaRect: TRect); var i: Integer; s: String; r: TRect; begin if YCoordList=nil then exit; Canvas.Font.Assign(RVStyle1.TextStyles[0]); for i := 0 to YCoordList.Count-1 do begin s := IntToStr(i+1)+'.'; r := Rect(PageRect.Left, YCoordList[i], PrintAreaRect.Left-Canvas.Font.PixelsPerInch div 20, YCoordList[i]+100); DrawText(Canvas.Handle, PChar(s), Length(s), r, DT_SINGLELINE or DT_RIGHT or DT_NOCLIP); end; YCoordList.Free; YCoordList := nil; end; |
Powered by ABC Amber Outlook Express Converter