summaryrefslogtreecommitdiffstats
path: root/libass/ass_shaper.c
Commit message (Collapse)AuthorAgeFilesLines
* ass_shaper: remove dependency on hb-ftrcombs2020-10-221-3/+40
|
* ass_shaper: handle harfbuzz allocation failuresrcombs2020-10-221-14/+22
| | | | | | | | | Edit by Oleg Oshmyan <chortos@inbox.lv>: Move the final ass_shaper_shape returns inside the switch. Add a default case in ass_shaper_shape to proactively placate static analysers that might decide the switch is not exhaustive and we therefore don't return a value. We know it is actually exhaustive as we validate the shaper selection in ass_set_shaper.
* Return bool from ass_shaper_shapeOleg Oshmyan2020-10-221-4/+4
|
* Make harfbuzz a hard dependency; closes #199rcombs2020-10-221-37/+0
|
* ass_shaper_find_runs: don't decrement pointer beyond array startOleg Oshmyan2020-10-191-3/+5
| | | | That triggers undefined behavior.
* shape_harfbuzz: don't attempt to shape drawingsOleg Oshmyan2020-10-191-0/+5
|
* shaper: ensure drawings are in separate shape runs from textOleg Oshmyan2020-10-191-6/+5
| | | | | | | Previously, drawings would get shape_run_id = 0 from calloc. Most of the time, this separated them from text shape runs, but drawings immediately following the very first shape run would get appended to it. Make sure this cannot happen.
* shaper: don't mingle run ID and bidi embedding levelOleg Oshmyan2020-10-191-9/+6
| | | | | | | | | | | | | | | | | | | A libass-chosen shaping run boundary can coincide with a bidi embedding level boundary such that the differences in shaper_run_id and emblevel cancel out. For example: English עבריתEnglish again (with parentheses) (with no space after the Hebrew) has ass_shaper_find_runs split runs after the Hebrew, adding 1 to shape_run_id, while the RTL embed also ends in the same place, removing 1 from emblevel. As a result, two shape runs that should be separate merge together. In this example, this leads to HarfBuzz thinking that "English again (with parentheses)" is still right-to-left, so it flips the parenthesis glyphs. To avoid this, don't attempt to add these numbers together. Just require explicitly that both numbers stay constant, rather than their sum.
* shaper: use FRIBIDI_LEVEL_IS_RTL macroOleg Oshmyan2020-10-191-1/+1
|
* shaper: honor/reuse starts_new_runOleg Oshmyan2020-10-191-27/+1
| | | | | | | | | This removes duplicated code (and a not-fully-correct comment). This also ensures shaping has breaks whenever the rest of the pipeline breaks runs (e. g. for bitmap combining). In particular, this adds missing breaks on karaoke changes, which the old code didn't actually honor despite the comment.
* shaper: handle U+FFFC characters that occur in textOleg Oshmyan2020-10-191-1/+1
| | | | | | | | | U+FFFC can not only come from drawings but also be actually contained in the source text. In that case, handle it like any other character. This doesn't distinguish source-text U+FFFC from drawings whose strdup failed. But the whole rest of the pipeline treats those drawings as plain U+FFFC characters, too.
* Add more invisible characters to ass_shaper_skip_charactersOleg Oshmyan2020-09-191-1/+5
| | | | | | | | * Bidirectional isolates * Arabic letter mark * Invisible plus * Variation selectors * Mongolian control characters
* Use bool and true/false assignments for GlyphInfo::skipOleg Oshmyan2020-09-191-4/+4
|
* Disable bidi bracket matching unless enabled via ASS_FeatureOleg Oshmyan2020-07-141-12/+21
| | | | | | | | | | | | | | | | | | | | | Bracket matching is incompatible with VSFilter (even on modern Windows), so disable it by default. But as it's generally a good thing (and 100% more compliant with current Unicode), keep it available as an ASS_Feature. It can be toggled individually or enabled as part of the catch-all ASS_FEATURE_INCOMPATIBLE_EXTENSIONS feature. If libass is compiled against FriBidi older than 1.0, bracket matching is impossible. Signal this at runtime by failing to recognize the ASS_FEATURE_BIDI_BRACKETS feature. This way, clients who want to use bracket matching can set the feature without any compile-time checks for FriBidi and can be freely linked against libass that is itself compiled against any version of FriBidi; and yet they can detect at runtime whether the feature is actually enabled. Fixes https://github.com/libass/libass/issues/374.
* Take bool in ass_shaper_set_kerningOleg Oshmyan2020-07-141-2/+2
|
* shaper: drop prealloc parameter of ass_shaper_newOleg Oshmyan2020-07-121-5/+2
| | | | | | The only prealloc value actually used is 0, which is not useful and invokes implementation-defined (and potentially obsolescent as per C11 DR400) behavior.
* ass_shaper: fix harfbuzz deprecation warning; closes #320rcombs2020-07-051-7/+23
|
* Use FriBiDi 1.x API when availableKhaled Hosny2019-09-261-0/+22
| | | | This allows making use of the updated UBA in Unicode 6.3 and up.
* cache: remove level of indirection in glyph metrics valueDr.Smile2019-05-201-21/+21
|
* cache: construct cache values only from corresponding keysDr.Smile2019-05-191-32/+41
| | | | | | | | | | | | | | | | | | | | 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.
* ass_set_fonts: empty cache as wellRodger Combs2017-10-221-0/+7
|
* shaper: fix reallocationGrigori Goronzy2016-10-041-0/+1
| | | | | | | | Update the variable that tracks the allocated size. This potentially improves performance and avoid some side effects, which lead to undefined behavior in some cases. Fixes fuzzer test case id:000051,sig:11,sync:fuzzer3,src:004221.
* cache: fix ownership tracking issues of ASS_FontDr.Smile2016-07-161-0/+1
|
* cache: keep ref_count of all active objects nonzeroDr.Smile2016-06-301-25/+29
|
* 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-15/+17
|
* cache: switch to gradual cache clearingDr.Smile2016-06-301-9/+8
| | | | | | | | | | | 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.
* shaper: drop RTL base direction for RTL font encodingsGrigori Goronzy2016-06-101-8/+4
| | | | | | | | VSFilter uses LTR base direction even if Arabic or Hebrew font encodings are used, so do the same. This resolves some reordering issues. Fixes #224.
* 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>
* ass_shaper: raise shaper info log levelwm42015-09-071-1/+1
| | | | | MSGL_V is usually for far noisier messages, such as those printed per subtitle event.
* Custom font matching and font sourcesGrigori Goronzy2015-07-101-1/+1
| | | | | | | 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.
* shaper: purge outdated commentGrigori Goronzy2015-05-241-2/+2
| | | | | HarfBuzz has been able to disable fallback kerning since commit 038c98f6. Add some more useful docstrings instead.
* More malloc checkingwm42014-11-201-12/+32
| | | | | | | | Don't crash if running out of memory when allocating per-glyph data during shaping. Also some fixes to initialization. The caller of ass_fontconfig.c/match_fullname() actually handles a NULL return value correctly.
* shaper: add FriBidi error handlingGrigori Goronzy2014-05-291-5/+15
| | | | | | It is unlikely, but FriBidi might not process a string correctly, and we should handle that. Tested by making it fail always. This should also fix some compiler warnings.
* shaper: fix nasty sign bug in font functionsGrigori Goronzy2014-03-171-1/+1
| | | | Fixes issue #68.
* Fix limits.h includesGrigori Goronzy2014-02-171-0/+1
| | | | These were missing in several places. Fixes #50.
* shaper: use global features correctlyGrigori Goronzy2014-01-291-5/+5
| | | | | | | start/end of feature tags is unsigned, so use the proper constant to signal to HarfBuzz that these features are global. This allows HarfBuzz to cache shape plans, and that can considerably speed up shaping, especially if many small runs need to be shaped.
* shaper: rewrite and simplify harfbuzz shapingGrigori Goronzy2014-01-291-73/+72
| | | | | | Rewrite the core of the harfbuzz shaping function. Gets rid of the MAX_RUNS limit of runs per line and reuses a single hb_buffer_t, which should be more efficient.
* Combine bitmaps before applying blur and shadow11rcombs2014-01-251-3/+26
|
* Fix missing pointer dereference in 1636a551Oleg Oshmyan2014-01-141-1/+1
|
* shaper: disable ligatures for non-zero \fspOleg Oshmyan2014-01-081-7/+20
|
* shaper: actually correctly handle @font advanceOleg Oshmyan2014-01-071-6/+11
| | | | | | | | | | The code was confusing glyph index and Unicode codepoint. 256df617 attempted a fix but merely moved the wrong code. Fixes Google Code issue #94. Vertical ligatures are possibly still broken, but horizontal ligatures and non-ligatures are correct now.
* Added ass_font_index_magic to fix char indexes in weird encodings11rcombs2013-12-061-3/+3
|
* ass_shaper: changing scale_x/y starts a new glyph runwm42013-09-261-0/+2
| | | | | Since font_size is usually normalized to 256, scale_x/y has to be used for this purpose.
* Fix Hinting againwm42013-09-261-8/+5
| | | | | | | | | | | | Commit 05eb520 missed some duplicated bits in ass_shaper.c. <wm4> oh crap <zgreg> oh crap indeed Instead of duplicating the logic in ass_shaper.c, just change the glyphs before they even get into processing. This way, all code reading the font size etc. is affected. This essentially reverts commit c207000c, because it's not needed anymore.
* Fix fribidi include pathwm42013-07-171-2/+0
| | | | | The old include statement works only by coincidence, and will actually break the build on certain setups.
* Remove unused variableswm42013-06-221-2/+1
|
* shaper: proper script/language handlingGrigori Goronzy2013-03-041-4/+170
| | | | | | | | | | | | | | | | | | | | | Determine script for each character and use this as an additional property for splitting up the text into runs. Characters of Common or Inherited script assume the script of the preceding character. If that is not possible (First character(s) in a run are Common/Inherited, for instance), a backwards scan is done so they can assume the script of the following character. Additionally, determine default language in case no override is set. This simply maps a language to a script, if a language exists that is mostly representative for a given script. Pango's mapping has been adapted. This helps with fonts that don't have OpenType features set up for default script/language pairs. It's also considered to be right approach by most people, and might help with correct OpenType rendering in some other cases. Fixes issue 85.
* shaper: correctly handle @font advanceGrigori Goronzy2013-03-031-3/+6
| | | | | | The code was confusing glyph index and unicode codepoint index. Fixes issue 94.
* shaper: add hack to workaround grid-fittingGrigori Goronzy2012-10-161-6/+8
| | | | | This complements commit 7af780, which didn't correctly apply the hack to the advance/position as calculated by the shaper.
* Revert "shaper: add UCDN support"Grigori Goronzy2012-10-151-13/+0
| | | | | | | | This reverts commit 840ce4c2d9381e340c3239d104933fea85fff3e5. Harfbuzz added UCDN support much quicker than I thought and the latest release 0.9.5 contains UCDN already, so we don't need it in libass anymore.
* shaper: improve skipping of zero-width charactersGrigori Goronzy2012-10-011-13/+25
| | | | | | The list was somewhat incomplete. Add what's important and left, and disable removal if HarfBuzz is used. HarfBuzz removes these characters now by itself. Refactor a little into a separate function.
* shaper: add UCDN supportGrigori Goronzy2012-10-011-0/+13
| | | | | | Add explicit support for UCDN, without relying on any HarfBuzz integration. This finally allows easy usage of HarfBuzz without glib, ICU, or some other big bloated library!
* shaper: allow font encoding -1 for neutral base directionGrigori Goronzy2012-10-011-2/+5
|
* shaper: always use LTR base direction by defaultGrigori Goronzy2012-10-011-4/+2
| | | | | | | | | | Unfortunately, VSFilter always assumes LTR base direction. All existing Arabic subtitles have been designed with that in mind. This causes various issues, for instance punctuation placed at the wrong side of a line. We have no other choice than to use the same braindead always-LTR assumption (except if overridden by the font encoding property).
* shaper: fix control character filteringGrigori Goronzy2012-05-191-1/+2
| | | | | | | | Correct off-by-one error and add 0x200c-0x200f range. This range is compromised of explicit direction and join marks. Fixes issue 54 Fixes issue 55
* harfbuzz: adjust to API changeGrigori Goronzy2011-09-241-1/+1
|
* harfbuzz: adjust to hb_buffer_t API changeGrigori Goronzy2011-08-291-1/+2
|
* harfbuzz: fix vertical advanceGrigori Goronzy2011-08-251-0/+5
| | | | | Make sure to use vertical advance under the right conditions - vertical font selected, requested glyph is non-latin.
* Add compile time switch for HarfBuzz supportGrigori Goronzy2011-08-081-38/+71
| | | | | | | | | | | | | Now that it's possible to switch shapers at runtime, it also becomes a lot easier to disable them at compile time. Add ifdefs and build system changes so that HarfBuzz can be safely disabled. It's autodetected now and enabled if available. This shuffles a bit of code around, but there are no functional changes. Note that FriBidi remains mandatory for the time being, but this shouldn't pose any problems, since it is a small and very portable library without any special dependencies.
* Runtime shaper selectionGrigori Goronzy2011-08-081-5/+29
| | | | | | | Add an API call, ass_set_shaper, and infrastructure to make shapers selectable at runtime. Currently, this allows to switch between two shapers: a SIMPLE shaper that maps to FriBidi and a COMPLEX shaper that maps to HarfBuzz.
* Remove a bunch of debug printf callsGrigori Goronzy2011-08-041-34/+1
| | | | Shaping works well now, they aren't needed anymore.
* Support language hint in the Script Info sectionGrigori Goronzy2011-08-011-0/+13
| | | | | | Parse a hint in the form "Language: xx" with xx being an ISO 639-1 language code, and pass it to HarfBuzz. This can be useful to render scripts with language-specific character variants.
* harfbuzz: cache glyph metricsGrigori Goronzy2011-07-291-4/+221
| | | | | | HarfBuzz' FreeType font functions do not cache anything and call FT_Load_Glyph all the time, which can be slow. Add a cache for metrics and use it with custom font functions.
* Axe misleading comment, reordering works fineGrigori Goronzy2011-07-251-2/+0
|
* Disable reordering of non-spacing marksGrigori Goronzy2011-07-251-1/+1
| | | | | | | | FriBidi's line reordering algorithm reorders non-spacing marks (diacritics, etc.) to come after the base character by default. This doesn't work particularly well with our layout model and leads to wrongly positioned marks in some cases with HarfBuzz and all cases with FriBidi shaping.
* Don't extend face runs as much as possibleGrigori Goronzy2011-07-221-5/+0
| | | | This leads to fewer shaping runs, but has many unwanted side effects.
* Update HarfBuzz' font metricsGrigori Goronzy2011-07-221-0/+16
|
* Remove unused variableGrigori Goronzy2011-07-161-2/+0
|
* shaper: fix run-specific font sizeGrigori Goronzy2011-07-161-1/+2
| | | | | Make sure to set the font size for every run, as needed, to get metrics (advance/offset) for the right size.
* Cache HarfBuzz fontsGrigori Goronzy2011-07-151-3/+36
| | | | | | Add a new opaque data structure to store shaper-specific font data in an ASS_Font. At the moment, this is used for caching HarfBuzz fonts, to reduce allocation and font initialization overhead.
* Use the "font encoding" property as a base direction hintGrigori Goronzy2011-07-151-3/+34
| | | | | | | | | | ASS specifies a "font encoding", both in the styles as well as with the \fe override tag. This font encoding is very Windows-specific and libass doesn't use it for charmap matching or anything like that. However, it can be useful for hinting the base direction of text. Make Hebrew and Arabic encodings switch to RTL base direction, other languages to LTR and use neutral base direction for the autodetect setting.
* Add kerning toggle for HarfBuzz shapingGrigori Goronzy2011-07-131-0/+10
| | | | | Make the "Kerning" track property toggle the OpenTyp