FontFamily native =
new
FontFamily(
"Playbill"
);
FontFamily native2 =
new
FontFamily(
"Comic Sans MS"
);
FontFamily embedded =
new
FontFamily(
"PLAYBILL.TTF#Playbill"
);
FontFamily embedded2 =
new
FontFamily(
"comic.ttf#Comic Sans MS"
);
radRichTextBox.Document.Sections.Add(
new
Telerik.Windows.Documents.Model.Section());
Telerik.Windows.Documents.Model.Paragraph paragraph =
new
Telerik.Windows.Documents.Model.Paragraph();
Telerik.Windows.Documents.Model.Span span =
new
Telerik.Windows.Documents.Model.Span();
span.FontFamily = embedded;
span.Text =
"This is RadRichTextBox test text."
;
paragraph.Children.Add(span);
radRichTextBox.Document.Sections.First.Children.Add(paragraph);
textBox.FontFamily = embedded2;
textBox.Text =
"This is TextBox test text."
;
The regular TextBox displays both native and embedded fonts as expected, but the RadRichTextBox only works with the native fonts. Both of the embedded fonts were added to the project as resources. Is this a known limitation of RadRichTextBox, or am I doing something wrong?
5 Answers, 1 is accepted
There are some specifics when using custom fonts in RadRichTextBox, as font families do not get initialized if they are not set to a TextBlock or other control from the framework first.
Please find attached an application showing how this limitation can be worked around.
Iva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
i have tried to solve a similar problem with the help of your EmbeddedFonts.zip. No luck so far.
I have stripped down my problem.
<
UserControl
x:Class
=
"RadControlsSilverlightApp1.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignWidth
=
"640"
d:DesignHeight
=
"480"
>
<
StackPanel
>
<
RichTextBox
>
<
Paragraph
>
<
Run
Text
=
"dummy rtb"
FontFamily
=
"Fonts/Helvetica.otf#Helvetica"
/>
</
Paragraph
>
</
RichTextBox
>
<
telerik:RadRichTextBox
IsSpellCheckingEnabled
=
"False"
>
<
telerik:RadDocument
>
<
telerik:Section
>
<
telerik:Paragraph
>
<
telerik:Span
Text
=
"dummy rrtb"
FontFamily
=
"Fonts/Helvetica.otf#Helvetica"
/>
</
telerik:Paragraph
>
</
telerik:Section
>
</
telerik:RadDocument
>
</
telerik:RadRichTextBox
>
</
StackPanel
>
</
UserControl
>
The upper richtextbox works as expected. The lower RadRichtextBox doesnt work within VS Designer.
ErrorMessage: MeasureOverride returned NaN: Telerik.Windows.Documents.Layout.ParagraphLayoutBox
Do you see any way to solve/workaround this problem?
Thanks Toni
There are issues when using custom fonts with RadRichTextBox, which we are trying to resolve. The first is that if the embedded font family is not set to the FontFamily property of a TextBox, TextBlock or RichTextBox, it does not get initialized. We have contacted Microsoft and are trying to resolve the issue.
Most probably the designer crash problem is related and is due to the fact that setting the FontFamily property of RadRichTextBox is not sufficient to instantiate the new font family. Therefore, the measure of the document fails. When you run the project, the font family is created by the MS control and RadRichTextBox can use it, too. The only workaround would be not to set the properties in XAML, but in code-behind, after the InitializeComponent method has passed as in the demo.
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
You write that there is an issue and you have a dialog with Microsoft. When is there a solution so we can use embedded custom fonts??
/R
Unfortunately, this issue was not resolved in Silverlight 5, so the only way to use custom fonts in RadRichTextBox would be to use the workaround demonstrated in the demo in this post. Basically, you need to keep a TextBox with a FontFamily set to your custom font and reference the font family through the TextBox. The demo also shows how you can import RTF files with custom fonts, which you have embedded as a Resource.
All the best,Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>