summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2018-10-29 16:39:05 -0700
committerAkira TAGOH <akira@tagoh.org>2019-04-03 12:02:09 +0000
commitc4324f54ee16e648ba91f3e9c66af13ab3b1754c (patch)
treedd64c4ac0bc6d628bf39cafabe1950578c2dfdbd /test
parent4cde12bfda1316e6d5464a2d9607d15322ef8024 (diff)
downloadfontconfig-c4324f54ee16e648ba91f3e9c66af13ab3b1754c.tar.gz
Replace UUID file mechanism with per-directory 'map' attribute [v2]
The UUID files would be placed in each font directory to provide the unique cache name, independent of path, for that directory. The UUID files are undesireable for a couple of reasons: 1) They must be placed in the font directories to be useful. This requires modifying the font directories themselves, introducing potential visible timestamp changes when running multiple applications, and makes the cache processing inconsistent between applications with permission to write to the font directories and applications without such permission. 2) The UUID contents were generated randomly, which makes the font cache not reproducible across multiple runs. One proposed fix for 2) is to make the UUID dependent on the font directory path, but once we do that, we can simply use the font directory path itself as the key as the original MD5-based font cache naming mechanism did. The goal of the UUID file mechanism was to fix startup time of flatpaks; as the font path names inside the flatpak did not match the font path names in the base system, the font cache would need to be reconstructed the first time the flatpak was launched. The new mechanism for doing this is to allow each '<dir>' element in the configuration include a 'map' attribute. When looking for a cache file for a particular directory, if the directory name starts with the contents of the <dir> element, that portion of the name will be replaced with the value of the 'map' attribute. Outside of the flatpak, nothing need change -- fontconfig will build cache files using real directory names. Inside the flatpak, the custom fonts.conf file will now include mappings such as this: <dir map="/usr/share/fonts">/run/host/fonts</dir> When scanning the directory /run/host/fonts/ttf, fontconfig will use the name /usr/share/fonts/ttf as the source for building the cache file name. The existing FC_FILE replacement code used for the UUID-based implementation continues to correctly adapt font path names seen by applications. v2: Leave FcDirCacheCreateUUID stub around to avoid removing public API function. Document 'map' attribute of <dir> element in fontconfig-user.sgml Suggested-by: Akira TAGOH <akira@tagoh.org> Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am2
-rw-r--r--test/fonts.conf.in2
-rwxr-xr-xtest/run-test-map.sh107
-rw-r--r--test/run-test.sh2
4 files changed, 111 insertions, 2 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index ff693e4..81aace0 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,4 +1,4 @@
-check_SCRIPTS=run-test.sh
+check_SCRIPTS=run-test.sh run-test-map.sh
TEST_EXTENSIONS = \
.sh \
$(NULL)
diff --git a/test/fonts.conf.in b/test/fonts.conf.in
index 95def72..24bd58b 100644
--- a/test/fonts.conf.in
+++ b/test/fonts.conf.in
@@ -1,4 +1,4 @@
<fontconfig>
-<dir>@FONTDIR@</dir>
+<dir @MAP@>@FONTDIR@</dir>
<cachedir>@CACHEDIR@</cachedir>
</fontconfig>
diff --git a/test/run-test-map.sh b/test/run-test-map.sh
new file mode 100755
index 0000000..869d7b2
--- /dev/null
+++ b/test/run-test-map.sh
@@ -0,0 +1,107 @@
+#!/bin/bash
+# fontconfig/test/run-test-cache-map.sh
+#
+# Copyright © 2018 Keith Packard
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that copyright
+# notice and this permission notice appear in supporting documentation, and
+# that the name of the copyright holders not be used in advertising or
+# publicity pertaining to distribution of the software without specific,
+# written prior permission. The copyright holders make no representations
+# about the suitability of this software for any purpose. It is provided "as
+# is" without express or implied warranty.
+#
+# THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+# EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+# OF THIS SOFTWARE.
+#
+
+case "$OSTYPE" in
+ msys ) MyPWD=`pwd -W` ;; # On Msys/MinGW, returns a MS Windows style path.
+ * ) MyPWD=`pwd` ;; # On any other platforms, returns a Unix style path.
+esac
+
+TESTDIR=${srcdir-"$MyPWD"}
+BUILDTESTDIR=${builddir-"$MyPWD"}
+
+FONTDIRA="$MyPWD"/fontsa
+FONTDIRB="$MyPWD"/fontsb
+CACHEDIR="$MyPWD"/cache.dir
+EXPECTEDIN=${EXPECTEDIN-"out-map.expected.in"}
+EXPECTEDA="out-map-a.expected"
+EXPECTEDB="out-map-b.expected"
+EXPECTED="out-map.expected"
+
+FCLIST=../fc-list/fc-list$EXEEXT
+FCCACHE=../fc-cache/fc-cache$EXEEXT
+
+which bwrap > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+ BWRAP=`which bwrap`
+fi
+
+FONT1=$TESTDIR/4x6.pcf
+FONT2=$TESTDIR/8x16.pcf
+
+check () {
+ $FCLIST - file family pixelsize | sort > out
+ echo "=" >> out
+ $FCLIST - file family pixelsize | sort >> out
+ echo "=" >> out
+ $FCLIST - file family pixelsize | sort >> out
+ tr -d '\015' <out >out.tmp; mv out.tmp out
+ if cmp out $BUILDTESTDIR/$EXPECTED > /dev/null ; then : ; else
+ echo "*** Test failed: $TEST"
+ echo "*** output is in 'out', expected output in '$EXPECTED'"
+ exit 1
+ fi
+ rm -f out
+}
+
+prep() {
+ rm -rf $CACHEDIR
+ rm -rf $FONTDIRA $FONTDIRB
+ mkdir $FONTDIRA
+ mkdir $CACHEDIR
+}
+
+dotest () {
+ TEST=$1
+ test x$VERBOSE = x || echo Running: $TEST
+}
+
+sed "s!@FONTDIR@!$FONTDIRA!
+s!@MAP@!!
+s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts-a.conf
+
+sed "s!@FONTDIR@!$FONTDIRB!
+s!@MAP@!map="'"'"$FONTDIRA"'"'"!
+s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts-b.conf
+
+sed "s!@FONTDIR@!$FONTDIRA!" < $EXPECTEDIN > $EXPECTEDA
+sed "s!@FONTDIR@!$FONTDIRB!" < $EXPECTEDIN > $EXPECTEDB
+
+FONTCONFIG_FILE="$MyPWD"/fonts-a.conf
+export FONTCONFIG_FILE
+
+dotest "Basic check"
+prep
+cp $FONT1 $FONT2 $FONTDIRA
+cp $EXPECTEDA $EXPECTED
+$FCCACHE $FONTDIRA
+check
+
+dotest "mapped check"
+prep
+cp $FONT1 $FONT2 $FONTDIRA
+cp $EXPECTEDB $EXPECTED
+$FCCACHE $FONTDIRA
+mv $FONTDIRA $FONTDIRB
+export FONTCONFIG_FILE="$MyPWD"/fonts-b.conf
+check
diff --git a/test/run-test.sh b/test/run-test.sh
index a05dadb..b9a07b8 100644
--- a/test/run-test.sh
+++ b/test/run-test.sh
@@ -73,6 +73,7 @@ dotest () {
}
sed "s!@FONTDIR@!$FONTDIR!
+s!@MAP@!!
s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts.conf
FONTCONFIG_FILE="$MyPWD"/fonts.conf
@@ -145,6 +146,7 @@ sleep 1
ls -l $CACHEDIR > out1
TESTTMPDIR=`mktemp -d /tmp/fontconfig.XXXXXXXX`
sed "s!@FONTDIR@!$TESTTMPDIR/fonts!
+s!@MAP@!map="'"'"$FONTDIR"'"'"!
s!@CACHEDIR@!$TESTTMPDIR/cache.dir!" < $TESTDIR/fonts.conf.in > bind-fonts.conf
$BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/fc-match/fc-match$EXEEXT -f "%{file}\n" ":foundry=Misc" > xxx
$BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/test/test-bz106618$EXEEXT | sort > flist1