Support font variants

Generate the font listing in javascript with variant support

An example of generated script:

"Opendyslexic": {
	"version": "0.6",
	"license": "Creative Commons Attribution 3.0 Unported License",
	"ttf": "Opendyslexic\/opendyslexic.ttf",
	"eot": "Opendyslexic\/opendyslexic.eot",
	"woff": "Opendyslexic\/opendyslexic.woff",
	"variants": {
		"bold": "Opendyslexic Bold",
		"italic": "Opendyslexic Italic"
	}
},
"Opendyslexic Bold": {
	"version": "0.6",
	"license": "Creative Commons Attribution 3.0 Unported License",
	"fontweight": "bold",
	"ttf": "Opendyslexic\/opendyslexic-bold.ttf",
	"eot": "Opendyslexic\/opendyslexic-bold.eot",
	"woff": "Opendyslexic\/opendyslexic-bold.woff"
},
"Opendyslexic Italic": {
	"version": "0.6",
	"license": "Creative Commons Attribution 3.0 Unported License",
	"fontstyle": "italic",
	"ttf": "Opendyslexic\/opendyslexic-italic.ttf",
	"eot": "Opendyslexic\/opendyslexic-italic.eot",
	"woff": "Opendyslexic\/opendyslexic-italic.woff"
},

Corresponding ini file:

[Opendyslexic]
languages=en,af,pt,es,sw,de,fi,sq,fr,hu,ca,da,fo,ga,is,ms,sv,wa,lb,gd,oc,tr,mi,it,et,cy
version=0.6
license=Creative Commons Attribution 3.0 Unported License
licensefile=http://dyslexicfonts.com/license.php
url=https://github.com/antijingoist/open-dyslexic
ttf=opendyslexic.ttf
eot=opendyslexic.eot
woff=opendyslexic.woff
bold=Opendyslexic Bold
italic=Opendyslexic Italic

[Opendyslexic Bold]
ttf=opendyslexic-bold.ttf
eot=opendyslexic-bold.eot
woff=opendyslexic-bold.woff
fontweight=bold

[Opendyslexic Italic]
ttf=opendyslexic-italic.ttf
eot=opendyslexic-italic.eot
woff=opendyslexic-italic.woff
fontstyle=italic

Change-Id: I55afcd89fe5be5ecf35b4f2fc47ba508fbcfc41e
This commit is contained in:
Santhosh Thottingal
2012-11-14 15:21:23 +05:30
parent bd8aa89c2b
commit 42e3a65131

View File

@@ -8,8 +8,14 @@ $list = array();
$list['base'] = '../data/fontrepo/fonts/';
foreach ( glob( '../fonts/*/font.ini' ) as $inifile ) {
$conf = parse_ini_file( $inifile, true );
$languages = array();
$version = null;
$license = null;
foreach ( $conf as $fontname => $font ) {
foreach ( explode( ',', $font['languages'] ) as $rcode ) {
if ( isset( $font['languages'] ) ) {
$languages = explode( ',', $font['languages'] );
foreach ( $languages as $rcode ) {
$rcode = trim( $rcode );
$code = str_replace( '*', '', $rcode );
if ( !isset( $list['languages'][$code] ) ) {
@@ -22,17 +28,60 @@ foreach ( glob( '../fonts/*/font.ini' ) as $inifile ) {
$list['languages'][$code][] = $fontname;
}
}
}
if ( isset( $font['version'] ) ) {
$version = $font['version'];
}
if ( isset( $font['license'] ) ) {
$license = $font['license'];
}
$list['fonts'][$fontname] = array(
'version' => $font['version'],
'license' => @$font['license'],
'version' => $version,
'license' => $license,
);
if ( isset( $font['fontweight'] ) ) {
$list['fonts'][$fontname]['fontweight'] = $font['fontweight'];
}
if ( isset( $font['fontstyle'] ) ) {
$list['fonts'][$fontname]['fontstyle'] = $font['fontstyle'];
}
$dir = dirname( $inifile );
if ( isset( $font['ttf'] ) ) {
$list['fonts'][$fontname]['ttf'] = basename( $dir ) . '/' . $font['ttf'] ;
}
if ( isset( $font['svg'] ) ) {
$list['fonts'][$fontname]['svg'] = basename( $dir ) . '/' . $font['svg'];
}
if ( isset( $font['eot'] ) ) {
$list['fonts'][$fontname]['eot'] = basename( $dir ) . '/' . $font['eot'];
}
if ( isset( $font['woff'] ) ) {
$list['fonts'][$fontname]['woff'] = basename( $dir ) . '/' . $font['woff'];
}
// If font formats are not explicitly defined, scan the directory.
if ( !isset( $list['fonts'][$fontname]['ttf'] ) ) {
foreach ( glob( "$dir/*.{eot,ttf,woff,svg}", GLOB_BRACE ) as $fontfile ) {
$type = substr( $fontfile, strrpos( $fontfile, '.' ) + 1 );
$list['fonts'][$fontname][$type] = str_replace( dirname( $dir ) . '/', '', $fontfile );
}
}
// Font variants
if ( isset( $font['bold'] ) ) {
$list['fonts'][$fontname]['variants']['bold'] = $font['bold'];
}
if ( isset( $font['bolditalic'] ) ) {
$list['fonts'][$fontname]['variants']['bolditalic'] = $font['bolditalic'];
}
if ( isset( $font['italic'] ) ) {
$list['fonts'][$fontname]['variants']['italic'] = $font['italic'];
}
}
}
ksort( $list['languages'] );