コード例 #1
0
        /** Outputs to the writer the font dictionaries and streams.
         * @param writer the writer for this document
         * @param ref the font indirect reference
         * @param parms several parameters that depend on the font type
         * @throws IOException on error
         * @throws DocumentException error in generating the object
         */
        internal override void writeFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms)
        {
            Hashmap   longTag = (Hashmap)parms[0];
            ArrayList tmp     = new ArrayList();

            foreach (object o in longTag.Values)
            {
                tmp.Add(o);
            }
            Object[] metrics = tmp.ToArray();
            Array.Sort(metrics, this);
            PdfIndirectReference ind_font = null;
            PdfObject            pobj     = null;
            PdfIndirectObject    obj      = null;
            TrueTypeFontSubSet   sb       = new TrueTypeFontSubSet(fileName, rf, longTag, directoryOffset, false);

            byte[] b       = sb.process();
            int[]  lengths = new int[] { b.Length };
            pobj     = new StreamFont(b, lengths);
            obj      = writer.addToBody(pobj);
            ind_font = obj.IndirectReference;
            string        subsetPrefix = createSubsetPrefix();
            PdfDictionary dic          = getFontDescriptor(ind_font, subsetPrefix);

            obj      = writer.addToBody(dic);
            ind_font = obj.IndirectReference;

            pobj     = getCIDFontType2(ind_font, subsetPrefix, metrics);
            obj      = writer.addToBody(pobj);
            ind_font = obj.IndirectReference;

            pobj = getToUnicode(metrics);
            PdfIndirectReference toUnicodeRef = null;

            if (pobj != null)
            {
                obj          = writer.addToBody(pobj);
                toUnicodeRef = obj.IndirectReference;
            }

            pobj = getFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
            writer.addToBody(pobj, piref);
        }
コード例 #2
0
ファイル: TrueTypeFont.cs プロジェクト: bmictech/iTextSharp
 /** Outputs to the writer the font dictionaries and streams.
  * @param writer the writer for this document
  * @param ref the font indirect reference
  * @param params several parameters that depend on the font type
  * @throws IOException on error
  * @throws DocumentException error in generating the object
  */
 internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms)
 {
     int firstChar = (int)parms[0];
     int lastChar = (int)parms[1];
     byte[] shortTag = (byte[])parms[2];
     bool subsetp = (bool)parms[3] && subset;
     if (!subsetp) {
         firstChar = 0;
         lastChar = shortTag.Length - 1;
         for (int k = 0; k < shortTag.Length; ++k)
             shortTag[k] = 1;
     }
     PdfIndirectReference ind_font = null;
     PdfObject pobj = null;
     PdfIndirectObject obj = null;
     string subsetPrefix = "";
     if (embedded) {
         if (cff) {
             pobj = new StreamFont(ReadCffFont(), "Type1C", compressionLevel);
             obj = writer.AddToBody(pobj);
             ind_font = obj.IndirectReference;
         }
         else {
             if (subsetp)
                 subsetPrefix = CreateSubsetPrefix();
             Hashtable glyphs = new Hashtable();
             for (int k = firstChar; k <= lastChar; ++k) {
                 if (shortTag[k] != 0) {
                     int[] metrics = null;
                     if (specialMap != null) {
                         int[] cd = GlyphList.NameToUnicode(differences[k]);
                         if (cd != null)
                             metrics = GetMetricsTT(cd[0]);
                     }
                     else {
                         if (fontSpecific)
                             metrics = GetMetricsTT(k);
                         else
                             metrics = GetMetricsTT(unicodeDifferences[k]);
                     }
                     if (metrics != null)
                         glyphs[metrics[0]] = null;
                 }
             }
             AddRangeUni(glyphs, false, subsetp);
             byte[] b = null;
             if (subsetp || directoryOffset != 0 || subsetRanges != null) {
                 TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), glyphs, directoryOffset, true, !subsetp);
                 b = sb.Process();
             }
             else {
                 b = GetFullFont();
             }
             int[] lengths = new int[]{b.Length};
             pobj = new StreamFont(b, lengths, compressionLevel);
             obj = writer.AddToBody(pobj);
             ind_font = obj.IndirectReference;
         }
     }
     pobj = GetFontDescriptor(ind_font, subsetPrefix, null);
     if (pobj != null){
         obj = writer.AddToBody(pobj);
         ind_font = obj.IndirectReference;
     }
     pobj = GetFontBaseType(ind_font, subsetPrefix, firstChar, lastChar, shortTag);
     writer.AddToBody(pobj, piref);
 }
