summaryrefslogtreecommitdiffstats
path: root/libass/ass_fontselect.c
Commit message (Collapse)AuthorAgeFilesLines
* 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 is already better than waiting *minutes* for Fontconfig to cache the fonts data. A later commit will improve the speed of the match by using a hybrid approach that lazy loads in the libass database only the necessary fonts.
* Add todo commentsGrigori Goronzy2015-07-101-0/+4
|
* Support multiple font family namesGrigori Goronzy2015-07-101-32/+53
| | | | | | Some fonts use localized family names, especially CJK fonts, which often have English and Japanese or Chinese names. Handle these cases just like full names.
* nit: add width to font_info_dumpGrigori Goronzy2015-07-101-0/+1
|
* Add support for font width propertyGrigori Goronzy2015-07-101-1/+10
| | | | | | Add a width field to metadata. This is used for sorting fonts as well. Fixes wrong matches with different width variants in the same font family.
* Use streamed access for memory fontsGrigori Goronzy2015-07-101-13/+19
| | | | | This is faster in many cases, and more suitable for Windows' GetFontData function.
* Pass family name as path for memory fontsGrigori Goronzy2015-07-101-4/+4
| | | | | This is a bit nicer because we can actually see which physical font has been selected for a certain logical font.
* Memory font supportGrigori Goronzy2015-07-101-26/+81
| | | | | Allow memory fonts with the get_face_data callback. This feature is used for embedded fonts, but can be used by any font provider.
* Make sure font path is validGrigori Goronzy2015-07-101-1/+3
| | | | We do not support memory-based fonts yet, so a path is mandatory.
* Fix weight validity checkGrigori Goronzy2015-07-101-1/+1
|
* Free a provider's fonts when it is freedGrigori Goronzy2015-07-101-25/+65
| | | | | When a provider is freed, iterate the font database, free all fonts that belong to that provider and compact the database afterwards.
* oops: remove debug outputGrigori Goronzy2015-07-101-2/+0
|
* Check weight and slant validity in font providerGrigori Goronzy2015-07-101-3/+13
| | | | | When adding a new font, check that weight and slant are valid. If they're not, use reasonable defaults.
* Use TrueType font weight scaleGrigori Goronzy2015-07-101-1/+3
| | | | | | | | | | fontconfig uses an unusual scale from 0-215 for the font weight. It looks like it is somewhat derived from the typographic scale some font families use, but is still rather nonstandard. Nowadays the TrueType scale from 100-900 seems to be standard. CSS uses it, for example. However, most importantly, VSFilter also uses the TrueType scale. So let's use it in libass, too.
* Fix similarity calculationsGrigori Goronzy2015-07-101-2/+2
|
* Add a fixed set of fallback fontsGrigori Goronzy2015-07-101-11/+22
| | | | | Add a small set of fixed fallback fonts, some of them with very wide glyph coverage.
* Don't match any font if there's no glyph coverageGrigori Goronzy2015-07-101-1/+3
| | | | | Do not return a font face at all instead of using the last one. Fixes fallback to the default font path.
* Restore fontconfig runtime configurationGrigori Goronzy2015-07-101-6/+5
| | | | | | | | | | | Pass the fontconfig configuration file option and enable switch through into the font selector. This restores some of the old functionality related to fontconfig. However, the functionality to delay the fontconfig database update will not come back. This is not a big problem. Later it will be possible to manually add the fontconfig provider, which will delay the update in a comparable way.
* Fix compilation without fontconfigGrigori Goronzy2015-07-101-0/+4
| | | | | | Conditionally add the fontconfig provider. We can actually run without fontconfig now! That is, if embedded fonts or fallbacks are good enough.
* Fix off-by-one bug in font matchingGrigori Goronzy2015-07-101-1/+1
|
* Add reference to font provider in font databaseGrigori Goronzy2015-07-101-13/+20
| | | | | | This provides more flexibility than just referencing the callbacks: we can identify the font provider (useful for removing fonts when a provider is freed) and possibly access the font provider private data.
* Improve font selector/provider documentationGrigori Goronzy2015-07-101-5/+41
|
* Convert embedded font handling to a real font providerGrigori Goronzy2015-07-101-33/+55
|
* Add glyph coverage map for embedded fontsGrigori Goronzy2015-07-101-4/+81
| | | | | | Introduce a simple glyph coverage map (created when the font is added) and use it for checking glyph coverage in font selection. This uses a simple linear search at the moment.
* Never add a face twice to an ASS_FontGrigori Goronzy2015-07-101-7/+20
| | | | | | Introduce a unique ID per font face and check it in add_face to make sure we never add a font face twice. This is useful in case the glyph coverage report is unreliable.
* Trim spaces of font family stringsGrigori Goronzy2015-07-101-2/+3
| | | | | This adds a trimming utility function that is used for trimming strings of font requests in the font sorter.
* Custom font matching and font sourcesGrigori Goronzy2015-07-101-0/+514
Implement a simple font sorter (FontSelector) and an interface to deal with multiple font sources (FontProvider). Unfinished business, but works for the most part. Currently the only implemented FontProvider uses fontconfig.