X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=libhb%2Fmuxmp4.c;h=1264f9b56b8824e58ba005916fd7004fa58a04a9;hb=033e32de9c380f54c7d1362a3979da205ebc3a29;hp=56400f03d97f59564a9389b11b2860b8cba99719;hpb=ea5b0b011612cc4cdd321e22fc2b88fb7c1bc632;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/libhb/muxmp4.c b/libhb/muxmp4.c index 56400f03..1264f9b5 100644 --- a/libhb/muxmp4.c +++ b/libhb/muxmp4.c @@ -451,7 +451,7 @@ static int MP4Init( hb_mux_object_t * m ) MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.dataReferenceIndex", 1); MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.horizontalJustification", 1); - MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.verticalJustification", 0); + MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.verticalJustification", 255); MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.bgColorAlpha", 255); @@ -554,7 +554,7 @@ static void hb_makestylerecord( stylerecord **stack, static void hb_makestyleatom( stylerecord *record, uint8_t *style) { uint8_t face = 1; - hb_log("Made style '%s' from %d to %d\n", + hb_deep_log(3, "Made style '%s' from %d to %d", record->style == ITALIC ? "Italic" : record->style == BOLD ? "Bold" : "Underline", record->start, record->stop); switch( record->style ) @@ -599,10 +599,21 @@ static void hb_muxmp4_process_subtitle_style( uint8_t *input, uint8_t *reader = input; uint8_t *writer = output; uint8_t stylecount = 0; - + uint16_t utf8_count = 0; // utf8 count from start of subtitle stylerecord *stylestack = NULL; + stylerecord *oldrecord = NULL; while(*reader != '\0') { + if( ( *reader & 0xc0 ) == 0x80 ) + { + /* + * Track the utf8_count when doing markup so that we get the tx3g stops + * based on UTF8 chr counts rather than bytes. + */ + utf8_count++; + hb_deep_log( 3, "MuxMP4: Counted %d UTF-8 chrs within subtitle so far", + utf8_count); + } if (*reader == '<') { /* * possible markup, peek at the next chr @@ -611,7 +622,7 @@ static void hb_muxmp4_process_subtitle_style( uint8_t *input, case 'i': if (*(reader+2) == '>') { reader += 3; - hb_makestylerecord(&stylestack, ITALIC, writer-output); + hb_makestylerecord(&stylestack, ITALIC, (writer - output - utf8_count)); } else { *writer++ = *reader++; } @@ -619,7 +630,7 @@ static void hb_muxmp4_process_subtitle_style( uint8_t *input, case 'b': if (*(reader+2) == '>') { reader += 3; - hb_makestylerecord(&stylestack, BOLD, writer-output); + hb_makestylerecord(&stylestack, BOLD, (writer - output - utf8_count)); } else { *writer++ = *reader++; } @@ -627,7 +638,7 @@ static void hb_muxmp4_process_subtitle_style( uint8_t *input, case 'u': if (*(reader+2) == '>') { reader += 3; - hb_makestylerecord(&stylestack, UNDERLINE, writer-output); + hb_makestylerecord(&stylestack, UNDERLINE, (writer - output - utf8_count)); } else { *writer++ = *reader++; } @@ -636,15 +647,45 @@ static void hb_muxmp4_process_subtitle_style( uint8_t *input, switch(*(reader+2)) { case 'i': if (*(reader+3) == '>') { + /* + * Check whether we then immediately start more markup of the same type, if so then + * lets not close it now and instead continue this markup. + */ + if ((*(reader+4) && *(reader+4) == '<') && + (*(reader+5) && *(reader+5) == 'i') && + (*(reader+6) && *(reader+6) == '>')) { + /* + * Opening italics right after, so don't close off these italics. + */ + hb_deep_log(3, "Joining two sets of italics"); + reader += (4 + 3); + continue; + } + + + if ((*(reader+4) && *(reader+4) == ' ') && + (*(reader+5) && *(reader+5) == '<') && + (*(reader+6) && *(reader+6) == 'i') && + (*(reader+7) && *(reader+7) == '>')) { + /* + * Opening italics right after, so don't close off these italics. + */ + hb_deep_log(3, "Joining two sets of italics (plus space)"); + reader += (4 + 4); + *writer++ = ' '; + continue; + } if (stylestack && stylestack->style == ITALIC) { uint8_t style_record[12]; - stylestack->stop = writer - output; + stylestack->stop = writer - output - utf8_count; hb_makestyleatom(stylestack, style_record); memcpy(style + 10 + (12 * stylecount), style_record, 12); stylecount++; + oldrecord = stylestack; stylestack = stylestack->next; + free(oldrecord); } else { hb_error("Mismatched Subtitle markup '%s'", input); } @@ -657,13 +698,14 @@ static void hb_muxmp4_process_subtitle_style( uint8_t *input, if (*(reader+3) == '>') { if (stylestack && stylestack->style == BOLD) { uint8_t style_record[12]; - stylestack->stop = writer - output; + stylestack->stop = writer - output - utf8_count; hb_makestyleatom(stylestack, style_record); memcpy(style + 10 + (12 * stylecount), style_record, 12); stylecount++; - + oldrecord = stylestack; stylestack = stylestack->next; + free(oldrecord); } else { hb_error("Mismatched Subtitle markup '%s'", input); } @@ -677,13 +719,15 @@ static void hb_muxmp4_process_subtitle_style( uint8_t *input, if (*(reader+3) == '>') { if (stylestack && stylestack->style == UNDERLINE) { uint8_t style_record[12]; - stylestack->stop = writer - output; + stylestack->stop = writer - output - utf8_count; hb_makestyleatom(stylestack, style_record); memcpy(style + 10 + (12 * stylecount), style_record, 12); stylecount++; + oldrecord = stylestack; stylestack = stylestack->next; + free(oldrecord); } else { hb_error("Mismatched Subtitle markup '%s'", input); } @@ -904,8 +948,6 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, (float)buf->start / 90000, buf->start, buf->stop, (buf->stop - buf->start), buffer); - hb_log("MuxMP4: sub len: %d, style_len %d", buffersize, stylesize); - /* Write the subtitle sample */ memcpy( output + 2, buffer, buffersize ); memcpy( output + 2 + buffersize, styleatom, stylesize); @@ -925,7 +967,6 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, } mux_data->sum_dur += (buf->stop - buf->start); - hb_deep_log(3, "MuxMP4:Total time elapsed:%"PRId64, mux_data->sum_dur); } } else