RadRichTextBox and Embedded Fonts

6 posts, 0 answers
  1. Jeff
    Jeff avatar
    2 posts
    Member since:
    May 2010

    Posted 08 Aug 2011 Link to this post

    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?
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 12 Aug 2011 Link to this post

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

  3. DevCraft banner
  4. Toni
    Toni avatar
    1 posts
    Member since:
    Sep 2011

    Posted 08 Nov 2011 Link to this post

    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
  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 14 Nov 2011 Link to this post

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

  6. Raymond
    Raymond avatar
    24 posts
    Member since:
    Apr 2009

    Posted 20 Dec 2011 Link to this post

    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
  7. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 23 Dec 2011 Link to this post

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

Back to Top
DevCraft banner