]> granicus.if.org Git - libass/log
libass
4 years agocoretext: replace CT attr reads with freetype lookups master
Rodger Combs [Thu, 11 Oct 2018 07:32:50 +0000 (02:32 -0500)]
coretext: replace CT attr reads with freetype lookups

This makes results much more consistent with other platforms,
particularly around cases where fonts have multiple conflicting names.

4 years agofontselect: add overflow check
Rodger Combs [Sat, 23 Mar 2019 13:30:32 +0000 (08:30 -0500)]
fontselect: add overflow check

4 years agofontselect: expose the freetype-provided family as well
Rodger Combs [Sat, 23 Mar 2019 13:30:16 +0000 (08:30 -0500)]
fontselect: expose the freetype-provided family as well

4 years agofontselect: provide a way to use freetype to get font info
Rodger Combs [Wed, 16 Jan 2019 00:17:57 +0000 (18:17 -0600)]
fontselect: provide a way to use freetype to get font info

4 years agocoretext: use weight steps from macOS SDK
Rodger Combs [Fri, 12 Oct 2018 05:58:04 +0000 (00:58 -0500)]
coretext: use weight steps from macOS SDK

4 years agofontconfig: improve weight mapping
Rodger Combs [Fri, 12 Oct 2018 05:37:47 +0000 (00:37 -0500)]
fontconfig: improve weight mapping

Use FcWeightToOpenType when available; otherwise, use an if/elseif ladder
implementing the inverse of fontconfig's behavior.

4 years agofontselect: load actual weight instead of a guess, when possible
Rodger Combs [Fri, 12 Oct 2018 05:35:18 +0000 (00:35 -0500)]
fontselect: load actual weight instead of a guess, when possible

4 years agofont: don't faux-bold fonts that are already bold enough
Rodger Combs [Fri, 12 Oct 2018 05:33:37 +0000 (00:33 -0500)]
font: don't faux-bold fonts that are already bold enough

And conversely, do faux-bold fonts that are too thin

The offset of 150 matches VSFilter's behavior

4 years agofont: add function to get the actual weight of a font face
Rodger Combs [Fri, 12 Oct 2018 05:22:53 +0000 (00:22 -0500)]
font: add function to get the actual weight of a font face

4 years agocoretext: fix reading weights of some fonts
Rodger Combs [Thu, 11 Oct 2018 07:32:50 +0000 (02:32 -0500)]
coretext: fix reading weights of some fonts

Some fonts have weights that can be expressed more precisely as doubles than
as floats. In these cases, when writing to a float, CFNumberGetValue will set
the value to the closest approximation, but return false (so we'd just clobber
whatever it set with 0). Easy fix: just store to a double instead.

4 years agorenderer: fix incorrect deallocation
Dr.Smile [Sat, 13 Jul 2019 23:27:15 +0000 (02:27 +0300)]
renderer: fix incorrect deallocation

shift_event() can change "bitmap" field of ASS_Image struct
so direct deallocation is no longer possible.
This commit introduces additional field "buffer"
into ASS_ImagePriv for that purpose.

Fixes https://github.com/libass/libass/issues/310.

4 years agoUse FriBiDi 1.x API when available
Khaled Hosny [Sat, 24 Feb 2018 11:50:57 +0000 (13:50 +0200)]
Use FriBiDi 1.x API when available

This allows making use of the updated UBA in Unicode 6.3 and up.

4 years agoUpdate ass_fontselect.h
C.W. Betts [Wed, 25 Sep 2019 22:41:22 +0000 (16:41 -0600)]
Update ass_fontselect.h

Fix documentation misspellings/texts.
As reported by Clang.

4 years agoFix bunch of UB
Dr.Smile [Mon, 20 May 2019 21:37:05 +0000 (00:37 +0300)]
Fix bunch of UB

Found by Coverity Scan and -fsanitize=undefined

4 years agorenderer: synchronize glyph motion to help composite cache
Dr.Smile [Sun, 2 Dec 2018 20:26:08 +0000 (23:26 +0300)]
renderer: synchronize glyph motion to help composite cache

