Skip to content

Commit

Permalink
fix: 紫光 uwl 不支持 GBK
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan authored and studyzy committed Jul 1, 2022
1 parent 82d278a commit fc3f52f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/ImeWlConverterCore/IME/ZiGuangPinyinUwl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public WordLibraryList Import(string path)
{
var pyAndWord = new WordLibraryList();
var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
fs.Position = 0x02;
int enc = fs.ReadByte();
Encoding encoding = (enc == 0x09) ? Encoding.Unicode : Encoding.GetEncoding("GB18030");

fs.Position = 0x44;
CountWord = BinFileHelper.ReadInt32(fs);
int segmentCount = BinFileHelper.ReadInt32(fs); //分为几段
Expand All @@ -57,7 +61,7 @@ public WordLibraryList Import(string path)
try
{
fs.Position = 0xC00 + 1024*i;
var segment = new Segment(fs);
var segment = new Segment(fs, encoding);
pyAndWord.AddWordLibraryList(segment.WordLibraryList);
CurrentStatus += segment.WordLibraryList.Count;
}
Expand Down Expand Up @@ -218,8 +222,9 @@ public class Segment
//private readonly IList<byte> LenDic = new List<byte>
//{0x05, 0x87, 0x09, 0x8B, 0x0D, 0x8F, 0x11, 0x13, 0x15, 0x17, 0x19};

public Segment(Stream stream)
public Segment(Stream stream,Encoding encoding)
{
UwlEncoding = encoding;
IndexNumber = BinFileHelper.ReadInt32(stream);
int ff = BinFileHelper.ReadInt32(stream);
WordLenEnums = BinFileHelper.ReadInt32(stream);
Expand All @@ -244,6 +249,7 @@ public Segment(Stream stream)
//FF
public int WordLenEnums { get; set; }
public int WordByteLen { get; set; }
public Encoding UwlEncoding { get; set; }

public WordLibraryList WordLibraryList { get; set; }

Expand Down Expand Up @@ -293,7 +299,7 @@ private WordLibrary Parse(Stream stream, out int lenByte)
//hz
var hzB = new byte[lenWord];
stream.Read(hzB, 0, lenWord);
wl.Word = Encoding.Unicode.GetString(hzB);
wl.Word = UwlEncoding.GetString(hzB);

return wl;
}
Expand Down

0 comments on commit fc3f52f

Please sign in to comment.