Esempio n. 1
0
        public void LoadFormat0()
        {
            var writer = new BinaryWriter();

            //int subtableCount = 1;
            writer.WriteCMapSubTable(new Format0SubTable(0, PlatformIDs.Windows, 2, new byte[] {
                1, 2, 3, 4, 5, 6, 7, 8
            }));

            BinaryReader reader = writer.GetReader();
            ushort       format = reader.ReadUInt16(); // read format before we pass along as thats whet the cmap table does

            Assert.Equal(0, format);

            Format0SubTable table = Format0SubTable.Load(new[] {
                new EncodingRecord(PlatformIDs.Windows, 2, 0)
            }, reader).Single();

            Assert.Equal(0, table.Language);
            Assert.Equal(PlatformIDs.Windows, table.Platform);
            Assert.Equal(2, table.Encoding);
            Assert.Equal(new byte[] {
                1, 2, 3, 4, 5, 6, 7, 8
            }, table.GlyphIds);
        }
Esempio n. 2
0
        public static CMapTable Load(BinaryReader reader)
        {
            ushort version   = reader.ReadUInt16();
            ushort numTables = reader.ReadUInt16();

            var encodings = new EncodingRecord[numTables];

            for (int i = 0; i < numTables; i++)
            {
                encodings[i] = EncodingRecord.Read(reader);
            }

            // foreach encoding we move forward looking for th subtables
            var tables = new List <CMapSubTable>(numTables);

            foreach (IGrouping <uint, EncodingRecord> encoding in encodings.Where(x => x.PlatformID == PlatformIDs.Windows).GroupBy(x => x.Offset))
            {
                reader.Seek(encoding.Key, System.IO.SeekOrigin.Begin);

                ushort subTypeTableFormat = reader.ReadUInt16();

                switch (subTypeTableFormat)
                {
                case 0:
                    tables.AddRange(Format0SubTable.Load(encoding, reader));
                    break;

                case 4:
                    tables.AddRange(Format4SubTable.Load(encoding, reader));
                    break;
                }
            }

            return(new CMapTable(tables.ToArray()));
        }
Esempio n. 3
0
        public void GetCharacter_missing()
        {
            Format0SubTable format = new Format0SubTable(0, PlatformIDs.Windows, 2, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });

            ushort id = format.GetGlyphId(99);

            Assert.Equal(0, id);
        }
Esempio n. 4
0
        public void GetCharacter()
        {
            var format = new Format0SubTable(0, PlatformIDs.Windows, 2, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });

            ushort id = format.GetGlyphId(4);

            Assert.Equal(5, id);
        }
        public void GetCharacter_missing()
        {
            var format = new Format0SubTable(0, PlatformIDs.Windows, 2, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });

            bool found = format.TryGetGlyphId(new CodePoint(99), out ushort id);

            Assert.False(found);
            Assert.Equal(0, id);
        }
Esempio n. 6
0
        public static void WriteCMapSubTable(this BinaryWriter writer, Format0SubTable subtable)
        {
            if (subtable == null)
            {
                return;
            }

            // Format 0 SubTable
            // Type     |Name              | Description
            // ---------|------------------|--------------------------------------------------------------------------
            // uint16   |format            | Format number is set to 0.
            // uint16   |length            | This is the length in bytes of the subtable.
            // uint16   |language          | Please see “Note on the language field in 'cmap' subtables“ in this document.
            // uint8    |glyphIdArray[glyphcount] | An array that maps character codes to glyph index values.
            writer.WriteUInt16(0);
            writer.WriteUInt16((ushort)subtable.DataLength());
            writer.WriteUInt16(subtable.Language);

            foreach (byte c in subtable.GlyphIds)
            {
                writer.WriteUInt8(c);
            }
        }