Gentoo Archives: gentoo-dev

From: Sam James <sam@g.o>
To: gentoo-dev@l.g.o
Cc: x11@g.o, fonts@g.o, gnome@g.o, Kerin Millar <kfm@×××××××××.net>, Sam James <sam@g.o>
Subject: [gentoo-dev] [PATCH 1/5] font.eclass: introduce FONT_CONVERT_SFNT for converting old bitmap fonts
Date: Sat, 15 Oct 2022 03:10:30
Message-Id: 20221015030958.2422501-1-sam@gentoo.org
1 >=x11-libs/pango-1.44 dropped support for old bitmap fonts. We can convert
2 fonts from the legacy .bdf and .pcf formats into the OTB wrapper format
3 using x11-apps/fonttosfnt.
4
5 This commit adds FONT_CONVERT_SFNT which packages installing bitmap fonts
6 can set to opt-in to conversion.
7
8 Note that the font conversion isn't perfect -- it's good enough
9 in many cases, but in some cases they may require tweaking
10 via fontconfig to get pixel size right, antialiasing settings, ...
11
12 Adds IUSE=+convert-sfnt to any ebuilds which set FONT_CONVERT_SFNT;
13 enabled by default given discoverability of this issue may be difficult
14 and presumably any font package enabling FONT_CONVERT_SFNT will be
15 useless without it anyway.
16
17 See also https://fedoraproject.org/wiki/BitmapFontConversion.
18
19 Bug: https://bugs.gentoo.org/698922
20 Thanks-to: Kerin Millar <kfm@×××××××××.net>
21 Signed-off-by: Sam James <sam@g.o>
22 ---
23 eclass/font.eclass | 35 +++++++++++++++++++++++++++++++++++
24 1 file changed, 35 insertions(+)
25
26 diff --git a/eclass/font.eclass b/eclass/font.eclass
27 index 83636ac3fed5..4b7021ee0599 100644
28 --- a/eclass/font.eclass
29 +++ b/eclass/font.eclass
30 @@ -46,6 +46,12 @@ FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
31 # Array containing fontconfig conf files to install.
32 FONT_CONF=( "" )
33
34 +# @ECLASS_VARIABLE: FONT_CONVERT_SFNT
35 +# @DEFAULT_UNSET
36 +# @DESCRIPTION:
37 +# Determines whether detected BDF and PCF font files should be converted
38 +# to an SFNT wrapper, for use with newer Pango.
39 +
40 if [[ ${CATEGORY}/${PN} != media-fonts/encodings ]]; then
41 IUSE="X"
42 BDEPEND="X? (
43 @@ -54,6 +60,31 @@ if [[ ${CATEGORY}/${PN} != media-fonts/encodings ]]; then
44 )"
45 fi
46
47 +if [[ -n ${FONT_CONVERT_SFNT} ]] ; then
48 + IUSE+=" +convert-sfnt"
49 + BDEPEND+=" convert-sfnt? ( x11-apps/fonttosfnt )"
50 +fi
51 +
52 +# @FUNCTION: font_convert_sfnt
53 +# @DESCRIPTION:
54 +# Converts .bdf and .pcf fonts detected within ${ED} to the OTB wrapper format
55 +# using x11-apps/fonttosfnt. Handles optional .gz extension.
56 +font_convert_sfnt() {
57 + local file tmpfile
58 +
59 + while IFS= read -rd '' file; do
60 + if [[ ${file} != *.gz ]] ; then
61 + tmpfile=${file%.*}
62 +
63 + gzip -cd -- "${file}" > "${tmpfile}" \
64 + && fonttosfnt -v -o "${file%.*}.otb" -- "${tmpfile}" \
65 + && rm -- "${tmpfile}"
66 + else
67 + fonttosfnt -v -o "${file%.*}.otb" -- "${file}"
68 + fi || ! break
69 + done < <(find "${ED}" \( -name '*.bdf' -o -name '*.bdf.gz' -o -name '*.pcf' -o -name '*.pcf.gz' \) -type f ! -type l -print0) || die
70 +}
71 +
72 # @FUNCTION: font_xfont_config
73 # @DESCRIPTION:
74 # Generate Xorg font files (mkfontscale/mkfontdir).
75 @@ -150,6 +181,10 @@ font_pkg_setup() {
76 font_src_install() {
77 local dir suffix commondoc
78
79 + if [[ -n ${FONT_CONVERT_SFNT} ]] && in_iuse convert-sfnt && use convert-sfnt ; then
80 + font_convert_sfnt
81 + fi
82 +
83 if [[ $(declare -p FONT_S 2>/dev/null) == "declare -a"* ]]; then
84 # recreate the directory structure if FONT_S is an array
85 for dir in "${FONT_S[@]}"; do
86 --
87 2.38.0

Replies