Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle negative Encoding values [XySubFilter] #27

Open
wants to merge 1 commit into
base: xy_sub_filter_rc5
Choose a base branch
from

Conversation

TheOneric
Copy link
Collaborator

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)

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)
@TheOneric TheOneric changed the title Gracefully handle negative Encoding values [xy-SF] Gracefully handle negative Encoding values [XySubFilter] Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant