-
Notifications
You must be signed in to change notification settings - Fork 19
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
SVG support for Shoes #54
Comments
Shoes::SVG should allow reading data from a string rather than a file and render its content on screen. It would still be possible to load a file in any event, such as in the example below. Or, perhaps, it should check whether a file or a string is passed and load data accordingly. Shoes.app {
svg(File.read("bunny.svg"))
} |
What does svg(File.read("bunny.svg")) return? A bit map image like png and jpg or a new Shoes widget class with svg specific methods and event handling to be written in C and Objective C? |
This is something to think about. Ultimately it should become Shoes::SVG but we could implement the features incrementally for which the svg is rendered as a Shoes::Image, can be displayed, responds to normal image related methods. This should be easy to implement. The additional features can come as time goes. For now I only need to be able to render svg on screen anyway. This would avoid me a whole lot of troubles converting files for different configurations using external tools. This enhancement will allow me to simplify and streamline the production of commercial software based on Shoes. My very next project will use it. So it's not wishlist as in wishful thinking... |
The following will be required to add SVG support to Shoes: librsvg, libxml2, libcroco. These can be found on http://www.gtk.org/download/win32.php for Windows related libraries. The binaries should do fine and the PC files can be obtained from the source files. |
Shoes.svg method could have the following styles:
Equivalent methods may be considered for manipulating the svg at runtime. REFERENCES |
I've got a minor concern over libxml2. We already include an XML dll. Is there a choice of parsers when building libsvg from source? |
Expat XML (libexpat) is an overly outdated, slow and complicate library. Might not be alive anymore as the last update is in 2012. Is libexpat used anywhere in Shoes? It is mostly included in GTK+ Bundle to ride along and compatibility. So librsvg does not support libexpat. A good simple example how to use librsvg in Cairo: http://blog.mathieu-leplatre.info/static-build-of-cairo-and-librsvg.html |
I believe libexpat is used by our old friend, fontconfig to parse the font.conf file. |
The good news is that fontconfig can be configured to use libxml2 using |
An interesting experiment on Windows: removed libexpat-1.dll and ran cshoes.exe, checked manual and cobbler — working. |
There is no libexpat-1 on MacOS X and probably not on Linux. Recommended to remove this unused library on Windows. It would be a good idea to list and compare libraries on all platforms. |
@backorder - since I'm redoing the dependencies for OSX , now would be the time to add librsvg to Shoes 3.3. Glancing at the API https://developer.gnome.org/rsvg/2.37/ it seems like a Shoes API is reasonable - make a class out of rsvghandle with some property getters and setter and init with a filename. Add a few methods for the GIO and Cairo calls and ??. Would that be sufficient for your needs? |
One other note. libexpat is included in OSX 10.6 and 10.9 in /usr/lib/ and it is used by Shoes - attempts to build libxml w/o homebrew have failed so far. |
It sounds reasonable to me. Loading and displaying images, basic manipulations would be a great start. |
There is an existing rsvg gem (part of ruby-gnome project). I have no idea what it's api but it depends on Gtk so it should be understandable code. |
rvsg2 seems to have a decent implementation with frequent and recent contributions. I don't know how it would integrate with Shoes. My understanding is that it would be best to roll up our own to fully integrate to Shoes. What are your thoughts? https://github.com/ruby-gnome2/ruby-gnome2/tree/master/rsvg2 |
There is a problem. From 10.9, attempt to configure:
gdk-pixbuf is a show stopper if it can't be configured away. libxml can be done if one is very careful in osx. That's for the older librsvg-2.39.0. The Changelog for the very recent 2.40 says it won't work with gtk2 and ours Shoes/Windows version of Gtk3 isn't high enough. I haven't looked at libcroco yet. Just a warning that this may be hard to do or even impossible. |
Of course, for all I know, cocoa has the svg handling inside it and we really just need to create a native widget (for gtk and cocoa) that can handle what ever the Shoes API is. Quick google says cocoa/Shoes would need an svg/xml to core graphics importer & exporter. If true that's a lot of code to write and test so I would need some major help (aka some one else writes the code). |
There is a cocoa project https://github.com/SVGKit/SVGKit that is active although they say it might be broken for OSX. It's also huge. If I was doing this, I'd look into getting librsvg working w/o a gtk requirement. Shoes really can't handle a completely different imaging model (vector vs pixel) in a general purpose way. We can already create and svg from an image but loading an svg into image seems very unlikely. Loading into a new widget might be possible but its going to be a lot of work and I'm not inclined to do it. |
It would just need some kind of wrapper class in Shoes C-level code with basic functionalities. We can extend it as time goes, as need goes. As a side note, it would be great to have some kind of wiki article on how to extend Shoes with new features, what a new class requires to be fully accessible in Shoes, etc. |
Yes, a better description is needed in the wiki if only to help me remember how and where (app.h, app.h, ruby.h, ruby.c, plus a few others) I've almost got librsvg built on 10.9 but I am running into a problem with gobject-introspection versions building (some) but not working with librsvg. It turns out you can build gdk-pixbuf with out Gtk. |
Update: |
Windows is being a problem. Gobject-introspection won't cross compile because it tries to run linux python and there is confusion about which include files to use. That's during the configuration phase - a nasty place in autoconf to be mucking about. Of course I don't have python-dev on my Win7 system. The rsvg2 gem does install on Windows (prebuilt .so's) and it does use libsrvg inside so it can be built, somehow. The link above to prebuilt Windows dlls doesn't work as given but http://sourceforge.net/projects/ezwinports/files/ does have librsvg-2.40.1-2-w32-bin.zip which includes the dlls and headers but may create some version number mis-match for Shoes. A good place to start, though because the README.txt is very useful. |
Yes. There are many Shoes "style" things you do not want to do with an Svg. I'm OK with svg being the stray dog at the doorstep of Shoes consistency. I'm going to write some more scripts/samples to test and demonstrate all that code that is stubbed out. If someone figures out the ruby/nokogiri query for all groups/layers that returns a hash of ?that would be helpful. |
* samples/good-flip.rb ("tap') displays one card at a time * suffle button doesn't do anything yet
@ccoupe for the nokogiri search, this one works for me : require 'nokogiri'
Shoes.app width: 500 do
doc = File.open("#{DIR}/samples/paris.svg") { |f| Nokogiri::XML(f) }
ids = doc.css("g").each_with_object("") { |tag, str| str << tag["id"].inspect << "\n" }
para ids
end search for nodes "g", then get the attribute "id", i think it's possible to go directly to the id attribute still, we must find a way to filter the result adequately |
@passenger94 - we need a way to skip the |
yes ! ids = doc.css("g[id]")
def_ids = doc.css("defs g[id]")
groups = ids - def_ids
groups.each_with_object("") { |elem, str| str << elem.attributes["id"].value << "\n" } but that's not the end of the story .... |
I think we've discovered why librsvg2 doesn't have a similar C function. So, if you're going to work with groups you need to know the names before you start coding. bonded.svg is another card deck from Klondike and the code above doesn't work as well. I've modified samples/good-svgview.rb to do the nokogiri query so it isn't lost knowledge. I should probably file a bug about list box items size - too much vertical space. Try drawing the jokers in paris.svg - something is not right. |
* segfaults in rb_threads if closed from window adornment * use tap button to display next card * off by one errors are likely because it's demo hack * needs a real programmer
Ian's deck that I claimed is malformed, svg-cards.svg almost works. |
i'm aware of this, it's the reason why i created offset_x, offset_y methods. Unfortunately there is nothing we can do : the svg file has a problem and rsvglib fetch wrong dimensions : x,y, width and height have nonsense values for the jokers ... (i even upgraded librsvg to the latest 2.40.12) |
what is the problem ? did you mean the popup window is too big ? |
when clicking on the list box (gtk3) with a long list there is a lot of vertical white space between list items. At first, I thought it had extra `\n in the entries. It could be be my theme vs your theme. |
you mean gtk3, right ? svg branch is using gtk3 ? |
* plus other random clean ups for #54
we have 2 group? method now, one for svg_handle one for svg, is it intended ? what is the plan for save method ? is it useful as we don't modify the file/xml ? incidentally what about dpi, if we don't save to a file ? |
We don't need group? method for svghandle. That's the problem for me with creating API - you don't really know what you'll need until you start write the test scripts or an app. save() would be a lot like snapshot - render the svghandle to an svg/ps/pdf surface (ie file) and use the given dpi setting. I think that'ss what @backorder wanted. in the long discussion above. |
ok, so save() would be a way to convert an svg to a rasterized image ,say png, at some specified dpi ? |
export() is a better name. Like the code comment says, no one know what its supposed to do. I would not bother with it until every thing else is cleaned up and working. |
I agree with @ccoupe : export() makes more sense. Save() might be used later on, i.e. imagine saving a group into its own svg. |
* see samples/good-flip line 29. We don't have an Svg onscreen to query into. * edge case to be sure - or maybe not.
* good startup speed on slow platforms * good drawing speed * needs a clever thread to started from init_with_path that loads missing handles while the user clicks. - That would make it expert-cardflip.rb
Closing #54 for Shoes 3,3,0. If there are bug/enhancements please create a more specific report. |
Cairo supports SVG rendering through libRSVG.
https://wiki.gnome.org/action/show/Projects/LibRsvg?action=show&redirect=LibRsvg
From http://cairographics.org/examples/
The text was updated successfully, but these errors were encountered: