comparison libass/ass_render.c @ 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
comparison
equal deleted inserted replaced
20293:1e953ab6c621 20294:4d7c8478e523
1554 else 1554 else
1555 return v2; 1555 return v2;
1556 } 1556 }
1557 1557
1558 /** 1558 /**
1559 * \brief Calculate base point for positioning and rotation
1560 * \param bbox text bbox
1561 * \param alignment alignment
1562 * \param bx, by out: base point coordinates
1563 */
1564 static void get_base_point(FT_BBox bbox, int alignment, int* bx, int* by)
1565 {
1566 const int halign = alignment & 3;
1567 const int valign = alignment & 12;
1568 if (bx)
1569 switch(halign) {
1570 case HALIGN_LEFT:
1571 *bx = bbox.xMin;
1572 break;
1573 case HALIGN_CENTER:
1574 *bx = (bbox.xMax + bbox.xMin) / 2;
1575 break;
1576 case HALIGN_RIGHT:
1577 *bx = bbox.xMax;
1578 break;
1579 }
1580 if (by)
1581 switch(valign) {
1582 case VALIGN_TOP:
1583 *by = bbox.yMin;
1584 break;
1585 case VALIGN_CENTER:
1586 *by = (bbox.yMax + bbox.yMin) / 2;
1587 break;
1588 case VALIGN_SUB:
1589 *by = bbox.yMax;
1590 break;
1591 }
1592 }
1593
1594 /**
1559 * \brief Main ass rendering function, glues everything together 1595 * \brief Main ass rendering function, glues everything together
1560 * \param event event to render 1596 * \param event event to render
1561 * Process event, appending resulting ass_image_t's to images_root. 1597 * Process event, appending resulting ass_image_t's to images_root.
1562 */ 1598 */
1563 static int ass_render_event(ass_event_t* event, event_images_t* event_images) 1599 static int ass_render_event(ass_event_t* event, event_images_t* event_images)
1786 device_y = y2scr(render_context.clip_y1 - render_context.scroll_shift); 1822 device_y = y2scr(render_context.clip_y1 - render_context.scroll_shift);
1787 } 1823 }
1788 1824
1789 // positioned events are totally different 1825 // positioned events are totally different
1790 if (render_context.evt_type == EVENT_POSITIONED) { 1826 if (render_context.evt_type == EVENT_POSITIONED) {
1791 int align_shift_x = 0; 1827 int base_x = 0;
1792 int align_shift_y = 0; 1828 int base_y = 0;
1793 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "positioned event at %d, %d\n", render_context.pos_x, render_context.pos_y); 1829 mp_msg(MSGT_GLOBAL, MSGL_DBG2, "positioned event at %d, %d\n", render_context.pos_x, render_context.pos_y);
1794 switch(halign) { 1830 get_base_point(bbox, alignment, &base_x, &base_y);
1795 case HALIGN_LEFT: 1831 device_x = x2scr(render_context.pos_x) - base_x;
1796 align_shift_x = - bbox.xMin; 1832 device_y = y2scr(render_context.pos_y) - base_y;
1797 break;
1798 case HALIGN_CENTER:
1799 align_shift_x = - (bbox.xMax + bbox.xMin) /2;
1800 break;
1801 case HALIGN_RIGHT:
1802 align_shift_x = - bbox.xMax;
1803 break;
1804 }
1805 switch(valign) {
1806 case VALIGN_TOP:
1807 align_shift_y = - bbox.yMin;
1808 break;
1809 case VALIGN_CENTER:
1810 align_shift_y = - (bbox.yMax + bbox.yMin) /2;
1811 break;
1812 case VALIGN_SUB:
1813 align_shift_y = - bbox.yMax;
1814 break;
1815 }
1816 device_x = x2scr(render_context.pos_x) + align_shift_x;
1817 device_y = y2scr(render_context.pos_y) + align_shift_y;
1818 } 1833 }
1819 1834
1820 // fix clip coordinates (they depend on alignment) 1835 // fix clip coordinates (they depend on alignment)
1821 render_context.clip_x0 = x2scr(render_context.clip_x0); 1836 render_context.clip_x0 = x2scr(render_context.clip_x0);
1822 render_context.clip_x1 = x2scr(render_context.clip_x1); 1837 render_context.clip_x1 = x2scr(render_context.clip_x1);