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

Tabs not handled correctly when using HTML provoder

1 Answer 72 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 05 Jan 2013, 12:05 AM
UPDATE: I fixed this by loading the html string directly instead of first converting to a byte array.

So this:
    string text = File.ReadAllText(@"c:\temp\RichText.txt");
    Byte[] convertedText = Encoding.ASCII.GetBytes(text);
    RadDocument document = _htmlFormatProvider.Import(convertedText);

became this:
    string text = File.ReadAllText(@"c:\temp\RichText.txt");
    RadDocument document = _htmlFormatProvider.Import(text);





When I save and reload using an HtmlFormatProvider I get strange results with Tab characters.

Here is an example where the original text is "a<tab>b<tab>c".

The first time it is saved it looks like this. The tabs have been replaced with two "&nbsp;":
<style type="text/css">
.p_CC664AAA { margin: 0px 0px 12px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; } 
.s_6BF1D20F { font-family: 'Calibri';font-style: normal;font-size: 16px;color: #000000; } 
</style><p class="p_CC664AAA"><span class="s_6BF1D20F">a&nbsp; &nbsp; b&nbsp; &nbsp; c</span></p>

After reloading and saving again it looks like this. The two "&nbsp;" have been replaced with whitespace:
<style type="text/css">
.p_384D933F { margin: 0px 0px 0px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; } 
.s_6BF1D20F { font-family: 'Calibri';font-style: normal;font-size: 16px;color: #000000; } 
</style><p class="p_384D933F"><span class="s_6BF1D20F">a    b    c</span></p>

After reloading and saving again it looks like this. The whitespaces have been replaced with question marks:
<style type="text/css">
.p_384D933F { margin: 0px 0px 0px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; } 
.s_6BF1D20F { font-family: 'Calibri';font-style: normal;font-size: 16px;color: #000000; } 
</style><p class="p_384D933F"><span class="s_6BF1D20F">a? ? b? ? c</span></p>

Here is the sample code I am using for this test: 
public Form1()
{
    InitHtmlFormatProvider();
    InitializeComponent();
}
 
private static HtmlFormatProvider _htmlFormatProvider;
 
private static void InitHtmlFormatProvider()
{
    _htmlFormatProvider = new HtmlFormatProvider();
    var htmlExportSettings = new HtmlExportSettings();
    htmlExportSettings.DocumentExportLevel = DocumentExportLevel.Fragment;
    _htmlFormatProvider.ExportSettings = htmlExportSettings;
}
 
private void commandBarButtonLoad_Click(object sender, EventArgs e)
{
    string text = File.ReadAllText(@"c:\temp\RichText.txt");
    Byte[] convertedText = Encoding.ASCII.GetBytes(text);
    RadDocument document = _htmlFormatProvider.Import(convertedText);
    radRichTextBox1.Document = document;
}
 
private void commandBarButtonSave_Click(object sender, EventArgs e)
{
    string html = _htmlFormatProvider.Export(radRichTextBox1.Document);
    File.WriteAllText(@"c:\temp\RichText.txt", html);           
}


1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 09 Jan 2013, 02:18 PM
Hello Paul,

I am glad to hear that you managed to resolve the issue. It seems that conversion to bytes loses the tabs due to encoding changes.

All the best,
Svett
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Paul
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or