示例#1
0
文件: cod.cs 项目: HappyASR/pujia
        public static bool ExportFont(string input, string refinput)
        {
            StreamEx sOri = new StreamEx(input, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            List <UInt16> originChars = new List <UInt16>();

            while (sOri.Position < sOri.Length)
            {
                originChars.Add(sOri.ReadUInt16BigEndian());
                sOri.Position += 6;
            }
            sOri.Close();

            // load ref file
            StreamEx sRef = new StreamEx(refinput, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            if (sRef.Length < 2)
            {
                return(false);
            }
            byte xff = sRef.ReadByte();
            byte xfe = sRef.ReadByte();

            if (xff != 0xff || xfe != 0xfe)
            {
                return(false);
            }
            while (sRef.Position < sRef.Length)
            {
                UInt16 c = sRef.ReadUInt16();
                if (!originChars.Contains(c))
                {
                    // add not already exist char
                    originChars.Add(c);
                }
            }
            sRef.Close();

            StreamEx sExp = new StreamEx(input + ".txt", System.IO.FileMode.Create, System.IO.FileAccess.Write);

            sExp.WriteByte(0xff);
            sExp.WriteByte(0xfe);
            foreach (UInt16 c in originChars)
            {
                sExp.WriteUInt16(c);
            }

            sExp.Close();

            return(true);
        }
示例#2
0
文件: ctdb.cs 项目: HappyASR/pujia
        public static void Import(string input)
        {
            StreamEx s = new StreamEx(input, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            string[] txtVal = Agemo.ReadFile(input + ".txt", _agemoEncoding);
            StreamEx si     = new StreamEx(input + ".imp", System.IO.FileMode.Create, System.IO.FileAccess.Write);

            // section offset
            s.Position = 0x10;
            Int32 sec1Offset = s.ReadInt32BigEndian();
            Int32 sec2Offset = s.ReadInt32BigEndian();
            Int32 sec3Offset = s.ReadInt32BigEndian();

            // before text data
            s.Position = 0;
            byte[] beforeText = s.Read(sec3Offset);
            si.Write(beforeText);
            si.Flush();

            // text
            UInt16[] txtOffset = new UInt16[txtVal.Length];
            for (int i = 0; i < txtVal.Length; i++)
            {
                txtOffset[i] = (UInt16)si.Position;
                txtVal[i]    = txtVal[i].Substring(0, txtVal[i].Length - 5);

                for (int k = 0; k < _convertChar.Count; k++)
                {
                    txtVal[i] = txtVal[i].Replace(_convertChar[k].Value, _convertChar[k].Key);
                }

                for (int j = 0; j < txtVal[i].Length; j++)
                {
                    si.WriteUInt16BigEndian((UInt16)txtVal[i][j]);
                }
                si.WriteUInt16(0);
            }

            // text offset
            si.Position = sec1Offset;
            for (int i = 0; i < txtOffset.Length; i++)
            {
                si.Position += 6;
                si.WriteUInt16BigEndian(txtOffset[i]);
            }
            si.Close();
        }