I'm adding multiple weights and styles of a single font to a font-face in a Rails project. I know that order matters here, ie. first define normal, then bold, then italic, then italic bold.
However, when I try to define normal first and then italic second, what shows up on my site by default is the italic version.
fonts.scss contains:
#font-face {
font-family: 'Sentinel Book';
src: font-url('sentinel-book-webfont.eot');
src: font-url('sentinel-book-webfont.eot?#iefix') format('embedded-opentype'),
font-url('sentinel-book-webfont.woff2') format('woff2'),
font-url('sentinel-book-webfont.woff') format('woff'),
font-url('sentinel-book-webfont.ttf') format('truetype'),
font-url('sentinel-book-webfont.svg#sentinelbook') format('svg');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'Sentinel Book';
src: font-url('sentinel-bookital-webfont.eot');
src: font-url('sentinel-bookital-webfont.eot?#iefix') format('embedded-opentype'),
font-url('sentinel-bookital-webfont.woff2') format('woff2'),
font-url('sentinel-bookital-webfont.woff') format('woff'),
font-url('sentinel-bookital-webfont.ttf') format('truetype'),
font-url('sentinel-bookital-webfont.svg#sentinelbook_italic') format('svg');
font-style: italic, oblique;
}
$font-family-serif: 'Sentinel Book', sans-serif;
$font-family-base: $font-family-serif;
Note that I'm using Bootstrap + SASS and overriding their variables, but still the default I'm seeing is italic:
If I rearrange the order in which the styles are defined (italic first, then norma), my text appears normal. But if I italicize anything (using <em> tags for example), the browser does its own italicization instead of using the italic version of the webfont loaded.
Any tips here would be appreciated!
The reason is that the declaration font-style: italic, oblique is syntactically malformed (see CSS 3 Fonts on font-style; only one keyword is allowed as the value). Change it to
font-style: italic;
It may sound surprising that the error in declaring the italic typeface causes all text to be rendered in italic. But the reason is that by CSS error handling rules, the incorrect declaration is ignored, so in this #font-face rule, font-style is defaulted to normal. This means that it will be applied to normal text; but the font file contains the italic typeface.
When you changed the order of the font-face rules, the latter rule that refers to the regular typeface will be used for normal text. Since there is no rule italic text, browsers will render italic text using regular typeface, applying algorithmic slantic (“faux italic”, “synthetic italic”) to it (usually; this in principle depends on browser).
The keywords italic and oblique mean the same thing in practice, though in theory they could have different meanings. But using them both in a font-style value makes the declaration syntactically invalid.
Related
The recommended code for including webfonts seems to be:
#font-face {
font-family: 'my_font';
src: url('my-font.eot');
src: url('my-font.eot?#iefix') format('embedded-opentype'),
url('my-font.woff2') format('woff2'),
url('my-font.woff') format('woff'),
url('my-font.ttf') format('truetype'),
url('my-font.svg#my_font') format('svg');
font-weight: normal;
font-style: normal;
}
As you may note, the name given to the font family is repeated in the URL pointing to the SVG font:
font-family: 'my_font'; <= "my_font"
url('my-font.svg#my_font') format('svg'); <= "my_font"
Now I don't like my font name to be lowercase and including an underscore. I want it to be "My Font":
font-family: 'My Font';
But then, how do I need to define the font-family name in the SVG url?
url('my-font.svg#My Font') format('svg');
url('my-font.svg#My%20Font') format('svg');
url('my-font.svg#my_font') format('svg');
And what is the purpose of the font-family name in that URL anyway?
After asking this question, I learned that:
a. TTF and WOFF are supported by all current browsers except Opera Mini (and Opera Mini doesn't support SVG fonts either), so no current browser needs SVG fonts.
b. Fonts have been dropped from the SVG2.2 specification in September 2015.
I have therefore removed SVG fonts from my websites and deleted the relevant line from the code given as a sample above. As a result, my question is outdated and no longer relevant.
The IRI scheme used in url('my-font.svg#my_font') is called a funcIRI and it's actually pointing to the element which has the id my_font inside the my-font.svg document.
I think you can name your font however you want in the font-family property, as long as your are pointing to the correct font IRI in the src one.
(In case of an SVG font, it needs to be pointing to a <font> element.)
The SVG fonts tutorial on the Mozilla Developer Network provides the following example:
<font id="Super_Sans">
<!-- and so on -->
</font>
<style type="text/css">
#font-face {
font-family: "Super Sans";
src: url(#Super_Sans);
}
</style>
<text font-family="Super Sans">My text uses Super Sans</text>
I've been using Source Sans Pro and Source Code Pro on my sites, and it looks great in Safari and Chrome. In Firefox, however, it looks like the wrong font weight is being used, as the weight is much lighter (and harder to read) in Firefox. My #font-face declarations look like this:
#font-face {
font-family: 'Source Sans Pro';
src: url('/fonts/sourcesanspro-regular-webfont.eot');
src: url('/fonts/sourcesanspro-regular-webfont.eot?#iefix') format('embedded-opentype'),
url('/fonts/sourcesanspro-regular-webfont.woff') format('woff'),
url('/fonts/sourcesanspro-regular-webfont.ttf') format('truetype'),
url('/fonts/sourcesanspro-regular-webfont.svg#source_sans_proregular') format('svg');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'Source Sans Pro';
src: url('/fonts/sourcesanspro-light-webfont.eot');
src: url('/fonts/sourcesanspro-light-webfont.eot?#iefix') format('embedded-opentype'),
url('/fonts/sourcesanspro-light-webfont.woff') format('woff'),
url('/fonts/sourcesanspro-light-webfont.ttf') format('truetype'),
url('/fonts/sourcesanspro-light-webfont.svg#source_sans_prolight') format('svg');
font-weight: lighter; // light
font-style: normal;
}
See the file for the full declaration. Is there something about my declarations that causes Firefox to select the wrong file when displaying the normal size?
As pointed out in this answer, it looks as though Firefox uses the last declared #font-face for a given style to display the content. The last face I had defined for the normal style had a weight of light, so that was the one Firefox used. The solution is to use the numeric weights in the #font-face declarations, as I have now done here. Then it properly uses the normal weight where appropriate.
Chrome and Safari use webkit as their rendering engine. (Chrome has now moved to Blink that uses a subset of webkit). Firefox on the other hand uses gecko. So yeah, that's pretty much the reason why we need to test webpages with different browsers.
As for your question, I guess this will help: http://css-tricks.com/forums/topic/font-rendering-ugly-in-firefox-but-beautiful-in-webkit/
I am using a custom font-family with following css rule:
#font-face {
font-family: 'matrix';
src: url('MaSGRgLn.eot');
src: url('MaSGRgLn.eot?#iefix') format('embedded-opentype'), url('MaSGRgLn.woff') format('woff'), url('MaSGRgLn.ttf') format('truetype'), url('MaSGRgLn.svg#MatrixScriptGr-RegularLin') format('svg');
font-weight: normal;
font-style: normal;
}
I have transformed my main font to all alternatives to be sure. Those work fine for all browsers except for ie < ie9. Is there sth i am missing or haven't paid attention to?
One important thing to note, based on my tests, is that the font-family name must match that what is inside the EOT file (viewable with hex-editor or if you have a matching TTF and Windows, the font preview will tell you).
IE8 does not display your font if the name differs, IE9 (even in IE8 mode) doesn't have this problem.
In your case, the SVG version has the name "MatrixScriptGr-RegularLin". Try using the same name in you CSS #font-face font-family definition.
Here's an example #font-face CSS rule:
#font-face {
font-family: 'DroidSerifBoldItalic';
font-weight: normal;
font-style: normal;
src: url('DroidSerif-BoldItalic-webfont.eot');
src: url('DroidSerif-BoldItalic-webfont.eot?#iefix') format('embedded-opentype'),
local('Droid Serif Bold Italic'), local('DroidSerif-BoldItalic'),
url('DroidSerif-BoldItalic-webfont.woff') format('woff'),
url('DroidSerif-BoldItalic-webfont.ttf') format('truetype');
}
Don't you think, the following #font-face CSS rule is better? (As you can see, the browsers, in this case even IE, can first check if the font is available on the user's computer, before downloading it.)
#font-face {
font-family: 'DroidSerifBoldItalic';
font-weight: normal;
font-style: normal;
src: local('Droid Serif Bold Italic'), local('DroidSerif-BoldItalic');
src: url('DroidSerif-BoldItalic-webfont.eot');
src: url('DroidSerif-BoldItalic-webfont.eot?#iefix') format('embedded-opentype'),
url('DroidSerif-BoldItalic-webfont.woff') format('woff'),
url('DroidSerif-BoldItalic-webfont.ttf') format('truetype');
}
Are there any gotchas here? If not, why isn't everyone using the latter?
From what i know about #font-face, the main fear behind using local is that the font will not be named the same on someone's desktop. You're ceding control there, and if you're wrong it'll fail. You do pose an interesting question though, and i'm not saying you're wrong. You can read more about that here and here.
ADDENDUM
Normally, it’s used as a mask to prevent unwanted http requests in IE.
The order matters because IE (at least until IE8) doesn't support the local descriptor, and placing the local descriptor right after the EOT font format prevents the older versions of Internet Explorer from downloading the other font formats (in the src declaration) as they aren't supported, and won't be used anyway.
What #BoltClock commented is true. And that's the reason why we use two local definitions -- local('Droid Serif Bold Italic'), local('DroidSerif-BoldItalic'),. The first is the normal name of the font (which is recognized by all browsers except Safari), and the latter is the PostScript name of the font which is required by Safari (at least on Mac / OS X systems).
To avoid issues like two different fonts (mostly on two different OSs) having the same name, some simply use local('☺').
Does anyone know how to use the Font Squirrel #font-face kit generator, or something similar, to output a variant of a font, i.e. the bold variant?
I am using Gill Sans on my website and it is set to "font-weight: 900" or "font-weight: bold," which looks great on my machine because it has the font installed. But if I just embed the font generated by Font Squirrel, I only get the "regular" variant and "bold" doesn't display correctly.
Does anyone know of a way to embed the bold variant of a font?
There is only one file for Gill Sans, and when I upload it, here is what Font Squirrel gave me:
#font-face {
font-family: 'GillSansRegular';
src: url('../fonts/gillsans-webfont.eot');
src: local('☺'), url('../fonts/gillsans-webfont.woff') format('woff'), url('../fonts/gillsans-webfont.ttf') format('truetype'), url('../fonts/gillsans-webfont.svg#webfontDATch26L') format('svg');
}
The original file no doubt contains the information for bold, italic, etc., but I'm wondering if Font Squirrel strips out the variants, leaving me with only the "regular" variant.
Even if I just add bold to everything it doesn't show up bold anywhere:
#font-face {
font-family: 'GillSansBold';
src: url('../fonts/gillsans-webfont.eot');
src: local('☺'), url('../fonts/gillsans-webfont.woff') format('woff'), url('../fonts/gillsans-webfont.ttf') format('truetype'), url('../fonts/gillsans-webfont.svg#webfontDATch26L') format('svg');
font-weight: bold;
}
Nothing is bold even when I strip all font-familys and font-weights from anywhere else in my stylesheets. Everything just shows up as Gill Sans Regular.
I just received an email from Font Squirrel: the generator doesn't split .dfont files in the current version, so that explains it.