Пример #1
0
        /// <summary>
        /// 从cfg文件读取数据构造FontConfig
        /// </summary>
        /// <param name="file"></param>
        public void FromCfg(FileInfo file)
        {
            string[] allLines = File.ReadAllLines(file.FullName);
            foreach (string line in allLines)
            {
                if (string.IsNullOrEmpty(line.Trim()))//不处理空行
                {
                    continue;
                }

                string temp = line;
                temp = temp.Substring(0, temp.LastIndexOf(";"));
                string[] words = temp.Split(new char[] { ',' });
                switch (GetId(line))
                {
                case CurrentId.INF:
                    words[0] = words[0].Replace(INF.Name, "");
                    Inf      = new INF
                    {
                        TileHeight = int.Parse(words[0].Trim()),
                        Number     = int.Parse(words[1].Trim()),
                        Width      = int.Parse(words[2].Trim()),
                        Height     = int.Parse(words[3].Trim()),
                        CS         = int.Parse(words[4].Trim())
                    };
                    break;

                case CurrentId.CHR:
                    words[0] = words[0].Replace(CHR.Name, "");
                    CHR c = new CHR
                    {
                        SJS      = int.Parse(words[0].Trim()),
                        UTF8     = int.Parse(words[1].Trim()),
                        X        = uint.Parse(words[2].Trim()),
                        Y        = uint.Parse(words[3].Trim()),
                        Width    = int.Parse(words[4].Trim()),
                        Unknown1 = int.Parse(words[5].Trim()),
                        Unknown2 = int.Parse(words[6].Trim()),
                        Channel  = int.Parse(words[7].Trim())
                    };
                    Chr.Add(c);
                    break;

                case CurrentId.KERNINF:
                    words[0] = words[0].Replace(KERNINF.Name, "");
                    KernInfo = new KERNINF
                    {
                        Number = int.Parse(words[0].Trim())
                    };
                    break;

                case CurrentId.KERN:
                    words[0] = words[0].Replace(KERN.Name, "");
                    KERN k = new KERN
                    {
                        Unknown1 = int.Parse(words[0].Trim()),
                        Unknown2 = int.Parse(words[1].Trim()),
                        Unknown3 = int.Parse(words[2].Trim())
                    };
                    Kern.Add(k);
                    break;

                case CurrentId.END:
                    break;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 从bin文件读取数据构造FontConfig
        /// </summary>
        /// <param name="file"></param>
        public void FromBin(FileInfo file)
        {
            using (FileStream stream = file.OpenRead())
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    IdentifierCount = DataConverter.BigEndian.GetUInt32(reader.ReadBytes(4), 0);
                    EndOffset       = DataConverter.BigEndian.GetUInt32(reader.ReadBytes(4), 0);
                    stream.Seek(0x10, SeekOrigin.Begin);
                    //INF是肯定存在的
                    byte[] id = reader.ReadBytes(8);
                    while (!ByteCompare(END.Identifier, id))
                    {
                        switch (GetId(id))
                        {
                        case CurrentId.INF:
                            Inf = new INF
                            {
                                TileHeight = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                Number     = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                Width      = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                Height     = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                CS         = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0)
                            };
                            break;

                        case CurrentId.CHR:
                            CHR c = new CHR
                            {
                                SJS      = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                UTF8     = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                X        = DataConverter.BigEndian.GetUInt32(reader.ReadBytes(4), 0),
                                Y        = DataConverter.BigEndian.GetUInt32(reader.ReadBytes(4), 0),
                                Width    = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                Unknown1 = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                Unknown2 = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                Channel  = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0)
                            };
                            Chr.Add(c);
                            break;

                        case CurrentId.KERNINF:
                            KernInfo = new KERNINF
                            {
                                Number = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0)
                            };
                            break;

                        case CurrentId.KERN:
                            KERN k = new KERN
                            {
                                Unknown1 = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                Unknown2 = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0),
                                Unknown3 = DataConverter.BigEndian.GetInt32(reader.ReadBytes(4), 0)
                            };
                            Kern.Add(k);
                            break;

                        case CurrentId.END:
                            break;
                        }
                        id = reader.ReadBytes(8);
                    }
                }
            }
        }