summaryrefslogtreecommitdiffstats
path: root/libass/ass_font.c
Commit message (Collapse)AuthorAgeFilesLines
* ass_shaper: create hb_font_t eagerly during add_faceHEADmasterrcombs2 days1-5/+13
|
* ass_font: remove unused size fieldrcombs7 days1-3/+0
|
* font: prefer full-Unicode cmaps to BMP-only onesOleg Oshmyan2024-01-231-9/+21
| | | | | Fixes: https://github.com/libass/libass/issues/634 Fixes: https://github.com/mpv-player/mpv/issues/13322
* ass_font: match GDI's faux-italicsrcombs2023-02-171-1/+16
| | | | GDI uses this same matrix.
* ass_font: add special-casing for weights under 10rcombs2023-02-171-3/+24
| | | | GDI uses this lookup table to convert these values to the usual scale.
* Drop unnecessary os2->version != 0xffff checkOleg Oshmyan2023-01-221-1/+1
| | | | | | | | This kind of check is used internally in FreeType to distinguish a real OS/2 table from a placeholder that is always present in every FT_Face. However, the public FT_Get_Sfnt_Table API already performs this check and returns NULL if a real table is absent: we do not need to recheck this, and indeed we do not do this anywhere else.
* Consistently use FT_SFNT_OS2 macro name to access OS/2 tableOleg Oshmyan2023-01-221-8/+8
| | | | | | | As a reminder, we require FreeType >= 2.3.6 since commit d7544850775344879dd3049046c5b7ce2d52d3b3, as explained in commit 6d4d51db96858f37570d169b18abc68f875c657e, which last updated the corresponding configure check.
* font: use actual NBSP character for \hOneric2022-11-301-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | \h is often used in typesetting purely for horizontal padding. We already correctly expand \h to NBSP (0xA0) during parsing, but then later replace it with a space (0x20) for shaping run detection. Actual shaping though again uses NBSP, but still uses the font face indices from shaping run detection. This can lead to problems if the font detected for a regular space doesn’t also provide a NBSP character. HarfBuzz automatically substiutes a missing NBSP character with the font’s space character, hiding the issue. With FriBidi doing shaping, \h will end up as a TOFU box. Stop replacing NBSP with a regular space, so font substitution can take place properly. Note: some subs rely on GDI picking Arial for a NBSP fallback. This commit makes no attempt to nudge fallback selection to any particular font. This reverts 33a3ab2c8777241b73ad85024158e19fb1f9c699. We no longer know what problems the original commit tried to solve, but know for sure the current replacing causes issues (and that VSFilter too uses a different font for fallback NBSP). Fixes: https://github.com/libass/libass/issues/2
* ass_font: remove unused functionrcombs2022-11-151-13/+0
|
* refactor: prefix all internal API with ass_Oneric2022-10-221-8/+8
| | | | | | | | | | | | | | | If static libass is linked into a binary defining functions of the same name there will be issues. To avoid this use an ass_ prefix for namespacing. Before this commit we already did this for most but not yet all internal API. read_file is renamed to ass_load_file as ass_read_file already exists as a public API function. All other functions are simply prefixed with ass_. Fixes: https://github.com/libass/libass/issues/222 Fixes: https://github.com/libass/libass/issues/654
* font: handle conversion failure betterApache5532022-01-301-10/+18
| | | | | If a conversion fails for a non-Unicode font, let font fallback happen instead of displaying bogus glyphs.
* font: use iconv to handle non-unicode cmap microsoft fontsApache5532022-01-301-6/+167
| | | | | | | | | Use Windows native API to convert Unicode to MBCS on Windows, then use iconv if not on Windows and iconv is available. Do nothing if neither is available. fix: `ass_font_index_magic` now doesn't mangle codepoint if charmap isn't Microsoft's.
* renderer: eliminate FT_GlyphDr.Smile2021-10-051-29/+16
|
* renderer: consolidate processing of glyph decoration flagsDr.Smile2021-10-051-98/+84
| | | | | | Processing of DECO_ROTATE has moved after ASS_Outline conversion too. All relevant outline processing functions have moved into ass_outline.c. outline_convert() now expects preallocated outline to reduce reallocations.
* ass_face_open: if only one face exists, use it without name checkOleg Oshmyan2021-09-241-3/+11
| | | | | | | | | | | At worst, even if this face isn't actually the desired one, this will just waste memory but won't break font selection. At best, this enables use of some broken TrueType fonts that lack valid PostScript names, as in https://github.com/libass/libass/issues/554. Core Text synthesizes a PostScript name, but FreeType doesn't, so every face has a NULL face_psname. Potentially, a font might also have a non-NULL face_psname that differs from Core Text's.
* ass_face_open: don't return garbage if PostScript name not foundOleg Oshmyan2021-09-241-4/+12
| | | | Fixes https://github.com/libass/libass/issues/554.
* Add strikeout/underline to ASS_Outline, not FreeType-owned memoryOleg Oshmyan2021-09-221-32/+23
| | | | | | | | | | | | | | | ass_strike_outline_glyph was realloc()ing memory that was allocated by FreeType, not us. This isn't generally safe. Indeed, FreeType recently switched to a different allocator on Windows, so this code started crashing. To avoid this, move the ass_strike_outline_glyph call after the FT_Outline -> ASS_Outline conversion. It's safer (less chance to exceed outline size limits) and easier to work with ASS_Outline, anyway. Fixes the crash in https://github.com/mpv-player/mpv/issues/9227.
* font: remove misleading no-op codeOleg Oshmyan2021-09-091-7/+0
| | | | | | ass_font_get_index is _always_ called with *face_index == 0, and even then it's only a fallback default rather than a request: it should be treated as an output-only parameter.
* ass_face_stream: don't leak first struct if second alloc failsOleg Oshmyan2021-07-101-1/+3
| | | | | | | | Bug in commit a7f67df5f96f03fab6661d90d716c16e0fab4a21, which introduced the alloc check. Before that, alloc failure would result in illegal memory access, so at least this was an improvement. Fixes CID 350862 found by Coverity Scan.
* fontselect: automatically read metadata from font file if neededOleg Oshmyan2021-07-101-2/+7
|
* fontselect: save library and ftlibrary in ASS_FontSelectorOleg Oshmyan2021-07-101-1/+1
| | | | ...instead of passing them as arguments everywhere.
* font, fontselect: factor out common code for creating FT_FaceOleg Oshmyan2021-07-101-49/+72
|
* Fix some format string bugsrcombs2021-05-301-3/+3
| | | | | - ass_drawing was logging size_t as %d - ass_font was logging ASS_StringView as %s (could crash!)
* parsing: use string references for font family and drawing textDr.Smile2021-02-221-1/+1
| | | | That eliminates most uses of strdup() in the rendering process.
* font: use library as a failure flagDr.Smile2020-10-111-2/+2
| | | | | | ass_font_clear() can now free family string even in a failure case. Fixes https://github.com/libass/libass/issues/414.
* Style-Nit: Adjust whitespacesOneric2020-07-051-1/+1
| | | | | | | - Convert tabs to spaces - Ensure one space between keywords and parenthesis - Ensure space between ')' and '{' - Trim trailing whitespace
* ass_font: fix typo in zero height checkOleg Oshmyan2020-07-051-1/+1
|
* font: simplify metrics handling; fixes #361rcombs2020-07-051-39/+26
| | | | | We used to do a lot of work to get freetype to imitate VSFilter's font-metrics handling. Instead, we now just duplicate its behavior directly early on.
* font: don't faux-bold fonts that are already bold enoughRodger Combs2019-09-261-2/+1
| | | | | | And conversely, do faux-bold fonts that are too thin The offset of 150 matches VSFilter's behavior
* font: add function to get the actual weight of a font faceRodger Combs2019-09-261-0/+17
|
* font: extract transformation from ass_font_get_glyph()Dr.Smile2019-05-191-17/+0
|
* cache: construct cache values only from corresponding keysDr.Smile2019-05-191-22/+19
| | | | | | | | | | | | | | | | | | | | This commit forces construction of cache values using only data available in its companion keys. That ensures logical correctness: keys are guaranteed to have all the necessary data, and prevents accidental collisions. Most fixes of cache logic correspond to minor problem when rendering is done with double parameter but cache key stores its approximate fixed-point representation. The only serious problem is missing scale of clip drawing. Also this commit removes unused scale parameters from glyph metrics cache key. Due to missing scale clip shapes that differed only in scale treated by cache system as identical. That can lead to incorrect reuse of cached bitmap of different scale instead of correct one. The only hack left is in glyph metrics cache with its unicode >= VERTICAL_LOWER_BOUND check.
* font: remove dependency on symbol codesDr.Smile2019-05-191-25/+17
| | | | | Leading newlines are now rendered, but still incorrectly: at full height rather than at half-height as required.
* font: remove unused fieldDr.Smile2019-05-191-10/+3
|
* cosmetic: extract most of the outline-related functions into separate fileDr.Smile2017-07-311-251/+0
|
* cache: keep ref_count of all active objects nonzeroDr.Smile2016-06-301-3/+8
|
* cache: replace size_func with parameter in ass_cache_commit()Dr.Smile2016-06-301-2/+2
|
* cache: remove ass_cache_cancel(), cache failures insteadDr.Smile2016-06-301-7/+8
|
* cache: switch to gradual cache clearingDr.Smile2016-06-301-27/+26
| | | | | | | | | | | Advantages over the old algorithm consist of the following. * There are no glitches due to full cache clearing. Items are arranged into linked list ordered by time of last use. Only the oldest items get deleted at the clearing event. * Each item now keeps track of number of references. Referenced cache values are immune to clearing. * Reduced amount of total cache memory for the same performance. * Reduced number of memory allocations per cache item.
* font: fix NULL pointer dereferenceHannes Domani2016-05-231-0/+3
|
* font: remove unused functionwm42016-01-141-26/+0
|
* font: check FT_Get_Postscript_Name return value for NULLOleg Oshmyan2015-10-231-1/+3
|
* ass_font: fix broken loop conditionwm42015-09-241-1/+1
| | | | | | As pointed out in #198. This is certainly just a typo. Fixes #198.
* 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>
* font: ignore bearing for strikesGrigori Goronzy2015-09-161-16/+11
| | | | | | | | | | This is more robust and simpler. The bearing calculations initially were bugged, but getting rid of them completely seems better. It is consistent with other text renderers as well. To simplify things, also move striking before the additional scale is applied and get rid of the half-pixel overlapping thing; it is not needed with additive blending. Fixes #193.
* NIH: add locale-independent string functionsGrigori Goronzy2015-09-111-1/+0
| | | | | | | | 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: initialize postscript nameGrigori Goronzy2015-09-071-1/+1
| | | | Bad things can happen otherwise. Found by coverity scan.
* fontselect: get rid of strdup for display nameGrigori Goronzy2015-09-071-5/+0
| | | | | The name is always pulled from the font info, which is static, so there is no need to strdup.
* font: fix double frees if opening memory font failswm42015-08-311-2/+0
| | | | | Apparently, libfreetype calls close_stream_font through the FT_Stream.close callback.
* font: fix broken charmap fallback handlingwm42015-08-281-1/+1
| | | | | | | | | An earlier commit added this code to avoid adding font faces multiple times. In this form, it breaks the "Trying all charmaps" fallback case, which can lead to text being rendered as boxes. Return the font that is going to contain the missing glyph instead. The calling code will check again, and run the fallback if necessary.
* fontselect: coretext: allow selection based on PostScript nameStefano Pigozzi2015-07-101-2/+22
| | | | | | | | | | | 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.
* Use streamed access for memory fontsGrigori Goronzy2015-07-101-6/+40
| | | | | This is faster in many cases, and more suitable for Windows' GetFontData function.
* Pass family name as path for memory fontsGrigori Goronzy2015-07-101-1/+1
| | | | | 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-23/+8
| | | | | Allow memory fonts with the get_face_data callback. This feature is used for embedded fonts, but can be used by any font provider.
* Use TrueType font weight scaleGrigori Goronzy2015-07-101-1/+1
| | | | | | | | | | 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.
* Add glyph coverage map for embedded fontsGrigori Goronzy2015-07-101-1/+1
| | | | | | 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/+16
| | | | | | 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.
* Custom font matching and font sourcesGrigori Goronzy2015-07-101-17/+13
| | | | | | | 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.
* Fix bug in ASS_Outline intrastructureDr.Smile2015-01-221-34/+19
|
* Destroy harfbuzz faces before freetype facesBehdad Esfahbod2014-12-281-2/+2
| | | | | HarfBuzz faces reference the FreeType faces. Destroying FT faces first can cause crash in HB destruction code: https://bugs.freedesktop.org/show_bug.cgi?id=86300
* Replace FT_Outline with ASS_OutlineDr.Smile2014-11-231-18/+119
|
* Check some allocations in strike-through codewm42014-11-141-5/+10
|
* Fix limits.h includesGrigori Goronzy2014-02-171-0/+1
| | | | These were missing in several places. Fixes #50.
* Font metrics: FreeType falls back to sTypoAscender/DescenderOleg Oshmyan2014-02-111-4/+8
| | | | Fixes libass#8.
* Fix compilation with VC++ 2013Thomas Goyne2013-12-121-47/+32
| | | | | | | | | | | For whatever reason FT_Vector points[4] = { ... }; needs to come at the beginning of a scope. Since that block was duplicated, just extract it to a function. This does not include buildsystem support, so actually compiling with VC++ requires creating a project and supplying a config.h file. Signed-off-by: wm4 <wm4@nowhere>
* Added ass_font_index_magic to fix char indexes in weird encodings11rcombs2013-12-061-7/+22
|
* Fix OS/2 usWinDescent/usWinAscent for quirky fontsGrigori Goronzy2013-07-061-3/+4
| | | | | | | | Some fonts stuff a signed, negative value into this unsigned field. This usually causes very small and wrongly positioned rendering. Also handle usWinAscent similarly, just in case. Fixes issue #106.
* Fix fix_freetype_strokerOleg Oshmyan2012-12-281-5/+5
| | | | | | | | | | | | The first point in a countour is not allowed to be a cubic control point, which is sometimes violated by blindly reversing a countour, producing the following errors: [ass] FT_Stroker_ParseOutline failed, error: 20 [ass] Failed to rasterize glyph: 1 To avoid this, let the first point remain the first and only reverse the order of the remaining points.
* vertical: improve glyph positioningGrigori Goronzy2011-08-251-2/+8
| | | | | | | | | | | | It is a bit crazy, but for vertical layout the sTypoAscender and sTypoDescender fields of the OS/2 table are supposed to be used for determining the size of the ideographic EM box [1], so that glyphs can be centered on the baseline more neatly. With this change, vertical layout should be completely equal to VSFilter. [1] http://www.microsoft.com/typography/otspec150/os2.htm#sta
* harfbuzz: fix vertical advanceGrigori Goronzy2011-08-251-2/+0
| | | | | Make sure to use vertical advance under the right conditions - vertical font selected, requested glyph is non-latin.
* Hack: return a valid face index even if no glyph is foundGrigori Goronzy2011-07-171-0/+2
| | | | | Temporary fix for a crash when a font face doesn't actually contain the glyph that fontconfig reports. Needs a real solution.
* Fix crash with FreeType's updated strokerGrigori Goronzy2011-07-171-7/+26
| | | | | | The new revision of the stroker in FreeType doesn't like the way contours are zero-filled to disable them. It's not particularly clean anyway, so rewrite the whole outline instead.
* Set requested font face correctlyGrigori Goronzy2011-07-161-1/+1
|
* shaper: fix run-specific font sizeGrigori Goronzy2011-07-161-5/+3