]> granicus.if.org Git - libass/log
libass
9 years agoRemove ENCA support
Grigori Goronzy [Wed, 23 Sep 2015 08:34:55 +0000 (10:34 +0200)]
Remove ENCA support

There is no real value in it. ENCA only works in some cases and I
can't find any information about software that integrates libass
which relies on it or users that rely on ENCA support in case the
interface is exposed directly (e.g. in MPlayer).

If there is still a wish to have charset detection integrated into
libass (it is out of scope, IMHO), a better library like uchardet
should be used for that.

9 years agoMerge pull request #84 from astiob/msvc
Grigori Goronzy [Tue, 22 Sep 2015 21:07:02 +0000 (23:07 +0200)]
Merge pull request #84 from astiob/msvc

MSVC/ICL and general header fixes

9 years agofontselect: make iconv optional again
wm4 [Sun, 20 Sep 2015 17:21:37 +0000 (19:21 +0200)]
fontselect: make iconv optional again

It was needed for UTF16BE -> UTF8 only, which is trivial to implement.

9 years agoFully fix compilation with MSVC/ICL
Oleg Oshmyan [Sun, 27 Apr 2014 05:55:42 +0000 (06:55 +0100)]
Fully fix compilation with MSVC/ICL

As before, this does not add any build system support:
a config.h file and a project must still be manually created
(or the compiler can be run manually instead of using a project).

Signed-off-by: Grigori Goronzy <greg@kinoho.net>
Signed-off-by: Oleg Oshmyan <chortos@inbox.lv>
9 years agoInclude config.h in all source files and in no headers
Oleg Oshmyan [Tue, 15 Sep 2015 14:10:58 +0000 (17:10 +0300)]
Include config.h in all source files and in no headers

This way, #include "config.h" is consistently the very
first thing the compiler sees when compiling any file.

Some source files currently don't use anything defined in config.h,
but it's easier and less error-prone to include it now to anticipate
possible future changes in those files, config.h or other headers.

9 years agoMove ASS_Shaper declaration to ass_shaper.h
Oleg Oshmyan [Sun, 27 Apr 2014 05:48:47 +0000 (06:48 +0100)]
Move ASS_Shaper declaration to ass_shaper.h

9 years agounistd.h is not needed
Oleg Oshmyan [Sun, 27 Apr 2014 04:06:05 +0000 (05:06 +0100)]
unistd.h is not needed

9 years agodirectwrite: change WINBOOL to BOOL.
torque [Sun, 13 Sep 2015 19:19:47 +0000 (12:19 -0700)]
directwrite: change WINBOOL to BOOL.

WINBOOL is MingW-specific.

9 years agodirectwrite: fix syntax error with MSVC.
torque [Sun, 13 Sep 2015 19:13:40 +0000 (12:13 -0700)]
directwrite: fix syntax error with MSVC.

MSVC requires the calling convention to be grouped with the identifier when
defining a callback type.

9 years agofont: ignore bearing for strikes
Grigori Goronzy [Tue, 15 Sep 2015 01:00:05 +0000 (03:00 +0200)]
font: ignore bearing for strikes

This is more robust and simpler. The bearing calculations initially
were bugged, but getting rid of them completely seems better. It is
consistent with other text renderers as well. To simplify things, also
move striking before the additional scale is applied and get rid of the
half-pixel overlapping thing; it is not needed with additive blending.

Fixes #193.

9 years agoass_fontselect: do not use PATH_MAX
wm4 [Sun, 13 Sep 2015 20:49:04 +0000 (22:49 +0200)]
ass_fontselect: do not use PATH_MAX

This seems to cause issues on MSVC. Considering that even most Unix OSes
hate PATH_MAX and don't really honour it, using 4096 is just as good.

9 years agoMerge pull request #192 from grigorig/stringfuncs
Grigori Goronzy [Thu, 10 Sep 2015 23:15:34 +0000 (01:15 +0200)]
Merge pull request #192 from grigorig/stringfuncs

NIH: add locale-independent string functions

