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

Pasting Plain Text Always Changes it to Verdana 12?

11 Answers 284 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Kurt Boyer
Top achievements
Rank 1
Kurt Boyer asked on 08 Apr 2015, 03:45 PM

I've been working with the RadRichTextEditor control in my application. It imports and exports simple html -- as I only need things like bold, italics, centering. However, even if I set the FontFamily of the RadRichTextEditor and even the RichTextBoxElement within to Arial, it doesn't respect that when I paste in plain text from an application like Notepad. It changes the text to Verdana with a font size of 12.

 If I copy and paste text from Word, I am fine. It keeps whatever font is was in Word. 

 Additionally, if I use the keyboard and hit shift + enter to give me a single line break (</ br>), It wraps that html with a style tag with the Verdana 12 font. I don't mind the style tag, but it would be nice if it respected the current font where the cursor is.

 Any ideas?

Here is my font properties code (which is overkill, but I'm trying everything to fix this).

public void SetDefaultFontPropertiesToEditor(RadRichTextEditor editor)
        {
            editor.DocumentInheritsDefaultStyleSettings = true;
            editor.RichTextBoxElement.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Arial"));
            editor.RichTextBoxElement.ChangeFontSize(Unit.PointToDip(10));
            editor.RichTextBoxElement.ChangeFontStyle(Telerik.WinControls.RichTextEditor.UI.FontStyles.Normal);
            editor.RichTextBoxElement.ChangeFontWeight(Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal);
 
            editor.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Arial"));
            editor.ChangeFontSize(Unit.PointToDip(10));
            editor.ChangeFontStyle(Telerik.WinControls.RichTextEditor.UI.FontStyles.Normal);
            editor.ChangeFontWeight(Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal);
 
            editor.RichTextBoxElement.Document.LineSpacingType = LineSpacingType.AtLeast;
            editor.RichTextBoxElement.Document.LineSpacing = 0;
            editor.RichTextBoxElement.Document.ParagraphDefaultSpacingAfter = 0;
            editor.RichTextBoxElement.Document.ParagraphDefaultSpacingBefore = 10;
        }

11 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 09 Apr 2015, 12:55 PM
Hi Kurt,

Thank you for contacting us.

To change the pasted text font you can use CommandExecuting event and paste the text manually: 
void radRichTextEditor1_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
    if (e.Command is PasteCommand)
    {
        e.Cancel = true;
        PasteNewText();
 
    }
}
 
public void PasteNewText()
{
    DocumentFragment clipboardDocument = null;
    string clipboardText = null;
    bool clipboardContainsData = false;
 
    if (ClipboardEx.ContainsDocument(null))
    {
        clipboardDocument = ClipboardEx.GetDocument();
        clipboardContainsData = true;
    }
    else if (ClipboardEx.ContainsText(null))
    {
        clipboardText = ClipboardEx.GetText(null);
        clipboardContainsData = true;
    }
 
    if (!clipboardContainsData)
    {
        return;
    }
 
    if (clipboardDocument != null)
    {
        RadDocument doc = new RadDocument();
        RadDocumentEditor editor = new RadDocumentEditor(doc);
        editor.InsertFragment(clipboardDocument);
        doc.Selection.SelectAll();
 
        editor.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Segoe Script"));
 
        DocumentFragment fragmentFromSelection = doc.Selection.CopySelectedDocumentElements();
        this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.InsertFragment(fragmentFromSelection);
    }
    else if (!string.IsNullOrEmpty(clipboardText))
    {
        this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.Insert(clipboardText);
    }
}

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Jason
Top achievements
Rank 1
answered on 07 May 2015, 06:34 AM

I have the same problem.  Copy some Calibri 11 point text from MS word - it pastes as Verdana 12 point.  Copy Kristen ITC 11 point - it pastes as Kristen ITC 12 point.  Copy plain text - it always pastes as Verdana 12 point, no matter what the current font of the control is set to.

If I copy rich text, I expect the paste to be in the same font and size as I copied.  For plain text I expect it to paste in the font that is currently set at the insertion point.

0
Dimitar
Telerik team
answered on 11 May 2015, 03:23 PM
Hello Jason,

Thank you for writing.

