summaryrefslogtreecommitdiffstats
path: root/libass/ass_fontselect.c
Commit message (Collapse)AuthorAgeFilesLines
* fontselect: cleanup lazy font index evaluationGrigori Goronzy2017-06-011-6/+8
| | | | Fixes a possible NULL pointer dereference, reported by Coverity.
* directwrite: fix font collectionsGrigori Goronzy2017-06-011-0/+5
| | | | | | | | | | | | | | | | DirectWrite's FontFileStream does not actually use the data of a specific font in a collection, which was an expectation of the existing code. It simply returns a stream to the underlying file, collection or not. So we need to get the index of the font. This needs to be done lazily as this information is only available in a FontFace, which is expensive to initialize. Add a new optional font provider function for lazy initialization of the index and use it. This is similar to the check_postscript callback. Fixes libass#275. v2: fix type of returned value.
* font load from dir: use MSGL_INFO instead of MSGL_WARNAvi Halachmi (:avih)2016-07-111-1/+1
| | | | | | | | This is a normal course of action and should not generate a warning, especially for applications which use libass and might notify the user on such "warnings", while in fact it should be info or even verbose. Fixes #231
* fontselect: destroy private data of fonts that fail to be addedOleg Oshmyan2015-12-011-0/+4
|
* fontselect: fix bool return valuesOleg Oshmyan2015-12-011-6/+6
| | | | | | | Return true on success and false on failure. get_font_info was actually inconsistent, returning false both on success and on failure due to the face not being scalable.
* fontselect: replace is_postscript flag with check_postscript functionOleg Oshmyan2015-11-041-20/+38
| | | | | | | | | | | | | | | | | | | | | | | DirectWrite does not provide fast access to the is_postscript flag, requiring each font to be loaded before its format can be determined. Eagerly doing this for every installed font can be quite slow, on the order of seconds. To improve performance, ask the font provider for this information only when it is actually needed, i.e. when one of the font's full names or its PostScript name matches a requested font name and we need to know whether to accept this match. The return value of check_postscript is not cached in this commit. This makes repeated calls slower than accessing is_postscript was. This should not be a problem, but if it is, the value can be cached (or precomputed) by font providers in their font private data. This commit also potentially increases the memory usage of some font providers by retaining data structures needed to implement check_postscript in their font private data. This should not be a problem either, but if it is, the value of check_postscript can be precomputed by all providers other than DirectWrite.
* fontselect: silence warnings about discarding constOleg Oshmyan2015-10-291-2/+2
| | | | | | | | Fixing this properly involves constifying ASS_FontProviderMetaData and refactoring code that allocates and frees strings stored in it. This seems easy on the surface but turns out to be nontrivial when you actually try to do it. This may still be done at a later date, but for now, just add explicit casts.
* fontselect: don't trim font namesOleg Oshmyan2015-10-231-15/+6
| | | | | | | | | | | | This matches the behavior of GDI and hence VSFilter. Note that \fn arguments are trimmed during parsing. However, none of the names inside fonts should be trimmed, and @-prefixed fonts should keep whitespace following the @, both of which this commit addresses. Remove strdup_trimmed because it is no longer used. Also remove the declaration of a function that was deleted a few months ago.
* fontselect: don't find fonts with PostScript outlines by full nameOleg Oshmyan2015-10-231-18/+13
| | | | | | | | | | | | Related to commit e00691e8096cc69e5651480155ebc61d9e079290: it turns out that GDI (and hence VSFilter) does not check full names of fonts that have PostScript outlines when searching for a font by name. To summarize the resulting behavior: * Fonts with PostScript outlines can be found by family name and by PostScript name. * Fonts without PostScript outlines can be found by family name and by full name.
* fontselect: use stdbool.h wherever appropriateOleg Oshmyan2015-10-231-10/+10
|
* fontselect: find fonts with PostScript outlines by PostScript nameOleg Oshmyan2015-10-231-12/+32
| | | | | | | Fonts without PostScript outlines (such as TrueType fonts) are unaffected, and their PostScript names continue to be ignored when searching for fonts. This matches the behavior of GDI and hence VSFilter.
* fontselect: read PostScript names for memory fontsOleg Oshmyan2015-10-221-1/+9
| | | | | | Currently this affects only the verbose output in ass_font_select, but it will become more useful when we start matching against PostScript names in the future.
* fontselect: move PostScript name into ASS_FontProviderMetaDataOleg Oshmyan2015-10-211-10/+8
|
* fontselect: fix ass_font_provider_add_font signature and doxygenOleg Oshmyan2015-10-211-3/+3
| | | | index is signed, and psname only overrides it iff index < 0.
* Merge pull request #84 from astiob/msvcGrigori Goronzy2015-09-221-0/+1
|\ | | | | MSVC/ICL and general header fixes
| * Fully fix compilation with MSVC/ICLOleg Oshmyan2015-09-171-0/+1
| | | | | | | | | | | | | | | | | | As before, this does not add any build system support: a config.h file and a project must still be manually created (or the compiler can be run manually instead of using a project). Signed-off-by: Grigori Goronzy <greg@kinoho.net> Signed-off-by: Oleg Oshmyan <chortos@inbox.lv>
* | fontselect: make iconv optional againwm42015-09-211-22/+2
|/ | | | It was needed for UTF16BE -> UTF8 only, which is trivial to implement.
* ass_fontselect: do not use PATH_MAXwm42015-09-131-1/+1
| | | | | This seems to cause issues on MSVC. Considering that even most Unix OSes hate PATH_MAX and don't really honour it, using 4096 is just as good.
* NIH: add locale-independent string functionsGrigori Goronzy2015-09-111-4/+4
| | | | | | | | OS or platform-specific locale independent functions are painful to use and/or not available, so roll our own. Not great but the least painful and least intrusive. v2: fix indexing, use static inline
* fontselect: avoid undefined behaviorwm42015-09-091-3/+5
| | | | | | Passing NULL as argument to %s format specifiers when using the printf fasmily of functions is not allowed. While some libcs handle it, other libcs will simply crash.
* fontselect: raise font selection log messagewm42015-09-091-1/+1
|
* ass_fontselect: ignore ./.. and hidden fileswm42015-09-081-0/+2
|
* fontselect: handle additional malloc errorsGrigori Goronzy2015-09-081-2/+5
|
* ass_fontselect: uninline ass_map_font()wm42015-09-071-0/+13
| | | | | Also fixes the build on OSX under some circumstances (weird and inconsistent rules for the inline keyword in C).
* ass_fontselect: log the selected font providerwm42015-09-071-5/+9
|
* fontselect: fix memory leakGrigori Goronzy2015-09-071-1/+1
| | | | Introduced by commit d6bb9af6. Found by coverity scan.
* fontselect: get rid of strdup for display nameGrigori Goronzy2015-09-071-3/+3
| | | | | The name is always pulled from the font info, which is static, so there is no need to strdup.
* fontselect: improve font display name choiceGrigori Goronzy2015-09-071-3/+7
|
* fontselect: remove outdated remarkGrigori Goronzy2015-09-071-4/+0
| | | | | fontselect is an internal only API for now. That said, it also seems much more sane to let library users deal with this resource management.
* fontselect: call match_fonts for each aliasGrigori Goronzy2015-09-071-3/+6
| | | | In case a font provider actually uses more than one substitution.
* fontselect: fix fallback family fallbackGrigori Goronzy2015-09-071-1/+1
|
* fontselect: fix match_fonts semanticsGrigori Goronzy2015-09-071-27/+55
| | | | | | | | | | We don't want to add fonts multiple times, so call match_fonts lazily, i.e. only after selecting a font with a certain name failed. Since font matching interacts with glyph coverage checks, add a simple mechanism to determine whether matching failed because of name or glyph coverage. Additionally make sure to handle substitutions before any calls to match_fonts; this only correctly deals with single-name substitutions, though.
* fontselect: fix yet another memory leakGrigori Goronzy2015-09-011-0/+2
|
* fontselect: stop font selection after first matchGrigori Goronzy2015-09-011-0/+5
|
* fontselect: remove static fallback font listGrigori Goronzy2015-09-011-26/+0
| | | | | The default font provider needs to provide a GetFallbackFunc callback instead.
* fontselect: add constwm42015-09-011-1/+1
|
* fontselect: never pass family=NULL to get_fallback()wm42015-09-011-0/+3
| | | | | The CoreText backend doesn't like this, and in fact there's no reason to pass NULL.
* fontselect: simplify get_fallback signaturewm42015-09-011-6/+1
| | | | | Apparently we only need the font family (and even that isn't used in all font providers). Drop the others.
* fontselect: use designated initializerswm42015-09-011-4/+5
| | | | | | Tired of matching the names and order of the callbacks in my head. While we're at it, also give some of the callbacks better names.
* fontselect: add bounds checking for memory font stream readswm42015-08-311-0/+6
|
* fontselect: fix a memory leakwm42015-08-311-22/+29
| | | | The result of the subst_font callback was not freed.
* fontselect: reimplement ass_set_fonts_dir() functionalitywm42015-08-281-0/+29
| | | | | | | | | | | | | | | | | | ass_set_fonts_dir() is supposed to enable all fonts in a specific directory. The implementation for it was dropped with the commit introducing the new fontselect code. Some users were relying on it, so we need it back. It used to be implemented using a single fontconfig call. But since this has to work even if fontconfig support is not even compiled, a new implementation is needed. This commit adds very simple and low-effort support for it. It loads all files into memory, and then lets the memory font code do the rest. A more efficient implementation would be possible, for example by implementing a new font provider, which serves get_data requests from open file handles. Anyone who wants to do this is welcome to try, and this commit is just the minimum to restore the lost feature.
* fontselect: fix fallbackswm42015-08-281-1/+1
| | | | I broke it.
* fontselect: minor cleanupwm42015-08-281-12/+11
| | | | | Use a pointer to the selected font info, instead of an index. Makes the code a bit more readable.
* fontselect: correctly match list of font substitutionswm42015-08-281-66/+72
| | | | | | | | | | | | This code prioritized fonts by scanning order, but the scanning order is essentially arbitrary. This resulted in suboptimal and indeterministic font selection by family name. Prefer the order as returned by the substitution callback. This requires some restructuring. The core algorithm is still exactly the same though; only the order of comparisons changes. If the font backend has no subtitution callback, nothing should change.
* fontselect: deal with potential ASS_FontProvider.subst_font failurewm42015-08-281-2/+3
| | | | | Don't assume it sets all fields. If it doesn't return any font names at all, go with the default.
* fontconfig: implement substitutionsGrigori Goronzy2015-08-281-17/+26
| | | | Signed-off-by: wm4 <wm4@nowhere>
* fontselect: check fontprovider constructors for failurewm42015-08-281-4/+4
| | | | Should fix the DirectWrite to Fontconfig fallback.
* fontselect: prefer platform font providersGrigori Goronzy2015-07-101-3/+3
| | | | | Prefer DirectWrite before the cross-platform fontconfig, so that DirectWrite is used by default if both are compiled into libass.
* fontselect: add fallback handling with callbackGrigori Goronzy2015-07-101-0/+19
| | | | | If we can't find a matching font face (with glyph coverage), ask the default font provider for a fallback family. The callback is optional.
* fontselect: improved face selection among a familyGrigori Goronzy2015-07-101-17/+27
| | | | | We want the best variant, but if it doesn't have the glyph coverage, we may also use another variant from the same family.
* fontselect: fix undefined behavior with callocGrigori Goronzy2015-07-101-7/+23
| | | | | | | | | If allocations have the size zero, malloc/calloc implementations can return a zero-size buffer or NULL. The earlier introduced malloc checking blows up if an implementation returns NULL. Fix that by only allocating and checking when it's actually needed. Also fix a minor problem with iconv deinitialization in an error path.
* fontselect: replace magic numbers (NFC)Grigori Goronzy2015-07-101-3/+6
|
* fontselect: trim names of embedded fontsGrigori Goronzy2015-07-101-2/+2
| | | | | | | | Embedded fonts tend to be extra bad, so trim the names. I have encountered fonts faces with untrimmed names. Leave this at the discretion of the font provider for platform-specific font providers.
* fontselect: add and use strdup_trimmedGrigori Goronzy2015-07-101-5/+8
| | | | This is just a cleaner and safer interface for string trimming.
* fontselect: simplify lookup of embedded fontsGrigori Goronzy2015-07-101-23/+3
| | | | | | | | | Currently, it is not safe to change the embedded fonts (ass_add_font/ass_clear_fonts) while an ASS_Renderer exists. We can simplify how embedded fonts are looked up because of that. At some point, ASS_Library and ASS_Renderer should be merged and we can then implement a more flexible approach.
* fontselect: malloc and error checkingGrigori Goronzy2015-07-101-26/+121
| | | | | | | | Add malloc checks with useful semantics and error checks in some specific cases. This should hopefully make fontselect more robust. The platform-specific font providers (DirectWrite/CoreText/FontConfig) still need to be checked for proper memory management.
* fontselect: simplify cmap lookup for embedded fontsGrigori Goronzy2015-07-101-63/+11
| | | | | FreeType can do it for us and is probably more efficient. Also fixes deinitialization order of ASS_Renderer to make this work.
* fontselect: improved and simplified matchingGrigori Goronzy2015-07-101-68/+59
| | | | | | | | | | | | Sorting the font list is overkill and not very useful. We are interested in *exact* name matches only; all other font families don't matter and we'll use another fallback mechanism for glyph fallbacks (TBD). Replace the sorting and glyph fallback search with a simple linear scan. Fonts are first matched against family name first (to allow further comparison against style attributes) and if that fails, the fullname is considered.
* fontselect: add fallback and substitution callbacksGrigori Goronzy2015-07-101-0/+2
| | | | | Add callbacks to introduce more sane fallback handling and font alias substitutions.
* directwrite: add initial fontselect implementationfeliwir2015-07-101-0/+22
| | | | Incomplete, leaks memory, but capable of rendering something.
* fontselect: fix NULL dereferenceStefano Pigozzi2015-07-101-1/+1
| | | | | Apparently on some broken fonts, FreeType can return a NULL family name. Avoid to crash in these cases.
* Fix warningsGrigori Goronzy2015-07-101-1/+2
|
* fontselect: expose a fontprovider listing APIStefano Pigozzi2015-07-101-0/+15
| | | | | | This allows client code to query libass for the font providers it was compiled with. It can be useful for clients so that they can show selection interfaces to their users.
* fontselect: expose a fontprovider selection APIStefano Pigozzi2015-07-101-12/+31
| | | | | | | | | Allow the user of libass to select the font provider from ass_set_fonts. This API change actually doesn't break client code which was passing `fc=1`; now the same value will autodetect a usable font provider. Also add an api to list available font providers as that is useful for client code to show drop down menus with a font provider to choose from.
* fontselect: use fallback fonts when querying font providersStefano Pigozzi2015-07-101-18/+11
| | | | | | | | | 51f9e80b added a MatchFontsFunc callback which allows to lookup font names directly on the font provider. This approach broke support for font fallback which worked only with lookups from libass in-memory font database. This commit moves the font fallback code in the font lookup function, so that it is available for all font providers.
* fontselect: coretext: allow to match fontname using the providerStefano Pigozzi2015-07-101-2/+8
| | | | | | | | | | | | | | | | | | | | | | Not all APIs cache everything the same way that fontconfig does. This allows to first perform a match based on the font name and then score the matched fonts using the common code using and in memory database approach. The benefit is the application doesn't have to load all of the fonts and query for weight, slant, width, path and fullnames. I left both code paths inside ass_coretext.c. This allows to test matching problems and have a term of comparison with the slower implementation. To activate it one just has to flip the CT_FONTS_EAGER_LOAD define to 1. Here are some benchmarks with a pretty typical OS X font library of ~600 fonts and using Libass's test program to load a script with 'Helvetica Neue': CT_FONTS_EAGER_LOAD=0 0.04s user 0.02s system 79% cpu 0.081 total CT_FONTS_EAGER_LOAD=1 0.12s user 0.06s system 44% cpu 0.420 total
* fontselect: coretext: allow selection based on PostScript nameStefano Pigozzi2015-07-101-20/+30
| | | | | | | | | | | Up until now fontselect used the face index to identify which font to load from a font collection. While this pretty convenient when using something freetype based like fontconfig, it seems to be somewhat freetype specific. CoreText uses the PostScript name as the unique identifier of a font. This commit allows to use that instead of the index to decide which face to open with FT_New_Face. To use the PostScript name the provider must return a -1 index and the PostScript name.
* fontselect: implement a coretext font providerStefano Pigozzi2015-07-101-0/+8
| | | | | | | | | | | | | | | Fontconfig is known to be very slow on OS X and Windows, this has to do with the extremely prohibitive cache times (which are getting even longer with latest versions of Fontconfig). This commits starts to address the problem by using CoreText on OS X to load the font data. The commit uses the simplest possible approach to load all of the data in memory and then use it to match. This causes a somewhat slow startup time (around ~400ms on my i7) but it i