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

support for reftree #165

Open
MasseGuillaume opened this issue Apr 20, 2017 · 10 comments
Open

support for reftree #165

MasseGuillaume opened this issue Apr 20, 2017 · 10 comments

Comments

@MasseGuillaume
Copy link
Contributor

MasseGuillaume commented Apr 20, 2017

/cc @stanch

reftree is a really nice way to visualize data structures. it would be nice to use it in scastie.

85de620 adds graphviz to the docker container running the sbt instances. I only need to redeploy this change.

The scrimage demo (https://github.com/scalacenter/scastie/blob/master/demo/scrimage.scala#L1) shows how we can render an image in the jvm and send it back to the browser.

@MasseGuillaume
Copy link
Contributor Author

MasseGuillaume commented Apr 25, 2017

@stanch
Done.

https://scastie.scala-lang.org/MasseGuillaume/fNDpQ9AgRbKA4KEvP3NaeQ/1

I added a image(path: String) to the api to display images from the server using base64 encoding.

For some reason, animations throw an Exception.

2017-04-25-181414_3000x1920_scrot

@stanch
Copy link
Contributor

stanch commented Apr 25, 2017

Very cool! Let me see if I can run the docker container and dig around it to find the issue with animations. I guess it’s also time for me to stop relying on Consolas...

@MasseGuillaume
Copy link
Contributor Author

MasseGuillaume commented Apr 25, 2017

take a look at https://github.com/scalacenter/scastie/blob/master/CONTRIBUTING.md#contributing

cd docker
<edit Dockerfile>
docker build -t scalacenter/scastie-docker-sbt:0.0.14 .

<bump docker version>
https://github.com/scalacenter/scastie/blob/master/build.sbt#L122

sbt
> sbtRunner/reStart  or sbtRunner/docker then docker run --network=host scalacenter/scastie-sbt-runner:0.16.0
> ~server/reStart

@stanch
Copy link
Contributor

stanch commented Apr 27, 2017

So after about 2 hours of debugging I finally traced it to a problem with text rendering. Converting SVG to BufferedImage (which is what the animations do via Apache Batik), without text — fine; with text — crashes.

Searching for “java alpine linux text rendering” lead me into this thread: docker-library/openjdk#73 (comment). With -Dsun.java2d.debugfonts=true, here is what I got:

...
Apr 26, 2017 11:40:02 PM sun.font.SunFontManager findFont2D
INFO: Load fonts looking for:Lucida Sans Regular
java.lang.Exception: Stack trace
	at java.lang.Thread.dumpStack(Thread.java:1333)
	at sun.font.SunFontManager.loadFonts(SunFontManager.java:3298)
	at sun.awt.X11FontManager.loadFonts(X11FontManager.java:460)
	at sun.font.SunFontManager.findFont2D(SunFontManager.java:2348)
	at sun.font.SunFontManager.getDefaultPhysicalFont(SunFontManager.java:1220)
	at sun.font.SunFontManager.initialiseDeferredFont(SunFontManager.java:1100)
	at sun.font.SunFontManager.initialiseDeferredFonts(SunFontManager.java:927)
	at sun.font.SunFontManager.loadFonts(SunFontManager.java:3302)
	at sun.awt.X11FontManager.loadFonts(X11FontManager.java:460)
	at sun.font.SunFontManager.loadFontFiles(SunFontManager.java:3429)
	at sun.font.SunFontManager.getInstalledFontFamilyNames(SunFontManager.java:3766)
	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:225)
	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:252)
	at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:94)
	at org.apache.batik.bridge.DefaultFontFamilyResolver.<clinit>(DefaultFontFamilyResolver.java:87)
...

I am happy to say that running apk add --update ttf-dejavu like suggested in the linked comment completely solved the problem. Additionally for pretty rendering I would be grateful if you could add the Source Code Pro font, which is the new default font in reftree, replacing proprietary Consolas.

I will send a PR with these changes.

@MasseGuillaume
Copy link
Contributor Author

Diagram:
https://scastie.scala-lang.org/zzQ4rnCFRVKQUqQjM7n0AA

Animation:
https://scastie.scala-lang.org/8oZtpMStRduxM2PfphZsfA

The animation shows as a static image.
ImageIO.read does no read the gif: https://github.com/scalacenter/scastie/blob/master/runtime-scala/jvm/src/main/scala/com.olegych.scastie.api.runtime/Runtime.scala#L17
This could solve the issue: http://elliot.kroo.net/software/java/GifSequenceWriter/

also

You can add additional bogus fields to the data url to force replaying of the animated gif:
url(data:image/gif;bogus:ABCDEF;base64,R0lGODlhA...);
see http://stackoverflow.com/a/12228790/449071

@stanch
Copy link
Contributor

stanch commented May 17, 2017

This could solve the issue: http://elliot.kroo.net/software/java/GifSequenceWriter/

Not sure I understand, doesn’t the problem have to do with the reader? Also scrimage already has a class like that, I am using it to generate those gifs ;)

@MasseGuillaume
Copy link
Contributor Author

ImageIO does not read the animation part of the gif.

basically what we need is to read the gif data and convert it to base64 so it can be sent to the client.

@stanch
Copy link
Contributor

stanch commented May 17, 2017

Actually I am not sure if ImageIO is really needed :) base64 encoding can be done on the file itself (and the MIME type can be derived from the file extension). Image width can be left unspecified or set to some percentage of the screen... (or it can be calculated with ImageIO just like it is now, that should work for animations as well).

@stanch
Copy link
Contributor

stanch commented Sep 28, 2017

Since this is closed, should I open a new issue for correct rendering of non-PNG images?

Edit: I meant animated images, or anything else not fully supported by ImageIO.

@MasseGuillaume
Copy link
Contributor Author

Oh indeed this was still pending. Reopening this issue.

mlachkar pushed a commit that referenced this issue Jan 12, 2021
@vincenzobaz vincenzobaz added the ui label Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants