Resources in Inkscape
I’ve been poking at making Inkscape’s key bindings configurable for a while; as of several weeks ago, I’ve actually got the keyboard shortcut code reading its settings from an XML document stored as a string constant.
That means we’re only a hair away from the real thing—we just need a way to specify an XML file to read settings from, and a bit of corresponding UI in the preferences dialog.
Now, the way I’d like to do this (internally) is to use IRIs. In general, the way we reference resources in Inkscape has been an ad-hoc mixture of native file paths in the native encoding (though Jon Cruz has cleaned that up mostly), native file paths in UTF-8, URLs, and “URI” strings which are actually IRIs in UTF-8.
If you’re feeling a bit lost in all this acronym soup, here’s a quick taxonomy:
- IRI – “Internationalized Resource Identifier” – Unicode resource identifiers; they are just URIs generalized to Unicode
- URI – “Uniform Resource Identifier” – limited to US-ASCII
- URL – “Uniform Resource Locator” – URIs which can be used to directly locate a resource. May overlap with the general sense of URN.
- URN – “Uniform Resource Name” – In the general sense, URIs which name resources as well as locating them. In the specific sense, URIs which provide absolutely permanent, globally-unique names for resources, but (necessarily) don’t directly specify resource locations; they normally start with the
urn:prefix
IRIs can be converted to URIs by taking their UTF-8 representation and percent-escaping it; the process is idempotent and reversible. Note that SVG (as of 1.1, at least) uses URIs, not IRIs.
IRIs/URIs have some big advantages over native file paths, including a standard path separator, and well-defined portable semantics for relative paths. I would really like to start using IRIs universally in Inkscape; the ideal is that fopen_utf8() should very seldom get used directly.
Native file paths (e.g. from the file dialog) would simply be translated to file URIs at the earliest opportunity; for example, /home/mental/blah.svg -> file:///home/mental/blah.svg, or D:\Projects\Fremple Design\Artwork\eeek.svg -> file://d:/Projects/Fremple%20Design/Artwork/eeek.svg.
This would also let us introduce new schemes for naming resources in Inkscape which don’t involve manually pasting together string constants to form paths. For example, x-inkscape-resource:keys:illustrator. Behind the scenes, that might translate to something like file:///home/mental/.inkscape/keys/illustrator.keys or (perhaps if the first didn’t exist) file:///usr/share/inkscape/keys/illustrator.keys.
(Incidentally, the exact form for resource URIs, and the file extension for key mapping files aren’t set in stone—I’m open to suggestions.)
The actual APIs involved should probably be pretty straightforward, encompassing not much more than the following:
- IRIs
- Convert native paths to/from IRIs
- Convert IRIs to/from URIs (for SVG, mainly)
- Resolve IRI relative to another (if needed)
- Generate relative form of IRI versus another (if possible)
- Get resource from IRI
- Resources
- fopen resource (if possible)
- get resource MIME type
- get “canonical” IRI for resource
- enumerate IRIs of “child” resources (e.g. contents of a directory)
Anyway, I think this may be my weekend project for the next few weeks.