Slow movement of one glyph looks like periodic jumps by quantization step.
In case of multiple glyphs at different subpixel shifts
jumps of individual glyphs occur at different frames.
That leads to performance penalty due to composite image
regeneration at every such jump.

This commit aligns glyphs in such a way that all jumps coincide
at the same frames, greatly improving performance of \move commands.
That optimization also helps in case of fast motion.

4 years agooutline: eliminate use of VLA
Dr.Smile [Sun, 2 Dec 2018 20:08:47 +0000 (23:08 +0300)]
outline: eliminate use of VLA

Fixes https://github.com/libass/libass/pull/321.

4 years agooutline: rearrange allocations
Dr.Smile [Sun, 19 May 2019 22:09:08 +0000 (01:09 +0300)]
outline: rearrange allocations

4 years agoMove outline transformations to ass_outline.c
Dr.Smile [Sun, 22 Oct 2017 04:21:34 +0000 (07:21 +0300)]
Move outline transformations to ass_outline.c

This also potentially improves performance by copying
and transforming in a single operation rather than
copying first and then transforming the result.

Also transformation function is specialized for case
where expensive perspective division is not necessary.

4 years agorenderer: quantize blur radius and shadow offset
Dr.Smile [Sun, 19 May 2019 22:07:36 +0000 (01:07 +0300)]
renderer: quantize blur radius and shadow offset

4 years agorenderer: eliminate use of bitmap pointers as mode flags
Dr.Smile [Sat, 8 Dec 2018 18:00:42 +0000 (21:00 +0300)]
renderer: eliminate use of bitmap pointers as mode flags

Render logic should depend only on input subs
and not on some internal state such as bitmap pointers.
That can prevent incorrect behavior in case of allocation failure.

4 years agorenderer: correctly handle case of small but nonzero \bord
Dr.Smile [Sun, 19 May 2019 22:04:22 +0000 (01:04 +0300)]
renderer: correctly handle case of small but nonzero \bord

Fixes https://github.com/libass/libass/pull/309.

4 years agorenderer: rearrange render flags
Dr.Smile [Sat, 8 Dec 2018 17:41:22 +0000 (20:41 +0300)]
renderer: rearrange render flags

Compatibility flag FILTER_DRAW_SHADOW has removed completely.

4 years agobitmap: make ass_synth_blur() work on single bitmap
Dr.Smile [Sat, 8 Dec 2018 18:03:37 +0000 (21:03 +0300)]
bitmap: make ass_synth_blur() work on single bitmap

Now ass_synth_blur() blurs one bitmap only.
Higher level decisions (to blur or not to blur)
have moved outside of that function.

4 years agobitmap: remove level of indirection in bitmap functions
Dr.Smile [Thu, 3 May 2018 00:09:52 +0000 (03:09 +0300)]
bitmap: remove level of indirection in bitmap functions

This allows to use Bitmap struct directly as cache value
and to remove bunch of unnecessary allocations.

4 years agobitmap: use types of fixed size in Bitmap struct
Dr.Smile [Wed, 2 May 2018 22:04:11 +0000 (01:04 +0300)]
bitmap: use types of fixed size in Bitmap struct

4 years agorenderer: improve usability of rectangle_combine()
Dr.Smile [Sun, 22 Oct 2017 04:42:33 +0000 (07:42 +0300)]
renderer: improve usability of rectangle_combine()

4 years agocache: remove level of indirection in glyph metrics value
Dr.Smile [Fri, 29 Sep 2017 00:49:18 +0000 (03:49 +0300)]
cache: remove level of indirection in glyph metrics value

4 years agorenderer: improve handling of subpixel shift
Dr.Smile [Sun, 19 May 2019 22:01:34 +0000 (01:01 +0300)]
renderer: improve handling of subpixel shift

Integral pixel shift is extracted in quantization function now,
taking account of full glyph transformation and not only translation
part of it. It makes program logic more straight and ensures that
subpixel shift from cache key never exceed full pixel.

