sample #11
reading svg file
  1. <?php
  2. include("sample_utils.php"); // provides some utils and using mk
  3.  
  4. //$svgFN = "linuxtag.svg"; // various svg to try...
  5. //$svgFN = "sample01.svg"; //
  6. //$svgFN = "vgai01.svg"; //
  7. //$svgFN = "tux.svg"; //
  8. //$svgFN = "tiger.svg"; //
  9. $svgFN = "three_hearts.svg"; //
  10. //$svgFN = "powerpuff01.svg"; //
  11. //$svgFN = "picasso_woman_vect01.svg"; //
  12. //$svgFN = "pclinux.svg"; //
  13.  
  14. $sv = new MKsimple_svg_reader($svgFN);
  15. $wd = $sv->get_svgWidth(); // get svg width
  16. $hg = $sv->get_svgHeight(); // get svg height
  17. $sd = $sv->update_tagData(); // get tag data
  18. $po = $sv->update_place_tagData(); // get placing data
  19.  
  20. $swf = new MKswf("test_svg01.swf"); // start a fresh swf
  21. $swf->set_swfDir(SERVER_MKTMP); // change default working dir
  22. $swf->set_stageWidth($wd); // set stage dimensions
  23. $swf->set_stageHeight($hg); //
  24.  
  25. $swf->add_tagData($sd); // populate with shape
  26. $swf->add_tagData($po); // place on stage
  27. $swf->swf_output(); // save to disk
  28.  
  29. $swfHeader = $swf->fetch_assoc();
  30.  
  31. $str = render_swf_box($swfHeader, $imgDir, false);
  32. $str .= "<br/><strong>test_svg01.swf created in" .SERVER_MKTMP ."</strong></td></tr>";
  33. echo show_content($str, basename(__FILE__));
  34. ?>

Earlier snapshot releases had a little svg support to let drawing with a graphic package such inkscape and make some kind of conversion.
The good news is a consistent svg handling improvement, you can see some working samples, complex svg drawings taken from various internet resources such open clipart gallery and inkscape samples.
Now mk supports most basic drawing commands, transformations and linear/radial gradient fills. I'd like to think svg means: simple vector graphics, but unfortunately it is not! S is for scalable...
Svg is an xml dialect that can reach an high level of complexity, it supports scripting and animation, it can contain linked resources and get the same result in various ways.
In most cases if you need to convert svg to swf you have to accommodate your svg following this simple rules:

  1. use inkscape, it's open source and offer a good svg support
  2. use px measure unit, it is better to choose document format near to swf stage
  3. even if groups are supported, it is suggested to ungroup all object
  4. try to transform all object to path
  5. convert text to path
  6. don't use stroke gradients (they will be implemented, but you have to know that advanced stroke definition is supported only from flash 8), you can convert a stroke to a path in inkscape

svg radial gradients have focal points that they are available only in flash 8. In the near future I will add such interesting thing. Scripting, animation and linked resources are not planned to be supported. The main goal of svg support is to give a way to create vector content to insert later in swf that will be handled by actionscript, or simply used as static visual content.

Sometimes svg conversion it's a piece of cake, sometimes it's an hell, there are some issue to fix, much test have to do.

Base xml support is given using xmllib, since mk don't use extensions by definition, I've made some little bug fixing e.g. in parsing attributes, but that library has to be considered not definitive, waiting for php6 mass support. That php version will support xml natively, php5 looks good but yet has not massive support.
I also made some few test using svg generated by illustrator, but it has to be simplified because that software tend to generate a large amount of complex data that mk can't handle properly.

mikrokosmos