示例#1
0
 internal static OTFile GetOTFile_CharisSILRegular()
 {
     string FilePath = "TestData\\CharisSIL-R.ttf";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
        /************************
         * public static methods
         */


        public static new OTFontVal ReadFont(OTFile file, uint FontFileNumber, uint filepos)
        {
            OTFontVal f = null;

            OffsetTable ot = ReadOffsetTable(file, filepos);

            if (ot != null)
            {
                if (ot.numTables == ot.DirectoryEntries.Count)
                {
                    OutlineType olt = OutlineType.OUTLINE_INVALID;
                    for (int i = 0; i < ot.DirectoryEntries.Count; i++)
                    {
                        DirectoryEntry temp   = (DirectoryEntry)ot.DirectoryEntries[i];
                        string         sTable = (string)temp.tag;
                        if (sTable == "CFF ")
                        {
                            olt = OutlineType.OUTLINE_POSTSCRIPT;
                            break;
                        }
                        else if (sTable == "glyf")
                        {
                            olt = OutlineType.OUTLINE_TRUETYPE;
                            break;
                        }
                    }

                    f = new OTFontVal(file, FontFileNumber, ot, olt);
                }
            }
            return(f);
        }
示例#3
0
        public void OTFileOpenTest_ReadSingleFontOffsetTable()
        {
            OTFile target = new OTFile();
            string FilePath = "TestData\\selawk.ttf";
            try
            {
                target.ReadFromFile(FilePath);
            }
            catch (Exception)
            {
                // unexpected exception
            }

            Assert.IsTrue(target.SfntVersionTag == (OTTag)(0x00010000), "Error: unexpected sfnt tag");

            OTFont f = target.GetFont(0);
            Assert.IsTrue(f.OffsetInFile == 0, "Error: unexpected font offset");
            Assert.IsTrue(f.SfntVersionTag == (OTTag)(0x00010000), "Error: unexpected font value");
            Assert.IsFalse(f.IsWithinTtc, "Error: unexpected font value");
            Assert.IsTrue(f.OffsetTable.OffsetInFile == 0, "Error: unexpected offset table offset");
            Assert.IsTrue(f.OffsetTable.SfntVersion == (OTTag)(0x00010000), "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.NumTables == 15, "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.SearchRange == 0x0080, "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.EntrySelector == 0x0003, "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.RangeShift == 0x0070, "Error: unexpected font offset table value");
        }
示例#4
0
 internal static OTFile GetOTFile_AndikaRegular()
 {
     string FilePath = "TestData\\Andika-R.TTF";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#5
0
 internal static OTFile GetOTFile_SelawikRegular()
 {
     string FilePath = "TestData\\selawk.ttf";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#6
0
 internal static OTFile GetOTFile_BungeeColorRegular()
 {
     string FilePath = "TestData\\BungeeColor-Regular_colr_Windows.TTF";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#7
0
 internal static OTFile GetOTFile_CharisSILBoldItalic()
 {
     string FilePath = "TestData\\CharisSIL-BI.ttf";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#8
0
 internal static OTFile GetOTFile_ScheherazadeRegular()
 {
     string FilePath = "TestData\\Scheherazade-Regular.ttf";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#9
0
 internal static OTFile GetOTFile_SourceHanSans_Regular()
 {
     string FilePath = "TestData\\SourceHanSans-Regular.ttc";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#10
0
 internal static OTFile GetOTFile_NotoSansMalayalamRegular()
 {
     string FilePath = "TestData\\NotoSansMalayalam-Regular.ttf";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#11
0
 internal static OTFile GetOTFile_CambriaTtc()
 {
     string FilePath = "TestData\\CAMBRIA.TTC";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#12
0
 internal static OTFile GetOTFile_NotoNastaliqUrduRegular()
 {
     string FilePath = "TestData\\NotoNastaliqUrdu-Regular.ttf";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#13
0
        public void OTFile_ReadFromFileAndGetMemoryStream()
        {
            // construct OTFile and read from test font
            OTFile target = new OTFile();
            string FilePath = "TestData\\selawk.ttf";
            target.ReadFromFile(FilePath);

            // Get memory stream and take sample
            System.IO.MemoryStream ms = target.GetMemoryStream();
            ms.Seek(0, System.IO.SeekOrigin.Begin);
            byte[] data = new byte[32];
            int cb = ms.Read(data, 0, 32);
            Assert.IsTrue((cb == 32), "Error: Read from memory stream returned less data than expected");

            // Create comparison data and compare
            byte[] expectedData = { 0, 1, 0, 0, 0, 0x0F, 0, 0x80, 0, 3, 0, 0x70, 0x44, 0x53, 0x49, 0x47, 0xF0, 0x54, 0x3E, 0x26, 0, 0, 0x91, 0xE4, 0, 0, 0x1A, 0xDC, 0x47, 0x44, 0x45, 0x46 };
            bool match = true;
            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] != expectedData[i])
                {
                    match = false;
                    break;
                }
            }
            Assert.IsTrue(match, "Error: Read from memory stream returned unexpected data");
        }
示例#14
0
 internal static OTFile GetOTFile_Skia()
 {
     string FilePath = "TestData\\Skia.ttf";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#15
0
 internal static OTFile GetOTFile_ADMSB()
 {
     string FilePath = "TestData\\ADMSB___.TTF";
     OTFile f = new OTFile();
     f.ReadFromFile(FilePath);
     return f;
 }
示例#16
0
        public void OTFileFieldInitializationHandlingTest()
        {
            bool caughtExpectedException = false; // will set to true if expected exception is caught

            OTFile target = new OTFile();
            Assert.IsNull(target.GetFileInfo(), "Error: unexpected FileInfo");
            Assert.IsNull(target.GetMemoryStream(), "Error: unexpected FileStream");
            try
            {
                OTFont f = target.GetFont(0);
            }
            catch (NullReferenceException)
            {
                caughtExpectedException = true;
            }
            Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught");
            Assert.IsFalse(target.IsCollection, "Error: unexpected value in unopened OTFile");
            Assert.IsFalse(target.IsSupportedFileType, "Error: unexpected value in unopened OTFile");
            Assert.IsTrue(target.Length == 0, "Error: unexpected value in unopened OTFile");
            Assert.IsTrue(target.NumFonts == 0, "Error: unexpected value in unopened OTFile");
            Assert.IsNull(target.SfntVersionTag, "Error: unexpected value in unopened OTFile");
            TtcHeader t = target.TtcHeader;
            Assert.IsTrue(t.FileOffset == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsNull(t.TtcTag, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.MajorVersion == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.MinorVersion == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.NumFonts == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsNull(t.OffsetTableOffsets, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsNull(t.DSIGTag, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.DSIGLength == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.DSIGOffset == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsFalse(t.HasDSIG, "Error: unexpected value in unconfigured TtcHeader");
        }
示例#17
0
        public DSIGInfo(string filename)
        {
            fontfile = new OTFile();
            tDSIG    = null;

            Warn_TTCv1            = false;
            Warn_DSIG_in_memFonts = false;
            Warn_MalformedSIG     = false;
            usNumSigs             = 0;

            if (!fontfile.open(filename))
            {
                throw new IOException("Cannot open file " + filename);
            }

            TTCHeader ttc = null;

            if (fontfile.IsCollection())
            {
                ttc = fontfile.GetTTCHeader();
                if (fontfile.GetTableManager().GetUnaliasedTableName(ttc.DsigTag) == "DSIG")
                {
                    MBOBuffer buf = fontfile.ReadPaddedBuffer(ttc.DsigOffset, ttc.DsigLength);
                    tDSIG = (Table_DSIG)fontfile.GetTableManager().CreateTableObject(ttc.DsigTag, buf);
                }
                for (uint i = 0; i < fontfile.GetNumFonts(); i++)
                {
                    OTFont     fn      = fontfile.GetFont(i);
                    Table_DSIG memDSIG = (Table_DSIG)fn.GetTable("DSIG");
                    if (memDSIG != null)
                    {
                        Warn_DSIG_in_memFonts = true;
                        break;
                    }
                }
            }
            else
            {
                OTFont fn = fontfile.GetFont(0);
                tDSIG = (Table_DSIG)fn.GetTable("DSIG");
            }

            HaveDSIG = ((tDSIG == null) ? false : true);

            // Officially we should only warn if HaveDSIG true
            if (fontfile.IsCollection() && ttc.version != 0x00020000)
            {
                Warn_TTCv1 = true;
            }

            if (HaveDSIG)
            {
                FurtherWork();
            }
        }
示例#18
0
        public void HeadCalculatedChecksumsTest()
        {
            OTFile f   = TestFonts.GetOTFile_AndikaRegular();
            uint?  idx = f.GetFont(0).OffsetTable.GetTableRecordIndex((OTTag)("head"));

            Assert.IsTrue(idx.HasValue);
            OTTable table;
            bool    result = f.GetFont(0).TryGetTable((OTTag)("head"), out table);

            Assert.IsTrue(result);
            TableHead head = (TableHead)table;

            Assert.AreEqual(head.CalculatedChecksum, head.TableRecordChecksum);
            Assert.AreEqual(head.CalculatedCheckSumAdjustment, head.CheckSumAdjustment);

            f   = TestFonts.GetOTFile_CharisSILBold();
            idx = f.GetFont(0).OffsetTable.GetTableRecordIndex((OTTag)("head"));
            Assert.IsTrue(idx.HasValue);
            table  = null;
            result = f.GetFont(0).TryGetTable((OTTag)("head"), out table);
            Assert.IsTrue(result);
            head = (TableHead)table;
            Assert.AreEqual(head.CalculatedChecksum, head.TableRecordChecksum);
            Assert.AreEqual(head.CalculatedCheckSumAdjustment, head.CheckSumAdjustment);

            f   = TestFonts.GetOTFile_CharisSILBoldItalic();
            idx = f.GetFont(0).OffsetTable.GetTableRecordIndex((OTTag)("head"));
            Assert.IsTrue(idx.HasValue);
            table  = null;
            result = f.GetFont(0).TryGetTable((OTTag)("head"), out table);
            Assert.IsTrue(result);
            head = (TableHead)table;
            Assert.AreEqual(head.CalculatedChecksum, head.TableRecordChecksum);
            Assert.AreEqual(head.CalculatedCheckSumAdjustment, head.CheckSumAdjustment);

            f   = TestFonts.GetOTFile_NotoNastaliqUrduRegular();
            idx = f.GetFont(0).OffsetTable.GetTableRecordIndex((OTTag)("head"));
            Assert.IsTrue(idx.HasValue);
            table  = null;
            result = f.GetFont(0).TryGetTable((OTTag)("head"), out table);
            Assert.IsTrue(result);
            head = (TableHead)table;
            Assert.AreEqual(head.CalculatedChecksum, head.TableRecordChecksum);
            Assert.AreEqual(head.CalculatedCheckSumAdjustment, head.CheckSumAdjustment);

            f   = TestFonts.GetOTFile_SelawikRegular();
            idx = f.GetFont(0).OffsetTable.GetTableRecordIndex((OTTag)("head"));
            Assert.IsTrue(idx.HasValue);
            table  = null;
            result = f.GetFont(0).TryGetTable((OTTag)("head"), out table);
            Assert.IsTrue(result);
            head = (TableHead)table;
            Assert.AreEqual(head.CalculatedChecksum, head.TableRecordChecksum);
            Assert.AreEqual(head.CalculatedCheckSumAdjustment, head.CheckSumAdjustment);
        }
示例#19
0
 public void OTFile_DestructEmpty()
 {
     OTFile target = new OTFile();
     try
     {
         target = null;
     }
     catch (Exception)
     {
         Assert.Fail("Error: Unexpected exception occured.");
     }
 }
示例#20
0
 /// <summary>Notify observer of FileBegin and FileEnd events</summary>
 public void OnFileValidationEvent(OTFile f, bool bBegin)
 {
     if (m_OnValidateEvent != null)
     {
         if (bBegin)
         {
             m_OnValidateEvent(EventTypes.FileBegin, f);
         }
         else
         {
             m_OnValidateEvent(EventTypes.FileEnd, f);
         }
     }
 }
示例#21
0
        public void OTFileCalcTableChecksumTest()
        {
            // construct OTFile, read from test font and get memory stream
            OTFile target = new OTFile();
            string FilePath = "TestData\\selawk.ttf";
            target.ReadFromFile(FilePath);
            System.IO.MemoryStream ms = target.GetMemoryStream();

            // Selawik GPOS table has a checksum of 0x8969_4DB2
            UInt32 expected = 0x8969_4DB2;
            // GPOS offset: 0x7BC4; length: 0x114C;
            UInt32 actual = OTFile.CalcTableCheckSum(ms, 0x7BC4, 0x114C);
            Assert.AreEqual(actual, expected);
        }
示例#22
0
 public void OTFileIsSupportedSfntVersionTest()
 {
     OTTag target = new OTTag(0x00010000);
     Assert.IsTrue(OTFile.IsSupportedSfntVersion(target), "Error: valid tag not recognized");
     target = new OTTag("OTTO");
     Assert.IsTrue(OTFile.IsSupportedSfntVersion(target), "Error: valid tag not recognized");
     target = new OTTag("ttcf");
     Assert.IsTrue(OTFile.IsSupportedSfntVersion(target), "Error: valid tag not recognized");
     target = new OTTag("true");
     Assert.IsTrue(OTFile.IsSupportedSfntVersion(target), "Error: invalid tag recognized");
     target = new OTTag("typ1");
     Assert.IsFalse(OTFile.IsSupportedSfntVersion(target), "Error: invalid tag recognized");
     target = new OTTag("xxxx");
     Assert.IsFalse(OTFile.IsSupportedSfntVersion(target), "Error: invalid tag recognized");
 }
示例#23
0
        public void ColrTableTest()
        {
            // Table constructor for 'COLR' will get the offset table record, calculate the table checksum
            // and then read the remainder of the table.

            OTFile f   = TestFonts.GetOTFile_BungeeColorRegular();
            uint?  idx = f.GetFont(0).OffsetTable.GetTableRecordIndex((OTTag)("COLR"));

            Assert.IsTrue(idx.HasValue);

            OTTable table;
            bool    result = f.GetFont(0).TryGetTable((OTTag)("COLR"), out table);

            Assert.IsTrue(result);
            VerifyBungeeColor_COLR((TableColr)(table));
        }
示例#24
0
        public void FmtxTableTest()
        {
            // Table constructor for 'fmtx' will get the offset table record, calculate the table checksum
            // and then read the remainder of the table.

            OTFile f   = TestFonts.GetOTFile_Skia();
            uint?  idx = f.GetFont(0).OffsetTable.GetTableRecordIndex((OTTag)("fmtx"));

            Assert.IsTrue(idx.HasValue);

            OTTable table;
            bool    result = f.GetFont(0).TryGetTable((OTTag)("fmtx"), out table);

            Assert.IsTrue(result);
            VerifySkiaFmtxTable((TableFmtx)(table));
        }
示例#25
0
        public void HheaTableTest2()
        {
            // Table constructor for 'hhea' will get the offset table record, calculate the table checksum
            // and then read the remainder of the table.

            OTFile f   = TestFonts.GetOTFile_SourceHanSans_Regular();
            uint?  idx = f.GetFont(0).OffsetTable.GetTableRecordIndex((OTTag)("hhea"));

            Assert.IsTrue(idx.HasValue);

            OTTable table;
            bool    result = f.GetFont(0).TryGetTable((OTTag)("hhea"), out table);

            Assert.IsTrue(result);
            VerifySourceHanSansHheaTable((TableHhea)(table));
        }
示例#26
0
        public void OTFileOpenTest_ReadTtcHeaderAndOffsetTables()
        {

            OTFile target = new OTFile();
            string FilePath = "TestData\\CAMBRIA.TTC";
            try
            {
                target.ReadFromFile(FilePath);
            }
            catch (Exception)
            {
                // unexpected exception
            }

            Assert.IsTrue(target.SfntVersionTag == (OTTag)("ttcf"), "Error: unexpected sfnt tag");
            // check one detail of ttc header
            Assert.IsTrue(target.TtcHeader.DSIGOffset == 0x0018AB54, "Error: unexpected TtcHeader value");
            Assert.IsTrue(target.NumFonts == 2, "Error: unexpected OTFile value");
            Assert.IsTrue(target.Length == 1622732, "Error: unexpected OTFile value");
            Assert.IsTrue(target.IsSupportedFileType, "Error: unexpected OTFile value");
            Assert.IsTrue(target.IsCollection, "Error: unexpected OTFile value");

            // now check that offset tables of both fonts are read
            OTFont f = target.GetFont(0);
            Assert.IsTrue(f.OffsetInFile == 0x20, "Error: unexpected font offset");
            Assert.IsTrue(f.SfntVersionTag == (OTTag)(0x00010000), "Error: unexpected font value");
            Assert.IsTrue(f.IsWithinTtc, "Error: unexpected font value");
            Assert.IsTrue(f.OffsetTable.OffsetInFile == 0x20, "Error: unexpected offset table offset");
            Assert.IsTrue(f.OffsetTable.SfntVersion == (OTTag)(0x00010000), "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.NumTables == 20, "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.SearchRange == 0x0100, "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.EntrySelector == 0x0004, "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.RangeShift == 64, "Error: unexpected font offset table value");

            f = target.GetFont(1);
            Assert.IsTrue(f.OffsetInFile == 0x16C, "Error: unexpected font offset");
            Assert.IsTrue(f.SfntVersionTag == (OTTag)(0x00010000), "Error: unexpected font value");
            Assert.IsTrue(f.IsWithinTtc, "Error: unexpected font value");
            Assert.IsTrue(f.OffsetTable.OffsetInFile == 0x16C, "Error: unexpected offset table offset");
            Assert.IsTrue(f.OffsetTable.SfntVersion == (OTTag)(0x00010000), "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.NumTables == 21, "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.SearchRange == 0x0100, "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.EntrySelector == 0x0004, "Error: unexpected font offset table value");
            Assert.IsTrue(f.OffsetTable.RangeShift == 80, "Error: unexpected font offset table value");
        }
示例#27
0
        public void OTFileReadUInt8Test()
        {
            byte[] b = new byte[32] { 0, 1, 0, 0, 0, 0x0F, 0, 0x80, 0, 3, 0, 0x70, 0x44, 0x53, 0x49, 0x47, 0xF0, 0x54, 0x3E, 0x26, 0, 0, 0x91, 0xE4, 0, 0, 0x1A, 0xDC, 0x47, 0x44, 0x45, 0x46 };
            MemoryStream ms = new MemoryStream(b);

            ms.Position = 5; // 0x0F
            Assert.IsTrue(OTFile.ReadUInt8(ms) == 0x0F, "Error: unexpected value read");
            ms.Position = 16; // 0xF0
            Assert.IsTrue(OTFile.ReadUInt8(ms) == 0xF0, "Error: unexpected value read");

            bool caughtExpectedException = false;
            ms.Position = ms.Length;
            try
            {
                OTFile.ReadUInt8(ms);
            }
            catch (OTDataIncompleteReadException)
            {
                caughtExpectedException = true;
            }
            catch (Exception)
            {
                // unexpected exception
            }
            Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught");

            ms.Close();
            caughtExpectedException = false;
            try
            {
                OTFile.ReadUInt8(ms);
            }
            catch (ObjectDisposedException)
            {
                caughtExpectedException = true;
            }
            catch (Exception)
            {
                // unexpected exception
            }
            Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught");
        }
示例#28
0
        public void OTFileOpenTest_InvalidFile_3Bytes()
        {
            bool caughtExpectedException = false; // will set to true if expected exception is caught

            OTFile target = new OTFile();
            string FilePath = "TestData\\InvalidFile_3Bytes.ttf";
            try
            {
                target.ReadFromFile(FilePath);
            }
            catch (OTFileParseException)
            {
                caughtExpectedException = true;
            }
            catch (Exception)
            {
                // unexpected exception
            }
            Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught");
        }
示例#29
0
        public void OTFileOpenTest_UnsupportedSfntTag()
        {
            OTFile target = new OTFile();
            bool caughtExpectedException = false; // will set to true if expected exception is caught

            // test for unrecognized sfnt tag
            string FilePath = "TestData\\InvalidFile_4Bytes.ttf";
            try
            {
                target.ReadFromFile(FilePath);
            }
            catch (OTFileParseException)
            {
                caughtExpectedException = true;
            }
            catch (Exception)
            {
                // unexpected exception
            }
            Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught");
        }
示例#30
0
        public void OTFileGetFileInfoTest()
        {
            OTFile target = new OTFile();

            string FilePath = "TestData\\selawk.ttf";
            try
            {
                target.ReadFromFile(FilePath);
            }
            catch (Exception)
            {
                // unexpected exception
            }

            FileInfo expected = new FileInfo(FilePath);
            FileInfo actual = target.GetFileInfo();
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.IsTrue(actual.Length == expected.Length);
            Assert.IsTrue(actual.Name == "selawk.ttf");
            Assert.IsTrue(actual.Extension == ".ttf");
            Assert.IsTrue(actual.DirectoryName == Directory.GetCurrentDirectory() + "\\TestData");
        }