public void Compile() { IEnumerable <ParsedPath> svgPaths = Target.InputFiles.Where(f => f.Extension == ".svg"); ParsedPath pdfPath = Target.OutputFiles.Where(f => f.Extension == ".pdf").First(); ParsedPath xnbPath = Target.OutputFiles.Where(f => f.Extension == ".xnb").First(); // TODO: Ensure that pdf and xnb have the same root directories (and volumes) int numRows; int numCols; this.Target.Properties.GetOptionalValue("Rows", out numRows, 1); this.Target.Properties.GetOptionalValue("Columns", out numCols, 1); ParsedPath nUpSvgPath = null; try { if (svgPaths.Count() > 1) { nUpSvgPath = pdfPath.WithFileAndExtension( String.Format("{0}_{1}x{2}.svg", pdfPath.File, numRows, numCols)); CreateNupSvg(svgPaths, nUpSvgPath, numRows, numCols); } if (!Directory.Exists(pdfPath.VolumeAndDirectory)) { Directory.CreateDirectory(pdfPath.VolumeAndDirectory); } ImageTools.SvgToPdfWithInkscape(nUpSvgPath == null ? svgPaths.First() : nUpSvgPath, pdfPath); } finally { if (nUpSvgPath != null) { File.Delete(nUpSvgPath); } } List <string> pdfInfo = new List <string>(); pdfInfo.Add(this.Target.Properties.GetRequiredValue("Pinboard")); pdfInfo.Add(this.Target.Properties.GetRequiredValue("Rectangle")); pdfInfo.Add(numRows.ToString()); pdfInfo.Add(numCols.ToString()); if (!Directory.Exists(xnbPath.VolumeAndDirectory)) { Directory.CreateDirectory(xnbPath.VolumeAndDirectory); } XnbFileWriterV5.WriteFile(pdfInfo, xnbPath); }
private ParsedPath GetSlnForProject(ParsedPath csprojPath) { var files = DirectoryUtility.GetFiles(csprojPath.WithFileAndExtension("*.sln"), SearchScope.RecurseParentDirectories); if (files.Count == 0) { throw new PopperToolExeception("Cannot find .sln for project '{0}'".InvariantFormat(csprojPath)); } return(files[0]); }
public void Compile() { IEnumerable <ParsedPath> svgPaths = Target.InputPaths.Where(f => f.Extension == ".svg"); ParsedPath pdfPath = Target.OutputPaths.Where(f => f.Extension == ".pdf").First(); ParsedPath pngdefPath = Target.OutputPaths.Where(f => f.Extension == ".pngdef").First(); ParsedPath nUpSvgPath = null; try { if (svgPaths.Count() > 1) { nUpSvgPath = pdfPath.WithFileAndExtension( String.Format("{0}_{1}x{2}.svg", pdfPath.File, Rows, Columns)); CreateNupSvg(svgPaths, nUpSvgPath, Rows, Columns); } if (!Directory.Exists(pdfPath.VolumeAndDirectory)) { Directory.CreateDirectory(pdfPath.VolumeAndDirectory); } ImageTools.SvgToPdfWithInkscape(nUpSvgPath == null ? svgPaths.First() : nUpSvgPath, pdfPath); } finally { if (nUpSvgPath != null) { File.Delete(nUpSvgPath); } } List <string> pdfInfo = new List <string>(); pdfInfo.Add(this.Pinboard); pdfInfo.Add(this.Rectangle); pdfInfo.Add(Rows.ToString()); pdfInfo.Add(Columns.ToString()); if (!Directory.Exists(pngdefPath.VolumeAndDirectory)) { Directory.CreateDirectory(pngdefPath.VolumeAndDirectory); } // Write the output file throw new NotImplementedException(); }
private ParsedPath FindNugetLibrary(ParsedPath slnPath, ParsedPath csprojPath) { var projectName = ProjectName; var packagesConfigPath = csprojPath.WithFileAndExtension("packages.config"); if (!File.Exists(packagesConfigPath)) { throw new PopperToolExeception("Cannot find '{0}'".InvariantFormat(packagesConfigPath)); } var doc = XDocument.Parse(File.ReadAllText(packagesConfigPath)); var element = doc.Root.Elements("package").Where(e => e.Attribute("id").Value == projectName).FirstOrDefault(); if (element == null) { throw new PopperToolExeception("Cannot find project '{0}' in '{1}'".InvariantFormat(projectName, packagesConfigPath)); } var s = "packages/{0}.{1}/lib/{2}/{0}.dll".InvariantFormat( projectName, element.Attribute("version").Value, element.Attribute("targetFramework").Value); return(slnPath.VolumeAndDirectory.Append(s, PathType.File)); }
public void Compile() { IEnumerable <ParsedPath> svgFileNames = Target.InputFiles.Where(f => f.Extension == ".svg"); ParsedPath pinboardFileName = Target.InputFiles.Where(f => f.Extension == ".pinboard").First(); ParsedPath xnbFileName = Target.OutputFiles.Where(f => f.Extension == ".xnb").First(); PinboardFileV1 pinboardFile = PinboardFileCache.Load(pinboardFileName); List <ImagePlacement> placements = new List <ImagePlacement>(); string rectangleName = this.Target.Properties.GetRequiredValue("Rectangle"); PinboardFileV1.RectangleInfo rectInfo = pinboardFile.GetRectangleInfoByName(rectangleName); if (rectInfo == null) { throw new ContentFileException("Rectangle {0} not found in pinboard file {1}".CultureFormat(rectangleName, pinboardFileName)); } string converterName = Target.Properties.GetOptionalValue("Converter", "Inkscape").ToLower(); if (converterName != "inkscape" && converterName != "rsvg") { throw new ContentFileException("Unknown SVG converter '{0}'".CultureFormat(converterName)); } ParsedPath combinedPngPathName = xnbFileName.WithExtension(".png"); try { int row = 0; foreach (var svgFileName in svgFileNames) { int col = 0; if (rectInfo == null) { throw new InvalidOperationException( "Rectangle '{0}' not found in pinboard '{1}'".CultureFormat(rectangleName, pinboardFileName)); } // TODO-johnls: This should probably go in an intermediate file directory ParsedPath pngFile = xnbFileName.WithFileAndExtension(String.Format("{0}_{1}_{2}.png", svgFileName.File, row, col)); placements.Add(new ImagePlacement(pngFile, new Rectangle(col * rectInfo.Width, row * rectInfo.Height, rectInfo.Width, rectInfo.Height))); switch (converterName) { default: case "rsvg": ImageTools.SvgToPngWithRSvg(svgFileName, pngFile, rectInfo.Width, rectInfo.Height); break; case "inkscape": ImageTools.SvgToPngWithInkscape(svgFileName, pngFile, rectInfo.Width, rectInfo.Height); break; } } ImageTools.CombinePngs(placements, combinedPngPathName); Texture2DContent textureContent; ImageTools.CompressPngToTexture2DContent( combinedPngPathName, this.Target.Properties.GetOptionalValue("CompressionType", "None"), out textureContent); XnbFileWriterV5.WriteFile(textureContent, xnbFileName); } finally { foreach (var placement in placements) { if (File.Exists(placement.ImageFile)) { File.Delete(placement.ImageFile); } } if (File.Exists(combinedPngPathName)) { File.Delete(combinedPngPathName); } } }
public void Compile() { IEnumerable <ParsedPath> svgPaths = Target.InputFiles.Where(f => f.Extension == ".svg"); ParsedPath pinboardPath = Target.InputFiles.Where(f => f.Extension == ".pinboard").First(); ParsedPath pngPath = Target.OutputFiles.Where(f => f.Extension == ".png").First(); PinboardFileV1 pinboardFile = PinboardFileCache.Load(pinboardPath); List <ImagePlacement> placements = new List <ImagePlacement>(); string[] rectangleNames; Target.Properties.GetRequiredValue("Rectangles", out rectangleNames); if (svgPaths.Count() != rectangleNames.Length) { throw new ContentFileException("Number of .svg files ({0}) does match number of RectangleNames ({1})" .CultureFormat(svgPaths.Count(), rectangleNames.Length)); } string s = Target.Properties.GetOptionalValue("Rotation", "None"); ImageRotation rotation; if (!Enum.TryParse(s, out rotation)) { throw new ContentFileException("Invalid value '{0}' for given for rotation. Valid are None, Left, Right, UpsideDown".CultureFormat(s)); } int i = 0; try { if (!Directory.Exists(pngPath.VolumeAndDirectory)) { Directory.CreateDirectory(pngPath.VolumeAndDirectory); } foreach (var svgPath in svgPaths) { PinboardFileV1.RectangleInfo rectInfo = pinboardFile.GetRectangleInfoByName(rectangleNames[i]); ParsedPath tempPngPath = pngPath.WithFileAndExtension(String.Format("{0}_{1}.png", pngPath.File, i)); if (rectInfo == null) { throw new ContentFileException("Rectangle '{0}' not found in pinboard file '{1}'" .CultureFormat(rectangleNames[i], pinboardFile)); } ImageTools.SvgToPngWithInkscape(svgPath, tempPngPath, rectInfo.Width, rectInfo.Height); placements.Add(new ImagePlacement( tempPngPath, new Cairo.Rectangle(rectInfo.X, rectInfo.Y, rectInfo.Width, rectInfo.Height))); i++; } ImageTools.CombinePngs(placements, pngPath); ImageTools.RotatePng(pngPath, rotation); } finally { foreach (var placement in placements) { if (File.Exists(placement.ImageFile)) { File.Delete(placement.ImageFile); } } } }