DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   Watched TopicsWatched Topics     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TSimpleGraph or TPrintPreview bug ?
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
P_G
Member


Joined: 14 Jun 2004
Posts: 44
Location: Germany

PostPosted: 19/04/05 13:35    Post subject: TSimpleGraph or TPrintPreview bug ? Reply with quote

Hello again,

I noticed a strange behaviour in TPrintPreview, but I'm not sure if this is a bug.
I use the TPrintPreview as a preview for a TSimpleGraph component. To create the graphic for TPrintPreview I took the following line:

Code:
Mainform.SimpleGraph.Print(PrintPreview1.Canvas, Rect(0, 0, Mainform.SimpleGraph.GraphBounds.Right, (Mainform.SimpleGraph.GraphBounds.Bottom)));


Here's the problem: I insert about 20 nodes (in line) in TSimpleGraph; each one containing a metafile. From a certain position TPrintPreview only displays the border of the nodes but not the metafiles. If I insert a bitmap instead the problem doesn't occur.
Does anyone have an idea concerning this effect?

C.U. P_G
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 19/04/05 20:11    Post subject: Reply with quote

The Print method of SimpleGraph draws the graph on the specified Canvas and in the rectangle specified by the Rect parameter. Therefore, you sould pass a rectangle on the PrintPreview page, not the bounding rectangle of the graph.

The following code is not tested but should work.

Code:
with PrintPreview1 do
  SimpleGraph.Print(Canvas, Rect(0, 0, PagePixels.X, PagePixels.Y));
Back to top
View user's profile Send private message Send e-mail Visit poster's website
P_G
Member


Joined: 14 Jun 2004
Posts: 44
Location: Germany

PostPosted: 20/04/05 16:48    Post subject: Reply with quote

Hello Kambiz,

I'm sorry but the problem occurs even with your code. And - as mentioned before - it doesn't effect nodes with simple bitmaps. That's why I thought it could be a bug, because I can't believe to have this problem by passing the wrong rect-parameters. In this case the bitmap nodes would show the same problem. BTW, nodes without graphics are always displayed in a correct way.

P_G
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 21/04/05 18:39    Post subject: Reply with quote

Hi P_G,

I dropped an instance of PrintPreview on the main form of the SimpleGraph's demo and added the following lines of code:

Code:
procedure MainForm.PreviewGraph;
begin
  PrintPreview.BeginDoc;
  try
    SimpleGraph.Print(PrintPreview.Canvas, PrintPreview.PageBounds);
  finally
    PrintPreview.EndDoc;
  end;
end;

Everything works just fine! Confused

_________________
Kambiz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
P_G
Member


Joined: 14 Jun 2004
Posts: 44
Location: Germany

PostPosted: 25/04/05 10:55    Post subject: Reply with quote

Hi Kambiz,

Here's what I get (see attachment). I took the simplegraph demo the way you did. I added a second form for the printpreview and put about 25 metafiles on the simplegraph. The printpreview shows the metafile nodes to a certain point and then only the borders.
Don't know why...

Shocked
P_G[/img]
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 09/05/05 12:18    Post subject: Reply with quote

Could you please attach your sgp file?
_________________
Kambiz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
P_G
Member


Joined: 14 Jun 2004
Posts: 44
Location: Germany

PostPosted: 09/05/05 19:08    Post subject: Reply with quote

Hello Kambiz,

here's the sgp-file attached.

P_G
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 11/05/05 18:17    Post subject: Reply with quote

Hi,

This problem occurs inside SimpleGraph. If you export the graph as metafile, you will see the bug.

So far I couldn't figure out the problem. I wonder why this bug appears only when the background image of the node is a metafile.

In case of any progress, I'll let you know.

Cheers

_________________
Kambiz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 12/05/05 14:13    Post subject: Reply with quote

This bug seems to be a Windows bug.

The bug occurs when the following conditions are met:
  1. The target canvas is a metafile canvas
  2. The canvas is clipped by a region
  3. A metafile is drawn on the canvas at X and Y position, which X or Y are larger than screen (better to say: reference DC) width or height, although are within the canvas bounds.
The attached program demonstrates the bug.

Cheers

_________________
Kambiz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 13/05/05 15:10    Post subject: Reply with quote

I had to modify TGraphNode.DrawBackground as follow to add a workaround to the mentioned bug.

Code:
procedure TGraphNode.DrawBackground(Canvas: TCanvas);
var
  ClipRgn: HRGN;
  Bitmap: TBitmap;
  Graphic: TGraphic;
