Commit Graph

1358 Commits

Author SHA1 Message Date
Akira TAGOH a264a2c0ca Work around decoding strings in Macintosh encoding for the name table. 2023-09-21 17:01:10 +09:00
Akira TAGOH 34883cb414 Retry to decode strings in the name table as UTF-16BE in some cases.
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/376
2023-09-21 17:01:10 +09:00
Akira TAGOH 81a26a6b62 Update the encoding table for Simplified Chinese 2023-09-21 17:01:10 +09:00
Akira TAGOH 70e2a9a189 Fix an error of "initializer element is not constant"
Patch from Andreas Falkenhahn

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/380
2023-09-11 17:34:23 +09:00
Khaled Hosny e0eb855462 Detect standalone CFF fonts for FC_FONT_WRAPPER
FreeType will return CFF for both SFNT fonts with CFF table as well as
standalone CFF fonts, but applications might want to support the former
and not the later, so now FC_FONT_WRAPPER makes the distinction more
clear.
2023-08-24 14:11:26 +03:00
Khaled Hosny f614ec4d60 Add FC_FONT_WRAPPER
Currently detects only SFNT wrappers:
- WOFF: if it is FreeType says it is an SFNT font the file starts with wOFF tag
- WOFF2: the same but tag is wOF2
- SFNT: for any other SFNT font (which helps distinguishing standalone
  CFF fonts from CFF in SFNT aka OTF)

Fixes #375
2023-08-08 18:17:10 +03:00
Akira TAGOH 2fb3419a92 Fix uninitialized memory access when failing memory allocation.
FamilyTableInit() is called after allocating memory.
but FamilyTableClear() may be called when the allocation is failed.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/374

Reported by Andreas Falkenhahn
2023-07-27 16:16:30 +09:00
Xavier Claessens ce182817b4 meson: Support any compiler with gcc or msvc argument syntax
This includes e.g. clang-cl.
2023-06-01 08:26:49 -04:00
Akira TAGOH e4987ef114 Remove the problematic language from code and doc 2023-05-29 22:13:23 +09:00
Akira TAGOH f0612537cb Add namedinstance property
This change allows applications to detect if a font
is a variable font and a named-instance.
If they are, namedinstance property is set to true,
otherwise false.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/362
2023-05-25 20:12:31 +09:00
Ben Wagner ec3e747d2f Fix leak of `reason` in _FcConfigParse when not complaining
In "Do not return FcFalse from FcConfigParseAndLoad*() if complain is
set to false" [0], _FcConfigParse was updated to return FcTrue early if
it was instructed not to complain on errors. In "Take effect sysroot
functionality to the default config file" [1] the error messages were
factored into a `reason` which was allocated. Be sure to free this
`reason` in the case of returning FcTrue early.

Discovered with a leak checker while attempting to configure in
interesting ways.

[0] fcada52291
[1] cd51cb241a
2023-03-30 14:23:57 -04:00
Akira TAGOH 860b9997ef Clean up unused code 2023-03-06 15:34:58 +09:00
msizanoen1 a6a1695722 Reload MM/VF metadata for each font face in font collection
This ensures that the MM/VF metadata is the correct metadata for each
font face instead of whatever happens to be in the first one in the
collection.
2023-02-22 21:57:44 +07:00
Vitaly Lysenkov 89af138176 In fcfreetype.c, `GetScriptTags`: fix `use_of_uninitialized_value` and return the correct number of parsed tags in case the font file contains less tags than indicated. 2023-02-21 20:13:23 +00:00
Tom Anderson 06929a556f Fix false-positive CFI failure
When building Chromium with upstream Fontconfig with CFI,
the following build error is raised:

../../third_party/fontconfig/src/src/fchash.c:105:21: runtime error:
control flow integrity check for type 'unsigned int (const void *)'
failed during indirect function call

This occurs because CFI doesn't like the conversion from
`unsigned int (const void *)` to `unsigned int (const char *)`.
To fix this, simply redefine `FcHashFunc` to use `char *` instead.
2023-02-13 17:02:53 +00:00
Tom Anderson 2ef790a0db Fix filepaths added when scanning with sysroot
This fixes a regression introduced by 76f88e780.  When
using FONTCONFIG_SYSROOT=/home/tom/test_fonts, strace
reveals that fontconfig attempted to open /test_fonts/Ahem.ttf
instead of /home/tom/test_fonts/Ahem.ttf.  The fix is to use
`s_dir` instead of `dir` in `file_prefix`.
2023-02-09 01:31:31 +00:00
Akira TAGOH b54b98bb21 Add some missing constant names for weight.
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/348
2023-01-25 23:04:35 +09:00
Akira TAGOH 92f093a4c4 Report more detailed logs instead of assertion.
Getting backtraces against this assertion isn't useful at all.
Fontconfig isn't capable to report who really have a reference
of caches though, this report may be better than assertion.
So we can try analysis tools then.
And report it only when running with FC_DEBUG=16.
2023-01-25 14:36:30 +09:00
Ondrej Balaz da1e3f35e6 Expand ~ in glob
Allow ~ home directory expansion in acceptfont and rejectfont globs.

Fixes: #347
2023-01-25 06:14:54 +09:00
Akira TAGOH aec775130b src/meson.build: Store correct paths to fontconfig.pc.
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/345
2022-12-28 21:58:09 +09:00
Jean Abou Samra 6e3fe92b20
Ignore LC_CTYPE if set to "UTF-8"
LC_CTYPE is set to "UTF-8" on some macOS systems, which is
POSIX-compliant in a strict sense, but breaks the usual assumption
that a locale name has the form "ll_LL.encoding".

https://unix.stackexchange.com/questions/503110/valid-values-for-lc-ctype

Previously, this would cause the warning

  Fontconfig warning: ignoring UTF-8: not a valid region tag

Now, we just skip this variable if set to "UTF-8", since that value
doesn't give any language information, and move on to try LANG.
2022-12-14 15:27:34 +01:00
Akira TAGOH ed6c9cf67b Ignore null pointer on Fc*Destroy functions
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/339
2022-12-05 21:40:26 +09:00
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
Akira TAGOH c42eb5b503 Fix the build issue on meson when -g option is added to c_args
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/335
2022-10-27 12:33:25 +09:00
Akira TAGOH fc0e9a78d2 Real fix of 91114d18c
The change in 91114d18c broke remapping font paths.

Patch from Mattias Clasen

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/331
2022-09-28 21:39:09 +09:00
Taylor R Campbell 7dfde9b736 Avoid misuse of ctype(3)
The ctype(3) functions take arguments of type int that are either

(a) EOF, or
(b) unsigned char values, {0, 1, 2, ..., 255} if char is 8-bit.

Passing values of type char, on platforms where it is signed, can go
wrong -- negative values may be confused with EOF (typically -1) or
may lead to undefined behaviour ranging in practice from returning
garbage data (possibly out of an adjacent buffer in memory that may
contain secrets) to crashing with SIGSEGV (if the page preceding the
ctype table is unmapped).

The ctype(3) functions can't themselves convert to unsigned char
because then they would give the wrong answers for EOF, for use with
functions like getchar and fgetc; the user has to cast char to
unsigned char.
2022-04-11 12:27:04 +00:00
Akira TAGOH 875878efb7 Fix possible memory leaks in FcPatternObjectAddWithBinding
Reported by Ruth Ivimey-Cook

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/302
2022-01-31 19:03:29 +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
Akira TAGOH 4238402f1c Initialize variable 2021-12-09 20:29:06 +09:00
Akira TAGOH 3196e1815e Apply the change made by 23e46d1 again
Regression by d62d984e2b
2021-12-09 20:28:16 +09:00
Akira TAGOH 92fbf14b0d Fix the issue fail to obtain the style name
The number of a couple of 'family' and 'familylang' and 'style' and 'stylelang'
is different. need to reset the counter to get the property regarding to regarding to the lang.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/303
2021-12-09 20:26:10 +09:00
Ben Wagner ce00010b1f Actually skip leading spaces in style name
Because the loop body is just 'break' the loop never loops and at most
one leading space is skipped. Remove the body to allow the loop to
continue. Found with ClangTidy.
2021-12-06 16:55:12 -05:00
Ben Wagner 8d3425b8b8 Back FcSerialize with open addressing hash table.
Instead of fixed number of buckets with chaining use an open addressing
hash table with linear probing, max load factor 0.75, and a power of two
number of buckets.
2021-11-16 15:48:56 -05: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 5841bd012d Fix some testcase fails for 14c265a1
Add an extra code to ignore an error of FT_Get_MM_Var()
only when FT_MM_Var variable isn't used in any case.
2021-11-09 20:42:52 +09:00
Behdad Esfahbod 14c265a10a If a varfont has 'opsz' axis, set FC_SIZE on default instant pattern
Otherwise default-instance pattern would match as an "all sizes",
which would be wrong. See:

https://gitlab.gnome.org/GNOME/pango/-/issues/621#note_1305844
2021-11-09 20:04:52 +09:00
Ben Wagner a204489885 Fix warning about os2->achVendID cannot be NULL
FreeType's TT_OS2::achVendID is a FT_Char[4] array and not a pointer,
so it does not need to be checked for NULL.
2021-10-28 16:17:48 -04: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
Akira TAGOH 2d17232a45 Fix score estimation for postscriptname
Before this fix:
$ fc-match :postscriptname=LiberationSans
LiberationSansNarrow.ttf: "Liberation Sans Narrow" "Regular"

After this fix:
$ fc-match :postscriptname=LiberationSans
LiberationSans-Regular.ttf: "Liberation Sans" "Regular"

See https://bugzilla.redhat.com/show_bug.cgi?id=1946871
2021-10-08 18:30:09 +09:00
Ben Wagner efc71a3c13 Free local FcCache lock on contention
If two threads attempt to create the FcCache lock in lock_cache at the
same time, both threads may create and initialize a local FcMutex. One
thread will atomically make cache_lock point to its FcMutex. The other
thread currently calls FcMutexFinish on the local lock, but does not
free it. Change this behavior to free the unused lock.

Found with test/test-pthread on an LeakSanitizer enabled build.
2021-09-06 03:20:31 +00:00
Ben Wagner 6e68763085 Add memory order constraints to C11 atomics
Reduce the strength of the C11 atomics from memory_order_seq_cst to the
actually required memory order constraints for each operation. In
addition to reflecting the already documented memory order constraints,
this should allow for better code generation.
2021-08-31 12:38:50 -04:00
Akira TAGOH 57032f489b Fix a memory leak when trying to open a non-existing file
https://bugzilla.redhat.com/show_bug.cgi?id=1914716
2021-08-25 15:52:53 +09:00
Akira TAGOH c7891755cb Reflect matching results to binding in FcPattern
This change allows applications to see what property was matched perfectly
and help to filter out for their needs.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/294
2021-08-24 19:32:09 +09:00
Alex Richardson 92ed966b74 FcCharSetPutLeaf(): Fix missing move of new_leaves contents
If the `realloc(numbers)` call fails, shrinking the leaves allocation
back to the old size is not guaranteed to return the old pointer value.
While this might be the case with some malloc() implementations, realloc()
could also just mark the following area as free.
To make this less error-prone, we grow numbers first and then grow leaves
since the numbers content does not need to be relocated, but leaves does.

See https://bugs.freedesktop.org/show_bug.cgi?id=90867
2021-08-18 10:36:47 +01:00
Alex Richardson 012ffaac75 Add support for C11 stdatomic atomics
This fixes deprecation warnings when building for macOS >= 10.12 systems.
Additionally, using stdatomic.h (or the more modern __atomic_ builtins)
is required when targeting CHERI-enabled architectures such as
CHERI-RISC-V or Arm's Morello since the compiler rejects __sync_* atomic
for pointer types (they only work with integers).
2021-07-20 09:32:52 +01:00
Alex Richardson ab4761ff87 fcint: add casts to allow building with stricter compilers
When targeting CHERI, casts between pointers and integers must use
(u)intptr_t. uintptr_t values contains pointer bounds (and additional
metadata), whereas other integer types do not. This change also adds a
cast to FcOffsetToPtr() to silence a compiler warning that triggers if
the compiler cannot statically infer which side of an arithmetic operation
is the pointer operand and which one is the offset/mask.
2021-07-20 03:31:47 +00:00
Ryan Schmidt 3a7ad1b49f Restore fcatomic compatibility with Mac OS X 10.4.
Reverts the part of 6def66164a that
removed the fc_atomic_ptr_cmpexch compatibility code for systems earlier
than Mac OS X 10.5.

Reverts the part of 447b9ccc7d that moved
the definition of fc_atomic_ptr_get into the Mac OS X > 10.4 block. That
code is still needed on 10.4 and is implemented using functions that are
available on 10.4.

Compare against MAC_OS_X_VERSION_MIN_REQUIRED using a number not a
constant because the constant is not available on earlier SDKs.
2021-07-19 07:17:34 +00:00
Akira TAGOH 4d43f84188 Do not set different score to non-string values
Non-string values in a cache is supposed to choose one from them.
Due to the change of da1c9f7a, there was a regression on scoring for
matching functions.  So reverting the behavior for evaluating non-string
values to the previous one.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/286
2021-07-08 14:47:36 +09:00
Mehdi Sabwat fd393c53d8 fcstat: add support for wasm-emscripten
fallback to f_type statfs struct field, since f_fstypename is not supported on the platform.
2021-07-06 18:17:32 +02:00