Пример #1
0
        public TextElementStyle(Element element, bool usePadding)
        {
            this.usePadding = usePadding;
            if (usePadding)
            {
                marginSource = "padding";
            }
            String classes = element.GetAttributeString("class");

            if (classes != null)
            {
                String[] splitClasses = classes.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                center = splitClasses.FirstOrDefault(c => "Center".Equals(c, StringComparison.InvariantCultureIgnoreCase)) != null;
                italic = splitClasses.FirstOrDefault(c => "Italic".Equals(c, StringComparison.InvariantCultureIgnoreCase)) != null;
                bold   = splitClasses.FirstOrDefault(c => "Bold".Equals(c, StringComparison.InvariantCultureIgnoreCase)) != null;
                _break = splitClasses.FirstOrDefault(c => "Break".Equals(c, StringComparison.InvariantCultureIgnoreCase)) != null;
                flow   = splitClasses.FirstOrDefault(c => "Flow".Equals(c, StringComparison.InvariantCultureIgnoreCase)) != null;
            }
            InlineCssParser inlineCss = new InlineCssParser(element.GetAttributeString("style"));

            if (inlineCss.contains("color"))
            {
                color = inlineCss.colorValue("color");
            }
            if (inlineCss.contains("background-color"))
            {
                backgroundColor = inlineCss.colorValue("background-color");
            }
            if (inlineCss.contains("font-size"))
            {
                fontSize = inlineCss.intValue("font-size");
            }
            marginTop    = inlineCss.intValue(marginSource + "-top");
            marginBottom = inlineCss.intValue(marginSource + "-bottom");
        }
Пример #2
0
        public ImageElementStyle(Element imageElement)
        {
            String classes = imageElement.GetAttributeString("class");

            if (classes != null)
            {
                String[] splitClasses = classes.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                center = splitClasses.FirstOrDefault(c => "Center".Equals(c, StringComparison.InvariantCultureIgnoreCase)) != null;
                if (splitClasses.FirstOrDefault(c => "LeftText".Equals(c, StringComparison.InvariantCultureIgnoreCase)) != null)
                {
                    textAlign = ImageTextAlign.Left;
                }
                else if (splitClasses.FirstOrDefault(c => "RightText".Equals(c, StringComparison.InvariantCultureIgnoreCase)) != null)
                {
                    textAlign = ImageTextAlign.Right;
                }
                _break = splitClasses.FirstOrDefault(c => "Break".Equals(c, StringComparison.InvariantCultureIgnoreCase)) != null;
            }
            InlineCssParser inlineCss = new InlineCssParser(imageElement.GetAttributeString("style"));

            if (inlineCss.contains("width"))
            {
                fixedSize = !inlineCss.isValuePercent("width");
                int?widthNull = inlineCss.intValue("width");
                if (widthNull.HasValue)
                {
                    width = widthNull.Value;
                }
            }
            int?x = null;
            int?y = inlineCss.intValue("margin-top");

            switch (textAlign)
            {
            case ImageTextAlign.None:
            case ImageTextAlign.Right:
                x = inlineCss.intValue("margin-left");
                textSideMargin = inlineCss.intValue("margin-right");
                break;

            case ImageTextAlign.Left:
                x = inlineCss.intValue("margin-right");
                textSideMargin = inlineCss.intValue("margin-left");
                break;
            }
            textBottomMargin = inlineCss.intValue("margin-bottom");
            offset           = new Vector2(x.GetValueOrDefault(0), y.GetValueOrDefault(0));
        }