/// <summary>
        /// The get image.
        /// </summary>
        /// <param name="src">The src.</param>
        /// <param name="attrs">The attrs.</param>
        /// <param name="chain">The chain.</param>
        /// <param name="doc">The doc.</param>
        /// <returns>
        /// The <see cref="Image" />.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">src</exception>
        /// <exception cref="ArgumentNullException">src</exception>
        public Image GetImage(string src, IDictionary<string, string> attrs, ChainedProperties chain, IDocListener doc)
        {
            if (string.IsNullOrWhiteSpace(src))
            {
                return null;
            }

            if (src.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                return this.GetImage(src);
            }

            if (HostingEnvironment.VirtualPathProvider.FileExists(src))
            {
                try
                {
                    UnifiedFile unifiedFile = HostingEnvironment.VirtualPathProvider.GetFile(src) as UnifiedFile;
                    return unifiedFile == null ? null : this.GetImage(unifiedFile.LocalPath);
                }
                catch (Exception exception)
                {
                    Logger.ErrorFormat(CultureInfo.InvariantCulture, "[OutputFormats] File not found for:'{0}'. \n {1}", src, exception);
                    return null;
                }
            }

            string baseurl = Settings.Instance.SiteUrl.GetLeftPart(UriPartial.Authority);
            src = string.Format(CultureInfo.InvariantCulture, "{0}{1}", baseurl, src);

            return this.GetImage(src);
        }
예제 #2
0
 public Image GetImage(String src, IDictionary<string,string> h, 
   ChainedProperties cprops, IDocListener doc)
 {
   return Image.GetInstance(Path.Combine(
     Utility.ResourcePosters,
     src.Substring(src.LastIndexOf("/") + 1)
   ));
 }    
예제 #3
0
 public Chunk CreateChunk(String text, ChainedProperties props) {
     Font font = GetFont(props);
     float size = font.Size;
     size /= 2;
     Chunk ck = new Chunk(text, font);
     if (props.HasProperty("sub"))
         ck.SetTextRise(-size);
     else if (props.HasProperty("sup"))
         ck.SetTextRise(size);
     ck.SetHyphenation(GetHyphenation(props));
     return ck;
 }
예제 #4
0
     /**
      * Creates a new instance of IncCell.
      * @param	tag		the cell that is wrapped in this object.
      * @param	chain	properties such as width
      * @since	5.0.6
      */
     public CellWrapper(String tag, ChainedProperties chain) {
         this.cell = CreatePdfPCell(tag, chain);
 	    String value = chain[HtmlTags.WIDTH];
         if (value != null) {
             value = value.Trim();
     	    if (value.EndsWith("%")) {
     		    percentage = true;
     		    value = value.Substring(0, value.Length - 1);
     	    }
             width = float.Parse(value, CultureInfo.InvariantCulture);
         }
     }
예제 #5
0
        public Chunk CreateChunk(string text, ChainedProperties props)
        {
            Font  font = GetFont(props);
            float size = font.Size;

            size /= 2;
            Chunk ck = new Chunk(text, font);

            if (props.HasProperty("sub"))
            {
                ck.SetTextRise(-size);
            }
            else if (props.HasProperty("sup"))
            {
                ck.SetTextRise(size);
            }
            ck.SetHyphenation(GetHyphenation(props));
            return(ck);
        }
예제 #6
0
        virtual public List CreateList(String tag, ChainedProperties chain)
        {
            List list;

            if (Util.EqualsIgnoreCase(HtmlTags.UL, tag))
            {
                list = new List(List.UNORDERED);
                list.SetListSymbol("\u2022 ");
            }
            else
            {
                list = new List(List.ORDERED);
            }
            try{
                list.IndentationLeft = float.Parse(chain[HtmlTags.INDENT], CultureInfo.InvariantCulture);
            }catch  {
                list.Autoindent = true;
            }
            return(list);
        }
예제 #7
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["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, System.Globalization.NumberFormatInfo.InvariantInfo);
     cell.BorderWidth = border;
     value = props["cellpadding"];
     if (value != null)
         cell.Padding = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
     cell.UseDescender = true;
     value = props["bgcolor"];
     cell.BackgroundColor = Markup.DecodeColor(value);
 }
            // alias: using iTextImage = iTextSharp.text.Image;
            public iTextImage GetImage(string src,
                IDictionary<string, string> attrs,
                ChainedProperties chain,
                IDocListener doc)
            {
                Match match;
                // [1]
                if ((match = Base64.Match(src)).Length > 0)
                {
                    return iTextImage.GetInstance(
                        Convert.FromBase64String(match.Groups["data"].Value)
                    );
                }

                // [2]
                if (!src.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    src = HttpContext.Current.Server.MapPath(
                        new Uri(new Uri(BaseUri), src).AbsolutePath
                    ); 
                }
                return iTextImage.GetInstance(src);
            }