4 years agorenderer: implement correct error estimation for stroking
Dr.Smile [Sun, 19 May 2019 21:58:13 +0000 (00:58 +0300)]
renderer: implement correct error estimation for stroking

Accuracy of border outline calculation should depend on subsequent
transformation.

4 years agorenderer: move outline stroking immediately before rasterization
Dr.Smile [Sun, 19 May 2019 21:50:49 +0000 (00:50 +0300)]
renderer: move outline stroking immediately before rasterization

4 years agoConsolidate and quantize all transformations
Dr.Smile [Sun, 19 May 2019 21:48:26 +0000 (00:48 +0300)]
Consolidate and quantize all transformations

This commit defers all outline transformations until rasterization stage.
Combined transformation is then quantized and used as bitmap key.
That should improve performance of slow animations.

Also caching of initial and stroked outlines and bitmaps is now separate
in preparation to proper error estimation for stroker stage.

Note that Z-clipping for perspective transformations is now done
differently compared to VSFilter. That clipping is mostly safety feature
to protect from overflows and divisions by zero and is almost never
triggered in real-world subtitles.

4 years agorenderer: fix potential memory leak
Dr.Smile [Sun, 2 Dec 2018 20:37:12 +0000 (23:37 +0300)]
renderer: fix potential memory leak

4 years agofont: extract transformation from ass_font_get_glyph()
Dr.Smile [Sun, 22 Oct 2017 02:58:24 +0000 (05:58 +0300)]
font: extract transformation from ass_font_get_glyph()

4 years agodrawing: extract transformation from parsing
Dr.Smile [Sun, 2 Dec 2018 19:43:52 +0000 (22:43 +0300)]
drawing: extract transformation from parsing

4 years agocache: cleanup
Dr.Smile [Fri, 20 Oct 2017 06:17:10 +0000 (09:17 +0300)]
cache: cleanup

4 years agocache: construct cache values only from corresponding keys
Dr.Smile [Sun, 19 May 2019 17:24:29 +0000 (20:24 +0300)]
cache: construct cache values only from corresponding keys

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.

4 years agorenderer: rewrite measure_text() to correctly account for leading newlines
Dr.Smile [Sun, 2 Dec 2018 19:20:25 +0000 (22:20 +0300)]
renderer: rewrite measure_text() to correctly account for leading newlines

4 years agofont: remove dependency on symbol codes
Dr.Smile [Sun, 19 May 2019 17:21:19 +0000 (20:21 +0300)]
font: remove dependency on symbol codes

Leading newlines are now rendered, but still incorrectly:
at full height rather than at half-height as required.

4 years agorenderer: use C99 features in some functions
Dr.Smile [Fri, 20 Oct 2017 01:58:44 +0000 (04:58 +0300)]
renderer: use C99 features in some functions

Note that return value is reversed in parse_events(),
ass_render_event() and ass_start_frame() functions.

4 years agodrawing: separate drawing text reading from outline construction
Dr.Smile [Sun, 2 Dec 2018 19:34:45 +0000 (22:34 +0300)]
drawing: separate drawing text reading from outline construction

Purpose of this commit is to simplify logic behind drawing handling.

4 years agoEliminate advance.y from drawings and glyphs
Dr.Smile [Thu, 8 Mar 2018 04:57:31 +0000 (07:57 +0300)]
Eliminate advance.y from drawings and glyphs

Drawings always have advance.y = 0 and
FreeType guarantees that for horizontal writing.

4 years agodrawing: remove unnecessary fields from ASS_Drawing struct
Dr.Smile [Tue, 19 Sep 2017 21:55:58 +0000 (00:55 +0300)]
drawing: remove unnecessary fields from ASS_Drawing struct

4 years agofont: remove unused field
Dr.Smile [Tue, 19 Sep 2017 17:36:50 +0000 (20:36 +0300)]
font: remove unused field

5 years agostroker: correctly handle case of many small segments
Dr.Smile [Thu, 10 Jan 2019 21:26:45 +0000 (00:26 +0300)]
stroker: correctly handle case of many small segments

