Grigori Goronzy [Wed, 29 Jan 2014 04:23:55 +0000 (05:23 +0100)]
shaper: use global features correctly
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.
Grigori Goronzy [Sun, 26 Jan 2014 02:30:45 +0000 (03:30 +0100)]
shaper: rewrite and simplify harfbuzz shaping
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.
wm4 [Mon, 20 Jan 2014 23:32:28 +0000 (00:32 +0100)]
Remove some ass_msg() calls
These aren't very useful for debugging due to the high volume of the log
output in problem cases. In fact, all they do is making the code slower
(the message callback can easily appear in the profiler output, even if
the callback doesn't actually print the messages).
Oleg Oshmyan [Tue, 7 Jan 2014 21:41:43 +0000 (23:41 +0200)]
Don't try to remove end-of-line \fsp
VSFilter does not do this.
The code being removed was already buggy: i > 0 should
have been "got any non-skipped glyphs since last_break?",
and hspacing should have been taken from glyphs[i-1].
Oleg Oshmyan [Tue, 7 Jan 2014 13:32:05 +0000 (15:32 +0200)]
Fix \pbo
b61d260b attempted to add support for \p scaling to \pbo.
However, while it fixed the exact sample originally reported,
it broke \pbo with other \p values, including \p1, by confusing
the direction of scaling and the units in which \pbo is measured.
In addition, the descenders assigned to drawings have always
had a wrong sign, causing lines that contain drawings with \pbo
to be shifted in the wrong direction: negative \pbo raised bottom-
aligned lines, while positive \pbo lowered top-aligned lines.
All errors and fixes have been confirmed with VSFilter.
Thomas Goyne [Wed, 11 Dec 2013 00:21:53 +0000 (16:21 -0800)]
Fix compilation with VC++ 2013
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.
wm4 [Mon, 7 Oct 2013 11:59:08 +0000 (13:59 +0200)]
Don't rely on events being sorted in ass_step_sub()
ass_step_sub() assumed that the subtitle event list was sorted by event
start time, but that is not guaranteed. Making the list sorted is not
an option. (At least for now - too many issues are in the way to get
such a change being done.) Fix this function so that it works with an
unsorted event list.
Semantics regarding corner cases might be slightly different, such as
what happens if the now parameter coincides with event start/end, or
behavior with overlapping subtitles.
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.
This was broken since commit f780146. For reasons why, read the commit
message of that commit. To make it short, we set the font size to
something large and constant (256), and scale the font outlines returned
by freetype to the size we need in order to get smooth animation and
accurate positioning.
Of course, this obviously breaks hinting. Fix hinting by not using the
hack mentioned above if hinting enabled.
To mitigate the issues caused by freetype grid fitting and extremely
bad ASS scripts (such as setting font size to very small values and
scaling them up with \fscx/y), we still adjust the font size such that
the font is never scaled in Y direction (only in X direction, because
the \fscx/y tags can change aspect ratio).
Grigori Goronzy [Fri, 5 Jul 2013 23:14:39 +0000 (01:14 +0200)]
Fix OS/2 usWinDescent/usWinAscent for quirky fonts
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.
wm4 [Sat, 22 Jun 2013 17:36:42 +0000 (19:36 +0200)]
Don't mutate input buffer for ass_read_memory()
Fixes google code issue #88.
process_text() garbles the memory as the text is parsed.
This also fixes that the user provided buffer implicitly had to
be null terminated. This wasn't obvious, because the caller
passes in the buffer length. libass ignored the buffer length
(unless a codepage was provided and iconv was enabled), and
happily read past the end of the buffer.
It would be much nicer if the parsing code would be fixed,
instead of just copying the input buffer. Maybe one day.
wm4 [Sat, 22 Jun 2013 17:22:53 +0000 (19:22 +0200)]
Allow different ASS_Library for ASS_Track and ASS_Renderer
Remove the explicit check whether the ASS_Track and ASS_Renderer were
created from the same ASS_Library object. Logging will not be entirely
consistent (some log messages go to the ASS_Track library when
rendering), but otherwise it works.
ASS_Library also contains embedded fonts added with ass_add_font().
It looks like the renderer will use the fonts from the ASS_Renderer
library object.
Oleg Oshmyan [Sat, 15 Jun 2013 21:24:45 +0000 (22:24 +0100)]
Parse style names like VSFilter does
Trim '*' from the start of style name fields of Style
and Dialogue lines and normalize the case of "Default"
in the style name field of Dialogue lines.
wm4 [Tue, 18 Jun 2013 00:14:14 +0000 (02:14 +0200)]
Fix blur scaling
Commit 0e1702ad7a6a827d "Add ass_set_storage_size and fix related scaling issues"
attempted to fix blur scaling. This breaks blur scaling for players
which don't call ass_set_storage_size().
This commit reverts the default behavior to the old behavior. The
behavior when ass_set_storage_size() is called should be unchanged.
wm4 [Mon, 17 Jun 2013 21:52:49 +0000 (23:52 +0200)]
Improve font mismatch message
Example for an old message:
[ass] fontconfig: Selected font is not the requested one: 'DejaVu Sans' != 'Wingdings'
it was hard to tell which was the selected and the requested font.
Also, it's not really clear what's the problem at all. Why would it
select a different font? Obviously, the issue is that it can't find
the font in the first place.
Now it prints:
[ass] fontconfig: cannot find glyph U+006C in font 'Wingdings', falling back to 'DejaVu Sans'
Or if the code parameter for select_font() is 0:
[ass] fontconfig: cannot find font 'Wingdings', falling back to 'DejaVu Sans'
I'm not sure if this message is really accurate in all cases. It's
possible that there are more reasons for failure. But all things
considered, this should be easier to understand.
Uoti Urpala [Mon, 6 May 2013 14:35:17 +0000 (17:35 +0300)]
fontconfig: remove default "lang" setting from patterns
Fontconfig defaults set the "lang" value in patterns, and it then
prefers fonts which are listed as supporting this language. The
default value may not match actual script language, and even a setting
of "en" for English subtitle can cause problems. Remove the "lang"
setting from patterns used to find fonts.
A file had a normal and an oblique version of the same font attached,
with different character set coverage: the normal version lacked some
non-ascii characters that fontconfig includes in its list of
characters required for English support. As a result, the oblique
version was picked for what was supposed to be normal text.
This fixes: {\clip(1,1,20,20)\clip\alpha&H1E&\c&HC7E5C0&}X
libass tries to interpret the second \clip, which has no arguments.
Since the parsing code doesn't require a starting '(', the parser will
skip over the other tags (treating them as junk) and interpret the
numbers that happen to be in the rest of the string. The result is a
bogus drawing command, which happens to rasterize an extremely wide
glyph, which takes several seconds to finish.
Make the '(' required. Neither the aegisub manual nor the vsfilter
source code have any indication that \clip without starting '(' is
allowed, so this should not break anything.
wm4 [Fri, 22 Mar 2013 09:04:57 +0000 (10:04 +0100)]
Ignore junk in nested \t tags
Normally, junk between tags is ignored. But unlike vsfilter, libass
doesn't do that inside \t tags. So the following fails and will never
actually switch the color: {\t(1000,1000,(\c&HFF0000&))} (The '(' and
')' are junk, and are not covered by any ASS documentation.)
Instead expecting that the last parameter to \t (the parameter that
takes nested tags) starts with '\', turn it around and assume that the
first parameter that's not a number is the last parameter. (This
parsing is kind of awkward because we don't do any lookahead.)
Likewise, let the nested tag parsing terminate on ')' instead of
checking whether a tag is started with '\'. This allows skipping
junk in the middle of the nested tag, without terminating too early.
(Check '}' and '\0' in case the tag is not properly terminated.)
ass_set_aspect_ratio() is confusing, because it takes a DAR and SAR
value, while libass just needs a single pixel aspect ratio. Introduce
ass_set_pixel_aspect(), which sets the pixel aspect ratio directly.
ass_set_aspect_ratio() is considered deprecated. There's no reason to
remove it, but hopefully directing users to ass_set_pixel_aspect() will
make for a simpler API.
Improve the doxygen and document what ass_set_margins() actually does.
wm4 [Mon, 18 Mar 2013 23:15:17 +0000 (00:15 +0100)]
Don't overwrite user-defined aspect ratio settings
ass_set_storage_size() overwrote the user-defined aspect ratio set with
ass_set_aspect_ratio(). Change it so that if ass_set_aspect_ratio() is
used, the ass_set_storage_size() parameters are not used for any aspect
ratio calculations. (The storage size is still used for calculating the
blur scale.) This simplifies the code as well, because the aspect ratio
is now centrally calculated in ass_start_frame().
Update the doxygen. Make it clear that ass_set_storage_size() will be
used for aspect ratio calculation, unless ass_set_aspect_ratio() is
used. Also mention what libass actually does with the dar and sar
parameters: it uses them to calculate a pixel aspect ratio, nothing
else.
Explicitly allow resetting the storage size with w=h=0. Document that
it's allowed to remove the user defined aspect ratio by setting a pixel
aspedct ratio of 0.
Grigori Goronzy [Mon, 4 Mar 2013 19:24:35 +0000 (20:24 +0100)]
shaper: proper script/language handling
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.
Oleg Oshmyan [Fri, 1 Feb 2013 23:35:02 +0000 (23:35 +0000)]
Support reading the YCbCr Matrix header
The value is parsed and stored as an enum constant that the consumer
can read from ASS_Track. All output images are still plain RGB,
and the consumer is expected to perform its own color correction.
Supported header values: (TV|PC).(601|709|240M|FCC) and None.
If the header is missing, a special compatibility value is used
that should be treated as TV.601 if the accompanying video stream
is YCbCr and as None otherwise. If the header is present but has
an invalid/unknown value, a different special value is substituted.
Oleg Oshmyan [Wed, 22 Aug 2012 21:59:46 +0000 (00:59 +0300)]
Add ass_set_storage_size and fix related scaling issues
\blur radius is not scaled from script to storage resolution
but is scaled from storage to display resolution. The same
applies to borders and shadows if ScaledBorderAndShadow is "no".
(If it is "yes", borders and shadows are scaled from script
to display resolution just like before.)
wm4 [Thu, 10 Jan 2013 23:27:55 +0000 (00:27 +0100)]
Make closing ')' optional for some ASS tags
It appears VSFilter generally accepts the tag anyway if closing ')' are
missing in tags like \pos(1,2). Since they're not strictly needed
anyway, make the last ')' optional in order to make parsing more
tolerant against broken subs.