refactor - add braces

This commit is contained in:
Nikolaj Olsson 2019-01-19 17:39:59 +01:00
parent 21c6910aef
commit 8c9417366a
45 changed files with 2295 additions and 175 deletions

View File

@ -116,8 +116,8 @@ namespace Nikse.SubtitleEdit.Core
public static DvdSubtitleLanguage GetLanguageOrNull(string code)
{
code = ConvertIsoToDvd(code.ToLowerInvariant());
return CompliantLanguagesByCode.GetValueOrNull(code);
var dvdCode = ConvertIsoToDvd(code.ToLowerInvariant());
return CompliantLanguagesByCode.GetValueOrNull(dvdCode);
}
private static string GetNonCompliantLocalLanguageName(string code)

View File

@ -37,15 +37,14 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
if (prev != null)
{
double betweenMilliseconds = p.StartTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds;
if (betweenMilliseconds > 1500)
if (betweenMilliseconds > 1500 || // cannot be quote spanning several lines of more than 1.5 seconds between lines!
// seems to have valid quotes, so no spanning
prev.Text.Replace("<i>", string.Empty).TrimStart().TrimStart('-').TrimStart().StartsWith('"') &&
prev.Text.Replace("</i>", string.Empty).TrimEnd().EndsWith('"') &&
Utilities.CountTagInText(prev.Text, '"') == 2)
{
prev = null; // cannot be quote spanning several lines of more than 1.5 seconds between lines!
}
else if (prev.Text.Replace("<i>", string.Empty).TrimStart().TrimStart('-').TrimStart().StartsWith('"') &&
prev.Text.Replace("</i>", string.Empty).TrimEnd().EndsWith('"') &&
Utilities.CountTagInText(prev.Text, '"') == 2)
{
prev = null; // seems to have valid quotes, so no spanning
prev = null;
}
}

View File

