SVG Comments
It’s been a while since I did anything really technologically innovative with this blog. But progress marches on, and it’s time to kick it up a notch. Mozilla/Firefox, Opera and the prerelease version of Safari all support inline SVG. So perhaps the time is ripe to enable SVG comments.
- First, this involved fixing
MT::Sanitize
, which now handles case-sensitive elements and attributes, and allows hyphens in attribute names. - Next, I needed to add SVG support to the Sanitize Spec2.
- Finally, there was a bug in the DTD used by the W3C Validator, which is patched in the local version used by our comment system.
Using that local copy of the W3C Validator means we need to adhere to (no longer!) the rather lame restrictions of the XHTML+MathML+SVG DTD:
- SVG elements must be prefixed.
- The prefixes for the SVG (“
svg:
”) and XLink (“xlink:
”) namespaces are hard-coded. - The
xmlns:xlink
attribute must appear on the<svg:svg>
element and not on a descendent thereof.
none of which are necessary consequences of the use of XML Namespaces.
Also, until I rewrite MT:Sanitize
, style attributes are forbidden. Which means that this trick can’t be used.
Finally, I’ll ask that commenters include an <desc>
element. Like the alt
attribute of an <img />
, the content of <desc>
will be displayed in place of the figure in non-SVG-capable browsers.
Here’s an example3 of the sort of thing you can now leave in the comments:
Here are a couple more examples.
I hope this feature will be useful. Or, at least, the source of some entertainment.
Anyway, here’s a question I could probably find the answer to, with sufficient Googling around. But, probably, one of my readers already knows the answer.
A cubic Bézier curve is a map Without loss of generality, we can take and . are cubic polynomials in .
In SVG, such a cubic Bézier curve is specified like this:
<path d="... c ..." />
where
for some constant, . This data completely specifies the pair of cubics.
My question is: what’s ?
I’m gonna guess the answer is because, for that value, a cubic Bézier curve degenerates to a quadratic Bézier
<path d="... q ..." />
when . But does anyone know for sure?
Update:
Sam Ruby proposes some code to ease a bit of the pain. It will take Namespace well-formed SVG code and convert it into the prefixed format demanded by the W3C Validator. IUpdate (4/29/2007):
Note that there is, currently, no way to mix SVG and MathML. One would like to be able to insert mathematical formulæ as labels in a figure. That, apparently, would require<foreignObject>
, which is
- not currently supported by Mozilla/Firefox
- not supported by our current setup (though it could be)
- in any case, a clumsy, broken mechanism for doing what we want
That’s fine for the above Feynman diagram, but inadequate for many other uses.
1 In other respects, MT::Sanitize
is something of a train wreck, and is badly in need of a complete rewrite along these lines.
2 For the curious, the Sanitize Spec currently reads:
img src alt,h4,textarea rows cols,div,bdo,span,p,br,a href target, abbr,acronym,b,u,i,strong,em,ul,ol,li,dl,dt,dd,sup,tt,sub,pre, blockquote cite,code,del,ins,math xmlns xmlns:xlink display, annotation-xml encoding, mfenced open close separators, mo lspace rspace fence separator stretchy maxsize minsize, mi mathvariant,msub,msup,msubsup,mfrac linethickness,mn, mstyle scriptlevel mathvariant displaystyle mathcolor mathbackground, mtext,mspace width height depth,msqrt,mmultiscripts,mprescripts, none,mroot,mphantom,merror,mover,munder,munderover, maction actiontype other selection,mtable align columnalign rowalign equalrows equalcolumns columnspacing rowspacing columnlines rowlines frame,mrow xmlns:xlink xlink:type xlink:href, mtr rowalign columnalign,mtd rowspan columnspan rowalign columnalign, mpadded width,semantics,animate,animateColor, animateMotion,animateTransform,circle,defs,desc,ellipse, foreignObject ,font-face,font-face-name,font-face-src, g,glyph,hkern,image,linearGradient,line,marker refX refY markerUnits markerWidth markerHeight orient,metadata,missing-glyph, mpath,path,polygon,polyline,radialGradient,rect,set,stop, svg xmlns xmlns:xlink,switch,text,title,tspan dx dy,use, * dir xml:lang title class id accent-height accumulate additive alphabetic arabic-form ascent attributeName attributeType baseProfile bbox begin by calcMode cap-height color color-rendering content cx cy d descent display dur end fill fill-rule font-family font-size font-stretch font-style font-variant font-weight from fx fy g1 g2 glyph-name gradientUnits hanging height horiz-adv-x horiz-origin-x ideographic k keyPoints keySplines keyTimes lang marker-end marker-mid marker-start mathematical max min name offset opacity origin overline-position overline-thickness panose-1 path pathLength points preserveAspectRatio r repeatCount repeatDur requiredExtensions requiredFeatures restart rotate rx ry slope stemh stemv stop-color stop-opacity strikethrough-position strikethrough-thickness stroke stroke-dasharray stroke-dashoffset stroke-linecap stroke-opacity stroke-linejoin stroke-miterlimit stroke-width systemLanguage target text-anchor to transform type u1 u2 underline-position underline-thickness unicode unicode-range units-per-em values version viewBox visibility width widths x x-height x1 x2 xlink:actuate xlink:arcrole xlink:href xlink:role xlink:show xlink:title xlink:type xml:base xml:space y y1 y2 zoomAndPan, svg:a,svg:animate,svg:animateColor,svg:animateMotion, svg:animateTransform,svg:circle,svg:defs,svg:desc,svg:ellipse, svg:foreignObject,svg:font-face,svg:font-face-name,svg:font-face-src, svg:g,svg:glyph,svg:hkern,svg:linearGradient,svg:line,svg:marker refX refYmarkerUnits markerWidth markerHeight orient,svg:metadata, svg:missing-glyph,svg:mpath,svg:path,svg:polygon,svg:polyline, svg:radialGradient,svg:rect,svg:set,svg:stop,svg:svg xmlns:svg xmlns:xlink,svg:switch,svg:text,svg:title,svg:tspan dx dy,svg:use
Note that we allow SVG elements in both their prefixed and un-prefixed forms.
3 Here’s the code to produce that example:
<div class="centeredfigure"> <svg xmlns="http://www.w3.org/2000/svg" width="192" height="64" viewBox="0 0 120 40"> <desc>sphere, cube, tetrahedron</desc> <defs> <radialGradient id="plat1" fx=".3" fy=".3" r=".7"> <stop stop-color="#CCF" offset="0" /> <stop stop-color="#55F" offset="1" /> </radialGradient> <linearGradient id="squ1" x1=".3" y1=".3" x2="1.7" y2="1.7"> <stop stop-color="#CDC" offset="0" /> <stop stop-color="#6D6" offset="1" /> </linearGradient> <linearGradient id="squ2" xmlns:xlink="http://www.w3.org/1999/xlink" x1="0" y1="0" x2="1" y2="-.6" xlink:href="#squ1" /> </defs> <g transform="translate(5,5)" stroke="none"> <circle cx="15" cy="15" r="15" fill="url(#plat1)" /> <g stroke="#9D9" stroke-width=".5" stroke-opacity="0.6"> <rect width="20" height="20" x="40" y="10" fill="url(#squ1)" /> <path d="M 40 10 l 20 0 l 10 -10 l -20 0 z" fill="url(#squ2)" /> <path d="M 60 30 l 0 -20 l 10 -10 l 0 20 z" fill="#9D9" /> </g> <g> <path d="M 95 0 l -17 20 l 17 10 z" fill="#FCC" /> <path d="M 95 0 l 17 20 l -17 10 z" fill="#FBB" /> </g> </g> </svg><br /> <span class="figurecaption">Three Solids</span> </div>
Feynman diagrams
How about some Feynman diagrams?
To kick things off, here’s the infamous box diagram:
Mixing
Nice!