Xamarin/Mono crashes on Japanese input, Mavericks OSX - c#

I just started using Xamarin with existing windows C# code. Running Mavericks.
It seems to work great until I try to enter Japanese text in a text box.
HIToolbox crashes - looks like it's trying to convert NSNotFound from 64bit MAXINT to the 32bit MAXINT... and of course... you can't do that.
Does anyone have a workaround? or a fix? or a suggestion?
I tried different Japanese input methods, and different fonts in the box, but... same result.

Related

How to show emoji in c# console output?

I have a problem in output emoji in console.
String starts with Unicode flag "\u" works well, like "\u263A".
However, if just simply copy and paste an emoji into string, like "🎁", it does not work.
code test below:
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
string s1 = "🎁";
string s1_uni = "\ud83c\udf81"; // unicode code for s1
string s2 = "☺";
string s2_uni = "\u263A"; // unicode code for s2
Console.WriteLine(s1);
Console.WriteLine(s1_uni);
Console.WriteLine(s2);
Console.WriteLine(s2_uni);
Console.ReadLine();
}
}
}
s1 and s1_uni can successfully be outputted while s2 and s2_uni failed.
I want to know how to fix this problem.
By the way, the font applied is 'Consolas', which works perfectly in Visual Studio.
Update:
Please note that, I've done some searches in stackoverflow before I present this question. The most common way is to set the Console encoding to utf-8, which is done in the first line of Main.
This way (Console.OutputEncoding = Encoding.UTF8) can not totally fit the situation I presented.
Also, the reason why I make supplement to the console font in the question is to declare that Consolas font works perfectly in showing emoji in VS but failed in console. The first emoji failed to show.
Please do not close this question. Thanks.
Update2:
this emoji can be shown in the VS terminal.
Update3:
Thank Peter Duniho for help. And you are right.
While we are discussing, I look through the document MS Unicode Support for the Console.
Display of characters outside the Basic Multilingual Plane (that is, of surrogate pairs) is not supported, even if they are defined in a linked font file.
Code point of the emoji can't be shown in the console is just outside the BMP. And console does not support show code point outside BMP. Therefore, this emoji is not shown.
To change running context which may support this emoji. I did some experiments.
CMD:
Power Shell:
Windows Terminal:
You can see, windows terminal supports it.
Strictly speaking, the problem I met is not a duplicate question in stackoverflow. Because my code just did whatever can be done to meet the requirement. The problem is the running context, not code.
Thank Peter Duniho for help.
The current Windows command line console, cmd.exe, still uses GDI+ to render text. And the GDI+ API it uses does not correctly handle combining/surrogate pair characters like the emoji you want to display.
This is true even when using a font that includes the glyph for the character you want, and even when you have correctly set the output encoding for the Console class to a Unicode encoding (both of which you've done in your example).
Microsoft appears to be working on improvements to the command prompt code, to upgrade it to use the DirectWrite API instead of GDI+. If and when these improvements are released, the console window should be able to display your emoji correctly. See Github issue UTF-8 rendering woes #75
In the meantime, you can run your program in a context that is able to render these characters correctly, such as Windows Terminal or PowerShell.
Additional details regarding the limitations of the GDI+ font rendering can be found in Github issues Add emoji support to Windows Console #190 and emoji/unicode support mostly broken in windows #2693 (the latter isn't about a Windows component per se, but still relates to this problem).

How to display 'higher' unicode letters using Mono on Raspbian?

I've written a C# application (using VS) and in general it works fine on a Raspi using Mono to run the exe. Now I need a Chinese version, but Mono will not display code points like U+34B5.
I'm quite sure Mono causes the problem, because running everything on Windows works fine displaying the right symbols, and when I open the language csv on the Raspi using a simple text editor, I see the correct symbols, too.
I'm using the same font in my app as in the text editor. I tried lable, textbox aswell as richttextbox. no success.
string str = "\u34B4 \u34B5 \u34B6";
TextBox1.Text = str;
I'd expect those nice little symbols to be displayed like on windows, but on the Raspi I only see small empty boxes.

C# datagridview unicode character encoding

I cannot sort out the following problem:
I use a datagridview column to tell the user if the item of that row has already been processed. A little unicode icon should suffice, I thought, so I went for U+2174 (check mark) and U+2715 (cross) to achieve what I wanted. For the datatable...
row["Done"] = (listProcessed.Contains(file.FullName)) ? "\u2714" : "\u2715";
It works well in debug and release mode on my development machine, but it fails on a Windows XP virtual machine. On that one, only narrow squares are shown, just as if it didn't know the characters.
I read somewhere that it might be due to line endings, so I tried to apply TrimEnd(null) to the strings, but that did not help.
Is there a way to make this work on Windows XP? What exactly is going wrong?
thx i.a.
That means that the Windows XP machine is using a font that does not contain those characters.
Use charmap to see if you can find a font which does. (try Arial Unicode MS)

Format a Drive from C#

I need to format a pen drive from within a C# application.
I've googled around and the only thing I can find is http://msdn.microsoft.com/en-us/library/aa394515(VS.85).aspx
But I need it to work on Win XP, so that solution won't do for me.
Can anyone suggest an alternate method?
You could try to simply fork (not the linux fork :) ) a new process and run the Windows format command from inside your C# program.

C# Unicode (Japanese Characters)

I have a Japanese final coming up soon, so to help me study I made a program to help me study. But, I can't seem to get VS2008 to display any Unicode in the Console. This is a sample I used to see if I could display Unicode:
string diancai = new string(new char[]{ '\u70B9','\u83DC' });
Console.Write(diancai[0] + " " + diancai[1]);
Output is:
? ?
Please help! Thank you!
Go to your command prompt and try a command "chcp"
It should be like this
C:\> chcp
現在のコード ページ: 932
932 is japanese, If code page is not correct or if your windows does not support, It can't display it in console.
I can run yours in mine, its display following chars, mine is japanese windows.
点 菜
So, For your case, I recommand you to try with GUI program instead of console
There are two conditions that must be satisfied in order for this to work:
The console's output encoding must be able to represent Japanese characters
The console's font must be able to render them
Condition 1 should be fairly simple to deal with; just set System.Console.OutputEncoding to an appropriate Encoding, such as a UTF8Encoding. (Of course, this won't work on Windows 9x, since that doesn't really support encodings or Unicode. But you aren't using that, now, are you?)
Satisfying condition 2 is a bit more involved:
First, an appropriate font must be installed on the user's system. If there aren't any installed yet, the user will have to install some, perhaps by:
Opening intl.cpl ("Regional and Language Options" in the Control Panel on Windows XP in English)
Going to the "Languages" tab
Enabling "Install files for East Asian languages"
Clicking "OK"
Actually getting the console to use such a font seems to be fairly hairy; see the question: How to display japanese Kanji inside a cmd window under windows? for more about that.
I use Windows XP english version.
But I set my OS so it can show Japanese characters.
For Windows XP this is the step:
1.Control Panel -> Regional and Language Options -> Advanced
2.Choose Japanese.
3.Choose code page conversion tables for language do you use.
4.Push OK button
5.Restart your computer.
I tried to use "chcp" command on command prompt.
It display: Active code page 932

Categories

Resources