예제 #9
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;
                }
            }
        }
예제 #10
0
 public Chunk CreateChunk(String text, ChainedProperties props)
 {
     Chunk ck = new Chunk(text, GetFont(props));
     if (props.HasProperty("sub"))
         ck.SetTextRise(-6);
     else if (props.HasProperty("sup"))
         ck.SetTextRise(6);
     return ck;
 }
예제 #11
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);
        }
예제 #12
0
 public List CreateList(String tag, ChainedProperties chain) {
     List list;
     if (Util.EqualsIgnoreCase(HtmlTags.UL, tag)) {
         list = new List(List.UNORDERED);
         list.SetListSymbol("\u2022 ");
     }
     else {
         list = new List(List.ORDERED);
     }
     try{
         list.IndentationLeft = float.Parse(chain[HtmlTags.INDENT], CultureInfo.InvariantCulture);
     }catch  {
         list.Autoindent = true;
     }
     return list;
 }
예제 #13
0
 /**
  * Gets a HyphenationEvent based on the hyphenation entry in
  * the hierarchy chain.
  * @param   chain   the hierarchy chain
  * @return  a HyphenationEvent
  * @since   2.1.2
  */
 public IHyphenationEvent GetHyphenation(ChainedProperties chain) {
     String value = chain[HtmlTags.HYPHENATION];
     // no hyphenation defined
     if (value == null || value.Length == 0) {
         return null;
     }
     // language code only
     int pos = value.IndexOf('_');
     if (pos == -1) {
         return new HyphenationAuto(value, null, 2, 2);
     }
     // language and country code
     String lang = value.Substring(0, pos);
     String country = value.Substring(pos + 1);
     // no leftMin or rightMin
     pos = country.IndexOf(',');
     if (pos == -1) {
         return new HyphenationAuto(lang, country, 2, 2);
     }
     // leftMin and rightMin value
     int leftMin;
     int rightMin = 2;
     value = country.Substring(pos + 1);
     country = country.Substring(0, pos);
     pos = value.IndexOf(',');
     if (pos == -1) {
         leftMin = int.Parse(value);
     } else {
         leftMin = int.Parse(value.Substring(0, pos));
         rightMin = int.Parse(value.Substring(pos + 1));
     }
     return new HyphenationAuto(lang, country, leftMin, rightMin);
 }
예제 #14
0
 /**
  * Creates an iText Paragraph object using the properties
  * of the different tags and properties in the hierarchy chain.
  * @param   chain   the hierarchy chain
  * @return  a ListItem without any content
  */
 public ListItem CreateListItem(ChainedProperties chain) {
     ListItem item = new ListItem();
     UpdateElement(item, chain);
     return item;
 }
예제 #15
0
 /**
  * Creates an iText Chunk
  * @param content the content of the Chunk
  * @param chain the hierarchy chain
  * @return a Chunk
  */
 public Chunk CreateChunk(String content, ChainedProperties chain) {
     Font font = GetFont(chain);
     Chunk ck = new Chunk(content, font);
     if (chain.HasProperty(HtmlTags.SUB))
         ck.SetTextRise(-font.Size / 2);
     else if (chain.HasProperty(HtmlTags.SUP))
         ck.SetTextRise(font.Size / 2);
     ck.SetHyphenation(GetHyphenation(chain));
     return ck;
 }
예제 #16
0
        /**
         * Creates a Font object based on a chain of properties.
         * @param   chain   chain of properties
         * @return  an iText Font object
         */
        virtual public Font GetFont(ChainedProperties chain)
        {
            // [1] font name

            String face = chain[HtmlTags.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 = chain[HtmlTags.FONTFAMILY];
            }
            // if the font consists of a comma separated list,
            // take the first font that is registered
            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 (provider.IsRegistered(face))
                    {
                        break;
                    }
                }
            }

            // [2] encoding
            String encoding = chain[HtmlTags.ENCODING];

            if (encoding == null)
            {
                encoding = BaseFont.WINANSI;
            }

            // [3] embedded

            // [4] font size
            String value = chain[HtmlTags.SIZE];
            float  size  = 12;

            if (value != null)
            {
                size = float.Parse(value, CultureInfo.InvariantCulture);
            }

            // [5] font style
            int style = 0;

            // text-decoration
            String decoration = chain[HtmlTags.TEXTDECORATION];

            if (decoration != null && decoration.Trim().Length != 0)
            {
                if (HtmlTags.UNDERLINE.Equals(decoration))
                {
                    style |= Font.UNDERLINE;
                }
                else if (HtmlTags.LINETHROUGH.Equals(decoration))
                {
                    style |= Font.STRIKETHRU;
                }
            }
            // italic
            if (chain.HasProperty(HtmlTags.I))
            {
                style |= Font.ITALIC;
            }
            // bold
            if (chain.HasProperty(HtmlTags.B))
            {
                style |= Font.BOLD;
            }
            // underline
            if (chain.HasProperty(HtmlTags.U))
            {
                style |= Font.UNDERLINE;
            }
            // strikethru
            if (chain.HasProperty(HtmlTags.S))
            {
                style |= Font.STRIKETHRU;
            }

            // [6] Color
            BaseColor color = HtmlUtilities.DecodeColor(chain[HtmlTags.COLOR]);

            // Get the font object from the provider
            return(provider.GetFont(face, encoding, true, size, style, color));
        }
예제 #17
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);
        }
예제 #18
0
 /**
 * Gets a HyphenationEvent based on the hyphenation entry in ChainedProperties.
 * @param    props   ChainedProperties
 * @return   a HyphenationEvent
 * @since    2.1.2
 */
 public static IHyphenationEvent GetHyphenation(ChainedProperties props) {
     return GetHyphenation(props["hyphenation"]);
 }
예제 #19
0
 public static ListItem CreateListItem(ChainedProperties props) {
     ListItem p = new ListItem();
     CreateParagraph(p, props);
     return p;
 }
예제 #20
0
 public static Paragraph CreateParagraph(ChainedProperties props) {
     Paragraph p = new Paragraph();
     CreateParagraph(p, props);
     return p;
 }
예제 #21
0
 public static void CreateParagraph(Paragraph p, ChainedProperties props) {
     String value = props["align"];
     if (value != null) {
         if (Util.EqualsIgnoreCase(value, "center"))
             p.Alignment = Element.ALIGN_CENTER;
         else if (Util.EqualsIgnoreCase(value, "right"))
             p.Alignment = Element.ALIGN_RIGHT;
         else if (Util.EqualsIgnoreCase(value, "justify"))
             p.Alignment = Element.ALIGN_JUSTIFIED;
     }
     p.Hyphenation = GetHyphenation(props);
     SetParagraphLeading(p, props["leading"]);
     value = props["before"];
     if (value != null) {
         try {
             p.SpacingBefore = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
         }
         catch {}
     }
     value = props["after"];
     if (value != null) {
         try {
             p.SpacingAfter = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
         }
         catch {}
     }
     value = props["extraparaspace"];
     if (value != null) {
         try {
             p.ExtraParagraphSpace = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
         }
         catch {}
     }
 }
예제 #22
0
        virtual public PdfPCell CreatePdfPCell(String tag, ChainedProperties chain)
        {
            PdfPCell cell = new PdfPCell((Phrase)null);
            // colspan
            String value = chain[HtmlTags.COLSPAN];

            if (value != null)
            {
                cell.Colspan = int.Parse(value);
            }
            // rowspan
            value = chain[HtmlTags.ROWSPAN];
            if (value != null)
            {
                cell.Rowspan = int.Parse(value);
            }
            // horizontal alignment
            if (tag.Equals(HtmlTags.TH))
            {
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
            }
            value = chain[HtmlTags.ALIGN];
            if (value != null)
            {
                cell.HorizontalAlignment = HtmlUtilities.AlignmentValue(value);
            }
            // vertical alignment
            value = chain[HtmlTags.VALIGN];
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;
            if (value != null)
            {
                cell.VerticalAlignment = HtmlUtilities.AlignmentValue(value);
            }
            // border
            value = chain[HtmlTags.BORDER];
            float border = 0;

            if (value != null)
            {
                border = float.Parse(value, CultureInfo.InvariantCulture);
            }
            cell.BorderWidth = border;

            // border buttom
            value = chain[HtmlTags.BORDERBUTTOM];
            if (value != null)
            {
                cell.BorderWidthBottom = float.Parse(value, CultureInfo.InvariantCulture);
            }

            // cellpadding
            value = chain[HtmlTags.CELLPADDING];
            if (value != null)
            {
                cell.Padding = float.Parse(value, CultureInfo.InvariantCulture);
            }
            cell.UseDescender = true;

            // background color
            value = chain[HtmlTags.BGCOLOR];
            cell.BackgroundColor = HtmlUtilities.DecodeColor(value);

            value = chain[HtmlTags.BORDERRADIUS];
            if (value != null)
            {
                float radius = float.Parse(value);
                value = chain[HtmlTags.BORDERCOLOR];
                if (value != null)
                {
                    cell.CellEvent = new RoundRectangle(radius, HtmlUtilities.DecodeColor(value));
                }
            }
            value = chain[HtmlTags.BORDERCOLOR];
            if (value != null)
            {
                cell.BorderColor = HtmlUtilities.DecodeColor(value);
            }
            return(cell);
        }
예제 #23
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);
            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);
        }
예제 #24
0
 /**
  * Method contributed by Lubos Strapko
  * @param h
  * @param chain
  * @since 2.1.3
  */
 public static void ResolveStyleAttribute(IDictionary<String, String> h, ChainedProperties chain) {
     String style;
     h.TryGetValue(HtmlTags.STYLE, out style);
     if (style == null)
         return;
     Properties prop = HtmlUtilities.ParseAttributes(style);
     foreach (string key in prop.Keys) {
         if (key.Equals(HtmlTags.FONTFAMILY)) {
             h[HtmlTags.FACE] = prop[key];
         } else if (key.Equals(HtmlTags.FONTSIZE)) {
             float actualFontSize = HtmlUtilities.ParseLength(chain[HtmlTags.SIZE],
                     HtmlUtilities.DEFAULT_FONT_SIZE);
             if (actualFontSize <= 0f)
                 actualFontSize = HtmlUtilities.DEFAULT_FONT_SIZE;
             h[HtmlTags.SIZE] = HtmlUtilities.ParseLength(prop[key], actualFontSize).ToString(CultureInfo.InvariantCulture) + "pt";
         } else if (key.Equals(HtmlTags.FONTSTYLE)) {
             String ss = prop[key].Trim().ToLowerInvariant();
             if (ss.Equals(HtmlTags.ITALIC) || ss.Equals(HtmlTags.OBLIQUE))
                 h[HtmlTags.I] = null;
         } else if (key.Equals(HtmlTags.FONTWEIGHT)) {
             String ss = prop[key].Trim().ToLowerInvariant();
             if (ss.Equals(HtmlTags.BOLD) || ss.Equals("700") || ss.Equals("800")
                     || ss.Equals("900"))
                 h[HtmlTags.B] = null;
         } else if (key.Equals(HtmlTags.TEXTDECORATION)) {
             String ss = prop[key].Trim().ToLowerInvariant();
             if (ss.Equals(HtmlTags.UNDERLINE))
                 h[HtmlTags.U] = null;
         } else if (key.Equals(HtmlTags.COLOR)) {
             BaseColor c = HtmlUtilities.DecodeColor(prop[key]);
             if (c != null) {
                 int hh = c.ToArgb();
                 String hs = hh.ToString("x");
                 hs = "000000" + hs;
                 hs = "#" + hs.Substring(hs.Length - 6);
                 h[HtmlTags.COLOR] = hs;
             }
         } else if (key.Equals(HtmlTags.LINEHEIGHT)) {
             String ss = prop[key].Trim();
             float actualFontSize = HtmlUtilities.ParseLength(chain[HtmlTags.SIZE],
                     HtmlUtilities.DEFAULT_FONT_SIZE);
             if (actualFontSize <= 0f)
                 actualFontSize = HtmlUtilities.DEFAULT_FONT_SIZE;
             float v = HtmlUtilities.ParseLength(prop[key],
                     actualFontSize);
             if (ss.EndsWith("%")) {
                 h[HtmlTags.LEADING] = "0," + v / 100;
                 return;
             }
             if (Util.EqualsIgnoreCase(HtmlTags.NORMAL, ss)) {
                 h[HtmlTags.LEADING] = "0,1.5";
                 return;
             }
             h[HtmlTags.LEADING] = v + ",0";
         } else if (key.Equals(HtmlTags.TEXTALIGN)) {
             String ss = prop[key].Trim().ToLowerInvariant();
             h[HtmlTags.ALIGN] = ss;
         } else if (key.Equals(HtmlTags.PADDINGLEFT)) {
             String ss = prop[key].Trim().ToLowerInvariant();
             h[HtmlTags.INDENT] = HtmlUtilities.ParseLength(ss).ToString(CultureInfo.InvariantCulture);
         }
     }
 }
