public DocumentImage(DocumentDeserializationContext context, PropertyDictionary framedObjectDictionary) { int imageLinkIndex = framedObjectDictionary.IntegerFor("imageLinkIndex").Value; if (!context.ImageLinksByKey.ContainsKey(imageLinkIndex)) { throw new DocumentReadingException(string.Format( "The image link index \"{0}\" was not found in the image link manager dictionary.", imageLinkIndex)); } _imageLink = context.ImageLinksByKey[imageLinkIndex]; }
public string ResolveFormat(string path, PropertyDictionary properties) { string extension = Path.GetExtension(path).ToLower(); if (extension == ".png") { return path; } if (extension == ".jpg") { return path; } if (extension == ".dot") { string newFilePath = _temporaryFileManager.CreateAnonymousFilePath(".ps"); string arguments = string.Format("\"{0}\" -Tps2 \"-o{1}\"", path, newFilePath); RunUtility(_dotCommand, arguments); return newFilePath; } if (extension == ".ps") { string newFilePath = _temporaryFileManager.CreateAnonymousFilePath(".pdf"); string arguments = string.Format( "-dFirstPage=1 -dLastPage=1 -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dUseCropBox " + "-sOutputFile=\"{1}\" \"{0}\"", path, newFilePath); RunUtility(_ghostscriptCommand, arguments); return newFilePath; } if (extension == ".pdf" || extension == ".ai") { string newFilePath = _temporaryFileManager.CreateAnonymousFilePath(".png"); int resolution = properties.IntegerFor("resolution", 72); string arguments = string.Format( "-dFirstPage=1 -dLastPage=1 -sDEVICE=png16m -dBATCH -dNOPAUSE " + "-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dUseCropBox -r{2} " + "-sOutputFile=\"{1}\" \"{0}\"", path, newFilePath, resolution); RunUtility(_ghostscriptCommand, arguments); return newFilePath; } if (extension == ".tex") { string newFilePath = _temporaryFileManager.CreateAnonymousFilePath(".pdf", ".log", ".aux"); string arguments = string.Format("-output-directory=\"{0}\" -job-name=\"{1}\" \"{2}\"", Path.GetDirectoryName(newFilePath), Path.GetFileNameWithoutExtension(newFilePath), path); RunUtility(_texCommand, arguments); return newFilePath; } return null; }
public static Color ToColor(PropertyDictionary dictionary) { if (!dictionary.HasIntegerFor("red", "green", "blue")) { throw new PropertyListException("A color property dictionary is missing one or " + "both of the required fields (red, green or blue)."); } return Color.FromArgb( (byte)dictionary.IntegerFor("alpha", 255), (byte)dictionary.IntegerFor("red").Value, (byte)dictionary.IntegerFor("green").Value, (byte)dictionary.IntegerFor("blue").Value ); }
public static Size ToSize(PropertyDictionary dictionary) { if (!dictionary.HasIntegerFor("width", "height")) { throw new PropertyListException("A size property dictionary is missing one or " + "both of the required fields (width or height)."); } return new Size( dictionary.IntegerFor("width").Value, dictionary.IntegerFor("height").Value ); }
public static Rectangle ToRectangle(PropertyDictionary dictionary) { if (!dictionary.HasIntegerFor("x", "y", "width", "height")) { throw new PropertyListException("A rectangle property dictionary is missing some or " + "all of the required fields (x, y, width or height)."); } return new Rectangle( dictionary.IntegerFor("x").Value, dictionary.IntegerFor("y").Value, dictionary.IntegerFor("width").Value, dictionary.IntegerFor("height").Value ); }
public static Point ToPoint(PropertyDictionary dictionary) { if (!dictionary.HasIntegerFor("x", "y")) { throw new PropertyListException("A point property dictionary is missing one or " + "both of the required fields (x or y)."); } return new Point( dictionary.IntegerFor("x").Value, dictionary.IntegerFor("y").Value ); }