コード例 #1
0
        private SpriteFontFile ReadXnaContentElement()
        {
            SpriteFontFile sff = new SpriteFontFile();

            this.xnaContentAtom       = this.reader.NameTable.Add("XnaContent");
            this.assetAtom            = this.reader.NameTable.Add("Asset");
            this.characterRegionsAtom = this.reader.NameTable.Add("CharacterRegions");

            reader.MoveToContent();

            reader.ReadStartElement(xnaContentAtom);
            reader.MoveToContent();

            reader.ReadStartElement(assetAtom);
            reader.MoveToContent();

            while (true)
            {
                if (reader.NodeType == XmlNodeType.EndElement &&
                    String.ReferenceEquals(reader.Name, this.assetAtom))
                {
                    reader.ReadEndElement();
                    reader.MoveToContent();
                    break;
                }

                if (reader.NodeType != XmlNodeType.Element)
                {
                    throw new XmlException("Expected an element");
                }

                switch (reader.Name)
                {
                case "FontName":
                    sff.FontName = reader.ReadElementContentAsString();
                    break;

                case "Size":
                    sff.Size = reader.ReadElementContentAsInt();
                    break;

                case "Spacing":
                    sff.Spacing = reader.ReadElementContentAsInt();
                    break;

                case "UseKerning":
                    sff.UseKerning = reader.ReadElementContentAsBoolean();
                    break;

                case "Style":
                {
                    SpriteFontFile.FontStyle result;
                    string value = reader.ReadElementContentAsString();

                    if (SpriteFontFile.FontStyle.TryParse(value, out result))
                    {
                        sff.Style = result;
                    }
                    else
                    {
                        throw new XmlException("Unrecognized font Style value".CultureFormat(value));
                    }

                    break;
                }

                case "DefaultCharacter":
                {
                    string value = reader.ReadElementContentAsString();

                    if (value.Length > 0)
                    {
                        sff.DefaultCharacter = value[0];
                    }
                    else
                    {
                        throw new XmlException("DefaultCharacter element is empty");
                    }

                    break;
                }

                case "CharacterRegions":
                    sff.CharacterRegions = ReadCharacterRegionsElement();
                    continue;

                default:
                    throw new XmlException("Unexpected element '{0}'".CultureFormat(reader.Name));
                }

                reader.MoveToContent();
            }

            reader.ReadEndElement();             // XnaContent
            reader.MoveToContent();

            return(sff);
        }
コード例 #2
0
        private SpriteFontFile ReadXnaContentElement()
        {
            SpriteFontFile sff = new SpriteFontFile();

            this.xnaContentAtom = this.reader.NameTable.Add("XnaContent");
            this.assetAtom = this.reader.NameTable.Add("Asset");
            this.characterRegionsAtom = this.reader.NameTable.Add("CharacterRegions");

            reader.MoveToContent();

            reader.ReadStartElement(xnaContentAtom);
            reader.MoveToContent();

            reader.ReadStartElement(assetAtom);
            reader.MoveToContent();

            while (true)
            {
                if (reader.NodeType == XmlNodeType.EndElement &&
                    String.ReferenceEquals(reader.Name, this.assetAtom))
                {
                    reader.ReadEndElement();
                    reader.MoveToContent();
                    break;
                }

                if (reader.NodeType != XmlNodeType.Element)
                    throw new XmlException("Expected an element");

                switch (reader.Name)
                {
                case "FontName":
                    sff.FontName = reader.ReadElementContentAsString();
                    break;
                case "Size":
                    sff.Size = reader.ReadElementContentAsInt();
                    break;
                case "Spacing":
                    sff.Spacing = reader.ReadElementContentAsInt();
                    break;
                case "UseKerning":
                    sff.UseKerning = reader.ReadElementContentAsBoolean();
                    break;
                case "Style":
                {
                    SpriteFontFile.FontStyle result;
                    string value = reader.ReadElementContentAsString();

                    if (SpriteFontFile.FontStyle.TryParse(value, out result))
                        sff.Style = result;
                    else
                        throw new XmlException("Unrecognized font Style value".CultureFormat(value));

                    break;
                }
                case "DefaultCharacter":
                {
                    string value = reader.ReadElementContentAsString();

                    if (value.Length > 0)
                        sff.DefaultCharacter = value[0];
                    else
                        throw new XmlException("DefaultCharacter element is empty");

                    break;
                }
                case "CharacterRegions":
                    sff.CharacterRegions = ReadCharacterRegionsElement();
                    continue;
                default:
                    throw new XmlException("Unexpected element '{0}'".CultureFormat(reader.Name));
                }

                reader.MoveToContent();
            }

            reader.ReadEndElement(); // XnaContent
            reader.MoveToContent();

            return sff;
        }