28728

how does one show extended unicode > 0xFFFF?

Some fonts i.e. Symbola and Segoe ui Symbols have characters with five digit hex assignments. I.e the character "mushroom" is Ox1F344.

They show up fine in the character picker in excel etc but this code.

gr.setFont(new Font("Segoe UI Symbol",Font.PLAIN,12); gr.drawString(""+(char)Ox1F344+(char)Ox270B,100,100);

Gives me a unknown character and a hand rather than a mushroom and hand.

What am I doing wrong?

Answer1:

(char)Ox1F344 will overflow, as char is a 16-bit type and 0x1F344 requires more than 16 bits.

In Java, characters are UTF-16 code units, not actual Unicode characters. So you need the UTF-16 version of the character, which is 0xD83C 0xDF44. Then you need to put that in the string:

gr.drawString("\uD83C\uDF44\u270B", 100, 100); // This -------------------^^^^^^ is unrelated, it's the // second character shown in your question.

Answer2:

""+(char)Ox1F344+(char)Ox270B

Java's char/String types are, unfortunately, based around UTF-16 code units, so 0x1F344 overflows the 16-bit char datatype and is the same as 0xF344 (an unstandardised code point in the Private Use Area that could appear as anything).

In UTF-16 to encode a characters outside the Basic Multilingual Plane (0–0xFFFF) you have to use two Surrogate (0xD800–0xDFFF) characters. So the \u-escaped form of

Recommend

  • class can't be instantiated
  • java falling matrix code (like the movie)
  • new System.Drawing.Font Code Behind
  • XNA - How to change orientation of Drawing a List of Strings
  • How can I pass complex expression to parametrized active pattern?
  • Installing ocropus-0.4.4
  • OpenOptionsMenu not working with ActionBarSherlock Custom SubMenu
  • How to remove left and right margins from all wrapped rows in flexbox (without nth-child or js)
  • Java: java.util.ConcurrentModificationException
  • Boost binary serialization doesn't work occasionally. The parsed data is corrupted sometimes
  • Get the last date of each month in a list of dates in Python
  • Appium MobileElement swipe returns unknown server error
  • How can I let users share their location in Bot Framework webchat channel?
  • powershell Get-Counter -ComputerName parameter on Windows 7
  • Building Qt project for C++11 standard
  • How can I run DataNucleus Bytecode Enhancer from SBT?
  • HttpURLConnection Closing IO Streams
  • How to 'create temp table as select' in Slick?
  • Jquery Knockout: ko.computed() vs classic function?
  • How to read piped content in C?
  • Function calls are not supported. Consider replacing the function or lambda with a reference to an e
  • std::remove_copy_if_ valgrind bytes in block are possibly lost in loss record
  • How to revert to previous XCode version?
  • Appending Character to Character Array In C
  • Parsing a CSV string while ignoring commas inside the individual columns
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • How to define and use opencv mat of user type
  • Allowing both email and username for authentication
  • Meteor: Do Something On Email Verification Confirmation
  • Get one-time binding to work for ng-if
  • Azure Cloud Service Web Role web pages do not load
  • AES padding and writing the ciphertext to a disk file
  • Where to put my custom functions in Wordpress?
  • Convert array of 8 bytes to signed long in C++
  • How do you troubleshoot character encoding problems?
  • RestKit - RKRequestDelegate does not exist
  • Linker errors when using intrinsic function via function pointer
  • WPF Applying a trigger on binding failure
  • LevelDB C iterator
  • Django query for large number of relationships