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.
Oleg Oshmyan [Sun, 16 Dec 2012 21:54:57 +0000 (23:54 +0200)]
Use glyph properties instead of renderer state in draw_opaque_box
scale_x, scale_y and hspacing should be read from the GlyphInfo
of the glyph the box is based on, not from render_priv->state.
The values in the renderer state are affected by override tags
specified after this glyph, so they are irrelevant.
Oleg Oshmyan [Sun, 16 Dec 2012 17:02:32 +0000 (19:02 +0200)]
Properly render opaque box shadows even when there is no border
Even if the border size is zero, the shadow is supposed to be
a copy of a hypothetical border: when border_style is 1, this
coincides with the borderless glyph, but when border_style is 3,
the shadow must be an opaque box.
Opaque box borders are now generated regardless of border size
being non-zero, and outline_to_bitmap3 gets a new flag indicating
whether it should discard the border (after generating a shadow
from it).
Oleg Oshmyan [Thu, 22 Nov 2012 02:19:17 +0000 (02:19 +0000)]
Fix fix_freetype_stroker
The first point in a countour is not allowed to be a cubic control
point, which is sometimes violated by blindly reversing a countour,
producing the following errors:
Grigori Goronzy [Mon, 1 Oct 2012 18:39:02 +0000 (20:39 +0200)]
shaper: improve skipping of zero-width characters
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.
Grigori Goronzy [Mon, 1 Oct 2012 17:33:36 +0000 (19:33 +0200)]
Fix change detection in a rare case
If an empty track is passed to ass_render_frame, always set the
change detection value to 2 (content and positions changed). This is
acceptable in both the case that the previous call resulted in images
(obviously) and in the case that the previous call resulted in no
images (in that case the change detection result doesn't actually
matter).
Grigori Goronzy [Mon, 1 Oct 2012 15:37:00 +0000 (17:37 +0200)]
shaper: add UCDN support
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!
Grigori Goronzy [Mon, 1 Oct 2012 13:53:32 +0000 (15:53 +0200)]
shaper: always use LTR base direction by default
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).
check_cache_limits() clears the image list. If all subtitles disappear
right in the frame the cache has been cleared, ass_detect_change() will
see two empty image lists (old - not empty, but cleared, new - empty),
and signal to the application that there was no change. As result,
media players which rely on the change detection will keep displaying
the last subtitle until the next subtitle event.
This bug was found by uau and has been reported on IRC in February.
Add ass_set_line_position() API function for subtitle position
This allows users to change the vertical position of normal subtitles.
MPlayer has such a feature as -sub-pos option using its internal
subtitle renderer.
When \fay tag is applied to a multiline sub, it causes subsequent lines
of the sub to be offset vertically as if it was rendered next to the
previous line (not below).
Patch by Hector Martin <hector@marcansoft.com>, with an additional
correction related to libass issue #46.
Fix issues with shearing in combination with scaling
There are two problems.
First, the shearing tags (\fay and \fax) misbehave when used with
scaling tags (\fscx and \fscy). We have to compensate for the scaling
in either direction when shearing, because the shearing is applied
after scaling. VSFilter, which by definition has the correct behavior,
does it the other way around.
Second, libass doesn't scale smoothly when small font sizes are
involved. These can come either from downscaling (e.g. make the mplayer
window smaller than the video with a video output like gl or vdpau), or
from setting the font size manually. In these cases, the font size
passed to freetype get very low, so that rounding errors or size
adjustments due to hinting or other pixel grid fitting add up. The
result is text rendered in the wrong size, or "pulsating" text if the
font size depends on animated parameters. This is worsened by the
practice found in subtitle scripts to use tag combinations like
"\fscy2500\fs2" to get more precision for controlling font size (needed
because VSFilter doesn't read fractional scale values).
We solve the second issue by always requesting a constant font size
from freetype, and then scaling the resulting glyph to the desired
size. This seems to disable freetype's glyph fitting issue. The caveat
is that it (obviously) also disables hinting, which may result in worse
text quality. However, the combination of applying \fs and \fscx tags,
and animating them, seems to leave no other choice.
The parsing code allowed override tags after \p0 to affect the drawing.
This is incorrect. Finish the drawing object as soon as \p0 is
encountered instead.
This requires moving the code executing the style overrides from
get_next_char() in ass_parse.c to the main render loop in
ass_renderer.c, because we have to re-enter the rendering loop
inside of a tag. The old code was simply executing all tags until
a new character could be returned to the renderer loop, mutating up
the state (RenderContext fields) for the drawing after the drawing
was closed, but before it was rendered.
With \rSTYLE, it is possible to change the border style within the same
subtitle event. You can do this by setting a different BorderStyle value
in the newly requested style. VSFilter handles this as expected, while
libass uses a single border style for the whole subtitle event.
Grigori Goronzy [Sun, 2 Oct 2011 22:41:53 +0000 (00:41 +0200)]
Letter spacing is a per-cluster property
Layout refactoring broke letter spacing and always used the last valid
spacing specified for the whole line, which is of course wrong.
Letter-spacing is an inline property and can be different for each glyph
cluster. Add that property to GlyphInfo and use it to fix this
regression.
Grigori Goronzy [Sun, 25 Sep 2011 00:18:20 +0000 (02:18 +0200)]
pkg-config: tailor libass.pc for static-only builds
Add library and package dependencies to the default (non-private)
pkg-config fields for static-only builds. This makes sure the packages
and libraries are always picked up and used, even if the --static option
is not supplied to the pkg-config commandline.
Grigori Goronzy [Mon, 29 Aug 2011 17:15:31 +0000 (19:15 +0200)]
Fix off-by-one error in \fad, \fade
Typical greater vs. greater-or-equal case. This especially fixes fades
with zero delays. A zero delay in the two-argument form means no fade at
all, but previously this faded over a single frame, since the code used
"greater" semantics, while "greater or equal" is required here.
Notably, this avoids blinking/flickering in some tightly timed karaoke
scripts.
Grigori Goronzy [Thu, 25 Aug 2011 01:48:18 +0000 (03:48 +0200)]
vertical: improve glyph positioning
It is a bit crazy, but for vertical layout the sTypoAscender and
sTypoDescender fields of the OS/2 table are supposed to be used for
determining the size of the ideographic EM box [1], so that glyphs
can be centered on the baseline more neatly.
With this change, vertical layout should be completely equal to
VSFilter.
Grigori Goronzy [Sun, 21 Aug 2011 22:21:50 +0000 (00:21 +0200)]
opaque box: avoid unnecessary outline copy
It's faster and easier to just create a new outline, than to copy it,
free it, and create a new one. The old glyph-based code needed to do
this since it's not possible to create a glyph "from scratch".
Grigori Goronzy [Sun, 21 Aug 2011 22:17:45 +0000 (00:17 +0200)]
Fix and simplify opaque box border
Make sure to pass the correct advance and ascender/descender to the
opaque box creation function. We can also simplify this a bit as we
do not need to check if it's a glyph or drawing anymore.
Grigori Goronzy [Sun, 7 Aug 2011 23:09:24 +0000 (01:09 +0200)]
Add compile time switch for HarfBuzz support
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.
Grigori Goronzy [Sun, 7 Aug 2011 22:22:32 +0000 (00:22 +0200)]
Runtime shaper selection
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.
Grigori Goronzy [Sat, 6 Aug 2011 18:06:54 +0000 (20:06 +0200)]
Adjust italic to non-italic style spacing
Previously, the space added was quite a lot, since it was calculated so
that it would be enough to accommodate a heavily FreeType-slanted glyph
in the worst case. In many cases this was too much spacing, especially
if the italic font was only slightly angled.
The new fix simply ensures that the glyph is inside the bounds of the
advance.
Grigori Goronzy [Mon, 1 Aug 2011 13:51:27 +0000 (15:51 +0200)]
Support language hint in the Script Info section
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.
Grigori Goronzy [Fri, 29 Jul 2011 02:21:48 +0000 (04:21 +0200)]
harfbuzz: cache glyph metrics
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.
Grigori Goronzy [Sun, 24 Jul 2011 22:00:53 +0000 (00:00 +0200)]
Disable reordering of non-spacing marks
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.
Grigori Goronzy [Sun, 17 Jul 2011 15:43:55 +0000 (17:43 +0200)]
Fix crash with FreeType's updated stroker
The new revision of the stroker in FreeType doesn't like the way
contours are zero-filled to disable them. It's not particularly clean
anyway, so rewrite the whole outline instead.
Grigori Goronzy [Sun, 17 Jul 2011 11:53:29 +0000 (13:53 +0200)]
Fix line counting and breaking
Make sure to increment the line counter only if the offset of the new
line is actually legal and inside the bounds of the text size. Fixes
random crashes in case the last symbol of the line is a break.
git-blame says it's Evgeniys fault, it wasn't caused by the recent
layout changes.
Grigori Goronzy [Thu, 14 Jul 2011 22:49:50 +0000 (00:49 +0200)]
Cache HarfBuzz fonts
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.
Grigori Goronzy [Thu, 14 Jul 2011 18:49:44 +0000 (20:49 +0200)]
Revert @font ascender/descender hack
This was introduced with commit e051ab. After re-evaluation, it
seems to be rather wrong. Windows appears to use the same ascender
as horizontal rendering, except for the first line. We don't have this
special handling of the first line, but apart from that, everything is
similar to Windows now. Verified with a couple of popular CJK fonts,
such as MS Mincho, Meiryo, etc.
Grigori Goronzy [Wed, 13 Jul 2011 22:01:11 +0000 (00:01 +0200)]
Use the "font encoding" property as a base direction hint
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.
Grigori Goronzy [Wed, 13 Jul 2011 20:32:00 +0000 (22:32 +0200)]
Enable vert/vkna features for @font vertical text
Set up a feature list and toggles these features as needed. The "vert"
feature enables vertical glyph variants in general, while "vkna"
additionally enables vertical variants for Kana.
Grigori Goronzy [Wed, 13 Jul 2011 19:52:23 +0000 (21:52 +0200)]
Introduce ASS_Shaper object
Encapsulate all data related to shaping into this new object and migrate
all shaping-related code to it. The object is long-living; arrays are
allocated only once and then grown as needed.
Grigori Goronzy [Mon, 11 Jul 2011 18:35:16 +0000 (20:35 +0200)]
Support glyph clusters of multiple glyphs
Sometimes a glyph cluster resolves to multiple glyphs, for example when
diacritics are used with Arabic script. This doesn't map well to the
list of glyphs expected by libass.
Extend the glyph list to a list of singly-linked glyph clusters of
glyphs and adapt the renderer to support this.
Grigori Goronzy [Sun, 10 Jul 2011 02:08:55 +0000 (04:08 +0200)]
Separate glyph font face matching and glyph loading
Split up ass_font_get_glyph into two functions: one function matches
checks the fonts for support of the requested codepoint and returns
a face_index and glyph_index to later load the glyph, with a second
function.
This approach is very useful for shaping, which needs to be done
on runs with the same font face and font size and changes the
glyph_index.
Grigori Goronzy [Sat, 9 Jul 2011 23:53:09 +0000 (01:53 +0200)]
Fix bitmap cache
Pass the *complete* hash key to the cache handling functions, not
only the outline-specific subkey. This mistake completely stopped
the cache from actually working and resulted in great slowdown!
Grigori Goronzy [Sat, 9 Jul 2011 22:38:12 +0000 (00:38 +0200)]
Reorder positions for "Banner" effect text
Events that use the "Banner" effect have different wrapping/breaking
handling (none at all, to be exact) and need special treatment to
make reordering work.