APSIMInitiative / ApsimX

ApsimX is the next generation of APSIM
http://www.apsim.info
Other
140 stars 168 forks source link

Curly braces not appearing in summary file Script listings. #106

Closed zur003 closed 9 years ago

zur003 commented 9 years ago

The HTML to RTF conversions now being used for generation and display of the Summary has some flaws. Specifically, "curly braces" are not appearing in the text, which is a problem with manager scripts. Also, it should be possible (I think) to convert the HTML tables to RTF tables. This should enhance readability.

hol353 commented 9 years ago

Yes, the HTML to rtf is pretty crude. Would be good to get table support. Should be possible. Are you volunteering? I certainly don't have the time in the next few months.

zur003 commented 9 years ago

I'd like to clean up the Summary display, and make it prettier, but I'm not sure what will be the best way to proceed. The current text is generated as HTML, then converted to RTF for display in a RichTextBox control. Some options are: 1) Improve the conversion code, at least to the point of handling tables more intelligently. 2) Use HTMLRenderer (http://htmlrenderer.codeplex.com - it appears to provide cross-platform support) to display the HTML. 3) Rewrite the generation code to use the MigraDoc part of PDFSharp to generate documents based on their object model, rather than HTML, and generate RTF or PDF from that for display.

I'm currently leaning toward the second option, though I'd like to see how well things render under Mono before taking it too far.

hol353 commented 9 years ago

Yes it would be good to clean up the summary file! HTMLRenderer looks good.Option 3 would have the benefit of not needing yet another third party library although that doesn't really matter these days.

zur003 commented 9 years ago

Sigh. I've wasted more time than I'd like to admit trying to get this to behave nicely, but haven't found a real solution. Here are the various paths I've trod, listed here so that those who follow can perhaps learn from my experience: I tried HTMLRenderer. It does a lovely job of displaying HTML,and works across platforms, but I think the rendering is much too slow for our needs here. For the rather long summary output from the Wheat example simulation, it took 30 seconds or so to display. That's not really acceptable in this context. Then I tried using the MigraDoc stuff to generate RTF. This was pretty easy to set up and use, but the results were disappointing - the tables looked dreadful, with text not wrapping correctly, colours not appearing, etc. I then tried using the PDF "previewer" in MigraDoc - it's appearance was OK, but, like HTMLRenderer, it took too long to render, and the scroll bars didn't seem to display properly (perhaps because PDF is a page-oriented format, but I was trying to effectively create a single very long page). I then went back to the RTF and discovered that the problem there wasn't with MigraDoc at all - the RTF it produces looks great if read into Word. The problem is with the RichEdit control that Microsoft defaults to in WinForms. It's apparently an old, poorly implemented version of the control (see http://stackoverflow.com/questions/1928853/why-isnt-the-richtextbox-displaying-this-table-properly). On Windows, it is possible to override the default and use a more up-to-date control that displays things properly, but I suspect this isn't an option for Mono/Linux (though I really should test the RichText controls on that platform and see what they do). So I'm not quite sure where to go from here. The RTF option almost works, but I need to see just how broken or not it is on Mono/Linux, and would require platform-specific code as a hack on Windows to load the newer version of the control. It would be nice to be able to use HTML for the formatting, but there are problems with handling this in a cross-platform way. There are .Net wrappers for embedding Gecko and Chromium, but they're likely to lead to headaches with distribution and installation. Neville's suggestion is to use HTML and not display it in GUI, but fire it off to the system for display in the user's default web browser. This has all been rather frustrating, as a lot of these approaches come close to working, but nothing really quite manages to do it all.

hol353 commented 9 years ago

Yes this sounds frustrating! I had a similar experience some time ago before writing the awful HTML / RTF converter. Perhaps we just need to tidy the converter up and move on. I don't like the idea of opening the users browser to display the summary file - too slow.

zur003 commented 9 years ago

I've made a set of changes which use MigraDoc to generate RTF, and (on Windows only, so there's a small bit of conditional code) uses the newer version of the RichEdit control, if it's available. The results look OK on Windows, but not so nice on Ubuntu/Mono, where the RichEdit control is even more awful. I think eventually we may want to go to embedding one of the web browsers (i.e., Gecko, Chromium or WebKit), although this may complicate setting things up for distribution.