9 years agoNIH: add locale-independent string functions
Grigori Goronzy [Mon, 7 Sep 2015 21:44:41 +0000 (23:44 +0200)]
NIH: add locale-independent string functions

OS or platform-specific locale independent functions are painful to
use and/or not available, so roll our own. Not great but the least
painful and least intrusive.

v2: fix indexing, use static inline

9 years agofontselect: avoid undefined behavior
wm4 [Wed, 9 Sep 2015 10:06:47 +0000 (12:06 +0200)]
fontselect: avoid undefined behavior

Passing NULL as argument to %s format specifiers when using the printf
fasmily of functions is not allowed. While some libcs handle it, other
libcs will simply crash.

9 years agofontselect: raise font selection log message
wm4 [Wed, 9 Sep 2015 10:04:51 +0000 (12:04 +0200)]
fontselect: raise font selection log message

9 years agoass_fontselect: ignore ./.. and hidden files
wm4 [Tue, 8 Sep 2015 17:45:07 +0000 (19:45 +0200)]
ass_fontselect: ignore ./.. and hidden files

9 years agofontselect: handle additional malloc errors
Grigori Goronzy [Mon, 7 Sep 2015 23:38:44 +0000 (01:38 +0200)]
fontselect: handle additional malloc errors

9 years agoass_fontselect: uninline ass_map_font()
wm4 [Mon, 7 Sep 2015 14:06:24 +0000 (16:06 +0200)]
ass_fontselect: uninline ass_map_font()

Also fixes the build on OSX under some circumstances (weird and
inconsistent rules for the inline keyword in C).

9 years agoconfigure: make fontconfig optional
wm4 [Mon, 7 Sep 2015 12:54:33 +0000 (14:54 +0200)]
configure: make fontconfig optional

9 years agoass_fontselect: log the selected font provider
wm4 [Mon, 7 Sep 2015 11:55:07 +0000 (13:55 +0200)]
ass_fontselect: log the selected font provider

9 years agoass_shaper: raise shaper info log level
wm4 [Mon, 7 Sep 2015 11:51:52 +0000 (13:51 +0200)]
ass_shaper: raise shaper info log level

MSGL_V is usually for far noisier messages, such as those printed per
subtitle event.

9 years agoass_bitmap: fix potential NULL deref
wm4 [Mon, 7 Sep 2015 11:43:00 +0000 (13:43 +0200)]
ass_bitmap: fix potential NULL deref

Another consequence of the trickiness in this code. This codepath for
opaque_box=1 assumes both bm_o and bm_g are set, but if memory
allocation fails somewhere, bm_o could be non-NULL, but bm_g NULL, which
then would result in a crash when accessing bm_g.

Possibly this code could be cleaned up to look much nicer (and not have
dozens of hidden, obscure bugs), but for now this fixes the potential
crash found by Coverity.

Fixes CID 146125.

9 years agoass_render: fix potential NULL deref
wm4 [Mon, 7 Sep 2015 11:36:23 +0000 (13:36 +0200)]
ass_render: fix potential NULL deref

Fixes CID 146421.

9 years agotravis: run on OSX too
wm4 [Mon, 7 Sep 2015 10:50:38 +0000 (12:50 +0200)]
travis: run on OSX too

9 years agoass_drawing: make ass_drawing_new() fail properly on OOM
wm4 [Mon, 7 Sep 2015 10:48:34 +0000 (12:48 +0200)]
ass_drawing: make ass_drawing_new() fail properly on OOM

Fixes CID 146124.

9 years agoass_parse: add check against ass_drawing_new() failure
wm4 [Mon, 7 Sep 2015 10:45:51 +0000 (12:45 +0200)]
ass_parse: add check against ass_drawing_new() failure

Also move the argument parsing part to the top of the function. IT's
easier to read this way.

9 years agoass_render: fix potential NULL deref
wm4 [Mon, 7 Sep 2015 10:43:40 +0000 (12:43 +0200)]
ass_render: fix potential NULL deref

