Working on no-break-after list

This commit is contained in:
niksedk 2014-04-09 16:23:22 +02:00
parent 082d07158c
commit 400a3e80fe
5 changed files with 93 additions and 15 deletions

View File

@ -5,7 +5,8 @@
<Version>3.3.14</Version> <Version>3.3.14</Version>
<TranslatedBy>Oversat til dansk af Nikse (mailto:nikse.dk@gmail.com)</TranslatedBy> <TranslatedBy>Oversat til dansk af Nikse (mailto:nikse.dk@gmail.com)</TranslatedBy>
<CultureName>da-DK</CultureName> <CultureName>da-DK</CultureName>
<HelpFile /> <HelpFile>
</HelpFile>
<OK>&amp;OK</OK> <OK>&amp;OK</OK>
<Cancel>&amp;Fortryd</Cancel> <Cancel>&amp;Fortryd</Cancel>
<Apply>Anvend</Apply> <Apply>Anvend</Apply>
@ -1309,6 +1310,7 @@ Fortsæt?</SubtitleAppendPrompt>
<NewVersionOfSubtitleEditRequired>Nyere version af Subtitle Edit kræves!</NewVersionOfSubtitleEditRequired> <NewVersionOfSubtitleEditRequired>Nyere version af Subtitle Edit kræves!</NewVersionOfSubtitleEditRequired>
<UpdateAvailable>[Ny version findes!]</UpdateAvailable> <UpdateAvailable>[Ny version findes!]</UpdateAvailable>
<UpdateAll>Opdater alle</UpdateAll> <UpdateAll>Opdater alle</UpdateAll>
<XPluginsUpdated>{0} plugin(s) opdateret</XPluginsUpdated>
</PluginsGet> </PluginsGet>
<RemoveTextFromHearImpaired> <RemoveTextFromHearImpaired>
<Title>Fjern tekst for hørehæmmede</Title> <Title>Fjern tekst for hørehæmmede</Title>
@ -1401,8 +1403,7 @@ Fortsæt?</SubtitleAppendPrompt>
<AutoWrapWhileTyping>Auto-ombryd tekst mens du skriver</AutoWrapWhileTyping> <AutoWrapWhileTyping>Auto-ombryd tekst mens du skriver</AutoWrapWhileTyping>
<DurationMinimumMilliseconds>Min. varighed, millisekunder</DurationMinimumMilliseconds> <DurationMinimumMilliseconds>Min. varighed, millisekunder</DurationMinimumMilliseconds>
<DurationMaximumMilliseconds>Max. varighed, millisekunder</DurationMaximumMilliseconds> <DurationMaximumMilliseconds>Max. varighed, millisekunder</DurationMaximumMilliseconds>
<MinimumGapMilliseconds> <MinimumGapMilliseconds>Min. mellemrum mellem undertekster i ms</MinimumGapMilliseconds>
</MinimumGapMilliseconds>
<SubtitleFont>undertekst skrifttype</SubtitleFont> <SubtitleFont>undertekst skrifttype</SubtitleFont>
<SubtitleFontSize>undertekst skriftstørrelse</SubtitleFontSize> <SubtitleFontSize>undertekst skriftstørrelse</SubtitleFontSize>
<SubtitleBold>Fed</SubtitleBold> <SubtitleBold>Fed</SubtitleBold>
@ -1444,8 +1445,7 @@ Fortsæt?</SubtitleAppendPrompt>
<MPlayerDescription>MPlayer2/Mplayer</MPlayerDescription> <MPlayerDescription>MPlayer2/Mplayer</MPlayerDescription>
<VlcMediaPlayer>VLC Media Player</VlcMediaPlayer> <VlcMediaPlayer>VLC Media Player</VlcMediaPlayer>
<VlcMediaPlayerDescription>libvlc.dll fra VLC Media Player 1.1.0 eller nyere</VlcMediaPlayerDescription> <VlcMediaPlayerDescription>libvlc.dll fra VLC Media Player 1.1.0 eller nyere</VlcMediaPlayerDescription>
<VlcBrowseToLabel> <VlcBrowseToLabel>VLC sti (kun nødvendig, hvis du bruger den portable version af VLC)</VlcBrowseToLabel>
</VlcBrowseToLabel>
<ShowStopButton>Vis stop-knap</ShowStopButton> <ShowStopButton>Vis stop-knap</ShowStopButton>
<ShowMuteButton>Vis mute-knap</ShowMuteButton> <ShowMuteButton>Vis mute-knap</ShowMuteButton>
<ShowFullscreenButton>Vis fuldskærm knap</ShowFullscreenButton> <ShowFullscreenButton>Vis fuldskærm knap</ShowFullscreenButton>
@ -1475,8 +1475,7 @@ Fortsæt?</SubtitleAppendPrompt>
<WaveformUseFFMPEG>Benyt FFMPEG til at udtrække lydfiler</WaveformUseFFMPEG> <WaveformUseFFMPEG>Benyt FFMPEG til at udtrække lydfiler</WaveformUseFFMPEG>
<WaveformFFMPEGPath>Sti til FFMPEG</WaveformFFMPEGPath> <WaveformFFMPEGPath>Sti til FFMPEG</WaveformFFMPEGPath>
<WaveformBrowseToFFMPEG>Vælg sti stil FFMPEG</WaveformBrowseToFFMPEG> <WaveformBrowseToFFMPEG>Vælg sti stil FFMPEG</WaveformBrowseToFFMPEG>
<WaveformBrowseToVLC> <WaveformBrowseToVLC>Gå til VLC portable</WaveformBrowseToVLC>
</WaveformBrowseToVLC>
<SubStationAlphaStyle>Sub Station Alpha Style</SubStationAlphaStyle> <SubStationAlphaStyle>Sub Station Alpha Style</SubStationAlphaStyle>
<ChooseFont>Vælg skrifttype</ChooseFont> <ChooseFont>Vælg skrifttype</ChooseFont>
<ChooseColor>Vælg farve</ChooseColor> <ChooseColor>Vælg farve</ChooseColor>
@ -1515,8 +1514,7 @@ Fortsæt?</SubtitleAppendPrompt>
<MusicSymbol>Musik symbol</MusicSymbol> <MusicSymbol>Musik symbol</MusicSymbol>
<MusicSymbolsToReplace>Musik symboler der skal erstattes (adskilt af mellemrum)</MusicSymbolsToReplace> <MusicSymbolsToReplace>Musik symboler der skal erstattes (adskilt af mellemrum)</MusicSymbolsToReplace>
<FixCommonOcrErrorsUseHardcodedRules>Ret normale OCR fejl - Inkluder hardcodede regler</FixCommonOcrErrorsUseHardcodedRules> <FixCommonOcrErrorsUseHardcodedRules>Ret normale OCR fejl - Inkluder hardcodede regler</FixCommonOcrErrorsUseHardcodedRules>
<FixCommonerrorsFixShortDisplayTimesAllowMoveStartTime> <FixCommonerrorsFixShortDisplayTimesAllowMoveStartTime>Fix kort visningstid - tillad flytning af starttidspunkt</FixCommonerrorsFixShortDisplayTimesAllowMoveStartTime>
</FixCommonerrorsFixShortDisplayTimesAllowMoveStartTime>
<Shortcuts>Genveje</Shortcuts> <Shortcuts>Genveje</Shortcuts>
<Shortcut>Genvej</Shortcut> <Shortcut>Genvej</Shortcut>
<Control>Control</Control> <Control>Control</Control>
@ -1599,6 +1597,8 @@ Fortsæt?</SubtitleAppendPrompt>
<MainTextBoxMoveFirstWordFromNextUp>Flyt første ord fra næste linje op</MainTextBoxMoveFirstWordFromNextUp> <MainTextBoxMoveFirstWordFromNextUp>Flyt første ord fra næste linje op</MainTextBoxMoveFirstWordFromNextUp>
<MainTextBoxAutoBreak>Auto-ombryd tekst</MainTextBoxAutoBreak> <MainTextBoxAutoBreak>Auto-ombryd tekst</MainTextBoxAutoBreak>
<MainTextBoxUnbreak>Fjern linjeskift</MainTextBoxUnbreak> <MainTextBoxUnbreak>Fjern linjeskift</MainTextBoxUnbreak>
<Miscellaneous>Diverse</Miscellaneous>
<UseDoNotBreakAfterList>Benyt skift-ikke-efter-liste (for auto-ombrydning)</UseDoNotBreakAfterList>
</Settings> </Settings>
<ShowEarlierLater> <ShowEarlierLater>
<Title>Vis valgte linjer tidligere/senere</Title> <Title>Vis valgte linjer tidligere/senere</Title>