예제 #25
0
            public iTextSharp.text.Image GetImage(string src,
                IDictionary<string, string> h,
                ChainedProperties cprops,
                IDocListener doc
            )
            {
                string imgPath = src;

                if (src.ToLower().Contains("http://") == false)
                    imgPath = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + src;

                return iTextSharp.text.Image.GetInstance(imgPath);
            }
예제 #26
0
        /**
         * Method contributed by Lubos Strapko
         * @param h
         * @param chain
         * @since 2.1.3
         */
        public static void ResolveStyleAttribute(IDictionary <String, String> h, ChainedProperties chain)
        {
            String style;

            h.TryGetValue(HtmlTags.STYLE, out style);
            if (style == null)
            {
                return;
            }
            Properties prop = HtmlUtilities.ParseAttributes(style);

            foreach (string key in prop.Keys)
            {
                if (key.Equals(HtmlTags.FONTFAMILY))
                {
                    h[HtmlTags.FACE] = prop[key];
                }
                else if (key.Equals(HtmlTags.FONTSIZE))
                {
                    float actualFontSize = HtmlUtilities.ParseLength(chain[HtmlTags.SIZE],
                                                                     HtmlUtilities.DEFAULT_FONT_SIZE);
                    if (actualFontSize <= 0f)
                    {
                        actualFontSize = HtmlUtilities.DEFAULT_FONT_SIZE;
                    }
                    h[HtmlTags.SIZE] = HtmlUtilities.ParseLength(prop[key], actualFontSize).ToString(CultureInfo.InvariantCulture) + "pt";
                }
                else if (key.Equals(HtmlTags.FONTSTYLE))
                {
                    String ss = prop[key].Trim().ToLowerInvariant();
                    if (ss.Equals(HtmlTags.ITALIC) || ss.Equals(HtmlTags.OBLIQUE))
                    {
                        h[HtmlTags.I] = null;
                    }
                }
                else if (key.Equals(HtmlTags.FONTWEIGHT))
                {
                    String ss = prop[key].Trim().ToLowerInvariant();
                    if (ss.Equals(HtmlTags.BOLD) || ss.Equals("700") || ss.Equals("800") ||
                        ss.Equals("900"))
                    {
                        h[HtmlTags.B] = null;
                    }
                }
                else if (key.Equals(HtmlTags.TEXTDECORATION))
                {
                    String ss = prop[key].Trim().ToLowerInvariant();
                    if (ss.Equals(HtmlTags.UNDERLINE))
                    {
                        h[HtmlTags.U] = null;
                    }
                }
                else if (key.Equals(HtmlTags.COLOR))
                {
                    BaseColor c = HtmlUtilities.DecodeColor(prop[key]);
                    if (c != null)
                    {
                        int    hh = c.ToArgb();
                        String hs = hh.ToString("x");
                        hs = "000000" + hs;
                        hs = "#" + hs.Substring(hs.Length - 6);
                        h[HtmlTags.COLOR] = hs;
                    }
                }
                else if (key.Equals(HtmlTags.LINEHEIGHT))
                {
                    String ss             = prop[key].Trim();
                    float  actualFontSize = HtmlUtilities.ParseLength(chain[HtmlTags.SIZE],
                                                                      HtmlUtilities.DEFAULT_FONT_SIZE);
                    if (actualFontSize <= 0f)
                    {
                        actualFontSize = HtmlUtilities.DEFAULT_FONT_SIZE;
                    }
                    float v = HtmlUtilities.ParseLength(prop[key],
                                                        actualFontSize);
                    if (ss.EndsWith("%"))
                    {
                        h[HtmlTags.LEADING] = "0," + v / 100;
                        return;
                    }
                    if (Util.EqualsIgnoreCase(HtmlTags.NORMAL, ss))
                    {
                        h[HtmlTags.LEADING] = "0,1.5";
                        return;
                    }
                    h[HtmlTags.LEADING] = v + ",0";
                }
                else if (key.Equals(HtmlTags.TEXTALIGN))
                {
                    String ss = prop[key].Trim().ToLowerInvariant();
                    h[HtmlTags.ALIGN] = ss;
                }
                else if (key.Equals(HtmlTags.PADDINGLEFT))
                {
                    String ss = prop[key].Trim().ToLowerInvariant();
                    h[HtmlTags.INDENT] = HtmlUtilities.ParseLength(ss).ToString(CultureInfo.InvariantCulture);
                }
            }
        }
