Exemplo n.º 1
0
        /// <summary>
        /// Reads an InkML file and creates a number list strokes from the traces.
        /// </summary>
        /// <param name="pathToInkMLFile">The path to ink ML file.</param>
        /// <returns></returns>
        public static List <Stroke> ReadInkMLFile(string pathToInkMLFile)
        {
            List <Stroke> r           = new List <Stroke>(10);
            FileStream    inputstream =
                new FileStream(
                    path + Path.DirectorySeparatorChar + pathToInkMLFile,
                    FileMode.Open);

            XmlTextReader xmlr = new XmlTextReader(inputstream);


            while ((!UPXReader.IsEndElementTypeWithName(xmlr, "ink")))
            {
                if (UPXReader.IsElementTypeWithName(xmlr, "trace"))
                {
                    Console.WriteLine(XmlTools.ReadIDAttribute(xmlr));
                    r.Add(new Stroke(
                              Stroke.PointListFromInkMLTrace(
                                  xmlr.ReadElementContentAsString())));
                }
                else
                {
                    xmlr.Read();  //overread element
                }
            }

            xmlr.Close();
            inputstream.Close();

            return(r);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses a UPX file.
        /// </summary>
        /// <param name="inputstream">The inputstream.</param>
        /// <returns>A List&lt;<see cref="Kanji.DesktopApp.LogicLayer.Character"/>&gt;</returns>
        public static List <Character> ParseUPXFile(Stream inputstream)
        {
            XmlTextReader    xmlr          = new XmlTextReader(inputstream);
            List <Character> characterList = new List <Character>();

            //if we're hitting and end element that is a hLevel stop reading
            //the ones from the strokes should be read within ReadUPXElementContentAsStroke
            while (xmlr.Read() && (!IsEndElementTypeWithName(xmlr, "hwData")))
            {
                if (UPXReader.IsUPXhLevelCharacter(xmlr))
                {
                    characterList.Add(UPXReader.ReadUPXElementContentAsCharacter(xmlr));
                }
            }

            return(characterList);
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reads the UPX element content as radical.
        /// </summary>
        /// <param name="xmlr">The XMLR.</param>
        /// <returns>An instance of the Radical class</returns>
        private static Radical ReadUPXElementContentAsRadical(XmlTextReader xmlr)
        {
            if (UPXReader.IsUPXhLevelRadical(xmlr) && (xmlr.HasAttributes))
            {
                Radical r = new Radical();

                r.ID = XmlTools.ReadIDAttribute(xmlr);

                //now moving to label and reading it
                //then the strokes
                //if we're hitting and end element that is a hLevel stop reading
                //the ones from the strokes should be eaten within ReadUPXElementContentAsStroke
                while (xmlr.Read() && (!IsEndElementTypeWithName(xmlr, "hLevel")))
                {
                    if (xmlr.NodeType == XmlNodeType.Element)
                    {
                        Stroke sTemp = null;
                        switch (xmlr.Name)
                        {
                        case "label":
                            r.Value = ReadUPXElementContentAsLabel(xmlr, r.ID);
                            break;

                        case "hLevel":
                            if (IsUPXhLevelStroke(xmlr))
                            {
                                sTemp = ReadUPXElementContentAsStroke(xmlr);
                                r.StrokeList.Add(sTemp);
                            }
                            break;
                        }
                    }
                }
                return(r);
            }
            else
            {
                throw new Exception(string.Format("Not the correct element. This was a {0}-tag.", xmlr.Name));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads the upx element content as a character.
        /// </summary>
        /// <param name="xmlr">The XMLR.</param>
        /// <returns>An instance of the Stroke class</returns>
        public static Stroke ReadUPXElementContentAsStroke(XmlTextReader xmlr)
        {
            if (UPXReader.IsUPXhLevelStroke(xmlr) && (xmlr.HasAttributes))
            {
                Stroke s = new Stroke();

                s.ID = XmlTools.ReadIDAttribute(xmlr);

                //now moving to label and reading it
                //then the strokes
                //if we're hitting and end element that is a hLevel stop reading
                //when hLevel end element is hit, stroke is finished
                while (xmlr.Read() && (!IsEndElementTypeWithName(xmlr, "hLevel")))
                {
                    if (xmlr.NodeType == XmlNodeType.Element)
                    {
                        switch (xmlr.Name)
                        {
                        case "label":
                            s.Value = ReadUPXElementContentAsLabel(xmlr, s.ID);
                            break;

                        case "hwTraces":
                            if (IsElementTypeWithName(xmlr, "hwtraces"))
                            {
                                s.AllPoints = ReadUPXElementContentAsPointList(xmlr);
                            }
                            break;
                        }
                    }
                }
                return(s);
            }
            else
            {
                throw new Exception(string.Format("Not the correct element. This was a {0}-tag.", xmlr.Name));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Reads an InkML trace.
        /// </summary>
        /// <param name="traceRef">The trace reference to read.</param>
        /// <returns></returns>
        public static List <Point> ReadInkMLTrace(string traceRef)
        {
            List <Point> retval = null;

            string[] pathXmlFile = traceRef.Split('#');
            string   filename    = path + Path.DirectorySeparatorChar + pathXmlFile[0];
            string   ID          = pathXmlFile[1];

            FileStream    inputstream = new FileStream(filename, FileMode.Open);
            XmlTextReader xmlr        = new XmlTextReader(inputstream);

            //var elements = XElement.Load(path + Path.DirectorySeparatorChar + pathXmlFile[0]);

            //var myTrace = from a in elements.Elements()
            //              where a.Attribute("id").Value.Equals(pathXmlFile[1])
            //              select a.Element("trace").Value;

            string trace = string.Empty;

            while (xmlr.Read() && (!UPXReader.IsEndElementTypeWithName(xmlr, "ink")))
            {
                if ((UPXReader.IsElementTypeWithName(xmlr, "trace"))
                    &&
                    (ID == XmlTools.ReadIDAttribute(xmlr)))
                {
                    trace  = xmlr.ReadElementContentAsString();
                    retval = Stroke.PointListFromInkMLTrace(trace);
                    break; //finished reading, now splitting the trace
                }
            }

            xmlr.Close();
            inputstream.Close();

            return(retval);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Creates an XmlDocument from the current character.
 /// </summary>
 /// <returns>An instance of the XmlDocument class</returns>
 public XmlDocument ToXmlDocument()
 {
     return(UPXReader.CreateXMLDocumentFromCharacter(this));
 }