changeset 23134:1de2a46a0987

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.
author eugeni
date Fri, 27 Apr 2007 14:25:36 +0000
parents 0574817cc6cb
children 960434b7d963
files DOCS/man/en/mplayer.1 cfg-common.h libass/ass.h libass/ass_font.c libass/ass_font.h libass/ass_mp.c libass/ass_mp.h libass/ass_render.c libmpcodecs/vf_ass.c libmpcodecs/vf_vo.c libmpcodecs/vfcap.h libvo/vo_gl.c
diffstat 12 files changed, 67 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1	Fri Apr 27 14:18:44 2007 +0000
+++ b/DOCS/man/en/mplayer.1	Fri Apr 27 14:25:36 2007 +0000
@@ -1902,6 +1902,27 @@
 .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.
 .
--- a/cfg-common.h	Fri Apr 27 14:18:44 2007 +0000
+++ b/cfg-common.h	Fri Apr 27 14:25:36 2007 +0000
@@ -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},
--- a/libass/ass.h	Fri Apr 27 14:18:44 2007 +0000
+++ b/libass/ass.h	Fri Apr 27 14:25:36 2007 +0000
@@ -37,6 +37,13 @@
 	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_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
--- a/libass/ass_font.c	Fri Apr 27 14:18:44 2007 +0000
+++ b/libass/ass_font.c	Fri Apr 27 14:25:36 2007 +0000
@@ -229,13 +229,14 @@
  * \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 @@
 	}
 #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;
--- a/libass/ass_font.h	Fri Apr 27 14:18:44 2007 +0000
+++ b/libass/ass_font.h	Fri Apr 27 14:25:36 2007 +0000
@@ -50,7 +50,7 @@
 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);
 
--- a/libass/ass_mp.c	Fri Apr 27 14:18:44 2007 +0000
+++ b/libass/ass_mp.c	Fri Apr 27 14:25:36 2007 +0000
@@ -50,6 +50,7 @@
 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 @@
 
 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) {
--- a/libass/ass_mp.h	Fri Apr 27 14:18:44 2007 +0000
+++ b/libass/ass_mp.h	Fri Apr 27 14:25:36 2007 +0000
@@ -35,12 +35,13 @@
 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);
 
--- a/libass/ass_render.c	Fri Apr 27 14:18:44 2007 +0000
+++ b/libass/ass_render.c	Fri Apr 27 14:25:36 2007 +0000
@@ -56,6 +56,7 @@
 	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 @@
 		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_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)
--- a/libmpcodecs/vf_ass.c	Fri Apr 27 14:18:44 2007 +0000
+++ b/libmpcodecs/vf_ass.c	Fri Apr 27 14:25:36 2007 +0000
@@ -92,7 +92,7 @@
 	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);
 	}
 
--- a/libmpcodecs/vf_vo.c	Fri Apr 27 14:18:44 2007 +0000
+++ b/libmpcodecs/vf_vo.c	Fri Apr 27 14:25:36 2007 +0000
@@ -60,14 +60,14 @@
   }
 
     // 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;
--- a/libmpcodecs/vfcap.h	Fri Apr 27 14:18:44 2007 +0000
+++ b/libmpcodecs/vfcap.h	Fri Apr 27 14:25:36 2007 +0000
@@ -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
--- a/libvo/vo_gl.c	Fri Apr 27 14:18:44 2007 +0000
+++ b/libvo/vo_gl.c	Fri Apr 27 14:25:36 2007 +0000
@@ -792,7 +792,7 @@
                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)