2

If you paste the below into a RichTextBox, the CJK character and everything afterwards turns into a second font - SimSun.

Inserting a CJK character: 色

...makes this font change.

This affects the formatting of the RichTextBox in an unwanted way, and also massively slows down large copy/pastes.

I have tried setting the RichTextBox to use a unicode font such as "Lucida Sans Unicode", and also made sure the source I was copying from (Wordpad) was also using the "Lucida Sans Unicode" font. However, at the end of the day, when I paste to the RichTextBox, it forces the use of another font such as SimSun (or other fonts like "Shonar Bangla" or "Microsoft Himalaya" if we use another type of character).

Since "Lucida Sans Unicode" has them all, why can't it stick to the one font?

I noticed someone else also has a similar problem: RichTextBox - retain original formatting (font), even after paste

Unfortunately, the solutions on that page didn't work for me as I still find the RTB uses another font after the CJK character.

Community
  • 1
  • 1
Dan W
  • 3,520
  • 7
  • 42
  • 69

3 Answers3

7

I've been having this problem on and off, myself.

After flipping around here and there on the internet today, I noticed something on msdn and tried something. Add this line to your Form1_Load(), or to the form constructor AFTER the InitializeComponent() line:

richTextBox1.LanguageOption = RichTextBoxLanguageOptions.DualFont;

I'm no expert, and I can't tell you anything about WHY it works but it DOES for me!

Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
SteelGolem
  • 71
  • 1
  • 1
  • 1
    Interesting. Which font do you use? Obviously, it would need to be one that contains at least a fair portion of the unicode set. – Dan W Aug 29 '12 at 00:28
  • I tried it out, and yes it does seem to make each line the same height. Unfortunately, it's still dog slow at loading the mixed text (to test, try the "List of colors" source at wikipedia), and certain unicode characters (such as రంగుల పట్టిక) don't make it through unscathed (they turn out as boxes). – Dan W Oct 09 '12 at 22:51
2

Unfortunately despite its slightly confusing name, Lucida Sans Unicode doesn't contain CJK characters (as you could expect from fonts with Unicode in its name). This triggers some font fallback mechanism which results in a font that contains the required symbol. The only possible solution I see is to use a font that actually contains all required characters.

dda
  • 6,030
  • 2
  • 25
  • 34
Petr Abdulin
  • 33,883
  • 9
  • 62
  • 96
  • The entire Unicode standard is huge and would require a font of several megabytes size to implement them all. If you go with a font like Bitstream Vera, that covers the most commonly-used scripts, just not ancient scripts, Klingon etc. – Sprachprofi Apr 12 '12 at 12:09
  • Maybe not so confusing name...`sans` means `without` in French. – Mark Tolonen Apr 12 '12 at 13:34
  • @ Mark: I'd agree except there's a font just called "Lucida Sans". So the 'Sans' here is referring to sans serif. – Dan W Apr 12 '12 at 14:22
  • @ Petr: You're right. Using Arial Unicode MS in its place seems to solve the "multiple font" problem. However, even with using Arial Unicode MS, line heights are still mixed, and I think that is making copy/pastes super slow compared to usual. – Dan W Apr 12 '12 at 14:24
  • CJK symbol display/draw is usually slower by an order (at least) compared to regular characters. As for line height, can't say for sure, maybe it's just because of CJK symbols size? – Petr Abdulin Apr 13 '12 at 04:37
  • Yes, it's not just CJK characters which are slower by the looks of it. What I've chosen to do is give the user the option to remove all unicode characters from 1280 (0x500) or higher. That (or shortly after) seems to be from where the slow down occurs. – Dan W Apr 13 '12 at 14:10
0

To complement Petr's answer (and partially use information from his comment), it turns out that many Unicode symbols render much slower in a RichTextBox.

But by filtering out unicode characters from about 1280 (0x500) and greater, I have found the paste to be as quick as before.

Dan W
  • 3,520
  • 7
  • 42
  • 69