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

RadRichTextBox and Embedded Fonts

5 Answers 254 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 08 Aug 2011, 08:39 PM
I've been trying to display an embedded font in a RadRichTextBox without success.  Here's some test code that demonstrates the behavior:

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

Sort by
0
Iva Toteva
Telerik team
answered on 12 Aug 2011, 11:19 AM
Hello Jeff,

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.

Best wishes,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Toni
Top achievements
Rank 1
answered on 08 Nov 2011, 10:16 PM
Hi Iva,

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"
        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
0
Iva Toteva
Telerik team
answered on 14 Nov 2011, 02:53 PM
Hello Antonio,

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. 

Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Raymond
Top achievements
Rank 1
answered on 20 Dec 2011, 02:11 PM
Hi,
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
0
Iva Toteva
Telerik team
answered on 23 Dec 2011, 07:23 PM
Hello Raymond,

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

Tags
RichTextBox
Asked by
Jeff
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Toni
Top achievements
Rank 1
Raymond
Top achievements
Rank 1
Share this question
or