comparison libass/ass_render.c @ 19538:ed0ae2df0fe8

Add right and left margins support to libass. Add ability to not use margins even when they are available.
author eugeni
date Sat, 26 Aug 2006 18:24:37 +0000
parents 4440aa9939dc
children 64009ae411fb
comparison
equal deleted inserted replaced
19537:45e1650f9ad5 19538:ed0ae2df0fe8
115 // frame-global data 115 // frame-global data
116 typedef struct frame_context_s { 116 typedef struct frame_context_s {
117 ass_instance_t* ass_priv; 117 ass_instance_t* ass_priv;
118 int width, height; // screen dimensions 118 int width, height; // screen dimensions
119 int orig_height; // frame height ( = screen height - margins ) 119 int orig_height; // frame height ( = screen height - margins )
120 int orig_width; // frame width ( = screen width - margins )
120 ass_track_t* track; 121 ass_track_t* track;
121 int add_bottom_margin; // additional margin, used to shift subtitles in case of collision 122 int add_bottom_margin; // additional margin, used to shift subtitles in case of collision
122 int add_top_margin; 123 int add_top_margin;
123 long long time; // frame's timestamp, ms 124 long long time; // frame's timestamp, ms
124 double font_scale_x; // x scale applied to all glyphs to preserve text aspect ratio 125 double font_scale_x; // x scale applied to all glyphs to preserve text aspect ratio
138 if (!track->PlayResX && !track->PlayResY) { 139 if (!track->PlayResX && !track->PlayResY) {
139 mp_msg(MSGT_GLOBAL, MSGL_WARN, "Neither PlayResX nor PlayResY defined. Assuming 384x288. \n"); 140 mp_msg(MSGT_GLOBAL, MSGL_WARN, "Neither PlayResX nor PlayResY defined. Assuming 384x288. \n");
140 track->PlayResX = 384; 141 track->PlayResX = 384;
141 track->PlayResY = 288; 142 track->PlayResY = 288;
142 } else { 143 } else {
143 double orig_aspect = (global_settings->aspect * frame_context.height) / frame_context.orig_height; 144 double orig_aspect = (global_settings->aspect * frame_context.height * frame_context.orig_width) /
145 frame_context.orig_height / frame_context.width;
144 if (!track->PlayResY) { 146 if (!track->PlayResY) {
145 track->PlayResY = track->PlayResX / orig_aspect + .5; 147 track->PlayResY = track->PlayResX / orig_aspect + .5;
146 mp_msg(MSGT_GLOBAL, MSGL_WARN, "PlayResY undefined, setting %d \n", track->PlayResY); 148 mp_msg(MSGT_GLOBAL, MSGL_WARN, "PlayResY undefined, setting %d \n", track->PlayResY);
147 } else if (!track->PlayResX) { 149 } else if (!track->PlayResX) {
148 track->PlayResX = track->PlayResY * orig_aspect + .5; 150 track->PlayResX = track->PlayResY * orig_aspect + .5;
408 410
409 /** 411 /**
410 * \brief Mapping between script and screen coordinates 412 * \brief Mapping between script and screen coordinates
411 */ 413 */
412 static int x2scr(int x) { 414 static int x2scr(int x) {
413 return x*frame_context.width / frame_context.track->PlayResX; 415 return x*frame_context.width / frame_context.track->PlayResX + global_settings->left_margin;
414 } 416 }
415 /** 417 /**
416 * \brief Mapping between script and screen coordinates 418 * \brief Mapping between script and screen coordinates
417 */ 419 */
418 static int y2scr(int y) { 420 static int y2scr(int y) {
419 return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin; 421 return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin;
420 } 422 }
421 // the same for toptitles 423 // the same for toptitles
422 static int y2scr_top(int y) { 424 static int y2scr_top(int y) {
423 return y * frame_context.orig_height / frame_context.track->PlayResY; 425 if (global_settings->use_margins)
426 return y * frame_context.orig_height / frame_context.track->PlayResY;
427 else
428 return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin;
424 } 429 }
425 // the same for subtitles 430 // the same for subtitles
426 static int y2scr_sub(int y) { 431 static int y2scr_sub(int y) {
427 return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin + global_settings->bottom_margin; 432 if (global_settings->use_margins)
433 return y * frame_context.orig_height / frame_context.track->PlayResY +
434 global_settings->top_margin + global_settings->bottom_margin;
435 else
436 return y * frame_context.orig_height / frame_context.track->PlayResY + global_settings->top_margin;
428 } 437 }
429 438
430 static void vmirror_bbox(FT_BBox* orig, FT_BBox* pbbox) { 439 static void vmirror_bbox(FT_BBox* orig, FT_BBox* pbbox) {
431 pbbox->xMin = orig->xMin; 440 pbbox->xMin = orig->xMin;
432 pbbox->xMax = orig->xMax; 441 pbbox->xMax = orig->xMax;
1743 return 1; // library not initialized 1752 return 1; // library not initialized
1744 1753
1745 frame_context.ass_priv = priv; 1754 frame_context.ass_priv = priv;
1746 frame_context.width = global_settings->frame_width; 1755 frame_context.width = global_settings->frame_width;
1747 frame_context.height = global_settings->frame_height; 1756 frame_context.height = global_settings->frame_height;
1757 frame_context.orig_width = global_settings->frame_width - global_settings->left_margin - global_settings->right_margin;
1748 frame_context.orig_height = global_settings->frame_height - global_settings->top_margin - global_settings->bottom_margin; 1758 frame_context.orig_height = global_settings->frame_height - global_settings->top_margin - global_settings->bottom_margin;
1749 frame_context.track = track; 1759 frame_context.track = track;
1750 frame_context.add_bottom_margin = 0; 1760 frame_context.add_bottom_margin = 0;
1751 frame_context.add_top_margin = 0; 1761 frame_context.add_top_margin = 0;
1752 frame_context.time = now; 1762 frame_context.time = now;