コード例 #1
0
        public Font GetFont(ChainedProperties props)
        {
            String face = props[ElementTags.FACE];

            if (face != null)
            {
                StringTokenizer tok = new StringTokenizer(face, ",");
                while (tok.HasMoreTokens())
                {
                    face = tok.NextToken().Trim();
                    if (face.StartsWith("\""))
                    {
                        face = face.Substring(1);
                    }
                    if (face.EndsWith("\""))
                    {
                        face = face.Substring(0, face.Length - 1);
                    }
                    if (fontImp.IsRegistered(face))
                    {
                        break;
                    }
                }
            }
            int style = 0;

            if (props.HasProperty(HtmlTags.I))
            {
                style |= Font.ITALIC;
            }
            if (props.HasProperty(HtmlTags.B))
            {
                style |= Font.BOLD;
            }
            if (props.HasProperty(HtmlTags.U))
            {
                style |= Font.UNDERLINE;
            }
            if (props.HasProperty(HtmlTags.S))
            {
                style |= Font.STRIKETHRU;
            }

            String value = props[ElementTags.SIZE];
            float  size  = 12;

            if (value != null)
            {
                size = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            Color  color    = Markup.DecodeColor(props["color"]);
            String encoding = props["encoding"];

            if (encoding == null)
            {
                encoding = BaseFont.WINANSI;
            }
            return(fontImp.GetFont(face, encoding, true, size, style, color));
        }
コード例 #2
0
        /// <summary>
        /// New method contributed by Lubos Strapko
        /// @since 2.1.3
        /// </summary>
        /// <param name="h"></param>
        /// <param name="cprops"></param>
        public static void InsertStyle(Hashtable h, ChainedProperties cprops)
        {
            var style = (string)h["style"];

            if (style == null)
            {
                return;
            }

            var prop = Markup.ParseAttributes(style);

            foreach (string key in prop.Keys)
            {
                if (key.Equals(Markup.CSS_KEY_FONTFAMILY))
                {
                    h["face"] = prop[key];
                }
                else if (key.Equals(Markup.CSS_KEY_FONTSIZE))
                {
                    var actualFontSize = Markup.ParseLength(cprops[ElementTags.SIZE], Markup.DEFAULT_FONT_SIZE);
                    if (actualFontSize <= 0f)
                    {
                        actualFontSize = Markup.DEFAULT_FONT_SIZE;
                    }

                    h[ElementTags.SIZE] = Markup.ParseLength(prop[key], actualFontSize).ToString(NumberFormatInfo.InvariantInfo) + "pt";
                }
                else if (key.Equals(Markup.CSS_KEY_FONTSTYLE))
                {
                    var ss = prop[key].Trim().ToLowerInvariant();
                    if (ss.Equals("italic") || ss.Equals("oblique"))
                    {
                        h["i"] = null;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_FONTWEIGHT))
                {
                    var ss = prop[key].Trim().ToLowerInvariant();
                    if (ss.Equals("bold") || ss.Equals("700") || ss.Equals("800") || ss.Equals("900"))
                    {
                        h["b"] = null;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_TEXTDECORATION))
                {
                    var ss = prop[key].Trim().ToLowerInvariant();
                    if (ss.Equals(Markup.CSS_VALUE_UNDERLINE))
                    {
                        h["u"] = null;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_COLOR))
                {
                    var c = Markup.DecodeColor(prop[key]);
                    if (c != null)
                    {
                        var hh = c.ToArgb() & 0xffffff;
                        var hs = "#" + hh.ToString("X06", NumberFormatInfo.InvariantInfo);
                        h["color"] = hs;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_LINEHEIGHT))
                {
                    var ss             = prop[key].Trim();
                    var actualFontSize = Markup.ParseLength(cprops[ElementTags.SIZE], Markup.DEFAULT_FONT_SIZE);
                    if (actualFontSize <= 0f)
                    {
                        actualFontSize = Markup.DEFAULT_FONT_SIZE;
                    }

                    var v = Markup.ParseLength(prop[key], actualFontSize);
                    if (ss.EndsWith("%"))
                    {
                        v           /= 100;
                        h["leading"] = "0," + v.ToString(NumberFormatInfo.InvariantInfo);
                    }
                    else if (Util.EqualsIgnoreCase("normal", ss))
                    {
                        h["leading"] = "0,1.5";
                    }
                    else
                    {
                        h["leading"] = v.ToString(NumberFormatInfo.InvariantInfo) + ",0";
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_TEXTALIGN))
                {
                    var ss = prop[key].Trim().ToLowerInvariant();
                    h["align"] = ss;
                }
                else if (key.Equals(Markup.CSS_KEY_PADDINGLEFT))
                {
                    var ss = prop[key].Trim().ToLowerInvariant();
                    h["indent"] = ss;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates a new instance of IncCell
        /// </summary>
        public IncCell(string tag, ChainedProperties props)
        {
            Cell = new PdfPCell();

            var value = props["colspan"];

            if (value != null)
            {
                Cell.Colspan = int.Parse(value);
            }

            value = props["rowspan"];
            if (value != null)
            {
                Cell.Rowspan = int.Parse(value);
            }

            value = props["align"];
            if (tag.Equals("th"))
            {
                Cell.HorizontalAlignment = Element.ALIGN_CENTER;
            }

            if (value != null)
            {
                if (Util.EqualsIgnoreCase(value, "center"))
                {
                    Cell.HorizontalAlignment = Element.ALIGN_CENTER;
                }
                else if (Util.EqualsIgnoreCase(value, "right"))
                {
                    Cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                }
                else if (Util.EqualsIgnoreCase(value, "left"))
                {
                    Cell.HorizontalAlignment = Element.ALIGN_LEFT;
                }
                else if (Util.EqualsIgnoreCase(value, "justify"))
                {
                    Cell.HorizontalAlignment = Element.ALIGN_JUSTIFIED;
                }
            }

            value = props["valign"];
            Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
            if (value != null)
            {
                if (Util.EqualsIgnoreCase(value, "top"))
                {
                    Cell.VerticalAlignment = Element.ALIGN_TOP;
                }
                else if (Util.EqualsIgnoreCase(value, "bottom"))
                {
                    Cell.VerticalAlignment = Element.ALIGN_BOTTOM;
                }
            }

            value = props["border"];
            float border = 0;

            if (value != null)
            {
                border = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            Cell.BorderWidth = border;
            value            = props["cellpadding"];
            if (value != null)
            {
                Cell.Padding = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            // Advanced formatting - does not conform to HTML standards
            value = props["bordertop"];
            if (value != null)
            {
                Cell.BorderWidthTop = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            value = props["borderbottom"];
            if (value != null)
            {
                Cell.BorderWidthBottom = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            value = props["borderleft"];
            if (value != null)
            {
                Cell.BorderWidthLeft = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            value = props["borderright"];
            if (value != null)
            {
                Cell.BorderWidthRight = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            value = props["cellpaddingtop"];
            if (value != null)
            {
                Cell.PaddingTop = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            value = props["cellpaddingbottom"];
            if (value != null)
            {
                Cell.PaddingBottom = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            value = props["cellpaddingleft"];
            if (value != null)
            {
                Cell.PaddingLeft = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            value = props["cellpaddingright"];
            if (value != null)
            {
                Cell.PaddingRight = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }

            value = props["bordercolor"];
            if (value != null)
            {
                Cell.BorderColor = Markup.DecodeColor(value);
            }

            Cell.UseDescender    = true;
            value                = props["bgcolor"];
            Cell.BackgroundColor = Markup.DecodeColor(value);
        }
コード例 #4
0
        /** Creates a new instance of IncCell */
        public IncCell(String tag, ChainedProperties props)
        {
            cell = new PdfPCell();
            String value = props["colspan"];

            if (value != null)
            {
                cell.Colspan = int.Parse(value);
            }
            value = props["align"];
            if (tag.Equals("th"))
            {
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
            }
            if (value != null)
            {
                if (Util.EqualsIgnoreCase(value, "center"))
                {
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                }
                else if (Util.EqualsIgnoreCase(value, "right"))
                {
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                }
                else if (Util.EqualsIgnoreCase(value, "left"))
                {
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                }
                else if (Util.EqualsIgnoreCase(value, "justify"))
                {
                    cell.HorizontalAlignment = Element.ALIGN_JUSTIFIED;
                }
            }
            value = props["valign"];
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;
            if (value != null)
            {
                if (Util.EqualsIgnoreCase(value, "top"))
                {
                    cell.VerticalAlignment = Element.ALIGN_TOP;
                }
                else if (Util.EqualsIgnoreCase(value, "bottom"))
                {
                    cell.VerticalAlignment = Element.ALIGN_BOTTOM;
                }
            }
            value = props["border"];
            float border = 0;

            if (value != null)
            {
                border = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }
            cell.BorderWidth = border;
            value            = props["cellpadding"];
            if (value != null)
            {
                cell.Padding = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }
            cell.UseDescender    = true;
            value                = props["bgcolor"];
            cell.BackgroundColor = Markup.DecodeColor(value);
        }
コード例 #5
0
        /// <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));
            }
        }
コード例 #6
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));
        }
コード例 #7
0
        public static Chunk GetChunk(Properties attributes)
        {
            Chunk chunk = new Chunk();

            chunk.Font = FontFactory.GetFont(attributes);
            String value;

            value = attributes[ElementTags.ITEXT];
            if (value != null)
            {
                chunk.Append(value);
            }
            value = attributes[ElementTags.LOCALGOTO];
            if (value != null)
            {
                chunk.SetLocalGoto(value);
            }
            value = attributes[ElementTags.REMOTEGOTO];
            if (value != null)
            {
                String page = attributes[ElementTags.PAGE];
                if (page != null)
                {
                    chunk.SetRemoteGoto(value, int.Parse(page));
                }
                else
                {
                    String destination = attributes[ElementTags.DESTINATION];
                    if (destination != null)
                    {
                        chunk.SetRemoteGoto(value, destination);
                    }
                }
            }
            value = attributes[ElementTags.LOCALDESTINATION];
            if (value != null)
            {
                chunk.SetLocalDestination(value);
            }
            value = attributes[ElementTags.SUBSUPSCRIPT];
            if (value != null)
            {
                chunk.SetTextRise(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo));
            }
            value = attributes[Markup.CSS_KEY_VERTICALALIGN];
            if (value != null && value.EndsWith("%"))
            {
                float p = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo) / 100f;
                chunk.SetTextRise(p * chunk.Font.Size);
            }
            value = attributes[ElementTags.GENERICTAG];
            if (value != null)
            {
                chunk.SetGenericTag(value);
            }
            value = attributes[ElementTags.BACKGROUNDCOLOR];
            if (value != null)
            {
                chunk.SetBackground(Markup.DecodeColor(value));
            }
            return(chunk);
        }
コード例 #8
0
        /// <summary>
        /// Sets some Rectangle properties (for a Cell, Table,...).
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="attributes"></param>
        private static void SetRectangleProperties(Rectangle rect, Properties attributes)
        {
            var value = attributes[ElementTags.BORDERWIDTH];

            if (value != null)
            {
                rect.BorderWidth = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            var border = 0;

            if (Utilities.CheckTrueOrFalse(attributes, ElementTags.LEFT))
            {
                border |= Rectangle.LEFT_BORDER;
            }
            if (Utilities.CheckTrueOrFalse(attributes, ElementTags.RIGHT))
            {
                border |= Rectangle.RIGHT_BORDER;
            }
            if (Utilities.CheckTrueOrFalse(attributes, ElementTags.TOP))
            {
                border |= Rectangle.TOP_BORDER;
            }
            if (Utilities.CheckTrueOrFalse(attributes, ElementTags.BOTTOM))
            {
                border |= Rectangle.BOTTOM_BORDER;
            }
            rect.Border = border;

            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);
                }

                rect.BorderColor = new BaseColor(red, green, blue);
            }
            else
            {
                rect.BorderColor = Markup.DecodeColor(attributes[ElementTags.BORDERCOLOR]);
            }
            r     = attributes.Remove(ElementTags.BGRED);
            g     = attributes.Remove(ElementTags.BGGREEN);
            b     = attributes.Remove(ElementTags.BGBLUE);
            value = attributes[ElementTags.BACKGROUNDCOLOR];
            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);
                }

                rect.BackgroundColor = new BaseColor(red, green, blue);
            }
            else if (value != null)
            {
                rect.BackgroundColor = Markup.DecodeColor(value);
            }
            else
            {
                value = attributes[ElementTags.GRAYFILL];
                if (value != null)
                {
                    rect.GrayFill = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                }
            }
        }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        public static Chunk GetChunk(Properties attributes)
        {
            var chunk = new Chunk {
                Font = FontFactory.GetFont(attributes)
            };

            var value = attributes[ElementTags.ITEXT];

            if (value != null)
            {
                chunk.Append(value);
            }
            value = attributes[ElementTags.Localgoto];
            if (value != null)
            {
                chunk.SetLocalGoto(value);
            }
            value = attributes[ElementTags.Remotegoto];
            if (value != null)
            {
                var page = attributes[ElementTags.PAGE];
                if (page != null)
                {
                    chunk.SetRemoteGoto(value, int.Parse(page));
                }
                else
                {
                    var destination = attributes[ElementTags.DESTINATION];
                    if (destination != null)
                    {
                        chunk.SetRemoteGoto(value, destination);
                    }
                }
            }
            value = attributes[ElementTags.Localdestination];
            if (value != null)
            {
                chunk.SetLocalDestination(value);
            }
            value = attributes[ElementTags.Subsupscript];
            if (value != null)
            {
                chunk.SetTextRise(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo));
            }
            value = attributes[Markup.CSS_KEY_VERTICALALIGN];
            if (value != null && value.EndsWith("%"))
            {
                var p = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo) / 100f;
                chunk.SetTextRise(p * chunk.Font.Size);
            }
            value = attributes[ElementTags.Generictag];
            if (value != null)
            {
                chunk.SetGenericTag(value);
            }
            value = attributes[ElementTags.BACKGROUNDCOLOR];
            if (value != null)
            {
                chunk.SetBackground(Markup.DecodeColor(value));
            }
            return(chunk);
        }
コード例 #10
0
        /**
         * This method isn't used by iText, but you can use it to analyze
         * the value of a style attribute inside a HashMap.
         * The different elements of the style attribute are added to the
         * HashMap as key-value pairs.
         * @param	h	a HashMap that should have at least a key named
         * style. After this method is invoked, more keys could be added.
         */
        public static void InsertStyle(Hashtable h)
        {
            String style = (String)h["style"];

            if (style == null)
            {
                return;
            }
            Properties prop = Markup.ParseAttributes(style);

            foreach (String key in prop.Keys)
            {
                if (key.Equals(Markup.CSS_KEY_FONTFAMILY))
                {
                    h["face"] = prop[key];
                }
                else if (key.Equals(Markup.CSS_KEY_FONTSIZE))
                {
                    h["size"] = Markup.ParseLength(prop[key]).ToString(NumberFormatInfo.InvariantInfo) + "pt";
                }
                else if (key.Equals(Markup.CSS_KEY_FONTSTYLE))
                {
                    String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
                    if (ss.Equals("italic") || ss.Equals("oblique"))
                    {
                        h["i"] = null;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_FONTWEIGHT))
                {
                    String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
                    if (ss.Equals("bold") || ss.Equals("700") || ss.Equals("800") || ss.Equals("900"))
                    {
                        h["b"] = null;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_TEXTDECORATION))
                {
                    String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
                    if (ss.Equals(Markup.CSS_VALUE_UNDERLINE))
                    {
                        h["u"] = null;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_COLOR))
                {
                    Color c = Markup.DecodeColor(prop[key]);
                    if (c != null)
                    {
                        int    hh = c.ToArgb() & 0xffffff;
                        String hs = "#" + hh.ToString("X06", NumberFormatInfo.InvariantInfo);
                        h["color"] = hs;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_LINEHEIGHT))
                {
                    String ss = prop[key].Trim();
                    float  v  = Markup.ParseLength(prop[key]);
                    if (ss.EndsWith("%"))
                    {
                        v           /= 100;
                        h["leading"] = "0," + v.ToString(NumberFormatInfo.InvariantInfo);
                    }
                    else if (Util.EqualsIgnoreCase("normal", ss))
                    {
                        h["leading"] = "0,1.5";
                    }
                    else
                    {
                        h["leading"] = v.ToString(NumberFormatInfo.InvariantInfo) + ",0";
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_TEXTALIGN))
                {
                    String ss = prop[key].Trim().ToLower(System.Globalization.CultureInfo.InvariantCulture);
                    h["align"] = ss;
                }
            }
        }
