- updated to 20150417:

added --user option

OBS-URL: https://build.opensuse.org/package/show/M17N/fonts-config?expand=0&rev=64
This commit is contained in:
Petr Gajdos 2015-04-17 14:22:23 +00:00 committed by Git OBS Bridge
parent 302f5404d0
commit ce3ee03fe1
5 changed files with 238 additions and 67 deletions

View File

@ -2,7 +2,7 @@
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<!-- DO NOT EDIT; this is a generated file --> <!-- DO NOT EDIT; this is a generated file -->
<!-- modify /etc/sysconfig/fonts-config && run fonts-config instead --> <!-- modify _SYSCONFIG_FILE_PLACEHOLDER_ && run _FONTSCONFIG_RUN_PLACEHOLDER_ instead -->
<!-- using target="pattern", because we want to change pattern in 60-family-prefer.conf <!-- using target="pattern", because we want to change pattern in 60-family-prefer.conf
regarding to this setting --> regarding to this setting -->
@ -58,5 +58,13 @@
_USE_EMBEDDED_BITMAPS_PLACEHOLDER_ _USE_EMBEDDED_BITMAPS_PLACEHOLDER_
<!-- Search for metric compatible families? -->
<match target="pattern" >
<edit name="search_metric_aliases" mode="assign">
<bool>_METRIC_ALIASES_PLACEHOLDER_</bool>
</edit>
</match>
_INCLUDE_USER_RENDERING_PLACEHOLDER_
</fontconfig> </fontconfig>

View File

@ -5,6 +5,9 @@
are not well hinted. Fall back to Liberation Sans instead, when are not well hinted. Fall back to Liberation Sans instead, when
black and white rendering was chosen. --> black and white rendering was chosen. -->
<match target="pattern"> <match target="pattern">
<test name="search_metric_aliases">
<bool>true</bool>
</test>
<test name="force_bw"> <test name="force_bw">
<bool>true</bool> <bool>true</bool>
</test> </test>
@ -18,6 +21,9 @@
</edit> </edit>
</match> </match>
<match target="pattern"> <match target="pattern">
<test name="search_metric_aliases">
<bool>true</bool>
</test>
<test name="force_bw"> <test name="force_bw">
<bool>true</bool> <bool>true</bool>
</test> </test>
@ -31,6 +37,9 @@
</edit> </edit>
</match> </match>
<match target="pattern"> <match target="pattern">
<test name="search_metric_aliases">
<bool>true</bool>
</test>
<test name="force_bw"> <test name="force_bw">
<bool>true</bool> <bool>true</bool>
</test> </test>

View File

