private Hanzi parseCharacter(string line) { Hanzi hanzi = new Hanzi(); JObject o = JObject.Parse(line); string strChar = (string)o["character"]; if (strChar.Length != 1) { throw new Exception("Not a character: " + strChar); } hanzi.Char = strChar[0]; var strokes = (JArray)o["medians"]; foreach (var jsonStroke in strokes.Children()) { Stroke stroke = new Stroke(); foreach (var jsonPoint in jsonStroke.Children()) { Point point = new Point { X = (int)jsonPoint[0], Y = (int)jsonPoint[1], }; stroke.Points.Add(point); } hanzi.Strokes.Add(stroke); } return(hanzi); }
public challenge(User user) { InitializeComponent(); this.user = user; this.cha = new Challenge(user); Atimer.Tick += Atimer_Tick; Atimer.Interval = 25; Hanzi Ahanzi = HanziIO.Read("中"); hanziPictureBox1.Hanzi = Ahanzi; hanziPictureBox1.Completed += cha.OnFinishHanzi; hanziPictureBox1.Enabled = false; cha.FinishLevel += OnFinishLevel; cha.FinishLevel += user.Achievement.OnFinishLevel; cha.Lose += OnLose; next.Visible = true; next.Enabled = true; timer1.Interval = 25; timeMaxLength = resttime.Width; resttime.BackColor = Color.Cyan; }
public learn() { InitializeComponent(); Atimer.Tick += Atimer_Tick; Atimer.Interval = 25; Ale = this; Ahanzi = HanziIO.Read(Ahanzilist[i].Zi); this.hanziPictureBox1.Hanzi = Ahanzi; hanziPictureBox1.CorrectDrew += new BihuaHandler(OnCorrectDrew); hanziPictureBox1.WrongDrew += new BihuaHandler(OnWrongDrew); hanziPictureBox1.Completed += new BihuaHandler(OnCompleted); this.paraphrase.Text = Ahanzi.Info; this.infoLabel.Text = "已成功载入汉字 " + "'" + Ahanzi.Zi + "'"; }
private void AddNewHanzi(string newChar) { if (newChar == null) { return; } if (mySemanticGraph.ContainsNode(newChar)) { return; } Hanzi newHanzi = new Hanzi(newChar); ErrorCode err; mySemanticGraph.AddNode(newHanzi, out err); }
/// <summary> /// Parses MMAH graphics.txt and analyzes characters; keeps all data in memory. /// </summary> public void Parse(string mmahGraphicsFileName) { using (FileStream fs = new FileStream(mmahGraphicsFileName, FileMode.Open, FileAccess.Read)) using (StreamReader sr = new StreamReader(fs)) { string line; while ((line = sr.ReadLine()) != null) { Hanzi hanzi = parseCharacter(line); normalize(hanzi); Analyzer a = new Analyzer(hanzi.Strokes); hanzi.SubStrokes = a.AnalyzedStrokes; data.Add(hanzi); } } }
private Hanzi parseHanzi(JArray jsonChar) { Hanzi hanzi = new Hanzi { Char = jsonChar[0].ToObject <string>()[0], StrokeCount = jsonChar[1].ToObject <int>(), SubStrokes = new List <SubStroke>(), }; JArray jsonSubStrokes = jsonChar[2] as JArray; foreach (var x in jsonSubStrokes.Children()) { JArray jsonSS = x as JArray; SubStroke ss = new SubStroke { Dir = jsonSS[0].ToObject <double>(), Len = jsonSS[1].ToObject <double>(), }; hanzi.SubStrokes.Add(ss); } return(hanzi); }
/// <summary> /// Converts coordinates to sane top-down system; 256x256 canvas. /// </summary> private static void normalize(Hanzi hanzi) { double ratio = 256.0 / 1024.0; foreach (var stroke in hanzi.Strokes) { for (int i = 0; i != stroke.Points.Count; ++i) { Point pt = stroke.Points[i]; double x = pt.X; double y = pt.Y; y = 900 - y; x *= ratio; y *= ratio; x = Math.Round(x); y = Math.Round(y); stroke.Points[i] = new Point { X = (int)x, Y = (int)y }; } } }
private static Hanzi FindHanziCanonical( IReadOnlyCollection <YngdiengDocument.Types.Source> sources, Hanzi fromZingzeuWords) { var feng = sources.FirstOrDefault(s => s.SourceCase == SourceOneofCase.Feng)?.Feng ?? null; if (feng != null) { return(new Hanzi {/* TODO: check for IDS in FengDocument.HanziCanonical */ Regular = feng.HanziCanonical }); } if (fromZingzeuWords != null) { return(fromZingzeuWords); } var historicalDoc = sources.FirstOrDefault(s => s.SourceCase == SourceOneofCase.CiklinDfd) ?.CiklinDfd ?? null; if (historicalDoc != null) { return(historicalDoc.HanziCanonical); } var contrib = sources.FirstOrDefault(s => s.SourceCase == SourceOneofCase.Contrib) ?.Contrib ?? null; if (contrib != null) { return(new Hanzi {/* TODO: check for IDS in ContribDocument.Hanzi */ Regular = contrib.Hanzi }); } return(null); }
private void prev_Click(object sender, EventArgs e) { Sound.PlaySE("se_buttonclick"); try { if (i - 1 < 0) { throw new UserException("已返回字表顶端!"); } Ahanzi = HanziIO.Read(Ahanzilist[--i].Zi); this.hanziPictureBox1.Hanzi = Ahanzi; this.paraphrase.Text = Ahanzi.Info; this.infoLabel.Text = "已成功载入汉字 " + "'" + Ahanzi.Zi + "'"; } catch (UserException A) { wrong Awrong = new wrong(A.Message); Awrong.Shown += BlockWindow; Awrong.FormClosed += UnblockWindow; Awrong.OnShow(); } }
public static string HanziToString(Hanzi h) { return(h.HanziCase == Hanzi.HanziOneofCase.Regular ? h.Regular : h.Ids); }
public void WriteResults(string compactFileName) { Dictionary <char, int> hanziToSubStrokePos = new Dictionary <char, int>(); List <byte> subStrokeData = new List <byte>(); foreach (Hanzi hanzi in data) { hanziToSubStrokePos[hanzi.Char] = subStrokeData.Count; for (int i = 0; i != hanzi.SubStrokes.Count; ++i) { SubStroke ss = hanzi.SubStrokes[i]; double x = ss.Dir * 256.0 / Math.PI / 2.0; int y = (int)Math.Round(x); if (y == 256) { y = 0; } if (y < 0 || y > 255) { throw new Exception("Value out of byte range."); } subStrokeData.Add((byte)y); x = ss.Len * 255.0; y = (int)Math.Round(x); if (y < 0 || y > 255) { throw new Exception("Value out of byte range."); } subStrokeData.Add((byte)y); y = (int)Math.Round(ss.CenterX * 15.0); if (y < 0 || y > 15) { throw new Exception("Value out of byte range."); } byte coords = (byte)y; coords <<= 4; y = (int)Math.Round(ss.CenterY * 15.0); if (y < 0 || y > 15) { throw new Exception("Value out of byte range."); } coords += (byte)y; subStrokeData.Add(coords); } } string base64 = Convert.ToBase64String(subStrokeData.ToArray()); using (FileStream fs = new FileStream(compactFileName, FileMode.Create, FileAccess.ReadWrite)) using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine("{ \"chars\": ["); for (int i = 0; i != data.Count; ++i) { Hanzi hanzi = data[i]; string line = "[\"" + hanzi.Char + "\"," + hanzi.StrokeCount + ","; line += hanzi.SubStrokes.Count + ","; line += hanziToSubStrokePos[hanzi.Char] + "]"; if (i + 1 < data.Count) { line += ","; } sw.WriteLine(line); } sw.WriteLine("],"); sw.WriteLine("\"substrokes\": \"" + base64 + "\""); sw.WriteLine("}"); } }
public int CompareTo(Word other) { int diff = Hanzi.CompareTo(other.Hanzi); return(diff != 0 ? diff : Traditional.CompareTo(other.Traditional)); }