From 42e3a65131dad33664024e7ef0eb36507e87bf9f Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 14 Nov 2012 15:21:23 +0530 Subject: [PATCH] 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 --- data/fontrepo/scripts/compile.php | 83 ++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 17 deletions(-) diff --git a/data/fontrepo/scripts/compile.php b/data/fontrepo/scripts/compile.php index 43136829..a202072f 100644 --- a/data/fontrepo/scripts/compile.php +++ b/data/fontrepo/scripts/compile.php @@ -1,36 +1,85 @@ $font ) { - foreach ( explode( ',', $font['languages'] ) as $rcode ) { - $rcode = trim( $rcode ); - $code = str_replace( '*', '', $rcode ); - if ( !isset( $list['languages'][$code] ) ) { - $list['languages'][$code] = array( 'system' ); - } - if ( strpos( $rcode, '*' ) !== false ) { - unset( $list['languages'][$code][0] ); - array_unshift( $list['languages'][$code], $fontname ); - } else { - $list['languages'][$code][] = $fontname; + + if ( isset( $font['languages'] ) ) { + $languages = explode( ',', $font['languages'] ); + foreach ( $languages as $rcode ) { + $rcode = trim( $rcode ); + $code = str_replace( '*', '', $rcode ); + if ( !isset( $list['languages'][$code] ) ) { + $list['languages'][$code] = array( 'system' ); + } + if ( strpos( $rcode, '*' ) !== false ) { + 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( - '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 ); - 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 ); + + 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']; } } }