コード例 #1
0
        /// <summary>
        /// Loads the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public static OpenTypeFont Load(OpenTypeFontReader reader, int index)
        {
            if (reader == null)
            {
                throw new PdfArgumentNullException("reader");
            }
            long position = reader.Position;

            if (reader.ReadLONG() == 0x74746366)
            {
                reader.ReadFixed();
                long num3 = reader.ReadULONG();
                if ((index < 0) || (index >= num3))
                {
                    throw new PdfReadFontException("index must be bigger than 0 and less than " + ((long)num3) + ".");
                }
                reader.Skip((long)(4 * index));
                long pos = reader.ReadULONG();
                reader.Seek(pos);
            }
            else
            {
                reader.Seek(position);
            }
            return(new OpenTypeFont(reader));
        }
コード例 #2
0
        /// <summary>
        /// Gets the sub font.
        /// </summary>
        /// <param name="chars">The chars.</param>
        /// <param name="isCFF">if set to <c>true</c> [is CFF].</param>
        /// <returns></returns>
        public override byte[] GetSubFont(Dictionary <char, int> chars, out bool isCFF)
        {
            if (this.IsCFF)
            {
                isCFF = true;
                OpenTypeFontReader reader = this.tables["CFF "].Reader;
                reader.Seek(0L);
                return(reader.ReadBytes((int)reader.Length));
            }
            isCFF = false;
            if (!base.isSubSet)
            {
                return(this.reader.ToArray());
            }
            List <string> list = new List <string> {
                "head", "glyf", "loca"
            };

            if (base.encoding == "WinAnsiEncoding")
            {
                list.Add("cmap");
            }
            list.Add("hhea");
            list.Add("maxp");
            list.Add("hmtx");
            list.Add("cvt ");
            list.Add("fpgm");
            list.Add("prep");
            if (!base.isSubSet)
            {
                list.Add("OS/2");
                if (!list.Contains("cmap"))
                {
                    list.Add("cmap");
                }
                list.Add("name");
            }
            OpenTypeFontWriter writer = new OpenTypeFontWriter();
            int i    = 0;
            int num2 = 0;
            int num3 = 1;

            foreach (string str in list)
            {
                if (this.tables.ContainsKey(str))
                {
                    i++;
                }
            }
            for (int j = 0; j < 0x20; j++)
            {
                if (num3 > i)
                {
                    break;
                }
                num3 = num3 << 1;
                num2++;
            }
            num2--;
            int num5 = (num3 / 2) * 0x10;
            int num6 = (i * 0x10) - num5;

            writer.WriteFixed(1f);
            writer.WriteSHORT(i);
            writer.WriteSHORT(num5);
            writer.WriteSHORT(num2);
            writer.WriteSHORT(num6);
            long position = writer.Position;

            writer.WriteBytes((int)(i * 0x10));
            List <OpenTypeFontTable> list2 = new List <OpenTypeFontTable>();

            foreach (string str2 in list)
            {
                if (this.tables.ContainsKey(str2))
                {
                    OpenTypeFontTable subset = this.tables[str2].GetSubset(chars);
                    long num8 = writer.Position;
                    writer.Write(subset.Reader);
                    list2.Add(subset);
                    subset.Offset = num8;
                }
            }
            writer.Seek(position);
            foreach (OpenTypeFontTable table2 in list2)
            {
                writer.WriteString(table2.Tag);
                writer.WriteLONG(table2.CheckSum);
                writer.WriteLONG(table2.Offset);
                writer.WriteLONG(table2.Length);
            }
            return(writer.ToArray());
        }