changeset 23982:17b5fa69243c

Workaround for fonts with zero ascender/descender in horizontal header.
author eugeni
date Fri, 03 Aug 2007 15:22:55 +0000
parents 705628816d98
children 90038c72d69e
files libass/ass_font.c
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libass/ass_font.c	Fri Aug 03 14:10:53 2007 +0000
+++ b/libass/ass_font.c	Fri Aug 03 15:22:55 2007 +0000
@@ -89,6 +89,25 @@
 
 static void face_set_size(FT_Face face, double size);
 
+static void buggy_font_workaround(FT_Face face)
+{
+	// Some fonts have zero Ascender/Descender fields in 'hhea' table.
+	// In this case, get the information from 'os2' table or, as
+	// a last resort, from face.bbox.
+	if (face->ascender + face->descender == 0 || face->height == 0) {
+		TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
+		if (os2) {
+			face->ascender = os2->sTypoAscender;
+			face->descender = os2->sTypoDescender;
+			face->height = face->ascender - face->descender;
+		} else {
+			face->ascender = face->bbox.yMax;
+			face->descender = face->bbox.yMin;
+			face->height = face->ascender - face->descender;
+		}
+	}
+}
+
 /**
  * \brief Select a face with the given charcode and add it to ass_font_t
  * \return index of the new face in font->faces, -1 if failed
@@ -123,6 +142,7 @@
 		}
 	}
 	charmap_magic(face);
+	buggy_font_workaround(face);
 	
 	font->faces[font->n_faces++] = face;
 	update_transform(font);