Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
278 lines (163 sloc) 13.6 KB
<!doctype html>
<!--[if lt IE 9]> <html class="no-js oldie" lang="en"> <![endif]-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>About Fonts in SVG | Divya Manian</title>
<meta name="author" content="Divya Manian">
<meta name="description" content="One area in my webfonts investigation that I wanted to know more about, was the state of SVG fonts. What is SVG? SVG stands for Scalable Vector &hellip;">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="">
<link href="/stylesheets/screen.css" rel="stylesheet">
<link href="" rel="alternate" title="Subscribe" type="application/atom+xml">
<link href="" rel="alternate" title="Subscribe to Web Development updates" type="application/atom+xml">
<body >
<div class="container">
<div class="content">
<header role="banner"> <h1><a href="/">Divya Manian</a></h1>
<h2><a class="twitter" href="">twitter</a> <a class="rss" href="">RSS Feed</a> <a class="youtube" href="">Youtube Channel</a> <a class="github" href="">Github</a></h2>
<nav class="sitenav"><a href="/">Home</a>
<a href="/archives">Archives</a>
<a href="/about.html">About</a>
<nav class="article">
<a class="previous" href="/book-reviews-for-september-2009.html" title="Book Reviews for September 2009">❬</a>
<a class="next" href="/book-reviews-for-october-2009.html" title="Book Reviews for October 2009">❭</a>
<time datetime="2009-09-19T00:00:00-07:00" pubdate><span class='month'>Sep</span> <span class='day'>19</span> <span class='year'>2009</span></time>
<h1 class="entry-title"><a href="/about-fonts-in-svg.html">About Fonts in SVG</a></h1>
<div class="entry-content"><p>One area in my <a href="" title="Font in your face | Nimbupani Designs">webfonts investigation</a> that I wanted to know more about, was the state of SVG fonts.</p>
<h3>What is SVG?</h3>
<p>SVG stands for Scalable Vector Graphics. SVG was created to fill the need for a standardized vector graphic solution for the web (read about <a href="">the history of SVG</a>). SVG uses XML to describe 2D graphics. So, a circle is defined in SVG as:</p>
&lt;svg width=&quot;12cm&quot; height=&quot;4cm&quot; viewBox=&quot;0 0 1200 400&quot;
xmlns=&quot;; version=&quot;1.1&quot;&gt;
&lt;desc&gt;Example Circle&lt;/desc&gt;
&lt;circle cx=&quot;600&quot; cy=&quot;200&quot; r=&quot;100&quot;
fill=&quot;red&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; /&gt;
<p>See <a href="/demo/svgfonts/circle.svg">the sample SVG</a>.</p>
<p>You can convert almost any <a href="" title="Vector graphics - Wikipedia, the free encyclopedia">vector graphic</a> to SVG format (here is <a href="">how to save your Adobe Illustrator files as SVG</a>). Typically, since SVG is XML (and a vector graphic), it will be smaller than other image formats.</p>
<h3>The elephant in the room</h3>
<p>Before I proceed, I must mention that <a href="">IE (even IE 8) does not support SVG</a>. <a href="">IE 9 Preview does have support for SVG</a>. Google Chrome&rsquo;s native support of SVG is not as good as Opera, <a href="">Firefox</a>, or <a href="">Safari</a> either (see <a href="" title="SVG Support in major browsers">this excellent chart of SVG support on various browsers</a>). Google has released <a href="">SVG Web</a> which allows SVG to be rendered on all browsers that support either SVG or Flash.</p>
<h3>Fonts in SVG</h3>
<p>Like in any vector graphic, SVG can have text. If you want the text to render a font on any SVG Viewer, you have 3 options:</p>
<li><p><em>Use web-safe fonts:</em> This is the easiest. An example:</p>
<pre>&lt;text x=&quot;100&quot; y=&quot;100&quot; style=&quot;font-family: impact, georgia, times, serif; font-weight: normal; font-style: normal&quot;&gt;
Text using web safe font
<p>See demo of <a href="/demo/svgfonts/svg-websafe.svg">SVG rendered with web-safe font</a></p>
<li><p><em>Use @font-face CSS declaration to specify fonts:</em> Browsers will render text just as they render HTML using @font-face. For example, Firefox does not allow cross-site linking of fonts, so it will not render a font if it is in another server (you need to add a <a href="" title="beautiful fonts with @font-face at">HTTP header to allow cross-site linking</a>). </p>
&lt;style type=&quot;text/css&quot;&gt;
@font-face {
font-family: Delicious;
src: url(&#x27;;);
&lt;text x=&quot;100&quot; y=&quot;100&quot; style=&quot;font-family: &#x27;Delicious&#x27;; font-weight:normal; font-style: normal&quot;&gt;
Text using CSS @font-face
<p>See a demo of <a href="/demo/svgfonts/svg-fontface.svg">SVG text rendered with CSS @font-face</a></p>
<em>Use fonts defined using SVG&rsquo;s font element: </em> SVG format provides a common font format that will be supported by all confirming SVG viewers. An SVG font will have a file extension of &ldquo;.svg&rdquo; and will be formatted as XML. Here are <a href="">some examples of SVG fonts</a>. There are two ways of using SVG Fonts: </p>
<li><p><em>Using external SVG Fonts: </em> You can link to an external SVG using the font-face element of SVG (not the CSS @font-face declaration).</p>
<li><p><em>Embed font within the svg file:</em> Most Vector Graphic editors default to this option.</p></li>
<p><a href=",frankbruder/article/SVGFonts-usage" title="Frank Bruder - SVG Fonts: How To">This page on SVG Fonts</a> explains exhaustively how to use SVG fonts (and how to convert fonts from other formats to SVG). It has great examples of these two methods of using SVG fonts.</p>
<h3>Using SVG Fonts for HTML</h3>
<p>Using the CSS <a href="">@font-face declaration</a>, you can also specify SVG fonts instead of just TTF/EOT/OTF fonts. It looks like only Opera 10 and Safari 4 support SVG fonts in CSS (<a href="" title="Web fonts example">see a demo of SVG Fonts in HTML</a>). There is a <a href="">bug filed for Firefox</a> but no fix yet.</p>
<h3>Why use SVG fonts?</h3>
<li><em>Universal support:</em> Any conforming SVG viewer will render the text in the SVG font specified.</li>
<li><em>Store multiple fonts in a single file:</em> You can create a single SVG file with multiple fonts and use the &#8220;id&#8221; of that specific font element to declare which font you want to use in your HTML or SVG document.</li>
<li><em>Open Source:</em> The font file is completely open. If <a href="">the font you are using is missing glyphs</a> you can add the glyph you need.</li>
<li><em>Chrome Support:</em> (Thanks for this suggestion <a href="">@paul_irish</a>!) If you use SVG font format in CSS @font-face declaration for HTML/SVG, it will now work on the latest releases of Chrome, Safari, and Opera (though not on Firefox!).</li>
<h3>Disadvantages of SVG fonts</h3>
<p>The main drawback to SVG fonts is there is no provision for <a href="">font-hinting</a>. The SVG standard states:</p>
<blockquote cite="">
<p>SVG fonts contain unhinted font outlines. Because of this, on many implementations there will be limitations regarding the quality and legibility of text in small font sizes. For increased quality and legibility in small font sizes, content creators may want to use an alternate font technology, such as fonts that ship with operating systems or an alternate WebFont format.</p>
<p>SVG support across browsers is still not consistent. The support for SVG fonts in HTML is even worse.</p>
<h3>The Future</h3>
<p>SVG has gained a lot of traction in the recent months. Projects like <a href="">SVG Web</a> can only make the adoption easier. Different browsers support SVG text differently. But, as someone said, these are interesting times for SVG.</p>
<p class="meta">This post was posted by
<a href="/about.html">Divya Manian</a>
<time datetime="2009-09-19T00:00:00-07:00" pubdate><span class='month'>Sep</span> <span class='day'>19</span> <span class='year'>2009</span></time> in
<span class="categories">
<a class='category' href='/categories/web-development/'>Web Development</a>
. If you would like to update this post, <a href="">please send a pull request</a>.
<div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="">comments powered by Disqus.</a></noscript>
<aside id="articles">
<p><img class="avatar" src="/assets/divya.png" height=50> <a href="">Divya Manian</a> is a Web Developer in Seattle. <a href="/about.html">More about me ❭</a></p>
<h2>Posts on Web Development</h2>
<ul><li><a href="/html5please.html">html5please</a></li><li><a href="/mustache.html">mustache, hogan, handlebars</a></li><li><a href="/redesign-notes.html">Redesign Notes</a></li><li><a href="/summary-of-various-exciting-css-drafts-and-proposals.html">Summary of various exciting CSS drafts and proposals</a></li><li><a href="/this-revolution-needs-new-revolutionaries.html">This revolution needs new revolutionaries</a></li><li><a href="/some-css-transition-hacks.html">Some CSS Transition hacks</a></li><li><a href="/safe-css-defaults.html">Safe CSS Defaults</a></li><li><a href="/unplugged-2011.html">Unplugged 2011</a></li><li><a href="/bokeh-with-css3-gradients.html">Bokeh with CSS3 Gradients</a></li><li><a href="/making-pure-css3-demos-better.html">Making "Pure CSS3" demos better</a></li><li><a href="/web-opener-at-opera.html">Web Opener at Opera</a></li><li><a href="/current-color-in-css.html">Current Color in CSS</a></li><li><a href="/css-vocabulary.html">CSS Vocabulary</a></li><li><a href="/active-web-development.html">Active Web Development</a></li><li><a href="/sexy-css3-buttons.html">Sexy CSS3 Buttons</a></li><li><a href="/accessible-css-barcharts.html">Accessible CSS Barcharts</a></li><li><a href="/svg-is-coming.html">SVG is coming!</a></li><li><a href="/wee-marquee.html">Wee! Marquee</a></li><li><a href="/vignettes-with-css3-box-shadows.html">Vignettes with CSS3 Box Shadows</a></li><li><a href="/drop-shadows-with-css3.html">Drop Shadows with CSS3</a></li><li><a class="btn" href="/categories/web-development/">More</a></li></ul>
<footer role="contentinfo"><p>
Copy to your heart’s content 2012 - Divya Manian -
<span class="credit">Powered by <a href="">Octopress</a></span>
<script type="text/javascript">
var disqus_shortname = 'nimbublog';
var disqus_developer = 1;
var disqus_url = '';
var disqus_identifier = '';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
<script src="/javascripts/octopress.js"></script>
var _gaq=[['_setAccount','UA-97188-1'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];