I want to create a new RadDocument and serialize it to byte array. And I want to set default font to something else than "Verdana". Let's use "Comic Sans MS" size 24 for instance. What should I do between "new RadDocument()" and "RtfFormatProvider.Export" (also "XamlFormatProvider.Export") so that word "Verdana" is not found in serialized byte array?
Also, when I want to deserialize this byte array into RadDocument are there some extra steps I should do to prevent Verdana from somehow creeping back in (unless the user explicitly changes some text to Verdana)?
5 Answers, 1 is accepted
After creating the document change the properties of the "Normal" style. Here is the code:
StyleDefinition h1 = editor.Document.StyleRepository.GetValueOrNull(
"Normal"
);
h1.SpanProperties.FontSize = Unit.PointToDip(8.5);
h1.SpanProperties.FontWeight = Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal;
h1.SpanProperties.FontFamily =
new
Telerik.WinControls.RichTextEditor.UI.FontFamily(
"Consolas"
);
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress Telerik
So I have to use RadDocumentEditor, right. The code makes the default font for new spans, but Verdana remains in both .xaml nad .rtf file as some kind of underlying default font (in xaml file at XPath /t:RadDocument/t:RadDocument.Styles/s:StyleDefinition[@DisplayName="defaultDocumentStyle"]/s:StyleDefinition.SpanStyle/s:SpanProperties/@FontFamily)
It feels unsettling to have that Verdana value lingering there. Will it be ignored in all use cases? Here is the code used for testing:
public
void
CreateNewDocumentViaByteArray()
{
var d =
new
RadDocument();
var editor =
new
RadDocumentEditor(d);
var h1 = editor.Document.StyleRepository.GetValueOrNull(
"Normal"
);
h1.SpanProperties.FontSize = Unit.PointToDip(24);
h1.SpanProperties.FontWeight = Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal;
h1.SpanProperties.FontFamily =
new
Telerik.WinControls.RichTextEditor.UI.FontFamily(
"Comic Sans MS"
);
var provider =
new
Telerik.WinForms.Documents.FormatProviders.Rtf.RtfFormatProvider();
byte
[] documentBytes = ((Telerik.WinForms.Documents.FormatProviders.DocumentFormatProviderBase)provider).Export(d);
radRichTextEditor1.Document = provider.Import(documentBytes);
}
This appears to be a style that is used for RightToLeft text. You can change it as well:
radRichTextEditor1.Document =
new
Telerik.WinForms.Documents.Model.RadDocument();
StyleDefinition h1 = radRichTextEditor1.Document.StyleRepository.GetValueOrNull(
"Normal"
);
h1.SpanProperties.FontSize = Unit.PointToDip(8.5);
h1.SpanProperties.FontWeight = Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal;
h1.SpanProperties.FontFamily =
new
Telerik.WinControls.RichTextEditor.UI.FontFamily(
"Consolas"
);
StyleDefinition h2 = radRichTextEditor1.Document.StyleRepository.GetValueOrNull(
"defaultDocumentStyle"
);
h2.SpanProperties.FontSize = Unit.PointToDip(8.5);
h2.SpanProperties.FontWeight = Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal;
h2.SpanProperties.FontFamily =
new
Telerik.WinControls.RichTextEditor.UI.FontFamily(
"Consolas"
);
radRichTextEditor1.Insert(
"Test"
);
var provider =
new
Telerik.WinForms.Documents.FormatProviders.Rtf.RtfFormatProvider();
byte
[] documentBytes = ((Telerik.WinForms.Documents.FormatProviders.DocumentFormatProviderBase)provider).Export(radRichTextEditor1.Document);
radRichTextEditor1.Document = provider.Import(documentBytes);
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
I have investigated this and it appears that the font comes from the table element style. By default, this style will be overridden by the "Normal" style and the Verdana font will not appear in the document. It is safe to ignore this setting in this case.
I hope this will be useful.
Regards,
Dimitar
Progress Telerik