Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 280 lines (165 sloc) 14.015 kb
601f25c Site updated at 2012-06-02 22:06:16 UTC
Divya Manian authored
1
2 <!doctype html>
3 <!--[if lt IE 9]> <html class="no-js oldie" lang="en"> <![endif]-->
4 <head>
5 <meta charset="utf-8">
6 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
7 <title>About Fonts in SVG | Divya Manian</title>
8 <meta name="author" content="Divya Manian">
9
10 <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;">
11
12
13 <meta name="viewport" content="width=device-width, initial-scale=1">
14
15
16 <link rel="canonical" href="http://nimbupani.github.com/about-fonts-in-svg.html">
17 <link href="/stylesheets/screen.css" rel="stylesheet">
18 <link href="http://feeds.feedburner.com/nimbupani" rel="alternate" title="Subscribe" type="application/atom+xml">
19 <link href="http://feeds.feedburner.com/nimbu" rel="alternate" title="Subscribe to Web Development updates" type="application/atom+xml">
20
21 </head>
22
23
24 <body >
25 <div class="container">
26 <div class="content">
27 <header role="banner"> <h1><a href="/">Divya Manian</a></h1>
28
29 <h2><a class="twitter" href="https://twitter.com/divya">twitter</a> <a class="rss" href="http://feeds.feedburner.com/nimbupani">RSS Feed</a> <a class="youtube" href="http://youtube.com/nimbupani">Youtube Channel</a> <a class="github" href="https://github.com/nimbupani">Github</a></h2>
30
31 </header>
32 <nav class="sitenav"><a href="/">Home</a>
33 <a href="/archives">Archives</a>
34 <a href="/about.html">About</a>
35 </nav>
36
37
38
39
40
41
42
43
44 <article>
45 <nav class="article">
46
5dc1495 Site updated at 2012-06-26 03:50:17 UTC
Divya Manian authored
47 <a class="previous" href="/book-reviews-for-september-2009.html" title="Book Reviews for September 2009">&#x276C;</a>
601f25c Site updated at 2012-06-02 22:06:16 UTC
Divya Manian authored
48
49
5dc1495 Site updated at 2012-06-26 03:50:17 UTC
Divya Manian authored
50 <a class="next" href="/book-reviews-for-october-2009.html" title="Book Reviews for October 2009">&#x276D;</a>
601f25c Site updated at 2012-06-02 22:06:16 UTC
Divya Manian authored
51
52
53
54 </nav>
55 <header>
56
57
58
59
60
61
62
63 <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>
64
65 <h1 class="entry-title"><a href="/about-fonts-in-svg.html">About Fonts in SVG</a></h1>
66
67
68
69
70 </header>
71 <div class="entry-content"><p>One area in my <a href="http://nimbupani.com/blog/font-in-your-face.html" title="Font in your face | Nimbupani Designs">webfonts investigation</a> that I wanted to know more about, was the state of SVG fonts.</p>
72
73
74 <h3>What is SVG?</h3>
75
76
77 <p></p>
78
79 <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="http://www.w3.org/Graphics/SVG/WG/wiki/Secret_Origin_of_SVG">the history of SVG</a>). SVG uses XML to describe 2D graphics. So, a circle is defined in SVG as:</p>
80
81
82
83
84 <pre>
85 &lt;svg width=&quot;12cm&quot; height=&quot;4cm&quot; viewBox=&quot;0 0 1200 400&quot;
86 xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot;&gt;
87 &lt;desc&gt;Example Circle&lt;/desc&gt;
88 &lt;circle cx=&quot;600&quot; cy=&quot;200&quot; r=&quot;100&quot;
89 fill=&quot;red&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; /&gt;
90 &lt;/svg&gt;
91 </pre>
92
93
94
95
96 <p>See <a href="/demo/svgfonts/circle.svg">the sample SVG</a>.</p>
97
98
99 <p>You can convert almost any <a href="http://en.wikipedia.org/wiki/Vector_graphics" title="Vector graphics - Wikipedia, the free encyclopedia">vector graphic</a> to SVG format (here is <a href="http://help.adobe.com/en_US/Illustrator/14.0/WS714a382cdf7d304e7e07d0100196cbc5f-655ba.html">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>
100
101
102 <p></p>
103
104 <h3>The elephant in the room</h3>
105
106
107 <p>Before I proceed, I must mention that <a href="http://www.rustybrick.com/svg-support-for-internet-explorer.html">IE (even IE 8) does not support SVG</a>. <a href="http://ie.microsoft.com/testdrive/info/ReleaseNotes/Default.html">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="https://developer.mozilla.org/En/SVG_in_Firefox">Firefox</a>, or <a href="http://webkit.org/projects/svg/index.html">Safari</a> either (see <a href="http://www.codedread.com/svg-support.php" title="SVG Support in major browsers">this excellent chart of SVG support on various browsers</a>). Google has released <a href="http://code.google.com/p/svgweb/">SVG Web</a> which allows SVG to be rendered on all browsers that support either SVG or Flash.</p>
108
109
110 <h3>Fonts in SVG</h3>
111
112
113 <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>
114
115
116 <p></p>
117
118 <ul>
119 <li><p><em>Use web-safe fonts:</em> This is the easiest. An example:</p>
120 <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;
121 Text using web safe font
122 &lt;/text&gt;
123 </pre>
124 <p>See demo of <a href="/demo/svgfonts/svg-websafe.svg">SVG rendered with web-safe font</a></p>
125 </li>
126 <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="http://hacks.mozilla.org/2009/06/beautiful-fonts-with-font-face/" title="beautiful fonts with @font-face at hacks.mozilla.org">HTTP header to allow cross-site linking</a>). </p>
127 <pre>
128 &lt;defs&gt;
129 &lt;style type=&quot;text/css&quot;&gt;
130 &lt;![CDATA[
131 @font-face {
132 font-family: Delicious;
133 src: url(&#x27;http://nimbupani.com/demo/svgfonts/delicious-roman.otf&#x27;);
134 }
135 ]]&gt;
136 &lt;/style&gt;
137 &lt;/defs&gt;
138 &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;
139 Text using CSS @font-face
140 &lt;/text&gt;
141 </pre>
142 <p>See a demo of <a href="/demo/svgfonts/svg-fontface.svg">SVG text rendered with CSS @font-face</a></p>
143 </li>
144 <li>
145 <p>
146 <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="http://devfiles.myopera.com/articles/751/SVGfonts_in_HTML.html">some examples of SVG fonts</a>. There are two ways of using SVG Fonts: </p>
147 <ul>
148 <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>
149 </li>
150 <li><p><em>Embed font within the svg file:</em> Most Vector Graphic editors default to this option.</p></li>
151 </ul>
152 <p><a href="http://purl.org/NET/2008,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>
153 </li>
154 </ul>
155
156
157 <h3>Using SVG Fonts for HTML</h3>
158
159
160 <p>Using the CSS <a href="http://nimbupani.com/blog/font-in-your-face.html">@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="http://devfiles.myopera.com/articles/593/SVGfonts_in_HTML.html" title="Web fonts example">see a demo of SVG Fonts in HTML</a>). There is a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=119490">bug filed for Firefox</a> but no fix yet.</p>
161
162
163 <h3>Why use SVG fonts?</h3>
164
165
166 <ul>
167 <li><em>Universal support:</em> Any conforming SVG viewer will render the text in the SVG font specified.</li>
168 <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>
169 <li><em>Open Source:</em> The font file is completely open. If <a href="http://www.w3.org/TR/SVG/fonts.html#MissingGlyphElement">the font you are using is missing glyphs</a> you can add the glyph you need.</li>
170 <li><em>Chrome Support:</em> (Thanks for this suggestion <a href="http://twitter.com/paul_irish">@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>
171 </ul>
172
173
174 <h3>Disadvantages of SVG fonts</h3>
175
176
177 <ul>
178 <li>
179 <p>The main drawback to SVG fonts is there is no provision for <a href="http://en.wikipedia.org/wiki/Font_hinting">font-hinting</a>. The SVG standard states:</p>
180 <blockquote cite="http://www.w3.org/TR/SVG/fonts.html#SVGFontsOverview">
181 <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>
182 </blockquote>
183 </li>
184 <li>
185 <p>SVG support across browsers is still not consistent. The support for SVG fonts in HTML is even worse.</p>
186 </li>
187 </ul>
188
189
190 <h3>The Future</h3>
191
192
193 <p>SVG has gained a lot of traction in the recent months. Projects like <a href="http://code.google.com/p/svgweb/">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>
194
195 </div>
196
197 <footer>
198 <p class="meta">This post was posted by
199
200
201 <a href="/about.html">Divya Manian</a>
202 on
203
204
205
206
207
208
209 <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
210
211 <span class="categories">
212
213 <a class='category' href='/categories/web-development/'>Web Development</a>
214
215 </span>
216
217 . If you would like to update this post, <a href="https://github.com/nimbupani/nimbupani.github.com/blob/source/source/_posts/2009-09-19-about-fonts-in-svg.md">please send a pull request</a>.
218 </p>
219 </footer>
220 </article>
221
222 <section>
223 <h1>Comments</h1>
224 <div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
225 </div>
226 </section>
227
228
229 </div>
230 </div>
231 <aside id="articles">
232 <p><img class="avatar"
233 src="http://a2.twimg.com/profile_images/1696865113/me_normal"
234 height=48> <a href="http://twitter.com/divya">Divya Manian</a> is a Web Developer in Seattle. <a href="/about.html">More about me ❭</a></p>
235 <h2>Posts on Web Development</h2>
2db5cff Site updated at 2012-06-18 17:59:15 UTC
Divya Manian authored
236 <ul><li><a href="/css-object-model.html">CSS Object Model</a></li><li><a href="/fake-bolding-of-web-fonts.html">Fake Bolding of Web Fonts</a></li><li><a href="/html5please-api.html">Html5please API</a></li><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 class="btn" href="/categories/web-development/">More</a></li></ul>
601f25c Site updated at 2012-06-02 22:06:16 UTC
Divya Manian authored
237 </aside>
238 <footer role="contentinfo"><p>
239 Copy to your heart’s content 2012 - Divya Manian -
240 <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
241 </p>
242
243
244 </footer>
245
246
247 <script type="text/javascript">
248 var disqus_shortname = 'nimbublog';
249 var disqus_developer = 1;
250
251
252 var disqus_url = 'http://nimbupani.com/about-fonts-in-svg.html';
253 var disqus_identifier = 'http://nimbupani.com/about-fonts-in-svg.html';
254
255
256
257
258 (function () {
259 var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
260 dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
261 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
262 }());
263 </script>
264
265
266 <script src="/javascripts/octopress.js"></script>
267
268 <script>
269 var _gaq=[['_setAccount','UA-97188-1'],['_trackPageview']];
270 (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
271 g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
272 s.parentNode.insertBefore(g,s)}(document,'script'));
273 </script>
274
275
276
277
278 </body>
279 </html>
Something went wrong with that request. Please try again.