Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

I'm new to SVGs, and just made my first decent graphic in Illustrator. I've embedded it into a page with the GWF script for the Ubuntu font in the tag. As it turns out, the Ubuntu font displays correctly in regular text, but for this trick to work in the SVG, the Google script has to be embedded in the SVG itself. How can I do this?

share|improve this question
    
Out of curiosity, why would you? –  DA01 Dec 27 '11 at 18:18
2  
I'm writing an article on my site about the advantages of new web technologies, among others HTML5, CSS3 and SVGs, one of the advantages of the latter being the ability to select text in what is otherwise effectively an image. –  Jules Mazur Dec 27 '11 at 21:19
1  
Ah. I can see uses for that! Good point. –  DA01 Dec 27 '11 at 21:34

3 Answers 3

up vote 10 down vote accepted

You embed fonts in CSS by using base64 encoding. You can apply styles in SVG documents similar to CSS by using a <style /> element. So if you have a WOFF font, you'd embed it like this:

<style>
@font-face {
    font-family: "Sample font";
    src: url("data:application/font-woff;charset=utf-8;base64,...");
}
</style>

Where ... is the base64 encoded font data.

You can find examples of this by looking at Typekit's stylesheets. I'm not sure if the mime type of font/woff is correct, as I've also seen people claim that it should be application/font-woff. Though font/woff, font/truetype, font/opentype, etc. seem to be more popular.

Alternatively, you could actually take the SVG version of the web font and embed the SVG font's description markup inside of your document.

However, you should also be able to link to an external font according to the SVG specification. That would seem to be the best solution if you're gonna have multiple SVG documents referencing that font.

share|improve this answer
    
@Verandaguy: You can either put in a separate CSS file just like you would an HTML document, or you can embed it in a <style> element like so. –  Lèse majesté Dec 23 '11 at 4:57
    
@Verandaguy: I don't see a <style> element anywhere in that SVG document. –  Lèse majesté Dec 23 '11 at 16:23
    
@Verandaguy: A few problems here. First off, FontSquirrel generated a bunch of CSS for embedding all the different styles of Ubuntu (e.g. bold and italic), and it used 'UbuntuRegular' as the font-family name for the regular version. I removed all the unused fonts, leaving just UbuntuRegular and renamed that to Ubuntu to match the font name you used later in your document. Secondly, there was an extra </svg> right after the style definitions. So everything after that was treated as junk data. Once I removed that, it worked fine. –  Lèse majesté Dec 23 '11 at 18:53
1  
The correct MIME-type for .woff is now application/font-woff. stackoverflow.com/a/5142316/90674 –  stigok Dec 10 '13 at 13:09

A <defs> section like

<defs>
  <style type="text/css">@import url(http://fonts.googleapis.com/css?family=Indie+Flower);</style>
</defs>

works.

share|improve this answer

This may be over simplifying, but have you considered downloading the font as a zip file from google and then letting Illustrator convert it as needed into your SVG file output?

This is only theoretical as I haven't tried this yet, but in theory would seem to work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.