Example #1
0
        protected bool DoConvertBorderStyle(StyleBase onStyle, object value, out LineType result)
        {
            LineType style;
            PDFDash  dash;

            if (null == value)
            {
                result = LineType.None;
                return(false);
            }
            else if (value is LineType)
            {
                result = (LineType)value;
                return(true);
            }
            else if (CSSBorderStyleParser.TryGetLineStyleFromString(value.ToString(), out style, out dash))
            {
                if (null != dash)
                {
                    onStyle.SetValue(this._dash, dash);
                }

                result = style;
                return(true);
            }
            else
            {
                result = LineType.None;
                return(false);
            }
        }
Example #2
0
        protected override bool DoSetStyleValue(Style style, CSSStyleItemReader reader)
        {
            int count  = 0;
            int failed = 0;

            while (reader.ReadNextValue())
            {
                count++;

                if (IsExpression(reader.CurrentTextValue))
                {
                    //Order Is Important - expecting Width, Style, Color in that order
                    if (count == 1)
                    {
                        if (!AttachExpressionBindingHandler(style, StyleKeys.BorderWidthKey, reader.CurrentTextValue, DoConvertBorderWidth))
                        {
                            failed++;
                        }
                    }
                    else if (count == 2)
                    {
                        if (!AttachExpressionBindingHandler(style, StyleKeys.BorderStyleKey, reader.CurrentTextValue, DoConvertBorderStyle))
                        {
                            failed++;
                        }
                    }
                    else if (count == 3)
                    {
                        if (!AttachExpressionBindingHandler(style, StyleKeys.BorderColorKey, reader.CurrentTextValue, DoConvertBorderColor))
                        {
                            failed++;
                        }
                    }
                }
                else if (IsNumber(reader.CurrentTextValue))
                {
                    PDFUnit unit;
                    if (ParseCSSUnit(reader.CurrentTextValue, out unit))
                    {
                        style.SetValue(_width, unit);
                    }
                    else
                    {
                        failed++;
                    }
                }
                else if (IsColor(reader.CurrentTextValue))
                {
                    PDFColor color;
                    double?  opacity;
                    if (ParseCSSColor(reader.CurrentTextValue, out color, out opacity))
                    {
                        style.SetValue(_color, color);
                        //TODO: Set the opacity of the border side.
                    }
                    else
                    {
                        failed++;
                    }
                }
                else
                {
                    LineType line;
                    PDFDash  dash;

                    if (CSSBorderStyleParser.TryGetLineStyleFromString(reader.CurrentTextValue, out line, out dash))
                    {
                        style.SetValue(_style, line);
                        if (null != dash)
                        {
                            style.SetValue(_dash, dash);
                        }
                    }
                    else
                    {
                        failed++;
                    }
                }
            }
            return(count > 0 && failed == 0);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            int count  = 0;
            int failed = 0;

            while (reader.ReadNextValue())
            {
                count++;
                if (IsExpression(reader.CurrentTextValue))
                {
                    //Border order is Width, Style, Color
                    if (count == 1)
                    {
                        if (!AttachExpressionBindingHandler(onStyle, StyleKeys.BorderWidthKey, reader.CurrentTextValue, DoConvertBorderWidth))
                        {
                            failed++;
                        }
                    }
                    else if (count == 2)
                    {
                        if (!AttachExpressionBindingHandler(onStyle, StyleKeys.BorderStyleKey, reader.CurrentTextValue, DoConvertBorderStyle))
                        {
                            failed++;
                        }
                    }
                    else if (count == 3)
                    {
                        if (!AttachExpressionBindingHandler(onStyle, StyleKeys.BorderColorKey, reader.CurrentTextValue, DoConvertBorderColor))
                        {
                            failed++;
                        }
                    }
                }
                else if (IsNumber(reader.CurrentTextValue))
                {
                    PDFUnit unit;
                    if (ParseCSSUnit(reader.CurrentTextValue, out unit))
                    {
                        onStyle.Border.Width = unit;
                    }
                    else
                    {
                        failed++;
                    }
                }
                else if (IsColor(reader.CurrentTextValue))
                {
                    PDFColor color;
                    double?  opacity;
                    if (ParseCSSColor(reader.CurrentTextValue, out color, out opacity))
                    {
                        onStyle.Border.Color = color;

                        if (opacity.HasValue)
                        {
                            onStyle.Border.Opacity = opacity.Value;
                        }
                    }
                    else
                    {
                        failed++;
                    }
                }
                else
                {
                    LineType style;
                    PDFDash  dash;
                    if (CSSBorderStyleParser.TryGetLineStyleFromString(reader.CurrentTextValue, out style, out dash))
                    {
                        onStyle.Border.LineStyle = style;
                        if (null != dash)
                        {
                            onStyle.Border.Dash = dash;
                        }
                    }
                    else
                    {
                        failed++;
                    }
                }
            }
            return(count > 0 && failed == 0);
        }