summaryrefslogtreecommitdiffstats
path: root/libass/ass_font.c
diff options
context:
space:
mode:
authoreugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-05-19 14:11:41 +0000
committereugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-05-19 14:11:41 +0000
commit676b104211c85790802ad38cdb6cc310d05b0484 (patch)
treedca8c2716053ed5d541e6455b6b3d694cfd216bd /libass/ass_font.c
parentf6551666dcdb8a3f6bb8ca86c60c652d20c36304 (diff)
downloadlibass-676b104211c85790802ad38cdb6cc310d05b0484.tar.bz2
libass-676b104211c85790802ad38cdb6cc310d05b0484.tar.xz
Correct font size in libass.
Values from TrueType OS/2 table are used to reproduce VSFilter behaviour. Magic 0.8 multiplier and scaling for the fractional part of font size are not needed anymore. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@23346 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libass/ass_font.c')
-rw-r--r--libass/ass_font.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/libass/ass_font.c b/libass/ass_font.c
index 4006087..0d38a76 100644
--- a/libass/ass_font.c
+++ b/libass/ass_font.c
@@ -25,6 +25,7 @@
#include FT_FREETYPE_H
#include FT_SYNTHESIS_H
#include FT_GLYPH_H
+#include FT_TRUETYPE_TABLES_H
#include "ass.h"
#include "ass_library.h"
@@ -67,9 +68,8 @@ static void update_transform(ass_font_t* font)
{
int i;
FT_Matrix m;
- double size_scale = font->size / (int)font->size;
- m.xx = double_to_d16(font->scale_x * size_scale);
- m.yy = double_to_d16(font->scale_y * size_scale);
+ m.xx = double_to_d16(font->scale_x);
+ m.yy = double_to_d16(font->scale_y);
m.xy = m.yx = 0;
for (i = 0; i < font->n_faces; ++i)
FT_Set_Transform(font->faces[i], &m, &font->v);
@@ -154,6 +154,28 @@ void ass_font_set_transform(ass_font_t* font, double scale_x, double scale_y, FT
update_transform(font);
}
+static void face_set_size(FT_Face face, double size)
+{
+ TT_HoriHeader *hori = FT_Get_Sfnt_Table(face, ft_sfnt_hhea);
+ TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
+ double mscale = 1.;
+ FT_Size_RequestRec rq;
+ FT_Size_Metrics *m = &face->size->metrics;
+ // VSFilter uses metrics from TrueType OS/2 table
+ // The idea was borrowed from asa (http://asa.diac24.net)
+ if (hori && os2)
+ mscale = ((double)(hori->Ascender - hori->Descender)) / (os2->usWinAscent + os2->usWinDescent);
+ memset(&rq, 0, sizeof(rq));
+ rq.type = FT_SIZE_REQUEST_TYPE_REAL_DIM;
+ rq.width = 0;
+ rq.height = double_to_d6(size * mscale);
+ rq.horiResolution = rq.vertResolution = 0;
+ FT_Request_Size(face, &rq);
+ m->ascender /= mscale;
+ m->descender /= mscale;
+ m->height /= mscale;
+}
+
/**
* \brief Set font size
**/
@@ -163,8 +185,7 @@ void ass_font_set_size(ass_font_t* font, double size)
if (font->size != size) {
font->size = size;
for (i = 0; i < font->n_faces; ++i)
- FT_Set_Pixel_Sizes(font->faces[i], 0, (int)size);
- update_transform(font);
+ face_set_size(font->faces[i], size);
}
}