/// <summary> /// The primary control word handler method. /// Called by the parser once it has a control word and parameter if applicable. /// The control word and associated parameter if applicable. /// true or false if the control word was handled. /// @since 2.0.8 /// </summary> /// <param name="ctrlWordDataIn"></param> /// <returns></returns> public bool HandleControlword(RtfCtrlWordData ctrlWordDataIn) { bool result = false; CtrlWordData = ctrlWordDataIn; RtfDestination dest = null; bool handled = false; CtrlWordData.Prefix = CtrlWordPrefix; CtrlWordData.Suffix = CtrlWordSuffix; CtrlWordData.NewGroup = RtfParser.GetState().NewGroup; CtrlWordData.CtrlWordType = CtrlWordType; CtrlWordData.SpecialHandler = SpecialHandler; if (!CtrlWordData.HasParam && PassDefaultParameterValue) { CtrlWordData.HasParam = true; CtrlWordData.Param = DefaultParameterValue.ToString(); } if (_debug) { printDebug("handleKeyword: [" + CtrlWordData.CtrlWord + "] param=" + ctrlWordDataIn.Param); RtfParser.OutputDebug(RtfParser.GetRtfDocument(), RtfParser.GetLevel() + 1, "RtfCtrlWordHandler debug Start: " + CtrlWordData.CtrlWord + " "); } if (CtrlWordData.CtrlWord.Equals("*")) { return(true); } if (!BeforeControlWord()) { return(true); } switch (CtrlWordType) { case RtfCtrlWordType.FLAG: case RtfCtrlWordType.TOGGLE: case RtfCtrlWordType.VALUE: dest = RtfParser.GetCurrentDestination(); if (dest != null) { handled = dest.HandleControlWord(CtrlWordData); } break; case RtfCtrlWordType.SYMBOL: dest = 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 (RtfParser.IsImport()) { data = CtrlWordPrefix + CtrlWordData.CtrlWord + CtrlWordSuffix; } if (RtfParser.IsConvert()) { data = 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) { handled = dest.HandleCharacter(cc); } } else { handled = dest.HandleControlWord(CtrlWordData); } } break; case RtfCtrlWordType.DESTINATION_EX: case RtfCtrlWordType.DESTINATION: // set the destination int x = 0; if (CtrlWord == "shppict" || CtrlWord == "nonshppict") { x++; } handled = RtfParser.SetCurrentDestination(CtrlWord); // let destination handle the ctrl word now. dest = RtfParser.GetCurrentDestination(); if (dest != null) { if (dest.GetNewTokeniserState() == RtfParser.TOKENISER_IGNORE_RESULT) { handled = dest.HandleControlWord(CtrlWordData); } else { RtfParser.SetTokeniserState(dest.GetNewTokeniserState()); } } break; } AfterControlWord(); if (_debug) { RtfParser.OutputDebug(RtfParser.GetRtfDocument(), RtfParser.GetLevel() + 1, "RtfCtrlWordHandler debug End: " + CtrlWordData.CtrlWord + " "); } return(result); }