# $Id: PKGBUILD 135473 2015-06-16 10:38:00Z fyan $
# Maintainer: Felix Yan <felixonmars@gmail.com>
# Contributor: Sascha Weaver <wzyboy@wzyboy.org>

# This font has four versions:
#
# * Multilingual versions with a default language: (OTF)
#   (We do not package them)
#   * Multilingual version with Japanese glyphs as default priority
#   * Multilingual version with Korean glyphs as default priority
#   * Multilingual version with Simplified Chinese glyphs as default priority
#   * Multilingual version with Traditional Chinese glyphs as default priority
# * Multilingual version combined the four versions above. (OTC)
#   (This version is "the best of the worlds", but it cannot be used in Windows)
#   -> adobe-source-han-sans-otc-fonts
# * Multilingual version compressed the 7 files into a single ttc file. (SuperOTC)
#   (We do not package them, as there's no difference from the OTC version in use)
# * Regional subsets with only characters used in CN, JP, KR or TW: (SubsetOTF)
#   (This version is smaller and has better compatibility)
#   * Regional subset with only Japanese glyphs + Latin
#   -> adobe-source-han-sans-jp-fonts
#   * Regional subset with only Korean glyphs + Latin
#   -> adobe-source-han-sans-kr-fonts
#   * Regional subset with only Simplified Chinese glyphs + Latin
#   -> adobe-source-han-sans-cn-fonts
#   * Regional subset with only Traditional Chinese glyphs + Latin
#   -> adobe-source-han-sans-tw-fonts

_pkgbase=adobe-source-han-sans
pkgbase=$_pkgbase-fonts
pkgname=($_pkgbase-jp-fonts $_pkgbase-kr-fonts $_pkgbase-cn-fonts $_pkgbase-tw-fonts $_pkgbase-otc-fonts)
pkgver=1.004
pkgrel=1
pkgdesc='Adobe Source Han Sans - A set of Pan-CJK fonts designed to complement Source Sans Pro'
arch=('any')
license=('Apache')
url='https://github.com/adobe-fonts/source-han-sans'
depends=('fontconfig')
install="fonts.install"
source=("https://github.com/adobe-fonts/source-han-sans/archive/${pkgver}R.tar.gz"
        44-source-han-sans-jp.conf
        44-source-han-sans-kr.conf
        44-source-han-sans-cn.conf
        44-source-han-sans-tw.conf
        44-source-han-sans-otc.conf)
sha256sums=('7f2d5fdbc76a5ff24ce8d4cacbebe2f87efd5f23dba1ed90acc66b90b8035deb'
            'f0e87368ffa91ac76b253846836da05baa120ab4f8a7bfd90fded36f4988c9e0'
            'fa8d487c7ba67489bde7b4d8558e07abb6d8bcb4d4e9db1bf454c2db23af9547'
            'd42ed0092a47cee5c7ff3972c90676109212dafc2cffb3388a8b339788a6cdb5'
            'bfcdadbe66f70baaf617c582ec69ccc6b10175020ccb1ec2de26220b09270e60'
            'd9ef4ab4db1ad22be57d7c4bfe1cc75e9e1ed5e41887fba49dd137a88401b5f2')

_jp=(
SourceHanSansJP-Bold.otf
SourceHanSansJP-ExtraLight.otf
SourceHanSansJP-Heavy.otf
SourceHanSansJP-Light.otf
SourceHanSansJP-Medium.otf
SourceHanSansJP-Normal.otf
SourceHanSansJP-Regular.otf
)
_kr=(
SourceHanSansKR-Bold.otf
SourceHanSansKR-ExtraLight.otf
SourceHanSansKR-Heavy.otf
SourceHanSansKR-Light.otf
SourceHanSansKR-Medium.otf
SourceHanSansKR-Normal.otf
SourceHanSansKR-Regular.otf
)
_cn=(
SourceHanSansCN-Bold.otf
SourceHanSansCN-ExtraLight.otf
SourceHanSansCN-Heavy.otf
SourceHanSansCN-Light.otf
SourceHanSansCN-Medium.otf
SourceHanSansCN-Normal.otf
SourceHanSansCN-Regular.otf
)
_tw=(
SourceHanSansTW-Bold.otf
SourceHanSansTW-ExtraLight.otf
SourceHanSansTW-Heavy.otf
SourceHanSansTW-Light.otf
SourceHanSansTW-Medium.otf
SourceHanSansTW-Normal.otf
SourceHanSansTW-Regular.otf
)
_otc=(
SourceHanSans-Bold.ttc
SourceHanSans-ExtraLight.ttc
SourceHanSans-Heavy.ttc
SourceHanSans-Light.ttc
SourceHanSans-Medium.ttc
SourceHanSans-Normal.ttc
SourceHanSans-Regular.ttc
)

function _package {
    cd "$srcdir/source-han-sans-${pkgver}R"

    case "$1" in
        $_pkgbase-jp-fonts)
            fonts=(${_jp[@]})
            cd SubsetOTF/JP
            _fontconfig_filename=44-source-han-sans-jp.conf
            pkgdesc="Adobe Source Han Sans Subset OTF - Japanese OpenType/CFF fonts";;
        $_pkgbase-kr-fonts)
            fonts=(${_kr[@]})
            cd SubsetOTF/KR
            _fontconfig_filename=44-source-han-sans-kr.conf
            pkgdesc="Adobe Source Han Sans Subset OTF - Korean OpenType/CFF fonts";;
        $_pkgbase-cn-fonts)
            fonts=(${_cn[@]})
            cd SubsetOTF/CN
            _fontconfig_filename=44-source-han-sans-cn.conf
            pkgdesc="Adobe Source Han Sans Subset OTF - Simplified Chinese OpenType/CFF fonts";;
        $_pkgbase-tw-fonts)
            fonts=(${_tw[@]})
            cd SubsetOTF/TW
            _fontconfig_filename=44-source-han-sans-tw.conf
            conflicts=("$_pkgbase-twhk-fonts")
            replaces=("$_pkgbase-twhk-fonts")
            pkgdesc="Adobe Source Han Sans Subset OTF - Traditional Chinese OpenType/CFF fonts";;
        $_pkgbase-otc-fonts)
            fonts=(${_otc[@]})
            cd OTC
            _fontconfig_filename=44-source-han-sans-otc.conf
            pkgdesc="Adobe Source Han Sans - Pan-CJK OpenType/CFF Collection fonts";;
    esac

    # Prepare destination directory
    install -dm755 "$pkgdir/usr/share/fonts/adobe-source-han-sans"

    # Install fonts
    for font in "${fonts[@]}"; do
        install -m644 "$font" "$pkgdir/usr/share/fonts/adobe-source-han-sans"
    done

    # Install fontconfig fix
    install -d "$pkgdir/etc/fonts/conf.d"
    install -Dm644 "$srcdir/$_fontconfig_filename" "$pkgdir/etc/fonts/conf.avail/$_fontconfig_filename"
    ln -s ../conf.avail/$_fontconfig_filename "$pkgdir/etc/fonts/conf.d/$_fontconfig_filename"
}

for _pkgname in ${pkgname[@]}; do
    eval "function package_$_pkgname() { _package $_pkgname; }"
done
