Example #1
0
        /// <summary>
        /// Creates an XML document from a character.
        /// </summary>
        /// <param name="character">The character.</param>
        /// <returns></returns>
        public static XmlDocument CreateXMLDocumentFromCharacter(Character character)
        {
            XmlDocument output = null;

            output = new XmlDocument();
            output.LoadXml("<ink></ink>");
            character.ToXmlNode(output, output.DocumentElement);
            //for (int i = 0; i < c.StrokeList.Count; i++)
            //{
            //    c.StrokeList[i].ToXmlNode(xmldoc, xmldoc.DocumentElement);
            //}

            return output;
        }
Example #2
0
        /// <summary>
        /// Reads the element content as a character from intermediate format.
        /// </summary>
        /// <param name="xmlr">The XMLR.</param>
        /// <returns></returns>
        private static Character ReadElementContentAsCharacter(this XmlTextReader xmlr)
        {
            if (xmlr.NodeType == XmlNodeType.Element)
            {
                if (xmlr.Name == "character")
                {
                    Character c = new Character();

                    xmlr.ReadStartElement("character"); //now moving to generalinfo

                    //now we should be at the first stroke

                    while (xmlr.NodeType != XmlNodeType.EndElement)
                    {
                        if (xmlr.NodeType == XmlNodeType.Element)
                        {
                            switch (xmlr.Name)
                            {
                                case "GeneralInfo":
                                    c.SHKK = xmlr.ReadElementContentAsString();// +".inkml";
                                    break;

                                case "stroke":
                                    c.StrokeList.Add(xmlr.ReadElementContentAsStroke());
                                    c.StrokeList[c.StrokeList.Count - 1].ID = StringTools.AddZeros(c.StrokeList.Count, 4);
                                    break;
                            }
                        }
                        else xmlr.Read(); //move on
                    }
                    xmlr.ReadEndElement();
                    return c;
                }
                else throw new Exception(string.Format("Not the correct element. This was a {0}-tag", xmlr.Name));
            }
            else throw new Exception("Not even an element type");
        }
Example #3
0
        private static void TestCharacterHashing()
        {
            Random rand = new Random();
            List<Point> p = new List<Point>();

            DateTime now = DateTime.Now;

            int randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            p.Add(new Point(1, 1, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            p.Add(new Point(2, 2, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            p.Add(new Point(4, 2, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            p.Add(new Point(5, 3, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            p.Add(new Point(6, 2, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            p.Add(new Point(6, 3, new DateTime(now.Ticks - randNext)));

            List<Point> q = new List<Point>();
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            q.Add(new Point(2, 4, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            q.Add(new Point(3, 5, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            q.Add(new Point(5, 5, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            q.Add(new Point(6, 6, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            q.Add(new Point(7, 5, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            q.Add(new Point(7, 6, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            q.Add(new Point(8, 7, new DateTime(now.Ticks - randNext)));
            randNext = rand.Next((int)Math.Pow(10, 4), (int)Math.Pow(10, 5));
            q.Add(new Point(9, 8, new DateTime(now.Ticks - randNext)));

            Stroke s = new Stroke(p);
            Stroke s2 = new Stroke(p);
            Stroke r = new Stroke(q);

            List<Stroke> strokelist = new List<Stroke>();
            strokelist.Add(s);
            strokelist.Add(s2);
            strokelist.Add(r);

            Radical rad1 = new Radical(strokelist);
            Radical rad2 = new Radical(strokelist);
            List<Radical> rl = new List<Radical>(2);
            rl.Add(rad1);
            rl.Add(rad2);
            Character ch = new Character(rl);

            BinaryWriter bw = new BinaryWriter(new FileStream("test", FileMode.Create, FileAccess.Write, FileShare.None));
            bw.Write(ch.Hash(false));
            bw.Close();
        }
Example #4
0
        /// <summary>
        /// Reads the upx element content as a character.
        /// </summary>
        /// <param name="xmlr">The XMLR.</param>
        /// <returns>An instance of the Character class</returns>
        public static Character ReadUPXElementContentAsCharacter(this XmlTextReader xmlr)
        {
            if (UPXReader.IsUPXhLevelCharacter(xmlr))
            {
                Character c = new Character();

                c.SHKK = XmlTools.ReadIDAttribute(xmlr);

                //now moving to label and reading it
                //then the radicals
                //if we're hitting and end element that is an hLevel stop reading
                //the ones from the Radicals should be eaten within ReadUPXElementContentAsRadical
                while (xmlr.Read() && (!IsEndElementTypeWithName(xmlr, "hLevel")))
                {
                    if (xmlr.NodeType == XmlNodeType.Element)
                    {
                        Radical rTemp = null;

                        switch (xmlr.Name)
                        {
                            case "label":
                                c.Value = ReadUPXElementContentAsLabel(xmlr, c.SHKK);
                                break;
                            case "hLevel":
                                if (IsUPXhLevelRadical(xmlr))
                                {
                                    rTemp = ReadUPXElementContentAsRadical(xmlr);
                                    c.RadicalList.Add(rTemp);
                                }
                                break;
                        }
                    }
                }

                return c;
            }
            else throw new Exception(string.Format("Not the correct element. This was a {0}-tag", xmlr.Name));
        }