From 3c98cbb3f3ddfc8f116b142567f7a488a07ee790 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sun, 30 Aug 2015 08:23:07 +0200 Subject: [PATCH] Fix for export to DOST time codes - thx Christian :) --- src/Forms/ExportPngXml.cs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Forms/ExportPngXml.cs b/src/Forms/ExportPngXml.cs index f80304943..a013778a7 100644 --- a/src/Forms/ExportPngXml.cs +++ b/src/Forms/ExportPngXml.cs @@ -118,14 +118,19 @@ namespace Nikse.SubtitleEdit.Forms return d; return 25; } + } + + private int MillisecondsToFramesMaxFrameRate(double milliseconds) + { + int frames = (int)Math.Round(milliseconds / (TimeCode.BaseUnit / FrameRate)); + if (frames >= FrameRate) + frames = (int)(FrameRate - 0.01); + return frames; } - private string BdnXmlTimeCode(TimeCode timecode) + private string ToHHMMSSFF(TimeCode timecode) { - var fr = FrameRate; - var tc = new TimeCode(timecode.TotalMilliseconds * (Math.Ceiling(fr) / fr)); - int frames = SubtitleFormat.MillisecondsToFramesMaxFrameRate(tc.Milliseconds); - return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", tc.Hours, tc.Minutes, tc.Seconds, frames); + return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", timecode.Hours, timecode.Minutes, timecode.Seconds, MillisecondsToFramesMaxFrameRate(timecode.Milliseconds)); } private static ContentAlignment GetAlignmentFromParagraph(MakeBitmapParameter p, SubtitleFormat format, Subtitle subtitle) @@ -841,7 +846,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + - "" + Environment.NewLine + + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + @@ -1270,8 +1275,8 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine + if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight) top = param.ScreenHeight - (param.Bitmap.Height / 2); - string startTime = BdnXmlTimeCode(param.P.StartTime); - string endTime = BdnXmlTimeCode(param.P.EndTime); + string startTime = ToHHMMSSFF(param.P.StartTime); + string endTime = ToHHMMSSFF(param.P.EndTime); sb.AppendLine(string.Format(paragraphWriteFormat, numberString, startTime, endTime, Path.GetFileName(fileName), left, top)); param.Saved = true; @@ -1399,8 +1404,8 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine + // // subtitle_exp_0001.png // - sb.AppendLine(""); + sb.AppendLine(""); int x = (width - param.Bitmap.Width) / 2; int y = height - (param.Bitmap.Height + param.BottomMargin);