| 1 |
/* This is xdvipsk, an eXtended version of dvips(k) by Tomas Rokicki. |
| 2 |
|
| 3 |
Copyright (C) 2016 by VTeX Ltd (www.vtex.lt), |
| 4 |
the xdvipsk project team - Sigitas Tolusis and Arunas Povilaitis. |
| 5 |
|
| 6 |
Program original code copyright (C) 2007-2014 by Jin-Hwan Cho and |
| 7 |
Shunsaku Hirata, the dvipdfmx project team. |
| 8 |
|
| 9 |
This program is free software; you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation; either version 2 of the License, or |
| 12 |
(at your option) any later version. |
| 13 |
|
| 14 |
This program is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
GNU General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License |
| 20 |
along with this program; if not, write to the Free Software |
| 21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 22 |
*/ |
| 23 |
|
| 24 |
/* |
| 25 |
* Unicode related: |
| 26 |
* Conversion between UTF-* and UCS-*. |
| 27 |
* ToUnicode CMap |
| 28 |
* |
| 29 |
* Normalization? |
| 30 |
*/ |
| 31 |
|
| 32 |
#include <config.h> |
| 33 |
|
| 34 |
#include <string.h> |
| 35 |
|
| 36 |
#include "system.h" |
| 37 |
#include "mem.h" |
| 38 |
#include "error.h" |
| 39 |
|
| 40 |
#include "unicode.h" |
| 41 |
|
| 42 |
#define UC_DEBUG 3 |
| 43 |
#define UC_DEBUG_STR "UC" |
| 44 |
|
| 45 |
#define UC_REPLACEMENT_CHAR 0x0000FFFDL |
| 46 |
|
| 47 |
#define UC_SUR_SHIFT 10 |
| 48 |
#define UC_SUR_MASK 0x3FFUL |
| 49 |
#define UC_SUR_LOW_START 0xDC00UL |
| 50 |
#define UC_SUR_HIGH_START 0xD800UL |
| 51 |
|
| 52 |
int |
| 53 |
UC_sput_UTF16BE (long ucv, unsigned char **pp, unsigned char *limptr) |
| 54 |
{ |
| 55 |
int count = 0; |
| 56 |
unsigned char *p = *pp; |
| 57 |
|
| 58 |
if (ucv >= 0 && ucv <= 0xFFFF) { |
| 59 |
if (p + 2 >= limptr) |
| 60 |
ERROR("Not enough space available..."); |
| 61 |
p[0] = (ucv >> 8) & 0xff; |
| 62 |
p[1] = ucv & 0xff; |
| 63 |
count = 2; |
| 64 |
} else if (ucv >= 0x010000L && ucv <= 0x10FFFFL) { |
| 65 |
unsigned short high, low; |
| 66 |
|
| 67 |
if (p + 4 >= limptr) |
| 68 |
ERROR("Not enough space available..."); |
| 69 |
ucv -= 0x00010000L; |
| 70 |
high = (ucv >> UC_SUR_SHIFT) + UC_SUR_HIGH_START; |
| 71 |
low = (ucv & UC_SUR_MASK) + UC_SUR_LOW_START; |
| 72 |
p[0] = (high >> 8) & 0xff; |
| 73 |
p[1] = (high & 0xff); |
| 74 |
p[2] = (low >> 8) & 0xff; |
| 75 |
p[3] = (low & 0xff); |
| 76 |
count = 4; |
| 77 |
} else { |
| 78 |
if (p + 2 >= limptr) |
| 79 |
ERROR("Not enough space available..."); |
| 80 |
p[0] = (UC_REPLACEMENT_CHAR >> 8) & 0xff; |
| 81 |
p[1] = (UC_REPLACEMENT_CHAR & 0xff); |
| 82 |
count = 2; |
| 83 |
} |
| 84 |
|
| 85 |
*pp += count; |
| 86 |
return count; |
| 87 |
} |
| 88 |
|
| 89 |
int |
| 90 |
UC_is_valid (long ucv) |
| 91 |
{ |
| 92 |
if (ucv < 0 || (ucv >= 0x0000D800L && ucv <= 0x0000DFFFL)) |
| 93 |
return 0; |
| 94 |
return 1; |
| 95 |
} |
| 96 |
|