Adjust margins for PrintProportional

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
manfred.gahr
Newbie
Newbie
Posts: 21
Joined: Thu Nov 08, 2007 12:00 am

Adjust margins for PrintProportional

Post by manfred.gahr » Fri Feb 27, 2009 11:40 am

Dear Steema Team,

We used to print the content of the TChart (ver 8.02) with PrintProportional=true. The recent demand from the customer is to make automatic margins customizable. I tried to change PrintMargins property, but in proportional mode it seems to be disregarded (a bug or intention?).

If I set PrintProportional=false, then margins are ok, but the whole chart conent changes. Unfortunately this is inacceptable.

My question is: how can I adjust margins in PrintProportional mode?

Thank you,
Manfred

manfred.gahr
Newbie
Newbie
Posts: 21
Joined: Thu Nov 08, 2007 12:00 am

Post by manfred.gahr » Fri Feb 27, 2009 1:01 pm

To be more precise: I can of course mimic PrintProportional mode actually having PrintProportional=false by manually doing a bunch of tricky calculations. But this looks like a code duplication as soon as similar calculations have been already implemented by Steema in PrintProportional mode. The only thing I lack is a possibility to control the size of a (smallest) automatic margin.

Ideal situation would be:

Code: Select all

Chart->PrintProportional = true;
Chart->PrintMargins = TRect(5,5,5,5);
Giving the picture where the smallest margin is 5% and another one is bigger just enough to make the printed chart proportional to the original one.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Mon Mar 02, 2009 2:16 pm

Hi Manfred,

Yes, the printproportional property could force the chart to be proportional, so that when the user changes one of the margins, the other is would be set automatically. I've added it to the wish list to be implemented in further releases (TV52013915).

In the meanwhile you could control the margins customly doing something similar to this:

Code: Select all

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  Chart1.PrintMargins := Rect(5,5,5,5);
  Chart1.PrintProportional := False;
  //Chart1.PrintResolution := -70;
  ChartPreviewer1.Chart := Chart1;
  ChartPreviewer1.Execute;
end;

procedure TForm1.ChartPreviewer1AfterDraw(Sender: TObject);
begin
  ChartPreviewer1.Chart.Title.Text.Text := inttostr(Chartpreviewer1.Chart.Width);
  if Chart1.PrintMargins.Left > 10 then
  begin
    ChartPreviewer1.PreviewPanel.Color := clblue;
    Chart1.PrintProportional := False;
    Chart1.PrintMargins := Rect(10,Chart1.PrintMargins.Top, chart1.PrintMargins.Right,chart1.PrintMargins.Bottom);
    ChartPreviewer1.PreviewPanel.Repaint;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

manfred.gahr
Newbie
Newbie
Posts: 21
Joined: Thu Nov 08, 2007 12:00 am

Post by manfred.gahr » Mon Mar 02, 2009 3:11 pm

Hi Yeray,

Thank you for your response and willing to help. The problem is that we don't use a preview component and just post the TChart directly to the printer. So in a meantime I've implemented the proportional-mimic logic by myself. Here's my solution just in case it might be helpful for TV52013915 or someone encounters a similar problem

Code: Select all

void __fastcall TMyChart::Print()
{
   // #3350: Margins
   const double marginCm  = MyCustomMargin; // !!!
   const HDC    hdc       = Printer()->Handle;
   const double hPxPerCm  = double(GetDeviceCaps(hdc, LOGPIXELSX)) / 2.54;
   const double vPxPerCm  = double(GetDeviceCaps(hdc, LOGPIXELSY)) / 2.54;
   const double hMarginPx = marginCm * hPxPerCm;
   const double vMarginPx = marginCm * vPxPerCm;

   // Mimic proportional printing
   const double W     = Printer()->PageWidth;
   const double H     = Printer()->PageHeight;
   const double k     = double(Width) / double(Height);
   const double coeff = k * H / W;
   double hMarginPercent, vMarginPercent;
   if (coeff <= 1.0)
   {  vMarginPercent = vMarginPx / H;
      hMarginPercent = (1.0 - (1.0-2.0*vMarginPercent)*coeff)/2.0;
   }
   else
   {  hMarginPercent = hMarginPx / W;
      vMarginPercent = (1.0 - (1.0-2.0*hMarginPercent)/coeff)/2.0;
   }

   hMarginPercent *= 100;
   vMarginPercent *= 100;

   PrintMargins = TRect(hMarginPercent,vMarginPercent,hMarginPercent,vMarginPercent);
   PrintProportional = false;

   TChart::Print();
}
Regards,
Manfred

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Mon Mar 02, 2009 3:54 pm

Hi Manfred,

Thanks for your code, we'll consider if it's a good solution for the general problem.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply