Beispiel #1
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);
 }
Beispiel #2
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);
        }
 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;
 }
        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, 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);
        }
 /**
 * 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"]);
 }
 /**
 * New method contributed by Lubos Strapko
 * @param h
 * @param cprops
 * @since 2.1.3
 */
 public static void InsertStyle(Hashtable h, ChainedProperties cprops)
 {
     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)) {
             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)) {
             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 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(CultureInfo.InvariantCulture);
             h["align"] = ss;
         } else if (key.Equals(Markup.CSS_KEY_PADDINGLEFT)) {
             String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
             h["indent"] = ss;
         }
     }
 }
 public static Paragraph CreateParagraph(ChainedProperties props)
 {
     Paragraph p = new Paragraph();
     CreateParagraph(p, props);
     return p;
 }
 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, NumberFormatInfo.InvariantInfo);
         }
         catch {}
     }
     value = props["after"];
     if (value != null) {
         try {
             p.SpacingAfter = float.Parse(value, NumberFormatInfo.InvariantInfo);
         }
         catch {}
     }
     value = props["extraparaspace"];
     if (value != null) {
         try {
             p.ExtraParagraphSpace = float.Parse(value, NumberFormatInfo.InvariantInfo);
         }
         catch {}
     }
 }
 public static ListItem CreateListItem(ChainedProperties props)
 {
     ListItem p = new ListItem();
     CreateParagraph(p, props);
     return p;
 }
Beispiel #10
0
        /**
         * New method contributed by Lubos Strapko
         * @param h
         * @param cprops
         * @since 2.1.3
         */
        public static void InsertStyle(Hashtable h, ChainedProperties cprops)
        {
            String 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))
                {
                    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))
                {
                    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  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(CultureInfo.InvariantCulture);
                    h["align"] = ss;
                }
                else if (key.Equals(Markup.CSS_KEY_PADDINGLEFT))
                {
                    String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture);
                    h["indent"] = ss;
                }
            }
        }
Beispiel #11
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"]));
 }