1 //========================================================================
5 // Copyright 2001-2003 Glyph & Cog, LLC
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2008 Koji Otani <sho@bbr.jp>
18 // To see a description of the changes please see the Changelog file that
19 // came with your tarball or type make ChangeLog if you are building from git
21 //========================================================================
23 static int mapUTF8(Unicode u
, char *buf
, int bufSize
) {
24 if (u
<= 0x0000007f) {
30 } else if (u
<= 0x000007ff) {
34 buf
[0] = (char)(0xc0 + (u
>> 6));
35 buf
[1] = (char)(0x80 + (u
& 0x3f));
37 } else if (u
<= 0x0000ffff) {
41 buf
[0] = (char)(0xe0 + (u
>> 12));
42 buf
[1] = (char)(0x80 + ((u
>> 6) & 0x3f));
43 buf
[2] = (char)(0x80 + (u
& 0x3f));
45 } else if (u
<= 0x0010ffff) {
49 buf
[0] = (char)(0xf0 + (u
>> 18));
50 buf
[1] = (char)(0x80 + ((u
>> 12) & 0x3f));
51 buf
[2] = (char)(0x80 + ((u
>> 6) & 0x3f));
52 buf
[3] = (char)(0x80 + (u
& 0x3f));
59 static int mapUCS2(Unicode u
, char *buf
, int bufSize
) {
64 buf
[0] = (char)((u
>> 8) & 0xff);
65 buf
[1] = (char)(u
& 0xff);
67 } else if (u
< 0x110000) {
70 /* using surrogate pair */
74 uu
= ((u
- 0x10000) >> 10) + 0xd800;
75 buf
[0] = (char)((uu
>> 8) & 0xff);
76 buf
[1] = (char)(uu
& 0xff);
77 uu
= (u
& 0x3ff)+0xdc00;
78 buf
[2] = (char)((uu
>> 8) & 0xff);
79 buf
[3] = (char)(uu
& 0xff);