예제 #27
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;
                }
            }
        }
예제 #28
0
 /**
  * Creates an iText Paragraph object using the properties
  * of the different tags and properties in the hierarchy chain.
  * @param   chain   the hierarchy chain
  * @return  a Paragraph without any content
  */
 public Paragraph CreateParagraph(ChainedProperties chain) {
     Paragraph paragraph = new Paragraph();
     UpdateElement(paragraph, chain);
     return paragraph;
 }
예제 #29
0
        /**
         * Creates a PdfPCell element based on a tag and its properties.
         * @param	tag		a cell tag
         * @param	chain	the hierarchy chain
         */
	    virtual public PdfPCell CreatePdfPCell(String tag, ChainedProperties chain) {
		    PdfPCell cell = new PdfPCell((Phrase)null);
            // colspan
		    String value = chain[HtmlTags.COLSPAN];
            if (value != null)
                cell.Colspan = int.Parse(value);
            // rowspan
            value = chain[HtmlTags.ROWSPAN];
            if (value != null)
                cell.Rowspan = int.Parse(value);
            // horizontal alignment
            if (tag.Equals(HtmlTags.TH))
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
            value = chain[HtmlTags.ALIGN];
            if (value != null) {
                cell.HorizontalAlignment = HtmlUtilities.AlignmentValue(value);
            }
            // vertical alignment
            value = chain[HtmlTags.VALIGN];
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;
            if (value != null) {
                cell.VerticalAlignment = HtmlUtilities.AlignmentValue(value);
            }
            // border
            value = chain[HtmlTags.BORDER];
            float border = 0;
            if (value != null)
                border = float.Parse(value, CultureInfo.InvariantCulture);
            cell.BorderWidth = border;
            // cellpadding
            value = chain[HtmlTags.CELLPADDING];
            if (value != null)
                cell.Padding = float.Parse(value, CultureInfo.InvariantCulture);
            cell.UseDescender = true;
            // background color
            value = chain[HtmlTags.BGCOLOR];
            cell.BackgroundColor = HtmlUtilities.DecodeColor(value);
            return cell;
	    }
예제 #30
0
 /**
  * Method that does the actual Element creating for
  * the createParagraph and createListItem method.
  * @param paragraph
  * @param chain
  */
 protected void UpdateElement(Paragraph paragraph, ChainedProperties chain) {
     // Alignment
     String value = chain[HtmlTags.ALIGN];
     paragraph.Alignment = HtmlUtilities.AlignmentValue(value);
     // hyphenation
     paragraph.Hyphenation = GetHyphenation(chain);
     // leading
     SetParagraphLeading(paragraph, chain[HtmlTags.LEADING]);
     // spacing before
     value = chain[HtmlTags.AFTER];
     if (value != null) {
         try {
             paragraph.SpacingBefore = float.Parse(value, CultureInfo.InvariantCulture);
         } catch {
         }
     }
     // spacing after
     value = chain[HtmlTags.AFTER];
     if (value != null) {
         try {
             paragraph.SpacingAfter = float.Parse(value, CultureInfo.InvariantCulture);
         } catch {
         }
     }
     // extra paragraph space
     value = chain[HtmlTags.EXTRAPARASPACE];
     if (value != null) {
         try {
             paragraph.ExtraParagraphSpace = float.Parse(value, CultureInfo.InvariantCulture);
         } catch {
         }
     }
     // indentation
     value = chain[HtmlTags.INDENT];
     if (value != null) {
         try {
             paragraph.IndentationLeft = float.Parse(value, CultureInfo.InvariantCulture);
         } catch {
         }
     }
 }
        /// <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;
                }
            }
        }
