changeset 26035:501ea0b13962

Check glyph bounding box before rasterizing and complain if it is too large.
author eugeni
date Fri, 22 Feb 2008 19:31:53 +0000
parents e8289d9a4fec
children 8d8c52a169ad
files help/help_mp-en.h libass/ass_bitmap.c
diffstat 2 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/help/help_mp-en.h	Fri Feb 22 19:31:51 2008 +0000
+++ b/help/help_mp-en.h	Fri Feb 22 19:31:53 2008 +0000
@@ -2010,6 +2010,7 @@
 // ass_bitmap.c
 #define MSGTR_LIBASS_FT_Glyph_To_BitmapError "[ass] FT_Glyph_To_Bitmap error %d \n"
 #define MSGTR_LIBASS_UnsupportedPixelMode "[ass] Unsupported pixel mode: %d\n"
+#define MSGTR_LIBASS_GlyphBBoxTooLarge "[ass] Glyph bounding box too large: %dx%dpx\n"
 
 // ass.c
 #define MSGTR_LIBASS_NoStyleNamedXFoundUsingY "[ass] [%p] Warning: no style named '%s' found, using '%s'\n"
--- a/libass/ass_bitmap.c	Fri Feb 22 19:31:51 2008 +0000
+++ b/libass/ass_bitmap.c	Fri Feb 22 19:31:53 2008 +0000
@@ -150,6 +150,20 @@
 	return dst;
 }
 
+static int check_glyph_area(FT_Glyph glyph)
+{
+	FT_BBox bbox;
+	long long dx, dy;
+	FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &bbox);
+	dx = bbox.xMax - bbox.xMin;
+	dy = bbox.yMax - bbox.yMin;
+	if (dx * dy > 8000000) {
+		mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_GlyphBBoxTooLarge, (int)dx, (int)dy);
+		return 1;
+	} else
+		return 0;
+}
+
 static bitmap_t* glyph_to_bitmap_internal(FT_Glyph glyph, int bord)
 {
 	FT_BitmapGlyph bg;
@@ -161,6 +175,8 @@
 	int i;
 	int error;
 
+	if (check_glyph_area(glyph))
+		return 0;
 	error = FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 0);
 	if (error) {
 		mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_FT_Glyph_To_BitmapError, error);