コード例 #11
0
        /**
         * New method contributed by Lubos Strapko
         * @param h
         * @param cprops
         * @since 2.1.3
         */
        public static void InsertStyle(Dictionary <string, string> h, ChainedProperties cprops)
        {
            String style;

            if (!h.TryGetValue("style", out style))
            {
                return;
            }
            Properties prop = Markup.ParseAttributes(style);

            foreach (String key in prop.Keys)
            {
                if (key.Equals(Markup.CSS_KEY_FONTFAMILY))
                {
                    h["face"] = prop[key];
                }
                else if (key.Equals(Markup.CSS_KEY_FONTSIZE))
                {
                    float actualFontSize = Markup.ParseLength(cprops[ElementTags.SIZE], Markup.DEFAULT_FONT_SIZE);
                    if (actualFontSize <= 0f)
                    {
                        actualFontSize = Markup.DEFAULT_FONT_SIZE;
                    }
                    h[ElementTags.SIZE] = Markup.ParseLength(prop[key], actualFontSize).ToString(NumberFormatInfo.InvariantInfo) + "pt";
                }
                else if (key.Equals(Markup.CSS_KEY_FONTSTYLE))
                {
                    String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
                    if (ss.Equals("italic") || ss.Equals("oblique"))
                    {
                        h["i"] = null;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_FONTWEIGHT))
                {
                    String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
                    if (ss.Equals("bold") || ss.Equals("700") || ss.Equals("800") || ss.Equals("900"))
                    {
                        h["b"] = null;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_TEXTDECORATION))
                {
                    String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
                    if (ss.Equals(Markup.CSS_VALUE_UNDERLINE))
                    {
                        h["u"] = null;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_COLOR))
                {
                    BaseColor c = Markup.DecodeColor(prop[key]);
                    if (c != null)
                    {
                        int    hh = c.ToArgb() & 0xffffff;
                        String hs = "#" + hh.ToString("X06", NumberFormatInfo.InvariantInfo);
                        h["color"] = hs;
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_LINEHEIGHT))
                {
                    String ss             = prop[key].Trim();
                    float  actualFontSize = Markup.ParseLength(cprops[ElementTags.SIZE], Markup.DEFAULT_FONT_SIZE);
                    if (actualFontSize <= 0f)
                    {
                        actualFontSize = Markup.DEFAULT_FONT_SIZE;
                    }
                    float v = Markup.ParseLength(prop[key], actualFontSize);
                    if (ss.EndsWith("%"))
                    {
                        v           /= 100;
                        h["leading"] = "0," + v.ToString(NumberFormatInfo.InvariantInfo);
                    }
                    else if (Util.EqualsIgnoreCase("normal", ss))
                    {
                        h["leading"] = "0,1.5";
                    }
                    else
                    {
                        h["leading"] = v.ToString(NumberFormatInfo.InvariantInfo) + ",0";
                    }
                }
                else if (key.Equals(Markup.CSS_KEY_TEXTALIGN))
                {
                    String ss = prop[key].Trim().ToLower(System.Globalization.CultureInfo.InvariantCulture);
                    h["align"] = ss;
                }
                else if (key.Equals(Markup.CSS_KEY_PADDINGLEFT))
                {
                    String ss = prop[key].Trim().ToLower(System.Globalization.CultureInfo.InvariantCulture);
                    h["indent"] = ss;
                }
            }
        }