@ -122,9 +122,15 @@ namespace Nikse.SubtitleEdit.Controls
set
{
if (value < ZoomMinimum)
{
value = ZoomMinimum;
}
if (value > ZoomMaximum)
{
value = ZoomMaximum;
}
value = Math.Round(value, 2); // round to prevent accumulated rounding errors
if (Math.Abs(_zoomFactor - value) > 0.01)
{
@ -147,9 +153,15 @@ namespace Nikse.SubtitleEdit.Controls
set
{
if (value < VerticalZoomMinimum)
{
value = VerticalZoomMinimum;
}
if (value > VerticalZoomMaximum)
{
value = VerticalZoomMaximum;
}
value = Math.Round(value, 2); // round to prevent accumulated rounding errors
if (Math.Abs(_verticalZoomFactor - value) > 0.01)
{
@ -237,10 +249,15 @@ namespace Nikse.SubtitleEdit.Controls
{
double endPositionSeconds = value + ((double)Width / _wavePeaks.SampleRate) / _zoomFactor;
if (endPositionSeconds > _wavePeaks.LengthInSeconds)
{
value -= endPositionSeconds - _wavePeaks.LengthInSeconds;
}
}
if (value < 0)
{
value = 0;
}
if (Math.Abs(_startPositionSeconds - value) > 0.01)
{
_startPositionSeconds = value;
@ -352,7 +369,9 @@ namespace Nikse.SubtitleEdit.Controls
_allSelectedParagraphs.Clear();
if (_wavePeaks == null)
{
return;
}
const double additionalSeconds = 15.0; // Helps when scrolling
double startThresholdMilliseconds = (_startPositionSeconds - additionalSeconds) * TimeCode.BaseUnit;
@ -363,27 +382,39 @@ namespace Nikse.SubtitleEdit.Controls
Paragraph p = subtitle.Paragraphs[i];
if (p.StartTime.IsMaxTime)
{
continue;
}
_subtitle.Paragraphs.Add(p);
if (p.EndTime.TotalMilliseconds >= startThresholdMilliseconds && p.StartTime.TotalMilliseconds <= endThresholdMilliseconds)
{
_displayableParagraphs.Add(p);
}
}
Action<int, bool> addSelection = (index, isPrimary) =>
{
Paragraph p = subtitle.GetParagraphOrDefault(index);
if (p == null || p.StartTime.IsMaxTime)
{
return;
}
if (isPrimary)
{
_selectedParagraph = p;
}
_allSelectedParagraphs.Add(p);
};
addSelection(primarySelectedIndex, true);
foreach (int selectedIndex in selectedIndexes)
{
addSelection(selectedIndex, false);
}
}
public void SetPosition(double startPositionSeconds, Subtitle subtitle, double currentVideoPositionSeconds, int subtitleIndex, ListView.SelectedIndexCollection selectedIndexes)
@ -419,7 +450,9 @@ namespace Nikse.SubtitleEdit.Controls
public bool IsSelected(int position)
{
if (position < _lastPosition || position > _nextSelection.End)
{
FindNextSelection(position);
}
_lastPosition = position;
@ -433,7 +466,9 @@ namespace Nikse.SubtitleEdit.Controls
{
SelectionRange range = _ranges[index];
if (range.End >= position && (range.Start < _nextSelection.Start || (range.Start == _nextSelection.Start && range.End > _nextSelection.End)))
{
_nextSelection = range;
}
}
}
@ -490,9 +525,15 @@ namespace Nikse.SubtitleEdit.Controls
{
var offset = (value / baseHeight) * halfWaveformHeight;
if (offset > halfWaveformHeight)
{
offset = halfWaveformHeight;
}
if (offset < -halfWaveformHeight)
{
offset = -halfWaveformHeight;
}
return (float)(halfWaveformHeight - offset);
};
var div = _wavePeaks.SampleRate * _zoomFactor;
@ -503,7 +544,10 @@ namespace Nikse.SubtitleEdit.Controls
int pos1 = pos0;
pos1++;
if (pos1 >= _wavePeaks.Peaks.Count)
{
break;
}
var pos1Weight = pos - pos0;
var pos0Weight = 1F - pos1Weight;
var peak0 = _wavePeaks.Peaks[pos0];
@ -543,14 +587,21 @@ namespace Nikse.SubtitleEdit.Controls
{ // scene change and current pos are the same - draw 2 pixels + current pos dotted
currentPosDone = true;
using (var p = new Pen(Color.AntiqueWhite, 2))
{
graphics.DrawLine(p, pos, 0, pos, Height);
}
using (var p = new Pen(Color.Turquoise, 2) { DashStyle = DashStyle.Dash })
{
graphics.DrawLine(p, currentPositionPos, 0, currentPositionPos, Height);
}
}
else
{
using (var p = new Pen(Color.AntiqueWhite))
{
graphics.DrawLine(p, pos, 0, pos, Height);
}
}
}
}
@ -565,7 +616,9 @@ namespace Nikse.SubtitleEdit.Controls
if (_currentVideoPositionSeconds > 0 && !currentPosDone && currentPositionPos > 0 && currentPositionPos < Width)
{
using (var p = new Pen(Color.Turquoise))
{
graphics.DrawLine(p, currentPositionPos, 0, currentPositionPos, Height);
}
}
// paragraphs
@ -588,7 +641,9 @@ namespace Nikse.SubtitleEdit.Controls
if (currentRegionRight >= 0 && currentRegionLeft <= Width)
{
using (var brush = new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
{
graphics.FillRectangle(brush, currentRegionLeft, 0, currentRegionWidth, graphics.VisibleClipBounds.Height);
}
if (currentRegionWidth > 40)
{
@ -619,14 +674,18 @@ namespace Nikse.SubtitleEdit.Controls
else
{
using (var stringFormat = new StringFormat(StringFormatFlags.DirectionVertical))
{
graphics.DrawString(WaveformNotLoadedText, textFont, textBrush, new PointF(1, 10), stringFormat);
}
}
}
}
if (Focused)
{
using (var p = new Pen(SelectedColor))
{
graphics.DrawRectangle(p, new Rectangle(0, 0, Width - 1, Height - 1));
}
}
//_sw.Stop();
//_ticks.Add(_sw.ElapsedMilliseconds);
@ -688,7 +747,9 @@ namespace Nikse.SubtitleEdit.Controls
position = SecondsToXPosition(seconds);
if (n > 64)
{
graphics.DrawLine(pen, position, imageHeight, position, imageHeight - 5);
}
seconds += 0.5;
position = SecondsToXPosition(seconds);
@ -700,9 +761,15 @@ namespace Nikse.SubtitleEdit.Controls
{
TimeSpan ts = TimeSpan.FromSeconds(seconds + Configuration.Settings.General.CurrentVideoOffsetInMs / TimeCode.BaseUnit);
if (ts.Minutes == 0 && ts.Hours == 0)
{
return ts.Seconds.ToString(CultureInfo.InvariantCulture);
}
if (ts.Hours == 0)
{
return $"{ts.Minutes:00}:{ts.Seconds:00}";
}
return $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}";
}
@ -714,15 +781,21 @@ namespace Nikse.SubtitleEdit.Controls
// background
using (var brush = new SolidBrush(Color.FromArgb(42, 255, 255, 255)))
{
graphics.FillRectangle(brush, currentRegionLeft, 0, currentRegionWidth, graphics.VisibleClipBounds.Height);
}
// left edge
using (var pen = new Pen(new SolidBrush(Color.FromArgb(175, 0, 100, 0))) { DashStyle = DashStyle.Solid, Width = 2 })
{
graphics.DrawLine(pen, currentRegionLeft, 0, currentRegionLeft, graphics.VisibleClipBounds.Height);
}
// right edge
using (var pen = new Pen(new SolidBrush(Color.FromArgb(175, 110, 10, 10))) { DashStyle = DashStyle.Dash, Width = 2 })
{
graphics.DrawLine(pen, currentRegionRight - 1, 0, currentRegionRight - 1, graphics.VisibleClipBounds.Height);
}
using (var font = new Font(Configuration.Settings.General.SubtitleFontName, TextSize, TextBold ? FontStyle.Bold : FontStyle.Regular))
using (var textBrush = new SolidBrush(TextColor))
@ -751,7 +824,10 @@ namespace Nikse.SubtitleEdit.Controls
{
var textSize = graphics.MeasureString(paragraph.Bookmark, font);
if (textSize.Width < 1)
{
textSize = new SizeF(-2, 18); // empty bookmark text
}
graphics.FillRectangle(bookmarkBackBrush, x, y, textSize.Width + 20, textSize.Height + 10);
}
@ -774,7 +850,10 @@ namespace Nikse.SubtitleEdit.Controls
{
string text = HtmlUtil.RemoveHtmlTags(paragraph.Text, true);
if (Configuration.Settings.VideoControls.WaveformUnwrapText)
{
text = text.Replace(Environment.NewLine, " ");
}
DrawParagraphText(graphics, text, font, currentRegionWidth, padding, drawStringOutlined, currentRegionLeft);
}
@ -791,16 +870,26 @@ namespace Nikse.SubtitleEdit.Controls
if (Configuration.Settings.VideoControls.WaveformHideWpmCpsLabels)
{
if (Configuration.Settings.VideoControls.WaveformDrawWpm)
{
text = $"{paragraph.WordsPerMinute:0.00}" + Environment.NewLine + text;
}
if (Configuration.Settings.VideoControls.WaveformDrawCps)
{
text = $"{Utilities.GetCharactersPerSecond(paragraph):0.00}" + Environment.NewLine + text;
}
}
else
{
if (Configuration.Settings.VideoControls.WaveformDrawWpm)
{
text = string.Format(Configuration.Settings.Language.Waveform.WordsMinX, paragraph.WordsPerMinute) + Environment.NewLine + text;
}
if (Configuration.Settings.VideoControls.WaveformDrawCps)
{
text = string.Format(Configuration.Settings.Language.Waveform.CharsSecX, Utilities.GetCharactersPerSecond(paragraph)) + Environment.NewLine + text;
}
}
}
drawStringOutlined(text, currentRegionLeft + padding, Height - 14 - (int)graphics.MeasureString(text, font).Height);
@ -811,9 +900,15 @@ namespace Nikse.SubtitleEdit.Controls
private void DrawParagraphText(Graphics graphics, string text, Font font, int currentRegionWidth, int padding, Action<string, int, int> drawStringOutlined, int currentRegionLeft)
{
if (Configuration.Settings.General.RightToLeftMode && LanguageAutoDetect.CouldBeRightToLeftLanguge(new Subtitle(_displayableParagraphs)))
{
text = Utilities.ReverseStartAndEndingForRightToLeft(text);
}
if (text.Length > 500)
{
text = text.Substring(0, 500); // don't now allow very long texts as they can make SE unresponsive - see https://github.com/SubtitleEdit/subtitleedit/issues/2536
}
int y = padding;
var max = currentRegionWidth - padding - 1;
foreach (var line in text.SplitToLines())
@ -825,11 +920,18 @@ namespace Nikse.SubtitleEdit.Controls
{
text = text.Remove(text.Length - removeLength).TrimEnd() + "…";
if (text.Length > 200)
{
removeLength = 21;
}
else if (text.Length > 100)
{
removeLength = 11;
}
else
{
removeLength = 2;
}
measureResult = graphics.MeasureString(text, font);
}
drawStringOutlined(text, currentRegionLeft + padding, y);
@ -861,7 +963,9 @@ namespace Nikse.SubtitleEdit.Controls
private void WaveformMouseDown(object sender, MouseEventArgs e)
{
if (_wavePeaks == null)
{
return;
}
Paragraph oldMouseDownParagraph = null;
_mouseDownParagraphType = MouseDownParagraphType.None;
@ -878,11 +982,17 @@ namespace Nikse.SubtitleEdit.Controls
if (SetParagrapBorderHit(milliseconds, NewSelectionParagraph))
{
if (_mouseDownParagraph != null)
{
oldMouseDownParagraph = new Paragraph(_mouseDownParagraph);
}
if (_mouseDownParagraphType == MouseDownParagraphType.Start)
{
if (_mouseDownParagraph != null)
{
_mouseDownParagraph.StartTime.TotalMilliseconds = milliseconds;
}
NewSelectionParagraph.StartTime.TotalMilliseconds = milliseconds;
_mouseMoveStartX = e.X;
_mouseMoveEndX = SecondsToXPosition(NewSelectionParagraph.EndTime.TotalSeconds - _startPositionSeconds);
@ -890,7 +1000,10 @@ namespace Nikse.SubtitleEdit.Controls
else
{
if (_mouseDownParagraph != null)
{
_mouseDownParagraph.EndTime.TotalMilliseconds = milliseconds;
}
NewSelectionParagraph.EndTime.TotalMilliseconds = milliseconds;
_mouseMoveStartX = SecondsToXPosition(NewSelectionParagraph.StartTime.TotalSeconds - _startPositionSeconds);
_mouseMoveEndX = e.X;
@ -911,7 +1024,9 @@ namespace Nikse.SubtitleEdit.Controls
{
var prev = _subtitle.Paragraphs[curIdx - 1];
if (prev.EndTime.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines < milliseconds)
{
_mouseDownParagraph.StartTime.TotalMilliseconds = milliseconds;
}
}
else
{
@ -924,7 +1039,9 @@ namespace Nikse.SubtitleEdit.Controls
{
var next = _subtitle.Paragraphs[curIdx + 1];
if (milliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines < next.StartTime.TotalMilliseconds)
{
_mouseDownParagraph.EndTime.TotalMilliseconds = milliseconds;
}
}
else
{
@ -952,7 +1069,10 @@ namespace Nikse.SubtitleEdit.Controls
Cursor = Cursors.Default;
}
if (p == null)
{
SetMinMaxViaSeconds(seconds);
}
NewSelectionParagraph = null;
_mouseMoveStartX = e.X;
_mouseMoveEndX = e.X;
@ -963,7 +1083,9 @@ namespace Nikse.SubtitleEdit.Controls
{
int curIdx = _subtitle.Paragraphs.IndexOf(_mouseDownParagraph);
if (curIdx > 0 && oldMouseDownParagraph != null)
{
_gapAtStart = oldMouseDownParagraph.StartTime.TotalMilliseconds - _subtitle.Paragraphs[curIdx - 1].EndTime.TotalMilliseconds;
}
}
}
else if (_mouseDownParagraphType == MouseDownParagraphType.End)
@ -972,7 +1094,9 @@ namespace Nikse.SubtitleEdit.Controls
{
int curIdx = _subtitle.Paragraphs.IndexOf(_mouseDownParagraph);
if (curIdx >= 0 && curIdx < _subtitle.Paragraphs.Count - 1 && oldMouseDownParagraph != null)
{
_gapAtStart = _subtitle.Paragraphs[curIdx + 1].StartTime.TotalMilliseconds - oldMouseDownParagraph.EndTime.TotalMilliseconds;
}
}
}
_mouseDown = true;
@ -997,9 +1121,14 @@ namespace Nikse.SubtitleEdit.Controls
if (PreventOverlap)
{
if (paragraph.StartTime.TotalMilliseconds <= _wholeParagraphMinMilliseconds)
{
paragraph.StartTime.TotalMilliseconds = _wholeParagraphMinMilliseconds + 1;
}
if (paragraph.EndTime.TotalMilliseconds >= _wholeParagraphMaxMilliseconds)
{
paragraph.EndTime.TotalMilliseconds = _wholeParagraphMaxMilliseconds - 1;
}
}
OnNewSelectionRightClicked.Invoke(this, new ParagraphEventArgs(paragraph));
NewSelectionParagraph = paragraph;
@ -1053,9 +1182,14 @@ namespace Nikse.SubtitleEdit.Controls
}
}
if (prev != null)
{
_wholeParagraphMinMilliseconds = prev.EndTime.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines;
}
if (next != null)
{
_wholeParagraphMaxMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
}
}
}
@ -1119,7 +1253,9 @@ namespace Nikse.SubtitleEdit.Controls
{
bool hit = SetParagrapBorderHit(milliseconds, p);
if (hit)
{
return true;
}
}
return false;
}
@ -1128,7 +1264,9 @@ namespace Nikse.SubtitleEdit.Controls
{
Paragraph p = null;
if (IsParagrapHit(milliseconds, _selectedParagraph))
{
p = _selectedParagraph;
}
if (p == null)
{
@ -1148,7 +1286,9 @@ namespace Nikse.SubtitleEdit.Controls
private bool SetParagrapBorderHit(int milliseconds, Paragraph paragraph)
{
if (paragraph == null)
{
return false;
}
if (IsParagrapBorderStartHit(milliseconds, paragraph.StartTime.TotalMilliseconds))
{
@ -1172,7 +1312,10 @@ namespace Nikse.SubtitleEdit.Controls
get
{
if (ModifierKeys == Keys.Shift)
{
return AllowOverlap;
}
return !AllowOverlap;
}
}
@ -1182,7 +1325,9 @@ namespace Nikse.SubtitleEdit.Controls
private void WaveformMouseMove(object sender, MouseEventArgs e)
{
if (_wavePeaks == null)
{
return;
}
int oldMouseMoveLastX = _mouseMoveLastX;
if (e.X < 0 && _startPositionSeconds > 0.1 && _mouseDown)
@ -1217,7 +1362,9 @@ namespace Nikse.SubtitleEdit.Controls
_mouseMoveLastX = e.X;
if (e.X < 0 || e.X > Width)
{
return;
}
if (e.Button == MouseButtons.None)
{
@ -1225,7 +1372,9 @@ namespace Nikse.SubtitleEdit.Controls
var milliseconds = (int)(seconds * TimeCode.BaseUnit);
if (IsParagrapBorderHit(milliseconds, NewSelectionParagraph))
{
Cursor = Cursors.VSplit;
}
else if (IsParagrapBorderHit(milliseconds, _selectedParagraph) ||
IsParagrapBorderHit(milliseconds, _displayableParagraphs))
{
@ -1239,7 +1388,9 @@ namespace Nikse.SubtitleEdit.Controls
else if (e.Button == MouseButtons.Left)
{
if (oldMouseMoveLastX == e.X)
{
return; // no horizontal movement
}
if (_mouseDown)
{
@ -1254,9 +1405,14 @@ namespace Nikse.SubtitleEdit.Controls
if (_firstMove && Math.Abs(oldMouseMoveLastX - e.X) < Configuration.Settings.General.MinimumMillisecondsBetweenLines && GetParagraphAtMilliseconds(milliseconds) == null)
{
if (_mouseDownParagraphType == MouseDownParagraphType.Start && _prevParagraph != null && Math.Abs(_mouseDownParagraph.StartTime.TotalMilliseconds - _prevParagraph.EndTime.TotalMilliseconds) <= ClosenessForBorderSelection + 15)
{
return; // do not decide which paragraph to move yet
}
if (_mouseDownParagraphType == MouseDownParagraphType.End && _nextParagraph != null && Math.Abs(_mouseDownParagraph.EndTime.TotalMilliseconds - _nextParagraph.StartTime.TotalMilliseconds) <= ClosenessForBorderSelection + 15)
{
return; // do not decide which paragraph to move yet
}
}
if (ModifierKeys != Keys.Alt)
@ -1286,9 +1442,14 @@ namespace Nikse.SubtitleEdit.Controls
if (_mouseDownParagraph.EndTime.TotalMilliseconds - milliseconds > MinimumSelectionMilliseconds)
{
if (AllowMovePrevOrNext)
{
SetMinAndMaxMoveStart();
}
else
{
SetMinAndMax();
}
_mouseDownParagraph.StartTime.TotalMilliseconds = milliseconds;
if (PreventOverlap && _mouseDownParagraph.StartTime.TotalMilliseconds <= _wholeParagraphMinMilliseconds)
{
@ -1317,9 +1478,14 @@ namespace Nikse.SubtitleEdit.Controls
if (milliseconds - _mouseDownParagraph.StartTime.TotalMilliseconds > MinimumSelectionMilliseconds)
{
if (AllowMovePrevOrNext)
{
SetMinAndMaxMoveEnd();
}
else
{
SetMinAndMax();
}
_mouseDownParagraph.EndTime.TotalMilliseconds = milliseconds;
if (PreventOverlap && _mouseDownParagraph.EndTime.TotalMilliseconds >= _wholeParagraphMaxMilliseconds)
{
@ -1386,7 +1552,9 @@ namespace Nikse.SubtitleEdit.Controls
if (NewSelectionParagraph == null && Math.Abs(_mouseMoveEndX - _mouseMoveStartX) > 2)
{
if (AllowNewSelection)
{
NewSelectionParagraph = new Paragraph();
}
}
if (NewSelectionParagraph != null)
@ -1424,7 +1592,9 @@ namespace Nikse.SubtitleEdit.Controls
{
bool hit = IsParagrapBorderHit(milliseconds, p);
if (hit)
{
return true;
}
}
return false;
}
@ -1432,7 +1602,9 @@ namespace Nikse.SubtitleEdit.Controls
private bool IsParagrapBorderHit(int milliseconds, Paragraph paragraph)
{
if (paragraph == null)
{
return false;
}
return IsParagrapBorderStartHit(milliseconds, paragraph.StartTime.TotalMilliseconds) ||
IsParagrapBorderEndHit(milliseconds, paragraph.EndTime.TotalMilliseconds);
@ -1478,7 +1650,9 @@ namespace Nikse.SubtitleEdit.Controls
private void WaveformMouseEnter(object sender, EventArgs e)
{
if (_wavePeaks == null)
{
return;
}
if (_noClear)
{
@ -1504,7 +1678,9 @@ namespace Nikse.SubtitleEdit.Controls
private void WaveformMouseDoubleClick(object sender, MouseEventArgs e)
{
if (_wavePeaks == null)
{
return;
}
_mouseDown = false;
_mouseDownParagraph = null;
@ -1530,7 +1706,9 @@ namespace Nikse.SubtitleEdit.Controls
{
double newStartPos = _startPositionSeconds + (endSeconds - EndPositionSeconds); // move later, so whole selected paragraph is visible
if (newStartPos < seconds) // but only if visibile screen is wide enough
{
_startPositionSeconds = newStartPos;
}
}
}
@ -1541,7 +1719,9 @@ namespace Nikse.SubtitleEdit.Controls
private static bool IsParagrapHit(int milliseconds, Paragraph paragraph)
{
if (paragraph == null)
{
return false;
}
return milliseconds >= paragraph.StartTime.TotalMilliseconds && milliseconds <= paragraph.EndTime.TotalMilliseconds;
}
@ -1613,7 +1793,9 @@ namespace Nikse.SubtitleEdit.Controls
}
if (_mouseDownParagraphType == MouseDownParagraphType.None || _mouseDownParagraphType == MouseDownParagraphType.Whole)
{
OnSingleClick.Invoke(this, new ParagraphEventArgs(RelativeXPositionToSeconds(e.X), null));
}
}
}
}
@ -1621,7 +1803,9 @@ namespace Nikse.SubtitleEdit.Controls
private void WaveformKeyDown(object sender, KeyEventArgs e)
{
if (_wavePeaks == null)
{
return;
}
if (e.Modifiers == Keys.None && e.KeyCode == Keys.Add)
{
@ -1690,9 +1874,14 @@ namespace Nikse.SubtitleEdit.Controls
for (int i = begin; i < _wavePeaks.Peaks.Count; i++)
{
if (i > 0 && i < _wavePeaks.Peaks.Count && _wavePeaks.Peaks[i].Abs <= threshold)
{
hitCount++;
}
else
{
hitCount = 0;
}
if (hitCount > length)
{
double seconds = SampleIndexToSeconds(i - (length / 2));
@ -1700,7 +1889,10 @@ namespace Nikse.SubtitleEdit.Controls
{
StartPositionSeconds = seconds;
if (_startPositionSeconds > 1)
{
StartPositionSeconds -= 1;
}
OnSingleClick?.Invoke(this, new ParagraphEventArgs(seconds, null));
Invalidate();
}
@ -1720,9 +1912,14 @@ namespace Nikse.SubtitleEdit.Controls
for (int i = begin; i > 0; i--)
{
if (i > 0 && i < _wavePeaks.Peaks.Count && _wavePeaks.Peaks[i].Abs <= threshold)
{
hitCount++;
}
else
{
hitCount = 0;
}
if (hitCount > length)
{
double seconds = SampleIndexToSeconds(i + (length / 2));
@ -1730,9 +1927,14 @@ namespace Nikse.SubtitleEdit.Controls
{
StartPositionSeconds = seconds;
if (_startPositionSeconds > 1)
{
StartPositionSeconds -= 1;
}
else
{
StartPositionSeconds = 0;
}
OnSingleClick?.Invoke(this, new ParagraphEventArgs(seconds, null));
Invalidate();
}
@ -1770,14 +1972,20 @@ namespace Nikse.SubtitleEdit.Controls
// just like dragging the slider, which does work without the waveform), but the
// code below doesn't support it, so bail out until someone feels like fixing it.
if (_wavePeaks == null)
{
return;
}
if (ModifierKeys == Keys.Control)
{
if (e.Delta > 0)
{
ZoomIn();
}
else
{
ZoomOut();
}
return;
}
@ -1785,16 +1993,23 @@ namespace Nikse.SubtitleEdit.Controls
if (ModifierKeys == (Keys.Control | Keys.Shift))
{
if (e.Delta > 0)
{
VerticalZoomIn();
}
else
{
VerticalZoomOut();
}
return;
}
int delta = e.Delta;
if (!MouseWheelScrollUpIsForward)
{
delta = delta * -1;
}
if (Locked)
{
OnPositionSelected?.Invoke(this, new ParagraphEventArgs(_currentVideoPositionSeconds + (delta / 256.0), null));
@ -1823,7 +2038,9 @@ namespace Nikse.SubtitleEdit.Controls
}
if (spectrogram == null)
{
return;
}
if (spectrogram.IsLoaded)
{
@ -1845,7 +2062,9 @@ namespace Nikse.SubtitleEdit.Controls
private void InitializeSpectrogramInternal(SpectrogramData spectrogram)
{
if (_spectrogram != null)
{
return;
}
_spectrogram = spectrogram;
Invalidate();
@ -1877,7 +2096,10 @@ namespace Nikse.SubtitleEdit.Controls
{
int length = SecondsToSampleIndex(milliseconds / TimeCode.BaseUnit);
if (length < 9)
{
length = 9;
}
double v = 0;
int count = 0;
for (int i = sampleIndex; i < sampleIndex + length; i++)
@ -1889,7 +2111,10 @@ namespace Nikse.SubtitleEdit.Controls
}
}
if (count == 0)
{
return 0;
}
return v / count;
}
@ -1899,7 +2124,10 @@ namespace Nikse.SubtitleEdit.Controls
double average = 0;
for (int k = begin; k < _wavePeaks.Peaks.Count; k++)
{
average += _wavePeaks.Peaks[k].Abs;
}
average /= _wavePeaks.Peaks.Count - begin;
var maxThreshold = (int)(_wavePeaks.HighestPeak * (maximumVolumePercent / 100.0));

View File

@ -97,9 +97,13 @@ namespace Nikse.SubtitleEdit.Controls
string newText;
if (e.Data.GetDataPresent(DataFormats.UnicodeText))
{
newText = (string)e.Data.GetData(DataFormats.UnicodeText);
}
else
{
newText = (string)e.Data.GetData(DataFormats.Text);
}
if (string.IsNullOrWhiteSpace(Text))
{
@ -117,13 +121,18 @@ namespace Nikse.SubtitleEdit.Controls
{
SelectionLength = 0;
if (justAppend)
{
index++;
}
SelectionStart = index;
return; // too fast - nobody can drag'n'drop this fast
}
if (index >= _dragStartFrom && index <= _dragStartFrom + _dragText.Length)
{
return; // don't drop same text at same position
}
if (_dragRemoveOld)
{
@ -140,20 +149,29 @@ namespace Nikse.SubtitleEdit.Controls
{
Text = Text.Remove(_dragStartFrom, 1);
if (_dragStartFrom < index)
{
index--;
}
}
else if (_dragStartFrom > 0 && Text.Length > _dragStartFrom + 1 && Text[_dragStartFrom] == ' ' && expectedChars.Contains(Text[_dragStartFrom + 1]))
{
Text = Text.Remove(_dragStartFrom, 1);
if (_dragStartFrom < index)
{
index--;
}
}
// fix index
if (index > _dragStartFrom)
{
index -= _dragText.Length;
}
if (index < 0)
{
index = 0;
}
}
}
if (justAppend)
@ -184,7 +202,9 @@ namespace Nikse.SubtitleEdit.Controls
{
bool lastWord = expectedChars.Contains(Text[endIndex]);
if (!lastWord)
{
Text = Text.Insert(endIndex, " ");
}
}
else if (endIndex < Text.Length && newText.EndsWith(' ') && Text[endIndex] == ' ')
{

View File

@ -64,9 +64,15 @@ namespace Nikse.SubtitleEdit.Controls
{
var hzAlignment = value ? HorizontalAlignment.Left : HorizontalAlignment.Right;
if (ColumnIndexCps >= 0)
{
Columns[ColumnIndexCps].TextAlign = hzAlignment;
}
if (ColumnIndexWpm >= 0)
{
Columns[ColumnIndexWpm].TextAlign = hzAlignment;
}
base.RightToLeftLayout = value;
}
}
@ -115,52 +121,80 @@ namespace Nikse.SubtitleEdit.Controls
{
int idx = GetColumnIndex(SubtitleColumn.Number);
if (idx >= 0)
{
Columns[idx].Text = general.NumberSymbol;
}
idx = GetColumnIndex(SubtitleColumn.Start);
if (idx >= 0)
{
Columns[idx].Text = general.StartTime;
}
idx = GetColumnIndex(SubtitleColumn.End);
if (idx >= 0)
{
Columns[idx].Text = general.EndTime;
}
idx = GetColumnIndex(SubtitleColumn.Duration);
if (idx >= 0)
{
Columns[idx].Text = general.Duration;
}
idx = GetColumnIndex(SubtitleColumn.CharactersPerSeconds);
if (idx >= 0)
{
Columns[idx].Text = general.CharsPerSec;
}
idx = GetColumnIndex(SubtitleColumn.WordsPerMinute);
if (idx >= 0)
{
Columns[idx].Text = general.WordsPerMin;
}
idx = GetColumnIndex(SubtitleColumn.Gap);
if (idx >= 0)
{
Columns[idx].Text = general.Gap;
}
idx = GetColumnIndex(SubtitleColumn.Actor);
if (idx >= 0)
{
Columns[idx].Text = general.Actor;
}
idx = GetColumnIndex(SubtitleColumn.Region);
if (idx >= 0)
{
Columns[idx].Text = general.Region;
}
idx = GetColumnIndex(SubtitleColumn.Text);
if (idx >= 0)
{
Columns[idx].Text = general.Text;
}
if (settings.General.ListViewLineSeparatorString != null)
{
_lineSeparatorString = settings.General.ListViewLineSeparatorString;
}
if (!string.IsNullOrEmpty(settings.General.SubtitleFontName))
{
_subtitleFontName = settings.General.SubtitleFontName;
}
SubtitleFontBold = settings.General.SubtitleListViewFontBold;
if (settings.General.SubtitleListViewFontSize > 6 && settings.General.SubtitleListViewFontSize < 72)
{
SubtitleFontSize = settings.General.SubtitleListViewFontSize;
}
ForeColor = settings.General.SubtitleFontColor;
BackColor = settings.General.SubtitleBackgroundColor;
_settings = settings;
@ -173,43 +207,63 @@ namespace Nikse.SubtitleEdit.Controls
{
int idx = GetColumnIndex(SubtitleColumn.Number);
if (idx >= 0)
{
Columns[idx].Width = Configuration.Settings.General.ListViewNumberWidth;
}
idx = GetColumnIndex(SubtitleColumn.Start);
if (idx >= 0)
{
Columns[idx].Width = _settings.General.ListViewStartWidth;
}
idx = GetColumnIndex(SubtitleColumn.End);
if (idx >= 0)
{
Columns[idx].Width = _settings.General.ListViewEndWidth;
}
idx = GetColumnIndex(SubtitleColumn.Duration);
if (idx >= 0)
{
Columns[idx].Width = _settings.General.ListViewDurationWidth;
}
idx = GetColumnIndex(SubtitleColumn.CharactersPerSeconds);
if (idx >= 0)
{
Columns[idx].Width = _settings.General.ListViewCpsWidth;
}
idx = GetColumnIndex(SubtitleColumn.WordsPerMinute);
if (idx >= 0)
{
Columns[idx].Width = _settings.General.ListViewWpmWidth;
}
idx = GetColumnIndex(SubtitleColumn.Gap);
if (idx >= 0)
{
Columns[idx].Width = _settings.General.ListViewGapWidth;
}
idx = GetColumnIndex(SubtitleColumn.Actor);
if (idx >= 0)
{
Columns[idx].Width = _settings.General.ListViewActorWidth;
}
idx = GetColumnIndex(SubtitleColumn.Region);
if (idx >= 0)
{
Columns[idx].Width = _settings.General.ListViewRegionWidth;
}
idx = GetColumnIndex(SubtitleColumn.Text);
if (idx >= 0)
{
Columns[idx].Width = _settings.General.ListViewTextWidth;
}
_saveColumnWidthChanges = true;
}
@ -222,15 +276,21 @@ namespace Nikse.SubtitleEdit.Controls
var idx = GetColumnIndex(SubtitleColumn.Start);
if (idx >= 0)
{
Columns[idx].Width = timestampWidth;
}
idx = GetColumnIndex(SubtitleColumn.End);
if (idx >= 0)
{
Columns[idx].Width = timestampWidth;
}
idx = GetColumnIndex(SubtitleColumn.Duration);
if (idx >= 0)
{
Columns[idx].Width = (int)(timestampWidth * 0.8);
}
}
}
@ -293,19 +353,29 @@ namespace Nikse.SubtitleEdit.Controls
}
if (Configuration.Settings != null && !Configuration.Settings.Tools.ListViewShowColumnEndTime)
{
HideColumn(SubtitleColumn.End);
}
if (Configuration.Settings != null && !Configuration.Settings.Tools.ListViewShowColumnDuration)
{
HideColumn(SubtitleColumn.Duration);
}
if (Configuration.Settings != null && Configuration.Settings.Tools.ListViewShowColumnCharsPerSec)
{
ShowCharsSecColumn(Configuration.Settings.Language.General.CharsPerSec);
}
if (Configuration.Settings != null && Configuration.Settings.Tools.ListViewShowColumnWordsPerMin)
{
ShowWordsMinColumn(Configuration.Settings.Language.General.WordsPerMin);
}
if (Configuration.Settings != null && Configuration.Settings.Tools.ListViewShowColumnGap)
{
ShowGapColumn(Configuration.Settings.Language.General.Gap);
}
SubtitleListViewLastColumnFill(this, null);
@ -420,7 +490,9 @@ namespace Nikse.SubtitleEdit.Controls
if (!Focused && (e.State & ListViewItemStates.Selected) != 0)
{
if (e.Item.Focused)
{
e.DrawFocusRectangle();
}
}
else
{
@ -554,7 +626,9 @@ namespace Nikse.SubtitleEdit.Controls
var column = SubtitleColumns[index];
int cw = Columns[index].Width;
if (column != SubtitleColumn.Text && column != SubtitleColumn.TextAlternate)
{
w += cw;
}
}
int lengthAvailable = Width - w;
if (ColumnIndexTextAlternate >= 0)
@ -578,9 +652,13 @@ namespace Nikse.SubtitleEdit.Controls
if (numberIdx >= 0)
{
if (_settings != null && _settings.General.ListViewColumnsRememberSize && _settings.General.ListViewNumberWidth > 1)
{
Columns[numberIdx].Width = _settings.General.ListViewNumberWidth;
}
else
{
Columns[numberIdx].Width = 50;
}
}
var startIdx = GetColumnIndex(SubtitleColumn.Start);
@ -601,16 +679,24 @@ namespace Nikse.SubtitleEdit.Controls
if (startIdx >= 0)
{
if (_settings != null && _settings.General.ListViewColumnsRememberSize && _settings.General.ListViewStartWidth > 1)
{
Columns[startIdx].Width = _settings.General.ListViewStartWidth;
}
else
{
Columns[startIdx].Width = timeStampWidth;
}
}
if (endIdx >= 0)
{
if (_settings != null && _settings.General.ListViewColumnsRememberSize && _settings.General.ListViewEndWidth > 1)
{
Columns[endIdx].Width = _settings.General.ListViewEndWidth;
}
else
{
Columns[endIdx].Width = timeStampWidth;
}
}
int w = 0;
@ -622,23 +708,38 @@ namespace Nikse.SubtitleEdit.Controls
{
cw = 55;
if (column == SubtitleColumn.CharactersPerSeconds)
{
cw = 65;
}
else if (column == SubtitleColumn.WordsPerMinute)
{
cw = 70;
}
else if (column == SubtitleColumn.Gap)
{
cw = 60;
}
else if (column == SubtitleColumn.Actor)
{
cw = 70;
}
else if (column == SubtitleColumn.Region)
{
cw = 60;
}
else if (column != SubtitleColumn.Number)
{
cw = 120;
}
Columns[index].Width = cw;
Columns[index].Width = cw;
Columns[index].Width = cw;
}
if (column != SubtitleColumn.Text && column != SubtitleColumn.TextAlternate)
{
w += cw;
}
}
int lengthAvailable = Width - w;
@ -1045,7 +1146,9 @@ namespace Nikse.SubtitleEdit.Controls
public void SaveFirstVisibleIndex()
{
if (TopItem != null)
{
FirstVisibleIndex = Items.Count > 0 ? TopItem.Index : -1;
}
}
private void RestoreFirstVisibleIndex()
@ -1053,7 +1156,9 @@ namespace Nikse.SubtitleEdit.Controls
if (IsValidIndex(FirstVisibleIndex))
{
if (FirstVisibleIndex + 1 < Items.Count)
{
FirstVisibleIndex++;
}
Items[Items.Count - 1].EnsureVisible();
Items[FirstVisibleIndex].EnsureVisible();
@ -1084,7 +1189,10 @@ namespace Nikse.SubtitleEdit.Controls
{
Paragraph next = null;
if (i + 1 < paragraphs.Count)
{
next = paragraphs[i + 1];
}
Add(paragraph, next, null);
SyntaxColorLine(paragraphs, i, paragraph);
i++;
@ -1094,7 +1202,9 @@ namespace Nikse.SubtitleEdit.Controls
EndUpdate();
if (FirstVisibleIndex == 0)
{
FirstVisibleIndex = -1;
}
}
internal void Fill(List<Paragraph> paragraphs, List<Paragraph> paragraphsAlternate)
@ -1110,7 +1220,10 @@ namespace Nikse.SubtitleEdit.Controls
Paragraph alternate = Utilities.GetOriginalParagraph(i, paragraph, paragraphsAlternate);
Paragraph next = null;
if (i + 1 < paragraphs.Count)
{
next = paragraphs[i + 1];
}
Add(paragraph, next, alternate);
SyntaxColorLine(paragraphs, i, paragraph);
i++;
@ -1120,7 +1233,9 @@ namespace Nikse.SubtitleEdit.Controls
EndUpdate();
if (FirstVisibleIndex == 0)
{
FirstVisibleIndex = -1;
}
}
public void SyntaxColorAllLines(Subtitle subtitle)
@ -1161,9 +1276,13 @@ namespace Nikse.SubtitleEdit.Controls
if (charactersPerSecond > Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
{
if (ColumnIndexCps >= 0)
{
item.SubItems[ColumnIndexCps].BackColor = Configuration.Settings.Tools.ListViewSyntaxErrorColor;
}
else if (ColumnIndexDuration >= 0)
{
item.SubItems[ColumnIndexDuration].BackColor = Configuration.Settings.Tools.ListViewSyntaxErrorColor;
}
}
if (paragraph.Duration.TotalMilliseconds < Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds && ColumnIndexDuration >= 0)
{
@ -1188,9 +1307,14 @@ namespace Nikse.SubtitleEdit.Controls
else
{
if (Items[i - 1].SubItems[ColumnIndexEnd].BackColor != BackColor)
{
Items[i - 1].SubItems[ColumnIndexEnd].BackColor = BackColor;
}
if (item.SubItems[ColumnIndexStart].BackColor != BackColor)
{
item.SubItems[ColumnIndexStart].BackColor = BackColor;
}
}
}
@ -1200,7 +1324,9 @@ namespace Nikse.SubtitleEdit.Controls
}
if (ColumnIndexText >= item.SubItems.Count)
{
return;
}
if (_settings.Tools.ListViewSyntaxColorLongLines)
{
@ -1219,9 +1345,13 @@ namespace Nikse.SubtitleEdit.Controls
if (len <= Configuration.Settings.General.SubtitleLineMaximumLength * noOfLines)
{
if (noOfLines > Configuration.Settings.Tools.ListViewSyntaxMoreThanXLinesX && _settings.Tools.ListViewSyntaxMoreThanXLines)
{
item.SubItems[ColumnIndexText].BackColor = Configuration.Settings.Tools.ListViewSyntaxErrorColor;
}
else if (item.SubItems[ColumnIndexText].BackColor != BackColor)
{
item.SubItems[ColumnIndexText].BackColor = BackColor;
}
}
else
{
@ -1232,7 +1362,9 @@ namespace Nikse.SubtitleEdit.Controls
item.SubItems[ColumnIndexText].BackColor != Configuration.Settings.Tools.ListViewSyntaxErrorColor)
{
if (paragraph.NumberOfLines > Configuration.Settings.Tools.ListViewSyntaxMoreThanXLinesX)
{
item.SubItems[ColumnIndexText].BackColor = Configuration.Settings.Tools.ListViewSyntaxErrorColor;
}
}
}
}
@ -1240,7 +1372,10 @@ namespace Nikse.SubtitleEdit.Controls
private string GetDisplayTime(TimeCode timeCode)
{
if (Configuration.Settings.General.CurrentVideoOffsetInMs > 0)
{
return new TimeCode(timeCode.TotalMilliseconds + Configuration.Settings.General.CurrentVideoOffsetInMs).ToDisplayString();
}
return timeCode.ToDisplayString();
}
@ -1299,7 +1434,9 @@ namespace Nikse.SubtitleEdit.Controls
public void SelectNone()
{
for (var i = Items.Count - 1; i >= 0; i--)
{
Items[i].Selected = false;
}
}
public void SelectIndexAndEnsureVisibleFaster(int index)
@ -1345,20 +1482,28 @@ namespace Nikse.SubtitleEdit.Controls
public void SelectIndexAndEnsureVisible(int index, bool focus)
{
if (!IsValidIndex(index) || TopItem == null)
{
return;
}
int bottomIndex = TopItem.Index + (Height - 25) / 16;
int itemsBeforeAfterCount = (bottomIndex - TopItem.Index) / 2 - 1;
if (itemsBeforeAfterCount < 0)
{
itemsBeforeAfterCount = 1;
}
int beforeIndex = index - itemsBeforeAfterCount;
if (beforeIndex < 0)
{
beforeIndex = 0;
}
int afterIndex = index + itemsBeforeAfterCount;
if (afterIndex >= Items.Count)
{
afterIndex = Items.Count - 1;
}
SelectNone();
if (TopItem.Index <= beforeIndex && bottomIndex > afterIndex)
@ -1366,7 +1511,10 @@ namespace Nikse.SubtitleEdit.Controls
Items[index].Selected = true;
Items[index].EnsureVisible();
if (focus)
{
Items[index].Focused = true;
}
return;
}
@ -1377,7 +1525,9 @@ namespace Nikse.SubtitleEdit.Controls
Items[index].Selected = true;
Items[index].EnsureVisible();
if (focus)
{
Items[index].Focused = true;
}
}
public void SelectIndexAndEnsureVisible(int index)
@ -1389,7 +1539,9 @@ namespace Nikse.SubtitleEdit.Controls
{
SelectNone();
if (p == null)
{
return;
}
for (int index = 0; index < Items.Count; index++)
{
@ -1412,21 +1564,30 @@ namespace Nikse.SubtitleEdit.Controls
public Paragraph GetSelectedParagraph(Subtitle subtitle)
{
if (subtitle != null && SelectedItems.Count > 0)
{
return subtitle.GetParagraphOrDefault(SelectedItems[0].Index);
}
return null;
}
public string GetText(int index)
{
if (IsValidIndex(index))
{
return Items[index].SubItems[ColumnIndexText].Text.Replace(_lineSeparatorString, Environment.NewLine);
}
return null;
}
public string GetTextAlternate(int index)
{
if (IsValidIndex(index) && ColumnIndexTextAlternate >= 0)
{
return Items[index].SubItems[ColumnIndexTextAlternate].Text.Replace(_lineSeparatorString, Environment.NewLine);
}
return null;
}
@ -1436,10 +1597,15 @@ namespace Nikse.SubtitleEdit.Controls
{
ListViewItem item = Items[index];
if (ColumnIndexText >= 0)
{
item.SubItems[ColumnIndexText].Text = text.Replace(Environment.NewLine, _lineSeparatorString);
}
var paragraph = item.Tag as Paragraph;
if (paragraph != null)
{
UpdateCpsAndWpm(item, paragraph);
}
}
}
@ -1449,19 +1615,40 @@ namespace Nikse.SubtitleEdit.Controls
{
ListViewItem item = Items[index];
if (ColumnIndexStart >= 0)
{
item.SubItems[ColumnIndexStart].Text = GetDisplayTime(paragraph.StartTime);
}
if (ColumnIndexEnd >= 0)
{
item.SubItems[ColumnIndexEnd].Text = GetDisplayTime(paragraph.EndTime);
}
if (ColumnIndexDuration >= 0)
{
item.SubItems[ColumnIndexDuration].Text = paragraph.Duration.ToShortDisplayString();
}
if (ColumnIndexGap >= 0)
{
item.SubItems[ColumnIndexGap].Text = GetGap(paragraph, next);
}
if (ColumnIndexActor >= 0)
{
item.SubItems[ColumnIndexActor].Text = paragraph.Actor;
}
if (ColumnIndexRegion >= 0)
{
item.SubItems[ColumnIndexRegion].Text = paragraph.Region;
}
if (ColumnIndexText >= 0)
{
item.SubItems[ColumnIndexText].Text = paragraph.Text.Replace(Environment.NewLine, _lineSeparatorString);
}
UpdateCpsAndWpm(item, paragraph);
}
}
@ -1487,7 +1674,9 @@ namespace Nikse.SubtitleEdit.Controls
ShowExtraColumn(string.Empty);
}
while (ColumnIndexExtra >= Items[index].SubItems.Count)
{
Items[index].SubItems.Add(string.Empty);
}
if (ColumnIndexExtra >= 0)
{
@ -1508,7 +1697,9 @@ namespace Nikse.SubtitleEdit.Controls
ShowNetworkColumn(string.Empty);
}
while (ColumnIndexNetwork >= Items[index].SubItems.Count)
{
Items[index].SubItems.Add(string.Empty);
}
if (ColumnIndexNetwork >= 0)
{
@ -1529,7 +1720,9 @@ namespace Nikse.SubtitleEdit.Controls
ShowAlternateTextColumn(string.Empty);
}
while (ColumnIndexTextAlternate >= Items[index].SubItems.Count)
{
Items[index].SubItems.Add(string.Empty);
}
if (ColumnIndexTextAlternate >= 0)
{
@ -1546,11 +1739,20 @@ namespace Nikse.SubtitleEdit.Controls
{
ListViewItem item = Items[index];
if (ColumnIndexEnd >= 0)
{
item.SubItems[ColumnIndexEnd].Text = GetDisplayTime(paragraph.EndTime);
}
if (ColumnIndexDuration >= 0)
{
item.SubItems[ColumnIndexDuration].Text = paragraph.Duration.ToShortDisplayString();
}
if (ColumnIndexGap >= 0)
{
item.SubItems[ColumnIndexGap].Text = GetGap(paragraph, next);
}
UpdateCpsAndWpm(item, paragraph);
}
}
@ -1575,11 +1777,19 @@ namespace Nikse.SubtitleEdit.Controls
Paragraph p = subtitle.Paragraphs[i];
ListViewItem item = Items[i];
if (ColumnIndexStart >= 0)
{
item.SubItems[ColumnIndexStart].Text = GetDisplayTime(p.StartTime);
}
if (ColumnIndexEnd >= 0)
{
item.SubItems[ColumnIndexEnd].Text = GetDisplayTime(p.EndTime);
}
if (ColumnIndexDuration >= 0)
{
item.SubItems[ColumnIndexDuration].Text = p.Duration.ToShortDisplayString();
}
}
}
EndUpdate();
@ -1592,13 +1802,25 @@ namespace Nikse.SubtitleEdit.Controls
{
ListViewItem item = Items[index];
if (ColumnIndexStart >= 0)
{
item.SubItems[ColumnIndexStart].Text = GetDisplayTime(paragraph.StartTime);
}
if (ColumnIndexEnd >= 0)
{
item.SubItems[ColumnIndexEnd].Text = GetDisplayTime(paragraph.EndTime);
}
if (ColumnIndexDuration >= 0)
{
item.SubItems[ColumnIndexDuration].Text = paragraph.Duration.ToShortDisplayString();
}
if (ColumnIndexGap >= 0)
{
item.SubItems[ColumnIndexGap].Text = GetGap(paragraph, next);
}
UpdateCpsAndWpm(item, paragraph);
}
SetGap(index - 1, prev, paragraph);
@ -1610,7 +1832,9 @@ namespace Nikse.SubtitleEdit.Controls
{
ListViewItem item = Items[index];
if (ColumnIndexGap >= 0)
{
item.SubItems[ColumnIndexGap].Text = GetGap(paragraph, next);
}
}
}
@ -1630,9 +1854,14 @@ namespace Nikse.SubtitleEdit.Controls
{
ListViewItem item = Items[index];
if (item.UseItemStyleForSubItems)
{
item.UseItemStyleForSubItems = false;
}
if (columnNumber >= 0 && columnNumber < item.SubItems.Count)
{
item.SubItems[columnNumber].BackColor = color;
}
}
}
@ -1643,19 +1872,39 @@ namespace Nikse.SubtitleEdit.Controls
ListViewItem item = Items[index];
item.BackColor = color;
if (ColumnIndexStart >= 0)
{
Items[index].SubItems[ColumnIndexStart].BackColor = color;
}
if (ColumnIndexEnd >= 0)
{
Items[index].SubItems[ColumnIndexEnd].BackColor = color;
}
if (ColumnIndexDuration >= 0)
{
Items[index].SubItems[ColumnIndexDuration].BackColor = color;
}
if (ColumnIndexCps >= 0)
{
Items[index].SubItems[ColumnIndexCps].BackColor = color;
}
if (ColumnIndexWpm >= 0)
{
Items[index].SubItems[ColumnIndexWpm].BackColor = color;
}
if (ColumnIndexText >= 0)
{
Items[index].SubItems[ColumnIndexText].BackColor = color;
}
if (ColumnIndexTextAlternate >= 0)
{
Items[index].SubItems[ColumnIndexTextAlternate].BackColor = color;
}
}
}
@ -1681,13 +1930,25 @@ namespace Nikse.SubtitleEdit.Controls
ListViewItem item = Items[index];
item.Text = string.Empty;
if (ColumnIndexStart >= 0)
{
item.SubItems[ColumnIndexStart].Text = string.Empty;
}
if (ColumnIndexEnd >= 0)
{
item.SubItems[ColumnIndexEnd].Text = string.Empty;
}
if (ColumnIndexDuration >= 0)
{
item.SubItems[ColumnIndexDuration].Text = string.Empty;
}
if (ColumnIndexText >= 0)
{
item.SubItems[ColumnIndexText].Text = string.Empty;
}
SetBackgroundColor(index, color);
}
}
@ -1696,7 +1957,10 @@ namespace Nikse.SubtitleEdit.Controls
{
var numberIdx = GetColumnIndex(SubtitleColumn.Number);
if (numberIdx >= 0)
{
Columns[numberIdx].Width = 0;
}
HideColumn(SubtitleColumn.End);
HideColumn(SubtitleColumn.Duration);
HideColumn(SubtitleColumn.CharactersPerSeconds);
@ -1706,7 +1970,10 @@ namespace Nikse.SubtitleEdit.Controls
public void SetCustomResize(EventHandler handler)
{
if (handler == null)
{
return;
}
Resize -= SubtitleListViewLastColumnFill;
Resize += handler;
}

View File

@ -43,7 +43,10 @@ namespace Nikse.SubtitleEdit.Controls
get
{
if (_forceHHMMSSFF || Configuration.Settings?.General.UseTimeFormatHHMMSSFF == true)
{
return TimeMode.HHMMSSFF;
}
return TimeMode.HHMMSSMS;
}
}
@ -81,7 +84,9 @@ namespace Nikse.SubtitleEdit.Controls
if (milliseconds.HasValue)
{
if (milliseconds.Value >= TimeCode.MaxTimeTotalMilliseconds - 0.1)
{
milliseconds = 0;
}
if (Mode == TimeMode.HHMMSSMS)
{
@ -137,7 +142,9 @@ namespace Nikse.SubtitleEdit.Controls
public double? GetTotalMilliseconds()
{
if (!_dirty)
{
return _initialTotalMilliseconds;
}
return TimeCode?.TotalMilliseconds;
}
@ -147,13 +154,19 @@ namespace Nikse.SubtitleEdit.Controls
get
{
if (_designMode)
{
return new TimeCode();
}
if (string.IsNullOrWhiteSpace(maskedTextBox1.Text.RemoveChar('.').Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, string.Empty).RemoveChar(',').RemoveChar(':')))
{
return new TimeCode(TimeCode.MaxTimeTotalMilliseconds);
}
if (!_dirty)
{
return new TimeCode(_initialTotalMilliseconds);
}
string startTime = maskedTextBox1.Text;
bool isNegative = startTime.StartsWith('-');
@ -161,7 +174,9 @@ namespace Nikse.SubtitleEdit.Controls
if (Mode == TimeMode.HHMMSSMS)
{
if (startTime.EndsWith(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, StringComparison.Ordinal))
{
startTime += "000";
}
string[] times = startTime.Split(_splitChars, StringSplitOptions.RemoveEmptyEntries);
@ -173,12 +188,16 @@ namespace Nikse.SubtitleEdit.Controls
int minutes;
int.TryParse(times[1], out minutes);
if (minutes > 59)
{
minutes = 59;
}
int seconds;
int.TryParse(times[2], out seconds);
if (seconds > 59)
{
seconds = 59;
}
int milliSeconds;
int.TryParse(times[3].PadRight(3, '0'), out milliSeconds);
@ -190,14 +209,19 @@ namespace Nikse.SubtitleEdit.Controls
}
if (isNegative)
{
tc.TotalMilliseconds *= -1;
}
return tc;
}
}
else
{
if (startTime.EndsWith(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, StringComparison.Ordinal) || startTime.EndsWith(':'))
{
startTime += "00";
}
string[] times = startTime.Split(_splitChars, StringSplitOptions.RemoveEmptyEntries);
@ -226,7 +250,10 @@ namespace Nikse.SubtitleEdit.Controls
}
if (isNegative)
{
tc.TotalMilliseconds *= -1;
}
return tc;
}
}
@ -235,7 +262,9 @@ namespace Nikse.SubtitleEdit.Controls
set
{
if (_designMode)
{
return;
}
if (value != null)
{
@ -301,7 +330,9 @@ namespace Nikse.SubtitleEdit.Controls
private void maskedTextBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
_dirty = true;
}
}
}
}

