Example #1
0
        private void ProcessStartTagAttributes(HtmlDtd.TagDefinition tagDef)
        {
            switch (tagDef.tagIndex)
            {
            case HtmlTagIndex.A:


                if (this.outputAnchorLinks)
                {
                    foreach (HtmlAttribute attr in this.token.Attributes)
                    {
                        if (attr.NameIndex == HtmlNameIndex.Href)
                        {
                            if (attr.IsAttrBegin)
                            {
                                this.urlScratch.Reset();
                            }

                            this.urlScratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize);
                            break;
                        }
                    }

                    if (this.token.IsTagEnd)
                    {
                        BufferString url = this.urlScratch.BufferString;

                        url.TrimWhitespace();

                        if (url.Length != 0 && url[0] != '#' && url[0] != '?' && url[0] != ';')
                        {
                            if (!this.lineStarted)
                            {
                                this.StartParagraphOrLine();
                            }



                            string urlString = url.ToString();

                            if (urlString.IndexOf(' ') != -1)
                            {
                                urlString = urlString.Replace(" ", "%20");
                            }

                            this.output.AnchorUrl = urlString;
                            this.insideAnchor     = true;

                            if (this.urlCompareSink == null)
                            {
                                this.urlCompareSink = new UrlCompareSink();
                            }

                            this.urlCompareSink.Initialize(urlString);
                        }

                        this.urlScratch.Reset();
                    }
                }
                break;

            case HtmlTagIndex.Image:
            case HtmlTagIndex.Img:



                if (this.outputImageLinks)
                {
                    foreach (HtmlAttribute attr in this.token.Attributes)
                    {
                        if (attr.NameIndex == HtmlNameIndex.Src)
                        {
                            if (attr.IsAttrBegin)
                            {
                                this.urlScratch.Reset();
                            }

                            this.urlScratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize);
                        }
                        else if (attr.NameIndex == HtmlNameIndex.Alt)
                        {
                            if (attr.IsAttrBegin)
                            {
                                this.imageAltText.Reset();
                            }

                            this.imageAltText.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize);
                        }
                        else if (attr.NameIndex == HtmlNameIndex.Height)
                        {
                            if (!attr.Value.IsEmpty)
                            {
                                PropertyValue value;

                                if (attr.Value.IsContiguous)
                                {
                                    value = HtmlSupport.ParseNumber(attr.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length);
                                }
                                else
                                {
                                    this.scratch.Reset();
                                    this.scratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize);
                                    value = HtmlSupport.ParseNumber(this.scratch.BufferString, HtmlSupport.NumberParseFlags.Length);
                                }

                                if (value.IsAbsRelLength)
                                {
                                    this.imageHeightPixels = value.PixelsInteger;
                                    if (this.imageHeightPixels == 0)
                                    {
                                        this.imageHeightPixels = 1;
                                    }
                                }
                            }
                        }
                        else if (attr.NameIndex == HtmlNameIndex.Width)
                        {
                            if (!attr.Value.IsEmpty)
                            {
                                PropertyValue value;

                                if (attr.Value.IsContiguous)
                                {
                                    value = HtmlSupport.ParseNumber(attr.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length);
                                }
                                else
                                {
                                    this.scratch.Reset();
                                    this.scratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize);
                                    value = HtmlSupport.ParseNumber(this.scratch.BufferString, HtmlSupport.NumberParseFlags.Length);
                                }

                                if (value.IsAbsRelLength)
                                {
                                    this.imageWidthPixels = value.PixelsInteger;
                                    if (this.imageWidthPixels == 0)
                                    {
                                        this.imageWidthPixels = 1;
                                    }
                                }
                            }
                        }
                    }



                    if (this.token.IsTagEnd)
                    {
                        string urlString = null;
                        string altString = null;



                        BufferString alt = this.imageAltText.BufferString;

                        alt.TrimWhitespace();

                        if (alt.Length != 0)
                        {
                            altString = alt.ToString();
                        }

                        if (altString == null || this.output.ImageRenderingCallbackDefined)
                        {
                            BufferString url = this.urlScratch.BufferString;

                            url.TrimWhitespace();

                            if (url.Length != 0)
                            {
                                urlString = url.ToString();
                            }
                        }

                        if (!this.lineStarted)
                        {
                            this.StartParagraphOrLine();
                        }

                        this.output.OutputImage(urlString, altString, this.imageWidthPixels, this.imageHeightPixels);

                        this.urlScratch.Reset();
                        this.imageAltText.Reset();
                        this.imageHeightPixels = 0;
                        this.imageWidthPixels  = 0;
                    }
                }
                break;

            case HtmlTagIndex.P:



                if (this.token.Attributes.Find(HtmlNameIndex.Class) && this.token.Attributes.Current.Value.CaseInsensitiveCompareEqual("msonormal"))
                {
                    this.wideGap = false;
                    this.nextParagraphCloseWideGap = false;
                }
                break;

            case HtmlTagIndex.Font:

                foreach (HtmlAttribute attr in this.token.Attributes)
                {
                    if (attr.NameIndex == HtmlNameIndex.Face)
                    {
                        this.scratch.Reset();
                        this.scratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize);

                        RecognizeInterestingFontName fontRecognizer = new RecognizeInterestingFontName();

                        for (int i = 0; i < this.scratch.Length && !fontRecognizer.IsRejected; i++)
                        {
                            fontRecognizer.AddCharacter(this.scratch.Buffer[i]);
                        }

                        this.textMapping = fontRecognizer.TextMapping;
                        break;
                    }
                }

                break;


            case HtmlTagIndex.Span:

                foreach (HtmlAttribute attr in this.token.Attributes)
                {
                    if (attr.NameIndex == HtmlNameIndex.Style)
                    {
                        this.scratch.Reset();
                        this.scratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize);

                        RecognizeInterestingFontNameInInlineStyle fontRecognizer = new RecognizeInterestingFontNameInInlineStyle();

                        for (int i = 0; i < this.scratch.Length && !fontRecognizer.IsFinished; i++)
                        {
                            fontRecognizer.AddCharacter(this.scratch.Buffer[i]);
                        }

                        this.textMapping = fontRecognizer.TextMapping;
                        break;
                    }
                }

                break;
            }
        }
        private void ProcessStartTagAttributes(HtmlDtd.TagDefinition tagDef)
        {
            HtmlTagIndex tagIndex = tagDef.TagIndex;

            if (tagIndex <= HtmlTagIndex.Font)
            {
                if (tagIndex != HtmlTagIndex.A)
                {
                    if (tagIndex != HtmlTagIndex.Font)
                    {
                        return;
                    }
                    foreach (HtmlAttribute attr in this.token.Attributes)
                    {
                        if (attr.NameIndex == HtmlNameIndex.Face)
                        {
                            this.scratch.Reset();
                            this.scratch.AppendHtmlAttributeValue(attr, 4096);
                            RecognizeInterestingFontName recognizeInterestingFontName = default(RecognizeInterestingFontName);
                            int num = 0;
                            while (num < this.scratch.Length && !recognizeInterestingFontName.IsRejected)
                            {
                                recognizeInterestingFontName.AddCharacter(this.scratch.Buffer[num]);
                                num++;
                            }
                            this.textMapping = recognizeInterestingFontName.TextMapping;
                            return;
                        }
                    }
                    return;
                }
                else if (this.outputAnchorLinks)
                {
                    foreach (HtmlAttribute attr2 in this.token.Attributes)
                    {
                        if (attr2.NameIndex == HtmlNameIndex.Href)
                        {
                            if (attr2.IsAttrBegin)
                            {
                                this.urlScratch.Reset();
                            }
                            this.urlScratch.AppendHtmlAttributeValue(attr2, 4096);
                            break;
                        }
                    }
                    if (this.token.IsTagEnd)
                    {
                        BufferString bufferString = this.urlScratch.BufferString;
                        bufferString.TrimWhitespace();
                        if (bufferString.Length != 0 && bufferString[0] != '#' && bufferString[0] != '?' && bufferString[0] != ';')
                        {
                            if (!this.lineStarted)
                            {
                                this.StartParagraphOrLine();
                            }
                            string text = bufferString.ToString();
                            if (text.IndexOf(' ') != -1)
                            {
                                text = text.Replace(" ", "%20");
                            }
                            this.output.OpenAnchor(text);
                            this.insideAnchor = true;
                            if (this.urlCompareSink == null)
                            {
                                this.urlCompareSink = new UrlCompareSink();
                            }
                            this.urlCompareSink.Initialize(text);
                        }
                        this.urlScratch.Reset();
                        return;
                    }
                }
            }
            else
            {
                switch (tagIndex)
                {
                case HtmlTagIndex.Image:
                case HtmlTagIndex.Img:
                    if (this.outputImageLinks)
                    {
                        foreach (HtmlAttribute attr3 in this.token.Attributes)
                        {
                            if (attr3.NameIndex == HtmlNameIndex.Src)
                            {
                                if (attr3.IsAttrBegin)
                                {
                                    this.urlScratch.Reset();
                                }
                                this.urlScratch.AppendHtmlAttributeValue(attr3, 4096);
                            }
                            else if (attr3.NameIndex == HtmlNameIndex.Alt)
                            {
                                if (attr3.IsAttrBegin)
                                {
                                    this.imageAltText.Reset();
                                }
                                this.imageAltText.AppendHtmlAttributeValue(attr3, 4096);
                            }
                            else if (attr3.NameIndex == HtmlNameIndex.Height)
                            {
                                if (!attr3.Value.IsEmpty)
                                {
                                    PropertyValue propertyValue;
                                    if (attr3.Value.IsContiguous)
                                    {
                                        propertyValue = HtmlSupport.ParseNumber(attr3.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length);
                                    }
                                    else
                                    {
                                        this.scratch.Reset();
                                        this.scratch.AppendHtmlAttributeValue(attr3, 4096);
                                        propertyValue = HtmlSupport.ParseNumber(this.scratch.BufferString, HtmlSupport.NumberParseFlags.Length);
                                    }
                                    if (propertyValue.IsAbsRelLength)
                                    {
                                        this.imageHeightPixels = propertyValue.PixelsInteger;
                                        if (this.imageHeightPixels == 0)
                                        {
                                            this.imageHeightPixels = 1;
                                        }
                                    }
                                }
                            }
                            else if (attr3.NameIndex == HtmlNameIndex.Width && !attr3.Value.IsEmpty)
                            {
                                PropertyValue propertyValue2;
                                if (attr3.Value.IsContiguous)
                                {
                                    propertyValue2 = HtmlSupport.ParseNumber(attr3.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length);
                                }
                                else
                                {
                                    this.scratch.Reset();
                                    this.scratch.AppendHtmlAttributeValue(attr3, 4096);
                                    propertyValue2 = HtmlSupport.ParseNumber(this.scratch.BufferString, HtmlSupport.NumberParseFlags.Length);
                                }
                                if (propertyValue2.IsAbsRelLength)
                                {
                                    this.imageWidthPixels = propertyValue2.PixelsInteger;
                                    if (this.imageWidthPixels == 0)
                                    {
                                        this.imageWidthPixels = 1;
                                    }
                                }
                            }
                        }
                        if (this.token.IsTagEnd)
                        {
                            string       imageUrl      = null;
                            string       text2         = null;
                            BufferString bufferString2 = this.imageAltText.BufferString;
                            bufferString2.TrimWhitespace();
                            if (bufferString2.Length != 0)
                            {
                                text2 = bufferString2.ToString();
                            }
                            if (text2 == null || this.output.ImageRenderingCallbackDefined)
                            {
                                BufferString bufferString3 = this.urlScratch.BufferString;
                                bufferString3.TrimWhitespace();
                                if (bufferString3.Length != 0)
                                {
                                    imageUrl = bufferString3.ToString();
                                }
                            }
                            if (!this.lineStarted)
                            {
                                this.StartParagraphOrLine();
                            }
                            this.output.OutputImage(imageUrl, text2, this.imageWidthPixels, this.imageHeightPixels);
                            this.urlScratch.Reset();
                            this.imageAltText.Reset();
                            this.imageHeightPixels = 0;
                            this.imageWidthPixels  = 0;
                            return;
                        }
                    }
                    break;

                default:
                    if (tagIndex == HtmlTagIndex.P)
                    {
                        if (!this.shouldUseNarrowGapForPTagHtmlToTextConversion)
                        {
                            if (!this.token.Attributes.Find(HtmlNameIndex.Class))
                            {
                                break;
                            }
                            HtmlAttribute htmlAttribute = this.token.Attributes.Current;
                            if (!htmlAttribute.Value.CaseInsensitiveCompareEqual("msonormal"))
                            {
                                break;
                            }
                        }
                        this.wideGap = false;
                        this.nextParagraphCloseWideGap = false;
                        return;
                    }
                    if (tagIndex != HtmlTagIndex.Span)
                    {
                        return;
                    }
                    foreach (HtmlAttribute attr4 in this.token.Attributes)
                    {
                        if (attr4.NameIndex == HtmlNameIndex.Style)
                        {
                            this.scratch.Reset();
                            this.scratch.AppendHtmlAttributeValue(attr4, 4096);
                            RecognizeInterestingFontNameInInlineStyle recognizeInterestingFontNameInInlineStyle = default(RecognizeInterestingFontNameInInlineStyle);
                            int num2 = 0;
                            while (num2 < this.scratch.Length && !recognizeInterestingFontNameInInlineStyle.IsFinished)
                            {
                                recognizeInterestingFontNameInInlineStyle.AddCharacter(this.scratch.Buffer[num2]);
                                num2++;
                            }
                            this.textMapping = recognizeInterestingFontNameInInlineStyle.TextMapping;
                            return;
                        }
                    }
                    break;
                }
            }
        }