예제 #1
0
        private void InitFontSize()
        {
            String mainTag = raf.ReadString(4, PdfEncodings.WINANSI);

            if (!mainTag.Equals("ttcf"))
            {
                throw new iText.IO.IOException(iText.IO.IOException.InvalidTtcFile);
            }
            raf.SkipBytes(4);
            TTCSize = raf.ReadInt();
        }
예제 #2
0
 private int ReadInt(RandomAccessFileOrArray stream)
 {
     if (isBigEndian)
     {
         return(stream.ReadInt());
     }
     else
     {
         return(stream.ReadIntLE());
     }
 }
        internal virtual void ReadSegment(Jbig2SegmentReader.Jbig2Segment s)
        {
            int ptr = (int)ra.GetPosition();

            if (s.dataLength == unchecked ((long)(0xffffffffl)))
            {
                // TODO figure this bit out, 7.2.7
                return;
            }
            byte[] data = new byte[(int)s.dataLength];
            ra.Read(data);
            s.data = data;
            if (s.type == PAGE_INFORMATION)
            {
                int last = (int)ra.GetPosition();
                ra.Seek(ptr);
                int page_bitmap_width  = ra.ReadInt();
                int page_bitmap_height = ra.ReadInt();
                ra.Seek(last);
                Jbig2SegmentReader.Jbig2Page p = pages.Get(s.page);
                if (p == null)
                {
                    throw new iText.IO.IOException("Referring to widht or height of a page we haven't seen yet: {0}").SetMessageParams
                              (s.page);
                }
                p.pageBitmapWidth  = page_bitmap_width;
                p.pageBitmapHeight = page_bitmap_height;
            }
        }
예제 #4
0
        void ReadSegment(JBIG2Segment s)
        {
            int ptr = ra.FilePointer;

            if (s.dataLength == 0xffffffffL)
            {
                // TODO figure this bit out, 7.2.7
                return;
            }

            byte[] data = new byte[(int)s.dataLength];
            ra.Read(data);
            s.data = data;

            if (s.type == PAGE_INFORMATION)
            {
                int last = ra.FilePointer;
                ra.Seek(ptr);
                int page_bitmap_width  = ra.ReadInt();
                int page_bitmap_height = ra.ReadInt();
                ra.Seek(last);
                JBIG2Page p = pages[s.page];
                if (p == null)
                {
                    throw new InvalidOperationException(MessageLocalization.GetComposedMessage("referring.to.widht.height.of.page.we.havent.seen.yet.1", s.page));
                }

                p.pageBitmapWidth  = page_bitmap_width;
                p.pageBitmapHeight = page_bitmap_height;
            }
        }
        void ReadSegment(JBIG2Segment s)
        {
            int ptr = ra.FilePointer;

            if (s.dataLength == 0xffffffffL)
            {
                // TODO figure this bit out, 7.2.7
                return;
            }

            byte[] data = new byte[(int)s.dataLength];
            ra.Read(data);
            s.data = data;

            if (s.type == PAGE_INFORMATION)
            {
                int last = ra.FilePointer;
                ra.Seek(ptr);
                int page_bitmap_width  = ra.ReadInt();
                int page_bitmap_height = ra.ReadInt();
                ra.Seek(last);
                JBIG2Page p = (JBIG2Page)pages[s.page];
                if (p == null)
                {
                    throw new InvalidOperationException("referring to widht/height of page we havent seen yet? " + s.page);
                }

                p.pageBitmapWidth  = page_bitmap_width;
                p.pageBitmapHeight = page_bitmap_height;
            }
        }
예제 #6
0
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual void CreateTableDirectory()
        {
            tableDirectory = new Dictionary <String, int[]>();
            rf.Seek(directoryOffset);
            int id = rf.ReadInt();

            if (id != 0x00010000)
            {
                throw new iText.IO.IOException(iText.IO.IOException.NotAtTrueTypeFile).SetMessageParams(fileName);
            }
            int num_tables = rf.ReadUnsignedShort();

            rf.SkipBytes(6);
            for (int k = 0; k < num_tables; ++k)
            {
                String tag           = ReadStandardString(4);
                int[]  tableLocation = new int[3];
                tableLocation[TABLE_CHECKSUM] = rf.ReadInt();
                tableLocation[TABLE_OFFSET]   = rf.ReadInt();
                tableLocation[TABLE_LENGTH]   = rf.ReadInt();
                tableDirectory.Put(tag, tableLocation);
            }
        }
예제 #7
0
 /// <summary>This is the starting point of the class.</summary>
 /// <remarks>
 /// This is the starting point of the class. A sub-class must call this
 /// method to start getting call backs to the
 /// <see cref="ReadLookupTable(int, int, int[])"/>
 /// method.
 /// </remarks>
 /// <exception cref="FontReadingException"/>
 /// <exception cref="iText.IO.Font.Otf.FontReadingException"/>
 internal void StartReadingTable()
 {
     try {
         rf.Seek(tableLocation);
         /*int version =*/
         rf.ReadInt();
         //version not used
         int scriptListOffset  = rf.ReadUnsignedShort();
         int featureListOffset = rf.ReadUnsignedShort();
         int lookupListOffset  = rf.ReadUnsignedShort();
         // read the Script tables
         scriptsType = new OpenTypeScript(this, tableLocation + scriptListOffset);
         // read Feature table
         featuresType = new OpenTypeFeature(this, tableLocation + featureListOffset);
         // read LookUpList table
         ReadLookupListTable(tableLocation + lookupListOffset);
     }
     catch (System.IO.IOException e) {
         throw new FontReadingException("Error reading font file", e);
     }
 }
