From c67220c86fa6267d8e0aa5b69d0eebbe17e0ede2 Mon Sep 17 00:00:00 2001 From: eugeni Date: Fri, 27 Apr 2007 14:25:36 +0000 Subject: [PATCH] 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 --- DOCS/man/en/mplayer.1 | 21 +++++++++++++++++++++ cfg-common.h | 1 + libass/ass.h | 8 ++++++++ libass/ass_font.c | 12 ++++++++++-- libass/ass_font.h | 2 +- libass/ass_mp.c | 9 ++++++++- libass/ass_mp.h | 3 ++- libass/ass_render.c | 11 ++++++++++- libmpcodecs/vf_ass.c | 2 +- libmpcodecs/vf_vo.c | 4 ++-- libmpcodecs/vfcap.h | 3 ++- libvo/vo_gl.c | 2 +- 12 files changed, 67 insertions(+), 11 deletions(-) diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1 index 946c3935e3..8591b518ae 100644 --- a/DOCS/man/en/mplayer.1 +++ b/DOCS/man/en/mplayer.1 @@ -1902,6 +1902,27 @@ Override some style parameters. .PD 1 . .TP +.B \-ass-hinting +Set hinting type. +.PD 0 +.RSs +.IPs +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 Set line spacing value for SSA/ASS renderer. . diff --git a/cfg-common.h b/cfg-common.h index 7bb1c903d7..e9f8a3e724 100644 --- a/cfg-common.h +++ b/cfg-common.h @@ -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}, diff --git a/libass/ass.h b/libass/ass.h index 7cba671ffd..2e1aa1ab96 100644 --- a/libass/ass.h +++ b/libass/ass.h @@ -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 diff --git a/libass/ass_font.c b/libass/ass_font.c index 285ecde63a..57423d1dd7 100644 --- a/libass/ass_font.c +++ b/libass/ass_font.c @@ -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; diff --git a/libass/ass_font.h b/libass/ass_font.h index 5d986e9f0b..e7793849fe 100644 --- a/libass/ass_font.h +++ b/libass/ass_font.h @@ -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); diff --git a/libass/ass_mp.c b/libass/ass_mp.c index e2c1092bca..02f81e4c7f 100644 --- a/libass/ass_mp.c +++ b/libass/ass_mp.c @@ -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) { diff --git a/libass/ass_mp.h b/libass/ass_mp.h index 5d8b722c28..7f98840d58 100644 --- a/libass/ass_mp.h +++ b/libass/ass_mp.h @@ -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); diff --git a/libass/ass_render.c b/libass/ass_render.c index f69c0c9518..da4d98ae9e 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -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) diff --git a/libmpcodecs/vf_ass.c b/libmpcodecs/vf_ass.c index 63355bff0f..f88ed99eca 100644 --- a/libmpcodecs/vf_ass.c +++ b/libmpcodecs/vf_ass.c @@ -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); } diff --git a/libmpcodecs/vf_vo.c b/libmpcodecs/vf_vo.c index 9d320cf855..fc1ca92d42 100644 --- a/libmpcodecs/vf_vo.c +++ b/libmpcodecs/vf_vo.c @@ -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; diff --git a/libmpcodecs/vfcap.h b/libmpcodecs/vfcap.h index 9c2288e8a3..0cc9c4ec4d 100644 --- a/libmpcodecs/vfcap.h +++ b/libmpcodecs/vfcap.h @@ -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 diff --git a/libvo/vo_gl.c b/libvo/vo_gl.c index 622955a6d3..327d27dea7 100644 --- a/libvo/vo_gl.c +++ b/libvo/vo_gl.c @@ -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)