Font Embedding Woes...

Permalink
I added a folder called 'fonts' to my theme folder. I tried to embed the font in typography.css with this code but it does not work:

@font-face {
font-family: 'MyCoolFont';
src: url('fonts/my_cool_font.eot');
src: url('fonts/my_cool_font.woff') format('woff'),
url('fonts/my_cool_font.ttf') format('truetype'),
url('fonts/my_cool_font.svg') format('svg');
font-weight: normal;
font-style: normal;
}

If, however, I include the complete path to the font, it does:

@font-face {
font-family: 'MyCoolFont';
src: url('http://www.mywebsite.com/themes/mytheme/fonts/my_cool_font.eot');
src: url('http://www.mywebsite.com/themes/mytheme/fonts/my_cool_font.woff') format('woff'),
url('http://www.mywebsite.com/themes/mytheme/fonts/my_cool_font.ttf') format('truetype'),
url('http://www.mywebsite.com/themes/mytheme/fonts/my_cool_font.svg') format('svg');
font-weight: normal;
font-style: normal;
}

How do I fix this issue? I don't want the full path in the style sheet like that. Thanks!

 
madeforspace replied on at Permalink Reply
madeforspace
You have probably tried this already but try adding a / in front of src: url(/fonts.....etc
orourkedd replied on at Permalink Reply
Yeah, already tried :-( Thanks though.
Steevb replied on at Permalink Reply
Steevb
Hi,

Perhaps you should try calling from the theme path as with other files:

<?=$this->getThemePath()?>/
orourkedd replied on at Permalink Reply
Unfortunately, PHP cannot be executed inside a CSS file... (or can it?) Anyway, I tried it and it didn't work.
aghouseh replied on at Permalink Best Answer Reply
aghouseh
I've always done relative pathing for the font URLs, but one thing I did notice with C5 is that I've had to remove the inner quotes around the font URL.

src: url(fonts/my_cool_font.eot);


Repeat for all the font face URLs. Give that a whirl and let us know how it goes.
orourkedd replied on at Permalink Reply
Tried it... didn't work for me.

EDIT
I think I was trying /fonts/... or something

It turns out that C5 does not work when there are quotes around it. In fact, it actually takes the CSS file, moves it to a new location, and goes through and turns all url(some/path.asset) to url(http://www.mysite.com/some/path.asset). Didn't expect that!
Steevb replied on at Permalink Reply
Steevb
Did you try:

<link rel="stylesheet" type="text/css" href="<?=$this->getThemePath()?>/fonts/typography.css">
adamjohnson replied on at Permalink Reply
adamjohnson
I had to include the full path to the font, without quotes, after the src:...

So it would be something like url(http://my.url/font/myfont.eot) . That should do it for you. After that, reference the font in your CSS exactly the same way it's referenced at the beginning of the @font-face declaration.

Edit: Just saw the bit about no full path. Doesn't make sense why /my/path/font.eot wouldn't work. Let us know what you find.
mario replied on at Permalink Reply
mario
yup, had my @fontface fonts disappear right after I upgraded a site from 5.4.1.1 to 5.4.2. switched to getThemePath and things are fine again. I have to use this method sometimes when trying to get SSL to validate for c5 ecommerce. I guess I'll need to switch over to use it now on everything just in case.