%define gsversion %(ghostscript --version)

%define xfontdir	%{_datadir}/fonts/%{name}
## for 7.07
#% define gsfontdir	%{_datadir}/ghostscript/Resource/CIDFont
## for 8.xx
%define gsfontdir	%{_datadir}/ghostscript/%{gsversion}/Resource/CIDFont
%define gsfontspecdir	%{_datadir}/ghostscript/%{gsversion}/Resource/Font
%define texfontdir	%{_datadir}/texmf/fonts/opentype

%define exec_updmap_otf [ -x %{_bindir}/updmap-otf ] && %{_bindir}/env - %{_bindir}/updmap-otf auto 2> /dev/null

%define FontList \\\
    KozGoPr6N-Bold,Japan \\\
    KozGoPr6N-ExtraLight,Japan \\\
    KozGoPr6N-Heavy,Japan \\\
    KozGoPr6N-Light,Japan \\\
    KozGoPr6N-Medium,Japan \\\
    KozGoPr6N-Regular,Japan \\\
    KozGoPro-Bold,Japan \\\
    KozGoPro-ExtraLight,Japan \\\
    KozGoPro-Heavy,Japan \\\
    KozGoPro-Light,Japan \\\
    KozGoPro-Medium,Japan \\\
    KozGoPro-Regular,Japan \\\
    KozGoStd-Bold,Japan \\\
    KozGoStd-ExtraLight,Japan \\\
    KozGoStd-Heavy,Japan \\\
    KozGoStd-Light,Japan \\\
    KozGoStd-Medium,Japan \\\
    KozGoStd-Regular,Japan \\\
    KozMinPr6N-Bold,Japan \\\
    KozMinPr6N-ExtraLight,Japan \\\
    KozMinPr6N-Heavy,Japan \\\
    KozMinPr6N-Light,Japan \\\
    KozMinPr6N-Medium,Japan \\\
    KozMinPr6N-Regular,Japan \\\
    KozMinPro-Bold,Japan \\\
    KozMinPro-ExtraLight,Japan \\\
    KozMinPro-Heavy,Japan \\\
    KozMinPro-Light,Japan \\\
    KozMinPro-Medium,Japan \\\
    KozMinPro-Regular,Japan \\\
    KozMinStd-Bold,Japan \\\
    KozMinStd-ExtraLight,Japan \\\
    KozMinStd-Heavy,Japan \\\
    KozMinStd-Light,Japan \\\
    KozMinStd-Medium,Japan \\\
    KozMinStd-Regular,Japan

%define EncodeList_Japan \\\
    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

%define EncodeList_GB \\\
    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

%define EncodeList_CNS \\\
    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

%define EncodeList_Korea \\\
    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

Summary: Kozuka Japanese/English OpenType Font
Summary(ja): 小塚 OpenType フォント
Name: OpenType-kozuka
Version: 1.0
Release: 4%{?_dist_release}
BuildArch: noarch

Source0: DUMMY
# Source0: KozGoPr6N-Bold.otf
# Source1: KozGoPr6N-ExtraLight.otf
# Source2: KozGoPr6N-Heavy.otf
# Source3: KozGoPr6N-Light.otf
# Source4: KozGoPr6N-Medium.otf
# Source5: KozGoPr6N-Regular.otf
# Source6: KozGoPro-Bold.otf
# Source7: KozGoPro-ExtraLight.otf
# Source8: KozGoPro-Heavy.otf
# Source9: KozGoPro-Light.otf
# Source10: KozGoPro-Medium.otf
# Source11: KozGoPro-Regular.otf
# Source12: KozGoStd-Bold.otf
# Source13: KozGoStd-ExtraLight.otf
# Source14: KozGoStd-Heavy.otf
# Source15: KozGoStd-Light.otf
# Source16: KozGoStd-Medium.otf
# Source17: KozGoStd-Regular.otf
# Source18: KozMinPr6N-Bold.otf
# Source19: KozMinPr6N-ExtraLight.otf
# Source20: KozMinPr6N-Heavy.otf
# Source21: KozMinPr6N-Light.otf
# Source22: KozMinPr6N-Medium.otf
# Source23: KozMinPr6N-Regular.otf
# Source24: KozMinPro-Bold.otf
# Source25: KozMinPro-ExtraLight.otf
# Source26: KozMinPro-Heavy.otf
# Source27: KozMinPro-Light.otf
# Source28: KozMinPro-Medium.otf
# Source29: KozMinPro-Regular.otf
# Source30: KozMinStd-Bold.otf
# Source31: KozMinStd-ExtraLight.otf
# Source32: KozMinStd-Heavy.otf
# Source33: KozMinStd-Light.otf
# Source34: KozMinStd-Medium.otf
# Source35: KozMinStd-Regular.otf
 
%if %{?nosrc:1} %{!?nosrc:0}
NoSource: 0
# NoSource: 1
# NoSource: 2
# NoSource: 3
# NoSource: 4
# NoSource: 5
# NoSource: 6
# NoSource: 7
# NoSource: 8
# NoSource: 9
# NoSource: 10
# NoSource: 11
# NoSource: 12
# NoSource: 13
# NoSource: 14
# NoSource: 15
# NoSource: 16
# NoSource: 17
# NoSource: 18
# NoSource: 19
# NoSource: 20
# NoSource: 21
# NoSource: 22
# NoSource: 23
# NoSource: 24
# NoSource: 25
# NoSource: 26
# NoSource: 27
# NoSource: 28
# NoSource: 29
# NoSource: 30
# NoSource: 31
# NoSource: 32
# NoSource: 33
# NoSource: 34
# NoSource: 35
%endif

