If you need to specify sizes related to a page, consider using ScaleRichView. It is a WYSIWYG editor, so sizes of content relative to the page will be the same on any computer, on the screen and on printers.
As for TRichView.
First, depending on RVStyle.Units, sizes may be specified in twips or in screen pixels.
I assume you use pixels. In this mode, picture size depends on the current screen resolution:
printing_size = size * printer_resolution / screen_resolution.
You need to remove dependency on the screen resolution.
You can do it by assigning the specific value (such as 96) to RichViewPixelsPerInch variable, and also RVStyle.TextStyles.PixelsPerInch.
Now, paper size for the current printer:
Code: Select all
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 := RV_UnitsToPixels(RVPrint.Margins.Left, RVPrint.Units, lpx)- phoX;
TM := RV_UnitsToPixels(RVPrint.Margins.Top, RVPrint.Units, lpy)- phoY;
RM := RV_UnitsToPixels(RVPrint.Margins.Right, RVPrint.Units, lpx)- (phW-(phoX+Width));
BM := RV_UnitsToPixels(RVPrint.Margins.Bottom, RVPrint.Units, lpy)- (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);
Width := MulDiv(Width, RichViewPixelsPerInch, lpx);
Height := MulDiv(Height, RichViewPixelsPerInch, lpy);
end;
To get the desired picture width, subtract from Width returned by this function:
- RichViewEdit.LeftMargin+RichViewEdit.RightMargin
- LeftIndent and RightIndent of the current paragraph.