font.eclass: Upgrade to latest from gentoo

Before making some custom changes, let's pull the latest.

BUG=b:187790181
TEST=build

Change-Id: I57e1b9d01b5cbedca07baf8a6f3779d9b05fadaa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/eclass-overlay/+/4428445
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Commit-Queue: Brian Norris <briannorris@chromium.org>
diff --git a/eclass/font.eclass b/eclass/font.eclass
index 0196755..3d25781 100644
--- a/eclass/font.eclass
+++ b/eclass/font.eclass
@@ -1,4 +1,4 @@
-# Copyright 1999-2022 Gentoo Authors
+# Copyright 1999-2023 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: font.eclass
@@ -7,16 +7,14 @@
 # @SUPPORTED_EAPIS: 7 8
 # @BLURB: Eclass to make font installation uniform
 
-case ${EAPI:-0} in
-	[7-8]) ;;
-	*) die "EAPI ${EAPI} is not supported by font.eclass." ;;
+case ${EAPI} in
+	7|8) ;;
+	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
 esac
 
-if [[ ! ${_FONT_ECLASS} ]]; then
+if [[ -z ${_FONT_ECLASS} ]]; then
 _FONT_ECLASS=1
 
-EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
-
 # @ECLASS_VARIABLE: FONT_SUFFIX
 # @DEFAULT_UNSET
 # @REQUIRED
@@ -46,6 +44,12 @@
 # Array containing fontconfig conf files to install.
 FONT_CONF=( "" )
 
+# @ECLASS_VARIABLE: FONT_OPENTYPE_COMPAT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Determines whether detected BDF and PCF font files should be converted
+# to an SFNT wrapper, for use with newer Pango.
+
 if [[ ${CATEGORY}/${PN} != media-fonts/encodings ]]; then
 	IUSE="X"
 	BDEPEND="X? (
@@ -54,6 +58,31 @@
 	)"
 fi
 
+if [[ -n ${FONT_OPENTYPE_COMPAT} ]] ; then
+	IUSE+=" +opentype-compat"
+	BDEPEND+=" opentype-compat? ( x11-apps/fonttosfnt )"
+fi
+
+# @FUNCTION: font_wrap_opentype_compat
+# @DESCRIPTION:
+# Converts .bdf and .pcf fonts detected within ${ED} to the OTB wrapper format
+# using x11-apps/fonttosfnt.  Handles optional .gz extension.
+font_wrap_opentype_compat() {
+	local file tmpfile
+
+	while IFS= read -rd '' file; do
+		if [[ ${file} == *.gz ]] ; then
+			tmpfile=${file%.*}
+
+			gzip -cd -- "${file}" > "${tmpfile}" \
+			&& fonttosfnt -v -o "${file%.*}.otb" -- "${tmpfile}" \
+			&& rm -- "${tmpfile}"
+		else
+			fonttosfnt -v -o "${file%.*}.otb" -- "${file}"
+		fi || ! break
+	done < <(find "${ED}" \( -name '*.bdf' -o -name '*.bdf.gz' -o -name '*.pcf' -o -name '*.pcf.gz' \) -type f ! -type l -print0) || die
+}
+
 # @FUNCTION: font_xfont_config
 # @DESCRIPTION:
 # Generate Xorg font files (mkfontscale/mkfontdir).
@@ -150,6 +179,10 @@
 font_src_install() {
 	local dir suffix commondoc
 
+	if [[ -n ${FONT_OPENTYPE_COMPAT} ]] && in_iuse opentype-compat && use opentype-compat ; then
+		font_wrap_opentype_compat
+	fi
+
 	if [[ $(declare -p FONT_S 2>/dev/null) == "declare -a"* ]]; then
 		# recreate the directory structure if FONT_S is an array
 		for dir in "${FONT_S[@]}"; do
@@ -229,3 +262,5 @@
 }
 
 fi
+
+EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm