Commit Graph

568 Commits

Author SHA1 Message Date
Behdad Esfahbod 04ac14fc14 [fcformat] Add list of undocumented language features 2009-02-16 02:14:41 -08:00
Behdad Esfahbod 384542fa91 [fcformat] Add a 'pkgkit' builtin that prints tags for font packages
For DejaVu Sans Condensed it generates:

font(dejavusans)
font(dejavusanscondensed)
font(:lang=aa)
font(:lang=ab)
...
font(:lang=yo)
font(:lang=zu)
2009-02-16 02:14:30 -08:00
Behdad Esfahbod 9d58d01c5c [fcformat] Enumerate langsets like we do arrays of values
If one asks for a format like '%{[]elt{expr}}' and the first value
for elt is a langset, we enumerate the langset languages in expr.
2009-02-15 14:13:38 -08:00
Behdad Esfahbod d62b85af21 [fclang] Implement FcLangSetGetLangs() (#18846) 2009-02-15 14:13:34 -08:00
Behdad Esfahbod cdfb76585e [fcformat] Implement array enumeration
The format '%{[]family,familylang{expr}}' expands expr once for the first
value of family and familylang, then for the second, etc, until both lists
are exhausted.
2009-02-15 13:40:31 -08:00
Behdad Esfahbod 0673ef3881 [fcformat] Support 'default value' for simple tags
The format '%{family:-XXX} prints XٓٓٓٓXX if the element family is not defined.
Also works for things like '%{family[1]:-XXX}'.
2009-02-15 13:40:30 -08:00
Behdad Esfahbod 9c83a8376f [fcformat] Support indexing simple tags
The format '%{family[0]}' will only output the first value for element family.
2009-02-15 13:40:30 -08:00
Behdad Esfahbod d04a750764 [fcformat] Add support for builtin formats
The '%{=unparse}' format expands to the FcNameUnparse() result on the
pattern.  Need to add '%{=verbose}' for FcPatternPrint() output but
need to change that function to output to a string first.

Also added the '%{=fclist}' and '%{=fcmatch}' which format like the
default format of fc-list and fc-match respectively.
2009-02-15 13:40:30 -08:00
Behdad Esfahbod 85c7fb67ce [fcformat] Refactor code to avoid malloc 2009-02-15 13:40:30 -08:00
Behdad Esfahbod d4f7a4c6af [fcformat] Start adding builtins 2009-02-15 13:40:29 -08:00
Behdad Esfahbod c8f5933d13 [fcformat] Implement 'delete', 'escape', and 'translate' filter functions
The format '%{family|delete( )}' expands to family values with space removed.
The format '%{family|translate( ,-)}' expands to family values with space
replaced by dash.  Multiple chars are supported, like tr(1).
The format '%{family|escape(\\ )}' expands to family values with space
escaped using backslash.
2009-02-15 13:40:29 -08:00
Behdad Esfahbod b6a23028be [fcformat] Add value-count syntax
The format '%{#family}' expands to the number of values for the element
'family', or '0' if no such element exists in the pattern.
2009-02-15 13:40:29 -08:00
Behdad Esfahbod dccbbe83ef [FcStrBuf] better handle malloc failure
If buffer has failed allocation, return NULL when done.
2009-02-15 13:40:28 -08:00
Behdad Esfahbod ced38254b4 [fcformat] Implement 'cescape', 'shescape', and 'xmlescape' converters 2009-02-15 13:40:28 -08:00
Behdad Esfahbod 2017a5eb79 [fcformat] Add simple converters
The format '%{family|downcase}' for example prints the lowercase of
the family element.  Three converters are defined right now:
'downcase', 'basename', and 'dirname'.
2009-02-15 13:40:27 -08:00
Behdad Esfahbod 7717b25ffd [fcformat] Add conditionals
The conditional '%{?elt1,elt2,!elt3{expr1}{expr2}}' will evaluate
expr1 if elt1 and elt2 exist in pattern and elt3 doesn't exist, and
expr2 otherwise.  The '{expr2}' part is optional.
2009-02-15 13:40:27 -08:00
Behdad Esfahbod 8c31a2434d [fcformat] Add element filtering and deletion
The filtering, '%{+elt1,elt2,elt3{subexpr}}' will evaluate subexpr
with a pattern only having the listed elements from the surrounding
pattern.

The deletion, '%{-elt1,elt2,elt3{subexpr}}' will evaluate subexpr
with a the surrounding pattern sans the listed elements.
2009-02-15 13:40:26 -08:00
Behdad Esfahbod d6506ff6ee [fcformat] Add support for subexpressions
The syntax is '{{expr}}'.  Can be used for aligning/justifying an entire
subexpr for example.
2009-02-15 13:40:26 -08:00
Behdad Esfahbod 27b3e2dddf [fcformat] Refactor and restructure code for upcoming changes
Also makes it thread-safe.
2009-02-15 13:40:26 -08:00
Behdad Esfahbod c493c3b770 [fcformat] Add support for width modifiers
One can do '%30{family}' for example.  Or '%-30{family}' for the
left-aligned version.
2009-02-15 13:40:25 -08:00
Behdad Esfahbod b697fa2523 [cache] After writing cache to file, update the internal copy to reflect this
Only do it for small caches though.  For large cache we'd better off loading
the cache file again, mmap()ing it.

Based on patch from Diego Santa Cruz.
2009-02-15 13:40:25 -08:00
Behdad Esfahbod 6bb5d72fe7 [fccache] Make sure the cache is current when reusing from open caches
Reported by Diego Santa Cruz.
2009-02-15 13:40:25 -08:00
Behdad Esfahbod f9feb587fa [win32] Do not remove leading '\\' such that network paths work
Raised by Diego Santa Cruz.
2009-02-15 13:40:24 -08:00
Behdad Esfahbod 1cdf7efb22 [win32] Expand "APPSHAREFONTDIR" to ../share/fonts relative to binary location
Proposed by Diego Santa Cruz.
2009-02-15 13:40:24 -08:00
Behdad Esfahbod e62058abb9 [win32] Fix usage of GetFullPathName()
Diego Santa Cruz pointed out that we are using that API wrongly.
The forth argument is a pointer to a pointer.  Turns out we don't
need that arugment and it accepts NULL, so just pass that.
2009-02-15 13:40:24 -08:00
Behdad Esfahbod 574805478c [fcfreetype] Fix typo in GB2312 encoding name string (#19845)
This was causing failure when opening iconv converter, hence rendering
GB2312-encoded fonts with no other usable encoding unusable.
2009-02-15 13:40:18 -08:00
Karl Tomlinson 575ee6cddd Change FcCharSetMerge API
To only work on writable charsets.  Also, return a bool indicating whether
the merge changed the charset.

Also changes the implementation of FcCharSetMerge and FcCharSetIsSubset
2009-02-15 13:40:18 -08:00
Behdad Esfahbod b8860e2faf [fcmatch] Fix crash when no fonts are available. 2009-02-15 13:40:17 -08:00
Behdad Esfahbod 263f16ced2 Oops, fix FcPatternFilter 2009-02-13 16:54:06 -08:00
Behdad Esfahbod 4074fd254e Revive FcConfigScan() (bug #17121)
FcConfigScan() with parameters cache=NULL and force=FcTrue can be used
to scan font dirs without any caching side effect.
2009-02-13 16:54:06 -08:00
Behdad Esfahbod 25a09eb9bf Don't use FcCharSetCopy in FcCharSetMerge
The Copy function is actually a ref, not real copy.
2009-02-13 16:54:06 -08:00
Behdad Esfahbod d230cf144f Make FcCharSetMerge() public
That's needed for apps to be abled to do pruning themselves without
the performance penalty of recreating new charsets all the time.
2009-02-13 16:54:05 -08:00
Behdad Esfahbod 6d764a3f9b [fcmatch] Move FcFontSetMatch() functionality into FcFontSetMatchInternal()
Except for the final FcFontRenderPrepare().  This way we have more
flexibility to do caching in FcFontMatch() while leaving FcFontSetMatch()
intact.
2009-02-13 16:54:05 -08:00
Behdad Esfahbod a5a384c5ff [fcmatch] When matching, reserve score 0 for when elements don't exist
Previously an index j was added to element score to prefer matches earlier
in the value list to the later ones.  This index started from 0, meaning
that the score zero could be generated for the first element.  By starting
j from one, scores for when the element exists in both pattern and font
can never be zero.  The score zero is reserved for when the element is
NOT available in both font and pattern.  We will use this property later.

This shouldn't change matching much.  The only difference I can think of
is that if a font family exists both as a bitmap font and a scalable
version, and when requesting it at the size of the bitmap version,
previously the font returned was nondeterministic.  Now the scalable
version will always be preferred.
2009-02-13 16:54:05 -08:00
Behdad Esfahbod c7641f2872 [fcmatch] Use larger multipliers to enforce order
Previously the matcher multiplied comparison results by 100 and added
index value to it.  With long lists of families (lots of aliases),
reaching 100 is not that hard.  That could result in a non-match early
in the list to be preferred over a match late in the list.  Changing
the multiplier from 100 to 1000 should fix that.

To keep things relatively in order, the lang multiplier is changed
from 1000 to 10000.
2009-02-13 16:54:05 -08:00
Behdad Esfahbod 1b43ccc805 [fcmatch.c] Fix debug formatting 2009-02-13 16:54:04 -08:00
Behdad Esfahbod a291cfc710 Fix comparison of family names to ignore leading space properly
Previously fc-match "xxx,nazli" matched Nazli, but "xxx, nazli" didn't.
This was because of a bug in FcCompareFamily's short-circuit check
that forgot to ignore spaces.
2009-02-13 16:54:04 -08:00
Behdad Esfahbod 0c93b91db0 Implement FcPatternFormat and use it in cmdline tools (bug #17107)
Still need to add more features, but the API is there, and used
by cmdline tools with -f or --format.
2009-02-13 16:54:04 -08:00
Behdad Esfahbod f9806ab4b9 Remove special-casing of FC_FILE in FcPatternPrint()
I can't understand why the special case is needed.  Indeed, removing it
does not make any difference in the "fc-match --verbose" output, and
that's the only time fc-match uses FcPatternPrint.
2009-02-13 16:54:03 -08:00
Behdad Esfahbod 8ae1e3d5dc Explicitly chmod() directories (bug #18934)
Two changes:

  - after mkdir(), we immediately chmod(), such that we are not affected
    by stupid umask's.

  - if a directory we want to use is not writable but exists, we try a
    chmod on it.  This is to recover from stupid umask's having affected
    us with older versions.
2009-02-13 16:54:03 -08:00
Behdad Esfahbod b6cf885a0a Don't use identifier named complex 2009-02-13 16:54:03 -08:00
Behdad Esfahbod 00c0972aca Fix compile with old FreeType that doesn't have FT_Select_Size() (bug #17498) 2009-02-13 16:54:02 -08:00
Behdad Esfahbod 350dc5f350 Use __builtin_popcount() when available (bug #17592) 2009-02-13 16:54:02 -08:00
Behdad Esfahbod f69db8d49c Consistently use FcStat() over stat() in all places 2009-02-13 16:54:01 -08:00
Behdad Esfahbod 9e2ed2513b [fccache] Consistently use FcStat() over stat() (bug #18195) 2009-02-13 16:54:01 -08:00
Harald Fernengel fe8e8a1dd7 Don't use variables named 'bool' (bug #18851) 2009-02-13 16:54:01 -08:00
Behdad Esfahbod 355ed50b18 Don't call FcPatternGetCharSet in FcSortWalk unless we need to (#17361) 2009-02-13 16:54:00 -08:00
Behdad Esfahbod 799691c901 Don't leak FcValues string loaded through fcxml.c (#17661)
Patch from Caolan McNamara.
2009-02-13 16:54:00 -08:00
Chris Wilson 311da2316f Reduce number of allocations during FcSortWalk().
The current behaviour of FcSortWalk() is to create a new FcCharSet on
each iteration that is the union of the previous iteration with the next
FcCharSet in the font set. This causes the existing FcCharSet to be
reproduced in its entirety and then allocates fresh leaves for the new
FcCharSet. In essence the number of allocations is quadratic wrt the
number of fonts required.

By introducing a new method for merging a new FcCharSet with an existing
one we can change the behaviour to be effectively linear with the number
of fonts - allocating no more leaves than necessary to cover all the
fonts in the set.

For example, profiling 'gedit UTF-8-demo.txt'
    Allocator		    nAllocs	    nBytes
Before:
    FcCharSetFindLeafCreate 62886	    2012352
    FcCharSetPutLeaf        9361	    11441108
After:
    FcCharSetFindLeafCreate 1940	    62080
    FcCharSetPutLeaf        281		    190336

The savings are even more significant for applications like firefox-3.0b5
which need to switch between large number of fonts.
Before:
    FcCharSetFindLeafCreate 4461192	    142758144
    FcCharSetPutLeaf	    1124536	    451574172
After:
    FcCharSetFindLeafCreate 80359	    2571488
    FcCharSetPutLeaf	    18940	    9720522

Out of interest, the next most frequent allocations are
    FcPatternObjectAddWithBinding 526029    10520580
    tt_face_load_eblc	    42103	    2529892
2009-02-13 16:54:00 -08:00
Behdad Esfahbod 241fbde1ab Add FcConfigReference() (#17124) 2009-02-13 16:53:59 -08:00