Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roassal should export PNG #1089

Closed
seandenigris opened this issue Aug 3, 2015 · 13 comments
Closed

Roassal should export PNG #1089

seandenigris opened this issue Aug 3, 2015 · 13 comments

Comments

@seandenigris
Copy link
Contributor

Originally reported on Google Code with ID 1089

We have a first draft of RTPNGExporter, but the problem is that it provides only the
visible part of the morph.

The problem is here:
exportToFile
    PNGReadWriter 
        putForm: view view canvas morph imageForm
        onFileNamed: self fileName 

Reported by tudor@tudorgirba.com on 2014-10-09 05:05:32

@seandenigris
Copy link
Contributor Author

Ideally, we should delegate to the AthensCairoCanvas, but somehow the athens canvas
instance from the TRCanvas is empty.

We certainly do not want to re-render the scene because some picture can be expensive
to produce.

Reported by tudor@tudorgirba.com on 2014-10-09 05:10:55

@seandenigris
Copy link
Contributor Author

Yes, somehow your canvas in TRCanvas is only used for shape creations
(computePath). Drawing is done with TRMorphs cairo-surface.

AthensCairoSurface has a writeToPng: method for writing the current surface data
as a png file.

Reported by nicolaihess on 2014-10-09 07:33:48

@seandenigris
Copy link
Contributor Author

Indeed. However, we probably have to redraw everything again given that the canvas in
the TRMorph is only the visible one

Reported by tudor@tudorgirba.com on 2014-10-09 07:56:07

@seandenigris
Copy link
Contributor Author

I tried this, but somehow it does not work:

exportToFile
     | completeMorph |
     completeMorph := view view canvas morphClass new
          canvas: view view canvas;
          extent: view view canvas encompassingRectangle extent.
     PNGReadWriter
          putForm: completeMorph imageForm
          onFileNamed: self fileName

Any idea why?

Reported by tudor@tudorgirba.com on 2014-10-12 22:09:02

@seandenigris
Copy link
Contributor Author

How do I render an existing trachel shape on an Athens surface?

Reported by tudor@tudorgirba.com on 2014-10-12 22:09:44

@seandenigris
Copy link
Contributor Author

Here is a script that Alex put together. It almost work, but we still need to extract
the logic from TRMorph. Also, there still is a problem with the logic as the picture
is shifted to the right.

b := RTMondrianViewBuilder new.
b shape rectangle 
   withBorder;
   width: [ :cls | cls numberOfVariables * 5];
   height: #numberOfMethods;
   linearFillColor: #numberOfLinesOfCode within: RTObject withAllSubclasses.
b nodes: RTObject withAllSubclasses.
b edgesFrom: #superclass.
b treeLayout.
b build.

form := FormCanvas extent: (b view canvas encompassingRectangle) extent.
m := TRMorph new.
m canvas: b view canvas.
m extent: (b view canvas encompassingRectangle) extent.
m createSurface.
m drawOn: form.
m surface writeToPng: 'foo.png'

Reported by tudor@tudorgirba.com on 2014-11-12 13:06:59

@seandenigris
Copy link
Contributor Author

Can anyone else look at this?

Reported by tudor@tudorgirba.com on 2014-11-12 13:07:14

@seandenigris
Copy link
Contributor Author

Here is a standalone script that seems to almost works. There is still seems to be a
problem with one pixel at the bottom and to the right that gets cut.

b := RTMondrianViewBuilder new.
b shape rectangle 
   withBorder;
   width: [ :cls | cls numberOfVariables * 5];
   height: #numberOfMethods;
   linearFillColor: #numberOfLinesOfCode within: RTObject withAllSubclasses.
b nodes: RTObject withAllSubclasses.
b edgesFrom: #superclass.
b treeLayout.
b build.

trachelCanvas := b view canvas.
form := FormCanvas extent: (trachelCanvas encompassingRectangle) extent.
session := Smalltalk session.
surface := AthensCairoSurface extent: (trachelCanvas encompassingRectangle extent)
asIntegerPoint.
form fillRectangle: trachelCanvas encompassingRectangle color: trachelCanvas color.
"The drawing has to be done when a change in the shapes occured or when there is an
animation."
surface drawDuring: [:cs |
    surface clear.
    "We display the elements that are subject to the camera"
    trachelCanvas shapes do: [ :trachelShape |
        trachelShape drawOn: cs.
    ].
    "We display the elements that are _NOT_ subject to the camera"
    trachelCanvas fixedShapes do: [ :trachelShape |
        trachelShape drawOn: cs.
    ].
].
"aCanvas translucentImage: surface asForm at: self bounds origin."
"asForm creates a new Form, which is likely to be expensive. This can be cached"
form image: surface asForm at: trachelCanvas encompassingRectangle origin sourceRect:
(0 @ 0 extent: surface extent) rule: 34.
surface writeToPng: 'foo.png'

Reported by tudor@tudorgirba.com on 2014-11-12 13:27:05

@seandenigris
Copy link
Contributor Author

I integrated this in RTPNGExporter, but we still have the one pixel problem.

Reported by tudor@tudorgirba.com on 2014-11-12 13:52:51

@seandenigris
Copy link
Contributor Author

I've tried this and it looks okay (simply adding 10 @ 10 to the extent):

b := RTMondrianViewBuilder new.
b shape rectangle
  withBorder;
  width: [ :cls | cls numberOfVariables * 5];
  height: #numberOfMethods;
  linearFillColor: #numberOfLinesOfCode within: RTObject withAllSubclasses.
b nodes: RTObject withAllSubclasses.
b edgesFrom: #superclass.
b treeLayout.
b build.

trachelCanvas := b view canvas.
form := FormCanvas extent: (trachelCanvas encompassingRectangle) extent.
session := Smalltalk session.
surface := AthensCairoSurface extent: (trachelCanvas encompassingRectangle extent +
(10 @ 10)) asIntegerPoint.
form fillRectangle: (trachelCanvas encompassingRectangle expandBy: 10 @ 10) color:
trachelCanvas color.
"The drawing has to be done when a change in the shapes occured or when there is an
animation."
surface drawDuring: [:cs |
    surface clear.
    "We display the elements that are subject to the camera"
    trachelCanvas shapes do: [ :trachelShape |
        trachelShape drawOn: cs.
    ].
    "We display the elements that are _NOT_ subject to the camera"
    trachelCanvas fixedShapes do: [ :trachelShape |
        trachelShape drawOn: cs.
    ].
].
"aCanvas translucentImage: surface asForm at: self bounds origin."
"asForm creates a new Form, which is likely to be expensive. This can be cached"
form image: surface asForm at: trachelCanvas encompassingRectangle origin sourceRect:
(0 @ 0 extent: surface extent) rule: 34.
surface writeToPng: '/tmp/foo.png'

Reported by alexandre.bergel on 2014-11-12 14:02:33

@seandenigris
Copy link
Contributor Author

How is adding 10@10 a solution?

1. asIntegerPoint rounds down.
2. encompassingRectangle does not take the strokewidth into account.

Reported by nicolaihess on 2014-11-12 22:46:07

@seandenigris
Copy link
Contributor Author

Other observiations:

- file chooser dialog has "Your title here" as title.
- cancel file chooser dialog -> MessageNotUnderstood: receiver of ""fullName"" is nil

Reported by nicolaihess on 2014-11-13 11:25:55

@seandenigris
Copy link
Contributor Author

@Nicolai: Thanks for finding the issues. They are fixed now.

@Alex: Looks great. Thanks!

Reported by tudor@tudorgirba.com on 2014-11-13 21:09:59

  • Status changed: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant