Ejemplo n.º 1
0
        private void ReadEllipseAttributes(EllipseVObject vObject, SvgEllipse svg)
        {
            ReadBaseRectangleVObjectAttributes(vObject, svg);

            using (var advPath = new AdvancedDrawing.Path())
            {
                advPath.DrawEllipse(svg.Cx - svg.Rx, svg.Cy - svg.Ry, svg.Rx * 2, svg.Ry * 2);
                vObject.Path = Path.FromAdvancedPath(advPath);
            }
            vObject.Angle = svg.Transform != null?Utils.GetAngle(svg.Transform.Elements[0], svg.Transform.Elements[1]) : 0;

            vObject.BorderWidth = svg.StrokeWidth;

            string borderColor = null;
            string fillColor   = null;

            foreach (var attr in svg.CustomAttributes)
            {
                if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "fixed-border-width")
                {
                    vObject.FixedBorderWidth = attr.GetValue() == "true";
                }
                else if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "border-color")
                {
                    borderColor = attr.GetValue();
                }
                else if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "fill-color")
                {
                    fillColor = attr.GetValue();
                }
            }
            vObject.BorderColor = !string.IsNullOrEmpty(borderColor) ? _serializer.Deserialize <Color>(borderColor) : new RgbColor(svg.Stroke);
            vObject.FillColor   = !string.IsNullOrEmpty(fillColor) ? _serializer.Deserialize <Color>(fillColor) : new RgbColor(svg.Fill);
        }
Ejemplo n.º 2
0
        private static VObject CreateShapeVObject(PsdShapeFrame frame)
        {
            if (frame.Width == 0 || frame.Height == 0)
            {
                return(null);
            }

            var brush = frame.Brush as SolidBrush;
            var path  = frame.VectorMask != null?Path.FromAdvancedPath(frame.VectorMask) : null;

            if (path != null)
            {
                path.Scale(72 / frame.DpiX, 72 / frame.DpiY);
            }

            var shapeVObject = new ShapeVObject
            {
                Path        = path,
                Opacity     = frame.Opacity,
                BorderColor = frame.Pen != null ? frame.Pen.Color : ColorManagement.GetBlackColor(frame.ColorSpace),
                BorderWidth = frame.Pen != null ? frame.Pen.Width : 0,
                FillColor   = brush != null ? brush.Color : ColorManagement.GetTransparentColor(frame.ColorSpace)
            };

            return(shapeVObject);
        }
Ejemplo n.º 3
0
 public PlaceholderVObject(ContentVObject content, Math.Path path, float angle)
     : base(path, angle)
 {
     BorderWidth       = 0f;
     FillColor         = RgbColor.Transparent;
     Content           = content;
     ShowMaskedContent = true;
     IsStubContent     = false;
 }
Ejemplo n.º 4
0
 public ShapeVObject(Path path, float angle)
 {
     Path             = path;
     Angle            = angle;
     FillColor        = new RgbColor(112, 112, 112, 255);
     BorderColor      = new RgbColor(0, 0, 0, 255);
     BorderWidth      = 1F;
     FixedBorderWidth = false;
 }
Ejemplo n.º 5
0
        private void UpdateControlPoints()
        {
            if (Path == null)
            {
                return;
            }

            var bounds = Path.ToAdvancedPath().GetBounds();

            ControlPoints = new[] { new PointF(bounds.Left, bounds.Top), new PointF(bounds.Right, bounds.Bottom) };
        }
Ejemplo n.º 6
0
        public CurvedTextVObject(string text, Path path, string postScriptFontName = "ArialMT", float fontSize = 10)
            : base(text, RectangleF.Empty, postScriptFontName, fontSize)
        {
            TextMode      = TextMode.Curved;
            FitToPath     = false;
            Stretch       = false;
            FitToPathStep = 1;

            TextPath  = path;
            PathStart = 0f;
            PathEnd   = 1f;
        }
Ejemplo n.º 7
0
        private void ReadShapeAttributes(ShapeVObject vObject, SvgVoShape svg)
        {
            ReadBaseRectangleVObjectAttributes(vObject, svg);

            vObject.Path  = Path.FromPathCommands(svg.Path);
            vObject.Angle = svg.Transform != null?Utils.GetAngle(svg.Transform.Elements[0], svg.Transform.Elements[1]) : 0;

            vObject.FillColor        = svg.GetFillColor(_serializer);
            vObject.BorderColor      = svg.GetBorderColor(_serializer);
            vObject.BorderWidth      = svg.StrokeWidth;
            vObject.FixedBorderWidth = svg.FixedBorderWidth;
        }