The logic here is pretty complicated. The caller of this function guards
it with "if(info->bm || info->bm_o){", and generally indeed only one of
them is set. But in some cases, both are needed. fix_outline()
definitely dereferences both. This is not necessarily guaranteed, e.g.
on out of memory errors. Add the missing checks.

Fixes CID 146125.

9 years agofontselect: initialize postscript name
Grigori Goronzy [Mon, 7 Sep 2015 10:13:33 +0000 (12:13 +0200)]
fontselect: initialize postscript name

Bad things can happen otherwise. Found by coverity scan.

9 years agofontselect: fix memory leak
Grigori Goronzy [Mon, 7 Sep 2015 10:08:08 +0000 (12:08 +0200)]
fontselect: fix memory leak

Introduced by commit d6bb9af6. Found by coverity scan.

9 years agoMerge branch 'fonts'
Grigori Goronzy [Mon, 7 Sep 2015 09:40:54 +0000 (11:40 +0200)]
Merge branch 'fonts'

9 years agoMerge pull request #190 from grigorig/fonts
Grigori Goronzy [Mon, 7 Sep 2015 09:32:49 +0000 (11:32 +0200)]
Merge pull request #190 from grigorig/fonts

Substitutions and some fixes

9 years agofontselect: get rid of strdup for display name
Grigori Goronzy [Mon, 7 Sep 2015 09:06:17 +0000 (11:06 +0200)]
fontselect: get rid of strdup for display name

The name is always pulled from the font info, which is static, so
there is no need to strdup.

9 years agofontselect: improve font display name choice
Grigori Goronzy [Mon, 7 Sep 2015 09:03:28 +0000 (11:03 +0200)]
fontselect: improve font display name choice

9 years agofontselect: remove outdated remark
Grigori Goronzy [Mon, 7 Sep 2015 08:56:59 +0000 (10:56 +0200)]
fontselect: remove outdated remark

fontselect is an internal only API for now. That said, it also seems
much more sane to let library users deal with this resource management.

9 years agofontconfig: fix memory leak in error path
Grigori Goronzy [Mon, 7 Sep 2015 08:48:17 +0000 (10:48 +0200)]
fontconfig: fix memory leak in error path

Found by clang static analysis.

9 years agofontselect: call match_fonts for each alias
Grigori Goronzy [Mon, 7 Sep 2015 08:27:26 +0000 (10:27 +0200)]
fontselect: call match_fonts for each alias

In case a font provider actually uses more than one substitution.

9 years agotest: use proper fallback name
Grigori Goronzy [Mon, 7 Sep 2015 00:12:43 +0000 (02:12 +0200)]
test: use proper fallback name

The correct generic family name is "sans-serif", the short form "Sans"
is specific to fontconfig only.

9 years agofontselect: fix fallback family fallback
Grigori Goronzy [Sun, 6 Sep 2015 23:34:48 +0000 (01:34 +0200)]
fontselect: fix fallback family fallback

9 years agofontconfig: handle fallback corner cases
Grigori Goronzy [Sun, 6 Sep 2015 23:29:27 +0000 (01:29 +0200)]
fontconfig: handle fallback corner cases

If no particular codepoint is requested (codepoint == 0), just return
the first font family. Additionally, handle fontconfig errors, albeit
they're unlikely to happen.

9 years agofontselect: fix match_fonts semantics
Grigori Goronzy [Wed, 2 Sep 2015 22:04:59 +0000 (00:04 +0200)]
fontselect: fix match_fonts semantics

We don't want to add fonts multiple times, so call match_fonts lazily,
i.e. only after selecting a font with a certain name failed. Since
font matching interacts with glyph coverage checks, add a simple
mechanism to determine whether matching failed because of name or
glyph coverage. Additionally make sure to handle substitutions before
any calls to match_fonts; this only correctly deals with single-name
substitutions, though.

9 years agodirectwrite, coretext: implement substitutions
Grigori Goronzy [Tue, 1 Sep 2015 13:47:40 +0000 (15:47 +0200)]
directwrite, coretext: implement substitutions

