<?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>Cameron McCormack&#039;s blog</title>
	<atom:link href="http://mcc.id.au/feed" rel="self" type="application/rss+xml" />
	<link>http://mcc.id.au</link>
	<description>mcc.id.au</description>
	<lastBuildDate>Tue, 16 Dec 2014 04:10:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6.1</generator>
		<item>
		<title>Submission</title>
		<link>http://mcc.id.au/blog/2014/12/submission</link>
		<comments>http://mcc.id.au/blog/2014/12/submission#comments</comments>
		<pubDate>Tue, 16 Dec 2014 04:10:50 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=427</guid>
		<description><![CDATA[254 pages, eleven and a half years of my life. Now for the months-long wait for the examiners to review it.]]></description>
				<content:encoded><![CDATA[<p>254 pages, eleven and a half years of my life.</p>
<p><img src="/2014/submission.jpg" alt="Me submitting my thesis at the Monash Institute of Graduate Research office." width="1260" height="1085" style="width: 840px; height: 723.333px; border: 2px solid #444"></p>
<p><img src="/2014/thesis.jpg" alt="My thesis front cover: Authoring and Publishing Adaptive Diagrams." width="703" height="819" style="border: 2px solid #444"></p>
<p>Now for the months-long wait for the examiners to review it.</p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2014/12/submission/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Using LLDB to debug Gecko</title>
		<link>http://mcc.id.au/blog/2014/01/lldb-gecko</link>
		<comments>http://mcc.id.au/blog/2014/01/lldb-gecko#comments</comments>
		<pubDate>Tue, 21 Jan 2014 10:03:30 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=366</guid>
		<description><![CDATA[On OS X 10.9, the Xcode command line utilities package no longer includes GDB. Instead, LLDB – the debugger from the LLVM project – is the officially supported debugger. LLDB&#8217;s syntax is a little different from GDB&#8217;s, but it doesn&#8217;t take too long to get used to. The LLDB site has a handy table showing [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>On OS X 10.9, the Xcode command line utilities package no longer includes GDB.  Instead, <a href="http://lldb.llvm.org/" title="LLDB Homepage">LLDB</a> – the debugger from the LLVM project – is the officially supported debugger.  LLDB&#8217;s syntax is a little different from GDB&#8217;s, but it doesn&#8217;t take too long to get used to.  The LLDB site has <a href="http://lldb.llvm.org/lldb-gdb.html" title="GDB to LLDB Command Map">a handy table</a> showing the equivalent LLDB commands for a number of common GDB commands.</p>
<p>One barrier to switching, for me, was that I have a few GDB commands defined in my .gdbinit file that I use for debugging Firefox.  Most of my .gdbinit was cribbed from Boris Zbarsky&#8217;s a few years ago, but nowadays there is a .gdbinit file in the tree.  So over the last couple of days I&#8217;ve ported the commands over to a <a href="https://hg.mozilla.org/integration/mozilla-inbound/file/tip/.lldbinit">.lldbinit file in the tree</a>.</p>
<p>LLDB uses Python as its scripting language, and most of the commands that have been ported over are written in Python.  The .lldbinit file imports the <code>lldbutils</code> module, which lives in <a href="https://hg.mozilla.org/integration/mozilla-inbound/file/tip/python/lldbutils/">python/lldbutils/</a>.  The <a href="https://hg.mozilla.org/integration/mozilla-inbound/raw-file/tip/python/lldbutils/README.txt">README.txt</a> file in there documents all of the currently supported Gecko-specific functionality.</p>
<p>For example, the <code>prefcnt</code> command can be used to show the refcount of an object.  Unlike the one in .gdbinit, the LLDB version of this command can take an argument that is a reference to a refcounted object, a pointer to one or one of our smart pointers to one:</p>
<pre>(lldb) <b>p this</b>
(nsHTMLDocument *) $1 = 0x0000000116e9d800
(lldb) <b>prefcnt this</b>
20
(lldb) <b>p mDocumentURI</b>
(nsCOMPtr<nsIURI>) $3 = {
  mRawPtr = 0x0000000117163e50
}
(lldb) <b>prefcnt mDocumentURI</b>
11</pre>
<p>In addition to a few commands, I&#8217;ve added a couple of <em>type summaries</em> to begin with.  In LLDB, a type summary is a rule for how to display a value.  This is useful for types like our string types, where you otherwise have to bury in to find the right member variable to get the string out.  With the <code>nsAString</code> and <code>nsACString</code> type summaries, you can just print the string object and the string value in it will be shown.</p>
<pre>(lldb) <b>frame info</b>
frame #0: 0x000000010400cfea XUL`nsCSSParser::ParseProperty(this=0x00007fff5fbf5248, aPropID=eCSSProperty_margin_top, aPropValue=0x00007fff5fbf53f8, aSheetURI=0x0000000115ae8c00, aBaseURI=0x0000000115ae8c00, aSheetPrincipal=0x000000010ff9e040, aDeclaration=0x00000001826fd580, aChanged=0x00007fff5fbf5247, aIsImportant=false, aIsSVGMode=false) + 74 at nsCSSParser.cpp:12851
(lldb) <b>p aPropValue</b>
(const nsAString_internal) $16 = u"-25px"

(lldb) <b>p this</b>
(nsHTMLDocument *) $18 = 0x0000000115b56000
(lldb) <b>p mContentType</b>
(nsCString) $19 = {
  nsACString_internal = "text/html"
}</pre>
<p>LLDB also provides the ability to define <em>synthetic children</em> for a type, which are fake member variables.  They can be used to expose the elements of container data structures.  For example, synthetic children for <code>nsTArray</code> and friends now let you inspect the array as if it were a plain array type, instead of just seeing an <code>mHdr</code> member:</p>
<pre>(lldb) <b>frame info</b>
frame #0: 0x00000001043eb8a8 XUL`SVGTextFrame::DoGlyphPositioning(this=0x000000012f3f8778) + 248 at SVGTextFrame.cpp:4940
(lldb) <b>p charPositions</b>
(nsTArray&lt;nsPoint>) $5 = {
  [0] = {
    mozilla::gfx::BasePoint&lt;int, nsPoint> = {
      x = 0
      y = 816
    }
  }
  [1] = {
    mozilla::gfx::BasePoint&lt;int, nsPoint> = {
      x = 426
      y = 816
    }
  }
  [2] = {
    mozilla::gfx::BasePoint&lt;int, nsPoint> = {
      x = 906
      y = 816
    }
  }
}</pre>
<p>(The <code>nsPoint</code> type looks like it could do with type summary to make it more compact, though!)</p>
<h2>Loading the .lldbinit</h2>
<p>LLDB by default looks in two places to load a .lldbinit file: the current directory when you start it, and your home directory.  In addition to the .lldbinit in the root of the source tree (which is where I normally launch my debugger from), the build system puts stub .lldbinit files in your objdir, so that commands like <code>mach reftest --debugger=lldb</code> will pick it up, and next to the final firefox (or other application) binary, in case that&#8217;s where you start the debugger from.  These stub files just load the main .lldbinit.</p>
<p>So if you are running lldb yourself or through mach, you shouldn&#8217;t need to do anything extra to load the in-tree .lldbinit.</p>
<h2>Loading it in Xcode</h2>
<p>Although the .lldbinit file works fine in Xcode, there is unfortunately no way to add a project-specific .lldbinit file in Xcode that will get loaded automatically.  Probably the best approach is to load it from your ~/.lldbinit.  If you are happy with the Gecko debugging commands being available regardless of what you&#8217;re debugging with LLDB, then add these lines:</p>
<pre>script topsrcdir = "/path/to/a/mozilla/tree"
command source -s true "/path/to/a/mozilla/tree/.lldbinit"</pre>
<p>where &#8220;/path/to/a/mozilla/tree&#8221; is any checkout of mozilla-central you&#8217;re likely to keep up to date.  The <code>topsrcdir</code> Python variable is used to tell the in-tree .lldbinit where the <code>lldbutils</code> module can be found.</p>
<p>If instead you want to manually enable the commands within Xcode whenever you want to use them, you could make the <code>command source</code> an alias:</p>
<pre>script topsrcdir = "/path/to/a/mozilla/tree"
command alias gk command source -s true "/path/to/a/mozilla/tree/.lldbinit"</pre>
<p>and then you can type <code>gk</code> at the LLDB prompt in the Xcode debugger window to load it.</p>
<p>In addition to the Gecko debugging commands being available, type summaries and synthetic children will be used whereever values are shown in the Xcode interface, like the Variables panel of the Debug area or when mousing over variables in a source file while debugging.</p>
<p><img class="figure" src="http://mcc.id.au/2014/variables.png" width="367" height="216" alt="The Xcode Variables area showing a nsTextNode object with its type summary, the string value of the node."></p>
<p>See how the <code>mContent</code> of the <code>nsTextFrame</code>, which is an <code>nsTextNode</code>, has its type summary displayed next to its pointer value.</p>
<p><img class="figure" src="http://mcc.id.au/2014/synthetic.png" width="367" height="163" alt="The Xcode Variables area showing the elements of an nsTArray."></p>
<p>Here the elements of the <code>nsTArray&lt;nsPoint></code> are shown and can be expanded as if they were plain array elements.</p>
<h2>What&#8217;s available now?</h2>
<p>So far these commands are available:</p>
<ul>
<li><b>frametree</b> (<b>ft</b>), <b>frametreelimited</b> (<b>ftl</b>)<br />
  These commands dump out information about the layout frame tree.  The &#8220;limited&#8221; version dumps a subtree, rather than the tree for the whole document.</li>
<li><b>js</b><br />
  Prints a backtrace of the current JS stack.</li>
<li><b>prefcnt</b><br />
  Prints the refcount of a refcounted object.</li>
<li><b>pstate</b><br />
  Prints the state bits of an nsIFrame in symbolic form, rather than as a uint64_t <em>(once <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=960848" title="Bug 960848 - make nsFrameState an enum and consolidate all frame state bit definitions in a single preprocessed file">bug 960848</a> relands)</em>.</li>
<li><b>ptag</b><br />
  Prints the tag name of a given nsINode.</li>
</ul>
<p>These types have type summaries:</p>
<ul>
<li><b>nsAString</b>, <b>nsACString</b><br />
  Shows the contents of the string.</li>
<li><b>nsIAtom</b><br />
  Shows the atom&#8217;s string.</li>
<li><b>nsTextNode</b><br />
  Shows the text node&#8217;s string value.</li>
</ul>
<p>And the only type to have synthetic children so far is <code>nsTArray</code>, as mentioned above.</p>
<p>Check <a href="https://hg.mozilla.org/integration/mozilla-inbound/raw-file/tip/python/lldbutils/README.txt">the README file</a> for examples and more information.</p>
<h2>Let&#8217;s add more!</h2>
<p>If you have any GDB commands that you&#8217;d like to see ported over to LLDB, or have ideas for other useful commands and type summaries, <a href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&#038;component=General&#038;cc=cam@mcc.id.au">file a bug CCing me</a> and I&#8217;ll see what I can do!</p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2014/01/lldb-gecko/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Variables in Firefox 29</title>
		<link>http://mcc.id.au/blog/2013/12/variables</link>
		<comments>http://mcc.id.au/blog/2013/12/variables#comments</comments>
		<pubDate>Fri, 13 Dec 2013 23:39:35 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=308</guid>
		<description><![CDATA[One of the most frequent requests to the CSS Working Group over the years has been to have some kind of support for declaring and using variables in style sheets. After much discussion, the CSS Custom Properties for Cascading Variables specification took the approach of allowing the author to specify custom properties in style rules [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>One of the most frequent requests to the CSS Working Group over the years has been to have some kind of support for declaring and using variables in style sheets.  After much discussion, the <a href="http://dev.w3.org/csswg/css-variables">CSS Custom Properties for Cascading Variables</a> specification took the approach of allowing the author to specify custom properties in style rules that cascade and inherit as other inherited properties do.  References to variables can be made in property values using the <code>var()</code> functional syntax.</p>
<p>Custom properties that declare variables all must be named beginning with <code>var-</code>.  The value of these custom properties is nearly freeform.  They can take nearly any stream of tokens, as long as it is balanced.</p>
<p>For example, an author might declare some common values on a style rule that matches the root element, so that they are available on every element in the document:</p>
<pre>:root {
  var-theme-colour-1: #009EE0; <span style="border-radius: 8px; width: 8px; height: 8px; background-color: #009EE0; border: 1px solid black; display: inline-block;"></span>
  var-theme-colour-2: #FFED00; <span style="border-radius: 8px; width: 8px; height: 8px; background-color: #FFED00; border: 1px solid black; display: inline-block;"></span>
  var-theme-colour-3: #E2007A; <span style="border-radius: 8px; width: 8px; height: 8px; background-color: #E2007A; border: 1px solid black; display: inline-block;"></span>
  var-spacing: 24px;
}</pre>
<p>Variables can be referenced at any position within the value of another property, including other custom properties.  The variables in the style sheet above can be used, for example, as follows:</p>
<pre>h1, h2 {
  color: <em>var(theme-colour-1)</em>;
}
h1, h2, p {
  margin-top: <em>var(spacing)</em>;
}
em {
  background-color: <em>var(theme-colour-2)</em>;
}
blockquote {
  margin: <em>var(spacing)</em> calc(<em>var(spacing)</em> * 2);
  padding: calc(<em>var(spacing)</em> / 2) 0;
  border-top: 2px solid <em>var(theme-colour-3)</em>;
  border-bottom: 1px dotted <em>var(theme-colour-3)</em>;
  font-style: italic;
}</pre>
<p>When applied to this document:</p>
<pre>&lt;!DOCTYPE html>
&lt;h1>The title of the document&lt;/h1>
&lt;h2>A witty subtitle&lt;/h2>
&lt;p>&lt;em>Please&lt;/em> consider the following quote:&lt;/p>
&lt;blockquote>Text of the quote goes here.&lt;/blockquote></pre>
<p>the result would be something that looks like this:</p>
<div id="example" style="background-color: white; margin-left: 32px; padding: 8px; border: 1px solid #ccc; font-size: 16px;">
<div style="margin-top: 24px; color: #009EE0; font-weight: bold; font-size: 24px">The title of the document</div>
<div style="margin-top: 24px; color: #009EE0; font-weight: bold; font-size: 20px">A witty subtitle</div>
<div style="margin-top: 24px"><span style="background-color: #FFED00; font-style: italic">Please</span> consider the following quote:</div>
<div style="margin: 24px 48px; padding: 12px 0; border-top: 2px solid #E2007A; border-bottom: 1px dotted #E2007A; font-style: italic">Text of the quote goes here.</div>
</div>
<p>Variables are resolved based on the value of the variable on the element that the property with a variable reference is applied to.  If the <code>h2</code> element had a <code>style="var-theme-colour-1: black"</code> attribute on it, then the <code>h2 { color: var(theme-colour-1); }</code> rule would be resolved using that value rather than the one specified in the <code>:root</code> rule.</p>
<p>Variable references can also include fallback to use in case the variable is not defined or is invalid (due to being part of a variable reference cycle).  The first rule in the style sheet using the variables could be rewritten as:</p>
<pre>h1, h2 {
  color: var(theme-colour-1, rgb(14, 14, 14));
}</pre>
<p>which would result in the colour being a dark grey if the <code>theme-colour-1</code> variable is not defined on one of the heading elements.</p>
<p>Since variable references are expanded using the variable value on the element, this process must be done while determining the computed value of a property.  Whenever there is an error during the variable substitution process, it causes the property to be “invalid at computed-value time”.  These errors can be due to referencing an undeclared variable with no fallback, or because the substituted value for the property does not parse (e.g. if we assigned a non-colour value to the <code>theme-colour-1</code> variable and then used that variable in the ‘color’ property).  When a property is invalid at computed-value time, the property declaration itself is parsed successfully and will be visible if you inspect the <code>CSSStyleDeclaration</code> object in the DOM.  The computed value of the property will take on a default value, however.  For inherited properties, like ‘color’, the default value will be ‘inherit’.  For non-inherited properties, it is ‘initial’.</p>
<h2>Implementation</h2>
<p>An initial implementation of CSS Variables has just landed in Firefox Nightly, which is currently at version 29.  The feature is not yet enabled for release builds (that is, Firefox Beta and the release version of Firefox), as we are waiting for a few issues to be resolved in the specification and for it to advance a little further in the W3C Process before making it more widely available.  It will however continue to be available in Nightly and, after the February 3 merge, in Firefox Aurora.</p>
<p>The only part of the specification that has not yet been implemented is the <code>CSSVariableMap</code> part, which provides an object that behaves like an ECMAScript <code>Map</code>, with <code>get</code>, <code>set</code> and other methods, to get the values of variables on a <code>CSSStyleDeclaration</code>.  Note however that you can still get at them in the DOM by using the <code>getPropertyValue</code> and <code>setProperty</code> methods, as long as you use the full property names such as <code>"var-theme-colour-1"</code>.</p>
<p>The work for this feature was done in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=773296">bug 773296</a>, and my thanks to <a href="http://dbaron.org/">David Baron</a> for doing the reviews there and to <a href="https://twitter.com/ebassi">Emmanuele Bassi</a> who did some initial work on the implementation.  If you encounter any problems using the feature, please <a href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&#038;component=CSS%20Parsing%20and%20Computation&#038;cc=cam@mcc.id.au&#038;blocked=773296">file a bug</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2013/12/variables/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Resetting styles using ‘all: unset’ in Firefox 27</title>
		<link>http://mcc.id.au/blog/2013/10/all-unset</link>
		<comments>http://mcc.id.au/blog/2013/10/all-unset#comments</comments>
		<pubDate>Wed, 09 Oct 2013 10:36:13 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=275</guid>
		<description><![CDATA[Some web developers like to use reset style sheets, which are style sheets that set all properties back to some known value on all elements. Although this does somewhat work against the “cascading” part of CSS, developers find it useful to avoid differences that come from user agent style sheets in different browsers and on [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Some web developers like to use <em>reset style sheets</em>, which are style sheets that set all properties back to some known value on all elements.  Although this does somewhat work against the “cascading” part of CSS, developers find it useful to avoid differences that come from user agent style sheets in different browsers and on different platforms.  Since reset style sheets explicitly list all of the properties and what value to set them back to, their use can result in unexpected styling when browsers begin to support new properties that the reset style sheets do not include.</p>
<p>The <a href="http://www.w3.org/TR/css-cascade-3/" title="CSS Cascading and Inheritance Level 3">CSS Cascading and Inheritance</a> specification adds a new shorthand named <a href="http://www.w3.org/TR/css-cascade-3/#all-shorthand" title="Resetting All Properties: the ‘all’ property">‘all’</a> that can be used in conjunction with a new CSS-wide keyword <a href="http://www.w3.org/TR/css-cascade-3/#inherit-initial" title="Erasing All Declarations: the ‘unset’ keyword">‘unset’</a>.  These can be used to the same effect as a reset style sheet.  ‘all’ is a shorthand property that is considered to have all properties that a user agent supports – except for ‘direction’ and ‘unicode-bidi’ – as component longhands.  ‘unset’ is a value that means the same as ‘inherit’, if used as the value of an inherited property, or the same as ‘initial’, if used as the value of a non-inherited property.</p>
<p>The effect of ‘unset’ is that it effectively removes any earlier matching declarations for that property at the same origin and with the same or lower specificity, and any matching declarations at all from earlier origins, while still respecting the precedence of <code>!important</code> declarations.  For example, in the following document, the ‘all: unset’ declaration is equivalent to ‘background-color: initial; color: inherit; display: initial; margin-top: initial; margin-left: initial; font-style: inherit; …’:</p>
<pre class="code">&lt;!DOCTYPE html&gt;
&lt;style&gt;
blockquote { background-color: skyblue; }
#quote { color: red; }
<em>blockquote { all: unset; }</em>
blockquote { font-style: italic; }
&lt;/style&gt;
&lt;blockquote id="quote"&gt;The blade itself incites to deeds of violence.&lt;/blockquote&gt;</pre>
<p>In a user agent that does not yet implement ‘all: unset’, the document would be rendered like this:</p>
<div style="background-color: white; margin-left: 32px; border: 1px solid #ccc; font: 16px serif;">
<blockquote style="background-color: skyblue; color: red; font-style: italic">The blade itself incites to deeds of violence.</p></blockquote>
</div>
<p>and in a user agent that does implement it, like this:</p>
<div style="background-color: white; margin-left: 32px; border: 1px solid #ccc; font: 16px serif;">
<blockquote style="all: unset; display: inline; margin: 0; color: red; font-style: italic">The blade itself incites to deeds of violence.</p></blockquote>
</div>
<p><i>(If you&#8217;re reading this in a feed reader that has other styles applied, and in a browser that does not yet implement ‘all: inherit’, the renderings above might not look exactly right.)</i></p>
<p>The quote is rendered with red, italic text, but without its typical margins, which come from the user agent style sheet.  The ‘all’ declaration wins over the ‘background-color: skyblue’ declaration, which has the same origin and specificity, while the ‘color: red’ declaration wins due to its higher specificity.</p>
<p>One thing to be aware of is that the initial value of the ‘display’ property is ‘inline’, which is different from the ‘block’ that would be set on <code>blockquote</code> elements in the user agent style sheet.  If we had two consecutive <code>blockquote</code> elements, they would be shown in the one run of inline text, as if they were <code>span</code>s.</p>
<p>Although the ‘all’ shorthand would typically be used with the ‘unset’ value, the other CSS-wide values ‘inherit’ and ‘initial’ can be used with it, and ‘unset’ can also be used on any other individual property.</p>
<p>Bugs <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=842329" title="Bug 842329 – [css3-cascade] implement the 'all' shorthand">842329</a> and <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=921731" title='Bug 921731 –  implement the "unset" value from CSS Cascading and Inheritance Level 3'>921731</a> landed in Firefox Nightly builds a couple of days ago, and will therefore be available in Firefox 27.</p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2013/10/all-unset/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>More SVG text news</title>
		<link>http://mcc.id.au/blog/2013/07/more-svg-text-news</link>
		<comments>http://mcc.id.au/blog/2013/07/more-svg-text-news#comments</comments>
		<pubDate>Tue, 09 Jul 2013 01:29:56 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=264</guid>
		<description><![CDATA[A couple of notes subsequent to my last post about Firefox Nightly&#8217;s SVG text improvements. First, Robert Longson pointed out to me that there were a couple more features that SVG text now supports since the rewrite landed: You can use ‘font-variant: small-caps’. SVG text can be copied to the clipboard with Cmd/Ctrl+C once selected. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>A couple of notes subsequent to my <a href="http://mcc.id.au/blog/2013/07/firefox-svg-text-improvements">last post</a> about Firefox Nightly&#8217;s SVG text improvements.</p>
<p>First, Robert Longson pointed out to me that there were a couple more features that SVG text now supports since the rewrite landed:</p>
<ul>
<li>You can use ‘font-variant: small-caps’.</li>
<li>SVG text can be copied to the clipboard with Cmd/Ctrl+C once selected.</li>
<li>SVG DOM methods for selecting text – selectSubString and deselectAll – are now implemented.</li>
</ul>
<p>Second, the latest Firefox Nightly (2013-07-08) now supports the <code>textLength=""</code> and <code>lengthAdjust=""</code> attributes on the <code>&lt;text&gt;</code> element (but not yet on child text content elements).  These attributes are useful if, for example, you have some text in a diagram that you want to ensure does not run over some other elements, which might happen if the font used is not present on the client, or if text layout resulted in a total text width different from what the author expected.</p>
<p>You can see the effect of using <code>textLength="..." lengthAdjust="spacingAndGlyphs"</code> in this example:</p>
<div style="text-align: center"><iframe src="http://mcc.id.au/2013/textLength.svg" width="280" height="100" style="border: none;"></iframe></div>
<p>If you mouse over the ellipses, the text is changed to use a monospaced font.  This would normally make the text wider than the ellipse, but the use of <code>lengthAdjust="spacingAndGlyphs"</code> scales the text so that it retains its specified width.</p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2013/07/more-svg-text-news/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improved SVG text support in Firefox Nightly</title>
		<link>http://mcc.id.au/blog/2013/07/firefox-svg-text-improvements</link>
		<comments>http://mcc.id.au/blog/2013/07/firefox-svg-text-improvements#comments</comments>
		<pubDate>Mon, 01 Jul 2013 08:48:19 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=238</guid>
		<description><![CDATA[On the weekend, I landed the final patch in what turned out to be quite a long running project to overhaul Firefox&#8217;s SVG text support to reuse the same text layout and rendering code that it uses for HTML. Much of the work was done in bug 655877, which ended up being a series of [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>On the weekend, I landed the final patch in what turned out to be quite a long running project to overhaul Firefox&#8217;s SVG text support to reuse the same text layout and rendering code that it uses for HTML.  Much of the work was done in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=655877" title="Bug 655877 – SVG text should use CSS text frames to gain support for various text layout features">bug 655877</a>, which ended up being a series of 50 patches<sup>(!)</sup>, with about 40 followup bugs to get the code into shape so that it could be turned on by default.</p>
<p>Improvements resulting from this work include the following:</p>
<ul>
<li>The ‘<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration">text-decoration</a>’ property is now honoured, so underlines, strike-throughs and overlines are painted.</li>
<li>Searching for text on a page will now search through and highlight SVG text.</li>
<li>Text can be selected with the mouse.</li>
<li>Layout of bidirectional text when there are multiple child nodes of a <code>&lt;text&gt;</code> element is now correct.</li>
<li>The ‘<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/white-space">white-space</a>’ property now applies to SVG text.  In the future, in SVG 2, ‘white-space’ will be recommended method to control white space handling rather than <code>xml:space=""</code>.  ‘white-space’ can be used to render manually wrapped text when using the <code>pre</code> and <code>pre-line</code> values.  ‘<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/line-height">line-height</a>’ is used to determine the spacing between lines.</li>
<li>Various <a href="http://dev.w3.org/csswg/css-fonts/">CSS3 Font properties</a>, including the new ‘font-variant’ related properties to turn on and off OpenType features, now apply to SVG text.</li>
<li>The <code>:first-letter</code> and <code>:first-line</code> pseudo-elements now apply to SVG text.</li>
</ul>
<p>If you work with SVG content, please download the latest <a href="http://nightly.mozilla.org/">Firefox Nightly</a> and test out the new functionality, and if you encounter any issues, please do <a href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&#038;component=SVG&#038;cc=cam@mcc.id.au&#038;blocked=839955">file a bug</a>.</p>
<p>My thanks to roc, jwatt, longsonr, bz and dbaron for their help and reviews!</p>
<hr />
<p><b>Update 3 July 2013:</b> Here is a <a href="/2013/text.html">page demonstrating these features</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2013/07/firefox-svg-text-improvements/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>@supports enabled by default for Firefox 22</title>
		<link>http://mcc.id.au/blog/2013/04/supports-enabled-by-default</link>
		<comments>http://mcc.id.au/blog/2013/04/supports-enabled-by-default#comments</comments>
		<pubDate>Mon, 01 Apr 2013 23:09:57 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=226</guid>
		<description><![CDATA[The CSS Working Group is planning to publish the CSS Conditional Rules Module as a Candidate Recommendation soon. As a result, David Baron has landed a patch that enables the @supports rule and the CSS.supports() API by default for Firefox 22, which is scheduled to hit Release some time in May.]]></description>
				<content:encoded><![CDATA[<p>The CSS Working Group is planning to publish the <a href="http://dev.w3.org/csswg/css-conditional/">CSS Conditional Rules Module</a> as a Candidate Recommendation soon.  As a result, David Baron has <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=855455">landed a patch</a> that enables the <a href="http://mcc.id.au/blog/2012/08/supports"><code>@supports</code> rule</a> and the <a href="http://mcc.id.au/blog/2012/12/css-supports-api"><code>CSS.supports()</code> API</a> by default for Firefox 22, which is scheduled to hit Release some time in May.</p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2013/04/supports-enabled-by-default/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scoped style sheets</title>
		<link>http://mcc.id.au/blog/2013/01/scoped-style-sheets</link>
		<comments>http://mcc.id.au/blog/2013/01/scoped-style-sheets#comments</comments>
		<pubDate>Tue, 15 Jan 2013 23:43:55 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=175</guid>
		<description><![CDATA[Scoped style sheets are a feature from HTML 5 (or the HTML Standard, if you prefer) that allows the effect of a style sheet to be limited to a subtree of the document. By placing a scoped attribute on a &#60;style&#62; element, the style sheet applies only to elements within the subtree rooted by the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Scoped style sheets are a feature <a href="http://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#attr-style-scoped">from HTML 5</a> (or <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#attr-style-scoped">the HTML Standard</a>, if you prefer) that allows the effect of a style sheet to be limited to a subtree of the document.  By placing a <code>scoped</code> attribute on a <code>&lt;style&gt;</code> element, the style sheet applies only to elements within the subtree rooted by the parent of the <code>&lt;style&gt;</code> element.</p>
<p>For example, consider this document:</p>
<pre style="margin-left: 32px">&lt;!DOCTYPE html&gt;
&lt;title&gt;Scoped style example&lt;/title&gt;
&lt;body&gt;
  &lt;style&gt;
    p { font-style: italic; }
  &lt;/style&gt;
  &lt;p&gt;The first paragraph.&lt;/p&gt;
  &lt;p&gt;
    &lt;style <em>scoped</em>&gt;
      p { color: crimson; }
    &lt;/style&gt;
    The second paragraph.
  &lt;/p&gt;
&lt;/body&gt;</pre>
<p>It would be rendered as follows:</p>
<div style="font-style: italic; border: 1px solid #ddd; background-color: #f8f8f8; margin-left: 32px">
<p>The first paragraph.</p>
<p style="color: crimson">The second paragraph.</p>
</div>
<p>Rules in the style sheet only match an element if all of the elements matched by a selector are within the style scope.  Thus, if the rule were instead <code>body > p { color: crimson; }</code>, it would not match that second paragraph.</p>
<p>The <a href="http://dev.w3.org/csswg/css3-cascade/#cascade">CSS Cascading and Inheritance Level 3</a> specification defines that when there are nested style scopes, rules on inner scopes override those from outer scopes, regardless of the specificity of the rules.  Using <code>!important</code> reverses this, and allows outer scopes to win over inner scopes.  Global style sheets, including <code>&lt;style&gt;</code> elements without a <code>scoped=""</code> attribute or those loaded using a <code>&lt;link&gt;</code> element, are treated as if they are scoped to the root element.</p>
<p>One use case for scoped style sheets is to isolate a set of style rules that apply to a single article or comment within a page to ensure that they cannot affect the style of other elements on the page.  On a web site that aggregates articles from different authors, this could allow the designer of the overall site to know that the elements of the page outside the article itself will not be affected by the article&#8217;s styles.</p>
<p>Another is to be able to specify style for a given element&#8217;s pseudo-element, or only when it matches a pseudo-class, which is not possible just by using the <code>style=""</code> on the element or without giving the element an ID and defining the style in a global style sheet.  For example if you have an element styled like this:</p>
<pre>&lt;p>
  ...
  &lt;span style="text-decoration: underline;">looks like a link&lt;/span>
  ...
&lt;/p></pre>
<p>and you decide you want the underline to be applied only when the element is hovered, then it&#8217;s not possible to use the <code>:hover</code> pseudo-class within the <code>style=""</code> attribute.  A scoped style sheet can be used:</p>
<pre>&lt;p>
  ...
  &lt;span>
    <em>&lt;style scoped>:hover { text-decoration: underline; }&lt;/style></em>
    looks like a link
  &lt;/span>
  ...
&lt;/p></pre>
<h2>Implementation</h2>
<p>Firefox 21, currently on the Nightly channel, supports scoped style sheets now that <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=508725">bug 508725</a> has landed.  This feature is not prefixed or behind a pref.  The <code>scoped=""</code> attribute can be placed on SVG <code>&lt;style&gt;</code> elements, too.</p>
<p>There are two aspects of the Firefox implementation that don&#8217;t match the specification yet:</p>
<ol>
<li>The <code>@global</code> at-rule, to allow all elements during selector matching except for the subject to be outside the style scope, is not implemented.  The name &#8220;global&#8221; doesn&#8217;t quite convey the meaning it has, and given there are no other at-rules that can be used as a prefix to a list of selectors, some other syntax might be better.  (Filed as <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=830058">bug 830058</a>.)</li>
<li>Other at-rules that have global effects, including <code>@font-face</code> and <code>@keyframes</code>, are not processed at all within scoped style sheets.  The HTML specification states that these should have effects limited to the style scope.  (Filed as <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=830056">bug 830056</a>.)</li>
</ol>
<p><small>[Edited 16 January 2013 – fixed the typo pointed out by Pablo]</small></p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2013/01/scoped-style-sheets/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>The paint-order property</title>
		<link>http://mcc.id.au/blog/2013/01/paint-order</link>
		<comments>http://mcc.id.au/blog/2013/01/paint-order#comments</comments>
		<pubDate>Mon, 14 Jan 2013 22:29:22 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=160</guid>
		<description><![CDATA[In SVG 1.1, every shape and text element has its components painted in the same order: fill, then stroke and finally any markers. In some situations, authors want these to be painted in a different order. The usual workaround to achieve this is to duplicate the element, and have say a stroke but no fill [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>In SVG 1.1, every shape and text element has its components painted in the same order: fill, then stroke and finally any markers.  In some situations, authors want these to be painted in a different order.  The usual workaround to achieve this is to duplicate the element, and have say a stroke but no fill set on the first and vice versa on the second.</p>
<p>SVG 2 adds a simple property that allows the author to control the painting order of the components of a shape or text content element: the <a href="http://www.w3.org/TR/2012/WD-SVG2-20120828/painting.html#PaintOrder">paint-order</a> property.  The initial value of the property is <code>normal</code>, which gets you the default, SVG 1.1 behaviour.  To specify a different order, a sequence of <code>fill</code>, <code>stroke</code> and <code>markers</code> keywords is used.  The keywords cannot be repeated, but some can be omitted, in which case all of the remaining unspecified components are painted in their default order, after the ones that were explicitly specified.  For example, <code>paint-order="stroke"</code> is equivalent to <code>paint-order="stroke fill markers"</code>.</p>
<p>Where I often want to place the stroke underneath the fill is when stroking text.  The problem with placing the stroke above the fill of a text element is that the stroke straddles the boundary of the fill, half lying inside the glyphs and half outside.  This results in the apparent glyph shape changing, the thicker the stroke you use.</p>
<p>The following example demonstrates the use of <code>paint-order</code> on a <code>&lt;text&gt;</code> element to produce stroked text that looks nicer:</p>
<pre>&lt;svg xmlns="http://www.w3.org/2000/svg" width="400" height="200"&gt;
  &lt;linearGradient id="g" x1="0" y1="0" x2="0" y2="1"&gt;
    &lt;stop stop-color="#888"/&gt;
    &lt;stop stop-color="#ccc" offset="1"/&gt;
  &lt;/linearGradient&gt;
  &lt;rect width="400" height="200" fill="url(#g)"/&gt;
  &lt;g fill="crimson" stroke="white" stroke-width="6" stroke-linejoin="round"
     text-anchor="middle" font-family="sans-serif" font-size="50px" font-weight="bold"&gt;
    &lt;text x="200" y="75"&gt;stroke over&lt;/text&gt;
    &lt;text x="200" y="150" <em>paint-order="stroke"</em>&gt;stroke under&lt;/text&gt;
  &lt;/g&gt;
&lt;/svg&gt;</pre>
<p>The example would be rendered like this:</p>
<div style="text-align: center"><img src="http://mcc.id.au/2013/paint-order.png" width="400" height="200" title="Rendering of the paint-order example"></div>
<p>Perhaps this comparison is a bit unfair; the apparent thickness of the stroke on the element with <code>paint-order="stroke"</code> is half that of the text with the default <code>paint-order</code> since half of it is occluded by the fill.  Here is what it would look like if the first text element had <code>stroke-width="3"</code>:</p>
<div style="text-align: center"><img src="http://mcc.id.au/2013/paint-order-2.png" width="400" height="200" title="Rendering of the paint-order example, but with the first text element with stroke-width set to 3"></div>
<p>It&#8217;s clearer to see here that due to the stroke paint intruding on the fill of the first text element, the red glyphs end up looking eroded, while those in the second element appear normal.</p>
<h2>Implementation</h2>
<p>Since <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=828805">bug 828805</a> landed yesterday, support for the <code>paint-order</code> property is now available in Firefox Nightly.  It currently is enabled only when the <code>svg.paint-order.enabled</code> property is set to <code>true</code>, which is the default on the Firefox Nightly and Aurora channels.  Once the SVG 2 specification matures further, support will be enabled across all channels.</p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2013/01/paint-order/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The mask-type property</title>
		<link>http://mcc.id.au/blog/2012/12/mask-type</link>
		<comments>http://mcc.id.au/blog/2012/12/mask-type#comments</comments>
		<pubDate>Sat, 29 Dec 2012 02:49:08 +0000</pubDate>
		<dc:creator>Cameron McCormack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mcc.id.au/?p=102</guid>
		<description><![CDATA[TL;DR: The mask-type property is now available in Firefox Nightly. Here is a simple use of an SVG mask: &#60;svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 341" width="512" height="341"&#62; &#60;defs&#62; &#60;mask id="m"&#62; &#60;circle cx="256" cy="200" r="150"/&#62; &#60;/mask&#62; &#60;/defs&#62; &#60;g mask="url(#m)"&#62; &#60;image width="512" height="341.5" xlink:href="http://farm8.staticflickr.com/7063/6860283873_b9f2e6d511_b.jpg"/&#62; &#60;!-- original: http://www.flickr.com/photos/yewenyi/6860283873/ http://creativecommons.org/licenses/by-nc/2.0/ --&#62; &#60;/g&#62; &#60;/svg&#62; And here is how it [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><i>TL;DR: The <code>mask-type</code> property is now available in Firefox Nightly.</i></p>
<p>Here is a simple use of an <a href="http://www.w3.org/TR/SVG11/masking.html#Masking">SVG mask</a>:</p>
<pre>&lt;svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
     viewBox="0 0 512 341" width="512" height="341"&gt;
  &lt;defs&gt;
    &lt;mask id="m"&gt;
      &lt;circle cx="256" cy="200" r="150"/&gt;
    &lt;/mask&gt;
  &lt;/defs&gt;
  &lt;g mask="url(#m)"&gt;
    &lt;image width="512" height="341.5" xlink:href="http://farm8.staticflickr.com/7063/6860283873_b9f2e6d511_b.jpg"/&gt;
    &lt;!-- original: http://www.flickr.com/photos/yewenyi/6860283873/
         http://creativecommons.org/licenses/by-nc/2.0/ --&gt;
  &lt;/g&gt;
&lt;/svg&gt;</pre>
<p>And here is how it renders:</p>
<p><iframe width=512 height=341 src="http://mcc.id.au/2012/mask-wrong.svg" style="border: 1px solid rgb(221,221,221); margin-left: 24px; background-color: rgba(255,255,255,0.5)"></iframe></p>
<p>Er, what?  This should be a simple raster image masked by a circle.  What went wrong?</p>
<p>If you&#8217;re like me, you would have made this mistake a thousand times.  The problem is that the <code>mask</code> element looks at the <em>luminance</em> of the mask child content to determine how much of the masked graphics to let show through.  Luminance is a measure of brightness – black has luminance of 0 and white has a luminance of 1.  The different red, green and blue component values contribute with different weights, and the luminance value is then multiplied with the alpha of the mask content pixel to determine the final mask value.  For each pixel, the mask value is multiplied by the RGBA pixel in the masked content.  Since our mask consists only of a black circle (black is the initial value of the <code>fill</code> property), the mask value over the entire mask is 0, letting nothing of the masked content through!  What we should have done is specified <code>fill="white"</code> on the circle.</p>
<p>It is a very common misconception that SVG masks look just at the alpha of the mask content, and this is also a common way that masks are used in authoring tools.  To accommodate this, <a href="http://svgwg.org/svg2-draft/">SVG 2</a> uses the new <a href="http://dvcs.w3.org/hg/FXTF/raw-file/tip/masking/index.html">CSS Masking</a> specification, which, among other things, allows an author to specify that the alpha of a mask&#8217;s content, and not the luminance, is used to determine mask values.  This is done by the use of the <code>mask-type</code> property.  We can use it in our example as follows:</p>
<pre>&lt;svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
     viewBox="0 0 512 341" width="512" height="341"&gt;
  &lt;defs&gt;
    &lt;mask id="m" <em>mask-type="alpha"</em>&gt;
      &lt;circle cx="256" cy="200" r="150"/&gt;
    &lt;/mask&gt;
  &lt;/defs&gt;
  &lt;g mask="url(#m)"&gt;
    &lt;image width="512" height="341.5" xlink:href="http://farm8.staticflickr.com/7063/6860283873_b9f2e6d511_b.jpg"/&gt;
    &lt;!-- original: http://www.flickr.com/photos/yewenyi/6860283873/
         http://creativecommons.org/licenses/by-nc/2.0/ --&gt;
  &lt;/g&gt;
&lt;/svg&gt;</pre>
<p>and the resulting image would look like this:</p>
<p><iframe width=512 height=341 src="http://mcc.id.au/2012/mask-right.svg" style="border: 1px solid rgb(221,221,221); margin-left: 24px; background-color: rgba(255,255,255,0.5)"></iframe></p>
<p>Now, obviously this example is simple enough that if you could remember that you needed to change something to make the mask work, you would probably remember that <code>fill="white"</code> would work just as well as <code>mask-type="alpha"</code>.  The <code>mask-type</code> property could become more useful if you already have some graphics (either SVG content, perhaps referencing some raster images too) that has alpha.  Although it would be possible to use an SVG filter to convert the alpha channel into an opaque image with just the right shade of white, this seems unnecessary work for the author.</p>
<p>Since <code>mask-type</code> is a CSS property, it means you can also set it once for all masks in a document with a single style rule, <code>mask { mask-type: alpha }</code>.</p>
<h2>Implementation</h2>
<p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=793617">Bug 793617</a> has just landed, which means that the <code>mask-type</code> property is now available in Firefox.  As with other new features we have been implementing recently, this property is not prefixed.  Instead, it lives behind a pref – <code>layout.css.masking.enabled</code> in this case.  The pref will default to being <code>true</code> for Nightly and Aurora builds, and <code>false</code> for Beta and Release.  Once the CSS Masking specification has matured further, the feature will be enabled by default on all builds.  This means that you can begin experimenting with the property, but don&#8217;t write productions web sites that rely on it just yet!</p>
<p>In WebKit land, <a href="https://bugs.webkit.org/show_bug.cgi?id=97011">Dirk Schulze has implemented the property</a>, also without a prefix.</p>
<p><small>[Edited 29 December 2012 – fix the examples to not use <code>fill="white"</code> as pointed out by <i>roc</i>]</small></p>
]]></content:encoded>
			<wfw:commentRss>http://mcc.id.au/blog/2012/12/mask-type/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
