libass中本身有Underline支持字体下画线参数的,但怎么设置也不正常,我跟踪了一下它的源代码,也没有找到其根本原因,我想mplayer中有它的插件,于是对比了一下它的mplayer中的区别,主要是增加了两个函数(事实上只要一个)即可解决;计划在视频转换软件thinkvd的 effect 功能中加上它
测试效果图如下:
附上相关代码:(调用部分参考mplayer需要自己更改)
/*
* Strike a glyph with a horizontal line; it's possible to underline it
* and/or strike through it. For the line's position and size, truetype
* tables are consulted. Obviously this relies on the data in the tables
* being accurate.
*
*/
static int ass_strike_outline_glyph(FT_Face face, ass_font_t *font,
FT_Glyph glyph, int under, int through)
{
TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
TT_Postscript *ps = FT_Get_Sfnt_Table(face, ft_sfnt_post);
FT_Outline *ol = &((FT_OutlineGlyph) glyph)->outline;
int bear, advance, y_scale, i, dir;
if (!under && !through)
return 0;
// Grow outline
i = (under ? 4 : 0) + (through ? 4 : 0);
ol->points = realloc(ol->points, sizeof(FT_Vector) *
(ol->n_points + i));
ol->tags = realloc(ol->tags, ol->n_points + i);
i = !!under + !!through;
ol->contours = realloc(ol->contours, sizeof(short) *
(ol->n_contours + i));
// If the bearing is negative, the glyph starts left of the current
// pen position
bear = FFMIN(face->glyph->metrics.horiBearingX, 0);
// We're adding half a pixel to avoid small gaps
advance = d16_to_d6(glyph->advance.x) + 32;
y_scale = face->size->metrics.y_scale;
// Reverse drawing direction for non-truetype fonts
dir = FT_Outline_Get_Orientation(ol);
// A

针对libass库中Underline字幕显示异常的问题,作者通过对比mplayer源码发现并解决了问题。通过增加特定函数,实现了字体下划线的正确显示。附带了相关代码段,涉及字体轮廓修改和FreeType库的使用。

1万+

被折叠的 条评论
为什么被折叠?