コード例 #12
0
        public Font GetFont(ChainedProperties props)
        {
            String face = props[ElementTags.FACE];

            // try again, under the CSS key.
            //ISSUE: If both are present, we always go with face, even if font-family was
            //  defined more recently in our ChainedProperties.  One solution would go like this:
            //    Map all our supported style attributes to the 'normal' tag name, so we could
            //    look everything up under that one tag, retrieving the most current value.
            if (face == null || face.Trim().Length == 0)
            {
                face = props[Markup.CSS_KEY_FONTFAMILY];
            }
            if (face != null)
            {
                StringTokenizer tok = new StringTokenizer(face, ",");
                while (tok.HasMoreTokens())
                {
                    face = tok.NextToken().Trim();
                    if (face.StartsWith("\""))
                    {
                        face = face.Substring(1);
                    }
                    if (face.EndsWith("\""))
                    {
                        face = face.Substring(0, face.Length - 1);
                    }
                    if (fontImp.IsRegistered(face))
                    {
                        break;
                    }
                }
            }
            int    style   = 0;
            String textDec = props[Markup.CSS_KEY_TEXTDECORATION];

            if (textDec != null && textDec.Trim().Length != 0)
            {
                if (Markup.CSS_VALUE_UNDERLINE.Equals(textDec))
                {
                    style |= Font.UNDERLINE;
                }
                else if (Markup.CSS_VALUE_LINETHROUGH.Equals(textDec))
                {
                    style |= Font.STRIKETHRU;
                }
            }
            if (props.HasProperty(HtmlTags.I))
            {
                style |= Font.ITALIC;
            }
            if (props.HasProperty(HtmlTags.B))
            {
                style |= Font.BOLD;
            }
            if (props.HasProperty(HtmlTags.U))
            {
                style |= Font.UNDERLINE;
            }
            if (props.HasProperty(HtmlTags.S))
            {
                style |= Font.STRIKETHRU;
            }

            String value = props[ElementTags.SIZE];
            float  size  = 12;

            if (value != null)
            {
                size = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            BaseColor color    = Markup.DecodeColor(props["color"]);
            String    encoding = props["encoding"];

            if (encoding == null)
            {
                encoding = BaseFont.WINANSI;
            }
            return(fontImp.GetFont(face, encoding, true, size, style, color));
        }