Changeset 343
- Timestamp:
- 02/15/07 15:11:35 (2 years ago)
- Files:
-
- trunk/SSADocument.m (modified) (1 diff)
- trunk/SSARenderCodec.m (modified) (5 diffs)
- trunk/SSATagParsing.m.rl (modified) (1 diff)
- trunk/SubImport.mm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/SSADocument.m
r342 r343 551 551 552 552 err=AddMediaSample(theMedia,sampleHndl,0,sampleLen, p->end_time - p->begin_time,(SampleDescriptionHandle)textDesc, 1, 0, &sampleTime); 553 if (err != noErr) { NSLog(@"error adding %d-%d",p->begin_time, p->end_time); err = GetMoviesError(); goto loopend;}553 if (err != noErr) {err = GetMoviesError(); NSLog(@"external SSA: error %d adding %d-%d line",err, p->begin_time, p->end_time); goto loopend;} 554 554 555 555 ConvertTimeScale(&movieStartTime, movieTimeScale); 556 556 557 557 err = InsertMediaIntoTrack(theTrack, movieStartTime.value.lo, sampleTime, p->end_time - p->begin_time, fixed1); 558 if (err != noErr) { err = GetMoviesError(); goto bail;}558 if (err != noErr) {goto loopend;} 559 559 560 560 loopend: 561 err = noErr; 561 562 DisposeHandle(sampleHndl); 562 563 } trunk/SSARenderCodec.m
r342 r343 68 68 OSStatus err; 69 69 70 //[[NSColor redColor] set];71 //NSBezierPath *path = [NSBezierPath bezierPath];72 70 err=ATSUGetGlyphBounds(re->layout,baseX,FloatToFixed(iheight) - baseY,breaks[i],end-breaks[i],kATSUseDeviceOrigins,1,&trap,&trapCount); 73 71 … … 76 74 77 75 baseY += ascent + descent; 78 /* 79 [path moveToPoint:np(trap.lowerLeft)]; 80 [path lineToPoint:np(trap.lowerRight)]; 81 [path lineToPoint:np(trap.upperRight)]; 82 [path lineToPoint:np(trap.upperLeft)]; 83 [path closePath]; 84 [path stroke]; 85 */ 76 86 77 rect.bottom = MAX(trap.lowerLeft.y, trap.lowerRight.y); 87 78 rect.left = MIN(trap.lowerLeft.x, trap.upperLeft.x); … … 166 157 break; 167 158 case S_MiddleAlign: // center 168 penY = (lastCenterPenY!=-1)?lastCenterPenY:(FloatToFixed(( cHeight- FixedToFloat(total)) / 2.)); direction = -1;159 penY = (lastCenterPenY!=-1)?lastCenterPenY:(FloatToFixed((ssa->resY - FixedToFloat(total)) / 2.)); direction = -1; 169 160 lstart = 0; lend = breakCount+1; lstep = 1; 170 161 storePenY = &lastCenterPenY; … … 185 176 GetTypographicRectangleForLayout(re,breaks,breakCount,&imageHeight,&imageWidth,penX,penY,ssa->resY); 186 177 187 storePenY = &ignoredPenY;188 178 penX = IntToFixed(re->posx); 189 179 penY = FloatToFixed((ssa->resY - re->posy)); 190 /* 191 NSBezierPath *posPath = [NSBezierPath bezierPath]; 192 [[NSColor redColor] set]; 193 [posPath setLineWidth:2.5]; 194 [posPath moveToPoint:NSMakePoint(re->posx,0)]; 195 [posPath lineToPoint:NSMakePoint(re->posx,ssa->resY)]; 196 [posPath moveToPoint:NSMakePoint(0,re->posy)]; 197 [posPath lineToPoint:NSMakePoint(ssa->resX,re->posy)]; 198 [posPath closePath]; 199 [posPath stroke]; 200 */ 180 // NSLog(@"pos (%d,%d) w %d (image: %f, %f)",re->posx,re->posy,re->usablewidth,FixedToFloat(imageWidth),FixedToFloat(imageHeight)); 201 181 switch(re->halign) { 202 182 case S_CenterAlign: … … 217 197 direction = 1; 218 198 lstart = breakCount; lend = -1; lstep = -1; 199 storePenY = &ignoredPenY; 219 200 } 220 201 trunk/SSATagParsing.m.rl
r342 r343 541 541 542 542 flag = ([01] % {unichar fl = *(p-1); if (flag == '0' || flag == '1') flag = fl - '0';})? > {flag = 1;}; 543 num_ = digit+('.' digit*)?;543 num_ = "-"? digit* ('.' digit*)?; 544 544 num = num_ > {numbegin = p;} % {num = [[NSString stringWithCharacters:numbegin length:p-numbegin] doubleValue];}; 545 545 546 intnum = digit*> {intbegin = p;} % {inum = [[NSString stringWithCharacters:intbegin length:p-intbegin] intValue];};547 548 color = "&H" xdigit*> {intbegin = p;} % color_end "&";546 intnum = "-"? (digit*) > {intbegin = p;} % {inum = [[NSString stringWithCharacters:intbegin length:p-intbegin] intValue];}; 547 548 color = ("H"|"&"){,2} (xdigit*) > {intbegin = p;} % color_end "&"; 549 549 550 550 cmd_specific = (("pos(" [^)]+ > pos_begin ")" % pos_end) trunk/SubImport.mm
r342 r343 12 12 #import "Categories.h" 13 13 #include "CommonUtils.h" 14 15 //#define SS_DEBUG 14 16 15 17 // if the subtitle filename is something like title.en.srt or movie.fre.srt … … 405 407 unsigned min_allowed = finished ? 1 : 2; 406 408 if (num < min_allowed) return; 407 unsigned times[num*2 +1], last_last_end = 0;409 unsigned times[num*2], last_last_end = 0; 408 410 SubLine *slines[num], *last=nil; 409 411 bool last_has_invalid_end = false, all_overlap = true; … … 411 413 [lines sortUsingFunction:cmp_line context:nil]; 412 414 [lines getObjects:slines]; 413 // NSLog(@"pre - %@",lines); 414 415 #ifdef SS_DEBUG 416 NSLog(@"pre - %@",lines); 417 #endif 415 418 //leave early if all subtitle lines overlap 416 419 if (!finished) { … … 436 439 times[i*2+1] = slines[i]->end_time; 437 440 } 438 439 times[num * 2] = times[num * 2 - 1]; 440 441 441 442 qsort(times, num*2, sizeof(unsigned), cmp_uint); 442 443 443 444 for (int i=0;i < num*2; i++) { 444 445 if (i > 0 && times[i-1] == times[i]) continue; 445 NSMutableString *accum = [NSMutableString string];446 unsigned start = times[i], last_end = start, next_start= slines[num-1]->begin_time, end = start;447 bool startedOutput = false, finishedOutput= false;446 NSMutableString *accum = nil; 447 unsigned start = times[i], last_end = start, next_start=times[num*2-1], end = start; 448 bool finishedOutput = false, is_last_line = false; 448 449 449 450 // Add on packets until we find one that marks it ending (by starting later) 450 451 // ...except if we know this is the last input packet from the stream, then we have to explicitly flush it 451 if (finished && i >= (num*2)-2) finishedOutput = true;452 if (finished && (times[i] == slines[num-1]->begin_time || times[i] == slines[num-1]->end_time)) finishedOutput = is_last_line = true; 452 453 453 454 for (int j=0; j < num; j++) { 454 455 if (isinrange(times[i], slines[j]->begin_time, slines[j]->end_time)) { 455 unsigned ns = slines[j]->end_time;456 456 457 457 // find the next line that starts after this one 458 if (j != num-1) 458 if (j != num-1) { 459 unsigned ns = slines[j]->end_time; 459 460 for (int h = j; h < num; h++) if (slines[h]->begin_time != slines[j]->begin_time) {ns = slines[h]->begin_time; break;} 461 next_start = MIN(next_start, ns); 462 } else next_start = slines[j]->end_time; 460 463 461 464 last_end = MAX(slines[j]->end_time, last_end); 462 next_start = MIN(next_start, ns); 463 [accum appendString:slines[j]->line]; 464 startedOutput = true; 465 if (accum) [accum appendString:slines[j]->line]; else accum = [slines[j]->line mutableCopy]; 465 466 } else if (j == num-1) finishedOutput = true; 466 467 } 467 468 468 if ( finishedOutput && startedOutput) {469 if (accum && finishedOutput) { 469 470 [accum deleteCharactersInRange:NSMakeRange([accum length] - 1, 1)]; // delete last newline 470 // NSLog(@"%d - %d %d",start,last_end,next_start); 471 #ifdef SS_DEBUG 472 NSLog(@"%d - %d %d",start,last_end,next_start); 473 #endif 471 474 if (last_has_invalid_end) { 472 475 if (last_end < next_start) { … … 479 482 end = last_end; 480 483 last_has_invalid_end = false; 481 if (last_end > next_start ) last_has_invalid_end = true;484 if (last_end > next_start && !is_last_line) last_has_invalid_end = true; 482 485 SubLine *event = [[SubLine alloc] initWithLine:accum start:start end:end]; 483 486 … … 492 495 last->end_time = slines[num-1]->begin_time; 493 496 } 494 // NSLog(@"out - %@",outpackets); 495 497 #ifdef SS_DEBUG 498 NSLog(@"out - %@",outpackets); 499 #endif 500 496 501 if (finished) [lines removeAllObjects]; 497 502 else { … … 502 507 } 503 508 } 504 // NSLog(@"post - %@",lines); 509 #ifdef SS_DEBUG 510 NSLog(@"post - %@",lines); 511 #endif 505 512 } 506 513