View File

@ -27,8 +27,16 @@ namespace Nikse.SubtitleEdit.Controls
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x204) return; // WM_RBUTTONDOWN
if (m.Msg == 0x205) return; // WM_RBUTTONUP
if (m.Msg == 0x204)
{
return; // WM_RBUTTONDOWN
}
if (m.Msg == 0x205)
{
return; // WM_RBUTTONUP
}
base.WndProc(ref m);
}
}
@ -45,12 +53,15 @@ namespace Nikse.SubtitleEdit.Controls
public VideoPlayer VideoPlayer
{
get { return _videoPlayer; }
get => _videoPlayer;
set
{
_videoPlayer = value;
if (_videoPlayer != null)
{
SetPlayerName(_videoPlayer.PlayerName);
}
if (_videoPlayer is LibMpvDynamic && Configuration.Settings.General.MpvHandlesPreviewText)
{
_subtitlesHeight = 0;
@ -109,7 +120,7 @@ namespace Nikse.SubtitleEdit.Controls
public RightToLeft TextRightToLeft
{
get { return _subtitleTextBox.RightToLeft; }
get => _subtitleTextBox.RightToLeft;
set
{
_subtitleTextBox.RightToLeft = value;
@ -120,7 +131,7 @@ namespace Nikse.SubtitleEdit.Controls
public bool ShowStopButton
{
get { return _pictureBoxStop.Visible || _pictureBoxStopOver.Visible || _pictureBoxStopDown.Visible; }
get => _pictureBoxStop.Visible || _pictureBoxStopOver.Visible || _pictureBoxStopDown.Visible;
set
{
if (value)
@ -136,7 +147,7 @@ namespace Nikse.SubtitleEdit.Controls
public bool ShowMuteButton
{
get { return _pictureBoxMute.Visible || _pictureBoxMuteOver.Visible || _pictureBoxMuteDown.Visible; }
get => _pictureBoxMute.Visible || _pictureBoxMuteOver.Visible || _pictureBoxMuteDown.Visible;
set
{
if (value)
@ -152,7 +163,7 @@ namespace Nikse.SubtitleEdit.Controls
public bool ShowFullscreenButton
{
get { return _pictureBoxFullscreen.Visible || _pictureBoxFullscreenOver.Visible || _pictureBoxFullscreenDown.Visible; }
get => _pictureBoxFullscreen.Visible || _pictureBoxFullscreenOver.Visible || _pictureBoxFullscreenDown.Visible;
set
{
if (value)
@ -234,7 +245,9 @@ namespace Nikse.SubtitleEdit.Controls
{
control.MouseWheel += ControlMouseWheel;
foreach (Control ctrl in control.Controls)
{
AddMouseWheelEvent(ctrl);
}
}
private void ControlMouseWheel(object sender, MouseEventArgs e)
@ -242,9 +255,14 @@ namespace Nikse.SubtitleEdit.Controls
int delta = e.Delta;
double newPosition = CurrentPosition - (delta / 256.0);
if (newPosition < 0)
{
newPosition = 0;
}
else if (newPosition > Duration)
{
newPosition = Duration;
}
CurrentPosition = newPosition;
}
@ -265,11 +283,19 @@ namespace Nikse.SubtitleEdit.Controls
{
var gs = Configuration.Settings.General;
if (string.IsNullOrEmpty(gs.SubtitleFontName))
{
gs.SubtitleFontName = "Tahoma";
}
if (gs.VideoPlayerPreviewFontBold)
{
_subtitleTextBox.Font = new Font(gs.SubtitleFontName, gs.VideoPlayerPreviewFontSize * FontSizeFactor, FontStyle.Bold);
}
else
{
_subtitleTextBox.Font = new Font(gs.SubtitleFontName, gs.VideoPlayerPreviewFontSize * FontSizeFactor, FontStyle.Regular);
}
SubtitleText = _subtitleText;
}
@ -294,7 +320,9 @@ namespace Nikse.SubtitleEdit.Controls
_subtitleText = text;
RefreshMpv(mpv, subtitle);
if (_subtitleTextBox.Text.Length > 0)
{
_subtitleTextBox.Text = string.Empty;
}
}
else
{
@ -317,7 +345,9 @@ namespace Nikse.SubtitleEdit.Controls
private void RefreshMpv(LibMpvDynamic mpv, Subtitle subtitle)
{
if (subtitle == null)
{
return;
}
try
{
@ -403,7 +433,7 @@ namespace Nikse.SubtitleEdit.Controls
public string SubtitleText
{
get { return _subtitleText; }
get => _subtitleText;
set
{
_subtitleText = value;
@ -511,9 +541,14 @@ namespace Nikse.SubtitleEdit.Controls
if (colorEnd > 0 || colorEnd == -1)
{
if (colorEnd == -1)
{
s = f.Substring(colorStart);
}
else
{
s = f.Substring(colorStart, colorEnd - colorStart);
}
s = s.Remove(0, " color=".Length);
s = s.Trim('"');
s = s.Trim('\'');
@ -575,11 +610,19 @@ namespace Nikse.SubtitleEdit.Controls
{
var idx = _subtitleTextBox.TextLength + sb.Length;
if (isBold)
{
styleLookups[idx] |= FontStyle.Bold;
}
if (isItalic)
{
styleLookups[idx] |= FontStyle.Italic;
}
if (isUnderline)
{
styleLookups[idx] |= FontStyle.Underline;
}
sb.Append(text[i]);
letterCount++;
@ -590,11 +633,17 @@ namespace Nikse.SubtitleEdit.Controls
_subtitleTextBox.SelectAll();
if (alignLeft)
{
_subtitleTextBox.SelectionAlignment = HorizontalAlignment.Left;
}
else if (alignRight)
{
_subtitleTextBox.SelectionAlignment = HorizontalAlignment.Right;
}
else
{
_subtitleTextBox.SelectionAlignment = HorizontalAlignment.Center;
}
_subtitleTextBox.DeselectAll();
@ -620,7 +669,9 @@ namespace Nikse.SubtitleEdit.Controls
private void PanelPlayerMouseDown(object sender, MouseEventArgs e)
{
if (VideoPlayer == null)
{
OnEmptyPlayerClicked?.Invoke(sender, e);
}
TogglePlayPause();
}
@ -645,7 +696,9 @@ namespace Nikse.SubtitleEdit.Controls
_panelcontrols.Visible = false;
}
if (hideCursor)
{
HideCursor();
}
}
public void ShowControls()
@ -661,7 +714,9 @@ namespace Nikse.SubtitleEdit.Controls
public void HideCursor()
{
if (_cursorStatus < 0)
{
return;
}
_cursorStatus--;
if (VideoPlayer != null)
@ -677,7 +732,9 @@ namespace Nikse.SubtitleEdit.Controls
public void ShowCursor()
{
if (_cursorStatus >= 0)
{
return;
}
_cursorStatus++;
if (VideoPlayer != null)
@ -1244,9 +1301,13 @@ namespace Nikse.SubtitleEdit.Controls
{
HideAllMuteImages();
if (Mute)
{
_pictureBoxMuteDown.Visible = true;
}
else
{
_pictureBoxMuteOver.Visible = true;
}
}
private void PictureBoxMuteOverMouseLeave(object sender, EventArgs e)
@ -1314,7 +1375,10 @@ namespace Nikse.SubtitleEdit.Controls
{
var newPosition = CurrentPosition - 3.0;
if (newPosition < 0)
{
newPosition = 0;
}
CurrentPosition = newPosition;
}
}
@ -1357,7 +1421,10 @@ namespace Nikse.SubtitleEdit.Controls
{
var newPosition = CurrentPosition + 3.0;
if (newPosition < 0)
{
newPosition = 0;
}
CurrentPosition = newPosition;
}
}
@ -1376,7 +1443,9 @@ namespace Nikse.SubtitleEdit.Controls
{
int max = _pictureBoxProgressbarBackground.Width - 9;
if (mouseX > max)
{
mouseX = max;
}
double percent = mouseX * 100.0 / max;
_pictureBoxProgressBar.Width = (int)(max * percent / 100.0);
@ -1417,11 +1486,15 @@ namespace Nikse.SubtitleEdit.Controls
_pictureBoxProgressBar.Width = (int)(max * percent / 100.0);
if (Convert.ToInt64(Duration) == 0)
{
return;
}
var pos = CurrentPosition;
if (pos > 1000000)
{
pos = 0;
}
var dur = TimeCode.FromSeconds(Duration + Configuration.Settings.General.CurrentVideoOffsetInMs / TimeCode.BaseUnit);
if (SmpteMode)
@ -1443,12 +1516,17 @@ namespace Nikse.SubtitleEdit.Controls
{
int max = _pictureBoxVolumeBarBackground.Width - 18;
if (mouseX > max)
{
mouseX = max;
}
double percent = (mouseX * 100.0) / max;
_pictureBoxVolumeBar.Width = (int)(max * percent / 100.0);
if (_videoPlayer != null)
{
_videoPlayer.Volume = (int)percent;
}
Configuration.Settings.General.VideoPlayerDefaultVolume = (int)percent;
}
@ -1523,9 +1601,13 @@ namespace Nikse.SubtitleEdit.Controls
if (VideoPlayer != null)
{
if (VideoPlayer.IsPaused)
{
Play();
}
else
{
Pause();
}
}
}
@ -1536,7 +1618,10 @@ namespace Nikse.SubtitleEdit.Controls
get
{
if (VideoPlayer != null)
{
return VideoPlayer.Volume;
}
return 0;
}
set
@ -1544,14 +1629,22 @@ namespace Nikse.SubtitleEdit.Controls
if (VideoPlayer != null)
{
if (value > 0)
{
_muteOldVolume = null;
}
if (value > 100)
{
VideoPlayer.Volume = 100;
}
else if (value < 0)
{
VideoPlayer.Volume = 0;
}
else
{
VideoPlayer.Volume = (int)value;
}
RefreshVolumeBar();
}
@ -1606,7 +1699,10 @@ namespace Nikse.SubtitleEdit.Controls
get
{
if (VideoPlayer != null)
{
return VideoPlayer.Duration;
}
return 0;
}
}

View File

@ -51,44 +51,69 @@ namespace Nikse.SubtitleEdit.Forms.DCinema
if (int.TryParse(ss.CurrentDCinemaReelNumber, out number))
{
if (numericUpDownReelNumber.Minimum <= number && numericUpDownReelNumber.Maximum >= number)
{
numericUpDownReelNumber.Value = number;
}
}
comboBoxLanguage.Text = ss.CurrentDCinemaLanguage;
textBoxFontID.Text = ss.CurrentDCinemaFontId;
textBoxFontUri.Text = ss.CurrentDCinemaFontUri;
panelFontColor.BackColor = ss.CurrentDCinemaFontColor;
if (ss.CurrentDCinemaFontEffect == "border")
{
comboBoxFontEffect.SelectedIndex = 1;
}
else if (ss.CurrentDCinemaFontEffect == "shadow")
{
comboBoxFontEffect.SelectedIndex = 2;
}
else
{
comboBoxFontEffect.SelectedIndex = 0;
}
panelFontEffectColor.BackColor = ss.CurrentDCinemaFontEffectColor;
numericUpDownFontSize.Value = ss.CurrentDCinemaFontSize;
if (numericUpDownTopBottomMargin.Minimum <= ss.DCinemaBottomMargin &&
numericUpDownTopBottomMargin.Maximum >= ss.DCinemaBottomMargin)
{
numericUpDownTopBottomMargin.Value = ss.DCinemaBottomMargin;
}
else
{
numericUpDownTopBottomMargin.Value = 8;
}
if (numericUpDownFadeUp.Minimum <= ss.DCinemaFadeUpTime &&
numericUpDownFadeUp.Maximum >= ss.DCinemaFadeUpTime)
{
numericUpDownFadeUp.Value = ss.DCinemaFadeUpTime;
}
else
{
numericUpDownFadeUp.Value = 0;
}
if (numericUpDownFadeDown.Minimum <= ss.DCinemaFadeDownTime &&
numericUpDownFadeDown.Maximum >= ss.DCinemaFadeDownTime)
{
numericUpDownFadeDown.Value = ss.DCinemaFadeDownTime;
}
else
{
numericUpDownFadeDown.Value = 0;
}
decimal zPosition = (decimal)ss.DCinemaZPosition;
if (numericUpDownZPosition.Minimum <= zPosition &&
numericUpDownZPosition.Maximum >= zPosition)
{
numericUpDownZPosition.Value = zPosition;
}
else
{
numericUpDownZPosition.Value = 0;
}
}
UiUtil.FixLargeFonts(this, buttonCancel);
}
@ -128,11 +153,18 @@ namespace Nikse.SubtitleEdit.Forms.DCinema
ss.CurrentDCinemaFontUri = textBoxFontUri.Text;
ss.CurrentDCinemaFontColor = panelFontColor.BackColor;
if (comboBoxFontEffect.SelectedIndex == 1)
{
ss.CurrentDCinemaFontEffect = "border";
}
else if (comboBoxFontEffect.SelectedIndex == 2)
{
ss.CurrentDCinemaFontEffect = "shadow";
}
else
{
ss.CurrentDCinemaFontEffect = string.Empty;
}
ss.CurrentDCinemaFontEffectColor = panelFontEffectColor.BackColor;
ss.CurrentDCinemaFontSize = (int)numericUpDownFontSize.Value;
ss.DCinemaBottomMargin = (int)numericUpDownTopBottomMargin.Value;

View File

@ -1,7 +1,6 @@
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Logic;
using System;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
@ -61,37 +60,59 @@ namespace Nikse.SubtitleEdit.Forms.DCinema
timeUpDownStartTime.ForceHHMMSSFF();
if (string.IsNullOrEmpty(ss.CurrentDCinemaStartTime))
{
ss.CurrentDCinemaStartTime = "00:00:00:00";
}
timeUpDownStartTime.MaskedTextBox.Text = ss.CurrentDCinemaStartTime;
textBoxFontUri.Text = ss.CurrentDCinemaFontUri;
textBoxIssueDate.Text = ss.CurrentDCinemaIssueDate;
panelFontColor.BackColor = ss.CurrentDCinemaFontColor;
if (ss.CurrentDCinemaFontEffect == "border")
{
comboBoxFontEffect.SelectedIndex = 1;
}
else if (ss.CurrentDCinemaFontEffect == "shadow")
{
comboBoxFontEffect.SelectedIndex = 2;
}
else
{
comboBoxFontEffect.SelectedIndex = 0;
}
panelFontEffectColor.BackColor = ss.CurrentDCinemaFontEffectColor;
numericUpDownFontSize.Value = ss.CurrentDCinemaFontSize;
if (numericUpDownTopBottomMargin.Minimum <= ss.DCinemaBottomMargin &&
numericUpDownTopBottomMargin.Maximum >= ss.DCinemaBottomMargin)
{
numericUpDownTopBottomMargin.Value = ss.DCinemaBottomMargin;
}
else
{
numericUpDownTopBottomMargin.Value = 8;
}
if (numericUpDownFadeUp.Minimum <= ss.DCinemaFadeUpTime &&
numericUpDownFadeUp.Maximum >= ss.DCinemaFadeUpTime)
{
numericUpDownFadeUp.Value = ss.DCinemaFadeUpTime;
}
else
{
numericUpDownFadeUp.Value = 0;
}
if (numericUpDownFadeDown.Minimum <= ss.DCinemaFadeDownTime &&
numericUpDownFadeDown.Maximum >= ss.DCinemaFadeDownTime)
{
numericUpDownFadeDown.Value = ss.DCinemaFadeDownTime;
}
else
{
numericUpDownFadeDown.Value = 0;
}
}
UiUtil.FixLargeFonts(this, buttonCancel);
}
@ -134,19 +155,31 @@ namespace Nikse.SubtitleEdit.Forms.DCinema
ss.CurrentDCinemaTimeCodeRate = comboBoxTimeCodeRate.Text;
ss.CurrentDCinemaStartTime = timeUpDownStartTime.TimeCode.ToHHMMSSFF();
if (comboBoxLanguage.SelectedItem != null)
{
ss.CurrentDCinemaLanguage = comboBoxLanguage.SelectedItem.ToString();
}
else
{
ss.CurrentDCinemaLanguage = string.Empty;
}
ss.CurrentDCinemaIssueDate = textBoxIssueDate.Text;
ss.CurrentDCinemaFontId = textBoxFontID.Text;
ss.CurrentDCinemaFontUri = textBoxFontUri.Text;
ss.CurrentDCinemaFontColor = panelFontColor.BackColor;
if (comboBoxFontEffect.SelectedIndex == 1)
{
ss.CurrentDCinemaFontEffect = "border";
}
else if (comboBoxFontEffect.SelectedIndex == 2)
{
ss.CurrentDCinemaFontEffect = "shadow";
}
else
{
ss.CurrentDCinemaFontEffect = string.Empty;
}
ss.CurrentDCinemaFontEffectColor = panelFontEffectColor.BackColor;
ss.CurrentDCinemaFontSize = (int)numericUpDownFontSize.Value;
ss.DCinemaBottomMargin = (int)numericUpDownTopBottomMargin.Value;

View File

@ -29,6 +29,7 @@ using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Forms.Networking;
namespace Nikse.SubtitleEdit.Forms
{

View File

@ -1,4 +1,4 @@
namespace Nikse.SubtitleEdit.Forms
namespace Nikse.SubtitleEdit.Forms.Networking
{
partial class NetworkChat
{

View File

@ -1,19 +1,16 @@
using Nikse.SubtitleEdit.Core;
using System;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.Networking;
using System;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms
namespace Nikse.SubtitleEdit.Forms.Networking
{
public sealed partial class NetworkChat : Form
{
private Logic.Networking.NikseWebServiceSession _networkSession;
protected override bool ShowWithoutActivation
{
get { return true; }
}
protected override bool ShowWithoutActivation => true;
public NetworkChat()
{
@ -95,9 +92,14 @@ namespace Nikse.SubtitleEdit.Forms
item.Tag = user;
item.ForeColor = Utilities.GetColorFromUserName(user.UserName);
if (DateTime.Now.Month == 12 && DateTime.Now.Day >= 23 && DateTime.Now.Day <= 25)
{
item.ImageIndex = 7;
}
else
{
item.ImageIndex = Utilities.GetNumber0To7FromUserName(user.UserName);
}
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, user.Ip));
listViewUsers.Items.Add(item);
}
@ -113,7 +115,9 @@ namespace Nikse.SubtitleEdit.Forms
}
}
if (removeItem != null)
{
listViewUsers.Items.Remove(removeItem);
}
}
}
}

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Forms
namespace Nikse.SubtitleEdit.Forms.Networking
{
partial class NetworkJoin
sealed partial class NetworkJoin
{
/// <summary>
/// Required designer variable.

View File

@ -1,12 +1,12 @@
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Logic;
using System;
using System;
using System.Net;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Forms
namespace Nikse.SubtitleEdit.Forms.Networking
{
public partial class NetworkJoin : Form
public sealed partial class NetworkJoin : Form
{
private Logic.Networking.NikseWebServiceSession _networkSession;
@ -35,12 +35,16 @@ namespace Nikse.SubtitleEdit.Forms
textBoxSessionKey.Text = Configuration.Settings.NetworkSettings.SessionKey;
if (textBoxSessionKey.Text.Trim().Length < 2)
{
textBoxSessionKey.Text = Guid.NewGuid().ToString().RemoveChar('-');
}
comboBoxWebServiceUrl.Text = Configuration.Settings.NetworkSettings.WebServiceUrl;
textBoxUserName.Text = Configuration.Settings.NetworkSettings.UserName;
if (textBoxUserName.Text.Trim().Length < 2)
{
textBoxUserName.Text = Dns.GetHostName();
}
}
private void buttonJoin_Click(object sender, EventArgs e)
@ -68,11 +72,17 @@ namespace Nikse.SubtitleEdit.Forms
else
{
if (message == "Session not found!")
{
MessageBox.Show(string.Format(Configuration.Settings.Language.Main.XNotFound, textBoxSessionKey.Text));
}
else if (message == "Username already in use!")
{
MessageBox.Show(string.Format(Configuration.Settings.Language.General.UserNameAlreadyInUse, textBoxSessionKey.Text));
}
else
{
MessageBox.Show(message);
}
}
}
catch (Exception exception)

View File

@ -1,4 +1,4 @@
namespace Nikse.SubtitleEdit.Forms
namespace Nikse.SubtitleEdit.Forms.Networking
{
partial class NetworkLogAndInfo
{

View File

@ -1,9 +1,9 @@
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Logic;
using System;
using System;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Forms
namespace Nikse.SubtitleEdit.Forms.Networking
{
public sealed partial class NetworkLogAndInfo : Form
{
@ -21,12 +21,12 @@ namespace Nikse.SubtitleEdit.Forms
buttonOK.Text = Configuration.Settings.Language.General.Ok;
}
internal void Initialize(Logic.Networking.NikseWebServiceSession _networkSession)
internal void Initialize(Logic.Networking.NikseWebServiceSession networkSession)
{
textBoxSessionKey.Text = _networkSession.SessionId;
textBoxUserName.Text = _networkSession.CurrentUser.UserName;
textBoxWebServiceUrl.Text = _networkSession.WebServiceUrl;
textBoxLog.Text = _networkSession.GetLog();
textBoxSessionKey.Text = networkSession.SessionId;
textBoxUserName.Text = networkSession.CurrentUser.UserName;
textBoxWebServiceUrl.Text = networkSession.WebServiceUrl;
textBoxLog.Text = networkSession.GetLog();
}
private void buttonOK_Click(object sender, EventArgs e)
@ -37,7 +37,9 @@ namespace Nikse.SubtitleEdit.Forms
private void NetworkLogAndInfo_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
}
}

View File

@ -1,4 +1,4 @@
namespace Nikse.SubtitleEdit.Forms
namespace Nikse.SubtitleEdit.Forms.Networking
{
partial class NetworkStart
{

View File

@ -1,10 +1,10 @@
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Logic;
using System;
using System;
using System.Net;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Forms
namespace Nikse.SubtitleEdit.Forms.Networking
{
public sealed partial class NetworkStart : PositionAndSizeForm
{
@ -36,12 +36,16 @@ namespace Nikse.SubtitleEdit.Forms
textBoxSessionKey.Text = Configuration.Settings.NetworkSettings.SessionKey;
if (textBoxSessionKey.Text.Trim().Length < 2)
{
textBoxSessionKey.Text = Guid.NewGuid().ToString().RemoveChar('-');
}
comboBoxWebServiceUrl.Text = Configuration.Settings.NetworkSettings.WebServiceUrl;
textBoxUserName.Text = Configuration.Settings.NetworkSettings.UserName;
if (textBoxUserName.Text.Trim().Length < 2)
{
textBoxUserName.Text = Dns.GetHostName();
}
}
private void buttonStart_Click(object sender, EventArgs e)

View File

@ -20,7 +20,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private List<VobSubOcr.CompareMatch> _matches;
private List<ImageSplitterItem> _splitterItems;
private int _startIndex;
int _extraCount = 0;
int _extraCount;
internal void Initialize(int selectedIndex, List<VobSubOcr.CompareMatch> matches, List<ImageSplitterItem> splitterItems)
{
@ -28,7 +28,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
for (int i = 0; i < selectedIndex; i++)
{
if (matches[i].Extra != null && matches[i].Extra.Count > 0)
{
_extraCount += matches[i].Extra.Count -1;
}
}
_matches = matches;
@ -37,16 +39,27 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
for (int i = _startIndex; i < _splitterItems.Count - _extraCount; i++)
{
if (i >= _matches.Count)
{
break;
}
var m = _matches[i];
if (m.Extra?.Count > 0)
{
break;
}
if (m.Text != Configuration.Settings.Language.VobSubOcr.NoMatch && (m.ImageSplitterItem?.NikseBitmap == null || !string.IsNullOrWhiteSpace(m.ImageSplitterItem.SpecialCharacter)))
{
break;
}
count++;
listBoxInspectItems.Items.Add(m);
if (count < 3)
{
listBoxInspectItems.SetSelected(listBoxInspectItems.Items.Count - 1, true);
}
}
numericUpDownExpandCount.Maximum = listBoxInspectItems.Items.Count;
MakeExpandImage();
@ -65,7 +78,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
var splitterItem = _splitterItems[_startIndex + _extraCount];
if (splitterItem.NikseBitmap == null)
{
return;
}
ExpandedMatch = new BinaryOcrBitmap(new NikseBitmap(splitterItem.NikseBitmap), false, (int)numericUpDownExpandCount.Value, string.Empty, splitterItem.X, splitterItem.Y) { ExpandedList = new List<BinaryOcrBitmap>() };
for (int i = 1; i < listBoxInspectItems.Items.Count; i++)
{
@ -73,7 +89,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
splitterItem = _splitterItems[_startIndex + i + _extraCount];
if (splitterItem.NikseBitmap == null)
{
break;
}
ExpandedMatch.ExpandedList.Add(new BinaryOcrBitmap(splitterItem.NikseBitmap, false, 0, null, splitterItem.X, splitterItem.Y));
}
}
@ -87,7 +106,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void buttonOK_Click(object sender, System.EventArgs e)
{
if (string.IsNullOrWhiteSpace(textBoxText.Text))
{
return;
}
ExpandedMatch.Italic = checkBoxItalic.Checked;
ExpandedMatch.Text = textBoxText.Text;
@ -103,7 +124,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void AddBeterMultiMatch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
}
}

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Forms.Ocr
{
partial class AddToOcrReplaceList
sealed partial class AddToOcrReplaceList
{
/// <summary>
/// Required designer variable.

View File

@ -7,7 +7,7 @@ using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms.Ocr
{
public partial class AddToOcrReplaceList : Form
public sealed partial class AddToOcrReplaceList : Form
{
private string _threeLetterIsoLanguageName;
@ -29,7 +29,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
string key = textBoxOcrFixKey.Text.RemoveControlCharacters().Trim();
string value = textBoxOcrFixValue.Text.RemoveControlCharacters().Trim();
if (key.Length == 0 || value.Length == 0 || key == value)
{
return;
}
var languageString = LanguageString;
if (languageString == null)
@ -61,7 +63,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void AddToOcrReplaceList_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
public string NewSource { get; set; }
@ -70,14 +74,18 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
internal void Initialize(string languageId, string hunspellName, string source)
{
if (!string.IsNullOrEmpty(source))
{
textBoxOcrFixKey.Text = source;
}
comboBoxDictionaries.Items.Clear();
foreach (string name in Utilities.GetDictionaryLanguages())
{
comboBoxDictionaries.Items.Add(name);
if (hunspellName != null && name.Equals(hunspellName, StringComparison.OrdinalIgnoreCase))
{
comboBoxDictionaries.SelectedIndex = comboBoxDictionaries.Items.Count - 1;
}
}
_threeLetterIsoLanguageName = languageId;
}

View File

@ -32,7 +32,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
string dictionaryFolder = Configuration.Tesseract302Directory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
var tempFileName = FileUtil.GetTempFileName(".tar");
using (var ms = new MemoryStream(e.Result))

View File

@ -34,7 +34,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
string dictionaryFolder = Configuration.TesseractDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
var tempFileName = FileUtil.GetTempFileName(".tar");
using (var ms = new MemoryStream(e.Result))

View File

@ -14,9 +14,8 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
public sealed partial class GetTesseract302Dictionaries : Form
{
private List<string> _dictionaryDownloadLinks = new List<string>();
private List<string> _descriptions = new List<string>();
private string _xmlName = null;
private string _dictionaryFileName = null;
private string _xmlName;
private string _dictionaryFileName;
internal string ChosenLanguage { get; private set; }
public GetTesseract302Dictionaries()
@ -39,7 +38,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void LoadDictionaryList(string xmlRessourceName)
{
_dictionaryDownloadLinks = new List<string>();
_descriptions = new List<string>();
_xmlName = xmlRessourceName;
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
Stream strm = asm.GetManifestResourceStream(_xmlName);
@ -67,18 +65,12 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
string englishName = node.SelectSingleNode("EnglishName").InnerText;
string downloadLink = node.SelectSingleNode("DownloadLink").InnerText;
string description = string.Empty;
if (node.SelectSingleNode("Description") != null)
description = node.SelectSingleNode("Description").InnerText;
if (!string.IsNullOrEmpty(downloadLink))
{
string name = englishName;
comboBoxDictionaries.Items.Add(name);
_dictionaryDownloadLinks.Add(downloadLink);
_descriptions.Add(description);
}
comboBoxDictionaries.SelectedIndex = 0;
}
@ -90,7 +82,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void FixLargeFonts()
{
if (labelDescription1.Left + labelDescription1.Width + 5 > Width)
{
Width = labelDescription1.Left + labelDescription1.Width + 5;
}
UiUtil.FixLargeFonts(this, buttonOK);
}
@ -148,7 +143,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
string dictionaryFolder = Configuration.Tesseract302DataDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
int index = comboBoxDictionaries.SelectedIndex;
@ -194,7 +191,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
string dictionaryFolder = Configuration.Tesseract302DataDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
int index = comboBoxDictionaries.SelectedIndex;
@ -221,7 +220,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
string dictionaryFolder = Configuration.Tesseract302DataDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
System.Diagnostics.Process.Start(dictionaryFolder);
}

View File

@ -53,7 +53,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void FixLargeFonts()
{
if (labelDescription1.Left + labelDescription1.Width + 5 > Width)
{
Width = labelDescription1.Left + labelDescription1.Width + 5;
}
UiUtil.FixLargeFonts(this, buttonOK);
}
@ -111,7 +114,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
string dictionaryFolder = Configuration.TesseractDataDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
int index = comboBoxDictionaries.SelectedIndex;
@ -157,7 +162,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
string dictionaryFolder = Configuration.TesseractDataDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
int index = comboBoxDictionaries.SelectedIndex;
@ -184,7 +191,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
string dictionaryFolder = Configuration.TesseractDataDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
System.Diagnostics.Process.Start(dictionaryFolder);
}

View File

@ -29,14 +29,8 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
public bool IsBinaryImageCompare
{
get
{
return buttonEditImageDb.Visible;
}
set
{
buttonEditImageDb.Visible = value;
}
get => buttonEditImageDb.Visible;
set => buttonEditImageDb.Visible = value;
}
public Action ActionResult { get; private set; }
public string Word { get; private set; }
@ -98,9 +92,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
textBoxWholeText.Text = line;
listBoxSuggestions.Items.Clear();
foreach (string suggestion in suggestions)
{
listBoxSuggestions.Items.Add(suggestion);
}
if (listBoxSuggestions.Items.Count > 0)
{
listBoxSuggestions.SelectedIndex = 0;
}
HighLightWord(richTextBoxParagraph, word);
ButtonEditWordClick(null, null);
@ -117,12 +116,18 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
bool startOk = i == 0;
if (!startOk)
{
startOk = expectedWordBoundaryChars.Contains(richTextBoxParagraph.Text[i - 1]);
}
if (startOk)
{
bool endOk = (i + word.Length == richTextBoxParagraph.Text.Length);
if (!endOk)
{
endOk = expectedWordBoundaryChars.Contains(richTextBoxParagraph.Text[i + word.Length]);
}
if (endOk)
{
richTextBoxParagraph.SelectionStart = i + 1;
@ -288,7 +293,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
string text = textBoxWord.Text;
if (!string.IsNullOrWhiteSpace(text))
{
System.Diagnostics.Process.Start("https://www.google.com/search?q=" + Utilities.UrlEncode(text));
}
}
private void OcrSpellCheck_KeyDown(object sender, KeyEventArgs e)

View File

@ -75,11 +75,18 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
n.ReplaceYellowWithWhite();
}
if (panelColorToWhite.BackColor != Color.Transparent)
{
n.ReplaceColor(panelColorToWhite.BackColor.A, panelColorToWhite.BackColor.R, panelColorToWhite.BackColor.G, panelColorToWhite.BackColor.B, 255, 255, 255, 255);
}
if (panelColorToRemove.BackColor != Color.Transparent)
{
n.ReplaceColor(panelColorToRemove.BackColor.A, panelColorToRemove.BackColor.R, panelColorToRemove.BackColor.G, panelColorToRemove.BackColor.B, Color.Transparent.A, Color.Transparent.R, Color.Transparent.G, Color.Transparent.B);
}
if (_isBinaryImageCompare)
{
n.MakeTwoColor((int)numericUpDownThreshold.Value);
}
pictureBox1.Image = n.GetBitmap();
}
@ -95,9 +102,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void pictureBoxSubtitleImage_Click(object sender, EventArgs e)
{
var bmp = pictureBoxSubtitleImage.Image as Bitmap;
if (bmp == null)
if (!(pictureBoxSubtitleImage.Image is Bitmap))
{
return;
}
Text = MousePosition.X + ":" + MousePosition.Y;
}

View File

@ -9,13 +9,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
public partial class OcrPreprocessingT4 : Form
{
private readonly bool _isBinaryImageCompare;
private readonly NikseBitmap _source;
public PreprocessingSettings PreprocessingSettings { get; }
public OcrPreprocessingT4(Bitmap bitmap, bool isBinaryImageCompare, PreprocessingSettings preprocessingSettings)
public OcrPreprocessingT4(Bitmap bitmap, PreprocessingSettings preprocessingSettings)
{
_isBinaryImageCompare = isBinaryImageCompare;
InitializeComponent();
_source = new NikseBitmap(bitmap);
pictureBoxSubtitleImage.Image = bitmap;
@ -68,10 +66,5 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
DialogResult = DialogResult.Cancel;
}
}
private void checkBoxCropTransparent_CheckedChanged(object sender, EventArgs e)
{
RefreshImage();
}
}
}

View File

@ -102,7 +102,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count < 1)
{
return;
}
var item = listView1.SelectedItems[0];
var bob = (BinaryOcrBitmap)item.Tag;
@ -119,6 +121,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
}
catch (Exception)
{
// ignored
}
}
@ -134,10 +137,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
listView1.ItemChecked -= listView1_ItemChecked;
foreach (ListViewItem item in listView1.Items)
{
item.Checked = true;
}
foreach (ListViewData d in _data)
{
d.Checked = true;
}
UpdateSelectCount();
@ -149,10 +156,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
listView1.ItemChecked -= listView1_ItemChecked;
foreach (ListViewItem item in listView1.Items)
{
item.Checked = !item.Checked;
}
foreach (ListViewData d in _data)
{
d.Checked = !d.Checked;
}
UpdateSelectCount();
@ -167,7 +178,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (e.Item == null)
{
return;
}
var idx = e.Item.Index;
_data[idx].Checked = listView1.Items[idx].Checked;
@ -184,7 +197,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
_selectCount++;
}
}
buttonImport.Text = string.Format("Import {0:#,##0}", _selectCount);
buttonImport.Text = $"Import {_selectCount:#,##0}";
}
private void buttonImport_Click(object sender, EventArgs e)

View File

@ -15,7 +15,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private readonly XmlDocument _compareDoc = new XmlDocument();
private readonly string _directoryPath;
private List<bool> _italics = new List<bool>();
internal List<VobSubOcr.ImageCompareAddition> Additions { get; private set; }
internal List<VobSubOcr.ImageCompareAddition> Additions { get; }
private readonly BinaryOcrDb _binOcrDb;
public XmlDocument ImageCompareDocument => _compareDoc;
@ -33,7 +33,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
Additions = new List<VobSubOcr.ImageCompareAddition>();
foreach (var a in additions)
{
Additions.Add(a);
}
const int makeHigher = 40;
labelImageCompareFiles.Top = labelImageCompareFiles.Top - makeHigher;
@ -48,9 +50,13 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
_directoryPath = Configuration.VobSubCompareDirectory + databaseFolderName + Path.DirectorySeparatorChar;
if (!File.Exists(_directoryPath + "Images.xml"))
{
_compareDoc.LoadXml("<OcrBitmaps></OcrBitmaps>");
}
else
{
_compareDoc.Load(_directoryPath + "Images.xml");
}
Refill(Additions);
@ -136,7 +142,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
}
if (listBoxFileNames.Items.Count > 0)
{
listBoxFileNames.SelectedIndex = 0;
}
}
private void FillComboWithUniqueAndSortedTexts()
@ -150,14 +158,20 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
string text = bob.Text;
if (!texts.Contains(text) && text != null)
{
texts.Add(text);
}
count++;
}
foreach (BinaryOcrBitmap bob in _binOcrDb.CompareImagesExpanded)
{
string text = bob.Text;
if (!texts.Contains(text) && text != null)
{
texts.Add(text);
}
count++;
}
}
@ -169,7 +183,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
string text = node.Attributes["Text"].InnerText;
if (!texts.Contains(text))
{
texts.Add(text);
}
count++;
}
}
@ -184,7 +201,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
}
if (comboBoxTexts.Items.Count > 0)
{
comboBoxTexts.SelectedIndex = 0;
}
}
private void ComboBoxTextsSelectedIndexChanged(object sender, EventArgs e)
@ -232,14 +251,19 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
}
if (listBoxFileNames.Items.Count > 0)
{
listBoxFileNames.SelectedIndex = 0;
}
}
private string GetSelectedFileName()
{
string fileName = listBoxFileNames.SelectedItem.ToString();
if (fileName.StartsWith('['))
{
fileName = fileName.Substring(fileName.IndexOf(']') + 1);
}
return fileName.Trim();
}
@ -247,7 +271,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
int idx = listBoxFileNames.SelectedIndex;
if (idx < 0 || _binOcrDb == null)
{
return null;
}
return listBoxFileNames.Items[idx] as BinaryOcrBitmap;
}
@ -256,7 +282,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
string fileName = listBoxFileNames.Items[index].ToString();
if (fileName.StartsWith('['))
{
fileName = fileName.Substring(fileName.IndexOf(']') + 1);
}
return fileName.Trim();
}
@ -291,7 +320,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
using (var f = new FileStream(databaseName, FileMode.Open))
{
if (name.Contains(']'))
{
name = name.Substring(name.IndexOf(']') + 1).Trim();
}
f.Position = Convert.ToInt64(name);
bmp = new ManagedBitmap(f).ToOldBitmap();
}
@ -347,13 +379,17 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void VobSubEditCharacters_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
private void ButtonUpdateClick(object sender, EventArgs e)
{
if (listBoxFileNames.Items.Count == 0)
{
return;
}
string target = GetSelectedFileName();
string newText = textBoxText.Text;
@ -364,7 +400,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
var bob = GetSelectedBinOcrBitmap();
if (bob == null)
{
return;
}
string oldText = bob.Text;
bob.Text = newText;
@ -387,9 +425,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (oldText == newText)
{
if (oldTextItem >= 0 && oldTextItem < comboBoxTexts.Items.Count)
{
comboBoxTexts.SelectedIndex = oldTextItem;
}
if (oldListBoxFileNamesIndex >= 0 && oldListBoxFileNamesIndex < listBoxFileNames.Items.Count)
{
listBoxFileNames.SelectedIndex = oldListBoxFileNamesIndex;
}
}
else
{
@ -467,7 +510,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
for (int j = 0; j < listBoxFileNames.Items.Count; j++)
{
if (GetFileName(j).StartsWith(target, StringComparison.Ordinal))
{
listBoxFileNames.SelectedIndex = j;
}
}
return;
}
@ -490,7 +535,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void ButtonDeleteClick(object sender, EventArgs e)
{
if (listBoxFileNames.Items.Count == 0)
{
return;
}
int oldComboBoxIndex = comboBoxTexts.SelectedIndex;
string target = GetSelectedFileName();
@ -501,9 +548,13 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (bob != null)
{
if (bob.ExpandCount > 0)
{
_binOcrDb.CompareImagesExpanded.Remove(bob);
}
else
{
_binOcrDb.CompareImages.Remove(bob);
}
if (Additions != null && Additions.Count > 0)
{
@ -520,7 +571,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Refill(Additions);
}
if (oldComboBoxIndex >= 0 && oldComboBoxIndex < comboBoxTexts.Items.Count)
{
comboBoxTexts.SelectedIndex = oldComboBoxIndex;
}
return;
}
@ -545,7 +599,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (Additions == null || Additions.Count == 0)
{
if (oldComboBoxIndex < comboBoxTexts.Items.Count)
{
comboBoxTexts.SelectedIndex = oldComboBoxIndex;
}
}
}
}
@ -564,7 +620,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
for (int j = 0; j < listBoxFileNames.Items.Count; j++)
{
if ((listBoxFileNames.Items[j] as BinaryOcrBitmap).Key == name)
{
listBoxFileNames.SelectedIndex = j;
}
}
}
else
@ -572,7 +630,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
for (int j = 0; j < listBoxFileNames.Items.Count; j++)
{
if (GetFileName(j).StartsWith(name, StringComparison.Ordinal))
{
listBoxFileNames.SelectedIndex = j;
}
}
}
return;
@ -618,13 +678,21 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
try
{
if (saveFileDialog1.FilterIndex == 0)
{
bmp.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png);
}
else if (saveFileDialog1.FilterIndex == 1)
{
bmp.Save(saveFileDialog1.FileName);
}
else if (saveFileDialog1.FilterIndex == 2)
{
bmp.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Gif);
}
else
{
bmp.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Tiff);
}
}
catch (Exception exception)
{

View File

@ -29,7 +29,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void VobSubNOcrCharacterInspect_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
internal void Initialize(Bitmap bitmap, int pixelsIsSpace, bool rightToLeft, NOcrDb nOcrDb, VobSubOcr vobSubOcr)
@ -45,7 +47,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
const int minLineHeight = 6;
_imageList = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nbmp, pixelsIsSpace, rightToLeft, Configuration.Settings.VobSubOcr.TopToBottom, minLineHeight);
// _imageList = NikseBitmapImageSplitter.SplitBitmapToLetters(nbmp, pixelsIsSpace, rightToLeft, Configuration.Settings.VobSubOcr.TopToBottom);
int index = 0;
while (index < _imageList.Count)
@ -84,7 +85,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void listBoxInspectItems_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBoxInspectItems.SelectedIndex < 0)
{
return;
}
var img = _imageList[listBoxInspectItems.SelectedIndex];
if (img.NikseBitmap != null)
@ -150,7 +153,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void pictureBoxCharacter_Paint(object sender, PaintEventArgs e)
{
if (_nocrChar == null)
{
return;
}
var foreground = new Pen(new SolidBrush(Color.Green));
var background = new Pen(new SolidBrush(Color.Red));
@ -169,16 +174,12 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void SizePictureBox()
{
if (pictureBoxCharacter.Image != null)
if (pictureBoxCharacter.Image is Bitmap bmp)
{
var bmp = pictureBoxCharacter.Image as Bitmap;
if (bmp != null)
{
pictureBoxCharacter.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBoxCharacter.Width = (int)Math.Round(bmp.Width * _zoomFactor);
pictureBoxCharacter.Height = (int)Math.Round(bmp.Height * _zoomFactor);
pictureBoxCharacter.Invalidate();
}
pictureBoxCharacter.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBoxCharacter.Width = (int)Math.Round(bmp.Width * _zoomFactor);
pictureBoxCharacter.Height = (int)Math.Round(bmp.Height * _zoomFactor);
pictureBoxCharacter.Invalidate();
}
}
@ -225,12 +226,16 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
var expandSelectionList = new List<ImageSplitterItem>();
if (listBoxInspectItems.SelectedIndex < 0)
{
return;
}
int index = listBoxInspectItems.SelectedIndex;
var img = _imageList[index];
if (img.NikseBitmap == null)
{
return;
}
using (var vobSubOcrNOcrCharacter = new VobSubOcrNOcrCharacter())
{
@ -268,7 +273,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
shrinkSelection = true;
index--;
if (expandSelectionList.Count > 0)
{
expandSelectionList.RemoveAt(expandSelectionList.Count - 1);
}
}
else if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ExpandSelection)
{
@ -280,7 +287,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (result == DialogResult.OK)
{
if (expandSelectionList.Count > 1)
{
vobSubOcrNOcrCharacter.NOcrChar.ExpandCount = expandSelectionList.Count;
}
_nocrChars.Add(vobSubOcrNOcrCharacter.NOcrChar);
_vobSubOcr.SaveNOcrWithCurrentLanguage();
DialogResult = DialogResult.OK;

View File

@ -10,8 +10,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
public partial class VobSubNOcrEdit : Form
{
private List<NOcrChar> _nocrChars;
private readonly List<NOcrChar> _nocrChars;
private NOcrChar _nocrChar;
private double _zoomFactor = 5.0;
private bool _drawLineOn;
@ -20,7 +19,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private Point _end;
private int _mx;
private int _my;
private Bitmap _bitmap;
private readonly Bitmap _bitmap;
private List<NOcrChar> _history = new List<NOcrChar>();
private int _historyIndex = -1;
@ -41,7 +40,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
SizePictureBox();
}
labelInfo.Text = string.Format("{0} elements in database", nocrChars.Count);
labelInfo.Text = $"{nocrChars.Count} elements in database";
labelNOcrCharInfo.Text = string.Empty;
}
@ -51,7 +50,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
foreach (NOcrChar c in _nocrChars)
{
if (!list.Contains(c.Text))
{
list.Add(c.Text);
}
}
list.Sort();
comboBoxTexts.Items.Clear();
@ -168,7 +169,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
labelNOcrCharInfo.Text = string.Empty;
if (listBoxFileNames.SelectedIndex < 0)
{
return;
}
_nocrChar = listBoxFileNames.Items[listBoxFileNames.SelectedIndex] as NOcrChar;
if (_nocrChar == null)
@ -194,7 +197,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
}
else
{
groupBoxCurrentCompareImage.BackColor = Control.DefaultBackColor;
groupBoxCurrentCompareImage.BackColor = DefaultBackColor;
}
}
_drawLineOn = false;
@ -217,7 +220,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void comboBoxTexts_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBoxTexts.SelectedIndex < 0)
{
return;
}
listBoxFileNames.Items.Clear();
string text = comboBoxTexts.Items[comboBoxTexts.SelectedIndex].ToString();
@ -229,13 +234,17 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
}
}
if (listBoxFileNames.Items.Count > 0)
{
listBoxFileNames.SelectedIndex = 0;
}
}
private void pictureBoxCharacter_Paint(object sender, PaintEventArgs e)
{
if (_nocrChar == null)
{
return;
}
NOcrPoint selectedPoint = null;
if (listBoxLinesForeground.Focused && listBoxLinesForeground.SelectedIndex >= 0)
@ -258,10 +267,15 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Point start = op.GetScaledStart(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height);
Point end = op.GetScaledEnd(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height);
if (start.X == end.X && start.Y == end.Y)
{
end.X++;
}
e.Graphics.DrawLine(foreground, start, end);
if (op == selectedPoint)
{
e.Graphics.DrawLine(selPenF, op.GetScaledStart(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height), op.GetScaledEnd(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height));
}
}
foreach (NOcrPoint op in _nocrChar.LinesBackground)
{
@ -269,7 +283,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Point end = op.GetScaledEnd(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height);
e.Graphics.DrawLine(background, start, end);
if (op == selectedPoint)
{
e.Graphics.DrawLine(selPenB, op.GetScaledStart(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height), op.GetScaledEnd(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height));
}
}
}
@ -279,7 +295,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
var p = foreground;
if (radioButtonCold.Checked)
{
p = background;
}
e.Graphics.DrawLine(p, new Point((int)Math.Round(_start.X * _zoomFactor), (int)Math.Round(_start.Y * _zoomFactor)), new Point(_mx, _my));
}
}
@ -292,12 +311,16 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void buttonDelete_Click(object sender, EventArgs e)
{
if (listBoxFileNames.Items.Count == 0 || _nocrChar == null)
{
return;
}
_nocrChars.Remove(_nocrChar);
FillComboBox();
if (comboBoxTexts.Items.Count > 0)
{
comboBoxTexts.SelectedIndex = 0;
}
}
private void buttonOK_Click(object sender, EventArgs e)
@ -315,7 +338,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (_historyIndex > 0 && _historyIndex < _history.Count - 1)
{
while (_history.Count > _historyIndex + 1)
{
_history.RemoveAt(_history.Count - 1);
}
_historyIndex = _history.Count - 1;
}
_history.Add(new NOcrChar(nocrChar));
@ -362,9 +388,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
_nocrChar.Width = pictureBoxCharacter.Image.Width;
_nocrChar.Height = pictureBoxCharacter.Image.Height;
if (radioButtonHot.Checked)
{
_nocrChar.LinesForeground.Add(new NOcrPoint(_start, _end));
}
else
{
_nocrChar.LinesBackground.Add(new NOcrPoint(_start, _end));
}
_drawLineOn = false;
pictureBoxCharacter.Invalidate();
ShowOcrPoints();
@ -508,7 +539,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
notImportedCount++;
}
}
MessageBox.Show(string.Format("Number of characters imported: {0}\r\nNumber of characters not imported (already present): {1}", importedCount, notImportedCount));
MessageBox.Show($"Number of characters imported: {importedCount}\r\nNumber of characters not imported (already present): {notImportedCount}");
}
}