예제 #32
0
 public Image CreateImage(
         String src,
         IDictionary<String, String> attrs,
         ChainedProperties chain,
         IDocListener document,
         IImageProvider img_provider,
         Dictionary<String, Image> img_store,
         String img_baseurl) {
     Image img = null;
     // getting the image using an image provider
     if (img_provider != null)
         img = img_provider.GetImage(src, attrs, chain, document);
     // getting the image from an image store
     if (img == null && img_store != null) {
         Image tim;
         img_store.TryGetValue(src, out tim);
         if (tim != null)
             img = Image.GetInstance(tim);
     }
     if (img != null)
         return img;
     // introducing a base url
     // relative src references only
     if (!src.StartsWith("http") && img_baseurl != null) {
         src = img_baseurl + src;
     }
     else if (img == null && !src.StartsWith("http")) {
         String path = chain[HtmlTags.IMAGEPATH];
         if (path == null)
             path = "";
         src = Path.Combine(path, src);
     }
     img = Image.GetInstance(src);
     if (img == null)
         return null;
     
     float actualFontSize = HtmlUtilities.ParseLength(
         chain[HtmlTags.SIZE],
         HtmlUtilities.DEFAULT_FONT_SIZE);
     if (actualFontSize <= 0f)
         actualFontSize = HtmlUtilities.DEFAULT_FONT_SIZE;
     String width;
     attrs.TryGetValue(HtmlTags.WIDTH, out width);
     float widthInPoints = HtmlUtilities.ParseLength(width, actualFontSize);
     String height;
     attrs.TryGetValue(HtmlTags.HEIGHT, out height);
     float heightInPoints = HtmlUtilities.ParseLength(height, actualFontSize);
     if (widthInPoints > 0 && heightInPoints > 0) {
         img.ScaleAbsolute(widthInPoints, heightInPoints);
     } else if (widthInPoints > 0) {
         heightInPoints = img.Height * widthInPoints
                 / img.Width;
         img.ScaleAbsolute(widthInPoints, heightInPoints);
     } else if (heightInPoints > 0) {
         widthInPoints = img.Width * heightInPoints
                 / img.Height;
         img.ScaleAbsolute(widthInPoints, heightInPoints);
     }
     
     String before = chain[HtmlTags.BEFORE];
     if (before != null)
         img.SpacingBefore = float.Parse(before, CultureInfo.InvariantCulture);
     String after = chain[HtmlTags.AFTER];
     if (after != null)
         img.SpacingAfter = float.Parse(after, CultureInfo.InvariantCulture);
     img.WidthPercentage = 0;
     return img;
 }
예제 #33
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));
        }
예제 #34
0
 /**
  * Creates a Font object based on a chain of properties.
  * @param   chain   chain of properties
  * @return  an iText Font object
  */
 public Font GetFont(ChainedProperties chain) {
     
     // [1] font name
     
     String face = chain[HtmlTags.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 = chain[HtmlTags.FONTFAMILY];
     }
     // if the font consists of a comma separated list,
     // take the first font that is registered
     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 (provider.IsRegistered(face))
                 break;
         }
     }
     
     // [2] encoding
     String encoding = chain[HtmlTags.ENCODING];
     if (encoding == null)
         encoding = BaseFont.WINANSI;
     
     // [3] embedded
     
     // [4] font size
     String value = chain[HtmlTags.SIZE];
     float size = 12;
     if (value != null)
         size = float.Parse(value, CultureInfo.InvariantCulture);
     
     // [5] font style
     int style = 0;
     
     // text-decoration
     String decoration = chain[HtmlTags.TEXTDECORATION];
     if (decoration != null && decoration.Trim().Length != 0) {
       if (HtmlTags.UNDERLINE.Equals(decoration)) {
         style |= Font.UNDERLINE;
       } else if (HtmlTags.LINETHROUGH.Equals(decoration)) {
         style |= Font.STRIKETHRU;
       }
     }
     // italic
     if (chain.HasProperty(HtmlTags.I))
         style |= Font.ITALIC;
     // bold
     if (chain.HasProperty(HtmlTags.B))
         style |= Font.BOLD;
     // underline
     if (chain.HasProperty(HtmlTags.U))
         style |= Font.UNDERLINE;
     // strikethru
     if (chain.HasProperty(HtmlTags.S))
         style |= Font.STRIKETHRU;
     
     // [6] Color
     BaseColor color = HtmlUtilities.DecodeColor(chain[HtmlTags.COLOR]);
     
     // Get the font object from the provider
     return provider.GetFont(face, encoding, true, size, style, color);
 }
