Commit Graph

206 Commits

Author SHA1 Message Date
Akira TAGOH 6715a14f13 Add FC_DESKTOP_NAME property
To allow users to have desktop-specific matching rule.
2022-11-26 14:37:49 +09:00
Francesco Pretto 16bbb5340b WIN32: Fix pGetSystemWindowsDirectory found initialized during FcConfigParseAndLoadFromMemory
Trying to early loading a custom fonts.xml created on the
fly results in the pGetSystemWindowsDirectory function
pointer being found intialized. Normally the initialization
is performed in the default configuration loading.
The commit factorizes the lazy initialization of both
WIN32 getters (together with pSHGetFolderPathA) in a
function and call it when actually needed.
2022-01-31 07:52:09 +00:00
Akira TAGOH 55eb1ef89b Add an user font directory for Win32 to the default font path
Patch from @takase1121

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/144
2022-01-17 16:19:22 +09:00
Ryan Gonzalez be453bd159 Ensure config.h is always included before stdlib headers
In particular, if an stdlib header goes first, it includes features.h
which only checks _FILE_OFFSET_BITS *once*, meaning that these files end
up compiled *without* _FILE_OFFSET_BITS taking effect, which affects
fcxml's operations in listing directories.

Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
2021-11-10 19:41:50 -06:00
Akira TAGOH 1d76699927 Resolves symlinks against <dir prefix="relative">
When a config file is symlinked and obtaining an relative path from it for <dir>,
it behaved like:

$ realpath /path/to/foo.conf
/path/to/realpath/foo.conf
$ FONTCONFIG_FILE=/path/to/foo.conf fc-cache -v
Font directories:
        /path/to/fonts
/path/to/fonts: skipping, existing cache is valid: 1 fonts, 0 dirs
/path/to/cachedir: cleaning cache directory
fc-cache: succeeded

And after this change:

$ FONTCONFIG_FILE=/path/to/foo.conf fc-cache -v
Font directories:
        /path/to/relpath/fonts
/path/to/realpath/fonts: skipping, existing cache is valid: 1 fonts, 0 dirs
/path/to/cachedir: cleaning cache directory
fc-cache: succeeded

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/290
2021-10-11 18:43:12 +09:00
Albert Astals Cid fd3eebad74 Fix potential memory leak in _get_real_paths_from_prefix 2021-04-10 00:10:20 +02:00
Akira TAGOH 6f27f42e61 Add support for XDG_DATA_DIRS
Add dirs from XDG_DATA_DIRS when <dir prefix="xdg"> appears in fonts.conf

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/271
2021-03-30 15:08:17 +09:00
Ben Wagner d55eaa6b31 Fix leaks in fcxml.c, fc-match.c, and tests.
Fix leaks reported by AddressSanitizer when running 'make check'.
2020-12-14 10:54:11 +00:00
Akira TAGOH 8815641571 Use memcpy instead of strcpy
To work around a warning with GCC10 on Win32

warning: '__builtin___strncpy_chk' specified bound depends on the length of the source argument [-Wstringop-overflow=]
2020-11-02 14:25:01 +09:00
Jan Tojnar 9133e799b5 Turn unknown attributes into warning
As far as I can tell, fontconfig can recover from encountering an unknown attribute.
And unknown elements already print a warning instead of an error, so let's make this a warning too.
2020-08-18 04:13:21 +00:00
Tim-Philipp Müller 03aa12c75e Guard dirent.h includes
Might not be available on Windows.
2020-07-27 13:43:23 +00:00
Akira TAGOH cd51cb241a Take effect sysroot functionality to the default config file
When loading the default config file with FONTCONFIG_SYSROOT,
it fails if no /etc/fonts/fonts.conf is available, even if it is
there where is based on sysroot.