View File

@ -77,7 +77,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
var nOcrD = new NOcrDb(textBoxNOcrDb.Text);
var lines = new List<string>();
foreach (string line in File.ReadAllLines(textBoxInputFile.Text))
{
lines.Add(line);
}
var format = new SubRip();
var sub = new Subtitle();
format.LoadSubtitle(sub, lines, textBoxInputFile.Text);
@ -101,7 +104,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
TrainLetter(ref numberOfCharactersLeaned, ref numberOfCharactersSkipped, nOcrD, charactersLearned, s, false);
if (checkBoxBold.Checked)
{
TrainLetter(ref numberOfCharactersLeaned, ref numberOfCharactersSkipped, nOcrD, charactersLearned, s, true);
}
}
}
}
@ -158,7 +163,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
var fontStyle = FontStyle.Regular;
if (subtitleFontBold)
{
fontStyle = FontStyle.Bold;
}
font = new Font(_subtitleFontName, _subtitleFontSize, fontStyle);
}
catch (Exception exception)
@ -178,9 +186,15 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
int sizeX = (int)(textSize.Width * 0.8) + 40;
int sizeY = (int)(textSize.Height * 0.8) + 30;
if (sizeX < 1)
{
sizeX = 1;
}
if (sizeY < 1)
{
sizeY = 1;
}
bmp = new Bitmap(sizeX, sizeY);
g = Graphics.FromImage(bmp);
@ -231,7 +245,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
i++;
}
if (sb.Length > 0)
{
TextDraw.DrawText(font, sf, path, sb, false, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
}
sf.Dispose();
g.DrawPath(new Pen(_borderColor, BorderWidth), path);

File diff suppressed because it is too large Load Diff

View File

@ -43,29 +43,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
UiUtil.FixLargeFonts(this, buttonCancel);
}
public string ManualRecognizedCharacters
{
get
{
return textBoxCharacters.Text;
}
}
public string ManualRecognizedCharacters => textBoxCharacters.Text;
public bool IsItalic
{
get
{
return checkBoxItalic.Checked;
}
}
public bool IsItalic => checkBoxItalic.Checked;
public Point FormPosition
{
get
{
return new Point(Left, Top);
}
}
public Point FormPosition => new Point(Left, Top);
public bool ExpandSelection { get; private set; }
@ -108,9 +90,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
var last = _additions[_additions.Count - 1];
buttonLastEdit.Visible = true;
if (last.Italic)
{
buttonLastEdit.Font = new Font(buttonLastEdit.Font.FontFamily, buttonLastEdit.Font.Size, FontStyle.Italic);
}
else
{
buttonLastEdit.Font = new Font(buttonLastEdit.Font.FontFamily, buttonLastEdit.Font.Size);
}
pictureBoxLastEdit.Visible = true;
pictureBoxLastEdit.Image = last.Image.GetBitmap();
buttonLastEdit.Text = string.Format(Configuration.Settings.Language.VobSubOcrCharacter.EditLastX, last.Text);
@ -147,9 +134,13 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void TextBoxCharactersKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
DialogResult = DialogResult.OK;
}
else if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
private void CheckBoxItalicCheckedChanged(object sender, EventArgs e)
@ -211,15 +202,18 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void InsertLanguageCharacter(object sender, EventArgs e)
{
var toolStripMenuItem = sender as ToolStripMenuItem;
if (toolStripMenuItem != null)
if (sender is ToolStripMenuItem toolStripMenuItem)
{
textBoxCharacters.Text = textBoxCharacters.Text.Insert(textBoxCharacters.SelectionStart, toolStripMenuItem.Text);
}
}
private void textBoxCharacters_TextChanged(object sender, EventArgs e)
{
if (checkBoxAutoSubmitOfFirstChar.Checked && textBoxCharacters.Text.Length > 0)
{
DialogResult = DialogResult.OK;
}
}
private void VobSubOcrCharacter_Shown(object sender, EventArgs e)

