Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

As refereced from the below link,
http://officeopenxml.com/WPtextSpecialContent-symbol.php

quotes:

"In a Unicode character value created by adding F000 to the character value, thereby shifting the value into the Unicode private use area. This is done to allow interoperability with legacy word processing formats. So, in the example above, the value of the char attribute is F034, and so we would obtain the character value by removing F000 from F034 to obtain the character at the hexadecimal value 0x34 in the Wingdings font (or 52 as a decimal value)."

How do we convert Unicode private use area to Unicode character(or hexadecimal value)?

For example,
I need to convert Unicode PUA "F0E9" to its equivalent unicode.
Posted
Comments
Richard MacCutchan 23-Nov-13 8:32am    
You have quoted how to do it in your text above. Just subtract (or mask off) 0xF000 from the character.

If I correctly interpret quotation in your query, the following code should work.
1. You need to convert character to 2 bytes array
2. Then you need to manipulate first byte
3. Finally you need convert manipulated bytes to Unicode character

C#
private char fromPUA(char PUAChar)
{
    byte[] bytes = Encoding.Unicode.GetBytes(new char[] { PUAChar });
    bytes[1] = 0;
    return Encoding.Unicode.GetChars(bytes)[0];

}
private char toPUA(char input)
{

    byte[] bytes= Encoding.Unicode.GetBytes(new char[] {input});
    bytes[1] = 0xF0;
    return Encoding.Unicode.GetChars(bytes)[0];

}
 
Share this answer
 
Comments
karthime 25-Nov-13 3:25am    
Hi,

Thanks for the reply,

As per my requirement, the input is in string format "F0C9",
kindly refer the below link in which the suitable Unicode hexadecimal provided for the above PUA is ⊃
https://github.com/Distrotech/groff/blob/master/font/devlj4/generate/symbol.map
As per the quotes, when i tried out the code posted by you, it is only converting into hexadecimal but i was stuck when trying to convert PUA(F0C9) -> ⊃.
If innput is a string the follwing should work:

C#
private char fromPUA(string PUAChar)
 {
     //1. convert input string to the numerixc format
     UInt32 asNumber = Convert.ToUInt32(PUAChar, 16);

     //2. filter out PUA byte
     asNumber = 0Xff & asNumber;

     //3. Return Unicode character
     return  (char)asNumber;
 }



usage:

char c = fromPUA("F061");
 
Share this answer
 
Comments
karthime 27-Nov-13 7:13am    
Hi,
Thanks for your response,
I tried out the above code and the results were
1) The string "F0C9" was provided as input, the output from the first statement was 61641
2) Output of the asNumber was used for the second statement as input and its corresponding output was 201
3) The char returned for the asNumber was 'É'

But the actual output for the unicode provided was ⊃.

Kindly let me know, how do we achieve the actual output.
Adam Zgagacz 27-Nov-13 9:15am    
This is all correct.
You entered "FOC9" and you got 201 what in hex is C9. So method first converted "FOC9" to numerical form (you saw 61641 when displayed as decimal). Then removed "F0" part so now value was 00C9 (or 201 as decimal). And such value was returned.

What you see dispalyed as character is not Unicode character itself but it's graphical representation that depends on Font you are using. Character value returned is correct. It's up to you (your program/your font) how you want to show it to the user.
karthime 29-Nov-13 3:51am    
Hi,

Thanks, I have succeeded in getting the solution from the explanation but it seems that its working out correctly in chrome browser where as in mozilla browser it is displaying the character É instead of ⊃.

So how do i make the charcter ⊃ to appear as uniformly in all browser in all different os.

I am rendering the returned character(from fromPUA()) within the font tag, font-family:Symbol.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900