private PainterEventArgs(FilesConfigInfo fileConfigInfo, string fileName, string densityKey, Size? documentSize, Exception exception) { FileConfigInfo = fileConfigInfo; FileName = fileName; DensityKey = densityKey; DocumentSize = documentSize; Exception = exception; }
/// <summary> /// Распарсить размер /// </summary> /// <param name="widthStr">Строковое представление ширины</param> /// <param name="heightStr">Строковое представление высоты</param> /// <returns>Размер</returns> private Size? ParseSizeStr(string widthStr, string heightStr) { Size? resultSize = null; int width; int height; if (int.TryParse(widthStr, out width) && int.TryParse(heightStr, out height)) { resultSize = new Size(width, height); } return resultSize; }
/// <summary> /// Разукрасить и сохраниь /// </summary> /// <param name="outputDirectoryPath">Выходная директория</param> /// <param name="fileConfigInfo">конфигурационная информация о файле</param> private void PaintAndSaveFile(String outputDirectoryPath, FilesConfigInfo fileConfigInfo) { var size = fileConfigInfo.ConfigInfo.Size; var sourceColor = fileConfigInfo.ConfigInfo.SourceColor; var color = fileConfigInfo.ConfigInfo.Color; var unitType = fileConfigInfo.ConfigInfo.SizeUnitType; try { var svgDocument = SvgDocument.Open(fileConfigInfo.FileInfo.FullName); ReColorDocument(ref svgDocument, sourceColor, color); if (unitType.Equals(SizeUnitType.Dp)) { foreach (var densityInfo in AndroidDensities.DensityCollection) { ReSizeDocument(ref svgDocument, size, densityInfo.Density); var documentSize = new Size(svgDocument.Width, svgDocument.Height); var filePath = CreateDirectoryAndFilePath(outputDirectoryPath, fileConfigInfo, densityInfo); SaveDocumentAsPngFile(ref svgDocument, filePath, ImageFormat.Png); RaiseFilePainted(fileConfigInfo, Path.GetFileName(filePath), densityInfo.Key, documentSize); } } else { foreach (var densityInfo in AndroidDensities.DensityCollection) { ReSizeDocument(ref svgDocument, size, AndroidDensities.mdpi.Density); var documentSize = new Size(svgDocument.Width, svgDocument.Height); var filePath = CreateDirectoryAndFilePath(outputDirectoryPath, fileConfigInfo, densityInfo); SaveDocumentAsPngFile(ref svgDocument, filePath, ImageFormat.Png); RaiseFilePainted(fileConfigInfo, Path.GetFileName(filePath), densityInfo.Key, documentSize); } } } catch (Exception ex) { RaiseFilePainted(ex); } }
public PainterEventArgs(FilesConfigInfo fileConfigInfo, string fileName, string densityKey, Size documentSize) : this(fileConfigInfo, fileName, densityKey, documentSize, null) { }
/// <summary> /// Изменить размер документа /// </summary> /// <param name="document">Документ</param> /// <param name="size">Размер</param> /// <param name="density">Плотность</param> private void ReSizeDocument(ref SvgDocument document, Size? size, float density) { if (size.HasValue) { float pxWidth = size.Value.Width * density + 0.5f; float pxHeight = size.Value.Height * density + 0.5f; float documentScale; if (document.Height >= document.Width) { documentScale = pxHeight / document.Height; } else { documentScale = pxWidth / document.Width; } document.Width = (int) (document.Width*documentScale); document.Height = (int) (document.Height*documentScale); } }
private void RaiseFilePainted(FilesConfigInfo fileConfigInfo, string fileName, string densityKey, Size documentSize) { RaiseFilePainted(new PainterEventArgs(fileConfigInfo, fileName, densityKey, documentSize)); }