From 5b5798f039283751ea2edab492429b4814956f9f Mon Sep 17 00:00:00 2001 From: eugeni Date: Wed, 18 Oct 2006 18:33:19 +0000 Subject: Move base point calculation to a separate function. Will be reused soon. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@20300 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libass/ass_render.c | 67 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 26 deletions(-) (limited to 'libass') diff --git a/libass/ass_render.c b/libass/ass_render.c index ce6dae3a0c..d322814ce9 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -1555,6 +1555,42 @@ static int get_face_descender(FT_Face face) return v2; } +/** + * \brief Calculate base point for positioning and rotation + * \param bbox text bbox + * \param alignment alignment + * \param bx, by out: base point coordinates + */ +static void get_base_point(FT_BBox bbox, int alignment, int* bx, int* by) +{ + const int halign = alignment & 3; + const int valign = alignment & 12; + if (bx) + switch(halign) { + case HALIGN_LEFT: + *bx = bbox.xMin; + break; + case HALIGN_CENTER: + *bx = (bbox.xMax + bbox.xMin) / 2; + break; + case HALIGN_RIGHT: + *bx = bbox.xMax; + break; + } + if (by) + switch(valign) { + case VALIGN_TOP: + *by = bbox.yMin; + break; + case VALIGN_CENTER: + *by = (bbox.yMax + bbox.yMin) / 2; + break; + case VALIGN_SUB: + *by = bbox.yMax; + break; + } +} + /** * \brief Main ass rendering function, glues everything together * \param event event to render @@ -1788,33 +1824,12 @@ static int ass_render_event(ass_event_t* event, event_images_t* event_images) // positioned events are totally different if (render_context.evt_type == EVENT_POSITIONED) { - int align_shift_x = 0; - int align_shift_y = 0; + int base_x = 0; + int base_y = 0; mp_msg(MSGT_GLOBAL, MSGL_DBG2, "positioned event at %d, %d\n", render_context.pos_x, render_context.pos_y); - switch(halign) { - case HALIGN_LEFT: - align_shift_x = - bbox.xMin; - break; - case HALIGN_CENTER: - align_shift_x = - (bbox.xMax + bbox.xMin) /2; - break; - case HALIGN_RIGHT: - align_shift_x = - bbox.xMax; - break; - } - switch(valign) { - case VALIGN_TOP: - align_shift_y = - bbox.yMin; - break; - case VALIGN_CENTER: - align_shift_y = - (bbox.yMax + bbox.yMin) /2; - break; - case VALIGN_SUB: - align_shift_y = - bbox.yMax; - break; - } - device_x = x2scr(render_context.pos_x) + align_shift_x; - device_y = y2scr(render_context.pos_y) + align_shift_y; + get_base_point(bbox, alignment, &base_x, &base_y); + device_x = x2scr(render_context.pos_x) - base_x; + device_y = y2scr(render_context.pos_y) - base_y; } // fix clip coordinates (they depend on alignment) -- cgit v1.2.3