mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 06:52:35 +01:00
Export to png/xml now uses font styles from ssa/ass
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1554 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
4fec165821
commit
dbf529ae9b
@ -41,6 +41,12 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
public int BottomMargin { get; set; }
|
public int BottomMargin { get; set; }
|
||||||
public bool Saved { get; set; }
|
public bool Saved { get; set; }
|
||||||
public ContentAlignment Alignment { get; set; }
|
public ContentAlignment Alignment { get; set; }
|
||||||
|
public Color BackgroundColor { get; set; }
|
||||||
|
|
||||||
|
public MakeBitmapParameter()
|
||||||
|
{
|
||||||
|
BackgroundColor = Color.Transparent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Subtitle _subtitle;
|
private Subtitle _subtitle;
|
||||||
@ -228,11 +234,38 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
Saved = false,
|
Saved = false,
|
||||||
Alignment = ContentAlignment.BottomCenter,
|
Alignment = ContentAlignment.BottomCenter,
|
||||||
SideBySide3D = checkBoxSideBySide3D.Checked,
|
SideBySide3D = checkBoxSideBySide3D.Checked,
|
||||||
|
BackgroundColor = Color.Transparent,
|
||||||
};
|
};
|
||||||
if (index < _subtitle.Paragraphs.Count)
|
if (index < _subtitle.Paragraphs.Count)
|
||||||
{
|
{
|
||||||
parameter.P = _subtitle.Paragraphs[index];
|
parameter.P = _subtitle.Paragraphs[index];
|
||||||
parameter.Alignment = GetAlignmentFromParagraph(parameter.P,_format, _subtitle);
|
parameter.Alignment = GetAlignmentFromParagraph(parameter.P,_format, _subtitle);
|
||||||
|
|
||||||
|
if (_format.HasStyleSupport && !string.IsNullOrEmpty(parameter.P.Extra))
|
||||||
|
{
|
||||||
|
if (_format.GetType() == typeof(SubStationAlpha))
|
||||||
|
{
|
||||||
|
var style = AdvancedSubStationAlpha.GetSsaStyle(parameter.P.Extra, _subtitle.Header);
|
||||||
|
parameter.SubtitleColor = style.Primary;
|
||||||
|
parameter.SubtitleFontBold = style.Bold;
|
||||||
|
parameter.SubtitleFontSize = style.FontSize;
|
||||||
|
if (style.BorderStyle == "3")
|
||||||
|
{
|
||||||
|
parameter.BackgroundColor = style.Background;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_format.GetType() == typeof(AdvancedSubStationAlpha))
|
||||||
|
{
|
||||||
|
var style = AdvancedSubStationAlpha.GetSsaStyle(parameter.P.Extra, _subtitle.Header);
|
||||||
|
parameter.SubtitleColor = style.Primary;
|
||||||
|
parameter.SubtitleFontBold = style.Bold;
|
||||||
|
parameter.SubtitleFontSize = style.FontSize;
|
||||||
|
if (style.BorderStyle == "3")
|
||||||
|
{
|
||||||
|
parameter.BackgroundColor = style.Outline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -768,7 +801,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
return Color.FromArgb(150, borderColor.R, borderColor.G, borderColor.B);
|
return Color.FromArgb(150, borderColor.R, borderColor.G, borderColor.B);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap GenerateImageFromTextWithStyle(string text)
|
private Bitmap GenerateImageFromTextWithStyle(Paragraph p)
|
||||||
{
|
{
|
||||||
var mbp = new MakeBitmapParameter();
|
var mbp = new MakeBitmapParameter();
|
||||||
mbp.AlignLeft = comboBoxHAlign.SelectedIndex == 0;
|
mbp.AlignLeft = comboBoxHAlign.SelectedIndex == 0;
|
||||||
@ -780,7 +813,36 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
mbp.SubtitleColor = _subtitleColor;
|
mbp.SubtitleColor = _subtitleColor;
|
||||||
mbp.SubtitleFontSize = _subtitleFontSize;
|
mbp.SubtitleFontSize = _subtitleFontSize;
|
||||||
mbp.SubtitleFontBold = _subtitleFontBold;
|
mbp.SubtitleFontBold = _subtitleFontBold;
|
||||||
mbp.P = new Paragraph(text, 0, 0);
|
mbp.P = p;
|
||||||
|
|
||||||
|
|
||||||
|
if (_format.HasStyleSupport && !string.IsNullOrEmpty(p.Extra))
|
||||||
|
{
|
||||||
|
if (_format.GetType() == typeof(SubStationAlpha))
|
||||||
|
{
|
||||||
|
var style = AdvancedSubStationAlpha.GetSsaStyle(p.Extra, _subtitle.Header);
|
||||||
|
mbp.SubtitleColor = style.Primary;
|
||||||
|
mbp.SubtitleFontBold = style.Bold;
|
||||||
|
mbp.SubtitleFontSize = style.FontSize;
|
||||||
|
if (style.BorderStyle == "3")
|
||||||
|
{
|
||||||
|
mbp.BackgroundColor = style.Background;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_format.GetType() == typeof(AdvancedSubStationAlpha))
|
||||||
|
{
|
||||||
|
var style = AdvancedSubStationAlpha.GetSsaStyle(p.Extra, _subtitle.Header);
|
||||||
|
mbp.SubtitleColor = style.Primary;
|
||||||
|
mbp.SubtitleFontBold = style.Bold;
|
||||||
|
mbp.SubtitleFontSize = style.FontSize;
|
||||||
|
if (style.BorderStyle == "3")
|
||||||
|
{
|
||||||
|
mbp.BackgroundColor = style.Outline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
@ -844,6 +906,8 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
sizeY = 1;
|
sizeY = 1;
|
||||||
bmp = new Bitmap(sizeX, sizeY);
|
bmp = new Bitmap(sizeX, sizeY);
|
||||||
g = Graphics.FromImage(bmp);
|
g = Graphics.FromImage(bmp);
|
||||||
|
if (parameter.BackgroundColor != Color.Transparent)
|
||||||
|
g.FillRectangle(new SolidBrush(parameter.BackgroundColor), 0, 0, bmp.Width, bmp.Height);
|
||||||
|
|
||||||
var lefts = new List<float>();
|
var lefts = new List<float>();
|
||||||
foreach (string line in Utilities.RemoveHtmlFontTag(text.Replace("<i>", string.Empty).Replace("</i>", string.Empty)).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
|
foreach (string line in Utilities.RemoveHtmlFontTag(text.Replace("<i>", string.Empty).Replace("</i>", string.Empty)).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
|
||||||
@ -1056,7 +1120,15 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
g.FillPath(new SolidBrush(c), path);
|
g.FillPath(new SolidBrush(c), path);
|
||||||
g.Dispose();
|
g.Dispose();
|
||||||
var nbmp = new NikseBitmap(bmp);
|
var nbmp = new NikseBitmap(bmp);
|
||||||
nbmp.CropTransparentSidesAndBottom(2);
|
if (parameter.BackgroundColor == Color.Transparent)
|
||||||
|
{
|
||||||
|
nbmp.CropTransparentSidesAndBottom(2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nbmp.CropSidesAndBottom(4, parameter.BackgroundColor);
|
||||||
|
nbmp.CropTop(4, parameter.BackgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
if (parameter.SideBySide3D)
|
if (parameter.SideBySide3D)
|
||||||
{
|
{
|
||||||
@ -1071,7 +1143,10 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
gSideBySide.DrawImage(singleBmp, singleWidth + singleLeftMargin, 0);
|
gSideBySide.DrawImage(singleBmp, singleWidth + singleLeftMargin, 0);
|
||||||
}
|
}
|
||||||
nbmp = new NikseBitmap(sideBySideBmp);
|
nbmp = new NikseBitmap(sideBySideBmp);
|
||||||
nbmp.CropTransparentSidesAndBottom(2);
|
if (parameter.BackgroundColor == Color.Transparent)
|
||||||
|
nbmp.CropTransparentSidesAndBottom(2);
|
||||||
|
else
|
||||||
|
nbmp.CropSidesAndBottom(4, parameter.BackgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nbmp.GetBitmap();
|
return nbmp.GetBitmap();
|
||||||
@ -1247,7 +1322,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
SetupImageParameters();
|
SetupImageParameters();
|
||||||
if (subtitleListView1.SelectedItems.Count > 0)
|
if (subtitleListView1.SelectedItems.Count > 0)
|
||||||
{
|
{
|
||||||
var bmp = GenerateImageFromTextWithStyle(_subtitle.Paragraphs[subtitleListView1.SelectedItems[0].Index].Text);
|
var bmp = GenerateImageFromTextWithStyle(_subtitle.Paragraphs[subtitleListView1.SelectedItems[0].Index]);
|
||||||
pictureBox1.Image = bmp;
|
pictureBox1.Image = bmp;
|
||||||
|
|
||||||
int w = groupBoxExportImage.Width - 4;
|
int w = groupBoxExportImage.Width - 4;
|
||||||
|
Loading…
Reference in New Issue
Block a user