<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kaizou &#187; SVG</title>
	<atom:link href="http://www.kaizou.org/tag/svg/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kaizou.org</link>
	<description>This is Web 2.71828</description>
	<lastBuildDate>Thu, 24 Nov 2011 09:34:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Inline SVG Fallback</title>
		<link>http://www.kaizou.org/2009/03/inline-svg-fallback/</link>
		<comments>http://www.kaizou.org/2009/03/inline-svg-fallback/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 13:07:15 +0000</pubDate>
		<dc:creator>David Corvoysier</dc:creator>
				<category><![CDATA[SVG]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[inline]]></category>

		<guid isPermaLink="false">http://www.kaizou.org/?p=178</guid>
		<description><![CDATA[As you may already know, IE doesn&#8217;t support SVG unless you install a plugin like the ASV, that is unfortunately not supported anymore by Adobe. As a web developer willing to use inline SVG, your best bet is thus to provide fallback mechanisms to display IE visitors at least a degraded version of what you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>As you may already know, IE doesn&#8217;t support SVG unless you install a plugin like the ASV, that is unfortunately not supported anymore by Adobe.</p>
<p>As a web developer willing to use inline SVG, your best bet is thus to provide fallback mechanisms to display IE visitors at least a degraded version of what you&#8217;re trying to express/demonstrate, and teach them what they&#8217;re missing by sticking with evil IE.</p>
<p>Luckily, IE will simply ignore any markup it does&#8217;nt know, so you usually don&#8217;t need to bother masking or removing the SVG markup when serving pages to your IE visitors.</p>
<p>This is however not true if you insert plain text if your SVG &#8230; Let&#8217;s take an example.</p>
<p>When you insert the following SVG in your page:</p>
<pre>
<code>&lt;svg xmlns="http://www.w3.org/2000/svg"
       version="1.1" wiewBox="0 0 200 100"&gt;
   &lt;text x="0" y="0"
         font-family="Verdana"
	 font-size="55" fill="blue" &gt;
        Hello, out there
   &lt;/text&gt;
&lt;/svg&gt;</code>
</pre>
<p>IE will ignore all SVG markup and formatting, and actually display the plain text with the current style:</p>
<p>Hello, out there</p>
<p>Now, what happens when you insert HTML markup inside your SVG using the <code>foreignObject</code> tag ?</p>
<pre>
<code>&lt;svg xmlns="http://www.w3.org/2000/svg"
       version="1.1" wiewBox="0 0 200 100"&gt;
   &lt;foreignObject width="200" height="100"&gt;
      &lt;span style="color:blue;"&gt;
        Hello, out there
      &lt;/span&gt;
   &lt;/foreignObject&gt;
&lt;/svg&gt;</code>
</pre>
<p>Well, IE ignores all SVG and displays only the HTML markup embedded in the <code>foreignObject</code> tag:</p>
<p><span style="color:blue;">Hello, out there</span></p>
<p>Based on this behavior, the guys at <a href="http://shepherd-interactive.com/" alt="Sheperd interactive">Sheperd interactive</a> have imagined a very elegant <a href="http://shepherd-interactive.com/#about-us/blog/2008/12/inline-svg-fallback/" alt="inline SVG fallback">inline SVG fallback</a> mechanism that uses <a href="http://www.w3.org/TR/SVG/struct.html#ConditionalProcessing" alt="SVG conditional processing">SVG conditional processing</a>.</p>
<p>In a nutshell, the actual SVG and the IE fallback are embedded in an SVG <code>switch</code>:</p>
<ul>
<li>SVG aware browsers will recognize the conditional directive, and render the first alternative they understand (the actual SVG), ignoring the other (the IE fallback)</li>
<li>IE will silently ignore all SVG markup (including the conditional directive), and go straight to the fallback written in HTML.</li>
</ul>
<p>In the example, below, SVG-aware browsers will display a red circle, and IE a simple text.</p>
<pre>
<code>&lt;svg xmlns="http://www.w3.org/2000/svg"
        version="1.1" wiewBox="0 0 200 100"&gt;
  &lt;switch&gt;
     &lt;circle cx="150px" cy="100px" r="50px"
               fill="#ff0000" stroke="#000000"
               stroke-width="5px"/&gt;
     &lt;foreignObject width="200" height="100"&gt;
        &lt;span style="color:red;"&gt;
          This is not a red circle
        &lt;/span&gt;
     &lt;/foreignObject&gt;
   &lt;/switch&gt;
&lt;/svg&gt;</code>
</pre>
<p>See the actual rendering below:</p>
<p><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="300px" height="200px"><switch><circle cx="150px" cy="100px" r="50px" fill="#ff0000" stroke="#000000" stroke-width="5px"/><foreignObject width="200" height="100"><span style="color:red;">This is not a red circle</span></foreignObject></switch></svg></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kaizou.org/2009/03/inline-svg-fallback/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SVG inline in (X)HTML</title>
		<link>http://www.kaizou.org/2009/02/svg-inline-in-xhtml/</link>
		<comments>http://www.kaizou.org/2009/02/svg-inline-in-xhtml/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 18:40:12 +0000</pubDate>
		<dc:creator>David Corvoysier</dc:creator>
				<category><![CDATA[SVG]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[inline]]></category>

		<guid isPermaLink="false">http://www.kaizou.org/?p=47</guid>
		<description><![CDATA[SVG is now supported by all web browsers except IE. Opera has the best SVG support, but Safari and Firefox are not far behind. I think it is now time to take advantage of the powerful SVG features. What does SVG add to the web developer toolkit ? Well, as its names indicates, SVG first [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.w3.org/Graphics/SVG/About.html">SVG</a> is now supported by all web browsers except IE. <a href="http://www.opera.com/">Opera</a> has the best SVG support, but <a href="http://www.apple.com/safari/">Safari</a> and <a href="http://www.mozilla.org/firefox/">Firefox</a> are not far behind. I think it is now time to take advantage of the powerful SVG features.</p>
<p>What does SVG add to the web developer toolkit ?</p>
<p>Well, as its names indicates, SVG first provides a simple syntax to draw shapes that scale: it is thus particularly handy to draw screen layouts and buttons. I see some people starting to get interested &#8230;</p>
<p>But wait: SVG also includes a wide range of gradient, opacity and geometric transformations that can be applied not only to native SVG shapes, but also to images. This give you access to many fancy effects very hard to achieve with HTML alone, like for instance image reflection or fading.</p>
<p>Want more ? Check this out: SVG markup can be modified dynamically using javascript, allowing you to actually animate it. Who said cover-flow at the back of the class ?</p>
<p>Animation through javascript sucks on low-end devices ? Well, SVG also includes native animation capabilities (unfortunately only supported today by Opera).</p>
<p>Fair enough, but the whole web is built on top of HTML, and switching to full SVG is definitely an option.</p>
<p>Well, the cherry on the cake is that you don&#8217;t have to: SVG can be inserted inline into XHTML. How powerful that is ?</p>
<p>You will find detailed information on why and how it works on the <a href="http://wiki.svg.org/Inline_SVG">SVG wiki</a>. A method to have inline SVG supported by IE using the <a href="http://www.adobe.com/svg/viewer/install/main.html">Adobe SVG viewer</a> is also provided.</p>
<p>Here is an overview of what you need to do.</p>
<ul>
<li>First, you need to use XHTML, because plain old HTML doesn&#8217;t support being extended by another markup language, and your SVG markup will be ignored by the browsers.</li>
<li>Second, you need to make sure that the SVG-aware browsers know this is XHTML, by delivering your content to them as application/xhtml+xml. You probably nevertheless still want to deliver your content to IE as text/html, so what you need is conditional mime-types based on the Accept header of the user agent.
<ul>
<li>it can be done at the HTTP server level. See example below for apache (example taken from the SVG wiki):
<pre>
<code>AddType text/html .xhtml
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0
RewriteCond %{REQUEST_URI} \.xhtml$
RewriteCond %{THE_REQUEST} HTTP/1\.1
RewriteRule .* - [T=application/xhtml+xml]</code>
</pre>
</li>
<li>If you don&#8217;t have access to your web server configuration, you can still:
<ul>
<li>modify headers on the fly. See an example for PHP below:
<pre>
<code>if(preg_match("|application/xhtml\+xml|i",$_SERVER["HTTP_ACCEPT"]){
  header("Content-Type: application/xhtml+xml");
}</code>
</pre>
</li>
<li>or insert meta tags in the HTML head to specify the proper mime-type. See another example for PHP:
<pre>
<code>if(preg_match("|application/xhtml\+xml|i",$_SERVER["HTTP_ACCEPT"]){
  echo "&lt;meta http-equiv='Content-Type' content='application/xhtml+xml' /&gt;" ;
}</code>
</pre>
</li>
<li>If you use <a href="http://wordpress.org">WordPress</a>, the simpliest way is to use the <a href="http://m0n5t3r.info/work/wordpress-plugins/content-negotiation/">Content-Negotiation</a> plugin</li>
</ul>
</li>
</ul>
</li>
<li>Third, put your SVG under an SVG tag</li>
<pre>
<code>&lt;div id="myDIV"&gt;
    &lt;svg xmlns="http://www.w3.org/2000/svg" version="1.1"
	 xmlns:xlink="http://www.w3.org/1999/xlink"
	 viewBox="0 0 400 50"
	 id="myDIVBG"&gt;
	    &lt;defs&gt;
	      &lt;linearGradient id="myGrad"&gt;
		&lt;stop style="stop-color:#ff5b06;"
                        offset="0" /&gt;
		&lt;stop style="stop-color:#ffb11a;"
                        offset="1" /&gt;
	      &lt;/linearGradient&gt;
	    &lt;/defs&gt;
	    &lt;rect style="fill:url(#myGrad);"
	       width="400" height="50"
               x="0" y="0" rx="10" ry="10" /&gt;
    &lt;/svg&gt;
    <span>HTML Text with SVG background</span>
&lt;/div&gt;</code>
</pre>
<li>Fourth, style your SVG with CSS</li>
<pre>
<code>&lt;style type="text/css"&gt;
#myDIV {
    position:relative;
    width:400px;
    height:50px;
}
#myDIV svg {
    position:absolute;
}
#myDIV svg:hover rect {
    fill: red !important;
}
#myDIV span {
    position:absolute;
    top:15px;
    left:40px;
    font-size: 16px;
    font-weight: bold;
}
&lt;/style&gt;</code>
</pre>
</ul>
<p>The result should look like this:</p>
<style type="text/css">
#myDIV {position:relative;width:400px;height:50px;}
#myDIV svg {position:absolute;}
#myDIV svg:hover rect {fill: red !important;}
#myDIV span {position:absolute;top:15px;left:40px;font-size: 16px;font-weight: bold;}
</style>
<div id="myDIV"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 400 50"><defs>
<linearGradient id="myGrad"><stop style="stop-color: #ff5b06;stop-opacity:1" offset="0"/><stop style="stop-color: #ffb11a;stop-opacity:1" offset="1"/></linearGradient></defs><rect style="fill: url(#myGrad);" width="400px" height="50px" rx="10" ry="10"/></svg><span>HTML Text with SVG background</span></div>
<p>Please note in particular how the CSS styling allows the SVG to be perfectly integrated in the page:</p>
<ul>
<li>the absolute positioning of the svg root element allows the next-coming HTML span to appear on top of the SVG background</li>
<li>the :hover behaviour allows a dynamic update of the SVG rect element fill attribute when the element is moused over</li>
</ul>
<p>You will find more examples below:</p>
<ul>
<li><a href="https://developer.mozilla.org/en/SVG_In_HTML_Introduction">A form with an SVG background at Mozilla&#8217;s</a>,</li>
<li><a href="http://jwatt.org/svg/demos/xhtml-with-inline-svg.xhtml">A simple proof of concept</a></li>
</ul>
<p>UPDATE(2010): You can now inline SVG directly in HTML in most modern browsers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kaizou.org/2009/02/svg-inline-in-xhtml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

