GetStyleValue() 공개 정적인 메소드

Translates a string-value of a certain style into the index value is used for this style in this class.
public static GetStyleValue ( string style ) : int
style string a string
리턴 int
        /// <summary>
        /// Constructs a Font-object.
        /// </summary>
        /// <param name="attributes">the attributes of a Font object</param>
        /// <returns>a Font object</returns>
        public Font GetFont(Properties attributes)
        {
            lock (_syncLock)
            {
                string    fontname = null;
                var       encoding = DefaultEncoding;
                var       embedded = DefaultEmbedding;
                float     size     = Font.UNDEFINED;
                var       style    = Font.NORMAL;
                BaseColor color    = null;
                var       value    = attributes[Markup.HTML_ATTR_STYLE];
                if (!string.IsNullOrEmpty(value))
                {
                    var styleAttributes = Markup.ParseAttributes(value);
                    if (styleAttributes.Count == 0)
                    {
                        attributes.Add(Markup.HTML_ATTR_STYLE, value);
                    }
                    else
                    {
                        fontname = styleAttributes[Markup.CSS_KEY_FONTFAMILY];
                        if (fontname != null)
                        {
                            string tmp;
                            while (fontname.IndexOf(",", StringComparison.Ordinal) != -1)
                            {
                                tmp = fontname.Substring(0, fontname.IndexOf(",", StringComparison.Ordinal));
                                if (IsRegistered(tmp))
                                {
                                    fontname = tmp;
                                }
                                else
                                {
                                    fontname = fontname.Substring(fontname.IndexOf(",", StringComparison.Ordinal) + 1);
                                }
                            }
                        }
                        if ((value = styleAttributes[Markup.CSS_KEY_FONTSIZE]) != null)
                        {
                            size = Markup.ParseLength(value);
                        }
                        if ((value = styleAttributes[Markup.CSS_KEY_FONTWEIGHT]) != null)
                        {
                            style |= Font.GetStyleValue(value);
                        }
                        if ((value = styleAttributes[Markup.CSS_KEY_FONTSTYLE]) != null)
                        {
                            style |= Font.GetStyleValue(value);
                        }
                        if ((value = styleAttributes[Markup.CSS_KEY_COLOR]) != null)
                        {
                            color = Markup.DecodeColor(value);
                        }
                        attributes.AddAll(styleAttributes);
                    }
                }
                if ((value = attributes[ElementTags.ENCODING]) != null)
                {
                    encoding = value;
                }
                if ("true".Equals(attributes[ElementTags.EMBEDDED]))
                {
                    embedded = true;
                }
                if ((value = attributes[ElementTags.FONT]) != null)
                {
                    fontname = value;
                }
                if ((value = attributes[ElementTags.SIZE]) != null)
                {
                    size = float.Parse(value, NumberFormatInfo.InvariantInfo);
                }
                if ((value = attributes[Markup.HTML_ATTR_STYLE]) != null)
                {
                    style |= Font.GetStyleValue(value);
                }
                if ((value = attributes[ElementTags.STYLE]) != null)
                {
                    style |= Font.GetStyleValue(value);
                }
                var r = attributes[ElementTags.RED];
                var g = attributes[ElementTags.GREEN];
                var b = attributes[ElementTags.BLUE];
                if (r != null || g != null || b != null)
                {
                    var red   = 0;
                    var green = 0;
                    var blue  = 0;
                    if (r != null)
                    {
                        red = int.Parse(r);
                    }

                    if (g != null)
                    {
                        green = int.Parse(g);
                    }

                    if (b != null)
                    {
                        blue = int.Parse(b);
                    }

                    color = new BaseColor(red, green, blue);
                }
                else if ((value = attributes[ElementTags.COLOR]) != null)
                {
                    color = Markup.DecodeColor(value);
                }
                if (fontname == null)
                {
                    return(GetFont(null, encoding, embedded, size, style, color));
                }
                return(GetFont(fontname, encoding, embedded, size, style, color));
            }
        }
예제 #2
0
        /// <summary>
        /// Constructs a Font-object.
        /// </summary>
        /// <param name="attributes">the attributes of a Font object</param>
        /// <returns>a Font object</returns>
        public virtual Font GetFont(Properties attributes)
        {
            string fontname = null;
            string encoding = defaultEncoding;
            bool   embedded = defaultEmbedding;
            float  size     = Font.UNDEFINED;
            int    style    = Font.NORMAL;
            Color  color    = null;
            string value    = attributes[Markup.HTML_ATTR_STYLE];

            if (value != null && value.Length > 0)
            {
                Properties styleAttributes = Markup.ParseAttributes(value);
                if (styleAttributes.Count == 0)
                {
                    attributes.Add(Markup.HTML_ATTR_STYLE, value);
                }
                else
                {
                    fontname = styleAttributes[Markup.CSS_KEY_FONTFAMILY];
                    if (fontname != null)
                    {
                        string tmp;
                        while (fontname.IndexOf(',') != -1)
                        {
                            tmp = fontname.Substring(0, fontname.IndexOf(','));
                            if (IsRegistered(tmp))
                            {
                                fontname = tmp;
                            }
                            else
                            {
                                fontname = fontname.Substring(fontname.IndexOf(',') + 1);
                            }
                        }
                    }
                    if ((value = styleAttributes[Markup.CSS_KEY_FONTSIZE]) != null)
                    {
                        size = Markup.ParseLength(value);
                    }
                    if ((value = styleAttributes[Markup.CSS_KEY_FONTWEIGHT]) != null)
                    {
                        style |= Font.GetStyleValue(value);
                    }
                    if ((value = styleAttributes[Markup.CSS_KEY_FONTSTYLE]) != null)
                    {
                        style |= Font.GetStyleValue(value);
                    }
                    if ((value = styleAttributes[Markup.CSS_KEY_COLOR]) != null)
                    {
                        color = Markup.DecodeColor(value);
                    }
                    attributes.AddAll(styleAttributes);
                }
            }
            if ((value = attributes[ElementTags.ENCODING]) != null)
            {
                encoding = value;
            }
            if ("true".Equals(attributes[ElementTags.EMBEDDED]))
            {
                embedded = true;
            }
            if ((value = attributes[ElementTags.FONT]) != null)
            {
                fontname = value;
            }
            if ((value = attributes[ElementTags.SIZE]) != null)
            {
                size = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            if ((value = attributes[Markup.HTML_ATTR_STYLE]) != null)
            {
                style |= Font.GetStyleValue(value);
            }
            if ((value = attributes[ElementTags.STYLE]) != null)
            {
                style |= Font.GetStyleValue(value);
            }
            string r = attributes[ElementTags.RED];
            string g = attributes[ElementTags.GREEN];
            string b = attributes[ElementTags.BLUE];

            if (r != null || g != null || b != null)
            {
                int red   = 0;
                int green = 0;
                int blue  = 0;
                if (r != null)
                {
                    red = int.Parse(r);
                }
                if (g != null)
                {
                    green = int.Parse(g);
                }
                if (b != null)
                {
                    blue = int.Parse(b);
                }
                color = new Color(red, green, blue);
            }
            else if ((value = attributes[ElementTags.COLOR]) != null)
            {
                color = Markup.DecodeColor(value);
            }
            if (fontname == null)
            {
                return(GetFont(null, encoding, embedded, size, style, color));
            }
            return(GetFont(fontname, encoding, embedded, size, style, color));
        }