1
mirror of https://github.com/mpv-player/mpv synced 2024-07-31 16:29:58 +02:00

Add -ass-hinting option for setting font hinting method.

It is possible to separately configure hinting for scaled and unscaled osd.
The default is native hinter for unscaled osd (only vo_gl at this point),
no hinting for vf_ass.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@23152 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
eugeni 2007-04-27 14:25:36 +00:00
parent 13156cd794
commit c67220c86f
12 changed files with 67 additions and 11 deletions

View File

@ -1902,6 +1902,27 @@ Override some style parameters.
.PD 1
.
.TP
.B \-ass-hinting <type>
Set hinting type.
.PD 0
.RSs
.IPs <type>
0: No hinting.
.br
1: FreeType autohinter, light mode.
.br
2: FreeType autohinter, normal mode.
.br
3: Font native hinter.
.br
0-3 + 4: The same, but hinting will only be performed if OSD is rendered at
screen resolution and, therefore, will not be scaled.
.br
The default value is 7 (use native hinter for unscaled OSD and no hinting otherwise).
.RE
.PD 1
.
.TP
.B \-ass-line-spacing <value>
Set line spacing value for SSA/ASS renderer.
.

View File

@ -322,6 +322,7 @@
{"ass-color", &ass_color, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"ass-border-color", &ass_border_color, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"ass-styles", &ass_styles_file, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"ass-hinting", &ass_hinting, CONF_TYPE_INT, CONF_RANGE, 0, 7, NULL},
#endif
#ifdef HAVE_FONTCONFIG
{"fontconfig", &font_fontconfig, CONF_TYPE_FLAG, 0, 0, 1, NULL},

View File

@ -37,6 +37,13 @@ typedef struct ass_image_s {
struct ass_image_s* next; // linked list
} ass_image_t;
/// Hinting type
typedef enum {ASS_HINTING_NONE = 0,
ASS_HINTING_LIGHT,
ASS_HINTING_NORMAL,
ASS_HINTING_NATIVE
} ass_hinting_t;
/**
* \brief initialize the library
* \return library handle or NULL if failed
@ -77,6 +84,7 @@ void ass_set_margins(ass_renderer_t* priv, int t, int b, int l, int r);
void ass_set_use_margins(ass_renderer_t* priv, int use);
void ass_set_aspect_ratio(ass_renderer_t* priv, double ar);
void ass_set_font_scale(ass_renderer_t* priv, double font_scale);
void ass_set_hinting(ass_renderer_t* priv, ass_hinting_t ht);
/**
* \brief set font lookup defaults

View File

@ -229,13 +229,14 @@ void ass_font_get_asc_desc(ass_font_t* font, uint32_t ch, int* asc, int* desc)
* \brief Get a glyph
* \param ch character code
**/
FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch)
FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch, ass_hinting_t hinting)
{
int error;
int index = 0;
int i;
FT_Glyph glyph;
FT_Face face = 0;
int flags = 0;
if (ch < 0x20)
return 0;
@ -264,7 +265,14 @@ FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch
}
#endif
error = FT_Load_Glyph(face, index, FT_LOAD_NO_BITMAP );
switch (hinting) {
case ASS_HINTING_NONE: flags = FT_LOAD_NO_HINTING; break;
case ASS_HINTING_LIGHT: flags = FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_LIGHT; break;
case ASS_HINTING_NORMAL: flags = FT_LOAD_FORCE_AUTOHINT; break;
case ASS_HINTING_NATIVE: flags = 0; break;
}
error = FT_Load_Glyph(face, index, FT_LOAD_NO_BITMAP | flags);
if (error) {
mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph);
return 0;

View File

@ -50,7 +50,7 @@ ass_font_t* ass_font_new(ass_library_t* library, FT_Library ftlibrary, void* fc_
void ass_font_set_transform(ass_font_t* font, FT_Matrix* m, FT_Vector* v);
void ass_font_set_size(ass_font_t* font, int size);
void ass_font_get_asc_desc(ass_font_t* font, uint32_t ch, int* asc, int* desc);
FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch);
FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch, ass_hinting_t hinting);
FT_Vector ass_font_get_kerning(ass_font_t* font, uint32_t c1, uint32_t c2);
void ass_font_free(ass_font_t* font);

View File

