Absolute print scaling.

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
HGG
Newbie
Newbie
Posts: 2
Joined: Fri Apr 30, 2004 4:00 am
Location: Denmark
Contact:

Absolute print scaling.

Post by HGG » Fri Mar 16, 2007 1:08 pm

Hi.

I am trying to print a chart to a user set axis length, ie. the user inputs a 10 cm X-axis length and the printer prints the chart with a 10 cm X-axis. I have tried all sorts of stunts to get it working, but it seems that there is some sort of rescaling going on. I attached a very simple code example, which I initially thought would do the job - but the print is off by several millimeters (I am printing in 600 dpi to a real printer and 1200 dpi to a pdf printer, so pixel roundoff is not the issue.). What am i doing wrong?

Regards,

Casper Kirkegaard, University of Aarhus.



// iWidth : integer -> Length of XAxis on print
// iHeight: integer -> Length of YAxis on print.

const
cmPerInch = 2.54;
begin
try
//Get printer resolution
PrinterPixPerInchX := GetDeviceCaps(Printer.Handle, LogPixelsX);
PrinterPixPerInchY := GetDeviceCaps(Printer.Handle, LogPixelsY);

//Calc desired print dimensions
PrintWidth := Round(iWidth * PrinterPixPerInchX/cmPerInch);
PrintHeight := Round(iHeight* PrinterPixPerInchY/cmPerInch);

//Upscale the length and height to match the length of the axis,
//rather than the length of the chart.
PrintWidth := (Self.Width/Self.ChartWidth)*PrintWidth;
PrintHeight := (Self.Height/Self.ChartHeight)*PrintHeight;

//Set printrect, the print is centered on the page.
PR.Left := Trunc((Printer.PageWidth - PrintWidth) / 2);
PR.Top := Trunc((Printer.PageHeight - PrintHeight) / 2);
PR.Right := PR.Left + PrintWidth;
PR.Bottom := PR.Top + PrintHeight;

//Send to printer
try
Printer.BeginDoc;
except
Raise EBubi.Create('Error connecting to printer.');
Printer.EndDoc;
end;
try
Self.PrintPartial(PR);
finally
Printer.EndDoc;
end;

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Mar 16, 2007 2:43 pm

Hi HGG,

You probably need to do what's told in this FAQ item.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply