|
| 1 | +import assert from 'assert'; |
| 2 | + |
| 3 | +import fontkit from '../src'; |
| 4 | + |
| 5 | +describe('i18n', function() { |
| 6 | + describe('fontkit.setDefaultLanguage', function () { |
| 7 | + let font; |
| 8 | + before('load Amiri font', function() { |
| 9 | + font = fontkit.openSync(__dirname + '/data/amiri/amiri-regular.ttf'); |
| 10 | + }); |
| 11 | + after('reset default language', function () { |
| 12 | + fontkit.setDefaultLanguage(); |
| 13 | + }); |
| 14 | + |
| 15 | + |
| 16 | + it('font has "en" metadata properties', function() { |
| 17 | + assert.equal(font.fullName, 'Amiri'); |
| 18 | + assert.equal(font.postscriptName, 'Amiri-Regular'); |
| 19 | + assert.equal(font.familyName, 'Amiri'); |
| 20 | + assert.equal(font.subfamilyName, 'Regular'); |
| 21 | + assert.equal(font.copyright, 'Copyright (c) 2010-2017, Khaled Hosny <khaledhosny@eglug.org>.\nPortions copyright (c) 2010, Sebastian Kosch <sebastian@aldusleaf.org>.'); |
| 22 | + assert.equal(font.version, 'Version 000.110 '); |
| 23 | + }); |
| 24 | + |
| 25 | + it('can set global default language to "ar"', function () { |
| 26 | + fontkit.setDefaultLanguage('ar'); |
| 27 | + assert.equal(fontkit.defaultLanguage, 'ar'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('font now has "ar" metadata properties', function() { |
| 31 | + assert.equal(font.fullName, 'Amiri'); |
| 32 | + assert.equal(font.postscriptName, 'Amiri-Regular'); |
| 33 | + assert.equal(font.familyName, 'Amiri'); |
| 34 | + assert.equal(font.subfamilyName, 'عادي'); |
| 35 | + assert.equal(font.copyright, 'حقوق النشر 2010-2017، خالد حسني <khaledhosny@eglug.org>.'); |
| 36 | + assert.equal(font.version, 'إصدارة 000٫110'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('can reset default language back to "en"', function () { |
| 40 | + fontkit.setDefaultLanguage(); |
| 41 | + assert.equal(fontkit.defaultLanguage, "en"); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('font.setDefaultLanguage', function () { |
| 46 | + let font; |
| 47 | + before('load Amiri font', function () { |
| 48 | + font = fontkit.openSync(__dirname + '/data/amiri/amiri-regular.ttf'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('font has "en" metadata properties', function() { |
| 52 | + assert.equal(font.fullName, 'Amiri'); |
| 53 | + assert.equal(font.postscriptName, 'Amiri-Regular'); |
| 54 | + assert.equal(font.familyName, 'Amiri'); |
| 55 | + assert.equal(font.subfamilyName, 'Regular'); |
| 56 | + assert.equal(font.copyright, 'Copyright (c) 2010-2017, Khaled Hosny <khaledhosny@eglug.org>.\nPortions copyright (c) 2010, Sebastian Kosch <sebastian@aldusleaf.org>.'); |
| 57 | + assert.equal(font.version, 'Version 000.110 '); |
| 58 | + }); |
| 59 | + |
| 60 | + it('can set font\'s default language to "ar"', function () { |
| 61 | + font.setDefaultLanguage('ar'); |
| 62 | + assert.equal(font.defaultLanguage, 'ar'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('font now has "ar" metadata properties', function() { |
| 66 | + assert.equal(font.fullName, 'Amiri'); |
| 67 | + assert.equal(font.postscriptName, 'Amiri-Regular'); |
| 68 | + assert.equal(font.familyName, 'Amiri'); |
| 69 | + assert.equal(font.subfamilyName, 'عادي'); |
| 70 | + assert.equal(font.copyright, 'حقوق النشر 2010-2017، خالد حسني <khaledhosny@eglug.org>.'); |
| 71 | + assert.equal(font.version, 'إصدارة 000٫110'); |
| 72 | + }); |
| 73 | + |
| 74 | + it('the font\'s language should not change when the global changes', function () { |
| 75 | + fontkit.setDefaultLanguage('en'); |
| 76 | + |
| 77 | + assert.equal(font.defaultLanguage, 'ar'); |
| 78 | + assert.equal(font.subfamilyName, 'عادي'); |
| 79 | + }); |
| 80 | + |
| 81 | + it('can reset default language back to "en"', function () { |
| 82 | + font.setDefaultLanguage(); |
| 83 | + assert.equal(font.defaultLanguage, null); |
| 84 | + assert.equal(font.subfamilyName, 'Regular'); |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | + describe('backup languages', function () { |
| 89 | + let font; |
| 90 | + before('load Amiri font', function () { |
| 91 | + font = fontkit.openSync(__dirname + '/data/amiri/amiri-regular.ttf'); |
| 92 | + }); |
| 93 | + after('reset default language', function () { |
| 94 | + fontkit.setDefaultLanguage(); |
| 95 | + }); |
| 96 | + |
| 97 | + it('if the font\'s default language isn\'t found, use the global language', function () { |
| 98 | + font.setDefaultLanguage('piglatin'); |
| 99 | + fontkit.setDefaultLanguage('ar'); |
| 100 | + |
| 101 | + assert.equal(font.subfamilyName, 'عادي'); |
| 102 | + }); |
| 103 | + it('if the global language isn\'t found, use "en"', function () { |
| 104 | + font.setDefaultLanguage('piglatin'); |
| 105 | + fontkit.setDefaultLanguage('klingon'); |
| 106 | + |
| 107 | + assert.equal(font.subfamilyName, 'Regular'); |
| 108 | + }); |
| 109 | + }); |
| 110 | +}); |
0 commit comments