To address this, FcConfig is required to determine the sysroot.
therefore, this change makes FcConfigFilename() deprecated,
use FcConfigGetFilename() instead.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/181
2019-10-21 20:46:09 +09:00
Akira TAGOH 75eadca266 Warn as well if no directory name for cachedir provided
cachedir is used to determine where cache files are stored.
the empty directory will ends up to put them under the top of
directory of XDG_CACHE_HOME. that messes it up and must be avoided.

As a note, if you want to read/write something from the top of
XDG_DATA_HOME (dir) and/or XDG_CACHE_HOME (cachedir),
put "." instead of the empty.

https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/180
2019-10-08 20:12:12 +09:00
Akira TAGOH fcada52291 Do not return FcFalse from FcConfigParseAndLoad*() if complain is set to false
https://bugzilla.redhat.com/show_bug.cgi?id=1744377
2019-08-28 17:48:29 +09:00
Akira TAGOH 1a0391c099 Fix memory leaks 2019-07-23 10:54:36 +00:00
Akira TAGOH 36f46ba720 FcConfigParseAndLoad*() should returns false on config errors
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/168

Reported by Lawrence D'Oliveiro
2019-07-22 05:35:21 +00:00
Akira TAGOH 83840fd1fa Fix obtaining real path from pre-defined names for Win32
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/166
2019-06-26 15:28:41 +09:00
Akira TAGOH cb1df8cb28 Don't warn if path can't be converted with prefix 2019-04-03 12:02:09 +00:00
Akira TAGOH ad3f335ccf Fix make check fail on MinGW again 2019-04-03 12:02:09 +00:00
Akira TAGOH b1bcc0cbb2 Fix build issues on MinGW 2019-04-03 12:02:09 +00:00
Akira TAGOH 2e8ce63514 Add salt attribute to dir and remap-dir elements
'salt' attribute affects a cache filename to generate different name from directory name.
This is useful when sharing caches with host on sandbox and/or give a filename differently:

    <dir salt="randomdata">/usr/share/fonts</dir>
    <remap-dir as-path="/usr/share/fonts" salt="salt for /usr/share/fonts on host">/run/host/fonts</remap-dir>

Applications can read caches as-is for fonts on /run/host/fonts where is mounted from host.
and write a cache for their own fonts on /usr/share/fonts with different name.
2019-04-03 12:02:09 +00:00
Akira TAGOH def1d00036 Add reset-dirs element
This element removes all of fonts directories where added by
dir elements. it is useful to override fonts dirs from system
to their own dirs only.
2019-04-03 12:02:09 +00:00
Akira TAGOH a563a1802e Add new element remap-dir instead of extending dir element 2019-04-03 12:02:09 +00:00
Keith Packard c4324f54ee 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>
2019-04-03 12:02:09 +00:00
Akira TAGOH 699d6e4d84 Fix a crash with invalid matrix element
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/140
2019-01-23 05:59:34 +00:00
Akira TAGOH a57647e155 covscan fix: get rid of unnecessary condition check 2018-11-30 07:41:16 +00:00
Akira TAGOH e4788c5a96 add missing the case of prefix="default" as documented 2018-10-04 08:07:09 +00:00
Akira TAGOH 1aa8b700c3 Add more prefix support in <dir> element
Added two prefix modes:
  "relative" that makes the relative path be relative to current file
  "cwd" for relative to current working directory which implies current behavior.

Resolves: https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/15
2018-10-02 10:12:14 +00:00
Tom Anderson 1451f829e7 Fix build with CFLAGS="-std=c11 -D_GNU_SOURCE" 2018-07-26 02:57:07 +00:00
Akira TAGOH 9f1b92f27f Fix memory leak 2018-07-25 13:41:47 +09:00
Akira TAGOH 5b277806df Drop the redundant code
"value == FcTypeInteger" won't be true because it was converted to FcTypeDouble earlier
2018-07-25 12:44:38 +09:00
Akira TAGOH 37c9c16dad Fix memory leak 2018-07-19 04:29:01 +00:00
Akira TAGOH 14c23a5715 Fix double-free 2018-05-25 15:20:10 +09:00
Akira TAGOH 684c3ce685 Fix leaks 2018-05-25 13:51:10 +09:00
Akira TAGOH cfb21c7d85 Bug 106497 - better error description when problem reading font configuration
https://bugs.freedesktop.org/show_bug.cgi?id=106497
2018-05-13 14:48:10 +09:00
Tom Anderson 7ad010e80b Use realfilename for FcOpen in _FcConfigParse
realfilename is the file name after sysroot adjustments.  It should be used
instead of filename in the call to FcOpen() which forwards the name directly to
open().

