private List <PinboardFileV1.RectangleInfo> ReadRectanglesXml() { List <PinboardFileV1.RectangleInfo> list = new List <PinboardFileV1.RectangleInfo>(); bool empty = reader.IsEmptyElement; reader.ReadStartElement(rectanglesAtom); reader.MoveToContent(); if (!empty) { while (true) { if (String.ReferenceEquals(reader.Name, rectanglesAtom)) { reader.ReadEndElement(); reader.MoveToContent(); break; } PinboardFileV1.RectangleInfo rectInfo = ReadRectangleXml(); list.Add(rectInfo); } } return(list); }
private static void WriteRectangleXml(XmlWriter writer, PinboardFileV1.RectangleInfo rectInfo) { writer.WriteStartElement("Rectangle"); writer.WriteElementString("Name", rectInfo.Name.ToString()); writer.WriteElementString("X", rectInfo.X.ToString()); writer.WriteElementString("Y", rectInfo.Y.ToString()); writer.WriteElementString("Width", rectInfo.Width.ToString()); writer.WriteElementString("Height", rectInfo.Height.ToString()); WriteColorXml(writer, rectInfo.Color); writer.WriteEndElement(); }
private PinboardFileV1.RectangleInfo ReadRectangleXml() { PinboardFileV1.RectangleInfo rectInfo = new PinboardFileV1.RectangleInfo(); // Read <Rectangle> reader.ReadStartElement("Rectangle"); reader.MoveToContent(); rectInfo.Name = reader.ReadElementContentAsString("Name", ""); reader.MoveToContent(); rectInfo.X = reader.ReadElementContentAsInt("X", ""); reader.MoveToContent(); rectInfo.Y = reader.ReadElementContentAsInt("Y", ""); reader.MoveToContent(); rectInfo.Width = reader.ReadElementContentAsInt("Width", ""); reader.MoveToContent(); rectInfo.Height = reader.ReadElementContentAsInt("Height", ""); reader.MoveToContent(); rectInfo.Color = ReadColorXml(); reader.ReadEndElement(); reader.MoveToContent(); return(rectInfo); }
public void Compile() { IEnumerable <ParsedPath> svgPaths = Target.InputPaths.Where(f => f.Extension == ".svg"); ParsedPath pinboardPath = Target.InputPaths.Where(f => f.Extension == ".pinboard").First(); ParsedPath pngPath = Target.OutputPaths.Where(f => f.Extension == ".png").First(); PinboardFileV1 pinboardFile = PinboardFileCache.Load(pinboardPath); List <ImagePlacement> placements = new List <ImagePlacement>(); string[] rectangleNames = this.Rectangle.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (svgPaths.Count() != rectangleNames.Length) { throw new ContentFileException("Number of .svg files ({0}) does match number of RectangleNames ({1})" .CultureFormat(svgPaths.Count(), rectangleNames.Length)); } ImageRotation rotation; if (!Enum.TryParse(this.Rotation, out rotation)) { throw new ContentFileException("Invalid value '{0}' for given for rotation. Valid are None, Left, Right, UpsideDown".CultureFormat(this.Rotation)); } 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); } } } }
private PinboardFileV1.RectangleInfo ReadRectangleXml() { PinboardFileV1.RectangleInfo rectInfo = new PinboardFileV1.RectangleInfo(); // Read <Rectangle> reader.ReadStartElement("Rectangle"); reader.MoveToContent(); rectInfo.Name = reader.ReadElementContentAsString("Name", ""); reader.MoveToContent(); rectInfo.X = reader.ReadElementContentAsInt("X", ""); reader.MoveToContent(); rectInfo.Y = reader.ReadElementContentAsInt("Y", ""); reader.MoveToContent(); rectInfo.Width = reader.ReadElementContentAsInt("Width", ""); reader.MoveToContent(); rectInfo.Height = reader.ReadElementContentAsInt("Height", ""); reader.MoveToContent(); rectInfo.Color = ReadColorXml(); reader.ReadEndElement(); reader.MoveToContent(); return rectInfo; }
public void DuplicateSelection() { if (selectedIndex != -1) { PinboardFileV1.RectangleInfo rectInfo = new PinboardFileV1.RectangleInfo(Data.RectInfos[selectedIndex]); rectInfo.Name += "_Copy"; Data.RectInfos.Insert(selectedIndex, rectInfo); Data.RectInfos.Reverse(selectedIndex, 2); DataDirty = true; selectedIndex++; RaiseSelectionChangedEvent(); } }