# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem      1.0

name            ghostscript-fonts-hiragino
version         9.54.0
categories      print japanese chinese
maintainers     nomaintainer
description     Hiragino font for ghostscript ${version}
long_description \
                {*}${description}
license         Permissive
platforms       macosx
supported_archs noarch
homepage
master_sites
distfiles

depends_lib     port:ghostscript

use_configure   no

build {}

destroot {
    if {${os.platform} eq "darwin"} {
        if {${os.major} <= 8} {
            # for Tiger or older
            set FontList    {"/System/Library/Fonts/ヒラギノ角ゴ Pro W3.otf"  HiraKakuPro-W3  Adobe-Japan1 {GothicBBB-Medium  A-OTF-GothicBBBPro-Medium}
                            "/System/Library/Fonts/ヒラギノ角ゴ Pro W6.otf"   HiraKakuPro-W6  Adobe-Japan1 {FutoGoB101-Bold   A-OTF-FutoGoB101Pro-Bold}
                            "/System/Library/Fonts/ヒラギノ角ゴ Std W8.otf"   HiraKakuStd-W8  Adobe-Japan1 {}
                            "/System/Library/Fonts/ヒラギノ丸ゴ Pro W4.otf"   HiraMaruPro-W4  Adobe-Japan1 {Jun101-Light      A-OTF-Jun101Pro-Light}
                            "/System/Library/Fonts/ヒラギノ明朝 Pro W3.otf"   HiraMinPro-W3   Adobe-Japan1 {Ryumin-Light      A-OTF-RyuminPro-Light}
                            "/System/Library/Fonts/ヒラギノ明朝 Pro W6.otf"   HiraMinPro-W6   Adobe-Japan1 {FutoMinA101-Bold  A-OTF-FutoMinA101Pro-Bold}}
        } elseif {${os.major} <= 14} {
            # for Loaprd to Yosemite
            set FontList    {"/Library/Fonts/ヒラギノ角ゴ Pro W3.otf"         HiraKakuPro-W3  Adobe-Japan1 {GothicBBB-Medium  A-OTF-GothicBBBPro-Medium}
                            "/Library/Fonts/ヒラギノ角ゴ Pro W6.otf"          HiraKakuPro-W6  Adobe-Japan1 {FutoGoB101-Bold   A-OTF-FutoGoB101Pro-Bold}
                            "/Library/Fonts/ヒラギノ角ゴ Std W8.otf"          HiraKakuStd-W8  Adobe-Japan1 {}
                            "/Library/Fonts/ヒラギノ丸ゴ Pro W4.otf"          HiraMaruPro-W4  Adobe-Japan1 {Jun101-Light      A-OTF-Jun101Pro-Light}
                            "/Library/Fonts/ヒラギノ明朝 Pro W3.otf"          HiraMinPro-W3   Adobe-Japan1 {Ryumin-Light      A-OTF-RyuminPro-Light}
                            "/Library/Fonts/ヒラギノ明朝 Pro W6.otf"          HiraMinPro-W6   Adobe-Japan1 {FutoMinA101-Bold  A-OTF-FutoMinA101Pro-Bold}
                            "/System/Library/Fonts/ヒラギノ角ゴ ProN W3.otf"  HiraKakuProN-W3 Adobe-Japan1 {}
                            "/System/Library/Fonts/ヒラギノ角ゴ ProN W6.otf"  HiraKakuProN-W6 Adobe-Japan1 {}
                            "/Library/Fonts/ヒラギノ角ゴ StdN W8.otf"         HiraKakuStdN-W8 Adobe-Japan1 {}
                            "/Library/Fonts/ヒラギノ丸ゴ ProN W4.otf"         HiraMaruProN-W4 Adobe-Japan1 {}
                            "/System/Library/Fonts/ヒラギノ明朝 ProN W3.otf"  HiraMinProN-W3  Adobe-Japan1 {}
                            "/System/Library/Fonts/ヒラギノ明朝 ProN W6.otf"  HiraMinProN-W6  Adobe-Japan1 {}}
        } else {
            set FontList    {"${prefix}/share/fonts/otf/Hiragino/ヒラギノ角ゴ Pro W3.otf"     HiraKakuPro-W3      Adobe-Japan1 {GothicBBB-Medium  A-OTF-GothicBBBPro-Medium}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ角ゴ Pro W6.otf"      HiraKakuPro-W6      Adobe-Japan1 {FutoGoB101-Bold   A-OTF-FutoGoB101Pro-Bold}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ角ゴ Std W8.otf"      HiraKakuStd-W8      Adobe-Japan1 {}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ丸ゴ Pro W4.otf"      HiraMaruPro-W4      Adobe-Japan1 {Jun101-Light      A-OTF-Jun101Pro-Light}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ明朝 Pro W3.otf"      HiraMinPro-W3       Adobe-Japan1 {Ryumin-Light      A-OTF-RyuminPro-Light}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ明朝 Pro W6.otf"      HiraMinPro-W6       Adobe-Japan1 {FutoMinA101-Bold  A-OTF-FutoMinA101Pro-Bold}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ角ゴ ProN W3.otf"     HiraKakuProN-W3     Adobe-Japan1 {}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ角ゴ ProN W6.otf"     HiraKakuProN-W6     Adobe-Japan1 {}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ角ゴ StdN W8.otf"     HiraKakuStdN-W8     Adobe-Japan1 {}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ丸ゴ ProN W4.otf"     HiraMaruProN-W4     Adobe-Japan1 {}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ明朝 ProN W3.otf"     HiraMinProN-W3      Adobe-Japan1 {}
                            "${prefix}/share/fonts/otf/Hiragino/ヒラギノ明朝 ProN W6.otf"     HiraMinProN-W6      Adobe-Japan1 {}}
        }
    }

    if {${os.platform} eq "darwin"} {
        if {${os.major} >= 10 && ${os.major} <= 14} {
            # for SnowLeopard to Yosemite
            lappend FontList \
                        "/Library/Fonts/Hiragino Sans GB W3.otf"    HiraginoSansGB-W3   Adobe-GB1    {} \
                        "/Library/Fonts/Hiragino Sans GB W6.otf"    HiraginoSansGB-W6   Adobe-GB1    {}
        } else {
            lappend FontList \
                        "${prefix}/share/fonts/otf/Hiragino/Hiragino Sans GB W3.otf"    HiraginoSansGB-W3  Adobe-GB1    {} \
                        "${prefix}/share/fonts/otf/Hiragino/Hiragino Sans GB W6.otf"    HiraginoSansGB-W6  Adobe-GB1    {}
        }
        if {${os.major} >= 13 && [variant_isset yu]} {
            # for Mavericks or newer; may be unstable
            lappend FontList \
                        "/Library/Fonts/Yu Gothic Bold.otf"         YuGo-Bold           Adobe-Japan1 {} \
                        "/Library/Fonts/Yu Gothic Medium.otf"       YuGo-Medium         Adobe-Japan1 {} \
                        "/Library/Fonts/Yu Mincho Demibold.otf"     YuMin-Demibold      Adobe-Japan1 {} \
                        "/Library/Fonts/Yu Mincho Medium.otf"       YuMin-Medium        Adobe-Japan1 {}
        }
    }

    set GSFontDir ${destroot}${prefix}/share/ghostscript/${version}/Resource/Font
    set GSCIDFontDir ${destroot}${prefix}/share/ghostscript/${version}/Resource/CIDFont
    set EncodeList(Adobe-Japan1)    {78-EUC-H
                                    78-EUC-V
                                    78-H
                                    78-RKSJ-H
                                    78-RKSJ-V
                                    78-V
                                    78ms-RKSJ-H
                                    78ms-RKSJ-V
                                    83pv-RKSJ-H
                                    90ms-RKSJ-H
                                    90ms-RKSJ-V
                                    90msp-RKSJ-H
                                    90msp-RKSJ-V
                                    90pv-RKSJ-H
                                    90pv-RKSJ-V
                                    Add-H
                                    Add-RKSJ-H
                                    Add-RKSJ-V
                                    Add-V
                                    Adobe-Japan1-0
                                    Adobe-Japan1-1
                                    Adobe-Japan1-2
                                    Adobe-Japan1-3
                                    Adobe-Japan1-4
                                    Adobe-Japan1-5
                                    Adobe-Japan1-6
                                    EUC-H
                                    EUC-V
                                    Ext-H
                                    Ext-RKSJ-H
                                    Ext-RKSJ-V
                                    Ext-V
                                    H
                                    Hankaku
                                    Hiragana
                                    Identity-H
                                    Identity-V
                                    Katakana
                                    NWP-H
                                    NWP-V
                                    RKSJ-H
                                    RKSJ-V
                                    Roman
                                    UniJIS-UCS2-H
                                    UniJIS-UCS2-HW-H
                                    UniJIS-UCS2-HW-V
                                    UniJIS-UCS2-V
                                    UniJIS-UTF16-H
                                    UniJIS-UTF16-V
                                    UniJIS-UTF32-H
                                    UniJIS-UTF32-V
                                    UniJIS-UTF8-H
                                    UniJIS-UTF8-V
                                    UniJIS2004-UTF16-H
                                    UniJIS2004-UTF16-V
                                    UniJIS2004-UTF32-H
                                    UniJIS2004-UTF32-V
                                    UniJIS2004-UTF8-H
                                    UniJIS2004-UTF8-V
                                    UniJISPro-UCS2-HW-V
                                    UniJISPro-UCS2-V
                                    UniJISPro-UTF8-V
                                    UniJISX0213-UTF32-H
                                    UniJISX0213-UTF32-V
                                    UniJISX02132004-UTF32-H
                                    UniJISX02132004-UTF32-V
                                    V
                                    WP-Symbol}
    set EncodeList(Adobe-GB1)       {Adobe-GB1-0
                                    Adobe-GB1-1
                                    Adobe-GB1-2
                                    Adobe-GB1-3
                                    Adobe-GB1-4
                                    Adobe-GB1-5
                                    GB-EUC-H
                                    GB-EUC-V
                                    GB-H
                                    GB-RKSJ-H
                                    GB-V
                                    GBK-EUC-H
                                    GBK-EUC-V
                                    GBK2K-H
                                    GBK2K-V
                                    GBKp-EUC-H
                                    GBKp-EUC-V
                                    GBT-EUC-H
                                    GBT-EUC-V
                                    GBT-H
                                    GBT-RKSJ-H
                                    GBT-V
                                    GBTpc-EUC-H
                                    GBTpc-EUC-V
                                    GBpc-EUC-H
                                    GBpc-EUC-V
                                    Identity-H
                                    Identity-V
                                    UniGB-UCS2-H
                                    UniGB-UCS2-V
                                    UniGB-UTF16-H
                                    UniGB-UTF16-V
                                    UniGB-UTF32-H
                                    UniGB-UTF32-V
                                    UniGB-UTF8-H
                                    UniGB-UTF8-V}
    set EncodeList(Adobe-CNS1)      {Adobe-CNS1-0
                                    Adobe-CNS1-1
                                    Adobe-CNS1-2
                                    Adobe-CNS1-3
                                    Adobe-CNS1-4
                                    Adobe-CNS1-5
                                    Adobe-CNS1-6
                                    B5-H
                                    B5-V
                                    B5pc-H
                                    B5pc-V
                                    CNS-EUC-H
                                    CNS-EUC-V
                                    CNS1-H
                                    CNS1-V
                                    CNS2-H
                                    CNS2-V
                                    ETHK-B5-H
                                    ETHK-B5-V
                                    ETen-B5-H
                                    ETen-B5-V
                                    ETenms-B5-H
                                    ETenms-B5-V
                                    HKdla-B5-H
                                    HKdla-B5-V
                                    HKdlb-B5-H
                                    HKdlb-B5-V
                                    HKgccs-B5-H
                                    HKgccs-B5-V
                                    HKm314-B5-H
                                    HKm314-B5-V
                                    HKm471-B5-H
                                    HKm471-B5-V
                                    HKscs-B5-H
                                    HKscs-B5-V
                                    Identity-H
                                    Identity-V
                                    UniCNS-UCS2-H
                                    UniCNS-UCS2-V
                                    UniCNS-UTF16-H
                                    UniCNS-UTF16-V
                                    UniCNS-UTF32-H
                                    UniCNS-UTF32-V
                                    UniCNS-UTF8-H
                                    UniCNS-UTF8-V}
    set EncodeList(Adobe-Korea1)    {Adobe-Korea1-0
                                    Adobe-Korea1-1
                                    Adobe-Korea1-2
                                    Identity-H
                                    Identity-V
                                    KSC-EUC-H
                                    KSC-EUC-V
                                    KSC-H
                                    KSC-Johab-H
                                    KSC-Johab-V
                                    KSC-RKSJ-H
                                    KSC-V
                                    KSCms-UHC-H
                                    KSCms-UHC-HW-H
                                    KSCms-UHC-HW-V
                                    KSCms-UHC-V
                                    KSCpc-EUC-H
                                    KSCpc-EUC-V
                                    UniKS-UCS2-H
                                    UniKS-UCS2-V
                                    UniKS-UTF16-H
                                    UniKS-UTF16-V
                                    UniKS-UTF32-H
                                    UniKS-UTF32-V
                                    UniKS-UTF8-H
                                    UniKS-UTF8-V}

    xinstall -m 755 -d ${GSFontDir}
    xinstall -m 755 -d ${GSCIDFontDir}

    foreach {fontfile fontname fontset aliases} ${FontList} {
        # expand ${prefix}
        set fontfile [subst -nocommands ${fontfile}]
        if {![file exists ${fontfile}]} {
            return -code error "Font file \"${fontfile}\" is not found. \nIf you have former versions of OS X such as Yosemite, copy the font file from it."
        }

        ln -s ${fontfile} ${GSCIDFontDir}/${fontname}

        foreach encode "$EncodeList($fontset)" {
            set fd [open [file join ${GSFontDir} ${fontname}-${encode}] w 0644]
            puts ${fd} "%!PS-Adobe-3.0 Resource-Font"
            puts ${fd} "%%DocumentNeededResources: ${encode} (CMap)"
            puts ${fd} "%%IncludeResource: ${encode} (CMap)"
            puts ${fd} "%%BeginResource: Font (${fontname}-${encode})"
            puts ${fd} "(${fontname}-${encode})"
            puts ${fd} "(${encode}) /CMap findresource"
            puts ${fd} "\[(${fontname}) /CIDFont findresource\]"
            puts ${fd} "composefont"
            puts ${fd} "pop"
            puts ${fd} "%%EndResource"
            puts ${fd} "%%EOF"
            close ${fd}
        }

        if {![variant_isset no_alias]} {
            foreach alias ${aliases} {
                foreach encode "$EncodeList($fontset)" {
                    set fd [open [file join ${GSFontDir} ${alias}-${encode}] w 0644]
                    puts ${fd} "%!PS-Adobe-3.0 Resource-Font"
                    puts ${fd} "%%DocumentNeededResources: ${encode} (CMap)"
                    puts ${fd} "%%IncludeResource: ${encode} (CMap)"
                    puts ${fd} "%%BeginResource: Font (${alias}-${encode})"
                    puts ${fd} "(${alias}-${encode})"
                    puts ${fd} "(${encode}) /CMap findresource"
                    puts ${fd} "\[(${fontname}) /CIDFont findresource\]"
                    puts ${fd} "composefont"
                    puts ${fd} "pop"
                    puts ${fd} "%%EndResource"
                    puts ${fd} "%%EOF"
                    close ${fd}
                }
            }
        }
    }
}

if {[variant_isset no_alias]} {
    default_variants    -alias
} else {
    default_variants    +alias
}

if {${os.platform} eq "darwin" && ${os.major} >= 13} {
    variant yu description {Add support for Yu fonts (experimental; unstable)} {
        notes "WARNING: Handling Yu fonts on ghostscript may cause unstable behavior"
    }
}

variant no_alias conflicts alias description {Legacy compatibility variant} {}

variant alias description "Use Hiragino as an alternative to Morisawa's standard 5 fonts" {}

livecheck.type  none
