Represents a subtitle, including its time settings, text and text style.
예제 #1
0
	internal string Build (SubtitleCollection collection, SubtitleProperties subtitleProperties, FileProperties fileProperties) {
		this.subtitleProperties = subtitleProperties;
		StringBuilder output = new StringBuilder();
		if (format.HasHeaders)
			output.Append(format.HeadersToString(subtitleProperties, fileProperties));

		if (format.HasBodyBegin)
			output.Append(format.BodyBeginOut);

		string subtitleExpression = GetSubtitleExpression(format, subtitleProperties, fileProperties);
		Regex fieldExpression = new Regex(@"<<(?<Field>\w+)(,(?<Width>\d+))?>>");
		MatchEvaluator matchEvaluator = new MatchEvaluator(this.FieldEvaluator);

		foreach (Subtitle currentSubtitle in collection) {
			subtitle = currentSubtitle;
			string outputSubtitle = fieldExpression.Replace(subtitleExpression, matchEvaluator);
			output.Append(outputSubtitle);
			output.Append("\n");
			subtitleNumber++;
			previousSubtitle = subtitle;
		}

		if (format.HasBodyEnd)
			output.Append(format.BodyEndOut);

		subtitle = null;
		previousSubtitle = null;
		subtitleNumber = 1;

		ConvertNewlines(output, fileProperties);
		return output.ToString();
	}
	public override void Undo () {
		if (this.subtitleAfter == null) {
			this.subtitleAfter = Base.Document.Subtitles[this.FirstPath];
		}
		Base.Document.Subtitles.Remove(this.FirstPath);
		Base.Ui.View.Insert(this.subtitlesBefore, this.FirstPath, this.FirstPath);
		PostProcess();
	}
예제 #3
0
	// can be optimized
	internal override void SubtitleInputPostProcess (Subtitle subtitle) {
		string subtitleText = subtitle.Text.Get(lineBreak);
		string styleText = String.Empty;
		MatchCollection matches = styleExpression.Matches(subtitleText);
		foreach (Match match in matches) {
			styleText +=  match.Value;
		}
		Style style = StringToStyle(styleText);
		subtitle.Style = style;
		subtitleText = styleExpression.Replace(subtitleText, String.Empty);
		subtitle.Text.Set(subtitleText, lineBreak, true);
	}
예제 #4
0
	private void ReadSubtitles (Encoding encoding, ParsingProperties properties, SubtitleCollection collection) {

		string[] lines = text.Split(new char[] {'\n'});
		for (int i = 0; i < lines.Length; i++) {
			SubtitleText stext = ParseSubtitleText(lines[i]);
			Style style = new Style();
			if(!stext.IsEmpty) {
				Subtitle subtitle = new Subtitle(null, stext, style);
				collection.Add(subtitle);
			}
		}

	}
예제 #5
0
	protected override string GetSubtitleTextContent (Subtitle subtitle) {
		return subtitle.Text.Get();
	}
예제 #6
0
	protected override void ChangeSubtitleTextContent (Subtitle subtitle, string text) {
		subtitle.Text.Set(text);
	}
예제 #7
0
	protected void OnSubtitleSelectionChanged (TreePath[] paths, Subtitle subtitle) {
		if (subtitle != null)
    		LoadSubtitle(subtitle);
    	else
    		ClearFields();
    }
예제 #8
0
	private void OnSubtitleSelectionChanged (TreePath[] paths, Subtitle subtitle) {
		if ((subtitle != null) && IsLoaded)
			SetSelectionDependentControlsSensitivity(true);
		else
			SetSelectionDependentControlsSensitivity(false);
	}
예제 #9
0
	/// <summary>Creates a subtitle based on the subtitle at the specified index and adds it to the
	/// collection, inserting it right after that index.</summary>
	/// <remarks>The newly created subtitle's times will be based on the specified subtitle.
	/// Its duration will be <see cref="SubtitleConstants.MaxSingleLineSubtitleDuration" />.</remarks>
	/// <param name="index">The zero-based index after which the subtitle should be inserted.</param>
	/// <param name="subtitleProperties">The SubtitleProperties of the subtitles.</param>
	/// <param name="timeBetweenSubtitles">The gap to keep after the existing subtitle, in milliseconds.</param>
	/// <returns>True if the subtitle could be added, false otherwise.</returns>
	public bool AddNewAfter (int index, SubtitleProperties subtitleProperties, int timeBetweenSubtitles) {
		Subtitle existing = Get(index);
		if (existing == null)
			return false;

		TimeSpan subtitleStart = existing.Times.End + TimeSpan.FromMilliseconds(timeBetweenSubtitles);
		TimeSpan subtitleEnd = subtitleStart + TimeSpan.FromSeconds(SubtitleConstants.AverageSubtitleDuration);
		Subtitle subtitle = new Subtitle(subtitleProperties, subtitleStart, subtitleEnd);
		Add(subtitle, index + 1);
		return true;
	}
