Esempio n. 1
0
        // Token: 0x06002E76 RID: 11894 RVA: 0x000D289C File Offset: 0x000D0A9C
        private static string _ConstructPageString(Stream pageStream, bool reverseRTL)
        {
            XmlTextReader baseReader = new XmlTextReader(pageStream);
            XmlReader     xmlReader  = new XmlCompatibilityReader(baseReader, FixedFindEngine._predefinedNamespaces);

            xmlReader = XmlReader.Create(xmlReader, new XmlReaderSettings
            {
                IgnoreWhitespace = true,
                IgnoreComments   = true,
                ProhibitDtd      = true
            });
            xmlReader.MoveToContent();
            StringBuilder stringBuilder = new StringBuilder();
            bool          flag          = false;
            string        text          = null;

            while (xmlReader.Read())
            {
                XmlNodeType nodeType = xmlReader.NodeType;
                if (nodeType == XmlNodeType.Element && xmlReader.Name == "Glyphs")
                {
                    text = xmlReader.GetAttribute("UnicodeString");
                    if (!string.IsNullOrEmpty(text))
                    {
                        string attribute = xmlReader.GetAttribute("IsSideways");
                        flag = false;
                        if (attribute != null && string.Compare(attribute, bool.TrueString, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            flag = true;
                        }
                        if (reverseRTL)
                        {
                            string attribute2 = xmlReader.GetAttribute("BidiLevel");
                            int    num        = 0;
                            if (!string.IsNullOrEmpty(attribute2))
                            {
                                try
                                {
                                    num = Convert.ToInt32(attribute2, CultureInfo.InvariantCulture);
                                }
                                catch (Exception)
                                {
                                }
                            }
                            string attribute3 = xmlReader.GetAttribute("CaretStops");
                            if (num == 0 && !flag && string.IsNullOrEmpty(attribute3) && FixedTextBuilder.MostlyRTL(text))
                            {
                                char[] array = text.ToCharArray();
                                Array.Reverse(array);
                                text = new string(array);
                            }
                        }
                        stringBuilder.Append(text);
                    }
                }
            }
            return(stringBuilder.ToString());
        }
        //If End element is present for Relationship then we process it
        private void ProcessEndElementForRelationshipTag(XmlCompatibilityReader reader)
        {
            Debug.Assert(!reader.IsEmptyElement, "This method should only be called if the Relationship Element is not empty");

            reader.Read();

            //Skips over the following - ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace
            reader.MoveToContent();

            if (reader.NodeType == XmlNodeType.EndElement && String.CompareOrdinal(s_relationshipTagName, reader.LocalName) == 0)
            {
                return;
            }
            else
            {
                throw new XmlException(SR.Format(SR.ElementIsNotEmptyElement, s_relationshipTagName), null, reader.LineNumber, reader.LinePosition);
            }
        }
        /// <summary>
        /// Parse PackageRelationship Stream
        /// </summary>
        /// <param name="part">relationship part</param>
        /// <exception cref="XmlException">Thrown if XML is malformed</exception>
        private void ParseRelationshipPart(PackagePart part)
        {
            //We can safely open the stream as FileAccess.Read, as this code
            //should only be invoked if the Package has been opened in Read or ReadWrite mode.
            Debug.Assert(_package.FileOpenAccess == FileAccess.Read || _package.FileOpenAccess == FileAccess.ReadWrite,
                         "This method should only be called when FileAccess is Read or ReadWrite");

            using (Stream s = part.GetStream(FileMode.Open, FileAccess.Read))
            {
                // load from the relationship part associated with the given part
                using (XmlReader baseReader = XmlReader.Create(s))
                {
                    using (XmlCompatibilityReader reader = new XmlCompatibilityReader(baseReader, s_relationshipKnownNamespaces))
                    {
                        //This method expects the reader to be in ReadState.Initial.
                        //It will make the first read call.
                        PackagingUtilities.PerformInitialReadAndVerifyEncoding(baseReader);

                        //Note: After the previous method call the reader should be at the first tag in the markup.
                        //MoveToContent - Skips over the following - ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace
                        //If the reader is currently at a content node then this function call is a no-op
                        reader.MoveToContent();

                        // look for our tag and namespace pair - throw if other elements are encountered
                        // Make sure that the current node read is an Element
                        if (reader.NodeType == XmlNodeType.Element &&
                            (reader.Depth == 0) &&
                            (String.CompareOrdinal(s_relationshipsTagName, reader.LocalName) == 0) &&
                            (String.CompareOrdinal(PackagingUtilities.RelationshipNamespaceUri, reader.NamespaceURI) == 0))
                        {
                            ThrowIfXmlBaseAttributeIsPresent(reader);

                            //There should be a namespace Attribute present at this level.
                            //Also any other attribute on the <Relationships> tag is an error including xml: and xsi: attributes
                            if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) > 0)
                            {
                                throw new XmlException(SR.RelationshipsTagHasExtraAttributes, null, reader.LineNumber, reader.LinePosition);
                            }

                            // start tag encountered for Relationships
                            // now parse individual Relationship tags
                            while (reader.Read())
                            {
                                //Skips over the following - ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace
                                //If the reader is currently at a content node then this function call is a no-op
                                reader.MoveToContent();

                                //If MoveToContent() takes us to the end of the content
                                if (reader.NodeType == XmlNodeType.None)
                                {
                                    continue;
                                }

                                if (reader.NodeType == XmlNodeType.Element &&
                                    (reader.Depth == 1) &&
                                    (String.CompareOrdinal(s_relationshipTagName, reader.LocalName) == 0) &&
                                    (String.CompareOrdinal(PackagingUtilities.RelationshipNamespaceUri, reader.NamespaceURI) == 0))
                                {
                                    ThrowIfXmlBaseAttributeIsPresent(reader);

                                    int expectedAttributesCount = 3;

                                    string targetModeAttributeValue = reader.GetAttribute(s_targetModeAttributeName);
                                    if (targetModeAttributeValue != null)
                                    {
                                        expectedAttributesCount++;
                                    }

                                    //check if there are expected number of attributes.
                                    //Also any other attribute on the <Relationship> tag is an error including xml: and xsi: attributes
                                    if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) == expectedAttributesCount)
                                    {
                                        ProcessRelationshipAttributes(reader);

                                        //Skip the EndElement for Relationship
                                        if (!reader.IsEmptyElement)
                                        {
                                            ProcessEndElementForRelationshipTag(reader);
                                        }
                                    }
                                    else
                                    {
                                        throw new XmlException(SR.RelationshipTagDoesntMatchSchema, null, reader.LineNumber, reader.LinePosition);
                                    }
                                }
                                else
                                if (!(String.CompareOrdinal(s_relationshipsTagName, reader.LocalName) == 0 && (reader.NodeType == XmlNodeType.EndElement)))
                                {
                                    throw new XmlException(SR.UnknownTagEncountered, null, reader.LineNumber, reader.LinePosition);
                                }
                            }
                        }
                        else
                        {
                            throw new XmlException(SR.ExpectedRelationshipsElementTag, null, reader.LineNumber, reader.LinePosition);
                        }
                    }
                }
            }
        }
        private static String _ConstructPageString(Stream pageStream, bool reverseRTL)
        {
            Debug.Assert(pageStream != null);

            XmlTextReader xmlTextReader = new XmlTextReader(pageStream);

            //Wrap around a compatibility reader
            XmlReader xmlReader = new XmlCompatibilityReader(xmlTextReader, _predefinedNamespaces);

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;
            settings.ProhibitDtd      = true;

            xmlReader = XmlReader.Create(xmlReader, settings);

            xmlReader.MoveToContent();

            StringBuilder pageString = new StringBuilder();
            bool          isSideways = false;
            string        unicodeStr = null;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    if (xmlReader.Name == "Glyphs")
                    {
                        unicodeStr = xmlReader.GetAttribute("UnicodeString");

                        if (!String.IsNullOrEmpty(unicodeStr))
                        {
                            string sidewaysString = xmlReader.GetAttribute("IsSideways");
                            isSideways = false;
                            if (sidewaysString != null &&
                                String.Compare(sidewaysString, Boolean.TrueString, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                isSideways = true;
                            }

                            if (reverseRTL)
                            {
                                //This is to cover for MXDW generation
                                //RTL Glyphs are saved LTR and bidi level is not set
                                //In this case we need to reverse the UnicodeString
                                string bidiLevelAsString = xmlReader.GetAttribute("BidiLevel");
                                int    bidiLevel         = 0;
                                if (!String.IsNullOrEmpty(bidiLevelAsString))
                                {
                                    try
                                    {
                                        bidiLevel = Convert.ToInt32(bidiLevelAsString, CultureInfo.InvariantCulture);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }

                                string caretStops = xmlReader.GetAttribute("CaretStops");

                                if (bidiLevel == 0 &&
                                    !isSideways &&
                                    String.IsNullOrEmpty(caretStops) &&
                                    FixedTextBuilder.MostlyRTL(unicodeStr))
                                {
                                    char[] chars = unicodeStr.ToCharArray();
                                    Array.Reverse(chars);
                                    unicodeStr = new String(chars);
                                }
                            }


                            pageString.Append(unicodeStr);
                        }
                    }
                }
                break;
                }
            }
            return(pageString.ToString());
        }