private void button1_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Archivos soportados (*.txt;*.ass;*.ssa)|*.txt;*.ass;*.ssa"; if (ofd.ShowDialog() == DialogResult.OK) { StreamReader sr = FileAccessWrapper.OpenTextFile(ofd.FileName); FileInfo finfo = new FileInfo(ofd.FileName); kanjisBox.Text = ""; string ext = finfo.Extension.ToLower(); switch (ext) { case ".txt": kanjisBox.Text = sr.ReadToEnd(); break; case ".ssa": case ".ass": string linea; while ((linea = sr.ReadLine()) != null) { if (linea.StartsWith("Dialogue", StringComparison.InvariantCultureIgnoreCase)) { lineaASS lass = new lineaASS(linea); kanjisBox.Text = kanjisBox.Text + lineaASS.cleanText(lass.texto); } } break; default: mW.errorMsg("Extensión desconocida."); break; } sr.Close(); } }
public static Bitmap GenerateAudioGridDisplayMarkers(Bitmap b, double pinicio, double pfinal, double marca, int pxsec, bool ActualTime, lineaASS lass, bool DrawText) { if (pinicio != -1 || pfinal != -1) { int x_inicial=0, x_final=0; Color inicio = (ActualTime) ? Color.Red : Color.DarkGreen; Color final = (ActualTime)? Color.Orange : Color.DarkGreen; Color selected = (ActualTime)? Color.AntiqueWhite : Color.Black; int alphaselected = (ActualTime)? 50 : 150; Color fondotiempo = Color.White; int ancho = b.Width; int alto = b.Height; string sinicio = Tiempo.SecondToTimeString(pinicio); string sfinal = Tiempo.SecondToTimeString(pfinal); StringFormat stringformat = new StringFormat(StringFormat.GenericTypographic); Font fuente = new Font("Tahoma", 8, FontStyle.Bold); double sec = (double)ancho / (double)pxsec; using (Graphics g = Graphics.FromImage((Image)b)) { int anchoi = Convert.ToInt32(g.MeasureString(sinicio, fuente, new PointF(0, 0), stringformat).Width); int altoi = Convert.ToInt32(g.MeasureString(sinicio, fuente, new PointF(0, 0), stringformat).Height); int anchof = Convert.ToInt32(g.MeasureString(sfinal, fuente, new PointF(0, 0), stringformat).Width); int altof = Convert.ToInt32(g.MeasureString(sfinal, fuente, new PointF(0, 0), stringformat).Height); if (pinicio != -1) { double rel = pinicio - marca; double p1 = (100 * rel) / sec; double p2 = (ancho * p1) / 100; x_inicial = (int)Math.Round(p2); g.DrawLine(new Pen(new SolidBrush(inicio), 1), x_inicial, 0, x_inicial, alto); if (ActualTime) { int xs = x_inicial - anchoi - 6; int ys = alto - (altoi * 2); anchoi += 6; g.FillRectangle(new SolidBrush(inicio), new Rectangle(xs - 1, ys - 1, anchoi + 2, altoi + 2)); g.FillRectangle(new SolidBrush(fondotiempo), new Rectangle(xs, ys, anchoi, altoi)); g.DrawString(sinicio, fuente, new SolidBrush(Color.Black), new Point(xs, ys)); } } if (pfinal != -1) { double rel = pfinal - marca; double p1 = (100 * rel) / sec; double p2 = (ancho * p1) / 100; x_final = (int)Math.Round(p2); g.DrawLine(new Pen(new SolidBrush(final), 1), x_final, 0, x_final, alto); if (ActualTime) { int xs = x_final + 1; int ys = alto - (altof * 2); anchof += 6; g.FillRectangle(new SolidBrush(final), new Rectangle(xs - 1, ys - 1, anchof + 2, altof + 2)); g.FillRectangle(new SolidBrush(fondotiempo), new Rectangle(xs, ys, anchof, altof)); g.DrawString(sfinal, fuente, new SolidBrush(Color.Black), new Point(xs, ys)); } } if (pinicio != -1 && pfinal != -1) { if (x_inicial < x_final) { //rectangulo Rectangle r = new Rectangle(x_inicial + 1, 0, (x_final - x_inicial) - 1, alto); g.FillRectangle(new SolidBrush(Color.FromArgb(alphaselected, selected)), r); // texto if (DrawText) { r.Height = alto - 10; StringFormat sf = new StringFormat(StringFormat.GenericTypographic); sf.Alignment = StringAlignment.Center; sf.LineAlignment = (ActualTime) ? StringAlignment.Center : StringAlignment.Far; Font f = (ActualTime) ? new Font("Tahoma", 9, FontStyle.Regular) : new Font("Tahoma", 9, FontStyle.Italic); string texto = lineaASS.cleanText(lass.texto); g.DrawString(texto, f, new SolidBrush((lass.IsComment()) ? Color.Yellow : Color.White), r, sf); } } } } } return b; }
public void Add(lineaASS o) { Lines.Add(o); }
private int LineaASS_to_Karaoke_K(lineaASS lass, int i) { Ks.Clear(); string s = lass.texto; Regex r = new Regex(@"\{\\[kK]f?\d+\}"); MatchCollection mc = r.Matches(s); for (int x = 0; x < mc.Count; x++) { Match m = mc[x]; int fin_actual = m.Index + m.Length; string texto = ""; // obtener texto :) if (x < mc.Count - 1) { Match siguiente = mc[x + 1]; int principio_siguiente = siguiente.Index; texto = s.Substring(fin_actual, principio_siguiente - fin_actual); } else texto = s.Substring(fin_actual); // estilo K Regex styleh = new Regex("kf|K|k"); Match sss = styleh.Match(m.ToString()); string estilok = sss.ToString(); // nº milisegundos Regex milis = new Regex(@"\d+"); Match mmm = milis.Match(m.ToString()); int milisec; if (mmm.ToString()=="") milisec = 0; else milisec = int.Parse(mmm.ToString()); Ks.Add(new Karaoke_K(i, estilok, milisec, texto)); } return Ks.Count; }
public void ProcesarAjuste() { ArrayList keysInRangeInit = new ArrayList(); ArrayList keysInRangeFinal = new ArrayList(); bool change; for (int count=0; count<lineasOrdenadas.Count; count++) { lineaASSidx lassidx = (lineaASSidx)lineasOrdenadas[count]; change = false; lineaASS lass = new lineaASS(lassidx.ToString()); lineaASS lass_original = new lineaASS(lassidx.ToString()); int idx = lassidx.Index; int anterior = 0, posterior = 0; int inFrame = Convert.ToInt32(Math.Round(lass.t_inicial.getTiempo() * fps)); int outFrame = Convert.ToInt32(Math.Round(lass.t_final.getTiempo() * fps)); int inRange = Math.Max(inFrame - iPre, 0); // evitando negatiffos int inRangeEnd = inFrame + iPost; int outRange = Math.Max(outFrame - fPre,0); // caso raro int outRangeEnd = outFrame + fPost; // lista de los keyframes que cumplen los requisitos keysInRangeInit.Clear(); keysInRangeFinal.Clear(); for (int i = 0; i < keyFrame.Length; i++) { int k = (int)keyFrame[i]; if ((k >= inRange) && (k <= inRangeEnd)) keysInRangeInit.Add(k); if ((k <= outRangeEnd) && (k >= outRange)) keysInRangeFinal.Add(k); if (k <= inFrame) anterior = k; if (k >= outFrame) if (posterior == 0) posterior = k; } double r=0.0, s=0.0; if (keysInRangeFinal.Count > 0) { r = (Convert.ToDouble((int)keysInRangeFinal[keysInRangeFinal.Count - 1]) / (double)fps); r -= 0.01; if (Math.Round(r,2)!=lassidx.t_inicial.getTiempo()) lass.t_final.setTiempo(r); // si el final coincide con el principio change = true; } r = lass.t_final.getTiempo(); if (keysInRangeInit.Count > 0) { s = (Convert.ToDouble((int)keysInRangeInit[0]) / (double)fps); s -= 0.01; if (r != Math.Round(s, 2) && r > Math.Round(s, 2)) // primamos fin a inicio lass.t_inicial.setTiempo(s); change = true; } double duracion = lass.t_final.getTiempo() - lass.t_inicial.getTiempo(); if (duracion <= 0.0) lass.t_inicial = lass_original.t_inicial; // lass tratada // aquí código de seguridad para evitar colisiones si los valores no están igualados si se ha cambiado algo if (seguridadColisiones) { foreach (int key in Resultado.Keys) { lineaASS otra = (lineaASS)Resultado[key]; // una de las anteriores if (otra.t_final.getTiempo() > lass.t_inicial.getTiempo()) { // sera con fpre supongo double pre_s = (Convert.ToDouble(fPre) / (double)fps); if (!((otra.t_final.getTiempo() - pre_s) > lass.t_inicial.getTiempo())) { lass.t_inicial = otra.t_final; // si hay más de 1 supongo que todos estarán al mismo keyframe, ¿no? change = true; } } } } // s'acabo if (change) Resultado.Add(idx, lass); if (LineaProcesada != null) LineaProcesada(this, new AjustarKeyframeLineaProcesadaEventArgs(count)); } if (ProcesoFinalizado != null) ProcesoFinalizado(this); }
private void makeTempFile() { TextWriter o = new StreamWriter(PreviewFile, false, System.Text.Encoding.UTF8); o.WriteLine(mW.headerMark); o.WriteLine("PlayResY: " + textPlayResY.Text); o.WriteLine(); o.WriteLine(mW.stylesMark); estiloV4 e = (estiloV4)mW.v4[listBox1.SelectedIndex]; estiloV4 e2 = new estiloV4(e.ToString()); switch (e.Alignment) { case 4: case 7: e2.Alignment = 1; break; case 5: case 8: e2.Alignment = 2; break; case 6: case 9: e2.Alignment = 3; break; default: e2.Alignment = e.Alignment; break; } o.WriteLine(e2.ToString()); o.WriteLine(); o.WriteLine(mW.dialoguesMark); lineaASS l = new lineaASS(); if (checkBox2.Checked) l.texto = "{\\be1}"+previewText.Text; else l.texto = previewText.Text; l.estilo = e.Name; l.t_final.setTiempo(50); o.WriteLine(l.ToString()); o.Close(); }
private void updateLineaASSwithPanelTextTools(lineaASS lass) { lass.texto = selectedLine.Text; lass.t_inicial.setTiempo(textInicio.Text); lass.t_final.setTiempo(textFin.Text); lass.personaje = textPers.Text; lass.estilo = textEst.Text; lass.vertical = int.Parse(textVert.Text); lass.izquierda = int.Parse(textIzq.Text); lass.derecha = int.Parse(textDcha.Text); //lass.clase = (/*checkComment.Checked*/ComentarDescomentar.BackColor.Equals(CommentBack)) ? "Comment" : "Dialogue"; lass.colision = (int)textLayer.Value; }
private void pasteClipToRow(int mode) { if (gridASS.SelectedRows.Count > 0) { UndoRedo.AddUndo(script, "Pegar"); //UndoStack.Push(al_clone); try { ArrayList al_clone = PrepareForPush(al); string[] l = Clipboard.GetText().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < l.Length; i++) { if (!l[i].Equals(String.Empty)) { lineaASS lass = new lineaASS(l[i]); lineaASS actual = (lineaASS)al[gridASS.SelectedRows[0].Index]; switch (lass.texto) { case "[Copiar Tiempo Inicial]": pastePartialCopy(l, CopyStyle.TInicial); return; case "[Copiar Tiempo Final]": pastePartialCopy(l, CopyStyle.TFinal); return; case "[Copiar Tiempo]": pastePartialCopy(l, CopyStyle.Tiempo); return; case "[Copiar Estilo]": pastePartialCopy(l, CopyStyle.Estilo); return; case "[Copiar Personaje]": pastePartialCopy(l, CopyStyle.Personaje); return; case "[Copiar Estilo y Personaje]": pastePartialCopy(l, CopyStyle.EstiloPersonaje); return; case "[Copiar Todo menos Texto]": pastePartialCopy(l, CopyStyle.SinTexto); return; default: al.Insert(gridASS.SelectedRows[0].Index + mode + i, lass); break; } } } updateGridWithArrayList(al); } catch { } } }
private void partialCopy(lineaASS lass, lineaASS actual, CopyStyle elque) { switch (elque) { case CopyStyle.TInicial: actual.t_inicial = lass.t_inicial; break; case CopyStyle.TFinal: actual.t_final = lass.t_final; break; case CopyStyle.Tiempo: actual.t_inicial = lass.t_inicial; actual.t_final = lass.t_final; break; case CopyStyle.Estilo: actual.estilo = lass.estilo; break; case CopyStyle.Personaje: actual.personaje = lass.personaje; break; case CopyStyle.EstiloPersonaje: actual.estilo = lass.estilo; actual.personaje = lass.personaje; break; case CopyStyle.SinTexto: actual.estilo = lass.estilo; actual.personaje = lass.personaje; actual.t_inicial = lass.t_inicial; actual.t_final = lass.t_final; break; } }
private void insertLineInRow(int mode) { if (gridASS.Rows.Count > 0) { if (gridASS.SelectedRows.Count > 0) { UndoRedo.AddUndo(script, "Insertar línea"); //UndoStack.Push(PrepareForPush(al)); lineaASS lass = new lineaASS(); al.Insert(gridASS.SelectedRows[0].Index + mode, lass); updateGridWithArrayList(al); updatePanelTextTools(); } } else { al.Add(new lineaASS()); updateGridWithArrayList(al); } }
private lineaASS adjToKeyF(lineaASS lass, int initPre, int initPost, int finalPre, int finalPost, ArrayList estilos, out int anterior, out int posterior) { bool styleOK = false; UndoRedo.AddUndo(script, "Ajustar tiempos a KeyFrames"); //UndoStack.Push(PrepareForPush(al)); foreach (estiloV4 a in estilos) if (lass.estilo.Equals(a.Name)) styleOK = true; anterior = 0; posterior = 0; if (!styleOK) return lass; int inFrame = Convert.ToInt32(Math.Round(lass.t_inicial.getTiempo() * videoInfo.FrameRate)); int outFrame = Convert.ToInt32(Math.Round(lass.t_final.getTiempo() * videoInfo.FrameRate)); int inRange = Math.Max(inFrame - initPre,0); // evitando negatiffos int inRangeEnd = inFrame + initPost; int outRange = outFrame - finalPre; int outRangeEnd = outFrame + finalPost; // lista de los keyframes que cumplen los requisitos ArrayList keysInRangeInit = new ArrayList(); ArrayList keysInRangeFinal = new ArrayList(); for (int i = 0; i < videoInfo.KeyFrames.Count; i++) { int k = (int)videoInfo.KeyFrames[i]; if ((k >= inRange) && (k <= inRangeEnd)) keysInRangeInit.Add(k); if ((k <= outRangeEnd) && (k >= outRange)) keysInRangeFinal.Add(k); if (k <= inFrame) anterior = k; if (k >= outFrame) if (posterior == 0) posterior = k; } if (keysInRangeInit.Count > 0) { double s = (Convert.ToDouble((int)keysInRangeInit[0]) / (double)videoInfo.FrameRate); lass.t_inicial.setTiempo(s - 0.01); } if (keysInRangeFinal.Count > 0) { double s = (Convert.ToDouble((int)keysInRangeFinal[keysInRangeFinal.Count - 1]) / (double)videoInfo.FrameRate); lass.t_final.setTiempo(s - 0.01); } return lass; }
public void LoadFromFile(string filename) { FileName = filename; FileInfo info = new FileInfo(FileName); if (!info.Exists) throw new FileNotFoundException(); ScriptFileType type = ScriptFileType.Unknown; switch (info.Extension.ToLower()) { case ".ass": case ".ssa": case ".autosave": type = ScriptFileType.ASS_SSA; break; case ".srt": type = ScriptFileType.SRT; break; case ".txt": type = ScriptFileType.TXT; break; default: type = ScriptFileType.Unknown; break; } if (type == ScriptFileType.Unknown) throw new PerrySubException("Tipo de archivo desconocido"); ResetScript(); StreamReader sr = FileAccessWrapper.OpenTextFile(FileName); ArrayList head = Header.GetHeaderList(); bool reachEOH = false; Tiempo ianterior = null; Tiempo fanterior = null; string linea = ""; string pj = ""; int i = 0; bool isGraphic = false; bool isFont = false; string gfx = ""; string gfx_name = ""; string fnt = ""; string fnt_name = ""; while ((linea = sr.ReadLine()) != null) { switch (type) { case ScriptFileType.ASS_SSA: if (linea.ToLower().StartsWith("[v4")) reachEOH = true; if (!linea.ToLower().Equals("[script info]") && !reachEOH) { if (!linea.StartsWith("; ")) if (linea.IndexOf(": ") != -1) head.Add(linea); } if (linea.ToLower().StartsWith("style:")) Styles.Add(new estiloV4(linea)); if (linea.ToLower().StartsWith("dialogue") || linea.ToLower().StartsWith("comment")) { try { Lines.Add(new lineaASS(linea)); } catch (LineException le) { System.Windows.Forms.MessageBox.Show("Detectada excepción en una línea\n" + le.Message, mainW.appTitle, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } // aqui tenemos que ver si hay attachments, y cargarlos si toca if (isGraphic) { if (linea.Equals("")) { Attachments.InsertGraphic(gfx_name, gfx); isGraphic = false; gfx = ""; break; } gfx += linea+"\r\n"; } if (isFont) { if (linea.Equals("")) { Attachments.InsertFont(fnt_name, fnt); isFont = false; fnt = ""; break; } fnt += linea+"\r\n"; } if (linea.ToLower().StartsWith("filename:")) // [Graphics] { isGraphic = true; gfx_name = linea.Substring(linea.IndexOf(':') + 1).Trim(); } if (linea.ToLower().StartsWith("fontname:")) // [Fonts] { isFont = true; fnt_name = linea.Substring(linea.IndexOf(':') + 1).Trim(); } break; case ScriptFileType.TXT: // 1- nueva cabecera (luego) // 2- estilo default (luego) // 3- lineas linea = linea.Replace("\t", ""); int idx = linea.IndexOf(":"); if (idx > 0) { pj = linea.Substring(0, idx).Trim(); linea = linea.Substring(idx + 1, linea.Length - (idx + 1)).Trim(); } lineaASS telameto = new lineaASS(); telameto.texto = linea; telameto.personaje = pj; Lines.Add(telameto); break; case ScriptFileType.SRT: //int moddy = i % 4; if (i == 1) { string[] tiempos = linea.Split(new string[] { "-->" }, StringSplitOptions.None); ianterior = new Tiempo(tiempos[0].Replace(',', '.').Trim()); fanterior = new Tiempo(tiempos[1].Replace(',', '.').Trim()); } else if (i == 2) { Lines.Add(new lineaASS(ianterior.ToString(), fanterior.ToString(), "Default", linea)); } else if (i > 2 && !linea.Equals("")) { lineaASS lass_ultima = (lineaASS)Lines.GetLines()[Lines.Count - 1]; lass_ultima.texto = lass_ultima.texto+"\\N"+linea; } if (linea.Equals("")) i = 0; else i++; break; } } Lines.Trim(); sr.Close(); if (isFont) Attachments.InsertFont(fnt_name, fnt); // por si acaso llegamos a EOF antes de \r\n if (isGraphic) Attachments.InsertFont(gfx_name, gfx); if (type == ScriptFileType.TXT || type == ScriptFileType.SRT) { Header.SetHeaderDefaults(); Styles.Add(new estiloV4()); } GC.Collect(); }
private int CalcularLineas(AviSynthClip avs, string PreviewFile, lineaASS actual) { int nLineas; //lineaASS actual = (lineaASS)lass.Clone(); TextWriter o = new StreamWriter(PreviewFile, false, System.Text.Encoding.UTF8); o.WriteLine(headerMark); o.WriteLine(script.GetHeader().ToString()); o.WriteLine(stylesMark); foreach (estiloV4 e2 in script.GetStyles()) { if (e2.Name.Equals(actual.estilo)) { estiloV4 new_est = new estiloV4(e2.ToString()); new_est.PrimaryColor = "&H00FFFFFF"; new_est.SecondaryColor = "&H00FFFFFF"; new_est.OutlineColor = "&H00FFFFFF"; new_est.ShadowColor = "&H00FFFFFF"; o.WriteLine(new_est.ToString().Replace("\n", string.Empty)); } } o.WriteLine(); // --- o.WriteLine(dialoguesMark); actual.t_inicial.setTiempo(0); actual.t_final.setTiempo(50); o.WriteLine(actual.ToString()); o.Close(); avs.AviSynthInvoke(avs.GetAVS(), 0, "Eval", false, "blankclip(color=$000000,width=" + width + ",height=" + height + ")"); avs.AviSynthInvoke(avs.GetAVS(), 0, "TextSub", true, PreviewFile); Image iimg = (Image)AviSynthFunctions.getBitmapFromFrame(avs, 0, 0); int x,y,x2,y2; nLineas = ContarLineas(iimg, out x, out y, out x2, out y2); iimg.Dispose(); File.Delete(PreviewFile); return nLineas; }
internal SpellCheckError(string badWordFound, lineaASS line, int lineNumber, int pos) { linea = new lineaASSidx(line.ToString(), lineNumber); posicion = pos; badWord = badWordFound; }