# $Id: Portfile,v 1.2 2006/05/20 15:28:14 takanori Exp $

PortSystem        1.0
name              ghostscript-fonts-hiragino
version           8.54
categories        print
maintainers       takanori@opendarwin.org
description       Japanese Hiragino fonts for ghostscript ${version}
long_description  ${description}
platforms         macosx
distfiles         
depends_lib       port:ghostscript

default_variants  +alias

configure	  {}
build		  {}
destroot	  {
		  set SystemLibraryFontsDir /System/Library/Fonts
		  set GSFontDir ${destroot}${prefix}/share/ghostscript/${version}/Resource/Font
		  set GSCIDFontDir ${destroot}${prefix}/share/ghostscript/${version}/Resource/CIDFont
		  set FontList {"ヒラギノ角ゴ Pro W3.otf" HiraKakuPro-W3 {GothicBBB-Medium}
		      	        "ヒラギノ角ゴ Pro W6.otf" HiraKakuPro-W6 {FutoGoB101-Bold}
				"ヒラギノ角ゴ Std W8.otf" HiraKakuStd-W8 {}
				"ヒラギノ丸ゴ Pro W4.otf" HiraMaruPro-W4 {Jun101-Light}
				"ヒラギノ明朝 Pro W3.otf" HiraMinPro-W3 {Ryumin-Light}
				"ヒラギノ明朝 Pro W6.otf" HiraMinPro-W6 {FutoMinA101-Bold}}
		  set EncodeList {H V EUC-H EUC-V UniJIS-UTF16-H UniJIS-UTF16-V}

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

		  foreach {file font aliases} ${FontList} {
			if {![file exists ${SystemLibraryFontsDir}/${file}]} {
                           ui_error "Please place \"${file}\" in ${SystemLibraryFontsDir} and restart the build."
                           exit 1
                        }

			system "ln -s \"${SystemLibraryFontsDir}/${file}\" ${GSCIDFontDir}/${font}"
			foreach encode ${EncodeList} {
				system "echo \"/${font}-${encode}\n/${encode} /CMap findresource\n\[/${font} /CIDFont findresource\]\ncomposefont pop\" > ${GSFontDir}/${font}-${encode}"
				if {[variant_isset alias]} { foreach alias ${aliases} { system "echo \"/${alias}-${encode}\n/${encode} /CMap findresource\n\[/${font} /CIDFont findresource\]\ncomposefont pop\" > ${GSFontDir}/${alias}-${encode}" } }
			}
		  }
}

#use Hiragino as an alternative to Morisawa's standard 5 fonts.
variant alias {}
