Bug RichTextBox load html content with multiple fonts

6 posts, 1 answers
  1. Adrien
    Adrien avatar
    4 posts
    Member since:
    Nov 2011

    Posted 18 Nov 2011 Link to this post

    Hello,

    I have a bug with the RichTextBox (silverlight 4.0). I did a RichTextBox in which you can choose two fonts. In order to have the right font and the right font-size when the RichTextBox is loaded, I load something on the event SetupDocument of provider:
    Xaml :

    <telerikDocumentsHtml:HtmlDataProvider x:Name="Provider" SetupDocument="Provider_SetupDocument" RichTextBox="{Binding ElementName=radRichTextBox}" Html="{Binding Content, Mode=TwoWay, NotifyOnValidationError=True}">
                <telerikDocumentsHtml:HtmlDataProvider.FormatProvider>
                    <telerikDocumentsHtml:HtmlFormatProvider>
                        <telerikDocumentsHtml:HtmlFormatProvider.ExportSettings>
                            <telerikDocumentsHtmlModel:HtmlExportSettings
                                DocumentExportLevel="Fragment"
                                StylesExportMode="Inline" />
                        </telerikDocumentsHtml:HtmlFormatProvider.ExportSettings>
                    </telerikDocumentsHtml:HtmlFormatProvider>
                </telerikDocumentsHtml:HtmlDataProvider.FormatProvider>
            </telerikDocumentsHtml:HtmlDataProvider>


    C# (Code-Behind) :

    private void Provider_SetupDocument(object sender, Telerik.Windows.Documents.FormatProviders.SetupDocumentEventArgs e)
            {
                e.Document.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(0, 0, 0, 0);
     
                FontFamily franklinGothicLTBook = new FontFamily("ITCFranklinGothicLTBook");
                //// Set the default font size for an empty document
                if (String.IsNullOrEmpty(this.Provider.Html))
                {
                    e.Document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                    e.Document.Arrange(new RectangleF(PointF.Empty, e.Document.DesiredSize));
                    //// 13.57 ==> 10 Word
                    ((Span)e.Document.CaretPosition.GetCurrentInlineBox().AssociatedDocumentElement).FontSize = 13.67;
                    ((Span)e.Document.CaretPosition.GetCurrentInlineBox().AssociatedDocumentElement).FontFamily = franklinGothicLTBook;
                }
                else
                {
                    ////Set the font size of an existing document
                    e.Document.Selection.SelectAll();
                    e.Document.UpdateSelectedSpansStyle((span) => { span.FontSize = 13.67; span.FontFamily = franklinGothicLTBook; return span; });
                }
            }


    Obviously, in the else here, I can’t have multiple fonts in a reloading html content generated by the same RichTextBox but I am waiting for the resolution of my problem. Indeed, I have to do that because otherwise I always have default options of the RichTextBox. But suddenly my problem is when the RichTextBox load, I can’t load content that uses both of my fonts.
    For information I am using the Q1 2011 SP1.

    Thanks by advance for your help.

    Adrien
  2. Adrien
    Adrien avatar
    4 posts
    Member since:
    Nov 2011

    Posted 23 Nov 2011 Link to this post

    ?? No body for help me ?
  3. Mike
    Admin
    Mike avatar
    640 posts

    Posted 23 Nov 2011 Link to this post

    Hi Adrien,

    We are sorry but we have troubles understanding the problem exactly. We noticed that you are trying to set the default font of the editor. You can do this by
    1. Set RadRichTextBox's property DocumentInheritsDefaultStyleSettings to true
    2. Set the FontSize/Familly properties of RadRichTextBox accordingly

    The following help article describes the approach:
    http://www.telerik.com/help/silverlight/radrichtextbox-frequently-asked-questions.html#Setting_Default_Style_Settings_on_the_Document


    Let us know if the problem persists or if you need further assistance.

    Best wishes,
    Mike
    the Telerik team

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

  4. Adrien
    Adrien avatar
    4 posts
    Member since:
    Nov 2011

    Posted 02 Dec 2011 Link to this post

    Hi,

    I have lost a lot and a lot of time with your control right now.
    When the document is empty and new, there is no problem, the richtextbox put the right font i have defined in the xaml, I did what you said :

    <telerikDocumentsHtml:HtmlDataProvider x:Name="Provider" SetupDocument="Provider_SetupDocument" RichTextBox="{Binding ElementName=radRichTextBox}" Html="{Binding Content, Mode=TwoWay, NotifyOnValidationError=True}">
                <telerikDocumentsHtml:HtmlDataProvider.FormatProvider>
                    <telerikDocumentsHtml:HtmlFormatProvider>
                        <telerikDocumentsHtml:HtmlFormatProvider.ExportSettings>
                            <telerikDocumentsHtmlModel:HtmlExportSettings
                                DocumentExportLevel="Fragment"
                                StylesExportMode="Inline" />
                        </telerikDocumentsHtml:HtmlFormatProvider.ExportSettings>
                        <telerikDocumentsHtml:HtmlFormatProvider.ImportSettings>
                            <telerikDocumentsHtmlModel:HtmlImportSettings UseDefaultStylesheetForFontProperties="True" />
                        </telerikDocumentsHtml:HtmlFormatProvider.ImportSettings>
                    </telerikDocumentsHtml:HtmlFormatProvider>
                </telerikDocumentsHtml:HtmlDataProvider.FormatProvider>
            </telerikDocumentsHtml:HtmlDataProvider>
            <telerik:RadRichTextBox x:Name="radRichTextBox" Loaded="RadRichTextBox_Loaded" DocumentInheritsDefaultStyleSettings="True" FontFamily="ITCFranklinGothicLTBook" FontSize="13.67" Grid.Row="1" IsSelectionMiniToolBarEnabled="False" IsSpellCheckingEnabled="False" IsContextMenuEnabled="False">
            </telerik:RadRichTextBox>


    But the problem is still the same when i load a document with this :
    <p style="margin: 0px 0px 12px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px;"><span style="font-family: 'ITCFranklinGothicLTBook';font-style: Normal;font-weight: normal;font-size: 13.6700000762939px;color: #000000;">aaaa</span><span style="font-family: 'ITCFranklinGothicLTDemi';font-style: Normal;font-weight: normal;font-size: 13.6700000762939px;color: #000000;">dddd</span><span style="font-family: 'ITCFranklinGothicLTBook';font-style: Normal;font-weight: normal;font-size: 13.6700000762939px;color: #000000;" /></p>


    I will always have this :
    <br><p style="margin: 0px 0px 12px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px;"><span style="font-family: 'Arial';font-style: Normal;font-weight: normal;font-size: 13.6700000762939px;color: #000000;">aaaadddd</span></p>


    And i have lost a lot of time with this... I am going to be crazy RIGHT NOW ! I have lost so much time for my company ... for this little bug. Please help me!

  5. Answer
    Boby
    Admin
    Boby avatar
    685 posts

    Posted 08 Dec 2011 Link to this post

    Hi Adrien,
    We are still not quite sure what is your problem. If you want to export the spans with their original font families, you can use the FontManager.RegisterFonts method:
    FontManager.RegisterFont(new FontFamily("ITCFranklinGothicLTBook"));
    You can also use the FontSubstituting event of HtmlImportSettings, unfortunately this way you will an issue with the default HtmlDataProvider, so you should use custom one, as demonstrated in the attached project:
    private void HtmlImportSettings_FontSubstituting(object sender, FontSubstitutingEventArgs e)
    {
        e.SubstitutionFontFamily = new FontFamily(e.OriginalFontName);
    }

    Don't hesitate to contact us if you need further assistance or if this doesn't answer your question.


    All the best,
    Boby
    the Telerik team

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

  6. Adrien
    Adrien avatar
    4 posts
    Member since:
    Nov 2011

    Posted 08 Dec 2011 Link to this post

    It's working !!! Thank you very very much !!! :)
    Your little solution is great !
Back to Top