예제 #8
0
        private void InitializeSfntTables()
        {
            tables = new LinkedDictionary <String, int[]>();
            if (ttcIndex >= 0)
            {
                int dirIdx = ttcIndex;
                if (dirIdx < 0)
                {
                    if (fileName != null)
                    {
                        throw new iText.IO.IOException("The font index for {0} must be positive.").SetMessageParams(fileName);
                    }
                    else
                    {
                        throw new iText.IO.IOException("The font index must be positive.");
                    }
                }
                String mainTag = ReadStandardString(4);
                if (!mainTag.Equals("ttcf"))
                {
                    if (fileName != null)
                    {
                        throw new iText.IO.IOException("{0} is not a valid ttc file.").SetMessageParams(fileName);
                    }
                    else
                    {
                        throw new iText.IO.IOException("Not a valid ttc file.");
                    }
                }
                raf.SkipBytes(4);
                int dirCount = raf.ReadInt();
                if (dirIdx >= dirCount)
                {
                    if (fileName != null)
                    {
                        throw new iText.IO.IOException("The font index for {0} must be between 0 and {1}. It is {2}.").SetMessageParams
                                  (fileName, dirCount - 1, dirIdx);
                    }
                    else
                    {
                        throw new iText.IO.IOException("The font index must be between 0 and {0}. It is {1}.").SetMessageParams(dirCount
                                                                                                                                - 1, dirIdx);
                    }
                }
                raf.SkipBytes(dirIdx * 4);
                directoryOffset = raf.ReadInt();
            }
            raf.Seek(directoryOffset);
            int ttId = raf.ReadInt();

            if (ttId != 0x00010000 && ttId != 0x4F54544F)
            {
                if (fileName != null)
                {
                    throw new iText.IO.IOException("{0} is not a valid ttf or otf file.").SetMessageParams(fileName);
                }
                else
                {
                    throw new iText.IO.IOException("Not a valid ttf or otf file.");
                }
            }
            int num_tables = raf.ReadUnsignedShort();

            raf.SkipBytes(6);
            for (int k = 0; k < num_tables; ++k)
            {
                String tag = ReadStandardString(4);
                raf.SkipBytes(4);
                int[] table_location = new int[2];
                table_location[0] = raf.ReadInt();
                table_location[1] = raf.ReadInt();
                tables.Put(tag, table_location);
            }
        }
예제 #9
0
        /// <summary>Reads the font data.</summary>
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual void Process()
        {
            tables = new LinkedDictionary <String, int[]>();
            if (ttcIndex >= 0)
            {
                int dirIdx = ttcIndex;
                if (dirIdx < 0)
                {
                    if (fileName != null)
                    {
                        throw new iText.IO.IOException("the.font.index.for.1.must.be.positive").SetMessageParams(fileName);
                    }
                    else
                    {
                        throw new iText.IO.IOException("the.font.index.must.be.positive");
                    }
                }
                String mainTag = ReadStandardString(4);
                if (!mainTag.Equals("ttcf"))
                {
                    if (fileName != null)
                    {
                        throw new iText.IO.IOException("1.is.not.a.valid.ttc.file").SetMessageParams(fileName);
                    }
                    else
                    {
                        throw new iText.IO.IOException("not.a.valid.ttc.file");
                    }
                }
                raf.SkipBytes(4);
                int dirCount = raf.ReadInt();
                if (dirIdx >= dirCount)
                {
                    if (fileName != null)
                    {
                        throw new iText.IO.IOException("the.font.index.for.1.must.be.between.0.and.2.it.was.3").SetMessageParams(fileName
                                                                                                                                 , dirCount - 1, dirIdx);
                    }
                    else
                    {
                        throw new iText.IO.IOException("the.font.index.must.be.between.0.and.1.it.was.2").SetMessageParams(dirCount
                                                                                                                           - 1, dirIdx);
                    }
                }
                raf.SkipBytes(dirIdx * 4);
                directoryOffset = raf.ReadInt();
            }
            raf.Seek(directoryOffset);
            int ttId = raf.ReadInt();

            if (ttId != 0x00010000 && ttId != 0x4F54544F)
            {
                if (fileName != null)
                {
                    throw new iText.IO.IOException("1.is.not.a.valid.ttf.or.otf.file").SetMessageParams(fileName);
                }
                else
                {
                    throw new iText.IO.IOException("not.a.valid.ttf.or.otf.file");
                }
            }
            int num_tables = raf.ReadUnsignedShort();

            raf.SkipBytes(6);
            for (int k = 0; k < num_tables; ++k)
            {
                String tag = ReadStandardString(4);
                raf.SkipBytes(4);
                int[] table_location = new int[2];
                table_location[0] = raf.ReadInt();
                table_location[1] = raf.ReadInt();
                tables[tag]       = table_location;
            }
            CheckCff();
            ReadHheaTable();
            ReadNameTable();
            ReadHeadTable();
            ReadOs_2Table();
            ReadPostTable();
            ReadGlyphWidths();
            ReadCmapTable();
        }