示例#1
0
        public bool ReadRenderCommand(XElement element, ComponentDescription description, out IXmlRenderCommand command)
        {
            var rectCommand = new XmlRectCommand();

            command = rectCommand;

            if (element.Attribute("thickness") != null)
            {
                rectCommand.StrokeThickness = double.Parse(element.Attribute("thickness").Value);
            }

            var fill = element.Attribute("fill");

            if (fill != null && fill.Value.ToLowerInvariant() != "false")
            {
                rectCommand.Fill = true;
            }

            if (element.Attribute("location") != null)
            {
                if (!componentPointParser.TryParse(element.Attribute("location"), out var location))
                {
                    return(false);
                }
                rectCommand.Location = location;
            }
            else
            {
                var x = element.Attribute("x");
                var y = element.Attribute("y");
                if (!componentPointParser.TryParse(x, y, out var location))
                {
                    return(false);
                }
                rectCommand.Location = location;
            }

            rectCommand.Width  = double.Parse(element.Attribute("width").Value);
            rectCommand.Height = double.Parse(element.Attribute("height").Value);

            return(true);
        }
示例#2
0
        public bool ReadRenderCommand(XElement element, ComponentDescription description, out IXmlRenderCommand command)
        {
            var textCommand = new XmlRenderTextWithDefinitions();

            command = textCommand;

            if (!ReadTextLocation(element, textCommand))
            {
                return(false);
            }

            if (!TryParseTextAlignment(element.Attribute("align"), out ConditionalCollection <TextAlignment> alignment))
            {
                return(false);
            }
            textCommand.Alignment = alignment;

            var tRotation = "0";

            if (description.Metadata.FormatVersion >= TextRotationMinFormatVersion && element.Attribute("rotate") != null)
            {
                tRotation = element.Attribute("rotate").Value;
            }

            var rotation = TextRotation.None;

            switch (tRotation)
            {
            case "0":
                rotation = TextRotation.None;
                break;

            case "90":
                rotation = TextRotation.Rotate90;
                break;

            case "180":
                rotation = TextRotation.Rotate180;
                break;

            case "270":
                rotation = TextRotation.Rotate270;
                break;

            default:
                logger.LogError(element.Attribute("rotate"), $"Invalid value for text rotation: '{tRotation}'");
                break;
            }
            textCommand.Rotation = new ConditionalCollection <TextRotation>
            {
                new Conditional <TextRotation>(rotation, ConditionTree.Empty),
            };

            double size = 11d;

            if (element.Attribute("size") != null)
            {
                if (element.Attribute("size").Value.ToLowerInvariant() == "large")
                {
                    size = 12d;
                }
            }

            var textValueNode = element.Element(XmlLoader.ComponentNamespace + "value");

            if (textValueNode != null)
            {
                foreach (var spanNode in textValueNode.Elements())
                {
                    string nodeValue  = spanNode.Value;
                    var    formatting = TextRunFormatting.Normal;

                    if (spanNode.Name.LocalName == "sub")
                    {
                        formatting = TextRunFormatting.Subscript;
                    }
                    else if (spanNode.Name.LocalName == "sup")
                    {
                        formatting = TextRunFormatting.Superscript;
                    }
                    else if (spanNode.Name.LocalName != "span")
                    {
                        logger.LogWarning(spanNode, $"Unknown node '{spanNode.Name}' will be treated as <span>");
                    }

                    var textRun = new TextRun(nodeValue, formatting);

                    if (!ValidateText(element, description, textRun.Text))
                    {
                        return(false);
                    }

                    textCommand.TextRuns.Add(textRun);
                }
            }
            else if (element.GetAttribute("value", logger, out var value))
            {
                var textRun = new TextRun(value.Value, new TextRunFormatting(TextRunFormattingType.Normal, size));

                if (!ValidateText(value, description, textRun.Text))
                {
                    return(false);
                }

                textCommand.TextRuns.Add(textRun);
            }
            else
            {
                return(false);
            }

            return(true);
        }
示例#3
0
        public bool ReadRenderCommand(XElement element, ComponentDescription description, out IXmlRenderCommand command)
        {
            var textCommand = new XmlRenderText();

            command = textCommand;

            if (!ReadTextLocation(element, textCommand))
            {
                return(false);
            }

            string tAlignment = "TopLeft";

            if (element.Attribute("align") != null)
            {
                tAlignment = element.Attribute("align").Value;
            }

            if (!Enum.TryParse(tAlignment, out TextAlignment alignment))
            {
                logger.LogError(element.Attribute("align"), $"Invalid value for text alignment: '{tAlignment}'");
                return(false);
            }
            textCommand.Alignment = alignment;

            var tRotation = "0";

            if (description.Metadata.FormatVersion >= TextRotationMinFormatVersion && element.Attribute("rotate") != null)
            {
                tRotation = element.Attribute("rotate").Value;
            }

            var rotation = TextRotation.None;

            switch (tRotation)
            {
            case "0":
                rotation = TextRotation.None;
                break;

            case "90":
                rotation = TextRotation.Rotate90;
                break;

            case "180":
                rotation = TextRotation.Rotate180;
                break;

            case "270":
                rotation = TextRotation.Rotate270;
                break;

            default:
                logger.LogError(element.Attribute("rotate"), $"Invalid value for text rotation: '{tRotation}'");
                break;
            }
            textCommand.Rotation = rotation;

            double size = 11d;

            if (element.Attribute("size") != null)
            {
                switch (element.Attribute("size").Value.ToLowerInvariant())
                {
                case "large":
                    size = 12.0;
                    break;

                case "sm":
                case "small":
                    size = 10.0;
                    break;

                case "xs":
                    size = 9.0;
                    break;

                case "xxs":
                    size = 8.0;
                    break;

                default:
                    logger.LogWarning(element.Attribute("size"), $"Invalid value for size attribute: '{element.Attribute("size").Value}'");
                    break;
                }
            }

            var textValueNode = element.Element(XmlLoader.ComponentNamespace + "value");

            if (textValueNode != null)
            {
                foreach (var spanNode in textValueNode.Elements())
                {
                    string nodeValue  = spanNode.Value;
                    var    formatting = new TextRunFormatting(TextRunFormattingType.Normal, size);

                    if (spanNode.Name.LocalName == "sub")
                    {
                        formatting.FormattingType = TextRunFormattingType.Subscript;
                    }
                    else if (spanNode.Name.LocalName == "sup")
                    {
                        formatting.FormattingType = TextRunFormattingType.Superscript;
                    }
                    else if (spanNode.Name.LocalName != "span")
                    {
                        logger.LogWarning(spanNode, $"Unknown node '{spanNode.Name}' will be treated as <span>");
                    }

                    var textRun = new TextRun(nodeValue, formatting);

                    if (!ValidateText(element, description, textRun.Text))
                    {
                        return(false);
                    }

                    textCommand.TextRuns.Add(textRun);
                }
            }
            else if (element.GetAttribute("value", logger, out var value))
            {
                var textRun = new TextRun(value.Value, new TextRunFormatting(TextRunFormattingType.Normal, size));

                if (!ValidateText(value, description, textRun.Text))
                {
                    return(false);
                }

                textCommand.TextRuns.Add(textRun);
            }
            else
            {
                return(false);
            }

            return(true);
        }