-
Notifications
You must be signed in to change notification settings - Fork 8
/
about-fonts-in-svg.html
277 lines (163 loc) · 13.6 KB
/
about-fonts-in-svg.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!doctype html>
<!--[if lt IE 9]> <html class="no-js oldie" lang="en"> <![endif]-->
<head>
<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 …">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://nimbupani.github.com/about-fonts-in-svg.html">
<link href="/stylesheets/screen.css" rel="stylesheet">
<link href="http://feeds.feedburner.com/nimbupani" rel="alternate" title="Subscribe" type="application/atom+xml">
<link href="http://feeds.feedburner.com/nimbu" rel="alternate" title="Subscribe to Web Development updates" type="application/atom+xml">
</head>
<body >
<div class="container">
<div class="content">
<header role="banner"> <h1><a href="/">Divya Manian</a></h1>
<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>
</header>
<nav class="sitenav"><a href="/">Home</a>
<a href="/archives">Archives</a>
<a href="/about.html">About</a>
</nav>
<article>
<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>
</nav>
<header>
<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>
</header>
<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>
<h3>What is SVG?</h3>
<p></p>
<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>
<pre>
<svg width="12cm" height="4cm" viewBox="0 0 1200 400"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<desc>Example Circle</desc>
<circle cx="600" cy="200" r="100"
fill="red" stroke="none" stroke-width="0" />
</svg>
</pre>
<p>See <a href="/demo/svgfonts/circle.svg">the sample SVG</a>.</p>
<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>
<p></p>
<h3>The elephant in the room</h3>
<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’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>
<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>
<p></p>
<ul>
<li><p><em>Use web-safe fonts:</em> This is the easiest. An example:</p>
<pre><text x="100" y="100" style="font-family: impact, georgia, times, serif; font-weight: normal; font-style: normal">
Text using web safe font
</text>
</pre>
<p>See demo of <a href="/demo/svgfonts/svg-websafe.svg">SVG rendered with web-safe font</a></p>
</li>
<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>
<pre>
<defs>
<style type="text/css">
<![CDATA[
@font-face {
font-family: Delicious;
src: url('http://nimbupani.com/demo/svgfonts/delicious-roman.otf');
}
]]>
</style>
</defs>
<text x="100" y="100" style="font-family: 'Delicious'; font-weight:normal; font-style: normal">
Text using CSS @font-face
</text>
</pre>
<p>See a demo of <a href="/demo/svgfonts/svg-fontface.svg">SVG text rendered with CSS @font-face</a></p>
</li>
<li>
<p>
<em>Use fonts defined using SVG’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 “.svg” 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>
<ul>
<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>
<li><p><em>Embed font within the svg file:</em> Most Vector Graphic editors default to this option.</p></li>
</ul>
<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>
</li>
</ul>
<h3>Using SVG Fonts for HTML</h3>
<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>
<h3>Why use SVG fonts?</h3>
<ul>
<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 “id” 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="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>
<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>
</ul>
<h3>Disadvantages of SVG fonts</h3>
<ul>
<li>
<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>
<blockquote cite="http://www.w3.org/TR/SVG/fonts.html#SVGFontsOverview">
<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>
</blockquote>
</li>
<li>
<p>SVG support across browsers is still not consistent. The support for SVG fonts in HTML is even worse.</p>
</li>
</ul>
<h3>The Future</h3>
<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>
</div>
<footer>
<p class="meta">This post was posted by
<a href="/about.html">Divya Manian</a>
on
<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>
</span>
. 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>.
</p>
</footer>
</article>
<section>
<h1>Comments</h1>
<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>
</div>
</section>
</div>
</div>
<aside id="articles">
<p><img class="avatar" src="/assets/divya.png" height=50> <a href="http://twitter.com/divya">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>
</aside>
<footer role="contentinfo"><p>
Copy to your heart’s content 2012 - Divya Manian -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>
</footer>
<script type="text/javascript">
var disqus_shortname = 'nimbublog';
var disqus_developer = 1;
var disqus_url = 'http://nimbupani.com/about-fonts-in-svg.html';
var disqus_identifier = 'http://nimbupani.com/about-fonts-in-svg.html';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}());
</script>
<script src="/javascripts/octopress.js"></script>
<script>
var _gaq=[['_setAccount','UA-97188-1'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>