-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFont.php
71 lines (68 loc) · 2.16 KB
/
Font.php
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
<?php
namespace Dfe\GoogleFont;
use Df\Core\Exception as DFE;
use Dfe\GoogleFont\Font\Variant as V;
/**
* 2015-11-27
* https://developers.google.com/fonts/docs/developer_api#Example
* {
* "kind": "webfonts#webfont",
* "family": "ABeeZee",
* "category": "sans-serif",
* "variants": ["regular", "italic"],
* "subsets": ["latin"],
* "version": "v4",
* "lastModified": "2015-04-06",
* "files": {
* "regular": "http://fonts.gstatic.com/s/abeezee/v4/mE5BOuZKGln_Ex0uYKpIaw.ttf",
* "italic": "http://fonts.gstatic.com/s/abeezee/v4/kpplLynmYgP0YtlJA3atRw.ttf"
* }
* },
* {
* "kind": "webfonts#webfont",
* "family": "Abel",
* "category": "sans-serif",
* "variants": ["regular"],
* "subsets": ["latin"],
* "version": "v6",
* "lastModified": "2015-04-06",
* "files": {"regular": "http://fonts.gstatic.com/s/abel/v6/RpUKfqNxoyNe_ka23bzQ2A.ttf"}
* }
*/
final class Font extends \Df\Core\O {
/**
* 2015-11-28 "family": "ABeeZee"
* @used-by self::variant()
* @used-by \Dfe\GoogleFont\Fonts::items()
* @used-by \Dfe\GoogleFont\Font\Variant\Preview::family()
*/
function family():string {return $this['family'];}
/**
* 2015-11-29
* @used-by \Dfe\GoogleFont\Controller\Index\Preview::contents()
* @throws DFE
*/
function variant(string $n):V {return df_assert(dfa($this->variants(), $n),
"The variant «{$n}» of the font «{$this->family()}» has not been found."
);}
/**
* 2015-11-27
* @used-by self::variant()
* @used-by self::variantsAvailable()
* @used-by \Dfe\GoogleFont\Controller\Index\Index::execute()
* @return array(string => V)
*/
function variants():array {return dfc($this, function():array {
# 2015-11-28 "variants": ["regular", "italic"]
$nn = $this['variants']; /** @var string[] $nn */
return array_combine($nn, array_map(function(string $n):V {return new V($this, $n, $this['files'][$n]);}, $nn));
});}
/**
* 2015-12-08
* @used-by \Dfe\GoogleFont\Fonts\Sprite::previews()
* @return array(string => V)
*/
function variantsAvailable():array {return dfc($this, function():array {return array_filter(
$this->variants(), function(V $v):bool {return $v->preview()->isAvailable();}
);});}
}