changeset 20294:4d7c8478e523

Move base point calculation to a separate function. Will be reused soon.
author eugeni
date Wed, 18 Oct 2006 18:33:19 +0000
parents 1e953ab6c621
children 49865cf70233
files libass/ass_render.c
diffstat 1 files changed, 41 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libass/ass_render.c	Wed Oct 18 17:57:00 2006 +0000
+++ b/libass/ass_render.c	Wed Oct 18 18:33:19 2006 +0000
@@ -1556,6 +1556,42 @@
 }
 
 /**
+ * \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
  * Process event, appending resulting ass_image_t's to images_root.
@@ -1788,33 +1824,12 @@
 
 	// 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)