Fixes: https://github.com/libass/libass/issues/326.
6 years agorender: simplify detection of hard overrides
Dr.Smile [Sun, 21 Jan 2018 17:30:35 +0000 (20:30 +0300)]
render: simplify detection of hard overrides

Previously each \r triggered full rescan of event string.
After this commit such scanning is done once in init_render_context().

Additionally some lines have moved around to correctly account for
state.evt_type (calculated in apply_transition_effects) and
state.explicit (used in reset_render_context).
That should fix cases with incorrectly applied style overrides
for subs with banner scrolling effect before the first \r.

6 years agoparse_tags: handle argumentless \t inside \t() like VSFilter
Oleg Oshmyan [Thu, 4 Jan 2018 01:37:28 +0000 (03:37 +0200)]
parse_tags: handle argumentless \t inside \t() like VSFilter

\t with no parantheses inside \t() resets the animation parameters
of the \t() for subsequent tags, so they are animated as if the \t()
was the single-argument version regardless of the actual number
of arguments the \t() has.

Equivalently, you could say parentheses are implied for \t inside \t().

For example, \t(20,60,\frx0\t\fry0\frz0) animates \frx from 20 to 60 ms
and animates \fry and \frz for the whole duration of the line,
just like \t(20,60,\frx0)\t(\fry0\frz0) or \t(20,60,\frx0\t(\fry0\frz0)).

Technically, VSFilter simply resets the animation parameters for any \t
it encounters but parses the embedded tags only if the \t has the right
number of arguments. However, top-level animation parameters don't matter
because top-level tags are not animated, while any nested \t that has
parentheses terminates the containing \t because they share the closing
parenthesis, so the fact that a nested \t with empty parentheses or with
at least four arguments changes the animation parameters also doesn't
matter because the containing \t immediately ends and the changed
parameters have nothing to apply to. Thus the only situation where
this has a visible effect is a nested \t without parentheses.

Closes https://github.com/libass/libass/pull/296.

6 years agoparse_tags: don't recurse for nested \t()
Oleg Oshmyan [Thu, 4 Jan 2018 00:42:09 +0000 (02:42 +0200)]
parse_tags: don't recurse for nested \t()

This fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4892
(stack overflow on deeply nested \t()).

