private void btnPageSelect_Click(object sender, EventArgs e) { GUIElements.PageOverview po = new GUIElements.PageOverview(doc, this, inkControl1.Page); po.ItemSelected += new EventHandler <int>(delegate(object selSender, int selInd) { if (selInd < doc.Pages.Count) { inkControl1.LoadPage(doc.Pages[selInd]); } else if (selInd == doc.Pages.Count) { KPage page = new KPage(doc); var formats = PageFormat.GetFormats(); if (formats.ContainsKey(doc.DefaultFormat)) { page.Format = formats[doc.DefaultFormat]; } else { page.Format = PageFormat.A4; } page.Background = new Backgrounds.BackgroundQuadPaper5mm(); doc.Pages.Add(page); inkControl1.LoadPage(page); } }); OpenDialog(po); }
public KPage(KDocument document) { var formats = PageFormat.GetFormats(); if (formats.ContainsKey(Configuration.DefaultFormat)) { Format = formats[Configuration.DefaultFormat]; } else { Format = PageFormat.A4; } lines = new List <Line>(); CreationTime = DateTime.Now; this.document = document; }
public void LoadFromString(string txt, MessageLog log) { lock (this) { StringReader input = new StringReader(txt); Line line = null; lines.Clear(); using (XmlReader xml = XmlReader.Create(input)) { while (xml.Read()) { if (xml.NodeType == XmlNodeType.Element) { if (xml.Name == "Line") { string typeN = xml.GetAttribute("type"); string param = xml.GetAttribute("params"); string color = null; try { color = xml.GetAttribute("color"); } catch (Exception) { } Type t = Assembly.GetCallingAssembly().GetType(typeN); line = t.GetConstructor(new Type[0]).Invoke(new object[0]) as Line; if (line != null) { if (line is Forms.TransformableForm) { try { var strMat = xml.GetAttribute("matrix"); ((Forms.TransformableForm)line).Transformation = Matrix3x3.LoadFromString(strMat); } catch (Exception) { } } line.FromParamString(param); line.CalcSpline(); line.CalculateBounds(); } if (color == null) { line.Brush = PBrush.CreateSolid(Color.Black); } else { line.Brush = PBrush.CreateSolid(ColorTranslator.FromHtml(color)); } lines.Add(line); } else if (xml.Name == "Brush") { PBrush brush = PBrush.FromStrings( xml.GetAttribute("type"), xml.GetAttribute("color"), xml.GetAttribute("nums")); if (line != null) { line.Brush = brush; } } else if (xml.Name == "Format") { float w = 1; float h = 1; float border = 15; Util.TrySToF(xml.GetAttribute("w"), out w); Util.TrySToF(xml.GetAttribute("h"), out h); Util.TrySToF(xml.GetAttribute("border"), out border); Border = border; Format = new PageFormat(w, h); string backgroundName = xml.GetAttribute("background"); Type backgroundType = Type.GetType(backgroundName); Backgrounds.Background bgr; if (backgroundType == null) { bgr = null; if (backgroundName != "null") { log?.Add(MessageType.WARN, "Background '{0}'", backgroundName); } } else { bgr = (Backgrounds.Background)backgroundType .GetConstructor(new Type[0]) .Invoke(new object[0]); } Background = bgr; } else if (xml.Name == "CreationTime") { bool show = xml.GetAttribute("show") == "true"; long time = 0; long.TryParse(xml.GetAttribute("date"), out time); ShowDate = show; CreationTime = DateTime.FromFileTime(time); } else if (xml.Name == "Name") { Name = xml.GetAttribute("value"); } else if (xml.Name == "Filter") { string filterName = xml.ReadElementContentAsString(); if (Enum.TryParse <ColorFilter>(filterName, out ColorFilter filter)) { Filter = filter; } else { log?.Add(0, MessageType.WARN, "Cant parse the ColorFilter '{0}'", filterName); } } } else if (xml.NodeType == XmlNodeType.EndElement) { if (xml.Name == "Line") { line = null; } } } } } }