Commit Graph

265 Commits

Author SHA1 Message Date
Matthias Clasen ff7d314ab5 Fix up FC_LIKELY macros
__builtin_expect returns the same type as the expression,
so enforce that we pass in a boolean expression.

Pointed out by Emmanuele Bassi.
2020-08-25 18:12:07 -04:00
Matthias Clasen 76699a4813 Add FC_LIKELY and FC_UNLIKELY macros
These wrap __builtin_expect where it exists.
2020-08-25 12:15:45 -04:00
Matthias Clasen 055843631b Add a hash function for families
Add a hash function that behaves like family
comparison: ignoring case and blanks. This
will be used to replace the list walking for
finding family matches with a hash table.
2020-08-25 12:10:53 -04:00
Akira TAGOH a53f79b4a2 Fix build issues regarding formatter for Win32
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/248
2020-08-06 13:02:00 +09:00
Tim-Philipp Müller a30e4db967 fccompat: fix build on Windows without unistd.h
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/access-waccess?view=vs-2019
2020-07-07 03:48:34 +00:00
Akira TAGOH 91114d18c3 Allow overriding salt with new one coming later 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
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 65c7427c01 Warn when constant name is used for unexpected object
This fixes the sort of weird things like `fc-match :size=rgb` done without any errors.
This might be annoyed but the error messages should helps to fix an application bug or
suggest more useful constant names to fontconfig.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/137
2018-11-30 07:04:22 +00:00
Akira TAGOH 8208f99fa1 Fix the build issue with --enable-static
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/109
2018-09-03 07:24:42 +00:00
Tom Anderson d1f48f11d5 Return canonicalized paths from FcConfigRealFilename
FcConfigRealFilename() follows symlinks, but the link may be relative to the
directory containing the link.  For example, on my system, I have this file:

/etc/fonts/conf.d/99-language-selector-zh.conf ->
    ../conf.avail/99-language-selector-zh.conf

Since /etc/fonts/conf.d is probably not in PATH, open()ing the file would fail.
This change makes FcConfigRealFilename() return the canonicalized filename
instead.  So for the example above, it would return:

/etc/fonts/conf.avail/99-language-selector-zh.conf

This was causing bad font rendering in Chromium [1] after the regression I
introduced in 7ad010e80b.

[1] https://bugs.chromium.org/p/chromium/issues/detail?id=857511
2018-07-16 18:00:35 +02:00
Akira TAGOH f5dd8512bd Remove .uuid when no font files exists on a directory
https://bugs.freedesktop.org/show_bug.cgi?id=106632
2018-06-11 17:03:46 +09:00
Alexander Larsson 3ea70f9368 Cache: Remove alias_table
There is really no need for this anymore

https://bugs.freedesktop.org/show_bug.cgi?id=106618
2018-05-25 14:43:06 +09:00
Alexander Larsson c42402d0b8 Cache: Rewrite relocated paths in earlier
This changes the rewriting of the FC_FILE values for relocated caches to an earlier stage
while reading the cache. This is better, because it means all APIs will report the
rewritten paths, not just the once that use the list apis.

We do this by detecting the relocated case and duplicating the FcPattern and FcPatternElm
in an cache allocation (which will die with the cache) and then reusing the FcValueLists
from the cache.

This means that in the rewritten case we will use some more memory, but not the full
size of the cache. In a test here I had 800k of relocated caches, but ~200k of wasted
on duplicating the objects.

This should fix https://bugs.freedesktop.org/show_bug.cgi?id=106618
2018-05-25 14:42:52 +09:00
Alexander Larsson a63b9c622e Add FcCacheAllocate() helper
This lets you allocate a chunk of memory that will be freed when the cache
is freed.

https://bugs.freedesktop.org/show_bug.cgi?id=106618
2018-05-25 14:42:05 +09:00
Akira TAGOH 307639cff1 Bug 43367 - RFE: iterator to peek objects in FcPattern
Add various APIs to obtain things in FcPattern through the iterator

https://bugs.freedesktop.org/show_bug.cgi?id=43367
2018-05-11 20:48:30 +09:00
Tom Anderson c60ed9ef66 Fix undefined-shift UBSAN errors
The expression "1 << 31" will cause UBSAN to complain with this error message:
runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