コード例 #3
0
        protected internal virtual void WriteFont(TrueTypeFontUnicode font, PdfIndirectReference refer, Object[] parms, byte[] rotbits)
        {
            Dictionary<int, int[]> longTag = (Dictionary<int, int[]>)parms[0];
            font.AddRangeUni(longTag, true, font.Subset);
            int[][] metrics = new int[longTag.Count][];
            longTag.Values.CopyTo(metrics, 0);
            Array.Sort(metrics, font);
            PdfIndirectReference ind_font = null;
            PdfObject pobj = null;
            PdfIndirectObject obj = null;
            PdfIndirectReference cidset = null;
            // sivan: cff
            if (font.Cff)
            {
                byte[] b = font.ReadCffFont();
                if (font.Subset || font.SubsetRanges != null)
                {
                    CFFFontSubset cff = new CFFFontSubset(new RandomAccessFileOrArray(b), longTag);
                    b = cff.Process(cff.GetNames()[0]);
                }
                pobj = new BaseFont.StreamFont(b, "CIDFontType0C", font.CompressionLevel);
                obj = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            else
            {
                byte[] b;
                if (font.Subset || font.DirectoryOffset != 0)
                {
                    TrueTypeFontSubSet sb = new TrueTypeFontSubSet(font.FileName, new RandomAccessFileOrArray(font.Rf), longTag, font.DirectoryOffset, false, false);
                    b = sb.Process();
                }
                else
                {
                    b = font.GetFullFont();
                }
                int[] lengths = new int[] { b.Length };
                pobj = new BaseFont.StreamFont(b, lengths, font.CompressionLevel);
                obj = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            String subsetPrefix = "";
            if (font.Subset)
                subsetPrefix = TrueTypeFontUnicode.CreateSubsetPrefix();
            PdfDictionary dic = font.GetFontDescriptor(ind_font, subsetPrefix, cidset);
            obj = writer.AddToBody(dic);
            ind_font = obj.IndirectReference;

            pobj = font.GetCIDFontType2(ind_font, subsetPrefix, metrics);
            obj = writer.AddToBody(pobj);
            ind_font = obj.IndirectReference;

            pobj = font.GetToUnicode(metrics);
            PdfIndirectReference toUnicodeRef = null;

            if (pobj != null)
            {
                obj = writer.AddToBody(pobj);
                toUnicodeRef = obj.IndirectReference;
            }

            pobj = font.GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
            writer.AddToBody(pobj, refer);
        }
コード例 #4
0
    /**
     * @see TtfUnicodeWriter#writeFont(TrueTypeFontUnicode, PdfIndirectReference, Object[], byte[])
     */
    override protected void WriteFont(TrueTypeFontUnicode font, PdfIndirectReference refer, Object[] parameters, byte[] rotbits) {
        Dictionary<int, int[]> longTag = (Dictionary<int, int[]>)parameters[0];
        font.AddRangeUni(longTag, true, font.Subset);
        int [][] metrics = new int[longTag.Count][];
        longTag.Values.CopyTo(metrics, 0);
        Array.Sort(metrics, font);
        PdfIndirectReference ind_font = null;
        PdfObject pobj = null;
        PdfIndirectObject obj = null;
        PdfIndirectReference cidset = null;
        PdfStream stream;
        if (metrics.Length == 0) {
            stream = new PdfStream(new byte[]{(byte)0x80});
        }
        else {
            int top = metrics[metrics.Length - 1][0];
            byte[] bt = new byte[top / 8 + 1];
            for (int k = 0; k < metrics.Length; ++k) {
                int v = metrics[k][0];
                bt[v / 8] |= rotbits[v % 8];
            }
            stream = new PdfStream(bt);
            stream.FlateCompress(font.CompressionLevel);
        }
            cidset = writer.AddToBody(stream).IndirectReference;

        if (font.Cff) {
            byte[] b = font.ReadCffFont();
            if (font.Subset || font.SubsetRanges != null) {
                CFFFontSubset cff = new CFFFontSubset(new RandomAccessFileOrArray(b),longTag);
                b = cff.Process(cff.GetNames()[0]);
            }
            pobj = new BaseFont.StreamFont(b, "CIDFontType0C", font.CompressionLevel);
            obj = writer.AddToBody(pobj);
            ind_font = obj.IndirectReference;
        } else {
            byte[] b;
            if (font.Subset || font.DirectoryOffset != 0) {
                TrueTypeFontSubSet sb = new TrueTypeFontSubSet(font.FileName, new RandomAccessFileOrArray(font.Rf), longTag, font.DirectoryOffset, false, false);
                b = sb.Process();
            }
            else {
                b = font.GetFullFont();
            }
            int[] lengths = new int[] { b.Length };
            pobj = new BaseFont.StreamFont(b,lengths, font.CompressionLevel);
            obj = writer.AddToBody(pobj);
            ind_font = obj.IndirectReference;
        }
        String subsetPrefix = "";
        if (font.Subset)
            subsetPrefix = BaseFont.CreateSubsetPrefix();
        PdfDictionary dic = font.GetFontDescriptor(ind_font, subsetPrefix, cidset);
        obj = writer.AddToBody(dic);
        ind_font = obj.IndirectReference;

        pobj = font.GetCIDFontType2(ind_font, subsetPrefix, metrics);
        obj = writer.AddToBody(pobj);
        ind_font = obj.IndirectReference;

        pobj = font.GetToUnicode(metrics);
        PdfIndirectReference toUnicodeRef = null;

        if (pobj != null) {
            obj = writer.AddToBody(pobj);
            toUnicodeRef = obj.IndirectReference;
        }

        pobj = font.GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
        writer.AddToBody(pobj, refer);
    }
コード例 #5
0
 protected internal byte[] GetSubSet(HashSet<int> glyphs, bool subsetp)  {
     lock (head) {
         TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), glyphs, directoryOffset, true, !subsetp);
         return sb.Process();
     }
 }
