mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 06:52:35 +01:00
Work on assa resampler/resizer
This commit is contained in:
parent
822cb1679f
commit
0bb1d3d492
51
src/Test/Assa/ResamplerTest.cs
Normal file
51
src/Test/Assa/ResamplerTest.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Nikse.SubtitleEdit.Core.Common;
|
||||
|
||||
namespace Test.Assa
|
||||
{
|
||||
[TestClass]
|
||||
public class AssaResamplerTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestResampleOverrideFontTags1()
|
||||
{
|
||||
var result = AssaResampler.ResampleOverrideTagsFont(100, 200, 100, 200, "{\\fs10}Hallo!");
|
||||
Assert.AreEqual("{\\fs20}Hallo!", result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestResampleOverrideFontTags2()
|
||||
{
|
||||
var result = AssaResampler.ResampleOverrideTagsFont(100, 200, 100, 200, "{\\fs10}Hallo! {\\fs20}Hallo!");
|
||||
Assert.AreEqual("{\\fs20}Hallo! {\\fs40}Hallo!", result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestResampleOverrideFontTags3()
|
||||
{
|
||||
var result = AssaResampler.ResampleOverrideTagsFont(100, 200, 100, 200, "{\\fs10\\fs20\\fs30}Hallo!");
|
||||
Assert.AreEqual("{\\fs20\\fs40\\fs60}Hallo!", result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestResampleOverridePositionTags1()
|
||||
{
|
||||
var result = AssaResampler.ResampleOverrideTagsPosition(100, 200, 100, 200, "{\\pos(10,20)}Hallo!");
|
||||
Assert.AreEqual("{\\pos(20,40)}Hallo!", result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestResampleOverridePositionTags2()
|
||||
{
|
||||
var result = AssaResampler.ResampleOverrideTagsPosition(100, 200, 100, 200, "{\\pos(10,20)\\pos(20,30)}Hallo!");
|
||||
Assert.AreEqual("{\\pos(20,40)\\pos(40,60)}Hallo!", result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestResampleOverrideDrawingTags1()
|
||||
{
|
||||
var result = AssaResampler.ResampleOverrideTagsDrawing(100, 200, 100, 200, "{\\p1}m 0 0 l 100 0 100 100 0 100{\\p0}");
|
||||
Assert.AreEqual("{\\p1}m 0 0 l 200 0 200 200 0 200{\\p0}", result);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Nikse.SubtitleEdit.Controls;
|
||||
|
||||
namespace Test.AssaTagHelper
|
||||
namespace Test.Assa
|
||||
{
|
||||
[TestClass]
|
||||
public class RemoveTag
|
||||
public class TagHelperRemoveTagTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void RemoveTag1()
|
@ -61,7 +61,8 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssaTagHelper\RemoveTag.cs" />
|
||||
<Compile Include="Assa\TagHelperRemoveTagTest.cs" />
|
||||
<Compile Include="Assa\ResamplerTest.cs" />
|
||||
<Compile Include="Core\UUEncodingTest.cs" />
|
||||
<Compile Include="Core\CharUtilsTest.cs" />
|
||||
<Compile Include="Core\DialogTypeTest.cs" />
|
||||
|
@ -19,7 +19,7 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
return factor * v;
|
||||
}
|
||||
|
||||
public static string ResampleOverrideTags(decimal sourceWidth, decimal targetWidth, decimal sourceHeight, decimal targetHeight, string input)
|
||||
public static string ResampleOverrideTagsFont(decimal sourceWidth, decimal targetWidth, decimal sourceHeight, decimal targetHeight, string input)
|
||||
{
|
||||
var s = input;
|
||||
|
||||
@ -28,23 +28,37 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
s = FixTagWithNumber(sourceWidth, targetWidth, s, "fscx");
|
||||
s = FixTagWithNumber(sourceHeight, targetHeight, s, "fscy");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static string ResampleOverrideTagsPosition(decimal sourceWidth, decimal targetWidth, decimal sourceHeight, decimal targetHeight, string input)
|
||||
{
|
||||
var s = input;
|
||||
|
||||
// {\\pos(10,11)}
|
||||
s = FixMethodTwoParameters(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "pos");
|
||||
s = FixMethodTwoParameters(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "org");
|
||||
|
||||
// {\\move(10,11,20,21,5,5)}
|
||||
FixMethodSixParametersFourActive(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "move");
|
||||
s = FixMethodSixParametersFourActive(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "move");
|
||||
|
||||
// {\\move(10,11,20,21)}
|
||||
FixMethodFourParameters(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "move");
|
||||
FixMethodFourParameters(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "clip");
|
||||
FixMethodFourParameters(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "iclip");
|
||||
s = FixMethodFourParameters(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "move");
|
||||
s = FixMethodFourParameters(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "clip");
|
||||
s = FixMethodFourParameters(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "iclip");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static string ResampleOverrideTagsDrawing(decimal sourceWidth, decimal targetWidth, decimal sourceHeight, decimal targetHeight, string input)
|
||||
{
|
||||
var s = input;
|
||||
|
||||
//{\clip(1,m 50 0 b 100 0 100 100 50 100 b 0 100 0 0 50 0)}
|
||||
//{\p1}m 0 0 l 100 0 100 100 0 100{\p0}
|
||||
FixDrawing(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "\\iclip\\(", ")");
|
||||
FixDrawing(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "\\clip\\(", ")");
|
||||
FixDrawing(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "{\\p1}", "{\\p0}");
|
||||
s = FixDrawing(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "\\iclip\\(", ")");
|
||||
s = FixDrawing(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "\\clip\\(", ")");
|
||||
s = FixDrawing(sourceWidth, targetWidth, sourceHeight, targetHeight, s, "{\\p1}", "{\\p0}");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
73
src/ui/Forms/Assa/ResolutionResampler.Designer.cs
generated
73
src/ui/Forms/Assa/ResolutionResampler.Designer.cs
generated
@ -41,7 +41,10 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
this.numericUpDownSourceWidth = new System.Windows.Forms.NumericUpDown();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonOK = new System.Windows.Forms.Button();
|
||||
this.checkBoxKeepAspectRatio = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxMargins = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxFontSize = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxPosition = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxDrawing = new System.Windows.Forms.CheckBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownTargetHeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownTargetWidth)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSourceHeight)).BeginInit();
|
||||
@ -157,7 +160,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.buttonCancel.Location = new System.Drawing.Point(327, 143);
|
||||
this.buttonCancel.Location = new System.Drawing.Point(371, 189);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonCancel.TabIndex = 16;
|
||||
@ -169,7 +172,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
//
|
||||
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.buttonOK.Location = new System.Drawing.Point(246, 143);
|
||||
this.buttonOK.Location = new System.Drawing.Point(290, 189);
|
||||
this.buttonOK.Name = "buttonOK";
|
||||
this.buttonOK.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonOK.TabIndex = 15;
|
||||
@ -177,22 +180,61 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
this.buttonOK.UseVisualStyleBackColor = true;
|
||||
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
|
||||
//
|
||||
// checkBoxKeepAspectRatio
|
||||
// checkBoxMargins
|
||||
//
|
||||
this.checkBoxKeepAspectRatio.AutoSize = true;
|
||||
this.checkBoxKeepAspectRatio.Location = new System.Drawing.Point(15, 99);
|
||||
this.checkBoxKeepAspectRatio.Name = "checkBoxKeepAspectRatio";
|
||||
this.checkBoxKeepAspectRatio.Size = new System.Drawing.Size(169, 17);
|
||||
this.checkBoxKeepAspectRatio.TabIndex = 17;
|
||||
this.checkBoxKeepAspectRatio.Text = "Keep aspect ration for margins";
|
||||
this.checkBoxKeepAspectRatio.UseVisualStyleBackColor = true;
|
||||
this.checkBoxMargins.AutoSize = true;
|
||||
this.checkBoxMargins.Location = new System.Drawing.Point(15, 99);
|
||||
this.checkBoxMargins.Name = "checkBoxMargins";
|
||||
this.checkBoxMargins.Size = new System.Drawing.Size(169, 17);
|
||||
this.checkBoxMargins.TabIndex = 17;
|
||||
this.checkBoxMargins.Text = "Keep aspect ration for margins";
|
||||
this.checkBoxMargins.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxFontSize
|
||||
//
|
||||
this.checkBoxFontSize.AutoSize = true;
|
||||
this.checkBoxFontSize.Checked = true;
|
||||
this.checkBoxFontSize.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.checkBoxFontSize.Location = new System.Drawing.Point(12, 122);
|
||||
this.checkBoxFontSize.Name = "checkBoxFontSize";
|
||||
this.checkBoxFontSize.Size = new System.Drawing.Size(172, 17);
|
||||
this.checkBoxFontSize.TabIndex = 18;
|
||||
this.checkBoxFontSize.Text = "Keep aspect ration for font size";
|
||||
this.checkBoxFontSize.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxPosition
|
||||
//
|
||||
this.checkBoxPosition.AutoSize = true;
|
||||
this.checkBoxPosition.Checked = true;
|
||||
this.checkBoxPosition.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.checkBoxPosition.Location = new System.Drawing.Point(12, 145);
|
||||
this.checkBoxPosition.Name = "checkBoxPosition";
|
||||
this.checkBoxPosition.Size = new System.Drawing.Size(169, 17);
|
||||
this.checkBoxPosition.TabIndex = 19;
|
||||
this.checkBoxPosition.Text = "Keep aspect ration for position";
|
||||
this.checkBoxPosition.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxDrawing
|
||||
//
|
||||
this.checkBoxDrawing.AutoSize = true;
|
||||
this.checkBoxDrawing.Checked = true;
|
||||
this.checkBoxDrawing.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.checkBoxDrawing.Location = new System.Drawing.Point(12, 168);
|
||||
this.checkBoxDrawing.Name = "checkBoxDrawing";
|
||||
this.checkBoxDrawing.Size = new System.Drawing.Size(170, 17);
|
||||
this.checkBoxDrawing.TabIndex = 20;
|
||||
this.checkBoxDrawing.Text = "Keep aspect ration for drawing";
|
||||
this.checkBoxDrawing.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// ResolutionResampler
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(414, 178);
|
||||
this.Controls.Add(this.checkBoxKeepAspectRatio);
|
||||
this.ClientSize = new System.Drawing.Size(458, 224);
|
||||
this.Controls.Add(this.checkBoxDrawing);
|
||||
this.Controls.Add(this.checkBoxPosition);
|
||||
this.Controls.Add(this.checkBoxFontSize);
|
||||
this.Controls.Add(this.checkBoxMargins);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonOK);
|
||||
this.Controls.Add(this.label1);
|
||||
@ -238,6 +280,9 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
private System.Windows.Forms.NumericUpDown numericUpDownSourceWidth;
|
||||
private System.Windows.Forms.Button buttonCancel;
|
||||
private System.Windows.Forms.Button buttonOK;
|
||||
private System.Windows.Forms.CheckBox checkBoxKeepAspectRatio;
|
||||
private System.Windows.Forms.CheckBox checkBoxMargins;
|
||||
private System.Windows.Forms.CheckBox checkBoxFontSize;
|
||||
private System.Windows.Forms.CheckBox checkBoxPosition;
|
||||
private System.Windows.Forms.CheckBox checkBoxDrawing;
|
||||
}
|
||||
}
|
@ -112,7 +112,10 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
var targetWidth = numericUpDownTargetWidth.Value;
|
||||
var targetHeight = numericUpDownTargetHeight.Value;
|
||||
|
||||
var fixMargins = checkBoxKeepAspectRatio.Checked;
|
||||
var fixMargins = checkBoxMargins.Checked;
|
||||
var fixFonts = checkBoxFontSize.Checked;
|
||||
var fixPos = checkBoxPosition.Checked;
|
||||
var fixDraw = checkBoxDrawing.Checked;
|
||||
var styles = AdvancedSubStationAlpha.GetSsaStylesFromHeader(_subtitle.Header);
|
||||
foreach (var style in styles)
|
||||
{
|
||||
@ -132,7 +135,20 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
|
||||
foreach (var p in _subtitle.Paragraphs)
|
||||
{
|
||||
p.Text = AssaResampler.ResampleOverrideTags(sourceWidth, targetWidth, sourceHeight, targetHeight, p.Text);
|
||||
if (fixFonts)
|
||||
{
|
||||
p.Text = AssaResampler.ResampleOverrideTagsFont(sourceWidth, targetWidth, sourceHeight, targetHeight, p.Text);
|
||||
}
|
||||
|
||||
if (fixPos)
|
||||
{
|
||||
p.Text = AssaResampler.ResampleOverrideTagsPosition(sourceWidth, targetWidth, sourceHeight, targetHeight, p.Text);
|
||||
}
|
||||
|
||||
if (fixDraw)
|
||||
{
|
||||
p.Text = AssaResampler.ResampleOverrideTagsDrawing(sourceWidth, targetWidth, sourceHeight, targetHeight, p.Text);
|
||||
}
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
|
Loading…
Reference in New Issue
Block a user