trichview.com

trichview.support




Re: TRVPrint Page Size


Return to index


Author

Message

Sergey Tkachenko

Posted: 06/05/2004 19:04:49


It's not possible to wrap lines in editor exactly like in TRVPrint, because

RVPrint is formatted in the printer resolution and editor is formatted in

the screen resolution.


If you do not really need printer, you can use TRVReportHelper instead of

TRVPrint.

Otherwise read the text below.



----


This code allows to resize RichView so that it _approximately_ corresponds

to the size on the page.

Wrapping in the same places as on the paper is not 100% guaranteed.


Using:


var w, h: Integer;


// rvoClientTextWidth must be excluded from RichViewEdit1.Options.


GetPageSize(RVPrint1, w,h);

RichViewEdit1.MaxTextWidth :=

  w-RichViewEdit1.LeftMargin-RichViewEdit1.RightMargin;

RichViewEdit1.Format;



procedure GetPageSize(RVPrint: TRVPrint;

                            var Width, Height: Integer);

var DC: HDC;

    phoX, phoY, phW, phH, lpy, lpx, LM, TM, RM, BM: Integer;

begin

  DC := RV_GetPrinterDC; // from PtblRV unit


  Width  := GetDeviceCaps(DC, HORZRES);

  Height := GetDeviceCaps(DC, VERTRES);


  lpy := GetDeviceCaps(DC, LOGPIXELSY);

  lpx := GetDeviceCaps(DC, LOGPIXELSX);


  phoX := GetDeviceCaps(DC, PHYSICALOFFSETX);

  phoY := GetDeviceCaps(DC, PHYSICALOFFSETY);

  phW  := GetDeviceCaps(DC, PHYSICALWIDTH);

  phH  := GetDeviceCaps(DC, PHYSICALHEIGHT);


  LM := MulDiv(RVPrint.LeftMarginMM,   5*lpx, 127)- phoX;

  TM := MulDiv(RVPrint.TopMarginMM,    5*lpy, 127)- phoY;

  RM := MulDiv(RVPrint.RightMarginMM,  5*lpx, 127)- (phW-(phoX+Width));

  BM := MulDiv(RVPrint.BottomMarginMM, 5*lpy, 127)- (phH-(phoY+Height));


  if LM<0 then LM := 0;

  if TM<0 then TM := 0;

  if RM<0 then RM := 0;

  if BM<0 then BM := 0;


  dec(Width, LM+RM);

  dec(Height, TM+BM);


  DeleteDC(DC);


  DC := GetDC(0);

  Width  := MulDiv(Width,  GetDeviceCaps(DC, LOGPIXELSX), lpx);

  Height := MulDiv(Height, GetDeviceCaps(DC, LOGPIXELSY), lpy);

  ReleaseDC(0, DC);


end;





>

> Hi Sergey,

>

> I'm using TRVPrint.DrawPreview to paint a TRichViewEdit to a TCanvas.

>

> I set the TRVPrint.Margin sizes etc. and call FormatPages(rvdoAll).

>

> Now when I call TRVPrint.DrawPreview I pass the PageRect as the size of

the

> paper, in this case A3, adjusted to pixels etc. that I want the

TRichViewEdit

> sized to.

>

> The issue is the DrawPreview clips the right-hand side of the content as

> though the TRVPrint has not formatted the content in the TRVRichEdit

correctly.

>

> Am I missing something here or doing something wrong?

>

> Code snippet below.

>

> Thanks,

>

> Joan

>

> RVPrint1.LeftMarginMM   := 10;

> RVPrint1.RightMarginMM  := 10;

> RVPrint1.TopMarginMM    := 10;

> RVPrint1.BottomMarginMM := 10;

> RVPrint1.HeaderYMM      := iHeader;

> RVPrint1.FooterYMM      := iFooter;

> RVPrint1.FormatPages(rvdoALL);

>

> RVPrint1.DrawPreview(i+1, ACanvas, rect(0, 0, AWidth, AHeight));

>

> AWidth = 1123 and AHeight = 1587 (A3 with my PPI).





Powered by ABC Amber Outlook Express Converter