コード例 #1
0
        /// <inheritdoc/>
        public override XElement Read(BinaryReader reader, int?count = null)
        {
            var builder = new TextEntryBuilder(new XElement("text"));

            char c;

            while ((c = reader.ReadChar()) != '\uf8ff')
            {
                switch (c)
                {
                case '\uf800':
                    // If the color element is the current element, convert it to an empty element
                    // and move its nodes to its parent element.
                    if (builder.Current.Name.LocalName == "color")
                    {
                        builder.ReplaceWithAdd();
                    }

                    builder.Push(new XElement("color", new XAttribute("value", reader.ReadUInt16())));
                    break;

                case '\uf801':
                    builder.Pop();
                    break;

                case '\uf812':
                    builder.Add(new XElement("clear"));
                    break;

                case '\uf813':
                    builder.Add(new XElement("arrow"));
                    break;

                case '\uf880':
                    builder.Add(new XElement("speed", new XAttribute("value", reader.ReadUInt16())));
                    break;

                case '\uf881':
                    builder.Add(new XElement("wait", new XAttribute("value", reader.ReadUInt16())));
                    break;

                case '\uf8fd':
                    builder.Add('\n');
                    break;

                case '\uffff':
                    throw new InvalidDataException(Resources.FpdOrFntRequired);

                default:
                    builder.Add(c);
                    break;
                }
            }

            // If the color element is the current element, convert it to an empty element
            // and move its nodes to its parent element.
            if (builder.Current.Name.LocalName == "color")
            {
                builder.ReplaceWithAdd();
            }

            return(builder.ToXElement());
        }
コード例 #2
0
        /// <inheritdoc/>
        public override XElement Read(BinaryReader reader, int?count = null)
        {
            var builder = new TextEntryBuilder(new XElement("text"));

            ushort c;

            while ((c = reader.ReadUInt16()) != 0xffff)
            {
                switch (c)
                {
                case 0xf800:
                    // If the color element is the current element, convert it to an empty element
                    // and move its nodes to its parent element.
                    if (builder.Current.Name.LocalName == "color")
                    {
                        builder.ReplaceWithAdd();
                    }

                    builder.Push(new XElement("color", new XAttribute("value", reader.ReadUInt16())));
                    break;

                case 0xf801:
                    builder.Pop();
                    break;

                case 0xf812:
                    builder.Add(new XElement("clear"));
                    break;

                case 0xf813:
                    builder.Add(new XElement("arrow"));
                    break;

                case 0xf880:
                    builder.Add(new XElement("speed", new XAttribute("value", reader.ReadUInt16())));
                    break;

                case 0xf881:
                    builder.Add(new XElement("wait", new XAttribute("value", reader.ReadUInt16())));
                    break;

                case 0xf884:
                    builder.Add(new XElement("tutorialCourse"));
                    break;

                case 0xf885:
                    builder.Add(new XElement("tutorialLevel"));
                    break;

                case 0xf886:
                    builder.Add(new XElement("tutorialQuestion"));
                    break;

                case 0xfffd:
                    builder.Add('\n');
                    break;

                case 0xfffe:
                    builder.Add(new XElement("r"));
                    break;

                case 0xf8ff:
                    throw new InvalidDataException(Resources.FpdOrFntNotRequired);

                default:
                    if (indexToCharDictionary.TryGetValue(c, out var value))
                    {
                        builder.Add(value);
                    }
                    else
                    {
                        throw new KeyNotFoundException(string.Format(Resources.IndexNotFoundInFontFile, c));
                    }
                    break;
                }
            }

            // If the color element is the current element, convert it to an empty element
            // and move its nodes to its parent element.
            if (builder.Current.Name.LocalName == "color")
            {
                builder.ReplaceWithAdd();
            }

            return(builder.ToXElement());
        }
コード例 #3
0
        /// <param name="count">The number of characters to read.</param>
        /// <inheritdoc/>
        public XElement Read(BinaryReader reader, int?count = null)
        {
            // The count parameter is required.
            if (!count.HasValue)
            {
                throw new ArgumentNullException(nameof(count));
            }

            var builder = new TextEntryBuilder(new XElement("text"));

            var chars = reader.ReadChars(count.Value); // We're under the assumption that the reader encoding is Unicode.

            for (var i = 0; i < chars.Length; i++)
            {
                var c = chars[i];
                switch (c & 0xF00F)
                {
                case 0xE000:         // Color
                    if (c == 0xE010) // Color end tag
                    {
                        builder.Pop();
                    }
                    else     // Color start tag
                    {
                        i++;

                        var colorNameLength = GetNameLength(c) - 2;
                        var colorArgb       = (uint)(chars[i] << 16 | (chars[i + 1]));
                        i += 2;
                        var colorName = new string(chars, i, colorNameLength);

                        builder.Push(new XElement("color",
                                                  new XAttribute("name", colorName),
                                                  new XAttribute("value", colorArgb.ToString("X8"))));

                        i += colorNameLength;
                    }

                    break;

                case 0xE001:     // Var(iable)
                    i++;

                    var varNameLength = GetNameLength(c);
                    var varName       = new string(chars, i, varNameLength);

                    builder.Add(new XElement("var", new XAttribute("name", varName)));

                    i += varNameLength;

                    break;

                case 0xE005:     // Image
                    i++;

                    var imageNameLength = GetNameLength(c);
                    var imageName       = new string(chars, i, imageNameLength);

                    builder.Add(new XElement("image", new XAttribute("name", imageName)));

                    i += imageNameLength;

                    break;

                default:     // All other characters (including new lines)
                    builder.Add(c);
                    break;
                }
            }

            return(builder.ToXElement());
        }