Detect tofu before applying any default fonts

To detect whether the client can render a given string,
use a tofu detection algorithm.

If the user has an explicit font preference, do not override it.

If the user has no preference and there is a default font for a
language, see if that language can be rendered at the user's browser
using tofu detection.

If tofu is detected, apply the font.

If the element has 'autonym' class, apply Autonym font only when
that language has tofu.

Change-Id: Ib9ee9497e6bcfa7eb86f7d264e0980d8880d6b70
This commit is contained in:
Santhosh Thottingal
2014-01-17 16:36:25 +05:30
parent f7066d4d2a
commit 1113786330
5 changed files with 110 additions and 21 deletions

View File

@@ -58,13 +58,14 @@
/**
* Get the default font family for given language.
* @param {String} language Language code.
* @param {array} classes
* @return {String} Font family name
*/
getFont: function( language ) {
getFont: function( language, classes ) {
language = ( language || this.language ).toLowerCase();
if ( this.options.fontSelector ) {
return this.options.fontSelector( this.repository, language );
return this.options.fontSelector( this.repository, language, classes );
} else {
return this.repository.defaultFont( language );
}
@@ -199,7 +200,6 @@
// Note: it depends on the browser whether this returns font names
// which don't exist. In Chrome it does, while in Opera it doesn't.
fontFamilyStyle = $element.css( 'fontFamily' );
// Note: It is unclear whether this can ever be falsy. Maybe also
// browser specific.
if ( fontFamilyStyle ) {
@@ -220,7 +220,7 @@
// browser settings.
return;
} else {
fontFamily = webfonts.getFont( element.lang );
fontFamily = webfonts.getFont( element.lang, element.className.split(/\s+/) );
}
if ( !fontFamily ) {
@@ -269,8 +269,8 @@
// whether the font is inherited from top element to which plugin applied
return this.$element.css( 'fontFamily' ) !== elementFontFamily
// whether the element has generic font family
&& ( $.inArray( elementFontFamily,
// whether the element has generic font family
&& ( $.inArray( elementFontFamily,
['monospace', 'serif', 'cursive','fantasy', 'sans-serif'] ) < 0 );
},