%global fontname    oldstandard
%global fontconf    60-%{fontname}.conf

Name:           %{fontname}-sfd-fonts
Version:        2.0.2
Release:        1
Summary:        Old Standard True-Type Fonts

License:        OFL-1.1
URL:            https://fontlibrary.org/en/font/old-standard
Source0:        http://www.thessalonica.org.ru/downloads/oldstandard-2.0.2.src.zip
# This is used to generate the fontconfig configuration file, thanks to Ankur Sinha.
# https://src.fedoraproject.org/rpms/oldstandard-sfd-fonts/raw/main/f/oldstandard-sfd-fonts-fontconfig.conf
Source1:        %{name}-fontconfig.conf
Source2:        http://www.thessalonica.org.ru/downloads/oldstand-manual.pdf
# This is for appstream, thanks to Parag Nemade.
# https://src.fedoraproject.org/rpms/oldstandard-sfd-fonts/raw/main/f/oldstandard.metainfo.xml
Source3:        %{fontname}.metainfo.xml

BuildArch:      noarch
BuildRequires:  fontforge,fontpackages-devel
Requires:       fontpackages-filesystem

%description
The Old Standard font family is an attempt to revive
a specific type of Modern (classicist) style of serif
typefaces, very commonly used in various editions
printed in the late 19th and early 20th century,
but almost completely  abandoned later.

%prep
%setup -q -c -n oldstandard-%{version}

for i in $(ls OldStandard*.sfd);do
    sed -i -e 's/OldStandardTT/OldStandardSFD/'  -e 's/Old \Standard \TT/Old \Standard \SFD/' $i;
done
for txt in OFL* ; do
    sed 's/\r//' $txt > $txt.new
    touch -r $txt $txt.new
    mv $txt.new $txt
done

install -m 644 -p %{SOURCE2} .

%build
fontforge -lang=ff -script "-" OldStandard*.sfd <<EOF
i = 1 
while ( i < \$argc )
  Open (\$argv[i], 1)
  Generate (\$fontname + ".otf")
  PrintSetup (5) 
  PrintFont (0, 0, "", \$fontname + "-sample.pdf")
  Close()
  i++ 
endloop
EOF

%install
install -m 755 -d %{buildroot}%{_fontdir}
install -m 644 -p *.otf %{buildroot}%{_fontdir}

install -m 755 -d %{buildroot}%{_fontconfig_templatedir} \
        %{buildroot}%{_fontconfig_confdir}

install -m 644 -p %{SOURCE1} \
    %{buildroot}%{_fontconfig_templatedir}/%{fontconf}

ln -s %{_fontconfig_templatedir}/%{fontconf} \
    %{buildroot}%{_fontconfig_confdir}/%{fontconf}

# Add AppStream metadata
install -Dm 0644 -p %{SOURCE3} \
        %{buildroot}%{_datadir}/appdata/%{fontname}.metainfo.xml

%_font_pkg -f %{fontconf} *.otf
%doc *.txt *.pdf
%{_datadir}/appdata/%{fontname}.metainfo.xml

%changelog
* Mon Jun 06 2022 misaka00251 <misaka00251@misakanet.cn> - 2.0.2-1
- Init package (Thanks to fedora team)