License: Adobe Systems Incorporated.
URL: http://www.adobe.co.jp
Group: User Interface/X
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root

Obsoletes: OTF-Kozuka < 1.0-3

Requires(post): fontconfig ghostscript texmacro-otf
Requires(postun): fontconfig ghostscript texmacro-otf

Distribution: Vine Linux
Vendor: Project Vine

%description
Kozuka Japanese OpenType Font
If you want to use Kozuka OpneType Font on X and teTeX 
(xdvi, dvips, dvipdfmx), Ghostscript, 
you build and install this package. 
To build this package, you copy Kozuka Fonts from package
which you bought to ~/rpm/SOURCES
Then you type
$ rpm -bb ~/rpm/SPEC/%{name}-vl.spec
$ sudo apt-get install ~/rpm/RPMS/noarch/%{name}-%{version}-%{release}.noarch.rpm

%description -l ja
Adobe の日本語 OpenType フォント
購入したパッケージの小塚ファミリー日本語 OpenType フォントを 
X や TeX Live ((p)xdvi, (p)dvips, dvipdfmx)、Ghostscript で使用したい場合は
このパッケージを構築してインストールして下さい。
このパッケージを構築するには購入したパッケージからフォントを 
~/rpm/SOURCES にコピーします。
次に、
$ rpm -bb ~/rpm/SPEC/%{name}-vl.spec
$ sudo apt-get install ~/rpm/RPMS/noarch/%{name}-%{version}-%{release}.noarch.rpm
とタイプして下さい。

%prep

%build

%install
%__rm -rf %{buildroot}
%__mkdir -p %{buildroot}%{xfontdir}
%__mkdir -p %{buildroot}%{gsfontdir}
%__mkdir -p %{buildroot}%{gsfontspecdir}
%__mkdir -p %{buildroot}%{texfontdir}
%__install -p -m 644 \
    %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} %{SOURCE5} %{SOURCE6} %{SOURCE7} %{SOURCE8} %{SOURCE9} %{SOURCE10} %{SOURCE11} %{SOURCE12} %{SOURCE13} %{SOURCE14} %{SOURCE15} %{SOURCE16} %{SOURCE17} %{SOURCE18} %{SOURCE19} %{SOURCE20} %{SOURCE21} %{SOURCE22} %{SOURCE23} %{SOURCE24} %{SOURCE25} %{SOURCE26} %{SOURCE27} %{SOURCE28} %{SOURCE29} %{SOURCE30} %{SOURCE31} %{SOURCE32} %{SOURCE33} %{SOURCE34} %{SOURCE35} \
    %{buildroot}%{xfontdir}

## mkgsfontspec [fontname] [encode] > [fontspec]
mkgsfontspec(){
    local fontname=$1
    local encode=$2
	cat <<EOT
%%!PS-Adobe-3.0 Resource-Font
%%%%DocumentNeededResources: ${encode} (CMap)
%%%%IncludeResource: ${encode} (CMap)
%%%%BeginResource: Font (${fontname}-${encode})
(${fontname}-${encode})
(${encode}) /CMap findresource
[(${fontname}) /CIDFont findresource]
composefont
pop
%%%%EndResource
%%%%EOF
EOT
}

for i in %{FontList}; do
    fnt=$(echo $i | %__sed -e "s/,.*$//")
    enc=$(echo $i | %__sed -e "s/^.*,//")

    case $enc in
    	 Japan)	enclist="%{EncodeList_Japan}";;
	 GB)	enclist="%{EncodeList_GB}";;
	 CNS)	enclist="%{EncodeList_CNS}";;
	 Korea)	enclist="%{EncodeList_Korea}";;
	 *)	exit 1;;
    esac

    %__ln_s -f %{xfontdir}/${fnt}.otf %{buildroot}%{texfontdir}/${fnt}.otf
    %__ln_s -f %{xfontdir}/${fnt}.otf %{buildroot}%{gsfontdir}/${fnt}

    for j in $enclist; do
    	mkgsfontspec ${fnt} ${j} > %{buildroot}%{gsfontspecdir}/${fnt}-${j}
    done
done


%post
%__font_install_post %{xfontdir}

%{exec_updmap_otf}
exit 0

%postun
%__font_install_postun %{xfontdir}

if [ "$1" = "0" ]; then
    %{exec_updmap_otf}
fi
exit 0

%clean
%__rm -rf %{buildroot}

%files
%defattr(-,root,root)
#%doc README*
%{xfontdir}/*
%{gsfontdir}/*
%{gsfontspecdir}/*
%{texfontdir}/*

%changelog
* Sun Mar  4 2012 Munehiro Yamamoto <munepi@vinelinux.org> 1.0-4
- dropped Requires(post): chkfontpath

* Sat Jun 11 2011 Munehiro Yamamoto <munepi@vinelinux.org> 1.0-3
- supported Vine Linux 6 + TeX Live 2009
- added Obsoletes: OTF-Kozuka < 1.0-3

* Sat Jun 20 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.0-2
- changed xfontdir

* Sun Jun 07 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.0-1
- spec in utf8
- applied new versioning policy
- s/Copyright/License/
- corrected %%description
- setup for Ghostscript 8.64
  - created many font spec files

* Sat Jun 18 2005 KOBAYASHI Taizo <tkoba@ike-dyn.ritsumei.ac.jp> 1.0-0vl3
- modified for teTeX3

* Thu Apr 02 2004 KOBAYASHI R. Taizo <tkoba@ike-dyn.ritsumei.ac.jp> 1-0vl2
- fix postun

* Fri Apr 02 2004 KOBAYASHI R. Taizo <tkoba@ike-dyn.ritsumei.ac.jp> 1-0vl1
- initial release