The same operation on unsigned types is fine, however.  This CL replaces the
strings "1 <<" with "1U <<".
2018-04-16 15:23:20 +02: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 3642d71724 Add FcReadLink to wrap up readlink impl. 2018-01-04 20:39:14 +09:00
Akira TAGOH 8ab4d67995 Replace uuid in the table properly when -r 2017-12-18 20:05:14 +09:00
Akira TAGOH dd21876e64 Update .uuid only when -r is given but not -f. 2017-12-18 12:11:21 +09:00
Akira TAGOH 8f88b1c47c abstract hash table functions 2017-11-20 17:37:22 +05:30
Akira TAGOH 85d9de58ed Add new API to find out a font from current search path 2017-11-20 17:37:22 +05:30
Akira TAGOH 7b48fd3dd4 Use uuid-based cache filename if uuid is assigned to dirs 2017-11-20 17:37:22 +05:30
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
Behdad Esfahbod 6f98286e15 Use inline functions instead of macros for a couple of things 2017-09-12 17:02:27 -04: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 ee2000494c Add FcPatternGetWithBinding() to obtain the binding type of the value in FcPattern.
https://bugs.freedesktop.org/show_bug.cgi?id=19375
2017-07-07 15:43:59 +09:00
Akira TAGOH abdb6d658e Fix the build issue on GNU/Hurd
PATH_MAX isn't defined on GNU/Hurd. according to the porting guidelines
(https://www.gnu.org/software/hurd/hurd/porting/guidelines.html)
allocate a memory dynamically instead of relying on the length of
a string with PATH_MAX.

https://bugs.freedesktop.org/show_bug.cgi?id=97512
2017-03-01 19:48:38 +09:00
Akira TAGOH d179cbc253 Revert "Workaround another race condition issue"
This reverts commit f44bfad235.
2016-04-06 14:39:15 +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
Akira TAGOH bd96984e4b Use int64_t instead of long long 2015-10-15 15:51:50 +09:00
Akira TAGOH a44cc450b5 Use long long to see the same size between LP64 and LLP64 2015-10-13 13:04:33 +09:00
Akira TAGOH ad9f588050 Fix the broken cache more.
Take a look at the nano second in the mtime to figure out
if the cache needs to be updated if available.
and do the mutex lock between scanning and writing a cache
to avoid the conflict.

Also we don't need to scan directories again after writing
caches. so getting rid of the related code as well.

https://bugs.freedesktop.org/show_bug.cgi?id=69845

and for reference:

https://bugzilla.redhat.com/show_bug.cgi?id=1236034
2015-08-14 17:19:29 +09:00
Behdad Esfahbod 46ec6a52d4 Revert changes made to FcConfigAppFontAddDir() recently
In 32ac7c75e8 the behavior of
FcConfigAppFontAddFile/Dir() were changed to return false
if not fonts were found.  While this is welldefined and useful
for AddFile(), it's quite problematic for AddDir().  For example,
if the directory is empty, is that a failure or success?  Worse,
the false value from AddDir() was being propagated all the way
to FcInit() returning false now.  This only happened upon memory
allocation failure before, and some clients assert that FcInit()
is successful.

With this change, AddDir() is reverted back to what it was.
AddFont() change (which was actually in fcdir.c) from the original
commit is left in.
2015-06-26 17:02:13 -07:00
Akira TAGOH 33fd436a3e Don't return FcFalse even when no fonts dirs is configured 2015-06-17 16:15:35 +09:00
Akira TAGOH f6d61c9bee mark as private at this moment 2015-06-12 11:30:01 +09:00
Akira TAGOH dbda117142 No need to be public 2015-06-09 11:15:25 +09:00
Akira TAGOH 10a57edd07 Add one more debugging option to see transformation on font-matching
just setting FC_MATCH=3 shows a lot of information and hard to keep on track for informamtion
which is really necessary to see. to use this more effectively, added FC_DBG_MATCH_FILTER to
see for what one really want to see. it takes a comma-separated-list of object names.
If you want to see family name only, try like this:

FC_DBG_MATCH_FILTER=family FC_DEBUG=4096 fc-match

debugging output will be filtered out and see family only in the result.
2015-06-08 17:39:25 +09:00
Behdad Esfahbod ee2d1da2d2 Reduce number of places that cache version is specified to 1 2015-05-27 14:36:35 -07:00
Behdad Esfahbod 5bad26ccb6 Simplify FcRange 2015-05-27 14:18:28 -07:00
Akira TAGOH fa6c6b53c5 Fix memory leaks after FcFini()
Reported by Jia Wang

https://bugs.freedesktop.org/show_bug.cgi?id=83770
2015-05-22 16:53:34 +09:00
Akira TAGOH 365809938e Bump the cache version to 5
FcPattern isn't compatible to the older.
2014-12-25 13:11:21 +09:00
Behdad Esfahbod 874a549164 Remove unused regex code
Regex matching was disabled in f6244d2cf2
2014-07-24 15:42:54 -04:00
Akira TAGOH d17f556153 Read the config files and fonts on the sysroot when --sysroot is given to fc-cache
Fix for e96d776088

https://bugs.freedesktop.org/show_bug.cgi?id=59456
2014-06-17 20:11:02 +09:00
Behdad Esfahbod 8f62ccaa96 Remove unused FcHash code now that FC_HASH is deprecated 2014-06-12 17:02:10 -04:00
Akira TAGOH f44bfad235 Workaround another race condition issue
See https://bugzilla.redhat.com/show_bug.cgi?id=921706
2014-06-05 19:06:02 +09:00
Behdad Esfahbod 3f992254f2 Rewrite hashing to use FT_Stream directly
This is more robust but introduces a small change in behavior:
For .pcf.gz fonts, the new code calculates the hash of the uncompressed
font data whereas the original code was calculating the hash of the
compressed data.

No big deal IMO.
2014-05-16 15:02:58 -06:00
Behdad Esfahbod 748e77e89f Simplify hash code 2014-05-16 14:10:06 -06:00