Why does Console.Write treat the x266A character differently?

I am writing a console application that should print some atypical (for a console application) Unicode characters such as musical notes, box drawing characters, etc.

Most characters display correctly or show? if the glyph does not exist for any font used by the console, however, I found one character that behaves strangely, which can be demonstrated by the following lines:

Console.Write("ABC"); Console.Write('β™ͺ'); //This is the same as: Console.Write((char)0x266A); Console.Write("XYZ"); 

When it starts, it will print ABC, and then move the cursor back to the beginning of the line and overwrite it with XYZ. Why is this happening?

+6
source share
2 answers

The console does not use Uncode, so characters must be translated to an 8-bit code page. The β™ͺ character is converted to the character code 13 (hex 0x0d), which is a CR or Return Carrage.

On most code pages, such as code page 850 , char character CR is similar to a quarter note, and character 266a is specified as the Unicode equivalent.

However, if you write a CR character on the console, it does not display a quarter-value glyph, instead, it is interpreted as a CR control character that moves the cursor to the beginning of the line.

+5
source

Console.Write('β™ͺ'); considered unicode. I guess it translates it to the nearest ASCII character. You must use U+1D160 or the corresponding Unicode, musical equivalent.

There are necessary primitives for generating a music output in Unicode encoding (starting from U + 1D100). For example, U + 1D11A is a 5-line staff, U + 1D158 is a closed notebook.

See http://www.unicode.org/charts/PDF/U1D100.pdf

.., then the problem will be that you have a font with the corresponding glyphs (and problems with correct interpolation, etc.).

IF you want to generate a printed result, you should look at Lilypond , which is an OSS musical notation package that uses a text file format to define music content and then generates a great result.

+2
source

Source: https://habr.com/ru/post/895901/


All Articles