#!/bin/sh

# VERSION: 1.04
# (c) 1998 SALSOFT, Jan ONDREJ (SAL) <ondrejj@salstar.shadow.sk>
# GPL
#
# With a little updates by Petr@Kristof.CZ, (c) 2000 GNU GPL 2.0.
#

STAR_OFFICE_ROOT=/opt/office52
FONTS_DIR=/usr/share/fonts/ISO8859-2/Type1

# -----------------------------------------------------------------------
# Pozor!!! Needitujte skript pod tymto riadkom.
# -----------------------------------------------------------------------

XP3_DIR=$STAR_OFFICE_ROOT/share/xp3
T1FONTS_DIR=$STAR_OFFICE_ROOT/share/fonts/type1

if [ -e $XP3_DIR/psstd.fonts.il2 ]; then
  echo "Zmeny uz boli raz prevedene! Nemozno previest znova."
  echo "Ak je nejaky problem a predsa to chcete, tak zmazte subor"
  echo "  $XP3_DIR/psstd.fonts.il2"
  exit 1
fi

if [ -e $FONTS_DIR/afm ]; then
  AFM_DIR=$FONTS_DIR/afm
else
  AFM_DIR=$FONTS_DIR
fi

# Link AFM files.
ln -sf $AFM_DIR/*.[aA][fF][mM] $XP3_DIR/fontmetrics/afm

# Link PFB files.
ln -sf $FONTS_DIR/*.[pP][fF][bB] $XP3_DIR/pssoftfonts/

# Link pfb files into type1 fonts directory.
ln -sf $FONTS_DIR/*.[pP][fF][bB] $T1FONTS_DIR/

# Make new fonts.{alias,dir,scale}
for FS in fonts.{alias,dir,scale}; do
  if [ ! -x $T1FONTS_DIR/$FS.orig ]; then
    mv $T1FONTS_DIR/$FS $T1FONTS_DIR/$FS.orig
  fi
done
cat $T1FONTS_DIR/fonts.alias.orig $FONTS_DIR/fonts.alias \
  > $T1FONTS_DIR/fonts.alias
for F in dir scale; do
  ( cat $T1FONTS_DIR/fonts.$F.orig | tail +2
    cat $FONTS_DIR/fonts.$F | tail +2
  ) > $T1FONTS_DIR/fonts.$F.new
  wc -l $T1FONTS_DIR/fonts.$F.new | awk '{print $1}' > $T1FONTS_DIR/fonts.$F
  cat $T1FONTS_DIR/fonts.$F.new >> $T1FONTS_DIR/fonts.$F
done

grep "\.pf" $FONTS_DIR/fonts.dir \
  | sed -e 's/\.pfb /, /g' -e 's/-0-0-0-0-/-%d-%d-%d-%d-/g' -e 's/adobe-fontspecific/iso8859-2/g'  \
  > $XP3_DIR/psstd.fonts.il2

echo -e "\n# Added by so_add_font.\n" \
  | cat - $XP3_DIR/psstd.fonts.il2 \
  >> $XP3_DIR/psstd.fonts


