Implementing an SVG input module The vector graphic Migration on Request tool currently supports the input of Draw and WMF formats, and the output of Draw, WMF and SVG formats. An SVG input module would allow more reversible migration tests to be performed. What is needed? There are three targets to meet in order to integrate an SVG input module into the Migration on Request tool.
Parsing SVG documents According to the W3C documentation: "In a Conforming SVG Interpreter, the XML parser must be able to parse and process all XML constructs ... complete support for the XML 1.0 specification ... complete support for inclusion of non-SVG namespaces within SVG content". In order to provide a thorough and correct implementation of SVG input, an XML parser is required. This would have to be written with software longevity in mind; for example using C--. There are a number of approaches that could be taken:
Using/adapting an existing XML parser Using an existing library might be possible although this would sacrifice the C-- aspects. Libxml, the gnu/gnome tool, is open source and written in C, which makes it suitable. If an existing library is used it could be hidden behind wrapper functions, so that it could be replaced with a home-grown C-- version at a later date without having to modify any input modules. Implementing and using an SVG parser A proper XML parser would be a large amount of work, if implemented from scratch. It would, however, be useful in the future if other XML formats are to be incorporated into the tool. Most of the structure of an SVG file is reasonably accessable. If the tool were limited to interpreting simple files with simple methods of styling (ie, specified as attributes of each element) there would be few problems. However, there are more complicated issues to consider:
Storing this sort of information in a portable, cross-format, preservable way, would require a lot of work. It was easier to lose some features of WMFs (such as the create/select/delete object model for attributes), and a similar approach could be taken with these tricky SVG elements. It is not an impossible task to build into the tool a 'definitions' structure, which can represent rules and instructions such as those above. With enough detail this might allow reversible migration. A simplified SVG parser Looking at the example files provided with the SVG recommendation documents, such as this one:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="12cm" height="4cm" viewBox="0 0 1200 400"
xmlns="http://www.w3.org/2000/svg">
<desc>Example rect01 - rectangle with sharp corners</desc>
<!-- Show outline of canvas using 'rect' element -->
<rect x="1" y="1" width="1198" height="398"
fill="none" stroke="blue" stroke-width="2"/>
<rect x="400" y="100" width="400" height="200"
fill="yellow" stroke="navy" stroke-width="10" />
</svg>
it seems that a 'simplified' interpreter could be written. This wouldn't use the DTD to interpet the file, instead the SVG definition would be hardwired into the code. This is obviously much more limiting, but would be easier in the short term. Many SVG files may be unreadable using a simplified interpreter. An examination of SVG files exported from applications in use (such as Corel Draw or Adobe Illustrator) could identify commonly used features of the format. This could be used to specify what should be supported by the simplified interpreter. Additional features could be added in the future. Conclusion Implementing an SVG input module would be possible, but labour intensive. A specialised SVG interpreter may be easier to develop in the short term, but a full XML parser would be more useful for implementing additional formats and migration tools. However, the time spent in development could be saved by using an existing open source XML parser. Further reading
|
||||||||||||||||||||||||||||||||||||||||||||||