google.php
4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
class N2SystemPluginFontServiceGoogle extends N2PluginBase {
/*
jQuery.getJSON('https://www.googleapis.com/webfonts/v1/webfonts?sort=alpha&key=AIzaSyBIzBtder0-ef5a6kX-Ri9IfzVwFu21PGw').done(function(data){
var f = [];
for(var i = 0; i < data.items.length; i++){
f.push(data.items[i].family);
}
console.log(JSON.stringify(f));
});
*/
private static $fonts = array();
var $_group = 'google';
private static $styles = array();
private static $subsets = array();
public static function init() {
$lines = file(dirname(__FILE__) . '/families.csv', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
for ($i = 0; $i < count($lines); $i++) {
self::$fonts[strtolower($lines[$i])] = $lines[$i];
}
self::$fonts['droid sans'] = 'Noto Sans';
self::$fonts['droid serif'] = 'Noto Serif';
}
function onFontServices(&$list) {
$list[$this->_group] = array(
'Google',
$this->getPath(),
1
);
}
public static function getDefaults() {
$defaults = array();
$fontsSets = explode(',', n2_x('latin', 'Default font sets'));
for ($i = 0; $i < count($fontsSets); $i++) {
$fontsSets[$i] = 'google-set-' . $fontsSets[$i];
}
$defaults += array_fill_keys($fontsSets, 1);
return $defaults;
}
function getPath() {
return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'google' . DIRECTORY_SEPARATOR;
}
function onFontManagerLoad($force = false) {
static $loaded;
if (!$loaded || $force) {
$loaded = true;
$settings = N2Fonts::loadSettings();
$parameters = $settings['plugins'];
$parameters->fillDefault(self::getDefaults());
if ($parameters->get('google-enabled', 1)) {
N2GoogleFonts::$enabled = 1;
for ($i = 100; $i < 1000; $i += 100) {
$this->addStyle($parameters, $i);
$this->addStyle($parameters, $i . 'italic');
}
if (empty(self::$styles)) {
self::$styles[] = '300';
self::$styles[] = '400';
}
$this->addSubset($parameters, 'latin');
$this->addSubset($parameters, 'latin-ext');
$this->addSubset($parameters, 'greek');
$this->addSubset($parameters, 'greek-ext');
$this->addSubset($parameters, 'cyrillic');
$this->addSubset($parameters, 'devanagari');
$this->addSubset($parameters, 'arabic');
$this->addSubset($parameters, 'khmer');
$this->addSubset($parameters, 'telugu');
$this->addSubset($parameters, 'vietnamese');
if (empty(self::$subsets)) {
self::$subsets[] = 'latin';
}
foreach (self::$subsets as $subset) {
N2GoogleFonts::addSubset($subset);
}
N2Pluggable::addAction('fontFamily', array(
$this,
'onFontFamily'
));
}
}
}
function onFontManagerLoadBackend() {
N2JS::addInline('new NextendFontServiceGoogle("' . implode(',', self::$styles) . '","' . implode(',', self::$subsets) . '", ' . json_encode(self::$fonts) . ');');
}
function addStyle($parameters, $weight) {
if ($parameters->get('google-style-' . $weight, 0)) {
self::$styles[] = $weight;
}
}
function addSubset($parameters, $subset) {
if ($parameters->get('google-set-' . $subset, 0)) {
self::$subsets[] = $subset;
}
}
function onFontFamily($family) {
$familyLower = strtolower($family);
if (isset(self::$fonts[$familyLower])) {
foreach (self::$styles AS $style) {
N2GoogleFonts::addFont(self::$fonts[$familyLower], $style);
}
return self::$fonts[$familyLower];
}
return $family;
}
}
N2SystemPluginFontServiceGoogle::init();
N2Plugin::addPlugin('fontservices', 'N2SystemPluginFontServiceGoogle');