Ejemplo n.º 8
0
        private void ReadRectangleAttributes(RectangleVObject vObject, SvgVoRectangle svg)
        {
            ReadBaseRectangleVObjectAttributes(vObject, svg);

            vObject.Path  = Path.CreateRectanglePath(svg.X, svg.Y, svg.Width, svg.Height);
            vObject.Angle = svg.Transform != null?Utils.GetAngle(svg.Transform.Elements[0], svg.Transform.Elements[1]) : 0;

            vObject.FillColor        = svg.GetFillColor(_serializer);
            vObject.BorderColor      = svg.GetBorderColor(_serializer);
            vObject.BorderWidth      = svg.StrokeWidth;
            vObject.FixedBorderWidth = svg.FixedBorderWidth;
        }
Ejemplo n.º 9
0
        protected internal override void UpdateSize()
        {
            if (ValidRect)
            {
                return;
            }

            RotatedRectangleF textRect;

            if (!TextPath.IsEmpty)
            {
                var dpi = Canvas != null ? 96 * Canvas.Zoom : 72;
                textRect = new RotatedRectangleF(MeasureText(dpi));
                textRect.Scale(72 / dpi, 72 / dpi);

                var firstPoint = TextPath.GetFirstPoint();

                // Move text rectangle to the text path's first point because GetBlackBox returns an empty rectangle (in location 0:0) when text is empty
                if (textRect.IsEmpty)
                {
                    textRect.CenterX = firstPoint.X;
                    textRect.CenterY = firstPoint.Y;
                }

                textRect.RotateAt(Angle, firstPoint);
            }
            else
            {
                textRect = new RotatedRectangleF();
            }

            Path = Path.CreateRectanglePath(textRect.ToRectangleF());
            Transform.Clear(keepAngle: true);
            ActualAngle = Transform.Angle;
            ValidRect   = true;
        }
Ejemplo n.º 10
0
 public ShapeVObject(Path path)
     : this(path, 0)
 {
 }
