Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gracefully handle negative Encoding values
Back in 2012 libass added a custom Encoding=-1 extension to enable automatic BiDi base direction instead of the usual LTR default. The assumption/hope presumably was that since all valid font encodings are positive VSFilter would just gracefully ignore them. However, this is unfortuantely not the case. When passed to GDI the charSet is cast to a byte and will wrap around to a valid value, severely restricting which fonts can be used. Searching through a large pile of subtitles the only hits for negative values in the Encoding field were from generally corrupted files. It thus appears so far fortunately nobody used the extension in released fiels (only transient conversion from other formats during playback) and also nobody is relying on the wraparound in VSFilter. To minimise future problems treat all negative Encodings as the default charset. This matches how libass does fontselection for -1 albeit it doesn't reproduce the BiDi base direction. It also conveniently carves out the [-2, INT_MIN] range for potential future extensions common to VSFilters and libass, e.g. Encoding=-2 for a RTL base direction (which should be easier to implement in VSFilter than auto base direction)
- Loading branch information