begin
  if Background.Graphic <> nil then
  begin
    ClipRgn := CreateClipRgn(Canvas);
    try
      SelectClipRgn(Canvas.Handle, ClipRgn);
      try
        Graphic := Background.Graphic;
        if (Graphic is TMetafile) or (Graphic is TIcon) or Graphic.Transparent then
          Canvas.FillRect(BoundsRect);
        Background.OnChange := nil;
        try
          if (Graphic is TMetafile) and (GetObjectType(Canvas.Handle) = OBJ_ENHMETADC) and
             ((BoundsRect.Left >= Screen.Width) or (BoundsRect.Top >= Screen.Height)) then
          begin // Workaround Windows bug!
            Bitmap := TBitmap.Create;
            try
              Bitmap.Transparent := True;
              Bitmap.TransparentColor := clFuchsia;
              Bitmap.Canvas.Brush.Color := clFuchsia;
              Bitmap.Width := BoundsRect.Right - BoundsRect.Left;
              Bitmap.Height := BoundsRect.Bottom - BoundsRect.Top;
              Bitmap.Canvas.StretchDraw(Rect(0, 0, Bitmap.Width, Bitmap.Height), Graphic);
              Canvas.Draw(BoundsRect.Left, BoundsRect.Top, Bitmap);
            finally
              Bitmap.Free;
            end;
          end
          else
            Canvas.StretchDraw(BoundsRect, Graphic);
        finally
          Background.OnChange := BackgroundChanged;
        end;
      finally
        SelectClipRgn(Canvas.Handle, 0);
      end;
    finally
      DeleteObject(ClipRgn);
    end;
    Canvas.Brush.Style := bsClear;
  end;
end;


The update for SimpleGraph is avilable to download.

_________________
Kambiz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
P_G
Member


Joined: 14 Jun 2004
Posts: 44
Location: Germany

PostPosted: 13/05/05 16:23    Post subject: Reply with quote

Do you know why I like this forum? Because of the support! This thread says it all: It's not only you get great components, but you get an even better support. That's absolutely unique! Very Happy

Thanks a lot, Kambiz
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 13/05/05 19:58    Post subject: Reply with quote

Thanks to you!
_________________
Kambiz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
P_G
Member


Joined: 14 Jun 2004
Posts: 44
Location: Germany

PostPosted: 17/05/05 13:25    Post subject: Reply with quote

Hi Kambiz,

I had some problems with your workaround due to the fact that all critical nodes are converted to bitmaps now, so the quality is not satisfying.
That's why I did some modifications on the GetAsMetafile function. It's not perfect but seems to be on the right way. Maybe you could take a look on the following code:

Code:
function TSimpleGraph.GetAsMetafile: TMetafile;
var
  I: Integer;
  GraphRect: TRect;
  MetaCanvas: TMetafileCanvas;
  v,w: TSize;
begin
  GraphRect := GraphBounds;
  Result := TMetafile.Create;
  Result.Width := GraphRect.Right - GraphRect.Left;
  Result.Height := GraphRect.Bottom - GraphRect.Top;
  MetaCanvas := TMetafileCanvas.Create(Result, 0);
  try
  // Workaraound for Windows-bug
   SetViewportOrgEx(MetaCanvas.Handle, GraphRect.Left, GraphRect.Top, nil);
   SetMapMode(MetaCanvas.Handle, MM_Lometric);
   GetWindowExtEx(MetaCanvas.Handle, w);
   GetViewPortExtEx(MetaCanvas.Handle, v);
   SetMapMode(MetaCanvas.Handle, MM_Anisotropic);
   SetWindowExtEx(MetaCanvas.Handle, w.cx, w.cy, nil);
   SetViewPortExtEx(MetaCanvas.Handle, v.cx, -v.cy, nil);
    for I := 0 to Objects.Count - 1 do
      with Objects[I] do if IsLink then Draw(MetaCanvas);
    for I := 0 to Objects.Count - 1 do
      with Objects[I] do if not IsLink then Draw(MetaCanvas);
  finally
    MetaCanvas.Free;
  end;
end;

P_G
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 23/05/05 07:40    Post subject: Reply with quote

In your code, the metafile size is in actual size, however you've scaled down the graph.
_________________
Kambiz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
P_G
Member


Joined: 14 Jun 2004
Posts: 44
Location: Germany

PostPosted: 23/05/05 08:09    Post subject: Reply with quote

Yes, of course. I've seen no other way to get all the metafiles as metafiles into the nodes. BTW - I'd be thankful for further suggestions concerning this problem.

Yours, P_G
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Goto page 1, 2  Next
Page 1 of 2

Add to favorites

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group