I like to fit an image into the boundaries of a page, inside MarginTop, -Left, -Right, -Bottom, at the moment where I fill a TRichView with data (rvComplete.AddPictureEx('Cover', CIm.Picture.Graphic, -1, rvvaBaseline);). My problem: at this moment I don't know any resolution so I can't calculate the images width.
It's for a title image of a novel that should be placed at the first page of the document.
Fit image into page
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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:
To get the desired picture width, subtract from Width returned by this function:
- RichViewEdit.LeftMargin+RichViewEdit.RightMargin
- LeftIndent and RightIndent of the current paragraph.
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;
- RichViewEdit.LeftMargin+RichViewEdit.RightMargin
- LeftIndent and RightIndent of the current paragraph.
Last edited by Sergey Tkachenko on Wed Sep 17, 2014 5:27 am, edited 1 time in total.