예제 #10
0
	protected abstract void ChangeSubtitleTextContent (Subtitle subtitle, string text);
	private void LoadDurationTiming (Subtitle subtitle) {
    	durationSpinButton.ValueChanged -= OnDurationValueChanged;

    	if (timingMode == TimingMode.Frames)
    		durationSpinButton.Value = subtitle.Frames.Duration;
    	else
    		durationSpinButton.Value = subtitle.Times.Duration.TotalMilliseconds;

    	durationSpinButton.ValueChanged += OnDurationValueChanged;
    }
예제 #12
0
	private void OnSubtitleViewSelectionChanged (TreePath[] paths, Subtitle subtitle) {
		if (subtitle != null) {
			/* One subtitle selected */
			SetStylesActivity(subtitle.Style.Bold, subtitle.Style.Italic, subtitle.Style.Underline);
			SetNonZeroSelectionDependentSensitivity(1, true);
			SetOneSelectionDependentSensitivity(true);
		}
		else {
			SetOneSelectionDependentSensitivity(false);
			int selectionCount = paths.Length;

			if (selectionCount == 0) {
				/* No selection */
				SetNonZeroSelectionDependentSensitivity(selectionCount, false);
				SetStylesActivity(false, false, false);
			}
			else {
				/* Multiple paths selected */
				SetNonZeroSelectionDependentSensitivity(selectionCount, true);
				bool bold, italic, underline;
				GetGlobalStyles(paths, out bold, out italic, out underline);
				SetStylesActivity(bold, italic, underline);
			}
		}
	}
예제 #13
0
	/* Public methods */

	/// <summary></summary>
	/// <remarks>SubtitleProperties is not cloned and should be set afterwards.</remarks>
	public Subtitle Clone (SubtitleProperties propertiesClone) {
		Subtitle subtitleClone = new Subtitle();

		Times timesClone = this.times.Clone(subtitleClone);
		Frames framesClone = this.frames.Clone(subtitleClone);
		SubtitleText textClone = this.text.Clone() as SubtitleText;
		SubtitleText translationClone = (this.translation != null ? this.translation.Clone() as SubtitleText : null);
		Style styleClone = this.style.Clone() as Style;
		subtitleClone.SetFieldsForDeepClone(propertiesClone, timesClone, framesClone, textClone, translationClone, styleClone);

		return subtitleClone;
	}
예제 #14
0
	public void Insert (Subtitle[] subtitles, TreePath firstPath, TreePath focus) {
		for (int index = 0, pathIndex = Util.PathToInt(firstPath) ; index < subtitles.Length  ; index++, pathIndex++) {
			Subtitle subtitle = subtitles[index];
			this.subtitles.Add(subtitle, pathIndex);
		}
		TreePath lastPath = Util.IntToPath(Util.PathToInt(firstPath) + subtitles.Length - 1);
		TreePath[] pathRange = new TreePath[]{firstPath, lastPath};
		selection.SelectRange(pathRange, focus, true);
	}
예제 #15
0
	/// <summary>Inserts a collection of subtitles in the specified paths.</summary>
	/// <param name="subtitles">The subtitles to insert.</param>
	/// <param name="paths">The paths corresponding to each of the subtitles. There must be the same number of paths as there are for subtitles.</param>
	/// <param name="focus">The path that should be given the focus.</param>
	public void Insert (Subtitle[] subtitles, TreePath[] paths, TreePath focus) {
		for (int index = 0 ; index < subtitles.Length ; index++) {
			Subtitle subtitle = subtitles[index];
			TreePath path = paths[index];
			int pathIndex = Util.PathToInt(path);
			this.subtitles.Add(subtitle, pathIndex);
		}
		selection.Select(paths, focus, true);
	}
예제 #16
0
	/// <summary>Inserts a subtitle in the specified path.</summary>
	public void Insert (Subtitle subtitle, TreePath path) {
		int index = Util.PathToInt(path);
		subtitles.Add(subtitle, index);
		selection.Select(path, true, true);
	}
	private void LoadStartTiming (Subtitle subtitle) {
    	startSpinButton.ValueChanged -= OnStartValueChanged;

    	if (timingMode == TimingMode.Frames)
    		startSpinButton.Value = subtitle.Frames.Start;
    	else
    		startSpinButton.Value = subtitle.Times.Start.TotalMilliseconds;

   		startSpinButton.ValueChanged += OnStartValueChanged;
   	}
예제 #18
0
	public ChangeTimingCommand (int frames, string description, bool seekAfterChange): base(description, true, true) {
		this.subtitle = Base.Document.Subtitles[Path];
		this.storedFrames = frames;
		this.seekAfterChange = seekAfterChange;
	}
	private void LoadEndTiming (Subtitle subtitle) {
   		endSpinButton.ValueChanged -= OnEndValueChanged;

    	if (timingMode == TimingMode.Frames)
    		endSpinButton.Value = subtitle.Frames.End;
    	else
    		endSpinButton.Value = subtitle.Times.End.TotalMilliseconds;

   		endSpinButton.ValueChanged += OnEndValueChanged;
	}