コード例 #6
0
        internal protected virtual void WriteFont(TrueTypeFontUnicode font, PdfIndirectReference refer, Object[] parms, byte[] rotbits)
        {
            Dictionary <int, int[]> longTag = (Dictionary <int, int[]>)parms[0];

            font.AddRangeUni(longTag, true, font.Subset);
            int[][] metrics = new int[longTag.Count][];
            longTag.Values.CopyTo(metrics, 0);
            Array.Sort(metrics, font);
            PdfIndirectReference ind_font = null;
            PdfObject            pobj     = null;
            PdfIndirectObject    obj      = null;

            // sivan: cff
            if (font.Cff)
            {
                byte[] b = font.ReadCffFont();
                if (font.Subset || font.SubsetRanges != null)
                {
                    CFFFontSubset cff = new CFFFontSubset(new RandomAccessFileOrArray(b), longTag);
                    try
                    {
                        b = cff.Process(cff.GetNames()[0]);
                    }
                    catch (Exception e)
                    {
                        // temporary fix for cff subset failure
                        font.Subset = false;
                        font.AddRangeUni(longTag, true, font.Subset);
                        metrics = new int[longTag.Count][];
                        longTag.Values.CopyTo(metrics, 0);
                        Array.Sort(metrics, font);
                    }
                }
                pobj     = new BaseFont.StreamFont(b, "CIDFontType0C", font.CompressionLevel);
                obj      = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            else
            {
                byte[] b;
                if (font.Subset || font.DirectoryOffset != 0)
                {
                    lock (font.Rf) {
                        TrueTypeFontSubSet sb = new TrueTypeFontSubSet(font.FileName, new RandomAccessFileOrArray(font.Rf), new HashSet2 <int>(longTag.Keys), font.DirectoryOffset, true, false);
                        b = sb.Process();
                    }
                }
                else
                {
                    b = font.GetFullFont();
                }
                int[] lengths = new int[] { b.Length };
                pobj     = new BaseFont.StreamFont(b, lengths, font.CompressionLevel);
                obj      = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            String subsetPrefix = "";

            if (font.Subset)
            {
                subsetPrefix = TrueTypeFontUnicode.CreateSubsetPrefix();
            }
            PdfDictionary dic = font.GetFontDescriptor(ind_font, subsetPrefix, null);

            obj      = writer.AddToBody(dic);
            ind_font = obj.IndirectReference;

            pobj     = font.GetCIDFontType2(ind_font, subsetPrefix, metrics);
            obj      = writer.AddToBody(pobj);
            ind_font = obj.IndirectReference;

            pobj = font.GetToUnicode(metrics);
            PdfIndirectReference toUnicodeRef = null;

            if (pobj != null)
            {
                obj          = writer.AddToBody(pobj);
                toUnicodeRef = obj.IndirectReference;
            }

            pobj = font.GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
            writer.AddToBody(pobj, refer);
        }
コード例 #7
0
        /**
         * @see TtfUnicodeWriter#writeFont(TrueTypeFontUnicode, PdfIndirectReference, Object[], byte[])
         */
        internal protected override void WriteFont(TrueTypeFontUnicode font, PdfIndirectReference refer, Object[] parameters, byte[] rotbits)
        {
            Dictionary <int, int[]> longTag = (Dictionary <int, int[]>)parameters[0];

            font.AddRangeUni(longTag, true, font.Subset);
            int [][] metrics = new int[longTag.Count][];
            longTag.Values.CopyTo(metrics, 0);
            Array.Sort(metrics, font);
            PdfIndirectReference ind_font = null;
            PdfObject            pobj     = null;
            PdfIndirectObject    obj      = null;

            if (font.Cff)
            {
                byte[] b = font.ReadCffFont();
                if (font.Subset || font.SubsetRanges != null)
                {
                    CFFFontSubset cff = new CFFFontSubset(new RandomAccessFileOrArray(b), longTag);
                    try
                    {
                        b = cff.Process(cff.GetNames()[0]);
                    }
                    catch (Exception e)
                    {
                        //temporary fix for cff subset failure
                        font.Subset = false;
                        font.AddRangeUni(longTag, true, font.Subset);
                        metrics = new int[longTag.Count][];
                        longTag.Values.CopyTo(metrics, 0);
                        Array.Sort(metrics, font);
                    }
                }
                pobj     = new BaseFont.StreamFont(b, "CIDFontType0C", font.CompressionLevel);
                obj      = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            else
            {
                byte[] b;
                if (font.Subset || font.DirectoryOffset != 0)
                {
                    lock (font.Rf) {
                        TrueTypeFontSubSet sb = new TrueTypeFontSubSet(font.FileName, new RandomAccessFileOrArray(font.Rf), new HashSet2 <int>(longTag.Keys), font.DirectoryOffset, false, false);
                        b = sb.Process();
                    }
                }
                else
                {
                    b = font.GetFullFont();
                }
                int[] lengths = new int[] { b.Length };
                pobj     = new BaseFont.StreamFont(b, lengths, font.CompressionLevel);
                obj      = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            // CIDSet shall be based on font.maxGlyphId property of the font, it is maxp.numGlyphs for ttf,
            // because technically we convert all unused glyphs to space, e.g. just remove outlines.
            byte[] cidSetBytes = new byte[font.MaxGlyphId / 8 + 1];
            for (int i = 0; i < font.MaxGlyphId / 8; i++)
            {
                cidSetBytes[i] |= 0xff;
            }
            for (int i = 0; i < font.MaxGlyphId % 8; i++)
            {
                cidSetBytes[cidSetBytes.Length - 1] |= rotbits[i];
            }
            PdfStream stream = new PdfStream(cidSetBytes);

            stream.FlateCompress(font.CompressionLevel);
            PdfIndirectReference cidset = writer.AddToBody(stream).IndirectReference;

            String subsetPrefix = "";

            if (font.Subset)
            {
                subsetPrefix = BaseFont.CreateSubsetPrefix();
            }
            PdfDictionary dic = font.GetFontDescriptor(ind_font, subsetPrefix, cidset);

            obj      = writer.AddToBody(dic);
            ind_font = obj.IndirectReference;

            pobj     = font.GetCIDFontType2(ind_font, subsetPrefix, metrics);
            obj      = writer.AddToBody(pobj);
            ind_font = obj.IndirectReference;

            pobj = font.GetToUnicode(metrics);
            PdfIndirectReference toUnicodeRef = null;

            if (pobj != null)
            {
                obj          = writer.AddToBody(pobj);
                toUnicodeRef = obj.IndirectReference;
            }

            pobj = font.GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
            writer.AddToBody(pobj, refer);
        }
コード例 #8
0
        /** Outputs to the writer the font dictionaries and streams.
         * @param writer the writer for this document
         * @param ref the font indirect reference
         * @param parms several parameters that depend on the font type
         * @throws IOException on error
         * @throws DocumentException error in generating the object
         */
        internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms)
        {
            Hashtable longTag = (Hashtable)parms[0];

            AddRangeUni(longTag, true, subset);
            ArrayList tmp = new ArrayList();

            foreach (object o in longTag.Values)
            {
                tmp.Add(o);
            }
            Object[] metrics = tmp.ToArray();
            Array.Sort(metrics, this);
            PdfIndirectReference ind_font = null;
            PdfObject            pobj     = null;
            PdfIndirectObject    obj      = null;
            PdfIndirectReference cidset   = null;

            if (writer.PDFXConformance == PdfWriter.PDFA1A || writer.PDFXConformance == PdfWriter.PDFA1B)
            {
                PdfStream stream;
                if (metrics.Length == 0)
                {
                    stream = new PdfStream(new byte[] { (byte)0x80 });
                }
                else
                {
                    int    top = ((int[])metrics[metrics.Length - 1])[0];
                    byte[] bt  = new byte[top / 8 + 1];
                    for (int k = 0; k < metrics.Length; ++k)
                    {
                        int v = ((int[])metrics[k])[0];
                        bt[v / 8] |= rotbits[v % 8];
                    }
                    stream = new PdfStream(bt);
                    stream.FlateCompress(compressionLevel);
                }
                cidset = writer.AddToBody(stream).IndirectReference;
            }
            // sivan: cff
            if (cff)
            {
                byte[] b = ReadCffFont();
                if (subset || subsetRanges != null)
                {
                    CFFFontSubset cffs = new CFFFontSubset(new RandomAccessFileOrArray(b), longTag);
                    b = cffs.Process((cffs.GetNames())[0]);
                }

                pobj     = new StreamFont(b, "CIDFontType0C", compressionLevel);
                obj      = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            else
            {
                byte[] b;
                if (subset || directoryOffset != 0)
                {
                    TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), longTag, directoryOffset, false, false);
                    b = sb.Process();
                }
                else
                {
                    b = GetFullFont();
                }
                int[] lengths = new int[] { b.Length };
                pobj     = new StreamFont(b, lengths, compressionLevel);
                obj      = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            String subsetPrefix = "";

            if (subset)
            {
                subsetPrefix = CreateSubsetPrefix();
            }
            PdfDictionary dic = GetFontDescriptor(ind_font, subsetPrefix, cidset);

            obj      = writer.AddToBody(dic);
            ind_font = obj.IndirectReference;

            pobj     = GetCIDFontType2(ind_font, subsetPrefix, metrics);
            obj      = writer.AddToBody(pobj);
            ind_font = obj.IndirectReference;

            pobj = GetToUnicode(metrics);
            PdfIndirectReference toUnicodeRef = null;

            if (pobj != null)
            {
                obj          = writer.AddToBody(pobj);
                toUnicodeRef = obj.IndirectReference;
            }

            pobj = GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
            writer.AddToBody(pobj, piref);
        }
コード例 #9
0
        /** Outputs to the writer the font dictionaries and streams.
         * @param writer the writer for this document
         * @param ref the font indirect reference
         * @param parms several parameters that depend on the font type
         * @throws IOException on error
         * @throws DocumentException error in generating the object
         */
        internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms)
        {
            Hashtable longTag = (Hashtable)parms[0];
            AddRangeUni(longTag, true, subset);
            ArrayList tmp = new ArrayList();
            foreach (object o in longTag.Values) {
                tmp.Add(o);
            }
            Object[] metrics = tmp.ToArray();
            Array.Sort(metrics, this);
            PdfIndirectReference ind_font = null;
            PdfObject pobj = null;
            PdfIndirectObject obj = null;
            // sivan: cff
            if (cff) {
                RandomAccessFileOrArray rf2 = new RandomAccessFileOrArray(rf);
                byte[] b = new byte[cffLength];
                try {
                    rf2.ReOpen();
                    rf2.Seek(cffOffset);
                    rf2.ReadFully(b);
                } finally {
                    try {
                        rf2.Close();
                    } catch  {
                        // empty on purpose
                    }
                }
                if (subset || subsetRanges != null) {
                    CFFFontSubset cffs = new CFFFontSubset(new RandomAccessFileOrArray(b),longTag);
                    b = cffs.Process( (cffs.GetNames())[0] );
                }

                pobj = new StreamFont(b, "CIDFontType0C");
                obj = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            } else {
                byte[] b;
                if (subset || directoryOffset != 0) {
                    TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), longTag, directoryOffset, false, false);
                    b = sb.Process();
                }
                else {
                    b = GetFullFont();
                }
                int[] lengths = new int[]{b.Length};
                pobj = new StreamFont(b, lengths);
                obj = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            String subsetPrefix = "";
            if (subset)
                subsetPrefix = CreateSubsetPrefix();
            PdfDictionary dic = GetFontDescriptor(ind_font, subsetPrefix);
            obj = writer.AddToBody(dic);
            ind_font = obj.IndirectReference;

            pobj = GetCIDFontType2(ind_font, subsetPrefix, metrics);
            obj = writer.AddToBody(pobj);
            ind_font = obj.IndirectReference;

            pobj = GetToUnicode(metrics);
            PdfIndirectReference toUnicodeRef = null;
            if (pobj != null) {
                obj = writer.AddToBody(pobj);
                toUnicodeRef = obj.IndirectReference;
            }

            pobj = GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
            writer.AddToBody(pobj, piref);
        }
コード例 #10
0
        /**
         * @see TtfUnicodeWriter#writeFont(TrueTypeFontUnicode, PdfIndirectReference, Object[], byte[])
         */
        internal protected override void WriteFont(TrueTypeFontUnicode font, PdfIndirectReference refer, Object[] parameters, byte[] rotbits)
        {
            Dictionary <int, int[]> longTag = (Dictionary <int, int[]>)parameters[0];

            font.AddRangeUni(longTag, true, font.Subset);
            int [][] metrics = new int[longTag.Count][];
            longTag.Values.CopyTo(metrics, 0);
            Array.Sort(metrics, font);
            PdfIndirectReference ind_font = null;
            PdfObject            pobj     = null;
            PdfIndirectObject    obj      = null;
            PdfIndirectReference cidset   = null;

            if (pdfAConformanceLevel == PdfAConformanceLevel.PDF_A_1A ||
                pdfAConformanceLevel == PdfAConformanceLevel.PDF_A_1B)
            {
                PdfStream stream;
                if (metrics.Length == 0)
                {
                    stream = new PdfStream(new byte[] { (byte)0x80 });
                }
                else
                {
                    int    top = metrics[metrics.Length - 1][0];
                    byte[] bt  = new byte[top / 8 + 1];
                    for (int k = 0; k < metrics.Length; ++k)
                    {
                        int v = metrics[k][0];
                        bt[v / 8] |= rotbits[v % 8];
                    }
                    stream = new PdfStream(bt);
                    stream.FlateCompress(font.CompressionLevel);
                }
                cidset = writer.AddToBody(stream).IndirectReference;
            }
            if (font.Cff)
            {
                byte[] b = font.ReadCffFont();
                if (font.Subset || font.SubsetRanges != null)
                {
                    CFFFontSubset cff = new CFFFontSubset(new RandomAccessFileOrArray(b), longTag);
                    b = cff.Process(cff.GetNames()[0]);
                }
                pobj     = new BaseFont.StreamFont(b, "CIDFontType0C", font.CompressionLevel);
                obj      = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            else
            {
                byte[] b;
                if (font.Subset || font.DirectoryOffset != 0)
                {
                    lock (font.Rf) {
                        TrueTypeFontSubSet sb = new TrueTypeFontSubSet(font.FileName, new RandomAccessFileOrArray(font.Rf), new HashSet2 <int>(longTag.Keys), font.DirectoryOffset, false, false);
                        b = sb.Process();
                    }
                }
                else
                {
                    b = font.GetFullFont();
                }
                int[] lengths = new int[] { b.Length };
                pobj     = new BaseFont.StreamFont(b, lengths, font.CompressionLevel);
                obj      = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            String subsetPrefix = "";

            if (font.Subset)
            {
                subsetPrefix = BaseFont.CreateSubsetPrefix();
            }
            PdfDictionary dic = font.GetFontDescriptor(ind_font, subsetPrefix, cidset);

            obj      = writer.AddToBody(dic);
            ind_font = obj.IndirectReference;

            pobj     = font.GetCIDFontType2(ind_font, subsetPrefix, metrics);
            obj      = writer.AddToBody(pobj);
            ind_font = obj.IndirectReference;

            pobj = font.GetToUnicode(metrics);
            PdfIndirectReference toUnicodeRef = null;

            if (pobj != null)
            {
                obj          = writer.AddToBody(pobj);
                toUnicodeRef = obj.IndirectReference;
            }

            pobj = font.GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
            writer.AddToBody(pobj, refer);
        }
コード例 #11
0
        /** Outputs to the writer the font dictionaries and streams.
         * @param writer the writer for this document
         * @param ref the font indirect reference
         * @param parms several parameters that depend on the font type
         * @throws IOException on error
         * @throws DocumentException error in generating the object
         */
        internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms) {
            Hashtable longTag = (Hashtable)parms[0];
            AddRangeUni(longTag, true, subset);
            ArrayList tmp = new ArrayList();
            foreach (object o in longTag.Values) {
                tmp.Add(o);
            }
            Object[] metrics = tmp.ToArray();
            Array.Sort(metrics, this);
            PdfIndirectReference ind_font = null;
            PdfObject pobj = null;
            PdfIndirectObject obj = null;
            PdfIndirectReference cidset = null;
            if (writer.PDFXConformance == PdfWriter.PDFA1A || writer.PDFXConformance == PdfWriter.PDFA1B) {
                PdfStream stream;
                if (metrics.Length == 0) {
                    stream = new PdfStream(new byte[]{(byte)0x80});
                }
                else {
                    int top = ((int[])metrics[metrics.Length - 1])[0];
                    byte[] bt = new byte[top / 8 + 1];
                    for (int k = 0; k < metrics.Length; ++k) {
                        int v = ((int[])metrics[k])[0];
                        bt[v / 8] |= rotbits[v % 8];
                    }
                    stream = new PdfStream(bt);
                    stream.FlateCompress(compressionLevel);
                }
                cidset = writer.AddToBody(stream).IndirectReference;
            }
            // sivan: cff
            if (cff) {
                byte[] b = ReadCffFont();
                if (subset || subsetRanges != null) {
                    CFFFontSubset cffs = new CFFFontSubset(new RandomAccessFileOrArray(b),longTag);
                    b = cffs.Process((cffs.GetNames())[0] );
                }
                
                pobj = new StreamFont(b, "CIDFontType0C", compressionLevel);
                obj = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            } else {
                byte[] b;
                if (subset || directoryOffset != 0) {
                    TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), longTag, directoryOffset, false, false);
                    b = sb.Process();
                }
                else {
                    b = GetFullFont();
                }
                int[] lengths = new int[]{b.Length};
                pobj = new StreamFont(b, lengths, compressionLevel);
                obj = writer.AddToBody(pobj);
                ind_font = obj.IndirectReference;
            }
            String subsetPrefix = "";
            if (subset)
                subsetPrefix = CreateSubsetPrefix();
            PdfDictionary dic = GetFontDescriptor(ind_font, subsetPrefix, cidset);
            obj = writer.AddToBody(dic);
            ind_font = obj.IndirectReference;

            pobj = GetCIDFontType2(ind_font, subsetPrefix, metrics);
            obj = writer.AddToBody(pobj);
            ind_font = obj.IndirectReference;

            pobj = GetToUnicode(metrics);
            PdfIndirectReference toUnicodeRef = null;
            if (pobj != null) {
                obj = writer.AddToBody(pobj);
                toUnicodeRef = obj.IndirectReference;
            }

            pobj = GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
            writer.AddToBody(pobj, piref);
        }