This is a migrated thread and some comments may be shown as answers.

Set default font for new document (and remove Verdana completely)

5 Answers 697 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Mihajlo
Top achievements
Rank 1
Mihajlo asked on 02 Oct 2018, 03:52 PM

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

Sort by
0
Dimitar
Telerik team
answered on 03 Oct 2018, 08:50 AM
Hello Mihajlo,

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
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mihajlo
Top achievements
Rank 1
answered on 03 Oct 2018, 09:54 AM

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);
}

 

1
Dimitar
Telerik team
answered on 03 Oct 2018, 11:01 AM
Hello Mihajlo,

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mihajlo
Top achievements
Rank 1
answered on 03 Oct 2018, 11:26 AM
Thanks for the answer. I'm being nitpicky here, but while Verdana is now gone from xaml file, it's still in rtf font table as entry \f1. Is this just a harmless bug? Font is automatically added, but never actually used for anything?
0
Accepted
Dimitar
Telerik team
answered on 05 Oct 2018, 09:30 AM
Hi Mihajlo,

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
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextEditor
Asked by
Mihajlo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Mihajlo
Top achievements
Rank 1
Share this question
or