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

change font during loading

1 Answer 88 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 05 Dec 2017, 09:04 AM

Hi,

Museo font looks different than in word. It is possibile to change only paragraphs with "museo" font to for example "arial" during loading document?

1 Answer, 1 is accepted

Sort by
0
Accepted
Polya
Telerik team
answered on 06 Dec 2017, 12:52 PM
Hello Tom,

In order to replace a particular FontFamily with another when a new document is loaded you can use the RadRichTextBox.DocumentChanged event:
<telerik:RadRichTextBox LayoutMode="Paged" DocumentChanged="editor_DocumentChanged"/>

In its handler you could iterate all RadDocument Styles and Spans and if their FontFamily is Museo change it to Arial. Here is a code snippet demonstrating how to change all spans and styles that have "Comic Sans MS" FontFamily to use "Arial" FontFamily:
private void editor_DocumentChanged(object sender, EventArgs e)
{
    var rtb = sender as RadRichTextBox;
    var doc = rtb.Document;
    foreach (StyleDefinition sd in doc.StyleRepository.Where(sd => sd.SpanProperties.FontFamily.Source == "Comic Sans MS"))
    {
        sd.SpanProperties.FontFamily = new FontFamily("Arial");
    }
 
    foreach (Span sp in doc.EnumerateChildrenOfType<Span>().Where(sp => sp.FontFamily.Source == "Comic Sans MS"))
    {
        sp.FontFamily = new FontFamily("Arial");
    }
 
    if (doc.Style.SpanProperties.FontFamily.Source == "Comic Sans MS")
    {
        doc.Style.SpanProperties.FontFamily = new FontFamily("Arial");
    }
}

Hope this helps.

Regards,
Polya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RichTextBox
Asked by
Tom
Top achievements
Rank 1
Answers by
Polya
Telerik team
Share this question
or