Ejemplo n.º 11
0
        private static VObject CreateTextVObject(
            PsdTextFrame frame,
            bool forceRichText = false,
            bool getRichTextForBoundedTextOnly = false)
        {
            BaseTextVObject textVObject;

            TextAlignment aligment;

            switch (frame.Justification)
            {
            case TextJustification.Left:
                aligment = TextAlignment.Left;
                break;

            case TextJustification.LastLeft:
                aligment = TextAlignment.LastLeft;
                break;

            case TextJustification.Right:
                aligment = TextAlignment.Right;
                break;

            case TextJustification.LastRight:
                aligment = TextAlignment.LastRight;
                break;

            case TextJustification.All:
                aligment = TextAlignment.Justify;
                break;

            case TextJustification.Center:
                aligment = TextAlignment.Center;
                break;

            case TextJustification.LastCenter:
                aligment = TextAlignment.LastCenter;
                break;

            default:
                aligment = TextAlignment.Left;
                break;
            }

            var transform = GetTransformFromPsdMatrix(frame.Transform);

            // Curved text
            if (frame.Path != null)
            {
                // Get the first point of transformed path and move raw path to this point.
                var path = Path.FromAdvancedPath(frame.Raw.Path);
                if (!path.IsEmpty)
                {
                    path.Scale(72 / frame.DpiX, 72 / frame.DpiY);
                    path.Scale(transform.ScaleX, transform.ScaleY);

                    var transformedPath = Path.FromAdvancedPath(frame.Path);
                    transformedPath.Scale(72 / frame.DpiX, 72 / frame.DpiY);
                    var transformedFirstPoint = transformedPath.GetFirstPoint();

                    var firstPoint = path.GetFirstPoint();
                    path.Translate(transformedFirstPoint.X - firstPoint.X, transformedFirstPoint.Y - firstPoint.Y);
                }

                textVObject = new CurvedTextVObject {
                    TextPath = path, FitToPath = true, Angle = transform.Angle, PathStart = frame.PathStartPoint, PathEnd = frame.PathEndPoint
                };
            }
            else if (Utils.EqualsOfFloatNumbers(frame.TextBox.Width, 0) && Utils.EqualsOfFloatNumbers(frame.TextBox.Height, 0))
            {
                var baselineLocation = new PointF(
                    Common.ConvertPixelsToPoints(frame.DpiX, frame.TextBox.X),
                    Common.ConvertPixelsToPoints(frame.DpiY, frame.TextBox.Y));

                textVObject = new PlainTextVObject {
                    BaselineLocation = baselineLocation, Angle = transform.Angle, IsVertical = frame.IsVertical
                };
            }
            else
            {
                var textBoxShift = frame.IsVertical ? frame.Raw.TextBox.Width * (float)transform.ScaleX : 0;

                var rectangle = new RotatedRectangleF(new RectangleF(
                                                          Common.ConvertPixelsToPoints(frame.DpiX, frame.TextBox.X - textBoxShift),
                                                          Common.ConvertPixelsToPoints(frame.DpiY, frame.TextBox.Y),
                                                          Common.ConvertPixelsToPoints(frame.DpiX, frame.Raw.TextBox.Width * (float)transform.ScaleX),
                                                          Common.ConvertPixelsToPoints(frame.DpiY, frame.Raw.TextBox.Height * (float)transform.ScaleY)
                                                          ));

                rectangle.RotateAt(transform.Angle, rectangle.Location);

                textVObject = new BoundedTextVObject {
                    Rectangle = rectangle, IsVertical = frame.IsVertical
                };
            }

            var boundedText = textVObject as BoundedTextVObject;

            // Empty text is allowed in boundedTextVObject only
            if (boundedText == null && string.IsNullOrEmpty(frame.Text))
            {
                return(null);
            }

            textVObject.Alignment       = aligment;
            textVObject.Tracking        = RoundFloat(frame.Tracking, 1);
            textVObject.Leading         = RoundFloat(frame.Leading, 1);
            textVObject.VerticalScale   = frame.VerticalScale * (float)transform.ScaleY;
            textVObject.HorizontalScale = frame.HorizontalScale * (float)transform.ScaleX;
            textVObject.TextColor       = frame.Color;
            textVObject.Opacity         = frame.Opacity;

            textVObject.Font.Size           = RoundFloat(frame.Raw.FontSize, 2);
            textVObject.Font.PostScriptName = frame.FontName;

            if (textVObject is CurvedTextVObject)
            {
                ((CurvedTextVObject)textVObject).OriginalFontSize = textVObject.Font.Size;
            }

            var nonDefaultParagraphs = frame.Paragraphs.Count > 1 && frame.Paragraphs.Any(p => !Utils.EqualsOfFloatNumbers(0, p.FirstLineIndent) ||
                                                                                          !Utils.EqualsOfFloatNumbers(0, p.SpaceAfterParagraph) || !Utils.EqualsOfFloatNumbers(0, p.SpaceBeforeParagraph)) ||
                                       frame.Paragraphs.Count == 1 && frame.Paragraphs.First().FirstLineIndent > 0;

            if ((boundedText == null && !getRichTextForBoundedTextOnly && (forceRichText || frame.FormattedText.Count > 1)) ||
                (boundedText != null && (forceRichText || frame.FormattedText.Count > 1 || nonDefaultParagraphs)))
            {
                textVObject.Text       = GetRichText(frame, textVObject);
                textVObject.IsRichText = true;
            }
            else
            {
                textVObject.Text = Common.XmlEscape(NormalizeString(frame.Text ?? "", frame.Caps));

                textVObject.Font.FauxBold   = frame.FauxBold;
                textVObject.Font.FauxItalic = frame.FauxItalic;
                textVObject.Underline       = frame.Underline;

                if (boundedText != null)
                {
                    boundedText.ParagraphSettings = new ParagraphSettings
                    {
                        FirstLineIndent = RoundFloat(frame.Paragraph.FirstLineIndent, 1),
                        SpaceAfter      = RoundFloat(frame.Paragraph.SpaceAfterParagraph, 1),
                        SpaceBefore     = RoundFloat(frame.Paragraph.SpaceBeforeParagraph, 1)
                    };
                }

                textVObject.IsRichText = false;
            }

            return(textVObject);
        }