Exemplo n.º 1
0
        // Token: 0x06001993 RID: 6547 RVA: 0x000CA044 File Offset: 0x000C8244
        private void ProcessText(RtfToken token)
        {
            if (this.state.Skip)
            {
                return;
            }
            RtfDestination destination = this.state.Destination;

            if (destination != RtfDestination.RTF)
            {
                if (destination != RtfDestination.HtmlTagIndex)
                {
                    this.firstKeyword = false;
                    return;
                }
            }
            else if (this.ignoreRtf)
            {
                return;
            }
            token.StripZeroBytes = true;
            int num = token.Text.Read(this.parseBuffer, this.parseEnd, this.parseBuffer.Length - this.parseEnd - 1);

            this.parseEnd += num;
            this.parseBuffer[this.parseEnd] = '\0';
            if (this.parseEnd == this.parseBuffer.Length - 1)
            {
                this.incompleteToken = token;
                return;
            }
            this.incompleteToken = null;
        }
Exemplo n.º 2
0
 /**
  * Default constructor
  *
  */
 public RtfParserState()
 {
     this.text             = new StringBuilder();
     this.ctrlWordHandlers = new Stack();
     this.properties       = new RtfProperty();
     this.destination      = RtfDestinationNull.GetInstance();
     this.newGroup         = false;
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 public RtfParserState()
 {
     Text             = new StringBuilder();
     CtrlWordHandlers = new Stack();
     Properties       = new RtfProperty();
     Destination      = RtfDestinationNull.GetInstance();
     NewGroup         = false;
 }
Exemplo n.º 4
0
 /**
  * Copy constructor
  * @param orig The object to copy
  */
 public RtfParserState(RtfParserState orig)
 {
     this.properties       = orig.properties;
     this.parserState      = orig.parserState;
     this.tokeniserState   = orig.tokeniserState;
     this.groupHandler     = null;
     this.destination      = orig.destination;
     this.text             = new StringBuilder();
     this.ctrlWordHandlers = new Stack();
     this.destination      = orig.destination;
     this.newGroup         = false;
 }
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="orig">The object to copy</param>
 public RtfParserState(RtfParserState orig)
 {
     Properties       = orig.Properties;
     ParserState      = orig.ParserState;
     TokeniserState   = orig.TokeniserState;
     GroupHandler     = null;
     Destination      = orig.Destination;
     Text             = new StringBuilder();
     CtrlWordHandlers = new Stack();
     Destination      = orig.Destination;
     NewGroup         = false;
 }
Exemplo n.º 6
0
        private void EndGroup()
        {
            RtfDestination destination = this.state.Destination;

            if (destination != RtfDestination.FontTable)
            {
                if (destination != RtfDestination.ColorTable)
                {
                    return;
                }
                if (this.state.ParentDestination != RtfDestination.ColorTable && this.injection != null)
                {
                    if (this.color != 0)
                    {
                        this.colorsCount++;
                        this.output.WriteControlText(";", false);
                    }
                    this.output.WriteControlText("\r\n", false);
                    this.output.RtfLineLength = 0;
                    this.injection.InjectRtfColors(this.colorsCount);
                }
            }
            else if (this.state.ParentDestination != RtfDestination.FontTable)
            {
                if (this.injection != null)
                {
                    this.output.WriteControlText("\r\n", false);
                    this.output.RtfLineLength = 0;
                    this.injection.InjectRtfFonts((int)(this.maxFontHandle + 1));
                    return;
                }
            }
            else if (this.state.FontIndex >= 0)
            {
                this.state.ParentFontIndex = this.state.FontIndex;
                return;
            }
        }
Exemplo n.º 7
0
        /**
         * The primary control word handler method.
         * Called by the parser once it has a control word and parameter if applicable.
         *
         * @param ctrlWordDataIn
         *      The control word and associated parameter if applicable.
         * @return
         *      <code>true</code> or <code>false</code> if the control word was handled.
         * @since 2.0.8
         */
        public bool HandleControlword(RtfCtrlWordData ctrlWordDataIn)
        {
            bool result = false;

            this.ctrlWordData = ctrlWordDataIn;
            RtfDestination dest    = null;
            bool           handled = false;

            this.ctrlWordData.prefix         = this.ctrlWordPrefix;
            this.ctrlWordData.suffix         = this.ctrlWordSuffix;
            this.ctrlWordData.newGroup       = this.rtfParser.GetState().newGroup;
            this.ctrlWordData.ctrlWordType   = this.ctrlWordType;
            this.ctrlWordData.specialHandler = this.specialHandler;

            if (!this.ctrlWordData.hasParam && this.passDefaultParameterValue)
            {
                this.ctrlWordData.hasParam = true;
                this.ctrlWordData.param    = this.defaultParameterValue.ToString();
            }

            if (debug)
            {
                PrintDebug("handleKeyword: [" + this.ctrlWordData.ctrlWord + "] param=" + ctrlWordDataIn.param);
                RtfParser.OutputDebug(this.rtfParser.GetRtfDocument(), this.rtfParser.GetLevel() + 1, "RtfCtrlWordHandler debug Start: " + this.ctrlWordData.ctrlWord + " ");
            }
            if (this.ctrlWordData.ctrlWord.Equals("*"))
            {
                return(true);
            }

            if (!BeforeControlWord())
            {
                return(true);
            }

            switch (this.ctrlWordType)
            {
            case RtfCtrlWordType.FLAG:
            case RtfCtrlWordType.TOGGLE:
            case RtfCtrlWordType.VALUE:
                dest = this.rtfParser.GetCurrentDestination();
                if (dest != null)
                {
                    handled = dest.HandleControlWord(this.ctrlWordData);
                }
                break;

            case RtfCtrlWordType.SYMBOL:
                dest = this.rtfParser.GetCurrentDestination();
                if (dest != null)
                {
                    String data = null;
                    // if doing an import, then put the control word in the output stream through the character handler
                    if (this.rtfParser.IsImport())
                    {
                        data = this.ctrlWordPrefix + this.ctrlWordData.ctrlWord + this.ctrlWordSuffix;
                    }
                    if (this.rtfParser.IsConvert())
                    {
                        data = this.specialHandler;
                    }

                    // If there is a substitute character, process the character.
                    // If no substitute character, then provide special handling in the destination for the ctrl word.
                    if (data != null)
                    {
                        foreach (char cc in data.ToCharArray())
                        {
                            handled = dest.HandleCharacter((int)cc);
                        }
                    }
                    else
                    {
                        handled = dest.HandleControlWord(this.ctrlWordData);
                    }
                }
                break;

            case RtfCtrlWordType.DESTINATION_EX:
            case RtfCtrlWordType.DESTINATION:
                // set the destination
                int x = 0;
                if (this.ctrlWord == "shppict" || this.ctrlWord == "nonshppict")
                {
                    x++;
                }
                handled = this.rtfParser.SetCurrentDestination(this.ctrlWord);
                // let destination handle the ctrl word now.
                dest = this.rtfParser.GetCurrentDestination();
                if (dest != null)
                {
                    if (dest.GetNewTokeniserState() == RtfParser.TOKENISER_IGNORE_RESULT)
                    {
                        handled = dest.HandleControlWord(this.ctrlWordData);
                    }
                    else
                    {
                        this.rtfParser.SetTokeniserState(dest.GetNewTokeniserState());
                    }
                }
                break;
            }

            AfterControlWord();

            if (debug)
            {
                RtfParser.OutputDebug(this.rtfParser.GetRtfDocument(), this.rtfParser.GetLevel() + 1, "RtfCtrlWordHandler debug End: " + this.ctrlWordData.ctrlWord + " ");
            }

            return(result);
        }
Exemplo n.º 8
0
        // Token: 0x0600173D RID: 5949 RVA: 0x000B4F28 File Offset: 0x000B3128
        private void EndGroup()
        {
            RtfDestination destination = this.state.Destination;

            switch (destination)
            {
            case RtfDestination.Field:
                if (this.state.ParentDestination != RtfDestination.Field)
                {
                    this.skipFieldResult = false;
                    if (this.includePictureField)
                    {
                        PropertyValue propertyValue  = new PropertyValue(LengthUnits.Twips, this.pictureHeight);
                        PropertyValue propertyValue2 = new PropertyValue(LengthUnits.Twips, this.pictureWidth);
                        this.output.OutputImage(this.imageUrl, this.imageAltText, propertyValue2.PixelsInteger, propertyValue.PixelsInteger);
                        this.includePictureField = false;
                        this.imageUrl            = null;
                        this.imageAltText        = null;
                        return;
                    }
                    if (this.hyperLinkActive)
                    {
                        if (!this.urlCompareSink.IsMatch)
                        {
                            this.output.CloseAnchor();
                        }
                        else
                        {
                            this.output.CancelAnchor();
                        }
                        this.hyperLinkActive = false;
                    }
                }
                break;

            case RtfDestination.FieldResult:
                break;

            case RtfDestination.FieldInstruction:
                if (this.state.ParentDestination == RtfDestination.Field)
                {
                    bool         flag;
                    BufferString bufferString;
                    TextMapping  textMapping;
                    char         ucs32Literal;
                    short        num;
                    if (RtfSupport.IsHyperlinkField(ref this.scratch, out flag, out bufferString))
                    {
                        if (!flag)
                        {
                            if (this.hyperLinkActive)
                            {
                                if (!this.urlCompareSink.IsMatch)
                                {
                                    this.output.CloseAnchor();
                                }
                                else
                                {
                                    this.output.CancelAnchor();
                                }
                                this.hyperLinkActive = false;
                                this.urlCompareSink.Reset();
                            }
                            bufferString.TrimWhitespace();
                            if (bufferString.Length != 0)
                            {
                                string text = bufferString.ToString();
                                this.output.OpenAnchor(text);
                                this.hyperLinkActive = true;
                                if (this.urlCompareSink == null)
                                {
                                    this.urlCompareSink = new UrlCompareSink();
                                }
                                this.urlCompareSink.Initialize(text);
                            }
                        }
                    }
                    else if (RtfSupport.IsIncludePictureField(ref this.scratch, out bufferString))
                    {
                        bufferString.TrimWhitespace();
                        if (bufferString.Length != 0)
                        {
                            this.includePictureField = true;
                            bufferString.TrimWhitespace();
                            if (bufferString.Length != 0)
                            {
                                this.imageUrl = bufferString.ToString();
                            }
                            this.pictureWidth  = 0;
                            this.pictureHeight = 0;
                        }
                    }
                    else if (RtfSupport.IsSymbolField(ref this.scratch, out textMapping, out ucs32Literal, out num))
                    {
                        if (this.output.LineEmpty && this.lineIndent >= 120 && this.lineIndent < 7200)
                        {
                            this.output.OutputSpace(this.lineIndent / 120);
                        }
                        this.output.OutputNonspace((int)ucs32Literal, textMapping);
                        this.skipFieldResult = true;
                    }
                    this.scratch.Reset();
                    return;
                }
                break;

            default:
                switch (destination)
                {
                case RtfDestination.Picture:
                    if (this.state.ParentDestination != RtfDestination.Picture && !this.includePictureField)
                    {
                        PropertyValue propertyValue3 = new PropertyValue(LengthUnits.Twips, this.pictureHeight);
                        PropertyValue propertyValue4 = new PropertyValue(LengthUnits.Twips, this.pictureWidth);
                        this.output.OutputImage(null, null, propertyValue4.PixelsInteger, propertyValue3.PixelsInteger);
                        return;
                    }
                    break;

                case RtfDestination.PictureProperties:
                    break;

                case RtfDestination.ShapeName:
                    if (this.state.ParentDestination != RtfDestination.ShapeName)
                    {
                        BufferString bufferString2 = this.scratch.BufferString;
                        bufferString2.TrimWhitespace();
                        this.descriptionProperty = bufferString2.EqualsToLowerCaseStringIgnoreCase("wzdescription");
                        this.scratch.Reset();
                        return;
                    }
                    break;

                case RtfDestination.ShapeValue:
                    if (this.state.ParentDestination != RtfDestination.ShapeValue && this.descriptionProperty)
                    {
                        BufferString bufferString3 = this.scratch.BufferString;
                        bufferString3.TrimWhitespace();
                        if (bufferString3.Length != 0)
                        {
                            this.imageAltText = bufferString3.ToString();
                        }
                        this.scratch.Reset();
                        return;
                    }
                    break;

                default:
                    return;
                }
                break;
            }
        }
Exemplo n.º 9
0
        // Token: 0x0600173A RID: 5946 RVA: 0x000B4D5C File Offset: 0x000B2F5C
        private void ProcessText(RtfToken token)
        {
            if (this.state.SkipLevel != 0 && this.state.Level >= this.state.SkipLevel)
            {
                return;
            }
            RtfDestination destination = this.state.Destination;

            if (destination != RtfDestination.RTF)
            {
                switch (destination)
                {
                case RtfDestination.Field:
                    break;

                case RtfDestination.FieldResult:
                    if (this.hyperLinkActive && this.urlCompareSink.IsActive)
                    {
                        token.Text.WriteTo(this.urlCompareSink);
                        token.Text.Rewind();
                        goto IL_107;
                    }
                    goto IL_107;

                case RtfDestination.FieldInstruction:
                    this.firstKeyword = false;
                    this.scratch.AppendRtfTokenText(token, 4096);
                    return;

                default:
                    switch (destination)
                    {
                    case RtfDestination.Picture:
                    case RtfDestination.PictureProperties:
                        break;

                    case RtfDestination.ShapeName:
                        this.firstKeyword = false;
                        this.scratch.AppendRtfTokenText(token, 128);
                        return;

                    case RtfDestination.ShapeValue:
                        this.firstKeyword = false;
                        if (this.descriptionProperty)
                        {
                            this.scratch.AppendRtfTokenText(token, 4096);
                            return;
                        }
                        return;

                    default:
                        this.firstKeyword = false;
                        return;
                    }
                    break;
                }
                this.firstKeyword = false;
                return;
            }
IL_107:
            if (this.state.IsInvisible)
            {
                return;
            }
            if (this.output.LineEmpty && this.lineIndent >= 120 && this.lineIndent < 7200)
            {
                this.output.OutputSpace(this.lineIndent / 120);
            }
            token.TextElements.OutputTextElements(this.output, this.treatNbspAsBreakable);
        }