View File

@ -58,15 +58,25 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
ImageCompareDocument = new XmlDocument();
_directoryPath = Configuration.VobSubCompareDirectory + databaseFolderName + Path.DirectorySeparatorChar;
if (!File.Exists(_directoryPath + "Images.xml"))
{
ImageCompareDocument.LoadXml("<OcrBitmaps></OcrBitmaps>");
}
else
{
ImageCompareDocument.Load(_directoryPath + "Images.xml");
}
}
for (int i = 0; i < _matches.Count; i++)
{
listBoxInspectItems.Items.Add(_matches[i]);
}
if (listBoxInspectItems.Items.Count > 0)
{
listBoxInspectItems.SelectedIndex = 0;
}
ShowCount();
}
@ -76,7 +86,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
labelExpandCount.Text = string.Empty;
if (listBoxInspectItems.SelectedIndex < 0)
{
return;
}
_selectedCompareNode = null;
_selectedCompareBinaryOcrBitmap = null;
@ -208,14 +220,19 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
pictureBoxCompareBitmapDouble.Visible = false;
labelDoubleSize.Visible = false;
if (img == null)
{
buttonAddBetterMatch.Enabled = false;
}
}
else
{
buttonUpdate.Enabled = true;
buttonDelete.Enabled = true;
if (_selectedCompareNode != null)
{
buttonAddBetterMatch.Enabled = true;
}
textBoxText.Enabled = true;
checkBoxItalic.Enabled = true;
pictureBoxCompareBitmap.Visible = true;
@ -237,7 +254,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (_selectedCompareNode == null && _selectedCompareBinaryOcrBitmap == null)
{
return;
}
string newText = textBoxText.Text;
@ -260,9 +279,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
_selectedCompareBinaryOcrBitmap.Italic = checkBoxItalic.Checked;
listBoxInspectItems.SelectedIndexChanged -= listBoxInspectItems_SelectedIndexChanged;
if (checkBoxItalic.Checked)
{
listBoxInspectItems.Items[listBoxInspectItems.SelectedIndex] = newText + " (italic)";
}
else
{
listBoxInspectItems.Items[listBoxInspectItems.SelectedIndex] = newText;
}
listBoxInspectItems.SelectedIndexChanged += listBoxInspectItems_SelectedIndexChanged;
}
else
@ -281,7 +305,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void SetItalic(XmlNode node)
{
if (node?.Attributes == null || node.OwnerDocument == null)
{
return;
}
if (checkBoxItalic.Checked)
{
@ -304,15 +330,22 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void buttonDelete_Click(object sender, EventArgs e)
{
if (_selectedCompareNode == null && _selectedCompareBinaryOcrBitmap == null)
{
return;
}
listBoxInspectItems.Items[listBoxInspectItems.SelectedIndex] = Configuration.Settings.Language.VobSubOcr.NoMatch;
if (_selectedCompareBinaryOcrBitmap != null)
{
if (_selectedCompareBinaryOcrBitmap.ExpandCount > 0)
{
_binOcrDb.CompareImagesExpanded.Remove(_selectedCompareBinaryOcrBitmap);
}
else
{
_binOcrDb.CompareImages.Remove(_selectedCompareBinaryOcrBitmap);
}
_selectedCompareBinaryOcrBitmap = null;
_binOcrDb.Save();
}
@ -327,7 +360,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void buttonAddBetterMatch_Click(object sender, EventArgs e)
{
if (listBoxInspectItems.SelectedIndex < 0)
{
return;
}
if (listBoxInspectItems.Items[listBoxInspectItems.SelectedIndex].ToString().Replace(" (italic)", string.Empty) == textBoxText.Text)
{
@ -382,7 +417,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
_matches[index].Text = textBoxText.Text;
listBoxInspectItems.Items.Clear();
for (int i = 0; i < _matches.Count; i++)
{
listBoxInspectItems.Items.Add(_matches[i].Text);
}
listBoxInspectItems.SelectedIndex = index;
listBoxInspectItems_SelectedIndexChanged(null, null);
ShowCount();
@ -446,7 +484,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
_matches[index].Text = textBoxText.Text;
listBoxInspectItems.Items.Clear();
for (int i = 0; i < _matches.Count; i++)
{
listBoxInspectItems.Items.Add(_matches[i].Text);
}
listBoxInspectItems.SelectedIndex = index;
ShowCount();
listBoxInspectItems_SelectedIndexChanged(null, null);
@ -471,7 +512,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (listBoxInspectItems.SelectedIndex < 0 ||
listBoxInspectItems.SelectedIndex == listBoxInspectItems.Items.Count - 1 ||
_binOcrDb == null ||
(_selectedCompareBinaryOcrBitmap != null && _selectedCompareBinaryOcrBitmap.ExpandCount > 1))
_selectedCompareBinaryOcrBitmap != null && _selectedCompareBinaryOcrBitmap.ExpandCount > 1)
{
e.Cancel = true;
return;

View File

@ -10,7 +10,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
public partial class VobSubOcrNOcrCharacter : Form
{
private NOcrChar _nocrChar = null;
private NOcrChar _nocrChar;
private bool _drawLineOn;
private bool _startDone;
private Point _start;
@ -20,7 +20,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private int _imageHeight;
private int _mx;
private int _my;
private bool _warningNoNotForegroundLinesShown = false;
private bool _warningNoNotForegroundLinesShown;
private List<NOcrChar> _history = new List<NOcrChar>();
private int _historyIndex = -1;
@ -33,33 +33,15 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
labelItalicOn.Visible = false;
}
public NOcrChar NOcrChar
{
get
{
return _nocrChar;
}
}
public NOcrChar NOcrChar => _nocrChar;
public Point FormPosition
{
get
{
return new Point(Left, Top);
}
}
public Point FormPosition => new Point(Left, Top);
public bool ExpandSelection { get; private set; }
public bool ShrinkSelection { get; private set; }
public bool IsItalic
{
get
{
return checkBoxItalic.Checked;
}
}
public bool IsItalic => checkBoxItalic.Checked;
internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink)
{
@ -74,8 +56,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
ExpandSelection = false;
textBoxCharacters.Text = string.Empty;
_nocrChar = new NOcrChar();
_nocrChar.MarginTop = character.Y - character.ParentY;
_nocrChar = new NOcrChar { MarginTop = character.Y - character.ParentY };
_imageWidth = character.NikseBitmap.Width;
_imageHeight = character.NikseBitmap.Height;
_drawLineOn = false;
@ -215,10 +196,15 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Point start = op.GetScaledStart(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height);
Point end = op.GetScaledEnd(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height);
if (start.X == end.X && start.Y == end.Y)
{
end.X++;
}
e.Graphics.DrawLine(foreground, start, end);
if (op == selectedPoint)
{
e.Graphics.DrawLine(selPenF, op.GetScaledStart(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height), op.GetScaledEnd(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height));
}
}
foreach (NOcrPoint op in _nocrChar.LinesBackground)
{
@ -226,7 +212,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Point end = op.GetScaledEnd(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height);
e.Graphics.DrawLine(background, start, end);
if (op == selectedPoint)
{
e.Graphics.DrawLine(selPenB, op.GetScaledStart(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height), op.GetScaledEnd(_nocrChar, pictureBoxCharacter.Width, pictureBoxCharacter.Height));
}
}
}
@ -236,7 +224,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
var p = foreground;
if (radioButtonCold.Checked)
{
p = background;
}
e.Graphics.DrawLine(p, new Point((int)Math.Round(_start.X * _zoomFactor), (int)Math.Round(_start.Y * _zoomFactor)), new Point(_mx, _my));
}
}
@ -297,9 +288,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
_nocrChar.Width = pictureBoxCharacter.Image.Width;
_nocrChar.Height = pictureBoxCharacter.Image.Height;
if (radioButtonHot.Checked)
{
_nocrChar.LinesForeground.Add(new NOcrPoint(_start, _end));
}
else
{
_nocrChar.LinesBackground.Add(new NOcrPoint(_start, _end));
}
_drawLineOn = false;
pictureBoxCharacter.Invalidate();
ShowOcrPoints();
@ -335,7 +331,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (_historyIndex > 0 && _historyIndex < _history.Count - 1)
{
while (_history.Count > _historyIndex + 1)
{
_history.RemoveAt(_history.Count - 1);
}
_historyIndex = _history.Count - 1;
}
_history.Add(new NOcrChar(nocrChar));
@ -435,7 +434,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private static bool IsMatchPointForeGround(NOcrPoint op, bool loose, NikseBitmap nbmp, NOcrChar nOcrChar)
{
if (Math.Abs(op.Start.X - op.End.X) < 2 && Math.Abs(op.End.Y - op.Start.Y) < 2)
{
return false;
}
foreach (Point point in op.ScaledGetPoints(nOcrChar, nbmp.Width, nbmp.Height))
{
@ -607,7 +608,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
if (existingOp.Start.X == op.Start.X && existingOp.Start.Y == op.Start.Y &&
existingOp.End.X == op.End.X && existingOp.End.Y == op.End.Y)
{
ok = false;
}
}
if (ok && IsMatchPointForeGround(op, !tempVeryPrecise, nbmp, nOcrChar))
{
@ -617,7 +620,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
}
count++;
if (count > giveUpCount - 100 && !tempVeryPrecise)
{
tempVeryPrecise = true;
}
}
count = 0;
@ -663,7 +668,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
if (existingOp.Start.X == op.Start.X && existingOp.Start.Y == op.Start.Y &&
existingOp.End.X == op.End.X && existingOp.End.Y == op.End.Y)
{
ok = false;
}
}
if (ok && IsMatchPointBackGround(op, !tempVeryPrecise, nbmp, nOcrChar))
{
@ -674,7 +681,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
count++;
if (count > giveUpCount - 100 && !tempVeryPrecise)
{
tempVeryPrecise = true;
}
}
}