This adds simple and sensible substitutions for generic font family
names. A helper function is introduced to reduce code duplication.

9 years agodirectwrite: fix fallback for codepoint 0
Grigori Goronzy [Tue, 1 Sep 2015 14:33:33 +0000 (16:33 +0200)]
directwrite: fix fallback for codepoint 0

9 years agodirectwrite: fix compilation
Grigori Goronzy [Tue, 1 Sep 2015 14:29:49 +0000 (16:29 +0200)]
directwrite: fix compilation

A name clash was introduced by commit ab08d079.

9 years agocoretext: use SAFE_CFRelease() for robustness
wm4 [Tue, 1 Sep 2015 12:50:36 +0000 (14:50 +0200)]
coretext: use SAFE_CFRelease() for robustness

CFRelease(NULL) can crash. While we're still not sure which CoreText API
calls can fail etc. (thanks Apple), this should fix a couple of
theoretically possible crashes.

9 years agofontselect: fix yet another memory leak
Grigori Goronzy [Tue, 1 Sep 2015 12:37:57 +0000 (14:37 +0200)]
fontselect: fix yet another memory leak

9 years agofontselect: stop font selection after first match
Grigori Goronzy [Tue, 1 Sep 2015 00:12:19 +0000 (02:12 +0200)]
fontselect: stop font selection after first match

9 years agofontselect: remove static fallback font list
Grigori Goronzy [Mon, 31 Aug 2015 23:17:53 +0000 (01:17 +0200)]
fontselect: remove static fallback font list

The default font provider needs to provide a GetFallbackFunc callback
instead.

9 years agofontselect: add const
wm4 [Tue, 1 Sep 2015 12:33:51 +0000 (14:33 +0200)]
fontselect: add const

9 years agofontselect: never pass family=NULL to get_fallback()
wm4 [Tue, 1 Sep 2015 12:33:08 +0000 (14:33 +0200)]
fontselect: never pass family=NULL to get_fallback()

The CoreText backend doesn't like this, and in fact there's no reason to
pass NULL.

9 years agocoretext: fix sizeof vs. strlen
wm4 [Tue, 1 Sep 2015 12:31:21 +0000 (14:31 +0200)]
coretext: fix sizeof vs. strlen

9 years agocoretext: always use lazy loading
wm4 [Tue, 1 Sep 2015 12:21:31 +0000 (14:21 +0200)]
coretext: always use lazy loading

We already decided that eager loading is too slow. No need to keep
multiple code paths around.

9 years agofontselect: simplify get_fallback signature
wm4 [Tue, 1 Sep 2015 12:18:51 +0000 (14:18 +0200)]
fontselect: simplify get_fallback signature

Apparently we only need the font family (and even that isn't used in all
font providers). Drop the others.

9 years agofontselect: use designated initializers
wm4 [Tue, 1 Sep 2015 12:08:47 +0000 (14:08 +0200)]
fontselect: use designated initializers

Tired of matching the names and order of the callbacks in my head.

While we're at it, also give some of the callbacks better names.

9 years agocoretext: implement GetFallbackFunc
Stefano Pigozzi [Mon, 31 Aug 2015 22:18:03 +0000 (00:18 +0200)]
coretext: implement GetFallbackFunc

9 years agofontselect: add bounds checking for memory font stream reads
wm4 [Mon, 31 Aug 2015 10:15:01 +0000 (12:15 +0200)]
fontselect: add bounds checking for memory font stream reads

9 years agofont: fix double frees if opening memory font fails
wm4 [Mon, 31 Aug 2015 10:03:37 +0000 (12:03 +0200)]
font: fix double frees if opening memory font fails

Apparently, libfreetype calls close_stream_font through the
FT_Stream.close callback.

9 years agofontselect: fix a memory leak
wm4 [Mon, 31 Aug 2015 09:56:15 +0000 (11:56 +0200)]
fontselect: fix a memory leak

