Multiple pages in SimpleGraph

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

Multiple pages in SimpleGraph

Postby P_G » January 25th, 2005, 10:34 am

Hello there,

I was looking for a way to have multiple pages in a SimpleGraph. Of course this could be a feature for future releases ***hint, hint***
Or does anyone have a workaround for splitting the contents of a SimpleGraph to several pages of a PrintPreview?

BTW - Kambiz, are you still programming :?: I think I read something about you stopping the development of freeware components (But I might be wrong). This would be really sad...

P_G
P_G
Senior Member
Senior Member
 
Posts: 51
Joined: June 14th, 2004, 11:13 am
Location: Germany

Postby Kambiz » January 27th, 2005, 10:16 am

As a workaround, you can get metafile of the graph, and then print on each page one part of the image.

I'm still programming because it's my profession. I hope one day I find my interest back to continue freeware component development.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2405
Joined: March 7th, 2003, 7:10 pm

Postby Stefan » January 27th, 2005, 3:11 pm

Hey,

I really like the idea of splitting up the Graph into pages in the runtime-design state. I'll put it on my "i-wish-i-had-more-time"-list ;)
Any thoughts on the subject; on how to implement or how it should "look" are more than very welcome...

Cheers,
Stefan
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Postby P_G » January 29th, 2005, 8:43 pm

I really love this forum! What more can I say ...?
:D
I hope, one day you find back your interest in programming freeware components, Kambiz. Your components rock !!!

With best regards, P_G
P_G
Senior Member
Senior Member
 
Posts: 51
Joined: June 14th, 2004, 11:13 am
Location: Germany

Postby MeW » February 17th, 2005, 6:41 pm

I've developed a multipage printing routine for TSimpleGraph and TPrintPreview. It's quite simple once you get the hang of it. From my Preview form I can adjust the scale of the Diagram from 10% to 200% using a Trackbar. Upon changing this bar the callback routine is triggered to re-generate the printer document.

Here comes the code:

Code: Select all
procedure TMainFrm.Printgraph(aPrintPreview: TPrintPreview; aScale: real);
var
  R: TRect;
  ImageSize, PrintSize: TPoint;
  x, y: integer;
begin
  aPrintPreview.BeginDoc;

  R := aPrintPreview.PrinterPageBounds;
  PrintSize.X := R.Right-R.Left;
  PrintSize.Y := R.Bottom-R.Top;
  ImageSize.X := Trunc(PrintSize.X * aScale); { aScale is [0.1 - 2] }
  ImageSize.Y := Trunc(PrintSize.Y * aScale);

  if (ImageSize.X > PrintSize.X) or
    (ImageSize.Y > PrintSize.Y) then
  begin
    { multipage printing }
    x := 0;
    y := 0;
    while (x < ImageSize.X) and (y < ImageSize.Y) do
    begin
      R := Rect(0, 0, ImageSize.X, ImageSize.Y);
      OffsetRect(R, -x, -y);
      FGraph.Print(aPrintPreview.Canvas, R); { or some other stretched drawing thing }
      { step horizontally }
      if (x + PrintSize.X < ImageSize.X) then
      begin
        Inc(x, PrintSize.X);
        aPrintPreview.NewPage;
      end
      else
      begin
        x := 0;
        Inc(y, PrintSize.Y);
        { step vertically }
        if (y < ImageSize.Y) then
        begin
          aPrintPreview.NewPage;
        end
        else
        begin
          y := 0;
          Break;
        end;
      end;
    end;
  end
  else
  begin
    { centered single page printing }
    InflateRect(R,
      -(PrintSize.X - ImageSize.X) div 2,
      -(PrintSize.Y - ImageSize.Y) div 2);
    FGraph.Print(aPrintPreview.Canvas, R);
  end;
  aPrintPreview.EndDoc;
end;


Works like magic if you don't mind me saying so.
MeW
Active Member
Active Member
 
Posts: 9
Joined: February 17th, 2005, 6:34 pm
Location: Netherlands

Centering and Overlap

Postby MeW » February 19th, 2005, 8:10 pm

I've extended the previous code post with a centering option (works for single and multipage) and an overlap % for multipage. Have fun.
Code: Select all
procedure TMainFrm.Printgraph(
  aPrintPreview: TPrintPreview;
  aScale: real;
  aCenter: boolean;
  aOverlapMultipage: real);
var
  R: TRect;
  ImageSize, PrintSize: TPoint;
  Centering: TPoint;
  x, y: integer;
begin
  aPrintPreview.BeginDoc;

  R := aPrintPreview.PrinterPageBounds;
  PrintSize.X := R.Right-R.Left;
  PrintSize.Y := R.Bottom-R.Top;
  ImageSize.X := Trunc(PrintSize.X * aScale);
  ImageSize.Y := Trunc(PrintSize.Y * aScale);
  FillChar(Centering, SizeOf(Centering), #0);

  if (ImageSize.X > PrintSize.X) or
    (ImageSize.Y > PrintSize.Y) then
  begin
    { multipage printing }
    if (aOverlapMultipage < 0) then aOverlapMultipage := 0;
    if (aOverlapMultipage > 0.5) then aOverlapMultipage := 0.5;

    if (aCenter) then
    begin
      Centering.X := (PrintSize.X - (ImageSize.X mod PrintSize.X)) div 2;
      Centering.Y := (PrintSize.Y - (ImageSize.Y mod PrintSize.Y)) div 2;
    end;
    x := 0;
    y := 0;
    while (x < ImageSize.X) and (y < ImageSize.Y) do
    begin
      R := Rect(0, 0, ImageSize.X, ImageSize.Y);
      OffsetRect(R, -x + Centering.X, -y + Centering.Y);
      FGraph.Print(aPrintPreview.Canvas, R);
      { step horizontally }
      if (x + PrintSize.X < ImageSize.X) then
      begin
        Inc(x, trunc(PrintSize.X * (1-aOverlapMultiPage)));
        aPrintPreview.NewPage;
      end
      else
      begin
        x := 0;
        Inc(y, trunc(PrintSize.Y * (1-aOverlapMultipage)));
        { step vertically }
        if (y < ImageSize.Y) then
        begin
          aPrintPreview.NewPage;
        end;
      end;
    end;
  end
  else
  begin
    { single page printing }
    InflateRect(R,
      -(PrintSize.X - ImageSize.X) div 2,
      -(PrintSize.Y - ImageSize.Y) div 2);
    if (not aCenter) then
      OffsetRect(R,
        -(PrintSize.X - ImageSize.X) div 2,
        -(PrintSize.Y - ImageSize.Y) div 2);
    FGraph.Print(aPrintPreview.Canvas, R);
  end;
  aPrintPreview.EndDoc;
end;
MeW
Active Member
Active Member
 
Posts: 9
Joined: February 17th, 2005, 6:34 pm
Location: Netherlands


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 2 guests

cron