public string MakeTemporaryTvgFile(string name, string arguments, string infile, ProjectController controller) { string temporaryFileString = new Uri(controller.FileDirectory, "temp/" + name + "_" + id + ".tvg").AbsolutePath; Directory.CreateDirectory(Path.GetDirectoryName(temporaryFileString)); string command = string.Format("{0} -outformat TVG -outfile \"{1}\" {2}", arguments, temporaryFileString, infile); string output, error; RunCommand(command, out output, out error); Tvg2Xml(String.Format("-infile \"{0}\" -outfile \"{1}\"", infile, temporaryFileString + "_source.xml")); Tvg2Xml(String.Format("-infile \"{0}\" -outfile \"{1}\"", temporaryFileString, temporaryFileString + ".xml")); return(temporaryFileString); }
public ExportListTab(ExportList list, ProjectController projectController, ExportListController controller) { this.Build(); this.exportList = list; this.controller = controller; this.projectController = projectController; _initNodeStore(); _setupExportDestinationButton(); ExportLocationEntry.Text = ((Uri)list.ExportDirectory).OriginalString; ExportListNameEntry.Text = list.Name; ExportListNameEntry.Changed += (sender, e) => { list.Name = ExportListNameEntry.Text; }; SuffixEntry.Text = list.Suffix; SuffixEntry.Changed += (sender, e) => { list.Suffix = SuffixEntry.Text; }; PrefixEntry.Text = list.Prefix; PrefixEntry.Changed += (sender, e) => { list.Prefix = PrefixEntry.Text; }; GlobalArgsTxt.Text = list.Options; GlobalArgsTxt.Changed += (sender, e) => { list.Options = GlobalArgsTxt.Text; }; ResXEntry.Text = "" + list.ResolutionX; ResXEntry.Changed += (sender, e) => { int parseResult; bool parsable = int.TryParse(ResXEntry.Text, out parseResult); if (parsable) { list.ResolutionX = parseResult; } }; ResXEntry.FocusOutEvent += (o, args) => { ResXEntry.Text = "" + list.ResolutionX; }; ResYEntry.Text = "" + list.ResolutionY; ResYEntry.Changed += (sender, e) => { int parseResult; bool parsable = int.TryParse(ResYEntry.Text, out parseResult); if (parsable) { list.ResolutionY = parseResult; } }; ResYEntry.FocusOutEvent += (o, args) => { ResYEntry.Text = "" + list.ResolutionY; }; ListStore formatModel = new ListStore(typeof(string), typeof(ElementExportSettings.CropSetting)); foreach (object enumVal in Enum.GetValues(typeof(ExportType))) { formatModel.AppendValues(enumVal.ToString(), enumVal); } FormatCombo.Model = formatModel; FormatCombo.Active = (int)list.DefaultExportType; FormatCombo.Changed += (sender, e) => { list.DefaultExportType = (ExportType)FormatCombo.Active; }; ListStore cropModeModel = new ListStore(typeof(string)); foreach (object enumVal in Enum.GetValues(typeof(ElementExportSettings.CropSetting))) { if ((ElementExportSettings.CropSetting)enumVal == ElementExportSettings.CropSetting.Default) { continue; } cropModeModel.AppendValues(enumVal.ToString()); } CropModeCombo.Model = cropModeModel; CropModeCombo.Changed += (sender, e) => { TreeIter selected; CropModeCombo.GetActiveIter(out selected); string selectedValue = (string)cropModeModel.GetValue(selected, 0); list.CropSetting = selectedValue; }; //Set combo to current value string initialValue = exportList.CropSetting; TreeIter pos; //Sets to first entry if next function fails due to invalid value. CropModeCombo.Model.GetIterFirst(out pos); //Iterates until we find a entry which matches the inital value. CropModeCombo.Model.Foreach((model, path, iter) => { if (((string)model.GetValue(iter, 0)).Equals(initialValue)) { pos = iter; return(true); } else { return(false); } }); CropModeCombo.SetActiveIter(pos); System.Action UpdateAllArtButton = () => { LineArtButton.Active = list.ExportLineArt; ColorArtButton.Active = list.ExportColorArt; AllArtButton.Sensitive = !(LineArtButton.Active && ColorArtButton.Active); AllArtButton.Active = (LineArtButton.Active && ColorArtButton.Active); }; UpdateAllArtButton(); AllArtButton.Clicked += (sender, e) => { if (AllArtButton.Active) { LineArtButton.Active = true; ColorArtButton.Active = true; UpdateAllArtButton(); } }; LineArtButton.Clicked += (sender, e) => { list.ExportLineArt = LineArtButton.Active; UpdateAllArtButton(); }; ColorArtButton.Clicked += (sender, e) => { list.ExportColorArt = ColorArtButton.Active; UpdateAllArtButton(); }; foreach (ElementExportSettings file in list.Elements) { nodestore.AddNode(file); } controller.TvgAdded += (activeList) => { if (activeList == list) { nodestore.Clear(); foreach (ElementExportSettings file in list.Elements) { nodestore.AddNode(file); } } }; ExportSelectedButton.Clicked += (sender, e) => { ITreeNode[] selected = NodeFileList.NodeSelection.SelectedNodes; List <ElementExportSettings> tvgs = new List <ElementExportSettings> (); foreach (ITreeNode node in selected) { tvgs.Add((ElementExportSettings)node); } if (tvgs.Count > 0) { projectController.Export(list, tvgs); } }; DeleteExportListButton.Clicked += (sender, e) => { projectController.RemoveExportList(exportList); }; RemoveButton.Clicked += (sender, e) => { ITreeNode [] selected = NodeFileList.NodeSelection.SelectedNodes; List <ElementExportSettings> tvgs = new List <ElementExportSettings> (); foreach (ITreeNode node in selected) { tvgs.Add((ElementExportSettings)node); } foreach (ElementExportSettings tvg in tvgs) { controller.RemoveTvg(tvg, exportList); } //Refresh node store nodestore.Clear(); foreach (ElementExportSettings file in list.Elements) { nodestore.AddNode(file); } }; }
public void Export(ProjectController project, ExportList list, ElementExportSettings tvg, out ExportResult output) { output = new ExportResult(tvg); string commandOut, commandErr; try { output.Info("Exporting {0} from {1}...", tvg.Name, list.Name); ElementExportSettings.CropSetting CropMode = tvg.CropMode; if (CropMode == ElementExportSettings.CropSetting.Default) { //We need to identify the crop mode from the global settings. CropMode = (ElementExportSettings.CropSetting)Enum.Parse(typeof(ElementExportSettings.CropSetting), list.CropSetting); } int resX = list.ResolutionX; int resY = list.ResolutionY; ExportType exportType = list.DefaultExportType; String outputFile = String.Format("{0}/{1}{2}{3}.{4}", new Uri(project.FileDirectory, list.ExportDirectory).AbsolutePath, list.Prefix, tvg.Name, list.Suffix, exportExtensionBindings [exportType]); String stagingFile = String.Format("{0}/tmp_{1}{2}{3}.{4}", new Uri(project.FileDirectory, list.ExportDirectory).AbsolutePath, list.Prefix, tvg.Name, list.Suffix, exportExtensionBindings[exportType]); String outformat = String.Format("-outformat {0}", exportType); String outfile = String.Format("-outfile {0}", stagingFile); String resolution = String.Format("-resolution {0} {1}", resX, resY); //Clean up global arguments String [] split = list.Options.Split(' '); String args = ""; foreach (String o in split) { if (o.Length != 0) { args += " " + o; } } args += " "; //Clean up local arguments String [] localSplit = tvg.Options.Split(' '); String localArgs = ""; foreach (String o in localSplit) { if (o.Length != 0) { localArgs += " " + o; } } localArgs += " "; string inputFile = String.Format("{0}", new Uri(project.FileDirectory, tvg.FilePath).AbsolutePath //Path to project location directory ); String infile = String.Format("\"{0}\"", inputFile ); string infileForExport = infile; string disableArtCommands = string.Empty; if (list.ExportAllArt == false) { if (list.ExportColorArt == false) { disableArtCommands += "-nocolorart "; } if (list.ExportLineArt == false) { disableArtCommands += "-nolineart "; } } String commandString = String.Format("{0} {1} {6}{2}{3}{4}{5}", outformat, outfile, resolution, args, localArgs, infileForExport, disableArtCommands); output.Info("utransform {0}", commandString); RunCommand(commandString, out commandOut, out commandErr); output.Info(commandOut); output.Info(commandErr); //Find cropping information. int [] cropBox = { 0, 0, resX, resY }; float [] tvgBox; int [] rect = new int[0]; ImageCropper cropper = new ImageCropper(); if (exportType == ExportType.PNG || exportType == ExportType.PNG4 || exportType == ExportType.OMFJPEG || exportType == ExportType.PDF) { switch (CropMode) { case ElementExportSettings.CropSetting.TVG_All: tvgBox = GetTvgBounds(project, infile); rect = GetRect(tvgBox, resX, resY, output); output.Info("Cropping box:\nx1: {0}, y1: {1}\nx2: {2}, y2: {3}", rect [0], rect [1], rect [2], rect [3]); break; case ElementExportSettings.CropSetting.TVG_Underlay: string underlayOnlyTvg = MakeTemporaryTvgFile("CROP_UNDERLAY", "-clearlayers colorart,lineart,overlayart", infile, project); tvgBox = GetTvgBounds(project, underlayOnlyTvg); rect = GetRect(tvgBox, resX, resY, output); output.Info("Cropping box:\nx1: {0}, y1: {1}\nx2: {2}, y2: {3} (underlay only)", rect [0], rect [1], rect [2], rect [3]); break; case ElementExportSettings.CropSetting.TVG_Overlay: string overlayOnly = MakeTemporaryTvgFile("CROP_OVERLAY", "-clearlayers colorart,lineart,underlayart", infile, project); tvgBox = GetTvgBounds(project, overlayOnly); rect = GetRect(tvgBox, resX, resY, output); output.Info("Cropping box:\nx1: {0}, y1: {1}\nx2: {2}, y2: {3} (overlay only)", rect [0], rect [1], rect [2], rect [3]); break; default: break; } } else { output.Info("Cropping is only supported on PNG, PNG4, OMFJPEG and PDF formats."); } if (rect.Length == 4) { if (exportType != ExportType.PDF) { cropper.CropImage(stagingFile, rect[0], rect[1], rect[2], rect[3]); } else { float[] pdfBox = new float[4]; pdfBox[0] = rect[0] / (float)resX; pdfBox[1] = rect[1] / (float)resY; pdfBox[2] = rect[2] / (float)resX; pdfBox[3] = rect[3] / (float)resY; cropper.CropPdf(stagingFile, pdfBox[0], pdfBox[1], pdfBox[2], pdfBox[3]); } } System.IO.File.Delete(outputFile); System.IO.File.Move(stagingFile, outputFile); } catch (Exception e) { output.Error(e.GetType() + "\n" + e.StackTrace + "\n" + e.Message); } }
public ExportJob(ProjectController projectController, ExportList exportList, ElementExportSettings tvg) { this.projectController = projectController; this.exportList = exportList; this.tvg = tvg; }