Ejemplo n.º 1
0
        protected override bool DoSetStyleValue(Style style, CSSStyleItemReader reader)
        {
            PDFFontSource root    = null;
            PDFFontSource curr    = null;
            bool          hasExpr = false;

            while (reader.ReadNextValue(',', ';', true))
            {
                string        src = reader.CurrentTextValue.Trim();
                PDFFontSource found;
                if (IsExpression(src))
                {
                    if (hasExpr)
                    {
                        throw new InvalidOperationException("Connot bind mupltiple values onto a Font src property");
                    }

                    if (this.AttachExpressionBindingHandler(style, StyleKeys.FontFaceSrcKey, src, DoConvertFontSource))
                    {
                        hasExpr = true;
                    }
                }
                if (TryGetFontSource(src, out found))
                {
                    if (hasExpr)
                    {
                        throw new InvalidOperationException("Connot bind mupltiple values onto a Font src property");
                    }

                    if (null == root)
                    {
                        root = found;
                    }
                    if (null == curr)
                    {
                        curr = found;
                    }
                    else
                    {
                        curr.Next = found;
                        curr      = found;
                    }
                }
                //We need this to go past the original comma on the following ones,
                //becase we ignore white space in values, bit of a hack
                if (!reader.InnerEnumerator.EOS && reader.InnerEnumerator.Current == ',')
                {
                    reader.InnerEnumerator.MoveNext();
                }
            }
            if (null != root)
            {
                style.SetValue(StyleKeys.FontFaceSrcKey, root);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool result = false;

            if (reader.ReadNextValue())
            {
                string value = reader.CurrentTextValue;

                PDFUnit parsed;
                if (IsExpression(value))
                {
                    //Attach to both the Width and the FullWidth flag
                    result  = AttachExpressionBindingHandler(onStyle, StyleKeys.SizeWidthKey, value, DoConvertExplicitWidth);
                    result &= AttachExpressionBindingHandler(onStyle, StyleKeys.SizeFullWidthKey, value, DoConvertFullWidth);
                }
                else if (value == "100%")
                {
                    onStyle.SetValue(StyleKeys.SizeFullWidthKey, true);
                    result = true;
                }
                else if (ParseCSSUnit(value, out parsed))
                {
                    onStyle.SetValue(this.StyleAttribute, parsed);
                    result = true;
                }
            }
            return(result);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool bold   = true;
            bool result = true;

            if (reader.ReadNextValue())
            {
                var str = reader.CurrentTextValue;
                if (IsExpression(str))
                {
                    result = AttachExpressionBindingHandler(onStyle, StyleKeys.FontBoldKey, str, DoConvertFontWeight);
                }
                else if (TryGetFontWeight(reader.CurrentTextValue, out bold))
                {
                    onStyle.SetValue(StyleKeys.FontBoldKey, bold);
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }
Ejemplo n.º 4
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool         result = true;
            PositionMode display;

            if (reader.ReadNextValue())
            {
                string value = reader.CurrentTextValue;

                if (IsExpression(value))
                {
                    result = AttachExpressionBindingHandler(onStyle, this.StyleAttribute, value, DoConvertPosition);
                }
                if (TryGetPositionEnum(value, out display))
                {
                    this.SetValue(onStyle, display);
                    result = true;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }
        protected override bool DoSetStyleValue(Style style, CSSStyleItemReader reader)
        {
            string          all    = string.Empty;
            StringBuilder   buffer = new StringBuilder();
            PDFColumnWidths widths;

            while (reader.ReadNextValue())
            {
                if (buffer.Length > 0)
                {
                    buffer.Append(" ");
                }
                buffer.Append(reader.CurrentTextValue);
            }

            if (buffer.Length > 0)
            {
                all = buffer.ToString();

                if (IsExpression(all))
                {
                    return(this.AttachExpressionBindingHandler(style, this.StyleAttribute, all, DoConvertColumnWidths));
                }
                else if (TryParseWidths(all, out widths))
                {
                    this.SetValue(style, widths);
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool success = true;

            Text.WordWrap wrap;
            bool          preserve;

            if (!reader.ReadNextValue())
            {
                wrap     = WordWrap.Auto;
                preserve = false;
                success  = false;
            }
            else if (IsExpression(reader.CurrentTextValue))
            {
                success = this.AttachExpressionBindingHandler(onStyle, StyleKeys.TextWordWrapKey, reader.CurrentTextValue, DoConvertWhitespace);
            }
            else if (TryParseWhitespace(reader.CurrentTextValue, out wrap, out preserve))
            {
                onStyle.SetValue(StyleKeys.TextWordWrapKey, wrap);
                onStyle.SetValue(StyleKeys.TextWhitespaceKey, preserve);
                success = true;
            }
            return(success);
        }
Ejemplo n.º 7
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            int number;

            if (reader.ReadNextValue())
            {
                string val = reader.CurrentTextValue;

                if (IsExpression(val))
                {
                    return(AttachExpressionBindingHandler(onStyle, this.StyleAttribute, val, DoConvertColumnSpan));
                }
                else if (ParseInteger(val, out number) && number >= 1)
                {
                    this.SetValue(onStyle, number);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        protected override bool DoSetStyleValue(Style style, CSSStyleItemReader reader)
        {
            var key    = StyleKeys.StrokeJoinKey;
            var result = false;

            if (reader.ReadNextValue())
            {
                var      val = reader.CurrentTextValue;
                LineJoin join;
                if (IsExpression(val))
                {
                    result = AttachExpressionBindingHandler(style, key, val, DoConvertLineJoin);
                }
                else if (TryParseLineJoin(val.ToLower(), out join))
                {
                    style.SetValue(key, join);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }

            return(result);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool           result = true;
            OverflowAction over;

            if (reader.ReadNextValue())
            {
                string value = reader.CurrentTextValue;

                if (IsExpression(value))
                {
                    result = this.AttachExpressionBindingHandler(onStyle, this.StyleAttribute, value, DoConvertOverflow);
                }
                else if (TryGetOverflowEnum(value, out over))
                {
                    this.SetValue(onStyle, over);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }
Ejemplo n.º 10
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool result = true;
            ListNumberingGroupStyle type;

            if (reader.ReadNextValue())
            {
                var val = reader.CurrentTextValue;

                if (IsExpression(val))
                {
                    result = AttachExpressionBindingHandler(onStyle, this.StyleAttribute, val, DoConvertListType);
                }
                else if (TryGetListTypeEnum(reader.CurrentTextValue, out type))
                {
                    this.SetValue(onStyle, type);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool success = true;
            HorizontalAlignment align;

            if (!reader.ReadNextValue())
            {
                align   = HorizontalAlignment.Left;
                success = false;
            }
            else
            {
                var val = reader.CurrentTextValue;

                if (IsExpression(val))
                {
                    success = AttachExpressionBindingHandler(onStyle, StyleKeys.PositionHAlignKey, val, DoConvertHAlign);
                }

                else if (TryParseHAlign(val, out align))
                {
                    onStyle.SetValue(StyleKeys.PositionHAlignKey, align);
                    success = true;
                }
            }
            return(success);
        }
Ejemplo n.º 12
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            PDFUnit size   = PDFUnit.Zero;
            bool    result = true;

            if (reader.ReadNextValue())
            {
                var str = reader.CurrentTextValue;
                if (IsExpression(str))
                {
                    result = this.AttachExpressionBindingHandler(onStyle, StyleKeys.FontSizeKey, str, DoConvertFontSize);
                }
                else if (TryGetFontSize(str, out size))
                {
                    onStyle.SetValue(StyleKeys.FontSizeKey, size);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            PDFUnit size   = PDFUnit.Zero;
            bool    result = true;

            if (reader.ReadNextValue())
            {
                var value = reader.CurrentTextValue;
                if (IsExpression(value))
                {
                    result = AttachExpressionBindingHandler(onStyle, StyleKeys.TextCharSpacingKey, value, DoConvertLetterSpacing);
                }
                else if (TryGetLetterSpacing(reader.CurrentTextValue, out size))
                {
                    onStyle.SetValue(StyleKeys.TextCharSpacingKey, size);
                    result = true;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool result;

            if (!reader.ReadNextValue())
            {
                result = false;
            }
            else
            {
                string val = reader.CurrentTextValue;
                bool   breakval;

                if (IsExpression(val))
                {
                    result = AttachExpressionBindingHandler(onStyle, this.StyleAttribute, val, DoConvertBreakValue);
                }
                else if (TryParseBreak(val, out breakval))
                {
                    onStyle.SetValue(this.StyleAttribute, breakval);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            return(result);
        }
Ejemplo n.º 15
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool italic = true;
            bool result = true;


            if (reader.ReadNextValue())
            {
                var str = reader.CurrentTextValue;
                if (IsExpression(str))
                {
                    result = AttachExpressionBindingHandler(onStyle, StyleKeys.FontItalicKey, str, DoConvertFontStyle);
                }
                else if (TryGetFontStyle(str, out italic))
                {
                    onStyle.SetValue(StyleKeys.FontItalicKey, italic);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool         result = true;
            PositionMode found  = PositionMode.Block;

            if (reader.ReadNextValue())
            {
                var val = reader.CurrentTextValue;

                if (IsExpression(val))
                {
                    result = AttachExpressionBindingHandler(onStyle, this.StyleAttribute, val, DoConvertPositionMode);
                }
                else if (TryGetPositionMode(val, out found))
                {
                    this.SetValue(onStyle, found);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            double number;

            if (reader.ReadNextValue())
            {
                if (IsExpression(reader.CurrentTextValue))
                {
                    return(this.AttachExpressionBindingHandler(onStyle, this.StyleAttribute, reader.CurrentTextValue, DoConvertOpacity));
                }
                else if (ParseDouble(reader.CurrentTextValue, out number))
                {
                    if (number < 0.0)
                    {
                        number = 0.0;
                    }
                    if (number > 1.0)
                    {
                        number = 1.0;
                    }

                    this.SetValue(onStyle, number);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
Ejemplo n.º 18
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool result = false;

            if (reader.ReadNextValue())
            {
                var val = reader.CurrentTextValue;

                if (IsExpression(val))
                {
                    result  = this.AttachExpressionBindingHandler(onStyle, StyleKeys.ClipTopKey, val, DoConvertOverflowY);
                    result &= this.AttachExpressionBindingHandler(onStyle, StyleKeys.ClipBottomKey, val, DoConvertOverflowY);
                }
                else if (TryParseOverflow(val, out bool setValue))
                {
                    if (setValue)
                    {
                        onStyle.SetValue(StyleKeys.ClipTopKey, (PDFUnit)0.1);
                        onStyle.SetValue(StyleKeys.ClipBottomKey, (PDFUnit)0.1);
                    }
                    else
                    {
                        onStyle.RemoveValue(StyleKeys.ClipTopKey);
                        onStyle.RemoveValue(StyleKeys.ClipBottomKey);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 19
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool          result = true;
            PatternRepeat repeat;

            if (reader.ReadNextValue())
            {
                var str = reader.CurrentTextValue;
                if (IsExpression(str))
                {
                    result = this.AttachExpressionBindingHandler(onStyle, this.StyleAttribute, str, DoConvertRepeatEnum);
                }
                else if (TryGetRepeatEnum(reader.CurrentTextValue, out repeat))
                {
                    this.SetValue(onStyle, repeat);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }
Ejemplo n.º 20
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            var result = base.DoSetStyleValue(onStyle, reader);

            //Make sure we are past the end of the inner css item
            while (reader.ReadNextValue())
            {
                ;
            }

            return(result);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            PDFFontSelector root    = null;
            PDFFontSelector curr    = null;
            bool            hasExpr = false;

            while (reader.ReadNextValue())
            {
                string          fontfamily = reader.CurrentTextValue.Trim();
                PDFFontSelector found;
                if (IsExpression(fontfamily))
                {
                    if (null != root)
                    {
                        throw new InvalidOperationException("Expressions - calc() and var() cannot be used within part of a font selector, us calc(concat(...)) instead.");
                    }

                    hasExpr = AttachExpressionBindingHandler(onStyle, StyleKeys.FontFamilyKey, fontfamily, DoConvertFontSelector);
                }
                if (TryGetActualFontFamily(fontfamily, out found))
                {
                    if (hasExpr)
                    {
                        throw new InvalidOperationException("Expressions - calc() and var() cannot be used within part of a font selector, us calc(concat(...)) instead.");
                    }

                    if (null == root)
                    {
                        root = found;
                    }
                    if (null == curr)
                    {
                        curr = found;
                    }
                    else
                    {
                        curr.Next = found;
                        curr      = found;
                    }
                }
            }
            if (null != root)
            {
                onStyle.SetValue(StyleKeys.FontFamilyKey, root);
                return(true);
            }
            else
            {
                return(hasExpr);
            }
        }
        protected override bool DoSetStyleValue(Style style, CSSStyleItemReader reader)
        {
            if (reader.ReadNextValue())
            {
                if (IsExpression(reader.CurrentTextValue))
                {
                    return(AttachExpressionBindingHandler(style, StyleKeys.StrokeDashKey, reader.CurrentTextValue, DoConvertDashes));
                }
                else
                {
                    var all = new List <int>(1);

                    do
                    {
                        int parsed;
                        if (ParseInteger(reader.CurrentTextValue, out parsed))
                        {
                            all.Add(parsed);
                        }
                    }while (reader.ReadNextValue());

                    if (all.Count > 0)
                    {
                        style.SetValue(StyleKeys.StrokeDashKey, new PDFDash(all.ToArray(), 0));
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool result;
            ListNumberingGroupStyle type;

            if (reader.ReadNextValue())
            {
                string val = reader.CurrentTextValue;

                if (IsExpression(val))
                {
                    result = AttachExpressionBindingHandler(onStyle, StyleKeys.ListNumberStyleKey, val, DoConvertListStyle);
                }
                else if (CSSListStyleTypeParser.TryGetListTypeEnum(reader.CurrentTextValue, out type))
                {
                    onStyle.SetValue(StyleKeys.ListNumberStyleKey, type);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            //make sure we read to the end of the style value
            while (reader.ReadNextValue())
            {
                ;
            }

            return(result);
        }
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            int number;

            if (reader.ReadNextValue())
            {
                if (IsExpression(reader.CurrentTextValue))
                {
                    return(this.AttachExpressionBindingHandler(onStyle, this.StyleAttribute, reader.CurrentTextValue, DoConvertColumnCount));
                }
                else if (ParseInteger(reader.CurrentTextValue, out number))
                {
                    this.SetValue(onStyle, number);
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Overrides the base implementation to either set the value of the enumeration or attach an expression to the
        /// style for evaluation later on.
        /// </summary>
        /// <param name="onStyle">The style we are parsing for</param>
        /// <param name="reader">The style item reader</param>
        /// <returns>True the value was parsed or the expression was bound</returns>
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool success = false;
            T    result;

            if (reader.ReadNextValue())
            {
                if (IsExpression(reader.CurrentTextValue))
                {
                    this.AttachExpressionBindingHandler(onStyle, this.StyleAttribute, reader.CurrentTextValue, this.DoConvertEnum);
                }
                else if (this.DoConvertEnum(onStyle, reader.CurrentTextValue, out result))
                {
                    this.SetValue(onStyle, result);
                    success = true;
                }
            }
            return(success);
        }
Ejemplo n.º 26
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool   result = false;
            string attrvalue;

            if (reader.ReadNextValue())
            {
                if (IsExpression(reader.CurrentTextValue))
                {
                    this.AttachExpressionBindingHandler(onStyle, this.StyleAttribute, reader.CurrentTextValue, this.DoConvertGradient);
                }
                else if (this.DoConvertGradient(onStyle, reader.CurrentTextValue, out attrvalue))
                {
                    onStyle.SetValue(this.StyleAttribute, attrvalue);
                    result = true;
                }
            }
            return(result);
        }
 protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
 {
     if (reader.ReadNextValue())
     {
         PDFUnit found;
         if (IsExpression(reader.CurrentTextValue))
         {
             if (this.AttachExpressionBindingHandler(onStyle, this.StyleAttribute, reader.CurrentTextValue, DoConvertThicknessValue))
             {
                 return(true);
             }
         }
         else if (ParseThicknessValue(reader.CurrentTextValue, this.AutoValue, out found))
         {
             this.SetValue(onStyle, found);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 28
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool result = true;

            Text.TextDecoration decor;
            TextDecoration      final = TextDecoration.None;
            bool hasExpr = false;

            while (reader.ReadNextValue())
            {
                string val = reader.CurrentTextValue;

                if (IsExpression(val))
                {
                    if (final != TextDecoration.None)
                    {
                        throw new InvalidOperationException("Cannot apply expressions and text decoration values in the same style selector");
                    }

                    result  = AttachExpressionBindingHandler(onStyle, this.StyleAttribute, val, DoConvertDecoration);
                    hasExpr = result;
                }
                else if (TryGetOneDecoration(val, out decor))
                {
                    if (hasExpr)
                    {
                        throw new InvalidOperationException("Cannot apply expressions and text decoration values in the same style selector");
                    }

                    final  |= decor;
                    result &= true;
                }
            }

            if (result && !hasExpr)
            {
                onStyle.SetValue(StyleKeys.TextDecorationKey, final);
            }

            return(result);
        }
Ejemplo n.º 29
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            bool result = false;

            if (reader.ReadNextValue())
            {
                string value = reader.CurrentTextValue;

                PDFUnit parsed;
                if (IsExpression(value))
                {
                    AttachExpressionBindingHandler(onStyle, this.StyleAttribute, value, this.DoConvertUnit);
                }
                if (this.DoConvertUnit(onStyle, value, out parsed))
                {
                    onStyle.SetValue(this.StyleAttribute, parsed);
                    result = true;
                }
            }
            return(result);
        }
Ejemplo n.º 30
0
        protected override bool DoSetStyleValue(Style onStyle, CSSStyleItemReader reader)
        {
            PDFUnit absolute;
            bool    result = false;

            if (reader.ReadNextValue())
            {
                var str = reader.CurrentTextValue;

                if (IsExpression(str))
                {
                    result = AttachExpressionBindingHandler(onStyle, StyleKeys.TextLeadingKey, str, DoConvertLineHeight);
                }
                else if (TryParseLineHeight(onStyle, str, out absolute))
                {
                    onStyle.SetValue(StyleKeys.TextLeadingKey, absolute);
                    result = true;
                }
            }
            return(result);
        }