예제 #1
0
        /**
         * Constructs a <CODE>PdfChunk</CODE>-object.
         *
         * @param chunk the original <CODE>Chunk</CODE>-object
         * @param action the <CODE>PdfAction</CODE> if the <CODE>Chunk</CODE> comes from an <CODE>Anchor</CODE>
         */

        internal PdfChunk(Chunk chunk, PdfAction action)
        {
            value = chunk.Content;

            iTextSharp.text.Font f = chunk.Font;
            float size             = f.Size;

            if (size == iTextSharp.text.Font.UNDEFINED)
            {
                size = 12;
            }
            BaseFont bf = f.BaseFont;
            int      family;
            int      style = f.Style;

            if (bf == null)
            {
                // translation of the font-family to a PDF font-family
                if (style == iTextSharp.text.Font.UNDEFINED)
                {
                    style = iTextSharp.text.Font.NORMAL;
                }
                switch (f.Family)
                {
                case iTextSharp.text.Font.COURIER:
                    switch (style & iTextSharp.text.Font.BOLDITALIC)
                    {
                    case iTextSharp.text.Font.BOLD:
                        family = PdfFont.COURIER_BOLD;
                        break;

                    case iTextSharp.text.Font.ITALIC:
                        family = PdfFont.COURIER_OBLIQUE;
                        break;

                    case iTextSharp.text.Font.BOLDITALIC:
                        family = PdfFont.COURIER_BOLDOBLIQUE;
                        break;

                    default:
                    case iTextSharp.text.Font.NORMAL:
                        family = PdfFont.COURIER;
                        break;
                    }
                    break;

                case iTextSharp.text.Font.TIMES_NEW_ROMAN:
                    switch (style & iTextSharp.text.Font.BOLDITALIC)
                    {
                    case iTextSharp.text.Font.BOLD:
                        family = PdfFont.TIMES_BOLD;
                        break;

                    case iTextSharp.text.Font.ITALIC:
                        family = PdfFont.TIMES_ITALIC;
                        break;

                    case iTextSharp.text.Font.BOLDITALIC:
                        family = PdfFont.TIMES_BOLDITALIC;
                        break;

                    default:
                    case iTextSharp.text.Font.NORMAL:
                        family = PdfFont.TIMES_ROMAN;
                        break;
                    }
                    break;

                case iTextSharp.text.Font.SYMBOL:
                    family = PdfFont.SYMBOL;
                    break;

                case iTextSharp.text.Font.ZAPFDINGBATS:
                    family = PdfFont.ZAPFDINGBATS;
                    break;

                default:
                case iTextSharp.text.Font.HELVETICA:
                    switch (style & iTextSharp.text.Font.BOLDITALIC)
                    {
                    case iTextSharp.text.Font.BOLD:
                        family = PdfFont.HELVETICA_BOLD;
                        break;

                    case iTextSharp.text.Font.ITALIC:
                        family = PdfFont.HELVETICA_OBLIQUE;
                        break;

                    case iTextSharp.text.Font.BOLDITALIC:
                        family = PdfFont.HELVETICA_BOLDOBLIQUE;
                        break;

                    default:
                    case iTextSharp.text.Font.NORMAL:
                        family = PdfFont.HELVETICA;
                        break;
                    }
                    break;
                }
                // creation of the PdfFont with the right size
                font = new PdfFont(family, size);
            }
            else
            {
                // bold simulation
                if ((style & iTextSharp.text.Font.BOLD) != 0)
                {
                    attributes.Add(Chunk.TEXTRENDERMODE, new Object[] { PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, size / 30f, null });
                }
                // italic simulation
                if ((style & iTextSharp.text.Font.ITALIC) != 0)
                {
                    attributes.Add(Chunk.SKEW, new float[] { 0, ITALIC_ANGLE });
                }

                font = new PdfFont(bf, size);
            }



            // other style possibilities
            Hashmap attr = chunk.Attributes;

            if (attr != null)
            {
                foreach (string name in attr.Keys)
                {
                    if (keysAttributes.ContainsKey(name))
                    {
                        attributes.Add(name, attr[name]);
                    }
                    else if (keysNoStroke.ContainsKey(name))
                    {
                        noStroke.Add(name, attr[name]);
                    }
                }
                if ("".Equals(attr[Chunk.GENERICTAG]))
                {
                    attributes.Add(Chunk.GENERICTAG, chunk.Content);
                }
            }
            if (f.isUnderlined())
            {
                attributes.Add(Chunk.UNDERLINE, null);
            }
            if (f.isStrikethru())
            {
                attributes.Add(Chunk.STRIKETHRU, null);
            }
            if (action != null)
            {
                attributes.Add(Chunk.ACTION, action);
            }
            // the color can't be stored in a PdfFont
            noStroke.Add(Chunk.COLOR, f.Color);
            noStroke.Add(Chunk.ENCODING, font.Font.Encoding);
            Object[] obj = (Object[])attributes[Chunk.IMAGE];
            if (obj == null)
            {
                image = null;
            }
            else
            {
                image         = (Image)obj[0];
                offsetX       = ((float)obj[1]);
                offsetY       = ((float)obj[2]);
                changeLeading = bool.Parse(obj[3].ToString());
            }
            font.Image     = image;
            encoding       = font.Font.Encoding;
            splitCharacter = (ISplitCharacter)noStroke[Chunk.SPLITCHARACTER];
            if (splitCharacter == null)
            {
                splitCharacter = this;
            }
        }