@ -50,6 +50,7 @@ int ass_use_margins = 0;
char* ass_color = NULL;
char* ass_border_color = NULL;
char* ass_styles_file = NULL;
int ass_hinting = ASS_HINTING_NATIVE + 4; // native hinting for unscaled osd
#ifdef HAVE_FONTCONFIG
extern int font_fontconfig;
@ -218,11 +219,17 @@ ass_track_t* ass_read_subdata(ass_library_t* library, sub_data* subdata, double
char *get_path(char *);
void ass_configure(ass_renderer_t* priv, int w, int h) {
void ass_configure(ass_renderer_t* priv, int w, int h, int unscaled) {
int hinting;
ass_set_frame_size(priv, w, h);
ass_set_margins(priv, ass_top_margin, ass_bottom_margin, 0, 0);
ass_set_use_margins(priv, ass_use_margins);
ass_set_font_scale(priv, ass_font_scale);
if (!unscaled && (ass_hinting & 4))
hinting = 0;
else
hinting = ass_hinting & 3;
ass_set_hinting(priv, hinting);
}
void ass_configure_fonts(ass_renderer_t* priv) {

View File

@ -35,12 +35,13 @@ extern int ass_use_margins;
extern char* ass_color;
extern char* ass_border_color;
extern char* ass_styles_file;
extern int ass_hinting;
ass_track_t* ass_default_track(ass_library_t* library);
int ass_process_subtitle(ass_track_t* track, subtitle* sub);
ass_track_t* ass_read_subdata(ass_library_t* library, sub_data* subdata, double fps);
void ass_configure(ass_renderer_t* priv, int w, int h);
void ass_configure(ass_renderer_t* priv, int w, int h, int hinting);
void ass_configure_fonts(ass_renderer_t* priv);
ass_library_t* ass_init(void);

View File

@ -56,6 +56,7 @@ typedef struct ass_settings_s {
int use_margins; // 0 - place all subtitles inside original frame
// 1 - use margins for placing toptitles and subtitles
double aspect; // frame aspect ratio, d_width / d_height.
ass_hinting_t hinting;
char* default_font;
char* default_family;
@ -1249,7 +1250,7 @@ static void get_outline_glyph(int symbol, glyph_info_t* info, FT_Vector* advance
info->advance.y = val->advance.y;
} else {
glyph_hash_val_t v;
info->glyph = ass_font_get_glyph(frame_context.ass_priv->fontconfig_priv, render_context.font, symbol);
info->glyph = ass_font_get_glyph(frame_context.ass_priv->fontconfig_priv, render_context.font, symbol, global_settings->hinting);
if (!info->glyph)
return;
info->advance.x = d16_to_d6(info->glyph->advance.x);
@ -2049,6 +2050,14 @@ void ass_set_font_scale(ass_renderer_t* priv, double font_scale)
}
}
void ass_set_hinting(ass_renderer_t* priv, ass_hinting_t ht)
{
if (priv->settings.hinting != ht) {
priv->settings.hinting = ht;
ass_reconfigure(priv);
}
}
int ass_set_fonts(ass_renderer_t* priv, const char* default_font, const char* default_family)
{
if (priv->settings.default_font)

View File

@ -92,7 +92,7 @@ static int config(struct vf_instance_s* vf,
vf->priv->dirty_rows = malloc(vf->priv->outh);
if (vf->priv->ass_priv) {
ass_configure(vf->priv->ass_priv, vf->priv->outw, vf->priv->outh);
ass_configure(vf->priv->ass_priv, vf->priv->outw, vf->priv->outh, 0);
ass_set_aspect_ratio(vf->priv->ass_priv, ((double)d_width) / d_height);
}

View File

@ -60,14 +60,14 @@ static int config(struct vf_instance_s* vf,
}
// save vo's stride capability for the wanted colorspace:
vf->default_caps=query_format(vf,outfmt) & VFCAP_ACCEPT_STRIDE;
vf->default_caps=query_format(vf,outfmt);
if(config_video_out(video_out,width,height,d_width,d_height,flags,"MPlayer",outfmt))
return 0;
#ifdef USE_ASS
if (vf->priv->ass_priv)
ass_configure(vf->priv->ass_priv, width, height);
ass_configure(vf->priv->ass_priv, width, height, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
#endif
++vo_config_count;

View File

@ -28,4 +28,5 @@
#define VFCAP_CONSTANT 0x1000
// filter can draw EOSD
#define VFCAP_EOSD 0x2000
// filter will draw EOSD at screen resolution (without scaling)
#define VFCAP_EOSD_UNSCALED 0x4000

View File

@ -792,7 +792,7 @@ query_format(uint32_t format)
VFCAP_FLIP |
VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE;
if (use_osd)
caps |= VFCAP_OSD | VFCAP_EOSD;
caps |= VFCAP_OSD | VFCAP_EOSD | VFCAP_EOSD_UNSCALED;
if ((format == IMGFMT_RGB24) || (format == IMGFMT_RGBA))
return caps;
if (use_yuv && format == IMGFMT_YV12)