Embedded fonts B and I not working on safari 3.2 - css

I have embedded fonts to my webpage and randomly in the divs i use font-style = italic and font-weight=700.
My #font-face rule is:
#font-face {
font-family: 'Arimo';
src: url('fonts/arimo_bold_italic.eot');
src: url('fonts/arimo_bold_italic.eot?#iefix') format('embedded-opentype'),url('fonts/arimo_bold_italic.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
Though the font-style and font-weight additions are working fine on all the browsers, it does not seem to work on Safari 3.2 giving weird results like the style and weight being applied only sometimes at random.
Any solution?

You are specifying the typeface as normal weight, regular (not italic). This is possible and often used to overcome some browser limitations, and it is also the way FontSquirrel uses in the CSS files it generates. But is has its implications.
In this case, font-family: Arimo alone produces bold italic Arimo, since this is how you have defined the name Arimo. To a browser, Arimo is just a normal-weight regular font, so if you ask, in CSS or indirectly e.g. via b or i markup, it to be used in bold face or italic, most browsers will use the font as such.
According to the CSS 2.1 font matching algorithm, when italic (or bold italic) is requested for, a regular face is not considered a match. This means that the browser should fall back to its default font, unless your rule specifies a secondary font. No browser actually does this: Safari produces “synthetic italic” by algorithmically slanting glyphs, whereas most other browsers just use the regular font (i.e., the font they regard as regular since it was declared that way). In CSS3, this is to be changed so that the behavior of most browsers becomes the norm.
So this is a messy business, and to avoid the mess, use one of these approaches:
a) Declare each font face as a family of its own, as regular and normal-weight, as you have done here, and do not apply font-weight values other than normal' orfont-stylevalues other thannormal` to text in such a font, directly or indirectly (note that many HTML elements produce italic or bold b default).
b) Declare each font face as a font in the family, with font-weight and font-style set in #font-face the logical way, and use the font family the normal way, declaring font-weight: bold when you want bold etc. This is how Google Web Fonts work, when hosted by Google.
P.S. It is odd that the `#font-face' rule does not mention a WOFF format file, which is the preferable format of downloadable fonts when a browser supports it. Generators normally produce it, too, and include it in the rule.

Related

using unicode_range to exclude numbers only

I'm using a custom font and loading it through #font-face. The text looks fine, but the numbers look screwy (only on chrome-windows, which is a very well know bug. And yes, I tried using the svg format for chrome, which solved the numbers but screwed the text). I decided to limit my own font to only [a-z][A-Z], and using this generator got this:
unicode-range: U+0041-U+005a, U+0061-U+007a;
And it seems to... not be working. Numbers are still being displayed using the font. How do I find the right range to use\some other solution? I'd love for a general solution, for example if I want to limit future fonts as well.
Thanks in advance!
P.s.
While I'm on the subject - I'm assuming there's no way to load the same font twice - using the .svg file for numbers and .otf for text, right? Because if possible that'd be awesome as well.
You can use #font-face rules to specify that a font family name (which is up to you to decide) is mapped to a specific font except for some character range, for which another font is used. This even works for local fonts, e.g. as follows:
<style>
#font-face {
font-family: foo;
src: local("Times New Roman");
}
#font-face {
font-family: foo;
src: local("Arial");
unicode-range: U+0030-0039;
}
p { font-family: foo }
</style>
<p>hello 123</p>
On supporting browsers, “hello” appears in Times New Roman (if available) but “123” in Arial (if available); the range U+0030-0039 is the common European digits 0 to 9.
You can use similar techniques for downloadable fonts.
The bad news is that unicode-range is not supported by Firefox or by IE 8 or earlier. They fail differently: for the code above, IE 8 uses Times New Roman, ignoring the latter #font-face rule, whereas current Firefox uses Arial, as if the unicode-range restriction were not there.
Finally, I used a "brute-force" method. Using Font Squirrel's webfont generator I recreated my font files, and using the advanced options > custom subsetting, I completely removed the numbers from the font.
Seems like a terrible solution, but the best I could find.

Web Fonts "Normal" font weight

Is it still reasonable to assume that font-weight:normal and font-weight:400 are equivalent even when using Web Fonts?
In the value of font-weight, normal by definition means 400. This does not depend on font.
Using #font-face, it is possible to cheat e.g. by declaring a font face as having normal weight (by defaulting font-weight, or by setting it to normal or 400) even though the typeface is in fact bold (or light or whatever). Fontsquirrel #font-face generator does this: it effectively defines each typeface as a font family. Example:
/* Generated by Font Squirrel (http://www.fontsquirrel.com) on January 22, 2013 */
#font-face {
font-family: 'source_sans_probold';
src: url('sourcesanspro-bold-webfont.eot');
src: url('sourcesanspro-bold-webfont.eot?#iefix') format('embedded-opentype'),
url('sourcesanspro-bold-webfont.woff') format('woff'),
url('sourcesanspro-bold-webfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
This means that an element may have the font-weight value of 400, even though the typeface actually used is bold design.
This is not in any way related to the use of 400 vs. normal, and it’s not just the font weight. FontSquirrel plays the same game with font-style.
This may not be the definitive answer but it will have to do for now - I went through the whole current set of 617 fonts on Google Web Fonts. From what I can see Normal is always 400. All current fonts specifiy Normal, 400.
The one thing I should add - there are some WOFF fonts, e.g. Open Sans Condensed, which do not in fact have a "Normal" style at all. However, this should not break the assumption of Normal = 400.
Here is an interesting gotcha with Chrome. It silently replaces font-weight:700 with font-weight:bold. It doesn't try to do that with the other font weights. Even so if you are relying on numeric values it is best to put in a silent test that does the requisite replacements. Something along the lines of
var sample = $('#fontSampleA');
var fontwt = sample.css('font-weight');
fontwt = ('normal' == fontwt)?400:(('bold' == fontwt)?700:(('book' == fontwt)?300:fontwt));
just in case a future version starts trying to do more silent "smart conversions".

Fallback fonts on special characters

I was wondering if it's possible to, when using #font-face, have a fallback setup so that if the text on my page contains characters that are not accounted for within the font (Japanese characters for example), only those characters are presented in a basic font and every other character remains as the custom font?
I'm imagining that potentially there'd be a mix of two fonts within one paragraph on occasion.
What you described is the default behaviour of a browser - it should naturally fall back to basic font for missing characters.
However, sometimes custom fonts use blank characters, in that case you can try using the unicode-range
For example:
#font-face {
font-family: BBCBengali;
src: url(fonts/BBCBengali.ttf) format("opentype");
unicode-range: U+00-FF;
}
Taken from this interesting article: Creating Custom Font Stacks with Unicode-Range
Unfortunatelly there are browser support issues.
CSS has default fallback to the system font if the specified font doesn't contain a character.
You can also specify which font to fall back to.
Example for a serif font:
body {
font-family: "MyNiceFontWithoutJapanesChars", "common serif font", serif;
}
As long as the fallback font has those characters your default font misses, you should be all right.

How do I set 'semi-bold' font via CSS? Font-weight of 600 doesn't make it look like the semi-bold I see in my Photoshop file

I'm doing a Photoshop-to-XHTML conversion, and the website designer used the Myriad Pro Semi-bold font which looks good in the photoshop file, but when I try the semi-bold option in CSS, it looks pretty much like a normal bold font, which is too bold for my purpose. Is there a way to achieve a nicer looking semi-bold font in HTML and CSS or am I just stuck with 'font-weight: 600;'?
In CSS, for the font-weight property, the value: normal defaults to the numeric value 400, and bold to 700.
If you want to specify other weights, you need to give the number value. That number value needs to be supported for the font family that you are using.
For example you would define semi-bold like this:
font-weight: 600;
Here an JSFiddle using 'Open Sans' font family, loaded with the above weights.
The practical way is setting font-family to a value that is the specific name of the semibold version, such as
font-family: "Myriad pro Semibold"
if that’s the name. (Personally I use my own font listing tool, which runs on Internet Explorer only to see the fonts in my system by names as usable in CSS.)
In this approach, font-weight is not needed (and probably better not set).
Web browsers have been poor at implementing font weights by the book: they largely cannot find the specific weight version, except bold. The workaround is to include the information in the font family name, even though this is not how things are supposed to work.
Testing with Segoe UI, which often exists in different font weight versions on Windows systems, I was able to make Internet Explorer 9 select the proper version when using the logical approach (of using the font family name Segoe UI and different font-weight values), but it failed on Firefox 9 and Chrome 16 (only normal and bold work). On all of these browsers, for example, setting font-family: Segoe UI Light works OK.
For me the following works good. Just add it. You can edit it as per your requirement. This is just a nice trick I use.
text-shadow : 0 0 0 #your-font-color;
font-family: 'Open Sans'; font-weight: 600; important to change to a different font-family
By mid-2016 the Chromium engine (v53) supports just 3 emphasis styles:
Plain text, bold, and super-bold...
<div style="font:normal 400 14px Arial;">Testing</div>
<div style="font:normal 700 14px Arial;">Testing</div>
<div style="font:normal 800 14px Arial;">Testing</div>
Select fonts by specifying the weights you need on load
Font-families consist of several distinct fonts
For example, extra-bold will make the font look quite different in say, Photoshop, because you're selecting a different font. The same applies to italic font, which can look very different indeed. Setting font-weight:800 or font-style:italic may result in just a best effort of the web browser to fatten or slant the normal font in the family.
Even though you're loading a font-family, you must specify the weights and styles you need for some web browsers to let you select a different font in the family with font-weight and font-style.
Example
This example specifies the light, normal, normal italic, bold, and extra-bold fonts in the font family Open Sans:
<html>
<head>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Open+Sans:100,400,400i,600,800">
<style>
body {
font-family: 'Open Sans', serif;
font-size: 48px;
}
</style>
</head>
<body>
<div style="font-weight:400">Didn't work with all the fonts</div>
<div style="font-weight:600">Didn't work with all the fonts</div>
<div style="font-weight:800">Didn't work with all the fonts</div>
</body>
</html>
Reference
(Quora warning, please remove if not allowed.)
https://www.quora.com/How-do-I-make-Open-Sans-extra-bold-once-imported-from-Google-Fonts
Testing
Tested working in Firefox 66.0.3 on Mac and Firefox 36.0.1 in Windows.
Non-Google fonts
Other fonts must be uploaded to the server, style and weight specified by their individual names.
System fonts
Assume nothing, font-wise, about what device is visiting your website or what fonts are installed on its OS.
(You may use the fall-backs of serif and sans-serif, but you will get the font mapped to these by the individual web browser version used, within the fonts available in the OS version it's running under, and not what you designed.)
Testing should be done with the font temporarily uninstalled from your system, to be sure that your design is in effect.

Same font renders differently across FF7 and Chrome

Screenshot: http://i.imgur.com/QVBGx.png
It is pretty evident that my site renders different on Chrome and FF7 on my Win7 machine
I am using this:
h1, h2 {font-family: "Lucida Grande", "Helvetica Neue", Arial; }
Does anybody can point me how can I even these diffs? I don't want fonts with different 'feelings' on each browser.
The font, Lucida Grande is installed in my Windows machine
EDIT:
font-weight: normal !important
doesn't work either
It looks like the two browsers are rendering it with a different weight.
I can think of two possibilities, though I don't know if either are correct.
You requested a bold font, but that font is not available in bold. One browser is just showing the regular, non-bold variant unchanged, whereas the other has processed it to look bold.
You requested a particular weight of font, say "bold" or "600" but the installed fonts do not precisely match that weighting. One browser is substituting an "extra-bold" variant of font, and the other a "regular-bold", or something of this nature.
If either of these is correct you could play around with the font-weight CSS property to try and alter it. But then that may affect substitution of whichever font is chosen in the case that it is viewed on a system with no Lucida Grande font at all.
Fonts will always render slightly different from one browser to another, but that was a bit more difference than usual. Probably because the headers have font-weight: bold; as default, and the font doesn't have a bold variation so the browsers create the bold style from the regular weight in different ways.
Anyway, you might want to use more common fonts. On my Windows 7 machine there is neither Lucida Grande nor Helvetica Neue, so it would render using Arial. Still, I have the additional fonts that come with both MS Office and Photoshop, so I have a lot more fonts installed than you can expect from a standard system.
Also, you should always specify a generic font as the last resort, in this case sans serif, otherwise it would render using the default font if none of the fonts are installed, which is something like Times Roman which has a completely different look. Perhaps also adding Helvetica, which is the closest equivalent of Arial on non-Windows systems.

Resources