This is possible because parentheses do not nest and the first ')'
terminates the whole tag. Thus something like \t(\t(\t(\t(\t() can be
read in a simple loop with no recursion required. Recursion is also
not required if the ')' is missing entirely and the outermost \t(...
never ends.

See https://github.com/libass/libass/pull/296 for more backstory.

6 years agoMove parse_tag loop into parse_tag itself, now called parse_tags
Oleg Oshmyan [Thu, 4 Jan 2018 00:37:02 +0000 (02:37 +0200)]
Move parse_tag loop into parse_tag itself, now called parse_tags

This commit is mostly transparent to `git blame -w`.

6 years agoRelease 0.14.0 coverity_scan 0.14.0
Oleg Oshmyan [Tue, 31 Oct 2017 12:07:26 +0000 (14:07 +0200)]
Release 0.14.0

6 years agoconfigure: remove obsolete --disable-rasterizer option
Oleg Oshmyan [Tue, 31 Oct 2017 12:53:55 +0000 (14:53 +0200)]
configure: remove obsolete --disable-rasterizer option

The internal rasterizer cannot be disabled (and the option has
no effect) since commit ef6cc020bc00118a5b142b37fe401327a029a1fc.

6 years agoSupport Core Text on earlier versions of Mac OS X
Oleg Oshmyan [Thu, 26 Oct 2017 19:38:49 +0000 (22:38 +0300)]
Support Core Text on earlier versions of Mac OS X

Loosely based on behdad/harfbuzz@b96af03c20e46105982b3608b608614403540661.

Prefer to link against ApplicationServices to maximize the
portability of binaries built on newer versions of macOS.

The symbol kCTFontURLAttribute, which is checked in this commit, was
introduced in Mac OS X 10.6, the latest of any Core Text symbols that
we use. It is essential to our Core Text font provider, so this is the
earliest version of Mac OS X where we can support this font provider.

The TARGET_OS_IPHONE conditional that this commit adds is necessary to
continue supporting iOS in addition to supporting old Mac OS X. On iOS,
CoreText.h *must* be included to use Core Text, whereas on old Mac OS X,
CoreText.h is not directly accessible and ApplicationServices.h must be
used. On modern macOS, either header works. This conditional is also
used in HarfBuzz.

6 years agoDon't link Core Text font provider to unneeded CoreGraphics framework
Oleg Oshmyan [Thu, 26 Oct 2017 19:34:03 +0000 (22:34 +0300)]
Don't link Core Text font provider to unneeded CoreGraphics framework

6 years agocoretext: don't use a variable-length array
Oleg Oshmyan [Tue, 13 Oct 2015 23:05:54 +0000 (02:05 +0300)]
coretext: don't use a variable-length array

This fixes compilation with GCC, which complains that a
variable-length array declaration must not have an initializer.

6 years agoSilence missing-field-initializers warning
Rodger Combs [Wed, 6 Sep 2017 12:28:02 +0000 (07:28 -0500)]
Silence missing-field-initializers warning

Clang gives this warning for the universal initializer `={0}`:
https://bugs.llvm.org/show_bug.cgi?id=21689

Signed-off-by: Oleg Oshmyan <chortos@inbox.lv>
6 years agofontselect: fix include guard macro name
Oleg Oshmyan [Thu, 26 Oct 2017 21:45:47 +0000 (00:45 +0300)]
fontselect: fix include guard macro name

6 years agoCompletely exclude ass_fontconfig.c from build when it is disabled
Oleg Oshmyan [Thu, 26 Oct 2017 21:41:36 +0000 (00:41 +0300)]
Completely exclude ass_fontconfig.c from build when it is disabled

6 years agoass_set_fonts: empty cache as well
Rodger Combs [Wed, 6 Sep 2017 02:15:40 +0000 (21:15 -0500)]
ass_set_fonts: empty cache as well

6 years agorasterizer: fix warning
Dr.Smile [Sun, 17 Sep 2017 21:56:00 +0000 (00:56 +0300)]
rasterizer: fix warning

While int8_t work in practice, uint8_t is more correct type here.

6 years agoConsolidate bounding box operations
Dr.Smile [Sun, 17 Sep 2017 00:39:11 +0000 (03:39 +0300)]
Consolidate bounding box operations

6 years agoRename DBBox to ASS_DRect for uniformity
Dr.Smile [Sun, 17 Sep 2017 00:47:45 +0000 (03:47 +0300)]
Rename DBBox to ASS_DRect for uniformity

6 years agoReorganize outline transformation functions
Dr.Smile [Sat, 5 Aug 2017 01:55:03 +0000 (04:55 +0300)]
Reorganize outline transformation functions

6 years agoSwitch to more efficient representation of outlines
Dr.Smile [Sun, 17 Sep 2017 00:36:29 +0000 (03:36 +0300)]
Switch to more efficient representation of outlines

6 years agoSwitch to native coordinate system for outlines
Dr.Smile [Wed, 2 Aug 2017 01:34:28 +0000 (04:34 +0300)]
Switch to native coordinate system for outlines

6 years agoReplace FreeType types with libass native types
Dr.Smile [Sun, 17 Sep 2017 00:00:34 +0000 (03:00 +0300)]
Replace FreeType types with libass native types

FT_Vector and FT_BBox types are based on FT_Pos, which is alias of long.
FreeType treats it as 32-bit integer, but on some platforms long can be
64-bit. That leads to wasted memory and suboptimal performance.

6 years agostroker: fix wording of algorithm description
Dr.Smile [Sat, 16 Sep 2017 23:57:43 +0000 (02:57 +0300)]
stroker: fix wording of algorithm description

6 years agox86: fix out-of-root builds after 8bddaa2a7
Ricardo Constantino [Tue, 12 Sep 2017 09:04:45 +0000 (10:04 +0100)]
x86: fix out-of-root builds after 8bddaa2a7

nasm always uses %include paths starting from the directory from where
it's started.

6 years agobuild: switch from yasm to nasm
Rodger Combs [Wed, 21 Jun 2017 04:16:53 +0000 (23:16 -0500)]
build: switch from yasm to nasm

6 years agoMakefile: silence warning when x86/utils has no symbols
Rodger Combs [Wed, 21 Jun 2017 04:16:22 +0000 (23:16 -0500)]
Makefile: silence warning when x86/utils has no symbols

6 years agox86: update x86inc.asm
Rodger Combs [Wed, 21 Jun 2017 04:15:31 +0000 (23:15 -0500)]
x86: update x86inc.asm

6 years agox86: asm adjustments for nasm compatibility
Rodger Combs [Wed, 21 Jun 2017 04:14:52 +0000 (23:14 -0500)]
x86: asm adjustments for nasm compatibility

6 years agoconfigure: cleanup in preparation for x86inc update and switch to nasm
Rodger Combs [Wed, 21 Jun 2017 04:10:34 +0000 (23:10 -0500)]
configure: cleanup in preparation for x86inc update and switch to nasm

6 years agorenderer: fix border existence check
Dr.Smile [Tue, 1 Aug 2017 18:35:59 +0000 (21:35 +0300)]
renderer: fix border existence check

Found by coverity scan.

6 years agostroker: add algorithm description
Dr.Smile [Tue, 1 Aug 2017 00:50:50 +0000 (03:50 +0300)]
stroker: add algorithm description

6 years agostroker: skip degenerate 2-point contours from broken fonts
Dr.Smile [Sat, 8 Apr 2017 18:15:48 +0000 (21:15 +0300)]
stroker: skip degenerate 2-point contours from broken fonts

6 years agocosmetic: fix codestyle
Dr.Smile [Sat, 8 Apr 2017 17:57:42 +0000 (20:57 +0300)]
cosmetic: fix codestyle

6 years agorenderer: fix handling of empty outlines
Dr.Smile [Sat, 8 Apr 2017 17:55:41 +0000 (20:55 +0300)]
renderer: fix handling of empty outlines

6 years agorenderer: switch to using two border outlines instead of one
Dr.Smile [Mon, 31 Jul 2017 03:27:09 +0000 (06:27 +0300)]
renderer: switch to using two border outlines instead of one

6 years agorenderer: remove legacy FreeType rasterizer
Dr.Smile [Thu, 13 Apr 2017 19:53:40 +0000 (22:53 +0300)]
renderer: remove legacy FreeType rasterizer

6 years agostroker: implement fast two-outline stroker
Dr.Smile [Mon, 31 Jul 2017 02:33:00 +0000 (05:33 +0300)]
stroker: implement fast two-outline stroker

6 years agorasterizer: implement simultaneous rasterization of two outlines
Dr.Smile [Mon, 31 Jul 2017 02:30:21 +0000 (05:30 +0300)]
rasterizer: implement simultaneous rasterization of two outlines

6 years agorasterizer: refactoring
Dr.Smile [Mon, 31 Jul 2017 02:33:59 +0000 (05:33 +0300)]
rasterizer: refactoring

6 years agocosmetic: extract most of the outline-related functions into separate file
Dr.Smile [Mon, 31 Jul 2017 02:15:13 +0000 (05:15 +0300)]
cosmetic: extract most of the outline-related functions into separate file

6 years agoRelease 0.13.7 0.13.7
Grigori Goronzy [Sat, 3 Jun 2017 17:07:46 +0000 (19:07 +0200)]
Release 0.13.7

6 years agoAllow using shadow offset to adjust size of text background
Ricardo Constantino [Wed, 26 Apr 2017 22:11:47 +0000 (23:11 +0100)]
Allow using shadow offset to adjust size of text background

Text background refers to the libass-only BorderStyle 4, which is
similar to 3, but isn't affected by outline/border size and doesn't
render shadow, so shadow offset can be used.

You can override the horizontal and vertical box size separately
with override tags, just like you can override the color with
shadow color.

Closes #270

6 years agoFix function prototype
Grigori Goronzy [Thu, 1 Jun 2017 12:04:03 +0000 (14:04 +0200)]
Fix function prototype

Not a serious issue: arguments were named/ordered incorrectly.
No functional change.

6 years agofontselect: cleanup lazy font index evaluation
Grigori Goronzy [Thu, 1 Jun 2017 12:01:15 +0000 (14:01 +0200)]
fontselect: cleanup lazy font index evaluation

Fixes a possible NULL pointer dereference, reported by Coverity.

6 years agodirectwrite: fix font collections dw-collections
Grigori Goronzy [Thu, 1 Jun 2017 09:25:09 +0000 (11:25 +0200)]
directwrite: fix font collections

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.

6 years agoFix PlayResX/Y calculations
Grigori Goronzy [Wed, 10 May 2017 11:39:57 +0000 (13:39 +0200)]
Fix PlayResX/Y calculations

Avoid that PlayResY is set to 0 when only PlayResX is specified and
set to 1. Setting PlayResY to 0 results in divide-by-zero errors.
Also fix PlayResX calculations in case only PlayResY is specified,
for completeness.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=1474.

7 years agoChangelog: update
wm4 [Thu, 27 Apr 2017 12:49:25 +0000 (14:49 +0200)]
Changelog: update

7 years agoRemove arbitrary bitmap size limit large-bitmaps
Rodger Combs [Sun, 12 Feb 2017 01:19:31 +0000 (19:19 -0600)]
Remove arbitrary bitmap size limit

We're not aware of any specific reason for this number to be used,
and actual potentially-dangerous cases should be handled by the
other limits.

Fixes #260

7 years agoDon't limit size of "uuencoded" font lines
Oleg Oshmyan [Sat, 4 Feb 2017 14:09:36 +0000 (16:09 +0200)]
Don't limit size of "uuencoded" font lines

7 years agoFix decode_font when size % 4 != 0 or data contains illegal bytes
Oleg Oshmyan [Sat, 4 Feb 2017 02:02:50 +0000 (04:02 +0200)]
Fix decode_font when size % 4 != 0 or data contains illegal bytes

When given a byte c, decode_chars expects that 0 <= c - 33 <= 63,
i. e. that only the six lowest bits of c - 33 are possibly set.
With this assumption, it shifts and adds together multiple c - 33 values.

When c > 96, c - 33 has high nonzero bits, which interferes with other
shifted terms. c < 33 is even worse: c - 33 is negative (if unsigned char
fits in int), and left-shifting negative numbers has undefined behavior.
Even before the shift, on common platforms with a two's complement
representation of negative integers (or if unsigned char does not fit in
int and is promoted to unsigned int), c - 33 has high nonzero bits, which
again interfere with other shifted terms.

To make matters worse, even perfectly valid encoded data is affected when
size % 4 != 0, as decode_font calls decode_chars with '\0', which leads
decode_chars to shift and add -33, causing undefined behavior and/or
incorrect output.

Take our cue from VSFilter and bit-mask c - 33 to keep only the six
relevant bits. To ensure that we get the same bits as VSFilter when
c < 33 and to avoid the undefined behavior of left-shifting negative
numbers, convert the number to unsigned before masking and shifting.

While we are at it, rewrite decode_chars entirely
to get rid of any GPL code from mkvtoolnix.

Related mkvtoolnix bug: https://github.com/mbunkus/mkvtoolnix/issues/1003

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=516.

Also allocate exactly the right amount of memory for the font,
because why not.

7 years agoass_lazy_track_init: handle negative PlayResX/PlayResY
Oleg Oshmyan [Fri, 3 Feb 2017 23:53:43 +0000 (01:53 +0200)]
ass_lazy_track_init: handle negative PlayResX/PlayResY

Like VSFilter, treat negative values the same as missing values.

7 years agostring2timecode: don't truncate milliseconds to int
Oleg Oshmyan [Fri, 3 Feb 2017 19:40:19 +0000 (21:40 +0200)]
string2timecode: don't truncate milliseconds to int

Commit 8c8741fe2000d4b4d89a53f894363a42288cec3e attempted to fix this
expression and make it use the full range of long long, but it missed
the millisecond term.

This fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=522.
The entire timestamp can still overflow long long though.

7 years agoReuse numpad2align in parse_tag
Oleg Oshmyan [Fri, 3 Feb 2017 19:36:23 +0000 (21:36 +0200)]
Reuse numpad2align in parse_tag

7 years agoFix parsing of unusual Alignment values in ASS style definitions
Oleg Oshmyan [Fri, 3 Feb 2017 19:34:13 +0000 (21:34 +0200)]
Fix parsing of unusual Alignment values in ASS style definitions

Handle large and negative values except INT32_MIN like VSFilter.
This avoids both overflow and inconsistent internal state.

This fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=523.

VSFilter handles INT32_MIN like a mix of \an1, \an2 and \an3:

  * Vertical alignment is bottom.
  * Lines within the event are center-aligned.
  * Without \pos or \move, the center of the event is aligned
    with the right edge of the screen minus MarginR.
  * With \pos or \move, the left edge of the event is aligned
    with the position point.
  * Without \org, the rotation origin is aligned
    with the horizontal center of the event.
  * (With \org, the rotation origin is as specified.)

If we wanted to emulate this in libass, the cleanest way would be to
introduce a new horizontal alignment constant for this purpose that
would be used only for ASS style definitions with Alignment INT32_MIN.
This commit makes no attempt to do this and instead arbitrarily picks
\an2 for style definitions with Alignment -INT_MAX-1, which equals
INT32_MIN if int is int32_t. The fact that int is platform-dependent
is one of the reasons for this. We could change Alignment to be int32_t
instead of int for perfect VSFilter compatibility, but the same applies
to many other fields that currently use platform-dependent types.

7 years agoDon't treat :;<=>? as hexadecimal digits in color headers
Oleg Oshmyan [Fri, 3 Feb 2017 13:45:55 +0000 (15:45 +0200)]
Don't treat :;<=>? as hexadecimal digits in color headers

Oops.

7 years agoExplicitly handle FcPatternGetString(FC_POSTSCRIPT_NAME) mismatch
Oleg Oshmyan [Sat, 11 Feb 2017 12:02:32 +0000 (14:02 +0200)]
Explicitly handle FcPatternGetString(FC_POSTSCRIPT_NAME) mismatch

This does not affect functionality in any way,
but it hopefully makes the logic easier to follow.

Resolves CID 175691.

7 years agoTravis CI: remove HarfBuzz and re-remove Fontconfig from OS X builds
Oleg Oshmyan [Tue, 7 Feb 2017 12:14:07 +0000 (14:14 +0200)]
Travis CI: remove HarfBuzz and re-remove Fontconfig from OS X builds

Installing HarfBuzz through Homebrew seems to be consistently slow
whether we use the bottles and disable the Fontconfig cache or build
it from source and drop Fontconfig and other dependencies entirely.

To speed up OS X builds, disable both HarfBuzz and Fontconfig.
We build with HarfBuzz and Fontconfig on Linux, and we should
not have any platform-dependent code that depends on them,
so this should not reduce our code coverage.

7 years agoTravis CI: re-enable Fontconfig on OS X but force no cache built
Oleg Oshmyan [Mon, 6 Feb 2017 16:46:22 +0000 (18:46 +0200)]
Travis CI: re-enable Fontconfig on OS X but force no cache built

Building HarfBuzz from source works to avoid Fontconfig, but it is still
fairly slow. To further speed up the build, try to use only the prebuilt
bottle packages (which inevitably brings in Fontconfig as a dependency)
but hack the Fontconfig formula to avoid building the font cache.

Adding Fontconfig is not the goal of this commit, as we already have it
on Linux and our Fontconfig-related code "should" work equally well on
other platforms. But since we can now afford it, explicitly ask Homebrew
to install Fontconfig even if the dependency that brings it in disappears
from Homebrew in the future, and enjoy the improved code coverage.