@ -129,6 +129,11 @@ with the xtt module and with recent versions of the freetype module.
Generate (or don't generate) font setup for Java. Generate (or don't generate) font setup for Java.
=item B<-u>, B<--user>
Run fontconfig setup for user. It reads ~/.config/fontconfig/fonts-config,
which is user analogy of /etc/sysconfig/fonts-config.
=item B<-f>, B<--force> =item B<-f>, B<--force>
Force the update of all generated files even if it appears to be Force the update of all generated files even if it appears to be
@ -316,16 +321,19 @@ Mike FABIAN, 2003, Petr Gajdos <I<pgajdos@suse.com>>, 2014.
use utf8; use utf8;
use English; use English;
use Getopt::Long; use Getopt::Long;
use File::Basename;
use File::Path qw(make_path);
use Env; use Env;
use strict; use strict;
my $script_start_time = time(); my $script_start_time = time();
my $version = 20141207; my $version = 20150417;
# #
# OPTIONS # OPTIONS
# #
my $OPT_USER = 0;
my $OPT_FORCE = 0; my $OPT_FORCE = 0;
my $OPT_QUIET = 0; my $OPT_QUIET = 0;
my $OPT_VERBOSE = 0; my $OPT_VERBOSE = 0;
@ -375,26 +383,35 @@ my %sysconfig_options = (
"GENERATE_JAVA_FONT_SETUP" , "OPT_JAVA", "GENERATE_JAVA_FONT_SETUP" , "OPT_JAVA",
); );
my %in_files = ( my $xdg_prefix = "$HOME/.config/";
my %files = (
"sysconfig file", "/etc/sysconfig/fonts-config", "sysconfig file", "/etc/sysconfig/fonts-config",
"user sysconfig file", "fontconfig/fonts-config",
"rendering config template", "/usr/share/fonts-config/10-rendering-options.conf.template", "rendering config template", "/usr/share/fonts-config/10-rendering-options.conf.template",
"metric compatibility config", "/usr/share/fontconfig/conf.avail/30-metric-aliases.conf",
"metric compatibility bw config", "/usr/share/fonts-config/conf.avail/31-metric-aliases-bw.conf",
"java fontconfig properties template", "/usr/share/fonts-config/fontconfig.SuSE.properties.template",
);
my %out_files = (
"rendering config", "/etc/fonts/conf.d/10-rendering-options.conf", "rendering config", "/etc/fonts/conf.d/10-rendering-options.conf",
"local family list", "/etc/fonts/conf.d/58-family-prefer-local.conf", "user rendering config", "fontconfig/rendering-options.conf",
"metric compatibility symlink", "/etc/fonts/conf.d/30-metric-aliases.conf", "metric compatibility symlink", "/etc/fonts/conf.d/30-metric-aliases.conf",
"metric compatibility config", "/etc/fonts/conf.d/30-metric-aliases.conf",
"metric compatibility avail", "/usr/share/fontconfig/conf.avail/30-metric-aliases.conf",
"metric compatibility bw symlink", "/etc/fonts/conf.d/31-metric-aliases-bw.conf", "metric compatibility bw symlink", "/etc/fonts/conf.d/31-metric-aliases-bw.conf",
"local family list", "/etc/fonts/conf.d/58-family-prefer-local.conf",
"user family list", "fontconfig/family-prefer.conf",
"java fontconfig properties template", "/usr/share/fonts-config/fontconfig.SuSE.properties.template",
"java fontconfig properties", "/usr/lib*/jvm/jre/lib/fontconfig.SuSE.properties", "java fontconfig properties", "/usr/lib*/jvm/jre/lib/fontconfig.SuSE.properties",
); );
get_option_defaults_from_sysconfig($in_files{"sysconfig file"});
# read sysconfig and userconfig if --user was given
get_option_defaults_from_sysconfig($files{'sysconfig file'});
if (grep(/^--user$/, @ARGV)) {
# read variables on the top on the system ones
get_option_defaults_from_sysconfig($xdg_prefix.$files{'user sysconfig file'});
}
# process command line options # process command line options
my %opt; my %opt;
unless (GetOptions(\%opt, unless (GetOptions(\%opt,
'user|u', \$OPT_USER,
'force|f', \$OPT_FORCE, 'force|f', \$OPT_FORCE,
'quiet|q', \$OPT_QUIET, 'quiet|q', \$OPT_QUIET,
'verbose|v', \$OPT_VERBOSE, 'verbose|v', \$OPT_VERBOSE,
@ -447,13 +464,9 @@ if ($OPT_HELP) {
if ($OPT_INFO) { if ($OPT_INFO) {
# this is read by yast-fonts, so may be that # this is read by yast-fonts, so may be that
# change should be reflected in this yast module # change should be reflected in this yast module
print "Input Files\n"; print "Involved Files\n";
for my $f (keys %in_files) { for my $f (keys %files) {
print " $f: $in_files{$f}\n" print " $f: $files{$f}\n"
}
print "Output Files\n";
for my $f (keys %out_files) {
print " $f: $out_files{$f}\n"
} }
exit 0; exit 0;
} }
@ -472,6 +485,14 @@ elsif ($OPT_VERBOSE) {
$VERBOSITY = $VERBOSITY_VERBOSE; $VERBOSITY = $VERBOSITY_VERBOSE;
} }
#
#
#
if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print $OPT_USER ? "USER mode ($USER)\n" : "SYSTEM mode\n";
}
# #
# SYSCONFIG VARS -- debug output # SYSCONFIG VARS -- debug output
# #
@ -479,7 +500,9 @@ elsif ($OPT_VERBOSE) {
no strict "vars"; no strict "vars";
no warnings; no warnings;
if ($VERBOSITY >= $VERBOSITY_DEBUG) { if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print "--- sysconfig options (read from $in_files{'sysconfig file'}):\n"; print "--- sysconfig options (read from $files{'sysconfig file'}".
($OPT_USER ? ", $xdg_prefix$files{'user sysconfig file'}" : "").
"):\n";
for my $i (keys %sysconfig_options) { for my $i (keys %sysconfig_options) {
if (defined eval ("\$$i")) { if (defined eval ("\$$i")) {
printf "$i=%s\n", eval("\$$i"); printf "$i=%s\n", eval("\$$i");
@ -494,8 +517,8 @@ use strict;
# UID 0 CHECK # UID 0 CHECK
# #
if ($UID != 0 && $ENV{USER} !~ /root/) { if (!$OPT_USER && $UID != 0 && $ENV{USER} !~ /root/) {
print "*** error: you must be root to start $0\n"; print "*** error: no root permissions; rerun with --user for user fontconfig setting\n";
exit 1; exit 1;
} }
@ -503,7 +526,9 @@ if ($UID != 0 && $ENV{USER} !~ /root/) {
# MKFONTSCALE, MKFONTSDIR # MKFONTSCALE, MKFONTSDIR
# #
if (!$OPT_USER) {
mkfont_scale_dir(); mkfont_scale_dir();
}
# The following two calls may change files in /etc/fonts, therefore # The following two calls may change files in /etc/fonts, therefore
# they have to be called *before* fc-cache. If anything is # they have to be called *before* fc-cache. If anything is
@ -514,31 +539,37 @@ mkfont_scale_dir();
# FONTCONFIG RENDERING SETUP # FONTCONFIG RENDERING SETUP
# #
rendering_options(); rendering_options($OPT_USER);
family_preference_config(); family_preference_config($OPT_USER);
# #
# FONTCONFIG CACHE # FONTCONFIG CACHE
# #
if (!$OPT_USER) {
run_fccache (""); run_fccache ("");
run_fccache ("32"); run_fccache ("32");
run_fccache ("64"); run_fccache ("64");
}
# #
# FONT DATABASE # FONT DATABASE
# #
if (!$OPT_USER) {
run_fp_rehash (); run_fp_rehash ();
}
# generate_java_font_setup uses fontconfig, # generate_java_font_setup uses fontconfig,
# therefore it has to be called *after* fc-cache # therefore it has to be called *after* fc-cache
if ($OPT_JAVA) { if (!$OPT_USER && $OPT_JAVA) {
generate_java_font_setup (); generate_java_font_setup ();
} }
if (!$OPT_USER) {
reload_xfs_config (); reload_xfs_config ();
}
exit 0; exit 0;
@ -549,6 +580,7 @@ exit 0;
sub usage { sub usage {
print "Usage: fonts-config [option] ...\n"; print "Usage: fonts-config [option] ...\n";
print "-u, --user Run fontconfig setup for user.\n";
print "-f, --force Force the update of all generated files even\n"; print "-f, --force Force the update of all generated files even\n";
print " if it appears unnecessary according to the time stamps\n"; print " if it appears unnecessary according to the time stamps\n";
print "-q, --quiet Work silently, unless an error occurs.\n"; print "-q, --quiet Work silently, unless an error occurs.\n";
@ -616,11 +648,10 @@ sub get_option_defaults_from_sysconfig {
eval("\$$sysconfig_options{$i}=0"); eval("\$$sysconfig_options{$i}=0");
} }
} }
return (0);
} }
else { else {
print "--- NOTE: $sysconfig_file doesn't exist, using builtin defaults.\n"; # VERBOSITY still not defined!
return (1); print "NOTE: $sysconfig_file doesn't exist, using builtin defaults.\n";
} }
} }
@ -950,7 +981,6 @@ sub make_fonts_scale_and_fonts_dir {
if ($VERBOSITY >= $VERBOSITY_DEBUG) { if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print "mkfontscale is not available or it failed "; print "mkfontscale is not available or it failed ";
print "-> creating an empty fonts.scale file.\n"; print "-> creating an empty fonts.scale file.\n";
exit 1
} }
$try_again = 1; $try_again = 1;
my_system ("echo 0 > $dir/fonts.scale"); my_system ("echo 0 > $dir/fonts.scale");
@ -1074,13 +1104,22 @@ sub create_symbolic_links {
# #
sub rendering_options { sub rendering_options {
my $suse_rendering_file = $out_files{"rendering config"}; my ($user) = @_;
my $suse_rendering_template_file = $in_files{"rendering config template"}; my $suse_rendering_file;
my $suse_rendering_template_file = $files{'rendering config template'};
my $suse_rendering = ""; my $suse_rendering = "";
my $suse_rendering_template = ""; my $suse_rendering_template = "";
if (!$user) {
$suse_rendering_file = $files{'rendering config'};
}
else {
$suse_rendering_file = $xdg_prefix . $files{'user rendering config'};
my_make_path(dirname($suse_rendering_file));
}
if ($VERBOSITY >= $VERBOSITY_DEBUG) { if ($VERBOSITY >= $VERBOSITY_DEBUG) {
printf "--- Generating $suse_rendering_file ---\n"; printf "--- generating $suse_rendering_file ---\n";
} }
if (-f "$suse_rendering_template_file") { if (-f "$suse_rendering_template_file") {
@ -1169,6 +1208,27 @@ sub rendering_options {
} }
} }
} }
elsif ($ARG =~ /_SYSCONFIG_FILE_PLACEHOLDER_/) {
my $arg = ($user ? " -\\-user" : "");
$ARG =~ s/_SYSCONFIG_FILE_PLACEHOLDER_/$files{'sysconfig file'}/;
$ARG =~ s/_FONTSCONFIG_RUN_PLACEHOLDER_/$0$arg/;
$suse_rendering_template .= $ARG;
}
elsif ($ARG =~ /_METRIC_ALIASES_PLACEHOLDER_/) {
if ($OPT_SEARCH_METRIC_COMPATIBLE) {
$ARG =~ s/_METRIC_ALIASES_PLACEHOLDER_/true/;
} else {
$ARG =~ s/_METRIC_ALIASES_PLACEHOLDER_/false/;
}
$suse_rendering_template .= $ARG;
}
elsif ($ARG =~ /_INCLUDE_USER_RENDERING_PLACEHOLDER_/) {
if (!$user) {
# let user have a possibility to override system settings
$ARG =~ s@_INCLUDE_USER_RENDERING_PLACEHOLDER_@<include ignore_missing="yes" prefix="xdg">$files{'user rendering config'}</include>@;
$suse_rendering_template .= $ARG;
}
}
else { else {
$suse_rendering_template .= $ARG; $suse_rendering_template .= $ARG;
} }
@ -1266,34 +1326,89 @@ sub family_preference_list {
return $cfg; return $cfg;
} }
sub family_metric_compatibility {
my ($fontconfig_metric_conf, $user) = @_;
my $suse_metric = "";
if (-f "$fontconfig_metric_conf") {
open (CONF, "$fontconfig_metric_conf") || die "can't open file $fontconfig_metric_conf: $!";
binmode CONF, ":utf8";
while (<CONF>) {
$suse_metric .= $ARG;
if ($ARG =~ /<alias.*>/) {
$suse_metric .= "\t <test name=\"search_metric_aliases\"><bool>true</bool></test>\n"
} elsif ($ARG =~ /<!DOCTYPE.*>/) {
$suse_metric .= "\n";
$suse_metric .= "<!-- DO NOT EDIT; this is a generated file -->\n";
$suse_metric .= "<!-- modify $files{($user ? 'user syconfig file' : 'sysconfig file')} && run $0 instead -->\n";
$suse_metric .= "\n";
}
}
} else {
if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print "--- WARNING: $fontconfig_metric_conf doesn't exist!\n";
}
}
close (CONF);
return $suse_metric;
}
sub family_preference_config { sub family_preference_config {
my $suse_pref_file = $out_files{"local family list"}; my ($user) = @_;
my $metric_file = $in_files{"metric compatibility config"}; my $suse_pref_file = $files{'local family list'};
my $bw_metric_file = $in_files{"metric compatibility bw config"}; my $suse_metric_file = $files{'metric compatibility config'};
my $metric_symlink = $out_files{"metric compatibility symlink"}; my $metric_symlink = $files{'metric compatibility symlink'};
my $bw_metric_symlink = $out_files{"metric compatibility bw symlink"}; my $metric_avail = $files{'metric compatibility avail'};
my $suse_metric = "";
my $suse_pref = ""; my $suse_pref = "";
my $edit_options; my $edit_options;
if ($VERBOSITY >= $VERBOSITY_DEBUG) { if (!$user) {
printf "--- Generating $suse_pref_file ---\n"; $suse_pref_file = $files{'local family list'};
}
else {
$suse_pref_file = $xdg_prefix . $files{'user family list'};
my_make_path(dirname($suse_pref_file));
} }
if ($OPT_SEARCH_METRIC_COMPATIBLE) { if ($VERBOSITY >= $VERBOSITY_DEBUG) {
my_symlink($metric_file, $metric_symlink); printf "--- generating $suse_pref_file ---\n";
my_symlink($bw_metric_file, $bw_metric_symlink); }
} else {
if (!$user)
{
# replace fontconfig's /etc/fonts/conf.d/30-metric-aliases.conf
# by fonts-config's one
if (-l $metric_symlink) {
my_remove_symlink($metric_symlink); my_remove_symlink($metric_symlink);
my_remove_symlink($bw_metric_symlink); }
$suse_metric .= family_metric_compatibility($metric_avail, $user);
if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print "--- writing $suse_metric_file ---\n";
print "---\n";
}
# same name as symlink from fontconfig
open (CONF, ">$suse_metric_file") || die "can't open file $suse_metric_file: $!";
print CONF $suse_metric;
close (CONF);
} }
$suse_pref .= "<?xml version=\"1.0\"?>\n"; $suse_pref .= "<?xml version=\"1.0\"?>\n";
$suse_pref .= "<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n"; $suse_pref .= "<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n";
$suse_pref .= "\n"; $suse_pref .= "\n";
$suse_pref .= "<!-- DO NOT EDIT; this is a generated file -->\n"; $suse_pref .= "<!-- DO NOT EDIT; this is a generated file -->\n";
$suse_pref .= "<!-- modify /etc/sysconfig/fonts-config && run fonts-config instead -->\n"; $suse_pref .= "<!-- modify $files{($user ? 'user sysconfig file' : 'sysconfig file')} && run $0" . ($user ? " -\\-user" : "") . " instead -->\n";
$suse_pref .= "\n"; $suse_pref .= "\n";
$suse_pref .= "<fontconfig>\n"; $suse_pref .= "<fontconfig>\n";
if (!$user) {
$suse_pref .= "\t<!-- Let user override here defined system setting. -->\n";
$suse_pref .= "\t<include ignore_missing=\"yes\" prefix=\"xdg\">fontconfig/family-prefer.conf</include>\n";
}
$suse_pref .= "\n";
$suse_pref .= family_preference_list("sans-serif", $OPT_SANS_FAMILIES); $suse_pref .= family_preference_list("sans-serif", $OPT_SANS_FAMILIES);
$suse_pref .= family_preference_list("serif", $OPT_SERIF_FAMILIES); $suse_pref .= family_preference_list("serif", $OPT_SERIF_FAMILIES);
$suse_pref .= family_preference_list("monospace", $OPT_MONO_FAMILIES); $suse_pref .= family_preference_list("monospace", $OPT_MONO_FAMILIES);
@ -1399,8 +1514,8 @@ sub run_fp_rehash {
# #
sub generate_java_font_setup { sub generate_java_font_setup {
my @fontconfig_SuSE_properties_globs = $out_files{"java fontconfig properties"}; my @fontconfig_SuSE_properties_globs = $files{'java fontconfig properties'};
my $fontconfig_SuSE_properties_template_file = $in_files{"java fontconfig properties template"}; my $fontconfig_SuSE_properties_template_file = $files{'java fontconfig properties template'};
my $fontconfig_SuSE_properties_template = ""; my $fontconfig_SuSE_properties_template = "";
my @sans_japanese_priority = ("MS Gothic", my @sans_japanese_priority = ("MS Gothic",
"HGGothicB", "HGGothicB",
@ -1494,10 +1609,10 @@ sub generate_java_font_setup {
if ($VERBOSITY == $VERBOSITY_VERBOSE) { if ($VERBOSITY == $VERBOSITY_VERBOSE) {
printf "Generating java font setup ...\n"; printf "generating java font setup ...\n";
} }
if ($VERBOSITY >= $VERBOSITY_DEBUG) { if ($VERBOSITY >= $VERBOSITY_DEBUG) {
printf "--- Generating java font setup\n"; printf "--- generating java font setup\n";
} }
my ($font, $file); my ($font, $file);
@ -1704,7 +1819,16 @@ sub select_java_font {
# #
sub reload_xfs_config { sub reload_xfs_config {
my $pids = `ps -C xfs -o pid= | sed 's:[ \t]::g'`; my $pids;
if (! -x '/usr/bin/ps') {
if ($VERBOSITY >= $VERBOSITY_VERBOSE) {
print "--- WARNING: ps command is missing, couldn't search for X Font Server pids\n";
}
return;
}
$pids = `/usr/bin/ps -C xfs -o pid= | sed 's:[ \t]::g'`;
$pids =~ s/\n//; $pids =~ s/\n//;
if ($pids) { if ($pids) {
@ -1766,7 +1890,7 @@ sub my_symlink {
sub my_remove_symlink { sub my_remove_symlink {
my ($link) = @_; my ($link) = @_;
if ($VERBOSITY >= $VERBOSITY_DEBUG) { if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print "--- remove symlink: $link .. "; print "--- removing symlink: $link .. ";
} }
if (! -l $link) { if (! -l $link) {
if ($VERBOSITY >= $VERBOSITY_DEBUG) { if ($VERBOSITY >= $VERBOSITY_DEBUG) {
@ -1787,6 +1911,30 @@ sub my_remove_symlink {
} }
} }
sub my_make_path {
my ($dir) = @_;
if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print "--- creating directory: $dir .. ";
}
if (-d $dir) {
if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print "exists\n";
}
return;
}
make_path($dir);
if (! -d $dir) {
if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print "can not create\n";
}
exit 1;
}
if ($VERBOSITY >= $VERBOSITY_DEBUG) {
print "created\n";
}
}
sub search_executable { sub search_executable {
for my $file (@_) { for my $file (@_) {
if (-x $file) { if (-x $file) {

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Apr 17 11:55:10 UTC 2015 - pgajdos@suse.com
- updated to 20150417:
added --user option
------------------------------------------------------------------- -------------------------------------------------------------------
Mon Jan 12 13:55:20 UTC 2015 - pgajdos@suse.com Mon Jan 12 13:55:20 UTC 2015 - pgajdos@suse.com

View File

@ -1,7 +1,7 @@
# #
# spec file for package fonts-config # spec file for package fonts-config
# #
# Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany. # Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
# #
# All modifications and additions to the file contributed by third parties # All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed # remain the property of their copyright owners, unless otherwise agreed
@ -19,7 +19,7 @@
%define infinality_srcver 1-20130104_1 %define infinality_srcver 1-20130104_1
%define infinality_name fontconfig-infinality %define infinality_name fontconfig-infinality
Name: fonts-config Name: fonts-config
Version: 20141207 Version: 20150417
Release: 0 Release: 0
Summary: Configures Fonts for X Windows and other applications Summary: Configures Fonts for X Windows and other applications
License: GPL-2.0+ and MIT License: GPL-2.0+ and MIT