Skip to content

Commit

Permalink
Remove autonym font and its usage
Browse files Browse the repository at this point in the history
I no longer maintain the Autonym font.
Also remove the tofu detection.

Bug: T135464
Bug: T135465
Change-Id: I103aab40ea5f5fc403a7ee5b23d1b634cc9c6ee1
  • Loading branch information
santhoshtr authored and Nikerabbit committed Nov 13, 2017
1 parent 679e587 commit 4f3461a
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 235 deletions.
2 changes: 1 addition & 1 deletion UniversalLanguageSelector.hooks.php
Expand Up @@ -188,7 +188,7 @@ public static function addPersonalBarTrigger( array &$personal_urls, &$title ) {
'uls' => [
'text' => Language::fetchLanguageName( $langCode ),
'href' => '#',
'class' => 'uls-trigger autonym',
'class' => 'uls-trigger',
'active' => true
]
] + $personal_urls;
Expand Down
Binary file removed data/fontrepo/fonts/Autonym/Autonym.ttf
Binary file not shown.
Binary file removed data/fontrepo/fonts/Autonym/Autonym.woff
Binary file not shown.
Binary file removed data/fontrepo/fonts/Autonym/Autonym.woff2
Binary file not shown.
6 changes: 0 additions & 6 deletions data/fontrepo/fonts/Autonym/font.ini

This file was deleted.

1 change: 0 additions & 1 deletion extension.json
Expand Up @@ -257,7 +257,6 @@
"ext.uls.webfonts.fonts": {
"dependencies": [
"jquery.webfonts",
"jquery.uls.data",
"ext.uls.webfonts.repository"
],
"localBasePath": "resources",
Expand Down
107 changes: 7 additions & 100 deletions resources/js/ext.uls.webfonts.js
Expand Up @@ -20,11 +20,7 @@
( function ( $, mw ) {
'use strict';

var ulsPreferences,
// Text to prepend the sample text. 0D00 is an unassigned unicode point.
tofuSalt = '\u0D00',
// cache languages with tofu.
tofuLanguages = {};
var ulsPreferences;

mw.webfonts = mw.webfonts || {};
ulsPreferences = mw.uls.preferences();
Expand Down Expand Up @@ -67,62 +63,6 @@
}
};

/**
* Detect tofu
*
* Create a temporary span in the page with fontsize 72px and font-family
* sans-serif for each letter of the text.
* For each of these spans, calculate the width and height. If they are same
* for all spans, we can understand that each of the letter is rendered using
* same glyph - it must be a tofu.
*
* @param {string} text
* @return {boolean}
*/
function detectTofu( text ) {
var index,
$fixture,
width = {},
height = {},
length = Math.min( 4, text.length ),
detected = false;

if ( $.client.test( {
msie: false
} ) ) {
// IE shows a different tofu for unassigned code points!
text = tofuSalt + text;
}
$fixture = $( '<span>' )
.css( {
fontSize: '72px',
fontFamily: 'sans-serif'
} )
.appendTo( 'body' );

for ( index = 0; index < length; index++ ) {
$fixture.text( text[ index ] );
width[ index ] = $fixture.width() || width[ index - 1 ];
height[ index ] = $fixture.height();

if ( index > 0 &&
( width[ index ] !== width[ index - 1 ] ||
height[ index ] !== height[ index - 1 ] )
) {
detected = false;
break;
}
}

$fixture.remove();

if ( index === length ) {
detected = true;
}

return detected;
}

mw.webfonts.setup = function () {
// Initialize webfonts
var mediawikiFontRepository = $.webfonts.repository;
Expand All @@ -143,7 +83,7 @@
* @return {string|null}
*/
fontSelector: function ( repository, language, classes ) {
var font, autonym, defaultFont;
var font, defaultFont;

if ( !language ) {
return null;
Expand All @@ -152,40 +92,15 @@
defaultFont = repository.defaultFont( language );

if ( classes && $.inArray( 'autonym', classes ) >= 0 ) {
autonym = true;
// Do not load font for showing autonym.
return null;
}

// If the user has a font preference, apply it always.
font = mw.webfonts.preferences.getFont( language );
if ( !font || autonym ) {
// Is there any default font for this language?
if ( ( !defaultFont || defaultFont === 'system' ) && !autonym ) {
return font;
}

// There is a default font for this language,
// but check whether the user sees tofu for it.
if ( tofuLanguages[ language ] === undefined ) {
tofuLanguages[ language ] = detectTofu( $.uls.data.getAutonym( language ) );

// Log the tofu detection only once per page per language
if ( tofuLanguages[ language ] ) {
mw.log( 'tofu detected for ' + language );
mw.hook( 'mw.uls.webfonts.tofudetected' ).fire( language );
}
}

if ( tofuLanguages[ language ] ) {
font = autonym ? 'Autonym' : defaultFont;
} else {
// No tofu and no font preference. Use system font.
font = 'system';
}
}

if ( font === 'system' ) {
font = mw.webfonts.preferences.getFont( language ) || defaultFont;
if ( !font || font === 'system' ) {
// Avoid setting 'system' as a font in css
font = null;
return null;
}

return font;
Expand Down Expand Up @@ -213,14 +128,6 @@
// property values set by stylesheets.
setTimeout( function () {
$( 'body' ).webfonts();

// Load the CSS required for the Autonym font. Note that this won't download the font.
// Browsers are smart enough to delay it till some element with this font-family
// becomes visible. For example: If there is a popup div with an element with class
// 'autonym', without explicitly calling .webfonts() on it, Autonym font will not
// be applied in general. But we ensure that the CSS is ready so that the font
// will be applied automatically to such future elements.
$( 'body' ).data( 'webfonts' ).load( 'Autonym' );
}, 0 );
};

Expand Down
11 changes: 1 addition & 10 deletions resources/js/ext.uls.webfonts.repository.js
@@ -1,4 +1,4 @@
// Do not edit! This file is generated from data/fontrepo by data/fontrepo/scripts/compile.php
// Do not edit! This file is generated from data/fontrepo by scripts/compile-font-repo.php
( function ( $ ) {
$.webfonts = $.webfonts || {};
$.webfonts.repository = {
Expand Down Expand Up @@ -306,10 +306,6 @@
"muk": [
"Jomolhari"
],
"mul": [
"system",
"Autonym"
],
"my": [
"TharLon",
"Myanmar3",
Expand Down Expand Up @@ -522,11 +518,6 @@
"woff": "Artaxerxes/Artaxerxes.woff?c1ed7",
"woff2": "Artaxerxes/Artaxerxes.woff2?7a96e"
},
"Autonym": {
"ttf": "Autonym/Autonym.ttf?d41f5",
"woff": "Autonym/Autonym.woff?235d8",
"woff2": "Autonym/Autonym.woff2?280d0"
},
"CharisSIL": {
"ttf": "CharisSIL/CharisSIL-R.ttf?20bec",
"woff": "CharisSIL/CharisSIL-R.woff?3a622",
Expand Down
117 changes: 0 additions & 117 deletions tests/autonym.html

This file was deleted.

0 comments on commit 4f3461a

Please sign in to comment.