Beispiel #1
0
        internal override void WriteFont(PdfWriter writer, PdfIndirectReference piRef, Object[] oParams)
        {
            if (this.writer != writer)
            {
                throw new ArgumentException("Type3 font used with the wrong PdfWriter");
            }
            // Get first & lastchar ...
            int firstChar = 0;

            while (firstChar < usedSlot.Length && !usedSlot[firstChar])
            {
                firstChar++;
            }

            if (firstChar == usedSlot.Length)
            {
                throw new DocumentException("No glyphs defined for Type3 font");
            }
            int lastChar = usedSlot.Length - 1;

            while (lastChar >= firstChar && !usedSlot[lastChar])
            {
                lastChar--;
            }

            int[] widths = new int[lastChar - firstChar + 1];
            int[] invOrd = new int[lastChar - firstChar + 1];

            int invOrdIndx = 0, w = 0;

            for (int u = firstChar; u <= lastChar; u++, w++)
            {
                if (usedSlot[u])
                {
                    invOrd[invOrdIndx++] = u;
                    widths[w]            = widths3[u];
                }
            }
            PdfArray      diffs     = new PdfArray();
            PdfDictionary charprocs = new PdfDictionary();
            int           last      = -1;

            for (int k = 0; k < invOrdIndx; ++k)
            {
                int c = invOrd[k];
                if (c > last)
                {
                    last = c;
                    diffs.Add(new PdfNumber(last));
                }
                ++last;
                int    c2 = invOrd[k];
                String s  = GlyphList.UnicodeToName(c2);
                if (s == null)
                {
                    s = "a" + c2;
                }
                PdfName n = new PdfName(s);
                diffs.Add(n);
                Type3Glyph glyph  = (Type3Glyph)char2glyph[(char)c2];
                PdfStream  stream = new PdfStream(glyph.ToPdf(null));
                stream.FlateCompress(compressionLevel);
                PdfIndirectReference refp = writer.AddToBody(stream).IndirectReference;
                charprocs.Put(n, refp);
            }
            PdfDictionary font = new PdfDictionary(PdfName.FONT);

            font.Put(PdfName.SUBTYPE, PdfName.TYPE3);
            if (colorized)
            {
                font.Put(PdfName.FONTBBOX, new PdfRectangle(0, 0, 0, 0));
            }
            else
            {
                font.Put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury));
            }
            font.Put(PdfName.FONTMATRIX, new PdfArray(new float[] { 0.001f, 0, 0, 0.001f, 0, 0 }));
            font.Put(PdfName.CHARPROCS, writer.AddToBody(charprocs).IndirectReference);
            PdfDictionary encoding = new PdfDictionary();

            encoding.Put(PdfName.DIFFERENCES, diffs);
            font.Put(PdfName.ENCODING, writer.AddToBody(encoding).IndirectReference);
            font.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar));
            font.Put(PdfName.LASTCHAR, new PdfNumber(lastChar));
            font.Put(PdfName.WIDTHS, writer.AddToBody(new PdfArray(widths)).IndirectReference);
            if (pageResources.HasResources())
            {
                font.Put(PdfName.RESOURCES, writer.AddToBody(pageResources.Resources).IndirectReference);
            }
            writer.AddToBody(font, piRef);
        }
Beispiel #2
0
            public void AlterContents()
            {
                if (over == null && under == null)
                {
                    return;
                }
                PdfArray  ar      = null;
                PdfObject content = PdfReader.GetPdfObject(pageN.Get(PdfName.CONTENTS), pageN);

                if (content == null)
                {
                    ar = new PdfArray();
                    pageN.Put(PdfName.CONTENTS, ar);
                }
                else if (content.IsArray())
                {
                    ar = (PdfArray)content;
                }
                else if (content.IsStream())
                {
                    ar = new PdfArray();
                    ar.Add(pageN.Get(PdfName.CONTENTS));
                    pageN.Put(PdfName.CONTENTS, ar);
                }
                else
                {
                    ar = new PdfArray();
                    pageN.Put(PdfName.CONTENTS, ar);
                }
                ByteBuffer out_p = new ByteBuffer();

                if (under != null)
                {
                    out_p.Append(PdfContents.SAVESTATE);
                    ApplyRotation(pageN, out_p);
                    out_p.Append(under.InternalBuffer);
                    out_p.Append(PdfContents.RESTORESTATE);
                }
                if (over != null)
                {
                    out_p.Append(PdfContents.SAVESTATE);
                }
                PdfStream stream = new PdfStream(out_p.ToByteArray());

                stream.FlateCompress(cstp.CompressionLevel);
                PdfIndirectReference ref1 = cstp.AddToBody(stream).IndirectReference;

                ar.AddFirst(ref1);
                out_p.Reset();
                if (over != null)
                {
                    out_p.Append(' ');
                    out_p.Append(PdfContents.RESTORESTATE);
                    out_p.Append(PdfContents.SAVESTATE);
                    ApplyRotation(pageN, out_p);
                    out_p.Append(over.InternalBuffer);
                    out_p.Append(PdfContents.RESTORESTATE);
                    stream = new PdfStream(out_p.ToByteArray());
                    stream.FlateCompress(cstp.CompressionLevel);
                    ar.Add(cstp.AddToBody(stream).IndirectReference);
                }
                pageN.Put(PdfName.RESOURCES, pageResources.Resources);
            }