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:
@@ -1,36 +1,85 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
|
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = array();
|
$list = array();
|
||||||
$list['base'] = '../data/fontrepo/fonts/';
|
$list['base'] = '../data/fontrepo/fonts/';
|
||||||
foreach ( glob( '../fonts/*/font.ini' ) as $inifile ) {
|
foreach ( glob( '../fonts/*/font.ini' ) as $inifile ) {
|
||||||
$conf = parse_ini_file( $inifile, true );
|
$conf = parse_ini_file( $inifile, true );
|
||||||
|
$languages = array();
|
||||||
|
$version = null;
|
||||||
|
$license = null;
|
||||||
foreach ( $conf as $fontname => $font ) {
|
foreach ( $conf as $fontname => $font ) {
|
||||||
foreach ( explode( ',', $font['languages'] ) as $rcode ) {
|
|
||||||
$rcode = trim( $rcode );
|
if ( isset( $font['languages'] ) ) {
|
||||||
$code = str_replace( '*', '', $rcode );
|
$languages = explode( ',', $font['languages'] );
|
||||||
if ( !isset( $list['languages'][$code] ) ) {
|
foreach ( $languages as $rcode ) {
|
||||||
$list['languages'][$code] = array( 'system' );
|
$rcode = trim( $rcode );
|
||||||
}
|
$code = str_replace( '*', '', $rcode );
|
||||||
if ( strpos( $rcode, '*' ) !== false ) {
|
if ( !isset( $list['languages'][$code] ) ) {
|
||||||
unset( $list['languages'][$code][0] );
|
$list['languages'][$code] = array( 'system' );
|
||||||
array_unshift( $list['languages'][$code], $fontname );
|
}
|
||||||
} else {
|
if ( strpos( $rcode, '*' ) !== false ) {
|
||||||
$list['languages'][$code][] = $fontname;
|
unset( $list['languages'][$code][0] );
|
||||||
|
array_unshift( $list['languages'][$code], $fontname );
|
||||||
|
} else {
|
||||||
|
$list['languages'][$code][] = $fontname;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( isset( $font['version'] ) ) {
|
||||||
|
$version = $font['version'];
|
||||||
|
}
|
||||||
|
if ( isset( $font['license'] ) ) {
|
||||||
|
$license = $font['license'];
|
||||||
|
}
|
||||||
|
|
||||||
$list['fonts'][$fontname] = array(
|
$list['fonts'][$fontname] = array(
|
||||||
'version' => $font['version'],
|
'version' => $version,
|
||||||
'license' => @$font['license'],
|
'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 );
|
$dir = dirname( $inifile );
|
||||||
foreach ( glob( "$dir/*.{eot,ttf,woff,svg}", GLOB_BRACE ) as $fontfile ) {
|
|
||||||
$type = substr( $fontfile, strrpos( $fontfile, '.' ) + 1 );
|
if ( isset( $font['ttf'] ) ) {
|
||||||
$list['fonts'][$fontname][$type] = str_replace( dirname( $dir ) . '/', '', $fontfile );
|
$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'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user