To achieve the desired functionality you can change the bellow code to check if the clipboard text has styles or it is just a plain text:
public void PasteNewText()
{
    DocumentFragment clipboardDocument = null;
    string clipboardText = null;
    bool clipboardContainsData = false;
 
    if (ClipboardEx.ContainsDocument(null))
    {
        clipboardDocument = ClipboardEx.GetDocument();
        clipboardContainsData = true;
    }
    else if (ClipboardEx.ContainsText(null))
    {
        clipboardText = ClipboardEx.GetText(null);
        clipboardContainsData = true;
    }
 
    if (!clipboardContainsData)
    {
        return;
    }
 
    if (clipboardDocument != null)
    {
        RadDocument doc = new RadDocument();
        RadDocumentEditor editor = new RadDocumentEditor(doc);
        editor.InsertFragment(clipboardDocument);
        doc.Selection.SelectAll();
        Span span = radRichTextEditor1.RichTextBoxElement.CurrentSpanStyle;
        if ((Clipboard.ContainsText(TextDataFormat.Text) || Clipboard.ContainsText(TextDataFormat.UnicodeText)) &&
            !(Clipboard.ContainsText(TextDataFormat.Rtf) || Clipboard.ContainsText(TextDataFormat.Html)))
        {
            editor.ChangeSpanStyle(span.Style);
            
        }
 
        DocumentFragment fragmentFromSelection = doc.Selection.CopySelectedDocumentElements();
        this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.InsertFragment(fragmentFromSelection);
    }
    else if (!string.IsNullOrEmpty(clipboardText))
    {
        this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.Insert(clipboardText);
    }
}

I hope this information is useful. Let me know if you need further assistance.
 
Regards,
Dimitar
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Jason
Top achievements
Rank 1
answered on 11 May 2015, 10:54 PM
I tried the updated code.  It made no difference.  The text is still pasted as Verdana 12 point.  It needs to paste as the same format as was copied - not change it to some arbitrary style as the sample code does.  I have raised a bug (933960) for this.
0
Dimitar
Telerik team
answered on 12 May 2015, 03:24 PM
Hi Jason,

Thank you for writing back.

On my side the styled text is pasted correctly and the font is preserved. I would recommend you to test this with different font family and style. The easiest way to is to open the First Look example for the RadRichTextEditor (from our demo application) and paste some code from Visual Studio. Could you please confirm that pasting code still does not work as expected?  

I am looking forward to your reply.

Regards,
Dimitar
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Jason
Top achievements
Rank 1
answered on 12 May 2015, 10:14 PM
I tried copying from Visual Studio and it did paste correctly.  However copying from Word 2010 does not.  Your colleague was able to reproduce this and has raised a fix on the feedback portal - http://feedback.telerik.com/Project/154/Feedback/Details/158293-fix-radrichtexteditor-pasting-from-ms-word-when-the-default-font-settings-are
0
Dimitar
Telerik team
answered on 13 May 2015, 10:36 AM
Hello Jason,

Thank you for writing back.

Yes there is a separate case where this is not working correctly. I want to mention that a workaround is available in the issue description.

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 12 Jun 2015, 02:05 PM
I have a similar problem. I am trying to use the radRichTextEditor to display a label preview so I am setting the text from code. It is always Verdana 12pt unless I select the text and change it. I also noticed that while in the VS designer the RTB has a blinking caret that appears to be 12pt. Changing the font size does not change anything in the RTB. This is clearly a bug.
0
Dimitar
Telerik team
answered on 15 Jun 2015, 09:44 AM
Hi Mark,

Thank you for contacting us.

You can see how to change the default font settings in the following article: Frequently Asked Questions. The font settings cannot be changed at design time they should be changed with the corresponding methods. Additionally, this should be done before any content is added to the document. If the document already contains something you should select the entire content first, if nothing is selected nothing will change. Detailed information about the selection is available here: Selection.

I hope this will be useful.

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Ralf
Top achievements
Rank 1
answered on 23 Jun 2015, 11:56 AM

Hello Telerik, 

your control changed also the format to Verdana when import rtf. But only in the first line. And only the first line is Arial. Is the first line with any other font formated, its all ok.

Here the code:

string rtfText = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fcharset0 Arial;}{\f1\fnil\fcharset0 Tahoma;}{\f2\fnil\fcharset0 Times New Roman;}{\f3\fnil\fcharset0 Arial Unicode MS;}{\f4\fnil\fcharset0 Calibri;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\tx300\tx600\tx900\tx1200\tx1500\tx1800\tx2100\tx2400\tx2700\tx3000\tx3300\tx3600\tx3900\tx4200\tx4500\cf1\b\fs32 Arial\f1\par
Tahoma\par
\f2 Times New Roman\par
\f0 Arial\f2\par
\f3 Arial Unicode MS\par
\f4 Calibri\b0\f0\fs20\par
}";
RtfFormatProvider rtf = new RtfFormatProvider();
this.radRichTextEditor1.Document = rtf.Import(rtfText);

this.richTextBox1.Rtf = rtfText;

In the screenshot you can see, left the standard .net rtf control and rigth the Telerik richtexteditor. 

 

0
Dimitar
Telerik team
answered on 23 Jun 2015, 01:29 PM
Hello Ralf,

Thank you for writing.

I was able to reproduce the observed issue. I have logged it in our Feedback Portal. You can track the item for status changes and add your vote for it here.

Unfortunately due to the nature of the issue I cannot suggest a workaround for it. If it is suitable for your case you can select the text and change its font.

Your Telerik Points have been updated for this report.

Should you have any other questions do not hesitate to ask.


Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextEditor
Asked by
Kurt Boyer
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Jason
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Ralf
Top achievements
Rank 1
Share this question
or