예제 #20
0
	public ChangeTimingCommand (TimeSpan time, string description, bool seekAfterChange): base(description, true, true) {
		this.subtitle = Base.Document.Subtitles[Path];
		this.storedTime = time;
		this.seekAfterChange = seekAfterChange;
	}
 private void OnSubtitleSelectionChanged (TreePath[] paths, Subtitle subtitle) {
 	if (subtitle != null)
 		LoadTimings();
 	else
 		ClearFields();
 }
예제 #22
0
	/// <summary>Adds a subtitle to the end of the collection.</summary>
	/// <param name="subtitle">The subtitle to add.</param>
	public void Add (Subtitle subtitle){
		subtitles.Add(subtitle);
	}
예제 #23
0
	/// <summary>Creates a subtitle based on the subtitle at the specified index and adds it to the
	/// collection, inserting it right before that index.</summary>
	/// <remarks>The newly created subtitle's times will be based on the specified subtitle. Its duration
	/// will be <see cref="SubtitleConstants.MaxSingleLineSubtitleDuration" />. Both the start and end times
	/// times will be wrapped to zero if they are negative.</remarks>
	/// <param name="index">The zero-based index before which the subtitle should be inserted.</param>
	/// <param name="subtitleProperties">The SubtitleProperties of the subtitles.</param>
	/// <param name="timeBetweenSubtitles">The gap to keep before the existing subtitle, in milliseconds.</param>
	/// <returns>True if the subtitle could be added, false otherwise.</returns>
	public bool AddNewBefore (int index, SubtitleProperties subtitleProperties, int timeBetweenSubtitles) {
		Subtitle existing = Get(index);
		if (existing == null)
			return false;

		TimeSpan subtitleEnd = existing.Times.Start - TimeSpan.FromMilliseconds(timeBetweenSubtitles);
		if (subtitleEnd < TimeSpan.Zero)
			subtitleEnd = TimeSpan.FromSeconds(0);

		TimeSpan subtitleStart = subtitleEnd - TimeSpan.FromSeconds(SubtitleConstants.AverageSubtitleDuration);
		if (subtitleStart < TimeSpan.Zero)
			subtitleStart = TimeSpan.FromSeconds(0);

		Subtitle subtitle = new Subtitle(subtitleProperties, subtitleStart, subtitleEnd);
		Add(subtitle, index);
		return true;
	}
예제 #24
0
	internal virtual void SubtitleInputPostProcess (Subtitle subtitle) {
		return;
	}
예제 #25
0
	/// <summary>Creates a subtitle and adds it to the collection, inserting it at the specified index
	/// and with the specified start time.</summary>
	/// <remarks>The newly created subtitle's duration will be
	/// <see cref="SubtitleConstants.MaxSingleLineSubtitleDuration" />.</remarks>
	/// <param name="index">The zero-based index at which the subtitle should be inserted.</param>
	/// <param name="subtitleProperties">The SubtitleProperties of the subtitles.</param>
	/// <param name="start">The time at which the new subtitle will start</para>
	/// <returns>True if the subtitle could be added, false otherwise.</returns>
	public bool AddNewAt (int index, SubtitleProperties subtitleProperties, TimeSpan start) {
		if ((index < 0) || (index > Count))
			return false;

		TimeSpan subtitleStart = start;
		TimeSpan subtitleEnd = subtitleStart + TimeSpan.FromSeconds(SubtitleConstants.AverageSubtitleDuration);
		Subtitle subtitle = new Subtitle(subtitleProperties, subtitleStart, subtitleEnd);
		Add(subtitle, index);
		return true;
	}
예제 #26
0
	protected abstract string GetSubtitleTextContent (Subtitle subtitle);
예제 #27
0
	/// <summary>Adds a subtitle to the collection, inserting it at the specified index.</summary>
	/// <param name="subtitle">The subtitle to add.</param>
	/// <param name="index">The zero-based index at which the subtitle should be inserted.</param>
	public void Add (Subtitle subtitle, int index){
		subtitles.Insert(index, subtitle);
	}
예제 #28
0
	/// <summary>Appends a subtitle to the end of the list.</summary>
	public void Add (Subtitle subtitle) {
		Collection.Add(subtitle);
		model.AppendValues(subtitle);
	}
예제 #29
0
	/* Public members */

	public override bool Execute () {
		InsertNew();
		subtitle = Base.Document.Subtitles[newPath];
		return true;
	}
예제 #30
0
	/// <summary>Adds a subtitle to the specified position on the list.</summary>
	public void Add (Subtitle subtitle, int index) {
		Collection.Add(subtitle, index);
		model.SetValue(model.Insert(index), 0, subtitle);
	}