Why does the display of a glyph depends on the browser? - html

The context
I wrote a home dashboard which, among others, provides a visual indication of the likelihood of rain in the next hour. If rain is expected, the 💧 symbol is displayed (with Open Sans), otherwise it is styled with filter: opacity(10%);.
In terms of code (HTML, CSS, Vue.js), it is displayed via
<span class="drop" :class="isDrop(horaires.first.rain, 2)">💧</span>
The dynamic class is calculated by
isDrop(rain, level) {
return rain >= level ? "full" : "empty"
}
and the class empty is
.empty {
filter: opacity(10%);
}
(the class full is not defined yet)
The problem
The drops look significantly different on my development environment (Windows 10, Chrome or Firefox)
and the actual dashboard (Raspberry Pi with Debian, Firefox)
Where does this discrepancy may come from?
the source of the page is the same in both cases
the font used on the page is explicitly loaded via #import url('https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800');
not only the filtered version is different (visoble in one case, invisible in the other) but even the non-styled drop looks different - despite being rendered with the same font.

That is because the font you use (Google Open Sans) doesn't include all the unicode glyphs, and more importantly for you, it doesn't include emojis.
So when the browser encounter these glyphs, it will fallback to one available on the system, and different browsers may use different order for choosing which font to use and you may indeed have different font used to represent the same glyph even on the same computer. However, you may be almost sure that different OS will have different fonts, and thus different rendering for these glyphs. Most modern browser's dev-tools allow you to verify which font are being used, check it to be sure which one are toggled on your system.
The solution is to use a web-font which does include these glyphs.
Google has a Noto font which does handle only emojis, Noto Emoji, but the color version is 8MB for only these emoji glyphs!. Saying this so that you understand it's not an easy thing to include these glyphs in any web-font.
There are other web-fonts that seem to exist, but all the free ones I can see are monochrome, so here I'll use Google's one for the example.
#font-face {
font-family: "NotoEmoji-Regular";
src: url("https://cdn.jsdelivr.net/gh/googlefonts/noto-emoji/fonts/NotoEmoji-Regular.ttf") format("truetype");
}
body {
font-family: "NotoEmoji-Regular";
}
💧
If you only have a small set of these emojis you'll use, you could probably make a fork of Google's one or of an other open font so it includes only the ones you need (and be lighter).
Or alternatively, if you have a good designer, you could make your own set of emojis and use a service like icomoon et al. to make your own font based on svg graphics.

Each browser has its own set of emojis. you can see diffrent emoji set here.
if you want an icon to be displayed the same way in every browser, you sould create an icon set and use svg.

Related

How to get uniform appearance of unicode (HTML entities) in all browsers

I'm developing a web application. It has buttons to control play/pause/stop etc. I chose to use unicode symbols as it seemed easier and more flexible than using images. The HTML for the buttons looks like this:
<button id="pauseButton">⏸</button>
<button id="playButton">⏵</button>
<button id="stopButton">⏹</button>
<button id="startButton">⏮</button>
<button id="rewindButton">⏪</button>
<button id="fastforwardButton">⏩</button>
<button id="endButton">⏭</button>
With some colour added via CSS, on Chrome/Ubuntu, this looks like this:
On Chrome/MacOS, like this:
On the Mac:
the play button is not rendering at all
it seems to be using images rather than characters, so the CSS colouring has no effect
to my taste, it looks horrible
I would like the buttons to be rendered the same on all platforms, and to look the way they do in Chrome/Ubuntu. But I don't undertand enough about what's going on.
Do I need to include a specific font in the application, and use that for the buttons?
If so, how do I find the font?
I have encoded the symbols as HTML entities. Should I be specifying them as unicode characters? Maybe that isn't even a valid question, but it demonstrates my current (lack of) understanding!
Are there browser settings that will foil attempts to make the buttons uniform (I'm thinking of font settings)?
As well as fixing my specific problem, I'd very much appreciate any pointers towards a better general understanding of this area.
Yes, you should use a specific font (search for webfonts). You will find the relevant information on how to use it (also in this site). You may need to try several fonts, to find what it appeal to you, and which includes all glyphs you want. Browsers will download the font (usually just a range), either from your site or from usual places, and display it. So you have full control.
On the other hand, uniform appearance is often a bad thing. If most webpages will display FastForward button in a similar way (and natively) on my specific computer/OS/browser, probably I would expect it. I do not really care how it will look on other computers. But it is very good to have uniform appearance if you look the uniform appearance of all elements in a page (which also requires controls on fonts). Prefer this latter uniform appearance.
Note: Unicode is just about semantics of a character, not about appearance (glyphs), so to control appearance, you need to use a specific font (something relatively new, but well supported by all browsers) or to use images (old method).
Thanks to #giacomo-catenazzi for pointing me towards webfonts. I found the following useful:
MDN Web fonts tutorial
fileformat.info for finding out which fonts have glyphs for particular unicodes
I downloaded the font from https://webfonts.ffonts.net/, but many other sources are available. MDN suggests fontsquirrel
Font squirrel web font generator - if you have a TTF or OTF font to convert into a webfont
I followed the instructions from MDN, and set up the newly created web font in the CSS:
#font-face {
font-family: 'Symbola';
src:url('fonts/Symbola.ttf.woff') format('woff'),
url('fonts/Symbola.ttf.svg#Symbola') format('svg'),
url('fonts/Symbola.ttf.eot'),
url('fonts/Symbola.ttf.eot?#iefix') format('embedded-opentype');
font-weight: normal;
font-style: normal;
}
body {
font-family: Symbola, sans-serif;
}
but this did not work.
There was one more hoop to jump through: It seems that font-family is not inherited by form elements, although I couldn't find reference to this in the specifications (but I assume it is there somewhere).
This was fixed by:
button {
font-family: inherit;
}

