<?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>Reinventing Fire &#187; SVG 2</title>
	<atom:link href="http://schepers.cc/category/svg-2/feed" rel="self" type="application/rss+xml" />
	<link>http://schepers.cc</link>
	<description>Technology upside down and backwards</description>
	<lastBuildDate>Sun, 09 Oct 2011 19:47:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Pointers on Background of SVG Borders on Mutiny</title>
		<link>http://schepers.cc/css-in-svg</link>
		<comments>http://schepers.cc/css-in-svg#comments</comments>
		<pubDate>Sat, 21 Aug 2010 21:37:09 +0000</pubDate>
		<dc:creator>Schepers</dc:creator>
				<category><![CDATA[CDF]]></category>
		<category><![CDATA[Standards]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[SVG 2]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://schepers.cc/?p=340</guid>
		<description><![CDATA[<br/>With SVG being integrated more and more into HTML5, both included via &#60;object&#62; and &#60;img&#62; elements, and inline in the same document, some natural questions about SVG and CSS are receiving more focus. This includes box model questions like background and border, and pointer events. I&#8217;m interested in comments from the community on what direction [...]]]></description>
			<content:encoded><![CDATA[<br/><p>With SVG being integrated more and more into HTML5, both included via <code>&lt;object&gt;</code> and <code>&lt;img&gt;</code> elements, and inline in the same document, some <a href="http://lists.w3.org/Archives/Public/www-svg/2010Aug/thread.html#msg28">natural questions</a> about SVG and CSS are receiving more focus.  This includes box model questions like background and border, and pointer events.</p>
<p>I&#8217;m interested in comments from the community on what direction SVG should take.</p>
<p><span id="more-340"></span></p>
<p>It&#8217;s pretty clear that the intent of the SVG 1.1 spec was that the box-model CSS properties must not apply to any SVG elements.  In addition to what the spec states on the subject, my conversations with people who participated in the SVG WG at the time leave me with no doubt on the matter.</p>
<p>The question is, is that the behavior we want?  How hard or easy is it to change that in modern SVG+HTML+CSS implementations?  What is most useful and intuitive for content authors?</p>
<p>In my opinion, we could specify that some aspects of the box model apply without screwing with SVG&#8217;s coordinate-based positioning system.  Here are my initial thoughts on some specific properties:</p>
<h4>Borders</h4>
<p>A borders is different than a stroke.  An SVG element, including any graphical (<code>&lt;rect&gt;</code>, <code>&lt;circle&gt;</code>, <code>&lt;path&gt;</code>, etc.) or container element (<code>&lt;svg&gt;</code>, <code>&lt;g&gt;</code>) can have both a stroke (which conforms to the geometry) and a border (which conforms to the element&#8217;s bounding box).  A common use case is setting the graphics apart from other content, or doing mouseover highlights of an SVG element; for example, when I mouse over or focus a circle, it would be much nicer, and just as semantic, to simply have a CSS property draw a rectangle around that element as a highlight than for me to generate a rectangle based on the bbox and insert that into the DOM, keep a pointer to it, then remove it when I mouse out.</p>
<p>Paint servers and similar resources (gradients, filters, etc.) should not have any border.  Note: <code>&lt;defs&gt;</code> is a non-rendering element, akin to <code>&lt;head&gt;</code>, so no border would be visible for that either, but if the content of a <code>&lt;defs&gt;</code> is <code>&lt;use&gt;</code>d, any border properties would apply in the same manner as for other properties.</p>
<p>The border should not have any effect on the layout or rendering; it would be strictly visual.</p>
<h4>Margin</h4>
<p>No effect on SVG content, but may affect HTML content around that SVG content.  So, an <code>&lt;svg&gt;</code> element with <code>'margin: 20px;'</code>  has a 20-pixel gap around the SVG content, just as if it were <code>&lt;img style="margin: 20px;"/&gt;</code></p>
<p>Alternately, maybe margin only has an effect for <code>&lt;svg&gt;</code> elements; that might be simpler to specify, implement, and understand for content authors.</p>
<h4>Padding</h4>
<p>Again, this has no effect on SVG content, but it does affect how the border is drawn.  This would be a nice way to compensate for thick stroke widths.</p>
<h4>Background</h4>
<p>A background is different than a fill.  Background is much the same as border; it is a rectangle (modulo the border-radius effects) around the shape, based on its geometric bounding box, taking into account padding.</p>
<p>By default, there should be no background color, including for the <code>&lt;svg&gt;</code> element.  Right now, there is a <a href="https://lists.webkit.org/pipermail/webkit-unassigned/2009-July/120301.html ">WebKit bug in Chrome and Safari</a> which renders a white, non-transparent background for SVG fragments or documents; this is a major pain for any content creators trying to use SVG, much like the old Internet Explorer bug on transparency in PNGs.  I hope it receives some attention from the WebKit developers soon.</p>
<p>SVG Tiny 1.2 defines a <a href="http://www.w3.org/TR/SVGTiny12/painting.html#viewport-fill-property"><code>'viewport-fill'</code></a>  and <a href="http://www.w3.org/TR/SVGTiny12/painting.html#viewport-fill-opacity-property"><code>'viewport-fill-opacity'</code></a>.  I think those should be deprecated in favor of <code>'background'</code>  properties; I have no opinion on which should have precedence&#8230; maybe they should be seen as aliases of <code>'background'</code>, if that makes it simpler.</p>
<p>A background on SVG content raises the question of pointer events, which is also relevant to borders.</p>
<h4>Pointer Events</h4>
<p>Should pointer events on the border or background fire on the element itself?  I think that the default should be &#8220;no&#8221;, just to be safe and consistent with older SVG content, but I could easily be persuaded to reverse that.  Either way, there should be a new property or set of properties that can modify this, in a manner consistent with how CSS is defining <code>'pointer-events'</code>.</p>
<p>This touches on the question, asked in a related thread, on whether the <code>&lt;svg&gt;</code> element, by default, should be a proximal event target for pointer events.  My answer on that is a pretty firm &#8220;no&#8221;; if you want to have it as an event target, give it a background, or change the <code>'pointer-events'</code>  value.</p>
<h4>Questions</h4>
<p>A few high level questions:</p>
<ul>
<li><strong>Is this a change from SVG 1.1 and SVG Tiny 1.2?</strong>  Yes.</li>
<li><strong>Is this backwards compatible?</strong>  Kind of.  It introduces new behavior that is not consistent with past behavior, but doesn&#8217;t explicitly change very much.</li>
<li><strong>Does this break existing content?</strong>  Very doubtful.</li>
<li><strong>Is this intuitive for content authors?</strong>  My intuition says yes.</li>
<li><strong>Does this match existing implementations?</strong>  Some, at least.</li>
<li><strong>Does this provide value for content authors?</strong> Yes.</li>
<li><strong>Does this make it harder to implement?</strong>  I don&#8217;t know; I suspect it makes it easier for at least some implementations.</li>
<li><strong>Would defining this improve interoperability?</strong>  Yes.</li>
</ul>
<h4>Conclusion</h4>
<p>I propose we change SVG 2 to explicitly define this behavior.  As the editor of the HTML5 spec, <a href="http://lists.w3.org/Archives/Public/www-svg/2010Aug/0048.html">Hixie seems to imply</a> that this is not for HTML5 to define, and I tend to agree with that, though maybe some informative mention in the HTML5 or CSS specs for how SVG treats margins and padding might be appropriate.  We recently <a href="http://lists.w3.org/Archives/Public/public-cdf/2010Aug/0000.html">formally closed</a> the <a href="http://www.w3.org/2004/CDF/">Compound Document Formats Working Group</a>, which was formed to look at exactly these sorts of questions, and published its specifications as Working Group Notes for posterity; we wanted to be clear about its status.  The CDF WG succumbed to the politics around the reformation of the HTML WG, and probably to good effect overall; but in its absence, we still need to resolve these questions by cooperation between the various groups involved.</p>
<p>I don&#8217;t think this should be any different in standalone SVG files than in SVG files referenced or inlined in HTML.  That would be very unintuitive, in my opinion.</p>
<p>If this is not controversial, I would be happy to put any or all of this in the <a href="http://dev.w3.org/SVG/modules/integration/SVGIntegration.html">SVG Integration spec</a>, which is one of the foundations of SVG 2.  If someone disagrees with this, we&#8217;ll have to talk about it before I start editing the spec.  In either case, it would need to be fleshed out some&#8230; I&#8217;m probably glossing over some possible stumbling blocks in the box model, which I&#8217;d appreciate feedback on.</p>
<p>Please leave a comment if you like my suggestions, if you see a flaw, or have a better suggestion.</p>
<h4 id="update1">Update:</h4>
<p>Just to show what I&#8217;m talking about, I created a sample.  Here is a good example of a bad example; below are 3 instance of the same SVG with the same CSS background and border values, with a border width of 2px.  The first 2 are external files referenced as objects, the third is inline in the HTML (you won&#8217;t see this one unless you are using preview releases of Firefox 4, WebKit, or IE9); the second image also has a padding and margin of 10px.</p>
<p>I tested this in several browsers, and in the referenced cases, the border width increases the image size, spawning scrollbars; I don&#8217;t think that&#8217;s a good outcome&#8230; it should clip the border, just as it does for any graphical overflow&#8230; borders should not contribute to the geometry of SVG images.</p>
<p>In the second case, where I added padding, the argument is less clear, but I still believe that for referenced content, the border and background should not displace the rendered graphics, and should be clipped.  For inline content, it would make sense for the padding and margin to be visible in the rendered document, but it should still not change the geometry of the SVG.</p>
<p><object type="image/svg+xml" width="150" height="150" data="http://www.schepers.cc/svg/blendups/css/border-bg.svg">Please use a modern browser.</object></p>
<p><object type="image/svg+xml" width="150" height="150" data="http://www.schepers.cc/svg/blendups/css/border-bg-padding.svg">Please use a modern browser.</object></p>
<p><svg xmlns="http://www.w3.org/2000/svg" width="150" height="150" viewBox="0 0 50 50" style="border: 2px solid green; background-color: palegreen;"><circle cx="25" cy="25" r="20" fill="orange" stroke="red" style="border: 2px solid gold; background-color: yellow;"/></svg></p>
<p>We&#8217;d need to specify this in order for it to behave the same across browsers (and authoring tools).  So, do people agree or disagree with my conlcusions?</p>
]]></content:encoded>
			<wfw:commentRss>http://schepers.cc/css-in-svg/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Getting to the Point</title>
		<link>http://schepers.cc/getting-to-the-point</link>
		<comments>http://schepers.cc/getting-to-the-point#comments</comments>
		<pubDate>Tue, 13 Jul 2010 15:18:15 +0000</pubDate>
		<dc:creator>Schepers</dc:creator>
				<category><![CDATA[Standards]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[SVG 2]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://schepers.cc/?p=243</guid>
		<description><![CDATA[<br/>SVG paths have a pretty good set of shape commands, enough to let you draw any 2D shape you might want in an authoring tool: horizontal, vertical, and diagonal straight lines, elliptical arc segments, and cubic and quadratic Bézier curves. Béziers are great, giving you precise control over the position and curve interpolation of each [...]]]></description>
			<content:encoded><![CDATA[<br/><p>SVG paths have a pretty good set of shape commands, enough to let you draw any 2D shape you might want in an authoring tool:  horizontal, vertical, and diagonal straight lines, elliptical arc segments, and cubic and quadratic Bézier curves.  Béziers are great, giving you precise control over the position and curve interpolation of each point in a concise format, using control points (&#8220;handles&#8221;), and are easily chained together to create complex shapes.</p>
</p>
<p>But let&#8217;s say you have a series of points, and you want to draw a smooth line between them, e.g. for stock data, an audio wave, or a mathematical graphing equation.  Béziers are not as handy there, because not all the points needed to define a Bézier spline are on the curve itself.  Obviously, you can decompose any set of points into a set of Béziers, but that takes math, and who wants to do that?  (Put your hand down, nerd.  I&#8217;m talking to the normals.)</p>
</p>
<p>Sometimes, you just want to lay down a set of points, and let the browser draw a smooth curve (unlike polylines, where each segment is just a straight line between the points).  Like this:</p>
<p>  <object type="image/svg+xml" width="420" height="120" data="http://schepers.cc/svg/path/pathpoints.svg">Please use a modern browser.</object><br />
<span id="more-243"></span>
</p>
<p> Mouse over the line above to see the equivalent cubic Bézier points.  They are off the line. Off the line! Oh, Math, why do you do this to me?</p>
<p>One thing that&#8217;s always bothered me about SVG&#8230; there should be more simple ways of doing things, and this is one of things.  Over the years, I&#8217;ve idly asked math-minded folks about how to achieve this, and the answers always soared right over my pointy little head.  I probably didn&#8217;t ask the question the right way.</p>
</p>
<p>But a few months ago, I was chatting with Ben Fry, one of the creators of Processing (the graphics programming language), and he mentioned <a href="http://en.wikipedia.org/wiki/Catmull%E2%80%93Rom_spline#Catmull.E2.80.93Rom_spline" title="Cubic Hermite spline - Wikipedia, the free encyclopedia">Catmull-Rom curves</a> as a possible solution.  I took note of that, and later read up on them; they seemed a pretty good fit for my use case.  In my spare time I looked for any libraries out there to convert Catmull-Rom curves to Bézier splines; I found <a href="http://almightybuserror.com/2009/12/04/drawing-splines-in-opengl.html">references</a> that talked about the the conversion using inverted matrixes, but no simple code to be had.  I&#8217;m lazy, and busy, and the problem wasn&#8217;t urgent, so I kept putting it off.</p>
</p>
<p>But in talking to folks about SVG throughout the UK, including designers, the thought kept running through my mind that SVG really does need a better authoring experience (and I don&#8217;t just mean authoring tools, though some nice animation tools would help).  So, when I got back home from vacation, before I really got back into the thick of the dozen other things I should be doing, I put on some music and spent a few hours after work scouring the intartubes for some suitable code.  And as luck would have it, Maxim Shemanarev&#8217;s <a href="http://www.antigrain.com/__code/include/agg_curves.h.html">Anti-Grain Geometry</a> library contained a single simplified conversion matrix and a line of code that did the grunt work in C++, easily ported to Javascript; whip up a custom parser for the &lt;path&gt; syntax, feed it into the convertor function, and you&#8217;ve got yourself a working proof-of-concept.</p>
</p>
<p>Here is a scientific chart showing how awesome the SVG &lt;path&gt; element is, with values derived from the overall awesomeness by different path commands, rendered using an experimental Catmull-Rom path command:</p>
<p><object type="image/svg+xml" width="450" height="400" data="http://schepers.cc/svg/path/path-awesomeness.svg">Please use a modern browser.</object></p>
<p>As you can see, adding Catmull-Rom curves would increase the awesomeness of SVG paths by almost 50%.  That is a lot more awesome!</p>
</p>
<p>The syntax is pretty intuitive&#8230; it&#8217;s just the command &#8216;R&#8217; followed by a set of coordinate points:</p>
<pre><code>
  &lt;path stroke="#BADA55"
        stroke-width="2"
        fill="none"
        d="M20,380
           R58,342
           100,342
           100,300
           140,250
           190,210
           220,197
           250,184
           280,155
           310,260
           404,20"/&gt;
</code></pre>
<p>And the path syntax isn&#8217;t just used for the &#8216;d&#8217; attribute of &lt;path&gt; elements.  It&#8217;s also used for laying out text-paths, and the shapes of SVG Font glyphs.  And it&#8217;s used in animation, both for motion paths and (in the case of Béziers) for timing functions in the &#8216;keysplines&#8217; easing attribute that controls the rate of animation.  So, making it easier to hit specific points for paths could have side benefits for all those uses as well.</p>
</p>
<p>I&#8217;m really interested in feedback from others on the usefulness of this idea.  I&#8217;m not married to the idea of Catmull-Rom curves specifically (<i>Fun fact: Ed Catmull is now the president of the Walt Disney and Pixar animation studios; I believe Rom became an astronaut, was captured by aliens and turned into a cyborg, and is now a Spaceknight</i>), just in the idea of adding this type of point-on-the-path command.  So, if you support the notion of adding this in SVG 2, or have a better idea along the same lines, send an email to the SVG Working Group&#8217;s public list, <a href="mailto:www-svg@w3.org">www-svg@w3.org</a>, to let us know.</p>
<p>The <a href="http://schepers.cc/svg/path/catmullrom2bezier.js">javascript library</a> I wrote to demonstrate this is, of course, open source, available under the MIT or GPL licenses.  Feel free to play around with it, and improve it to make a better proposal.  You&#8217;re welcome to use it for other purposes, but I intended it just as a quick-and-dirty prototype to solicit feedback about extending SVG, so the code isn&#8217;t that great.</p>
<hr />
<h4 id="normals">Update 1:</h4>
<p><a href="http://xn--dahlstrm-t4a.net/">Erik Dahlström</a>, Chief Vectorizer at Opera and chair of the SVG WG, posted a <a href="http://schepers.cc/?p=243#comment-166">visual reply</a>, which WordPress filtered, but I&#8217;ve now <a href="http://schepers.cc/?p=243#comment-166">restored this inline</a>.  Nothing to see here, move along.</p>
<hr />
<h4 id="spiro">Update 2:</h4>
<p>Here is my Catmull-Rom code trying to achieve the nice curves of <a href="http://www.levien.com/spiro/">Spiro</a>, as suggested by Dave Crossland in <a href="http://schepers.cc/?p=243#comment-170">his comment</a>:<br />
<object type="image/svg+xml" width="485" height="277" data="http://schepers.cc/svg/path/spiro.svg">Please use a modern browser.</object></p>
<hr />
<h4 id="spiro-a">Update 3:</h4>
<p>Looking at Spiro curves a bit closer (just the image, not the code), it seems that there are actually different node types illustrated, not simply an undifferentiated set of coordinate points as in my interpretation of the Catmull-Rom algorithm.  This means that, from an syntax standpoint, those segments would need additional parameters in addition to the coordinate points on the curve, which somewhat undercuts the simplicity.</p>
<p>Given that SVG already has a &#8216;Lineto&#8217; command, I set out to see how closely I could match <a href="http://www.levien.com/spiro/spiro.png">the letter &#8220;a&#8221; in Raph Levien&#8217;s example</a>, using just my Catmull-Rom and Lineto segments, and with minimal effort:</p>
<p><object type="image/svg+xml" width="485" height="465" data="http://schepers.cc/svg/path/spiro-a.svg">Please use a modern browser.</object></p>
<p>Mouse over the raster image to hide the SVG path.  There are definite artifacts, and I am running into some known limitations of my script implementation in how it interpolates the last coordinate segment, but with not much effort, I was able to get pretty close.</p>
<p>This is not to belittle Spiro at all&#8230; Spiro generates <a href="http://fontly.com/sandbox/spiro.html">painfully elegant curves</a>.  It&#8217;s just to compare apples to apples.</p>
]]></content:encoded>
			<wfw:commentRss>http://schepers.cc/getting-to-the-point/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

