A little while ago, we changed the rtf editor used in our application from another third party editor to the telerik RichTextBox editor. However, I have recently found that Rtf docs created in the previous editor contain list styles that Telerik is unable to handle correctly. In some cases it just won't display them properly, and in worse case it will crash my application.
The following document causes the editor to crash my application:
When this document is loaded, using version 2012.3.1129.40 of the telerik wpf components, I initially get the following exception:
The application will continue throwing exceptions until either it crashes or I have to kill it. I've tried loading this document using the Demo control included in the Q2 2013 SP1 demos, and while it doesn't crash it won't load the document giving a modal dialog saying "The file cannot be opened". If I manually strip out the \*\listtable section, the telerik editor will be able to load the document without problem, but the list will no longer be numbered as expected. MS Word & WordPad will display this document without any issue.
I have an immediate solution to this problem, using another rtf library to resave without list styling, but it would be ideal if I didn't have to do that, as it changes the styles of the lists in any of these documents.
The following document causes the editor to crash my application:
{\rtf1\ansi\deff0\uc1\ansicpg1252\deftab720{\fonttbl{\f0\fnil\fcharset1 Times New Roman;}{\f1\fnil\fcharset1 WingDings;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;}\wpprheadfoot1\paperw12240\paperh15840\margl1800\margr1800\margt1440\margb1440\headery254\footery254\endnhere\sectdefaultcl{\*\generator WPTools_5.18;}{\*\listtable{\list\listtemplateid1
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc1{\leveltext\'02\'00.;}{\levelnumbers\'01;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc3{\leveltext\'02\'01.;}{\levelnumbers\'01;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc0{\leveltext\'02\'02.;}{\levelnumbers\'01;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc4{\leveltext\'02\'03);}{\levelnumbers\'01;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc2{\leveltext\'03(\'04);}{\levelnumbers\'02;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc4{\leveltext\'03(\'05);}{\levelnumbers\'02;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc0{\leveltext\'03(\'06);}{\levelnumbers\'02;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc0{\leveltext\'03(\'07);}{\levelnumbers\'02;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc0{\leveltext\'03(\'08);}{\levelnumbers\'02;}}
\listid1}}{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}}{\plain\fs24 test @ test 123 /\par
\pard\plain\plain\fs24\par
\plain\fs24 test \'E0 test \par
\pard\plain\plain\fs24\par
\pard\plain\plain\fs24\par
\ls1\ilvl-1{\listtext\fs24 (1)\tab}\plain\fs24\line test Resume\par
}}
When this document is loaded, using version 2012.3.1129.40 of the telerik wpf components, I initially get the following exception:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at Telerik.Windows.Documents.Model.Paragraph.get_LeftIndent()
at Telerik.Windows.Documents.Model.Paragraph.get_LeftMargin()
at Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverrideInternal(SizeF availableSize)
at Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverride(SizeF availableSize)
at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize)
at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize)
at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverrideInternal(SizeF availableSize)
at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverride(SizeF availableSize)
at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize)
at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize)
at Telerik.Windows.Documents.Model.RadDocument.Measure(SizeF measureSize)
at Telerik.Windows.Documents.UI.DocumentWebLayoutPresenter.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
The application will continue throwing exceptions until either it crashes or I have to kill it. I've tried loading this document using the Demo control included in the Q2 2013 SP1 demos, and while it doesn't crash it won't load the document giving a modal dialog saying "The file cannot be opened". If I manually strip out the \*\listtable section, the telerik editor will be able to load the document without problem, but the list will no longer be numbered as expected. MS Word & WordPad will display this document without any issue.
I have an immediate solution to this problem, using another rtf library to resave without list styling, but it would be ideal if I didn't have to do that, as it changes the styles of the lists in any of these documents.