The result of the subst_font callback was not freed.

9 years agofontselect: reimplement ass_set_fonts_dir() functionality
wm4 [Fri, 28 Aug 2015 17:32:46 +0000 (19:32 +0200)]
fontselect: reimplement ass_set_fonts_dir() functionality

ass_set_fonts_dir() is supposed to enable all fonts in a specific
directory. The implementation for it was dropped with the commit
introducing the new fontselect code. Some users were relying on it, so
we need it back.

It used to be implemented using a single fontconfig call. But since this
has to work even if fontconfig support is not even compiled, a new
implementation is needed.

This commit adds very simple and low-effort support for it. It loads all
files into memory, and then lets the memory font code do the rest. A
more efficient implementation would be possible, for example by
implementing a new font provider, which serves get_data requests from
open file handles. Anyone who wants to do this is welcome to try, and
this commit is just the minimum to restore the lost feature.

9 years agorender_api: fix crash when calling ass_set_fonts() after rendering
wm4 [Fri, 28 Aug 2015 16:34:36 +0000 (18:34 +0200)]
render_api: fix crash when calling ass_set_fonts() after rendering

The caches may reference data which belongs to the font provider. If the
font selector and the font provider are destroyed, it can leave dangling
pointers in the renderer cache. (At least that's what it looks like.)

For some reason, this didn't even trigger valgrind warnings with the
fontconfig font provider. Possibly the dangling pointers were FT_Face
pointers, and fontconfig might cache these process-wide.

9 years agofont: fix broken charmap fallback handling
wm4 [Fri, 28 Aug 2015 15:39:08 +0000 (17:39 +0200)]
font: fix broken charmap fallback handling

An earlier commit added this code to avoid adding font faces multiple
times. In this form, it breaks the "Trying all charmaps" fallback case,
which can lead to text being rendered as boxes.

Return the font that is going to contain the missing glyph instead. The
calling code will check again, and run the fallback if necessary.

9 years agofontselect: fix fallbacks
wm4 [Fri, 28 Aug 2015 14:29:06 +0000 (16:29 +0200)]
fontselect: fix fallbacks

I broke it.

9 years agoconfigure: proper configure switches for DirectWrite and CoreText
wm4 [Fri, 28 Aug 2015 13:39:32 +0000 (15:39 +0200)]
configure: proper configure switches for DirectWrite and CoreText

Also, remove the ass_coretext.c conditional compilation hack, and fix
Makefile.am instead.

9 years agoass: make font_provider API private
wm4 [Fri, 28 Aug 2015 12:51:09 +0000 (14:51 +0200)]
ass: make font_provider API private

We were discussing whether this should be public or private. It could be
public, because the API is potentially useful, and is relatively simple.
On the other hand, the API is not necessarily final, and making it
public would prevent us from improving/fixing it.

Make it private for now - making it public later is much easier than
having to break the public API later.

9 years agoass: ass_fonts_update() is a stub
wm4 [Fri, 28 Aug 2015 12:38:16 +0000 (14:38 +0200)]
ass: ass_fonts_update() is a stub

9 years agoass: restore ABI compatibility with older versions (more or less)
wm4 [Fri, 28 Aug 2015 12:35:41 +0000 (14:35 +0200)]
ass: restore ABI compatibility with older versions (more or less)

While enums normally are ints on most systems, it isn't guaranteed. This
might also make C++ code fail to compile, since C++ doesn't allow
implicit conversion of ints to enums.

If the API user ever passed anything other than 0 or 1, compatibility
will still break, but I guess we have to live with this.

Also extend the doxygen.

9 years agofontconfig: fix error checking
wm4 [Fri, 28 Aug 2015 12:02:19 +0000 (14:02 +0200)]
fontconfig: fix error checking

FcInitLoadConfig() could faul, leaving rc=1 and fc->config=NULL, making
FcConfigBuildFonts() potentially crash.

Also, the FcConfigBuildFonts() return value was not checked.

9 years agofontselect: minor cleanup
wm4 [Fri, 28 Aug 2015 11:56:51 +0000 (13:56 +0200)]
fontselect: minor cleanup

Use a pointer to the selected font info, instead of an index. Makes the
code a bit more readable.

9 years agofontselect: correctly match list of font substitutions
wm4 [Fri, 28 Aug 2015 11:54:33 +0000 (13:54 +0200)]
fontselect: correctly match list of font substitutions

This code prioritized fonts by scanning order, but the scanning order is
essentially arbitrary. This resulted in suboptimal and indeterministic
font selection by family name.

Prefer the order as returned by the substitution callback. This requires
some restructuring. The core algorithm is still exactly the same though;
only the order of comparisons changes.

If the font backend has no subtitution callback, nothing should change.

9 years agofontselect: deal with potential ASS_FontProvider.subst_font failure
wm4 [Fri, 28 Aug 2015 10:52:31 +0000 (12:52 +0200)]
fontselect: deal with potential ASS_FontProvider.subst_font failure

Don't assume it sets all fields. If it doesn't return any font names at
all, go with the default.

9 years agofontconfig: implement substitutions
Grigori Goronzy [Thu, 6 Aug 2015 02:35:56 +0000 (04:35 +0200)]
fontconfig: implement substitutions

Signed-off-by: wm4 <wm4@nowhere>
9 years agofontselect: check fontprovider constructors for failure
wm4 [Thu, 27 Aug 2015 18:46:11 +0000 (20:46 +0200)]
fontselect: check fontprovider constructors for failure

Should fix the DirectWrite to Fontconfig fallback.

9 years agoRename dwrite.h, minor cleanups
wm4 [Wed, 5 Aug 2015 20:05:36 +0000 (22:05 +0200)]
Rename dwrite.h, minor cleanups

Rename dwrite.h to dwrite_c.h to make the difference between the
official header and ours clearer. Also apply minor cleanups to it.

Remove the patch against upstream MinGW; it's pointless now.

9 years agoFix typedefs
wm4 [Tue, 4 Aug 2015 09:33:40 +0000 (11:33 +0200)]
Fix typedefs

9 years agoProperly skip glyphs for multiple consecutive line breaks
Oleg Oshmyan [Sun, 2 Aug 2015 21:40:16 +0000 (00:40 +0300)]
Properly skip glyphs for multiple consecutive line breaks

This corrects the calculated width of events that contain \N\N,
which previously included the width of the glyph corresponding
to '\n' (more generally, for n consecutive line breaks, only
the first glyph was skipped and n-1 glyphs were included).

Reported on IRC.

9 years agoFix crash when the OS doesn't support AVX2
Rodger Combs [Mon, 27 Jul 2015 22:53:21 +0000 (17:53 -0500)]
Fix crash when the OS doesn't support AVX2

9 years agoconfigure: remove some unneeded checks
wm4 [Sat, 11 Jul 2015 21:06:52 +0000 (23:06 +0200)]
configure: remove some unneeded checks

9 years agodirectwrite: don't crash on unknown DWRITE_FONT_STRETCH
wm4 [Sat, 11 Jul 2015 21:00:26 +0000 (23:00 +0200)]
directwrite: don't crash on unknown DWRITE_FONT_STRETCH

The existing code doesn't even handle all currently defined values
for it, and nothing says no new values are ever going to be added.

9 years agodirectwrite: convert to C
wm4 [Sat, 11 Jul 2015 18:33:15 +0000 (20:33 +0200)]
directwrite: convert to C

Unfortunately, nobody ever tested the MinGW dwrite.h header in C. There
are multiple glaring mistakes, and the header doesn't even compile by
itself. The main issues are overloaded functions (which doesn't work
in C), and broken COBJMACROS defines.

dwrite.diff contains changes to dwrite.h which make libass work.
Warning: the patch lacks a required change to the DrawInlineObject
method of IDWriteTextRenderer (missing THIS_).

Additionally, these definitions would ideally be provided by dwrite.h:

DEFINE_GUID(IID_IDWriteFactory, 0xb859ee5a,0xd838,0x4b5b,0xa2,0xe8,0x1a,0xdc,0x7d,0x93,0xdb,0x48);
DEFINE_GUID(IID_IDWritePixelSnapping, 0xeaf3a2da,0xecf4,0x4d24,0xb6,0x44,0xb3,0x4f,0x68,0x42,0x02,0x4b);
DEFINE_GUID(IID_IDWriteTextRenderer, 0xef8a8135,0x5cc6,0x45fe,0x88,0x25,0xc5,0xa0,0x72,0x4e,0xb8,0x19);

Also, in order to make libass compile out of the box with current
MinGW/msys installations, a very stripped down in-tree copy of dwrite.h
is provided.

9 years agodirectwrite: dynamically load dwrite.dll
wm4 [Sat, 11 Jul 2015 17:33:44 +0000 (19:33 +0200)]
directwrite: dynamically load dwrite.dll

9 years agodirectwrite: compile only on Windows
wm4 [Sat, 11 Jul 2015 16:51:54 +0000 (18:51 +0200)]
directwrite: compile only on Windows

9 years agofontselect: prefer platform font providers
Grigori Goronzy [Sun, 14 Jun 2015 10:49:31 +0000 (12:49 +0200)]
fontselect: prefer platform font providers

Prefer DirectWrite before the cross-platform fontconfig, so that
DirectWrite is used by default if both are compiled into libass.

9 years agodirectwrite: add font fallback callback
Grigori Goronzy [Sun, 14 Jun 2015 10:34:09 +0000 (12:34 +0200)]
directwrite: add font fallback callback

This uses a faux rendering with a high-level interface of DirectWrite
to determine a suitable fallback. Choices are different from GDI,
but reasonable.

9 years agofontconfig: add font fallback callback
Grigori Goronzy [Sun, 14 Jun 2015 01:13:37 +0000 (03:13 +0200)]
fontconfig: add font fallback callback

This creates a sorted list of fallback fonts and reuses it, for speed.
Font sorting is very slow.

9 years agofontselect: add fallback handling with callback
Grigori Goronzy [Sun, 14 Jun 2015 01:11:50 +0000 (03:11 +0200)]
fontselect: add fallback handling with callback

If we can't find a matching font face (with glyph coverage), ask the
default font provider for a fallback family. The callback is optional.

9 years agofontselect: improved face selection among a family
Grigori Goronzy [Sun, 14 Jun 2015 01:09:10 +0000 (03:09 +0200)]
fontselect: improved face selection among a family

We want the best variant, but if it doesn't have the glyph coverage,
we may also use another variant from the same family.

9 years agoConstify ass_msg format (NFC)
Grigori Goronzy [Sat, 13 Jun 2015 15:32:59 +0000 (17:32 +0200)]
Constify ass_msg format (NFC)

9 years agodirectwrite: multiple improvements to font scanning
Grigori Goronzy [Sat, 13 Jun 2015 14:29:10 +0000 (16:29 +0200)]
directwrite: multiple improvements to font scanning

There were various issues with font scanning. This addresses the following:

- Synthesized font faces (bold/oblique) were added to the list. Just skip
  those, this is handled internally by libass.
- Use the win32 font family names, if available. Traditionally, Windows
  groups font families in a different way, so that the number of
  variants is small (<= 4). With this, Arial Narrow and Arial Black
  appear as a separate family, which is what we want.
- Full names are not mandatory. Correctly handle the case that there
  are no full names.
- Don't use the bogus LOCALE_NAME_MAX_LENGTH constant to determine the
  size of the name buffer. Names can be almost arbitrarily long.
  Handle names up to 256 characters correctly and truncate longer names.

9 years agofontselect: fix oblique/italic mixup
Grigori Goronzy [Sat, 13 Jun 2015 14:25:41 +0000 (16:25 +0200)]
fontselect: fix oblique/italic mixup

The constants were swapped. In some cases this lead to incorrect matching.

9 years agofontselect: fix undefined behavior with calloc
Grigori Goronzy [Fri, 12 Jun 2015 19:14:53 +0000 (21:14 +0200)]
fontselect: fix undefined behavior with calloc

If allocations have the size zero, malloc/calloc implementations
can return a zero-size buffer or NULL. The earlier introduced malloc
checking blows up if an implementation returns NULL. Fix that by only
allocating and checking when it's actually needed.

Also fix a minor problem with iconv deinitialization in an error path.

9 years agodirectwrite: fix linking
Grigori Goronzy [Fri, 12 Jun 2015 19:13:29 +0000 (21:13 +0200)]
directwrite: fix linking

9 years agofontselect: replace magic numbers (NFC)
Grigori Goronzy [Fri, 12 Jun 2015 01:31:35 +0000 (03:31 +0200)]
fontselect: replace magic numbers (NFC)

9 years agofontselect: trim names of embedded fonts
Grigori Goronzy [Fri, 12 Jun 2015 01:20:49 +0000 (03:20 +0200)]
fontselect: trim names of embedded fonts

Embedded fonts tend to be extra bad, so trim the names. I have
encountered fonts faces with untrimmed names.

Leave this at the discretion of the font provider for platform-specific
font providers.

9 years agofontselect: add and use strdup_trimmed
Grigori Goronzy [Fri, 12 Jun 2015 00:53:09 +0000 (02:53 +0200)]
fontselect: add and use strdup_trimmed

This is just a cleaner and safer interface for string trimming.

9 years agofontselect: simplify lookup of embedded fonts
Grigori Goronzy [Fri, 12 Jun 2015 00:04:43 +0000 (02:04 +0200)]
fontselect: simplify lookup of embedded fonts

Currently, it is not safe to change the embedded fonts
(ass_add_font/ass_clear_fonts) while an ASS_Renderer exists. We can
simplify how embedded fonts are looked up because of that.

At some point, ASS_Library and ASS_Renderer should be merged and we
can then implement a more flexible approach.

9 years agofontselect: malloc and error checking
Grigori Goronzy [Thu, 11 Jun 2015 23:35:40 +0000 (01:35 +0200)]
fontselect: malloc and error checking

Add malloc checks with useful semantics and error checks in some
specific cases. This should hopefully make fontselect more robust.

The platform-specific font providers (DirectWrite/CoreText/FontConfig)
still need to be checked for proper memory management.

9 years agofontselect: simplify cmap lookup for embedded fonts
Grigori Goronzy [Thu, 11 Jun 2015 20:46:10 +0000 (22:46 +0200)]
fontselect: simplify cmap lookup for embedded fonts

FreeType can do it for us and is probably more efficient. Also fixes
deinitialization order of ASS_Renderer to make this work.

9 years agofontselect: improved and simplified matching
Grigori Goronzy [Thu, 11 Jun 2015 19:29:35 +0000 (21:29 +0200)]
fontselect: improved and simplified matching

Sorting the font list is overkill and not very useful. We are
interested in *exact* name matches only; all other font families don't
matter and we'll use another fallback mechanism for glyph fallbacks
(TBD).

Replace the sorting and glyph fallback search with a simple linear
scan.  Fonts are first matched against family name first (to allow
further comparison against style attributes) and if that fails,
the fullname is considered.

9 years agofontselect: add fallback and substitution callbacks
Grigori Goronzy [Mon, 8 Jun 2015 23:20:28 +0000 (01:20 +0200)]
fontselect: add fallback and substitution callbacks

Add callbacks to introduce more sane fallback handling and font
alias substitutions.

9 years agofontselect: add documentation
Grigori Goronzy [Mon, 8 Jun 2015 21:21:50 +0000 (23:21 +0200)]
fontselect: add documentation

Add some documentation to the font provider callbacks and metadata
struct.

9 years agodirectwrite: fix indentation
Stephan Vedder [Fri, 29 May 2015 09:23:23 +0000 (11:23 +0200)]
directwrite: fix indentation