Hide text if font not available or fails to load in CSS/HTML

I am using the #font-face rule to create a font for a fictional language on my web pages. This works fine for full-featured desktop browsers, but some browsers, particularly mobile browsers, do not support loading fonts this way. The result is that my pages have weird encoded text on them if viewed via some browsers, which I would like to hide somehow.
There is no available alternative for this font, as it is not merely stylistic, but actually translates a character encoding system to the appropriate symbols.
What I would like to do is only display the text to which the fictional language's CSS class is applied if the browser is able to use #font-face, and otherwise, hide it via display: none; or some trick. However, I have been unable to find any method of doing this.
Alternatively, it would be acceptable to swap all the characters for some sort of "invalid character-character", as at least then the user will have some idea what they are looking at. However, the font is implemented using typical Latin letters as codes (0-9, a-Z), so merely failing to load the font does not already display them as invalid characters.
You may try Web Font Loader.
It will append the classes in HTML such as .wf-<familyname>-<fvd>-loading, .wf-<familyname>-<fvd>-active and .wf-<familyname>-<fvd>-inactive.
You can use CSS to hide on loading state.

vertical alignment some fonts

With some fonts have a problem. For example Neo Sans W1G. On different platforms, they have different vertical alignment.
On Linux and Mac OS font rises to the top, but on windows it looks fine. I'm testing on browsers chrome, safari and firefox.
Maybe someone else encountered this problem?
font-size: 48px;
line-height: 50px;
screenshot
http://imglink.ru/show-image.php?id=76735ce51bbdb8b7a11f4378c2e667c8
It's caused by font format history and Microsoft/Apple/Adobe format wars, different font formats included different metadata fields to compute line height, and the situation was "fixed" by allowing to declare all of them in later formats. (different metadata = different fields with different definitions, not same fields with different names)
Basically any software can pick and choose any of the line height computation algorithms as long as the corresponding metadata is present in the font. Unless the font creator was very careful with the values he put in this metadata all the algorithms won't produce the same value. Most font authoring tools will try to fill all the possible variants of metadata in order to "work" on as many platforms as possible. They rely on the font author to check the values they put there before release. Since most font creators only test a specific platform weird things happen when you try to use their fonts in a cross-platform context.
Likewise, depending on its original platform an app will prefer one algorithm over others for legacy compatibility reasons.
Some webfont platforms propose to "fix" legacy fonts but you need to have a license to modify the font files.
IIRC the typography CSS workgroup wanted to replace all of this with a new unified algorithm, I don't think they have finished yet and when they will have I'm not sure it will actually replace legacy methods instead of adding one more possibility to the mix.
Better, not to make your design depend on an exact value here.

Prevent browsers from using default/fallback fonts

I have a web app in which a user can change the font family of an input text area in a WSIWYG-kind style. Now, let's say the user inputs some Chinese text in the text area, but selects a Font that has no support for Chinese characters. In my application, I'd like the user to see those nasty squares (or something like that) that are usually shown when the font doesn't support the character. That way, the user would know that the font doesn't support the language and could choose a different one. The issue I'm having is that the browsers (Firefox 17 and Chrome 23) seem to render the Chinese part of the text with fonts (as Arial) that do support those Chinese characters, making the user believe that the font he's trying to use works fine.
Is there a way (I'm guessing through CSS) to prevent this? Is there a way of making the browsers not to be so "nice" for only this time?
Thank you in advance.
As the other answer already explained, the solution is to use a fallback font which includes 'all' unicode codepoints. However the difficult part was to find or built one which doesn't weight a few MBs.
A few years later there is now a more lightweight solution for a fallback font, the NotDef font by Adobe. It shows a box with a cross for 1,111,998 Unicode code points, is only about 22Kb and is using the SIL OPEN FONT LICENSE Version 1.1.
If you don't want to show anything there is also the Adobe Blank font.
You can intercept the font substitution process by throwing in a catchall font, using some equivalent of font-family: userChoice, yourCatchAll where yourCatchAll is a font that has a generic glyph for all characters.
The problem is in finding such a font. The LastResort font distributed by the Unicode Consortium would be ideal, since it also visually indicates the category of the character in broad terms, but its EULA does not seem to allow modifications. It is debatable whether this applies to the construction of web font formats (like .eot and .woff).
The Unicode BMP Fallback Font appears to have more liberal rules of use, but it displays a character simply as its Unicode number in a box (and supports only Basic Multilingual Plane, though it contains all characters that most people ever heard of).

HTML → / ← not displayed on some systems

I'm making heavy use of → / ← arrow symbols in HTML so that i spare myself the pain of having to go with images. This is for an enclosed system, not for a public website.
Now i noticed that my client does not have those symbols in their charsets somehow - and i am wondering why. Since i am using CSS to select the font, the charset should be the same, right? And the symbols should be available. But they are not. Instead they just get blanks.
The font in use is Verdana.
Since i am using CSS to select the font, the charset should be the same, right?
Not necessarily: The font might not be installed on every machine, and fonts can have different versions. You can't trust every client machine 100% to have exactly the font you need.
See this question for more background and approaches to determine font support for a specific glyph: Unicode support in Web standard fonts
The only way to make pretty sure the user has the correct font is to embed it into your web page using #font-face or using a hosted one by Google Web Fonts. In all browsers that support this method, you can then trust the same font to be delivered to every client.
However, embedding a font using font-face is tantamount to redistributing it, which most commercial licenses do not allow (see e.g. the Microsoft Typography FAQ). You would need to find a completely free font that allows redistribution this way - ideally one from Google's portfolio, or from a place like the Open Font Library.
These symbols are not included in Verdana. Use e.g. Arial, Times, Courier New, Garamond