Finally, I've solved this trouble as I needed. Here is a small contribution.
It's very raw source, but it works in my application
Some comments:
FRichEdit - internal editor;
fmMain - main form with TRVPrint on it
Printer - instance of TRVPrint on main form
ScaleX, ScaleY - scales for X-axis and Y-axis. 1 is for 100 percent.
Code: Select all
procedure TopLeftCanvasDraw(Canvas: TCanvas; ScaleX, ScaleY: Extended; Width, Height: Integer);
var
EMF: TMetafile;
EMFCanvas: TMetafileCanvas;
dc: hdc;
LocalHandle: THandle;
tHeight, tWidth: Integer;
rgn: HRGN;
begin
//Assigning sources and reformating pages
fmMain.Printer.AssignSource(FRichEdit);
fmMain.Printer.FormatPages(rvDoAll);
//Getting HDC for further actions
LocalHandle := GetDC(0);
//Creating main metafile
EMF := TMetafile.Create;
try
//Creating canvas
EMFCanvas := TMetafileCanvas.Create(EMF, LocalHandle);
try
//Calculating height and width
EMF.Width := Trunc(fmMain.Printer.Preview100PercentWidth * ScaleX);
EMF.Height := Trunc(fmMain.Printer.Preview100PercentHeight * ScaleY);
//Creating clipping region and Selecting it
rgn := CreateRectRgn(0, 0, Width, Height);
SelectClipRgn(EMFCanvas.Handle, rgn);
//Outputing first page in component
//actually, we can make it in cycle for other pages, but it doesn't
//needed in my project
fmMain.Printer.DrawPreview(1, EMFCanvas, Rect(0, 0, EMF.Width, EMF.Height));
//Clear graphic objects
SelectClipRgn(Canvas.Handle, 0);
DeleteObject(rgn);
finally
EMFCanvas.Free;
end;
//Output on canvas
Canvas.Draw(FX, FY, EMF);
finally
EMF.Free;
ReleaseDC(0, LocalHandle);
end;
end;
By the way, Sergey, I've found, that the better way is to use Metafiles, not Bitmaps - it cause a lot of troubles with big images - I don't know graphic side of WinAPI and Delphi so well, and I got some troubles by making this code.
Anyway, if you consider, that this code is good enough for making some major improvements or it's good for some ideas, you can use it freely.
---
Best regards,
Michael.
PS If you have a better suggestion of source, I would be very appreciate.