Open RJVB opened 10 years ago
One of the changes/improvements I've been hoping to see in freetype2-iu is feeding it with fixed default settings when infinality-settings.sh
isn't present on the system. This would prevent issues like yours from happening, at least to a certain degree. Basically we may try replacing current hard coded defaults with those from infinality-settings.sh
. Of course, those new defaults could be overwritten in the same way we do it now.
Does your solution work in a similar way? I'd really like to try it out.
On Thursday September 18 2014 09:43:39 bohoomil wrote:
Does your solution work in a similar way? I'd really like to try it out.
Yes, more or less. It works by replacing the standard getenv() (through a C macro, you can see from the code below just how old it is ... K&R ... brrr!) . Doing getenv("FOO")
will search in a specific location on disk (for ".env/FOO" to be exact) if FOO doesn't exist in the environment, and then read the value from that file. I used it a lot at some point, because it also allowed me to keep my environment lean. I've copied the code as it exists; you'll see that it even has a mechanism to override an existing FOO with _FOO (I guess I didn't yet know tricks like env FOO=newvalue somecommand
at the time). It's just an example, I presume the fallback database will be stored in a appropriate place like under ~/.config/fontconfig.
char Dir[256]= "./.env", *EnvDir= Dir; static char CX_env[256];
/* check if a variable of name
in the environment or on disk. / char __GetEnv( n, pref, add_prefix ) char n, pref; int add_prefix; { char env= CX_env; char set, getenv(), name[256], fname[512]; char home= getenv("HOME"); FILE EnvFp; int nn= EOF; char where;
errno= 0; if( !home) home= "."; if( !addprefix ){ /* first time: try without prefix / strncpy( name, n, 255); } else if( strlen(pref) + strlen(n) < 255 ){ sprintf( name, "%s%s", pref, n); } else{ if( getenv("GETENV_DEBUG") ) fprintf( stderr, "cx::GetEnv(\"%s\",\"%s\",%d) = NULL\n", n, pref, addprefix ); return( NULL ); } if( !(set= getenv(name)) ){ int en; / name not set in the environment; try to find it on disk _/ if( EnvDir && strlen( EnvDir)){ sprintf( fname, "%s/%s", EnvDir, name); } else{ sprintf( fname, "%s/.env/%s", home, name); } en= errno; if( ( EnvFp= fopen( fname, "r"))){ nn= fread( env, 1, sizeof(CX_env), EnvFp); fclose( EnvFp); if( !set && nn>= 0 && nn!= EOF ){ env[nn]= '\0'; if( env[0]== '\' ){ set= ( &env[1]); } else{ set= ( env); } } where= "DSK"; } else{ errno= en; } } else{ where= "ENV"; } if( set ){ char *nextset; / variable was found: see if a prefixed one exists to \ override it. _/ if( getenv("GETENV_DEBUG") ){ fprintf( stderr, "cx::GetEnv(\"%s\";\"%s\",\"%s\") = \"%s\" (%s)\n", name, n, pref, set, where ); } if( nn>= 0 && nn!= EOF){ if( env[0]=='$' ){ if( / strcmp( n, &env[1]) && / strcmp( name, &env[1]) ){ / disk env-variable refers to another / / recursiveness / strncpy( fname, &env[1], 255 ); set= ( GetEnv( fname, pref, False ) ); } else{ fprintf( stderr, "cx::GetEnv(): recursive variable '%s' (%s) == '%s'\n", n, name, &env[1] ); fflush( stderr); } } if( !set ){ if( env[0]== '\' ){ set= ( &env[1]); } else{ set= ( env); } } } /_ recursiveness */ next_set= __GetEnv( name, pref, True ); return( (next_set)? next_set : set ); } if( getenv("GETENV_DEBUG") ){ fprintf( stderr, "cx::__GetEnv(\"%s\";\"%s\",\"%s\") = NULL\n", name, n, pref ); } return( NULL); }
I just noticed that the synaptic graphical package manager I use from time to time had very off-looking fonts. I traced that down to a very simple reason: it's launched in a script through pkexec, and that tool drops the environment. It does not parse source ~root/.profile, so fontconfig-ultimate finds itself run without any parameters set. I don't know how it handles that situation, but clearly not by setting a reasonable default.
So I wonder, wouldn't it be possible to override the getenv() function in the code by one that reads the corresponding variable/value from file if not set in the environment? I could even contribute a draft, because I wrote exactly such a function ages ago...