/// <summary> /// Opens the json. /// </summary> /// <param name="objects">The objects.</param> public void OpenJson(List <JsonObject> objects) { List <KeyValuePair <int, Control> > ctrls = new List <KeyValuePair <int, Control> >(); foreach (JsonObject obj in objects) { if (obj is Config) { Config config = obj as Config; Enum.TryParse <Paper>(config.Paper, out Paper paper); Enum.TryParse <ColorType>(config.Color, out ColorType color); Enum.TryParse <Sticky>(config.Sticky, out Sticky sticky); (this.Parent as NemonicForm).ChangePaper(paper); (this.Parent as NemonicForm).ChangeColor(color); this.ChangeSticky(paper, sticky); } else if (obj is TemplateLayer) { TemplateLayer layer = obj as TemplateLayer; this.ChangeTemplate(NemonicApp.ByteToImage(layer.image)); } else if (obj is TransparentImage.ImageLayer) { TransparentImage.ImageLayer layer = obj as TransparentImage.ImageLayer; TransparentImage imageBox = new TransparentImage() { Location = new Point(layer.x, layer.y), Image = NemonicApp.ByteToImage(layer.image), Size = new Size(layer.width, layer.height) }; ctrls.Add(new KeyValuePair <int, Control>(layer.priority, imageBox)); } else if (obj is TransparentRichText.RichTextLayer) { TransparentRichText.RichTextLayer layer = obj as TransparentRichText.RichTextLayer; this.Layer_TextField.Font = layer.font; this.Layer_TextField.SelectAll(); this.Layer_TextField.SelectionAlignment = layer.align; this.Layer_TextField.DeselectAll(); this.Layer_TextField.Text = layer.text; } } ctrls.Sort(delegate(KeyValuePair <int, Control> A, KeyValuePair <int, Control> B) { return(B.Key.CompareTo(A.Key)); }); foreach (KeyValuePair <int, Control> element in ctrls) { this.AddCtrl(element.Value); } }
//실제로 페이지에 정보를 입력하는 과정 protected override void OnPrintPage(PrintPageEventArgs e) { base.OnPrintPage(e); e.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; RectangleF printArea = this.DecidePrintableArea(); this.DecideGraphicsAngle(e.Graphics, printArea); //그리기 시작 if (IsScreenShot) { e.Graphics.DrawImage(this.LayerCtrl.TakeScreenShot(), printArea); } else { TransparentRichText textLayer = null; for (LinkedListNode <Control> node = this.LayerCtrl.CtrlList.First; node != this.LayerCtrl.CtrlList.Last.Next; node = node.Next) { if (node.Value is TransparentRichText) { textLayer = node.Value as TransparentRichText; } else if (node.Value is PictureBox) { PictureBox layer = node.Value as PictureBox; if (layer.Image != null) { e.Graphics.DrawImage(layer.Image, printArea); } } else if (node.Value is TransparentImage && !(node.Value is StickyCtrl)) { TransparentImage layer = node.Value as TransparentImage; RectangleF area = new RectangleF() { Location = new PointF(ChangePixelToUnit(layer.Location.X - LayerCtrl.Padding.All), ChangePixelToUnit(layer.Location.Y - LayerCtrl.Padding.All)), Size = new SizeF(ChangePixelToUnit(layer.Size.Width), ChangePixelToUnit(layer.Height)) }; e.Graphics.DrawImage(layer.Image, area); } } if (textLayer != null && !String.IsNullOrEmpty(textLayer.Text)) { string text = textLayer.Text; text = text.Replace("\r", Environment.NewLine); //TODO: 폰트크기에 따라, string을 그리는 방식이 달라질 수 있다. 스크린 샷을 찍는 방식은 글이 깨져서 안된다. /* * RectangleF displayRectangle = * new RectangleF( * new PointF(ChangePixelToUnit(0), ChangePixelToUnit(0)), * new SizeF(printArea.Width + ChangePixelToUnit(0), printArea.Height + ChangePixelToUnit(0)) * ); */ //WordWrap이 반영되도록 설정하는 부분! StringFormat format = new StringFormat(StringFormatFlags.DisplayFormatControl) { //Horizontal Align Alignment = StringAlignment.Near, //Vertical Align LineAlignment = StringAlignment.Near, }; //e.Graphics.DrawString(textLayer.Text, font, Brushes.Black, printArea, format); e.Graphics.DrawString(text, textLayer.Font /*this.CalculateFont(288, textLayer.Font)*/, Brushes.Black, printArea); //Debug 코드 /* * SizeF textSize = e.Graphics.MeasureString(textLayer.Text, textLayer.Font, displayRectangle.Size, format); * * //SizeF textSize = this.MeasureString(textLayer.Text, textLayer.Font); * * textSize.Width = ChangePixelToUnit(textSize.Width); * textSize.Height = ChangePixelToUnit(textSize.Height); * * e.Graphics.DrawRectangle(Pens.Black, displayRectangle.Location.X, displayRectangle.Location.Y, textSize.Width, textSize.Height); */ } } //Debug 코드 #if DEBUG e.Graphics.DrawRectangle(Pens.Black, printArea.X, printArea.Y, printArea.Width, printArea.Height); #endif }
/// <summary> /// Adds the image. /// </summary> /// <param name="image">The image.</param> /// <param name="path">The path.</param> /// <param name="location">The location.</param> public void AddImage(Bitmap image, string path = null, Point location = new Point()) { TransparentImage imageBox = new TransparentImage(); int maxWidth = this.Width - (this.Padding.All * 2); int maxHeight = this.Height - (this.Padding.All * 2); int imageWidth = image.Width / 2; int imageHeight = image.Height / 2; //사이즈 결정 if (imageWidth > maxWidth && imageHeight > maxHeight) { if (imageWidth > imageHeight) { int calcHeight = (int)Math.Round(((double)imageHeight / imageWidth) * maxWidth); imageBox.Size = new Size(maxWidth, calcHeight); } else { int calcWidth = (int)Math.Round(((double)imageWidth / imageHeight) * maxHeight); imageBox.Size = new Size(calcWidth, maxHeight); } } else if (imageWidth > maxWidth && imageHeight < maxHeight) { int calcHeight = (int)Math.Round(((double)imageHeight / maxHeight) * maxHeight); imageBox.Size = new Size(maxWidth, calcHeight); } else if (imageWidth < maxWidth && imageHeight > maxHeight) { int calcWidth = (int)Math.Round(((double)imageWidth / maxWidth) * maxWidth); imageBox.Size = new Size(calcWidth, maxHeight); } else { imageBox.Size = new Size(imageWidth, imageHeight); } //위치를 고정된 곳으로 잡아 달라는 요청에 따른 코드 location = new Point(this.Padding.All, this.Padding.All); /* * //위치결정 * if (location.X + imageWidth > maxWidth && location.Y + imageHeight > maxHeight) * { * location.X -= (location.X + imageWidth - maxWidth); * location.Y -= (location.Y + imageHeight - maxHeight); * } * else if (location.X + imageWidth > maxWidth) * { * location.X -= (location.X + imageWidth - maxWidth); * } * else if (location.Y + imageHeight > maxHeight) * { * location.Y -= (location.Y + imageHeight - maxHeight); * } * * //최솟값 * if (location.X < this.Padding.All) * { * location.X = this.Padding.All; * } * * if(location.Y < this.Padding.All) * { * location.Y = this.Padding.All; * } */ //결정사항 반영 if (path != null) { imageBox.Name = Path.GetFileName(path); } imageBox.Image = image; imageBox.Location = location; this.AddCtrl(imageBox); this.Layer_TextField.Enabled = false; }