Back to index

texmacs  1.0.7.15
unicode.c
Go to the documentation of this file.
00001 /*  $Header: /home/cvsroot/dvipdfmx/src/unicode.c,v 1.21 2004/09/11 14:50:29 hirata Exp $
00002 
00003     This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
00004 
00005     Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata,
00006     the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
00007 
00008     Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00023 */
00024 
00025 /*
00026  * Unicode related:
00027  *  Conversion between UTF-* and UCS-*.
00028  *  ToUnicode CMap
00029  *
00030  * Normalization?
00031  */
00032 
00033 #if HAVE_CONFIG_H
00034 #include "config.h"
00035 #endif
00036 
00037 #include <string.h>
00038 
00039 #include "system.h"
00040 #include "mem.h"
00041 #include "error.h"
00042 #include "dpxutil.h"
00043 
00044 #include "pdfobj.h"
00045 #include "pdfresource.h"
00046 
00047 #include "pdfencoding.h"
00048 #include "agl.h"
00049 #include "unicode.h"
00050 
00051 static int __verbose = 0;
00052 
00053 #define UC_DEBUG     3
00054 #define UC_DEBUG_STR "UC"
00055 
00056 void
00057 UC_set_verbose (void)
00058 {
00059   __verbose++;
00060 }
00061 
00062 #define UC_REPLACEMENT_CHAR 0x0000FFFDL
00063 
00064 #define UC_SUR_SHIFT      10
00065 #define UC_SUR_MASK       0x3FFUL
00066 #define UC_SUR_LOW_START  0xDC00UL
00067 #define UC_SUR_HIGH_START 0xD800UL
00068 
00069 int
00070 UC_sput_UTF16BE (long ucv, unsigned char **pp, unsigned char *limptr)
00071 {
00072   int count = 0;
00073   unsigned char *p = *pp;
00074 
00075   if (ucv >= 0 && ucv <= 0xFFFF) {
00076     if (p + 2 >= limptr)
00077       ERROR("Not enough space available...");
00078     p[0] = (ucv >> 8) & 0xff;
00079     p[1] = ucv & 0xff;
00080     count = 2;
00081   } else if (ucv >= 0x010000L && ucv <= 0x10FFFFL) {
00082     unsigned short high, low;
00083 
00084     if (p + 4 >= limptr)
00085       ERROR("Not enough space available...");
00086     ucv  -= 0x00010000L;
00087     high = (ucv >> UC_SUR_SHIFT) + UC_SUR_HIGH_START;
00088     low  = (ucv &  UC_SUR_MASK)  + UC_SUR_LOW_START;
00089     p[0] = (high >> 8) & 0xff;
00090     p[1] = (high & 0xff);
00091     p[2] = (low >> 8) & 0xff;
00092     p[3] = (low & 0xff);
00093     count = 4;
00094   } else {
00095     if (p + 2 >= limptr)
00096       ERROR("Not enough space available...");
00097     p[0] = (UC_REPLACEMENT_CHAR >> 8) & 0xff;
00098     p[1] = (UC_REPLACEMENT_CHAR & 0xff);
00099     count = 2;
00100   }
00101 
00102   *pp += count;
00103   return count;
00104 }
00105 
00106 int
00107 UC_is_valid (long ucv)
00108 {
00109   if (ucv < 0 || (ucv >= 0x0000D800L && ucv <= 0x0000DFFFL))
00110     return 0;
00111   return 1;
00112 }
00113