[MPlayer-cvslog] r21630 - in trunk/libass: ass_font.c ass_font.h ass_render.c
eugeni
subversion at mplayerhq.hu
Sat Dec 16 20:17:51 CET 2006
Author: eugeni
Date: Sat Dec 16 20:17:50 2006
New Revision: 21630
Modified:
trunk/libass/ass_font.c
trunk/libass/ass_font.h
trunk/libass/ass_render.c
Log:
Move ascender, descender, and kerning computation to ass_font.c.
Modified: trunk/libass/ass_font.c
==============================================================================
--- trunk/libass/ass_font.c (original)
+++ trunk/libass/ass_font.c Sat Dec 16 20:17:50 2006
@@ -178,6 +178,24 @@
}
#endif
+void ass_font_get_asc_desc(ass_font_t* font, uint32_t ch, int* asc, int* desc)
+{
+ FT_Face face = font->face;
+ if (FT_Get_Char_Index(face, ch)) {
+ int v, v2;
+ v = face->size->metrics.ascender;
+ v2 = FT_MulFix(face->bbox.yMax, face->size->metrics.y_scale);
+ *asc = (v > v2 * 0.9) ? v : v2;
+
+ v = - face->size->metrics.descender;
+ v2 = - FT_MulFix(face->bbox.yMin, face->size->metrics.y_scale);
+ *desc = (v > v2 * 0.9) ? v : v2;
+ return;
+ }
+
+ *asc = *desc = 0;
+}
+
FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch)
{
int error;
@@ -226,6 +244,20 @@
return glyph;
}
+FT_Vector ass_font_get_kerning(ass_font_t* font, uint32_t c1, uint32_t c2)
+{
+ FT_Vector v = {0, 0};
+ int i1, i2;
+
+ if (!FT_HAS_KERNING(font->face))
+ return v;
+ i1 = FT_Get_Char_Index(font->face, c1);
+ i2 = FT_Get_Char_Index(font->face, c2);
+ if (i1 && i2)
+ FT_Get_Kerning(font->face, i1, i2, FT_KERNING_DEFAULT, &v);
+ return v;
+}
+
void ass_font_free(ass_font_t* font)
{
if (font->face) FT_Done_Face(font->face);
Modified: trunk/libass/ass_font.h
==============================================================================
--- trunk/libass/ass_font.h (original)
+++ trunk/libass/ass_font.h Sat Dec 16 20:17:50 2006
@@ -48,7 +48,9 @@
ass_font_t* ass_font_new(ass_library_t* library, FT_Library ftlibrary, void* fc_priv, ass_font_desc_t* desc);
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_Vector ass_font_get_kerning(ass_font_t* font, uint32_t c1, uint32_t c2);
void ass_font_free(ass_font_t* font);
#endif
Modified: trunk/libass/ass_render.c
==============================================================================
--- trunk/libass/ass_render.c (original)
+++ trunk/libass/ass_render.c Sat Dec 16 20:17:50 2006
@@ -1485,26 +1485,6 @@
}
}
-static int get_face_ascender(FT_Face face)
-{
- int v = face->size->metrics.ascender;
- int v2 = FT_MulFix(face->bbox.yMax, face->size->metrics.y_scale);
- if (v > v2 * 0.9)
- return v;
- else
- return v2;
-}
-
-static int get_face_descender(FT_Face face)
-{
- int v = - face->size->metrics.descender;
- int v2 = - FT_MulFix(face->bbox.yMin, face->size->metrics.y_scale);
- if (v > v2 * 0.9)
- return v;
- else
- return v2;
-}
-
/**
* \brief Calculate base point for positioning and rotation
* \param bbox text bbox
@@ -1549,8 +1529,6 @@
static int ass_render_event(ass_event_t* event, event_images_t* event_images)
{
char* p;
- FT_UInt glyph_index;
- FT_Bool use_kerning;
FT_UInt previous;
FT_UInt num_glyphs;
FT_Vector pen;
@@ -1596,19 +1574,15 @@
if (code == 0)
break;
- use_kerning = FT_HAS_KERNING(render_context.font->face);
-
if (text_info.length >= MAX_GLYPHS) {
mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_MAX_GLYPHS_Reached,
(int)(event - frame_context.track->events), event->Start, event->Duration, event->Text);
break;
}
- glyph_index = FT_Get_Char_Index( render_context.font->face, code);
-
- if ( use_kerning && previous && glyph_index ) {
+ if ( previous && code ) {
FT_Vector delta;
- FT_Get_Kerning( render_context.font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta );
+ delta = ass_font_get_kerning(render_context.font, previous, code);
pen.x += delta.x * render_context.scale_x;
pen.y += delta.y * render_context.scale_y;
}
@@ -1644,9 +1618,8 @@
FT_Glyph_Get_CBox( text_info.glyphs[text_info.length].glyph, FT_GLYPH_BBOX_PIXELS, &(text_info.glyphs[text_info.length].bbox) );
}
-
- previous = glyph_index;
-
+ previous = code;
+
text_info.glyphs[text_info.length].symbol = code;
text_info.glyphs[text_info.length].linebreak = 0;
for (i = 0; i < 4; ++i) {
@@ -1657,11 +1630,14 @@
text_info.glyphs[text_info.length].effect_type = render_context.effect_type;
text_info.glyphs[text_info.length].effect_timing = render_context.effect_timing;
text_info.glyphs[text_info.length].effect_skip_timing = render_context.effect_skip_timing;
- text_info.glyphs[text_info.length].asc = get_face_ascender(render_context.font->face);
- text_info.glyphs[text_info.length].desc = get_face_descender(render_context.font->face);
text_info.glyphs[text_info.length].be = render_context.be;
text_info.glyphs[text_info.length].shadow = render_context.shadow;
text_info.glyphs[text_info.length].frz = render_context.rotation;
+ ass_font_get_asc_desc(render_context.font, code,
+ &text_info.glyphs[text_info.length].asc,
+ &text_info.glyphs[text_info.length].desc);
+
+ printf("asc = %d, desc = %d \n", text_info.glyphs[text_info.length].asc, text_info.glyphs[text_info.length].desc);
text_info.length++;
More information about the MPlayer-cvslog
mailing list