source: trunk/poppler/mypoppler/poppler/UTF8.h @ 257

Last change on this file since 257 was 257, checked in by Eugene Romanenko, 13 years ago

PDF plugin: Poppler library updated to version 0.10.0

File size: 2.1 KB
Line 
1//========================================================================
2//
3// UTF8.h
4//
5// Copyright 2001-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2008 Koji Otani <sho@bbr.jp>
17//
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
20//
21//========================================================================
22
23static int mapUTF8(Unicode u, char *buf, int bufSize) {
24  if        (u <= 0x0000007f) {
25    if (bufSize < 1) {
26      return 0;
27    }
28    buf[0] = (char)u;
29    return 1;
30  } else if (u <= 0x000007ff) {
31    if (bufSize < 2) {
32      return 0;
33    }
34    buf[0] = (char)(0xc0 + (u >> 6));
35    buf[1] = (char)(0x80 + (u & 0x3f));
36    return 2;
37  } else if (u <= 0x0000ffff) {
38    if (bufSize < 3) {
39      return 0;
40    }
41    buf[0] = (char)(0xe0 + (u >> 12));
42    buf[1] = (char)(0x80 + ((u >> 6) & 0x3f));
43    buf[2] = (char)(0x80 + (u & 0x3f));
44    return 3;
45  } else if (u <= 0x0010ffff) {
46    if (bufSize < 4) {
47      return 0;
48    }
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));
53    return 4;
54  } else {
55    return 0;
56  }
57}
58
59static int mapUCS2(Unicode u, char *buf, int bufSize) {
60  if (u <= 0xffff) {
61    if (bufSize < 2) {
62      return 0;
63    }
64    buf[0] = (char)((u >> 8) & 0xff);
65    buf[1] = (char)(u & 0xff);
66    return 2;
67  } else if (u < 0x110000) {
68    Unicode uu;
69
70    /* using surrogate pair */
71    if (bufSize < 4) {
72      return 0;
73    }
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);
80    return 4;
81  } else {
82    return 0;
83  }
84}
Note: See TracBrowser for help on using the repository browser.