#!/bin/bash ################################################################################# # # # font-convert batch & recursive Type1 fonts to .OTF format conversion # # # # relies on: # # - fontforge project: # # https://fontforge.github.io/en-US/ # # # # - font-convert (check site) # # https://fontforge.github.io/scripting-tutorial.html # # # # by TCMcG 2019-01-20 # # # # place in ~/bin/ # # # ################################################################################# PROGNAME=`basename $0` OIFS=$IFS IFS=$'\n' usage () { cat <<- EOF Usage 1: $PROGNAME SRC_DIR DST_DIR recursively convert Type1 fonts to .otf fonts using FontForge Where: SRC_DIR is the [parent] directory where the Type1 fonts reside DST_DIR is the directory where the converted files will be written to EOF return } MAIN_CMD="/usr/bin/fontforge" CONVERT_CMD="${HOME}/bin/font-convert.pe" OUT_FORMAT='.otf' FONTFORGE_LANGUAGE=ff export FONTFORGE_LANGUAGE OUT_FORMAT SRC_DIR=${1} DST_DIR=${2} if [[ -z $1 || -z $2 ]]; then usage >&2 exit 2 fi if [[ ! -d $DST_DIR ]]; then mkdir $DST_DIR if [[ $? != 0 ]]; then sudo mkdir $DST_DIR if [[ $? != 0 ]]; then echo "You do not have priveleges to create a directory in this location." exit 3 fi fi fi cd $SRC_DIR PFBFonts=`find . -type f -iname "*.pfb" | sed -e 's/^\.\///g'` for font in $PFBFonts; do # convert the fonts here $CONVERT_CMD ${font} $OUT_FORMAT if [[ $? != 0 ]]; then sudo $CONVERT_CMD ${font} $OUT_FORMAT if [[ $? != 0 ]]; then echo "You do not have priveleges to write to this location." exit 3 fi fi done OTFFonts=`find . -type f -iname "*.otf" | sed -e 's/^\.\///g' ` for font in $OTFFonts; do mv ${SRC_DIR}/${font} $DST_DIR if [[ $? != 0 ]]; then sudo mv ${SRC_DIR}/${font} $DST_DIR if [[ $? != 0 ]]; then echo "You do not have priveleges to move files to this location." exit 3 fi fi done IFS=$OIFS exit 0