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); }
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); }
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); }