You are not logged in.

#1 2005-02-01 06:14:37

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

Refresh Fonts Script

I use this in all my font pkgs and to do a general refersh when things get screwed up - it is based on bits from various font pkgs.  Run it in a term ideally and don't forget to restart X

#!/bin/bash

basedir=/usr/X11R6/lib/X11/fonts

cd $basedir

echo "Rebuilding font cache..."
fc-cache -fv
echo "...done."

for dir in {TTF,misc,75dpi,Type1,Speedo,100dpi,cyrillic,artwiz-fonts,terminus,lfp-fix,lfp-var,nucleus}
do
    
echo "Rebuilding font index in $dir..."
cd $dir
mkfontscale
mkfontdir
rm -f encodings.dir
ln -s /usr/X11R6/lib/X11/fonts/encodings/encodings.dir encodings.dir
echo "...done."

cd $basedir
done

echo "Fonts refreshed!  Press any key to exit."
read KEY

Offline

#2 2005-02-01 14:49:07

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: Refresh Fonts Script

I wonder if it would be possible to not restart x if you add xset -fp and xset +fp for each font dir (something like xset -fp ${basedir}/${dir} and then xset +fp ${basedir}/${dir} after reindexing and inside "for")?

EDIT: or fp rehash ?

fp rehash
The rehash argument resets the font path to its current value, causing the server to reread the font databases in the current font path. This is generally only used when adding new fonts to a font directory (after running mkfontdir to recreate the font database).

-fp or fp-
The -fp and fp- options remove elements from the current font path. They must be followed by a comma-separated list of entries.

+fp or fp+
This +fp and fp+ options prepend and append elements to the current font path, respectively. They must be followed by a comma-separated list of entries.

EDIT2: of course this is not something to be put inside pkgbuild's install file because you may not be running x while running this script. On the other hand it should be possible to detect if you are running x or not and further improve the script (ah perfection...)

Offline

#3 2005-02-01 17:14:34

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Refresh Fonts Script

you could do like

[-x $DISPLAY ] && xpset fp rehash

Offline

#4 2005-02-02 13:33:52

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

Re: Refresh Fonts Script

nice one guys

Offline

#5 2005-02-09 10:40:14

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

Re: Refresh Fonts Script

#!/bin/bash

# which xserver are we running?

if [ -z "$(pacman -Qi | grep xorg)" ]; then
    xconfig=/etc/X11/XF86Config-4
else
    xconfig=/etc/X11/xorg.conf
fi

echo "Rebuilding font cache..."
fc-cache -fv
echo "...done."

# grab the font paths from xserver config

FontPath=`cat $xconfig | grep "FontPath .*/" | sed "s|#FontPath .*||g" | sed "s|FontPath||g" | sed "s|"||g" | sed "s|.*:unscaled||g"`

for dir in $FontPath; do
    echo "Rebuilding font index in $dir..."
    cd $dir
    mkfontscale
    mkfontdir
    rm -f encodings.dir
    ln -s /usr/X11R6/lib/X11/fonts/encodings/encodings.dir encodings.dir
    echo "...done."
    cd $basedir
done

echo "Fonts refreshed!  Press any key to exit."
read KEY

improved smile still no x detect and xset but i'll work on that

phrak - how do i set my $DISPLAY var - it doesn't seem to be set which is screwing up me lauching apps in win from the console wink

Offline

#6 2005-04-12 11:13:57

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

Re: Refresh Fonts Script

OK! I finally included your suggestions!  I think this script is now as good as lanrat hoped.  It now detects if X is running and rehashes if it is.  You can now also run the script and provide a specific dir to be updated, this allows it to be included as a function in an install script.

#!/bin/bash

# some colour
colour="33[1;32m"
no_colour="33[1;0m"

# are we root?
if [ "$(whoami)" != "root" ] ; then
    echo "You need to run as root!"
    exit
fi

# which xserver are we running?
if [ -z "$(pacman -Qi | grep xorg)" ] ; then
    xconfig=/etc/X11/XF86Config-4
else
    xconfig=/etc/X11/xorg.conf
fi

echo -e "${no_colour}Rebuilding font cache..."
fc-cache -fv
echo

# Grab the font paths from command line (for specific install)
# or xserver config (for general refresh)
if [ -z $1 ] ; then
    FontPath=`cat $xconfig | grep "FontPath .*/" | sed "s|#FontPath .*||g" | 
    sed "s|FontPath||g" | sed "s|"||g" | sed "s|.*:unscaled||g"`
else
    FontPath="$1"
fi

for dir in $FontPath ; do
    echo -ne "${no_colour}Rebuilding font index in $dir..."
    cd $dir
    mkfontscale
    mkfontdir
    rm -f encodings.dir
    ln -s /usr/X11R6/lib/X11/fonts/encodings/encodings.dir encodings.dir
    [ ! -z $DISPLAY ] && xset fp rehash
    echo -e "${colour}done${no_colour}."
done

echo
echo -e "${no_colour}Fonts refreshed!  Press any key to exit."
read KEY

I added the colour for fun - easy to remove!

Offline

#7 2006-03-04 03:13:23

Ethilien
Member
From: Parker, CO
Registered: 2005-09-21
Posts: 36
Website

Re: Refresh Fonts Script

I didn't write this of course, but I thought I'd update it for xorg7

#!/bin/bash

# some colour
colour="33[1;32m"
no_colour="33[1;0m"

# are we root?
if [ "$(whoami)" != "root" ] ; then
   echo "You need to run as root!"
   exit
fi

# which xserver are we running?
if [ -z "$(pacman -Qi | grep xorg)" ] ; then
   xconfig=/etc/X11/XF86Config-4
else
   xconfig=/etc/X11/xorg.conf
fi

echo -e "${no_colour}Rebuilding font cache..."
fc-cache -fv
echo

# Grab the font paths from command line (for specific install)
# or xserver config (for general refresh)
if [ -z $1 ] ; then
   FontPath=`cat $xconfig | grep "FontPath .*/" | sed "s|#FontPath .*||g" | 
   sed "s|FontPath||g" | sed "s|"||g" | sed "s|.*:unscaled||g"`
else
   FontPath="$1"
fi

for dir in $FontPath ; do
   echo -ne "${no_colour}Rebuilding font index in $dir..."
   cd $dir
   mkfontscale
   mkfontdir
   rm -f encodings.dir
   ln -s /usr/share/fonts/encodings/encodings.dir encodings.dir
   [ ! -z $DISPLAY ] && xset fp rehash
   echo -e "${colour}done${no_colour}."
done

echo
echo -e "${no_colour}Fonts refreshed!  Press any key to exit."
read KEY

-Connor McKay

"He is no fool who gives what he cannot keep to gain what he cannot lose" - Jim Elliot

Offline

Board footer

Powered by FluxBB