View File

@ -9,7 +9,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
public sealed partial class VobSubOcrNewFolder : Form
{
public string FolderName { get; set; }
private bool _vobSub = false;
private readonly bool _vobSub;
public VobSubOcrNewFolder(bool vobsub)
{
UiUtil.PreInitialize(this);
@ -28,7 +28,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void FormVobSubOcrNewFolder_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
private void ButtonOkClick(object sender, EventArgs e)
@ -73,7 +75,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void TextBoxFolderKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
ButtonOkClick(null, null);
}
}
}
}

View File

@ -8,7 +8,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
public sealed partial class VobSubOcrSetItalicFactor : Form
{
private Bitmap _bmp;
private readonly Bitmap _bmp;
private double _factor;
public VobSubOcrSetItalicFactor(Bitmap bmp, double factor)
@ -52,7 +52,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void VobSubOcrSetItalicFactor_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
private void saveImageAsToolStripMenuItem_Click(object sender, EventArgs e)
@ -76,13 +78,21 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
try
{
if (saveFileDialog1.FilterIndex == 0)
{
bmp.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png);
}
else if (saveFileDialog1.FilterIndex == 1)
{
bmp.Save(saveFileDialog1.FileName);
}
else if (saveFileDialog1.FilterIndex == 2)
{
bmp.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Gif);
}
else
{
bmp.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Tiff);
}
}
catch (Exception exception)
{

View File

@ -6,7 +6,6 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
public /* abstract */ class StylesForm : Form
{
private readonly Subtitle _subtitle;
private readonly Timer _previewTimer = new Timer();
private StylesForm()
@ -16,24 +15,15 @@ namespace Nikse.SubtitleEdit.Forms.Styles
protected StylesForm(Subtitle subtitle)
{
_subtitle = subtitle;
Subtitle = subtitle;
_previewTimer.Interval = 200;
_previewTimer.Tick += PreviewTimerTick;
}
public virtual string Header
{
get
{
throw new NotImplementedException("This property getter has to be overridden.");
}
}
public virtual string Header => throw new NotImplementedException("This property getter has to be overridden.");
protected Subtitle Subtitle
{
get { return _subtitle; }
}
protected Subtitle Subtitle { get; }
protected void GeneratePreview()
{

View File

@ -896,7 +896,9 @@ namespace Nikse.SubtitleEdit.Forms.Styles
listViewStyles.SelectedItems[0].Text = textBoxStyleName.Text;
bool found = SetSsaStyle(_oldSsaName, "name", textBoxStyleName.Text);
if (!found)
{
SetSsaStyle(_oldSsaName, "name", textBoxStyleName.Text, false);
}
_oldSsaName = textBoxStyleName.Text;
}

View File

@ -30,15 +30,18 @@ namespace Nikse.SubtitleEdit.Forms.Styles
_header = subtitle.Header;
_isSubStationAlpha = format.Name == SubStationAlpha.NameOfFormat;
if (_header == null || !_header.Contains("style:", StringComparison.OrdinalIgnoreCase))
{
ResetHeader();
}
comboBoxFontName.Items.Clear();
foreach (var x in FontFamily.Families)
{
comboBoxFontName.Items.Add(x.Name);
}
var l = Configuration.Settings.Language.SubStationAlphaStyles;
Text = l.Title;
// groupBoxStyles.Text = l.Styles;
groupBoxProperties.Text = l.Properties;
groupBoxFont.Text = l.Font;
labelFontName.Text = l.FontName;
@ -96,9 +99,13 @@ namespace Nikse.SubtitleEdit.Forms.Styles
comboBoxFontName.Left = labelFontName.Left + labelFontName.Width + 10;
numericUpDownFontSize.Left = labelFontSize.Left + labelFontSize.Width + 10;
if (comboBoxFontName.Left > numericUpDownFontSize.Left)
{
numericUpDownFontSize.Left = comboBoxFontName.Left;
}
else
{
comboBoxFontName.Left = numericUpDownFontSize.Left;
}
numericUpDownOutline.Left = radioButtonOutline.Left + radioButtonOutline.Width + 5;
labelShadow.Left = numericUpDownOutline.Left + numericUpDownOutline.Width + 5;
@ -137,9 +144,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string f = format[i].Trim().ToLower();
if (f == "name")
{
nameIndex = i;
}
if (f == propertyName)
{
propertyIndex = i;
}
}
}
sb.AppendLine(line);
@ -154,7 +166,9 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string f = format[i].Trim();
if (i == nameIndex)
{
correctLine = f.Equals(styleName, StringComparison.OrdinalIgnoreCase);
}
}
if (correctLine)
{
@ -164,11 +178,18 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string f = format[i].Trim();
if (i == propertyIndex)
{
sb.Append(propertyValue);
}
else
{
sb.Append(f);
}
if (i < format.Length - 1)
{
sb.Append(',');
}
}
sb.AppendLine();
}
@ -194,9 +215,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
SubtitleFormat format;
if (_isSubStationAlpha)
{
format = new SubStationAlpha();
}
else
{
format = new AdvancedSubStationAlpha();
}
var sub = new Subtitle();
string text = format.ToText(sub, string.Empty);
var lines = text.SplitToLines();
@ -217,7 +243,9 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void SubStationAlphaStylesBatchConvert_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
private void buttonReset_Click(object sender, EventArgs e)
@ -252,7 +280,10 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private string GetSsaColorString(Color c)
{
if (_isSubStationAlpha)
{
return Color.FromArgb(0, c.B, c.G, c.R).ToArgb().ToString(CultureInfo.InvariantCulture);
}
return AdvancedSubStationAlpha.GetSsaColorString(c);
}
@ -382,7 +413,10 @@ namespace Nikse.SubtitleEdit.Forms.Styles
string name = CurrentStyleName;
var item = comboBoxFontName.SelectedItem;
if (item != null)
{
SetSsaStyle(name, "fontname", item.ToString());
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -403,9 +437,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = CurrentStyleName;
if (checkBoxFontBold.Checked)
{
SetSsaStyle(name, "bold", "-1");
}
else
{
SetSsaStyle(name, "bold", "0");
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -416,9 +455,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = CurrentStyleName;
if (checkBoxFontItalic.Checked)
{
SetSsaStyle(name, "italic", "-1");
}
else
{
SetSsaStyle(name, "italic", "0");
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -429,9 +473,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = CurrentStyleName;
if (checkBoxFontUnderline.Checked)
{
SetSsaStyle(name, "underline", "-1");
}
else
{
SetSsaStyle(name, "underline", "0");
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -442,9 +491,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = CurrentStyleName;
if (_isSubStationAlpha)
{
SetSsaStyle(name, "alignment", "5");
}
else
{
SetSsaStyle(name, "alignment", "7");
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -455,9 +509,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = CurrentStyleName;
if (_isSubStationAlpha)
{
SetSsaStyle(name, "alignment", "6");
}
else
{
SetSsaStyle(name, "alignment", "8");
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -468,9 +527,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = CurrentStyleName;
if (_isSubStationAlpha)
{
SetSsaStyle(name, "alignment", "7");
}
else
{
SetSsaStyle(name, "alignment", "9");
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -481,9 +545,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = CurrentStyleName;
if (_isSubStationAlpha)
{
SetSsaStyle(name, "alignment", "9");
}
else
{
SetSsaStyle(name, "alignment", "4");
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -494,9 +563,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = CurrentStyleName;
if (_isSubStationAlpha)
{
SetSsaStyle(name, "alignment", "10");
}
else
{
SetSsaStyle(name, "alignment", "5");
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -507,9 +581,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = CurrentStyleName;
if (_isSubStationAlpha)
{
SetSsaStyle(name, "alignment", "11");
}
else
{
SetSsaStyle(name, "alignment", "6");
}
GeneratePreviewAndUpdateRawHeader();
}
}
@ -629,15 +708,21 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void UpdateRawHeader()
{
if (_header == null)
{
textBoxRawHeader.Text = string.Empty;
}
else
{
textBoxRawHeader.Text = _header.Replace("[Events]", string.Empty).TrimEnd();
}
}
private void UpdatePropertiesTag(string tag, string text, bool remove)
{
if (_header == null)
{
return;
}
bool scriptInfoOn = false;
var sb = new StringBuilder();
@ -665,7 +750,10 @@ namespace Nikse.SubtitleEdit.Forms.Styles
if (s.StartsWith(tag.ToLower() + ":"))
{
if (!remove)
{
sb.AppendLine(line.Substring(0, tag.Length) + ": " + text);
}
found = true;
}
else
@ -685,9 +773,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void comboBoxCollision_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBoxCollision.SelectedIndex == 0)
{
UpdatePropertiesTag("collisions", "Normal", false); // normal
}
else
{
UpdatePropertiesTag("collisions", "Reverse", false); // reverse
}
UpdateRawHeader();
}
@ -705,9 +798,13 @@ namespace Nikse.SubtitleEdit.Forms.Styles
if (!_isSubStationAlpha)
{
if (checkBoxScaleBorderAndShadow.Checked)
{
UpdatePropertiesTag("ScaledBorderAndShadow", "Yes", false);
}
else
{
UpdatePropertiesTag("ScaledBorderAndShadow", "No", false);
}
}
UpdateRawHeader();
}
@ -743,19 +840,25 @@ namespace Nikse.SubtitleEdit.Forms.Styles
if (s.StartsWith("collisions:"))
{
if (s.Remove(0, 11).Trim() == "reverse")
{
comboBoxCollision.SelectedIndex = 1;
}
}
else if (s.StartsWith("playresx:"))
{
int number;
if (int.TryParse(s.Remove(0, 9).Trim(), out number))
{
numericUpDownVideoWidth.Value = number;
}
}
else if (s.StartsWith("playresy:"))
{
int number;
if (int.TryParse(s.Remove(0, 9).Trim(), out number))
{
numericUpDownVideoHeight.Value = number;
}
}
else if (s.StartsWith("scaledborderandshadow:"))
{
@ -784,27 +887,44 @@ namespace Nikse.SubtitleEdit.Forms.Styles
checkBoxFontUnderline.Checked = style.Underline;
if (style.FontSize > 0 && style.FontSize <= numericUpDownFontSize.Maximum)
{
numericUpDownFontSize.Value = style.FontSize;
}
else
{
numericUpDownFontSize.Value = 20;
}
panelPrimaryColor.BackColor = style.Primary;
panelSecondaryColor.BackColor = style.Secondary;
if (_isSubStationAlpha)
{
panelOutlineColor.BackColor = style.Tertiary;
}
else
{
panelOutlineColor.BackColor = style.Outline;
}
panelBackColor.BackColor = style.Background;
if (style.OutlineWidth >= 0 && style.OutlineWidth <= numericUpDownOutline.Maximum)
{
numericUpDownOutline.Value = style.OutlineWidth;
}
else
{
numericUpDownOutline.Value = 2;
}
if (style.ShadowWidth >= 0 && style.ShadowWidth <= numericUpDownShadowWidth.Maximum)
{
numericUpDownShadowWidth.Value = style.ShadowWidth;
}
else
{
numericUpDownShadowWidth.Value = 1;
}
if (_isSubStationAlpha)
{
@ -874,19 +994,31 @@ namespace Nikse.SubtitleEdit.Forms.Styles
}
if (style.MarginLeft >= 0 && style.MarginLeft <= numericUpDownMarginLeft.Maximum)
{
numericUpDownMarginLeft.Value = style.MarginLeft;
}
else
{
numericUpDownMarginLeft.Value = 10;
}
if (style.MarginRight >= 0 && style.MarginRight <= numericUpDownMarginRight.Maximum)
{
numericUpDownMarginRight.Value = style.MarginRight;
}
else
{
numericUpDownMarginRight.Value = 10;
}
if (style.MarginVertical >= 0 && style.MarginVertical <= numericUpDownMarginVertical.Maximum)
{
numericUpDownMarginVertical.Value = style.MarginVertical;
}
else
{
numericUpDownMarginVertical.Value = 10;
}
if (style.BorderStyle == "3")
{
@ -900,8 +1032,8 @@ namespace Nikse.SubtitleEdit.Forms.Styles
protected override void GeneratePreviewReal()
{
if (pictureBoxPreview.Image != null)
pictureBoxPreview.Image.Dispose();
pictureBoxPreview.Image?.Dispose();
var bmp = new Bitmap(pictureBoxPreview.Width, pictureBoxPreview.Height);
using (Graphics g = Graphics.FromImage(bmp))
@ -916,12 +1048,16 @@ namespace Nikse.SubtitleEdit.Forms.Styles
if (y % (rectangleSize * 2) == 0)
{
if (x % (rectangleSize * 2) == 0)
{
c = Color.LightGray;
}
}
else
{
if (x % (rectangleSize * 2) != 0)
{
c = Color.LightGray;
}
}
g.FillRectangle(new SolidBrush(c), x, y, rectangleSize, rectangleSize);
}
@ -951,22 +1087,37 @@ namespace Nikse.SubtitleEdit.Forms.Styles
float left;
if (radioButtonTopLeft.Checked || radioButtonMiddleLeft.Checked || radioButtonBottomLeft.Checked)
{
left = (float)numericUpDownMarginLeft.Value;
}
else if (radioButtonTopRight.Checked || radioButtonMiddleRight.Checked || radioButtonBottomRight.Checked)
{
left = bmp.Width - (measuredWidth + ((float)numericUpDownMarginRight.Value));
}
else
{
left = ((float)(bmp.Width - measuredWidth * 0.8 + 15) / 2);
}
float top;
if (radioButtonTopLeft.Checked || radioButtonTopCenter.Checked || radioButtonTopRight.Checked)
{
top = (float)numericUpDownMarginVertical.Value;
}
else if (radioButtonMiddleLeft.Checked || radioButtonMiddleCenter.Checked || radioButtonMiddleRight.Checked)
{
top = (bmp.Height - measuredHeight) / 2;
}
else
{
top = bmp.Height - measuredHeight - ((int)numericUpDownMarginVertical.Value);
}
top -= (int)numericUpDownShadowWidth.Value;
if (radioButtonTopCenter.Checked || radioButtonMiddleCenter.Checked || radioButtonBottomCenter.Checked)
{
left -= (int)(numericUpDownShadowWidth.Value / 2);
}
const int leftMargin = 0;
int pathPointsStart = -1;
@ -974,9 +1125,13 @@ namespace Nikse.SubtitleEdit.Forms.Styles
if (radioButtonOpaqueBox.Checked)
{
if (_isSubStationAlpha)
{
g.FillRectangle(new SolidBrush(panelBackColor.BackColor), left, top, measuredWidth + 3, measuredHeight + 3);
}
else
{
g.FillRectangle(new SolidBrush(panelOutlineColor.BackColor), left, top, measuredWidth + 3, measuredHeight + 3);
}
}
TextDraw.DrawText(font, sf, path, sb, checkBoxFontItalic.Checked, checkBoxFontBold.Checked, checkBoxFontUnderline.Checked, left, top, ref newLine, leftMargin, ref pathPointsStart);
@ -994,16 +1149,22 @@ namespace Nikse.SubtitleEdit.Forms.Styles
shadowPath.Transform(translateMatrix);
using (var p1 = new Pen(Color.FromArgb(250, panelBackColor.BackColor), outline))
{
g.DrawPath(p1, shadowPath);
}
}
}
if (outline > 0 && radioButtonOutline.Checked)
{
if (_isSubStationAlpha)
{
g.DrawPath(new Pen(panelBackColor.BackColor, outline), path);
}
else
{
g.DrawPath(new Pen(panelOutlineColor.BackColor, outline), path);
}
}
g.FillPath(new SolidBrush(panelPrimaryColor.BackColor), path);
}

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Forms.Styles
{
partial class SubStationAlphaStylesExport
sealed partial class SubStationAlphaStylesExport
{
/// <summary>
/// Required designer variable.

View File

@ -8,12 +8,12 @@ using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms.Styles
{
public partial class SubStationAlphaStylesExport : Form
public sealed partial class SubStationAlphaStylesExport : Form
{
private string _header;
private bool _isSubStationAlpha;
private SubtitleFormat _format;
private List<string> _styles;
private readonly string _header;
private readonly bool _isSubStationAlpha;
private readonly SubtitleFormat _format;
private readonly List<string> _styles;
public List<string> ExportedStyles { get; set; }
public SubStationAlphaStylesExport(string header, bool isSubStationAlpha, SubtitleFormat format)
@ -43,7 +43,9 @@ namespace Nikse.SubtitleEdit.Forms.Styles
foreach (ListViewItem item in listViewExportStyles.Items)
{
if (item.Checked)
{
ExportedStyles.Add(item.Text);
}
}
if (ExportedStyles.Count == 0)
{
@ -117,9 +119,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
var toLower = line.Trim().ToLowerInvariant();
while (toLower.Contains(": "))
{
toLower = toLower.Replace(": ", ":");
}
while (toLower.Contains(" :"))
{
toLower = toLower.Replace(" :", ":");
}
if (stylesOn && toLower.StartsWith("style:" + styleName.Trim() + ",", StringComparison.OrdinalIgnoreCase))
{
@ -142,12 +149,19 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
var toLower = line.Trim().ToLowerInvariant();
while (toLower.Contains(": "))
{
toLower = toLower.Replace(": ", ":");
}
while (toLower.Contains(" :"))
{
toLower = toLower.Replace(" :", ":");
}
if (toLower.StartsWith("style:" + styleName.ToLowerInvariant().Trim(), StringComparison.Ordinal))
{
sb.AppendLine(line);
}
}
}
else

View File

@ -75,7 +75,9 @@ namespace Nikse.SubtitleEdit.Forms.Styles
protected override void GeneratePreviewReal()
{
if (listViewStyles.SelectedItems.Count != 1)
{
return;
}
pictureBoxPreview.Image?.Dispose();
var bmp = new Bitmap(pictureBoxPreview.Width, pictureBoxPreview.Height);
@ -112,8 +114,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
try
{
var fontSize = 20.0f;
int fontSizeInt;
if (int.TryParse(textBoxFontSize.Text.Replace("px", string.Empty), out fontSizeInt))
if (int.TryParse(textBoxFontSize.Text.Replace("px", string.Empty), out var fontSizeInt))
{
fontSize = fontSizeInt;
}
@ -200,34 +201,50 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string name = "default";
if (node.Attributes["xml:id"] != null)
{
name = node.Attributes["xml:id"].Value;
}
else if (node.Attributes["id"] != null)
{
name = node.Attributes["id"].Value;
}
string fontFamily = "Arial";
if (node.Attributes["tts:fontFamily"] != null)
{
fontFamily = node.Attributes["tts:fontFamily"].Value;
}
string fontWeight = "normal";
if (node.Attributes["tts:fontWeight"] != null)
{
fontWeight = node.Attributes["tts:fontWeight"].Value;
}
string fontStyle = "normal";
if (node.Attributes["tts:fontStyle"] != null)
{
fontStyle = node.Attributes["tts:fontStyle"].Value;
}
string fontColor = "white";
if (node.Attributes["tts:color"] != null)
{
fontColor = node.Attributes["tts:color"].Value;
}
string fontSize = "100%";
if (node.Attributes["tts:fontSize"] != null)
{
fontSize = node.Attributes["tts:fontSize"].Value;
}
AddStyle(name, fontFamily, fontColor, fontSize);
}
if (listViewStyles.Items.Count > 0)
{
listViewStyles.Items[0].Selected = true;
}
}
private void AddStyle(string name, string fontFamily, string color, string fontSize)