예제 #35
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, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            cell.BorderWidth = border;
            value            = props["cellpadding"];
            if (value != null)
            {
                cell.Padding = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            cell.UseDescender    = true;
            value                = props["bgcolor"];
            cell.BackgroundColor = Markup.DecodeColor(value);
        }
 /// <summary>
 /// Gets a HyphenationEvent based on the hyphenation entry in ChainedProperties.
 /// @since    2.1.2
 /// </summary>
 /// <param name="props">ChainedProperties</param>
 /// <returns>a HyphenationEvent</returns>
 public static IHyphenationEvent GetHyphenation(ChainedProperties props) => GetHyphenation(props["hyphenation"]);
예제 #37
0
        virtual public Image CreateImage(
            String src,
            IDictionary <String, String> attrs,
            ChainedProperties chain,
            IDocListener document,
            IImageProvider img_provider,
            Dictionary <String, Image> img_store,
            String img_baseurl)
        {
            Image img = null;

            // getting the image using an image provider
            if (img_provider != null)
            {
                img = img_provider.GetImage(src, attrs, chain, document);
            }
            // getting the image from an image store
            if (img == null && img_store != null)
            {
                Image tim;
                img_store.TryGetValue(src, out tim);
                if (tim != null)
                {
                    img = Image.GetInstance(tim);
                }
            }
            if (img != null)
            {
                return(img);
            }
            // introducing a base url
            // relative src references only
            if (!src.StartsWith("http") && img_baseurl != null)
            {
                src = img_baseurl + src;
            }
            else if (img == null && !src.StartsWith("http"))
            {
                String path = chain[HtmlTags.IMAGEPATH];
                if (path == null)
                {
                    path = "";
                }
                src = Path.Combine(path, src);
            }
            img = Image.GetInstance(src);
            if (img == null)
            {
                return(null);
            }

            float actualFontSize = HtmlUtilities.ParseLength(
                chain[HtmlTags.SIZE],
                HtmlUtilities.DEFAULT_FONT_SIZE);

            if (actualFontSize <= 0f)
            {
                actualFontSize = HtmlUtilities.DEFAULT_FONT_SIZE;
            }
            String width;

            attrs.TryGetValue(HtmlTags.WIDTH, out width);
            float  widthInPoints = HtmlUtilities.ParseLength(width, actualFontSize);
            String height;

            attrs.TryGetValue(HtmlTags.HEIGHT, out height);
            float heightInPoints = HtmlUtilities.ParseLength(height, actualFontSize);

            if (widthInPoints > 0 && heightInPoints > 0)
            {
                img.ScaleAbsolute(widthInPoints, heightInPoints);
            }
            else if (widthInPoints > 0)
            {
                heightInPoints = img.Height * widthInPoints
                                 / img.Width;
                img.ScaleAbsolute(widthInPoints, heightInPoints);
            }
            else if (heightInPoints > 0)
            {
                widthInPoints = img.Width * heightInPoints
                                / img.Height;
                img.ScaleAbsolute(widthInPoints, heightInPoints);
            }

            String before = chain[HtmlTags.BEFORE];

            if (before != null)
            {
                img.SpacingBefore = float.Parse(before, CultureInfo.InvariantCulture);
            }
            String after = chain[HtmlTags.AFTER];

            if (after != null)
            {
                img.SpacingAfter = float.Parse(after, CultureInfo.InvariantCulture);
            }
            img.WidthPercentage = 0;
            return(img);
        }
        public Font GetFont(ChainedProperties props)
        {
            var face = props[ElementTags.FACE];

            if (face != null)
            {
                var 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;
                    }
                }
            }
            var 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;
            }

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

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

            var color    = Markup.DecodeColor(props["color"]);
            var encoding = props["encoding"];

            if (encoding == null)
            {
                encoding = BaseFont.WINANSI;
            }

            return(FontImp.GetFont(face, encoding, true, size, style, color));
        }
예제 #39
0
 /**
  * Gets a HyphenationEvent based on the hyphenation entry in ChainedProperties.
  * @param    props   ChainedProperties
  * @return   a HyphenationEvent
  * @since    2.1.2
  */
 public static IHyphenationEvent GetHyphenation(ChainedProperties props)
 {
     return(GetHyphenation(props["hyphenation"]));
 }