[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[RFC] Better font filetype and metadata file detection for xfsinitscript



The attached diff attempts to do the following improvements 
to the xfs initscript for performance and correctness:

The individual fixes are:

- Consider all .ttf, .ttc, .otf, .otc file extensions of any 
  combination of upper and/or lowercase in a font directory to be 
  a truetype or opentype font which ttmkfdir should handle.  
  Previously, only .ttf and .ttc fonts were handled.  This is a
  correctness fix.

- When determining wether or not mkfontdir and ttmkfdir need to 
  be called, ignore any fonts.cache files that might be present, 
  as they're metadata files, not fonts.  This is both a 
  correctness and performance fix, as any non-font metadata files 
  found that aren't explicitly ignored, but are newer than 
  fonts.dir will unnecessarily trigger regeneration of fonts.dir

- When determining wether a directory contains non-truetype 
  fonts, ignore all ttf/ttc/otf/otc font types, not just ttf.

- If any fonts.dir files were recreated, it now calls fc-cache 
  afterward if fc-cache exists, in order to update all fontconfig 
  fonts.cache-* files

I've studied the regular expressions carefully and think that
they cleanly implement the above, however there could be a glitch
in there, so I'd like to get other people to review this change
before officially committing it to the next build of XFree86, as
a bad regex could result in rather serious font subsystem
breakage, so the more eyes who review this the better.

If you review the change and think it to be correct, please
respond with an "ACK" email to fedora-devel-list, along with 
any comments and/or suggestions for futher improvements.


On a separate note from the above, there is one possible flaw 
that was in the original initscript as well as my above proposal, 
however I want this issue treated/considered separately from the 
above, so please comment on each issue separately.  The following 
line:

if [ "$(ls |grep -iv '\(fonts\.\(scale\|alias\|cache.*\)$\|.+\(\.[ot]t[cf]\|dir\)$\)')" != "" ]; then

In both the original initscript, and this updated one, the test 
doesn't take into account wether or not the directory may contain 
subdirectories for whatever reason.  If the dir does contain 
subdirs, the subdir name will pass the grep test, and cause 
mkfontdir to be executed even if no font files are updated.

I'm thinking of changing this ls|grep test to be something 
similar to the following, which explicitly tests for files only 
and ignores dirs:

if [ "$(find . -type f -maxdepth=0 -not -regex '.*fonts\.\(scale\|alias\|cache.*\)$' -and -not -iregex '.+\(\.[ot]t[cf]\|dir\)$' != "" ]; then

It's ugly, but I believe it may do what we're looking for nicely.  
Comments appreciated.





-- 
Mike A. Harris     ftp://people.redhat.com/mharris
OS Systems Engineer - XFree86 maintainer - Red Hat
--- xfs.init.old	2003-09-18 19:15:34.000000000 -0400
+++ xfs.init	2003-10-08 23:08:35.000000000 -0400
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # xfs:       Starts the X Font Server
 #
@@ -29,28 +29,32 @@
       if [ -d "$d" ]; then
          cd $d
          # Check if we need to rerun mkfontdir
-         NEEDED=no
+         REGEN_FONTS_DIR=no
          if ! [ -e fonts.dir ]; then
-            NEEDED=yes
-         elif [ "$(find . -type f -cnewer fonts.dir 2>/dev/null)" != "" ];then
-            NEEDED=yes
+            REGEN_FONTS_DIR=yes
+         elif [ "$(find . -type f -cnewer fonts.dir -not -name "fonts.cache*" 2>/dev/null)" != "" ];then
+            REGEN_FONTS_DIR=yes
          fi
-         if [ "$NEEDED" = "yes" ]; then
+         if [ "$REGEN_FONTS_DIR" = "yes" ]; then
             rm -f fonts.dir &>/dev/null
-            if ls | grep -i "\.tt[cf]$" &>/dev/null; then
-               # TrueType fonts found...
+            if ls | grep -i "\.[ot]t[cf]$" &>/dev/null; then
+               # TrueType or Opentype fonts found...
                ttmkfdir -d . -o fonts.scale
                mkfontdir . &>/dev/null
                [ -e fonts.dir ] && chmod 644 fonts.scale fonts.dir
             fi
-            if [ "$(ls |egrep -iv '\.tt[cf]$|^fonts\.|^encodings\.')" != "" ]; then
-               # This directory contains fonts that are not TrueType...
+            if [ "$(ls |grep -iv '\(fonts\.\(scale\|alias\|cache.*\)$\|.+\(\.[ot]t[cf]\|dir\)$\)')" != "" ]; then
+               # This directory contains fonts that are not TrueType or Opentype...
                mkfontdir . &>/dev/null
                [ -e fonts.dir ] && chmod 644 fonts.dir
             fi
          fi
       fi
    done
+   # Recreating fonts.dir files above may result in stale fonts.cache-1
+   # files since the directory mtimes change, so we run fc-cache to
+   # update any necessary fonts.cache files.
+   [ "$REGEN_FONTS_DIR" = "yes" -a -x /usr/bin/fc-cache ] && /usr/bin/fc-cache
    popd &> /dev/null
 }
 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]