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

6 posts, 1 answers
  1. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 02 Oct 2018 Link to this post

    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)?

  2. Dimitar
    Admin
    Dimitar avatar
    2823 posts

    Posted 03 Oct 2018 Link to this post

    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.
  3. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 03 Oct 2018 in reply to Dimitar Link to this post

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

     

  4. Dimitar
    Admin
    Dimitar avatar
    2823 posts

    Posted 03 Oct 2018 Link to this post

    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.
  5. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 03 Oct 2018 Link to this post

    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?
  6. Answer
    Dimitar
    Admin
    Dimitar avatar
    2823 posts

    Posted 05 Oct 2018 Link to this post

    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.
Back to Top