Merge pull request #1484 from ivandrofly/patch-xy3

Cleanup + Refactor
This commit is contained in:
Nikolaj Olsson 2016-01-15 12:53:40 +01:00
commit d88579e324
9 changed files with 32 additions and 51 deletions

View File

@ -4,7 +4,6 @@ namespace Nikse.SubtitleEdit.Core
{
public class BmpReader
{
public string HeaderId { get; private set; }
public UInt32 HeaderFileSize { get; private set; }
public UInt32 OffsetToPixelArray { get; private set; }
@ -18,5 +17,4 @@ namespace Nikse.SubtitleEdit.Core
}
}
}
}

View File

@ -11,7 +11,6 @@
public string CodecPrivate { get; set; }
public int DefaultDuration { get; set; }
public string Language { get; set; }
public string Name { get; set; }
public int ContentCompressionAlgorithm { get; set; }
public int ContentEncodingType { get; set; }

View File

@ -631,7 +631,7 @@ namespace Nikse.SubtitleEdit.Core
//FALCONE:<i> I didn't think</i><br /><i>it was going to be you,</i>
var colIdx = text.IndexOf(':');
if (colIdx > -1 && Utilities.CountTagInText(text, beginTag) + Utilities.CountTagInText(text, endTag) == 4 && text.Length > colIdx + 1 && !char.IsDigit(text[colIdx + 1]))
if (colIdx >= 0 && Utilities.CountTagInText(text, beginTag) + Utilities.CountTagInText(text, endTag) == 4 && text.Length > colIdx + 1 && !char.IsDigit(text[colIdx + 1]))
{
var firstLine = text.Substring(0, index);
var secondLine = text.Substring(index).TrimStart();

View File

@ -59,7 +59,7 @@ namespace Nikse.SubtitleEdit.Core
public ManagedBitmap(Bitmap oldBitmap)
{
NikseBitmap nbmp = new NikseBitmap(oldBitmap);
var nbmp = new NikseBitmap(oldBitmap);
Width = nbmp.Width;
Height = nbmp.Height;
_colors = new Color[Width * Height];
@ -67,7 +67,7 @@ namespace Nikse.SubtitleEdit.Core
{
for (int x = 0; x < Width; x++)
{
this.SetPixel(x, y, nbmp.GetPixel(x, y));
SetPixel(x, y, nbmp.GetPixel(x, y));
}
}
}
@ -81,14 +81,14 @@ namespace Nikse.SubtitleEdit.Core
{
for (int x = 0; x < Width; x++)
{
this.SetPixel(x, y, nbmp.GetPixel(x, y));
SetPixel(x, y, nbmp.GetPixel(x, y));
}
}
}
public void Save(string fileName)
{
using (MemoryStream outFile = new MemoryStream())
using (var outFile = new MemoryStream())
{
byte[] buffer = System.Text.Encoding.UTF8.GetBytes("MBMP");
outFile.Write(buffer, 0, buffer.Length);
@ -99,7 +99,7 @@ namespace Nikse.SubtitleEdit.Core
WriteColor(outFile, c);
}
buffer = outFile.ToArray();
using (GZipStream gz = new GZipStream(new FileStream(fileName, FileMode.Create), CompressionMode.Compress, false))
using (var gz = new GZipStream(new FileStream(fileName, FileMode.Create), CompressionMode.Compress, false))
{
gz.Write(buffer, 0, buffer.Length);
}
@ -108,7 +108,7 @@ namespace Nikse.SubtitleEdit.Core
public void AppendToStream(Stream targetStream)
{
using (MemoryStream outFile = new MemoryStream())
using (var outFile = new MemoryStream())
{
byte[] buffer = System.Text.Encoding.UTF8.GetBytes("MBMP");
outFile.Write(buffer, 0, buffer.Length);
@ -172,7 +172,7 @@ namespace Nikse.SubtitleEdit.Core
/// <returns>Rectangle from current image as new bitmap</returns>
public ManagedBitmap GetRectangle(Rectangle section)
{
ManagedBitmap newRectangle = new ManagedBitmap(section.Width, section.Height);
var newRectangle = new ManagedBitmap(section.Width, section.Height);
int recty = 0;
for (int y = section.Top; y < section.Top + section.Height; y++)
@ -190,7 +190,7 @@ namespace Nikse.SubtitleEdit.Core
public Bitmap ToOldBitmap()
{
NikseBitmap nbmp = new NikseBitmap(Width, Height);
var nbmp = new NikseBitmap(Width, Height);
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)

View File

@ -8,7 +8,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class SubStationAlpha : SubtitleFormat
{
public string Errors { get; private set; }
public override string Extension

View File

@ -13,16 +13,13 @@ namespace Nikse.SubtitleEdit.Core
if (path.PointCount > 0)
{
int k = 0;
var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
for (int i = list.Length - 1; i >= 0; i--)
{
if (list[i].X > next.X)
next.X = list[i].X;
k++;
if (k > 60)
break;
if (i <= pathPointsStart && pathPointsStart != -1)
if ((k > 60) || (i <= pathPointsStart && pathPointsStart != -1))
break;
}
}
@ -79,17 +76,13 @@ namespace Nikse.SubtitleEdit.Core
float width = 0;
var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
int index = list.Length - 42;
if (index < 0)
index = 0;
int index = System.Math.Max(list.Length - 42, 0);
for (int i = index; i < list.Length; i += 2)
{
if (list[i].X > width)
width = list[i].X;
}
int max = 52;
if (max > list.Length)
max = list.Length;
int max = System.Math.Max(52, list.Length);
for (int i = 0; i < max; i += 2)
{
if (list[i].X > width)
@ -115,9 +108,7 @@ namespace Nikse.SubtitleEdit.Core
float height = 0;
var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
int index = list.Length - 80;
if (index < 0)
index = 0;
int index = System.Math.Max(list.Length - 80, 0);
for (int i = index; i < list.Length; i += 2)
{
if (list[i].Y > height)

View File

@ -260,15 +260,9 @@ namespace Nikse.SubtitleEdit.Controls
private static Color GetCustomColor(Color color)
{
int r = color.R - 39;
int g = color.G - 39;
int b = color.B - 39;
if (r < 0)
r = 0;
if (g < 0)
g = 0;
if (b < 0)
b = 0;
int r = Math.Max(color.R - 39, 0);
int g = Math.Max(color.G - 39, 0);
int b = Math.Max(color.B - 39, 0);
return Color.FromArgb(color.A, r, g, b);
}

View File

@ -14,7 +14,7 @@ namespace Nikse.SubtitleEdit.Forms
public GoToLine()
{
InitializeComponent();
Icon = SubtitleEdit.Properties.Resources.SubtitleEditFormIcon;
Icon = Properties.Resources.SubtitleEditFormIcon;
Text = Configuration.Settings.Language.GoToLine.Title;
buttonOK.Text = Configuration.Settings.Language.General.Ok;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;

View File

@ -62,60 +62,60 @@ namespace Nikse.SubtitleEdit.Forms
foreach (string line in header.SplitToLines())
{
string s = line.ToLowerInvariant().Trim();
if (s.StartsWith("title:"))
if (s.StartsWith("title:", StringComparison.Ordinal))
{
textBoxTitle.Text = s.Remove(0, 6).Trim();
}
else if (s.StartsWith("original script:"))
else if (s.StartsWith("original script:", StringComparison.Ordinal))
{
textBoxOriginalScript.Text = s.Remove(0, 16).Trim();
}
else if (s.StartsWith("original translation:"))
else if (s.StartsWith("original translation:", StringComparison.Ordinal))
{
textBoxTranslation.Text = s.Remove(0, 21).Trim();
}
else if (s.StartsWith("original editing:"))
else if (s.StartsWith("original editing:", StringComparison.Ordinal))
{
textBoxEditing.Text = s.Remove(0, 17).Trim();
}
else if (s.StartsWith("original timing:"))
else if (s.StartsWith("original timing:", StringComparison.Ordinal))
{
textBoxTiming.Text = s.Remove(0, 16).Trim();
}
else if (s.StartsWith("synch point:"))
else if (s.StartsWith("synch point:", StringComparison.Ordinal))
{
textBoxSyncPoint.Text = s.Remove(0, 12).Trim();
}
else if (s.StartsWith("script updated by:"))
else if (s.StartsWith("script updated by:", StringComparison.Ordinal))
{
textBoxUpdatedBy.Text = s.Remove(0, 18).Trim();
}
else if (s.StartsWith("update details:"))
else if (s.StartsWith("update details:", StringComparison.Ordinal))
{
textBoxUpdateDetails.Text = s.Remove(0, 15).Trim();
}
else if (s.StartsWith("collisions:"))
else if (s.StartsWith("collisions:", StringComparison.Ordinal))
{
if (s.Remove(0, 11).Trim() == "reverse")
comboBoxCollision.SelectedIndex = 1;
}
else if (s.StartsWith("playresx:"))
else if (s.StartsWith("playresx:", StringComparison.Ordinal))
{
int number;
if (int.TryParse(s.Remove(0, 9).Trim(), out number))
numericUpDownVideoWidth.Value = number;
}
else if (s.StartsWith("playresy:"))
else if (s.StartsWith("playresy:", StringComparison.Ordinal))
{
int number;
if (int.TryParse(s.Remove(0, 9).Trim(), out number))
numericUpDownVideoHeight.Value = number;
}
else if (s.StartsWith("scaledborderandshadow:"))
else if (s.StartsWith("scaledborderandshadow:", StringComparison.Ordinal))
{
checkBoxScaleBorderAndShadow.Checked = s.Remove(0, 22).Trim().ToLowerInvariant().Equals("yes");
}
else if (s.StartsWith("wrapstyle:"))
else if (s.StartsWith("wrapstyle:", StringComparison.Ordinal))
{
var wrapStyle = s.Remove(0, 10).Trim();
for (int i = 0; i < comboBoxWrapStyle.Items.Count; i++)
@ -232,7 +232,7 @@ namespace Nikse.SubtitleEdit.Forms
}
string s = line.ToLower();
if (s.StartsWith(tag.ToLower() + ":"))
if (s.StartsWith(tag.ToLower() + ":", StringComparison.Ordinal))
{
if (!remove)
sb.AppendLine(line.Substring(0, tag.Length) + ": " + text);