Completed
Last Updated: 24 Nov 2014 11:10 by Jesse Dyck
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 04 Dec 2013 01:58
Category:
Type: Bug Report
5
FIX. RadRichTextBox export/import results in wrong document's Font
To reproduce:
-add 2 RadRichTextBoxes and use the following code:
public Form1()
{
    InitializeComponent();
    Load += Form1_Load;
}

void SetDefaults(RadRichTextBox rtfbox)
{
    StyleDefinition style = rtfbox.Document.DefaultStyleSettings;
    style.SetPropertyValue(Span.FontFamilyProperty, "Microsoft Sans Serif");
    style.SetPropertyValue(Span.FontSizeProperty, (float)Math.Round(Unit.PointToDip(11), 1));
    rtfbox.Document.Selection.SelectAll();
    rtfbox.ChangeFontFamily("Microsoft Sans Serif");
    rtfbox.ChangeFontSize((float)Math.Round(Unit.PointToDip(11), 1));
}

void Form1_Load(object sender, EventArgs e)
{
    SetDefaults(rtf1);
    SetDefaults(rtf2);
}

private void rtf1_CurrentEditingStyleChanged(object sender, EventArgs e)
{
    radLabel1.Text = "Current font: " + (string)rtf1.CurrentEditingStyle.GetPropertyValue(Span.FontFamilyProperty);
    float fontSize = (float)rtf1.CurrentEditingStyle.GetPropertyValue(Span.FontSizeProperty);
    fontSize = (float)Math.Round(Unit.DipToPoint(fontSize), 1);
    radLabel2.Text = "Current fontsize: " + fontSize.ToString();
}

private void rtf2_CurrentEditingStyleChanged(object sender, EventArgs e)
{
    radLabel3.Text = "Current font: " + (string)rtf2.CurrentEditingStyle.GetPropertyValue(Span.FontFamilyProperty);
    float fontSize = (float)rtf2.CurrentEditingStyle.GetPropertyValue(Span.FontSizeProperty);
    fontSize = (float)Math.Round(Unit.DipToPoint(fontSize), 1);
    radLabel4.Text = "Current fontsize: " + fontSize.ToString();
}

private void radButton1_Click(object sender, EventArgs e)
{
    RtfFormatProvider rtfFormatProvider = new RtfFormatProvider();
    RadDocument doc = rtfFormatProvider.Import(File.ReadAllText("RadRichTextBox.rtf"));
    rtf2.Document = doc;
}

private void radButton2_Click(object sender, EventArgs e)
{
    RtfFormatProvider rtfProv1 = new RtfFormatProvider();
    SaveFileDialog saveDialog = new SaveFileDialog();
    saveDialog.DefaultExt = ".rtf";
    saveDialog.Filter = "Documents|*.rtf";
    DialogResult dialogResult = saveDialog.ShowDialog();
    string exp=string.Empty ;
    if (dialogResult == System.Windows.Forms.DialogResult.OK)
    {
        //use "RadRichTextBox.rtf"
        using (Stream output = saveDialog.OpenFile())
        {
            rtfProv1.Export(rtf1.Document, output);
            exp = rtfProv1.Export(rtf1.Document);
        }
    }
    
    RtfFormatProvider rtfProv2 = new RtfFormatProvider();
    rtf2.Document = rtfProv2.Import(exp);
}

Steps to perform:
1. Write some text in the fisrt RadRichTextBox and click the button for exporting. As a result the .rtf file content is correct (considering the desired Font - "Microsoft Sans Serif").
2.The imported content (from the exported .rtf file) in the second RadRichTextBox has incorrect Font: the default Calibri Font.

Resolution: 
This issue is addressed in the new version of the control - RadRichTextEditor. Please use the new control instead the RadRichTextBox. 
2 comments
Jesse Dyck
Posted on: 04 Dec 2013 06:42
I have now rolled back to the previous version and can confirm that RTF exported with Q3 2013 SP shows the same bug when imported using Q3 2013.
Jesse Dyck
Posted on: 04 Dec 2013 03:32
Seems like the error might be in the export part. RTF exported with the previous release seems to import correctly in the current release.