Though I don't explicitly request a sysroot, I was getting error messages saying
"failed reading config file".  This CL fixes the error spam.
2018-04-17 13:49:41 +09:00
Akira TAGOH 34b5c949d5 Do not mix up font dirs into the list of config dirs 2018-02-05 12:47:01 +09:00
Akira TAGOH ef748b39e0 Take effects on dir, cachedir, acceptfont, and rejectfont only when loading
Those elements takes effects immediately during parsing config files so makes them conditional to ignore on scanning.
2018-01-23 22:27:17 +09:00
Akira TAGOH 97898b1158 Fix the mis-ordering of ruleset evaluation in a file with include element 2018-01-03 22:15:11 +09:00
Akira TAGOH e73b5dcbf2 Correct debugging messages to load/scan config 2017-11-16 11:37:36 +09:00
Akira TAGOH 9a0fcb948f Add the ruleset description support
Trying to address what these configuration files really do.
This change allows to see the short description that mention
the purpose of the content in the config file and obtain
them through API.

This change also encourage one who want to make some UI for
the user-specific configuration management. it is the main
purpose of this change for me though.

Aside from that, I've also made programs translatable. so
we see more dependencies on the build time for gettext,
and itstool to generate PO from xml.
2017-11-07 15:24:54 +09:00
Alexander Kanavin 90271ae079 src/fcxml.c: avoid double free() of filename
It's also freed after bail1, so no need to do it here.
2017-10-12 11:27:07 +09:00
Akira TAGOH 052115aa83 Fix again to keep the same behavior to the return value of FcConfigParseAndLoad
https://bugs.freedesktop.org/show_bug.cgi?id=102141
2017-09-21 14:04:10 +09:00
Akira TAGOH 5603e06aeb Revert "Keep the same behavior to the return value of FcConfigParseAndLoad"
This reverts commit dc56ff8040.
2017-09-21 14:03:51 +09:00
Behdad Esfahbod 8f4c4d278d Remove blanks facility from the library
XML parser does not accept it anymore either.
2017-09-12 17:02:27 -04:00
Akira TAGOH dc56ff8040 Keep the same behavior to the return value of FcConfigParseAndLoad
reverting the behavior accidentally changed by 12b750

https://bugs.freedesktop.org/show_bug.cgi?id=102141
2017-08-13 16:18:46 +09:00
Akira TAGOH 5b6af242e1 Fix gcc warnings with enabling libxml2 2017-07-11 15:38:01 +09:00
Akira TAGOH 12b7501bad Add FcConfigParseAndLoadFromMemory() to load a configuration from memory.
https://bugs.freedesktop.org/show_bug.cgi?id=78452
2017-07-07 15:52:15 +09:00
Akira TAGOH 7441dbec03 Bug 95481 - Build fails on Android due to broken lconv struct 2016-05-27 11:16:09 +09:00
Patrick Haller d570a841a2 Optimizations in FcStrSet
Applied optimizations:
- skip duplicate check in FcStrSetAppend for values originating from readdir()
- grow FcStrSet in 64-element bulks for local FcStrSets (FcConfig layout unaltered)

Starting gedit is measured to

                        Unoptimized     Optimized
user[s]                         0,806         0,579
sys[s]                          0,062         0,062
Total Instr Fetch Cost: 1.658.683.750   895.069.820
Cachegrind D Refs:        513.917.619   312.000.436
Cachegrind Dl Misses:       8.605.632     4.954.639
2016-01-12 10:42:40 +09:00