View File

@ -0,0 +1,33 @@
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Logic
{
public class NoBreakAfterItem
{
public Regex _regex;
public string _text;
private string p1;
public NoBreakAfterItem(Regex regex)
{
_regex = regex;
}
public NoBreakAfterItem(string text)
{
_text = text;
}
public bool IsMatch(string line)
{
if (_regex != null)
return _regex.IsMatch(line);
if (!string.IsNullOrEmpty(_text) && line.EndsWith(_text))
return true;
return false;
}
}
}

View File

@ -356,12 +356,14 @@ namespace Nikse.SubtitleEdit.Logic
// Some words we don't like breaking after // Some words we don't like breaking after
string s2 = s.Substring(0, index); string s2 = s.Substring(0, index);
if (Configuration.Settings.Tools.UseNoLineBreakAfter && language == "en") if (Configuration.Settings.Tools.UseNoLineBreakAfter)
{ {
foreach (string ending in Configuration.Settings.Tools.NoLineBreakAfterEnglish.Split(';'))
foreach (NoBreakAfterItem ending in NoBreakAfterList(language))
{ {
if (ending.Length > 0 && s2.EndsWith(ending)) if (ending.IsMatch(s2))
return false; return false;
} }
} }
@ -371,6 +373,46 @@ namespace Nikse.SubtitleEdit.Logic
return true; return true;
} }
private static string _lastNoBreakAfterListLanguage = null;
private static List<NoBreakAfterItem> _lastNoBreakAfterList = new List<NoBreakAfterItem>();
private static IEnumerable<NoBreakAfterItem> NoBreakAfterList(string languageName)
{
if (string.IsNullOrEmpty(languageName))
return new List<NoBreakAfterItem>();
if (languageName == _lastNoBreakAfterListLanguage)
return _lastNoBreakAfterList;
_lastNoBreakAfterList = new List<NoBreakAfterItem>();
//load words via xml
string noBreakAfterFileName = DictionaryFolder + languageName + "_NoBreakAfterList.xml";
var doc = new XmlDocument();
if (File.Exists(noBreakAfterFileName))
{
doc.Load(noBreakAfterFileName);
foreach (XmlNode node in doc.DocumentElement)
{
if (!string.IsNullOrEmpty(node.InnerText))
{
if (node.Attributes["RegEx"] != null && node.Attributes["RegEx"].InnerText.ToLower() == "true")
{
Regex r = new Regex(node.InnerText, RegexOptions.Compiled);
_lastNoBreakAfterList.Add(new NoBreakAfterItem(r));
}
else
{
_lastNoBreakAfterList.Add(new NoBreakAfterItem(node.InnerText));
}
}
}
}
_lastNoBreakAfterListLanguage = languageName;
return _lastNoBreakAfterList;
}
public static string AutoBreakLineMoreThanTwoLines(string text, int maximumLineLength, string language) public static string AutoBreakLineMoreThanTwoLines(string text, int maximumLineLength, string language)
{ {
if (text == null || text.Length < 3) if (text == null || text.Length < 3)

View File

@ -833,6 +833,7 @@
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Logic\NikseBitmap.cs" /> <Compile Include="Logic\NikseBitmap.cs" />
<Compile Include="Logic\NoBreakAfterItem.cs" />
<Compile Include="Logic\OCR\Binary\BinaryOcrBitmap.cs" /> <Compile Include="Logic\OCR\Binary\BinaryOcrBitmap.cs" />
<Compile Include="Logic\OCR\Binary\BinaryOcrDb.cs" /> <Compile Include="Logic\OCR\Binary\BinaryOcrDb.cs" />
<Compile Include="Logic\OCR\ModiLanguage.cs" /> <Compile Include="Logic\OCR\ModiLanguage.cs" />

View File

@ -1,5 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013 # Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubtitleEdit", "SubtitleEdit.csproj", "{511A5B59-1C35-4719-8536-23B19AF9B21A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubtitleEdit", "SubtitleEdit.csproj", "{511A5B59-1C35-4719-8536-23B19AF9B21A}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{DBD4656C-5F40-4067-A70B-C4460DE20F77} = {DBD4656C-5F40-4067-A70B-C4460DE20F77} {DBD4656C-5F40-4067-A70B-C4460DE20F77} = {DBD4656C-5F40-4067-A70B-C4460DE20F77}
@ -17,9 +19,6 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateAssemblyInfo", "UpdateAssemblyInfo\UpdateAssemblyInfo.csproj", "{DBD4656C-5F40-4067-A70B-C4460DE20F77}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateAssemblyInfo", "UpdateAssemblyInfo\UpdateAssemblyInfo.csproj", "{DBD4656C-5F40-4067-A70B-C4460DE20F77}"
EndProject EndProject
Global Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = SubtitleEdit.vsmdi
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
@ -41,4 +40,7 @@ Global
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = SubtitleEdit.vsmdi
EndGlobalSection
EndGlobal EndGlobal