diff --git a/project/jni/expat/Android.mk b/project/jni/expat/Android.mk new file mode 100644 index 000000000..4dca89e6a --- /dev/null +++ b/project/jni/expat/Android.mk @@ -0,0 +1,33 @@ +LOCAL_PATH:= $(call my-dir) + +common_SRC_FILES := \ + lib/xmlparse.c \ + lib/xmlrole.c \ + lib/xmltok.c + +common_CFLAGS := \ + -Wall \ + -Wmissing-prototypes -Wstrict-prototypes \ + -Wno-unused-parameter -Wno-missing-field-initializers \ + -fexceptions \ + -DHAVE_EXPAT_CONFIG_H \ + -I$(LOCAL_PATH)/lib -I$(LOCAL_PATH) + +common_C_INCLUDES += \ + $(LOCAL_PATH)/include + +common_COPY_HEADERS_TO := libexpat +common_COPY_HEADERS := \ + lib/expat.h \ + lib/expat_external.h + +# Device shared library +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(common_SRC_FILES) +LOCAL_CFLAGS += $(common_CFLAGS) +LOCAL_C_INCLUDES += $(common_C_INCLUDES) + +LOCAL_MODULE:= expat + +include $(BUILD_SHARED_LIBRARY) diff --git a/project/jni/expat/Changes b/project/jni/expat/Changes new file mode 100644 index 000000000..08897b9f9 --- /dev/null +++ b/project/jni/expat/Changes @@ -0,0 +1,205 @@ +Release 2.1.0 Sat March 24 2012 + - Bug Fixes: + #1742315: Harmful XML_ParserCreateNS suggestion. + #2895533: CVE-2012-1147 - Resource leak in readfilemap.c. + #1785430: Expat build fails on linux-amd64 with gcc version>=4.1 -O3. + #1983953, 2517952, 2517962, 2649838: + Build modifications using autoreconf instead of buildconf.sh. + #2815947, #2884086: OBJEXT and EXEEXT support while building. + #1990430: CVE-2009-3720 - Parser crash with special UTF-8 sequences. + #2517938: xmlwf should return non-zero exit status if not well-formed. + #2517946: Wrong statement about XMLDecl in xmlwf.1 and xmlwf.sgml. + #2855609: Dangling positionPtr after error. + #2894085: CVE-2009-3560 - Buffer over-read and crash in big2_toUtf8(). + #2958794: CVE-2012-1148 - Memory leak in poolGrow. + #2990652: CMake support. + #3010819: UNEXPECTED_STATE with a trailing "%" in entity value. + #3206497: Unitialized memory returned from XML_Parse. + #3287849: make check fails on mingw-w64. + #3496608: CVE-2012-0876 - Hash DOS attack. + - Patches: + #1749198: pkg-config support. + #3010222: Fix for bug #3010819. + #3312568: CMake support. + #3446384: Report byte offsets for attr names and values. + - New Features / API changes: + Added new API member XML_SetHashSalt() that allows setting an intial + value (salt) for hash calculations. This is part of the fix for + bug #3496608 to randomize hash parameters. + When compiled with XML_ATTR_INFO defined, adds new API member + XML_GetAttributeInfo() that allows retrieving the byte + offsets for attribute names and values (patch #3446384). + Added CMake build system. + See bug #2990652 and patch #3312568. + Added run-benchmark target to Makefile.in - relies on testdata module + present in the same relative location as in the repository. + +Release 2.0.1 Tue June 5 2007 + - Fixed bugs #1515266, #1515600: The character data handler's calling + of XML_StopParser() was not handled properly; if the parser was + stopped and the handler set to NULL, the parser would segfault. + - Fixed bug #1690883: Expat failed on EBCDIC systems as it assumed + some character constants to be ASCII encoded. + - Minor cleanups of the test harness. + - Fixed xmlwf bug #1513566: "out of memory" error on file size zero. + - Fixed outline.c bug #1543233: missing a final XML_ParserFree() call. + - Fixes and improvements for Windows platform: + bugs #1409451, #1476160, #1548182, #1602769, #1717322. + - Build fixes for various platforms: + HP-UX, Tru64, Solaris 9: patch #1437840, bug #1196180. + All Unix: #1554618 (refreshed config.sub/config.guess). + #1490371, #1613457: support both, DESTDIR and INSTALL_ROOT, + without relying on GNU-Make specific features. + #1647805: Patched configure.in to work better with Intel compiler. + - Fixes to Makefile.in to have make check work correctly: + bugs #1408143, #1535603, #1536684. + - Added Open Watcom support: patch #1523242. + +Release 2.0.0 Wed Jan 11 2006 + - We no longer use the "check" library for C unit testing; we + always use the (partial) internal implementation of the API. + - Report XML_NS setting via XML_GetFeatureList(). + - Fixed headers for use from C++. + - XML_GetCurrentLineNumber() and XML_GetCurrentColumnNumber() + now return unsigned integers. + - Added XML_LARGE_SIZE switch to enable 64-bit integers for + byte indexes and line/column numbers. + - Updated to use libtool 1.5.22 (the most recent). + - Added support for AmigaOS. + - Some mostly minor bug fixes. SF issues include: #1006708, + #1021776, #1023646, #1114960, #1156398, #1221160, #1271642. + +Release 1.95.8 Fri Jul 23 2004 + - Major new feature: suspend/resume. Handlers can now request + that a parse be suspended for later resumption or aborted + altogether. See "Temporarily Stopping Parsing" in the + documentation for more details. + - Some mostly minor bug fixes, but compilation should no + longer generate warnings on most platforms. SF issues + include: #827319, #840173, #846309, #888329, #896188, #923913, + #928113, #961698, #985192. + +Release 1.95.7 Mon Oct 20 2003 + - Fixed enum XML_Status issue (reported on SourceForge many + times), so compilers that are properly picky will be happy. + - Introduced an XMLCALL macro to control the calling + convention used by the Expat API; this macro should be used + to annotate prototypes and definitions of callback + implementations in code compiled with a calling convention + other than the default convention for the host platform. + - Improved ability to build without the configure-generated + expat_config.h header. This is useful for applications + which embed Expat rather than linking in the library. + - Fixed a variety of bugs: see SF issues #458907, #609603, + #676844, #679754, #692878, #692964, #695401, #699323, #699487, + #820946. + - Improved hash table lookups. + - Added more regression tests and improved documentation. + +Release 1.95.6 Tue Jan 28 2003 + - Added XML_FreeContentModel(). + - Added XML_MemMalloc(), XML_MemRealloc(), XML_MemFree(). + - Fixed a variety of bugs: see SF issues #615606, #616863, + #618199, #653180, #673791. + - Enhanced the regression test suite. + - Man page improvements: includes SF issue #632146. + +Release 1.95.5 Fri Sep 6 2002 + - Added XML_UseForeignDTD() for improved SAX2 support. + - Added XML_GetFeatureList(). + - Defined XML_Bool type and the values XML_TRUE and XML_FALSE. + - Use an incomplete struct instead of a void* for the parser + (may not retain). + - Fixed UTF-8 decoding bug that caused legal UTF-8 to be rejected. + - Finally fixed bug where default handler would report DTD + events that were already handled by another handler. + Initial patch contributed by Darryl Miles. + - Removed unnecessary DllMain() function that caused static + linking into a DLL to be difficult. + - Added VC++ projects for building static libraries. + - Reduced line-length for all source code and headers to be + no longer than 80 characters, to help with AS/400 support. + - Reduced memory copying during parsing (SF patch #600964). + - Fixed a variety of bugs: see SF issues #580793, #434664, + #483514, #580503, #581069, #584041, #584183, #584832, #585537, + #596555, #596678, #598352, #598944, #599715, #600479, #600971. + +Release 1.95.4 Fri Jul 12 2002 + - Added support for VMS, contributed by Craig Berry. See + vms/README.vms for more information. + - Added Mac OS (classic) support, with a makefile for MPW, + contributed by Thomas Wegner and Daryle Walker. + - Added Borland C++ Builder 5 / BCC 5.5 support, contributed + by Patrick McConnell (SF patch #538032). + - Fixed a variety of bugs: see SF issues #441449, #563184, + #564342, #566334, #566901, #569461, #570263, #575168, #579196. + - Made skippedEntityHandler conform to SAX2 (see source comment) + - Re-implemented WFC: Entity Declared from XML 1.0 spec and + added a new error "entity declared in parameter entity": + see SF bug report #569461 and SF patch #578161 + - Re-implemented section 5.1 from XML 1.0 spec: + see SF bug report #570263 and SF patch #578161 + +Release 1.95.3 Mon Jun 3 2002 + - Added a project to the MSVC workspace to create a wchar_t + version of the library; the DLLs are named libexpatw.dll. + - Changed the name of the Windows DLLs from expat.dll to + libexpat.dll; this fixes SF bug #432456. + - Added the XML_ParserReset() API function. + - Fixed XML_SetReturnNSTriplet() to work for element names. + - Made the XML_UNICODE builds usable (thanks, Karl!). + - Allow xmlwf to read from standard input. + - Install a man page for xmlwf on Unix systems. + - Fixed many bugs; see SF bug reports #231864, #461380, #464837, + #466885, #469226, #477667, #484419, #487840, #494749, #496505, + #547350. Other bugs which we can't test as easily may also + have been fixed, especially in the area of build support. + +Release 1.95.2 Fri Jul 27 2001 + - More changes to make MSVC happy with the build; add a single + workspace to support both the library and xmlwf application. + - Added a Windows installer for Windows users; includes + xmlwf.exe. + - Added compile-time constants that can be used to determine the + Expat version + - Removed a lot of GNU-specific dependencies to aide portability + among the various Unix flavors. + - Fix the UTF-8 BOM bug. + - Cleaned up warning messages for several compilers. + - Added the -Wall, -Wstrict-prototypes options for GCC. + +Release 1.95.1 Sun Oct 22 15:11:36 EDT 2000 + - Changes to get expat to build under Microsoft compiler + - Removed all aborts and instead return an UNEXPECTED_STATE error. + - Fixed a bug where a stray '%' in an entity value would cause an + abort. + - Defined XML_SetEndNamespaceDeclHandler. Thanks to Darryl Miles for + finding this oversight. + - Changed default patterns in lib/Makefile.in to fit non-GNU makes + Thanks to robin@unrated.net for reporting and providing an + account to test on. + - The reference had the wrong label for XML_SetStartNamespaceDecl. + Reported by an anonymous user. + +Release 1.95.0 Fri Sep 29 2000 + - XML_ParserCreate_MM + Allows you to set a memory management suite to replace the + standard malloc,realloc, and free. + - XML_SetReturnNSTriplet + If you turn this feature on when namespace processing is in + effect, then qualified, prefixed element and attribute names + are returned as "uri|name|prefix" where '|' is whatever + separator character is used in namespace processing. + - Merged in features from perl-expat + o XML_SetElementDeclHandler + o XML_SetAttlistDeclHandler + o XML_SetXmlDeclHandler + o XML_SetEntityDeclHandler + o StartDoctypeDeclHandler takes 3 additional parameters: + sysid, pubid, has_internal_subset + o Many paired handler setters (like XML_SetElementHandler) + now have corresponding individual handler setters + o XML_GetInputContext for getting the input context of + the current parse position. + - Added reference material + - Packaged into a distribution that builds a sharable library diff --git a/project/jni/expat/MODULE_LICENSE_BSD_LIKE b/project/jni/expat/MODULE_LICENSE_BSD_LIKE new file mode 100644 index 000000000..e69de29bb diff --git a/project/jni/expat/NOTICE b/project/jni/expat/NOTICE new file mode 100644 index 000000000..dcb450642 --- /dev/null +++ b/project/jni/expat/NOTICE @@ -0,0 +1,22 @@ +Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + and Clark Cooper +Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/project/jni/expat/README b/project/jni/expat/README new file mode 100644 index 000000000..1f88467d1 --- /dev/null +++ b/project/jni/expat/README @@ -0,0 +1,139 @@ + + Expat, Release 2.1.0 + +This is Expat, a C library for parsing XML, written by James Clark. +Expat is a stream-oriented XML parser. This means that you register +handlers with the parser before starting the parse. These handlers +are called when the parser discovers the associated structures in the +document being parsed. A start tag is an example of the kind of +structures for which you may register handlers. + +Windows users should use the expat_win32bin package, which includes +both precompiled libraries and executables, and source code for +developers. + +Expat is free software. You may copy, distribute, and modify it under +the terms of the License contained in the file COPYING distributed +with this package. This license is the same as the MIT/X Consortium +license. + +Versions of Expat that have an odd minor version (the middle number in +the release above), are development releases and should be considered +as beta software. Releases with even minor version numbers are +intended to be production grade software. + +If you are building Expat from a check-out from the CVS repository, +you need to run a script that generates the configure script using the +GNU autoconf and libtool tools. To do this, you need to have +autoconf 2.58 or newer. Run the script like this: + + ./buildconf.sh + +Once this has been done, follow the same instructions as for building +from a source distribution. + +To build Expat from a source distribution, you first run the +configuration shell script in the top level distribution directory: + + ./configure + +There are many options which you may provide to configure (which you +can discover by running configure with the --help option). But the +one of most interest is the one that sets the installation directory. +By default, the configure script will set things up to install +libexpat into /usr/local/lib, expat.h into /usr/local/include, and +xmlwf into /usr/local/bin. If, for example, you'd prefer to install +into /home/me/mystuff/lib, /home/me/mystuff/include, and +/home/me/mystuff/bin, you can tell configure about that with: + + ./configure --prefix=/home/me/mystuff + +Another interesting option is to enable 64-bit integer support for +line and column numbers and the over-all byte index: + + ./configure CPPFLAGS=-DXML_LARGE_SIZE + +However, such a modification would be a breaking change to the ABI +and is therefore not recommended for general use - e.g. as part of +a Linux distribution - but rather for builds with special requirements. + +After running the configure script, the "make" command will build +things and "make install" will install things into their proper +location. Have a look at the "Makefile" to learn about additional +"make" options. Note that you need to have write permission into +the directories into which things will be installed. + +If you are interested in building Expat to provide document +information in UTF-16 encoding rather than the default UTF-8, follow +these instructions (after having run "make distclean"): + + 1. For UTF-16 output as unsigned short (and version/error + strings as char), run: + + ./configure CPPFLAGS=-DXML_UNICODE + + For UTF-16 output as wchar_t (incl. version/error strings), + run: + + ./configure CFLAGS="-g -O2 -fshort-wchar" \ + CPPFLAGS=-DXML_UNICODE_WCHAR_T + + 2. Edit the MakeFile, changing: + + LIBRARY = libexpat.la + + to: + + LIBRARY = libexpatw.la + + (Note the additional "w" in the library name.) + + 3. Run "make buildlib" (which builds the library only). + Or, to save step 2, run "make buildlib LIBRARY=libexpatw.la". + + 4. Run "make installlib" (which installs the library only). + Or, if step 2 was omitted, run "make installlib LIBRARY=libexpatw.la". + +Using DESTDIR or INSTALL_ROOT is enabled, with INSTALL_ROOT being the default +value for DESTDIR, and the rest of the make file using only DESTDIR. +It works as follows: + $ make install DESTDIR=/path/to/image +overrides the in-makefile set DESTDIR, while both + $ INSTALL_ROOT=/path/to/image make install + $ make install INSTALL_ROOT=/path/to/image +use DESTDIR=$(INSTALL_ROOT), even if DESTDIR eventually is defined in the +environment, because variable-setting priority is +1) commandline +2) in-makefile +3) environment + +Note: This only applies to the Expat library itself, building UTF-16 versions +of xmlwf and the tests is currently not supported. + +Note for Solaris users: The "ar" command is usually located in +"/usr/ccs/bin", which is not in the default PATH. You will need to +add this to your path for the "make" command, and probably also switch +to GNU make (the "make" found in /usr/ccs/bin does not seem to work +properly -- appearantly it does not understand .PHONY directives). If +you're using ksh or bash, use this command to build: + + PATH=/usr/ccs/bin:$PATH make + +When using Expat with a project using autoconf for configuration, you +can use the probing macro in conftools/expat.m4 to determine how to +include Expat. See the comments at the top of that file for more +information. + +A reference manual is available in the file doc/reference.html in this +distribution. + +The homepage for this project is http://www.libexpat.org/. There +are links there to connect you to the bug reports page. If you need +to report a bug when you don't have access to a browser, you may also +send a bug report by email to expat-bugs@mail.libexpat.org. + +Discussion related to the direction of future expat development takes +place on expat-discuss@mail.libexpat.org. Archives of this list and +other Expat-related lists may be found at: + + http://mail.libexpat.org/mailman/listinfo/ diff --git a/project/jni/expat/expat_config.h b/project/jni/expat/expat_config.h new file mode 100644 index 000000000..724f47f1d --- /dev/null +++ b/project/jni/expat/expat_config.h @@ -0,0 +1,103 @@ +/* expat_config.h. Generated from expat_config.h.in by configure. */ +/* expat_config.h.in. Generated from configure.in by autoheader. */ + +/* 1234 = LIL_ENDIAN, 4321 = BIGENDIAN */ +#define BYTEORDER 1234 + +/* Define to 1 if you have the `bcopy' function. */ +#define HAVE_BCOPY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `getpagesize' function. */ +#define HAVE_GETPAGESIZE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have a working `mmap' system call. */ +#define HAVE_MMAP 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "expat-bugs@libexpat.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "expat" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "expat 2.1.0" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "expat" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2.1.0" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* whether byteorder is bigendian */ +/* #undef WORDS_BIGENDIAN */ + +/* Define to specify how much context to retain around the current parse + point. */ +#define XML_CONTEXT_BYTES 1024 + +/* Define to make parameter entity parsing functionality available. */ +#define XML_DTD 1 + +/* Define to make XML Namespaces functionality available. */ +#define XML_NS 1 + +/* Define to __FUNCTION__ or "" if `__func__' does not conform to ANSI C. */ +/* #undef __func__ */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `long int' if does not define. */ +/* #undef off_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/project/jni/expat/include/expat.h b/project/jni/expat/include/expat.h new file mode 120000 index 000000000..c8f139577 --- /dev/null +++ b/project/jni/expat/include/expat.h @@ -0,0 +1 @@ +../lib/expat.h \ No newline at end of file diff --git a/project/jni/expat/include/expat_external.h b/project/jni/expat/include/expat_external.h new file mode 120000 index 000000000..beda254ab --- /dev/null +++ b/project/jni/expat/include/expat_external.h @@ -0,0 +1 @@ +../lib/expat_external.h \ No newline at end of file diff --git a/project/jni/expat/lib/ascii.h b/project/jni/expat/lib/ascii.h new file mode 100644 index 000000000..d10530b09 --- /dev/null +++ b/project/jni/expat/lib/ascii.h @@ -0,0 +1,92 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#define ASCII_A 0x41 +#define ASCII_B 0x42 +#define ASCII_C 0x43 +#define ASCII_D 0x44 +#define ASCII_E 0x45 +#define ASCII_F 0x46 +#define ASCII_G 0x47 +#define ASCII_H 0x48 +#define ASCII_I 0x49 +#define ASCII_J 0x4A +#define ASCII_K 0x4B +#define ASCII_L 0x4C +#define ASCII_M 0x4D +#define ASCII_N 0x4E +#define ASCII_O 0x4F +#define ASCII_P 0x50 +#define ASCII_Q 0x51 +#define ASCII_R 0x52 +#define ASCII_S 0x53 +#define ASCII_T 0x54 +#define ASCII_U 0x55 +#define ASCII_V 0x56 +#define ASCII_W 0x57 +#define ASCII_X 0x58 +#define ASCII_Y 0x59 +#define ASCII_Z 0x5A + +#define ASCII_a 0x61 +#define ASCII_b 0x62 +#define ASCII_c 0x63 +#define ASCII_d 0x64 +#define ASCII_e 0x65 +#define ASCII_f 0x66 +#define ASCII_g 0x67 +#define ASCII_h 0x68 +#define ASCII_i 0x69 +#define ASCII_j 0x6A +#define ASCII_k 0x6B +#define ASCII_l 0x6C +#define ASCII_m 0x6D +#define ASCII_n 0x6E +#define ASCII_o 0x6F +#define ASCII_p 0x70 +#define ASCII_q 0x71 +#define ASCII_r 0x72 +#define ASCII_s 0x73 +#define ASCII_t 0x74 +#define ASCII_u 0x75 +#define ASCII_v 0x76 +#define ASCII_w 0x77 +#define ASCII_x 0x78 +#define ASCII_y 0x79 +#define ASCII_z 0x7A + +#define ASCII_0 0x30 +#define ASCII_1 0x31 +#define ASCII_2 0x32 +#define ASCII_3 0x33 +#define ASCII_4 0x34 +#define ASCII_5 0x35 +#define ASCII_6 0x36 +#define ASCII_7 0x37 +#define ASCII_8 0x38 +#define ASCII_9 0x39 + +#define ASCII_TAB 0x09 +#define ASCII_SPACE 0x20 +#define ASCII_EXCL 0x21 +#define ASCII_QUOT 0x22 +#define ASCII_AMP 0x26 +#define ASCII_APOS 0x27 +#define ASCII_MINUS 0x2D +#define ASCII_PERIOD 0x2E +#define ASCII_COLON 0x3A +#define ASCII_SEMI 0x3B +#define ASCII_LT 0x3C +#define ASCII_EQUALS 0x3D +#define ASCII_GT 0x3E +#define ASCII_LSQB 0x5B +#define ASCII_RSQB 0x5D +#define ASCII_UNDERSCORE 0x5F +#define ASCII_LPAREN 0x28 +#define ASCII_RPAREN 0x29 +#define ASCII_FF 0x0C +#define ASCII_SLASH 0x2F +#define ASCII_HASH 0x23 +#define ASCII_PIPE 0x7C +#define ASCII_COMMA 0x2C diff --git a/project/jni/expat/lib/asciitab.h b/project/jni/expat/lib/asciitab.h new file mode 100644 index 000000000..79a15c28c --- /dev/null +++ b/project/jni/expat/lib/asciitab.h @@ -0,0 +1,36 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, +/* 0x0C */ BT_NONXML, BT_CR, BT_NONXML, BT_NONXML, +/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, +/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, +/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, +/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, +/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, +/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, +/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, +/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, +/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, diff --git a/project/jni/expat/lib/expat.h b/project/jni/expat/lib/expat.h new file mode 100644 index 000000000..9a21680be --- /dev/null +++ b/project/jni/expat/lib/expat.h @@ -0,0 +1,1047 @@ +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef Expat_INCLUDED +#define Expat_INCLUDED 1 + +#ifdef __VMS +/* 0 1 2 3 0 1 2 3 + 1234567890123456789012345678901 1234567890123456789012345678901 */ +#define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler +#define XML_SetUnparsedEntityDeclHandler XML_SetUnparsedEntDeclHandler +#define XML_SetStartNamespaceDeclHandler XML_SetStartNamespcDeclHandler +#define XML_SetExternalEntityRefHandlerArg XML_SetExternalEntRefHandlerArg +#endif + +#include +#include "expat_external.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct XML_ParserStruct; +typedef struct XML_ParserStruct *XML_Parser; + +/* Should this be defined using stdbool.h when C99 is available? */ +typedef unsigned char XML_Bool; +#define XML_TRUE ((XML_Bool) 1) +#define XML_FALSE ((XML_Bool) 0) + +/* The XML_Status enum gives the possible return values for several + API functions. The preprocessor #defines are included so this + stanza can be added to code that still needs to support older + versions of Expat 1.95.x: + + #ifndef XML_STATUS_OK + #define XML_STATUS_OK 1 + #define XML_STATUS_ERROR 0 + #endif + + Otherwise, the #define hackery is quite ugly and would have been + dropped. +*/ +enum XML_Status { + XML_STATUS_ERROR = 0, +#define XML_STATUS_ERROR XML_STATUS_ERROR + XML_STATUS_OK = 1, +#define XML_STATUS_OK XML_STATUS_OK + XML_STATUS_SUSPENDED = 2 +#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED +}; + +enum XML_Error { + XML_ERROR_NONE, + XML_ERROR_NO_MEMORY, + XML_ERROR_SYNTAX, + XML_ERROR_NO_ELEMENTS, + XML_ERROR_INVALID_TOKEN, + XML_ERROR_UNCLOSED_TOKEN, + XML_ERROR_PARTIAL_CHAR, + XML_ERROR_TAG_MISMATCH, + XML_ERROR_DUPLICATE_ATTRIBUTE, + XML_ERROR_JUNK_AFTER_DOC_ELEMENT, + XML_ERROR_PARAM_ENTITY_REF, + XML_ERROR_UNDEFINED_ENTITY, + XML_ERROR_RECURSIVE_ENTITY_REF, + XML_ERROR_ASYNC_ENTITY, + XML_ERROR_BAD_CHAR_REF, + XML_ERROR_BINARY_ENTITY_REF, + XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, + XML_ERROR_MISPLACED_XML_PI, + XML_ERROR_UNKNOWN_ENCODING, + XML_ERROR_INCORRECT_ENCODING, + XML_ERROR_UNCLOSED_CDATA_SECTION, + XML_ERROR_EXTERNAL_ENTITY_HANDLING, + XML_ERROR_NOT_STANDALONE, + XML_ERROR_UNEXPECTED_STATE, + XML_ERROR_ENTITY_DECLARED_IN_PE, + XML_ERROR_FEATURE_REQUIRES_XML_DTD, + XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, + /* Added in 1.95.7. */ + XML_ERROR_UNBOUND_PREFIX, + /* Added in 1.95.8. */ + XML_ERROR_UNDECLARING_PREFIX, + XML_ERROR_INCOMPLETE_PE, + XML_ERROR_XML_DECL, + XML_ERROR_TEXT_DECL, + XML_ERROR_PUBLICID, + XML_ERROR_SUSPENDED, + XML_ERROR_NOT_SUSPENDED, + XML_ERROR_ABORTED, + XML_ERROR_FINISHED, + XML_ERROR_SUSPEND_PE, + /* Added in 2.0. */ + XML_ERROR_RESERVED_PREFIX_XML, + XML_ERROR_RESERVED_PREFIX_XMLNS, + XML_ERROR_RESERVED_NAMESPACE_URI +}; + +enum XML_Content_Type { + XML_CTYPE_EMPTY = 1, + XML_CTYPE_ANY, + XML_CTYPE_MIXED, + XML_CTYPE_NAME, + XML_CTYPE_CHOICE, + XML_CTYPE_SEQ +}; + +enum XML_Content_Quant { + XML_CQUANT_NONE, + XML_CQUANT_OPT, + XML_CQUANT_REP, + XML_CQUANT_PLUS +}; + +/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be + XML_CQUANT_NONE, and the other fields will be zero or NULL. + If type == XML_CTYPE_MIXED, then quant will be NONE or REP and + numchildren will contain number of elements that may be mixed in + and children point to an array of XML_Content cells that will be + all of XML_CTYPE_NAME type with no quantification. + + If type == XML_CTYPE_NAME, then the name points to the name, and + the numchildren field will be zero and children will be NULL. The + quant fields indicates any quantifiers placed on the name. + + CHOICE and SEQ will have name NULL, the number of children in + numchildren and children will point, recursively, to an array + of XML_Content cells. + + The EMPTY, ANY, and MIXED types will only occur at top level. +*/ + +typedef struct XML_cp XML_Content; + +struct XML_cp { + enum XML_Content_Type type; + enum XML_Content_Quant quant; + XML_Char * name; + unsigned int numchildren; + XML_Content * children; +}; + + +/* This is called for an element declaration. See above for + description of the model argument. It's the caller's responsibility + to free model when finished with it. +*/ +typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData, + const XML_Char *name, + XML_Content *model); + +XMLPARSEAPI(void) +XML_SetElementDeclHandler(XML_Parser parser, + XML_ElementDeclHandler eldecl); + +/* The Attlist declaration handler is called for *each* attribute. So + a single Attlist declaration with multiple attributes declared will + generate multiple calls to this handler. The "default" parameter + may be NULL in the case of the "#IMPLIED" or "#REQUIRED" + keyword. The "isrequired" parameter will be true and the default + value will be NULL in the case of "#REQUIRED". If "isrequired" is + true and default is non-NULL, then this is a "#FIXED" default. +*/ +typedef void (XMLCALL *XML_AttlistDeclHandler) ( + void *userData, + const XML_Char *elname, + const XML_Char *attname, + const XML_Char *att_type, + const XML_Char *dflt, + int isrequired); + +XMLPARSEAPI(void) +XML_SetAttlistDeclHandler(XML_Parser parser, + XML_AttlistDeclHandler attdecl); + +/* The XML declaration handler is called for *both* XML declarations + and text declarations. The way to distinguish is that the version + parameter will be NULL for text declarations. The encoding + parameter may be NULL for XML declarations. The standalone + parameter will be -1, 0, or 1 indicating respectively that there + was no standalone parameter in the declaration, that it was given + as no, or that it was given as yes. +*/ +typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData, + const XML_Char *version, + const XML_Char *encoding, + int standalone); + +XMLPARSEAPI(void) +XML_SetXmlDeclHandler(XML_Parser parser, + XML_XmlDeclHandler xmldecl); + + +typedef struct { + void *(*malloc_fcn)(size_t size); + void *(*realloc_fcn)(void *ptr, size_t size); + void (*free_fcn)(void *ptr); +} XML_Memory_Handling_Suite; + +/* Constructs a new parser; encoding is the encoding specified by the + external protocol or NULL if there is none specified. +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreate(const XML_Char *encoding); + +/* Constructs a new parser and namespace processor. Element type + names and attribute names that belong to a namespace will be + expanded; unprefixed attribute names are never expanded; unprefixed + element type names are expanded only if there is a default + namespace. The expanded name is the concatenation of the namespace + URI, the namespace separator character, and the local part of the + name. If the namespace separator is '\0' then the namespace URI + and the local part will be concatenated without any separator. + It is a programming error to use the separator '\0' with namespace + triplets (see XML_SetReturnNSTriplet). +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); + + +/* Constructs a new parser using the memory management suite referred to + by memsuite. If memsuite is NULL, then use the standard library memory + suite. If namespaceSeparator is non-NULL it creates a parser with + namespace processing as described above. The character pointed at + will serve as the namespace separator. + + All further memory operations used for the created parser will come from + the given suite. +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreate_MM(const XML_Char *encoding, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *namespaceSeparator); + +/* Prepare a parser object to be re-used. This is particularly + valuable when memory allocation overhead is disproportionatly high, + such as when a large number of small documnents need to be parsed. + All handlers are cleared from the parser, except for the + unknownEncodingHandler. The parser's external state is re-initialized + except for the values of ns and ns_triplets. + + Added in Expat 1.95.3. +*/ +XMLPARSEAPI(XML_Bool) +XML_ParserReset(XML_Parser parser, const XML_Char *encoding); + +/* atts is array of name/value pairs, terminated by 0; + names and values are 0 terminated. +*/ +typedef void (XMLCALL *XML_StartElementHandler) (void *userData, + const XML_Char *name, + const XML_Char **atts); + +typedef void (XMLCALL *XML_EndElementHandler) (void *userData, + const XML_Char *name); + + +/* s is not 0 terminated. */ +typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData, + const XML_Char *s, + int len); + +/* target and data are 0 terminated */ +typedef void (XMLCALL *XML_ProcessingInstructionHandler) ( + void *userData, + const XML_Char *target, + const XML_Char *data); + +/* data is 0 terminated */ +typedef void (XMLCALL *XML_CommentHandler) (void *userData, + const XML_Char *data); + +typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData); +typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData); + +/* This is called for any characters in the XML document for which + there is no applicable handler. This includes both characters that + are part of markup which is of a kind that is not reported + (comments, markup declarations), or characters that are part of a + construct which could be reported but for which no handler has been + supplied. The characters are passed exactly as they were in the XML + document except that they will be encoded in UTF-8 or UTF-16. + Line boundaries are not normalized. Note that a byte order mark + character is not passed to the default handler. There are no + guarantees about how characters are divided between calls to the + default handler: for example, a comment might be split between + multiple calls. +*/ +typedef void (XMLCALL *XML_DefaultHandler) (void *userData, + const XML_Char *s, + int len); + +/* This is called for the start of the DOCTYPE declaration, before + any DTD or internal subset is parsed. +*/ +typedef void (XMLCALL *XML_StartDoctypeDeclHandler) ( + void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid, + int has_internal_subset); + +/* This is called for the start of the DOCTYPE declaration when the + closing > is encountered, but after processing any external + subset. +*/ +typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); + +/* This is called for entity declarations. The is_parameter_entity + argument will be non-zero if the entity is a parameter entity, zero + otherwise. + + For internal entities (), value will + be non-NULL and systemId, publicID, and notationName will be NULL. + The value string is NOT nul-terminated; the length is provided in + the value_length argument. Since it is legal to have zero-length + values, do not use this argument to test for internal entities. + + For external entities, value will be NULL and systemId will be + non-NULL. The publicId argument will be NULL unless a public + identifier was provided. The notationName argument will have a + non-NULL value only for unparsed entity declarations. + + Note that is_parameter_entity can't be changed to XML_Bool, since + that would break binary compatibility. +*/ +typedef void (XMLCALL *XML_EntityDeclHandler) ( + void *userData, + const XML_Char *entityName, + int is_parameter_entity, + const XML_Char *value, + int value_length, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName); + +XMLPARSEAPI(void) +XML_SetEntityDeclHandler(XML_Parser parser, + XML_EntityDeclHandler handler); + +/* OBSOLETE -- OBSOLETE -- OBSOLETE + This handler has been superceded by the EntityDeclHandler above. + It is provided here for backward compatibility. + + This is called for a declaration of an unparsed (NDATA) entity. + The base argument is whatever was set by XML_SetBase. The + entityName, systemId and notationName arguments will never be + NULL. The other arguments may be. +*/ +typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) ( + void *userData, + const XML_Char *entityName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName); + +/* This is called for a declaration of notation. The base argument is + whatever was set by XML_SetBase. The notationName will never be + NULL. The other arguments can be. +*/ +typedef void (XMLCALL *XML_NotationDeclHandler) ( + void *userData, + const XML_Char *notationName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* When namespace processing is enabled, these are called once for + each namespace declaration. The call to the start and end element + handlers occur between the calls to the start and end namespace + declaration handlers. For an xmlns attribute, prefix will be + NULL. For an xmlns="" attribute, uri will be NULL. +*/ +typedef void (XMLCALL *XML_StartNamespaceDeclHandler) ( + void *userData, + const XML_Char *prefix, + const XML_Char *uri); + +typedef void (XMLCALL *XML_EndNamespaceDeclHandler) ( + void *userData, + const XML_Char *prefix); + +/* This is called if the document is not standalone, that is, it has an + external subset or a reference to a parameter entity, but does not + have standalone="yes". If this handler returns XML_STATUS_ERROR, + then processing will not continue, and the parser will return a + XML_ERROR_NOT_STANDALONE error. + If parameter entity parsing is enabled, then in addition to the + conditions above this handler will only be called if the referenced + entity was actually read. +*/ +typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData); + +/* This is called for a reference to an external parsed general + entity. The referenced entity is not automatically parsed. The + application can parse it immediately or later using + XML_ExternalEntityParserCreate. + + The parser argument is the parser parsing the entity containing the + reference; it can be passed as the parser argument to + XML_ExternalEntityParserCreate. The systemId argument is the + system identifier as specified in the entity declaration; it will + not be NULL. + + The base argument is the system identifier that should be used as + the base for resolving systemId if systemId was relative; this is + set by XML_SetBase; it may be NULL. + + The publicId argument is the public identifier as specified in the + entity declaration, or NULL if none was specified; the whitespace + in the public identifier will have been normalized as required by + the XML spec. + + The context argument specifies the parsing context in the format + expected by the context argument to XML_ExternalEntityParserCreate; + context is valid only until the handler returns, so if the + referenced entity is to be parsed later, it must be copied. + context is NULL only when the entity is a parameter entity. + + The handler should return XML_STATUS_ERROR if processing should not + continue because of a fatal error in the handling of the external + entity. In this case the calling parser will return an + XML_ERROR_EXTERNAL_ENTITY_HANDLING error. + + Note that unlike other handlers the first argument is the parser, + not userData. +*/ +typedef int (XMLCALL *XML_ExternalEntityRefHandler) ( + XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* This is called in two situations: + 1) An entity reference is encountered for which no declaration + has been read *and* this is not an error. + 2) An internal entity reference is read, but not expanded, because + XML_SetDefaultHandler has been called. + Note: skipped parameter entities in declarations and skipped general + entities in attribute values cannot be reported, because + the event would be out of sync with the reporting of the + declarations or attribute values +*/ +typedef void (XMLCALL *XML_SkippedEntityHandler) ( + void *userData, + const XML_Char *entityName, + int is_parameter_entity); + +/* This structure is filled in by the XML_UnknownEncodingHandler to + provide information to the parser about encodings that are unknown + to the parser. + + The map[b] member gives information about byte sequences whose + first byte is b. + + If map[b] is c where c is >= 0, then b by itself encodes the + Unicode scalar value c. + + If map[b] is -1, then the byte sequence is malformed. + + If map[b] is -n, where n >= 2, then b is the first byte of an + n-byte sequence that encodes a single Unicode scalar value. + + The data member will be passed as the first argument to the convert + function. + + The convert function is used to convert multibyte sequences; s will + point to a n-byte sequence where map[(unsigned char)*s] == -n. The + convert function must return the Unicode scalar value represented + by this byte sequence or -1 if the byte sequence is malformed. + + The convert function may be NULL if the encoding is a single-byte + encoding, that is if map[b] >= -1 for all bytes b. + + When the parser is finished with the encoding, then if release is + not NULL, it will call release passing it the data member; once + release has been called, the convert function will not be called + again. + + Expat places certain restrictions on the encodings that are supported + using this mechanism. + + 1. Every ASCII character that can appear in a well-formed XML document, + other than the characters + + $@\^`{}~ + + must be represented by a single byte, and that byte must be the + same byte that represents that character in ASCII. + + 2. No character may require more than 4 bytes to encode. + + 3. All characters encoded must have Unicode scalar values <= + 0xFFFF, (i.e., characters that would be encoded by surrogates in + UTF-16 are not allowed). Note that this restriction doesn't + apply to the built-in support for UTF-8 and UTF-16. + + 4. No Unicode character may be encoded by more than one distinct + sequence of bytes. +*/ +typedef struct { + int map[256]; + void *data; + int (XMLCALL *convert)(void *data, const char *s); + void (XMLCALL *release)(void *data); +} XML_Encoding; + +/* This is called for an encoding that is unknown to the parser. + + The encodingHandlerData argument is that which was passed as the + second argument to XML_SetUnknownEncodingHandler. + + The name argument gives the name of the encoding as specified in + the encoding declaration. + + If the callback can provide information about the encoding, it must + fill in the XML_Encoding structure, and return XML_STATUS_OK. + Otherwise it must return XML_STATUS_ERROR. + + If info does not describe a suitable encoding, then the parser will + return an XML_UNKNOWN_ENCODING error. +*/ +typedef int (XMLCALL *XML_UnknownEncodingHandler) ( + void *encodingHandlerData, + const XML_Char *name, + XML_Encoding *info); + +XMLPARSEAPI(void) +XML_SetElementHandler(XML_Parser parser, + XML_StartElementHandler start, + XML_EndElementHandler end); + +XMLPARSEAPI(void) +XML_SetStartElementHandler(XML_Parser parser, + XML_StartElementHandler handler); + +XMLPARSEAPI(void) +XML_SetEndElementHandler(XML_Parser parser, + XML_EndElementHandler handler); + +XMLPARSEAPI(void) +XML_SetCharacterDataHandler(XML_Parser parser, + XML_CharacterDataHandler handler); + +XMLPARSEAPI(void) +XML_SetProcessingInstructionHandler(XML_Parser parser, + XML_ProcessingInstructionHandler handler); +XMLPARSEAPI(void) +XML_SetCommentHandler(XML_Parser parser, + XML_CommentHandler handler); + +XMLPARSEAPI(void) +XML_SetCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start, + XML_EndCdataSectionHandler end); + +XMLPARSEAPI(void) +XML_SetStartCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start); + +XMLPARSEAPI(void) +XML_SetEndCdataSectionHandler(XML_Parser parser, + XML_EndCdataSectionHandler end); + +/* This sets the default handler and also inhibits expansion of + internal entities. These entity references will be passed to the + default handler, or to the skipped entity handler, if one is set. +*/ +XMLPARSEAPI(void) +XML_SetDefaultHandler(XML_Parser parser, + XML_DefaultHandler handler); + +/* This sets the default handler but does not inhibit expansion of + internal entities. The entity reference will not be passed to the + default handler. +*/ +XMLPARSEAPI(void) +XML_SetDefaultHandlerExpand(XML_Parser parser, + XML_DefaultHandler handler); + +XMLPARSEAPI(void) +XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end); + +XMLPARSEAPI(void) +XML_SetStartDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start); + +XMLPARSEAPI(void) +XML_SetEndDoctypeDeclHandler(XML_Parser parser, + XML_EndDoctypeDeclHandler end); + +XMLPARSEAPI(void) +XML_SetUnparsedEntityDeclHandler(XML_Parser parser, + XML_UnparsedEntityDeclHandler handler); + +XMLPARSEAPI(void) +XML_SetNotationDeclHandler(XML_Parser parser, + XML_NotationDeclHandler handler); + +XMLPARSEAPI(void) +XML_SetNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start, + XML_EndNamespaceDeclHandler end); + +XMLPARSEAPI(void) +XML_SetStartNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start); + +XMLPARSEAPI(void) +XML_SetEndNamespaceDeclHandler(XML_Parser parser, + XML_EndNamespaceDeclHandler end); + +XMLPARSEAPI(void) +XML_SetNotStandaloneHandler(XML_Parser parser, + XML_NotStandaloneHandler handler); + +XMLPARSEAPI(void) +XML_SetExternalEntityRefHandler(XML_Parser parser, + XML_ExternalEntityRefHandler handler); + +/* If a non-NULL value for arg is specified here, then it will be + passed as the first argument to the external entity ref handler + instead of the parser object. +*/ +XMLPARSEAPI(void) +XML_SetExternalEntityRefHandlerArg(XML_Parser parser, + void *arg); + +XMLPARSEAPI(void) +XML_SetSkippedEntityHandler(XML_Parser parser, + XML_SkippedEntityHandler handler); + +XMLPARSEAPI(void) +XML_SetUnknownEncodingHandler(XML_Parser parser, + XML_UnknownEncodingHandler handler, + void *encodingHandlerData); + +/* This can be called within a handler for a start element, end + element, processing instruction or character data. It causes the + corresponding markup to be passed to the default handler. +*/ +XMLPARSEAPI(void) +XML_DefaultCurrent(XML_Parser parser); + +/* If do_nst is non-zero, and namespace processing is in effect, and + a name has a prefix (i.e. an explicit namespace qualifier) then + that name is returned as a triplet in a single string separated by + the separator character specified when the parser was created: URI + + sep + local_name + sep + prefix. + + If do_nst is zero, then namespace information is returned in the + default manner (URI + sep + local_name) whether or not the name + has a prefix. + + Note: Calling XML_SetReturnNSTriplet after XML_Parse or + XML_ParseBuffer has no effect. +*/ + +XMLPARSEAPI(void) +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); + +/* This value is passed as the userData argument to callbacks. */ +XMLPARSEAPI(void) +XML_SetUserData(XML_Parser parser, void *userData); + +/* Returns the last value set by XML_SetUserData or NULL. */ +#define XML_GetUserData(parser) (*(void **)(parser)) + +/* This is equivalent to supplying an encoding argument to + XML_ParserCreate. On success XML_SetEncoding returns non-zero, + zero otherwise. + Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer + has no effect and returns XML_STATUS_ERROR. +*/ +XMLPARSEAPI(enum XML_Status) +XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); + +/* If this function is called, then the parser will be passed as the + first argument to callbacks instead of userData. The userData will + still be accessible using XML_GetUserData. +*/ +XMLPARSEAPI(void) +XML_UseParserAsHandlerArg(XML_Parser parser); + +/* If useDTD == XML_TRUE is passed to this function, then the parser + will assume that there is an external subset, even if none is + specified in the document. In such a case the parser will call the + externalEntityRefHandler with a value of NULL for the systemId + argument (the publicId and context arguments will be NULL as well). + Note: For the purpose of checking WFC: Entity Declared, passing + useDTD == XML_TRUE will make the parser behave as if the document + had a DTD with an external subset. + Note: If this function is called, then this must be done before + the first call to XML_Parse or XML_ParseBuffer, since it will + have no effect after that. Returns + XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. + Note: If the document does not have a DOCTYPE declaration at all, + then startDoctypeDeclHandler and endDoctypeDeclHandler will not + be called, despite an external subset being parsed. + Note: If XML_DTD is not defined when Expat is compiled, returns + XML_ERROR_FEATURE_REQUIRES_XML_DTD. +*/ +XMLPARSEAPI(enum XML_Error) +XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); + + +/* Sets the base to be used for resolving relative URIs in system + identifiers in declarations. Resolving relative identifiers is + left to the application: this value will be passed through as the + base argument to the XML_ExternalEntityRefHandler, + XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base + argument will be copied. Returns XML_STATUS_ERROR if out of memory, + XML_STATUS_OK otherwise. +*/ +XMLPARSEAPI(enum XML_Status) +XML_SetBase(XML_Parser parser, const XML_Char *base); + +XMLPARSEAPI(const XML_Char *) +XML_GetBase(XML_Parser parser); + +/* Returns the number of the attribute/value pairs passed in last call + to the XML_StartElementHandler that were specified in the start-tag + rather than defaulted. Each attribute/value pair counts as 2; thus + this correspondds to an index into the atts array passed to the + XML_StartElementHandler. +*/ +XMLPARSEAPI(int) +XML_GetSpecifiedAttributeCount(XML_Parser parser); + +/* Returns the index of the ID attribute passed in the last call to + XML_StartElementHandler, or -1 if there is no ID attribute. Each + attribute/value pair counts as 2; thus this correspondds to an + index into the atts array passed to the XML_StartElementHandler. +*/ +XMLPARSEAPI(int) +XML_GetIdAttributeIndex(XML_Parser parser); + +#ifdef XML_ATTR_INFO +/* Source file byte offsets for the start and end of attribute names and values. + The value indices are exclusive of surrounding quotes; thus in a UTF-8 source + file an attribute value of "blah" will yield: + info->valueEnd - info->valueStart = 4 bytes. +*/ +typedef struct { + XML_Index nameStart; /* Offset to beginning of the attribute name. */ + XML_Index nameEnd; /* Offset after the attribute name's last byte. */ + XML_Index valueStart; /* Offset to beginning of the attribute value. */ + XML_Index valueEnd; /* Offset after the attribute value's last byte. */ +} XML_AttrInfo; + +/* Returns an array of XML_AttrInfo structures for the attribute/value pairs + passed in last call to the XML_StartElementHandler that were specified + in the start-tag rather than defaulted. Each attribute/value pair counts + as 1; thus the number of entries in the array is + XML_GetSpecifiedAttributeCount(parser) / 2. +*/ +XMLPARSEAPI(const XML_AttrInfo *) +XML_GetAttributeInfo(XML_Parser parser); +#endif + +/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is + detected. The last call to XML_Parse must have isFinal true; len + may be zero for this call (or any other). + + Though the return values for these functions has always been + described as a Boolean value, the implementation, at least for the + 1.95.x series, has always returned exactly one of the XML_Status + values. +*/ +XMLPARSEAPI(enum XML_Status) +XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); + +XMLPARSEAPI(void *) +XML_GetBuffer(XML_Parser parser, int len); + +XMLPARSEAPI(enum XML_Status) +XML_ParseBuffer(XML_Parser parser, int len, int isFinal); + +/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. + Must be called from within a call-back handler, except when aborting + (resumable = 0) an already suspended parser. Some call-backs may + still follow because they would otherwise get lost. Examples: + - endElementHandler() for empty elements when stopped in + startElementHandler(), + - endNameSpaceDeclHandler() when stopped in endElementHandler(), + and possibly others. + + Can be called from most handlers, including DTD related call-backs, + except when parsing an external parameter entity and resumable != 0. + Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. + Possible error codes: + - XML_ERROR_SUSPENDED: when suspending an already suspended parser. + - XML_ERROR_FINISHED: when the parser has already finished. + - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. + + When resumable != 0 (true) then parsing is suspended, that is, + XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. + Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() + return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. + + *Note*: + This will be applied to the current parser instance only, that is, if + there is a parent parser then it will continue parsing when the + externalEntityRefHandler() returns. It is up to the implementation of + the externalEntityRefHandler() to call XML_StopParser() on the parent + parser (recursively), if one wants to stop parsing altogether. + + When suspended, parsing can be resumed by calling XML_ResumeParser(). +*/ +XMLPARSEAPI(enum XML_Status) +XML_StopParser(XML_Parser parser, XML_Bool resumable); + +/* Resumes parsing after it has been suspended with XML_StopParser(). + Must not be called from within a handler call-back. Returns same + status codes as XML_Parse() or XML_ParseBuffer(). + Additional error code XML_ERROR_NOT_SUSPENDED possible. + + *Note*: + This must be called on the most deeply nested child parser instance + first, and on its parent parser only after the child parser has finished, + to be applied recursively until the document entity's parser is restarted. + That is, the parent parser will not resume by itself and it is up to the + application to call XML_ResumeParser() on it at the appropriate moment. +*/ +XMLPARSEAPI(enum XML_Status) +XML_ResumeParser(XML_Parser parser); + +enum XML_Parsing { + XML_INITIALIZED, + XML_PARSING, + XML_FINISHED, + XML_SUSPENDED +}; + +typedef struct { + enum XML_Parsing parsing; + XML_Bool finalBuffer; +} XML_ParsingStatus; + +/* Returns status of parser with respect to being initialized, parsing, + finished, or suspended and processing the final buffer. + XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, + XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED +*/ +XMLPARSEAPI(void) +XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); + +/* Creates an XML_Parser object that can parse an external general + entity; context is a '\0'-terminated string specifying the parse + context; encoding is a '\0'-terminated string giving the name of + the externally specified encoding, or NULL if there is no + externally specified encoding. The context string consists of a + sequence of tokens separated by formfeeds (\f); a token consisting + of a name specifies that the general entity of the name is open; a + token of the form prefix=uri specifies the namespace for a + particular prefix; a token of the form =uri specifies the default + namespace. This can be called at any point after the first call to + an ExternalEntityRefHandler so longer as the parser has not yet + been freed. The new parser is completely independent and may + safely be used in a separate thread. The handlers and userData are + initialized from the parser argument. Returns NULL if out of memory. + Otherwise returns a new XML_Parser object. +*/ +XMLPARSEAPI(XML_Parser) +XML_ExternalEntityParserCreate(XML_Parser parser, + const XML_Char *context, + const XML_Char *encoding); + +enum XML_ParamEntityParsing { + XML_PARAM_ENTITY_PARSING_NEVER, + XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, + XML_PARAM_ENTITY_PARSING_ALWAYS +}; + +/* Controls parsing of parameter entities (including the external DTD + subset). If parsing of parameter entities is enabled, then + references to external parameter entities (including the external + DTD subset) will be passed to the handler set with + XML_SetExternalEntityRefHandler. The context passed will be 0. + + Unlike external general entities, external parameter entities can + only be parsed synchronously. If the external parameter entity is + to be parsed, it must be parsed during the call to the external + entity ref handler: the complete sequence of + XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and + XML_ParserFree calls must be made during this call. After + XML_ExternalEntityParserCreate has been called to create the parser + for the external parameter entity (context must be 0 for this + call), it is illegal to make any calls on the old parser until + XML_ParserFree has been called on the newly created parser. + If the library has been compiled without support for parameter + entity parsing (ie without XML_DTD being defined), then + XML_SetParamEntityParsing will return 0 if parsing of parameter + entities is requested; otherwise it will return non-zero. + Note: If XML_SetParamEntityParsing is called after XML_Parse or + XML_ParseBuffer, then it has no effect and will always return 0. +*/ +XMLPARSEAPI(int) +XML_SetParamEntityParsing(XML_Parser parser, + enum XML_ParamEntityParsing parsing); + +/* Sets the hash salt to use for internal hash calculations. + Helps in preventing DoS attacks based on predicting hash + function behavior. This must be called before parsing is started. + Returns 1 if successful, 0 when called after parsing has started. +*/ +XMLPARSEAPI(int) +XML_SetHashSalt(XML_Parser parser, + unsigned long hash_salt); + +/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then + XML_GetErrorCode returns information about the error. +*/ +XMLPARSEAPI(enum XML_Error) +XML_GetErrorCode(XML_Parser parser); + +/* These functions return information about the current parse + location. They may be called from any callback called to report + some parse event; in this case the location is the location of the + first of the sequence of characters that generated the event. When + called from callbacks generated by declarations in the document + prologue, the location identified isn't as neatly defined, but will + be within the relevant markup. When called outside of the callback + functions, the position indicated will be just past the last parse + event (regardless of whether there was an associated callback). + + They may also be called after returning from a call to XML_Parse + or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then + the location is the location of the character at which the error + was detected; otherwise the location is the location of the last + parse event, as described above. +*/ +XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser); +XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser); +XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); + +/* Return the number of bytes in the current event. + Returns 0 if the event is in an internal entity. +*/ +XMLPARSEAPI(int) +XML_GetCurrentByteCount(XML_Parser parser); + +/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets + the integer pointed to by offset to the offset within this buffer + of the current parse position, and sets the integer pointed to by size + to the size of this buffer (the number of input bytes). Otherwise + returns a NULL pointer. Also returns a NULL pointer if a parse isn't + active. + + NOTE: The character pointer returned should not be used outside + the handler that makes the call. +*/ +XMLPARSEAPI(const char *) +XML_GetInputContext(XML_Parser parser, + int *offset, + int *size); + +/* For backwards compatibility with previous versions. */ +#define XML_GetErrorLineNumber XML_GetCurrentLineNumber +#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber +#define XML_GetErrorByteIndex XML_GetCurrentByteIndex + +/* Frees the content model passed to the element declaration handler */ +XMLPARSEAPI(void) +XML_FreeContentModel(XML_Parser parser, XML_Content *model); + +/* Exposing the memory handling functions used in Expat */ +XMLPARSEAPI(void *) +XML_MemMalloc(XML_Parser parser, size_t size); + +XMLPARSEAPI(void *) +XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); + +XMLPARSEAPI(void) +XML_MemFree(XML_Parser parser, void *ptr); + +/* Frees memory used by the parser. */ +XMLPARSEAPI(void) +XML_ParserFree(XML_Parser parser); + +/* Returns a string describing the error. */ +XMLPARSEAPI(const XML_LChar *) +XML_ErrorString(enum XML_Error code); + +/* Return a string containing the version number of this expat */ +XMLPARSEAPI(const XML_LChar *) +XML_ExpatVersion(void); + +typedef struct { + int major; + int minor; + int micro; +} XML_Expat_Version; + +/* Return an XML_Expat_Version structure containing numeric version + number information for this version of expat. +*/ +XMLPARSEAPI(XML_Expat_Version) +XML_ExpatVersionInfo(void); + +/* Added in Expat 1.95.5. */ +enum XML_FeatureEnum { + XML_FEATURE_END = 0, + XML_FEATURE_UNICODE, + XML_FEATURE_UNICODE_WCHAR_T, + XML_FEATURE_DTD, + XML_FEATURE_CONTEXT_BYTES, + XML_FEATURE_MIN_SIZE, + XML_FEATURE_SIZEOF_XML_CHAR, + XML_FEATURE_SIZEOF_XML_LCHAR, + XML_FEATURE_NS, + XML_FEATURE_LARGE_SIZE, + XML_FEATURE_ATTR_INFO + /* Additional features must be added to the end of this enum. */ +}; + +typedef struct { + enum XML_FeatureEnum feature; + const XML_LChar *name; + long int value; +} XML_Feature; + +XMLPARSEAPI(const XML_Feature *) +XML_GetFeatureList(void); + + +/* Expat follows the GNU/Linux convention of odd number minor version for + beta/development releases and even number minor version for stable + releases. Micro is bumped with each release, and set to 0 with each + change to major or minor version. +*/ +#define XML_MAJOR_VERSION 2 +#define XML_MINOR_VERSION 1 +#define XML_MICRO_VERSION 0 + +#ifdef __cplusplus +} +#endif + +#endif /* not Expat_INCLUDED */ diff --git a/project/jni/expat/lib/expat_external.h b/project/jni/expat/lib/expat_external.h new file mode 100644 index 000000000..2c03284ea --- /dev/null +++ b/project/jni/expat/lib/expat_external.h @@ -0,0 +1,115 @@ +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef Expat_External_INCLUDED +#define Expat_External_INCLUDED 1 + +/* External API definitions */ + +#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__) +#define XML_USE_MSC_EXTENSIONS 1 +#endif + +/* Expat tries very hard to make the API boundary very specifically + defined. There are two macros defined to control this boundary; + each of these can be defined before including this header to + achieve some different behavior, but doing so it not recommended or + tested frequently. + + XMLCALL - The calling convention to use for all calls across the + "library boundary." This will default to cdecl, and + try really hard to tell the compiler that's what we + want. + + XMLIMPORT - Whatever magic is needed to note that a function is + to be imported from a dynamically loaded library + (.dll, .so, or .sl, depending on your platform). + + The XMLCALL macro was added in Expat 1.95.7. The only one which is + expected to be directly useful in client code is XMLCALL. + + Note that on at least some Unix versions, the Expat library must be + compiled with the cdecl calling convention as the default since + system headers may assume the cdecl convention. +*/ +#ifndef XMLCALL +#if defined(_MSC_VER) +#define XMLCALL __cdecl +#elif defined(__GNUC__) && defined(__i386) && !defined(__INTEL_COMPILER) +#define XMLCALL __attribute__((cdecl)) +#else +/* For any platform which uses this definition and supports more than + one calling convention, we need to extend this definition to + declare the convention used on that platform, if it's possible to + do so. + + If this is the case for your platform, please file a bug report + with information on how to identify your platform via the C + pre-processor and how to specify the same calling convention as the + platform's malloc() implementation. +*/ +#define XMLCALL +#endif +#endif /* not defined XMLCALL */ + + +#if !defined(XML_STATIC) && !defined(XMLIMPORT) +#ifndef XML_BUILDING_EXPAT +/* using Expat from an application */ + +#ifdef XML_USE_MSC_EXTENSIONS +#define XMLIMPORT __declspec(dllimport) +#endif + +#endif +#endif /* not defined XML_STATIC */ + + +/* If we didn't define it above, define it away: */ +#ifndef XMLIMPORT +#define XMLIMPORT +#endif + + +#define XMLPARSEAPI(type) XMLIMPORT type XMLCALL + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef XML_UNICODE_WCHAR_T +#define XML_UNICODE +#endif + +#ifdef XML_UNICODE /* Information is UTF-16 encoded. */ +#ifdef XML_UNICODE_WCHAR_T +typedef wchar_t XML_Char; +typedef wchar_t XML_LChar; +#else +typedef unsigned short XML_Char; +typedef char XML_LChar; +#endif /* XML_UNICODE_WCHAR_T */ +#else /* Information is UTF-8 encoded. */ +typedef char XML_Char; +typedef char XML_LChar; +#endif /* XML_UNICODE */ + +#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */ +#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400 +typedef __int64 XML_Index; +typedef unsigned __int64 XML_Size; +#else +typedef long long XML_Index; +typedef unsigned long long XML_Size; +#endif +#else +typedef long XML_Index; +typedef unsigned long XML_Size; +#endif /* XML_LARGE_SIZE */ + +#ifdef __cplusplus +} +#endif + +#endif /* not Expat_External_INCLUDED */ diff --git a/project/jni/expat/lib/iasciitab.h b/project/jni/expat/lib/iasciitab.h new file mode 100644 index 000000000..24a1d5ccc --- /dev/null +++ b/project/jni/expat/lib/iasciitab.h @@ -0,0 +1,37 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* Like asciitab.h, except that 0xD has code BT_S rather than BT_CR */ +/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, +/* 0x0C */ BT_NONXML, BT_S, BT_NONXML, BT_NONXML, +/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, +/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, +/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, +/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, +/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, +/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, +/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, +/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, +/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, diff --git a/project/jni/expat/lib/internal.h b/project/jni/expat/lib/internal.h new file mode 100644 index 000000000..dd5454831 --- /dev/null +++ b/project/jni/expat/lib/internal.h @@ -0,0 +1,73 @@ +/* internal.h + + Internal definitions used by Expat. This is not needed to compile + client code. + + The following calling convention macros are defined for frequently + called functions: + + FASTCALL - Used for those internal functions that have a simple + body and a low number of arguments and local variables. + + PTRCALL - Used for functions called though function pointers. + + PTRFASTCALL - Like PTRCALL, but for low number of arguments. + + inline - Used for selected internal functions for which inlining + may improve performance on some platforms. + + Note: Use of these macros is based on judgement, not hard rules, + and therefore subject to change. +*/ + +#if defined(__GNUC__) && defined(__i386__) && !defined(__MINGW32__) +/* We'll use this version by default only where we know it helps. + + regparm() generates warnings on Solaris boxes. See SF bug #692878. + + Instability reported with egcs on a RedHat Linux 7.3. + Let's comment out: + #define FASTCALL __attribute__((stdcall, regparm(3))) + and let's try this: +*/ +#define FASTCALL __attribute__((regparm(3))) +#define PTRFASTCALL __attribute__((regparm(3))) +#endif + +/* Using __fastcall seems to have an unexpected negative effect under + MS VC++, especially for function pointers, so we won't use it for + now on that platform. It may be reconsidered for a future release + if it can be made more effective. + Likely reason: __fastcall on Windows is like stdcall, therefore + the compiler cannot perform stack optimizations for call clusters. +*/ + +/* Make sure all of these are defined if they aren't already. */ + +#ifndef FASTCALL +#define FASTCALL +#endif + +#ifndef PTRCALL +#define PTRCALL +#endif + +#ifndef PTRFASTCALL +#define PTRFASTCALL +#endif + +#ifndef XML_MIN_SIZE +#if !defined(__cplusplus) && !defined(inline) +#ifdef __GNUC__ +#define inline __inline +#endif /* __GNUC__ */ +#endif +#endif /* XML_MIN_SIZE */ + +#ifdef __cplusplus +#define inline inline +#else +#ifndef inline +#define inline +#endif +#endif diff --git a/project/jni/expat/lib/latin1tab.h b/project/jni/expat/lib/latin1tab.h new file mode 100644 index 000000000..53c25d76b --- /dev/null +++ b/project/jni/expat/lib/latin1tab.h @@ -0,0 +1,36 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* 0x80 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x84 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x88 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x8C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x90 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x94 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x98 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x9C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xA0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xA4 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xA8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, +/* 0xAC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xB0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xB4 */ BT_OTHER, BT_NMSTRT, BT_OTHER, BT_NAME, +/* 0xB8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, +/* 0xBC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xC0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xC4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xC8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xCC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xD0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xD4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0xD8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xDC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xE0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xE4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xE8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xEC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xF0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xF4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0xF8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xFC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, diff --git a/project/jni/expat/lib/nametab.h b/project/jni/expat/lib/nametab.h new file mode 100644 index 000000000..b05e62c77 --- /dev/null +++ b/project/jni/expat/lib/nametab.h @@ -0,0 +1,150 @@ +static const unsigned namingBitmap[] = { +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0x00000000, 0x04000000, 0x87FFFFFE, 0x07FFFFFE, +0x00000000, 0x00000000, 0xFF7FFFFF, 0xFF7FFFFF, +0xFFFFFFFF, 0x7FF3FFFF, 0xFFFFFDFE, 0x7FFFFFFF, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE00F, 0xFC31FFFF, +0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, +0xFFFFFFFF, 0xF80001FF, 0x00000003, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFD740, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, +0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, +0xFFFF0003, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, +0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, +0x0000007F, 0x00000000, 0xFFFF0000, 0x000707FF, +0x00000000, 0x07FFFFFE, 0x000007FE, 0xFFFE0000, +0xFFFFFFFF, 0x7CFFFFFF, 0x002F7FFF, 0x00000060, +0xFFFFFFE0, 0x23FFFFFF, 0xFF000000, 0x00000003, +0xFFF99FE0, 0x03C5FDFF, 0xB0000000, 0x00030003, +0xFFF987E0, 0x036DFDFF, 0x5E000000, 0x001C0000, +0xFFFBAFE0, 0x23EDFDFF, 0x00000000, 0x00000001, +0xFFF99FE0, 0x23CDFDFF, 0xB0000000, 0x00000003, +0xD63DC7E0, 0x03BFC718, 0x00000000, 0x00000000, +0xFFFDDFE0, 0x03EFFDFF, 0x00000000, 0x00000003, +0xFFFDDFE0, 0x03EFFDFF, 0x40000000, 0x00000003, +0xFFFDDFE0, 0x03FFFDFF, 0x00000000, 0x00000003, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFE, 0x000D7FFF, 0x0000003F, 0x00000000, +0xFEF02596, 0x200D6CAE, 0x0000001F, 0x00000000, +0x00000000, 0x00000000, 0xFFFFFEFF, 0x000003FF, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x007FFFFF, +0x0007DAED, 0x50000000, 0x82315001, 0x002C62AB, +0x40000000, 0xF580C900, 0x00000007, 0x02010800, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0x0FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x03FFFFFF, +0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF, +0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF, +0x00000000, 0x00004C40, 0x00000000, 0x00000000, +0x00000007, 0x00000000, 0x00000000, 0x00000000, +0x00000080, 0x000003FE, 0xFFFFFFFE, 0xFFFFFFFF, +0x001FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x07FFFFFF, +0xFFFFFFE0, 0x00001FFF, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0xFFFFFFFF, 0x0000000F, 0x00000000, 0x00000000, +0x00000000, 0x07FF6000, 0x87FFFFFE, 0x07FFFFFE, +0x00000000, 0x00800000, 0xFF7FFFFF, 0xFF7FFFFF, +0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, +0xFFFFFFFF, 0xF80001FF, 0x00030003, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0x0000003F, 0x00000003, +0xFFFFD7C0, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, +0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, +0xFFFF007B, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, +0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, +0xFFFE007F, 0xBBFFFFFB, 0xFFFF0016, 0x000707FF, +0x00000000, 0x07FFFFFE, 0x0007FFFF, 0xFFFF03FF, +0xFFFFFFFF, 0x7CFFFFFF, 0xFFEF7FFF, 0x03FF3DFF, +0xFFFFFFEE, 0xF3FFFFFF, 0xFF1E3FFF, 0x0000FFCF, +0xFFF99FEE, 0xD3C5FDFF, 0xB080399F, 0x0003FFCF, +0xFFF987E4, 0xD36DFDFF, 0x5E003987, 0x001FFFC0, +0xFFFBAFEE, 0xF3EDFDFF, 0x00003BBF, 0x0000FFC1, +0xFFF99FEE, 0xF3CDFDFF, 0xB0C0398F, 0x0000FFC3, +0xD63DC7EC, 0xC3BFC718, 0x00803DC7, 0x0000FF80, +0xFFFDDFEE, 0xC3EFFDFF, 0x00603DDF, 0x0000FFC3, +0xFFFDDFEC, 0xC3EFFDFF, 0x40603DDF, 0x0000FFC3, +0xFFFDDFEC, 0xC3FFFDFF, 0x00803DCF, 0x0000FFC3, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFE, 0x07FF7FFF, 0x03FF7FFF, 0x00000000, +0xFEF02596, 0x3BFF6CAE, 0x03FF3F5F, 0x00000000, +0x03000000, 0xC2A003FF, 0xFFFFFEFF, 0xFFFE03FF, +0xFEBF0FDF, 0x02FE3FFF, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x1FFF0000, 0x00000002, +0x000000A0, 0x003EFFFE, 0xFFFFFFFE, 0xFFFFFFFF, +0x661FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x77FFFFFF, +}; +static const unsigned char nmstrtPages[] = { +0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, +0x00, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, +0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, +0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x15, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static const unsigned char namePages[] = { +0x19, 0x03, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x00, +0x00, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, +0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, +0x26, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x27, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; diff --git a/project/jni/expat/lib/utf8tab.h b/project/jni/expat/lib/utf8tab.h new file mode 100644 index 000000000..7bb3e7760 --- /dev/null +++ b/project/jni/expat/lib/utf8tab.h @@ -0,0 +1,37 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + + +/* 0x80 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x88 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x8C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x90 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x94 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x98 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x9C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xA0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xA4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xA8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xAC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xB0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xB4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xB8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xBC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xC0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xC4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xC8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xCC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xD0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xD4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xD8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xDC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xE0 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xE4 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xE8 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xEC */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xF0 */ BT_LEAD4, BT_LEAD4, BT_LEAD4, BT_LEAD4, +/* 0xF4 */ BT_LEAD4, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0xF8 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0xFC */ BT_NONXML, BT_NONXML, BT_MALFORM, BT_MALFORM, diff --git a/project/jni/expat/lib/xmlparse.c b/project/jni/expat/lib/xmlparse.c new file mode 100644 index 000000000..f35aa36ba --- /dev/null +++ b/project/jni/expat/lib/xmlparse.c @@ -0,0 +1,6403 @@ +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#include +#include /* memset(), memcpy() */ +#include +#include /* UINT_MAX */ +#include /* time() */ + +#define XML_BUILDING_EXPAT 1 + +#ifdef COMPILED_FROM_DSP +#include "winconfig.h" +#elif defined(MACOS_CLASSIC) +#include "macconfig.h" +#elif defined(__amigaos__) +#include "amigaconfig.h" +#elif defined(__WATCOMC__) +#include "watcomconfig.h" +#elif defined(HAVE_EXPAT_CONFIG_H) +#include +#endif /* ndef COMPILED_FROM_DSP */ + +#include "ascii.h" +#include "expat.h" + +#ifdef XML_UNICODE +#define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX +#define XmlConvert XmlUtf16Convert +#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding +#define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS +#define XmlEncode XmlUtf16Encode +/* Using pointer subtraction to convert to integer type. */ +#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1)) +typedef unsigned short ICHAR; +#else +#define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX +#define XmlConvert XmlUtf8Convert +#define XmlGetInternalEncoding XmlGetUtf8InternalEncoding +#define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS +#define XmlEncode XmlUtf8Encode +#define MUST_CONVERT(enc, s) (!(enc)->isUtf8) +typedef char ICHAR; +#endif + + +#ifndef XML_NS + +#define XmlInitEncodingNS XmlInitEncoding +#define XmlInitUnknownEncodingNS XmlInitUnknownEncoding +#undef XmlGetInternalEncodingNS +#define XmlGetInternalEncodingNS XmlGetInternalEncoding +#define XmlParseXmlDeclNS XmlParseXmlDecl + +#endif + +#ifdef XML_UNICODE + +#ifdef XML_UNICODE_WCHAR_T +#define XML_T(x) (const wchar_t)x +#define XML_L(x) L ## x +#else +#define XML_T(x) (const unsigned short)x +#define XML_L(x) x +#endif + +#else + +#define XML_T(x) x +#define XML_L(x) x + +#endif + +/* Round up n to be a multiple of sz, where sz is a power of 2. */ +#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) + +/* Handle the case where memmove() doesn't exist. */ +#ifndef HAVE_MEMMOVE +#ifdef HAVE_BCOPY +#define memmove(d,s,l) bcopy((s),(d),(l)) +#else +#error memmove does not exist on this platform, nor is a substitute available +#endif /* HAVE_BCOPY */ +#endif /* HAVE_MEMMOVE */ + +#include "internal.h" +#include "xmltok.h" +#include "xmlrole.h" + +typedef const XML_Char *KEY; + +typedef struct { + KEY name; +} NAMED; + +typedef struct { + NAMED **v; + unsigned char power; + size_t size; + size_t used; + const XML_Memory_Handling_Suite *mem; +} HASH_TABLE; + +/* Basic character hash algorithm, taken from Python's string hash: + h = h * 1000003 ^ character, the constant being a prime number. + +*/ +#ifdef XML_UNICODE +#define CHAR_HASH(h, c) \ + (((h) * 0xF4243) ^ (unsigned short)(c)) +#else +#define CHAR_HASH(h, c) \ + (((h) * 0xF4243) ^ (unsigned char)(c)) +#endif + +/* For probing (after a collision) we need a step size relative prime + to the hash table size, which is a power of 2. We use double-hashing, + since we can calculate a second hash value cheaply by taking those bits + of the first hash value that were discarded (masked out) when the table + index was calculated: index = hash & mask, where mask = table->size - 1. + We limit the maximum step size to table->size / 4 (mask >> 2) and make + it odd, since odd numbers are always relative prime to a power of 2. +*/ +#define SECOND_HASH(hash, mask, power) \ + ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2)) +#define PROBE_STEP(hash, mask, power) \ + ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1)) + +typedef struct { + NAMED **p; + NAMED **end; +} HASH_TABLE_ITER; + +#define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ +#define INIT_DATA_BUF_SIZE 1024 +#define INIT_ATTS_SIZE 16 +#define INIT_ATTS_VERSION 0xFFFFFFFF +#define INIT_BLOCK_SIZE 1024 +#define INIT_BUFFER_SIZE 1024 + +#define EXPAND_SPARE 24 + +typedef struct binding { + struct prefix *prefix; + struct binding *nextTagBinding; + struct binding *prevPrefixBinding; + const struct attribute_id *attId; + XML_Char *uri; + int uriLen; + int uriAlloc; +} BINDING; + +typedef struct prefix { + const XML_Char *name; + BINDING *binding; +} PREFIX; + +typedef struct { + const XML_Char *str; + const XML_Char *localPart; + const XML_Char *prefix; + int strLen; + int uriLen; + int prefixLen; +} TAG_NAME; + +/* TAG represents an open element. + The name of the element is stored in both the document and API + encodings. The memory buffer 'buf' is a separately-allocated + memory area which stores the name. During the XML_Parse()/ + XMLParseBuffer() when the element is open, the memory for the 'raw' + version of the name (in the document encoding) is shared with the + document buffer. If the element is open across calls to + XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to + contain the 'raw' name as well. + + A parser re-uses these structures, maintaining a list of allocated + TAG objects in a free list. +*/ +typedef struct tag { + struct tag *parent; /* parent of this element */ + const char *rawName; /* tagName in the original encoding */ + int rawNameLength; + TAG_NAME name; /* tagName in the API encoding */ + char *buf; /* buffer for name components */ + char *bufEnd; /* end of the buffer */ + BINDING *bindings; +} TAG; + +typedef struct { + const XML_Char *name; + const XML_Char *textPtr; + int textLen; /* length in XML_Chars */ + int processed; /* # of processed bytes - when suspended */ + const XML_Char *systemId; + const XML_Char *base; + const XML_Char *publicId; + const XML_Char *notation; + XML_Bool open; + XML_Bool is_param; + XML_Bool is_internal; /* true if declared in internal subset outside PE */ +} ENTITY; + +typedef struct { + enum XML_Content_Type type; + enum XML_Content_Quant quant; + const XML_Char * name; + int firstchild; + int lastchild; + int childcnt; + int nextsib; +} CONTENT_SCAFFOLD; + +#define INIT_SCAFFOLD_ELEMENTS 32 + +typedef struct block { + struct block *next; + int size; + XML_Char s[1]; +} BLOCK; + +typedef struct { + BLOCK *blocks; + BLOCK *freeBlocks; + const XML_Char *end; + XML_Char *ptr; + XML_Char *start; + const XML_Memory_Handling_Suite *mem; +} STRING_POOL; + +/* The XML_Char before the name is used to determine whether + an attribute has been specified. */ +typedef struct attribute_id { + XML_Char *name; + PREFIX *prefix; + XML_Bool maybeTokenized; + XML_Bool xmlns; +} ATTRIBUTE_ID; + +typedef struct { + const ATTRIBUTE_ID *id; + XML_Bool isCdata; + const XML_Char *value; +} DEFAULT_ATTRIBUTE; + +typedef struct { + unsigned long version; + unsigned long hash; + const XML_Char *uriName; +} NS_ATT; + +typedef struct { + const XML_Char *name; + PREFIX *prefix; + const ATTRIBUTE_ID *idAtt; + int nDefaultAtts; + int allocDefaultAtts; + DEFAULT_ATTRIBUTE *defaultAtts; +} ELEMENT_TYPE; + +typedef struct { + HASH_TABLE generalEntities; + HASH_TABLE elementTypes; + HASH_TABLE attributeIds; + HASH_TABLE prefixes; + STRING_POOL pool; + STRING_POOL entityValuePool; + /* false once a parameter entity reference has been skipped */ + XML_Bool keepProcessing; + /* true once an internal or external PE reference has been encountered; + this includes the reference to an external subset */ + XML_Bool hasParamEntityRefs; + XML_Bool standalone; +#ifdef XML_DTD + /* indicates if external PE has been read */ + XML_Bool paramEntityRead; + HASH_TABLE paramEntities; +#endif /* XML_DTD */ + PREFIX defaultPrefix; + /* === scaffolding for building content model === */ + XML_Bool in_eldecl; + CONTENT_SCAFFOLD *scaffold; + unsigned contentStringLen; + unsigned scaffSize; + unsigned scaffCount; + int scaffLevel; + int *scaffIndex; +} DTD; + +typedef struct open_internal_entity { + const char *internalEventPtr; + const char *internalEventEndPtr; + struct open_internal_entity *next; + ENTITY *entity; + int startTagLevel; + XML_Bool betweenDecl; /* WFC: PE Between Declarations */ +} OPEN_INTERNAL_ENTITY; + +typedef enum XML_Error PTRCALL Processor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr); + +static Processor prologProcessor; +static Processor prologInitProcessor; +static Processor contentProcessor; +static Processor cdataSectionProcessor; +#ifdef XML_DTD +static Processor ignoreSectionProcessor; +static Processor externalParEntProcessor; +static Processor externalParEntInitProcessor; +static Processor entityValueProcessor; +static Processor entityValueInitProcessor; +#endif /* XML_DTD */ +static Processor epilogProcessor; +static Processor errorProcessor; +static Processor externalEntityInitProcessor; +static Processor externalEntityInitProcessor2; +static Processor externalEntityInitProcessor3; +static Processor externalEntityContentProcessor; +static Processor internalEntityProcessor; + +static enum XML_Error +handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName); +static enum XML_Error +processXmlDecl(XML_Parser parser, int isGeneralTextEntity, + const char *s, const char *next); +static enum XML_Error +initializeEncoding(XML_Parser parser); +static enum XML_Error +doProlog(XML_Parser parser, const ENCODING *enc, const char *s, + const char *end, int tok, const char *next, const char **nextPtr, + XML_Bool haveMore); +static enum XML_Error +processInternalEntity(XML_Parser parser, ENTITY *entity, + XML_Bool betweenDecl); +static enum XML_Error +doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, + const char *start, const char *end, const char **endPtr, + XML_Bool haveMore); +static enum XML_Error +doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, + const char *end, const char **nextPtr, XML_Bool haveMore); +#ifdef XML_DTD +static enum XML_Error +doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, + const char *end, const char **nextPtr, XML_Bool haveMore); +#endif /* XML_DTD */ + +static enum XML_Error +storeAtts(XML_Parser parser, const ENCODING *, const char *s, + TAG_NAME *tagNamePtr, BINDING **bindingsPtr); +static enum XML_Error +addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, + const XML_Char *uri, BINDING **bindingsPtr); +static int +defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, + XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser); +static enum XML_Error +storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, + const char *, const char *, STRING_POOL *); +static enum XML_Error +appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, + const char *, const char *, STRING_POOL *); +static ATTRIBUTE_ID * +getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); +static int +setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); +static enum XML_Error +storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); +static int +reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end); +static int +reportComment(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); +static void +reportDefault(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); + +static const XML_Char * getContext(XML_Parser parser); +static XML_Bool +setContext(XML_Parser parser, const XML_Char *context); + +static void FASTCALL normalizePublicId(XML_Char *s); + +static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms); +/* do not call if parentParser != NULL */ +static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms); +static void +dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); +static int +dtdCopy(XML_Parser oldParser, + DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); +static int +copyEntityTable(XML_Parser oldParser, + HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); +static NAMED * +lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize); +static void FASTCALL +hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); +static void FASTCALL hashTableClear(HASH_TABLE *); +static void FASTCALL hashTableDestroy(HASH_TABLE *); +static void FASTCALL +hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); +static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *); + +static void FASTCALL +poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms); +static void FASTCALL poolClear(STRING_POOL *); +static void FASTCALL poolDestroy(STRING_POOL *); +static XML_Char * +poolAppend(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end); +static XML_Char * +poolStoreString(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end); +static XML_Bool FASTCALL poolGrow(STRING_POOL *pool); +static const XML_Char * FASTCALL +poolCopyString(STRING_POOL *pool, const XML_Char *s); +static const XML_Char * +poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); +static const XML_Char * FASTCALL +poolAppendString(STRING_POOL *pool, const XML_Char *s); + +static int FASTCALL nextScaffoldPart(XML_Parser parser); +static XML_Content * build_model(XML_Parser parser); +static ELEMENT_TYPE * +getElementType(XML_Parser parser, const ENCODING *enc, + const char *ptr, const char *end); + +static unsigned long generate_hash_secret_salt(void); +static XML_Bool startParsing(XML_Parser parser); + +static XML_Parser +parserCreate(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep, + DTD *dtd); + +static void +parserInit(XML_Parser parser, const XML_Char *encodingName); + +#define poolStart(pool) ((pool)->start) +#define poolEnd(pool) ((pool)->ptr) +#define poolLength(pool) ((pool)->ptr - (pool)->start) +#define poolChop(pool) ((void)--(pool->ptr)) +#define poolLastChar(pool) (((pool)->ptr)[-1]) +#define poolDiscard(pool) ((pool)->ptr = (pool)->start) +#define poolFinish(pool) ((pool)->start = (pool)->ptr) +#define poolAppendChar(pool, c) \ + (((pool)->ptr == (pool)->end && !poolGrow(pool)) \ + ? 0 \ + : ((*((pool)->ptr)++ = c), 1)) + +struct XML_ParserStruct { + /* The first member must be userData so that the XML_GetUserData + macro works. */ + void *m_userData; + void *m_handlerArg; + char *m_buffer; + const XML_Memory_Handling_Suite m_mem; + /* first character to be parsed */ + const char *m_bufferPtr; + /* past last character to be parsed */ + char *m_bufferEnd; + /* allocated end of buffer */ + const char *m_bufferLim; + XML_Index m_parseEndByteIndex; + const char *m_parseEndPtr; + XML_Char *m_dataBuf; + XML_Char *m_dataBufEnd; + XML_StartElementHandler m_startElementHandler; + XML_EndElementHandler m_endElementHandler; + XML_CharacterDataHandler m_characterDataHandler; + XML_ProcessingInstructionHandler m_processingInstructionHandler; + XML_CommentHandler m_commentHandler; + XML_StartCdataSectionHandler m_startCdataSectionHandler; + XML_EndCdataSectionHandler m_endCdataSectionHandler; + XML_DefaultHandler m_defaultHandler; + XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler; + XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler; + XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler; + XML_NotationDeclHandler m_notationDeclHandler; + XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler; + XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler; + XML_NotStandaloneHandler m_notStandaloneHandler; + XML_ExternalEntityRefHandler m_externalEntityRefHandler; + XML_Parser m_externalEntityRefHandlerArg; + XML_SkippedEntityHandler m_skippedEntityHandler; + XML_UnknownEncodingHandler m_unknownEncodingHandler; + XML_ElementDeclHandler m_elementDeclHandler; + XML_AttlistDeclHandler m_attlistDeclHandler; + XML_EntityDeclHandler m_entityDeclHandler; + XML_XmlDeclHandler m_xmlDeclHandler; + const ENCODING *m_encoding; + INIT_ENCODING m_initEncoding; + const ENCODING *m_internalEncoding; + const XML_Char *m_protocolEncodingName; + XML_Bool m_ns; + XML_Bool m_ns_triplets; + void *m_unknownEncodingMem; + void *m_unknownEncodingData; + void *m_unknownEncodingHandlerData; + void (XMLCALL *m_unknownEncodingRelease)(void *); + PROLOG_STATE m_prologState; + Processor *m_processor; + enum XML_Error m_errorCode; + const char *m_eventPtr; + const char *m_eventEndPtr; + const char *m_positionPtr; + OPEN_INTERNAL_ENTITY *m_openInternalEntities; + OPEN_INTERNAL_ENTITY *m_freeInternalEntities; + XML_Bool m_defaultExpandInternalEntities; + int m_tagLevel; + ENTITY *m_declEntity; + const XML_Char *m_doctypeName; + const XML_Char *m_doctypeSysid; + const XML_Char *m_doctypePubid; + const XML_Char *m_declAttributeType; + const XML_Char *m_declNotationName; + const XML_Char *m_declNotationPublicId; + ELEMENT_TYPE *m_declElementType; + ATTRIBUTE_ID *m_declAttributeId; + XML_Bool m_declAttributeIsCdata; + XML_Bool m_declAttributeIsId; + DTD *m_dtd; + const XML_Char *m_curBase; + TAG *m_tagStack; + TAG *m_freeTagList; + BINDING *m_inheritedBindings; + BINDING *m_freeBindingList; + int m_attsSize; + int m_nSpecifiedAtts; + int m_idAttIndex; + ATTRIBUTE *m_atts; + NS_ATT *m_nsAtts; + unsigned long m_nsAttsVersion; + unsigned char m_nsAttsPower; +#ifdef XML_ATTR_INFO + XML_AttrInfo *m_attInfo; +#endif + POSITION m_position; + STRING_POOL m_tempPool; + STRING_POOL m_temp2Pool; + char *m_groupConnector; + unsigned int m_groupSize; + XML_Char m_namespaceSeparator; + XML_Parser m_parentParser; + XML_ParsingStatus m_parsingStatus; +#ifdef XML_DTD + XML_Bool m_isParamEntity; + XML_Bool m_useForeignDTD; + enum XML_ParamEntityParsing m_paramEntityParsing; +#endif + unsigned long m_hash_secret_salt; +}; + +#define MALLOC(s) (parser->m_mem.malloc_fcn((s))) +#define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s))) +#define FREE(p) (parser->m_mem.free_fcn((p))) + +#define userData (parser->m_userData) +#define handlerArg (parser->m_handlerArg) +#define startElementHandler (parser->m_startElementHandler) +#define endElementHandler (parser->m_endElementHandler) +#define characterDataHandler (parser->m_characterDataHandler) +#define processingInstructionHandler \ + (parser->m_processingInstructionHandler) +#define commentHandler (parser->m_commentHandler) +#define startCdataSectionHandler \ + (parser->m_startCdataSectionHandler) +#define endCdataSectionHandler (parser->m_endCdataSectionHandler) +#define defaultHandler (parser->m_defaultHandler) +#define startDoctypeDeclHandler (parser->m_startDoctypeDeclHandler) +#define endDoctypeDeclHandler (parser->m_endDoctypeDeclHandler) +#define unparsedEntityDeclHandler \ + (parser->m_unparsedEntityDeclHandler) +#define notationDeclHandler (parser->m_notationDeclHandler) +#define startNamespaceDeclHandler \ + (parser->m_startNamespaceDeclHandler) +#define endNamespaceDeclHandler (parser->m_endNamespaceDeclHandler) +#define notStandaloneHandler (parser->m_notStandaloneHandler) +#define externalEntityRefHandler \ + (parser->m_externalEntityRefHandler) +#define externalEntityRefHandlerArg \ + (parser->m_externalEntityRefHandlerArg) +#define internalEntityRefHandler \ + (parser->m_internalEntityRefHandler) +#define skippedEntityHandler (parser->m_skippedEntityHandler) +#define unknownEncodingHandler (parser->m_unknownEncodingHandler) +#define elementDeclHandler (parser->m_elementDeclHandler) +#define attlistDeclHandler (parser->m_attlistDeclHandler) +#define entityDeclHandler (parser->m_entityDeclHandler) +#define xmlDeclHandler (parser->m_xmlDeclHandler) +#define encoding (parser->m_encoding) +#define initEncoding (parser->m_initEncoding) +#define internalEncoding (parser->m_internalEncoding) +#define unknownEncodingMem (parser->m_unknownEncodingMem) +#define unknownEncodingData (parser->m_unknownEncodingData) +#define unknownEncodingHandlerData \ + (parser->m_unknownEncodingHandlerData) +#define unknownEncodingRelease (parser->m_unknownEncodingRelease) +#define protocolEncodingName (parser->m_protocolEncodingName) +#define ns (parser->m_ns) +#define ns_triplets (parser->m_ns_triplets) +#define prologState (parser->m_prologState) +#define processor (parser->m_processor) +#define errorCode (parser->m_errorCode) +#define eventPtr (parser->m_eventPtr) +#define eventEndPtr (parser->m_eventEndPtr) +#define positionPtr (parser->m_positionPtr) +#define position (parser->m_position) +#define openInternalEntities (parser->m_openInternalEntities) +#define freeInternalEntities (parser->m_freeInternalEntities) +#define defaultExpandInternalEntities \ + (parser->m_defaultExpandInternalEntities) +#define tagLevel (parser->m_tagLevel) +#define buffer (parser->m_buffer) +#define bufferPtr (parser->m_bufferPtr) +#define bufferEnd (parser->m_bufferEnd) +#define parseEndByteIndex (parser->m_parseEndByteIndex) +#define parseEndPtr (parser->m_parseEndPtr) +#define bufferLim (parser->m_bufferLim) +#define dataBuf (parser->m_dataBuf) +#define dataBufEnd (parser->m_dataBufEnd) +#define _dtd (parser->m_dtd) +#define curBase (parser->m_curBase) +#define declEntity (parser->m_declEntity) +#define doctypeName (parser->m_doctypeName) +#define doctypeSysid (parser->m_doctypeSysid) +#define doctypePubid (parser->m_doctypePubid) +#define declAttributeType (parser->m_declAttributeType) +#define declNotationName (parser->m_declNotationName) +#define declNotationPublicId (parser->m_declNotationPublicId) +#define declElementType (parser->m_declElementType) +#define declAttributeId (parser->m_declAttributeId) +#define declAttributeIsCdata (parser->m_declAttributeIsCdata) +#define declAttributeIsId (parser->m_declAttributeIsId) +#define freeTagList (parser->m_freeTagList) +#define freeBindingList (parser->m_freeBindingList) +#define inheritedBindings (parser->m_inheritedBindings) +#define tagStack (parser->m_tagStack) +#define atts (parser->m_atts) +#define attsSize (parser->m_attsSize) +#define nSpecifiedAtts (parser->m_nSpecifiedAtts) +#define idAttIndex (parser->m_idAttIndex) +#define nsAtts (parser->m_nsAtts) +#define nsAttsVersion (parser->m_nsAttsVersion) +#define nsAttsPower (parser->m_nsAttsPower) +#define attInfo (parser->m_attInfo) +#define tempPool (parser->m_tempPool) +#define temp2Pool (parser->m_temp2Pool) +#define groupConnector (parser->m_groupConnector) +#define groupSize (parser->m_groupSize) +#define namespaceSeparator (parser->m_namespaceSeparator) +#define parentParser (parser->m_parentParser) +#define ps_parsing (parser->m_parsingStatus.parsing) +#define ps_finalBuffer (parser->m_parsingStatus.finalBuffer) +#ifdef XML_DTD +#define isParamEntity (parser->m_isParamEntity) +#define useForeignDTD (parser->m_useForeignDTD) +#define paramEntityParsing (parser->m_paramEntityParsing) +#endif /* XML_DTD */ +#define hash_secret_salt (parser->m_hash_secret_salt) + +XML_Parser XMLCALL +XML_ParserCreate(const XML_Char *encodingName) +{ + return XML_ParserCreate_MM(encodingName, NULL, NULL); +} + +XML_Parser XMLCALL +XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) +{ + XML_Char tmp[2]; + *tmp = nsSep; + return XML_ParserCreate_MM(encodingName, NULL, tmp); +} + +static const XML_Char implicitContext[] = { + ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, + ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, + ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g, + ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9, + ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e, + ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' +}; + +static unsigned long +generate_hash_secret_salt(void) +{ + unsigned int seed = time(NULL) % UINT_MAX; + srand(seed); + return rand(); +} + +static XML_Bool /* only valid for root parser */ +startParsing(XML_Parser parser) +{ + /* hash functions must be initialized before setContext() is called */ + if (hash_secret_salt == 0) + hash_secret_salt = generate_hash_secret_salt(); + if (ns) { + /* implicit context only set for root parser, since child + parsers (i.e. external entity parsers) will inherit it + */ + return setContext(parser, implicitContext); + } + return XML_TRUE; +} + +XML_Parser XMLCALL +XML_ParserCreate_MM(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep) +{ + return parserCreate(encodingName, memsuite, nameSep, NULL); +} + +static XML_Parser +parserCreate(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep, + DTD *dtd) +{ + XML_Parser parser; + + if (memsuite) { + XML_Memory_Handling_Suite *mtemp; + parser = (XML_Parser) + memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); + if (parser != NULL) { + mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); + mtemp->malloc_fcn = memsuite->malloc_fcn; + mtemp->realloc_fcn = memsuite->realloc_fcn; + mtemp->free_fcn = memsuite->free_fcn; + } + } + else { + XML_Memory_Handling_Suite *mtemp; + parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct)); + if (parser != NULL) { + mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); + mtemp->malloc_fcn = malloc; + mtemp->realloc_fcn = realloc; + mtemp->free_fcn = free; + } + } + + if (!parser) + return parser; + + buffer = NULL; + bufferLim = NULL; + + attsSize = INIT_ATTS_SIZE; + atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE)); + if (atts == NULL) { + FREE(parser); + return NULL; + } +#ifdef XML_ATTR_INFO + attInfo = (XML_AttrInfo*)MALLOC(attsSize * sizeof(XML_AttrInfo)); + if (attInfo == NULL) { + FREE(atts); + FREE(parser); + return NULL; + } +#endif + dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char)); + if (dataBuf == NULL) { + FREE(atts); +#ifdef XML_ATTR_INFO + FREE(attInfo); +#endif + FREE(parser); + return NULL; + } + dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE; + + if (dtd) + _dtd = dtd; + else { + _dtd = dtdCreate(&parser->m_mem); + if (_dtd == NULL) { + FREE(dataBuf); + FREE(atts); +#ifdef XML_ATTR_INFO + FREE(attInfo); +#endif + FREE(parser); + return NULL; + } + } + + freeBindingList = NULL; + freeTagList = NULL; + freeInternalEntities = NULL; + + groupSize = 0; + groupConnector = NULL; + + unknownEncodingHandler = NULL; + unknownEncodingHandlerData = NULL; + + namespaceSeparator = ASCII_EXCL; + ns = XML_FALSE; + ns_triplets = XML_FALSE; + + nsAtts = NULL; + nsAttsVersion = 0; + nsAttsPower = 0; + + poolInit(&tempPool, &(parser->m_mem)); + poolInit(&temp2Pool, &(parser->m_mem)); + parserInit(parser, encodingName); + + if (encodingName && !protocolEncodingName) { + XML_ParserFree(parser); + return NULL; + } + + if (nameSep) { + ns = XML_TRUE; + internalEncoding = XmlGetInternalEncodingNS(); + namespaceSeparator = *nameSep; + } + else { + internalEncoding = XmlGetInternalEncoding(); + } + + return parser; +} + +static void +parserInit(XML_Parser parser, const XML_Char *encodingName) +{ + processor = prologInitProcessor; + XmlPrologStateInit(&prologState); + protocolEncodingName = (encodingName != NULL + ? poolCopyString(&tempPool, encodingName) + : NULL); + curBase = NULL; + XmlInitEncoding(&initEncoding, &encoding, 0); + userData = NULL; + handlerArg = NULL; + startElementHandler = NULL; + endElementHandler = NULL; + characterDataHandler = NULL; + processingInstructionHandler = NULL; + commentHandler = NULL; + startCdataSectionHandler = NULL; + endCdataSectionHandler = NULL; + defaultHandler = NULL; + startDoctypeDeclHandler = NULL; + endDoctypeDeclHandler = NULL; + unparsedEntityDeclHandler = NULL; + notationDeclHandler = NULL; + startNamespaceDeclHandler = NULL; + endNamespaceDeclHandler = NULL; + notStandaloneHandler = NULL; + externalEntityRefHandler = NULL; + externalEntityRefHandlerArg = parser; + skippedEntityHandler = NULL; + elementDeclHandler = NULL; + attlistDeclHandler = NULL; + entityDeclHandler = NULL; + xmlDeclHandler = NULL; + bufferPtr = buffer; + bufferEnd = buffer; + parseEndByteIndex = 0; + parseEndPtr = NULL; + declElementType = NULL; + declAttributeId = NULL; + declEntity = NULL; + doctypeName = NULL; + doctypeSysid = NULL; + doctypePubid = NULL; + declAttributeType = NULL; + declNotationName = NULL; + declNotationPublicId = NULL; + declAttributeIsCdata = XML_FALSE; + declAttributeIsId = XML_FALSE; + memset(&position, 0, sizeof(POSITION)); + errorCode = XML_ERROR_NONE; + eventPtr = NULL; + eventEndPtr = NULL; + positionPtr = NULL; + openInternalEntities = NULL; + defaultExpandInternalEntities = XML_TRUE; + tagLevel = 0; + tagStack = NULL; + inheritedBindings = NULL; + nSpecifiedAtts = 0; + unknownEncodingMem = NULL; + unknownEncodingRelease = NULL; + unknownEncodingData = NULL; + parentParser = NULL; + ps_parsing = XML_INITIALIZED; +#ifdef XML_DTD + isParamEntity = XML_FALSE; + useForeignDTD = XML_FALSE; + paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; +#endif + hash_secret_salt = 0; +} + +/* moves list of bindings to freeBindingList */ +static void FASTCALL +moveToFreeBindingList(XML_Parser parser, BINDING *bindings) +{ + while (bindings) { + BINDING *b = bindings; + bindings = bindings->nextTagBinding; + b->nextTagBinding = freeBindingList; + freeBindingList = b; + } +} + +XML_Bool XMLCALL +XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) +{ + TAG *tStk; + OPEN_INTERNAL_ENTITY *openEntityList; + if (parentParser) + return XML_FALSE; + /* move tagStack to freeTagList */ + tStk = tagStack; + while (tStk) { + TAG *tag = tStk; + tStk = tStk->parent; + tag->parent = freeTagList; + moveToFreeBindingList(parser, tag->bindings); + tag->bindings = NULL; + freeTagList = tag; + } + /* move openInternalEntities to freeInternalEntities */ + openEntityList = openInternalEntities; + while (openEntityList) { + OPEN_INTERNAL_ENTITY *openEntity = openEntityList; + openEntityList = openEntity->next; + openEntity->next = freeInternalEntities; + freeInternalEntities = openEntity; + } + moveToFreeBindingList(parser, inheritedBindings); + FREE(unknownEncodingMem); + if (unknownEncodingRelease) + unknownEncodingRelease(unknownEncodingData); + poolClear(&tempPool); + poolClear(&temp2Pool); + parserInit(parser, encodingName); + dtdReset(_dtd, &parser->m_mem); + return XML_TRUE; +} + +enum XML_Status XMLCALL +XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) +{ + /* Block after XML_Parse()/XML_ParseBuffer() has been called. + XXX There's no way for the caller to determine which of the + XXX possible error cases caused the XML_STATUS_ERROR return. + */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return XML_STATUS_ERROR; + if (encodingName == NULL) + protocolEncodingName = NULL; + else { + protocolEncodingName = poolCopyString(&tempPool, encodingName); + if (!protocolEncodingName) + return XML_STATUS_ERROR; + } + return XML_STATUS_OK; +} + +XML_Parser XMLCALL +XML_ExternalEntityParserCreate(XML_Parser oldParser, + const XML_Char *context, + const XML_Char *encodingName) +{ + XML_Parser parser = oldParser; + DTD *newDtd = NULL; + DTD *oldDtd = _dtd; + XML_StartElementHandler oldStartElementHandler = startElementHandler; + XML_EndElementHandler oldEndElementHandler = endElementHandler; + XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler; + XML_ProcessingInstructionHandler oldProcessingInstructionHandler + = processingInstructionHandler; + XML_CommentHandler oldCommentHandler = commentHandler; + XML_StartCdataSectionHandler oldStartCdataSectionHandler + = startCdataSectionHandler; + XML_EndCdataSectionHandler oldEndCdataSectionHandler + = endCdataSectionHandler; + XML_DefaultHandler oldDefaultHandler = defaultHandler; + XML_UnparsedEntityDeclHandler oldUnparsedEntityDeclHandler + = unparsedEntityDeclHandler; + XML_NotationDeclHandler oldNotationDeclHandler = notationDeclHandler; + XML_StartNamespaceDeclHandler oldStartNamespaceDeclHandler + = startNamespaceDeclHandler; + XML_EndNamespaceDeclHandler oldEndNamespaceDeclHandler + = endNamespaceDeclHandler; + XML_NotStandaloneHandler oldNotStandaloneHandler = notStandaloneHandler; + XML_ExternalEntityRefHandler oldExternalEntityRefHandler + = externalEntityRefHandler; + XML_SkippedEntityHandler oldSkippedEntityHandler = skippedEntityHandler; + XML_UnknownEncodingHandler oldUnknownEncodingHandler + = unknownEncodingHandler; + XML_ElementDeclHandler oldElementDeclHandler = elementDeclHandler; + XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler; + XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler; + XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler; + ELEMENT_TYPE * oldDeclElementType = declElementType; + + void *oldUserData = userData; + void *oldHandlerArg = handlerArg; + XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities; + XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg; +#ifdef XML_DTD + enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing; + int oldInEntityValue = prologState.inEntityValue; +#endif + XML_Bool oldns_triplets = ns_triplets; + /* Note that the new parser shares the same hash secret as the old + parser, so that dtdCopy and copyEntityTable can lookup values + from hash tables associated with either parser without us having + to worry which hash secrets each table has. + */ + unsigned long oldhash_secret_salt = hash_secret_salt; + +#ifdef XML_DTD + if (!context) + newDtd = oldDtd; +#endif /* XML_DTD */ + + /* Note that the magical uses of the pre-processor to make field + access look more like C++ require that `parser' be overwritten + here. This makes this function more painful to follow than it + would be otherwise. + */ + if (ns) { + XML_Char tmp[2]; + *tmp = namespaceSeparator; + parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd); + } + else { + parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd); + } + + if (!parser) + return NULL; + + startElementHandler = oldStartElementHandler; + endElementHandler = oldEndElementHandler; + characterDataHandler = oldCharacterDataHandler; + processingInstructionHandler = oldProcessingInstructionHandler; + commentHandler = oldCommentHandler; + startCdataSectionHandler = oldStartCdataSectionHandler; + endCdataSectionHandler = oldEndCdataSectionHandler; + defaultHandler = oldDefaultHandler; + unparsedEntityDeclHandler = oldUnparsedEntityDeclHandler; + notationDeclHandler = oldNotationDeclHandler; + startNamespaceDeclHandler = oldStartNamespaceDeclHandler; + endNamespaceDeclHandler = oldEndNamespaceDeclHandler; + notStandaloneHandler = oldNotStandaloneHandler; + externalEntityRefHandler = oldExternalEntityRefHandler; + skippedEntityHandler = oldSkippedEntityHandler; + unknownEncodingHandler = oldUnknownEncodingHandler; + elementDeclHandler = oldElementDeclHandler; + attlistDeclHandler = oldAttlistDeclHandler; + entityDeclHandler = oldEntityDeclHandler; + xmlDeclHandler = oldXmlDeclHandler; + declElementType = oldDeclElementType; + userData = oldUserData; + if (oldUserData == oldHandlerArg) + handlerArg = userData; + else + handlerArg = parser; + if (oldExternalEntityRefHandlerArg != oldParser) + externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg; + defaultExpandInternalEntities = oldDefaultExpandInternalEntities; + ns_triplets = oldns_triplets; + hash_secret_salt = oldhash_secret_salt; + parentParser = oldParser; +#ifdef XML_DTD + paramEntityParsing = oldParamEntityParsing; + prologState.inEntityValue = oldInEntityValue; + if (context) { +#endif /* XML_DTD */ + if (!dtdCopy(oldParser, _dtd, oldDtd, &parser->m_mem) + || !setContext(parser, context)) { + XML_ParserFree(parser); + return NULL; + } + processor = externalEntityInitProcessor; +#ifdef XML_DTD + } + else { + /* The DTD instance referenced by _dtd is shared between the document's + root parser and external PE parsers, therefore one does not need to + call setContext. In addition, one also *must* not call setContext, + because this would overwrite existing prefix->binding pointers in + _dtd with ones that get destroyed with the external PE parser. + This would leave those prefixes with dangling pointers. + */ + isParamEntity = XML_TRUE; + XmlPrologStateInitExternalEntity(&prologState); + processor = externalParEntInitProcessor; + } +#endif /* XML_DTD */ + return parser; +} + +static void FASTCALL +destroyBindings(BINDING *bindings, XML_Parser parser) +{ + for (;;) { + BINDING *b = bindings; + if (!b) + break; + bindings = b->nextTagBinding; + FREE(b->uri); + FREE(b); + } +} + +void XMLCALL +XML_ParserFree(XML_Parser parser) +{ + TAG *tagList; + OPEN_INTERNAL_ENTITY *entityList; + if (parser == NULL) + return; + /* free tagStack and freeTagList */ + tagList = tagStack; + for (;;) { + TAG *p; + if (tagList == NULL) { + if (freeTagList == NULL) + break; + tagList = freeTagList; + freeTagList = NULL; + } + p = tagList; + tagList = tagList->parent; + FREE(p->buf); + destroyBindings(p->bindings, parser); + FREE(p); + } + /* free openInternalEntities and freeInternalEntities */ + entityList = openInternalEntities; + for (;;) { + OPEN_INTERNAL_ENTITY *openEntity; + if (entityList == NULL) { + if (freeInternalEntities == NULL) + break; + entityList = freeInternalEntities; + freeInternalEntities = NULL; + } + openEntity = entityList; + entityList = entityList->next; + FREE(openEntity); + } + + destroyBindings(freeBindingList, parser); + destroyBindings(inheritedBindings, parser); + poolDestroy(&tempPool); + poolDestroy(&temp2Pool); +#ifdef XML_DTD + /* external parameter entity parsers share the DTD structure + parser->m_dtd with the root parser, so we must not destroy it + */ + if (!isParamEntity && _dtd) +#else + if (_dtd) +#endif /* XML_DTD */ + dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem); + FREE((void *)atts); +#ifdef XML_ATTR_INFO + FREE((void *)attInfo); +#endif + FREE(groupConnector); + FREE(buffer); + FREE(dataBuf); + FREE(nsAtts); + FREE(unknownEncodingMem); + if (unknownEncodingRelease) + unknownEncodingRelease(unknownEncodingData); + FREE(parser); +} + +void XMLCALL +XML_UseParserAsHandlerArg(XML_Parser parser) +{ + handlerArg = parser; +} + +enum XML_Error XMLCALL +XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) +{ +#ifdef XML_DTD + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING; + useForeignDTD = useDTD; + return XML_ERROR_NONE; +#else + return XML_ERROR_FEATURE_REQUIRES_XML_DTD; +#endif +} + +void XMLCALL +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) +{ + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return; + ns_triplets = do_nst ? XML_TRUE : XML_FALSE; +} + +void XMLCALL +XML_SetUserData(XML_Parser parser, void *p) +{ + if (handlerArg == userData) + handlerArg = userData = p; + else + userData = p; +} + +enum XML_Status XMLCALL +XML_SetBase(XML_Parser parser, const XML_Char *p) +{ + if (p) { + p = poolCopyString(&_dtd->pool, p); + if (!p) + return XML_STATUS_ERROR; + curBase = p; + } + else + curBase = NULL; + return XML_STATUS_OK; +} + +const XML_Char * XMLCALL +XML_GetBase(XML_Parser parser) +{ + return curBase; +} + +int XMLCALL +XML_GetSpecifiedAttributeCount(XML_Parser parser) +{ + return nSpecifiedAtts; +} + +int XMLCALL +XML_GetIdAttributeIndex(XML_Parser parser) +{ + return idAttIndex; +} + +#ifdef XML_ATTR_INFO +const XML_AttrInfo * XMLCALL +XML_GetAttributeInfo(XML_Parser parser) +{ + return attInfo; +} +#endif + +void XMLCALL +XML_SetElementHandler(XML_Parser parser, + XML_StartElementHandler start, + XML_EndElementHandler end) +{ + startElementHandler = start; + endElementHandler = end; +} + +void XMLCALL +XML_SetStartElementHandler(XML_Parser parser, + XML_StartElementHandler start) { + startElementHandler = start; +} + +void XMLCALL +XML_SetEndElementHandler(XML_Parser parser, + XML_EndElementHandler end) { + endElementHandler = end; +} + +void XMLCALL +XML_SetCharacterDataHandler(XML_Parser parser, + XML_CharacterDataHandler handler) +{ + characterDataHandler = handler; +} + +void XMLCALL +XML_SetProcessingInstructionHandler(XML_Parser parser, + XML_ProcessingInstructionHandler handler) +{ + processingInstructionHandler = handler; +} + +void XMLCALL +XML_SetCommentHandler(XML_Parser parser, + XML_CommentHandler handler) +{ + commentHandler = handler; +} + +void XMLCALL +XML_SetCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start, + XML_EndCdataSectionHandler end) +{ + startCdataSectionHandler = start; + endCdataSectionHandler = end; +} + +void XMLCALL +XML_SetStartCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start) { + startCdataSectionHandler = start; +} + +void XMLCALL +XML_SetEndCdataSectionHandler(XML_Parser parser, + XML_EndCdataSectionHandler end) { + endCdataSectionHandler = end; +} + +void XMLCALL +XML_SetDefaultHandler(XML_Parser parser, + XML_DefaultHandler handler) +{ + defaultHandler = handler; + defaultExpandInternalEntities = XML_FALSE; +} + +void XMLCALL +XML_SetDefaultHandlerExpand(XML_Parser parser, + XML_DefaultHandler handler) +{ + defaultHandler = handler; + defaultExpandInternalEntities = XML_TRUE; +} + +void XMLCALL +XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end) +{ + startDoctypeDeclHandler = start; + endDoctypeDeclHandler = end; +} + +void XMLCALL +XML_SetStartDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start) { + startDoctypeDeclHandler = start; +} + +void XMLCALL +XML_SetEndDoctypeDeclHandler(XML_Parser parser, + XML_EndDoctypeDeclHandler end) { + endDoctypeDeclHandler = end; +} + +void XMLCALL +XML_SetUnparsedEntityDeclHandler(XML_Parser parser, + XML_UnparsedEntityDeclHandler handler) +{ + unparsedEntityDeclHandler = handler; +} + +void XMLCALL +XML_SetNotationDeclHandler(XML_Parser parser, + XML_NotationDeclHandler handler) +{ + notationDeclHandler = handler; +} + +void XMLCALL +XML_SetNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start, + XML_EndNamespaceDeclHandler end) +{ + startNamespaceDeclHandler = start; + endNamespaceDeclHandler = end; +} + +void XMLCALL +XML_SetStartNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start) { + startNamespaceDeclHandler = start; +} + +void XMLCALL +XML_SetEndNamespaceDeclHandler(XML_Parser parser, + XML_EndNamespaceDeclHandler end) { + endNamespaceDeclHandler = end; +} + +void XMLCALL +XML_SetNotStandaloneHandler(XML_Parser parser, + XML_NotStandaloneHandler handler) +{ + notStandaloneHandler = handler; +} + +void XMLCALL +XML_SetExternalEntityRefHandler(XML_Parser parser, + XML_ExternalEntityRefHandler handler) +{ + externalEntityRefHandler = handler; +} + +void XMLCALL +XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) +{ + if (arg) + externalEntityRefHandlerArg = (XML_Parser)arg; + else + externalEntityRefHandlerArg = parser; +} + +void XMLCALL +XML_SetSkippedEntityHandler(XML_Parser parser, + XML_SkippedEntityHandler handler) +{ + skippedEntityHandler = handler; +} + +void XMLCALL +XML_SetUnknownEncodingHandler(XML_Parser parser, + XML_UnknownEncodingHandler handler, + void *data) +{ + unknownEncodingHandler = handler; + unknownEncodingHandlerData = data; +} + +void XMLCALL +XML_SetElementDeclHandler(XML_Parser parser, + XML_ElementDeclHandler eldecl) +{ + elementDeclHandler = eldecl; +} + +void XMLCALL +XML_SetAttlistDeclHandler(XML_Parser parser, + XML_AttlistDeclHandler attdecl) +{ + attlistDeclHandler = attdecl; +} + +void XMLCALL +XML_SetEntityDeclHandler(XML_Parser parser, + XML_EntityDeclHandler handler) +{ + entityDeclHandler = handler; +} + +void XMLCALL +XML_SetXmlDeclHandler(XML_Parser parser, + XML_XmlDeclHandler handler) { + xmlDeclHandler = handler; +} + +int XMLCALL +XML_SetParamEntityParsing(XML_Parser parser, + enum XML_ParamEntityParsing peParsing) +{ + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return 0; +#ifdef XML_DTD + paramEntityParsing = peParsing; + return 1; +#else + return peParsing == XML_PARAM_ENTITY_PARSING_NEVER; +#endif +} + +int XMLCALL +XML_SetHashSalt(XML_Parser parser, + unsigned long hash_salt) +{ + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return 0; + hash_secret_salt = hash_salt; + return 1; +} + +enum XML_Status XMLCALL +XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) +{ + switch (ps_parsing) { + case XML_SUSPENDED: + errorCode = XML_ERROR_SUSPENDED; + return XML_STATUS_ERROR; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return XML_STATUS_ERROR; + case XML_INITIALIZED: + if (parentParser == NULL && !startParsing(parser)) { + errorCode = XML_ERROR_NO_MEMORY; + return XML_STATUS_ERROR; + } + default: + ps_parsing = XML_PARSING; + } + + if (len == 0) { + ps_finalBuffer = (XML_Bool)isFinal; + if (!isFinal) + return XML_STATUS_OK; + positionPtr = bufferPtr; + parseEndPtr = bufferEnd; + + /* If data are left over from last buffer, and we now know that these + data are the final chunk of input, then we have to check them again + to detect errors based on that fact. + */ + errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); + + if (errorCode == XML_ERROR_NONE) { + switch (ps_parsing) { + case XML_SUSPENDED: + XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); + positionPtr = bufferPtr; + return XML_STATUS_SUSPENDED; + case XML_INITIALIZED: + case XML_PARSING: + ps_parsing = XML_FINISHED; + /* fall through */ + default: + return XML_STATUS_OK; + } + } + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } +#ifndef XML_CONTEXT_BYTES + else if (bufferPtr == bufferEnd) { + const char *end; + int nLeftOver; + enum XML_Error result; + parseEndByteIndex += len; + positionPtr = s; + ps_finalBuffer = (XML_Bool)isFinal; + + errorCode = processor(parser, s, parseEndPtr = s + len, &end); + + if (errorCode != XML_ERROR_NONE) { + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + else { + switch (ps_parsing) { + case XML_SUSPENDED: + result = XML_STATUS_SUSPENDED; + break; + case XML_INITIALIZED: + case XML_PARSING: + if (isFinal) { + ps_parsing = XML_FINISHED; + return XML_STATUS_OK; + } + /* fall through */ + default: + result = XML_STATUS_OK; + } + } + + XmlUpdatePosition(encoding, positionPtr, end, &position); + nLeftOver = s + len - end; + if (nLeftOver) { + if (buffer == NULL || nLeftOver > bufferLim - buffer) { + /* FIXME avoid integer overflow */ + char *temp; + temp = (buffer == NULL + ? (char *)MALLOC(len * 2) + : (char *)REALLOC(buffer, len * 2)); + if (temp == NULL) { + errorCode = XML_ERROR_NO_MEMORY; + eventPtr = eventEndPtr = NULL; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + buffer = temp; + bufferLim = buffer + len * 2; + } + memcpy(buffer, end, nLeftOver); + } + bufferPtr = buffer; + bufferEnd = buffer + nLeftOver; + positionPtr = bufferPtr; + parseEndPtr = bufferEnd; + eventPtr = bufferPtr; + eventEndPtr = bufferPtr; + return result; + } +#endif /* not defined XML_CONTEXT_BYTES */ + else { + void *buff = XML_GetBuffer(parser, len); + if (buff == NULL) + return XML_STATUS_ERROR; + else { + memcpy(buff, s, len); + return XML_ParseBuffer(parser, len, isFinal); + } + } +} + +enum XML_Status XMLCALL +XML_ParseBuffer(XML_Parser parser, int len, int isFinal) +{ + const char *start; + enum XML_Status result = XML_STATUS_OK; + + switch (ps_parsing) { + case XML_SUSPENDED: + errorCode = XML_ERROR_SUSPENDED; + return XML_STATUS_ERROR; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return XML_STATUS_ERROR; + case XML_INITIALIZED: + if (parentParser == NULL && !startParsing(parser)) { + errorCode = XML_ERROR_NO_MEMORY; + return XML_STATUS_ERROR; + } + default: + ps_parsing = XML_PARSING; + } + + start = bufferPtr; + positionPtr = start; + bufferEnd += len; + parseEndPtr = bufferEnd; + parseEndByteIndex += len; + ps_finalBuffer = (XML_Bool)isFinal; + + errorCode = processor(parser, start, parseEndPtr, &bufferPtr); + + if (errorCode != XML_ERROR_NONE) { + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + else { + switch (ps_parsing) { + case XML_SUSPENDED: + result = XML_STATUS_SUSPENDED; + break; + case XML_INITIALIZED: + case XML_PARSING: + if (isFinal) { + ps_parsing = XML_FINISHED; + return result; + } + default: ; /* should not happen */ + } + } + + XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); + positionPtr = bufferPtr; + return result; +} + +void * XMLCALL +XML_GetBuffer(XML_Parser parser, int len) +{ + switch (ps_parsing) { + case XML_SUSPENDED: + errorCode = XML_ERROR_SUSPENDED; + return NULL; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return NULL; + default: ; + } + + if (len > bufferLim - bufferEnd) { + /* FIXME avoid integer overflow */ + int neededSize = len + (int)(bufferEnd - bufferPtr); +#ifdef XML_CONTEXT_BYTES + int keep = (int)(bufferPtr - buffer); + + if (keep > XML_CONTEXT_BYTES) + keep = XML_CONTEXT_BYTES; + neededSize += keep; +#endif /* defined XML_CONTEXT_BYTES */ + if (neededSize <= bufferLim - buffer) { +#ifdef XML_CONTEXT_BYTES + if (keep < bufferPtr - buffer) { + int offset = (int)(bufferPtr - buffer) - keep; + memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep); + bufferEnd -= offset; + bufferPtr -= offset; + } +#else + memmove(buffer, bufferPtr, bufferEnd - bufferPtr); + bufferEnd = buffer + (bufferEnd - bufferPtr); + bufferPtr = buffer; +#endif /* not defined XML_CONTEXT_BYTES */ + } + else { + char *newBuf; + int bufferSize = (int)(bufferLim - bufferPtr); + if (bufferSize == 0) + bufferSize = INIT_BUFFER_SIZE; + do { + bufferSize *= 2; + } while (bufferSize < neededSize); + newBuf = (char *)MALLOC(bufferSize); + if (newBuf == 0) { + errorCode = XML_ERROR_NO_MEMORY; + return NULL; + } + bufferLim = newBuf + bufferSize; +#ifdef XML_CONTEXT_BYTES + if (bufferPtr) { + int keep = (int)(bufferPtr - buffer); + if (keep > XML_CONTEXT_BYTES) + keep = XML_CONTEXT_BYTES; + memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep); + FREE(buffer); + buffer = newBuf; + bufferEnd = buffer + (bufferEnd - bufferPtr) + keep; + bufferPtr = buffer + keep; + } + else { + bufferEnd = newBuf + (bufferEnd - bufferPtr); + bufferPtr = buffer = newBuf; + } +#else + if (bufferPtr) { + memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr); + FREE(buffer); + } + bufferEnd = newBuf + (bufferEnd - bufferPtr); + bufferPtr = buffer = newBuf; +#endif /* not defined XML_CONTEXT_BYTES */ + } + eventPtr = eventEndPtr = NULL; + positionPtr = NULL; + } + return bufferEnd; +} + +enum XML_Status XMLCALL +XML_StopParser(XML_Parser parser, XML_Bool resumable) +{ + switch (ps_parsing) { + case XML_SUSPENDED: + if (resumable) { + errorCode = XML_ERROR_SUSPENDED; + return XML_STATUS_ERROR; + } + ps_parsing = XML_FINISHED; + break; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return XML_STATUS_ERROR; + default: + if (resumable) { +#ifdef XML_DTD + if (isParamEntity) { + errorCode = XML_ERROR_SUSPEND_PE; + return XML_STATUS_ERROR; + } +#endif + ps_parsing = XML_SUSPENDED; + } + else + ps_parsing = XML_FINISHED; + } + return XML_STATUS_OK; +} + +enum XML_Status XMLCALL +XML_ResumeParser(XML_Parser parser) +{ + enum XML_Status result = XML_STATUS_OK; + + if (ps_parsing != XML_SUSPENDED) { + errorCode = XML_ERROR_NOT_SUSPENDED; + return XML_STATUS_ERROR; + } + ps_parsing = XML_PARSING; + + errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); + + if (errorCode != XML_ERROR_NONE) { + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + else { + switch (ps_parsing) { + case XML_SUSPENDED: + result = XML_STATUS_SUSPENDED; + break; + case XML_INITIALIZED: + case XML_PARSING: + if (ps_finalBuffer) { + ps_parsing = XML_FINISHED; + return result; + } + default: ; + } + } + + XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); + positionPtr = bufferPtr; + return result; +} + +void XMLCALL +XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) +{ + assert(status != NULL); + *status = parser->m_parsingStatus; +} + +enum XML_Error XMLCALL +XML_GetErrorCode(XML_Parser parser) +{ + return errorCode; +} + +XML_Index XMLCALL +XML_GetCurrentByteIndex(XML_Parser parser) +{ + if (eventPtr) + return parseEndByteIndex - (parseEndPtr - eventPtr); + return -1; +} + +int XMLCALL +XML_GetCurrentByteCount(XML_Parser parser) +{ + if (eventEndPtr && eventPtr) + return (int)(eventEndPtr - eventPtr); + return 0; +} + +const char * XMLCALL +XML_GetInputContext(XML_Parser parser, int *offset, int *size) +{ +#ifdef XML_CONTEXT_BYTES + if (eventPtr && buffer) { + *offset = (int)(eventPtr - buffer); + *size = (int)(bufferEnd - buffer); + return buffer; + } +#endif /* defined XML_CONTEXT_BYTES */ + return (char *) 0; +} + +XML_Size XMLCALL +XML_GetCurrentLineNumber(XML_Parser parser) +{ + if (eventPtr && eventPtr >= positionPtr) { + XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); + positionPtr = eventPtr; + } + return position.lineNumber + 1; +} + +XML_Size XMLCALL +XML_GetCurrentColumnNumber(XML_Parser parser) +{ + if (eventPtr && eventPtr >= positionPtr) { + XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); + positionPtr = eventPtr; + } + return position.columnNumber; +} + +void XMLCALL +XML_FreeContentModel(XML_Parser parser, XML_Content *model) +{ + FREE(model); +} + +void * XMLCALL +XML_MemMalloc(XML_Parser parser, size_t size) +{ + return MALLOC(size); +} + +void * XMLCALL +XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) +{ + return REALLOC(ptr, size); +} + +void XMLCALL +XML_MemFree(XML_Parser parser, void *ptr) +{ + FREE(ptr); +} + +void XMLCALL +XML_DefaultCurrent(XML_Parser parser) +{ + if (defaultHandler) { + if (openInternalEntities) + reportDefault(parser, + internalEncoding, + openInternalEntities->internalEventPtr, + openInternalEntities->internalEventEndPtr); + else + reportDefault(parser, encoding, eventPtr, eventEndPtr); + } +} + +const XML_LChar * XMLCALL +XML_ErrorString(enum XML_Error code) +{ + static const XML_LChar* const message[] = { + 0, + XML_L("out of memory"), + XML_L("syntax error"), + XML_L("no element found"), + XML_L("not well-formed (invalid token)"), + XML_L("unclosed token"), + XML_L("partial character"), + XML_L("mismatched tag"), + XML_L("duplicate attribute"), + XML_L("junk after document element"), + XML_L("illegal parameter entity reference"), + XML_L("undefined entity"), + XML_L("recursive entity reference"), + XML_L("asynchronous entity"), + XML_L("reference to invalid character number"), + XML_L("reference to binary entity"), + XML_L("reference to external entity in attribute"), + XML_L("XML or text declaration not at start of entity"), + XML_L("unknown encoding"), + XML_L("encoding specified in XML declaration is incorrect"), + XML_L("unclosed CDATA section"), + XML_L("error in processing external entity reference"), + XML_L("document is not standalone"), + XML_L("unexpected parser state - please send a bug report"), + XML_L("entity declared in parameter entity"), + XML_L("requested feature requires XML_DTD support in Expat"), + XML_L("cannot change setting once parsing has begun"), + XML_L("unbound prefix"), + XML_L("must not undeclare prefix"), + XML_L("incomplete markup in parameter entity"), + XML_L("XML declaration not well-formed"), + XML_L("text declaration not well-formed"), + XML_L("illegal character(s) in public id"), + XML_L("parser suspended"), + XML_L("parser not suspended"), + XML_L("parsing aborted"), + XML_L("parsing finished"), + XML_L("cannot suspend in external parameter entity"), + XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"), + XML_L("reserved prefix (xmlns) must not be declared or undeclared"), + XML_L("prefix must not be bound to one of the reserved namespace names") + }; + if (code > 0 && code < sizeof(message)/sizeof(message[0])) + return message[code]; + return NULL; +} + +const XML_LChar * XMLCALL +XML_ExpatVersion(void) { + + /* V1 is used to string-ize the version number. However, it would + string-ize the actual version macro *names* unless we get them + substituted before being passed to V1. CPP is defined to expand + a macro, then rescan for more expansions. Thus, we use V2 to expand + the version macros, then CPP will expand the resulting V1() macro + with the correct numerals. */ + /* ### I'm assuming cpp is portable in this respect... */ + +#define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c) +#define V2(a,b,c) XML_L("expat_")V1(a,b,c) + + return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION); + +#undef V1 +#undef V2 +} + +XML_Expat_Version XMLCALL +XML_ExpatVersionInfo(void) +{ + XML_Expat_Version version; + + version.major = XML_MAJOR_VERSION; + version.minor = XML_MINOR_VERSION; + version.micro = XML_MICRO_VERSION; + + return version; +} + +const XML_Feature * XMLCALL +XML_GetFeatureList(void) +{ + static const XML_Feature features[] = { + {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), + sizeof(XML_Char)}, + {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), + sizeof(XML_LChar)}, +#ifdef XML_UNICODE + {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, +#endif +#ifdef XML_UNICODE_WCHAR_T + {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, +#endif +#ifdef XML_DTD + {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, +#endif +#ifdef XML_CONTEXT_BYTES + {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), + XML_CONTEXT_BYTES}, +#endif +#ifdef XML_MIN_SIZE + {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, +#endif +#ifdef XML_NS + {XML_FEATURE_NS, XML_L("XML_NS"), 0}, +#endif +#ifdef XML_LARGE_SIZE + {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, +#endif +#ifdef XML_ATTR_INFO + {XML_FEATURE_ATTR_INFO, XML_L("XML_ATTR_INFO"), 0}, +#endif + {XML_FEATURE_END, NULL, 0} + }; + + return features; +} + +/* Initially tag->rawName always points into the parse buffer; + for those TAG instances opened while the current parse buffer was + processed, and not yet closed, we need to store tag->rawName in a more + permanent location, since the parse buffer is about to be discarded. +*/ +static XML_Bool +storeRawNames(XML_Parser parser) +{ + TAG *tag = tagStack; + while (tag) { + int bufSize; + int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1); + char *rawNameBuf = tag->buf + nameLen; + /* Stop if already stored. Since tagStack is a stack, we can stop + at the first entry that has already been copied; everything + below it in the stack is already been accounted for in a + previous call to this function. + */ + if (tag->rawName == rawNameBuf) + break; + /* For re-use purposes we need to ensure that the + size of tag->buf is a multiple of sizeof(XML_Char). + */ + bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)); + if (bufSize > tag->bufEnd - tag->buf) { + char *temp = (char *)REALLOC(tag->buf, bufSize); + if (temp == NULL) + return XML_FALSE; + /* if tag->name.str points to tag->buf (only when namespace + processing is off) then we have to update it + */ + if (tag->name.str == (XML_Char *)tag->buf) + tag->name.str = (XML_Char *)temp; + /* if tag->name.localPart is set (when namespace processing is on) + then update it as well, since it will always point into tag->buf + */ + if (tag->name.localPart) + tag->name.localPart = (XML_Char *)temp + (tag->name.localPart - + (XML_Char *)tag->buf); + tag->buf = temp; + tag->bufEnd = temp + bufSize; + rawNameBuf = temp + nameLen; + } + memcpy(rawNameBuf, tag->rawName, tag->rawNameLength); + tag->rawName = rawNameBuf; + tag = tag->parent; + } + return XML_TRUE; +} + +static enum XML_Error PTRCALL +contentProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doContent(parser, 0, encoding, start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result == XML_ERROR_NONE) { + if (!storeRawNames(parser)) + return XML_ERROR_NO_MEMORY; + } + return result; +} + +static enum XML_Error PTRCALL +externalEntityInitProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = initializeEncoding(parser); + if (result != XML_ERROR_NONE) + return result; + processor = externalEntityInitProcessor2; + return externalEntityInitProcessor2(parser, start, end, endPtr); +} + +static enum XML_Error PTRCALL +externalEntityInitProcessor2(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + const char *next = start; /* XmlContentTok doesn't always set the last arg */ + int tok = XmlContentTok(encoding, start, end, &next); + switch (tok) { + case XML_TOK_BOM: + /* If we are at the end of the buffer, this would cause the next stage, + i.e. externalEntityInitProcessor3, to pass control directly to + doContent (by detecting XML_TOK_NONE) without processing any xml text + declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent. + */ + if (next == end && !ps_finalBuffer) { + *endPtr = next; + return XML_ERROR_NONE; + } + start = next; + break; + case XML_TOK_PARTIAL: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + eventPtr = start; + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + eventPtr = start; + return XML_ERROR_PARTIAL_CHAR; + } + processor = externalEntityInitProcessor3; + return externalEntityInitProcessor3(parser, start, end, endPtr); +} + +static enum XML_Error PTRCALL +externalEntityInitProcessor3(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + int tok; + const char *next = start; /* XmlContentTok doesn't always set the last arg */ + eventPtr = start; + tok = XmlContentTok(encoding, start, end, &next); + eventEndPtr = next; + + switch (tok) { + case XML_TOK_XML_DECL: + { + enum XML_Error result; + result = processXmlDecl(parser, 1, start, next); + if (result != XML_ERROR_NONE) + return result; + switch (ps_parsing) { + case XML_SUSPENDED: + *endPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + start = next; + } + } + break; + case XML_TOK_PARTIAL: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + } + processor = externalEntityContentProcessor; + tagLevel = 1; + return externalEntityContentProcessor(parser, start, end, endPtr); +} + +static enum XML_Error PTRCALL +externalEntityContentProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doContent(parser, 1, encoding, start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result == XML_ERROR_NONE) { + if (!storeRawNames(parser)) + return XML_ERROR_NO_MEMORY; + } + return result; +} + +static enum XML_Error +doContent(XML_Parser parser, + int startTagLevel, + const ENCODING *enc, + const char *s, + const char *end, + const char **nextPtr, + XML_Bool haveMore) +{ + /* save one level of indirection */ + DTD * const dtd = _dtd; + + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + *eventPP = s; + + for (;;) { + const char *next = s; /* XmlContentTok doesn't always set the last arg */ + int tok = XmlContentTok(enc, s, end, &next); + *eventEndPP = next; + switch (tok) { + case XML_TOK_TRAILING_CR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + *eventEndPP = end; + if (characterDataHandler) { + XML_Char c = 0xA; + characterDataHandler(handlerArg, &c, 1); + } + else if (defaultHandler) + reportDefault(parser, enc, s, end); + /* We are at the end of the final buffer, should we check for + XML_SUSPENDED, XML_FINISHED? + */ + if (startTagLevel == 0) + return XML_ERROR_NO_ELEMENTS; + if (tagLevel != startTagLevel) + return XML_ERROR_ASYNC_ENTITY; + *nextPtr = end; + return XML_ERROR_NONE; + case XML_TOK_NONE: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + if (startTagLevel > 0) { + if (tagLevel != startTagLevel) + return XML_ERROR_ASYNC_ENTITY; + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_NO_ELEMENTS; + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_ENTITY_REF: + { + const XML_Char *name; + ENTITY *entity; + XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (ch) { + if (characterDataHandler) + characterDataHandler(handlerArg, &ch, 1); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + name = poolStoreString(&dtd->pool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); + poolDiscard(&dtd->pool); + /* First, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal, + otherwise call the skipped entity or default handler. + */ + if (!dtd->hasParamEntityRefs || dtd->standalone) { + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (!entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } + else if (!entity) { + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, name, 0); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + if (entity->open) + return XML_ERROR_RECURSIVE_ENTITY_REF; + if (entity->notation) + return XML_ERROR_BINARY_ENTITY_REF; + if (entity->textPtr) { + enum XML_Error result; + if (!defaultExpandInternalEntities) { + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, entity->name, 0); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + result = processInternalEntity(parser, entity, XML_FALSE); + if (result != XML_ERROR_NONE) + return result; + } + else if (externalEntityRefHandler) { + const XML_Char *context; + entity->open = XML_TRUE; + context = getContext(parser); + entity->open = XML_FALSE; + if (!context) + return XML_ERROR_NO_MEMORY; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + context, + entity->base, + entity->systemId, + entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + poolDiscard(&tempPool); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + case XML_TOK_START_TAG_NO_ATTS: + /* fall through */ + case XML_TOK_START_TAG_WITH_ATTS: + { + TAG *tag; + enum XML_Error result; + XML_Char *toPtr; + if (freeTagList) { + tag = freeTagList; + freeTagList = freeTagList->parent; + } + else { + tag = (TAG *)MALLOC(sizeof(TAG)); + if (!tag) + return XML_ERROR_NO_MEMORY; + tag->buf = (char *)MALLOC(INIT_TAG_BUF_SIZE); + if (!tag->buf) { + FREE(tag); + return XML_ERROR_NO_MEMORY; + } + tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; + } + tag->bindings = NULL; + tag->parent = tagStack; + tagStack = tag; + tag->name.localPart = NULL; + tag->name.prefix = NULL; + tag->rawName = s + enc->minBytesPerChar; + tag->rawNameLength = XmlNameLength(enc, tag->rawName); + ++tagLevel; + { + const char *rawNameEnd = tag->rawName + tag->rawNameLength; + const char *fromPtr = tag->rawName; + toPtr = (XML_Char *)tag->buf; + for (;;) { + int bufSize; + int convLen; + XmlConvert(enc, + &fromPtr, rawNameEnd, + (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); + convLen = (int)(toPtr - (XML_Char *)tag->buf); + if (fromPtr == rawNameEnd) { + tag->name.strLen = convLen; + break; + } + bufSize = (int)(tag->bufEnd - tag->buf) << 1; + { + char *temp = (char *)REALLOC(tag->buf, bufSize); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + tag->buf = temp; + tag->bufEnd = temp + bufSize; + toPtr = (XML_Char *)temp + convLen; + } + } + } + tag->name.str = (XML_Char *)tag->buf; + *toPtr = XML_T('\0'); + result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); + if (result) + return result; + if (startElementHandler) + startElementHandler(handlerArg, tag->name.str, + (const XML_Char **)atts); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + poolClear(&tempPool); + break; + } + case XML_TOK_EMPTY_ELEMENT_NO_ATTS: + /* fall through */ + case XML_TOK_EMPTY_ELEMENT_WITH_ATTS: + { + const char *rawName = s + enc->minBytesPerChar; + enum XML_Error result; + BINDING *bindings = NULL; + XML_Bool noElmHandlers = XML_TRUE; + TAG_NAME name; + name.str = poolStoreString(&tempPool, enc, rawName, + rawName + XmlNameLength(enc, rawName)); + if (!name.str) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + result = storeAtts(parser, enc, s, &name, &bindings); + if (result) + return result; + poolFinish(&tempPool); + if (startElementHandler) { + startElementHandler(handlerArg, name.str, (const XML_Char **)atts); + noElmHandlers = XML_FALSE; + } + if (endElementHandler) { + if (startElementHandler) + *eventPP = *eventEndPP; + endElementHandler(handlerArg, name.str); + noElmHandlers = XML_FALSE; + } + if (noElmHandlers && defaultHandler) + reportDefault(parser, enc, s, next); + poolClear(&tempPool); + while (bindings) { + BINDING *b = bindings; + if (endNamespaceDeclHandler) + endNamespaceDeclHandler(handlerArg, b->prefix->name); + bindings = bindings->nextTagBinding; + b->nextTagBinding = freeBindingList; + freeBindingList = b; + b->prefix->binding = b->prevPrefixBinding; + } + } + if (tagLevel == 0) + return epilogProcessor(parser, next, end, nextPtr); + break; + case XML_TOK_END_TAG: + if (tagLevel == startTagLevel) + return XML_ERROR_ASYNC_ENTITY; + else { + int len; + const char *rawName; + TAG *tag = tagStack; + tagStack = tag->parent; + tag->parent = freeTagList; + freeTagList = tag; + rawName = s + enc->minBytesPerChar*2; + len = XmlNameLength(enc, rawName); + if (len != tag->rawNameLength + || memcmp(tag->rawName, rawName, len) != 0) { + *eventPP = rawName; + return XML_ERROR_TAG_MISMATCH; + } + --tagLevel; + if (endElementHandler) { + const XML_Char *localPart; + const XML_Char *prefix; + XML_Char *uri; + localPart = tag->name.localPart; + if (ns && localPart) { + /* localPart and prefix may have been overwritten in + tag->name.str, since this points to the binding->uri + buffer which gets re-used; so we have to add them again + */ + uri = (XML_Char *)tag->name.str + tag->name.uriLen; + /* don't need to check for space - already done in storeAtts() */ + while (*localPart) *uri++ = *localPart++; + prefix = (XML_Char *)tag->name.prefix; + if (ns_triplets && prefix) { + *uri++ = namespaceSeparator; + while (*prefix) *uri++ = *prefix++; + } + *uri = XML_T('\0'); + } + endElementHandler(handlerArg, tag->name.str); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + while (tag->bindings) { + BINDING *b = tag->bindings; + if (endNamespaceDeclHandler) + endNamespaceDeclHandler(handlerArg, b->prefix->name); + tag->bindings = tag->bindings->nextTagBinding; + b->nextTagBinding = freeBindingList; + freeBindingList = b; + b->prefix->binding = b->prevPrefixBinding; + } + if (tagLevel == 0) + return epilogProcessor(parser, next, end, nextPtr); + } + break; + case XML_TOK_CHAR_REF: + { + int n = XmlCharRefNumber(enc, s); + if (n < 0) + return XML_ERROR_BAD_CHAR_REF; + if (characterDataHandler) { + XML_Char buf[XML_ENCODE_MAX]; + characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + } + break; + case XML_TOK_XML_DECL: + return XML_ERROR_MISPLACED_XML_PI; + case XML_TOK_DATA_NEWLINE: + if (characterDataHandler) { + XML_Char c = 0xA; + characterDataHandler(handlerArg, &c, 1); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_CDATA_SECT_OPEN: + { + enum XML_Error result; + if (startCdataSectionHandler) + startCdataSectionHandler(handlerArg); +#if 0 + /* Suppose you doing a transformation on a document that involves + changing only the character data. You set up a defaultHandler + and a characterDataHandler. The defaultHandler simply copies + characters through. The characterDataHandler does the + transformation and writes the characters out escaping them as + necessary. This case will fail to work if we leave out the + following two lines (because & and < inside CDATA sections will + be incorrectly escaped). + + However, now we have a start/endCdataSectionHandler, so it seems + easier to let the user deal with this. + */ + else if (characterDataHandler) + characterDataHandler(handlerArg, dataBuf, 0); +#endif + else if (defaultHandler) + reportDefault(parser, enc, s, next); + result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore); + if (result != XML_ERROR_NONE) + return result; + else if (!next) { + processor = cdataSectionProcessor; + return result; + } + } + break; + case XML_TOK_TRAILING_RSQB: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + if (characterDataHandler) { + if (MUST_CONVERT(enc, s)) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); + characterDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + } + else + characterDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)end - (XML_Char *)s)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, end); + /* We are at the end of the final buffer, should we check for + XML_SUSPENDED, XML_FINISHED? + */ + if (startTagLevel == 0) { + *eventPP = end; + return XML_ERROR_NO_ELEMENTS; + } + if (tagLevel != startTagLevel) { + *eventPP = end; + return XML_ERROR_ASYNC_ENTITY; + } + *nextPtr = end; + return XML_ERROR_NONE; + case XML_TOK_DATA_CHARS: + { + XML_CharacterDataHandler charDataHandler = characterDataHandler; + if (charDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = s; + charDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + if (s == next) + break; + *eventPP = s; + } + } + else + charDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + } + break; + case XML_TOK_PI: + if (!reportProcessingInstruction(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_COMMENT: + if (!reportComment(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + break; + default: + if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + *eventPP = s = next; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: ; + } + } + /* not reached */ +} + +/* Precondition: all arguments must be non-NULL; + Purpose: + - normalize attributes + - check attributes for well-formedness + - generate namespace aware attribute names (URI, prefix) + - build list of attributes for startElementHandler + - default attributes + - process namespace declarations (check and report them) + - generate namespace aware element name (URI, prefix) +*/ +static enum XML_Error +storeAtts(XML_Parser parser, const ENCODING *enc, + const char *attStr, TAG_NAME *tagNamePtr, + BINDING **bindingsPtr) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + ELEMENT_TYPE *elementType; + int nDefaultAtts; + const XML_Char **appAtts; /* the attribute list for the application */ + int attIndex = 0; + int prefixLen; + int i; + int n; + XML_Char *uri; + int nPrefixes = 0; + BINDING *binding; + const XML_Char *localPart; + + /* lookup the element type name */ + elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, tagNamePtr->str,0); + if (!elementType) { + const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); + if (!name) + return XML_ERROR_NO_MEMORY; + elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, name, + sizeof(ELEMENT_TYPE)); + if (!elementType) + return XML_ERROR_NO_MEMORY; + if (ns && !setElementTypePrefix(parser, elementType)) + return XML_ERROR_NO_MEMORY; + } + nDefaultAtts = elementType->nDefaultAtts; + + /* get the attributes from the tokenizer */ + n = XmlGetAttributes(enc, attStr, attsSize, atts); + if (n + nDefaultAtts > attsSize) { + int oldAttsSize = attsSize; + ATTRIBUTE *temp; +#ifdef XML_ATTR_INFO + XML_AttrInfo *temp2; +#endif + attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; + temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + atts = temp; +#ifdef XML_ATTR_INFO + temp2 = (XML_AttrInfo *)REALLOC((void *)attInfo, attsSize * sizeof(XML_AttrInfo)); + if (temp2 == NULL) + return XML_ERROR_NO_MEMORY; + attInfo = temp2; +#endif + if (n > oldAttsSize) + XmlGetAttributes(enc, attStr, n, atts); + } + + appAtts = (const XML_Char **)atts; + for (i = 0; i < n; i++) { + ATTRIBUTE *currAtt = &atts[i]; +#ifdef XML_ATTR_INFO + XML_AttrInfo *currAttInfo = &attInfo[i]; +#endif + /* add the name and value to the attribute list */ + ATTRIBUTE_ID *attId = getAttributeId(parser, enc, currAtt->name, + currAtt->name + + XmlNameLength(enc, currAtt->name)); + if (!attId) + return XML_ERROR_NO_MEMORY; +#ifdef XML_ATTR_INFO + currAttInfo->nameStart = parseEndByteIndex - (parseEndPtr - currAtt->name); + currAttInfo->nameEnd = currAttInfo->nameStart + + XmlNameLength(enc, currAtt->name); + currAttInfo->valueStart = parseEndByteIndex - + (parseEndPtr - currAtt->valuePtr); + currAttInfo->valueEnd = parseEndByteIndex - (parseEndPtr - currAtt->valueEnd); +#endif + /* Detect duplicate attributes by their QNames. This does not work when + namespace processing is turned on and different prefixes for the same + namespace are used. For this case we have a check further down. + */ + if ((attId->name)[-1]) { + if (enc == encoding) + eventPtr = atts[i].name; + return XML_ERROR_DUPLICATE_ATTRIBUTE; + } + (attId->name)[-1] = 1; + appAtts[attIndex++] = attId->name; + if (!atts[i].normalized) { + enum XML_Error result; + XML_Bool isCdata = XML_TRUE; + + /* figure out whether declared as other than CDATA */ + if (attId->maybeTokenized) { + int j; + for (j = 0; j < nDefaultAtts; j++) { + if (attId == elementType->defaultAtts[j].id) { + isCdata = elementType->defaultAtts[j].isCdata; + break; + } + } + } + + /* normalize the attribute value */ + result = storeAttributeValue(parser, enc, isCdata, + atts[i].valuePtr, atts[i].valueEnd, + &tempPool); + if (result) + return result; + appAtts[attIndex] = poolStart(&tempPool); + poolFinish(&tempPool); + } + else { + /* the value did not need normalizing */ + appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, + atts[i].valueEnd); + if (appAtts[attIndex] == 0) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + } + /* handle prefixed attribute names */ + if (attId->prefix) { + if (attId->xmlns) { + /* deal with namespace declarations here */ + enum XML_Error result = addBinding(parser, attId->prefix, attId, + appAtts[attIndex], bindingsPtr); + if (result) + return result; + --attIndex; + } + else { + /* deal with other prefixed names later */ + attIndex++; + nPrefixes++; + (attId->name)[-1] = 2; + } + } + else + attIndex++; + } + + /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */ + nSpecifiedAtts = attIndex; + if (elementType->idAtt && (elementType->idAtt->name)[-1]) { + for (i = 0; i < attIndex; i += 2) + if (appAtts[i] == elementType->idAtt->name) { + idAttIndex = i; + break; + } + } + else + idAttIndex = -1; + + /* do attribute defaulting */ + for (i = 0; i < nDefaultAtts; i++) { + const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i; + if (!(da->id->name)[-1] && da->value) { + if (da->id->prefix) { + if (da->id->xmlns) { + enum XML_Error result = addBinding(parser, da->id->prefix, da->id, + da->value, bindingsPtr); + if (result) + return result; + } + else { + (da->id->name)[-1] = 2; + nPrefixes++; + appAtts[attIndex++] = da->id->name; + appAtts[attIndex++] = da->value; + } + } + else { + (da->id->name)[-1] = 1; + appAtts[attIndex++] = da->id->name; + appAtts[attIndex++] = da->value; + } + } + } + appAtts[attIndex] = 0; + + /* expand prefixed attribute names, check for duplicates, + and clear flags that say whether attributes were specified */ + i = 0; + if (nPrefixes) { + int j; /* hash table index */ + unsigned long version = nsAttsVersion; + int nsAttsSize = (int)1 << nsAttsPower; + /* size of hash table must be at least 2 * (# of prefixed attributes) */ + if ((nPrefixes << 1) >> nsAttsPower) { /* true for nsAttsPower = 0 */ + NS_ATT *temp; + /* hash table size must also be a power of 2 and >= 8 */ + while (nPrefixes >> nsAttsPower++); + if (nsAttsPower < 3) + nsAttsPower = 3; + nsAttsSize = (int)1 << nsAttsPower; + temp = (NS_ATT *)REALLOC(nsAtts, nsAttsSize * sizeof(NS_ATT)); + if (!temp) + return XML_ERROR_NO_MEMORY; + nsAtts = temp; + version = 0; /* force re-initialization of nsAtts hash table */ + } + /* using a version flag saves us from initializing nsAtts every time */ + if (!version) { /* initialize version flags when version wraps around */ + version = INIT_ATTS_VERSION; + for (j = nsAttsSize; j != 0; ) + nsAtts[--j].version = version; + } + nsAttsVersion = --version; + + /* expand prefixed names and check for duplicates */ + for (; i < attIndex; i += 2) { + const XML_Char *s = appAtts[i]; + if (s[-1] == 2) { /* prefixed */ + ATTRIBUTE_ID *id; + const BINDING *b; + unsigned long uriHash = hash_secret_salt; + ((XML_Char *)s)[-1] = 0; /* clear flag */ + id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0); + b = id->prefix->binding; + if (!b) + return XML_ERROR_UNBOUND_PREFIX; + + /* as we expand the name we also calculate its hash value */ + for (j = 0; j < b->uriLen; j++) { + const XML_Char c = b->uri[j]; + if (!poolAppendChar(&tempPool, c)) + return XML_ERROR_NO_MEMORY; + uriHash = CHAR_HASH(uriHash, c); + } + while (*s++ != XML_T(ASCII_COLON)) + ; + do { /* copies null terminator */ + const XML_Char c = *s; + if (!poolAppendChar(&tempPool, *s)) + return XML_ERROR_NO_MEMORY; + uriHash = CHAR_HASH(uriHash, c); + } while (*s++); + + { /* Check hash table for duplicate of expanded name (uriName). + Derived from code in lookup(parser, HASH_TABLE *table, ...). + */ + unsigned char step = 0; + unsigned long mask = nsAttsSize - 1; + j = uriHash & mask; /* index into hash table */ + while (nsAtts[j].version == version) { + /* for speed we compare stored hash values first */ + if (uriHash == nsAtts[j].hash) { + const XML_Char *s1 = poolStart(&tempPool); + const XML_Char *s2 = nsAtts[j].uriName; + /* s1 is null terminated, but not s2 */ + for (; *s1 == *s2 && *s1 != 0; s1++, s2++); + if (*s1 == 0) + return XML_ERROR_DUPLICATE_ATTRIBUTE; + } + if (!step) + step = PROBE_STEP(uriHash, mask, nsAttsPower); + j < step ? (j += nsAttsSize - step) : (j -= step); + } + } + + if (ns_triplets) { /* append namespace separator and prefix */ + tempPool.ptr[-1] = namespaceSeparator; + s = b->prefix->name; + do { + if (!poolAppendChar(&tempPool, *s)) + return XML_ERROR_NO_MEMORY; + } while (*s++); + } + + /* store expanded name in attribute list */ + s = poolStart(&tempPool); + poolFinish(&tempPool); + appAtts[i] = s; + + /* fill empty slot with new version, uriName and hash value */ + nsAtts[j].version = version; + nsAtts[j].hash = uriHash; + nsAtts[j].uriName = s; + + if (!--nPrefixes) { + i += 2; + break; + } + } + else /* not prefixed */ + ((XML_Char *)s)[-1] = 0; /* clear flag */ + } + } + /* clear flags for the remaining attributes */ + for (; i < attIndex; i += 2) + ((XML_Char *)(appAtts[i]))[-1] = 0; + for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) + binding->attId->name[-1] = 0; + + if (!ns) + return XML_ERROR_NONE; + + /* expand the element type name */ + if (elementType->prefix) { + binding = elementType->prefix->binding; + if (!binding) + return XML_ERROR_UNBOUND_PREFIX; + localPart = tagNamePtr->str; + while (*localPart++ != XML_T(ASCII_COLON)) + ; + } + else if (dtd->defaultPrefix.binding) { + binding = dtd->defaultPrefix.binding; + localPart = tagNamePtr->str; + } + else + return XML_ERROR_NONE; + prefixLen = 0; + if (ns_triplets && binding->prefix->name) { + for (; binding->prefix->name[prefixLen++];) + ; /* prefixLen includes null terminator */ + } + tagNamePtr->localPart = localPart; + tagNamePtr->uriLen = binding->uriLen; + tagNamePtr->prefix = binding->prefix->name; + tagNamePtr->prefixLen = prefixLen; + for (i = 0; localPart[i++];) + ; /* i includes null terminator */ + n = i + binding->uriLen + prefixLen; + if (n > binding->uriAlloc) { + TAG *p; + uri = (XML_Char *)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char)); + if (!uri) + return XML_ERROR_NO_MEMORY; + binding->uriAlloc = n + EXPAND_SPARE; + memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); + for (p = tagStack; p; p = p->parent) + if (p->name.str == binding->uri) + p->name.str = uri; + FREE(binding->uri); + binding->uri = uri; + } + /* if namespaceSeparator != '\0' then uri includes it already */ + uri = binding->uri + binding->uriLen; + memcpy(uri, localPart, i * sizeof(XML_Char)); + /* we always have a namespace separator between localPart and prefix */ + if (prefixLen) { + uri += i - 1; + *uri = namespaceSeparator; /* replace null terminator */ + memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char)); + } + tagNamePtr->str = binding->uri; + return XML_ERROR_NONE; +} + +/* addBinding() overwrites the value of prefix->binding without checking. + Therefore one must keep track of the old value outside of addBinding(). +*/ +static enum XML_Error +addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, + const XML_Char *uri, BINDING **bindingsPtr) +{ + static const XML_Char xmlNamespace[] = { + ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, + ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, + ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, + ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, ASCII_SLASH, + ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c, + ASCII_e, '\0' + }; + static const int xmlLen = + (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1; + static const XML_Char xmlnsNamespace[] = { + ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, + ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, + ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0, + ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s, + ASCII_SLASH, '\0' + }; + static const int xmlnsLen = + (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1; + + XML_Bool mustBeXML = XML_FALSE; + XML_Bool isXML = XML_TRUE; + XML_Bool isXMLNS = XML_TRUE; + + BINDING *b; + int len; + + /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */ + if (*uri == XML_T('\0') && prefix->name) + return XML_ERROR_UNDECLARING_PREFIX; + + if (prefix->name + && prefix->name[0] == XML_T(ASCII_x) + && prefix->name[1] == XML_T(ASCII_m) + && prefix->name[2] == XML_T(ASCII_l)) { + + /* Not allowed to bind xmlns */ + if (prefix->name[3] == XML_T(ASCII_n) + && prefix->name[4] == XML_T(ASCII_s) + && prefix->name[5] == XML_T('\0')) + return XML_ERROR_RESERVED_PREFIX_XMLNS; + + if (prefix->name[3] == XML_T('\0')) + mustBeXML = XML_TRUE; + } + + for (len = 0; uri[len]; len++) { + if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len])) + isXML = XML_FALSE; + + if (!mustBeXML && isXMLNS + && (len > xmlnsLen || uri[len] != xmlnsNamespace[len])) + isXMLNS = XML_FALSE; + } + isXML = isXML && len == xmlLen; + isXMLNS = isXMLNS && len == xmlnsLen; + + if (mustBeXML != isXML) + return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML + : XML_ERROR_RESERVED_NAMESPACE_URI; + + if (isXMLNS) + return XML_ERROR_RESERVED_NAMESPACE_URI; + + if (namespaceSeparator) + len++; + if (freeBindingList) { + b = freeBindingList; + if (len > b->uriAlloc) { + XML_Char *temp = (XML_Char *)REALLOC(b->uri, + sizeof(XML_Char) * (len + EXPAND_SPARE)); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + b->uri = temp; + b->uriAlloc = len + EXPAND_SPARE; + } + freeBindingList = b->nextTagBinding; + } + else { + b = (BINDING *)MALLOC(sizeof(BINDING)); + if (!b) + return XML_ERROR_NO_MEMORY; + b->uri = (XML_Char *)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE)); + if (!b->uri) { + FREE(b); + return XML_ERROR_NO_MEMORY; + } + b->uriAlloc = len + EXPAND_SPARE; + } + b->uriLen = len; + memcpy(b->uri, uri, len * sizeof(XML_Char)); + if (namespaceSeparator) + b->uri[len - 1] = namespaceSeparator; + b->prefix = prefix; + b->attId = attId; + b->prevPrefixBinding = prefix->binding; + /* NULL binding when default namespace undeclared */ + if (*uri == XML_T('\0') && prefix == &_dtd->defaultPrefix) + prefix->binding = NULL; + else + prefix->binding = b; + b->nextTagBinding = *bindingsPtr; + *bindingsPtr = b; + /* if attId == NULL then we are not starting a namespace scope */ + if (attId && startNamespaceDeclHandler) + startNamespaceDeclHandler(handlerArg, prefix->name, + prefix->binding ? uri : 0); + return XML_ERROR_NONE; +} + +/* The idea here is to avoid using stack for each CDATA section when + the whole file is parsed with one call. +*/ +static enum XML_Error PTRCALL +cdataSectionProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doCdataSection(parser, encoding, &start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result != XML_ERROR_NONE) + return result; + if (start) { + if (parentParser) { /* we are parsing an external entity */ + processor = externalEntityContentProcessor; + return externalEntityContentProcessor(parser, start, end, endPtr); + } + else { + processor = contentProcessor; + return contentProcessor(parser, start, end, endPtr); + } + } + return result; +} + +/* startPtr gets set to non-null if the section is closed, and to null if + the section is not yet closed. +*/ +static enum XML_Error +doCdataSection(XML_Parser parser, + const ENCODING *enc, + const char **startPtr, + const char *end, + const char **nextPtr, + XML_Bool haveMore) +{ + const char *s = *startPtr; + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + *eventPP = s; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + *eventPP = s; + *startPtr = NULL; + + for (;;) { + const char *next; + int tok = XmlCdataSectionTok(enc, s, end, &next); + *eventEndPP = next; + switch (tok) { + case XML_TOK_CDATA_SECT_CLOSE: + if (endCdataSectionHandler) + endCdataSectionHandler(handlerArg); +#if 0 + /* see comment under XML_TOK_CDATA_SECT_OPEN */ + else if (characterDataHandler) + characterDataHandler(handlerArg, dataBuf, 0); +#endif + else if (defaultHandler) + reportDefault(parser, enc, s, next); + *startPtr = next; + *nextPtr = next; + if (ps_parsing == XML_FINISHED) + return XML_ERROR_ABORTED; + else + return XML_ERROR_NONE; + case XML_TOK_DATA_NEWLINE: + if (characterDataHandler) { + XML_Char c = 0xA; + characterDataHandler(handlerArg, &c, 1); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_DATA_CHARS: + { + XML_CharacterDataHandler charDataHandler = characterDataHandler; + if (charDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = next; + charDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + if (s == next) + break; + *eventPP = s; + } + } + else + charDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + } + break; + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_PARTIAL: + case XML_TOK_NONE: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_CDATA_SECTION; + default: + *eventPP = next; + return XML_ERROR_UNEXPECTED_STATE; + } + + *eventPP = s = next; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: ; + } + } + /* not reached */ +} + +#ifdef XML_DTD + +/* The idea here is to avoid using stack for each IGNORE section when + the whole file is parsed with one call. +*/ +static enum XML_Error PTRCALL +ignoreSectionProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doIgnoreSection(parser, encoding, &start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result != XML_ERROR_NONE) + return result; + if (start) { + processor = prologProcessor; + return prologProcessor(parser, start, end, endPtr); + } + return result; +} + +/* startPtr gets set to non-null is the section is closed, and to null + if the section is not yet closed. +*/ +static enum XML_Error +doIgnoreSection(XML_Parser parser, + const ENCODING *enc, + const char **startPtr, + const char *end, + const char **nextPtr, + XML_Bool haveMore) +{ + const char *next; + int tok; + const char *s = *startPtr; + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + *eventPP = s; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + *eventPP = s; + *startPtr = NULL; + tok = XmlIgnoreSectionTok(enc, s, end, &next); + *eventEndPP = next; + switch (tok) { + case XML_TOK_IGNORE_SECT: + if (defaultHandler) + reportDefault(parser, enc, s, next); + *startPtr = next; + *nextPtr = next; + if (ps_parsing == XML_FINISHED) + return XML_ERROR_ABORTED; + else + return XML_ERROR_NONE; + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_PARTIAL: + case XML_TOK_NONE: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */ + default: + *eventPP = next; + return XML_ERROR_UNEXPECTED_STATE; + } + /* not reached */ +} + +#endif /* XML_DTD */ + +static enum XML_Error +initializeEncoding(XML_Parser parser) +{ + const char *s; +#ifdef XML_UNICODE + char encodingBuf[128]; + if (!protocolEncodingName) + s = NULL; + else { + int i; + for (i = 0; protocolEncodingName[i]; i++) { + if (i == sizeof(encodingBuf) - 1 + || (protocolEncodingName[i] & ~0x7f) != 0) { + encodingBuf[0] = '\0'; + break; + } + encodingBuf[i] = (char)protocolEncodingName[i]; + } + encodingBuf[i] = '\0'; + s = encodingBuf; + } +#else + s = protocolEncodingName; +#endif + if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s)) + return XML_ERROR_NONE; + return handleUnknownEncoding(parser, protocolEncodingName); +} + +static enum XML_Error +processXmlDecl(XML_Parser parser, int isGeneralTextEntity, + const char *s, const char *next) +{ + const char *encodingName = NULL; + const XML_Char *storedEncName = NULL; + const ENCODING *newEncoding = NULL; + const char *version = NULL; + const char *versionend; + const XML_Char *storedversion = NULL; + int standalone = -1; + if (!(ns + ? XmlParseXmlDeclNS + : XmlParseXmlDecl)(isGeneralTextEntity, + encoding, + s, + next, + &eventPtr, + &version, + &versionend, + &encodingName, + &newEncoding, + &standalone)) { + if (isGeneralTextEntity) + return XML_ERROR_TEXT_DECL; + else + return XML_ERROR_XML_DECL; + } + if (!isGeneralTextEntity && standalone == 1) { + _dtd->standalone = XML_TRUE; +#ifdef XML_DTD + if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) + paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; +#endif /* XML_DTD */ + } + if (xmlDeclHandler) { + if (encodingName != NULL) { + storedEncName = poolStoreString(&temp2Pool, + encoding, + encodingName, + encodingName + + XmlNameLength(encoding, encodingName)); + if (!storedEncName) + return XML_ERROR_NO_MEMORY; + poolFinish(&temp2Pool); + } + if (version) { + storedversion = poolStoreString(&temp2Pool, + encoding, + version, + versionend - encoding->minBytesPerChar); + if (!storedversion) + return XML_ERROR_NO_MEMORY; + } + xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone); + } + else if (defaultHandler) + reportDefault(parser, encoding, s, next); + if (protocolEncodingName == NULL) { + if (newEncoding) { + if (newEncoding->minBytesPerChar != encoding->minBytesPerChar) { + eventPtr = encodingName; + return XML_ERROR_INCORRECT_ENCODING; + } + encoding = newEncoding; + } + else if (encodingName) { + enum XML_Error result; + if (!storedEncName) { + storedEncName = poolStoreString( + &temp2Pool, encoding, encodingName, + encodingName + XmlNameLength(encoding, encodingName)); + if (!storedEncName) + return XML_ERROR_NO_MEMORY; + } + result = handleUnknownEncoding(parser, storedEncName); + poolClear(&temp2Pool); + if (result == XML_ERROR_UNKNOWN_ENCODING) + eventPtr = encodingName; + return result; + } + } + + if (storedEncName || storedversion) + poolClear(&temp2Pool); + + return XML_ERROR_NONE; +} + +static enum XML_Error +handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName) +{ + if (unknownEncodingHandler) { + XML_Encoding info; + int i; + for (i = 0; i < 256; i++) + info.map[i] = -1; + info.convert = NULL; + info.data = NULL; + info.release = NULL; + if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName, + &info)) { + ENCODING *enc; + unknownEncodingMem = MALLOC(XmlSizeOfUnknownEncoding()); + if (!unknownEncodingMem) { + if (info.release) + info.release(info.data); + return XML_ERROR_NO_MEMORY; + } + enc = (ns + ? XmlInitUnknownEncodingNS + : XmlInitUnknownEncoding)(unknownEncodingMem, + info.map, + info.convert, + info.data); + if (enc) { + unknownEncodingData = info.data; + unknownEncodingRelease = info.release; + encoding = enc; + return XML_ERROR_NONE; + } + } + if (info.release != NULL) + info.release(info.data); + } + return XML_ERROR_UNKNOWN_ENCODING; +} + +static enum XML_Error PTRCALL +prologInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + enum XML_Error result = initializeEncoding(parser); + if (result != XML_ERROR_NONE) + return result; + processor = prologProcessor; + return prologProcessor(parser, s, end, nextPtr); +} + +#ifdef XML_DTD + +static enum XML_Error PTRCALL +externalParEntInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + enum XML_Error result = initializeEncoding(parser); + if (result != XML_ERROR_NONE) + return result; + + /* we know now that XML_Parse(Buffer) has been called, + so we consider the external parameter entity read */ + _dtd->paramEntityRead = XML_TRUE; + + if (prologState.inEntityValue) { + processor = entityValueInitProcessor; + return entityValueInitProcessor(parser, s, end, nextPtr); + } + else { + processor = externalParEntProcessor; + return externalParEntProcessor(parser, s, end, nextPtr); + } +} + +static enum XML_Error PTRCALL +entityValueInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + int tok; + const char *start = s; + const char *next = start; + eventPtr = start; + + for (;;) { + tok = XmlPrologTok(encoding, start, end, &next); + eventEndPtr = next; + if (tok <= 0) { + if (!ps_finalBuffer && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: /* start == end */ + default: + break; + } + /* found end of entity value - can store it now */ + return storeEntityValue(parser, encoding, s, end); + } + else if (tok == XML_TOK_XML_DECL) { + enum XML_Error result; + result = processXmlDecl(parser, 0, start, next); + if (result != XML_ERROR_NONE) + return result; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + *nextPtr = next; + } + /* stop scanning for text declaration - we found one */ + processor = entityValueProcessor; + return entityValueProcessor(parser, next, end, nextPtr); + } + /* If we are at the end of the buffer, this would cause XmlPrologTok to + return XML_TOK_NONE on the next call, which would then cause the + function to exit with *nextPtr set to s - that is what we want for other + tokens, but not for the BOM - we would rather like to skip it; + then, when this routine is entered the next time, XmlPrologTok will + return XML_TOK_INVALID, since the BOM is still in the buffer + */ + else if (tok == XML_TOK_BOM && next == end && !ps_finalBuffer) { + *nextPtr = next; + return XML_ERROR_NONE; + } + start = next; + eventPtr = start; + } +} + +static enum XML_Error PTRCALL +externalParEntProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + const char *next = s; + int tok; + + tok = XmlPrologTok(encoding, s, end, &next); + if (tok <= 0) { + if (!ps_finalBuffer && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: /* start == end */ + default: + break; + } + } + /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM. + However, when parsing an external subset, doProlog will not accept a BOM + as valid, and report a syntax error, so we have to skip the BOM + */ + else if (tok == XML_TOK_BOM) { + s = next; + tok = XmlPrologTok(encoding, s, end, &next); + } + + processor = prologProcessor; + return doProlog(parser, encoding, s, end, tok, next, + nextPtr, (XML_Bool)!ps_finalBuffer); +} + +static enum XML_Error PTRCALL +entityValueProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + const char *start = s; + const char *next = s; + const ENCODING *enc = encoding; + int tok; + + for (;;) { + tok = XmlPrologTok(enc, start, end, &next); + if (tok <= 0) { + if (!ps_finalBuffer && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: /* start == end */ + default: + break; + } + /* found end of entity value - can store it now */ + return storeEntityValue(parser, enc, s, end); + } + start = next; + } +} + +#endif /* XML_DTD */ + +static enum XML_Error PTRCALL +prologProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + const char *next = s; + int tok = XmlPrologTok(encoding, s, end, &next); + return doProlog(parser, encoding, s, end, tok, next, + nextPtr, (XML_Bool)!ps_finalBuffer); +} + +static enum XML_Error +doProlog(XML_Parser parser, + const ENCODING *enc, + const char *s, + const char *end, + int tok, + const char *next, + const char **nextPtr, + XML_Bool haveMore) +{ +#ifdef XML_DTD + static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' }; +#endif /* XML_DTD */ + static const XML_Char atypeCDATA[] = + { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; + static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' }; + static const XML_Char atypeIDREF[] = + { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; + static const XML_Char atypeIDREFS[] = + { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; + static const XML_Char atypeENTITY[] = + { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; + static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N, + ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' }; + static const XML_Char atypeNMTOKEN[] = { + ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; + static const XML_Char atypeNMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T, + ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' }; + static const XML_Char notationPrefix[] = { ASCII_N, ASCII_O, ASCII_T, + ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0' }; + static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' }; + static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' }; + + /* save one level of indirection */ + DTD * const dtd = _dtd; + + const char **eventPP; + const char **eventEndPP; + enum XML_Content_Quant quant; + + if (enc == encoding) { + eventPP = &eventPtr; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + + for (;;) { + int role; + XML_Bool handleDefault = XML_TRUE; + *eventPP = s; + *eventEndPP = next; + if (tok <= 0) { + if (haveMore && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case -XML_TOK_PROLOG_S: + tok = -tok; + break; + case XML_TOK_NONE: +#ifdef XML_DTD + /* for internal PE NOT referenced between declarations */ + if (enc != encoding && !openInternalEntities->betweenDecl) { + *nextPtr = s; + return XML_ERROR_NONE; + } + /* WFC: PE Between Declarations - must check that PE contains + complete markup, not only for external PEs, but also for + internal PEs if the reference occurs between declarations. + */ + if (isParamEntity || enc != encoding) { + if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc) + == XML_ROLE_ERROR) + return XML_ERROR_INCOMPLETE_PE; + *nextPtr = s; + return XML_ERROR_NONE; + } +#endif /* XML_DTD */ + return XML_ERROR_NO_ELEMENTS; + default: + tok = -tok; + next = end; + break; + } + } + role = XmlTokenRole(&prologState, tok, s, next, enc); + switch (role) { + case XML_ROLE_XML_DECL: + { + enum XML_Error result = processXmlDecl(parser, 0, s, next); + if (result != XML_ERROR_NONE) + return result; + enc = encoding; + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_DOCTYPE_NAME: + if (startDoctypeDeclHandler) { + doctypeName = poolStoreString(&tempPool, enc, s, next); + if (!doctypeName) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + doctypePubid = NULL; + handleDefault = XML_FALSE; + } + doctypeSysid = NULL; /* always initialize to NULL */ + break; + case XML_ROLE_DOCTYPE_INTERNAL_SUBSET: + if (startDoctypeDeclHandler) { + startDoctypeDeclHandler(handlerArg, doctypeName, doctypeSysid, + doctypePubid, 1); + doctypeName = NULL; + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + break; +#ifdef XML_DTD + case XML_ROLE_TEXT_DECL: + { + enum XML_Error result = processXmlDecl(parser, 1, s, next); + if (result != XML_ERROR_NONE) + return result; + enc = encoding; + handleDefault = XML_FALSE; + } + break; +#endif /* XML_DTD */ + case XML_ROLE_DOCTYPE_PUBLIC_ID: +#ifdef XML_DTD + useForeignDTD = XML_FALSE; + declEntity = (ENTITY *)lookup(parser, + &dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; +#endif /* XML_DTD */ + dtd->hasParamEntityRefs = XML_TRUE; + if (startDoctypeDeclHandler) { + XML_Char *pubId; + if (!XmlIsPublicId(enc, s, next, eventPP)) + return XML_ERROR_PUBLICID; + pubId = poolStoreString(&tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!pubId) + return XML_ERROR_NO_MEMORY; + normalizePublicId(pubId); + poolFinish(&tempPool); + doctypePubid = pubId; + handleDefault = XML_FALSE; + goto alreadyChecked; + } + /* fall through */ + case XML_ROLE_ENTITY_PUBLIC_ID: + if (!XmlIsPublicId(enc, s, next, eventPP)) + return XML_ERROR_PUBLICID; + alreadyChecked: + if (dtd->keepProcessing && declEntity) { + XML_Char *tem = poolStoreString(&dtd->pool, + enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!tem) + return XML_ERROR_NO_MEMORY; + normalizePublicId(tem); + declEntity->publicId = tem; + poolFinish(&dtd->pool); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_DOCTYPE_CLOSE: + if (doctypeName) { + startDoctypeDeclHandler(handlerArg, doctypeName, + doctypeSysid, doctypePubid, 0); + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + /* doctypeSysid will be non-NULL in the case of a previous + XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler + was not set, indicating an external subset + */ +#ifdef XML_DTD + if (doctypeSysid || useForeignDTD) { + XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; + dtd->hasParamEntityRefs = XML_TRUE; + if (paramEntityParsing && externalEntityRefHandler) { + ENTITY *entity = (ENTITY *)lookup(parser, + &dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!entity) + return XML_ERROR_NO_MEMORY; + if (useForeignDTD) + entity->base = curBase; + dtd->paramEntityRead = XML_FALSE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + if (dtd->paramEntityRead) { + if (!dtd->standalone && + notStandaloneHandler && + !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; + } + /* if we didn't read the foreign DTD then this means that there + is no external subset and we must reset dtd->hasParamEntityRefs + */ + else if (!doctypeSysid) + dtd->hasParamEntityRefs = hadParamEntityRefs; + /* end of DTD - no need to update dtd->keepProcessing */ + } + useForeignDTD = XML_FALSE; + } +#endif /* XML_DTD */ + if (endDoctypeDeclHandler) { + endDoctypeDeclHandler(handlerArg); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_INSTANCE_START: +#ifdef XML_DTD + /* if there is no DOCTYPE declaration then now is the + last chance to read the foreign DTD + */ + if (useForeignDTD) { + XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; + dtd->hasParamEntityRefs = XML_TRUE; + if (paramEntityParsing && externalEntityRefHandler) { + ENTITY *entity = (ENTITY *)lookup(parser, &dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!entity) + return XML_ERROR_NO_MEMORY; + entity->base = curBase; + dtd->paramEntityRead = XML_FALSE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + if (dtd->paramEntityRead) { + if (!dtd->standalone && + notStandaloneHandler && + !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; + } + /* if we didn't read the foreign DTD then this means that there + is no external subset and we must reset dtd->hasParamEntityRefs + */ + else + dtd->hasParamEntityRefs = hadParamEntityRefs; + /* end of DTD - no need to update dtd->keepProcessing */ + } + } +#endif /* XML_DTD */ + processor = contentProcessor; + return contentProcessor(parser, s, end, nextPtr); + case XML_ROLE_ATTLIST_ELEMENT_NAME: + declElementType = getElementType(parser, enc, s, next); + if (!declElementType) + return XML_ERROR_NO_MEMORY; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_NAME: + declAttributeId = getAttributeId(parser, enc, s, next); + if (!declAttributeId) + return XML_ERROR_NO_MEMORY; + declAttributeIsCdata = XML_FALSE; + declAttributeType = NULL; + declAttributeIsId = XML_FALSE; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_CDATA: + declAttributeIsCdata = XML_TRUE; + declAttributeType = atypeCDATA; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_ID: + declAttributeIsId = XML_TRUE; + declAttributeType = atypeID; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_IDREF: + declAttributeType = atypeIDREF; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_IDREFS: + declAttributeType = atypeIDREFS; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_ENTITY: + declAttributeType = atypeENTITY; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_ENTITIES: + declAttributeType = atypeENTITIES; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN: + declAttributeType = atypeNMTOKEN; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS: + declAttributeType = atypeNMTOKENS; + checkAttListDeclHandler: + if (dtd->keepProcessing && attlistDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ATTRIBUTE_ENUM_VALUE: + case XML_ROLE_ATTRIBUTE_NOTATION_VALUE: + if (dtd->keepProcessing && attlistDeclHandler) { + const XML_Char *prefix; + if (declAttributeType) { + prefix = enumValueSep; + } + else { + prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE + ? notationPrefix + : enumValueStart); + } + if (!poolAppendString(&tempPool, prefix)) + return XML_ERROR_NO_MEMORY; + if (!poolAppend(&tempPool, enc, s, next)) + return XML_ERROR_NO_MEMORY; + declAttributeType = tempPool.start; + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE: + case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE: + if (dtd->keepProcessing) { + if (!defineAttribute(declElementType, declAttributeId, + declAttributeIsCdata, declAttributeIsId, + 0, parser)) + return XML_ERROR_NO_MEMORY; + if (attlistDeclHandler && declAttributeType) { + if (*declAttributeType == XML_T(ASCII_LPAREN) + || (*declAttributeType == XML_T(ASCII_N) + && declAttributeType[1] == XML_T(ASCII_O))) { + /* Enumerated or Notation type */ + if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) + || !poolAppendChar(&tempPool, XML_T('\0'))) + return XML_ERROR_NO_MEMORY; + declAttributeType = tempPool.start; + poolFinish(&tempPool); + } + *eventEndPP = s; + attlistDeclHandler(handlerArg, declElementType->name, + declAttributeId->name, declAttributeType, + 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE: + case XML_ROLE_FIXED_ATTRIBUTE_VALUE: + if (dtd->keepProcessing) { + const XML_Char *attVal; + enum XML_Error result = + storeAttributeValue(parser, enc, declAttributeIsCdata, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar, + &dtd->pool); + if (result) + return result; + attVal = poolStart(&dtd->pool); + poolFinish(&dtd->pool); + /* ID attributes aren't allowed to have a default */ + if (!defineAttribute(declElementType, declAttributeId, + declAttributeIsCdata, XML_FALSE, attVal, parser)) + return XML_ERROR_NO_MEMORY; + if (attlistDeclHandler && declAttributeType) { + if (*declAttributeType == XML_T(ASCII_LPAREN) + || (*declAttributeType == XML_T(ASCII_N) + && declAttributeType[1] == XML_T(ASCII_O))) { + /* Enumerated or Notation type */ + if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) + || !poolAppendChar(&tempPool, XML_T('\0'))) + return XML_ERROR_NO_MEMORY; + declAttributeType = tempPool.start; + poolFinish(&tempPool); + } + *eventEndPP = s; + attlistDeclHandler(handlerArg, declElementType->name, + declAttributeId->name, declAttributeType, + attVal, + role == XML_ROLE_FIXED_ATTRIBUTE_VALUE); + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_ENTITY_VALUE: + if (dtd->keepProcessing) { + enum XML_Error result = storeEntityValue(parser, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (declEntity) { + declEntity->textPtr = poolStart(&dtd->entityValuePool); + declEntity->textLen = (int)(poolLength(&dtd->entityValuePool)); + poolFinish(&dtd->entityValuePool); + if (entityDeclHandler) { + *eventEndPP = s; + entityDeclHandler(handlerArg, + declEntity->name, + declEntity->is_param, + declEntity->textPtr, + declEntity->textLen, + curBase, 0, 0, 0); + handleDefault = XML_FALSE; + } + } + else + poolDiscard(&dtd->entityValuePool); + if (result != XML_ERROR_NONE) + return result; + } + break; + case XML_ROLE_DOCTYPE_SYSTEM_ID: +#ifdef XML_DTD + useForeignDTD = XML_FALSE; +#endif /* XML_DTD */ + dtd->hasParamEntityRefs = XML_TRUE; + if (startDoctypeDeclHandler) { + doctypeSysid = poolStoreString(&tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (doctypeSysid == NULL) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + handleDefault = XML_FALSE; + } +#ifdef XML_DTD + else + /* use externalSubsetName to make doctypeSysid non-NULL + for the case where no startDoctypeDeclHandler is set */ + doctypeSysid = externalSubsetName; +#endif /* XML_DTD */ + if (!dtd->standalone +#ifdef XML_DTD + && !paramEntityParsing +#endif /* XML_DTD */ + && notStandaloneHandler + && !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; +#ifndef XML_DTD + break; +#else /* XML_DTD */ + if (!declEntity) { + declEntity = (ENTITY *)lookup(parser, + &dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; + declEntity->publicId = NULL; + } + /* fall through */ +#endif /* XML_DTD */ + case XML_ROLE_ENTITY_SYSTEM_ID: + if (dtd->keepProcessing && declEntity) { + declEntity->systemId = poolStoreString(&dtd->pool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!declEntity->systemId) + return XML_ERROR_NO_MEMORY; + declEntity->base = curBase; + poolFinish(&dtd->pool); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_ENTITY_COMPLETE: + if (dtd->keepProcessing && declEntity && entityDeclHandler) { + *eventEndPP = s; + entityDeclHandler(handlerArg, + declEntity->name, + declEntity->is_param, + 0,0, + declEntity->base, + declEntity->systemId, + declEntity->publicId, + 0); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_ENTITY_NOTATION_NAME: + if (dtd->keepProcessing && declEntity) { + declEntity->notation = poolStoreString(&dtd->pool, enc, s, next); + if (!declEntity->notation) + return XML_ERROR_NO_MEMORY; + poolFinish(&dtd->pool); + if (unparsedEntityDeclHandler) { + *eventEndPP = s; + unparsedEntityDeclHandler(handlerArg, + declEntity->name, + declEntity->base, + declEntity->systemId, + declEntity->publicId, + declEntity->notation); + handleDefault = XML_FALSE; + } + else if (entityDeclHandler) { + *eventEndPP = s; + entityDeclHandler(handlerArg, + declEntity->name, + 0,0,0, + declEntity->base, + declEntity->systemId, + declEntity->publicId, + declEntity->notation); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_GENERAL_ENTITY_NAME: + { + if (XmlPredefinedEntityName(enc, s, next)) { + declEntity = NULL; + break; + } + if (dtd->keepProcessing) { + const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); + if (!name) + return XML_ERROR_NO_MEMORY; + declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, + sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; + if (declEntity->name != name) { + poolDiscard(&dtd->pool); + declEntity = NULL; + } + else { + poolFinish(&dtd->pool); + declEntity->publicId = NULL; + declEntity->is_param = XML_FALSE; + /* if we have a parent parser or are reading an internal parameter + entity, then the entity declaration is not considered "internal" + */ + declEntity->is_internal = !(parentParser || openInternalEntities); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + } + else { + poolDiscard(&dtd->pool); + declEntity = NULL; + } + } + break; + case XML_ROLE_PARAM_ENTITY_NAME: +#ifdef XML_DTD + if (dtd->keepProcessing) { + const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); + if (!name) + return XML_ERROR_NO_MEMORY; + declEntity = (ENTITY *)lookup(parser, &dtd->paramEntities, + name, sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; + if (declEntity->name != name) { + poolDiscard(&dtd->pool); + declEntity = NULL; + } + else { + poolFinish(&dtd->pool); + declEntity->publicId = NULL; + declEntity->is_param = XML_TRUE; + /* if we have a parent parser or are reading an internal parameter + entity, then the entity declaration is not considered "internal" + */ + declEntity->is_internal = !(parentParser || openInternalEntities); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + } + else { + poolDiscard(&dtd->pool); + declEntity = NULL; + } +#else /* not XML_DTD */ + declEntity = NULL; +#endif /* XML_DTD */ + break; + case XML_ROLE_NOTATION_NAME: + declNotationPublicId = NULL; + declNotationName = NULL; + if (notationDeclHandler) { + declNotationName = poolStoreString(&tempPool, enc, s, next); + if (!declNotationName) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_NOTATION_PUBLIC_ID: + if (!XmlIsPublicId(enc, s, next, eventPP)) + return XML_ERROR_PUBLICID; + if (declNotationName) { /* means notationDeclHandler != NULL */ + XML_Char *tem = poolStoreString(&tempPool, + enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!tem) + return XML_ERROR_NO_MEMORY; + normalizePublicId(tem); + declNotationPublicId = tem; + poolFinish(&tempPool); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_NOTATION_SYSTEM_ID: + if (declNotationName && notationDeclHandler) { + const XML_Char *systemId + = poolStoreString(&tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!systemId) + return XML_ERROR_NO_MEMORY; + *eventEndPP = s; + notationDeclHandler(handlerArg, + declNotationName, + curBase, + systemId, + declNotationPublicId); + handleDefault = XML_FALSE; + } + poolClear(&tempPool); + break; + case XML_ROLE_NOTATION_NO_SYSTEM_ID: + if (declNotationPublicId && notationDeclHandler) { + *eventEndPP = s; + notationDeclHandler(handlerArg, + declNotationName, + curBase, + 0, + declNotationPublicId); + handleDefault = XML_FALSE; + } + poolClear(&tempPool); + break; + case XML_ROLE_ERROR: + switch (tok) { + case XML_TOK_PARAM_ENTITY_REF: + /* PE references in internal subset are + not allowed within declarations. */ + return XML_ERROR_PARAM_ENTITY_REF; + case XML_TOK_XML_DECL: + return XML_ERROR_MISPLACED_XML_PI; + default: + return XML_ERROR_SYNTAX; + } +#ifdef XML_DTD + case XML_ROLE_IGNORE_SECT: + { + enum XML_Error result; + if (defaultHandler) + reportDefault(parser, enc, s, next); + handleDefault = XML_FALSE; + result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore); + if (result != XML_ERROR_NONE) + return result; + else if (!next) { + processor = ignoreSectionProcessor; + return result; + } + } + break; +#endif /* XML_DTD */ + case XML_ROLE_GROUP_OPEN: + if (prologState.level >= groupSize) { + if (groupSize) { + char *temp = (char *)REALLOC(groupConnector, groupSize *= 2); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + groupConnector = temp; + if (dtd->scaffIndex) { + int *temp = (int *)REALLOC(dtd->scaffIndex, + groupSize * sizeof(int)); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + dtd->scaffIndex = temp; + } + } + else { + groupConnector = (char *)MALLOC(groupSize = 32); + if (!groupConnector) + return XML_ERROR_NO_MEMORY; + } + } + groupConnector[prologState.level] = 0; + if (dtd->in_eldecl) { + int myindex = nextScaffoldPart(parser); + if (myindex < 0) + return XML_ERROR_NO_MEMORY; + dtd->scaffIndex[dtd->scaffLevel] = myindex; + dtd->scaffLevel++; + dtd->scaffold[myindex].type = XML_CTYPE_SEQ; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_GROUP_SEQUENCE: + if (groupConnector[prologState.level] == ASCII_PIPE) + return XML_ERROR_SYNTAX; + groupConnector[prologState.level] = ASCII_COMMA; + if (dtd->in_eldecl && elementDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_GROUP_CHOICE: + if (groupConnector[prologState.level] == ASCII_COMMA) + return XML_ERROR_SYNTAX; + if (dtd->in_eldecl + && !groupConnector[prologState.level] + && (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type + != XML_CTYPE_MIXED) + ) { + dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type + = XML_CTYPE_CHOICE; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + groupConnector[prologState.level] = ASCII_PIPE; + break; + case XML_ROLE_PARAM_ENTITY_REF: +#ifdef XML_DTD + case XML_ROLE_INNER_PARAM_ENTITY_REF: + dtd->hasParamEntityRefs = XML_TRUE; + if (!paramEntityParsing) + dtd->keepProcessing = dtd->standalone; + else { + const XML_Char *name; + ENTITY *entity; + name = poolStoreString(&dtd->pool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0); + poolDiscard(&dtd->pool); + /* first, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal, + otherwise call the skipped entity handler + */ + if (prologState.documentEntity && + (dtd->standalone + ? !openInternalEntities + : !dtd->hasParamEntityRefs)) { + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (!entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } + else if (!entity) { + dtd->keepProcessing = dtd->standalone; + /* cannot report skipped entities in declarations */ + if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) { + skippedEntityHandler(handlerArg, name, 1); + handleDefault = XML_FALSE; + } + break; + } + if (entity->open) + return XML_ERROR_RECURSIVE_ENTITY_REF; + if (entity->textPtr) { + enum XML_Error result; + XML_Bool betweenDecl = + (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE); + result = processInternalEntity(parser, entity, betweenDecl); + if (result != XML_ERROR_NONE) + return result; + handleDefault = XML_FALSE; + break; + } + if (externalEntityRefHandler) { + dtd->paramEntityRead = XML_FALSE; + entity->open = XML_TRUE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) { + entity->open = XML_FALSE; + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + } + entity->open = XML_FALSE; + handleDefault = XML_FALSE; + if (!dtd->paramEntityRead) { + dtd->keepProcessing = dtd->standalone; + break; + } + } + else { + dtd->keepProcessing = dtd->standalone; + break; + } + } +#endif /* XML_DTD */ + if (!dtd->standalone && + notStandaloneHandler && + !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; + break; + + /* Element declaration stuff */ + + case XML_ROLE_ELEMENT_NAME: + if (elementDeclHandler) { + declElementType = getElementType(parser, enc, s, next); + if (!declElementType) + return XML_ERROR_NO_MEMORY; + dtd->scaffLevel = 0; + dtd->scaffCount = 0; + dtd->in_eldecl = XML_TRUE; + handleDefault = XML_FALSE; + } + break; + + case XML_ROLE_CONTENT_ANY: + case XML_ROLE_CONTENT_EMPTY: + if (dtd->in_eldecl) { + if (elementDeclHandler) { + XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content)); + if (!content) + return XML_ERROR_NO_MEMORY; + content->quant = XML_CQUANT_NONE; + content->name = NULL; + content->numchildren = 0; + content->children = NULL; + content->type = ((role == XML_ROLE_CONTENT_ANY) ? + XML_CTYPE_ANY : + XML_CTYPE_EMPTY); + *eventEndPP = s; + elementDeclHandler(handlerArg, declElementType->name, content); + handleDefault = XML_FALSE; + } + dtd->in_eldecl = XML_FALSE; + } + break; + + case XML_ROLE_CONTENT_PCDATA: + if (dtd->in_eldecl) { + dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type + = XML_CTYPE_MIXED; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + break; + + case XML_ROLE_CONTENT_ELEMENT: + quant = XML_CQUANT_NONE; + goto elementContent; + case XML_ROLE_CONTENT_ELEMENT_OPT: + quant = XML_CQUANT_OPT; + goto elementContent; + case XML_ROLE_CONTENT_ELEMENT_REP: + quant = XML_CQUANT_REP; + goto elementContent; + case XML_ROLE_CONTENT_ELEMENT_PLUS: + quant = XML_CQUANT_PLUS; + elementContent: + if (dtd->in_eldecl) { + ELEMENT_TYPE *el; + const XML_Char *name; + int nameLen; + const char *nxt = (quant == XML_CQUANT_NONE + ? next + : next - enc->minBytesPerChar); + int myindex = nextScaffoldPart(parser); + if (myindex < 0) + return XML_ERROR_NO_MEMORY; + dtd->scaffold[myindex].type = XML_CTYPE_NAME; + dtd->scaffold[myindex].quant = quant; + el = getElementType(parser, enc, s, nxt); + if (!el) + return XML_ERROR_NO_MEMORY; + name = el->name; + dtd->scaffold[myindex].name = name; + nameLen = 0; + for (; name[nameLen++]; ); + dtd->contentStringLen += nameLen; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + break; + + case XML_ROLE_GROUP_CLOSE: + quant = XML_CQUANT_NONE; + goto closeGroup; + case XML_ROLE_GROUP_CLOSE_OPT: + quant = XML_CQUANT_OPT; + goto closeGroup; + case XML_ROLE_GROUP_CLOSE_REP: + quant = XML_CQUANT_REP; + goto closeGroup; + case XML_ROLE_GROUP_CLOSE_PLUS: + quant = XML_CQUANT_PLUS; + closeGroup: + if (dtd->in_eldecl) { + if (elementDeclHandler) + handleDefault = XML_FALSE; + dtd->scaffLevel--; + dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant; + if (dtd->scaffLevel == 0) { + if (!handleDefault) { + XML_Content *model = build_model(parser); + if (!model) + return XML_ERROR_NO_MEMORY; + *eventEndPP = s; + elementDeclHandler(handlerArg, declElementType->name, model); + } + dtd->in_eldecl = XML_FALSE; + dtd->contentStringLen = 0; + } + } + break; + /* End element declaration stuff */ + + case XML_ROLE_PI: + if (!reportProcessingInstruction(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + handleDefault = XML_FALSE; + break; + case XML_ROLE_COMMENT: + if (!reportComment(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + handleDefault = XML_FALSE; + break; + case XML_ROLE_NONE: + switch (tok) { + case XML_TOK_BOM: + handleDefault = XML_FALSE; + break; + } + break; + case XML_ROLE_DOCTYPE_NONE: + if (startDoctypeDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ENTITY_NONE: + if (dtd->keepProcessing && entityDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_NOTATION_NONE: + if (notationDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ATTLIST_NONE: + if (dtd->keepProcessing && attlistDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ELEMENT_NONE: + if (elementDeclHandler) + handleDefault = XML_FALSE; + break; + } /* end of big switch */ + + if (handleDefault && defaultHandler) + reportDefault(parser, enc, s, next); + + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + s = next; + tok = XmlPrologTok(enc, s, end, &next); + } + } + /* not reached */ +} + +static enum XML_Error PTRCALL +epilogProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + processor = epilogProcessor; + eventPtr = s; + for (;;) { + const char *next = NULL; + int tok = XmlPrologTok(encoding, s, end, &next); + eventEndPtr = next; + switch (tok) { + /* report partial linebreak - it might be the last token */ + case -XML_TOK_PROLOG_S: + if (defaultHandler) { + reportDefault(parser, encoding, s, next); + if (ps_parsing == XML_FINISHED) + return XML_ERROR_ABORTED; + } + *nextPtr = next; + return XML_ERROR_NONE; + case XML_TOK_NONE: + *nextPtr = s; + return XML_ERROR_NONE; + case XML_TOK_PROLOG_S: + if (defaultHandler) + reportDefault(parser, encoding, s, next); + break; + case XML_TOK_PI: + if (!reportProcessingInstruction(parser, encoding, s, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_COMMENT: + if (!reportComment(parser, encoding, s, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_INVALID: + eventPtr = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + if (!ps_finalBuffer) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (!ps_finalBuffer) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + default: + return XML_ERROR_JUNK_AFTER_DOC_ELEMENT; + } + eventPtr = s = next; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: ; + } + } +} + +static enum XML_Error +processInternalEntity(XML_Parser parser, ENTITY *entity, + XML_Bool betweenDecl) +{ + const char *textStart, *textEnd; + const char *next; + enum XML_Error result; + OPEN_INTERNAL_ENTITY *openEntity; + + if (freeInternalEntities) { + openEntity = freeInternalEntities; + freeInternalEntities = openEntity->next; + } + else { + openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(sizeof(OPEN_INTERNAL_ENTITY)); + if (!openEntity) + return XML_ERROR_NO_MEMORY; + } + entity->open = XML_TRUE; + entity->processed = 0; + openEntity->next = openInternalEntities; + openInternalEntities = openEntity; + openEntity->entity = entity; + openEntity->startTagLevel = tagLevel; + openEntity->betweenDecl = betweenDecl; + openEntity->internalEventPtr = NULL; + openEntity->internalEventEndPtr = NULL; + textStart = (char *)entity->textPtr; + textEnd = (char *)(entity->textPtr + entity->textLen); + +#ifdef XML_DTD + if (entity->is_param) { + int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); + result = doProlog(parser, internalEncoding, textStart, textEnd, tok, + next, &next, XML_FALSE); + } + else +#endif /* XML_DTD */ + result = doContent(parser, tagLevel, internalEncoding, textStart, + textEnd, &next, XML_FALSE); + + if (result == XML_ERROR_NONE) { + if (textEnd != next && ps_parsing == XML_SUSPENDED) { + entity->processed = (int)(next - textStart); + processor = internalEntityProcessor; + } + else { + entity->open = XML_FALSE; + openInternalEntities = openEntity->next; + /* put openEntity back in list of free instances */ + openEntity->next = freeInternalEntities; + freeInternalEntities = openEntity; + } + } + return result; +} + +static enum XML_Error PTRCALL +internalEntityProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + ENTITY *entity; + const char *textStart, *textEnd; + const char *next; + enum XML_Error result; + OPEN_INTERNAL_ENTITY *openEntity = openInternalEntities; + if (!openEntity) + return XML_ERROR_UNEXPECTED_STATE; + + entity = openEntity->entity; + textStart = ((char *)entity->textPtr) + entity->processed; + textEnd = (char *)(entity->textPtr + entity->textLen); + +#ifdef XML_DTD + if (entity->is_param) { + int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); + result = doProlog(parser, internalEncoding, textStart, textEnd, tok, + next, &next, XML_FALSE); + } + else +#endif /* XML_DTD */ + result = doContent(parser, openEntity->startTagLevel, internalEncoding, + textStart, textEnd, &next, XML_FALSE); + + if (result != XML_ERROR_NONE) + return result; + else if (textEnd != next && ps_parsing == XML_SUSPENDED) { + entity->processed = (int)(next - (char *)entity->textPtr); + return result; + } + else { + entity->open = XML_FALSE; + openInternalEntities = openEntity->next; + /* put openEntity back in list of free instances */ + openEntity->next = freeInternalEntities; + freeInternalEntities = openEntity; + } + +#ifdef XML_DTD + if (entity->is_param) { + int tok; + processor = prologProcessor; + tok = XmlPrologTok(encoding, s, end, &next); + return doProlog(parser, encoding, s, end, tok, next, nextPtr, + (XML_Bool)!ps_finalBuffer); + } + else +#endif /* XML_DTD */ + { + processor = contentProcessor; + /* see externalEntityContentProcessor vs contentProcessor */ + return doContent(parser, parentParser ? 1 : 0, encoding, s, end, + nextPtr, (XML_Bool)!ps_finalBuffer); + } +} + +static enum XML_Error PTRCALL +errorProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + return errorCode; +} + +static enum XML_Error +storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, + const char *ptr, const char *end, + STRING_POOL *pool) +{ + enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, + end, pool); + if (result) + return result; + if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) + poolChop(pool); + if (!poolAppendChar(pool, XML_T('\0'))) + return XML_ERROR_NO_MEMORY; + return XML_ERROR_NONE; +} + +static enum XML_Error +appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, + const char *ptr, const char *end, + STRING_POOL *pool) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + for (;;) { + const char *next; + int tok = XmlAttributeValueTok(enc, ptr, end, &next); + switch (tok) { + case XML_TOK_NONE: + return XML_ERROR_NONE; + case XML_TOK_INVALID: + if (enc == encoding) + eventPtr = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_CHAR_REF: + { + XML_Char buf[XML_ENCODE_MAX]; + int i; + int n = XmlCharRefNumber(enc, ptr); + if (n < 0) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_BAD_CHAR_REF; + } + if (!isCdata + && n == 0x20 /* space */ + && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) + break; + n = XmlEncode(n, (ICHAR *)buf); + if (!n) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_BAD_CHAR_REF; + } + for (i = 0; i < n; i++) { + if (!poolAppendChar(pool, buf[i])) + return XML_ERROR_NO_MEMORY; + } + } + break; + case XML_TOK_DATA_CHARS: + if (!poolAppend(pool, enc, ptr, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_TRAILING_CR: + next = ptr + enc->minBytesPerChar; + /* fall through */ + case XML_TOK_ATTRIBUTE_VALUE_S: + case XML_TOK_DATA_NEWLINE: + if (!isCdata && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) + break; + if (!poolAppendChar(pool, 0x20)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_ENTITY_REF: + { + const XML_Char *name; + ENTITY *entity; + char checkEntityDecl; + XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, + ptr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (ch) { + if (!poolAppendChar(pool, ch)) + return XML_ERROR_NO_MEMORY; + break; + } + name = poolStoreString(&temp2Pool, enc, + ptr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); + poolDiscard(&temp2Pool); + /* First, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal. + */ + if (pool == &dtd->pool) /* are we called from prolog? */ + checkEntityDecl = +#ifdef XML_DTD + prologState.documentEntity && +#endif /* XML_DTD */ + (dtd->standalone + ? !openInternalEntities + : !dtd->hasParamEntityRefs); + else /* if (pool == &tempPool): we are called from content */ + checkEntityDecl = !dtd->hasParamEntityRefs || dtd->standalone; + if (checkEntityDecl) { + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (!entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } + else if (!entity) { + /* Cannot report skipped entity here - see comments on + skippedEntityHandler. + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, name, 0); + */ + /* Cannot call the default handler because this would be + out of sync with the call to the startElementHandler. + if ((pool == &tempPool) && defaultHandler) + reportDefault(parser, enc, ptr, next); + */ + break; + } + if (entity->open) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_RECURSIVE_ENTITY_REF; + } + if (entity->notation) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_BINARY_ENTITY_REF; + } + if (!entity->textPtr) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF; + } + else { + enum XML_Error result; + const XML_Char *textEnd = entity->textPtr + entity->textLen; + entity->open = XML_TRUE; + result = appendAttributeValue(parser, internalEncoding, isCdata, + (char *)entity->textPtr, + (char *)textEnd, pool); + entity->open = XML_FALSE; + if (result) + return result; + } + } + break; + default: + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_UNEXPECTED_STATE; + } + ptr = next; + } + /* not reached */ +} + +static enum XML_Error +storeEntityValue(XML_Parser parser, + const ENCODING *enc, + const char *entityTextPtr, + const char *entityTextEnd) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + STRING_POOL *pool = &(dtd->entityValuePool); + enum XML_Error result = XML_ERROR_NONE; +#ifdef XML_DTD + int oldInEntityValue = prologState.inEntityValue; + prologState.inEntityValue = 1; +#endif /* XML_DTD */ + /* never return Null for the value argument in EntityDeclHandler, + since this would indicate an external entity; therefore we + have to make sure that entityValuePool.start is not null */ + if (!pool->blocks) { + if (!poolGrow(pool)) + return XML_ERROR_NO_MEMORY; + } + + for (;;) { + const char *next; + int tok = XmlEntityValueTok(enc, entityTextPtr, entityTextEnd, &next); + switch (tok) { + case XML_TOK_PARAM_ENTITY_REF: +#ifdef XML_DTD + if (isParamEntity || enc != encoding) { + const XML_Char *name; + ENTITY *entity; + name = poolStoreString(&tempPool, enc, + entityTextPtr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0); + poolDiscard(&tempPool); + if (!entity) { + /* not a well-formedness error - see XML 1.0: WFC Entity Declared */ + /* cannot report skipped entity here - see comments on + skippedEntityHandler + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, name, 0); + */ + dtd->keepProcessing = dtd->standalone; + goto endEntityValue; + } + if (entity->open) { + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_RECURSIVE_ENTITY_REF; + goto endEntityValue; + } + if (entity->systemId) { + if (externalEntityRefHandler) { + dtd->paramEntityRead = XML_FALSE; + entity->open = XML_TRUE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) { + entity->open = XML_FALSE; + result = XML_ERROR_EXTERNAL_ENTITY_HANDLING; + goto endEntityValue; + } + entity->open = XML_FALSE; + if (!dtd->paramEntityRead) + dtd->keepProcessing = dtd->standalone; + } + else + dtd->keepProcessing = dtd->standalone; + } + else { + entity->open = XML_TRUE; + result = storeEntityValue(parser, + internalEncoding, + (char *)entity->textPtr, + (char *)(entity->textPtr + + entity->textLen)); + entity->open = XML_FALSE; + if (result) + goto endEntityValue; + } + break; + } +#endif /* XML_DTD */ + /* In the internal subset, PE references are not legal + within markup declarations, e.g entity values in this case. */ + eventPtr = entityTextPtr; + result = XML_ERROR_PARAM_ENTITY_REF; + goto endEntityValue; + case XML_TOK_NONE: + result = XML_ERROR_NONE; + goto endEntityValue; + case XML_TOK_ENTITY_REF: + case XML_TOK_DATA_CHARS: + if (!poolAppend(pool, enc, entityTextPtr, next)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + break; + case XML_TOK_TRAILING_CR: + next = entityTextPtr + enc->minBytesPerChar; + /* fall through */ + case XML_TOK_DATA_NEWLINE: + if (pool->end == pool->ptr && !poolGrow(pool)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + *(pool->ptr)++ = 0xA; + break; + case XML_TOK_CHAR_REF: + { + XML_Char buf[XML_ENCODE_MAX]; + int i; + int n = XmlCharRefNumber(enc, entityTextPtr); + if (n < 0) { + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_BAD_CHAR_REF; + goto endEntityValue; + } + n = XmlEncode(n, (ICHAR *)buf); + if (!n) { + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_BAD_CHAR_REF; + goto endEntityValue; + } + for (i = 0; i < n; i++) { + if (pool->end == pool->ptr && !poolGrow(pool)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + *(pool->ptr)++ = buf[i]; + } + } + break; + case XML_TOK_PARTIAL: + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_INVALID_TOKEN; + goto endEntityValue; + case XML_TOK_INVALID: + if (enc == encoding) + eventPtr = next; + result = XML_ERROR_INVALID_TOKEN; + goto endEntityValue; + default: + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_UNEXPECTED_STATE; + goto endEntityValue; + } + entityTextPtr = next; + } +endEntityValue: +#ifdef XML_DTD + prologState.inEntityValue = oldInEntityValue; +#endif /* XML_DTD */ + return result; +} + +static void FASTCALL +normalizeLines(XML_Char *s) +{ + XML_Char *p; + for (;; s++) { + if (*s == XML_T('\0')) + return; + if (*s == 0xD) + break; + } + p = s; + do { + if (*s == 0xD) { + *p++ = 0xA; + if (*++s == 0xA) + s++; + } + else + *p++ = *s++; + } while (*s); + *p = XML_T('\0'); +} + +static int +reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end) +{ + const XML_Char *target; + XML_Char *data; + const char *tem; + if (!processingInstructionHandler) { + if (defaultHandler) + reportDefault(parser, enc, start, end); + return 1; + } + start += enc->minBytesPerChar * 2; + tem = start + XmlNameLength(enc, start); + target = poolStoreString(&tempPool, enc, start, tem); + if (!target) + return 0; + poolFinish(&tempPool); + data = poolStoreString(&tempPool, enc, + XmlSkipS(enc, tem), + end - enc->minBytesPerChar*2); + if (!data) + return 0; + normalizeLines(data); + processingInstructionHandler(handlerArg, target, data); + poolClear(&tempPool); + return 1; +} + +static int +reportComment(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end) +{ + XML_Char *data; + if (!commentHandler) { + if (defaultHandler) + reportDefault(parser, enc, start, end); + return 1; + } + data = poolStoreString(&tempPool, + enc, + start + enc->minBytesPerChar * 4, + end - enc->minBytesPerChar * 3); + if (!data) + return 0; + normalizeLines(data); + commentHandler(handlerArg, data); + poolClear(&tempPool); + return 1; +} + +static void +reportDefault(XML_Parser parser, const ENCODING *enc, + const char *s, const char *end) +{ + if (MUST_CONVERT(enc, s)) { + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + do { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = s; + defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); + *eventPP = s; + } while (s != end); + } + else + defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); +} + + +static int +defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, + XML_Bool isId, const XML_Char *value, XML_Parser parser) +{ + DEFAULT_ATTRIBUTE *att; + if (value || isId) { + /* The handling of default attributes gets messed up if we have + a default which duplicates a non-default. */ + int i; + for (i = 0; i < type->nDefaultAtts; i++) + if (attId == type->defaultAtts[i].id) + return 1; + if (isId && !type->idAtt && !attId->xmlns) + type->idAtt = attId; + } + if (type->nDefaultAtts == type->allocDefaultAtts) { + if (type->allocDefaultAtts == 0) { + type->allocDefaultAtts = 8; + type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(type->allocDefaultAtts + * sizeof(DEFAULT_ATTRIBUTE)); + if (!type->defaultAtts) + return 0; + } + else { + DEFAULT_ATTRIBUTE *temp; + int count = type->allocDefaultAtts * 2; + temp = (DEFAULT_ATTRIBUTE *) + REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE))); + if (temp == NULL) + return 0; + type->allocDefaultAtts = count; + type->defaultAtts = temp; + } + } + att = type->defaultAtts + type->nDefaultAtts; + att->id = attId; + att->value = value; + att->isCdata = isCdata; + if (!isCdata) + attId->maybeTokenized = XML_TRUE; + type->nDefaultAtts += 1; + return 1; +} + +static int +setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + const XML_Char *name; + for (name = elementType->name; *name; name++) { + if (*name == XML_T(ASCII_COLON)) { + PREFIX *prefix; + const XML_Char *s; + for (s = elementType->name; s != name; s++) { + if (!poolAppendChar(&dtd->pool, *s)) + return 0; + } + if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + return 0; + prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool), + sizeof(PREFIX)); + if (!prefix) + return 0; + if (prefix->name == poolStart(&dtd->pool)) + poolFinish(&dtd->pool); + else + poolDiscard(&dtd->pool); + elementType->prefix = prefix; + + } + } + return 1; +} + +static ATTRIBUTE_ID * +getAttributeId(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + ATTRIBUTE_ID *id; + const XML_Char *name; + if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + return NULL; + name = poolStoreString(&dtd->pool, enc, start, end); + if (!name) + return NULL; + /* skip quotation mark - its storage will be re-used (like in name[-1]) */ + ++name; + id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); + if (!id) + return NULL; + if (id->name != name) + poolDiscard(&dtd->pool); + else { + poolFinish(&dtd->pool); + if (!ns) + ; + else if (name[0] == XML_T(ASCII_x) + && name[1] == XML_T(ASCII_m) + && name[2] == XML_T(ASCII_l) + && name[3] == XML_T(ASCII_n) + && name[4] == XML_T(ASCII_s) + && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) { + if (name[5] == XML_T('\0')) + id->prefix = &dtd->defaultPrefix; + else + id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, name + 6, sizeof(PREFIX)); + id->xmlns = XML_TRUE; + } + else { + int i; + for (i = 0; name[i]; i++) { + /* attributes without prefix are *not* in the default namespace */ + if (name[i] == XML_T(ASCII_COLON)) { + int j; + for (j = 0; j < i; j++) { + if (!poolAppendChar(&dtd->pool, name[j])) + return NULL; + } + if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + return NULL; + id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool), + sizeof(PREFIX)); + if (id->prefix->name == poolStart(&dtd->pool)) + poolFinish(&dtd->pool); + else + poolDiscard(&dtd->pool); + break; + } + } + } + } + return id; +} + +#define CONTEXT_SEP XML_T(ASCII_FF) + +static const XML_Char * +getContext(XML_Parser parser) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + HASH_TABLE_ITER iter; + XML_Bool needSep = XML_FALSE; + + if (dtd->defaultPrefix.binding) { + int i; + int len; + if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) + return NULL; + len = dtd->defaultPrefix.binding->uriLen; + if (namespaceSeparator) + len--; + for (i = 0; i < len; i++) + if (!poolAppendChar(&tempPool, dtd->defaultPrefix.binding->uri[i])) + return NULL; + needSep = XML_TRUE; + } + + hashTableIterInit(&iter, &(dtd->prefixes)); + for (;;) { + int i; + int len; + const XML_Char *s; + PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter); + if (!prefix) + break; + if (!prefix->binding) + continue; + if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) + return NULL; + for (s = prefix->name; *s; s++) + if (!poolAppendChar(&tempPool, *s)) + return NULL; + if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) + return NULL; + len = prefix->binding->uriLen; + if (namespaceSeparator) + len--; + for (i = 0; i < len; i++) + if (!poolAppendChar(&tempPool, prefix->binding->uri[i])) + return NULL; + needSep = XML_TRUE; + } + + + hashTableIterInit(&iter, &(dtd->generalEntities)); + for (;;) { + const XML_Char *s; + ENTITY *e = (ENTITY *)hashTableIterNext(&iter); + if (!e) + break; + if (!e->open) + continue; + if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) + return NULL; + for (s = e->name; *s; s++) + if (!poolAppendChar(&tempPool, *s)) + return 0; + needSep = XML_TRUE; + } + + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return NULL; + return tempPool.start; +} + +static XML_Bool +setContext(XML_Parser parser, const XML_Char *context) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + const XML_Char *s = context; + + while (*context != XML_T('\0')) { + if (*s == CONTEXT_SEP || *s == XML_T('\0')) { + ENTITY *e; + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return XML_FALSE; + e = (ENTITY *)lookup(parser, &dtd->generalEntities, poolStart(&tempPool), 0); + if (e) + e->open = XML_TRUE; + if (*s != XML_T('\0')) + s++; + context = s; + poolDiscard(&tempPool); + } + else if (*s == XML_T(ASCII_EQUALS)) { + PREFIX *prefix; + if (poolLength(&tempPool) == 0) + prefix = &dtd->defaultPrefix; + else { + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return XML_FALSE; + prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&tempPool), + sizeof(PREFIX)); + if (!prefix) + return XML_FALSE; + if (prefix->name == poolStart(&tempPool)) { + prefix->name = poolCopyString(&dtd->pool, prefix->name); + if (!prefix->name) + return XML_FALSE; + } + poolDiscard(&tempPool); + } + for (context = s + 1; + *context != CONTEXT_SEP && *context != XML_T('\0'); + context++) + if (!poolAppendChar(&tempPool, *context)) + return XML_FALSE; + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return XML_FALSE; + if (addBinding(parser, prefix, NULL, poolStart(&tempPool), + &inheritedBindings) != XML_ERROR_NONE) + return XML_FALSE; + poolDiscard(&tempPool); + if (*context != XML_T('\0')) + ++context; + s = context; + } + else { + if (!poolAppendChar(&tempPool, *s)) + return XML_FALSE; + s++; + } + } + return XML_TRUE; +} + +static void FASTCALL +normalizePublicId(XML_Char *publicId) +{ + XML_Char *p = publicId; + XML_Char *s; + for (s = publicId; *s; s++) { + switch (*s) { + case 0x20: + case 0xD: + case 0xA: + if (p != publicId && p[-1] != 0x20) + *p++ = 0x20; + break; + default: + *p++ = *s; + } + } + if (p != publicId && p[-1] == 0x20) + --p; + *p = XML_T('\0'); +} + +static DTD * +dtdCreate(const XML_Memory_Handling_Suite *ms) +{ + DTD *p = (DTD *)ms->malloc_fcn(sizeof(DTD)); + if (p == NULL) + return p; + poolInit(&(p->pool), ms); + poolInit(&(p->entityValuePool), ms); + hashTableInit(&(p->generalEntities), ms); + hashTableInit(&(p->elementTypes), ms); + hashTableInit(&(p->attributeIds), ms); + hashTableInit(&(p->prefixes), ms); +#ifdef XML_DTD + p->paramEntityRead = XML_FALSE; + hashTableInit(&(p->paramEntities), ms); +#endif /* XML_DTD */ + p->defaultPrefix.name = NULL; + p->defaultPrefix.binding = NULL; + + p->in_eldecl = XML_FALSE; + p->scaffIndex = NULL; + p->scaffold = NULL; + p->scaffLevel = 0; + p->scaffSize = 0; + p->scaffCount = 0; + p->contentStringLen = 0; + + p->keepProcessing = XML_TRUE; + p->hasParamEntityRefs = XML_FALSE; + p->standalone = XML_FALSE; + return p; +} + +static void +dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms) +{ + HASH_TABLE_ITER iter; + hashTableIterInit(&iter, &(p->elementTypes)); + for (;;) { + ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); + if (!e) + break; + if (e->allocDefaultAtts != 0) + ms->free_fcn(e->defaultAtts); + } + hashTableClear(&(p->generalEntities)); +#ifdef XML_DTD + p->paramEntityRead = XML_FALSE; + hashTableClear(&(p->paramEntities)); +#endif /* XML_DTD */ + hashTableClear(&(p->elementTypes)); + hashTableClear(&(p->attributeIds)); + hashTableClear(&(p->prefixes)); + poolClear(&(p->pool)); + poolClear(&(p->entityValuePool)); + p->defaultPrefix.name = NULL; + p->defaultPrefix.binding = NULL; + + p->in_eldecl = XML_FALSE; + + ms->free_fcn(p->scaffIndex); + p->scaffIndex = NULL; + ms->free_fcn(p->scaffold); + p->scaffold = NULL; + + p->scaffLevel = 0; + p->scaffSize = 0; + p->scaffCount = 0; + p->contentStringLen = 0; + + p->keepProcessing = XML_TRUE; + p->hasParamEntityRefs = XML_FALSE; + p->standalone = XML_FALSE; +} + +static void +dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms) +{ + HASH_TABLE_ITER iter; + hashTableIterInit(&iter, &(p->elementTypes)); + for (;;) { + ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); + if (!e) + break; + if (e->allocDefaultAtts != 0) + ms->free_fcn(e->defaultAtts); + } + hashTableDestroy(&(p->generalEntities)); +#ifdef XML_DTD + hashTableDestroy(&(p->paramEntities)); +#endif /* XML_DTD */ + hashTableDestroy(&(p->elementTypes)); + hashTableDestroy(&(p->attributeIds)); + hashTableDestroy(&(p->prefixes)); + poolDestroy(&(p->pool)); + poolDestroy(&(p->entityValuePool)); + if (isDocEntity) { + ms->free_fcn(p->scaffIndex); + ms->free_fcn(p->scaffold); + } + ms->free_fcn(p); +} + +/* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise. + The new DTD has already been initialized. +*/ +static int +dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) +{ + HASH_TABLE_ITER iter; + + /* Copy the prefix table. */ + + hashTableIterInit(&iter, &(oldDtd->prefixes)); + for (;;) { + const XML_Char *name; + const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter); + if (!oldP) + break; + name = poolCopyString(&(newDtd->pool), oldP->name); + if (!name) + return 0; + if (!lookup(oldParser, &(newDtd->prefixes), name, sizeof(PREFIX))) + return 0; + } + + hashTableIterInit(&iter, &(oldDtd->attributeIds)); + + /* Copy the attribute id table. */ + + for (;;) { + ATTRIBUTE_ID *newA; + const XML_Char *name; + const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter); + + if (!oldA) + break; + /* Remember to allocate the scratch byte before the name. */ + if (!poolAppendChar(&(newDtd->pool), XML_T('\0'))) + return 0; + name = poolCopyString(&(newDtd->pool), oldA->name); + if (!name) + return 0; + ++name; + newA = (ATTRIBUTE_ID *)lookup(oldParser, &(newDtd->attributeIds), name, + sizeof(ATTRIBUTE_ID)); + if (!newA) + return 0; + newA->maybeTokenized = oldA->maybeTokenized; + if (oldA->prefix) { + newA->xmlns = oldA->xmlns; + if (oldA->prefix == &oldDtd->defaultPrefix) + newA->prefix = &newDtd->defaultPrefix; + else + newA->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes), + oldA->prefix->name, 0); + } + } + + /* Copy the element type table. */ + + hashTableIterInit(&iter, &(oldDtd->elementTypes)); + + for (;;) { + int i; + ELEMENT_TYPE *newE; + const XML_Char *name; + const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter); + if (!oldE) + break; + name = poolCopyString(&(newDtd->pool), oldE->name); + if (!name) + return 0; + newE = (ELEMENT_TYPE *)lookup(oldParser, &(newDtd->elementTypes), name, + sizeof(ELEMENT_TYPE)); + if (!newE) + return 0; + if (oldE->nDefaultAtts) { + newE->defaultAtts = (DEFAULT_ATTRIBUTE *) + ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); + if (!newE->defaultAtts) { + ms->free_fcn(newE); + return 0; + } + } + if (oldE->idAtt) + newE->idAtt = (ATTRIBUTE_ID *) + lookup(oldParser, &(newDtd->attributeIds), oldE->idAtt->name, 0); + newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; + if (oldE->prefix) + newE->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes), + oldE->prefix->name, 0); + for (i = 0; i < newE->nDefaultAtts; i++) { + newE->defaultAtts[i].id = (ATTRIBUTE_ID *) + lookup(oldParser, &(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); + newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; + if (oldE->defaultAtts[i].value) { + newE->defaultAtts[i].value + = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value); + if (!newE->defaultAtts[i].value) + return 0; + } + else + newE->defaultAtts[i].value = NULL; + } + } + + /* Copy the entity tables. */ + if (!copyEntityTable(oldParser, + &(newDtd->generalEntities), + &(newDtd->pool), + &(oldDtd->generalEntities))) + return 0; + +#ifdef XML_DTD + if (!copyEntityTable(oldParser, + &(newDtd->paramEntities), + &(newDtd->pool), + &(oldDtd->paramEntities))) + return 0; + newDtd->paramEntityRead = oldDtd->paramEntityRead; +#endif /* XML_DTD */ + + newDtd->keepProcessing = oldDtd->keepProcessing; + newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs; + newDtd->standalone = oldDtd->standalone; + + /* Don't want deep copying for scaffolding */ + newDtd->in_eldecl = oldDtd->in_eldecl; + newDtd->scaffold = oldDtd->scaffold; + newDtd->contentStringLen = oldDtd->contentStringLen; + newDtd->scaffSize = oldDtd->scaffSize; + newDtd->scaffLevel = oldDtd->scaffLevel; + newDtd->scaffIndex = oldDtd->scaffIndex; + + return 1; +} /* End dtdCopy */ + +static int +copyEntityTable(XML_Parser oldParser, + HASH_TABLE *newTable, + STRING_POOL *newPool, + const HASH_TABLE *oldTable) +{ + HASH_TABLE_ITER iter; + const XML_Char *cachedOldBase = NULL; + const XML_Char *cachedNewBase = NULL; + + hashTableIterInit(&iter, oldTable); + + for (;;) { + ENTITY *newE; + const XML_Char *name; + const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter); + if (!oldE) + break; + name = poolCopyString(newPool, oldE->name); + if (!name) + return 0; + newE = (ENTITY *)lookup(oldParser, newTable, name, sizeof(ENTITY)); + if (!newE) + return 0; + if (oldE->systemId) { + const XML_Char *tem = poolCopyString(newPool, oldE->systemId); + if (!tem) + return 0; + newE->systemId = tem; + if (oldE->base) { + if (oldE->base == cachedOldBase) + newE->base = cachedNewBase; + else { + cachedOldBase = oldE->base; + tem = poolCopyString(newPool, cachedOldBase); + if (!tem) + return 0; + cachedNewBase = newE->base = tem; + } + } + if (oldE->publicId) { + tem = poolCopyString(newPool, oldE->publicId); + if (!tem) + return 0; + newE->publicId = tem; + } + } + else { + const XML_Char *tem = poolCopyStringN(newPool, oldE->textPtr, + oldE->textLen); + if (!tem) + return 0; + newE->textPtr = tem; + newE->textLen = oldE->textLen; + } + if (oldE->notation) { + const XML_Char *tem = poolCopyString(newPool, oldE->notation); + if (!tem) + return 0; + newE->notation = tem; + } + newE->is_param = oldE->is_param; + newE->is_internal = oldE->is_internal; + } + return 1; +} + +#define INIT_POWER 6 + +static XML_Bool FASTCALL +keyeq(KEY s1, KEY s2) +{ + for (; *s1 == *s2; s1++, s2++) + if (*s1 == 0) + return XML_TRUE; + return XML_FALSE; +} + +static unsigned long FASTCALL +hash(XML_Parser parser, KEY s) +{ + unsigned long h = hash_secret_salt; + while (*s) + h = CHAR_HASH(h, *s++); + return h; +} + +static NAMED * +lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) +{ + size_t i; + if (table->size == 0) { + size_t tsize; + if (!createSize) + return NULL; + table->power = INIT_POWER; + /* table->size is a power of 2 */ + table->size = (size_t)1 << INIT_POWER; + tsize = table->size * sizeof(NAMED *); + table->v = (NAMED **)table->mem->malloc_fcn(tsize); + if (!table->v) { + table->size = 0; + return NULL; + } + memset(table->v, 0, tsize); + i = hash(parser, name) & ((unsigned long)table->size - 1); + } + else { + unsigned long h = hash(parser, name); + unsigned long mask = (unsigned long)table->size - 1; + unsigned char step = 0; + i = h & mask; + while (table->v[i]) { + if (keyeq(name, table->v[i]->name)) + return table->v[i]; + if (!step) + step = PROBE_STEP(h, mask, table->power); + i < step ? (i += table->size - step) : (i -= step); + } + if (!createSize) + return NULL; + + /* check for overflow (table is half full) */ + if (table->used >> (table->power - 1)) { + unsigned char newPower = table->power + 1; + size_t newSize = (size_t)1 << newPower; + unsigned long newMask = (unsigned long)newSize - 1; + size_t tsize = newSize * sizeof(NAMED *); + NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); + if (!newV) + return NULL; + memset(newV, 0, tsize); + for (i = 0; i < table->size; i++) + if (table->v[i]) { + unsigned long newHash = hash(parser, table->v[i]->name); + size_t j = newHash & newMask; + step = 0; + while (newV[j]) { + if (!step) + step = PROBE_STEP(newHash, newMask, newPower); + j < step ? (j += newSize - step) : (j -= step); + } + newV[j] = table->v[i]; + } + table->mem->free_fcn(table->v); + table->v = newV; + table->power = newPower; + table->size = newSize; + i = h & newMask; + step = 0; + while (table->v[i]) { + if (!step) + step = PROBE_STEP(h, newMask, newPower); + i < step ? (i += newSize - step) : (i -= step); + } + } + } + table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize); + if (!table->v[i]) + return NULL; + memset(table->v[i], 0, createSize); + table->v[i]->name = name; + (table->used)++; + return table->v[i]; +} + +static void FASTCALL +hashTableClear(HASH_TABLE *table) +{ + size_t i; + for (i = 0; i < table->size; i++) { + table->mem->free_fcn(table->v[i]); + table->v[i] = NULL; + } + table->used = 0; +} + +static void FASTCALL +hashTableDestroy(HASH_TABLE *table) +{ + size_t i; + for (i = 0; i < table->size; i++) + table->mem->free_fcn(table->v[i]); + table->mem->free_fcn(table->v); +} + +static void FASTCALL +hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms) +{ + p->power = 0; + p->size = 0; + p->used = 0; + p->v = NULL; + p->mem = ms; +} + +static void FASTCALL +hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) +{ + iter->p = table->v; + iter->end = iter->p + table->size; +} + +static NAMED * FASTCALL +hashTableIterNext(HASH_TABLE_ITER *iter) +{ + while (iter->p != iter->end) { + NAMED *tem = *(iter->p)++; + if (tem) + return tem; + } + return NULL; +} + +static void FASTCALL +poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms) +{ + pool->blocks = NULL; + pool->freeBlocks = NULL; + pool->start = NULL; + pool->ptr = NULL; + pool->end = NULL; + pool->mem = ms; +} + +static void FASTCALL +poolClear(STRING_POOL *pool) +{ + if (!pool->freeBlocks) + pool->freeBlocks = pool->blocks; + else { + BLOCK *p = pool->blocks; + while (p) { + BLOCK *tem = p->next; + p->next = pool->freeBlocks; + pool->freeBlocks = p; + p = tem; + } + } + pool->blocks = NULL; + pool->start = NULL; + pool->ptr = NULL; + pool->end = NULL; +} + +static void FASTCALL +poolDestroy(STRING_POOL *pool) +{ + BLOCK *p = pool->blocks; + while (p) { + BLOCK *tem = p->next; + pool->mem->free_fcn(p); + p = tem; + } + p = pool->freeBlocks; + while (p) { + BLOCK *tem = p->next; + pool->mem->free_fcn(p); + p = tem; + } +} + +static XML_Char * +poolAppend(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end) +{ + if (!pool->ptr && !poolGrow(pool)) + return NULL; + for (;;) { + XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); + if (ptr == end) + break; + if (!poolGrow(pool)) + return NULL; + } + return pool->start; +} + +static const XML_Char * FASTCALL +poolCopyString(STRING_POOL *pool, const XML_Char *s) +{ + do { + if (!poolAppendChar(pool, *s)) + return NULL; + } while (*s++); + s = pool->start; + poolFinish(pool); + return s; +} + +static const XML_Char * +poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n) +{ + if (!pool->ptr && !poolGrow(pool)) + return NULL; + for (; n > 0; --n, s++) { + if (!poolAppendChar(pool, *s)) + return NULL; + } + s = pool->start; + poolFinish(pool); + return s; +} + +static const XML_Char * FASTCALL +poolAppendString(STRING_POOL *pool, const XML_Char *s) +{ + while (*s) { + if (!poolAppendChar(pool, *s)) + return NULL; + s++; + } + return pool->start; +} + +static XML_Char * +poolStoreString(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end) +{ + if (!poolAppend(pool, enc, ptr, end)) + return NULL; + if (pool->ptr == pool->end && !poolGrow(pool)) + return NULL; + *(pool->ptr)++ = 0; + return pool->start; +} + +static XML_Bool FASTCALL +poolGrow(STRING_POOL *pool) +{ + if (pool->freeBlocks) { + if (pool->start == 0) { + pool->blocks = pool->freeBlocks; + pool->freeBlocks = pool->freeBlocks->next; + pool->blocks->next = NULL; + pool->start = pool->blocks->s; + pool->end = pool->start + pool->blocks->size; + pool->ptr = pool->start; + return XML_TRUE; + } + if (pool->end - pool->start < pool->freeBlocks->size) { + BLOCK *tem = pool->freeBlocks->next; + pool->freeBlocks->next = pool->blocks; + pool->blocks = pool->freeBlocks; + pool->freeBlocks = tem; + memcpy(pool->blocks->s, pool->start, + (pool->end - pool->start) * sizeof(XML_Char)); + pool->ptr = pool->blocks->s + (pool->ptr - pool->start); + pool->start = pool->blocks->s; + pool->end = pool->start + pool->blocks->size; + return XML_TRUE; + } + } + if (pool->blocks && pool->start == pool->blocks->s) { + int blockSize = (int)(pool->end - pool->start)*2; + BLOCK *temp = (BLOCK *) + pool->mem->realloc_fcn(pool->blocks, + (offsetof(BLOCK, s) + + blockSize * sizeof(XML_Char))); + if (temp == NULL) + return XML_FALSE; + pool->blocks = temp; + pool->blocks->size = blockSize; + pool->ptr = pool->blocks->s + (pool->ptr - pool->start); + pool->start = pool->blocks->s; + pool->end = pool->start + blockSize; + } + else { + BLOCK *tem; + int blockSize = (int)(pool->end - pool->start); + if (blockSize < INIT_BLOCK_SIZE) + blockSize = INIT_BLOCK_SIZE; + else + blockSize *= 2; + tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s) + + blockSize * sizeof(XML_Char)); + if (!tem) + return XML_FALSE; + tem->size = blockSize; + tem->next = pool->blocks; + pool->blocks = tem; + if (pool->ptr != pool->start) + memcpy(tem->s, pool->start, + (pool->ptr - pool->start) * sizeof(XML_Char)); + pool->ptr = tem->s + (pool->ptr - pool->start); + pool->start = tem->s; + pool->end = tem->s + blockSize; + } + return XML_TRUE; +} + +static int FASTCALL +nextScaffoldPart(XML_Parser parser) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + CONTENT_SCAFFOLD * me; + int next; + + if (!dtd->scaffIndex) { + dtd->scaffIndex = (int *)MALLOC(groupSize * sizeof(int)); + if (!dtd->scaffIndex) + return -1; + dtd->scaffIndex[0] = 0; + } + + if (dtd->scaffCount >= dtd->scaffSize) { + CONTENT_SCAFFOLD *temp; + if (dtd->scaffold) { + temp = (CONTENT_SCAFFOLD *) + REALLOC(dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); + if (temp == NULL) + return -1; + dtd->scaffSize *= 2; + } + else { + temp = (CONTENT_SCAFFOLD *)MALLOC(INIT_SCAFFOLD_ELEMENTS + * sizeof(CONTENT_SCAFFOLD)); + if (temp == NULL) + return -1; + dtd->scaffSize = INIT_SCAFFOLD_ELEMENTS; + } + dtd->scaffold = temp; + } + next = dtd->scaffCount++; + me = &dtd->scaffold[next]; + if (dtd->scaffLevel) { + CONTENT_SCAFFOLD *parent = &dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel-1]]; + if (parent->lastchild) { + dtd->scaffold[parent->lastchild].nextsib = next; + } + if (!parent->childcnt) + parent->firstchild = next; + parent->lastchild = next; + parent->childcnt++; + } + me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0; + return next; +} + +static void +build_node(XML_Parser parser, + int src_node, + XML_Content *dest, + XML_Content **contpos, + XML_Char **strpos) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + dest->type = dtd->scaffold[src_node].type; + dest->quant = dtd->scaffold[src_node].quant; + if (dest->type == XML_CTYPE_NAME) { + const XML_Char *src; + dest->name = *strpos; + src = dtd->scaffold[src_node].name; + for (;;) { + *(*strpos)++ = *src; + if (!*src) + break; + src++; + } + dest->numchildren = 0; + dest->children = NULL; + } + else { + unsigned int i; + int cn; + dest->numchildren = dtd->scaffold[src_node].childcnt; + dest->children = *contpos; + *contpos += dest->numchildren; + for (i = 0, cn = dtd->scaffold[src_node].firstchild; + i < dest->numchildren; + i++, cn = dtd->scaffold[cn].nextsib) { + build_node(parser, cn, &(dest->children[i]), contpos, strpos); + } + dest->name = NULL; + } +} + +static XML_Content * +build_model (XML_Parser parser) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + XML_Content *ret; + XML_Content *cpos; + XML_Char * str; + int allocsize = (dtd->scaffCount * sizeof(XML_Content) + + (dtd->contentStringLen * sizeof(XML_Char))); + + ret = (XML_Content *)MALLOC(allocsize); + if (!ret) + return NULL; + + str = (XML_Char *) (&ret[dtd->scaffCount]); + cpos = &ret[1]; + + build_node(parser, 0, ret, &cpos, &str); + return ret; +} + +static ELEMENT_TYPE * +getElementType(XML_Parser parser, + const ENCODING *enc, + const char *ptr, + const char *end) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end); + ELEMENT_TYPE *ret; + + if (!name) + return NULL; + ret = (ELEMENT_TYPE *) lookup(parser, &dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); + if (!ret) + return NULL; + if (ret->name != name) + poolDiscard(&dtd->pool); + else { + poolFinish(&dtd->pool); + if (!setElementTypePrefix(parser, ret)) + return NULL; + } + return ret; +} diff --git a/project/jni/expat/lib/xmlrole.c b/project/jni/expat/lib/xmlrole.c new file mode 100644 index 000000000..44772e21d --- /dev/null +++ b/project/jni/expat/lib/xmlrole.c @@ -0,0 +1,1336 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#include + +#ifdef COMPILED_FROM_DSP +#include "winconfig.h" +#elif defined(MACOS_CLASSIC) +#include "macconfig.h" +#elif defined(__amigaos__) +#include "amigaconfig.h" +#elif defined(__WATCOMC__) +#include "watcomconfig.h" +#else +#ifdef HAVE_EXPAT_CONFIG_H +#include +#endif +#endif /* ndef COMPILED_FROM_DSP */ + +#include "expat_external.h" +#include "internal.h" +#include "xmlrole.h" +#include "ascii.h" + +/* Doesn't check: + + that ,| are not mixed in a model group + content of literals + +*/ + +static const char KW_ANY[] = { + ASCII_A, ASCII_N, ASCII_Y, '\0' }; +static const char KW_ATTLIST[] = { + ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' }; +static const char KW_CDATA[] = { + ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; +static const char KW_DOCTYPE[] = { + ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' }; +static const char KW_ELEMENT[] = { + ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' }; +static const char KW_EMPTY[] = { + ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' }; +static const char KW_ENTITIES[] = { + ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, + '\0' }; +static const char KW_ENTITY[] = { + ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; +static const char KW_FIXED[] = { + ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' }; +static const char KW_ID[] = { + ASCII_I, ASCII_D, '\0' }; +static const char KW_IDREF[] = { + ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; +static const char KW_IDREFS[] = { + ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; +#ifdef XML_DTD +static const char KW_IGNORE[] = { + ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' }; +#endif +static const char KW_IMPLIED[] = { + ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' }; +#ifdef XML_DTD +static const char KW_INCLUDE[] = { + ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' }; +#endif +static const char KW_NDATA[] = { + ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; +static const char KW_NMTOKEN[] = { + ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; +static const char KW_NMTOKENS[] = { + ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, + '\0' }; +static const char KW_NOTATION[] = + { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, + '\0' }; +static const char KW_PCDATA[] = { + ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; +static const char KW_PUBLIC[] = { + ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' }; +static const char KW_REQUIRED[] = { + ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D, + '\0' }; +static const char KW_SYSTEM[] = { + ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' }; + +#ifndef MIN_BYTES_PER_CHAR +#define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar) +#endif + +#ifdef XML_DTD +#define setTopLevel(state) \ + ((state)->handler = ((state)->documentEntity \ + ? internalSubset \ + : externalSubset1)) +#else /* not XML_DTD */ +#define setTopLevel(state) ((state)->handler = internalSubset) +#endif /* not XML_DTD */ + +typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc); + +static PROLOG_HANDLER + prolog0, prolog1, prolog2, + doctype0, doctype1, doctype2, doctype3, doctype4, doctype5, + internalSubset, + entity0, entity1, entity2, entity3, entity4, entity5, entity6, + entity7, entity8, entity9, entity10, + notation0, notation1, notation2, notation3, notation4, + attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6, + attlist7, attlist8, attlist9, + element0, element1, element2, element3, element4, element5, element6, + element7, +#ifdef XML_DTD + externalSubset0, externalSubset1, + condSect0, condSect1, condSect2, +#endif /* XML_DTD */ + declClose, + error; + +static int FASTCALL common(PROLOG_STATE *state, int tok); + +static int PTRCALL +prolog0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + state->handler = prolog1; + return XML_ROLE_NONE; + case XML_TOK_XML_DECL: + state->handler = prolog1; + return XML_ROLE_XML_DECL; + case XML_TOK_PI: + state->handler = prolog1; + return XML_ROLE_PI; + case XML_TOK_COMMENT: + state->handler = prolog1; + return XML_ROLE_COMMENT; + case XML_TOK_BOM: + return XML_ROLE_NONE; + case XML_TOK_DECL_OPEN: + if (!XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_DOCTYPE)) + break; + state->handler = doctype0; + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_INSTANCE_START: + state->handler = error; + return XML_ROLE_INSTANCE_START; + } + return common(state, tok); +} + +static int PTRCALL +prolog1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_PI: + return XML_ROLE_PI; + case XML_TOK_COMMENT: + return XML_ROLE_COMMENT; + case XML_TOK_BOM: + return XML_ROLE_NONE; + case XML_TOK_DECL_OPEN: + if (!XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_DOCTYPE)) + break; + state->handler = doctype0; + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_INSTANCE_START: + state->handler = error; + return XML_ROLE_INSTANCE_START; + } + return common(state, tok); +} + +static int PTRCALL +prolog2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_PI: + return XML_ROLE_PI; + case XML_TOK_COMMENT: + return XML_ROLE_COMMENT; + case XML_TOK_INSTANCE_START: + state->handler = error; + return XML_ROLE_INSTANCE_START; + } + return common(state, tok); +} + +static int PTRCALL +doctype0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = doctype1; + return XML_ROLE_DOCTYPE_NAME; + } + return common(state, tok); +} + +static int PTRCALL +doctype1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = internalSubset; + return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; + case XML_TOK_DECL_CLOSE: + state->handler = prolog2; + return XML_ROLE_DOCTYPE_CLOSE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = doctype3; + return XML_ROLE_DOCTYPE_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = doctype2; + return XML_ROLE_DOCTYPE_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +doctype2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_LITERAL: + state->handler = doctype3; + return XML_ROLE_DOCTYPE_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +doctype3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_LITERAL: + state->handler = doctype4; + return XML_ROLE_DOCTYPE_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +doctype4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = internalSubset; + return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; + case XML_TOK_DECL_CLOSE: + state->handler = prolog2; + return XML_ROLE_DOCTYPE_CLOSE; + } + return common(state, tok); +} + +static int PTRCALL +doctype5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_DECL_CLOSE: + state->handler = prolog2; + return XML_ROLE_DOCTYPE_CLOSE; + } + return common(state, tok); +} + +static int PTRCALL +internalSubset(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_DECL_OPEN: + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_ENTITY)) { + state->handler = entity0; + return XML_ROLE_ENTITY_NONE; + } + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_ATTLIST)) { + state->handler = attlist0; + return XML_ROLE_ATTLIST_NONE; + } + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_ELEMENT)) { + state->handler = element0; + return XML_ROLE_ELEMENT_NONE; + } + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_NOTATION)) { + state->handler = notation0; + return XML_ROLE_NOTATION_NONE; + } + break; + case XML_TOK_PI: + return XML_ROLE_PI; + case XML_TOK_COMMENT: + return XML_ROLE_COMMENT; + case XML_TOK_PARAM_ENTITY_REF: + return XML_ROLE_PARAM_ENTITY_REF; + case XML_TOK_CLOSE_BRACKET: + state->handler = doctype5; + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_NONE: + return XML_ROLE_NONE; + } + return common(state, tok); +} + +#ifdef XML_DTD + +static int PTRCALL +externalSubset0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + state->handler = externalSubset1; + if (tok == XML_TOK_XML_DECL) + return XML_ROLE_TEXT_DECL; + return externalSubset1(state, tok, ptr, end, enc); +} + +static int PTRCALL +externalSubset1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_COND_SECT_OPEN: + state->handler = condSect0; + return XML_ROLE_NONE; + case XML_TOK_COND_SECT_CLOSE: + if (state->includeLevel == 0) + break; + state->includeLevel -= 1; + return XML_ROLE_NONE; + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_CLOSE_BRACKET: + break; + case XML_TOK_NONE: + if (state->includeLevel) + break; + return XML_ROLE_NONE; + default: + return internalSubset(state, tok, ptr, end, enc); + } + return common(state, tok); +} + +#endif /* XML_DTD */ + +static int PTRCALL +entity0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_PERCENT: + state->handler = entity1; + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + state->handler = entity2; + return XML_ROLE_GENERAL_ENTITY_NAME; + } + return common(state, tok); +} + +static int PTRCALL +entity1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + state->handler = entity7; + return XML_ROLE_PARAM_ENTITY_NAME; + } + return common(state, tok); +} + +static int PTRCALL +entity2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = entity4; + return XML_ROLE_ENTITY_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = entity3; + return XML_ROLE_ENTITY_NONE; + } + break; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_ENTITY_NONE; + return XML_ROLE_ENTITY_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +entity3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity4; + return XML_ROLE_ENTITY_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity5; + return XML_ROLE_ENTITY_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_ENTITY_COMPLETE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) { + state->handler = entity6; + return XML_ROLE_ENTITY_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +entity6(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + state->handler = declClose; + state->role_none = XML_ROLE_ENTITY_NONE; + return XML_ROLE_ENTITY_NOTATION_NAME; + } + return common(state, tok); +} + +static int PTRCALL +entity7(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = entity9; + return XML_ROLE_ENTITY_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = entity8; + return XML_ROLE_ENTITY_NONE; + } + break; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_ENTITY_NONE; + return XML_ROLE_ENTITY_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +entity8(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity9; + return XML_ROLE_ENTITY_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity9(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity10; + return XML_ROLE_ENTITY_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity10(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_ENTITY_COMPLETE; + } + return common(state, tok); +} + +static int PTRCALL +notation0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_NAME: + state->handler = notation1; + return XML_ROLE_NOTATION_NAME; + } + return common(state, tok); +} + +static int PTRCALL +notation1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = notation3; + return XML_ROLE_NOTATION_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = notation2; + return XML_ROLE_NOTATION_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +notation2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_LITERAL: + state->handler = notation4; + return XML_ROLE_NOTATION_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +notation3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_NOTATION_NONE; + return XML_ROLE_NOTATION_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +notation4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_NOTATION_NONE; + return XML_ROLE_NOTATION_SYSTEM_ID; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_NOTATION_NO_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +attlist0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = attlist1; + return XML_ROLE_ATTLIST_ELEMENT_NAME; + } + return common(state, tok); +} + +static int PTRCALL +attlist1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = attlist2; + return XML_ROLE_ATTRIBUTE_NAME; + } + return common(state, tok); +} + +static int PTRCALL +attlist2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + { + static const char * const types[] = { + KW_CDATA, + KW_ID, + KW_IDREF, + KW_IDREFS, + KW_ENTITY, + KW_ENTITIES, + KW_NMTOKEN, + KW_NMTOKENS, + }; + int i; + for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++) + if (XmlNameMatchesAscii(enc, ptr, end, types[i])) { + state->handler = attlist8; + return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i; + } + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) { + state->handler = attlist5; + return XML_ROLE_ATTLIST_NONE; + } + break; + case XML_TOK_OPEN_PAREN: + state->handler = attlist3; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +static int PTRCALL +attlist3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NMTOKEN: + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = attlist4; + return XML_ROLE_ATTRIBUTE_ENUM_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +attlist4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_CLOSE_PAREN: + state->handler = attlist8; + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_OR: + state->handler = attlist3; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +static int PTRCALL +attlist5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_OPEN_PAREN: + state->handler = attlist6; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +static int PTRCALL +attlist6(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + state->handler = attlist7; + return XML_ROLE_ATTRIBUTE_NOTATION_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +attlist7(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_CLOSE_PAREN: + state->handler = attlist8; + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_OR: + state->handler = attlist6; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +/* default value */ +static int PTRCALL +attlist8(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_POUND_NAME: + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_IMPLIED)) { + state->handler = attlist1; + return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE; + } + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_REQUIRED)) { + state->handler = attlist1; + return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE; + } + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_FIXED)) { + state->handler = attlist9; + return XML_ROLE_ATTLIST_NONE; + } + break; + case XML_TOK_LITERAL: + state->handler = attlist1; + return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +attlist9(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_LITERAL: + state->handler = attlist1; + return XML_ROLE_FIXED_ATTRIBUTE_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +element0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element1; + return XML_ROLE_ELEMENT_NAME; + } + return common(state, tok); +} + +static int PTRCALL +element1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_CONTENT_EMPTY; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_CONTENT_ANY; + } + break; + case XML_TOK_OPEN_PAREN: + state->handler = element2; + state->level = 1; + return XML_ROLE_GROUP_OPEN; + } + return common(state, tok); +} + +static int PTRCALL +element2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_POUND_NAME: + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_PCDATA)) { + state->handler = element3; + return XML_ROLE_CONTENT_PCDATA; + } + break; + case XML_TOK_OPEN_PAREN: + state->level = 2; + state->handler = element6; + return XML_ROLE_GROUP_OPEN; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT; + case XML_TOK_NAME_QUESTION: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_OPT; + case XML_TOK_NAME_ASTERISK: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_REP; + case XML_TOK_NAME_PLUS: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_PLUS; + } + return common(state, tok); +} + +static int PTRCALL +element3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_CLOSE_PAREN: + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_GROUP_CLOSE; + case XML_TOK_CLOSE_PAREN_ASTERISK: + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_GROUP_CLOSE_REP; + case XML_TOK_OR: + state->handler = element4; + return XML_ROLE_ELEMENT_NONE; + } + return common(state, tok); +} + +static int PTRCALL +element4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element5; + return XML_ROLE_CONTENT_ELEMENT; + } + return common(state, tok); +} + +static int PTRCALL +element5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_CLOSE_PAREN_ASTERISK: + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_GROUP_CLOSE_REP; + case XML_TOK_OR: + state->handler = element4; + return XML_ROLE_ELEMENT_NONE; + } + return common(state, tok); +} + +static int PTRCALL +element6(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_OPEN_PAREN: + state->level += 1; + return XML_ROLE_GROUP_OPEN; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT; + case XML_TOK_NAME_QUESTION: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_OPT; + case XML_TOK_NAME_ASTERISK: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_REP; + case XML_TOK_NAME_PLUS: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_PLUS; + } + return common(state, tok); +} + +static int PTRCALL +element7(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_CLOSE_PAREN: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE; + case XML_TOK_CLOSE_PAREN_ASTERISK: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE_REP; + case XML_TOK_CLOSE_PAREN_QUESTION: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE_OPT; + case XML_TOK_CLOSE_PAREN_PLUS: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE_PLUS; + case XML_TOK_COMMA: + state->handler = element6; + return XML_ROLE_GROUP_SEQUENCE; + case XML_TOK_OR: + state->handler = element6; + return XML_ROLE_GROUP_CHOICE; + } + return common(state, tok); +} + +#ifdef XML_DTD + +static int PTRCALL +condSect0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) { + state->handler = condSect1; + return XML_ROLE_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) { + state->handler = condSect2; + return XML_ROLE_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +condSect1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = externalSubset1; + state->includeLevel += 1; + return XML_ROLE_NONE; + } + return common(state, tok); +} + +static int PTRCALL +condSect2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = externalSubset1; + return XML_ROLE_IGNORE_SECT; + } + return common(state, tok); +} + +#endif /* XML_DTD */ + +static int PTRCALL +declClose(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return state->role_none; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return state->role_none; + } + return common(state, tok); +} + +static int PTRCALL +error(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + return XML_ROLE_NONE; +} + +static int FASTCALL +common(PROLOG_STATE *state, int tok) +{ +#ifdef XML_DTD + if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF) + return XML_ROLE_INNER_PARAM_ENTITY_REF; +#endif + state->handler = error; + return XML_ROLE_ERROR; +} + +void +XmlPrologStateInit(PROLOG_STATE *state) +{ + state->handler = prolog0; +#ifdef XML_DTD + state->documentEntity = 1; + state->includeLevel = 0; + state->inEntityValue = 0; +#endif /* XML_DTD */ +} + +#ifdef XML_DTD + +void +XmlPrologStateInitExternalEntity(PROLOG_STATE *state) +{ + state->handler = externalSubset0; + state->documentEntity = 0; + state->includeLevel = 0; +} + +#endif /* XML_DTD */ diff --git a/project/jni/expat/lib/xmlrole.h b/project/jni/expat/lib/xmlrole.h new file mode 100644 index 000000000..4dd9f06f9 --- /dev/null +++ b/project/jni/expat/lib/xmlrole.h @@ -0,0 +1,114 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef XmlRole_INCLUDED +#define XmlRole_INCLUDED 1 + +#ifdef __VMS +/* 0 1 2 3 0 1 2 3 + 1234567890123456789012345678901 1234567890123456789012345678901 */ +#define XmlPrologStateInitExternalEntity XmlPrologStateInitExternalEnt +#endif + +#include "xmltok.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + XML_ROLE_ERROR = -1, + XML_ROLE_NONE = 0, + XML_ROLE_XML_DECL, + XML_ROLE_INSTANCE_START, + XML_ROLE_DOCTYPE_NONE, + XML_ROLE_DOCTYPE_NAME, + XML_ROLE_DOCTYPE_SYSTEM_ID, + XML_ROLE_DOCTYPE_PUBLIC_ID, + XML_ROLE_DOCTYPE_INTERNAL_SUBSET, + XML_ROLE_DOCTYPE_CLOSE, + XML_ROLE_GENERAL_ENTITY_NAME, + XML_ROLE_PARAM_ENTITY_NAME, + XML_ROLE_ENTITY_NONE, + XML_ROLE_ENTITY_VALUE, + XML_ROLE_ENTITY_SYSTEM_ID, + XML_ROLE_ENTITY_PUBLIC_ID, + XML_ROLE_ENTITY_COMPLETE, + XML_ROLE_ENTITY_NOTATION_NAME, + XML_ROLE_NOTATION_NONE, + XML_ROLE_NOTATION_NAME, + XML_ROLE_NOTATION_SYSTEM_ID, + XML_ROLE_NOTATION_NO_SYSTEM_ID, + XML_ROLE_NOTATION_PUBLIC_ID, + XML_ROLE_ATTRIBUTE_NAME, + XML_ROLE_ATTRIBUTE_TYPE_CDATA, + XML_ROLE_ATTRIBUTE_TYPE_ID, + XML_ROLE_ATTRIBUTE_TYPE_IDREF, + XML_ROLE_ATTRIBUTE_TYPE_IDREFS, + XML_ROLE_ATTRIBUTE_TYPE_ENTITY, + XML_ROLE_ATTRIBUTE_TYPE_ENTITIES, + XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN, + XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS, + XML_ROLE_ATTRIBUTE_ENUM_VALUE, + XML_ROLE_ATTRIBUTE_NOTATION_VALUE, + XML_ROLE_ATTLIST_NONE, + XML_ROLE_ATTLIST_ELEMENT_NAME, + XML_ROLE_IMPLIED_ATTRIBUTE_VALUE, + XML_ROLE_REQUIRED_ATTRIBUTE_VALUE, + XML_ROLE_DEFAULT_ATTRIBUTE_VALUE, + XML_ROLE_FIXED_ATTRIBUTE_VALUE, + XML_ROLE_ELEMENT_NONE, + XML_ROLE_ELEMENT_NAME, + XML_ROLE_CONTENT_ANY, + XML_ROLE_CONTENT_EMPTY, + XML_ROLE_CONTENT_PCDATA, + XML_ROLE_GROUP_OPEN, + XML_ROLE_GROUP_CLOSE, + XML_ROLE_GROUP_CLOSE_REP, + XML_ROLE_GROUP_CLOSE_OPT, + XML_ROLE_GROUP_CLOSE_PLUS, + XML_ROLE_GROUP_CHOICE, + XML_ROLE_GROUP_SEQUENCE, + XML_ROLE_CONTENT_ELEMENT, + XML_ROLE_CONTENT_ELEMENT_REP, + XML_ROLE_CONTENT_ELEMENT_OPT, + XML_ROLE_CONTENT_ELEMENT_PLUS, + XML_ROLE_PI, + XML_ROLE_COMMENT, +#ifdef XML_DTD + XML_ROLE_TEXT_DECL, + XML_ROLE_IGNORE_SECT, + XML_ROLE_INNER_PARAM_ENTITY_REF, +#endif /* XML_DTD */ + XML_ROLE_PARAM_ENTITY_REF +}; + +typedef struct prolog_state { + int (PTRCALL *handler) (struct prolog_state *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc); + unsigned level; + int role_none; +#ifdef XML_DTD + unsigned includeLevel; + int documentEntity; + int inEntityValue; +#endif /* XML_DTD */ +} PROLOG_STATE; + +void XmlPrologStateInit(PROLOG_STATE *); +#ifdef XML_DTD +void XmlPrologStateInitExternalEntity(PROLOG_STATE *); +#endif /* XML_DTD */ + +#define XmlTokenRole(state, tok, ptr, end, enc) \ + (((state)->handler)(state, tok, ptr, end, enc)) + +#ifdef __cplusplus +} +#endif + +#endif /* not XmlRole_INCLUDED */ diff --git a/project/jni/expat/lib/xmltok.c b/project/jni/expat/lib/xmltok.c new file mode 100644 index 000000000..bf09dfc72 --- /dev/null +++ b/project/jni/expat/lib/xmltok.c @@ -0,0 +1,1651 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#include + +#ifdef COMPILED_FROM_DSP +#include "winconfig.h" +#elif defined(MACOS_CLASSIC) +#include "macconfig.h" +#elif defined(__amigaos__) +#include "amigaconfig.h" +#elif defined(__WATCOMC__) +#include "watcomconfig.h" +#else +#ifdef HAVE_EXPAT_CONFIG_H +#include +#endif +#endif /* ndef COMPILED_FROM_DSP */ + +#include "expat_external.h" +#include "internal.h" +#include "xmltok.h" +#include "nametab.h" + +#ifdef XML_DTD +#define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok) +#else +#define IGNORE_SECTION_TOK_VTABLE /* as nothing */ +#endif + +#define VTABLE1 \ + { PREFIX(prologTok), PREFIX(contentTok), \ + PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \ + { PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \ + PREFIX(sameName), \ + PREFIX(nameMatchesAscii), \ + PREFIX(nameLength), \ + PREFIX(skipS), \ + PREFIX(getAtts), \ + PREFIX(charRefNumber), \ + PREFIX(predefinedEntityName), \ + PREFIX(updatePosition), \ + PREFIX(isPublicId) + +#define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16) + +#define UCS2_GET_NAMING(pages, hi, lo) \ + (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1 << ((lo) & 0x1F))) + +/* A 2 byte UTF-8 representation splits the characters 11 bits between + the bottom 5 and 6 bits of the bytes. We need 8 bits to index into + pages, 3 bits to add to that index and 5 bits to generate the mask. +*/ +#define UTF8_GET_NAMING2(pages, byte) \ + (namingBitmap[((pages)[(((byte)[0]) >> 2) & 7] << 3) \ + + ((((byte)[0]) & 3) << 1) \ + + ((((byte)[1]) >> 5) & 1)] \ + & (1 << (((byte)[1]) & 0x1F))) + +/* A 3 byte UTF-8 representation splits the characters 16 bits between + the bottom 4, 6 and 6 bits of the bytes. We need 8 bits to index + into pages, 3 bits to add to that index and 5 bits to generate the + mask. +*/ +#define UTF8_GET_NAMING3(pages, byte) \ + (namingBitmap[((pages)[((((byte)[0]) & 0xF) << 4) \ + + ((((byte)[1]) >> 2) & 0xF)] \ + << 3) \ + + ((((byte)[1]) & 3) << 1) \ + + ((((byte)[2]) >> 5) & 1)] \ + & (1 << (((byte)[2]) & 0x1F))) + +#define UTF8_GET_NAMING(pages, p, n) \ + ((n) == 2 \ + ? UTF8_GET_NAMING2(pages, (const unsigned char *)(p)) \ + : ((n) == 3 \ + ? UTF8_GET_NAMING3(pages, (const unsigned char *)(p)) \ + : 0)) + +/* Detection of invalid UTF-8 sequences is based on Table 3.1B + of Unicode 3.2: http://www.unicode.org/unicode/reports/tr28/ + with the additional restriction of not allowing the Unicode + code points 0xFFFF and 0xFFFE (sequences EF,BF,BF and EF,BF,BE). + Implementation details: + (A & 0x80) == 0 means A < 0x80 + and + (A & 0xC0) == 0xC0 means A > 0xBF +*/ + +#define UTF8_INVALID2(p) \ + ((*p) < 0xC2 || ((p)[1] & 0x80) == 0 || ((p)[1] & 0xC0) == 0xC0) + +#define UTF8_INVALID3(p) \ + (((p)[2] & 0x80) == 0 \ + || \ + ((*p) == 0xEF && (p)[1] == 0xBF \ + ? \ + (p)[2] > 0xBD \ + : \ + ((p)[2] & 0xC0) == 0xC0) \ + || \ + ((*p) == 0xE0 \ + ? \ + (p)[1] < 0xA0 || ((p)[1] & 0xC0) == 0xC0 \ + : \ + ((p)[1] & 0x80) == 0 \ + || \ + ((*p) == 0xED ? (p)[1] > 0x9F : ((p)[1] & 0xC0) == 0xC0))) + +#define UTF8_INVALID4(p) \ + (((p)[3] & 0x80) == 0 || ((p)[3] & 0xC0) == 0xC0 \ + || \ + ((p)[2] & 0x80) == 0 || ((p)[2] & 0xC0) == 0xC0 \ + || \ + ((*p) == 0xF0 \ + ? \ + (p)[1] < 0x90 || ((p)[1] & 0xC0) == 0xC0 \ + : \ + ((p)[1] & 0x80) == 0 \ + || \ + ((*p) == 0xF4 ? (p)[1] > 0x8F : ((p)[1] & 0xC0) == 0xC0))) + +static int PTRFASTCALL +isNever(const ENCODING *enc, const char *p) +{ + return 0; +} + +static int PTRFASTCALL +utf8_isName2(const ENCODING *enc, const char *p) +{ + return UTF8_GET_NAMING2(namePages, (const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isName3(const ENCODING *enc, const char *p) +{ + return UTF8_GET_NAMING3(namePages, (const unsigned char *)p); +} + +#define utf8_isName4 isNever + +static int PTRFASTCALL +utf8_isNmstrt2(const ENCODING *enc, const char *p) +{ + return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isNmstrt3(const ENCODING *enc, const char *p) +{ + return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p); +} + +#define utf8_isNmstrt4 isNever + +static int PTRFASTCALL +utf8_isInvalid2(const ENCODING *enc, const char *p) +{ + return UTF8_INVALID2((const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isInvalid3(const ENCODING *enc, const char *p) +{ + return UTF8_INVALID3((const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isInvalid4(const ENCODING *enc, const char *p) +{ + return UTF8_INVALID4((const unsigned char *)p); +} + +struct normal_encoding { + ENCODING enc; + unsigned char type[256]; +#ifdef XML_MIN_SIZE + int (PTRFASTCALL *byteType)(const ENCODING *, const char *); + int (PTRFASTCALL *isNameMin)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrtMin)(const ENCODING *, const char *); + int (PTRFASTCALL *byteToAscii)(const ENCODING *, const char *); + int (PTRCALL *charMatches)(const ENCODING *, const char *, int); +#endif /* XML_MIN_SIZE */ + int (PTRFASTCALL *isName2)(const ENCODING *, const char *); + int (PTRFASTCALL *isName3)(const ENCODING *, const char *); + int (PTRFASTCALL *isName4)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrt2)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrt3)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrt4)(const ENCODING *, const char *); + int (PTRFASTCALL *isInvalid2)(const ENCODING *, const char *); + int (PTRFASTCALL *isInvalid3)(const ENCODING *, const char *); + int (PTRFASTCALL *isInvalid4)(const ENCODING *, const char *); +}; + +#define AS_NORMAL_ENCODING(enc) ((const struct normal_encoding *) (enc)) + +#ifdef XML_MIN_SIZE + +#define STANDARD_VTABLE(E) \ + E ## byteType, \ + E ## isNameMin, \ + E ## isNmstrtMin, \ + E ## byteToAscii, \ + E ## charMatches, + +#else + +#define STANDARD_VTABLE(E) /* as nothing */ + +#endif + +#define NORMAL_VTABLE(E) \ + E ## isName2, \ + E ## isName3, \ + E ## isName4, \ + E ## isNmstrt2, \ + E ## isNmstrt3, \ + E ## isNmstrt4, \ + E ## isInvalid2, \ + E ## isInvalid3, \ + E ## isInvalid4 + +static int FASTCALL checkCharRefNumber(int); + +#include "xmltok_impl.h" +#include "ascii.h" + +#ifdef XML_MIN_SIZE +#define sb_isNameMin isNever +#define sb_isNmstrtMin isNever +#endif + +#ifdef XML_MIN_SIZE +#define MINBPC(enc) ((enc)->minBytesPerChar) +#else +/* minimum bytes per character */ +#define MINBPC(enc) 1 +#endif + +#define SB_BYTE_TYPE(enc, p) \ + (((struct normal_encoding *)(enc))->type[(unsigned char)*(p)]) + +#ifdef XML_MIN_SIZE +static int PTRFASTCALL +sb_byteType(const ENCODING *enc, const char *p) +{ + return SB_BYTE_TYPE(enc, p); +} +#define BYTE_TYPE(enc, p) \ + (AS_NORMAL_ENCODING(enc)->byteType(enc, p)) +#else +#define BYTE_TYPE(enc, p) SB_BYTE_TYPE(enc, p) +#endif + +#ifdef XML_MIN_SIZE +#define BYTE_TO_ASCII(enc, p) \ + (AS_NORMAL_ENCODING(enc)->byteToAscii(enc, p)) +static int PTRFASTCALL +sb_byteToAscii(const ENCODING *enc, const char *p) +{ + return *p; +} +#else +#define BYTE_TO_ASCII(enc, p) (*(p)) +#endif + +#define IS_NAME_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isName ## n(enc, p)) +#define IS_NMSTRT_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isNmstrt ## n(enc, p)) +#define IS_INVALID_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isInvalid ## n(enc, p)) + +#ifdef XML_MIN_SIZE +#define IS_NAME_CHAR_MINBPC(enc, p) \ + (AS_NORMAL_ENCODING(enc)->isNameMin(enc, p)) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) \ + (AS_NORMAL_ENCODING(enc)->isNmstrtMin(enc, p)) +#else +#define IS_NAME_CHAR_MINBPC(enc, p) (0) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) (0) +#endif + +#ifdef XML_MIN_SIZE +#define CHAR_MATCHES(enc, p, c) \ + (AS_NORMAL_ENCODING(enc)->charMatches(enc, p, c)) +static int PTRCALL +sb_charMatches(const ENCODING *enc, const char *p, int c) +{ + return *p == c; +} +#else +/* c is an ASCII character */ +#define CHAR_MATCHES(enc, p, c) (*(p) == c) +#endif + +#define PREFIX(ident) normal_ ## ident +#define XML_TOK_IMPL_C +#include "xmltok_impl.c" +#undef XML_TOK_IMPL_C + +#undef MINBPC +#undef BYTE_TYPE +#undef BYTE_TO_ASCII +#undef CHAR_MATCHES +#undef IS_NAME_CHAR +#undef IS_NAME_CHAR_MINBPC +#undef IS_NMSTRT_CHAR +#undef IS_NMSTRT_CHAR_MINBPC +#undef IS_INVALID_CHAR + +enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */ + UTF8_cval1 = 0x00, + UTF8_cval2 = 0xc0, + UTF8_cval3 = 0xe0, + UTF8_cval4 = 0xf0 +}; + +static void PTRCALL +utf8_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + char *to; + const char *from; + if (fromLim - *fromP > toLim - *toP) { + /* Avoid copying partial characters. */ + for (fromLim = *fromP + (toLim - *toP); fromLim > *fromP; fromLim--) + if (((unsigned char)fromLim[-1] & 0xc0) != 0x80) + break; + } + for (to = *toP, from = *fromP; from != fromLim; from++, to++) + *to = *from; + *fromP = from; + *toP = to; +} + +static void PTRCALL +utf8_toUtf16(const ENCODING *enc, + const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) +{ + unsigned short *to = *toP; + const char *from = *fromP; + while (from != fromLim && to != toLim) { + switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) { + case BT_LEAD2: + *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f)); + from += 2; + break; + case BT_LEAD3: + *to++ = (unsigned short)(((from[0] & 0xf) << 12) + | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f)); + from += 3; + break; + case BT_LEAD4: + { + unsigned long n; + if (to + 1 == toLim) + goto after; + n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12) + | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f); + n -= 0x10000; + to[0] = (unsigned short)((n >> 10) | 0xD800); + to[1] = (unsigned short)((n & 0x3FF) | 0xDC00); + to += 2; + from += 4; + } + break; + default: + *to++ = *from++; + break; + } + } +after: + *fromP = from; + *toP = to; +} + +#ifdef XML_NS +static const struct normal_encoding utf8_encoding_ns = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#include "asciitab.h" +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; +#endif + +static const struct normal_encoding utf8_encoding = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; + +#ifdef XML_NS + +static const struct normal_encoding internal_utf8_encoding_ns = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#include "iasciitab.h" +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; + +#endif + +static const struct normal_encoding internal_utf8_encoding = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; + +static void PTRCALL +latin1_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + for (;;) { + unsigned char c; + if (*fromP == fromLim) + break; + c = (unsigned char)**fromP; + if (c & 0x80) { + if (toLim - *toP < 2) + break; + *(*toP)++ = (char)((c >> 6) | UTF8_cval2); + *(*toP)++ = (char)((c & 0x3f) | 0x80); + (*fromP)++; + } + else { + if (*toP == toLim) + break; + *(*toP)++ = *(*fromP)++; + } + } +} + +static void PTRCALL +latin1_toUtf16(const ENCODING *enc, + const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) +{ + while (*fromP != fromLim && *toP != toLim) + *(*toP)++ = (unsigned char)*(*fromP)++; +} + +#ifdef XML_NS + +static const struct normal_encoding latin1_encoding_ns = { + { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, + { +#include "asciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(sb_) +}; + +#endif + +static const struct normal_encoding latin1_encoding = { + { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(sb_) +}; + +static void PTRCALL +ascii_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + while (*fromP != fromLim && *toP != toLim) + *(*toP)++ = *(*fromP)++; +} + +#ifdef XML_NS + +static const struct normal_encoding ascii_encoding_ns = { + { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, + { +#include "asciitab.h" +/* BT_NONXML == 0 */ + }, + STANDARD_VTABLE(sb_) +}; + +#endif + +static const struct normal_encoding ascii_encoding = { + { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +/* BT_NONXML == 0 */ + }, + STANDARD_VTABLE(sb_) +}; + +static int PTRFASTCALL +unicode_byte_type(char hi, char lo) +{ + switch ((unsigned char)hi) { + case 0xD8: case 0xD9: case 0xDA: case 0xDB: + return BT_LEAD4; + case 0xDC: case 0xDD: case 0xDE: case 0xDF: + return BT_TRAIL; + case 0xFF: + switch ((unsigned char)lo) { + case 0xFF: + case 0xFE: + return BT_NONXML; + } + break; + } + return BT_NONASCII; +} + +#define DEFINE_UTF16_TO_UTF8(E) \ +static void PTRCALL \ +E ## toUtf8(const ENCODING *enc, \ + const char **fromP, const char *fromLim, \ + char **toP, const char *toLim) \ +{ \ + const char *from; \ + for (from = *fromP; from != fromLim; from += 2) { \ + int plane; \ + unsigned char lo2; \ + unsigned char lo = GET_LO(from); \ + unsigned char hi = GET_HI(from); \ + switch (hi) { \ + case 0: \ + if (lo < 0x80) { \ + if (*toP == toLim) { \ + *fromP = from; \ + return; \ + } \ + *(*toP)++ = lo; \ + break; \ + } \ + /* fall through */ \ + case 0x1: case 0x2: case 0x3: \ + case 0x4: case 0x5: case 0x6: case 0x7: \ + if (toLim - *toP < 2) { \ + *fromP = from; \ + return; \ + } \ + *(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \ + *(*toP)++ = ((lo & 0x3f) | 0x80); \ + break; \ + default: \ + if (toLim - *toP < 3) { \ + *fromP = from; \ + return; \ + } \ + /* 16 bits divided 4, 6, 6 amongst 3 bytes */ \ + *(*toP)++ = ((hi >> 4) | UTF8_cval3); \ + *(*toP)++ = (((hi & 0xf) << 2) | (lo >> 6) | 0x80); \ + *(*toP)++ = ((lo & 0x3f) | 0x80); \ + break; \ + case 0xD8: case 0xD9: case 0xDA: case 0xDB: \ + if (toLim - *toP < 4) { \ + *fromP = from; \ + return; \ + } \ + plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \ + *(*toP)++ = ((plane >> 2) | UTF8_cval4); \ + *(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \ + from += 2; \ + lo2 = GET_LO(from); \ + *(*toP)++ = (((lo & 0x3) << 4) \ + | ((GET_HI(from) & 0x3) << 2) \ + | (lo2 >> 6) \ + | 0x80); \ + *(*toP)++ = ((lo2 & 0x3f) | 0x80); \ + break; \ + } \ + } \ + *fromP = from; \ +} + +#define DEFINE_UTF16_TO_UTF16(E) \ +static void PTRCALL \ +E ## toUtf16(const ENCODING *enc, \ + const char **fromP, const char *fromLim, \ + unsigned short **toP, const unsigned short *toLim) \ +{ \ + /* Avoid copying first half only of surrogate */ \ + if (fromLim - *fromP > ((toLim - *toP) << 1) \ + && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \ + fromLim -= 2; \ + for (; *fromP != fromLim && *toP != toLim; *fromP += 2) \ + *(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \ +} + +#define SET2(ptr, ch) \ + (((ptr)[0] = ((ch) & 0xff)), ((ptr)[1] = ((ch) >> 8))) +#define GET_LO(ptr) ((unsigned char)(ptr)[0]) +#define GET_HI(ptr) ((unsigned char)(ptr)[1]) + +DEFINE_UTF16_TO_UTF8(little2_) +DEFINE_UTF16_TO_UTF16(little2_) + +#undef SET2 +#undef GET_LO +#undef GET_HI + +#define SET2(ptr, ch) \ + (((ptr)[0] = ((ch) >> 8)), ((ptr)[1] = ((ch) & 0xFF))) +#define GET_LO(ptr) ((unsigned char)(ptr)[1]) +#define GET_HI(ptr) ((unsigned char)(ptr)[0]) + +DEFINE_UTF16_TO_UTF8(big2_) +DEFINE_UTF16_TO_UTF16(big2_) + +#undef SET2 +#undef GET_LO +#undef GET_HI + +#define LITTLE2_BYTE_TYPE(enc, p) \ + ((p)[1] == 0 \ + ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \ + : unicode_byte_type((p)[1], (p)[0])) +#define LITTLE2_BYTE_TO_ASCII(enc, p) ((p)[1] == 0 ? (p)[0] : -1) +#define LITTLE2_CHAR_MATCHES(enc, p, c) ((p)[1] == 0 && (p)[0] == c) +#define LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0]) +#define LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[1], (unsigned char)p[0]) + +#ifdef XML_MIN_SIZE + +static int PTRFASTCALL +little2_byteType(const ENCODING *enc, const char *p) +{ + return LITTLE2_BYTE_TYPE(enc, p); +} + +static int PTRFASTCALL +little2_byteToAscii(const ENCODING *enc, const char *p) +{ + return LITTLE2_BYTE_TO_ASCII(enc, p); +} + +static int PTRCALL +little2_charMatches(const ENCODING *enc, const char *p, int c) +{ + return LITTLE2_CHAR_MATCHES(enc, p, c); +} + +static int PTRFASTCALL +little2_isNameMin(const ENCODING *enc, const char *p) +{ + return LITTLE2_IS_NAME_CHAR_MINBPC(enc, p); +} + +static int PTRFASTCALL +little2_isNmstrtMin(const ENCODING *enc, const char *p) +{ + return LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p); +} + +#undef VTABLE +#define VTABLE VTABLE1, little2_toUtf8, little2_toUtf16 + +#else /* not XML_MIN_SIZE */ + +#undef PREFIX +#define PREFIX(ident) little2_ ## ident +#define MINBPC(enc) 2 +/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ +#define BYTE_TYPE(enc, p) LITTLE2_BYTE_TYPE(enc, p) +#define BYTE_TO_ASCII(enc, p) LITTLE2_BYTE_TO_ASCII(enc, p) +#define CHAR_MATCHES(enc, p, c) LITTLE2_CHAR_MATCHES(enc, p, c) +#define IS_NAME_CHAR(enc, p, n) 0 +#define IS_NAME_CHAR_MINBPC(enc, p) LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) +#define IS_NMSTRT_CHAR(enc, p, n) (0) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) + +#define XML_TOK_IMPL_C +#include "xmltok_impl.c" +#undef XML_TOK_IMPL_C + +#undef MINBPC +#undef BYTE_TYPE +#undef BYTE_TO_ASCII +#undef CHAR_MATCHES +#undef IS_NAME_CHAR +#undef IS_NAME_CHAR_MINBPC +#undef IS_NMSTRT_CHAR +#undef IS_NMSTRT_CHAR_MINBPC +#undef IS_INVALID_CHAR + +#endif /* not XML_MIN_SIZE */ + +#ifdef XML_NS + +static const struct normal_encoding little2_encoding_ns = { + { VTABLE, 2, 0, +#if BYTEORDER == 1234 + 1 +#else + 0 +#endif + }, + { +#include "asciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) +}; + +#endif + +static const struct normal_encoding little2_encoding = { + { VTABLE, 2, 0, +#if BYTEORDER == 1234 + 1 +#else + 0 +#endif + }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) +}; + +#if BYTEORDER != 4321 + +#ifdef XML_NS + +static const struct normal_encoding internal_little2_encoding_ns = { + { VTABLE, 2, 0, 1 }, + { +#include "iasciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) +}; + +#endif + +static const struct normal_encoding internal_little2_encoding = { + { VTABLE, 2, 0, 1 }, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) +}; + +#endif + + +#define BIG2_BYTE_TYPE(enc, p) \ + ((p)[0] == 0 \ + ? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \ + : unicode_byte_type((p)[0], (p)[1])) +#define BIG2_BYTE_TO_ASCII(enc, p) ((p)[0] == 0 ? (p)[1] : -1) +#define BIG2_CHAR_MATCHES(enc, p, c) ((p)[0] == 0 && (p)[1] == c) +#define BIG2_IS_NAME_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1]) +#define BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[0], (unsigned char)p[1]) + +#ifdef XML_MIN_SIZE + +static int PTRFASTCALL +big2_byteType(const ENCODING *enc, const char *p) +{ + return BIG2_BYTE_TYPE(enc, p); +} + +static int PTRFASTCALL +big2_byteToAscii(const ENCODING *enc, const char *p) +{ + return BIG2_BYTE_TO_ASCII(enc, p); +} + +static int PTRCALL +big2_charMatches(const ENCODING *enc, const char *p, int c) +{ + return BIG2_CHAR_MATCHES(enc, p, c); +} + +static int PTRFASTCALL +big2_isNameMin(const ENCODING *enc, const char *p) +{ + return BIG2_IS_NAME_CHAR_MINBPC(enc, p); +} + +static int PTRFASTCALL +big2_isNmstrtMin(const ENCODING *enc, const char *p) +{ + return BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p); +} + +#undef VTABLE +#define VTABLE VTABLE1, big2_toUtf8, big2_toUtf16 + +#else /* not XML_MIN_SIZE */ + +#undef PREFIX +#define PREFIX(ident) big2_ ## ident +#define MINBPC(enc) 2 +/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ +#define BYTE_TYPE(enc, p) BIG2_BYTE_TYPE(enc, p) +#define BYTE_TO_ASCII(enc, p) BIG2_BYTE_TO_ASCII(enc, p) +#define CHAR_MATCHES(enc, p, c) BIG2_CHAR_MATCHES(enc, p, c) +#define IS_NAME_CHAR(enc, p, n) 0 +#define IS_NAME_CHAR_MINBPC(enc, p) BIG2_IS_NAME_CHAR_MINBPC(enc, p) +#define IS_NMSTRT_CHAR(enc, p, n) (0) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) + +#define XML_TOK_IMPL_C +#include "xmltok_impl.c" +#undef XML_TOK_IMPL_C + +#undef MINBPC +#undef BYTE_TYPE +#undef BYTE_TO_ASCII +#undef CHAR_MATCHES +#undef IS_NAME_CHAR +#undef IS_NAME_CHAR_MINBPC +#undef IS_NMSTRT_CHAR +#undef IS_NMSTRT_CHAR_MINBPC +#undef IS_INVALID_CHAR + +#endif /* not XML_MIN_SIZE */ + +#ifdef XML_NS + +static const struct normal_encoding big2_encoding_ns = { + { VTABLE, 2, 0, +#if BYTEORDER == 4321 + 1 +#else + 0 +#endif + }, + { +#include "asciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) +}; + +#endif + +static const struct normal_encoding big2_encoding = { + { VTABLE, 2, 0, +#if BYTEORDER == 4321 + 1 +#else + 0 +#endif + }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) +}; + +#if BYTEORDER != 1234 + +#ifdef XML_NS + +static const struct normal_encoding internal_big2_encoding_ns = { + { VTABLE, 2, 0, 1 }, + { +#include "iasciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) +}; + +#endif + +static const struct normal_encoding internal_big2_encoding = { + { VTABLE, 2, 0, 1 }, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) +}; + +#endif + +#undef PREFIX + +static int FASTCALL +streqci(const char *s1, const char *s2) +{ + for (;;) { + char c1 = *s1++; + char c2 = *s2++; + if (ASCII_a <= c1 && c1 <= ASCII_z) + c1 += ASCII_A - ASCII_a; + if (ASCII_a <= c2 && c2 <= ASCII_z) + c2 += ASCII_A - ASCII_a; + if (c1 != c2) + return 0; + if (!c1) + break; + } + return 1; +} + +static void PTRCALL +initUpdatePosition(const ENCODING *enc, const char *ptr, + const char *end, POSITION *pos) +{ + normal_updatePosition(&utf8_encoding.enc, ptr, end, pos); +} + +static int +toAscii(const ENCODING *enc, const char *ptr, const char *end) +{ + char buf[1]; + char *p = buf; + XmlUtf8Convert(enc, &ptr, end, &p, p + 1); + if (p == buf) + return -1; + else + return buf[0]; +} + +static int FASTCALL +isSpace(int c) +{ + switch (c) { + case 0x20: + case 0xD: + case 0xA: + case 0x9: + return 1; + } + return 0; +} + +/* Return 1 if there's just optional white space or there's an S + followed by name=val. +*/ +static int +parsePseudoAttribute(const ENCODING *enc, + const char *ptr, + const char *end, + const char **namePtr, + const char **nameEndPtr, + const char **valPtr, + const char **nextTokPtr) +{ + int c; + char open; + if (ptr == end) { + *namePtr = NULL; + return 1; + } + if (!isSpace(toAscii(enc, ptr, end))) { + *nextTokPtr = ptr; + return 0; + } + do { + ptr += enc->minBytesPerChar; + } while (isSpace(toAscii(enc, ptr, end))); + if (ptr == end) { + *namePtr = NULL; + return 1; + } + *namePtr = ptr; + for (;;) { + c = toAscii(enc, ptr, end); + if (c == -1) { + *nextTokPtr = ptr; + return 0; + } + if (c == ASCII_EQUALS) { + *nameEndPtr = ptr; + break; + } + if (isSpace(c)) { + *nameEndPtr = ptr; + do { + ptr += enc->minBytesPerChar; + } while (isSpace(c = toAscii(enc, ptr, end))); + if (c != ASCII_EQUALS) { + *nextTokPtr = ptr; + return 0; + } + break; + } + ptr += enc->minBytesPerChar; + } + if (ptr == *namePtr) { + *nextTokPtr = ptr; + return 0; + } + ptr += enc->minBytesPerChar; + c = toAscii(enc, ptr, end); + while (isSpace(c)) { + ptr += enc->minBytesPerChar; + c = toAscii(enc, ptr, end); + } + if (c != ASCII_QUOT && c != ASCII_APOS) { + *nextTokPtr = ptr; + return 0; + } + open = (char)c; + ptr += enc->minBytesPerChar; + *valPtr = ptr; + for (;; ptr += enc->minBytesPerChar) { + c = toAscii(enc, ptr, end); + if (c == open) + break; + if (!(ASCII_a <= c && c <= ASCII_z) + && !(ASCII_A <= c && c <= ASCII_Z) + && !(ASCII_0 <= c && c <= ASCII_9) + && c != ASCII_PERIOD + && c != ASCII_MINUS + && c != ASCII_UNDERSCORE) { + *nextTokPtr = ptr; + return 0; + } + } + *nextTokPtr = ptr + enc->minBytesPerChar; + return 1; +} + +static const char KW_version[] = { + ASCII_v, ASCII_e, ASCII_r, ASCII_s, ASCII_i, ASCII_o, ASCII_n, '\0' +}; + +static const char KW_encoding[] = { + ASCII_e, ASCII_n, ASCII_c, ASCII_o, ASCII_d, ASCII_i, ASCII_n, ASCII_g, '\0' +}; + +static const char KW_standalone[] = { + ASCII_s, ASCII_t, ASCII_a, ASCII_n, ASCII_d, ASCII_a, ASCII_l, ASCII_o, + ASCII_n, ASCII_e, '\0' +}; + +static const char KW_yes[] = { + ASCII_y, ASCII_e, ASCII_s, '\0' +}; + +static const char KW_no[] = { + ASCII_n, ASCII_o, '\0' +}; + +static int +doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *, + const char *, + const char *), + int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingName, + const ENCODING **encoding, + int *standalone) +{ + const char *val = NULL; + const char *name = NULL; + const char *nameEnd = NULL; + ptr += 5 * enc->minBytesPerChar; + end -= 2 * enc->minBytesPerChar; + if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr) + || !name) { + *badPtr = ptr; + return 0; + } + if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_version)) { + if (!isGeneralTextEntity) { + *badPtr = name; + return 0; + } + } + else { + if (versionPtr) + *versionPtr = val; + if (versionEndPtr) + *versionEndPtr = ptr; + if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { + *badPtr = ptr; + return 0; + } + if (!name) { + if (isGeneralTextEntity) { + /* a TextDecl must have an EncodingDecl */ + *badPtr = ptr; + return 0; + } + return 1; + } + } + if (XmlNameMatchesAscii(enc, name, nameEnd, KW_encoding)) { + int c = toAscii(enc, val, end); + if (!(ASCII_a <= c && c <= ASCII_z) && !(ASCII_A <= c && c <= ASCII_Z)) { + *badPtr = val; + return 0; + } + if (encodingName) + *encodingName = val; + if (encoding) + *encoding = encodingFinder(enc, val, ptr - enc->minBytesPerChar); + if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { + *badPtr = ptr; + return 0; + } + if (!name) + return 1; + } + if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_standalone) + || isGeneralTextEntity) { + *badPtr = name; + return 0; + } + if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_yes)) { + if (standalone) + *standalone = 1; + } + else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_no)) { + if (standalone) + *standalone = 0; + } + else { + *badPtr = val; + return 0; + } + while (isSpace(toAscii(enc, ptr, end))) + ptr += enc->minBytesPerChar; + if (ptr != end) { + *badPtr = ptr; + return 0; + } + return 1; +} + +static int FASTCALL +checkCharRefNumber(int result) +{ + switch (result >> 8) { + case 0xD8: case 0xD9: case 0xDA: case 0xDB: + case 0xDC: case 0xDD: case 0xDE: case 0xDF: + return -1; + case 0: + if (latin1_encoding.type[result] == BT_NONXML) + return -1; + break; + case 0xFF: + if (result == 0xFFFE || result == 0xFFFF) + return -1; + break; + } + return result; +} + +int FASTCALL +XmlUtf8Encode(int c, char *buf) +{ + enum { + /* minN is minimum legal resulting value for N byte sequence */ + min2 = 0x80, + min3 = 0x800, + min4 = 0x10000 + }; + + if (c < 0) + return 0; + if (c < min2) { + buf[0] = (char)(c | UTF8_cval1); + return 1; + } + if (c < min3) { + buf[0] = (char)((c >> 6) | UTF8_cval2); + buf[1] = (char)((c & 0x3f) | 0x80); + return 2; + } + if (c < min4) { + buf[0] = (char)((c >> 12) | UTF8_cval3); + buf[1] = (char)(((c >> 6) & 0x3f) | 0x80); + buf[2] = (char)((c & 0x3f) | 0x80); + return 3; + } + if (c < 0x110000) { + buf[0] = (char)((c >> 18) | UTF8_cval4); + buf[1] = (char)(((c >> 12) & 0x3f) | 0x80); + buf[2] = (char)(((c >> 6) & 0x3f) | 0x80); + buf[3] = (char)((c & 0x3f) | 0x80); + return 4; + } + return 0; +} + +int FASTCALL +XmlUtf16Encode(int charNum, unsigned short *buf) +{ + if (charNum < 0) + return 0; + if (charNum < 0x10000) { + buf[0] = (unsigned short)charNum; + return 1; + } + if (charNum < 0x110000) { + charNum -= 0x10000; + buf[0] = (unsigned short)((charNum >> 10) + 0xD800); + buf[1] = (unsigned short)((charNum & 0x3FF) + 0xDC00); + return 2; + } + return 0; +} + +struct unknown_encoding { + struct normal_encoding normal; + CONVERTER convert; + void *userData; + unsigned short utf16[256]; + char utf8[256][4]; +}; + +#define AS_UNKNOWN_ENCODING(enc) ((const struct unknown_encoding *) (enc)) + +int +XmlSizeOfUnknownEncoding(void) +{ + return sizeof(struct unknown_encoding); +} + +static int PTRFASTCALL +unknown_isName(const ENCODING *enc, const char *p) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + int c = uenc->convert(uenc->userData, p); + if (c & ~0xFFFF) + return 0; + return UCS2_GET_NAMING(namePages, c >> 8, c & 0xFF); +} + +static int PTRFASTCALL +unknown_isNmstrt(const ENCODING *enc, const char *p) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + int c = uenc->convert(uenc->userData, p); + if (c & ~0xFFFF) + return 0; + return UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xFF); +} + +static int PTRFASTCALL +unknown_isInvalid(const ENCODING *enc, const char *p) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + int c = uenc->convert(uenc->userData, p); + return (c & ~0xFFFF) || checkCharRefNumber(c) < 0; +} + +static void PTRCALL +unknown_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + char buf[XML_UTF8_ENCODE_MAX]; + for (;;) { + const char *utf8; + int n; + if (*fromP == fromLim) + break; + utf8 = uenc->utf8[(unsigned char)**fromP]; + n = *utf8++; + if (n == 0) { + int c = uenc->convert(uenc->userData, *fromP); + n = XmlUtf8Encode(c, buf); + if (n > toLim - *toP) + break; + utf8 = buf; + *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] + - (BT_LEAD2 - 2)); + } + else { + if (n > toLim - *toP) + break; + (*fromP)++; + } + do { + *(*toP)++ = *utf8++; + } while (--n != 0); + } +} + +static void PTRCALL +unknown_toUtf16(const ENCODING *enc, + const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + while (*fromP != fromLim && *toP != toLim) { + unsigned short c = uenc->utf16[(unsigned char)**fromP]; + if (c == 0) { + c = (unsigned short) + uenc->convert(uenc->userData, *fromP); + *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] + - (BT_LEAD2 - 2)); + } + else + (*fromP)++; + *(*toP)++ = c; + } +} + +ENCODING * +XmlInitUnknownEncoding(void *mem, + int *table, + CONVERTER convert, + void *userData) +{ + int i; + struct unknown_encoding *e = (struct unknown_encoding *)mem; + for (i = 0; i < (int)sizeof(struct normal_encoding); i++) + ((char *)mem)[i] = ((char *)&latin1_encoding)[i]; + for (i = 0; i < 128; i++) + if (latin1_encoding.type[i] != BT_OTHER + && latin1_encoding.type[i] != BT_NONXML + && table[i] != i) + return 0; + for (i = 0; i < 256; i++) { + int c = table[i]; + if (c == -1) { + e->normal.type[i] = BT_MALFORM; + /* This shouldn't really get used. */ + e->utf16[i] = 0xFFFF; + e->utf8[i][0] = 1; + e->utf8[i][1] = 0; + } + else if (c < 0) { + if (c < -4) + return 0; + e->normal.type[i] = (unsigned char)(BT_LEAD2 - (c + 2)); + e->utf8[i][0] = 0; + e->utf16[i] = 0; + } + else if (c < 0x80) { + if (latin1_encoding.type[c] != BT_OTHER + && latin1_encoding.type[c] != BT_NONXML + && c != i) + return 0; + e->normal.type[i] = latin1_encoding.type[c]; + e->utf8[i][0] = 1; + e->utf8[i][1] = (char)c; + e->utf16[i] = (unsigned short)(c == 0 ? 0xFFFF : c); + } + else if (checkCharRefNumber(c) < 0) { + e->normal.type[i] = BT_NONXML; + /* This shouldn't really get used. */ + e->utf16[i] = 0xFFFF; + e->utf8[i][0] = 1; + e->utf8[i][1] = 0; + } + else { + if (c > 0xFFFF) + return 0; + if (UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xff)) + e->normal.type[i] = BT_NMSTRT; + else if (UCS2_GET_NAMING(namePages, c >> 8, c & 0xff)) + e->normal.type[i] = BT_NAME; + else + e->normal.type[i] = BT_OTHER; + e->utf8[i][0] = (char)XmlUtf8Encode(c, e->utf8[i] + 1); + e->utf16[i] = (unsigned short)c; + } + } + e->userData = userData; + e->convert = convert; + if (convert) { + e->normal.isName2 = unknown_isName; + e->normal.isName3 = unknown_isName; + e->normal.isName4 = unknown_isName; + e->normal.isNmstrt2 = unknown_isNmstrt; + e->normal.isNmstrt3 = unknown_isNmstrt; + e->normal.isNmstrt4 = unknown_isNmstrt; + e->normal.isInvalid2 = unknown_isInvalid; + e->normal.isInvalid3 = unknown_isInvalid; + e->normal.isInvalid4 = unknown_isInvalid; + } + e->normal.enc.utf8Convert = unknown_toUtf8; + e->normal.enc.utf16Convert = unknown_toUtf16; + return &(e->normal.enc); +} + +/* If this enumeration is changed, getEncodingIndex and encodings +must also be changed. */ +enum { + UNKNOWN_ENC = -1, + ISO_8859_1_ENC = 0, + US_ASCII_ENC, + UTF_8_ENC, + UTF_16_ENC, + UTF_16BE_ENC, + UTF_16LE_ENC, + /* must match encodingNames up to here */ + NO_ENC +}; + +static const char KW_ISO_8859_1[] = { + ASCII_I, ASCII_S, ASCII_O, ASCII_MINUS, ASCII_8, ASCII_8, ASCII_5, ASCII_9, + ASCII_MINUS, ASCII_1, '\0' +}; +static const char KW_US_ASCII[] = { + ASCII_U, ASCII_S, ASCII_MINUS, ASCII_A, ASCII_S, ASCII_C, ASCII_I, ASCII_I, + '\0' +}; +static const char KW_UTF_8[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_8, '\0' +}; +static const char KW_UTF_16[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, '\0' +}; +static const char KW_UTF_16BE[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_B, ASCII_E, + '\0' +}; +static const char KW_UTF_16LE[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_L, ASCII_E, + '\0' +}; + +static int FASTCALL +getEncodingIndex(const char *name) +{ + static const char * const encodingNames[] = { + KW_ISO_8859_1, + KW_US_ASCII, + KW_UTF_8, + KW_UTF_16, + KW_UTF_16BE, + KW_UTF_16LE, + }; + int i; + if (name == NULL) + return NO_ENC; + for (i = 0; i < (int)(sizeof(encodingNames)/sizeof(encodingNames[0])); i++) + if (streqci(name, encodingNames[i])) + return i; + return UNKNOWN_ENC; +} + +/* For binary compatibility, we store the index of the encoding + specified at initialization in the isUtf16 member. +*/ + +#define INIT_ENC_INDEX(enc) ((int)(enc)->initEnc.isUtf16) +#define SET_INIT_ENC_INDEX(enc, i) ((enc)->initEnc.isUtf16 = (char)i) + +/* This is what detects the encoding. encodingTable maps from + encoding indices to encodings; INIT_ENC_INDEX(enc) is the index of + the external (protocol) specified encoding; state is + XML_CONTENT_STATE if we're parsing an external text entity, and + XML_PROLOG_STATE otherwise. +*/ + + +static int +initScan(const ENCODING * const *encodingTable, + const INIT_ENCODING *enc, + int state, + const char *ptr, + const char *end, + const char **nextTokPtr) +{ + const ENCODING **encPtr; + + if (ptr == end) + return XML_TOK_NONE; + encPtr = enc->encPtr; + if (ptr + 1 == end) { + /* only a single byte available for auto-detection */ +#ifndef XML_DTD /* FIXME */ + /* a well-formed document entity must have more than one byte */ + if (state != XML_CONTENT_STATE) + return XML_TOK_PARTIAL; +#endif + /* so we're parsing an external text entity... */ + /* if UTF-16 was externally specified, then we need at least 2 bytes */ + switch (INIT_ENC_INDEX(enc)) { + case UTF_16_ENC: + case UTF_16LE_ENC: + case UTF_16BE_ENC: + return XML_TOK_PARTIAL; + } + switch ((unsigned char)*ptr) { + case 0xFE: + case 0xFF: + case 0xEF: /* possibly first byte of UTF-8 BOM */ + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC + && state == XML_CONTENT_STATE) + break; + /* fall through */ + case 0x00: + case 0x3C: + return XML_TOK_PARTIAL; + } + } + else { + switch (((unsigned char)ptr[0] << 8) | (unsigned char)ptr[1]) { + case 0xFEFF: + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC + && state == XML_CONTENT_STATE) + break; + *nextTokPtr = ptr + 2; + *encPtr = encodingTable[UTF_16BE_ENC]; + return XML_TOK_BOM; + /* 00 3C is handled in the default case */ + case 0x3C00: + if ((INIT_ENC_INDEX(enc) == UTF_16BE_ENC + || INIT_ENC_INDEX(enc) == UTF_16_ENC) + && state == XML_CONTENT_STATE) + break; + *encPtr = encodingTable[UTF_16LE_ENC]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); + case 0xFFFE: + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC + && state == XML_CONTENT_STATE) + break; + *nextTokPtr = ptr + 2; + *encPtr = encodingTable[UTF_16LE_ENC]; + return XML_TOK_BOM; + case 0xEFBB: + /* Maybe a UTF-8 BOM (EF BB BF) */ + /* If there's an explicitly specified (external) encoding + of ISO-8859-1 or some flavour of UTF-16 + and this is an external text entity, + don't look for the BOM, + because it might be a legal data. + */ + if (state == XML_CONTENT_STATE) { + int e = INIT_ENC_INDEX(enc); + if (e == ISO_8859_1_ENC || e == UTF_16BE_ENC + || e == UTF_16LE_ENC || e == UTF_16_ENC) + break; + } + if (ptr + 2 == end) + return XML_TOK_PARTIAL; + if ((unsigned char)ptr[2] == 0xBF) { + *nextTokPtr = ptr + 3; + *encPtr = encodingTable[UTF_8_ENC]; + return XML_TOK_BOM; + } + break; + default: + if (ptr[0] == '\0') { + /* 0 isn't a legal data character. Furthermore a document + entity can only start with ASCII characters. So the only + way this can fail to be big-endian UTF-16 if it it's an + external parsed general entity that's labelled as + UTF-16LE. + */ + if (state == XML_CONTENT_STATE && INIT_ENC_INDEX(enc) == UTF_16LE_ENC) + break; + *encPtr = encodingTable[UTF_16BE_ENC]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); + } + else if (ptr[1] == '\0') { + /* We could recover here in the case: + - parsing an external entity + - second byte is 0 + - no externally specified encoding + - no encoding declaration + by assuming UTF-16LE. But we don't, because this would mean when + presented just with a single byte, we couldn't reliably determine + whether we needed further bytes. + */ + if (state == XML_CONTENT_STATE) + break; + *encPtr = encodingTable[UTF_16LE_ENC]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); + } + break; + } + } + *encPtr = encodingTable[INIT_ENC_INDEX(enc)]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); +} + + +#define NS(x) x +#define ns(x) x +#define XML_TOK_NS_C +#include "xmltok_ns.c" +#undef XML_TOK_NS_C +#undef NS +#undef ns + +#ifdef XML_NS + +#define NS(x) x ## NS +#define ns(x) x ## _ns + +#define XML_TOK_NS_C +#include "xmltok_ns.c" +#undef XML_TOK_NS_C + +#undef NS +#undef ns + +ENCODING * +XmlInitUnknownEncodingNS(void *mem, + int *table, + CONVERTER convert, + void *userData) +{ + ENCODING *enc = XmlInitUnknownEncoding(mem, table, convert, userData); + if (enc) + ((struct normal_encoding *)enc)->type[ASCII_COLON] = BT_COLON; + return enc; +} + +#endif /* XML_NS */ diff --git a/project/jni/expat/lib/xmltok.h b/project/jni/expat/lib/xmltok.h new file mode 100644 index 000000000..ca867aa6b --- /dev/null +++ b/project/jni/expat/lib/xmltok.h @@ -0,0 +1,316 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef XmlTok_INCLUDED +#define XmlTok_INCLUDED 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* The following token may be returned by XmlContentTok */ +#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be + start of illegal ]]> sequence */ +/* The following tokens may be returned by both XmlPrologTok and + XmlContentTok. +*/ +#define XML_TOK_NONE -4 /* The string to be scanned is empty */ +#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan; + might be part of CRLF sequence */ +#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */ +#define XML_TOK_PARTIAL -1 /* only part of a token */ +#define XML_TOK_INVALID 0 + +/* The following tokens are returned by XmlContentTok; some are also + returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok. +*/ +#define XML_TOK_START_TAG_WITH_ATTS 1 +#define XML_TOK_START_TAG_NO_ATTS 2 +#define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag */ +#define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4 +#define XML_TOK_END_TAG 5 +#define XML_TOK_DATA_CHARS 6 +#define XML_TOK_DATA_NEWLINE 7 +#define XML_TOK_CDATA_SECT_OPEN 8 +#define XML_TOK_ENTITY_REF 9 +#define XML_TOK_CHAR_REF 10 /* numeric character reference */ + +/* The following tokens may be returned by both XmlPrologTok and + XmlContentTok. +*/ +#define XML_TOK_PI 11 /* processing instruction */ +#define XML_TOK_XML_DECL 12 /* XML decl or text decl */ +#define XML_TOK_COMMENT 13 +#define XML_TOK_BOM 14 /* Byte order mark */ + +/* The following tokens are returned only by XmlPrologTok */ +#define XML_TOK_PROLOG_S 15 +#define XML_TOK_DECL_OPEN 16 /* */ +#define XML_TOK_NAME 18 +#define XML_TOK_NMTOKEN 19 +#define XML_TOK_POUND_NAME 20 /* #name */ +#define XML_TOK_OR 21 /* | */ +#define XML_TOK_PERCENT 22 +#define XML_TOK_OPEN_PAREN 23 +#define XML_TOK_CLOSE_PAREN 24 +#define XML_TOK_OPEN_BRACKET 25 +#define XML_TOK_CLOSE_BRACKET 26 +#define XML_TOK_LITERAL 27 +#define XML_TOK_PARAM_ENTITY_REF 28 +#define XML_TOK_INSTANCE_START 29 + +/* The following occur only in element type declarations */ +#define XML_TOK_NAME_QUESTION 30 /* name? */ +#define XML_TOK_NAME_ASTERISK 31 /* name* */ +#define XML_TOK_NAME_PLUS 32 /* name+ */ +#define XML_TOK_COND_SECT_OPEN 33 /* */ +#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */ +#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */ +#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */ +#define XML_TOK_COMMA 38 + +/* The following token is returned only by XmlAttributeValueTok */ +#define XML_TOK_ATTRIBUTE_VALUE_S 39 + +/* The following token is returned only by XmlCdataSectionTok */ +#define XML_TOK_CDATA_SECT_CLOSE 40 + +/* With namespace processing this is returned by XmlPrologTok for a + name with a colon. +*/ +#define XML_TOK_PREFIXED_NAME 41 + +#ifdef XML_DTD +#define XML_TOK_IGNORE_SECT 42 +#endif /* XML_DTD */ + +#ifdef XML_DTD +#define XML_N_STATES 4 +#else /* not XML_DTD */ +#define XML_N_STATES 3 +#endif /* not XML_DTD */ + +#define XML_PROLOG_STATE 0 +#define XML_CONTENT_STATE 1 +#define XML_CDATA_SECTION_STATE 2 +#ifdef XML_DTD +#define XML_IGNORE_SECTION_STATE 3 +#endif /* XML_DTD */ + +#define XML_N_LITERAL_TYPES 2 +#define XML_ATTRIBUTE_VALUE_LITERAL 0 +#define XML_ENTITY_VALUE_LITERAL 1 + +/* The size of the buffer passed to XmlUtf8Encode must be at least this. */ +#define XML_UTF8_ENCODE_MAX 4 +/* The size of the buffer passed to XmlUtf16Encode must be at least this. */ +#define XML_UTF16_ENCODE_MAX 2 + +typedef struct position { + /* first line and first column are 0 not 1 */ + XML_Size lineNumber; + XML_Size columnNumber; +} POSITION; + +typedef struct { + const char *name; + const char *valuePtr; + const char *valueEnd; + char normalized; +} ATTRIBUTE; + +struct encoding; +typedef struct encoding ENCODING; + +typedef int (PTRCALL *SCANNER)(const ENCODING *, + const char *, + const char *, + const char **); + +struct encoding { + SCANNER scanners[XML_N_STATES]; + SCANNER literalScanners[XML_N_LITERAL_TYPES]; + int (PTRCALL *sameName)(const ENCODING *, + const char *, + const char *); + int (PTRCALL *nameMatchesAscii)(const ENCODING *, + const char *, + const char *, + const char *); + int (PTRFASTCALL *nameLength)(const ENCODING *, const char *); + const char *(PTRFASTCALL *skipS)(const ENCODING *, const char *); + int (PTRCALL *getAtts)(const ENCODING *enc, + const char *ptr, + int attsMax, + ATTRIBUTE *atts); + int (PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr); + int (PTRCALL *predefinedEntityName)(const ENCODING *, + const char *, + const char *); + void (PTRCALL *updatePosition)(const ENCODING *, + const char *ptr, + const char *end, + POSITION *); + int (PTRCALL *isPublicId)(const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr); + void (PTRCALL *utf8Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, + char **toP, + const char *toLim); + void (PTRCALL *utf16Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, + unsigned short **toP, + const unsigned short *toLim); + int minBytesPerChar; + char isUtf8; + char isUtf16; +}; + +/* Scan the string starting at ptr until the end of the next complete + token, but do not scan past eptr. Return an integer giving the + type of token. + + Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set. + + Return XML_TOK_PARTIAL when the string does not contain a complete + token; nextTokPtr will not be set. + + Return XML_TOK_INVALID when the string does not start a valid + token; nextTokPtr will be set to point to the character which made + the token invalid. + + Otherwise the string starts with a valid token; nextTokPtr will be + set to point to the character following the end of that token. + + Each data character counts as a single token, but adjacent data + characters may be returned together. Similarly for characters in + the prolog outside literals, comments and processing instructions. +*/ + + +#define XmlTok(enc, state, ptr, end, nextTokPtr) \ + (((enc)->scanners[state])(enc, ptr, end, nextTokPtr)) + +#define XmlPrologTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr) + +#define XmlContentTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr) + +#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr) + +#ifdef XML_DTD + +#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr) + +#endif /* XML_DTD */ + +/* This is used for performing a 2nd-level tokenization on the content + of a literal that has already been returned by XmlTok. +*/ +#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \ + (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr)) + +#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \ + XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr) + +#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \ + XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr) + +#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2)) + +#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \ + (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2)) + +#define XmlNameLength(enc, ptr) \ + (((enc)->nameLength)(enc, ptr)) + +#define XmlSkipS(enc, ptr) \ + (((enc)->skipS)(enc, ptr)) + +#define XmlGetAttributes(enc, ptr, attsMax, atts) \ + (((enc)->getAtts)(enc, ptr, attsMax, atts)) + +#define XmlCharRefNumber(enc, ptr) \ + (((enc)->charRefNumber)(enc, ptr)) + +#define XmlPredefinedEntityName(enc, ptr, end) \ + (((enc)->predefinedEntityName)(enc, ptr, end)) + +#define XmlUpdatePosition(enc, ptr, end, pos) \ + (((enc)->updatePosition)(enc, ptr, end, pos)) + +#define XmlIsPublicId(enc, ptr, end, badPtr) \ + (((enc)->isPublicId)(enc, ptr, end, badPtr)) + +#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \ + (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim)) + +#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \ + (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim)) + +typedef struct { + ENCODING initEnc; + const ENCODING **encPtr; +} INIT_ENCODING; + +int XmlParseXmlDecl(int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingNamePtr, + const ENCODING **namedEncodingPtr, + int *standalonePtr); + +int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); +const ENCODING *XmlGetUtf8InternalEncoding(void); +const ENCODING *XmlGetUtf16InternalEncoding(void); +int FASTCALL XmlUtf8Encode(int charNumber, char *buf); +int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf); +int XmlSizeOfUnknownEncoding(void); + + +typedef int (XMLCALL *CONVERTER) (void *userData, const char *p); + +ENCODING * +XmlInitUnknownEncoding(void *mem, + int *table, + CONVERTER convert, + void *userData); + +int XmlParseXmlDeclNS(int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingNamePtr, + const ENCODING **namedEncodingPtr, + int *standalonePtr); + +int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name); +const ENCODING *XmlGetUtf8InternalEncodingNS(void); +const ENCODING *XmlGetUtf16InternalEncodingNS(void); +ENCODING * +XmlInitUnknownEncodingNS(void *mem, + int *table, + CONVERTER convert, + void *userData); +#ifdef __cplusplus +} +#endif + +#endif /* not XmlTok_INCLUDED */ diff --git a/project/jni/expat/lib/xmltok_impl.c b/project/jni/expat/lib/xmltok_impl.c new file mode 100644 index 000000000..9c2895b87 --- /dev/null +++ b/project/jni/expat/lib/xmltok_impl.c @@ -0,0 +1,1783 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* This file is included! */ +#ifdef XML_TOK_IMPL_C + +#ifndef IS_INVALID_CHAR +#define IS_INVALID_CHAR(enc, ptr, n) (0) +#endif + +#define INVALID_LEAD_CASE(n, ptr, nextTokPtr) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (IS_INVALID_CHAR(enc, ptr, n)) { \ + *(nextTokPtr) = (ptr); \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +#define INVALID_CASES(ptr, nextTokPtr) \ + INVALID_LEAD_CASE(2, ptr, nextTokPtr) \ + INVALID_LEAD_CASE(3, ptr, nextTokPtr) \ + INVALID_LEAD_CASE(4, ptr, nextTokPtr) \ + case BT_NONXML: \ + case BT_MALFORM: \ + case BT_TRAIL: \ + *(nextTokPtr) = (ptr); \ + return XML_TOK_INVALID; + +#define CHECK_NAME_CASE(n, enc, ptr, end, nextTokPtr) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (!IS_NAME_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +#define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) \ + case BT_NONASCII: \ + if (!IS_NAME_CHAR_MINBPC(enc, ptr)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + case BT_NMSTRT: \ + case BT_HEX: \ + case BT_DIGIT: \ + case BT_NAME: \ + case BT_MINUS: \ + ptr += MINBPC(enc); \ + break; \ + CHECK_NAME_CASE(2, enc, ptr, end, nextTokPtr) \ + CHECK_NAME_CASE(3, enc, ptr, end, nextTokPtr) \ + CHECK_NAME_CASE(4, enc, ptr, end, nextTokPtr) + +#define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (!IS_NMSTRT_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +#define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) \ + case BT_NONASCII: \ + if (!IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + case BT_NMSTRT: \ + case BT_HEX: \ + ptr += MINBPC(enc); \ + break; \ + CHECK_NMSTRT_CASE(2, enc, ptr, end, nextTokPtr) \ + CHECK_NMSTRT_CASE(3, enc, ptr, end, nextTokPtr) \ + CHECK_NMSTRT_CASE(4, enc, ptr, end, nextTokPtr) + +#ifndef PREFIX +#define PREFIX(ident) ident +#endif + +/* ptr points to character following " */ + switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) { + case BT_S: case BT_CR: case BT_LF: case BT_PERCNT: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + /* fall through */ + case BT_S: case BT_CR: case BT_LF: + *nextTokPtr = ptr; + return XML_TOK_DECL_OPEN; + case BT_NMSTRT: + case BT_HEX: + ptr += MINBPC(enc); + break; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, + const char *end, int *tokPtr) +{ + int upper = 0; + *tokPtr = XML_TOK_PI; + if (end - ptr != MINBPC(enc)*3) + return 1; + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_x: + break; + case ASCII_X: + upper = 1; + break; + default: + return 1; + } + ptr += MINBPC(enc); + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_m: + break; + case ASCII_M: + upper = 1; + break; + default: + return 1; + } + ptr += MINBPC(enc); + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_l: + break; + case ASCII_L: + upper = 1; + break; + default: + return 1; + } + if (upper) + return 0; + *tokPtr = XML_TOK_XML_DECL; + return 1; +} + +/* ptr points to character following " 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + if (n == 0) + return XML_TOK_PARTIAL; + end = ptr + n; + } + } + switch (BYTE_TYPE(enc, ptr)) { + case BT_RSQB: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) + break; + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + ptr -= MINBPC(enc); + break; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CDATA_SECT_CLOSE; + case BT_CR: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + case BT_LF: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + INVALID_CASES(ptr, nextTokPtr) + default: + ptr += MINBPC(enc); + break; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_DATA_CHARS; \ + } \ + ptr += n; \ + break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NONXML: + case BT_MALFORM: + case BT_TRAIL: + case BT_CR: + case BT_LF: + case BT_RSQB: + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +/* ptr points to character following " 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + if (n == 0) + return XML_TOK_PARTIAL; + end = ptr + n; + } + } + switch (BYTE_TYPE(enc, ptr)) { + case BT_LT: + return PREFIX(scanLt)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_AMP: + return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_CR: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_CR; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + case BT_LF: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + case BT_RSQB: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_RSQB; + if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) + break; + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_RSQB; + if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + ptr -= MINBPC(enc); + break; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + INVALID_CASES(ptr, nextTokPtr) + default: + ptr += MINBPC(enc); + break; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_DATA_CHARS; \ + } \ + ptr += n; \ + break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_RSQB: + if (ptr + MINBPC(enc) != end) { + if (!CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) { + ptr += MINBPC(enc); + break; + } + if (ptr + 2*MINBPC(enc) != end) { + if (!CHAR_MATCHES(enc, ptr + 2*MINBPC(enc), ASCII_GT)) { + ptr += MINBPC(enc); + break; + } + *nextTokPtr = ptr + 2*MINBPC(enc); + return XML_TOK_INVALID; + } + } + /* fall through */ + case BT_AMP: + case BT_LT: + case BT_NONXML: + case BT_MALFORM: + case BT_TRAIL: + case BT_CR: + case BT_LF: + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +/* ptr points to character following "%" */ + +static int PTRCALL +PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + case BT_S: case BT_LF: case BT_CR: case BT_PERCNT: + *nextTokPtr = ptr; + return XML_TOK_PERCENT; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_SEMI: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_PARAM_ENTITY_REF; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_CR: case BT_LF: case BT_S: + case BT_RPAR: case BT_GT: case BT_PERCNT: case BT_VERBAR: + *nextTokPtr = ptr; + return XML_TOK_POUND_NAME; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return -XML_TOK_POUND_NAME; +} + +static int PTRCALL +PREFIX(scanLit)(int open, const ENCODING *enc, + const char *ptr, const char *end, + const char **nextTokPtr) +{ + while (ptr != end) { + int t = BYTE_TYPE(enc, ptr); + switch (t) { + INVALID_CASES(ptr, nextTokPtr) + case BT_QUOT: + case BT_APOS: + ptr += MINBPC(enc); + if (t != open) + break; + if (ptr == end) + return -XML_TOK_LITERAL; + *nextTokPtr = ptr; + switch (BYTE_TYPE(enc, ptr)) { + case BT_S: case BT_CR: case BT_LF: + case BT_GT: case BT_PERCNT: case BT_LSQB: + return XML_TOK_LITERAL; + default: + return XML_TOK_INVALID; + } + default: + ptr += MINBPC(enc); + break; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + int tok; + if (ptr == end) + return XML_TOK_NONE; + if (MINBPC(enc) > 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + if (n == 0) + return XML_TOK_PARTIAL; + end = ptr + n; + } + } + switch (BYTE_TYPE(enc, ptr)) { + case BT_QUOT: + return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_APOS: + return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_LT: + { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + case BT_EXCL: + return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_QUEST: + return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_NMSTRT: + case BT_HEX: + case BT_NONASCII: + case BT_LEAD2: + case BT_LEAD3: + case BT_LEAD4: + *nextTokPtr = ptr - MINBPC(enc); + return XML_TOK_INSTANCE_START; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + case BT_CR: + if (ptr + MINBPC(enc) == end) { + *nextTokPtr = end; + /* indicate that this might be part of a CR/LF pair */ + return -XML_TOK_PROLOG_S; + } + /* fall through */ + case BT_S: case BT_LF: + for (;;) { + ptr += MINBPC(enc); + if (ptr == end) + break; + switch (BYTE_TYPE(enc, ptr)) { + case BT_S: case BT_LF: + break; + case BT_CR: + /* don't split CR/LF pair */ + if (ptr + MINBPC(enc) != end) + break; + /* fall through */ + default: + *nextTokPtr = ptr; + return XML_TOK_PROLOG_S; + } + } + *nextTokPtr = ptr; + return XML_TOK_PROLOG_S; + case BT_PERCNT: + return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_COMMA: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_COMMA; + case BT_LSQB: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_OPEN_BRACKET; + case BT_RSQB: + ptr += MINBPC(enc); + if (ptr == end) + return -XML_TOK_CLOSE_BRACKET; + if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { + if (ptr + MINBPC(enc) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) { + *nextTokPtr = ptr + 2*MINBPC(enc); + return XML_TOK_COND_SECT_CLOSE; + } + } + *nextTokPtr = ptr; + return XML_TOK_CLOSE_BRACKET; + case BT_LPAR: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_OPEN_PAREN; + case BT_RPAR: + ptr += MINBPC(enc); + if (ptr == end) + return -XML_TOK_CLOSE_PAREN; + switch (BYTE_TYPE(enc, ptr)) { + case BT_AST: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CLOSE_PAREN_ASTERISK; + case BT_QUEST: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CLOSE_PAREN_QUESTION; + case BT_PLUS: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CLOSE_PAREN_PLUS; + case BT_CR: case BT_LF: case BT_S: + case BT_GT: case BT_COMMA: case BT_VERBAR: + case BT_RPAR: + *nextTokPtr = ptr; + return XML_TOK_CLOSE_PAREN; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + case BT_VERBAR: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_OR; + case BT_GT: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DECL_CLOSE; + case BT_NUM: + return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr); +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (IS_NMSTRT_CHAR(enc, ptr, n)) { \ + ptr += n; \ + tok = XML_TOK_NAME; \ + break; \ + } \ + if (IS_NAME_CHAR(enc, ptr, n)) { \ + ptr += n; \ + tok = XML_TOK_NMTOKEN; \ + break; \ + } \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NMSTRT: + case BT_HEX: + tok = XML_TOK_NAME; + ptr += MINBPC(enc); + break; + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: +#ifdef XML_NS + case BT_COLON: +#endif + tok = XML_TOK_NMTOKEN; + ptr += MINBPC(enc); + break; + case BT_NONASCII: + if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { + ptr += MINBPC(enc); + tok = XML_TOK_NAME; + break; + } + if (IS_NAME_CHAR_MINBPC(enc, ptr)) { + ptr += MINBPC(enc); + tok = XML_TOK_NMTOKEN; + break; + } + /* fall through */ + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_GT: case BT_RPAR: case BT_COMMA: + case BT_VERBAR: case BT_LSQB: case BT_PERCNT: + case BT_S: case BT_CR: case BT_LF: + *nextTokPtr = ptr; + return tok; +#ifdef XML_NS + case BT_COLON: + ptr += MINBPC(enc); + switch (tok) { + case XML_TOK_NAME: + if (ptr == end) + return XML_TOK_PARTIAL; + tok = XML_TOK_PREFIXED_NAME; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + default: + tok = XML_TOK_NMTOKEN; + break; + } + break; + case XML_TOK_PREFIXED_NAME: + tok = XML_TOK_NMTOKEN; + break; + } + break; +#endif + case BT_PLUS: + if (tok == XML_TOK_NMTOKEN) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_NAME_PLUS; + case BT_AST: + if (tok == XML_TOK_NMTOKEN) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_NAME_ASTERISK; + case BT_QUEST: + if (tok == XML_TOK_NMTOKEN) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_NAME_QUESTION; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return -tok; +} + +static int PTRCALL +PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + const char *start; + if (ptr == end) + return XML_TOK_NONE; + start = ptr; + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: ptr += n; break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_AMP: + if (ptr == start) + return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_LT: + /* this is for inside entity references */ + *nextTokPtr = ptr; + return XML_TOK_INVALID; + case BT_LF: + if (ptr == start) { + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_CR: + if (ptr == start) { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_CR; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_S: + if (ptr == start) { + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_ATTRIBUTE_VALUE_S; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +static int PTRCALL +PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + const char *start; + if (ptr == end) + return XML_TOK_NONE; + start = ptr; + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: ptr += n; break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_AMP: + if (ptr == start) + return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_PERCNT: + if (ptr == start) { + int tok = PREFIX(scanPercent)(enc, ptr + MINBPC(enc), + end, nextTokPtr); + return (tok == XML_TOK_PERCENT) ? XML_TOK_INVALID : tok; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_LF: + if (ptr == start) { + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_CR: + if (ptr == start) { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_CR; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +#ifdef XML_DTD + +static int PTRCALL +PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + int level = 0; + if (MINBPC(enc) > 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + end = ptr + n; + } + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + INVALID_CASES(ptr, nextTokPtr) + case BT_LT: + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_EXCL)) { + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_LSQB)) { + ++level; + ptr += MINBPC(enc); + } + } + break; + case BT_RSQB: + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { + ptr += MINBPC(enc); + if (level == 0) { + *nextTokPtr = ptr; + return XML_TOK_IGNORE_SECT; + } + --level; + } + } + break; + default: + ptr += MINBPC(enc); + break; + } + } + return XML_TOK_PARTIAL; +} + +#endif /* XML_DTD */ + +static int PTRCALL +PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end, + const char **badPtr) +{ + ptr += MINBPC(enc); + end -= MINBPC(enc); + for (; ptr != end; ptr += MINBPC(enc)) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_DIGIT: + case BT_HEX: + case BT_MINUS: + case BT_APOS: + case BT_LPAR: + case BT_RPAR: + case BT_PLUS: + case BT_COMMA: + case BT_SOL: + case BT_EQUALS: + case BT_QUEST: + case BT_CR: + case BT_LF: + case BT_SEMI: + case BT_EXCL: + case BT_AST: + case BT_PERCNT: + case BT_NUM: +#ifdef XML_NS + case BT_COLON: +#endif + break; + case BT_S: + if (CHAR_MATCHES(enc, ptr, ASCII_TAB)) { + *badPtr = ptr; + return 0; + } + break; + case BT_NAME: + case BT_NMSTRT: + if (!(BYTE_TO_ASCII(enc, ptr) & ~0x7f)) + break; + default: + switch (BYTE_TO_ASCII(enc, ptr)) { + case 0x24: /* $ */ + case 0x40: /* @ */ + break; + default: + *badPtr = ptr; + return 0; + } + break; + } + } + return 1; +} + +/* This must only be called for a well-formed start-tag or empty + element tag. Returns the number of attributes. Pointers to the + first attsMax attributes are stored in atts. +*/ + +static int PTRCALL +PREFIX(getAtts)(const ENCODING *enc, const char *ptr, + int attsMax, ATTRIBUTE *atts) +{ + enum { other, inName, inValue } state = inName; + int nAtts = 0; + int open = 0; /* defined when state == inValue; + initialization just to shut up compilers */ + + for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) { + switch (BYTE_TYPE(enc, ptr)) { +#define START_NAME \ + if (state == other) { \ + if (nAtts < attsMax) { \ + atts[nAtts].name = ptr; \ + atts[nAtts].normalized = 1; \ + } \ + state = inName; \ + } +#define LEAD_CASE(n) \ + case BT_LEAD ## n: START_NAME ptr += (n - MINBPC(enc)); break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NONASCII: + case BT_NMSTRT: + case BT_HEX: + START_NAME + break; +#undef START_NAME + case BT_QUOT: + if (state != inValue) { + if (nAtts < attsMax) + atts[nAtts].valuePtr = ptr + MINBPC(enc); + state = inValue; + open = BT_QUOT; + } + else if (open == BT_QUOT) { + state = other; + if (nAtts < attsMax) + atts[nAtts].valueEnd = ptr; + nAtts++; + } + break; + case BT_APOS: + if (state != inValue) { + if (nAtts < attsMax) + atts[nAtts].valuePtr = ptr + MINBPC(enc); + state = inValue; + open = BT_APOS; + } + else if (open == BT_APOS) { + state = other; + if (nAtts < attsMax) + atts[nAtts].valueEnd = ptr; + nAtts++; + } + break; + case BT_AMP: + if (nAtts < attsMax) + atts[nAtts].normalized = 0; + break; + case BT_S: + if (state == inName) + state = other; + else if (state == inValue + && nAtts < attsMax + && atts[nAtts].normalized + && (ptr == atts[nAtts].valuePtr + || BYTE_TO_ASCII(enc, ptr) != ASCII_SPACE + || BYTE_TO_ASCII(enc, ptr + MINBPC(enc)) == ASCII_SPACE + || BYTE_TYPE(enc, ptr + MINBPC(enc)) == open)) + atts[nAtts].normalized = 0; + break; + case BT_CR: case BT_LF: + /* This case ensures that the first attribute name is counted + Apart from that we could just change state on the quote. */ + if (state == inName) + state = other; + else if (state == inValue && nAtts < attsMax) + atts[nAtts].normalized = 0; + break; + case BT_GT: + case BT_SOL: + if (state != inValue) + return nAtts; + break; + default: + break; + } + } + /* not reached */ +} + +static int PTRFASTCALL +PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) +{ + int result = 0; + /* skip &# */ + ptr += 2*MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_x)) { + for (ptr += MINBPC(enc); + !CHAR_MATCHES(enc, ptr, ASCII_SEMI); + ptr += MINBPC(enc)) { + int c = BYTE_TO_ASCII(enc, ptr); + switch (c) { + case ASCII_0: case ASCII_1: case ASCII_2: case ASCII_3: case ASCII_4: + case ASCII_5: case ASCII_6: case ASCII_7: case ASCII_8: case ASCII_9: + result <<= 4; + result |= (c - ASCII_0); + break; + case ASCII_A: case ASCII_B: case ASCII_C: + case ASCII_D: case ASCII_E: case ASCII_F: + result <<= 4; + result += 10 + (c - ASCII_A); + break; + case ASCII_a: case ASCII_b: case ASCII_c: + case ASCII_d: case ASCII_e: case ASCII_f: + result <<= 4; + result += 10 + (c - ASCII_a); + break; + } + if (result >= 0x110000) + return -1; + } + } + else { + for (; !CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) { + int c = BYTE_TO_ASCII(enc, ptr); + result *= 10; + result += (c - ASCII_0); + if (result >= 0x110000) + return -1; + } + } + return checkCharRefNumber(result); +} + +static int PTRCALL +PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, + const char *end) +{ + switch ((end - ptr)/MINBPC(enc)) { + case 2: + if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_t)) { + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_l: + return ASCII_LT; + case ASCII_g: + return ASCII_GT; + } + } + break; + case 3: + if (CHAR_MATCHES(enc, ptr, ASCII_a)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_m)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_p)) + return ASCII_AMP; + } + } + break; + case 4: + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_q: + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_u)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_o)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_t)) + return ASCII_QUOT; + } + } + break; + case ASCII_a: + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_p)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_o)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_s)) + return ASCII_APOS; + } + } + break; + } + } + return 0; +} + +static int PTRCALL +PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2) +{ + for (;;) { + switch (BYTE_TYPE(enc, ptr1)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (*ptr1++ != *ptr2++) \ + return 0; + LEAD_CASE(4) LEAD_CASE(3) LEAD_CASE(2) +#undef LEAD_CASE + /* fall through */ + if (*ptr1++ != *ptr2++) + return 0; + break; + case BT_NONASCII: + case BT_NMSTRT: +#ifdef XML_NS + case BT_COLON: +#endif + case BT_HEX: + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: + if (*ptr2++ != *ptr1++) + return 0; + if (MINBPC(enc) > 1) { + if (*ptr2++ != *ptr1++) + return 0; + if (MINBPC(enc) > 2) { + if (*ptr2++ != *ptr1++) + return 0; + if (MINBPC(enc) > 3) { + if (*ptr2++ != *ptr1++) + return 0; + } + } + } + break; + default: + if (MINBPC(enc) == 1 && *ptr1 == *ptr2) + return 1; + switch (BYTE_TYPE(enc, ptr2)) { + case BT_LEAD2: + case BT_LEAD3: + case BT_LEAD4: + case BT_NONASCII: + case BT_NMSTRT: +#ifdef XML_NS + case BT_COLON: +#endif + case BT_HEX: + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: + return 0; + default: + return 1; + } + } + } + /* not reached */ +} + +static int PTRCALL +PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, + const char *end1, const char *ptr2) +{ + for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) { + if (ptr1 == end1) + return 0; + if (!CHAR_MATCHES(enc, ptr1, *ptr2)) + return 0; + } + return ptr1 == end1; +} + +static int PTRFASTCALL +PREFIX(nameLength)(const ENCODING *enc, const char *ptr) +{ + const char *start = ptr; + for (;;) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: ptr += n; break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NONASCII: + case BT_NMSTRT: +#ifdef XML_NS + case BT_COLON: +#endif + case BT_HEX: + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: + ptr += MINBPC(enc); + break; + default: + return (int)(ptr - start); + } + } +} + +static const char * PTRFASTCALL +PREFIX(skipS)(const ENCODING *enc, const char *ptr) +{ + for (;;) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_LF: + case BT_CR: + case BT_S: + ptr += MINBPC(enc); + break; + default: + return ptr; + } + } +} + +static void PTRCALL +PREFIX(updatePosition)(const ENCODING *enc, + const char *ptr, + const char *end, + POSITION *pos) +{ + while (ptr < end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + ptr += n; \ + break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_LF: + pos->columnNumber = (XML_Size)-1; + pos->lineNumber++; + ptr += MINBPC(enc); + break; + case BT_CR: + pos->lineNumber++; + ptr += MINBPC(enc); + if (ptr != end && BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + pos->columnNumber = (XML_Size)-1; + break; + default: + ptr += MINBPC(enc); + break; + } + pos->columnNumber++; + } +} + +#undef DO_LEAD_CASE +#undef MULTIBYTE_CASES +#undef INVALID_CASES +#undef CHECK_NAME_CASE +#undef CHECK_NAME_CASES +#undef CHECK_NMSTRT_CASE +#undef CHECK_NMSTRT_CASES + +#endif /* XML_TOK_IMPL_C */ diff --git a/project/jni/expat/lib/xmltok_impl.h b/project/jni/expat/lib/xmltok_impl.h new file mode 100644 index 000000000..da0ea60a6 --- /dev/null +++ b/project/jni/expat/lib/xmltok_impl.h @@ -0,0 +1,46 @@ +/* +Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd +See the file COPYING for copying permission. +*/ + +enum { + BT_NONXML, + BT_MALFORM, + BT_LT, + BT_AMP, + BT_RSQB, + BT_LEAD2, + BT_LEAD3, + BT_LEAD4, + BT_TRAIL, + BT_CR, + BT_LF, + BT_GT, + BT_QUOT, + BT_APOS, + BT_EQUALS, + BT_QUEST, + BT_EXCL, + BT_SOL, + BT_SEMI, + BT_NUM, + BT_LSQB, + BT_S, + BT_NMSTRT, + BT_COLON, + BT_HEX, + BT_DIGIT, + BT_NAME, + BT_MINUS, + BT_OTHER, /* known not to be a name or name start character */ + BT_NONASCII, /* might be a name or name start character */ + BT_PERCNT, + BT_LPAR, + BT_RPAR, + BT_AST, + BT_PLUS, + BT_COMMA, + BT_VERBAR +}; + +#include diff --git a/project/jni/expat/lib/xmltok_ns.c b/project/jni/expat/lib/xmltok_ns.c new file mode 100644 index 000000000..c3b88fdf4 --- /dev/null +++ b/project/jni/expat/lib/xmltok_ns.c @@ -0,0 +1,115 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* This file is included! */ +#ifdef XML_TOK_NS_C + +const ENCODING * +NS(XmlGetUtf8InternalEncoding)(void) +{ + return &ns(internal_utf8_encoding).enc; +} + +const ENCODING * +NS(XmlGetUtf16InternalEncoding)(void) +{ +#if BYTEORDER == 1234 + return &ns(internal_little2_encoding).enc; +#elif BYTEORDER == 4321 + return &ns(internal_big2_encoding).enc; +#else + const short n = 1; + return (*(const char *)&n + ? &ns(internal_little2_encoding).enc + : &ns(internal_big2_encoding).enc); +#endif +} + +static const ENCODING * const NS(encodings)[] = { + &ns(latin1_encoding).enc, + &ns(ascii_encoding).enc, + &ns(utf8_encoding).enc, + &ns(big2_encoding).enc, + &ns(big2_encoding).enc, + &ns(little2_encoding).enc, + &ns(utf8_encoding).enc /* NO_ENC */ +}; + +static int PTRCALL +NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + return initScan(NS(encodings), (const INIT_ENCODING *)enc, + XML_PROLOG_STATE, ptr, end, nextTokPtr); +} + +static int PTRCALL +NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + return initScan(NS(encodings), (const INIT_ENCODING *)enc, + XML_CONTENT_STATE, ptr, end, nextTokPtr); +} + +int +NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, + const char *name) +{ + int i = getEncodingIndex(name); + if (i == UNKNOWN_ENC) + return 0; + SET_INIT_ENC_INDEX(p, i); + p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog); + p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent); + p->initEnc.updatePosition = initUpdatePosition; + p->encPtr = encPtr; + *encPtr = &(p->initEnc); + return 1; +} + +static const ENCODING * +NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) +{ +#define ENCODING_MAX 128 + char buf[ENCODING_MAX]; + char *p = buf; + int i; + XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1); + if (ptr != end) + return 0; + *p = 0; + if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2) + return enc; + i = getEncodingIndex(buf); + if (i == UNKNOWN_ENC) + return 0; + return NS(encodings)[i]; +} + +int +NS(XmlParseXmlDecl)(int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingName, + const ENCODING **encoding, + int *standalone) +{ + return doParseXmlDecl(NS(findEncoding), + isGeneralTextEntity, + enc, + ptr, + end, + badPtr, + versionPtr, + versionEndPtr, + encodingName, + encoding, + standalone); +} + +#endif /* XML_TOK_NS_C */ diff --git a/project/jni/fontconfig/AUTHORS b/project/jni/fontconfig/AUTHORS new file mode 100644 index 000000000..5ef888548 --- /dev/null +++ b/project/jni/fontconfig/AUTHORS @@ -0,0 +1,3 @@ +Keith Packard +Patrick Lam + diff --git a/project/jni/fontconfig/Android.mk b/project/jni/fontconfig/Android.mk new file mode 100644 index 000000000..41e24a3cd --- /dev/null +++ b/project/jni/fontconfig/Android.mk @@ -0,0 +1,26 @@ + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := fontconfig + +LOCAL_CFLAGS := -DFONTCONFIG_PATH=\".fontconfig\" +LOCAL_CFLAGS += -DFC_CACHEDIR=\".font-cache\" +LOCAL_CFLAGS += -DFC_DEFAULT_FONTS=\"/system/fonts\" +LOCAL_CFLAGS += -I$(LOCAL_PATH) -I$(LOCAL_PATH)/src +LOCAL_CFLAGS += -DHAVE_CONFIG_H + +LOCAL_SHARED_LIBRARIES := freetype expat + +LOCAL_LDLIBS := -lz + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/include \ + $(LOCAL_PATH)/../freetype/include \ + $(LOCAL_PATH)/../expat/include + + +LOCAL_SRC_FILES := $(addprefix src/, $(notdir $(wildcard $(LOCAL_PATH)/src/*.c) $(wildcard $(LOCAL_PATH)/src/*.cpp))) + +include $(BUILD_SHARED_LIBRARY) diff --git a/project/jni/fontconfig/COPYING b/project/jni/fontconfig/COPYING new file mode 100644 index 000000000..66392b13b --- /dev/null +++ b/project/jni/fontconfig/COPYING @@ -0,0 +1,28 @@ +fontconfig/COPYING + +Copyright © 2000,2001,2002,2003,2004,2006,2007 Keith Packard +Copyright © 2005 Patrick Lam +Copyright © 2009 Roozbeh Pournader +Copyright © 2008,2009 Red Hat, Inc. +Copyright © 2008 Danilo Šegan +Copyright © 2012 Google, Inc. + + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation, and that the name of the author(s) not be used in +advertising or publicity pertaining to distribution of the software without +specific, written prior permission. The authors make no +representations about the suitability of this software for any purpose. It +is provided "as is" without express or implied warranty. + +THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. + diff --git a/project/jni/fontconfig/README b/project/jni/fontconfig/README new file mode 100644 index 000000000..d2288a559 --- /dev/null +++ b/project/jni/fontconfig/README @@ -0,0 +1,1431 @@ + Fontconfig + Font configuration and customization library + Version 2.11 + 2013-10-11 + + +Check INSTALL for compilation and installation instructions. +Report bugs to https://bugs.freedesktop.org in the fontconfig module. + +2.11 + +Akira TAGOH (15): + Do not create a config dir for migration when no config files nor dirs + Add a test case of the migration for config place + Fix memory leaks in FcFreeTypeQueryFace + Bug 68955 - Deprecate / remove FC_RASTERIZER + Copy all values from the font to the pattern if the pattern doesn't have the element + Fix a crash when FcPattern is set to null on FcFontSetList() and FcFontList() + Add the description of -q option to the man page + avoid reading config.h twice + clean up + Add the relative path for to fonts.conf if the parent path is same to fonts.conf + Workaround the race condition issue on updating cache + exit with the error code when FcNameParse() failed + Add missing doc for FcStrListFirst and fix a typo + Bump libtool revision + Update CaseFolding.txt to Unicode 6.3 + +Jan Alexander Steffens (heftig) (1): + Further changes to 30-metric-aliases.conf + +W. Trevor King (1): + doc/fccharset.fncs: Describe the map format in more detail + +2.10.95 (2.11 RC5) + +Akira TAGOH (2): + Fix a typo + Fix a crash + +2.10.94 (2.11 RC4) + +Akira TAGOH (25): + Bug 64906 - FcNameParse() should ignore leading whitespace in parameters + Fix a comparison of constant warning with clang + Fix a shift count overflow on 32bit box + Fix a incompatible pointer warning on NetBSD + Add FcTypeUnknown to FcType to avoid comparison of constant -1 + Fix the behavior of intermixed tests end edits in match + Ignore scandir() check on mingw + Use INT_MAX instead of unreliable hardcoding value + Add FC_UNUSED to FC_ASSERT_STATIC macro to avoid compiler warning + Rework to apply the intermixed test and edit elements in one-pass + trivial code optimization + Correct fontconfig.pc to add certain dependencies for build + Correct fontconfig.pc to add certain dependencies for static build + Fix wrong edit position + Bug 67809 - Invalid read/write with valgrind when assigning something twice + warn deprecated only when migration failed + Bug 67845 - Match on FC_SCALABLE + Bug 16818 - fontformat in match pattern is not respected? + Bug 68340 - More metric compat fonts + Bug 63399 - Add default aliases for Georgia, Garamond, Palatino Linotype, Trebuchet MS + Fix a typo + Fix a crash when non-builtin objects are edited + Fix a wrong edit position when 'kind' is different + Bug 68587 - copy qu.orth to quz.orth + Add quz.orth to Makefile.am + +Behdad Esfahbod (2): + Minor + Fix assertion + +2.10.93 (2.11 RC3) + +Akira TAGOH (10): + Bug 62980 - matching native fonts with even :lang=en + Ensure closing fp on error + Obtain fonts data via FT_Face instead of opening a file directly + Revert the previous change and rework to not export freetype API outside fcfreetype.c + documented FC_HASH and FC_POSTSCRIPT_NAME + Bug 63329 - make check fails: .. contents:: :depth: 2 + Use the glob matching for filename + Bug 63452 - conf.d/README outdated + Fix missing OSAtomicCompareAndSwapPtrBarrier() on Mac OS X 10.4 + Bug 63922 - FcFreeTypeQueryFace fails on postscripts fonts loaded from memory + +Sebastian Freundt (1): + build-chain, replace INCLUDES directive by AM_CPPFLAGS + +2.10.92 (2.11 RC2) + +Akira TAGOH (33): + Fix the build fail on MinGW + Bug 50497 - RFE: Add OpenType feature tags support + Improve FcGetPrgname() to work on BSD + Better fix for 2fe5ddfd + Add missing file descriptor to F_DUPFD_CLOEXEC + Fix mkstemp absence for some platform + Fix installation on MinGW32 + Add another approach to FC_PRGNAME for Solaris 10 or before + remove the unnecessary code + Bug 59385 - Do the right thing for intermixed edit and test elements + Bug 23757 - Add mode="delete" to + Modernize configure.ac + Use AM_MISSING_PROG instead of hardcoding missing + Revert "test: Use SH_LOG_COMPILER and AM_TESTS_ENVIRONMENT" + Use AM_MISSING_PROG instead of hardcoding missing + Bug 50733 - Add font-file hash? + Bug 60312 - DIST_SUBDIRS should never appear in a conditional + Update _FcMatchers definition logic + Bump the cache version to 4 + Add Culmus foundry to the vendor list + Bug 60748 - broken conf.d/10-autohint.conf and conf.d/10-unhinted.conf + Bug 60783 - Add Liberation Sans Narrow to 30-metric-aliases.conf + Fix a typo + Fix a crash when the object is non-builtin object + Fix broken sort order with FcFontSort() + Fix a memory leak + Bug 59456 - Adding a --sysroot like option to fc-cache + Do not copy FC_*LANG_OBJECT even if it's not available on the pattern + Fix a SIGSEGV on FcPatternGet* with NULL pattern + Bug 38737 - Wishlist: support FC_POSTSCRIPT_NAME + Minor cleanup + Bump libtool revision + Minor fix + +Behdad Esfahbod (12): + Resepct $NOCONFIGURE + Ensure we find the uninstalled fontconfig header + Copy all values from pattern to font if the font doesn't have the element + Minor + Bug 59379 - FC_PRGNAME + Remove unused checks for common functions + Minor + Fix fc-cache crash caused by looking up NULL object incorrectly + Fix FC_PRGNAME default + Fix readlink failure + Accept digits as part of OpenType script tags + Fix crash with FcConfigSetCurrent(NULL) + +Christoph J. Thompson (1): + Use the PKG_INSTALLDIR macro. + +Colin Walters (1): + build: Only use PKG_INSTALLDIR if available + +Quentin Glidic (2): + test: Use SH_LOG_COMPILER and AM_TESTS_ENVIRONMENT + Use LOG_COMPILER and AM_TESTS_ENVIRONMENT + +2.10.91 (2.11 RC1) + +Akira TAGOH (19): + Fix a potability issue about stdint.h + Fix build issues on clean tree + Do not show the deprecation warning if it is a symlink + Fix a typo + Fix the wrong estimation for the memory usage information in fontconfig + Remove the duplicate null-check + Remove the dead code + clean up + Fix a typo that accessing to the out of array + Fix a memory leak + Check the system font to be initialized + Missing header file for _mkdir declaration + Clean up the unused variable + Bug 47705 - Using O_CLOEXEC + missing header file to declare _mkdir + Fix a build fail on mingw + Fix a typo in the manpages template + Bug 29312 - RFE: feature to indicate which characters are missing to satisfy the language support + Update the date in README properly + +Behdad Esfahbod (73): + Fix typo + Parse matrices of expressions + Fix compiler warnings + Fix unused-parameter warnings + Fix more warnings + Fix sign-compare warnings + Fix warning + Fix more warnings + Fixup from 4f6767470f52b287a2923e7e6d8de5fae1993f67 + Remove memory accounting and reporting + Allow target="font/pattern/default" in elements + Don't warn if an unknown element is used in an expression + Unbreak build when FC_ARCHITECTURE is defined + Remove unneeded stuff + Enable fcarch assert checks even when FC_ARCHITECTURE is explicitly given + Make tests run on Windows + Initialize matrix during name parsing + Adjust docs for recent changes + Warn if appears in + Make FC_DBG_OBJTYPES debug messages into warnings + Refuse to set value to unsupported types during config too + Add NULL check + Don't crash in FcPatternDestroy with NULL pattern + Don't crash in FcPatternFormat() with NULL pattern + Minor + Whitespace + Deprecate FcName(Un)RegisterObjectTypes / FcName(Un)RegisterConstants + Use a static perfect hash table for object-name lookup + Switch .gitignore to git.mk + Remove shared-str pool + Fix build stuff + Add build stuff for threadsafety primitives + Add thread-safety primitives + Make refcounts, patterns, charsets, strings, and FcLang thread-safe + Make FcGetDefaultLang and FcGetDefaultLangs thread-safe + Make FcInitDebug() idempotent + Make FcDefaultFini() threadsafe + Refactor; contain default config in fccfg.c + Minor + Make default-FcConfig threadsafe + Minor + Make FcCacheIsMmapSafe() threadsafe + Minor + Make cache refcounting threadsafe + Add a big cache lock + Make random-state initialization threadsafe + Make cache hash threadsafe + Make FcDirCacheDispose() threadsafe + Make fcobjs.c thread-safe + Warn about undefined/invalid attributes during config parsing + Fixup fcobjs.c + Remove FcSharedStr* + Fix compiler warnings + Minor + Fix build and warnings on win32 + Use CC_FOR_BUILD to generate source files + Fix more warnings. + Trying to fix distcheck + Fix build around true/false + Work around Sun CPP + Really fix cross-compiling and building of tools this time + Second try to make Sun CPP happy + Ugh, add Tools.mk + Minor + Don't use blanks for fc-query + Remove FcInit() calls from tools + Add 10-scale-bitmap-fonts.conf and enable by default + Oops, add the actual file + Fix pthreads setup + Fix memory corruption! + Add pthread test + Add atomic ops for Solaris + Make linker happy + +Jon TURNEY (1): + Fix build when srcdir != builddir + +2.10.2 + +Akira TAGOH (13): + Bug 53585 - Two highly-visible typos in src/fcxml.c + Fix for libtoolize's warnings + Bug 54138 - X_OK permission is invalid for win32 access(..) calls + Bug 52573 - patch required to build 2.10.x with oldish GNU C library headers + deal with warnings as errors for the previous change + Fix wrongly squashing for the network path on Win32. + Fix syntax errors in fonts.dtd. + autogen.sh: Add -I option to tell aclocal a place for external m4 files + Use automake variable instead of cleaning files in clean-local + Bug 56531 - autogen.sh fails due to missing 'm4' directory + Bug 57114 - regression on FcFontMatch with namelang + Update CaseFolding.txt to Unicode 6.2 + Bug 57286 - Remove UnBatang and Baekmuk Batang from monospace in 65-nonlatin.conf + +Behdad Esfahbod (1): + Fix N'ko orthography + +Jeremy Huddleston Sequoia (1): + Remove _CONFIG_FIXUPS_H_ guards, so multiple includes of "config.h" result in the correct values + +2.10.1 + +Akira TAGOH (2): + Fix a typo in fontconfig.pc + Install config files first + +2.10.0 + +Akira TAGOH (5): + Bug 34266 - configs silently ignored if libxml2 doesn't support SAX1 interface + Update CaseFolding.txt to Unicode 6.1 + Fix a build fail with gcc 2.95, not supporting the flexible array members. + Bump libtool revision + Update INSTALL + +2.9.92 (2.10 RC2) + +Akira TAGOH (9): + Bug 50835 - Deprecate FC_GLOBAL_ADVANCE + Fix a typo and build fail. + Fix a build fail on MINGW + Fix the fail of make install with --disable-shared on Win32 + clean up the lock file properly on even hardlink-not-supported filesystem. + Rename configure.in to configure.ac + Bug 18726 - RFE: help write locale-specific tests + Bump libtool revision + Update INSTALL + +Marius Tolzmann (2): + Fix newline in warning about deprecated config includes + Fix warning about deprecated, non-existent config includes + +2.9.91 (2.10 RC1) + +Akira TAGOH (60): + [doc] Update the path for cache files and the version. + [doc] Update for cachedir. + Revert "Fix a build fail on some environment." + Revert "Fix a build fail on some environment" + Fix a build issue due to the use of non-portable variables + Get rid of the prerequisites from the sufix rules + Bug 39914 - Please tag the cache directory with CACHEDIR.TAG + fc-cache: improvement of the fix for Bug#39914. + fcmatch: Set FcResultMatch at the end if the return value is valid. + Bug 47703 - SimSun default family + Bug 17722 - Don't overwrite user's configurations in default config + Fix a memory leak in FcDirScanConfig() + Bug 17832 - Memory leaks due to FcStrStaticName use for external patterns + fcpat: Increase the number of buckets in the shared string hash table + Fix the hardcoded cache file suffix + Move workaround macros for fat binaries into the separate header file + Bug 48020 - Fix for src/makealias on Solaris 10 + Bug 24729 - [ne_NP] Fix ortho file + doc: Add contains and not_contains operators and elements + Use AC_HELP_STRING instead of formatting manually + Use pkgconfig to check builddeps + Bug 29341 - Make some fontconfig paths configurable + Bug 22862 - ignores s + Bug 26830 - Add search for libiconv non-default directory + Bug 28491 - Allow matching on FC_FILE + Bug 48573 - platform without regex do not have also REG_XXX defines + Bug 27526 - Compatibility fix for old windows sytems + Add --with-expat, --with-expat-includes and --with-expat-lib back. + doc: Fix a typo of the environment variable name. + Bug 25151 - Move cleanCacheDirectory() from fc-cache.c into + Rework to avoid adding the unexpected value to ICONV_CFLAGS and ICONV_LIBS + Fix a build issue again when no regex functions available + C++11 requires a space between literal and identifier + Bug 47721 - Add ChromeOS fonts to 30-metric-aliases.conf + Create CACHEDIR.TAG when fc-cache is run or only when the cache directory is created at the runtime. + Add --enable-iconv option to configure + Bug 27765 - FcMatch() returns style in wrong language + Disable iconv support anyway... + Bug 39278 - make usage of mmap optional + Output more verbose debugging log to show where to insert the element into the value list + fonts.conf: keeps same binding for alternatives + fcarch.c: get rid of the duplicate definition of FC_MAX + Bug 19128 - Handling whitespace in aliases + Bug 20411 - fontconfig doesn't match FreeDesktop directories specs + Correct the example + Bug 33644 - Fontconfig doesn't match correctly in + fcatomic: fallback to create a directory with FcAtomicLock + Move statfs/statvfs wrapper to fcstat.c and add a test for the mtime broken fs + Fix the build fail on Solaris + Fix a typo and polish the previous change + Fix the wrong estimation for the memory usage information in fontconfig + Bug 32853 - Export API to get the default language + fcdefault: fallback if the environment variables are empty + Add the default language to the pattern prior to do build the substitution + fcdefault: no need to set FC_LANG in FcDefaultSubstitute() anymore + fcdefault: Add the lang object at FcConfigSubstituteWithPat() only when kind is FcMatchPattern + Bug 50525 - superfluous whitespace in the style + Bump libtool revision + doc: Fix distcheck error again... + Generate bzip2-compressed tarball too + +Jeremy Huddleston (1): + fcarch: Check for architecture signature at compile time rather than configure time + +Keith Packard (3): + Use posix_fadvise to speed startup + Extra ',' in AC_ARG_WITH(arch causes arch to never be autodetected + Deal with architectures where ALIGNOF_DOUBLE < 4 + +Mark Brand (1): + fix building for WIN32 + +Mikhail Gusarov (2): + Move FcStat to separate compilation unit + Fix cache aging for fonts on FAT filesystem under Linux + +2.9 + +Akira TAGOH (28): + Add charset editing feature. + add some document for range and charset. + Add the range support in blank element + Add editing langset feature. + add some documents + Bug 24744 - No n'ko orthography + Remove the unnecessary comment in ks.orth + Bug 32965 - Asturian (ast-ES) language matching missing ḷḷḥ + Add a missing file + Bug 35517 - Remove Apple Roman cmap support + Bug 40452 - Running 'fc-match --all' core dumps when no fonts are installed + Get rid of the unexpected family name + Bug 44826 - must contain only a single + Bug 46169 - Pointer error in FcConfigGlobMatch + Do not update stream->pos when seeking is failed. + Bug 27385 - lcdfilter settings for freetype-2.3.12 not available in fontconfig-2.8.0 + Add brx.orth and sat.orth + Bug 41694 - FcCache functions have random-number-generator side effects + Bug 23336 - unable to display bitmap-only (SFNT) TrueType or OpenType + Check null value for given object to avoid possibly segfaulting + Bug 19128 - Handling whitespace in aliases + Fix distcheck error + Update the version info + Update to detect the uncommited changes properly + Fix a build issue + Fix a build fail on some environment + Fix a build fail on some environment. + Get rid of $< from Makefile.am + +Alan Coopersmith (1): + Fix compiler warnings + +Behdad Esfahbod (54): + [fc-cache] Document -r argument in man page + [doc] Fix typo + Bug 25508 configure assumes bash > 2.0 is on system + Update INSTALL + Add note about autogen.sh to INSTALL + Fix doc typo + More doc typo fixes + Bug 18886 installation crashes if fontconfig already installed + Bug 26157 Solaris/Sun C 5.8: compilation of 2.8.0 and 2.7.3 fails + Bug 25152 Don't sleep(2) if all caches were uptodate + Don't include unistd.h in fontconfig.h + Accept TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS from name table + Whitespace + More whitespace + Remove all training whitespaces + Fix comment + Add fc-pattern cmdline tool + Bug 29338 - fc-pattern.sgml, open para tag + Add comments + Bug 29995 - fc-cat does not invoke FcFini() + Add new public API: FcCharSetDelChar() + [fc-lang] Support excluding characters + Bug 24729 - [ne_NP] Fix ortho file + Add more copyright owners + Cleanup copyright notices to replace "Keith Packard" with "the author(s)" + Fix returned value + Bug 28958 - lang=en matches other langs + Make most generated-files cross-compiling-safe + Make fc-arch stuff cross-compiling-safe + Bump version + Allow editing charset and lang in target="scan" + Add support for into the DTD + Skip elements with begin > end + Doc nit + Fix assertion failure on le32d4 + Remove AM_MAINTAINER_MODE + Update CaseFolding.txt to Unicode 6.0 + Remove --enable-maintainer-mode from autogen.sh + Bug 20113 - Uighur (ug) orthography incomplete + Bug 30566 - fcformat.c:interpret_enumerate() passes uninitialized idx to FcPatternGetLangSet() + Mark constant strings as constant + More doc typo fixes + Always define FcStat as a function + Fix warning + Bug 35587 - Add padding to make valgrind and glibc not hate each other + [.gitignore] Update + Bug 36577 - Updating cache with no-bitmaps disables bitmap fonts... + Bug 26718 - "fc-match sans file" doesn't work + Switch fc-match to use FcPatternFormat() + Switch fc-cat to use FcPatternFormat() + Fix stupid bug in FcFontSort() + Bug 41171 - Invalid use of memset + Fix parallel build + Add FcPublic to FcLangSetUnion and FcLangSetSubtract + +Brad Hards (1): + Documentation fixes + +Jeremy Huddleston (2): + fontconfig.pc: Add variables for confdir and cachedir + fontconfig.pc.in: Add sysconfdir, localstatedir, and PACKAGE + +Jinkyu Yi (1): + Bug 42423 - make default Korean font from Un to Nanum + +MINAMI Hirokazu (1): + Bug 43406 - typo of Japanese font name in conf.d/65-nonlatin.conf + +Mike Frysinger (9): + FcStrPlus: optimize a little + delete unused variables + FcStat: change to FcChar8 for first arg + fc-cat: fix pointer warning + FcName{,Get}Constant: constify string input + fc-{list,match}: constify format string + fix build warnings when using --with-arch + FcObjectValidType: tweak -1 checking + makealias: handle missing funcs better + +Parag Nemade (2): + Bug 25651 - Add ortho file for locale brx_IN + Bug 25650 - Add ortho file for locale sat_IN + +Pravin Satpute (4): + Bug 27195 - need updates to ks.orth file + Bug 43321 - Required corrections in urdu.orth file + Bug 25653 - Add ortho file for locale doi_IN + Bug 25652 - Add ortho file for locale mni_IN + +2.8 + +Behdad Esfahbod (24): + Clarify default confdir and cachedir better. + Move FcAlign to fcint.h + [fc-arch] Add FcAlign to arch signature + [int] Define MIN/MAX/ABS macros + Bump cache version up from 2 to 3 and fix FcLangSet caching/crash + Remove unused macros + [int] Remove fc_storage_type() in favor of direct access to v->type + [int] Remove fc_value_* macros that did nothing other than renaming + Enable automake silent rules + [int] Remove more unused macros + [xml] Remove unused code + [arch] Try to ensure proper FcLangSet alignment in arch + [lang] Fix serializing LangSet from older versions + Make sure fclang.h and fcarch.h are built + Remove bogus comment + [fc-glyphname] Cleanup Makefile.am + [src] Create fcglyphname.h automatically + [fc-glyphname] Rename internal arrays to prefix with _fc_ + Clean up Makefile's a bit + [fc-glyphname] Remove Adobe glyphlist + [fc-case] Update CaseFolding.txt to Unicode 5.2.0 + [fc-arch] Beautify the arch template + [fc-arch] Rename architecture names to better reflect what they are + Bump libtool revision in preparation for release + +2.7.3 + +Behdad Esfahbod (2): + Use default config in FcFileScan() and FcDirScan() + Bump libtool version in preparation for release + +Roozbeh Pournader (2): + Correct Ewe (ee) orthography to use U+025B (bug #20711) + Updated Arabic, Persian, and Urdu orthographies + +2.7.2 + +Behdad Esfahbod (6): + Improve charset printing + [ja.orth] Comment out FULLWIDTH YEN SIGN (#22942) + Bug 22037 - No Fonts installed on a default install on Windows Server 2003 + Bug 23419 - "contains" expression seems not working on the fontconfig rule + Revert "Fix FcNameUnparseLangSet()" and redo it + Bump libtool version for release + +Tor Lillqvist (3): + Fix MinGW compilation + Fix heap corruption on Windows in FcEndElement() + Use multi-byte codepage aware string function on Windows + +2.7.1 + +Behdad Esfahbod (16): + git-tag -s again + Fix win32 build + Replace spaces with tabs in conf files + Remove unused ftglue code + Add Inconsolata to monospace config (#22710) + Fix leak with string VStack objects + Improve libtool version parsing (#22122) + Use GetSystemWindowsDirectory() instead of GetWindowsDirectory() (#22037) + Remove unused macros + Fix FcNameUnparseLangSet() + Fix doc syntax (#22902) + TT_MS_ID_UCS_4 is really UTF-16BE, not UTF-32 + [doc] Add ~/fonts.conf.d to user docs + Hardcode /etc/fonts instead of @CONFDIR@ in docs (#22911) + Bump libtool versions that 2.7.0 (I forgot to do back then) + Update .gitignore + +Karl Tomlinson (1): + Don't change the order of names unnecessarily (#20128) + +2.7 + +Alexey Khoroshilov (1): + Use human-readable file names in the docs (bug #16278) + +Behdad Esfahbod (119): + Avoid C99ism in Win32 code (#16651) + [doc] Fix inaccuracy in FcFontRenderPrepare docs (#16985) + When canonizing filenames, squash // and remove final / (#bug 16286) + Add orth file for Maithili mai.orth (#15821) + Replace RCS Id tags with the file name + [doc] Fix signatures of FcPatternGetFTFace and FcPatternGetLangSet (#16272) + Update Thai default families (#16223) + Add ~/.fonts.conf.d to default config (#17100) + [fc-match] Fix list of getopt options in --help + Update man pages + Add fc-query (#13019) + Implement fc-list --verbose (#13015) + [doc] Add const decorator for FcPatternDuplicate() + Add FcPatternFilter() (#13016) + [doc] Document that a zero rescanInterval disables automatic checks (#17103) + Get rid of $Id$ tags + [doc] Fix signature of FcConfigHome() + Fix docs re 'orig' argument of FcPatternBuild and family + Update sr.orth to actul subset of Cyrillic used by Serbian (#17208) + Add Sindhi .orth file. (#17140) + Add WenQuanYi fonts to default conf (#17262, from Mandriva) + Handle -h and --help according to GNU Coding Standards (#17104) + Document when config can be NULL (#17105) + Add FcConfigReference() (#17124) + Document how to free return value of FcNameUnparse() + Don't leak FcValues string loaded through fcxml.c (#17661) + Don't call FcPatternGetCharSet in FcSortWalk unless we need to (#17361) + Fix two more doc typos + [.gitignore] Update + Cleanup symlinks in "make uninstall" (bug #18885) + [fccache] Consistently use FcStat() over stat() (bug #18195) + Consistently use FcStat() over stat() in all places + Use __builtin_popcount() when available (bug #17592) + Fix compile with old FreeType that doesn't have FT_Select_Size() (bug #17498) + Implement fc-list --quiet ala grep (bug #17141) + [65-fonts-persian.conf] Set foundry in target=scan instead of target=font + Don't use identifier named complex + Explicitly chmod() directories (bug #18934) + Remove special-casing of FC_FILE in FcPatternPrint() + [.gitignore] Update + Implement FcPatternFormat and use it in cmdline tools (bug #17107) + Fix comparison of family names to ignore leading space properly + [fcmatch.c] Fix debug formatting + [fcmatch] Use larger multipliers to enforce order + [fcmatch] When matching, reserve score 0 for when elements don't exist + [fcmatch] Move FcFontSetMatch() functionality into FcFontSetMatchInternal() + [doc] Note that fontset returned by FcConfigGetFonts should not be modified + Make FcCharSetMerge() public + Don't use FcCharSetCopy in FcCharSetMerge + Oops. Fix usage output. + Revive FcConfigScan() (bug #17121) + Add fc-scan too that runs FcFileScan/FcDirScan + Oops, fix FcPatternFilter + [fc-match] Accept list of elements like fc-list (bug #13017) + Cleanup all manpage.* files + [fcmatch] Fix crash when no fonts are available. + [fcfreetype] Fix typo in GB2312 encoding name string (#19845) + Add ICONV_LIBS to fontconfig.pc.in (#19606) + [win32] Fix usage of GetFullPathName() + [win32] Expand "APPSHAREFONTDIR" to ../share/fonts relative to binary location + [win32] Do not remove leading '\\' such that network paths work + [fccache] Make sure the cache is current when reusing from open caches + Update Sinhala orthography (#19288) + [cache] After writing cache to file, update the internal copy to reflect this + Further update Sinhala orthography (#19288) + [fcformat] Add support for width modifiers + [fcformat] Refactor and restructure code for upcoming changes + [fcformat] Add support for subexpressions + [fcformat] Add element filtering and deletion + [fcformat] Add conditionals + [fcformat] Add simple converters + [fcformat] Implement 'cescape', 'shescape', and 'xmlescape' converters + [FcStrBuf] better handle malloc failure + [fcformat] Add value-count syntax + [fcformat] Implement 'delete', 'escape', and 'translate' filter functions + [fcformat] Start adding builtins + [fcformat] Refactor code to avoid malloc + [fcformat] Add support for builtin formats + [fcformat] Support indexing simple tags + [fcformat] Support 'default value' for simple tags + [fcformat] Implement array enumeration + [fclang] Implement FcLangSetGetLangs() (#18846) + [fcformat] Enumerate langsets like we do arrays of values + [fcformat] Add a 'pkgkit' builtin that prints tags for font packages + [fcformat] Add list of undocumented language features + [fc-lang] Continue parsing after an "include" (#20179) + Fix Fanti (fat) orth file (#20390) + Fix Makefile's to not create target file in case of failure + [fcstr.c] Embed a static 64-byte buffer in FcStrBuf + [fcstr,fcxml] Don't copy FcStrBuf contents when we would free it soon + [fcxml] Don't allocate attr array if there are no attributes + [fcxml] Embed 8 static FcPStack objects in FcConfigParse + [fcxml] Embed 64 static FcVStack objects in FcConfigParse + [fcxml.c] Embed a static 64-byte attr buffer in FcPStack + Call git tools using "git cmd" instead of "git-cmd" syntax + Replace 'KEITH PACKARD' with 'THE AUTHOR(S)' in license text in all files + [fcformat] Fix default-value handling + Document FcPatternFormat() format + [Makefile.am] Don't clean ChangeLog in distclean + Revert "[conf] Disable hinting when emboldening (#19904)" (#20599) + [fc-lang] Fix bug in country map generation + [fcstr] Remove unused variable + [fc-lang] Make LangSet representation in the cache files stable + [fc-cache] Remove obsolete sentence from man page + Detect TrueType Collections by checking the font data header + Mark matchers array const (#21935) + Use/prefer WWS family/style (name table id 21/22) + Simplify FcValueSave() semantics + Add XXX note about Unicode Plane 16 + Always set *changed in FcCharsetMerge + [charset] Grow internal FcCharset arrays exponentially + Remove unused prototypes and function + [xml] Centralize FcExpr allocation + [xml] Mark more symbols static + [xml] Allocate FcExpr's in a pool in FcConfig + [xml] Intern more strings + Bug 22154 -- fontconfig.pc doesn't include libxml2 link flags + Fix distcheck + Remove keithp's GPG key id + +Benjamin Close (1): + Remove build manpage logfile if it exists + +Chris Wilson (1): + Reduce number of allocations during FcSortWalk(). + +Dan Nicholson (1): + Let make expand fc_cachedir/FC_CACHEDIR (bug #18675) + +Harald Fernengel (1): + Don't use variables named 'bool' (bug #18851) + +Harshula Jayasuriya (1): + Fix Sinhala coverage (bug #19288) + +Karl Tomlinson (1): + Change FcCharSetMerge API + +Mike FABIAN (1): + [conf] Disable hinting when emboldening (#19904) + +Peter (1): + Make sure alias files are built first (bug 16464) + +Rahul Bhalerao (1): + Add config for new Indic fonts (bug #17856) + +Roozbeh Pournader (60): + Correct Sindhi orthography to use Arabic script (bug #17140) + Remove Sinhala characters not in modern use (bug #19288) + Add Filipino orth, alias Tagalog to Filipino (bug #19846) + Split Mongolian orth to Mongolia and China (bug #19847) + Fix doubly encoded UTF-8 in comments (bug #19848) + Change Turkmen orth from Cyrillic to Latin (bug #19849) + Rename Venda from "ven" to "ve" (bug #19852) + Rename "ku" to "ku_am", add "ku_iq" (bug #19853). + Add Kashubian (csb) orth file (bug #19866) + Add Malay (ms) orthography (bug #19867) + Add Kinyarwanda (rw) orthography (bug #19868) + Add Upper Sorbian (hsb) orthography (bug #19870) + Add Berber orthographies in Latin and Tifinagh scripts (bug #19881) + Renamed az to az_az (bug #19889) + Rename Igbo from "ibo" to "ig" (bug #19892) + Remove punctuation symbols from Asturian orthography (bug #19893) + Add Chhattisgarhi (hne) orthography (bug #19891) + Use newly added Cyrillic letters for Kurdish (bug #20049) + Add Kurdish in Turkey (ku_tr) orthography (bug #19891) + Add Aragonese (an) orthography (bug #19891) + Add Haitian Creole (ht) orthography (bug #19891) + Ad Ganda (lg) orthography (bug #19891) + Add Limburgan (li) orthography (bug #19891) + Add Sardinian (sc) orthography (bug #19891) + Add Sidamo (sid) and Wolaitta (wal) orthographies (bug #19891) + Fix Bengali (bn) and Assamese (as) orthographies (bug #22924) + Remove Euro Sign from all orthographies (bug #19865) + Add Ottoman Turkish (ota) orthography (bug #20114) + Divide Panjabi (pa) to that of Pakistan and India (bug #19890) + Add Blin (byn) orthography (bug #19891) + Add Papiamento (pap_aw, pap_an) orthographies (bug #19891) + Add Crimean Tatar (crh) orthography (bug #19891) + Switch Uzbek (uz) orthography to Latin (bug #19851) + Update Azerbaijani in Latin (az_az) to present usage (bug #20173) + Rename Avaric orthography from 'ava' to 'av' (bug #20174) + Rename Bambara orthography from 'bam' to 'bm' (bug #20175) + Rename Fulah orthography from 'ful' to 'ff' (bug #20177) + Change Kashmiri (ks) orthography to Arabic script (bug #20200) + Tighten Central Khmer (km) orthography (bug #20202) + Remove digits and symbols from some Indic orthographies (bug #20204) + Add Divehi (dv) orthography (bug #20207) + Extend Crimean Tatar (crh) orthography (bug #19891) + Update Serbo-Croatian (sh) orthography (bug #20368) + Add Ewe (ee) orthography (bug #20386) + Add Herero (hz) orthograhy (bug #20387) + Add Akan (ak) and Fanti (fat) orthographies (bug #20390) + Added Quechua (qu) orthography (bug #20392) + Add Sango (sg) orthography (bug #20393) + Add Tahitian (ty) orthography (bug #20391) + Add Navajo (nv) orthography (bug #20395) + Add Rundi (rn) orthography (bug #20398) + Add Zhuang (za) orthography (bug #20399) + Add orthographies for Oshiwambo languages (bug #20401) + Add Shona (sn) orthography (bug #20394) + Add Sichuan Yi (ii) orthography (bug #20402) + Add Javanese (jv) orthography (bug #20403) + Add Nauru (na) orthography (bug #20418) + Add Kanuri (kr) orthography (bug #20438) + Add Sundanese (su) orthography (bug #20440) + Reorganize Panjabi/Punjabi and Lahnda orthographies (bug #19890) + +Serge van den Boom (1): + Correctly handle mmap() failure (#21062) + +2.6 + +2.5.93 (2.6 RC3) + +Alexey Khoroshilov (1): + Fix FcStrDirname documentation. (bug 16068) + +Behdad Esfahbod (1): + Persian conf update. (bug 16066). + +Evgeniy Stepanov (1): + Fix index/offset for 'decorative' matcher. Bug 15890. + +Glen Low (1): + Fix Win32 build error: install tries to run fc-cache locally (bug 15928). + +Keith Packard (8): + Call FcFini to make memory debugging easier + Fix a few memory tracking mistakes. + Add extended, caps, dunhill style mappings. + Freetype 2.3.5 (2007-jul-02) fixes indic font hinting. re-enable (bug 15822) + Add a copy of dolt.m4 to acinclude.m4. + Libs.private needs freetype libraries + Oops. Fix for bug 15928 used wrong path for installed fc-cache. + Ignore empty elements + +Neskie Manuel (1): + Add Secwepemctsin Orthography. Bug 15996. + +Sayamindu Dasgupta (1): + FcConfigUptoDate breaks if directory mtime is in the future. Bug 14424. + +2.5.92 (2.6 RC2) + +Carlo Bramini (1): + Add FreeType-dependent functions to fontconfig.def file. (bug 15415) + +Changwoo Ryu (1): + Korean font in the default config - replacing baekmuk with un (bug 13569) + +Dennis Schridde (1): + Proper config path for static libraries in win32 + +Eric Anholt (1): + Fix build with !ENABLE_DOCS and no built manpages. + +Frederic Crozat (1): + Merge some of Mandriva configuration into upstream configuration. Bug 13247 + +Keith Packard (11): + Use DOLT if available + Work around for bitmap-only TrueType fonts that are missing the glyf table. + Remove size and dpi values from bitmap fonts. Bug 8765. + Add some sample cursive and fantasy families. + Add --all flag to fc-match to show the untrimmed list. Bug 13018. + Remove doltcompile in distclean + Use of ":=" in src/Makefile.am is unportable (bug 14420) + Make fc-match behave better when style is unknown (bug 15332) + Deal with libtool 2.2 which doesn't let us use LT_ variables. (bug 15692) + Allow for RC versions in README update + git ignore doltcompile + +Ryan Schmidt (1): + fontconfig build fails if "head" is missing or unusable (bug 14304) + +Sylvain Pasche (1): + Fontconfig options for freetype sub-pixel filter configuration + +2.5.91 (2.6 RC1) + +Hongbo Zhao (1): + Not_contain should use strstr, not strcmp on strings. (bug 13632) + +Keith Packard (11): + Move conf.avail/README to conf.d/README (bug 13392) + Fix OOM failure case in FcPStackPush. + Remove freetype requirement for build-time applications. + Include fcftaliastail.h so that the freetype funcs are exported. + Eliminate references to freetype from utility Makefile.am's + Distribute new fcftint.h file + Create new-version.sh to help with releases, update INSTALL instructions + Distribute khmer font aliases + Add more files to .gitignore + new-version.sh was mis-editing files + git-tag requires space after -m flag + +2.5 + +Keith Packard (4): + Document several function return values (Bug 13145). + Document that Match calls FcFontRenderPrepare (bug 13162). + Document that FcConfigGetFonts returns the internal fontset (bug 13197) + Revert "Remove fcprivate.h, move the remaining macros to fcint.h." + +Tor Lillqvist (1): + Workaround for stat() brokenness in Microsoft's C library (bug 8526) + +2.4.92 (2.5 RC2) + +Behdad Esfahbod (14): + Make fc-match --sort call FcFontRenderPrepare. + Port fonts-persian.conf to new alias syntax with binding="same" + Fix trivial bugs in edit-sgml.c + Add FcGetLangs() and FcLangGetCharSet(). + Add/update config files from Fedora. + Split 40-generic.conf into 40-nonlatin.conf and 45-latin.conf + Use binding="same" in 30-urw-aliases.conf and remove duplicate entries. + Remove redundant/obsolete comments from conf files. + Remove 20-lohit-gujarati.conf. It's covered by 25-unhint-nonlatin.conf now. + Oops, fix Makefile.am. + Remove 25-unhint-nonlatin.conf from default configuration by not linking it. + Fix documented conf-file naming format in README + Remove list of available conf files from README. + Simplify/improve 30-metric-aliases.conf + +Keith Packard (25): + Also check configDirs mtimes in FcConfigUptoDate + Respect "binding" attribute in entries. + Correct documentation for FcAtomicLock (Bug 12947). + Remove fcprivate.h, move the remaining macros to fcint.h. + Correct documentation for FcConfigUptoDate (bug 12948). + Document skipping of fonts from FcFileScan/FcDirScan. + Make file_stat argument to FcDirCacheLoadFile optional. + Clean up exported names in fontconfig.h. + Track line numbers in sgml edit tool input. + Typo error in function name: Inverval -> interval + Don't check cache file time stamps when cleaning cache dir. + Use FcLangDifferentTerritory instead of FcLangDifferentCountry. + Verify documentation covers exposed symbols. + Document previously undocumented functions. (bug 12963) + Update documentation for FcStrCopyFilename (bug 12964). + Update documentation for stale FcConfigGetConfig function. + Have FcConfigSetCurrent accept the current configuration and simply return + Remove references to FcConfigParse and FcConfigLoad. + Replace incorrect documentation uses of 'char' with 'FcChar8' (bug 13002). + Fix formatting syntax in doc/fccache.fncs + Generate fccache.sgml, fcdircache.sgml and fclangset.sgml. + Formatting syntax mistake in doc/fclangset.fncs. + Link new function documentation into the fontconfig-devel.sgml + Ignore new generated documentation + Export FcConfig{G,S}etRescanInverval from .so, mark as deprecated. + +2.4.91 (2.5 RC1) + +Behdad Esfahbod (1): + Update CaseFolding.txt to Unicode 5.1.0 + +Dwayne Bailey (1): + Add/fix *.orth files for South African languages + +Hideki Yamane (1): + Handle Japanese fonts better. (debian bug #435971) + +Keith Packard (32): + rehash increment could be zero, causing rehash infinite loop. + Work around FreeType bug when glyph name buffer is too small. + Free temporary string in FcDirCacheUnlink (Bug #11758) + Fix ChangeLog generation to avoid circular make dependency + Store font directory mtime in cache file. + Comment about mmaping cache files was misleading. + Make FC_FULLNAME include all fullname entries, elide nothing. [bug 12827] + Remove unneeded call to access(2) in fc-cache. + Improve verbose messages from fc-cache. + Verbose message about cleaning directories was imprecise + Don't use X_OK bit when checking for writable directories (bug 12438) + Have fc-cache remove invalid cache files from cache directories. + FcConfigParseAndLoad doc was missing the last param. + Place language name in constant array instead of pointer. + Must not insert cache into hash table before completely validating. + Eliminate relocations for glyph name table. + Eliminate relocations from FcCodePageRange structure (bug 10982). + Leave generated headers out of distribution (bug 12734). + Move elements to the end of fonts.conf. + Add BRAILLE PATTERN BLANK to list of blank glyphs. + Replace makealias pattern with something supported by POSIX grep (bug 11083) + FcInit should return FcFalse when FcInitLoadConfigAndFonts fails. (bug 10976) + There is no U+1257 (bug 10899). + Spelling errors in documentation. (bug 10879). + Oops. Left debugging printf in previous commit. + Handle UltraBlack weight. + Fix parallel build in fontconfig/docs (bug 10481). + Distribute man source files for command line programs (bug 9678). + Ensure weight/slant values present even when style is supplied (bug 9313). + fontconfig needs configure option to use gnu iconv (bug 4083). + Match 'ultra' on word boundaries to detect ultra bold fonts. (bug 2511) + Build fix for Solaris 10 with GCC. + +Mike FABIAN (1): + Avoid crashes if config files contain junk. + +Stephan Kulow (1): + Make FcPatternDuplicate copy the binding instead of always using Strong. + +Tilman Sauerbeck (2): + Store FcNoticeFoundries in read-only memory. + Store FcVendorFoundries in read-only memory. + +2.4.2 + +Han-Wen Nienhuys: + FcStrCanonFileName buggy for mingw. (bug 8311) + More fixes for Win32 building (bug 8311) + +Kean Johnston: + Don't use varargs CPP macros in fccache.c. (bug 8733) + +Keith Packard: + Remove documentation for non-existant FcConfigNormalizeFontDir. + Build fontconfig.def from header files when needed. + Detect and use available random number generator (bug 8308) + Add sparc64 architecture string. + FcStrCanonAbsoluteFilename should be static. + Use explicit platform/nameid order when scanning ttf files. + Warn (and recover) from config file without elements. + Avoid writing uninitialized structure pad bytes to cache files. + Fix grep pattern in makealias to work on non-Gnu grep (bug 8368). + Add FcFreeTypeQueryFace external API. Bug #7311. + Segfault scanning non-font files. Disallow scan edit of user vars. (#8767) + Add space between type and formal in devel man pages (bug 8935) + +Mike FABIAN: + Do not clean cache files for different architectures + +Peter Breitenlohner: + A VPATH build of fontconfig-2.4.1 fails for various reasons. Bug 8933. + Use instead of when documenting fonts.conf. Bug 8935. + Fix fc-cat documentation (bug 8935). + + +2.4.1 + +Keith Packard: + Update installation notes for 2.4 base. + Add ppc64 signature. Bug 8227 + Add signatures for m68k and mipsel (thanks debian buildd) + Add warning flags to fc-cache build. Clean up warnings in fc-cache. + Reimplement FcConfigAppFontAddDir; function was lost in 2.4.0. + +2.4.0 + +David Turner: + Replace character discovery loop with simpler, faster version. + +James Cloos: + Move files from conf.d to conf.avail + Standardize conf.avail number prefixing convention + Support all five possibilities for sub-pixel + Move user and local conf file loading into conf.avail files + Number the remaining conf.avail files + Update Makefile.am to match conf.avail changes + Replace load of conf.d in fonts.conf.in + Make room for chunks from fonts.conf in conf.avail + Re-order old conf.d files + Move some section from fonts.conf into conf.avail files + Update Makefile.am files + Make conf.avail and conf.d work + +Keith Packard: + Create fc_cachedir at install time. Bug 8157. + Reference patterns in FcCacheCopySet. + Replace gnu-specific sed command with simple grep. + Attempt to fix makealias usage for build on Mac OS X. + Accept locale environment variables that do not contain territory. + Merge branch 'jhcloos' + Insert newly created caches into reference data structure. + Add XML headers to new conf files. Move link make commands to conf.avail dir + Rename conf.avail to conf.d + Fix conf.d directory sorting. + Include cachedir in fonts.dtd. + Don't display tests for DESTDIR on make install. + Split much of the configuration into separate files. Renumber files + +2.3.97 + +Carl Worth: + Rename FcPatternThawAll to FcPatternFini. + Add a configuration file that disables hinting for the Lohit Gujarati font + +Keith Packard: + Various GCC 4 cleanups for signed vs unsigned char + Finish INSTALL changes. .gitignore ChangeLog + Merge branch 'fc-2_4_branch' to master + Remove all .cvsignore files + Hide private functions in shared library. Export functionality for utilities. + Hide FreeType glue code from library ABI. + Can't typecheck values for objects with no known type. + Leave cache files mapped permanently. + Reference count cache objects. + Make cache reference counting more efficient. + Oops, fc-lang broke when I added cache referencing. + Correct reference count when sharing cache file objects. + Eliminate .so PLT entries for local symbols. (thanks to Arjan van de Ven) + Update architecture signatures for x86-64 and ppc. + Parallel build fix for fcalias.h and fcaliastail.h + Charset hashing depended on uniqueness of leaves. + +Patrick Lam: + file Makefile.am was initially added on branch fc-2_4_branch. + Modify config file to use Greek fonts before Asian fonts with Greek glyphs. + Use libtool -no-undefined flag on all platforms. + file ftglue.c was initially added on branch fc-2_4_branch. + 2005-11-23 Frederic Crozat : reviewed by: plam + file 10-fonts-persian.conf was initially added on branch fc-2_4_branch. + Sort directory entries while scanning them from disk; prevents Heisenbugs + file ln.orth was initially added on branch fc-2_4_branch. + Fix typos in orth files. Reported by Denis Jacquerye. + On Windows, unlink before rename. Reported by Tim Evans. + file fc-match.sgml was initially added on branch fc-2_4_branch. + +2.3.96 + +Keith Packard: + Make path names in cache files absolute (NB, cache format change) Stop + Eliminate pattern freezing + Add .gitignore + Construct short architecture name from architecture signature. + Write caches to first directory with permission. Valid cache in FcDirCacheOpen. + Eliminate NormalizeDir. Eliminate gratuitous stat/access calls per dir. + Add architecture to cache filename. + Eliminate global cache. Eliminate multi-arch cache code. + Fix up fc-cache and fc-cat for no global cache changes. + Eliminate ./ and ../ elements from font directory names when scanning. + Regenerate x86 line in fcarch.tmpl.h to match change in cache data. + Add x86-64 architecture and signature. + During test run, remove cache directory to avoid stale cache usage. + Add ppc architecture + Revert to original FcFontSetMatch algorithm to avoid losing fonts. + Rework cache files to use offsets for all data structures. + Fix build problems caused by cache rework. + FcCharSetSerialize was using wrong offset for leaves. Make fc-cat work. + Rework Object name database to unify typechecking and object lookup. + Skip broken caches. Cache files are auto-written, don't rewrite in fc-cache. + Fix fc-cat again. Sigh. + Use intptr_t instead of off_t inside FcCache structure. + Serialized value lists were only including one value. + Automatically remove invalid cache files. + With no args, fc-cat now dumps all directories. + Revert ABI changes from version 2.3 + Change $(pkgcachedir) to $(fc_cachedir) in fc-cat and fc-cache Makefile.am + Allow FcTypeLangSet to match either FcTypeLangSet or FcTypeString. + Remove stale architecture signatures. + Pass directory information around in FcCache structure. Freeze charsets. + Fix fc-lang to use new charset freezer API. + Fontset pattern references are relative to fontset, not array. + Add some ignores + Only rebuild caches for system fonts at make install time. + Fix memory leaks in fc-cache directory cleaning code. + Add @EXPAT_LIBS@ to Libs.private in fontconfig.pc (bug 7683) + Avoid #warning directives on non-GCC compilers. (bug 7683) + Chinese/Macau needs the Hong Kong orthography instead of Taiwan (bug 7884) + Add Assamese orthography (as.orth). Bug #8050 + Really only rebuild caches for system fonts at make install time. + Fonts matching lang not territory should satisfy sort pattern lang. + Prefer Bitstream Vera to DejaVu families. + Guess that mac roman names with lots of high bits are actually SJIS. + Document FC_DEBUG values (bug 6393). Document name \ escape syntax. + Move Free family names to bottom of respective aliases. (bug 7429) + Unify directory canonicalization into FcStrAddFilename. + Allow font caches to contain newer version numbers + Add FcMatchScan to resolve Delicious font matching issues (bug #6769) + Fix missing initialization/destruction of new 'scan' target subst list. + Don't segfault when string values can't be parsed as charsets or langsets. + Using uninitialized (and wrong) variable in FcStrCopyFilename. + Oops; missed the 60-delicious.conf file. + +Patrick Lam: + Keith Packard + 2006-04-27 Paolo Borelli (pborelli@katamail.com) reviewed by: plam + 2006-05-31 Yong Li (rigel863@gmail.com) reviewed by: plam, Bedhad Esfahbod + 2006-07-19 Jon Burgess (jburgess@uklinux.net) reviewed by: plam + 2006-08-04 Keith Packard (keithp@keithp.com) reviewed by: plam + +2.3.95 + +Match 'Standard Symbols L' for 'Symbol'. Add URW fonts as aliases for +all of the PostScript fonts. (reported by Miguel Rodriguez). Fix a +number of Coverity defects (Frederic Crozat). Speed up FcFontSort +(fix suggested by Kenichi Handa). Fix error with charsets. Survive +missing docbook2pdf. Compile on HP-UX, AIX, SGI and Windows (Cygwin, +MinGW). Fix intel compiler warnings. Fix multiarch support (don't +destroy multiarch files!) Require pkg-config. (Thanks Behdad; better +solution wanted for libxml2 detection!) Fix typos in orth files and +add orth for Lingala (reported by Denis Jacquerye). Remove debian/ +directory. Add a configuration file that disables hinting for the +Lohit Gujarati font (since the hinting distorts some glyphs quite +badly). Sort directory entries while scanning them from disk; +prevents Heisenbugs due to file ordering in a directory (due to Egmont +Koblinger). Fix Wine's problem with finding fonts. (Reported by +Bernhard Rosenkraenzer.) Fix the issues with GNU libiconv vs. libc +iconv (which especially appear on Solarii); patch by Behdad Esfahbod, +approach suggested by Tim Mooney. + +2.3.94 + +fc-cat can take directories as input and creates old-style fonts.cache +listings. +fc-cache takes -r --really-force which blows away all old caches and +regenerates. +Robustness fixes, integer overflow fixes (notably to cache handling +code), toast broken global cache files. +Change binary format to make it compatible with static langset +information (thanks to Takashi Iwai). +Open hashed caches before fonts.cache-2 (Takashi Iwai). +Fix FcFontSetMatch's algorithm, which used to unjustly kill fonts for +not declaring certain elements (Takashi Iwai). +Fix matching bug when multiple elements match; don't use +the sum of all scores, but the best score (James Su). +Make fc-lang more friendly to Windows systems. +Remove archaic chars from Georgian charset; add Euro character to +charsets for European languages. +Fix treatment of broken PCF fonts that don't declare family names. +Pass O_BINARY to open if appropriate (reported by Doodle). +Normalize font directories to the form in which they appear in +config files. +Add a record of the cached directory to the cache file. +Perf optimizations (Dirk Mueller; some reported by Michael Meeks.) +Don't loop infinitely on recursive symlinks. +Make 'make distcheck' work with automake 1.6.3. +Replace 'stamp' target with mkinstalldirs. +Don't stop scanning if a directory in fonts.conf doesn't exist, +because subsequent directories might exist. +Put directory names into global cache (reported by Ronny V. Vindenes). +Treat zh-hk fonts differently from zh-tw fonts. This patch may cause +fontconfig to treat A-X fonts differently from A-Y fonts; please mail +the fontconfig list if this causes any problems. +Fix for unaligned memory accesses (Andreas Schwab). +Fix treatment of cache directory as read from cache file; don't use +string equality to determine if we have the right file, use inode +equality. +Properly skip past dir caches that contain zero fonts, as occurs +in global caches (reported by Mike Fabian). +Print out full pathname in fc-match -v (reported by Frederic Crozat). +Fix bug where fc-match crashes when given __DUMMY__ property to +match on. + +2.3.93 + +Create cache files in /var/cache/fontconfig with hashed filenames, if +possible, for added FHS compliance. +Make fc-cat read both per-directory and global cache files. +Add config file for Persian fonts from Sharif FarsiWeb, Inc. +Major performance improvements by Dirk Mueller, Stephen Kulow, and Michael Matz at SuSE: in particular, speed up FcFontSetMatch, and inline many functions. +Fix treatment of globs in config files, broken since 2.3.2 and discovered by Mathias Clasen. +Don't use freetype internal headers (patch by Matthias Clasen). +Further space improvements: create langsets statically, so that they can live in .rodata. +Properly align mmapped data structures to make e.g. ia64 happy. +Bug fixes. + +2.3.92 + +Fix corrupted caches bugs from 2.3.91 (reported by Mike Fabian). +Store only basename in the cache, reconstitute on demand +(reported by James Cloos). +Change the rule for artificial emboldening in fonts.conf.in. This +enables the support for artificial emboldening included in cairo +(patch by Zhe Su). +Add FC_EMBEDDED_BITMAP object type to tell Xft/Cairo whether +to load embedded bitmaps or not (patch by Jinghua Luo). +Fix GCC4 warnings (some by Behdad Esfahbod). +Support localized font family and style names; this has been reported +to break old apps like xfd, but modern (gtk+/qt/mozilla) apps work +fine (patch by Zhe Su). +Prevent fc-list from escaping strings when printing them (reported by +Matthias Clasen). +Add valist sentinel markup for FcObjectSetBuild and +FcPatternBuild (patch by Marcus Meissner). +Add consts to variables so as to move arrays into .rodata (patch by +Ross Burton). +Modify config file to use Greek fonts before Asian fonts with +Greek glyphs. (patch by Simos Xenitellis). +Use libtool -no-undefined flag on all platforms (patch by Christian +Biesinger). + +2.3.91 + +Use libxml2 if requested or if expat not available. (Mathias Hasselmann) +Fix multi-arch cache files: compute the position for the +block to be added using info from OrigFile, not NewFile. (plam) +Cast results of sizeof() to unsigned int to get rid of +warnings on x86_64 (reported by Matthias Clasen). +Use FcAtomic to rewrite cache files; don't unlink the fonts.cache-2 +file even if there's no data to write; just write an empty cache file. +(Reported by Lubos Lunak) +Allocate room for the subdirectory names in each directory cache. +(Reported by James Cloos) + +2.3.90 + +Development release of mmap patch: load pattern information +directly from cache files. (Patrick Lam) + +2.3.2 + +Patch memory leaks in using iconv. (Reported by Chris Capoccia) +Patch memory leaks in fc-cache. (Reported by Chris Capoccia) +Fetch bitmap glyphs to get widths during font evaluation. (keithp) +Share strings through FcObjectStaticName (Ross Burton) +Windows build updates (Tor Lillqvist) + +2.3.1 + +Be more careful about broken GSUB/GPOS tables (Manish Singh) +Include debian packaging stuff in CVS (Josselin Mouette) +Add more conf.d examples (Keith Packard) +Make manuals build again (Keith Packard) +Johap -> Johab (Funda Wang) + +2.3.0 + +Fix memory leak of patterns rejected by configuration (#2518) + +Create prototype /etc/fonts/conf.d directory and populate it with a few +sample files. These samples are unused as the file names don't start with +numbers. + +Update documentation. + +2.2.99 + +Verify cache for FC_FILE and FC_FAMILY in every entry (#2219) + +Update blanks list from recent Unicode docs (#86) + +Various small build fixes (#280, #2278, + +Documentation fixes (#2085, #2284, #2285) + +Add polite typechecking to config file loader (#229) + +2.2.98 + +Share object name strings (Michael Meeks) + +Eliminate a couple of codepoints from Russian orthography (John Thacker) + +Add synthetic emboldening configuration changes (Jakub Pavelek) + +Change FcFontSetSort to ignore language after fonts with the requested +languages have been found. (Owen Taylor) + +Add some RedHat font configuration changes (Owen Tayler). + +Add full Unicode case folding support to case-ignoring string functions +(Keith Packard) + +Remove Han characters from Korean orthography (Tor Andersson) + +2.2.97 + +Fc-cache sleeps before exiting to ensure filesystem timestamps are well +ordered. + +Added Punjai orthography. + +The timestamp in fonts.conf is gone now. Too many problems. + +The default font path includes all of the X fonts; use selectfont/rejectfont +to eliminate bitmaps, as shown in the sample local.conf file. + + configuration elements may now reference a directory. Files +in that directory matching [0-9]* are loaded in UTF-8 collating sequence order. + + configuration added to control which fonts are used. + +fontformat font pattern elements built from the FT_Get_X11_Font_Format +function in newer versions of FreeType. + +'capability' list constructed from gsub/gpos and silf values in TrueType +files. + +Multi-lingual names (style, family, fullname) extracted and stored with +parallel lang properties marking language. + +2.2.96 + +Fix FcConfigUpToDate to actually check all font directories and eliminate +a typo which completely prevented it from working (Lubos Lunak +) + +Remove comma at end of FcResult enum definition for picky compilers. + +2.2.95 + +Add FcResultOutOfMemory so FcFontSetMatch can return accurate error. + +Replace MIN/MAX/ABS macros which happened to be in old FreeType releases +with FC_MIN/FC_MAX/FC_ABS macros owned by fontconfig. + +2.2.94 + +The 2.2.93 release was prepared with a broken libtool which created +the shared library without the '.so' in the file names. + +2.2.93 + +This is the third prerelease of fontconfig 2.3. Significant changes from +2.2.92 are: + + o Use new FreeType #include syntax + o use y_ppem field instead of 'height' in bitmap sizes rec - + FreeType changed the semantics. Still uses height for + older versions of FreeType + o Don't construct program manuals unless docbook is available + +2.2.92 + + o make distcheck work + +2.2.91 + + o Switch to SGML manuals + o Add FC_DUAL width spacing value + o Add FcFini to close out fontconfig and release all memory + +2.2 + +This is the third public release of fontconfig, a font configuration and +customization library. Fontconfig is designed to locate fonts within the +system and select them according to requirements specified by applications. + +Fontconfig is not a rasterization library, nor does it impose a particular +rasterization library on the application. The X-specific library +'Xft' uses fontconfig along with freetype to specify and rasterize fonts. + +Keith Packard +keithp@keithp.com diff --git a/project/jni/fontconfig/config-fixups.h b/project/jni/fontconfig/config-fixups.h new file mode 100644 index 000000000..93ebf5bb3 --- /dev/null +++ b/project/jni/fontconfig/config-fixups.h @@ -0,0 +1,40 @@ +/* + * Copyright 息 2006 Keith Packard + * Copyright 息 2010 Behdad Esfahbod + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* This header file is supposed to be included in config.h */ + +/* just a hack to build the fat binaries: + * https://bugs.freedesktop.org/show_bug.cgi?id=20208 + */ +#ifdef __APPLE__ +# include +# undef SIZEOF_VOID_P +# undef ALIGNOF_DOUBLE +# ifdef __LP64__ +# define SIZEOF_VOID_P 8 +# define ALIGNOF_DOUBLE 8 +# else +# define SIZEOF_VOID_P 4 +# define ALIGNOF_DOUBLE 4 +# endif +#endif diff --git a/project/jni/fontconfig/config.h b/project/jni/fontconfig/config.h new file mode 100644 index 000000000..36939c024 --- /dev/null +++ b/project/jni/fontconfig/config.h @@ -0,0 +1,374 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* The normal alignment of `double', in bytes. */ +#define ALIGNOF_DOUBLE 8 + +/* Use libxml2 instead of Expat */ +/* #undef ENABLE_LIBXML2 */ + +/* Additional font directories */ +#define FC_ADD_FONTS "yes" + +/* Architecture prefix to use for cache file names */ +/* #undef FC_ARCHITECTURE */ + +/* System font directory */ +// #define FC_DEFAULT_FONTS "/system/fonts" + +/* Define to nothing if C supports flexible array members, and to 1 if it does + not. That way, with a declaration like `struct s { int n; double + d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 + compilers. When computing the size of such an object, don't use 'sizeof + (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' + instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with + MSVC and with C++ compilers. */ +#define FLEXIBLE_ARRAY_MEMBER /**/ + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#define HAVE_DIRENT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ +/* #undef HAVE_DOPRNT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `fstatfs' function. */ +#define HAVE_FSTATFS 1 + +/* Define to 1 if you have the `fstatvfs' function. */ +#define HAVE_FSTATVFS 1 + +/* FT_Bitmap_Size structure includes y_ppem field */ +#define HAVE_FT_BITMAP_SIZE_Y_PPEM 1 + +/* Define to 1 if you have the `FT_Get_BDF_Property' function. */ +#define HAVE_FT_GET_BDF_PROPERTY 1 + +/* Define to 1 if you have the `FT_Get_Next_Char' function. */ +#define HAVE_FT_GET_NEXT_CHAR 1 + +/* Define to 1 if you have the `FT_Get_PS_Font_Info' function. */ +#define HAVE_FT_GET_PS_FONT_INFO 1 + +/* Define to 1 if you have the `FT_Get_X11_Font_Format' function. */ +#define HAVE_FT_GET_X11_FONT_FORMAT 1 + +/* Define to 1 if you have the `FT_Has_PS_Glyph_Names' function. */ +#define HAVE_FT_HAS_PS_GLYPH_NAMES 1 + +/* Define to 1 if you have the `FT_Select_Size' function. */ +#define HAVE_FT_SELECT_SIZE 1 + +/* Define to 1 if you have the `getexecname' function. */ +/* #undef HAVE_GETEXECNAME */ + +/* Define to 1 if you have the `getopt' function. */ +// #define HAVE_GETOPT 1 + +/* Define to 1 if you have the `getopt_long' function. */ +// #define HAVE_GETOPT_LONG 1 + +/* Define to 1 if you have the `getpagesize' function. */ +// #define HAVE_GETPAGESIZE 1 + +/* Define to 1 if you have the `getprogname' function. */ +/* #undef HAVE_GETPROGNAME */ + +/* Have Intel __sync_* atomic primitives */ +// #define HAVE_INTEL_ATOMIC_PRIMITIVES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `link' function. */ +#define HAVE_LINK 1 + +/* Define to 1 if you have the `lrand48' function. */ +#define HAVE_LRAND48 1 + +/* Define to 1 if you have the `lstat' function. */ +#define HAVE_LSTAT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `mkdtemp' function. */ +#define HAVE_MKDTEMP 1 + +/* Define to 1 if you have the `mkostemp' function. */ +// #define HAVE_MKOSTEMP 1 + +/* Define to 1 if you have the `mkstemp' function. */ +#define HAVE_MKSTEMP 1 + +/* Define to 1 if you have a working `mmap' system call. */ +#define HAVE_MMAP 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + +/* Define to 1 if you have the 'posix_fadivse' function. */ +// #define HAVE_POSIX_FADVISE 1 + +/* Have POSIX threads */ +#define HAVE_PTHREAD 1 + +/* Have PTHREAD_PRIO_INHERIT. */ +//#define HAVE_PTHREAD_PRIO_INHERIT 1 + +/* Define to 1 if you have the `rand' function. */ +#define HAVE_RAND 1 + +/* Define to 1 if you have the `random' function. */ +//#define HAVE_RANDOM 1 + +/* Define to 1 if you have the `random_r' function. */ +//#define HAVE_RANDOM_R 1 + +/* Define to 1 if you have the `rand_r' function. */ +//#define HAVE_RAND_R 1 + +/* Define to 1 if you have the `readlink' function. */ +#define HAVE_READLINK 1 + +/* Define to 1 if you have the `regcomp' function. */ +#define HAVE_REGCOMP 1 + +/* Define to 1 if you have the `regerror' function. */ +#define HAVE_REGERROR 1 + +/* Define to 1 if you have the `regexec' function. */ +#define HAVE_REGEXEC 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_REGEX_H 1 + +/* Define to 1 if you have the `regfree' function. */ +#define HAVE_REGFREE 1 + +/* Define to 1 if you have the 'scandir' function. */ +#define HAVE_SCANDIR 1 + +/* Define to 1 if you have the 'scandir' function with int (* compar)(const + void *, const void *) */ +/* #undef HAVE_SCANDIR_VOID_P */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SCHED_H */ + +/* Have sched_yield */ +/* #undef HAVE_SCHED_YIELD */ + +/* Have Solaris __machine_*_barrier and atomic_* operations */ +/* #undef HAVE_SOLARIS_ATOMIC_OPS */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if `d_type' is a member of `struct dirent'. */ +#define HAVE_STRUCT_DIRENT_D_TYPE 1 + +/* Define to 1 if `f_flags' is a member of `struct statfs'. */ +#define HAVE_STRUCT_STATFS_F_FLAGS 1 + +/* Define to 1 if `f_fstypename' is a member of `struct statfs'. */ +/* #undef HAVE_STRUCT_STATFS_F_FSTYPENAME */ + +/* Define to 1 if `f_basetype' is a member of `struct statvfs'. */ +/* #undef HAVE_STRUCT_STATVFS_F_BASETYPE */ + +/* Define to 1 if `f_fstypename' is a member of `struct statvfs'. */ +/* #undef HAVE_STRUCT_STATVFS_F_FSTYPENAME */ + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define to 1 if you have the header file. */ +//#define HAVE_SYS_MOUNT_H 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +//#define HAVE_SYS_STATFS_H 1 + +/* Define to 1 if you have the header file. */ +//#define HAVE_SYS_STATVFS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_VFS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `vprintf' function. */ +#define HAVE_VPRINTF 1 + +/* Can use #warning in C files */ +#define HAVE_WARNING_CPP_DIRECTIVE 1 + +/* Use xmlparse.h instead of expat.h */ +/* #undef HAVE_XMLPARSE_H */ + +/* Define to 1 if you have the `XML_SetDoctypeDeclHandler' function. */ +//#define HAVE_XML_SETDOCTYPEDECLHANDLER 1 + +/* Define to 1 if you have the `_mktemp_s' function. */ +/* #undef HAVE__MKTEMP_S */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "fontconfig" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "https://bugs.freedesktop.org/enter_bug.cgi?product=fontconfig" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "fontconfig" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "fontconfig 2.11.0" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "fontconfig" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2.11.0" + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* The size of `char', as computed by sizeof. */ +/* #undef SIZEOF_CHAR */ + +/* The size of `int', as computed by sizeof. */ +/* #undef SIZEOF_INT */ + +/* The size of `long', as computed by sizeof. */ +/* #undef SIZEOF_LONG */ + +/* The size of `short', as computed by sizeof. */ +/* #undef SIZEOF_SHORT */ + +/* The size of `void*', as computed by sizeof. */ +/* #undef SIZEOF_VOIDP */ + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Use iconv. */ +#define USE_ICONV 0 + +/* Use regex */ +#define USE_REGEX /**/ + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + + +/* Version number of package */ +#define VERSION "2.11.0" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `int' if does not define. */ +/* #undef pid_t */ + +#include "config-fixups.h" diff --git a/project/jni/fontconfig/fc-case/fccase.h b/project/jni/fontconfig/fc-case/fccase.h new file mode 100644 index 000000000..e80a00951 --- /dev/null +++ b/project/jni/fontconfig/fc-case/fccase.h @@ -0,0 +1,330 @@ +/* + * fontconfig/fc-case/fccase.tmpl.h + * + * Copyright © 2003 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#define FC_NUM_CASE_FOLD 264 +#define FC_NUM_CASE_FOLD_CHARS 471 +#define FC_MAX_CASE_FOLD_CHARS 6 +#define FC_MAX_CASE_FOLD_EXPAND 4 +#define FC_MIN_FOLD_CHAR 0x00000041 +#define FC_MAX_FOLD_CHAR 0x00010427 + +static const FcCaseFold fcCaseFold[FC_NUM_CASE_FOLD] = { + { 0x00000041, FC_CASE_FOLD_RANGE, 0x001a, 32 }, + { 0x000000b5, FC_CASE_FOLD_RANGE, 0x0001, 775 }, + { 0x000000c0, FC_CASE_FOLD_RANGE, 0x0017, 32 }, + { 0x000000d8, FC_CASE_FOLD_RANGE, 0x0007, 32 }, + { 0x000000df, FC_CASE_FOLD_FULL, 0x0002, 0 }, + { 0x00000100, FC_CASE_FOLD_EVEN_ODD, 0x002f, 1 }, + { 0x00000130, FC_CASE_FOLD_FULL, 0x0003, 2 }, + { 0x00000132, FC_CASE_FOLD_EVEN_ODD, 0x0005, 1 }, + { 0x00000139, FC_CASE_FOLD_EVEN_ODD, 0x000f, 1 }, + { 0x00000149, FC_CASE_FOLD_FULL, 0x0003, 5 }, + { 0x0000014a, FC_CASE_FOLD_EVEN_ODD, 0x002d, 1 }, + { 0x00000178, FC_CASE_FOLD_RANGE, 0x0001, -121 }, + { 0x00000179, FC_CASE_FOLD_EVEN_ODD, 0x0005, 1 }, + { 0x0000017f, FC_CASE_FOLD_RANGE, 0x0001, -268 }, + { 0x00000181, FC_CASE_FOLD_RANGE, 0x0001, 210 }, + { 0x00000182, FC_CASE_FOLD_EVEN_ODD, 0x0003, 1 }, + { 0x00000186, FC_CASE_FOLD_RANGE, 0x0001, 206 }, + { 0x00000187, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x00000189, FC_CASE_FOLD_RANGE, 0x0002, 205 }, + { 0x0000018b, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x0000018e, FC_CASE_FOLD_RANGE, 0x0001, 79 }, + { 0x0000018f, FC_CASE_FOLD_RANGE, 0x0001, 202 }, + { 0x00000190, FC_CASE_FOLD_RANGE, 0x0001, 203 }, + { 0x00000191, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x00000193, FC_CASE_FOLD_RANGE, 0x0001, 205 }, + { 0x00000194, FC_CASE_FOLD_RANGE, 0x0001, 207 }, + { 0x00000196, FC_CASE_FOLD_RANGE, 0x0001, 211 }, + { 0x00000197, FC_CASE_FOLD_RANGE, 0x0001, 209 }, + { 0x00000198, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x0000019c, FC_CASE_FOLD_RANGE, 0x0001, 211 }, + { 0x0000019d, FC_CASE_FOLD_RANGE, 0x0001, 213 }, + { 0x0000019f, FC_CASE_FOLD_RANGE, 0x0001, 214 }, + { 0x000001a0, FC_CASE_FOLD_EVEN_ODD, 0x0005, 1 }, + { 0x000001a6, FC_CASE_FOLD_RANGE, 0x0001, 218 }, + { 0x000001a7, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000001a9, FC_CASE_FOLD_RANGE, 0x0001, 218 }, + { 0x000001ac, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000001ae, FC_CASE_FOLD_RANGE, 0x0001, 218 }, + { 0x000001af, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000001b1, FC_CASE_FOLD_RANGE, 0x0002, 217 }, + { 0x000001b3, FC_CASE_FOLD_EVEN_ODD, 0x0003, 1 }, + { 0x000001b7, FC_CASE_FOLD_RANGE, 0x0001, 219 }, + { 0x000001b8, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000001bc, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000001c4, FC_CASE_FOLD_RANGE, 0x0001, 2 }, + { 0x000001c5, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000001c7, FC_CASE_FOLD_RANGE, 0x0001, 2 }, + { 0x000001c8, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000001ca, FC_CASE_FOLD_RANGE, 0x0001, 2 }, + { 0x000001cb, FC_CASE_FOLD_EVEN_ODD, 0x0011, 1 }, + { 0x000001de, FC_CASE_FOLD_EVEN_ODD, 0x0011, 1 }, + { 0x000001f0, FC_CASE_FOLD_FULL, 0x0003, 8 }, + { 0x000001f1, FC_CASE_FOLD_RANGE, 0x0001, 2 }, + { 0x000001f2, FC_CASE_FOLD_EVEN_ODD, 0x0003, 1 }, + { 0x000001f6, FC_CASE_FOLD_RANGE, 0x0001, -97 }, + { 0x000001f7, FC_CASE_FOLD_RANGE, 0x0001, -56 }, + { 0x000001f8, FC_CASE_FOLD_EVEN_ODD, 0x0027, 1 }, + { 0x00000220, FC_CASE_FOLD_RANGE, 0x0001, -130 }, + { 0x00000222, FC_CASE_FOLD_EVEN_ODD, 0x0011, 1 }, + { 0x0000023a, FC_CASE_FOLD_RANGE, 0x0001, 10795 }, + { 0x0000023b, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x0000023d, FC_CASE_FOLD_RANGE, 0x0001, -163 }, + { 0x0000023e, FC_CASE_FOLD_RANGE, 0x0001, 10792 }, + { 0x00000241, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x00000243, FC_CASE_FOLD_RANGE, 0x0001, -195 }, + { 0x00000244, FC_CASE_FOLD_RANGE, 0x0001, 69 }, + { 0x00000245, FC_CASE_FOLD_RANGE, 0x0001, 71 }, + { 0x00000246, FC_CASE_FOLD_EVEN_ODD, 0x0009, 1 }, + { 0x00000345, FC_CASE_FOLD_RANGE, 0x0001, 116 }, + { 0x00000370, FC_CASE_FOLD_EVEN_ODD, 0x0003, 1 }, + { 0x00000376, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x00000386, FC_CASE_FOLD_RANGE, 0x0001, 38 }, + { 0x00000388, FC_CASE_FOLD_RANGE, 0x0003, 37 }, + { 0x0000038c, FC_CASE_FOLD_RANGE, 0x0001, 64 }, + { 0x0000038e, FC_CASE_FOLD_RANGE, 0x0002, 63 }, + { 0x00000390, FC_CASE_FOLD_FULL, 0x0006, 11 }, + { 0x00000391, FC_CASE_FOLD_RANGE, 0x0011, 32 }, + { 0x000003a3, FC_CASE_FOLD_RANGE, 0x0009, 32 }, + { 0x000003b0, FC_CASE_FOLD_FULL, 0x0006, 17 }, + { 0x000003c2, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000003cf, FC_CASE_FOLD_RANGE, 0x0001, 8 }, + { 0x000003d0, FC_CASE_FOLD_RANGE, 0x0001, -30 }, + { 0x000003d1, FC_CASE_FOLD_RANGE, 0x0001, -25 }, + { 0x000003d5, FC_CASE_FOLD_RANGE, 0x0001, -15 }, + { 0x000003d6, FC_CASE_FOLD_RANGE, 0x0001, -22 }, + { 0x000003d8, FC_CASE_FOLD_EVEN_ODD, 0x0017, 1 }, + { 0x000003f0, FC_CASE_FOLD_RANGE, 0x0001, -54 }, + { 0x000003f1, FC_CASE_FOLD_RANGE, 0x0001, -48 }, + { 0x000003f4, FC_CASE_FOLD_RANGE, 0x0001, -60 }, + { 0x000003f5, FC_CASE_FOLD_RANGE, 0x0001, -64 }, + { 0x000003f7, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000003f9, FC_CASE_FOLD_RANGE, 0x0001, -7 }, + { 0x000003fa, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000003fd, FC_CASE_FOLD_RANGE, 0x0003, -130 }, + { 0x00000400, FC_CASE_FOLD_RANGE, 0x0010, 80 }, + { 0x00000410, FC_CASE_FOLD_RANGE, 0x0020, 32 }, + { 0x00000460, FC_CASE_FOLD_EVEN_ODD, 0x0021, 1 }, + { 0x0000048a, FC_CASE_FOLD_EVEN_ODD, 0x0035, 1 }, + { 0x000004c0, FC_CASE_FOLD_RANGE, 0x0001, 15 }, + { 0x000004c1, FC_CASE_FOLD_EVEN_ODD, 0x000d, 1 }, + { 0x000004d0, FC_CASE_FOLD_EVEN_ODD, 0x0057, 1 }, + { 0x00000531, FC_CASE_FOLD_RANGE, 0x0026, 48 }, + { 0x00000587, FC_CASE_FOLD_FULL, 0x0004, 23 }, + { 0x000010a0, FC_CASE_FOLD_RANGE, 0x0026, 7264 }, + { 0x000010c7, FC_CASE_FOLD_RANGE, 0x0001, 7264 }, + { 0x000010cd, FC_CASE_FOLD_RANGE, 0x0001, 7264 }, + { 0x00001e00, FC_CASE_FOLD_EVEN_ODD, 0x0095, 1 }, + { 0x00001e96, FC_CASE_FOLD_FULL, 0x0003, 27 }, + { 0x00001e97, FC_CASE_FOLD_FULL, 0x0003, 30 }, + { 0x00001e98, FC_CASE_FOLD_FULL, 0x0003, 33 }, + { 0x00001e99, FC_CASE_FOLD_FULL, 0x0003, 36 }, + { 0x00001e9a, FC_CASE_FOLD_FULL, 0x0003, 39 }, + { 0x00001e9b, FC_CASE_FOLD_RANGE, 0x0001, -58 }, + { 0x00001e9e, FC_CASE_FOLD_FULL, 0x0002, 42 }, + { 0x00001ea0, FC_CASE_FOLD_EVEN_ODD, 0x005f, 1 }, + { 0x00001f08, FC_CASE_FOLD_RANGE, 0x0008, -8 }, + { 0x00001f18, FC_CASE_FOLD_RANGE, 0x0006, -8 }, + { 0x00001f28, FC_CASE_FOLD_RANGE, 0x0008, -8 }, + { 0x00001f38, FC_CASE_FOLD_RANGE, 0x0008, -8 }, + { 0x00001f48, FC_CASE_FOLD_RANGE, 0x0006, -8 }, + { 0x00001f50, FC_CASE_FOLD_FULL, 0x0004, 44 }, + { 0x00001f52, FC_CASE_FOLD_FULL, 0x0006, 48 }, + { 0x00001f54, FC_CASE_FOLD_FULL, 0x0006, 54 }, + { 0x00001f56, FC_CASE_FOLD_FULL, 0x0006, 60 }, + { 0x00001f59, FC_CASE_FOLD_RANGE, 0x0001, -8 }, + { 0x00001f5b, FC_CASE_FOLD_RANGE, 0x0001, -8 }, + { 0x00001f5d, FC_CASE_FOLD_RANGE, 0x0001, -8 }, + { 0x00001f5f, FC_CASE_FOLD_RANGE, 0x0001, -8 }, + { 0x00001f68, FC_CASE_FOLD_RANGE, 0x0008, -8 }, + { 0x00001f80, FC_CASE_FOLD_FULL, 0x0005, 66 }, + { 0x00001f81, FC_CASE_FOLD_FULL, 0x0005, 71 }, + { 0x00001f82, FC_CASE_FOLD_FULL, 0x0005, 76 }, + { 0x00001f83, FC_CASE_FOLD_FULL, 0x0005, 81 }, + { 0x00001f84, FC_CASE_FOLD_FULL, 0x0005, 86 }, + { 0x00001f85, FC_CASE_FOLD_FULL, 0x0005, 91 }, + { 0x00001f86, FC_CASE_FOLD_FULL, 0x0005, 96 }, + { 0x00001f87, FC_CASE_FOLD_FULL, 0x0005, 101 }, + { 0x00001f88, FC_CASE_FOLD_FULL, 0x0005, 106 }, + { 0x00001f89, FC_CASE_FOLD_FULL, 0x0005, 111 }, + { 0x00001f8a, FC_CASE_FOLD_FULL, 0x0005, 116 }, + { 0x00001f8b, FC_CASE_FOLD_FULL, 0x0005, 121 }, + { 0x00001f8c, FC_CASE_FOLD_FULL, 0x0005, 126 }, + { 0x00001f8d, FC_CASE_FOLD_FULL, 0x0005, 131 }, + { 0x00001f8e, FC_CASE_FOLD_FULL, 0x0005, 136 }, + { 0x00001f8f, FC_CASE_FOLD_FULL, 0x0005, 141 }, + { 0x00001f90, FC_CASE_FOLD_FULL, 0x0005, 146 }, + { 0x00001f91, FC_CASE_FOLD_FULL, 0x0005, 151 }, + { 0x00001f92, FC_CASE_FOLD_FULL, 0x0005, 156 }, + { 0x00001f93, FC_CASE_FOLD_FULL, 0x0005, 161 }, + { 0x00001f94, FC_CASE_FOLD_FULL, 0x0005, 166 }, + { 0x00001f95, FC_CASE_FOLD_FULL, 0x0005, 171 }, + { 0x00001f96, FC_CASE_FOLD_FULL, 0x0005, 176 }, + { 0x00001f97, FC_CASE_FOLD_FULL, 0x0005, 181 }, + { 0x00001f98, FC_CASE_FOLD_FULL, 0x0005, 186 }, + { 0x00001f99, FC_CASE_FOLD_FULL, 0x0005, 191 }, + { 0x00001f9a, FC_CASE_FOLD_FULL, 0x0005, 196 }, + { 0x00001f9b, FC_CASE_FOLD_FULL, 0x0005, 201 }, + { 0x00001f9c, FC_CASE_FOLD_FULL, 0x0005, 206 }, + { 0x00001f9d, FC_CASE_FOLD_FULL, 0x0005, 211 }, + { 0x00001f9e, FC_CASE_FOLD_FULL, 0x0005, 216 }, + { 0x00001f9f, FC_CASE_FOLD_FULL, 0x0005, 221 }, + { 0x00001fa0, FC_CASE_FOLD_FULL, 0x0005, 226 }, + { 0x00001fa1, FC_CASE_FOLD_FULL, 0x0005, 231 }, + { 0x00001fa2, FC_CASE_FOLD_FULL, 0x0005, 236 }, + { 0x00001fa3, FC_CASE_FOLD_FULL, 0x0005, 241 }, + { 0x00001fa4, FC_CASE_FOLD_FULL, 0x0005, 246 }, + { 0x00001fa5, FC_CASE_FOLD_FULL, 0x0005, 251 }, + { 0x00001fa6, FC_CASE_FOLD_FULL, 0x0005, 256 }, + { 0x00001fa7, FC_CASE_FOLD_FULL, 0x0005, 261 }, + { 0x00001fa8, FC_CASE_FOLD_FULL, 0x0005, 266 }, + { 0x00001fa9, FC_CASE_FOLD_FULL, 0x0005, 271 }, + { 0x00001faa, FC_CASE_FOLD_FULL, 0x0005, 276 }, + { 0x00001fab, FC_CASE_FOLD_FULL, 0x0005, 281 }, + { 0x00001fac, FC_CASE_FOLD_FULL, 0x0005, 286 }, + { 0x00001fad, FC_CASE_FOLD_FULL, 0x0005, 291 }, + { 0x00001fae, FC_CASE_FOLD_FULL, 0x0005, 296 }, + { 0x00001faf, FC_CASE_FOLD_FULL, 0x0005, 301 }, + { 0x00001fb2, FC_CASE_FOLD_FULL, 0x0005, 306 }, + { 0x00001fb3, FC_CASE_FOLD_FULL, 0x0004, 311 }, + { 0x00001fb4, FC_CASE_FOLD_FULL, 0x0004, 315 }, + { 0x00001fb6, FC_CASE_FOLD_FULL, 0x0004, 319 }, + { 0x00001fb7, FC_CASE_FOLD_FULL, 0x0006, 323 }, + { 0x00001fb8, FC_CASE_FOLD_RANGE, 0x0002, -8 }, + { 0x00001fba, FC_CASE_FOLD_RANGE, 0x0002, -74 }, + { 0x00001fbc, FC_CASE_FOLD_FULL, 0x0004, 329 }, + { 0x00001fbe, FC_CASE_FOLD_RANGE, 0x0001, -7173 }, + { 0x00001fc2, FC_CASE_FOLD_FULL, 0x0005, 333 }, + { 0x00001fc3, FC_CASE_FOLD_FULL, 0x0004, 338 }, + { 0x00001fc4, FC_CASE_FOLD_FULL, 0x0004, 342 }, + { 0x00001fc6, FC_CASE_FOLD_FULL, 0x0004, 346 }, + { 0x00001fc7, FC_CASE_FOLD_FULL, 0x0006, 350 }, + { 0x00001fc8, FC_CASE_FOLD_RANGE, 0x0004, -86 }, + { 0x00001fcc, FC_CASE_FOLD_FULL, 0x0004, 356 }, + { 0x00001fd2, FC_CASE_FOLD_FULL, 0x0006, 360 }, + { 0x00001fd3, FC_CASE_FOLD_FULL, 0x0006, 366 }, + { 0x00001fd6, FC_CASE_FOLD_FULL, 0x0004, 372 }, + { 0x00001fd7, FC_CASE_FOLD_FULL, 0x0006, 376 }, + { 0x00001fd8, FC_CASE_FOLD_RANGE, 0x0002, -8 }, + { 0x00001fda, FC_CASE_FOLD_RANGE, 0x0002, -100 }, + { 0x00001fe2, FC_CASE_FOLD_FULL, 0x0006, 382 }, + { 0x00001fe3, FC_CASE_FOLD_FULL, 0x0006, 388 }, + { 0x00001fe4, FC_CASE_FOLD_FULL, 0x0004, 394 }, + { 0x00001fe6, FC_CASE_FOLD_FULL, 0x0004, 398 }, + { 0x00001fe7, FC_CASE_FOLD_FULL, 0x0006, 402 }, + { 0x00001fe8, FC_CASE_FOLD_RANGE, 0x0002, -8 }, + { 0x00001fea, FC_CASE_FOLD_RANGE, 0x0002, -112 }, + { 0x00001fec, FC_CASE_FOLD_RANGE, 0x0001, -7 }, + { 0x00001ff2, FC_CASE_FOLD_FULL, 0x0005, 408 }, + { 0x00001ff3, FC_CASE_FOLD_FULL, 0x0004, 413 }, + { 0x00001ff4, FC_CASE_FOLD_FULL, 0x0004, 417 }, + { 0x00001ff6, FC_CASE_FOLD_FULL, 0x0004, 421 }, + { 0x00001ff7, FC_CASE_FOLD_FULL, 0x0006, 425 }, + { 0x00001ff8, FC_CASE_FOLD_RANGE, 0x0002, -128 }, + { 0x00001ffa, FC_CASE_FOLD_RANGE, 0x0002, -126 }, + { 0x00001ffc, FC_CASE_FOLD_FULL, 0x0004, 431 }, + { 0x00002126, FC_CASE_FOLD_RANGE, 0x0001, -7517 }, + { 0x0000212a, FC_CASE_FOLD_RANGE, 0x0001, -8383 }, + { 0x0000212b, FC_CASE_FOLD_RANGE, 0x0001, -8262 }, + { 0x00002132, FC_CASE_FOLD_RANGE, 0x0001, 28 }, + { 0x00002160, FC_CASE_FOLD_RANGE, 0x0010, 16 }, + { 0x00002183, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x000024b6, FC_CASE_FOLD_RANGE, 0x001a, 26 }, + { 0x00002c00, FC_CASE_FOLD_RANGE, 0x002f, 48 }, + { 0x00002c60, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x00002c62, FC_CASE_FOLD_RANGE, 0x0001, -10743 }, + { 0x00002c63, FC_CASE_FOLD_RANGE, 0x0001, -3814 }, + { 0x00002c64, FC_CASE_FOLD_RANGE, 0x0001, -10727 }, + { 0x00002c67, FC_CASE_FOLD_EVEN_ODD, 0x0005, 1 }, + { 0x00002c6d, FC_CASE_FOLD_RANGE, 0x0001, -10780 }, + { 0x00002c6e, FC_CASE_FOLD_RANGE, 0x0001, -10749 }, + { 0x00002c6f, FC_CASE_FOLD_RANGE, 0x0001, -10783 }, + { 0x00002c70, FC_CASE_FOLD_RANGE, 0x0001, -10782 }, + { 0x00002c72, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x00002c75, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x00002c7e, FC_CASE_FOLD_RANGE, 0x0002, -10815 }, + { 0x00002c80, FC_CASE_FOLD_EVEN_ODD, 0x0063, 1 }, + { 0x00002ceb, FC_CASE_FOLD_EVEN_ODD, 0x0003, 1 }, + { 0x00002cf2, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x0000a640, FC_CASE_FOLD_EVEN_ODD, 0x002d, 1 }, + { 0x0000a680, FC_CASE_FOLD_EVEN_ODD, 0x0017, 1 }, + { 0x0000a722, FC_CASE_FOLD_EVEN_ODD, 0x000d, 1 }, + { 0x0000a732, FC_CASE_FOLD_EVEN_ODD, 0x003d, 1 }, + { 0x0000a779, FC_CASE_FOLD_EVEN_ODD, 0x0003, 1 }, + { 0x0000a77d, FC_CASE_FOLD_RANGE, 0x0001, 30204 }, + { 0x0000a77e, FC_CASE_FOLD_EVEN_ODD, 0x0009, 1 }, + { 0x0000a78b, FC_CASE_FOLD_EVEN_ODD, 0x0001, 1 }, + { 0x0000a78d, FC_CASE_FOLD_RANGE, 0x0001, 23256 }, + { 0x0000a790, FC_CASE_FOLD_EVEN_ODD, 0x0003, 1 }, + { 0x0000a7a0, FC_CASE_FOLD_EVEN_ODD, 0x0009, 1 }, + { 0x0000a7aa, FC_CASE_FOLD_RANGE, 0x0001, 23228 }, + { 0x0000fb00, FC_CASE_FOLD_FULL, 0x0002, 435 }, + { 0x0000fb01, FC_CASE_FOLD_FULL, 0x0002, 437 }, + { 0x0000fb02, FC_CASE_FOLD_FULL, 0x0002, 439 }, + { 0x0000fb03, FC_CASE_FOLD_FULL, 0x0003, 441 }, + { 0x0000fb04, FC_CASE_FOLD_FULL, 0x0003, 444 }, + { 0x0000fb05, FC_CASE_FOLD_FULL, 0x0002, 447 }, + { 0x0000fb06, FC_CASE_FOLD_FULL, 0x0002, 449 }, + { 0x0000fb13, FC_CASE_FOLD_FULL, 0x0004, 451 }, + { 0x0000fb14, FC_CASE_FOLD_FULL, 0x0004, 455 }, + { 0x0000fb15, FC_CASE_FOLD_FULL, 0x0004, 459 }, + { 0x0000fb16, FC_CASE_FOLD_FULL, 0x0004, 463 }, + { 0x0000fb17, FC_CASE_FOLD_FULL, 0x0004, 467 }, + { 0x0000ff21, FC_CASE_FOLD_RANGE, 0x001a, 32 }, + { 0x00010400, FC_CASE_FOLD_RANGE, 0x0028, 40 }, +}; + +static const FcChar8 fcCaseFoldChars[FC_NUM_CASE_FOLD_CHARS] = { +0x73,0x73,0x69,0xcc,0x87,0xca,0xbc,0x6e,0x6a,0xcc,0x8c,0xce,0xb9,0xcc,0x88,0xcc, +0x81,0xcf,0x85,0xcc,0x88,0xcc,0x81,0xd5,0xa5,0xd6,0x82,0x68,0xcc,0xb1,0x74,0xcc, +0x88,0x77,0xcc,0x8a,0x79,0xcc,0x8a,0x61,0xca,0xbe,0x73,0x73,0xcf,0x85,0xcc,0x93, +0xcf,0x85,0xcc,0x93,0xcc,0x80,0xcf,0x85,0xcc,0x93,0xcc,0x81,0xcf,0x85,0xcc,0x93, +0xcd,0x82,0xe1,0xbc,0x80,0xce,0xb9,0xe1,0xbc,0x81,0xce,0xb9,0xe1,0xbc,0x82,0xce, +0xb9,0xe1,0xbc,0x83,0xce,0xb9,0xe1,0xbc,0x84,0xce,0xb9,0xe1,0xbc,0x85,0xce,0xb9, +0xe1,0xbc,0x86,0xce,0xb9,0xe1,0xbc,0x87,0xce,0xb9,0xe1,0xbc,0x80,0xce,0xb9,0xe1, +0xbc,0x81,0xce,0xb9,0xe1,0xbc,0x82,0xce,0xb9,0xe1,0xbc,0x83,0xce,0xb9,0xe1,0xbc, +0x84,0xce,0xb9,0xe1,0xbc,0x85,0xce,0xb9,0xe1,0xbc,0x86,0xce,0xb9,0xe1,0xbc,0x87, +0xce,0xb9,0xe1,0xbc,0xa0,0xce,0xb9,0xe1,0xbc,0xa1,0xce,0xb9,0xe1,0xbc,0xa2,0xce, +0xb9,0xe1,0xbc,0xa3,0xce,0xb9,0xe1,0xbc,0xa4,0xce,0xb9,0xe1,0xbc,0xa5,0xce,0xb9, +0xe1,0xbc,0xa6,0xce,0xb9,0xe1,0xbc,0xa7,0xce,0xb9,0xe1,0xbc,0xa0,0xce,0xb9,0xe1, +0xbc,0xa1,0xce,0xb9,0xe1,0xbc,0xa2,0xce,0xb9,0xe1,0xbc,0xa3,0xce,0xb9,0xe1,0xbc, +0xa4,0xce,0xb9,0xe1,0xbc,0xa5,0xce,0xb9,0xe1,0xbc,0xa6,0xce,0xb9,0xe1,0xbc,0xa7, +0xce,0xb9,0xe1,0xbd,0xa0,0xce,0xb9,0xe1,0xbd,0xa1,0xce,0xb9,0xe1,0xbd,0xa2,0xce, +0xb9,0xe1,0xbd,0xa3,0xce,0xb9,0xe1,0xbd,0xa4,0xce,0xb9,0xe1,0xbd,0xa5,0xce,0xb9, +0xe1,0xbd,0xa6,0xce,0xb9,0xe1,0xbd,0xa7,0xce,0xb9,0xe1,0xbd,0xa0,0xce,0xb9,0xe1, +0xbd,0xa1,0xce,0xb9,0xe1,0xbd,0xa2,0xce,0xb9,0xe1,0xbd,0xa3,0xce,0xb9,0xe1,0xbd, +0xa4,0xce,0xb9,0xe1,0xbd,0xa5,0xce,0xb9,0xe1,0xbd,0xa6,0xce,0xb9,0xe1,0xbd,0xa7, +0xce,0xb9,0xe1,0xbd,0xb0,0xce,0xb9,0xce,0xb1,0xce,0xb9,0xce,0xac,0xce,0xb9,0xce, +0xb1,0xcd,0x82,0xce,0xb1,0xcd,0x82,0xce,0xb9,0xce,0xb1,0xce,0xb9,0xe1,0xbd,0xb4, +0xce,0xb9,0xce,0xb7,0xce,0xb9,0xce,0xae,0xce,0xb9,0xce,0xb7,0xcd,0x82,0xce,0xb7, +0xcd,0x82,0xce,0xb9,0xce,0xb7,0xce,0xb9,0xce,0xb9,0xcc,0x88,0xcc,0x80,0xce,0xb9, +0xcc,0x88,0xcc,0x81,0xce,0xb9,0xcd,0x82,0xce,0xb9,0xcc,0x88,0xcd,0x82,0xcf,0x85, +0xcc,0x88,0xcc,0x80,0xcf,0x85,0xcc,0x88,0xcc,0x81,0xcf,0x81,0xcc,0x93,0xcf,0x85, +0xcd,0x82,0xcf,0x85,0xcc,0x88,0xcd,0x82,0xe1,0xbd,0xbc,0xce,0xb9,0xcf,0x89,0xce, +0xb9,0xcf,0x8e,0xce,0xb9,0xcf,0x89,0xcd,0x82,0xcf,0x89,0xcd,0x82,0xce,0xb9,0xcf, +0x89,0xce,0xb9,0x66,0x66,0x66,0x69,0x66,0x6c,0x66,0x66,0x69,0x66,0x66,0x6c,0x73, +0x74,0x73,0x74,0xd5,0xb4,0xd5,0xb6,0xd5,0xb4,0xd5,0xa5,0xd5,0xb4,0xd5,0xab,0xd5, +0xbe,0xd5,0xb6,0xd5,0xb4,0xd5,0xad +}; diff --git a/project/jni/fontconfig/fc-glyphname/fcglyphname.h b/project/jni/fontconfig/fc-glyphname/fcglyphname.h new file mode 100644 index 000000000..f9e5343ae --- /dev/null +++ b/project/jni/fontconfig/fc-glyphname/fcglyphname.h @@ -0,0 +1,781 @@ +/* + * fontconfig/fc-glyphname/fcglyphname.tmpl.h + * + * Copyright © 2003 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* 201 glyphnames in 271 entries, 74% occupancy */ + +#define FC_GLYPHNAME_HASH 271 +#define FC_GLYPHNAME_REHASH 269 +#define FC_GLYPHNAME_MAXLEN 4 + +typedef int16_t FcGlyphId; + +static const struct { const FcChar32 ucs; const FcChar8 name[5]; } _fc_glyph_names[201] = { + { 0x2701, "a1" }, + { 0x2721, "a10" }, + { 0x275e, "a100" }, + { 0x2761, "a101" }, + { 0x2762, "a102" }, + { 0x2763, "a103" }, + { 0x2764, "a104" }, + { 0x2710, "a105" }, + { 0x2765, "a106" }, + { 0x2766, "a107" }, + { 0x2767, "a108" }, + { 0x2660, "a109" }, + { 0x261b, "a11" }, + { 0x2665, "a110" }, + { 0x2666, "a111" }, + { 0x2663, "a112" }, + { 0x2709, "a117" }, + { 0x2708, "a118" }, + { 0x2707, "a119" }, + { 0x261e, "a12" }, + { 0x2460, "a120" }, + { 0x2461, "a121" }, + { 0x2462, "a122" }, + { 0x2463, "a123" }, + { 0x2464, "a124" }, + { 0x2465, "a125" }, + { 0x2466, "a126" }, + { 0x2467, "a127" }, + { 0x2468, "a128" }, + { 0x2469, "a129" }, + { 0x270c, "a13" }, + { 0x2776, "a130" }, + { 0x2777, "a131" }, + { 0x2778, "a132" }, + { 0x2779, "a133" }, + { 0x277a, "a134" }, + { 0x277b, "a135" }, + { 0x277c, "a136" }, + { 0x277d, "a137" }, + { 0x277e, "a138" }, + { 0x277f, "a139" }, + { 0x270d, "a14" }, + { 0x2780, "a140" }, + { 0x2781, "a141" }, + { 0x2782, "a142" }, + { 0x2783, "a143" }, + { 0x2784, "a144" }, + { 0x2785, "a145" }, + { 0x2786, "a146" }, + { 0x2787, "a147" }, + { 0x2788, "a148" }, + { 0x2789, "a149" }, + { 0x270e, "a15" }, + { 0x278a, "a150" }, + { 0x278b, "a151" }, + { 0x278c, "a152" }, + { 0x278d, "a153" }, + { 0x278e, "a154" }, + { 0x278f, "a155" }, + { 0x2790, "a156" }, + { 0x2791, "a157" }, + { 0x2792, "a158" }, + { 0x2793, "a159" }, + { 0x270f, "a16" }, + { 0x2794, "a160" }, + { 0x2192, "a161" }, + { 0x27a3, "a162" }, + { 0x2194, "a163" }, + { 0x2195, "a164" }, + { 0x2799, "a165" }, + { 0x279b, "a166" }, + { 0x279c, "a167" }, + { 0x279d, "a168" }, + { 0x279e, "a169" }, + { 0x2711, "a17" }, + { 0x279f, "a170" }, + { 0x27a0, "a171" }, + { 0x27a1, "a172" }, + { 0x27a2, "a173" }, + { 0x27a4, "a174" }, + { 0x27a5, "a175" }, + { 0x27a6, "a176" }, + { 0x27a7, "a177" }, + { 0x27a8, "a178" }, + { 0x27a9, "a179" }, + { 0x2712, "a18" }, + { 0x27ab, "a180" }, + { 0x27ad, "a181" }, + { 0x27af, "a182" }, + { 0x27b2, "a183" }, + { 0x27b3, "a184" }, + { 0x27b5, "a185" }, + { 0x27b8, "a186" }, + { 0x27ba, "a187" }, + { 0x27bb, "a188" }, + { 0x27bc, "a189" }, + { 0x2713, "a19" }, + { 0x27bd, "a190" }, + { 0x27be, "a191" }, + { 0x279a, "a192" }, + { 0x27aa, "a193" }, + { 0x27b6, "a194" }, + { 0x27b9, "a195" }, + { 0x2798, "a196" }, + { 0x27b4, "a197" }, + { 0x27b7, "a198" }, + { 0x27ac, "a199" }, + { 0x2702, "a2" }, + { 0x2714, "a20" }, + { 0x27ae, "a200" }, + { 0x27b1, "a201" }, + { 0x2703, "a202" }, + { 0x2750, "a203" }, + { 0x2752, "a204" }, + { 0x276e, "a205" }, + { 0x2770, "a206" }, + { 0x2715, "a21" }, + { 0x2716, "a22" }, + { 0x2717, "a23" }, + { 0x2718, "a24" }, + { 0x2719, "a25" }, + { 0x271a, "a26" }, + { 0x271b, "a27" }, + { 0x271c, "a28" }, + { 0x2722, "a29" }, + { 0x2704, "a3" }, + { 0x2723, "a30" }, + { 0x2724, "a31" }, + { 0x2725, "a32" }, + { 0x2726, "a33" }, + { 0x2727, "a34" }, + { 0x2605, "a35" }, + { 0x2729, "a36" }, + { 0x272a, "a37" }, + { 0x272b, "a38" }, + { 0x272c, "a39" }, + { 0x260e, "a4" }, + { 0x272d, "a40" }, + { 0x272e, "a41" }, + { 0x272f, "a42" }, + { 0x2730, "a43" }, + { 0x2731, "a44" }, + { 0x2732, "a45" }, + { 0x2733, "a46" }, + { 0x2734, "a47" }, + { 0x2735, "a48" }, + { 0x2736, "a49" }, + { 0x2706, "a5" }, + { 0x2737, "a50" }, + { 0x2738, "a51" }, + { 0x2739, "a52" }, + { 0x273a, "a53" }, + { 0x273b, "a54" }, + { 0x273c, "a55" }, + { 0x273d, "a56" }, + { 0x273e, "a57" }, + { 0x273f, "a58" }, + { 0x2740, "a59" }, + { 0x271d, "a6" }, + { 0x2741, "a60" }, + { 0x2742, "a61" }, + { 0x2743, "a62" }, + { 0x2744, "a63" }, + { 0x2745, "a64" }, + { 0x2746, "a65" }, + { 0x2747, "a66" }, + { 0x2748, "a67" }, + { 0x2749, "a68" }, + { 0x274a, "a69" }, + { 0x271e, "a7" }, + { 0x274b, "a70" }, + { 0x25cf, "a71" }, + { 0x274d, "a72" }, + { 0x25a0, "a73" }, + { 0x274f, "a74" }, + { 0x2751, "a75" }, + { 0x25b2, "a76" }, + { 0x25bc, "a77" }, + { 0x25c6, "a78" }, + { 0x2756, "a79" }, + { 0x271f, "a8" }, + { 0x25d7, "a81" }, + { 0x2758, "a82" }, + { 0x2759, "a83" }, + { 0x275a, "a84" }, + { 0x276f, "a85" }, + { 0x2771, "a86" }, + { 0x2772, "a87" }, + { 0x2773, "a88" }, + { 0x2768, "a89" }, + { 0x2720, "a9" }, + { 0x2769, "a90" }, + { 0x276c, "a91" }, + { 0x276d, "a92" }, + { 0x276a, "a93" }, + { 0x276b, "a94" }, + { 0x2774, "a95" }, + { 0x2775, "a96" }, + { 0x275b, "a97" }, + { 0x275c, "a98" }, + { 0x275d, "a99" }, +}; +static const FcGlyphId _fc_name_to_ucs[271] = { + 123, + 81, + 198, + 154, + 142, + 186, + 82, + -1, + 143, + 172, + 181, + 79, + 153, + 191, + -1, + -1, + 80, + 195, + 179, + 170, + 151, + 129, + 101, + 194, + 85, + 102, + 73, + 171, + 99, + -1, + -1, + 100, + 196, + -1, + 189, + 163, + 110, + 199, + -1, + -1, + 59, + 50, + -1, + 60, + 75, + -1, + 51, + -1, + -1, + 58, + -1, + 61, + 55, + -1, + 192, + 56, + 62, + -1, + 53, + 166, + 113, + 54, + -1, + 157, + 33, + 188, + 177, + 21, + -1, + -1, + 31, + -1, + -1, + 32, + -1, + -1, + 24, + 160, + -1, + 38, + -1, + -1, + 26, + -1, + 161, + 27, + 197, + 94, + 95, + 105, + 106, + 90, + 91, + 92, + 93, + 86, + 87, + 88, + 89, + 28, + 29, + 39, + 40, + 10, + 11, + 17, + 18, + 6, + 7, + 8, + 9, + 2, + 3, + 4, + 5, + -1, + -1, + 114, + 108, + 146, + 74, + -1, + 117, + 115, + 118, + 156, + 119, + -1, + 120, + -1, + 121, + 131, + 122, + -1, + 109, + -1, + 124, + 141, + 134, + 174, + 144, + -1, + 137, + 155, + 138, + -1, + 64, + -1, + 140, + 152, + 65, + -1, + 111, + -1, + 57, + 162, + -1, + -1, + 67, + -1, + -1, + 150, + 68, + -1, + 167, + -1, + 69, + 164, + -1, + 116, + 70, + -1, + -1, + 148, + 71, + -1, + -1, + 184, + 72, + 149, + 176, + 193, + 34, + 182, + 145, + -1, + 83, + 187, + -1, + 103, + 84, + 104, + 200, + 63, + 37, + 41, + 52, + 19, + 30, + 1, + 12, + 97, + 35, + 98, + 135, + 46, + 36, + 47, + 96, + 48, + 159, + 49, + -1, + 42, + 112, + 43, + 173, + 44, + 168, + 45, + -1, + 20, + 183, + 16, + 147, + 22, + 178, + 23, + -1, + 15, + -1, + 25, + 190, + 13, + 139, + 14, + -1, + -1, + -1, + 128, + 107, + 125, + -1, + 0, + 158, + 169, + 136, + 126, + -1, + -1, + 180, + 127, + 77, + -1, + -1, + 132, + -1, + 78, + -1, + 133, + -1, + 165, + 66, + 130, + -1, + -1, + -1, + 76, + -1, + 185, + 175, +}; +static const FcGlyphId _fc_ucs_to_name[271] = { + 56, + 135, + 19, + 138, + 58, + 140, + 59, + 142, + 60, + 144, + 61, + 146, + 62, + 149, + 64, + 151, + 152, + 153, + 154, + 155, + 156, + 157, + 159, + 160, + 161, + 162, + 163, + 131, + 165, + 166, + 167, + 168, + 170, + -1, + 172, + -1, + 174, + 112, + 175, + 113, + -1, + 173, + -1, + 179, + -1, + 182, + 183, + 158, + 198, + 199, + 200, + 2, + -1, + -1, + 3, + 4, + 5, + 6, + 8, + 9, + 10, + 189, + 164, + 194, + 195, + 192, + 193, + 114, + 11, + 115, + 186, + 15, + 188, + 13, + 14, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 53, + 54, + 55, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + -1, + 103, + 69, + 99, + 70, + 71, + 72, + 73, + 75, + 76, + 77, + 78, + 66, + 79, + 80, + 81, + 82, + 83, + 84, + 100, + 86, + 106, + 87, + 109, + 88, + -1, + 110, + 89, + 90, + 104, + 91, + 101, + 105, + 92, + 102, + 93, + 94, + 95, + 97, + 98, + 196, + -1, + 134, + -1, + -1, + -1, + -1, + -1, + 137, + -1, + -1, + -1, + -1, + -1, + 139, + -1, + -1, + 176, + -1, + -1, + 141, + 184, + -1, + -1, + -1, + -1, + 143, + 177, + 57, + -1, + -1, + -1, + 145, + -1, + -1, + -1, + -1, + 178, + 148, + -1, + -1, + -1, + -1, + -1, + 150, + 65, + 171, + 67, + 68, + -1, + -1, + 191, + -1, + -1, + 181, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + 185, + -1, + -1, + -1, + -1, + -1, + 187, + -1, + -1, + -1, + 133, + -1, + 197, + -1, + -1, + -1, + -1, + -1, + 0, + 107, + 111, + 125, + -1, + 147, + 18, + 17, + 16, + -1, + -1, + 30, + 41, + 52, + 63, + 7, + 74, + 85, + 96, + 108, + 116, + 117, + 118, + 119, + 120, + 121, + 122, + 123, + 136, + 169, + 180, + 190, + 1, + 124, + 126, + 127, + 128, + 129, + 130, + -1, + 132, + 12, +}; diff --git a/project/jni/fontconfig/fc-lang/fclang.h b/project/jni/fontconfig/fc-lang/fclang.h new file mode 100644 index 000000000..18ccf1e5b --- /dev/null +++ b/project/jni/fontconfig/fc-lang/fclang.h @@ -0,0 +1,4549 @@ +/* + * fontconfig/fc-lang/fclang.tmpl.h + * + * Copyright © 2002 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* total size: 1087 unique leaves: 702 */ + +#define LEAF0 (244 * sizeof (FcLangCharSet)) +#define OFF0 (LEAF0 + 702 * sizeof (FcCharLeaf)) +#define NUM0 (OFF0 + 755 * sizeof (uintptr_t)) +#define SET(n) (n * sizeof (FcLangCharSet) + offsetof (FcLangCharSet, charset)) +#define OFF(s,o) (OFF0 + o * sizeof (uintptr_t) - SET(s)) +#define NUM(s,n) (NUM0 + n * sizeof (FcChar16) - SET(s)) +#define LEAF(o,l) (LEAF0 + l * sizeof (FcCharLeaf) - (OFF0 + o * sizeof (intptr_t))) +#define fcLangCharSets (fcLangData.langCharSets) +#define fcLangCharSetIndices (fcLangData.langIndices) +#define fcLangCharSetIndicesInv (fcLangData.langIndicesInv) + +static const struct { + FcLangCharSet langCharSets[244]; + FcCharLeaf leaves[702]; + uintptr_t leaf_offsets[755]; + FcChar16 numbers[755]; + FcChar8 langIndices[244]; + FcChar8 langIndicesInv[244]; +} fcLangData = { +{ + { "aa", { FC_REF_CONSTANT, 1, OFF(0,0), NUM(0,0) } }, /* 0 */ + { "ab", { FC_REF_CONSTANT, 1, OFF(1,1), NUM(1,1) } }, /* 1 */ + { "af", { FC_REF_CONSTANT, 2, OFF(2,2), NUM(2,2) } }, /* 2 */ + { "ak", { FC_REF_CONSTANT, 5, OFF(3,4), NUM(3,4) } }, /* 3 */ + { "am", { FC_REF_CONSTANT, 2, OFF(4,9), NUM(4,9) } }, /* 4 */ + { "an", { FC_REF_CONSTANT, 1, OFF(5,11), NUM(5,11) } }, /* 5 */ + { "ar", { FC_REF_CONSTANT, 1, OFF(6,12), NUM(6,12) } }, /* 6 */ + { "as", { FC_REF_CONSTANT, 1, OFF(7,13), NUM(7,13) } }, /* 7 */ + { "ast", { FC_REF_CONSTANT, 2, OFF(8,14), NUM(8,14) } }, /* 8 */ + { "av", { FC_REF_CONSTANT, 1, OFF(9,16), NUM(9,16) } }, /* 9 */ + { "ay", { FC_REF_CONSTANT, 1, OFF(10,17), NUM(10,17) } }, /* 10 */ + { "az-az", { FC_REF_CONSTANT, 3, OFF(11,18), NUM(11,18) } }, /* 11 */ + { "az-ir", { FC_REF_CONSTANT, 1, OFF(12,21), NUM(12,21) } }, /* 12 */ + { "ba", { FC_REF_CONSTANT, 1, OFF(13,22), NUM(13,22) } }, /* 13 */ + { "be", { FC_REF_CONSTANT, 1, OFF(14,23), NUM(14,23) } }, /* 14 */ + { "ber-dz", { FC_REF_CONSTANT, 4, OFF(15,24), NUM(15,24) } }, /* 15 */ + { "ber-ma", { FC_REF_CONSTANT, 1, OFF(16,28), NUM(16,28) } }, /* 16 */ + { "bg", { FC_REF_CONSTANT, 1, OFF(17,29), NUM(17,29) } }, /* 17 */ + { "bh", { FC_REF_CONSTANT, 1, OFF(18,30), NUM(18,30) } }, /* 18 */ + { "bho", { FC_REF_CONSTANT, 1, OFF(19,30), NUM(19,30) } }, /* 19 */ + { "bi", { FC_REF_CONSTANT, 1, OFF(20,31), NUM(20,31) } }, /* 20 */ + { "bin", { FC_REF_CONSTANT, 3, OFF(21,32), NUM(21,32) } }, /* 21 */ + { "bm", { FC_REF_CONSTANT, 3, OFF(22,35), NUM(22,35) } }, /* 22 */ + { "bn", { FC_REF_CONSTANT, 1, OFF(23,38), NUM(23,38) } }, /* 23 */ + { "bo", { FC_REF_CONSTANT, 1, OFF(24,39), NUM(24,39) } }, /* 24 */ + { "br", { FC_REF_CONSTANT, 1, OFF(25,40), NUM(25,40) } }, /* 25 */ + { "brx", { FC_REF_CONSTANT, 1, OFF(26,41), NUM(26,41) } }, /* 26 */ + { "bs", { FC_REF_CONSTANT, 2, OFF(27,42), NUM(27,42) } }, /* 27 */ + { "bua", { FC_REF_CONSTANT, 1, OFF(28,44), NUM(28,44) } }, /* 28 */ + { "byn", { FC_REF_CONSTANT, 2, OFF(29,45), NUM(29,45) } }, /* 29 */ + { "ca", { FC_REF_CONSTANT, 2, OFF(30,47), NUM(30,47) } }, /* 30 */ + { "ce", { FC_REF_CONSTANT, 1, OFF(31,16), NUM(31,16) } }, /* 31 */ + { "ch", { FC_REF_CONSTANT, 1, OFF(32,49), NUM(32,49) } }, /* 32 */ + { "chm", { FC_REF_CONSTANT, 1, OFF(33,50), NUM(33,50) } }, /* 33 */ + { "chr", { FC_REF_CONSTANT, 1, OFF(34,51), NUM(34,51) } }, /* 34 */ + { "co", { FC_REF_CONSTANT, 2, OFF(35,52), NUM(35,52) } }, /* 35 */ + { "crh", { FC_REF_CONSTANT, 2, OFF(36,54), NUM(36,54) } }, /* 36 */ + { "cs", { FC_REF_CONSTANT, 2, OFF(37,56), NUM(37,56) } }, /* 37 */ + { "csb", { FC_REF_CONSTANT, 2, OFF(38,58), NUM(38,58) } }, /* 38 */ + { "cu", { FC_REF_CONSTANT, 1, OFF(39,60), NUM(39,60) } }, /* 39 */ + { "cv", { FC_REF_CONSTANT, 2, OFF(40,61), NUM(40,61) } }, /* 40 */ + { "cy", { FC_REF_CONSTANT, 3, OFF(41,63), NUM(41,63) } }, /* 41 */ + { "da", { FC_REF_CONSTANT, 1, OFF(42,66), NUM(42,66) } }, /* 42 */ + { "de", { FC_REF_CONSTANT, 1, OFF(43,67), NUM(43,67) } }, /* 43 */ + { "doi", { FC_REF_CONSTANT, 1, OFF(44,68), NUM(44,68) } }, /* 44 */ + { "dv", { FC_REF_CONSTANT, 1, OFF(45,69), NUM(45,69) } }, /* 45 */ + { "dz", { FC_REF_CONSTANT, 1, OFF(46,39), NUM(46,39) } }, /* 46 */ + { "ee", { FC_REF_CONSTANT, 4, OFF(47,70), NUM(47,70) } }, /* 47 */ + { "el", { FC_REF_CONSTANT, 1, OFF(48,74), NUM(48,74) } }, /* 48 */ + { "en", { FC_REF_CONSTANT, 1, OFF(49,75), NUM(49,75) } }, /* 49 */ + { "eo", { FC_REF_CONSTANT, 2, OFF(50,76), NUM(50,76) } }, /* 50 */ + { "es", { FC_REF_CONSTANT, 1, OFF(51,11), NUM(51,11) } }, /* 51 */ + { "et", { FC_REF_CONSTANT, 2, OFF(52,78), NUM(52,78) } }, /* 52 */ + { "eu", { FC_REF_CONSTANT, 1, OFF(53,80), NUM(53,80) } }, /* 53 */ + { "fa", { FC_REF_CONSTANT, 1, OFF(54,21), NUM(54,21) } }, /* 54 */ + { "fat", { FC_REF_CONSTANT, 5, OFF(55,4), NUM(55,4) } }, /* 55 */ + { "ff", { FC_REF_CONSTANT, 3, OFF(56,81), NUM(56,81) } }, /* 56 */ + { "fi", { FC_REF_CONSTANT, 2, OFF(57,84), NUM(57,84) } }, /* 57 */ + { "fil", { FC_REF_CONSTANT, 1, OFF(58,86), NUM(58,86) } }, /* 58 */ + { "fj", { FC_REF_CONSTANT, 1, OFF(59,87), NUM(59,87) } }, /* 59 */ + { "fo", { FC_REF_CONSTANT, 1, OFF(60,88), NUM(60,88) } }, /* 60 */ + { "fr", { FC_REF_CONSTANT, 2, OFF(61,52), NUM(61,52) } }, /* 61 */ + { "fur", { FC_REF_CONSTANT, 1, OFF(62,89), NUM(62,89) } }, /* 62 */ + { "fy", { FC_REF_CONSTANT, 1, OFF(63,90), NUM(63,90) } }, /* 63 */ + { "ga", { FC_REF_CONSTANT, 3, OFF(64,91), NUM(64,91) } }, /* 64 */ + { "gd", { FC_REF_CONSTANT, 1, OFF(65,94), NUM(65,94) } }, /* 65 */ + { "gez", { FC_REF_CONSTANT, 2, OFF(66,95), NUM(66,95) } }, /* 66 */ + { "gl", { FC_REF_CONSTANT, 1, OFF(67,11), NUM(67,11) } }, /* 67 */ + { "gn", { FC_REF_CONSTANT, 3, OFF(68,97), NUM(68,97) } }, /* 68 */ + { "gu", { FC_REF_CONSTANT, 1, OFF(69,100), NUM(69,100) } }, /* 69 */ + { "gv", { FC_REF_CONSTANT, 1, OFF(70,101), NUM(70,101) } }, /* 70 */ + { "ha", { FC_REF_CONSTANT, 3, OFF(71,102), NUM(71,102) } }, /* 71 */ + { "haw", { FC_REF_CONSTANT, 3, OFF(72,105), NUM(72,105) } }, /* 72 */ + { "he", { FC_REF_CONSTANT, 1, OFF(73,108), NUM(73,108) } }, /* 73 */ + { "hi", { FC_REF_CONSTANT, 1, OFF(74,30), NUM(74,30) } }, /* 74 */ + { "hne", { FC_REF_CONSTANT, 1, OFF(75,30), NUM(75,30) } }, /* 75 */ + { "ho", { FC_REF_CONSTANT, 1, OFF(76,87), NUM(76,87) } }, /* 76 */ + { "hr", { FC_REF_CONSTANT, 2, OFF(77,42), NUM(77,42) } }, /* 77 */ + { "hsb", { FC_REF_CONSTANT, 2, OFF(78,109), NUM(78,109) } }, /* 78 */ + { "ht", { FC_REF_CONSTANT, 1, OFF(79,111), NUM(79,111) } }, /* 79 */ + { "hu", { FC_REF_CONSTANT, 2, OFF(80,112), NUM(80,112) } }, /* 80 */ + { "hy", { FC_REF_CONSTANT, 1, OFF(81,114), NUM(81,114) } }, /* 81 */ + { "hz", { FC_REF_CONSTANT, 3, OFF(82,115), NUM(82,115) } }, /* 82 */ + { "ia", { FC_REF_CONSTANT, 1, OFF(83,87), NUM(83,87) } }, /* 83 */ + { "id", { FC_REF_CONSTANT, 1, OFF(84,118), NUM(84,118) } }, /* 84 */ + { "ie", { FC_REF_CONSTANT, 1, OFF(85,87), NUM(85,87) } }, /* 85 */ + { "ig", { FC_REF_CONSTANT, 2, OFF(86,119), NUM(86,119) } }, /* 86 */ + { "ii", { FC_REF_CONSTANT, 5, OFF(87,121), NUM(87,121) } }, /* 87 */ + { "ik", { FC_REF_CONSTANT, 1, OFF(88,126), NUM(88,126) } }, /* 88 */ + { "io", { FC_REF_CONSTANT, 1, OFF(89,87), NUM(89,87) } }, /* 89 */ + { "is", { FC_REF_CONSTANT, 1, OFF(90,127), NUM(90,127) } }, /* 90 */ + { "it", { FC_REF_CONSTANT, 1, OFF(91,128), NUM(91,128) } }, /* 91 */ + { "iu", { FC_REF_CONSTANT, 3, OFF(92,129), NUM(92,129) } }, /* 92 */ + { "ja", { FC_REF_CONSTANT, 83, OFF(93,132), NUM(93,132) } }, /* 93 */ + { "jv", { FC_REF_CONSTANT, 1, OFF(94,215), NUM(94,215) } }, /* 94 */ + { "ka", { FC_REF_CONSTANT, 1, OFF(95,216), NUM(95,216) } }, /* 95 */ + { "kaa", { FC_REF_CONSTANT, 1, OFF(96,217), NUM(96,217) } }, /* 96 */ + { "kab", { FC_REF_CONSTANT, 4, OFF(97,24), NUM(97,24) } }, /* 97 */ + { "ki", { FC_REF_CONSTANT, 2, OFF(98,218), NUM(98,218) } }, /* 98 */ + { "kj", { FC_REF_CONSTANT, 1, OFF(99,87), NUM(99,87) } }, /* 99 */ + { "kk", { FC_REF_CONSTANT, 1, OFF(100,220), NUM(100,220) } }, /* 100 */ + { "kl", { FC_REF_CONSTANT, 2, OFF(101,221), NUM(101,221) } }, /* 101 */ + { "km", { FC_REF_CONSTANT, 1, OFF(102,223), NUM(102,223) } }, /* 102 */ + { "kn", { FC_REF_CONSTANT, 1, OFF(103,224), NUM(103,224) } }, /* 103 */ + { "ko", { FC_REF_CONSTANT, 45, OFF(104,225), NUM(104,225) } }, /* 104 */ + { "kok", { FC_REF_CONSTANT, 1, OFF(105,30), NUM(105,30) } }, /* 105 */ + { "kr", { FC_REF_CONSTANT, 3, OFF(106,270), NUM(106,270) } }, /* 106 */ + { "ks", { FC_REF_CONSTANT, 1, OFF(107,273), NUM(107,273) } }, /* 107 */ + { "ku-am", { FC_REF_CONSTANT, 2, OFF(108,274), NUM(108,274) } }, /* 108 */ + { "ku-iq", { FC_REF_CONSTANT, 1, OFF(109,276), NUM(109,276) } }, /* 109 */ + { "ku-ir", { FC_REF_CONSTANT, 1, OFF(110,276), NUM(110,276) } }, /* 110 */ + { "ku-tr", { FC_REF_CONSTANT, 2, OFF(111,277), NUM(111,277) } }, /* 111 */ + { "kum", { FC_REF_CONSTANT, 1, OFF(112,279), NUM(112,279) } }, /* 112 */ + { "kv", { FC_REF_CONSTANT, 1, OFF(113,280), NUM(113,280) } }, /* 113 */ + { "kw", { FC_REF_CONSTANT, 3, OFF(114,281), NUM(114,281) } }, /* 114 */ + { "kwm", { FC_REF_CONSTANT, 1, OFF(115,87), NUM(115,87) } }, /* 115 */ + { "ky", { FC_REF_CONSTANT, 1, OFF(116,284), NUM(116,284) } }, /* 116 */ + { "la", { FC_REF_CONSTANT, 2, OFF(117,285), NUM(117,285) } }, /* 117 */ + { "lah", { FC_REF_CONSTANT, 1, OFF(118,287), NUM(118,287) } }, /* 118 */ + { "lb", { FC_REF_CONSTANT, 1, OFF(119,288), NUM(119,288) } }, /* 119 */ + { "lez", { FC_REF_CONSTANT, 1, OFF(120,16), NUM(120,16) } }, /* 120 */ + { "lg", { FC_REF_CONSTANT, 2, OFF(121,289), NUM(121,289) } }, /* 121 */ + { "li", { FC_REF_CONSTANT, 1, OFF(122,291), NUM(122,291) } }, /* 122 */ + { "ln", { FC_REF_CONSTANT, 4, OFF(123,292), NUM(123,292) } }, /* 123 */ + { "lo", { FC_REF_CONSTANT, 1, OFF(124,296), NUM(124,296) } }, /* 124 */ + { "lt", { FC_REF_CONSTANT, 2, OFF(125,297), NUM(125,297) } }, /* 125 */ + { "lv", { FC_REF_CONSTANT, 2, OFF(126,299), NUM(126,299) } }, /* 126 */ + { "mai", { FC_REF_CONSTANT, 1, OFF(127,30), NUM(127,30) } }, /* 127 */ + { "mg", { FC_REF_CONSTANT, 1, OFF(128,301), NUM(128,301) } }, /* 128 */ + { "mh", { FC_REF_CONSTANT, 2, OFF(129,302), NUM(129,302) } }, /* 129 */ + { "mi", { FC_REF_CONSTANT, 3, OFF(130,304), NUM(130,304) } }, /* 130 */ + { "mk", { FC_REF_CONSTANT, 1, OFF(131,307), NUM(131,307) } }, /* 131 */ + { "ml", { FC_REF_CONSTANT, 1, OFF(132,308), NUM(132,308) } }, /* 132 */ + { "mn-cn", { FC_REF_CONSTANT, 1, OFF(133,309), NUM(133,309) } }, /* 133 */ + { "mn-mn", { FC_REF_CONSTANT, 1, OFF(134,310), NUM(134,310) } }, /* 134 */ + { "mni", { FC_REF_CONSTANT, 1, OFF(135,311), NUM(135,311) } }, /* 135 */ + { "mo", { FC_REF_CONSTANT, 4, OFF(136,312), NUM(136,312) } }, /* 136 */ + { "mr", { FC_REF_CONSTANT, 1, OFF(137,30), NUM(137,30) } }, /* 137 */ + { "ms", { FC_REF_CONSTANT, 1, OFF(138,87), NUM(138,87) } }, /* 138 */ + { "mt", { FC_REF_CONSTANT, 2, OFF(139,316), NUM(139,316) } }, /* 139 */ + { "my", { FC_REF_CONSTANT, 1, OFF(140,318), NUM(140,318) } }, /* 140 */ + { "na", { FC_REF_CONSTANT, 2, OFF(141,319), NUM(141,319) } }, /* 141 */ + { "nb", { FC_REF_CONSTANT, 1, OFF(142,321), NUM(142,321) } }, /* 142 */ + { "nds", { FC_REF_CONSTANT, 1, OFF(143,67), NUM(143,67) } }, /* 143 */ + { "ne", { FC_REF_CONSTANT, 1, OFF(144,322), NUM(144,322) } }, /* 144 */ + { "ng", { FC_REF_CONSTANT, 1, OFF(145,87), NUM(145,87) } }, /* 145 */ + { "nl", { FC_REF_CONSTANT, 1, OFF(146,323), NUM(146,323) } }, /* 146 */ + { "nn", { FC_REF_CONSTANT, 1, OFF(147,324), NUM(147,324) } }, /* 147 */ + { "no", { FC_REF_CONSTANT, 1, OFF(148,321), NUM(148,321) } }, /* 148 */ + { "nqo", { FC_REF_CONSTANT, 1, OFF(149,325), NUM(149,325) } }, /* 149 */ + { "nr", { FC_REF_CONSTANT, 1, OFF(150,87), NUM(150,87) } }, /* 150 */ + { "nso", { FC_REF_CONSTANT, 2, OFF(151,326), NUM(151,326) } }, /* 151 */ + { "nv", { FC_REF_CONSTANT, 4, OFF(152,328), NUM(152,328) } }, /* 152 */ + { "ny", { FC_REF_CONSTANT, 2, OFF(153,332), NUM(153,332) } }, /* 153 */ + { "oc", { FC_REF_CONSTANT, 1, OFF(154,334), NUM(154,334) } }, /* 154 */ + { "om", { FC_REF_CONSTANT, 1, OFF(155,87), NUM(155,87) } }, /* 155 */ + { "or", { FC_REF_CONSTANT, 1, OFF(156,335), NUM(156,335) } }, /* 156 */ + { "os", { FC_REF_CONSTANT, 1, OFF(157,279), NUM(157,279) } }, /* 157 */ + { "ota", { FC_REF_CONSTANT, 1, OFF(158,336), NUM(158,336) } }, /* 158 */ + { "pa", { FC_REF_CONSTANT, 1, OFF(159,337), NUM(159,337) } }, /* 159 */ + { "pa-pk", { FC_REF_CONSTANT, 1, OFF(160,287), NUM(160,287) } }, /* 160 */ + { "pap-an", { FC_REF_CONSTANT, 1, OFF(161,338), NUM(161,338) } }, /* 161 */ + { "pap-aw", { FC_REF_CONSTANT, 1, OFF(162,339), NUM(162,339) } }, /* 162 */ + { "pl", { FC_REF_CONSTANT, 2, OFF(163,340), NUM(163,340) } }, /* 163 */ + { "ps-af", { FC_REF_CONSTANT, 1, OFF(164,342), NUM(164,342) } }, /* 164 */ + { "ps-pk", { FC_REF_CONSTANT, 1, OFF(165,343), NUM(165,343) } }, /* 165 */ + { "pt", { FC_REF_CONSTANT, 1, OFF(166,344), NUM(166,344) } }, /* 166 */ + { "qu", { FC_REF_CONSTANT, 2, OFF(167,345), NUM(167,345) } }, /* 167 */ + { "quz", { FC_REF_CONSTANT, 2, OFF(168,345), NUM(168,345) } }, /* 168 */ + { "rm", { FC_REF_CONSTANT, 1, OFF(169,347), NUM(169,347) } }, /* 169 */ + { "rn", { FC_REF_CONSTANT, 1, OFF(170,87), NUM(170,87) } }, /* 170 */ + { "ro", { FC_REF_CONSTANT, 3, OFF(171,348), NUM(171,348) } }, /* 171 */ + { "ru", { FC_REF_CONSTANT, 1, OFF(172,279), NUM(172,279) } }, /* 172 */ + { "rw", { FC_REF_CONSTANT, 1, OFF(173,87), NUM(173,87) } }, /* 173 */ + { "sa", { FC_REF_CONSTANT, 1, OFF(174,30), NUM(174,30) } }, /* 174 */ + { "sah", { FC_REF_CONSTANT, 1, OFF(175,351), NUM(175,351) } }, /* 175 */ + { "sat", { FC_REF_CONSTANT, 1, OFF(176,352), NUM(176,352) } }, /* 176 */ + { "sc", { FC_REF_CONSTANT, 1, OFF(177,353), NUM(177,353) } }, /* 177 */ + { "sco", { FC_REF_CONSTANT, 3, OFF(178,354), NUM(178,354) } }, /* 178 */ + { "sd", { FC_REF_CONSTANT, 1, OFF(179,357), NUM(179,357) } }, /* 179 */ + { "se", { FC_REF_CONSTANT, 2, OFF(180,358), NUM(180,358) } }, /* 180 */ + { "sel", { FC_REF_CONSTANT, 1, OFF(181,279), NUM(181,279) } }, /* 181 */ + { "sg", { FC_REF_CONSTANT, 1, OFF(182,360), NUM(182,360) } }, /* 182 */ + { "sh", { FC_REF_CONSTANT, 3, OFF(183,361), NUM(183,361) } }, /* 183 */ + { "shs", { FC_REF_CONSTANT, 2, OFF(184,364), NUM(184,364) } }, /* 184 */ + { "si", { FC_REF_CONSTANT, 1, OFF(185,366), NUM(185,366) } }, /* 185 */ + { "sid", { FC_REF_CONSTANT, 2, OFF(186,367), NUM(186,367) } }, /* 186 */ + { "sk", { FC_REF_CONSTANT, 2, OFF(187,369), NUM(187,369) } }, /* 187 */ + { "sl", { FC_REF_CONSTANT, 2, OFF(188,42), NUM(188,42) } }, /* 188 */ + { "sm", { FC_REF_CONSTANT, 2, OFF(189,371), NUM(189,371) } }, /* 189 */ + { "sma", { FC_REF_CONSTANT, 1, OFF(190,373), NUM(190,373) } }, /* 190 */ + { "smj", { FC_REF_CONSTANT, 1, OFF(191,374), NUM(191,374) } }, /* 191 */ + { "smn", { FC_REF_CONSTANT, 2, OFF(192,375), NUM(192,375) } }, /* 192 */ + { "sms", { FC_REF_CONSTANT, 3, OFF(193,377), NUM(193,377) } }, /* 193 */ + { "sn", { FC_REF_CONSTANT, 1, OFF(194,87), NUM(194,87) } }, /* 194 */ + { "so", { FC_REF_CONSTANT, 1, OFF(195,87), NUM(195,87) } }, /* 195 */ + { "sq", { FC_REF_CONSTANT, 1, OFF(196,380), NUM(196,380) } }, /* 196 */ + { "sr", { FC_REF_CONSTANT, 1, OFF(197,381), NUM(197,381) } }, /* 197 */ + { "ss", { FC_REF_CONSTANT, 1, OFF(198,87), NUM(198,87) } }, /* 198 */ + { "st", { FC_REF_CONSTANT, 1, OFF(199,87), NUM(199,87) } }, /* 199 */ + { "su", { FC_REF_CONSTANT, 1, OFF(200,118), NUM(200,118) } }, /* 200 */ + { "sv", { FC_REF_CONSTANT, 1, OFF(201,382), NUM(201,382) } }, /* 201 */ + { "sw", { FC_REF_CONSTANT, 1, OFF(202,87), NUM(202,87) } }, /* 202 */ + { "syr", { FC_REF_CONSTANT, 1, OFF(203,383), NUM(203,383) } }, /* 203 */ + { "ta", { FC_REF_CONSTANT, 1, OFF(204,384), NUM(204,384) } }, /* 204 */ + { "te", { FC_REF_CONSTANT, 1, OFF(205,385), NUM(205,385) } }, /* 205 */ + { "tg", { FC_REF_CONSTANT, 1, OFF(206,386), NUM(206,386) } }, /* 206 */ + { "th", { FC_REF_CONSTANT, 1, OFF(207,387), NUM(207,387) } }, /* 207 */ + { "ti-er", { FC_REF_CONSTANT, 2, OFF(208,45), NUM(208,45) } }, /* 208 */ + { "ti-et", { FC_REF_CONSTANT, 2, OFF(209,367), NUM(209,367) } }, /* 209 */ + { "tig", { FC_REF_CONSTANT, 2, OFF(210,388), NUM(210,388) } }, /* 210 */ + { "tk", { FC_REF_CONSTANT, 2, OFF(211,390), NUM(211,390) } }, /* 211 */ + { "tl", { FC_REF_CONSTANT, 1, OFF(212,86), NUM(212,86) } }, /* 212 */ + { "tn", { FC_REF_CONSTANT, 2, OFF(213,326), NUM(213,326) } }, /* 213 */ + { "to", { FC_REF_CONSTANT, 2, OFF(214,371), NUM(214,371) } }, /* 214 */ + { "tr", { FC_REF_CONSTANT, 2, OFF(215,392), NUM(215,392) } }, /* 215 */ + { "ts", { FC_REF_CONSTANT, 1, OFF(216,87), NUM(216,87) } }, /* 216 */ + { "tt", { FC_REF_CONSTANT, 1, OFF(217,394), NUM(217,394) } }, /* 217 */ + { "tw", { FC_REF_CONSTANT, 5, OFF(218,4), NUM(218,4) } }, /* 218 */ + { "ty", { FC_REF_CONSTANT, 3, OFF(219,395), NUM(219,395) } }, /* 219 */ + { "tyv", { FC_REF_CONSTANT, 1, OFF(220,284), NUM(220,284) } }, /* 220 */ + { "ug", { FC_REF_CONSTANT, 1, OFF(221,398), NUM(221,398) } }, /* 221 */ + { "uk", { FC_REF_CONSTANT, 1, OFF(222,399), NUM(222,399) } }, /* 222 */ + { "ur", { FC_REF_CONSTANT, 1, OFF(223,287), NUM(223,287) } }, /* 223 */ + { "uz", { FC_REF_CONSTANT, 1, OFF(224,87), NUM(224,87) } }, /* 224 */ + { "ve", { FC_REF_CONSTANT, 2, OFF(225,400), NUM(225,400) } }, /* 225 */ + { "vi", { FC_REF_CONSTANT, 4, OFF(226,402), NUM(226,402) } }, /* 226 */ + { "vo", { FC_REF_CONSTANT, 1, OFF(227,406), NUM(227,406) } }, /* 227 */ + { "vot", { FC_REF_CONSTANT, 2, OFF(228,407), NUM(228,407) } }, /* 228 */ + { "wa", { FC_REF_CONSTANT, 1, OFF(229,409), NUM(229,409) } }, /* 229 */ + { "wal", { FC_REF_CONSTANT, 2, OFF(230,367), NUM(230,367) } }, /* 230 */ + { "wen", { FC_REF_CONSTANT, 2, OFF(231,410), NUM(231,410) } }, /* 231 */ + { "wo", { FC_REF_CONSTANT, 2, OFF(232,412), NUM(232,412) } }, /* 232 */ + { "xh", { FC_REF_CONSTANT, 1, OFF(233,87), NUM(233,87) } }, /* 233 */ + { "yap", { FC_REF_CONSTANT, 1, OFF(234,414), NUM(234,414) } }, /* 234 */ + { "yi", { FC_REF_CONSTANT, 1, OFF(235,108), NUM(235,108) } }, /* 235 */ + { "yo", { FC_REF_CONSTANT, 4, OFF(236,415), NUM(236,415) } }, /* 236 */ + { "za", { FC_REF_CONSTANT, 1, OFF(237,87), NUM(237,87) } }, /* 237 */ + { "zh-cn", { FC_REF_CONSTANT, 82, OFF(238,419), NUM(238,419) } }, /* 238 */ + { "zh-hk", { FC_REF_CONSTANT, 171, OFF(239,501), NUM(239,501) } }, /* 239 */ + { "zh-mo", { FC_REF_CONSTANT, 171, OFF(240,501), NUM(240,501) } }, /* 240 */ + { "zh-sg", { FC_REF_CONSTANT, 82, OFF(241,419), NUM(241,419) } }, /* 241 */ + { "zh-tw", { FC_REF_CONSTANT, 83, OFF(242,672), NUM(242,672) } }, /* 242 */ + { "zu", { FC_REF_CONSTANT, 1, OFF(243,87), NUM(243,87) } }, /* 243 */ +}, +{ + { { /* 0 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x08104404, 0x08104404, + } }, + { { /* 1 */ + 0xffff8002, 0xffffffff, 0x8002ffff, 0x00000000, + 0xc0000000, 0xf0fc33c0, 0x03000000, 0x00000003, + } }, + { { /* 2 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x0810cf00, 0x0810cf00, + } }, + { { /* 3 */ + 0x00000000, 0x00000000, 0x00000200, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 4 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00220008, 0x00220008, + } }, + { { /* 5 */ + 0x00000000, 0x00000300, 0x00000000, 0x00000300, + 0x00010040, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 6 */ + 0x00000000, 0x00000000, 0x08100000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 7 */ + 0x00000048, 0x00000200, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 8 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x30000000, 0x00000000, 0x03000000, + } }, + { { /* 9 */ + 0xff7fff7f, 0xff01ff7f, 0x00003d7f, 0xffff7fff, + 0xffff3d7f, 0x003d7fff, 0xff7f7f00, 0x00ff7fff, + } }, + { { /* 10 */ + 0x003d7fff, 0xffffffff, 0x007fff7f, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 11 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x140a2202, 0x140a2202, + } }, + { { /* 12 */ + 0x00000000, 0x07fffffe, 0x000007fe, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 13 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xfff99fee, 0xd3c4fdff, 0xb000399f, 0x00030000, + } }, + { { /* 14 */ + 0x00000000, 0x00c00030, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 15 */ + 0xffff0042, 0xffffffff, 0x0002ffff, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 16 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x10028010, 0x10028010, + } }, + { { /* 17 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x10400080, 0x10400080, + } }, + { { /* 18 */ + 0xc0000000, 0x00030000, 0xc0000000, 0x00000000, + 0x00008000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 19 */ + 0x00000000, 0x00000000, 0x02000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 20 */ + 0x00000000, 0x07ffffde, 0x001009f6, 0x40000000, + 0x01000040, 0x00008200, 0x00001000, 0x00000000, + } }, + { { /* 21 */ + 0xffff0000, 0xffffffff, 0x0000ffff, 0x00000000, + 0x030c0000, 0x0c00cc0f, 0x03000000, 0x00000300, + } }, + { { /* 22 */ + 0xffff4040, 0xffffffff, 0x4040ffff, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 23 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 24 */ + 0x00003000, 0x00000000, 0x00000000, 0x00000000, + 0x00110000, 0x00000000, 0x00000000, 0x000000c0, + } }, + { { /* 25 */ + 0x00000000, 0x00000000, 0x08000000, 0x00000008, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 26 */ + 0x00003000, 0x00000030, 0x00000000, 0x0000300c, + 0x000c0000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 27 */ + 0x00000000, 0x3a8b0000, 0x9e78e6b9, 0x0000802e, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 28 */ + 0xffff0000, 0xffffd7ff, 0x0000d7ff, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 29 */ + 0xffffffe0, 0x83ffffff, 0x00003fff, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 30 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x10008200, 0x10008200, + } }, + { { /* 31 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x060c3303, 0x060c3303, + } }, + { { /* 32 */ + 0x00000003, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 33 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x03000000, 0x00003000, 0x00000000, + } }, + { { /* 34 */ + 0x00000000, 0x00000000, 0x00000c00, 0x00000000, + 0x20010040, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 35 */ + 0x00000000, 0x00000000, 0x08100000, 0x00040000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 36 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xfff99fee, 0xd3c5fdff, 0xb000399f, 0x00000000, + } }, + { { /* 37 */ + 0x00000000, 0x00000000, 0xfffffeff, 0x3d7e03ff, + 0xfeff0003, 0x03ffffff, 0x00000000, 0x00000000, + } }, + { { /* 38 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x12120404, 0x12120404, + } }, + { { /* 39 */ + 0xfff99fee, 0xf3e5fdff, 0x0007399f, 0x0001ffff, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 40 */ + 0x000330c0, 0x00000000, 0x00000000, 0x60000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 41 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x00000000, 0x0c00c000, 0x00000000, 0x00000000, + } }, + { { /* 42 */ + 0xff7fff7f, 0xff01ff00, 0x3d7f3d7f, 0xffff7fff, + 0xffff0000, 0x003d7fff, 0xff7f7f3d, 0x00ff7fff, + } }, + { { /* 43 */ + 0x003d7fff, 0xffffffff, 0x007fff00, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 44 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x140ca381, 0x140ca381, + } }, + { { /* 45 */ + 0x00000000, 0x80000000, 0x00000001, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 46 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x10020004, 0x10020004, + } }, + { { /* 47 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x00000000, 0x00000030, 0x000c0000, 0x030300c0, + } }, + { { /* 48 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0xffffffff, 0xffffffff, 0x001fffff, + } }, + { { /* 49 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x1a10cfc5, 0x9a10cfc5, + } }, + { { /* 50 */ + 0x00000000, 0x00000000, 0x000c0000, 0x01000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 51 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x10420084, 0x10420084, + } }, + { { /* 52 */ + 0xc0000000, 0x00030000, 0xc0000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 53 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x24082202, 0x24082202, + } }, + { { /* 54 */ + 0x0c00f000, 0x00000000, 0x03000180, 0x6000c033, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 55 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x021c0a08, 0x021c0a08, + } }, + { { /* 56 */ + 0x00000030, 0x00000000, 0x0000001e, 0x18000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 57 */ + 0xfdffa966, 0xffffdfff, 0xa965dfff, 0x03ffffff, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 58 */ + 0x0000000c, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 59 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x00000000, 0x00000c00, 0x00c00000, 0x000c0000, + } }, + { { /* 60 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x0010c604, 0x8010c604, + } }, + { { /* 61 */ + 0x00000000, 0x00000000, 0x00000000, 0x01f00000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 62 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x0000003f, 0x00000000, 0x00000000, 0x000c0000, + } }, + { { /* 63 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x25082262, 0x25082262, + } }, + { { /* 64 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x90400010, 0x10400010, + } }, + { { /* 65 */ + 0xfff99fec, 0xf3e5fdff, 0xf807399f, 0x0000ffff, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 66 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xffffffff, 0x0001ffff, 0x00000000, 0x00000000, + } }, + { { /* 67 */ + 0x0c000000, 0x00000000, 0x00000c00, 0x00000000, + 0x00170240, 0x00040000, 0x001fe000, 0x00000000, + } }, + { { /* 68 */ + 0x00000000, 0x00000000, 0x08500000, 0x00000008, + 0x00000800, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 69 */ + 0x00001003, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 70 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xffffd740, 0xfffffffb, 0x00007fff, 0x00000000, + } }, + { { /* 71 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00528f81, 0x00528f81, + } }, + { { /* 72 */ + 0x30000300, 0x00300030, 0x30000000, 0x00003000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 73 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x10600010, 0x10600010, + } }, + { { /* 74 */ + 0x00000000, 0x00000000, 0x00000000, 0x60000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 75 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x10020000, 0x10020000, + } }, + { { /* 76 */ + 0x00000000, 0x00000000, 0x00000c00, 0x00000000, + 0x20000402, 0x00180000, 0x00000000, 0x00000000, + } }, + { { /* 77 */ + 0x00000000, 0x00000000, 0x00880000, 0x00040000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 78 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00400030, 0x00400030, + } }, + { { /* 79 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x0e1e7707, 0x0e1e7707, + } }, + { { /* 80 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x25092042, 0x25092042, + } }, + { { /* 81 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x02041107, 0x02041107, + } }, + { { /* 82 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x9c508e14, 0x1c508e14, + } }, + { { /* 83 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x04082202, 0x04082202, + } }, + { { /* 84 */ + 0x00000c00, 0x00000003, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 85 */ + 0xc0000c0c, 0x00000000, 0x00c00003, 0x00000c03, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 86 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x020c1383, 0x020c1383, + } }, + { { /* 87 */ + 0xff7fff7f, 0xff01ff7f, 0x00003d7f, 0x00ff00ff, + 0x00ff3d7f, 0x003d7fff, 0xff7f7f00, 0x00ff7f00, + } }, + { { /* 88 */ + 0x003d7f00, 0xffff01ff, 0x007fff7f, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 89 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x040a2202, 0x042a220a, + } }, + { { /* 90 */ + 0x00000000, 0x00000200, 0x00000000, 0x00000200, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 91 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x20000000, 0x00000000, 0x02000000, + } }, + { { /* 92 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xfffbafee, 0xf3edfdff, 0x00013bbf, 0x00000001, + } }, + { { /* 93 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00000080, 0x00000080, + } }, + { { /* 94 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03000402, 0x00180000, 0x00000000, 0x00000000, + } }, + { { /* 95 */ + 0x00000000, 0x00000000, 0x00880000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 96 */ + 0x000c0003, 0x00000c00, 0x00003000, 0x00000c00, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 97 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x08000000, 0x00000000, 0x00000000, + } }, + { { /* 98 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0xffff0000, 0x000007ff, + } }, + { { /* 99 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00080000, 0x00080000, + } }, + { { /* 100 */ + 0x0c0030c0, 0x00000000, 0x0300001e, 0x66000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 101 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00040100, 0x00040100, + } }, + { { /* 102 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x14482202, 0x14482202, + } }, + { { /* 103 */ + 0x00000000, 0x00000000, 0x00030000, 0x00030000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 104 */ + 0x00000000, 0xfffe0000, 0x007fffff, 0xfffffffe, + 0x000000ff, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 105 */ + 0x00000000, 0x00008000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 106 */ + 0x000c0000, 0x00000000, 0x00000c00, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 107 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00000200, 0x00000200, + } }, + { { /* 108 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00003c00, 0x00000030, + } }, + { { /* 109 */ + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + } }, + { { /* 110 */ + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0x00001fff, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 111 */ + 0xffff4002, 0xffffffff, 0x4002ffff, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 112 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x64092242, 0x64092242, + } }, + { { /* 113 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x060cb301, 0x060cb301, + } }, + { { /* 114 */ + 0x00000c7e, 0x031f8000, 0x0063f200, 0x000df840, + 0x00037e08, 0x08000dfa, 0x0df901bf, 0x5437e400, + } }, + { { /* 115 */ + 0x00000025, 0x40006fc0, 0x27f91be4, 0xdee00000, + 0x007ff83f, 0x00007f7f, 0x00000000, 0x00000000, + } }, + { { /* 116 */ + 0x00000000, 0x00000000, 0x00000000, 0x007f8000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 117 */ + 0x000000e7, 0x00000000, 0xfffffffe, 0xffffffff, + 0x780fffff, 0xfffffffe, 0xffffffff, 0x787fffff, + } }, + { { /* 118 */ + 0x43f36f8b, 0x9b462442, 0xe3e0e82c, 0x400a0004, + 0xdb365f65, 0x04497977, 0xe3f0ecd7, 0x08c56038, + } }, + { { /* 119 */ + 0x3403e602, 0x35518000, 0x7eabe0c8, 0x98698200, + 0x2942a948, 0x8060e803, 0xad93441c, 0x4568c03a, + } }, + { { /* 120 */ + 0x8656aa60, 0x02403f7a, 0x14618388, 0x21741020, + 0x07022021, 0x40bc3000, 0x4462a624, 0x0a2060a8, + } }, + { { /* 121 */ + 0x85740217, 0x9c840402, 0x14157bfb, 0x11e27f24, + 0x02efb665, 0x20ff1f75, 0x28403a70, 0x676326c3, + } }, + { { /* 122 */ + 0x20924dd9, 0x0fc946b0, 0x4850bc98, 0xa03f8638, + 0x88162388, 0x52323e09, 0xe3a422aa, 0xc72c00dd, + } }, + { { /* 123 */ + 0x26e1a166, 0x8f0a840b, 0x559e27eb, 0x89bbc241, + 0x85400014, 0x08496361, 0x8ad07f0c, 0x05cfff3e, + } }, + { { /* 124 */ + 0xa803ff1a, 0x7b407a41, 0x80024745, 0x38eb0500, + 0x0005d851, 0x710c9934, 0x01000397, 0x24046366, + } }, + { { /* 125 */ + 0x005180d0, 0x430ac000, 0x30c89071, 0x58000008, + 0xf7000e99, 0x00415f80, 0x941000b0, 0x62800018, + } }, + { { /* 126 */ + 0x09d00240, 0x01568200, 0x08015004, 0x05101d10, + 0x001084c1, 0x10504025, 0x4d8a410f, 0xa60d4009, + } }, + { { /* 127 */ + 0x914cab19, 0x098121c0, 0x0003c485, 0x80000652, + 0x00080b04, 0x0009041d, 0x905c4849, 0x16900009, + } }, + { { /* 128 */ + 0x22200c65, 0x24338412, 0x47960c03, 0x42250a04, + 0x90880028, 0x4f084900, 0xd3aa14a2, 0x3e87d830, + } }, + { { /* 129 */ + 0x1f618604, 0x41867ea4, 0x05b3c390, 0x211857a5, + 0x2a48241e, 0x4a041128, 0x161b0a40, 0x88400d60, + } }, + { { /* 130 */ + 0x9502020a, 0x10608221, 0x04000243, 0x80001444, + 0x0c040000, 0x70000000, 0x00c11a06, 0x0c00024a, + } }, + { { /* 131 */ + 0x00401a00, 0x40451404, 0xbdb30029, 0x052b0a78, + 0xbfa0bba9, 0x8379407c, 0xe81d12fc, 0xc5694bf6, + } }, + { { /* 132 */ + 0x044aeff6, 0xff022115, 0x402bed63, 0x0242d033, + 0x00131000, 0x59ca1b02, 0x020000a0, 0x2c41a703, + } }, + { { /* 133 */ + 0x8ff24880, 0x00000204, 0x10055800, 0x00489200, + 0x20011894, 0x34805004, 0x684c3200, 0x68be49ea, + } }, + { { /* 134 */ + 0x2e42184c, 0x21c9a820, 0x80b050b9, 0xff7c001e, + 0x14e0849a, 0x01e028c1, 0xac49870e, 0xdddb130f, + } }, + { { /* 135 */ + 0x89fbbe1a, 0x51a2a2e0, 0x32ca5502, 0x928b3e46, + 0x438f1dbf, 0x32186703, 0x33c03028, 0xa9230811, + } }, + { { /* 136 */ + 0x3a65c000, 0x04028fe3, 0x86252c4e, 0x00a1bf3d, + 0x8cd43a1a, 0x317c06c9, 0x950a00e0, 0x0edb018b, + } }, + { { /* 137 */ + 0x8c20e34b, 0xf0101182, 0xa7287d94, 0x40fbc9ac, + 0x06534484, 0x44445a90, 0x00013fc8, 0xf5d40048, + } }, + { { /* 138 */ + 0xec577701, 0x891dc442, 0x49286b83, 0xd2424109, + 0x59fe061d, 0x3a221800, 0x3b9fb7e4, 0xc0eaf003, + } }, + { { /* 139 */ + 0x82021386, 0xe4008980, 0x10a1b200, 0x0cc44b80, + 0x8944d309, 0x48341faf, 0x0c458259, 0x0450420a, + } }, + { { /* 140 */ + 0x10c8a040, 0x44503140, 0x01004004, 0x05408280, + 0x442c0108, 0x1a056a30, 0x051420a6, 0x645690cf, + } }, + { { /* 141 */ + 0x31000021, 0xcbf09c18, 0x63e2a120, 0x01b5104c, + 0x9a83538c, 0x3281b8b2, 0x0a84987a, 0x0c0233e7, + } }, + { { /* 142 */ + 0x9018d4cc, 0x9070a1a1, 0xe0048a1e, 0x0451c3d4, + 0x21c2439a, 0x53104844, 0x36400292, 0xf3bd0241, + } }, + { { /* 143 */ + 0xe8f0ab09, 0xa5d27dc0, 0xd24bc242, 0xd0afa43f, + 0x34a11aa0, 0x03d88247, 0x651bc452, 0xc83ad294, + } }, + { { /* 144 */ + 0x40c8001c, 0x33140e06, 0xb21b614f, 0xc0d00088, + 0xa898a02a, 0x166ba1c5, 0x85b42e50, 0x0604c08b, + } }, + { { /* 145 */ + 0x1e04f933, 0xa251056e, 0x76380400, 0x73b8ec07, + 0x18324406, 0xc8164081, 0x63097c8a, 0xaa042980, + } }, + { { /* 146 */ + 0xca9c1c24, 0x27604e0e, 0x83000990, 0x81040046, + 0x10816011, 0x0908540d, 0xcc0a000e, 0x0c000500, + } }, + { { /* 147 */ + 0xa0440430, 0x6784008b, 0x8a195288, 0x8b18865e, + 0x41602e59, 0x9cbe8c10, 0x891c6861, 0x00089800, + } }, + { { /* 148 */ + 0x089a8100, 0x41900018, 0xe4a14007, 0x640d0505, + 0x0e4d310e, 0xff0a4806, 0x2aa81632, 0x000b852e, + } }, + { { /* 149 */ + 0xca841800, 0x696c0e20, 0x16000032, 0x03905658, + 0x1a285120, 0x11248000, 0x432618e1, 0x0eaa5d52, + } }, + { { /* 150 */ + 0xae280fa0, 0x4500fa7b, 0x89406408, 0xc044c880, + 0xb1419005, 0x24c48424, 0x603a1a34, 0xc1949000, + } }, + { { /* 151 */ + 0x003a8246, 0xc106180d, 0x99100022, 0x1511e050, + 0x00824057, 0x020a041a, 0x8930004f, 0x444ad813, + } }, + { { /* 152 */ + 0xed228a02, 0x400510c0, 0x01021000, 0x31018808, + 0x02044600, 0x0708f000, 0xa2008900, 0x22020000, + } }, + { { /* 153 */ + 0x16100200, 0x10400042, 0x02605200, 0x200052f4, + 0x80308510, 0x42021100, 0x80b54308, 0x9a2070e1, + } }, + { { /* 154 */ + 0x08012040, 0xfc653500, 0xab0419c1, 0x62140286, + 0x00440087, 0x02449085, 0x0a85405c, 0x33803207, + } }, + { { /* 155 */ + 0xb8c00400, 0xc0d0ce20, 0x0080c030, 0x0d250508, + 0x00400a90, 0x080c0200, 0x40006505, 0x41026421, + } }, + { { /* 156 */ + 0x00000268, 0x847c0024, 0xde200002, 0x40498619, + 0x40000808, 0x20010084, 0x10108400, 0x01c742cd, + } }, + { { /* 157 */ + 0xd52a7038, 0x1d8f1968, 0x3e12be50, 0x81d92ef5, + 0x2412cec4, 0x732e0828, 0x4b3424ac, 0xd41d020c, + } }, + { { /* 158 */ + 0x80002a02, 0x08110097, 0x114411c4, 0x7d451786, + 0x064949d9, 0x87914000, 0xd8c4254c, 0x491444ba, + } }, + { { /* 159 */ + 0xc8001b92, 0x15800271, 0x0c000081, 0xc200096a, + 0x40024800, 0xba493021, 0x1c802080, 0x1008e2ac, + } }, + { { /* 160 */ + 0x00341004, 0x841400e1, 0x20000020, 0x10149800, + 0x04aa70c2, 0x54208688, 0x04130c62, 0x20109180, + } }, + { { /* 161 */ + 0x02064082, 0x54001c40, 0xe4e90383, 0x84802125, + 0x2000e433, 0xe60944c0, 0x81260a03, 0x080112da, + } }, + { { /* 162 */ + 0x97906901, 0xf8864001, 0x0081e24d, 0xa6510a0e, + 0x81ec011a, 0x8441c600, 0xb62cadb8, 0x8741a46f, + } }, + { { /* 163 */ + 0x4b028d54, 0x02681161, 0x2057bb60, 0x043350a0, + 0xb7b4a8c0, 0x01122402, 0x20009ad3, 0x00c82271, + } }, + { { /* 164 */ + 0x809e2081, 0xe1800c8a, 0x8151b009, 0x40281031, + 0x89a52a0e, 0x620e69b6, 0xd1444425, 0x4d548085, + } }, + { { /* 165 */ + 0x1fb12c75, 0x862dd807, 0x4841d87c, 0x226e414e, + 0x9e088200, 0xed37f80c, 0x75268c80, 0x08149313, + } }, + { { /* 166 */ + 0xc8040e32, 0x6ea6484e, 0x66702c4a, 0xba0126c0, + 0x185dd30c, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 167 */ + 0x00000000, 0x05400000, 0x81337020, 0x03a54f81, + 0x641055ec, 0x2344c318, 0x00341462, 0x1a090a43, + } }, + { { /* 168 */ + 0x13a5187b, 0xa8480102, 0xc5440440, 0xe2dd8106, + 0x2d481af0, 0x0416b626, 0x6e405058, 0x31128032, + } }, + { { /* 169 */ + 0x0c0007e4, 0x420a8208, 0x803b4840, 0x87134860, + 0x3428850d, 0xe5290319, 0x870a2345, 0x5c1825a9, + } }, + { { /* 170 */ + 0xd9c577a6, 0x03e85e00, 0xa7000081, 0x41c6cd54, + 0xa2042800, 0x2b0ab860, 0xda9e0020, 0x0e1a08ea, + } }, + { { /* 171 */ + 0x11c0427c, 0x03768908, 0x01058621, 0x18a80000, + 0xc44846a0, 0x20220d05, 0x91485422, 0x28978a01, + } }, + { { /* 172 */ + 0x00087898, 0x31221605, 0x08804240, 0x06a2fa4e, + 0x92110814, 0x9b042002, 0x06432e52, 0x90105000, + } }, + { { /* 173 */ + 0x85ba0041, 0x20203042, 0x05a04f0b, 0x40802708, + 0x1a930591, 0x0600df50, 0x3021a202, 0x4e800630, + } }, + { { /* 174 */ + 0x04c80cc4, 0x8001a004, 0xd4316000, 0x0a020880, + 0x00281c00, 0x00418e18, 0xca106ad0, 0x4b00f210, + } }, + { { /* 175 */ + 0x1506274d, 0x88900220, 0x82a85a00, 0x81504549, + 0x80002004, 0x2c088804, 0x000508d1, 0x4ac48001, + } }, + { { /* 176 */ + 0x0062e020, 0x0a42008e, 0x6a8c3055, 0xe0a5090e, + 0x42c42906, 0x80b34814, 0xb330803e, 0x731c0102, + } }, + { { /* 177 */ + 0x600d1494, 0x09400c20, 0xc040301a, 0xc094a451, + 0x05c88dca, 0xa40c96c2, 0x34040001, 0x011000c8, + } }, + { { /* 178 */ + 0xa9c9550d, 0x1c5a2428, 0x48370142, 0x100f7a4d, + 0x452a32b4, 0x9205317b, 0x5c44b894, 0x458a68d7, + } }, + { { /* 179 */ + 0x2ed15097, 0x42081943, 0x9d40d202, 0x20979840, + 0x064d5409, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 180 */ + 0x00000000, 0x84800000, 0x04215542, 0x17001c06, + 0x61107624, 0xb9ddff87, 0x5c0a659f, 0x3c00245d, + } }, + { { /* 181 */ + 0x0059adb0, 0x00000000, 0x00000000, 0x009b28d0, + 0x02000422, 0x44080108, 0xac409804, 0x90288d0a, + } }, + { { /* 182 */ + 0xe0018700, 0x00310400, 0x82211794, 0x10540019, + 0x021a2cb2, 0x40039c02, 0x88043d60, 0x7900080c, + } }, + { { /* 183 */ + 0xba3c1628, 0xcb088640, 0x90807274, 0x0000001e, + 0xd8000000, 0x9c87e188, 0x04124034, 0x2791ae64, + } }, + { { /* 184 */ + 0xe6fbe86b, 0x5366408f, 0x537feea6, 0xb5e4e32b, + 0x0002869f, 0x01228548, 0x08004402, 0x20a02116, + } }, + { { /* 185 */ + 0x02040004, 0x00052000, 0x01547e00, 0x01ac162c, + 0x10852a84, 0x05308c14, 0xb943fbc3, 0x906000ca, + } }, + { { /* 186 */ + 0x40326000, 0x80901200, 0x4c810b30, 0x40020054, + 0x1d6a0029, 0x02802000, 0x00048000, 0x150c2610, + } }, + { { /* 187 */ + 0x07018040, 0x0c24d94d, 0x18502810, 0x50205001, + 0x04d01000, 0x02017080, 0x21c30108, 0x00000132, + } }, + { { /* 188 */ + 0x07190088, 0x05600802, 0x4c0e0012, 0xf0a10405, + 0x00000002, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 189 */ + 0x00000000, 0x00000000, 0x00000000, 0x00800000, + 0x035a8e8d, 0x5a0421bd, 0x11703488, 0x00000026, + } }, + { { /* 190 */ + 0x10000000, 0x8804c502, 0xf801b815, 0x25ed147c, + 0x1bb0ed60, 0x1bd70589, 0x1a627af3, 0x0ac50d0c, + } }, + { { /* 191 */ + 0x524ae5d1, 0x63050490, 0x52440354, 0x16122b57, + 0x1101a872, 0x00182949, 0x10080948, 0x886c6000, + } }, + { { /* 192 */ + 0x058f916e, 0x39903012, 0x4930f840, 0x001b8880, + 0x00000000, 0x00428500, 0x98000058, 0x7014ea04, + } }, + { { /* 193 */ + 0x611d1628, 0x60005113, 0x00a71a24, 0x00000000, + 0x03c00000, 0x10187120, 0xa9270172, 0x89066004, + } }, + { { /* 194 */ + 0x020cc022, 0x40810900, 0x8ca0202d, 0x00000e34, + 0x00000000, 0x11012100, 0xc11a8011, 0x0892ec4c, + } }, + { { /* 195 */ + 0x85000040, 0x1806c7ac, 0x0512e03e, 0x00108000, + 0x80ce4008, 0x02106d01, 0x08568641, 0x0027011e, + } }, + { { /* 196 */ + 0x083d3750, 0x4e05e032, 0x048401c0, 0x01400081, + 0x00000000, 0x00000000, 0x00000000, 0x00591aa0, + } }, + { { /* 197 */ + 0x882443c8, 0xc8001d48, 0x72030152, 0x04049013, + 0x04008280, 0x0d148a10, 0x02088056, 0x2704a040, + } }, + { { /* 198 */ + 0x4c000000, 0x00000000, 0x00000000, 0xa3200000, + 0xa0ae1902, 0xdf002660, 0x7b15f010, 0x3ad08121, + } }, + { { /* 199 */ + 0x00284180, 0x48001003, 0x8014cc00, 0x00c414cf, + 0x30202000, 0x00000001, 0x00000000, 0x00000000, + } }, + { { /* 200 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00000300, 0x00000300, + } }, + { { /* 201 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0xffff0000, 0x0001ffff, + } }, + { { /* 202 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x0c0c0000, 0x000cc00c, 0x03000000, 0x00000000, + } }, + { { /* 203 */ + 0x00000000, 0x00000300, 0x00000000, 0x00000300, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 204 */ + 0xffff0000, 0xffffffff, 0x0040ffff, 0x00000000, + 0x0c0c0000, 0x0c00000c, 0x03000000, 0x00000300, + } }, + { { /* 205 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x0d10646e, 0x0d10646e, + } }, + { { /* 206 */ + 0x00000000, 0x01000300, 0x00000000, 0x00000300, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 207 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x9fffffff, 0xffcffee7, 0x0000003f, 0x00000000, + } }, + { { /* 208 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xfffddfec, 0xc3effdff, 0x40603ddf, 0x00000003, + } }, + { { /* 209 */ + 0x00000000, 0xfffe0000, 0xffffffff, 0xffffffff, + 0x00007fff, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 210 */ + 0x3eff0793, 0x1303b011, 0x11102801, 0x05930000, + 0xb0111e7b, 0x3b019703, 0x00a01112, 0x306b9593, + } }, + { { /* 211 */ + 0x1102b051, 0x11303201, 0x011102b0, 0xb879300a, + 0x30011306, 0x00800010, 0x100b0113, 0x93000011, + } }, + { { /* 212 */ + 0x00102b03, 0x05930000, 0xb051746b, 0x3b011323, + 0x00001030, 0x70000000, 0x1303b011, 0x11102900, + } }, + { { /* 213 */ + 0x00012180, 0xb0153000, 0x3001030e, 0x02000030, + 0x10230111, 0x13000000, 0x10106b81, 0x01130300, + } }, + { { /* 214 */ + 0x30111013, 0x00000100, 0x22b85530, 0x30000000, + 0x9702b011, 0x113afb07, 0x011303b0, 0x00000021, + } }, + { { /* 215 */ + 0x3b0d1b00, 0x03b01138, 0x11330113, 0x13000001, + 0x111c2b05, 0x00000100, 0xb0111000, 0x2a011300, + } }, + { { /* 216 */ + 0x02b01930, 0x10100001, 0x11000000, 0x10300301, + 0x07130230, 0x0011146b, 0x2b051300, 0x8fb8f974, + } }, + { { /* 217 */ + 0x103b0113, 0x00000000, 0xd9700000, 0x01134ab0, + 0x0011103b, 0x00001103, 0x2ab15930, 0x10000111, + } }, + { { /* 218 */ + 0x11010000, 0x00100b01, 0x01130000, 0x0000102b, + 0x20000101, 0x02a01110, 0x30210111, 0x0102b059, + } }, + { { /* 219 */ + 0x19300000, 0x011307b0, 0xb011383b, 0x00000003, + 0x00000000, 0x383b0d13, 0x0103b011, 0x00001000, + } }, + { { /* 220 */ + 0x01130000, 0x00101020, 0x00000100, 0x00000110, + 0x30000000, 0x00021811, 0x00100000, 0x01110000, + } }, + { { /* 221 */ + 0x00000023, 0x0b019300, 0x00301110, 0x302b0111, + 0x13c7b011, 0x01303b01, 0x00000280, 0xb0113000, + } }, + { { /* 222 */ + 0x2b011383, 0x03b01130, 0x300a0011, 0x1102b011, + 0x00002000, 0x01110100, 0xa011102b, 0x2b011302, + } }, + { { /* 223 */ + 0x01000010, 0x30000001, 0x13029011, 0x11302b01, + 0x000066b0, 0xb0113000, 0x6b07d302, 0x07b0113a, + } }, + { { /* 224 */ + 0x00200103, 0x13000000, 0x11386b05, 0x011303b0, + 0x000010b8, 0x2b051b00, 0x03000110, 0x10000000, + } }, + { { /* 225 */ + 0x1102a011, 0x79700a01, 0x0111a2b0, 0x0000100a, + 0x00011100, 0x00901110, 0x00090111, 0x93000000, + } }, + { { /* 226 */ + 0xf9f2bb05, 0x011322b0, 0x2001323b, 0x00000000, + 0x06b05930, 0x303b0193, 0x1123a011, 0x11700000, + } }, + { { /* 227 */ + 0x001102b0, 0x00001010, 0x03011301, 0x00000110, + 0x162b0793, 0x01010010, 0x11300000, 0x01110200, + } }, + { { /* 228 */ + 0xb0113029, 0x00000000, 0x0eb05130, 0x383b0513, + 0x0303b011, 0x00000100, 0x01930000, 0x00001039, + } }, + { { /* 229 */ + 0x3b000302, 0x00000000, 0x00230113, 0x00000000, + 0x00100000, 0x00010000, 0x90113020, 0x00000002, + } }, + { { /* 230 */ + 0x00000000, 0x10000000, 0x11020000, 0x00000301, + 0x01130000, 0xb079b02b, 0x3b011323, 0x02b01130, + } }, + { { /* 231 */ + 0xf0210111, 0x1343b0d9, 0x11303b01, 0x011103b0, + 0xb0517020, 0x20011322, 0x01901110, 0x300b0111, + } }, + { { /* 232 */ + 0x9302b011, 0x0016ab01, 0x01130100, 0xb0113021, + 0x29010302, 0x02b03130, 0x30000000, 0x1b42b819, + } }, + { { /* 233 */ + 0x11383301, 0x00000330, 0x00000020, 0x33051300, + 0x00001110, 0x00000000, 0x93000000, 0x01302305, + } }, + { { /* 234 */ + 0x00010100, 0x30111010, 0x00000100, 0x02301130, + 0x10100001, 0x11000000, 0x00000000, 0x85130200, + } }, + { { /* 235 */ + 0x10111003, 0x2b011300, 0x63b87730, 0x303b0113, + 0x11a2b091, 0x7b300201, 0x011357f0, 0xf0d1702b, + } }, + { { /* 236 */ + 0x1b0111e3, 0x0ab97130, 0x303b0113, 0x13029001, + 0x11302b01, 0x071302b0, 0x3011302b, 0x23011303, + } }, + { { /* 237 */ + 0x02b01130, 0x30ab0113, 0x11feb411, 0x71300901, + 0x05d347b8, 0xb011307b, 0x21015303, 0x00001110, + } }, + { { /* 238 */ + 0x306b0513, 0x1102b011, 0x00103301, 0x05130000, + 0xa01038eb, 0x30000102, 0x02b01110, 0x30200013, + } }, + { { /* 239 */ + 0x0102b071, 0x00101000, 0x01130000, 0x1011100b, + 0x2b011300, 0x00000000, 0x366b0593, 0x1303b095, + } }, + { { /* 240 */ + 0x01103b01, 0x00000200, 0xb0113000, 0x20000103, + 0x01000010, 0x30000000, 0x030ab011, 0x00101001, + } }, + { { /* 241 */ + 0x01110100, 0x00000003, 0x23011302, 0x03000010, + 0x10000000, 0x01000000, 0x00100000, 0x00000290, + } }, + { { /* 242 */ + 0x30113000, 0x7b015386, 0x03b01130, 0x00210151, + 0x13000000, 0x11303b01, 0x001102b0, 0x00011010, + } }, + { { /* 243 */ + 0x2b011302, 0x02001110, 0x10000000, 0x0102b011, + 0x11300100, 0x000102b0, 0x00011010, 0x2b011100, + } }, + { { /* 244 */ + 0x02101110, 0x002b0113, 0x93000000, 0x11302b03, + 0x011302b0, 0x0000303b, 0x00000002, 0x03b01930, + } }, + { { /* 245 */ + 0x102b0113, 0x0103b011, 0x11300000, 0x011302b0, + 0x00001021, 0x00010102, 0x00000010, 0x102b0113, + } }, + { { /* 246 */ + 0x01020011, 0x11302000, 0x011102b0, 0x30113001, + 0x00000002, 0x02b01130, 0x303b0313, 0x0103b011, + } }, + { { /* 247 */ + 0x00002000, 0x05130000, 0xb011303b, 0x10001102, + 0x00000110, 0x142b0113, 0x01000001, 0x01100000, + } }, + { { /* 248 */ + 0x00010280, 0xb0113000, 0x10000102, 0x00000010, + 0x10230113, 0x93021011, 0x11100b05, 0x01130030, + } }, + { { /* 249 */ + 0xb051702b, 0x3b011323, 0x00000030, 0x30000000, + 0x1303b011, 0x11102b01, 0x01010330, 0xb011300a, + } }, + { { /* 250 */ + 0x20000102, 0x00000000, 0x10000011, 0x9300a011, + 0x00102b05, 0x00000200, 0x90111000, 0x29011100, + } }, + { { /* 251 */ + 0x00b01110, 0x30000000, 0x1302b011, 0x11302b21, + 0x000103b0, 0x00000020, 0x2b051300, 0x02b01130, + } }, + { { /* 252 */ + 0x103b0113, 0x13002011, 0x11322b21, 0x00130280, + 0xa0113028, 0x0a011102, 0x02921130, 0x30210111, + } }, + { { /* 253 */ + 0x13020011, 0x11302b01, 0x03d30290, 0x3011122b, + 0x2b011302, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 254 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00004000, 0x00000000, 0x20000000, 0x00000000, + } }, + { { /* 255 */ + 0x00000000, 0x00000000, 0x00003000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 256 */ + 0x00000000, 0x040001df, 0x80800176, 0x420c0000, + 0x01020140, 0x44008200, 0x00041018, 0x00000000, + } }, + { { /* 257 */ + 0xffff0000, 0xffff27bf, 0x000027bf, 0x00000000, + 0x00000000, 0x0c000000, 0x03000000, 0x000000c0, + } }, + { { /* 258 */ + 0x3c000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 259 */ + 0x00000000, 0x061ef5c0, 0x000001f6, 0x40000000, + 0x01040040, 0x00208210, 0x00005040, 0x00000000, + } }, + { { /* 260 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x08004480, 0x08004480, + } }, + { { /* 261 */ + 0x00000000, 0x00000000, 0xc0000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 262 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 263 */ + 0xffff0042, 0xffffffff, 0x0042ffff, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x000000c0, + } }, + { { /* 264 */ + 0x00000000, 0x000c0000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 265 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x00000000, 0x0000c00c, 0x00000000, 0x00000000, + } }, + { { /* 266 */ + 0x000c0003, 0x00003c00, 0x0000f000, 0x00003c00, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 267 */ + 0x00000000, 0x040001de, 0x00000176, 0x42000000, + 0x01020140, 0x44008200, 0x00041008, 0x00000000, + } }, + { { /* 268 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x98504f14, 0x18504f14, + } }, + { { /* 269 */ + 0x00000000, 0x00000000, 0x00000c00, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 270 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00480910, 0x00480910, + } }, + { { /* 271 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x0c186606, 0x0c186606, + } }, + { { /* 272 */ + 0x0c000000, 0x00000000, 0x00000000, 0x00000000, + 0x00010040, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 273 */ + 0x00001006, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 274 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xfef02596, 0x3bffecae, 0x30003f5f, 0x00000000, + } }, + { { /* 275 */ + 0x03c03030, 0x0000c000, 0x00000000, 0x600c0c03, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 276 */ + 0x000c3003, 0x18c00c0c, 0x00c03060, 0x60000c03, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 277 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00100002, 0x00100002, + } }, + { { /* 278 */ + 0x00000003, 0x18000000, 0x00003060, 0x00000c00, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 279 */ + 0x00000000, 0x00300000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 280 */ + 0xfdffb729, 0x000001ff, 0xb7290000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 281 */ + 0xfffddfec, 0xc3fffdff, 0x00803dcf, 0x00000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 282 */ + 0x00000000, 0xffffffff, 0xffffffff, 0x00ffffff, + 0xffffffff, 0x000003ff, 0x00000000, 0x00000000, + } }, + { { /* 283 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x00000000, 0x0000c000, 0x00000000, 0x00000300, + } }, + { { /* 284 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000010, + 0xfff99fee, 0xf3c5fdff, 0xb000798f, 0x0002ffc0, + } }, + { { /* 285 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00004004, 0x00004004, + } }, + { { /* 286 */ + 0x0f000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 287 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x02045101, 0x02045101, + } }, + { { /* 288 */ + 0x00000c00, 0x000000c3, 0x00000000, 0x18000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 289 */ + 0xffffffff, 0x0007f6fb, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 290 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000300, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 291 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x011c0661, 0x011c0661, + } }, + { { /* 292 */ + 0xfff98fee, 0xc3e5fdff, 0x0001398f, 0x0001fff0, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 293 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x1c58af16, 0x1c58af16, + } }, + { { /* 294 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x115c0671, 0x115c0671, + } }, + { { /* 295 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0xffffffff, 0x07ffffff, + } }, + { { /* 296 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00100400, 0x00100400, + } }, + { { /* 297 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 298 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00082202, 0x00082202, + } }, + { { /* 299 */ + 0x03000030, 0x0000c000, 0x00000006, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000c00, + } }, + { { /* 300 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x10000000, 0x00000000, 0x00000000, + } }, + { { /* 301 */ + 0x00000002, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 302 */ + 0x00000000, 0x00000000, 0x00000000, 0x00300000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 303 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x040c2383, 0x040c2383, + } }, + { { /* 304 */ + 0xfff99fee, 0xf3cdfdff, 0xb0c0398f, 0x00000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 305 */ + 0x00000000, 0x07ffffc6, 0x000001fe, 0x40000000, + 0x01000040, 0x0000a000, 0x00001000, 0x00000000, + } }, + { { /* 306 */ + 0xfff987e0, 0xd36dfdff, 0x1e003987, 0x001f0000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 307 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x160e2302, 0x160e2302, + } }, + { { /* 308 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00020000, 0x00020000, + } }, + { { /* 309 */ + 0x030000f0, 0x00000000, 0x0c00001e, 0x1e000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 310 */ + 0x00000000, 0x07ffffde, 0x000005f6, 0x50000000, + 0x05480262, 0x10000a00, 0x00013000, 0x00000000, + } }, + { { /* 311 */ + 0x00000000, 0x07ffffde, 0x000005f6, 0x50000000, + 0x05480262, 0x10000a00, 0x00052000, 0x00000000, + } }, + { { /* 312 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x143c278f, 0x143c278f, + } }, + { { /* 313 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000100, 0x00000000, + } }, + { { /* 314 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x02045301, 0x02045301, + } }, + { { /* 315 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x00300000, 0x0c00c030, 0x03000000, 0x00000000, + } }, + { { /* 316 */ + 0xfff987ee, 0xf325fdff, 0x00013987, 0x0001fff0, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 317 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x02041101, 0x02041101, + } }, + { { /* 318 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00800000, 0x00000000, 0x00000000, + } }, + { { /* 319 */ + 0x30000000, 0x00000000, 0x00000000, 0x00000000, + 0x00040000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 320 */ + 0x00000000, 0x07fffdd6, 0x000005f6, 0xec000000, + 0x0200b4d9, 0x480a8640, 0x00000000, 0x00000000, + } }, + { { /* 321 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00000002, 0x00000002, + } }, + { { /* 322 */ + 0x00033000, 0x00000000, 0x00000c00, 0x600000c3, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 323 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x1850cc14, 0x1850cc14, + } }, + { { /* 324 */ + 0xffff8f04, 0xffffffff, 0x8f04ffff, 0x00000000, + 0x030c0000, 0x0c00cc0f, 0x03000000, 0x00000300, + } }, + { { /* 325 */ + 0x00000000, 0x00800000, 0x03bffbaa, 0x03bffbaa, + 0x00000000, 0x00000000, 0x00002202, 0x00002202, + } }, + { { /* 326 */ + 0x00080000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 327 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xfc7e3fec, 0x2ffbffbf, 0x7f5f847f, 0x00040000, + } }, + { { /* 328 */ + 0xff7fff7f, 0xff01ff7f, 0x3d7f3d7f, 0xffff7fff, + 0xffff3d7f, 0x003d7fff, 0xff7f7f3d, 0x00ff7fff, + } }, + { { /* 329 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x24182212, 0x24182212, + } }, + { { /* 330 */ + 0x0000f000, 0x66000000, 0x00300180, 0x60000033, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 331 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00408030, 0x00408030, + } }, + { { /* 332 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00020032, 0x00020032, + } }, + { { /* 333 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00000016, 0x00000016, + } }, + { { /* 334 */ + 0x00033000, 0x00000000, 0x00000c00, 0x60000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 335 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00200034, 0x00200034, + } }, + { { /* 336 */ + 0x00033000, 0x00000000, 0x00000c00, 0x60000003, + 0x00000000, 0x00800000, 0x00000000, 0x0000c3f0, + } }, + { { /* 337 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00040000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 338 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00000880, 0x00000880, + } }, + { { /* 339 */ + 0xfdff8f04, 0xfdff01ff, 0x8f0401ff, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 340 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x10400a33, 0x10400a33, + } }, + { { /* 341 */ + 0xffff0000, 0xffff1fff, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 342 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xd63dc7e8, 0xc3bfc718, 0x00803dc7, 0x00000000, + } }, + { { /* 343 */ + 0xfffddfee, 0xc3effdff, 0x00603ddf, 0x00000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 344 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x0c0c0000, 0x00cc0000, 0x00000000, 0x0000c00c, + } }, + { { /* 345 */ + 0xfffffffe, 0x87ffffff, 0x00007fff, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 346 */ + 0xff7fff7f, 0xff01ff00, 0x00003d7f, 0xffff7fff, + 0x00ff0000, 0x003d7f7f, 0xff7f7f00, 0x00ff7f00, + } }, + { { /* 347 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x30400090, 0x30400090, + } }, + { { /* 348 */ + 0x00000000, 0x00000000, 0xc0000180, 0x60000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 349 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x18404084, 0x18404084, + } }, + { { /* 350 */ + 0xffff0002, 0xffffffff, 0x0002ffff, 0x00000000, + 0x00c00000, 0x0c00c00c, 0x03000000, 0x00000000, + } }, + { { /* 351 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00008000, 0x00008000, + } }, + { { /* 352 */ + 0x00000000, 0x041ed5c0, 0x0000077e, 0x40000000, + 0x01000040, 0x4000a000, 0x002109c0, 0x00000000, + } }, + { { /* 353 */ + 0xffff00d0, 0xffffffff, 0x00d0ffff, 0x00000000, + 0x00030000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 354 */ + 0x000c0000, 0x30000000, 0x00000c30, 0x00030000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 355 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x263c370f, 0x263c370f, + } }, + { { /* 356 */ + 0x0003000c, 0x00000300, 0x00000000, 0x00000300, + 0x00000000, 0x00018003, 0x00000000, 0x00000000, + } }, + { { /* 357 */ + 0x0800024f, 0x00000008, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 358 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0xffffffff, 0xffffffff, 0x03ffffff, + } }, + { { /* 359 */ + 0x00000000, 0x00000000, 0x077dfffe, 0x077dfffe, + 0x00000000, 0x00000000, 0x10400010, 0x10400010, + } }, + { { /* 360 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x10400010, 0x10400010, + } }, + { { /* 361 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x081047a4, 0x081047a4, + } }, + { { /* 362 */ + 0x0c0030c0, 0x00000000, 0x0f30001e, 0x66000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 363 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x000a0a09, 0x000a0a09, + } }, + { { /* 364 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x00400810, 0x00400810, + } }, + { { /* 365 */ + 0x00000000, 0x00000000, 0x07fffffe, 0x07fffffe, + 0x00000000, 0x00000000, 0x0e3c770f, 0x0e3c770f, + } }, + { { /* 366 */ + 0x0c000000, 0x00000300, 0x00000018, 0x00000300, + 0x00000000, 0x00000000, 0x001fe000, 0x03000000, + } }, + { { /* 367 */ + 0x0000100f, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 368 */ + 0x00000000, 0xc0000000, 0x00000000, 0x0000000c, + 0x00000000, 0x33000000, 0x00003000, 0x00000000, + } }, + { { /* 369 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000280, 0x00000000, + } }, + { { /* 370 */ + 0x7f7b7f8b, 0xef553db4, 0xf35dfba8, 0x400b0243, + 0x8d3efb40, 0x8c2c7bf7, 0xe3fa6eff, 0xa8ed1d3a, + } }, + { { /* 371 */ + 0xcf83e602, 0x35558cf5, 0xffabe048, 0xd85992b9, + 0x2892ab18, 0x8020d7e9, 0xf583c438, 0x450ae74a, + } }, + { { /* 372 */ + 0x9714b000, 0x54007762, 0x1420d188, 0xc8c01020, + 0x00002121, 0x0c0413a8, 0x04408000, 0x082870c0, + } }, + { { /* 373 */ + 0x000408c0, 0x80000002, 0x14722b7b, 0x3bfb7924, + 0x1ae43327, 0x38ef9835, 0x28029ad1, 0xbf69a813, + } }, + { { /* 374 */ + 0x2fc665cf, 0xafc96b11, 0x5053340f, 0xa00486a2, + 0xe8090106, 0xc00e3f0f, 0x81450a88, 0xc6010010, + } }, + { { /* 375 */ + 0x26e1a161, 0xce00444b, 0xd4eec7aa, 0x85bbcadf, + 0xa5203a74, 0x8840436c, 0x8bd23f06, 0x3befff79, + } }, + { { /* 376 */ + 0xe8eff75a, 0x5b36fbcb, 0x1bfd0d49, 0x39ee0154, + 0x2e75d855, 0xa91abfd8, 0xf6bff3d7, 0xb40c67e0, + } }, + { { /* 377 */ + 0x081382c2, 0xd08bd49d, 0x1061065a, 0x59e074f2, + 0xb3128f9f, 0x6aaa0080, 0xb05e3230, 0x60ac9d7a, + } }, + { { /* 378 */ + 0xc900d303, 0x8a563098, 0x13907000, 0x18421f14, + 0x0008c060, 0x10808008, 0xec900400, 0xe6332817, + } }, + { { /* 379 */ + 0x90000758, 0x4e09f708, 0xfc83f485, 0x18c8af53, + 0x080c187c, 0x01146adf, 0xa734c80c, 0x2710a011, + } }, + { { /* 380 */ + 0x422228c5, 0x00210413, 0x41123010, 0x40001820, + 0xc60c022b, 0x10000300, 0x00220022, 0x02495810, + } }, + { { /* 381 */ + 0x9670a094, 0x1792eeb0, 0x05f2cb96, 0x23580025, + 0x42cc25de, 0x4a04cf38, 0x359f0c40, 0x8a001128, + } }, + { { /* 382 */ + 0x910a13fa, 0x10560229, 0x04200641, 0x84f00484, + 0x0c040000, 0x412c0400, 0x11541206, 0x00020a4b, + } }, + { { /* 383 */ + 0x00c00200, 0x00940000, 0xbfbb0001, 0x242b167c, + 0x7fa89bbb, 0xe3790c7f, 0xe00d10f4, 0x9f014132, + } }, + { { /* 384 */ + 0x35728652, 0xff1210b4, 0x4223cf27, 0x8602c06b, + 0x1fd33106, 0xa1aa3a0c, 0x02040812, 0x08012572, + } }, + { { /* 385 */ + 0x485040cc, 0x601062d0, 0x29001c80, 0x00109a00, + 0x22000004, 0x00800000, 0x68002020, 0x609ecbe6, + } }, + { { /* 386 */ + 0x3f73916e, 0x398260c0, 0x48301034, 0xbd5c0006, + 0xd6fb8cd1, 0x43e820e1, 0x084e0600, 0xc4d00500, + } }, + { { /* 387 */ + 0x89aa8d1f, 0x1602a6e1, 0x21ed0001, 0x1a8b3656, + 0x13a51fb7, 0x30a06502, 0x23c7b278, 0xe9226c93, + } }, + { { /* 388 */ + 0x3a74e47f, 0x98208fe3, 0x2625280e, 0xbf49bf9c, + 0xac543218, 0x1916b949, 0xb5220c60, 0x0659fbc1, + } }, + { { /* 389 */ + 0x8420e343, 0x800008d9, 0x20225500, 0x00a10184, + 0x20104800, 0x40801380, 0x00160d04, 0x80200040, + } }, + { { /* 390 */ + 0x8de7fd40, 0xe0985436, 0x091e7b8b, 0xd249fec8, + 0x8dee0611, 0xba221937, 0x9fdd77f4, 0xf0daf3ec, + } }, + { { /* 391 */ + 0xec424386, 0x26048d3f, 0xc021fa6c, 0x0cc2628e, + 0x0145d785, 0x559977ad, 0x4045e250, 0xa154260b, + } }, + { { /* 392 */ + 0x58199827, 0xa4103443, 0x411405f2, 0x07002280, + 0x426600b4, 0x15a17210, 0x41856025, 0x00000054, + } }, + { { /* 393 */ + 0x01040201, 0xcb70c820, 0x6a629320, 0x0095184c, + 0x9a8b1880, 0x3201aab2, 0x00c4d87a, 0x04c3f3e5, + } }, + { { /* 394 */ + 0xa238d44d, 0x5072a1a1, 0x84fc980a, 0x44d1c152, + 0x20c21094, 0x42104180, 0x3a000000, 0xd29d0240, + } }, + { { /* 395 */ + 0xa8b12f01, 0x2432bd40, 0xd04bd34d, 0xd0ada723, + 0x75a10a92, 0x01e9adac, 0x771f801a, 0xa01b9225, + } }, + { { /* 396 */ + 0x20cadfa1, 0x738c0602, 0x003b577f, 0x00d00bff, + 0x0088806a, 0x0029a1c4, 0x05242a05, 0x16234009, + } }, + { { /* 397 */ + 0x80056822, 0xa2112011, 0x64900004, 0x13824849, + 0x193023d5, 0x08922980, 0x88115402, 0xa0042001, + } }, + { { /* 398 */ + 0x81800400, 0x60228502, 0x0b010090, 0x12020022, + 0x00834011, 0x00001a01, 0x00000000, 0x00000000, + } }, + { { /* 399 */ + 0x00000000, 0x4684009f, 0x020012c8, 0x1a0004fc, + 0x0c4c2ede, 0x80b80402, 0x0afca826, 0x22288c02, + } }, + { { /* 400 */ + 0x8f7ba0e0, 0x2135c7d6, 0xf8b106c7, 0x62550713, + 0x8a19936e, 0xfb0e6efa, 0x48f91630, 0x7debcd2f, + } }, + { { /* 401 */ + 0x4e845892, 0x7a2e4ca0, 0x561eedea, 0x1190c649, + 0xe83a5324, 0x8124cfdb, 0x634218f1, 0x1a8a5853, + } }, + { { /* 402 */ + 0x24d37420, 0x0514aa3b, 0x89586018, 0xc0004800, + 0x91018268, 0x2cd684a4, 0xc4ba8886, 0x02100377, + } }, + { { /* 403 */ + 0x00388244, 0x404aae11, 0x510028c0, 0x15146044, + 0x10007310, 0x02480082, 0x40060205, 0x0000c003, + } }, + { { /* 404 */ + 0x0c020000, 0x02200008, 0x40009000, 0xd161b800, + 0x32744621, 0x3b8af800, 0x8b00050f, 0x2280bbd0, + } }, + { { /* 405 */ + 0x07690600, 0x00438040, 0x50005420, 0x250c41d0, + 0x83108410, 0x02281101, 0x00304008, 0x020040a1, + } }, + { { /* 406 */ + 0x20000040, 0xabe31500, 0xaa443180, 0xc624c2c6, + 0x8004ac13, 0x03d1b000, 0x4285611e, 0x1d9ff303, + } }, + { { /* 407 */ + 0x78e8440a, 0xc3925e26, 0x00852000, 0x4000b001, + 0x88424a90, 0x0c8dca04, 0x4203a705, 0x000422a1, + } }, + { { /* 408 */ + 0x0c018668, 0x10795564, 0xdea00002, 0x40c12000, + 0x5001488b, 0x04000380, 0x50040000, 0x80d0c05d, + } }, + { { /* 409 */ + 0x970aa010, 0x4dafbb20, 0x1e10d921, 0x83140460, + 0xa6d68848, 0x733fd83b, 0x497427bc, 0x92130ddc, + } }, + { { /* 410 */ + 0x8ba1142b, 0xd1392e75, 0x50503009, 0x69008808, + 0x024a49d4, 0x80164010, 0x89d7e564, 0x5316c020, + } }, + { { /* 411 */ + 0x86002b92, 0x15e0a345, 0x0c03008b, 0xe200196e, + 0x80067031, 0xa82916a5, 0x18802000, 0xe1487aac, + } }, + { { /* 412 */ + 0xb5d63207, 0x5f9132e8, 0x20e550a1, 0x10807c00, + 0x9d8a7280, 0x421f00aa, 0x02310e22, 0x04941100, + } }, + { { /* 413 */ + 0x40080022, 0x5c100010, 0xfcc80343, 0x0580a1a5, + 0x04008433, 0x6e080080, 0x81262a4b, 0x2901aad8, + } }, + { { /* 414 */ + 0x4490684d, 0xba880009, 0x00820040, 0x87d10000, + 0xb1e6215b, 0x80083161, 0xc2400800, 0xa600a069, + } }, + { { /* 415 */ + 0x4a328d58, 0x550a5d71, 0x2d579aa0, 0x4aa64005, + 0x30b12021, 0x01123fc6, 0x260a10c2, 0x50824462, + } }, + { { /* 416 */ + 0x80409880, 0x810004c0, 0x00002003, 0x38180000, + 0xf1a60200, 0x720e4434, 0x92e035a2, 0x09008101, + } }, + { { /* 417 */ + 0x00000400, 0x00008885, 0x00000000, 0x00804000, + 0x00000000, 0x00004040, 0x00000000, 0x00000000, + } }, + { { /* 418 */ + 0x00000000, 0x08000000, 0x00000082, 0x00000000, + 0x88000004, 0xe7efbfff, 0xffbfffff, 0xfdffefef, + } }, + { { /* 419 */ + 0xbffefbff, 0x057fffff, 0x85b30034, 0x42164706, + 0xe4105402, 0xb3058092, 0x81305422, 0x180b4263, + } }, + { { /* 420 */ + 0x13f5387b, 0xa9ea07e5, 0x05143c4c, 0x80020600, + 0xbd481ad9, 0xf496ee37, 0x7ec0705f, 0x355fbfb2, + } }, + { { /* 421 */ + 0x455fe644, 0x41469000, 0x063b1d40, 0xfe1362a1, + 0x39028505, 0x0c080548, 0x0000144f, 0x58183488, + } }, + { { /* 422 */ + 0xd8153077, 0x4bfbbd0e, 0x85008a90, 0xe61dc100, + 0xb386ed14, 0x639bff72, 0xd9befd92, 0x0a92887b, + } }, + { { /* 423 */ + 0x1cb2d3fe, 0x177ab980, 0xdc1782c9, 0x3980fffb, + 0x590c4260, 0x37df0f01, 0xb15094a3, 0x23070623, + } }, + { { /* 424 */ + 0x3102f85a, 0x310201f0, 0x1e820040, 0x056a3a0a, + 0x12805b84, 0xa7148002, 0xa04b2612, 0x90011069, + } }, + { { /* 425 */ + 0x848a1000, 0x3f801802, 0x42400708, 0x4e140110, + 0x180080b0, 0x0281c510, 0x10298202, 0x88000210, + } }, + { { /* 426 */ + 0x00420020, 0x11000280, 0x4413e000, 0xfe025804, + 0x30283c07, 0x04739798, 0xcb13ced1, 0x431f6210, + } }, + { { /* 427 */ + 0x55ac278d, 0xc892422e, 0x02885380, 0x78514039, + 0x8088292c, 0x2428b900, 0x080e0c41, 0x42004421, + } }, + { { /* 428 */ + 0x08680408, 0x12040006, 0x02903031, 0xe0855b3e, + 0x10442936, 0x10822814, 0x83344266, 0x531b013c, + } }, + { { /* 429 */ + 0x0e0d0404, 0x00510c22, 0xc0000012, 0x88000040, + 0x0000004a, 0x00000000, 0x5447dff6, 0x00088868, + } }, + { { /* 430 */ + 0x00000081, 0x40000000, 0x00000100, 0x02000000, + 0x00080600, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 431 */ + 0x00000080, 0x00000040, 0x00000000, 0x00001040, + 0x00000000, 0xf7fdefff, 0xfffeff7f, 0xfffffbff, + } }, + { { /* 432 */ + 0xbffffdff, 0x00ffffff, 0x042012c2, 0x07080c06, + 0x01101624, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 433 */ + 0xe0000000, 0xfffffffe, 0x7f79ffff, 0x00f928df, + 0x80120c32, 0xd53a0008, 0xecc2d858, 0x2fa89d18, + } }, + { { /* 434 */ + 0xe0109620, 0x2622d60c, 0x02060f97, 0x9055b240, + 0x501180a2, 0x04049800, 0x00004000, 0x00000000, + } }, + { { /* 435 */ + 0x00000000, 0x00000000, 0x00000000, 0xfffffbc0, + 0xdffbeffe, 0x62430b08, 0xfb3b41b6, 0x23896f74, + } }, + { { /* 436 */ + 0xecd7ae7f, 0x5960e047, 0x098fa096, 0xa030612c, + 0x2aaa090d, 0x4f7bd44e, 0x388bc4b2, 0x6110a9c6, + } }, + { { /* 437 */ + 0x42000014, 0x0202800c, 0x6485fe48, 0xe3f7d63e, + 0x0c073aa0, 0x0430e40c, 0x1002f680, 0x00000000, + } }, + { { /* 438 */ + 0x00000000, 0x00000000, 0x00000000, 0x00100000, + 0x00004000, 0x00004000, 0x00000100, 0x00000000, + } }, + { { /* 439 */ + 0x00000000, 0x40000000, 0x00000000, 0x00000400, + 0x00008000, 0x00000000, 0x00400400, 0x00000000, + } }, + { { /* 440 */ + 0x00000000, 0x40000000, 0x00000000, 0x00000800, + 0xfebdffe0, 0xffffffff, 0xfbe77f7f, 0xf7ffffbf, + } }, + { { /* 441 */ + 0xefffffff, 0xdff7ff7e, 0xfbdff6f7, 0x804fbffe, + 0x00000000, 0x00000000, 0x00000000, 0x7fffef00, + } }, + { { /* 442 */ + 0xb6f7ff7f, 0xb87e4406, 0x88313bf5, 0x00f41796, + 0x1391a960, 0x72490080, 0x0024f2f3, 0x42c88701, + } }, + { { /* 443 */ + 0x5048e3d3, 0x43052400, 0x4a4c0000, 0x10580227, + 0x01162820, 0x0014a809, 0x00000000, 0x00683ec0, + } }, + { { /* 444 */ + 0x00000000, 0x00000000, 0x00000000, 0xffe00000, + 0xfddbb7ff, 0x000000f7, 0xc72e4000, 0x00000180, + } }, + { { /* 445 */ + 0x00012000, 0x00004000, 0x00300000, 0xb4f7ffa8, + 0x03ffadf3, 0x00000120, 0x00000000, 0x00000000, + } }, + { { /* 446 */ + 0x00000000, 0x00000000, 0x00000000, 0xfffbf000, + 0xfdcf9df7, 0x15c301bf, 0x810a1827, 0x0a00a842, + } }, + { { /* 447 */ + 0x80088108, 0x18048008, 0x0012a3be, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 448 */ + 0x00000000, 0x00000000, 0x00000000, 0x90000000, + 0xdc3769e6, 0x3dff6bff, 0xf3f9fcf8, 0x00000004, + } }, + { { /* 449 */ + 0x80000000, 0xe7eebf6f, 0x5da2dffe, 0xc00b3fd8, + 0xa00c0984, 0x69100040, 0xb912e210, 0x5a0086a5, + } }, + { { /* 450 */ + 0x02896800, 0x6a809005, 0x00030010, 0x80000000, + 0x8e001ff9, 0x00000001, 0x00000000, 0x00000000, + } }, + { { /* 451 */ + 0x00000080, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 452 */ + 0x00000000, 0x00000000, 0x00001000, 0x64080010, + 0x00480000, 0x10000020, 0x80000102, 0x08000010, + } }, + { { /* 453 */ + 0x00000040, 0x40000000, 0x00020000, 0x01852002, + 0x00800010, 0x80002022, 0x084444a2, 0x480e0000, + } }, + { { /* 454 */ + 0x04000200, 0x02202008, 0x80004380, 0x04000000, + 0x00000002, 0x12231420, 0x2058003a, 0x00200060, + } }, + { { /* 455 */ + 0x10002508, 0x040d0028, 0x00000009, 0x00008004, + 0x00800000, 0x42000001, 0x00000000, 0x09040000, + } }, + { { /* 456 */ + 0x02008000, 0x01402001, 0x00000000, 0x00000008, + 0x00000000, 0x00000001, 0x00021008, 0x04000000, + } }, + { { /* 457 */ + 0x00100100, 0x80040080, 0x00002000, 0x00000008, + 0x08040601, 0x01000012, 0x10000000, 0x49001024, + } }, + { { /* 458 */ + 0x0180004a, 0x00100600, 0x50840800, 0x000000c0, + 0x00800000, 0x20000800, 0x40000000, 0x08050000, + } }, + { { /* 459 */ + 0x02004000, 0x02000804, 0x01000004, 0x18060001, + 0x02400001, 0x40000002, 0x20800014, 0x000c1000, + } }, + { { /* 460 */ + 0x00222000, 0x00000000, 0x00100000, 0x00000000, + 0x00000000, 0x00000000, 0x10422800, 0x00000800, + } }, + { { /* 461 */ + 0x20080000, 0x00040000, 0x80025040, 0x20208604, + 0x00028020, 0x80102020, 0x080820c0, 0x10880800, + } }, + { { /* 462 */ + 0x00000000, 0x00000000, 0x00200109, 0x00100000, + 0x00000000, 0x81022700, 0x40c21404, 0x84010882, + } }, + { { /* 463 */ + 0x00004010, 0x00000000, 0x03000000, 0x00000008, + 0x00080000, 0x00000000, 0x10800001, 0x06002020, + } }, + { { /* 464 */ + 0x00000010, 0x02000000, 0x00880020, 0x00008424, + 0x00000000, 0x88000000, 0x81000100, 0x04000000, + } }, + { { /* 465 */ + 0x00004218, 0x00040000, 0x00000000, 0x80005080, + 0x00010000, 0x00040000, 0x08008000, 0x02008000, + } }, + { { /* 466 */ + 0x00020000, 0x00000000, 0x00000001, 0x04000401, + 0x00100000, 0x12200004, 0x00000000, 0x18100000, + } }, + { { /* 467 */ + 0x00000000, 0x00000800, 0x00000000, 0x00004000, + 0x00800000, 0x04000000, 0x82000002, 0x00042000, + } }, + { { /* 468 */ + 0x00080006, 0x00000000, 0x00000000, 0x04000000, + 0x80008000, 0x00810001, 0xa0000000, 0x00100410, + } }, + { { /* 469 */ + 0x00400218, 0x88084080, 0x00260008, 0x00800404, + 0x00000020, 0x00000000, 0x00000000, 0x00000200, + } }, + { { /* 470 */ + 0x00a08048, 0x00000000, 0x08000000, 0x04000000, + 0x00000000, 0x00000000, 0x00018000, 0x00200000, + } }, + { { /* 471 */ + 0x01000000, 0x00000000, 0x00000000, 0x10000000, + 0x00000000, 0x00000000, 0x00200000, 0x00102000, + } }, + { { /* 472 */ + 0x00000801, 0x00000000, 0x00000000, 0x00020000, + 0x08000000, 0x00002000, 0x20010000, 0x04002000, + } }, + { { /* 473 */ + 0x40000040, 0x50202400, 0x000a0020, 0x00040420, + 0x00000200, 0x00000080, 0x80000000, 0x00000020, + } }, + { { /* 474 */ + 0x20008000, 0x00200010, 0x00000000, 0x00000000, + 0x00400000, 0x01100000, 0x00020000, 0x80000010, + } }, + { { /* 475 */ + 0x02000000, 0x00801000, 0x00000000, 0x48058000, + 0x20c94000, 0x60000000, 0x00000001, 0x00000000, + } }, + { { /* 476 */ + 0x00004090, 0x48000000, 0x08000000, 0x28802000, + 0x00000002, 0x00014000, 0x00002000, 0x00002002, + } }, + { { /* 477 */ + 0x00010200, 0x00100000, 0x00000000, 0x00800000, + 0x10020000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 478 */ + 0x00000010, 0x00000402, 0x0c000000, 0x01000400, + 0x01000021, 0x00000000, 0x00004000, 0x00004000, + } }, + { { /* 479 */ + 0x00000000, 0x00800000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x02000020, + } }, + { { /* 480 */ + 0x00000100, 0x08000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00002000, 0x00000000, + } }, + { { /* 481 */ + 0x00006000, 0x00000000, 0x00000000, 0x00000400, + 0x04000040, 0x003c0180, 0x00000200, 0x00102000, + } }, + { { /* 482 */ + 0x00000800, 0x101000c0, 0x00800000, 0x00000000, + 0x00008000, 0x02200000, 0x00020020, 0x00000000, + } }, + { { /* 483 */ + 0x00000000, 0x01000000, 0x00000000, 0x20100000, + 0x00080000, 0x00000141, 0x02001002, 0x40400001, + } }, + { { /* 484 */ + 0x00580000, 0x00000002, 0x00003000, 0x00002400, + 0x00988000, 0x00040010, 0x00002800, 0x00000008, + } }, + { { /* 485 */ + 0x40080004, 0x00000020, 0x20080000, 0x02060a00, + 0x00010040, 0x14010200, 0x40800000, 0x08031000, + } }, + { { /* 486 */ + 0x40020020, 0x0000202c, 0x2014a008, 0x00000000, + 0x80040200, 0x82020012, 0x00400000, 0x20000000, + } }, + { { /* 487 */ + 0x00000000, 0x00000000, 0x00000004, 0x04000000, + 0x00000000, 0x00000000, 0x40800100, 0x00000000, + } }, + { { /* 488 */ + 0x00000008, 0x04000040, 0x00000001, 0x000c0200, + 0x00000000, 0x08000400, 0x00000000, 0x080c0001, + } }, + { { /* 489 */ + 0x00000400, 0x00000000, 0x00000000, 0x00200000, + 0x80000000, 0x00001000, 0x00000200, 0x01000800, + } }, + { { /* 490 */ + 0x00000000, 0x00000800, 0x00000000, 0x40000000, + 0x00000000, 0x00000000, 0x00000000, 0x04040000, + } }, + { { /* 491 */ + 0x00000000, 0x00000000, 0x00000040, 0x00002000, + 0xa0000000, 0x00000000, 0x08000008, 0x00080000, + } }, + { { /* 492 */ + 0x00000020, 0x00000000, 0x40000400, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00008000, + } }, + { { /* 493 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000800, 0x00000000, 0x00000000, 0x00200000, + } }, + { { /* 494 */ + 0x00000000, 0x00000000, 0x00000000, 0x04000000, + 0x00000008, 0x00000000, 0x00010000, 0x1b000000, + } }, + { { /* 495 */ + 0x00007000, 0x00000000, 0x10000000, 0x00000000, + 0x00000000, 0x00000080, 0x80000000, 0x00000000, + } }, + { { /* 496 */ + 0x00000000, 0x00020000, 0x00000000, 0x00200000, + 0x40000000, 0x00000010, 0x00800000, 0x00000008, + } }, + { { /* 497 */ + 0x00000000, 0x00000000, 0x02000000, 0x20000010, + 0x00000080, 0x00000000, 0x00010000, 0x00000000, + } }, + { { /* 498 */ + 0x00000000, 0x02000000, 0x00000000, 0x00000000, + 0x20000000, 0x00000040, 0x00200028, 0x00000000, + } }, + { { /* 499 */ + 0x00000000, 0x00020000, 0x00000000, 0x02000000, + 0x00000000, 0x02000000, 0x40020000, 0x51000040, + } }, + { { /* 500 */ + 0x00000080, 0x04040000, 0x00000000, 0x10000000, + 0x00022000, 0x00100000, 0x20000000, 0x00000082, + } }, + { { /* 501 */ + 0x40000000, 0x00010000, 0x00002000, 0x00000000, + 0x00000240, 0x00000000, 0x00000000, 0x00000008, + } }, + { { /* 502 */ + 0x00000000, 0x00010000, 0x00000810, 0x00080880, + 0x00004000, 0x00000000, 0x00000000, 0x00020000, + } }, + { { /* 503 */ + 0x00000000, 0x00400020, 0x00000000, 0x00000082, + 0x00000000, 0x00020001, 0x00000000, 0x00000000, + } }, + { { /* 504 */ + 0x40000018, 0x00000004, 0x00000000, 0x00000000, + 0x01000000, 0x00400000, 0x00000000, 0x00000000, + } }, + { { /* 505 */ + 0x00000001, 0x00400000, 0x00000000, 0x00080002, + 0x00000400, 0x00040000, 0x00000000, 0x00000000, + } }, + { { /* 506 */ + 0x00000800, 0x00000800, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000100, 0x00000000, + } }, + { { /* 507 */ + 0x00000000, 0x00200000, 0x00000000, 0x04108000, + 0x00000000, 0x00000000, 0x00000000, 0x00000002, + } }, + { { /* 508 */ + 0x00000000, 0x02800000, 0x04000000, 0x00000000, + 0x00000000, 0x00000004, 0x00000000, 0x00000400, + } }, + { { /* 509 */ + 0x00000000, 0x00000000, 0x10000000, 0x00040000, + 0x00400000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 510 */ + 0x00200000, 0x00000200, 0x00000000, 0x10000000, + 0x00000000, 0x00000000, 0x2a000000, 0x00000000, + } }, + { { /* 511 */ + 0x00400000, 0x00000000, 0x00400000, 0x00000000, + 0x00000002, 0x40000000, 0x00000000, 0x00400000, + } }, + { { /* 512 */ + 0x40000000, 0x00001000, 0x00000000, 0x00000000, + 0x00000202, 0x02000000, 0x80000000, 0x00020000, + } }, + { { /* 513 */ + 0x00000020, 0x00000800, 0x00020421, 0x00020000, + 0x00000000, 0x00000000, 0x00000000, 0x00400000, + } }, + { { /* 514 */ + 0x00200000, 0x00000000, 0x00000001, 0x00000000, + 0x00000084, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 515 */ + 0x00000000, 0x00004400, 0x00000002, 0x00100000, + 0x00000000, 0x00000000, 0x00008200, 0x00000000, + } }, + { { /* 516 */ + 0x00000000, 0x12000000, 0x00000100, 0x00000001, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 517 */ + 0x00000020, 0x08100000, 0x000a0400, 0x00000081, + 0x00006000, 0x00120000, 0x00000000, 0x00000000, + } }, + { { /* 518 */ + 0x00000004, 0x08000000, 0x00004000, 0x044000c0, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 519 */ + 0x40001000, 0x00000000, 0x01000001, 0x05000000, + 0x00080000, 0x02000000, 0x00000800, 0x00000000, + } }, + { { /* 520 */ + 0x00000100, 0x00000000, 0x00000000, 0x00000000, + 0x00002002, 0x01020000, 0x00800000, 0x00000000, + } }, + { { /* 521 */ + 0x00000040, 0x00004000, 0x01000000, 0x00000004, + 0x00020000, 0x00000000, 0x00000010, 0x00000000, + } }, + { { /* 522 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00080000, 0x00010000, 0x30000300, 0x00000400, + } }, + { { /* 523 */ + 0x00000800, 0x02000000, 0x00000000, 0x00008000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 524 */ + 0x00200000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x000040c0, 0x00002200, 0x12002000, + } }, + { { /* 525 */ + 0x00000000, 0x00000020, 0x20000000, 0x00000000, + 0x00000200, 0x00080800, 0x1000a000, 0x00000000, + } }, + { { /* 526 */ + 0x00000000, 0x00000000, 0x00000000, 0x00004000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 527 */ + 0x00000000, 0x00000000, 0x00004280, 0x01000000, + 0x00800000, 0x00000008, 0x00000000, 0x00000000, + } }, + { { /* 528 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000002, + 0x00000000, 0x20400000, 0x00000040, 0x00000000, + } }, + { { /* 529 */ + 0x00800080, 0x00800000, 0x00000000, 0x00000000, + 0x00000000, 0x00400020, 0x00000000, 0x00008000, + } }, + { { /* 530 */ + 0x01000000, 0x00000040, 0x00000000, 0x00400000, + 0x00000000, 0x00000440, 0x00000000, 0x00800000, + } }, + { { /* 531 */ + 0x01000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00080000, 0x00000000, + } }, + { { /* 532 */ + 0x01000000, 0x00000001, 0x00000000, 0x00020000, + 0x00000000, 0x20002000, 0x00000000, 0x00000004, + } }, + { { /* 533 */ + 0x00000008, 0x00100000, 0x00000000, 0x00010000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 534 */ + 0x00000004, 0x00008000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00008000, + } }, + { { /* 535 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000040, 0x00000000, 0x00004000, 0x00000000, + } }, + { { /* 536 */ + 0x00000010, 0x00002000, 0x40000040, 0x00000000, + 0x10000000, 0x00000000, 0x00008080, 0x00000000, + } }, + { { /* 537 */ + 0x00000000, 0x00000000, 0x00000080, 0x00000000, + 0x00100080, 0x000000a0, 0x00000000, 0x00000000, + } }, + { { /* 538 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00100000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 539 */ + 0x00000000, 0x00000000, 0x00001000, 0x00000000, + 0x0001000a, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 540 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x08002000, 0x00000000, + } }, + { { /* 541 */ + 0x00000808, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 542 */ + 0x00004000, 0x00002400, 0x00008000, 0x40000000, + 0x00000001, 0x00002000, 0x04000000, 0x00040004, + } }, + { { /* 543 */ + 0x00000000, 0x00002000, 0x00000000, 0x00000000, + 0x00000000, 0x1c200000, 0x00000000, 0x02000000, + } }, + { { /* 544 */ + 0x00000000, 0x00080000, 0x00400000, 0x00000002, + 0x00000000, 0x00000100, 0x00000000, 0x00000000, + } }, + { { /* 545 */ + 0x00000000, 0x00000000, 0x00000000, 0x00400000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 546 */ + 0x00004100, 0x00000400, 0x20200010, 0x00004004, + 0x00000000, 0x42000000, 0x00000000, 0x00000000, + } }, + { { /* 547 */ + 0x00000080, 0x00000000, 0x00000121, 0x00000200, + 0x000000b0, 0x80002000, 0x00000000, 0x00010000, + } }, + { { /* 548 */ + 0x00000010, 0x000000c0, 0x08100000, 0x00000020, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 549 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x02000000, 0x00000404, 0x00000000, 0x00000000, + } }, + { { /* 550 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00400000, 0x00000008, 0x00000000, 0x00000000, + } }, + { { /* 551 */ + 0x00000000, 0x00000002, 0x00020000, 0x00002000, + 0x00000000, 0x00000000, 0x00000000, 0x00204000, + } }, + { { /* 552 */ + 0x00000000, 0x00100000, 0x00000000, 0x00000000, + 0x00000000, 0x00800000, 0x00000100, 0x00000001, + } }, + { { /* 553 */ + 0x10000000, 0x01000000, 0x00002400, 0x00000004, + 0x00000000, 0x00000000, 0x00000020, 0x00000002, + } }, + { { /* 554 */ + 0x00010000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 555 */ + 0x00000000, 0x00002400, 0x00000000, 0x00000000, + 0x00004802, 0x00000000, 0x00000000, 0x80022000, + } }, + { { /* 556 */ + 0x00001004, 0x04208000, 0x20000020, 0x00040000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 557 */ + 0x00000000, 0x00100000, 0x40010000, 0x00000000, + 0x00080000, 0x00000000, 0x00100211, 0x00000000, + } }, + { { /* 558 */ + 0x00001400, 0x00000000, 0x00000000, 0x00000000, + 0x00610000, 0x80008c00, 0x00000000, 0x00000000, + } }, + { { /* 559 */ + 0x00000100, 0x00000040, 0x00000000, 0x00000004, + 0x00004000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 560 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000400, 0x00000000, + } }, + { { /* 561 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000210, 0x00000000, 0x00000000, + } }, + { { /* 562 */ + 0x00000000, 0x00000020, 0x00000002, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 563 */ + 0x00004000, 0x00000000, 0x00000000, 0x02000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 564 */ + 0x00000000, 0x00000000, 0x00080002, 0x01000020, + 0x00400000, 0x00200000, 0x00008000, 0x00000000, + } }, + { { /* 565 */ + 0x00000000, 0x00020000, 0x00000000, 0xc0020000, + 0x10000000, 0x00000080, 0x00000000, 0x00000000, + } }, + { { /* 566 */ + 0x00000210, 0x00000000, 0x00001000, 0x04480000, + 0x20000000, 0x00000004, 0x00800000, 0x02000000, + } }, + { { /* 567 */ + 0x00000000, 0x08006000, 0x00001000, 0x00000000, + 0x00000000, 0x00100000, 0x00000000, 0x00000400, + } }, + { { /* 568 */ + 0x00100000, 0x00000000, 0x10000000, 0x08608000, + 0x00000000, 0x00000000, 0x00080002, 0x00000000, + } }, + { { /* 569 */ + 0x00000000, 0x20000000, 0x00008020, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 570 */ + 0x00000000, 0x00000000, 0x00000000, 0x10000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 571 */ + 0x00000000, 0x00100000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 572 */ + 0x00000000, 0x00000400, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 573 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x02000000, + } }, + { { /* 574 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000080, 0x00000000, + } }, + { { /* 575 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000002, 0x00000000, 0x00000000, + } }, + { { /* 576 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00008000, 0x00000000, + } }, + { { /* 577 */ + 0x00000000, 0x00000000, 0x00000008, 0x00000000, + 0x00000000, 0x00000000, 0x00000400, 0x00000000, + } }, + { { /* 578 */ + 0x00000000, 0x00000000, 0x00220000, 0x00000004, + 0x00000000, 0x00040000, 0x00000004, 0x00000000, + } }, + { { /* 579 */ + 0x00000000, 0x00000000, 0x00001000, 0x00000080, + 0x00002000, 0x00000000, 0x00000000, 0x00004000, + } }, + { { /* 580 */ + 0x00000000, 0x00000000, 0x00000000, 0x00100000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 581 */ + 0x00000000, 0x00020000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 582 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00200000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 583 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x04000000, 0x00000000, 0x00000000, + } }, + { { /* 584 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000200, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 585 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000001, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 586 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00080000, 0x00000000, + } }, + { { /* 587 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01000000, 0x00000000, 0x00000400, + } }, + { { /* 588 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000080, 0x00000000, 0x00000000, + } }, + { { /* 589 */ + 0x00000000, 0x00000800, 0x00000100, 0x40000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 590 */ + 0x00000000, 0x00200000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 591 */ + 0x00000000, 0x00000000, 0x01000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 592 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x04000000, 0x00000000, + } }, + { { /* 593 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00001000, 0x00000000, + } }, + { { /* 594 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000400, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 595 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x04040000, + } }, + { { /* 596 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000020, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 597 */ + 0x00000000, 0x00000000, 0x00800000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 598 */ + 0x00000000, 0x00200000, 0x40000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 599 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x20000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 600 */ + 0x00000000, 0x00000000, 0x00000000, 0x04000000, + 0x00000000, 0x00000001, 0x00000000, 0x00000000, + } }, + { { /* 601 */ + 0x00000000, 0x40000000, 0x02000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 602 */ + 0x00000000, 0x00000000, 0x00000000, 0x00080000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 603 */ + 0x00000000, 0x00000010, 0x00000000, 0x00000000, + 0x00000000, 0x20000000, 0x00000000, 0x00000000, + } }, + { { /* 604 */ + 0x00000000, 0x00000000, 0x20000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 605 */ + 0x00000080, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000004, + } }, + { { /* 606 */ + 0x00000000, 0x00000000, 0x00000000, 0x00002000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 607 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x10000001, 0x00000000, + } }, + { { /* 608 */ + 0x00008000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 609 */ + 0x00000000, 0x00000000, 0x00004040, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 610 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00042400, 0x00000000, + } }, + { { /* 611 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x02000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 612 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000080, + } }, + { { /* 613 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000020, + } }, + { { /* 614 */ + 0x00000000, 0x00000001, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 615 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00020000, 0x00000000, + } }, + { { /* 616 */ + 0x00000000, 0x00000000, 0x00002000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 617 */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x01000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 618 */ + 0x00000000, 0x00040000, 0x08000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 619 */ + 0xc373ff8b, 0x1b0f6840, 0xf34ce9ac, 0xc0080200, + 0xca3e795c, 0x06487976, 0xf7f02fdf, 0xa8ff033a, + } }, + { { /* 620 */ + 0x233fef37, 0xfd59b004, 0xfffff3ca, 0xfff9de9f, + 0x7df7abff, 0x8eecc000, 0xffdbeebf, 0x45fad003, + } }, + { { /* 621 */ + 0xdffefae1, 0x10abbfef, 0xfcaaffeb, 0x24fdef3f, + 0x7f7678ad, 0xedfff00c, 0x2cfacff6, 0xeb6bf7f9, + } }, + { { /* 622 */ + 0x95bf1ffd, 0xbfbf6677, 0xfeb43bfb, 0x11e27bae, + 0x41bea681, 0x72c31435, 0x71917d70, 0x276b0003, + } }, + { { /* 623 */ + 0x70cf57cb, 0x0def4732, 0xfc747eda, 0xbdb4fe06, + 0x8bca3f9f, 0x58007e49, 0xebec228f, 0xddbb8a5c, + } }, + { { /* 624 */ + 0xb6e7ef60, 0xf293a40f, 0x549e37bb, 0x9bafd04b, + 0xf7d4c414, 0x0a1430b0, 0x88d02f08, 0x192fff7e, + } }, + { { /* 625 */ + 0xfb07ffda, 0x7beb7ff1, 0x0010c5ef, 0xfdff99ff, + 0x056779d7, 0xfdcbffe7, 0x4040c3ff, 0xbd8e6ff7, + } }, + { { /* 626 */ + 0x0497dffa, 0x5bfff4c0, 0xd0e7ed7b, 0xf8e0047e, + 0xb73eff9f, 0x882e7dfe, 0xbe7ffffd, 0xf6c483fe, + } }, + { { /* 627 */ + 0xb8fdf357, 0xef7dd680, 0x47885767, 0xc3dfff7d, + 0x37a9f0ff, 0x70fc7de0, 0xec9a3f6f, 0x86814cb3, + } }, + { { /* 628 */ + 0xdd5c3f9e, 0x4819f70d, 0x0007fea3, 0x38ffaf56, + 0xefb8980d, 0xb760403d, 0x9035d8ce, 0x3fff72bf, + } }, + { { /* 629 */ + 0x7a117ff7, 0xabfff7bb, 0x6fbeff00, 0xfe72a93c, + 0xf11bcfef, 0xf40adb6b, 0xef7ec3e6, 0xf6109b9c, + } }, + { { /* 630 */ + 0x16f4f048, 0x5182feb5, 0x15bbc7b1, 0xfbdf6e87, + 0x63cde43f, 0x7e7ec1ff, 0x7d5ffdeb, 0xfcfe777b, + } }, + { { /* 631 */ + 0xdbea960b, 0x53e86229, 0xfdef37df, 0xbd8136f5, + 0xfcbddc18, 0xffffd2e4, 0xffe03fd7, 0xabf87f6f, + } }, + { { /* 632 */ + 0x6ed99bae, 0xf115f5fb, 0xbdfb79a9, 0xadaf5a3c, + 0x1facdbba, 0x837971fc, 0xc35f7cf7, 0x0567dfff, + } }, + { { /* 633 */ + 0x8467ff9a, 0xdf8b1534, 0x3373f9f3, 0x5e1af7bd, + 0xa03fbf40, 0x01ebffff, 0xcfdddfc0, 0xabd37500, + } }, + { { /* 634 */ + 0xeed6f8c3, 0xb7ff43fd, 0x42275eaf, 0xf6869bac, + 0xf6bc27d7, 0x35b7f787, 0xe176aacd, 0xe29f49e7, + } }, + { { /* 635 */ + 0xaff2545c, 0x61d82b3f, 0xbbb8fc3b, 0x7b7dffcf, + 0x1ce0bf95, 0x43ff7dfd, 0xfffe5ff6, 0xc4ced3ef, + } }, + { { /* 636 */ + 0xadbc8db6, 0x11eb63dc, 0x23d0df59, 0xf3dbbeb4, + 0xdbc71fe7, 0xfae4ff63, 0x63f7b22b, 0xadbaed3b, + } }, + { { /* 637 */ + 0x7efffe01, 0x02bcfff7, 0xef3932ff, 0x8005fffc, + 0xbcf577fb, 0xfff7010d, 0xbf3afffb, 0xdfff0057, + } }, + { { /* 638 */ + 0xbd7def7b, 0xc8d4db88, 0xed7cfff3, 0x56ff5dee, + 0xac5f7e0d, 0xd57fff96, 0xc1403fee, 0xffe76ff9, + } }, + { { /* 639 */ + 0x8e77779b, 0xe45d6ebf, 0x5f1f6fcf, 0xfedfe07f, + 0x01fed7db, 0xfb7bff00, 0x1fdfffd4, 0xfffff800, + } }, + { { /* 640 */ + 0x007bfb8f, 0x7f5cbf00, 0x07f3ffff, 0x3de7eba0, + 0xfbd7f7bf, 0x6003ffbf, 0xbfedfffd, 0x027fefbb, + } }, + { { /* 641 */ + 0xddfdfe40, 0xe2f9fdff, 0xfb1f680b, 0xaffdfbe3, + 0xf7ed9fa4, 0xf80f7a7d, 0x0fd5eebe, 0xfd9fbb5d, + } }, + { { /* 642 */ + 0x3bf9f2db, 0xebccfe7f, 0x73fa876a, 0x9ffc95fc, + 0xfaf7109f, 0xbbcdddb7, 0xeccdf87e, 0x3c3ff366, + } }, + { { /* 643 */ + 0xb03ffffd, 0x067ee9f7, 0xfe0696ae, 0x5fd7d576, + 0xa3f33fd1, 0x6fb7cf07, 0x7f449fd1, 0xd3dd7b59, + } }, + { { /* 644 */ + 0xa9bdaf3b, 0xff3a7dcf, 0xf6ebfbe0, 0xffffb401, + 0xb7bf7afa, 0x0ffdc000, 0xff1fff7f, 0x95fffefc, + } }, + { { /* 645 */ + 0xb5dc0000, 0x3f3eef63, 0x001bfb7f, 0xfbf6e800, + 0xb8df9eef, 0x003fff9f, 0xf5ff7bd0, 0x3fffdfdb, + } }, + { { /* 646 */ + 0x00bffdf0, 0xbbbd8420, 0xffdedf37, 0x0ff3ff6d, + 0x5efb604c, 0xfafbfffb, 0x0219fe5e, 0xf9de79f4, + } }, + { { /* 647 */ + 0xebfaa7f7, 0xff3401eb, 0xef73ebd3, 0xc040afd7, + 0xdcff72bb, 0x2fd8f17f, 0xfe0bb8ec, 0x1f0bdda3, + } }, + { { /* 648 */ + 0x47cf8f1d, 0xffdeb12b, 0xda737fee, 0xcbc424ff, + 0xcbf2f75d, 0xb4edecfd, 0x4dddbff9, 0xfb8d99dd, + } }, + { { /* 649 */ + 0xaf7bbb7f, 0xc959ddfb, 0xfab5fc4f, 0x6d5fafe3, + 0x3f7dffff, 0xffdb7800, 0x7effb6ff, 0x022ffbaf, + } }, + { { /* 650 */ + 0xefc7ff9b, 0xffffffa5, 0xc7000007, 0xfff1f7ff, + 0x01bf7ffd, 0xfdbcdc00, 0xffffbff5, 0x3effff7f, + } }, + { { /* 651 */ + 0xbe000029, 0xff7ff9ff, 0xfd7e6efb, 0x039ecbff, + 0xfbdde300, 0xf6dfccff, 0x117fffff, 0xfbf6f800, + } }, + { { /* 652 */ + 0xd73ce7ef, 0xdfeffeef, 0xedbfc00b, 0xfdcdfedf, + 0x40fd7bf5, 0xb75fffff, 0xf930ffdf, 0xdc97fbdf, + } }, + { { /* 653 */ + 0xbff2fef3, 0xdfbf8fdf, 0xede6177f, 0x35530f7f, + 0x877e447c, 0x45bbfa12, 0x779eede0, 0xbfd98017, + } }, + { { /* 654 */ + 0xde897e55, 0x0447c16f, 0xf75d7ade, 0x290557ff, + 0xfe9586f7, 0xf32f97b3, 0x9f75cfff, 0xfb1771f7, + } }, + { { /* 655 */ + 0xee1934ee, 0xef6137cc, 0xef4c9fd6, 0xfbddd68f, + 0x6def7b73, 0xa431d7fe, 0x97d75e7f, 0xffd80f5b, + } }, + { { /* 656 */ + 0x7bce9d83, 0xdcff22ec, 0xef87763d, 0xfdeddfe7, + 0xa0fc4fff, 0xdbfc3b77, 0x7fdc3ded, 0xf5706fa9, + } }, + { { /* 657 */ + 0x2c403ffb, 0x847fff7f, 0xdeb7ec57, 0xf22fe69c, + 0xd5b50feb, 0xede7afeb, 0xfff08c2f, 0xe8f0537f, + } }, + { { /* 658 */ + 0xb5ffb99d, 0xe78fff66, 0xbe10d981, 0xe3c19c7c, + 0x27339cd1, 0xff6d0cbc, 0xefb7fcb7, 0xffffa0df, + } }, + { { /* 659 */ + 0xfe7bbf0b, 0x353fa3ff, 0x97cd13cc, 0xfb277637, + 0x7e6ccfd6, 0xed31ec50, 0xfc1c677c, 0x5fbff6fa, + } }, + { { /* 660 */ + 0xae2f0fba, 0x7ffea3ad, 0xde74fcf0, 0xf200ffef, + 0xfea2fbbf, 0xbcff3daf, 0x5fb9f694, 0x3f8ff3ad, + } }, + { { /* 661 */ + 0xa01ff26c, 0x01bfffef, 0x70057728, 0xda03ff35, + 0xc7fad2f9, 0x5c1d3fbf, 0xec33ff3a, 0xfe9cb7af, + } }, + { { /* 662 */ + 0x7a9f5236, 0xe722bffa, 0xfcff9ff7, 0xb61d2fbb, + 0x1dfded06, 0xefdf7dd7, 0xf166eb23, 0x0dc07ed9, + } }, + { { /* 663 */ + 0xdfbf3d3d, 0xba83c945, 0x9dd07dd1, 0xcf737b87, + 0xc3f59ff3, 0xc5fedf0d, 0x83020cb3, 0xaec0e879, + } }, + { { /* 664 */ + 0x6f0fc773, 0x093ffd7d, 0x0157fff1, 0x01ff62fb, + 0x3bf3fdb4, 0x43b2b013, 0xff305ed3, 0xeb9f0fff, + } }, + { { /* 665 */ + 0xf203feef, 0xfb893fef, 0x9e9937a9, 0xa72cdef9, + 0xc1f63733, 0xfe3e812e, 0xf2f75d20, 0x69d7d585, + } }, + { { /* 666 */ + 0xffffffff, 0xff6fdb07, 0xd97fc4ff, 0xbe0fefce, + 0xf05ef17b, 0xffb7f6cf, 0xef845ef7, 0x0edfd7cb, + } }, + { { /* 667 */ + 0xfcffff08, 0xffffee3f, 0xd7ff13ff, 0x7ffdaf0f, + 0x1ffabdc7, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 668 */ + 0x00000000, 0xe7400000, 0xf933bd38, 0xfeed7feb, + 0x7c767fe8, 0xffefb3f7, 0xd8b7feaf, 0xfbbfff6f, + } }, + { { /* 669 */ + 0xdbf7f8fb, 0xe2f91752, 0x754785c8, 0xe3ef9090, + 0x3f6d9ef4, 0x0536ee2e, 0x7ff3f7bc, 0x7f3fa07b, + } }, + { { /* 670 */ + 0xeb600567, 0x6601babe, 0x583ffcd8, 0x87dfcaf7, + 0xffa0bfcd, 0xfebf5bcd, 0xefa7b6fd, 0xdf9c77ef, + } }, + { { /* 671 */ + 0xf8773fb7, 0xb7fc9d27, 0xdfefcab5, 0xf1b6fb5a, + 0xef1fec39, 0x7ffbfbbf, 0xdafe000d, 0x4e7fbdfb, + } }, + { { /* 672 */ + 0x5ac033ff, 0x9ffebff5, 0x005fffbf, 0xfdf80000, + 0x6ffdffca, 0xa001cffd, 0xfbf2dfff, 0xff7fdfbf, + } }, + { { /* 673 */ + 0x080ffeda, 0xbfffba08, 0xeed77afd, 0x67f9fbeb, + 0xff93e044, 0x9f57df97, 0x08dffef7, 0xfedfdf80, + } }, + { { /* 674 */ + 0xf7feffc5, 0x6803fffb, 0x6bfa67fb, 0x5fe27fff, + 0xff73ffff, 0xe7fb87df, 0xf7a7ebfd, 0xefc7bf7e, + } }, + { { /* 675 */ + 0xdf821ef3, 0xdf7e76ff, 0xda7d79c9, 0x1e9befbe, + 0x77fb7ce0, 0xfffb87be, 0xffdb1bff, 0x4fe03f5c, + } }, + { { /* 676 */ + 0x5f0e7fff, 0xddbf77ff, 0xfffff04f, 0x0ff8ffff, + 0xfddfa3be, 0xfffdfc1c, 0xfb9e1f7d, 0xdedcbdff, + } }, + { { /* 677 */ + 0xbafb3f6f, 0xfbefdf7f, 0x2eec7d1b, 0xf2f7af8e, + 0xcfee7b0f, 0x77c61d96, 0xfff57e07, 0x7fdfd982, + } }, + { { /* 678 */ + 0xc7ff5ee6, 0x79effeee, 0xffcf9a56, 0xde5efe5f, + 0xf9e8896e, 0xe6c4f45e, 0xbe7c0001, 0xdddf3b7f, + } }, + { { /* 679 */ + 0xe9efd59d, 0xde5334ac, 0x4bf7f573, 0x9eff7b4f, + 0x476eb8fe, 0xff450dfb, 0xfbfeabfd, 0xddffe9d7, + } }, + { { /* 680 */ + 0x7fffedf7, 0x7eebddfd, 0xb7ffcfe7, 0xef91bde9, + 0xd77c5d75, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 681 */ + 0x00000000, 0xfa800000, 0xb4f1ffee, 0x2fefbf76, + 0x77bfb677, 0xfffd9fbf, 0xf6ae95bf, 0x7f3b75ff, + } }, + { { /* 682 */ + 0x0af9a7f5, 0x00000000, 0x00000000, 0x2bddfbd0, + 0x9a7ff633, 0xd6fcfdab, 0xbfebf9e6, 0xf41fdfdf, + } }, + { { /* 683 */ + 0xffffa6fd, 0xf37b4aff, 0xfef97fb7, 0x1d5cb6ff, + 0xe5ff7ff6, 0x24041f7b, 0xf99ebe05, 0xdff2dbe3, + } }, + { { /* 684 */ + 0xfdff6fef, 0xcbfcd679, 0xefffebfd, 0x0000001f, + 0x98000000, 0x8017e148, 0x00fe6a74, 0xfdf16d7f, + } }, + { { /* 685 */ + 0xfef3b87f, 0xf176e01f, 0x7b3fee96, 0xfffdeb8d, + 0xcbb3adff, 0xe17f84ef, 0xbff04daa, 0xfe3fbf3f, + } }, + { { /* 686 */ + 0xffd7ebff, 0xcf7fffdf, 0x85edfffb, 0x07bcd73f, + 0xfe0faeff, 0x76bffdaf, 0x37bbfaef, 0xa3ba7fdc, + } }, + { { /* 687 */ + 0x56f7b6ff, 0xe7df60f8, 0x4cdfff61, 0xff45b0fb, + 0x3ffa7ded, 0x18fc1fff, 0xe3afffff, 0xdf83c7d3, + } }, + { { /* 688 */ + 0xef7dfb57, 0x1378efff, 0x5ff7fec0, 0x5ee334bb, + 0xeff6f70d, 0x00bfd7fe, 0xf7f7f59d, 0xffe051de, + } }, + { { /* 689 */ + 0x037ffec9, 0xbfef5f01, 0x60a79ff1, 0xf1ffef1d, + 0x0000000f, 0x00000000, 0x00000000, 0x00000000, + } }, + { { /* 690 */ + 0x00000000, 0x00000000, 0x00000000, 0x3c800000, + 0xd91ffb4d, 0xfee37b3a, 0xdc7f3fe9, 0x0000003f, + } }, + { { /* 691 */ + 0x50000000, 0xbe07f51f, 0xf91bfc1d, 0x71ffbc1e, + 0x5bbe6ff9, 0x9b1b5796, 0xfffc7fff, 0xafe7872e, + } }, + { { /* 692 */ + 0xf34febf5, 0xe725dffd, 0x5d440bdc, 0xfddd5747, + 0x7790ed3f, 0x8ac87d7f, 0xf3f9fafa, 0xef4b202a, + } }, + { { /* 693 */ + 0x79cff5ff, 0x0ba5abd3, 0xfb8ff77a, 0x001f8ebd, + 0x00000000, 0xfd4ef300, 0x88001a57, 0x7654aeac, + } }, + { { /* 694 */ + 0xcdff17ad, 0xf42fffb2, 0xdbff5baa, 0x00000002, + 0x73c00000, 0x2e3ff9ea, 0xbbfffa8e, 0xffd376bc, + } }, + { { /* 695 */ + 0x7e72eefe, 0xe7f77ebd, 0xcefdf77f, 0x00000ff5, + 0x00000000, 0xdb9ba900, 0x917fa4c7, 0x7ecef8ca, + } }, + { { /* 696 */ + 0xc7e77d7a, 0xdcaecbbd, 0x8f76fd7e, 0x7cf391d3, + 0x4c2f01e5, 0xa360ed77, 0x5ef807db, 0x21811df7, + } }, + { { /* 697 */ + 0x309c6be0, 0xfade3b3a, 0xc3f57f53, 0x07ba61cd, + 0x00000000, 0x00000000, 0x00000000, 0xbefe26e0, + } }, + { { /* 698 */ + 0xebb503f9, 0xe9cbe36d, 0xbfde9c2f, 0xabbf9f83, + 0xffd51ff7, 0xdffeb7df, 0xffeffdae, 0xeffdfb7e, + } }, + { { /* 699 */ + 0x6ebfaaff, 0x00000000, 0x00000000, 0xb6200000, + 0xbe9e7fcd, 0x58f162b3, 0xfd7bf10d, 0xbefde9f1, + } }, + { { /* 700 */ + 0x5f6dc6c3, 0x69ffff3d, 0xfbf4ffcf, 0x4ff7dcfb, + 0x11372000, 0x00000015, 0x00000000, 0x00000000, + } }, + { { /* 701 */ + 0x00003000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + } }, +}, +{ + /* aa */ + LEAF( 0, 0), + /* ab */ + LEAF( 1, 1), + /* af */ + LEAF( 2, 2), LEAF( 2, 3), + /* ak */ + LEAF( 4, 4), LEAF( 4, 5), LEAF( 4, 6), LEAF( 4, 7), + LEAF( 4, 8), + /* am */ + LEAF( 9, 9), LEAF( 9, 10), + /* an */ + LEAF( 11, 11), + /* ar */ + LEAF( 12, 12), + /* as */ + LEAF( 13, 13), + /* ast */ + LEAF( 14, 11), LEAF( 14, 14), + /* av */ + LEAF( 16, 15), + /* ay */ + LEAF( 17, 16), + /* az_az */ + LEAF( 18, 17), LEAF( 18, 18), LEAF( 18, 19), + /* az_ir */ + LEAF( 21, 20), + /* ba */ + LEAF( 22, 21), + /* be */ + LEAF( 23, 22), + /* ber_dz */ + LEAF( 24, 23), LEAF( 24, 24), LEAF( 24, 25), LEAF( 24, 26), + /* ber_ma */ + LEAF( 28, 27), + /* bg */ + LEAF( 29, 28), + /* bh */ + LEAF( 30, 29), + /* bi */ + LEAF( 31, 30), + /* bin */ + LEAF( 32, 31), LEAF( 32, 32), LEAF( 32, 33), + /* bm */ + LEAF( 35, 23), LEAF( 35, 34), LEAF( 35, 35), + /* bn */ + LEAF( 38, 36), + /* bo */ + LEAF( 39, 37), + /* br */ + LEAF( 40, 38), + /* brx */ + LEAF( 41, 39), + /* bs */ + LEAF( 42, 23), LEAF( 42, 40), + /* bua */ + LEAF( 44, 41), + /* byn */ + LEAF( 45, 42), LEAF( 45, 43), + /* ca */ + LEAF( 47, 44), LEAF( 47, 45), + /* ch */ + LEAF( 49, 46), + /* chm */ + LEAF( 50, 47), + /* chr */ + LEAF( 51, 48), + /* co */ + LEAF( 52, 49), LEAF( 52, 50), + /* crh */ + LEAF( 54, 51), LEAF( 54, 52), + /* cs */ + LEAF( 56, 53), LEAF( 56, 54), + /* csb */ + LEAF( 58, 55), LEAF( 58, 56), + /* cu */ + LEAF( 60, 57), + /* cv */ + LEAF( 61, 58), LEAF( 61, 59), + /* cy */ + LEAF( 63, 60), LEAF( 63, 61), LEAF( 63, 62), + /* da */ + LEAF( 66, 63), + /* de */ + LEAF( 67, 64), + /* doi */ + LEAF( 68, 65), + /* dv */ + LEAF( 69, 66), + /* ee */ + LEAF( 70, 31), LEAF( 70, 67), LEAF( 70, 68), LEAF( 70, 69), + /* el */ + LEAF( 74, 70), + /* en */ + LEAF( 75, 71), + /* eo */ + LEAF( 76, 23), LEAF( 76, 72), + /* et */ + LEAF( 78, 73), LEAF( 78, 74), + /* eu */ + LEAF( 80, 75), + /* ff */ + LEAF( 81, 23), LEAF( 81, 76), LEAF( 81, 77), + /* fi */ + LEAF( 84, 78), LEAF( 84, 74), + /* fil */ + LEAF( 86, 79), + /* fj */ + LEAF( 87, 23), + /* fo */ + LEAF( 88, 80), + /* fur */ + LEAF( 89, 81), + /* fy */ + LEAF( 90, 82), + /* ga */ + LEAF( 91, 83), LEAF( 91, 84), LEAF( 91, 85), + /* gd */ + LEAF( 94, 86), + /* gez */ + LEAF( 95, 87), LEAF( 95, 88), + /* gn */ + LEAF( 97, 89), LEAF( 97, 90), LEAF( 97, 91), + /* gu */ + LEAF(100, 92), + /* gv */ + LEAF(101, 93), + /* ha */ + LEAF(102, 23), LEAF(102, 94), LEAF(102, 95), + /* haw */ + LEAF(105, 23), LEAF(105, 96), LEAF(105, 97), + /* he */ + LEAF(108, 98), + /* hsb */ + LEAF(109, 99), LEAF(109,100), + /* ht */ + LEAF(111,101), + /* hu */ + LEAF(112,102), LEAF(112,103), + /* hy */ + LEAF(114,104), + /* hz */ + LEAF(115, 23), LEAF(115,105), LEAF(115,106), + /* id */ + LEAF(118,107), + /* ig */ + LEAF(119, 23), LEAF(119,108), + /* ii */ + LEAF(121,109), LEAF(121,109), LEAF(121,109), LEAF(121,109), + LEAF(121,110), + /* ik */ + LEAF(126,111), + /* is */ + LEAF(127,112), + /* it */ + LEAF(128,113), + /* iu */ + LEAF(129,114), LEAF(129,115), LEAF(129,116), + /* ja */ + LEAF(132,117), LEAF(132,118), LEAF(132,119), LEAF(132,120), + LEAF(132,121), LEAF(132,122), LEAF(132,123), LEAF(132,124), + LEAF(132,125), LEAF(132,126), LEAF(132,127), LEAF(132,128), + LEAF(132,129), LEAF(132,130), LEAF(132,131), LEAF(132,132), + LEAF(132,133), LEAF(132,134), LEAF(132,135), LEAF(132,136), + LEAF(132,137), LEAF(132,138), LEAF(132,139), LEAF(132,140), + LEAF(132,141), LEAF(132,142), LEAF(132,143), LEAF(132,144), + LEAF(132,145), LEAF(132,146), LEAF(132,147), LEAF(132,148), + LEAF(132,149), LEAF(132,150), LEAF(132,151), LEAF(132,152), + LEAF(132,153), LEAF(132,154), LEAF(132,155), LEAF(132,156), + LEAF(132,157), LEAF(132,158), LEAF(132,159), LEAF(132,160), + LEAF(132,161), LEAF(132,162), LEAF(132,163), LEAF(132,164), + LEAF(132,165), LEAF(132,166), LEAF(132,167), LEAF(132,168), + LEAF(132,169), LEAF(132,170), LEAF(132,171), LEAF(132,172), + LEAF(132,173), LEAF(132,174), LEAF(132,175), LEAF(132,176), + LEAF(132,177), LEAF(132,178), LEAF(132,179), LEAF(132,180), + LEAF(132,181), LEAF(132,182), LEAF(132,183), LEAF(132,184), + LEAF(132,185), LEAF(132,186), LEAF(132,187), LEAF(132,188), + LEAF(132,189), LEAF(132,190), LEAF(132,191), LEAF(132,192), + LEAF(132,193), LEAF(132,194), LEAF(132,195), LEAF(132,196), + LEAF(132,197), LEAF(132,198), LEAF(132,199), + /* jv */ + LEAF(215,200), + /* ka */ + LEAF(216,201), + /* kaa */ + LEAF(217,202), + /* ki */ + LEAF(218, 23), LEAF(218,203), + /* kk */ + LEAF(220,204), + /* kl */ + LEAF(221,205), LEAF(221,206), + /* km */ + LEAF(223,207), + /* kn */ + LEAF(224,208), + /* ko */ + LEAF(225,209), LEAF(225,210), LEAF(225,211), LEAF(225,212), + LEAF(225,213), LEAF(225,214), LEAF(225,215), LEAF(225,216), + LEAF(225,217), LEAF(225,218), LEAF(225,219), LEAF(225,220), + LEAF(225,221), LEAF(225,222), LEAF(225,223), LEAF(225,224), + LEAF(225,225), LEAF(225,226), LEAF(225,227), LEAF(225,228), + LEAF(225,229), LEAF(225,230), LEAF(225,231), LEAF(225,232), + LEAF(225,233), LEAF(225,234), LEAF(225,235), LEAF(225,236), + LEAF(225,237), LEAF(225,238), LEAF(225,239), LEAF(225,240), + LEAF(225,241), LEAF(225,242), LEAF(225,243), LEAF(225,244), + LEAF(225,245), LEAF(225,246), LEAF(225,247), LEAF(225,248), + LEAF(225,249), LEAF(225,250), LEAF(225,251), LEAF(225,252), + LEAF(225,253), + /* kr */ + LEAF(270, 23), LEAF(270,254), LEAF(270,255), + /* ks */ + LEAF(273,256), + /* ku_am */ + LEAF(274,257), LEAF(274,258), + /* ku_iq */ + LEAF(276,259), + /* ku_tr */ + LEAF(277,260), LEAF(277,261), + /* kum */ + LEAF(279,262), + /* kv */ + LEAF(280,263), + /* kw */ + LEAF(281, 23), LEAF(281, 96), LEAF(281,264), + /* ky */ + LEAF(284,265), + /* la */ + LEAF(285, 23), LEAF(285,266), + /* lah */ + LEAF(287,267), + /* lb */ + LEAF(288,268), + /* lg */ + LEAF(289, 23), LEAF(289,269), + /* li */ + LEAF(291,270), + /* ln */ + LEAF(292,271), LEAF(292,272), LEAF(292, 6), LEAF(292,273), + /* lo */ + LEAF(296,274), + /* lt */ + LEAF(297, 23), LEAF(297,275), + /* lv */ + LEAF(299, 23), LEAF(299,276), + /* mg */ + LEAF(301,277), + /* mh */ + LEAF(302, 23), LEAF(302,278), + /* mi */ + LEAF(304, 23), LEAF(304, 96), LEAF(304,279), + /* mk */ + LEAF(307,280), + /* ml */ + LEAF(308,281), + /* mn_cn */ + LEAF(309,282), + /* mn_mn */ + LEAF(310,283), + /* mni */ + LEAF(311,284), + /* mo */ + LEAF(312,285), LEAF(312, 58), LEAF(312,286), LEAF(312,262), + /* mt */ + LEAF(316,287), LEAF(316,288), + /* my */ + LEAF(318,289), + /* na */ + LEAF(319, 4), LEAF(319,290), + /* nb */ + LEAF(321,291), + /* ne */ + LEAF(322,292), + /* nl */ + LEAF(323,293), + /* nn */ + LEAF(324,294), + /* nqo */ + LEAF(325,295), + /* nso */ + LEAF(326,296), LEAF(326,297), + /* nv */ + LEAF(328,298), LEAF(328,299), LEAF(328,300), LEAF(328,301), + /* ny */ + LEAF(332, 23), LEAF(332,302), + /* oc */ + LEAF(334,303), + /* or */ + LEAF(335,304), + /* ota */ + LEAF(336,305), + /* pa */ + LEAF(337,306), + /* pap_an */ + LEAF(338,307), + /* pap_aw */ + LEAF(339,308), + /* pl */ + LEAF(340, 99), LEAF(340,309), + /* ps_af */ + LEAF(342,310), + /* ps_pk */ + LEAF(343,311), + /* pt */ + LEAF(344,312), + /* qu */ + LEAF(345,308), LEAF(345,313), + /* rm */ + LEAF(347,314), + /* ro */ + LEAF(348,285), LEAF(348, 58), LEAF(348,286), + /* sah */ + LEAF(351,315), + /* sat */ + LEAF(352,316), + /* sc */ + LEAF(353,317), + /* sco */ + LEAF(354, 23), LEAF(354,318), LEAF(354,319), + /* sd */ + LEAF(357,320), + /* se */ + LEAF(358,321), LEAF(358,322), + /* sg */ + LEAF(360,323), + /* sh */ + LEAF(361, 23), LEAF(361, 40), LEAF(361,324), + /* shs */ + LEAF(364,325), LEAF(364,326), + /* si */ + LEAF(366,327), + /* sid */ + LEAF(367,328), LEAF(367, 10), + /* sk */ + LEAF(369,329), LEAF(369,330), + /* sm */ + LEAF(371, 23), LEAF(371, 97), + /* sma */ + LEAF(373,331), + /* smj */ + LEAF(374,332), + /* smn */ + LEAF(375,333), LEAF(375,334), + /* sms */ + LEAF(377,335), LEAF(377,336), LEAF(377,337), + /* sq */ + LEAF(380,338), + /* sr */ + LEAF(381,339), + /* sv */ + LEAF(382,340), + /* syr */ + LEAF(383,341), + /* ta */ + LEAF(384,342), + /* te */ + LEAF(385,343), + /* tg */ + LEAF(386,344), + /* th */ + LEAF(387,345), + /* tig */ + LEAF(388,346), LEAF(388, 43), + /* tk */ + LEAF(390,347), LEAF(390,348), + /* tr */ + LEAF(392,349), LEAF(392, 52), + /* tt */ + LEAF(394,350), + /* ty */ + LEAF(395,351), LEAF(395, 96), LEAF(395,300), + /* ug */ + LEAF(398,352), + /* uk */ + LEAF(399,353), + /* ve */ + LEAF(400, 23), LEAF(400,354), + /* vi */ + LEAF(402,355), LEAF(402,356), LEAF(402,357), LEAF(402,358), + /* vo */ + LEAF(406,359), + /* vot */ + LEAF(407,360), LEAF(407, 74), + /* wa */ + LEAF(409,361), + /* wen */ + LEAF(410, 99), LEAF(410,362), + /* wo */ + LEAF(412,363), LEAF(412,269), + /* yap */ + LEAF(414,364), + /* yo */ + LEAF(415,365), LEAF(415,366), LEAF(415,367), LEAF(415,368), + /* zh_cn */ + LEAF(419,369), LEAF(419,370), LEAF(419,371), LEAF(419,372), + LEAF(419,373), LEAF(419,374), LEAF(419,375), LEAF(419,376), + LEAF(419,377), LEAF(419,378), LEAF(419,379), LEAF(419,380), + LEAF(419,381), LEAF(419,382), LEAF(419,383), LEAF(419,384), + LEAF(419,385), LEAF(419,386), LEAF(419,387), LEAF(419,388), + LEAF(419,389), LEAF(419,390), LEAF(419,391), LEAF(419,392), + LEAF(419,393), LEAF(419,394), LEAF(419,395), LEAF(419,396), + LEAF(419,397), LEAF(419,398), LEAF(419,399), LEAF(419,400), + LEAF(419,401), LEAF(419,402), LEAF(419,403), LEAF(419,404), + LEAF(419,405), LEAF(419,406), LEAF(419,407), LEAF(419,408), + LEAF(419,409), LEAF(419,410), LEAF(419,411), LEAF(419,412), + LEAF(419,413), LEAF(419,414), LEAF(419,415), LEAF(419,416), + LEAF(419,417), LEAF(419,418), LEAF(419,419), LEAF(419,420), + LEAF(419,421), LEAF(419,422), LEAF(419,423), LEAF(419,424), + LEAF(419,425), LEAF(419,426), LEAF(419,427), LEAF(419,428), + LEAF(419,429), LEAF(419,430), LEAF(419,431), LEAF(419,432), + LEAF(419,433), LEAF(419,434), LEAF(419,435), LEAF(419,436), + LEAF(419,437), LEAF(419,438), LEAF(419,439), LEAF(419,440), + LEAF(419,441), LEAF(419,442), LEAF(419,443), LEAF(419,444), + LEAF(419,445), LEAF(419,446), LEAF(419,447), LEAF(419,448), + LEAF(419,449), LEAF(419,450), + /* zh_hk */ + LEAF(501,451), LEAF(501,452), LEAF(501,453), LEAF(501,454), + LEAF(501,455), LEAF(501,456), LEAF(501,457), LEAF(501,458), + LEAF(501,459), LEAF(501,460), LEAF(501,461), LEAF(501,462), + LEAF(501,463), LEAF(501,464), LEAF(501,465), LEAF(501,466), + LEAF(501,467), LEAF(501,468), LEAF(501,469), LEAF(501,470), + LEAF(501,471), LEAF(501,472), LEAF(501,473), LEAF(501,474), + LEAF(501,475), LEAF(501,476), LEAF(501,477), LEAF(501,478), + LEAF(501,479), LEAF(501,480), LEAF(501,481), LEAF(501,482), + LEAF(501,483), LEAF(501,484), LEAF(501,485), LEAF(501,486), + LEAF(501,487), LEAF(501,488), LEAF(501,489), LEAF(501,490), + LEAF(501,491), LEAF(501,492), LEAF(501,493), LEAF(501,494), + LEAF(501,495), LEAF(501,496), LEAF(501,497), LEAF(501,498), + LEAF(501,499), LEAF(501,500), LEAF(501,501), LEAF(501,502), + LEAF(501,503), LEAF(501,504), LEAF(501,505), LEAF(501,506), + LEAF(501,507), LEAF(501,508), LEAF(501,509), LEAF(501,510), + LEAF(501,511), LEAF(501,512), LEAF(501,513), LEAF(501,514), + LEAF(501,515), LEAF(501,516), LEAF(501,517), LEAF(501,518), + LEAF(501,519), LEAF(501,520), LEAF(501,521), LEAF(501,522), + LEAF(501,523), LEAF(501,524), LEAF(501,525), LEAF(501,526), + LEAF(501,527), LEAF(501,528), LEAF(501,529), LEAF(501,530), + LEAF(501,531), LEAF(501,532), LEAF(501,533), LEAF(501,534), + LEAF(501,535), LEAF(501,536), LEAF(501,537), LEAF(501,538), + LEAF(501,539), LEAF(501,540), LEAF(501,541), LEAF(501,542), + LEAF(501,543), LEAF(501,544), LEAF(501,545), LEAF(501,546), + LEAF(501,547), LEAF(501,548), LEAF(501,549), LEAF(501,550), + LEAF(501,551), LEAF(501,552), LEAF(501,553), LEAF(501,554), + LEAF(501,555), LEAF(501,556), LEAF(501,557), LEAF(501,558), + LEAF(501,559), LEAF(501,560), LEAF(501,561), LEAF(501,562), + LEAF(501,563), LEAF(501,564), LEAF(501,565), LEAF(501,566), + LEAF(501,567), LEAF(501,568), LEAF(501,569), LEAF(501,570), + LEAF(501,571), LEAF(501,572), LEAF(501,573), LEAF(501,574), + LEAF(501,575), LEAF(501,576), LEAF(501,577), LEAF(501,578), + LEAF(501,579), LEAF(501,580), LEAF(501,581), LEAF(501,582), + LEAF(501,583), LEAF(501,318), LEAF(501,584), LEAF(501,585), + LEAF(501,586), LEAF(501,587), LEAF(501,588), LEAF(501,589), + LEAF(501,590), LEAF(501, 3), LEAF(501,591), LEAF(501,592), + LEAF(501,593), LEAF(501,594), LEAF(501,595), LEAF(501,596), + LEAF(501,580), LEAF(501,597), LEAF(501,598), LEAF(501,599), + LEAF(501,600), LEAF(501,601), LEAF(501,602), LEAF(501,603), + LEAF(501,604), LEAF(501,605), LEAF(501,606), LEAF(501,607), + LEAF(501,608), LEAF(501,609), LEAF(501,610), LEAF(501,611), + LEAF(501,612), LEAF(501,613), LEAF(501,614), LEAF(501,615), + LEAF(501,616), LEAF(501,617), LEAF(501,618), + /* zh_tw */ + LEAF(672,619), LEAF(672,620), LEAF(672,621), LEAF(672,622), + LEAF(672,623), LEAF(672,624), LEAF(672,625), LEAF(672,626), + LEAF(672,627), LEAF(672,628), LEAF(672,629), LEAF(672,630), + LEAF(672,631), LEAF(672,632), LEAF(672,633), LEAF(672,634), + LEAF(672,635), LEAF(672,636), LEAF(672,637), LEAF(672,638), + LEAF(672,639), LEAF(672,640), LEAF(672,641), LEAF(672,642), + LEAF(672,643), LEAF(672,644), LEAF(672,645), LEAF(672,646), + LEAF(672,647), LEAF(672,648), LEAF(672,649), LEAF(672,650), + LEAF(672,651), LEAF(672,652), LEAF(672,653), LEAF(672,654), + LEAF(672,655), LEAF(672,656), LEAF(672,657), LEAF(672,658), + LEAF(672,659), LEAF(672,660), LEAF(672,661), LEAF(672,662), + LEAF(672,663), LEAF(672,664), LEAF(672,665), LEAF(672,666), + LEAF(672,667), LEAF(672,668), LEAF(672,669), LEAF(672,670), + LEAF(672,671), LEAF(672,672), LEAF(672,673), LEAF(672,674), + LEAF(672,675), LEAF(672,676), LEAF(672,677), LEAF(672,678), + LEAF(672,679), LEAF(672,680), LEAF(672,681), LEAF(672,682), + LEAF(672,683), LEAF(672,684), LEAF(672,685), LEAF(672,686), + LEAF(672,687), LEAF(672,688), LEAF(672,689), LEAF(672,690), + LEAF(672,691), LEAF(672,692), LEAF(672,693), LEAF(672,694), + LEAF(672,695), LEAF(672,696), LEAF(672,697), LEAF(672,698), + LEAF(672,699), LEAF(672,700), LEAF(672,701), +}, +{ + /* aa */ + 0x0000, + /* ab */ + 0x0004, + /* af */ + 0x0000, 0x0001, + /* ak */ + 0x0000, 0x0001, 0x0002, 0x0003, 0x001e, + /* am */ + 0x0012, 0x0013, + /* an */ + 0x0000, + /* ar */ + 0x0006, + /* as */ + 0x0009, + /* ast */ + 0x0000, 0x001e, + /* av */ + 0x0004, + /* ay */ + 0x0000, + /* az_az */ + 0x0000, 0x0001, 0x0002, + /* az_ir */ + 0x0006, + /* ba */ + 0x0004, + /* be */ + 0x0004, + /* ber_dz */ + 0x0000, 0x0001, 0x0002, 0x001e, + /* ber_ma */ + 0x002d, + /* bg */ + 0x0004, + /* bh */ + 0x0009, + /* bi */ + 0x0000, + /* bin */ + 0x0000, 0x0003, 0x001e, + /* bm */ + 0x0000, 0x0001, 0x0002, + /* bn */ + 0x0009, + /* bo */ + 0x000f, + /* br */ + 0x0000, + /* brx */ + 0x0009, + /* bs */ + 0x0000, 0x0001, + /* bua */ + 0x0004, + /* byn */ + 0x0012, 0x0013, + /* ca */ + 0x0000, 0x0001, + /* ch */ + 0x0000, + /* chm */ + 0x0004, + /* chr */ + 0x0013, + /* co */ + 0x0000, 0x0001, + /* crh */ + 0x0000, 0x0001, + /* cs */ + 0x0000, 0x0001, + /* csb */ + 0x0000, 0x0001, + /* cu */ + 0x0004, + /* cv */ + 0x0001, 0x0004, + /* cy */ + 0x0000, 0x0001, 0x001e, + /* da */ + 0x0000, + /* de */ + 0x0000, + /* doi */ + 0x0009, + /* dv */ + 0x0007, + /* ee */ + 0x0000, 0x0001, 0x0002, 0x0003, + /* el */ + 0x0003, + /* en */ + 0x0000, + /* eo */ + 0x0000, 0x0001, + /* et */ + 0x0000, 0x0001, + /* eu */ + 0x0000, + /* ff */ + 0x0000, 0x0001, 0x0002, + /* fi */ + 0x0000, 0x0001, + /* fil */ + 0x0000, + /* fj */ + 0x0000, + /* fo */ + 0x0000, + /* fur */ + 0x0000, + /* fy */ + 0x0000, + /* ga */ + 0x0000, 0x0001, 0x001e, + /* gd */ + 0x0000, + /* gez */ + 0x0012, 0x0013, + /* gn */ + 0x0000, 0x0001, 0x001e, + /* gu */ + 0x000a, + /* gv */ + 0x0000, + /* ha */ + 0x0000, 0x0001, 0x0002, + /* haw */ + 0x0000, 0x0001, 0x0002, + /* he */ + 0x0005, + /* hsb */ + 0x0000, 0x0001, + /* ht */ + 0x0000, + /* hu */ + 0x0000, 0x0001, + /* hy */ + 0x0005, + /* hz */ + 0x0000, 0x0003, 0x001e, + /* id */ + 0x0000, + /* ig */ + 0x0000, 0x001e, + /* ii */ + 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, + /* ik */ + 0x0004, + /* is */ + 0x0000, + /* it */ + 0x0000, + /* iu */ + 0x0014, 0x0015, 0x0016, + /* ja */ + 0x0030, 0x004e, 0x004f, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, + 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, + 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, + 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, + 0x006d, 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, + 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, + 0x007d, 0x007e, 0x007f, 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, + 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, + 0x008d, 0x008e, 0x008f, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, + 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, + 0x009d, 0x009e, 0x009f, + /* jv */ + 0x0000, + /* ka */ + 0x0010, + /* kaa */ + 0x0004, + /* ki */ + 0x0000, 0x0001, + /* kk */ + 0x0004, + /* kl */ + 0x0000, 0x0001, + /* km */ + 0x0017, + /* kn */ + 0x000c, + /* ko */ + 0x0031, 0x00ac, 0x00ad, 0x00ae, 0x00af, 0x00b0, 0x00b1, 0x00b2, + 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, + 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, 0x00c0, 0x00c1, 0x00c2, + 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, + 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, 0x00d0, 0x00d1, 0x00d2, + 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, + /* kr */ + 0x0000, 0x0001, 0x0002, + /* ks */ + 0x0006, + /* ku_am */ + 0x0004, 0x0005, + /* ku_iq */ + 0x0006, + /* ku_tr */ + 0x0000, 0x0001, + /* kum */ + 0x0004, + /* kv */ + 0x0004, + /* kw */ + 0x0000, 0x0001, 0x0002, + /* ky */ + 0x0004, + /* la */ + 0x0000, 0x0001, + /* lah */ + 0x0006, + /* lb */ + 0x0000, + /* lg */ + 0x0000, 0x0001, + /* li */ + 0x0000, + /* ln */ + 0x0000, 0x0001, 0x0002, 0x0003, + /* lo */ + 0x000e, + /* lt */ + 0x0000, 0x0001, + /* lv */ + 0x0000, 0x0001, + /* mg */ + 0x0000, + /* mh */ + 0x0000, 0x0001, + /* mi */ + 0x0000, 0x0001, 0x001e, + /* mk */ + 0x0004, + /* ml */ + 0x000d, + /* mn_cn */ + 0x0018, + /* mn_mn */ + 0x0004, + /* mni */ + 0x0009, + /* mo */ + 0x0000, 0x0001, 0x0002, 0x0004, + /* mt */ + 0x0000, 0x0001, + /* my */ + 0x0010, + /* na */ + 0x0000, 0x0001, + /* nb */ + 0x0000, + /* ne */ + 0x0009, + /* nl */ + 0x0000, + /* nn */ + 0x0000, + /* nqo */ + 0x0007, + /* nso */ + 0x0000, 0x0001, + /* nv */ + 0x0000, 0x0001, 0x0002, 0x0003, + /* ny */ + 0x0000, 0x0001, + /* oc */ + 0x0000, + /* or */ + 0x000b, + /* ota */ + 0x0006, + /* pa */ + 0x000a, + /* pap_an */ + 0x0000, + /* pap_aw */ + 0x0000, + /* pl */ + 0x0000, 0x0001, + /* ps_af */ + 0x0006, + /* ps_pk */ + 0x0006, + /* pt */ + 0x0000, + /* qu */ + 0x0000, 0x0002, + /* rm */ + 0x0000, + /* ro */ + 0x0000, 0x0001, 0x0002, + /* sah */ + 0x0004, + /* sat */ + 0x0009, + /* sc */ + 0x0000, + /* sco */ + 0x0000, 0x0001, 0x0002, + /* sd */ + 0x0006, + /* se */ + 0x0000, 0x0001, + /* sg */ + 0x0000, + /* sh */ + 0x0000, 0x0001, 0x0004, + /* shs */ + 0x0000, 0x0003, + /* si */ + 0x000d, + /* sid */ + 0x0012, 0x0013, + /* sk */ + 0x0000, 0x0001, + /* sm */ + 0x0000, 0x0002, + /* sma */ + 0x0000, + /* smj */ + 0x0000, + /* smn */ + 0x0000, 0x0001, + /* sms */ + 0x0000, 0x0001, 0x0002, + /* sq */ + 0x0000, + /* sr */ + 0x0004, + /* sv */ + 0x0000, + /* syr */ + 0x0007, + /* ta */ + 0x000b, + /* te */ + 0x000c, + /* tg */ + 0x0004, + /* th */ + 0x000e, + /* tig */ + 0x0012, 0x0013, + /* tk */ + 0x0000, 0x0001, + /* tr */ + 0x0000, 0x0001, + /* tt */ + 0x0004, + /* ty */ + 0x0000, 0x0001, 0x0002, + /* ug */ + 0x0006, + /* uk */ + 0x0004, + /* ve */ + 0x0000, 0x001e, + /* vi */ + 0x0000, 0x0001, 0x0003, 0x001e, + /* vo */ + 0x0000, + /* vot */ + 0x0000, 0x0001, + /* wa */ + 0x0000, + /* wen */ + 0x0000, 0x0001, + /* wo */ + 0x0000, 0x0001, + /* yap */ + 0x0000, + /* yo */ + 0x0000, 0x0001, 0x0003, 0x001e, + /* zh_cn */ + 0x0002, 0x004e, 0x004f, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, + 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, + 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, + 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, + 0x006d, 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, + 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, + 0x007d, 0x007e, 0x007f, 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, + 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, + 0x008d, 0x008e, 0x008f, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, + 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, + 0x009e, 0x009f, + /* zh_hk */ + 0x0030, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, + 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, 0x0040, 0x0041, 0x0042, + 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, + 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 0x0050, 0x0051, 0x0052, + 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, + 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062, + 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, + 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, + 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, + 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, 0x0080, 0x0081, 0x0082, + 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, + 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, 0x0090, 0x0091, 0x0092, + 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, + 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, 0x0200, 0x0201, 0x0203, + 0x0207, 0x020c, 0x020d, 0x020e, 0x020f, 0x0210, 0x0211, 0x0219, + 0x021a, 0x021c, 0x021d, 0x0220, 0x0221, 0x022a, 0x022b, 0x022c, + 0x022d, 0x022f, 0x0232, 0x0235, 0x0236, 0x023c, 0x023e, 0x023f, + 0x0244, 0x024d, 0x024e, 0x0251, 0x0255, 0x025e, 0x0262, 0x0266, + 0x0267, 0x0268, 0x0269, 0x0272, 0x0275, 0x0276, 0x0277, 0x0278, + 0x0279, 0x027a, 0x027d, 0x0280, 0x0281, 0x0282, 0x0283, 0x0289, + 0x028a, 0x028b, 0x028c, 0x028d, 0x028e, 0x0294, 0x0297, 0x0298, + 0x029a, 0x029d, 0x02a6, + /* zh_tw */ + 0x004e, 0x004f, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, + 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, + 0x005e, 0x005f, 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, + 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, + 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, + 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, + 0x007e, 0x007f, 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, + 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, + 0x008e, 0x008f, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, + 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, + 0x009e, 0x009f, 0x00fa, +}, +{ + 0, /* aa */ + 1, /* ab */ + 2, /* af */ + 190, /* ak */ + 3, /* am */ + 191, /* an */ + 4, /* ar */ + 5, /* as */ + 6, /* ast */ + 7, /* av */ + 8, /* ay */ + 9, /* az_az */ + 10, /* az_ir */ + 11, /* ba */ + 13, /* be */ + 192, /* ber_dz */ + 193, /* ber_ma */ + 14, /* bg */ + 15, /* bh */ + 16, /* bho */ + 17, /* bi */ + 18, /* bin */ + 12, /* bm */ + 19, /* bn */ + 20, /* bo */ + 21, /* br */ + 240, /* brx */ + 22, /* bs */ + 23, /* bua */ + 194, /* byn */ + 24, /* ca */ + 25, /* ce */ + 26, /* ch */ + 27, /* chm */ + 28, /* chr */ + 29, /* co */ + 195, /* crh */ + 30, /* cs */ + 196, /* csb */ + 31, /* cu */ + 32, /* cv */ + 33, /* cy */ + 34, /* da */ + 35, /* de */ + 242, /* doi */ + 197, /* dv */ + 36, /* dz */ + 198, /* ee */ + 37, /* el */ + 38, /* en */ + 39, /* eo */ + 40, /* es */ + 41, /* et */ + 42, /* eu */ + 43, /* fa */ + 199, /* fat */ + 48, /* ff */ + 44, /* fi */ + 200, /* fil */ + 45, /* fj */ + 46, /* fo */ + 47, /* fr */ + 49, /* fur */ + 50, /* fy */ + 51, /* ga */ + 52, /* gd */ + 53, /* gez */ + 54, /* gl */ + 55, /* gn */ + 56, /* gu */ + 57, /* gv */ + 58, /* ha */ + 59, /* haw */ + 60, /* he */ + 61, /* hi */ + 201, /* hne */ + 62, /* ho */ + 63, /* hr */ + 202, /* hsb */ + 203, /* ht */ + 64, /* hu */ + 65, /* hy */ + 204, /* hz */ + 66, /* ia */ + 68, /* id */ + 69, /* ie */ + 67, /* ig */ + 205, /* ii */ + 70, /* ik */ + 71, /* io */ + 72, /* is */ + 73, /* it */ + 74, /* iu */ + 75, /* ja */ + 206, /* jv */ + 76, /* ka */ + 77, /* kaa */ + 207, /* kab */ + 78, /* ki */ + 208, /* kj */ + 79, /* kk */ + 80, /* kl */ + 81, /* km */ + 82, /* kn */ + 83, /* ko */ + 84, /* kok */ + 209, /* kr */ + 85, /* ks */ + 86, /* ku_am */ + 210, /* ku_iq */ + 87, /* ku_ir */ + 211, /* ku_tr */ + 88, /* kum */ + 89, /* kv */ + 90, /* kw */ + 212, /* kwm */ + 91, /* ky */ + 92, /* la */ + 238, /* lah */ + 93, /* lb */ + 94, /* lez */ + 213, /* lg */ + 214, /* li */ + 95, /* ln */ + 96, /* lo */ + 97, /* lt */ + 98, /* lv */ + 215, /* mai */ + 99, /* mg */ + 100, /* mh */ + 101, /* mi */ + 102, /* mk */ + 103, /* ml */ + 104, /* mn_cn */ + 216, /* mn_mn */ + 243, /* mni */ + 105, /* mo */ + 106, /* mr */ + 217, /* ms */ + 107, /* mt */ + 108, /* my */ + 218, /* na */ + 109, /* nb */ + 110, /* nds */ + 111, /* ne */ + 219, /* ng */ + 112, /* nl */ + 113, /* nn */ + 114, /* no */ + 239, /* nqo */ + 115, /* nr */ + 116, /* nso */ + 220, /* nv */ + 117, /* ny */ + 118, /* oc */ + 119, /* om */ + 120, /* or */ + 121, /* os */ + 221, /* ota */ + 122, /* pa */ + 222, /* pa_pk */ + 223, /* pap_an */ + 224, /* pap_aw */ + 123, /* pl */ + 124, /* ps_af */ + 125, /* ps_pk */ + 126, /* pt */ + 225, /* qu */ + 226, /* quz */ + 127, /* rm */ + 227, /* rn */ + 128, /* ro */ + 129, /* ru */ + 228, /* rw */ + 130, /* sa */ + 131, /* sah */ + 241, /* sat */ + 229, /* sc */ + 132, /* sco */ + 230, /* sd */ + 133, /* se */ + 134, /* sel */ + 231, /* sg */ + 135, /* sh */ + 136, /* shs */ + 137, /* si */ + 232, /* sid */ + 138, /* sk */ + 139, /* sl */ + 140, /* sm */ + 141, /* sma */ + 142, /* smj */ + 143, /* smn */ + 144, /* sms */ + 233, /* sn */ + 145, /* so */ + 146, /* sq */ + 147, /* sr */ + 148, /* ss */ + 149, /* st */ + 234, /* su */ + 150, /* sv */ + 151, /* sw */ + 152, /* syr */ + 153, /* ta */ + 154, /* te */ + 155, /* tg */ + 156, /* th */ + 157, /* ti_er */ + 158, /* ti_et */ + 159, /* tig */ + 160, /* tk */ + 161, /* tl */ + 162, /* tn */ + 163, /* to */ + 164, /* tr */ + 165, /* ts */ + 166, /* tt */ + 167, /* tw */ + 235, /* ty */ + 168, /* tyv */ + 169, /* ug */ + 170, /* uk */ + 171, /* ur */ + 172, /* uz */ + 173, /* ve */ + 174, /* vi */ + 175, /* vo */ + 176, /* vot */ + 177, /* wa */ + 236, /* wal */ + 178, /* wen */ + 179, /* wo */ + 180, /* xh */ + 181, /* yap */ + 182, /* yi */ + 183, /* yo */ + 237, /* za */ + 184, /* zh_cn */ + 185, /* zh_hk */ + 186, /* zh_mo */ + 187, /* zh_sg */ + 188, /* zh_tw */ + 189, /* zu */ +}, +{ + 0, /* aa */ + 1, /* ab */ + 2, /* af */ + 4, /* am */ + 6, /* ar */ + 7, /* as */ + 8, /* ast */ + 9, /* av */ + 10, /* ay */ + 11, /* az_az */ + 12, /* az_ir */ + 13, /* ba */ + 22, /* bm */ + 14, /* be */ + 17, /* bg */ + 18, /* bh */ + 19, /* bho */ + 20, /* bi */ + 21, /* bin */ + 23, /* bn */ + 24, /* bo */ + 25, /* br */ + 27, /* bs */ + 28, /* bua */ + 30, /* ca */ + 31, /* ce */ + 32, /* ch */ + 33, /* chm */ + 34, /* chr */ + 35, /* co */ + 37, /* cs */ + 39, /* cu */ + 40, /* cv */ + 41, /* cy */ + 42, /* da */ + 43, /* de */ + 46, /* dz */ + 48, /* el */ + 49, /* en */ + 50, /* eo */ + 51, /* es */ + 52, /* et */ + 53, /* eu */ + 54, /* fa */ + 57, /* fi */ + 59, /* fj */ + 60, /* fo */ + 61, /* fr */ + 56, /* ff */ + 62, /* fur */ + 63, /* fy */ + 64, /* ga */ + 65, /* gd */ + 66, /* gez */ + 67, /* gl */ + 68, /* gn */ + 69, /* gu */ + 70, /* gv */ + 71, /* ha */ + 72, /* haw */ + 73, /* he */ + 74, /* hi */ + 76, /* ho */ + 77, /* hr */ + 80, /* hu */ + 81, /* hy */ + 83, /* ia */ + 86, /* ig */ + 84, /* id */ + 85, /* ie */ + 88, /* ik */ + 89, /* io */ + 90, /* is */ + 91, /* it */ + 92, /* iu */ + 93, /* ja */ + 95, /* ka */ + 96, /* kaa */ + 98, /* ki */ + 100, /* kk */ + 101, /* kl */ + 102, /* km */ + 103, /* kn */ + 104, /* ko */ + 105, /* kok */ + 107, /* ks */ + 108, /* ku_am */ + 110, /* ku_ir */ + 112, /* kum */ + 113, /* kv */ + 114, /* kw */ + 116, /* ky */ + 117, /* la */ + 119, /* lb */ + 120, /* lez */ + 123, /* ln */ + 124, /* lo */ + 125, /* lt */ + 126, /* lv */ + 128, /* mg */ + 129, /* mh */ + 130, /* mi */ + 131, /* mk */ + 132, /* ml */ + 133, /* mn_cn */ + 136, /* mo */ + 137, /* mr */ + 139, /* mt */ + 140, /* my */ + 142, /* nb */ + 143, /* nds */ + 144, /* ne */ + 146, /* nl */ + 147, /* nn */ + 148, /* no */ + 150, /* nr */ + 151, /* nso */ + 153, /* ny */ + 154, /* oc */ + 155, /* om */ + 156, /* or */ + 157, /* os */ + 159, /* pa */ + 163, /* pl */ + 164, /* ps_af */ + 165, /* ps_pk */ + 166, /* pt */ + 169, /* rm */ + 171, /* ro */ + 172, /* ru */ + 174, /* sa */ + 175, /* sah */ + 178, /* sco */ + 180, /* se */ + 181, /* sel */ + 183, /* sh */ + 184, /* shs */ + 185, /* si */ + 187, /* sk */ + 188, /* sl */ + 189, /* sm */ + 190, /* sma */ + 191, /* smj */ + 192, /* smn */ + 193, /* sms */ + 195, /* so */ + 196, /* sq */ + 197, /* sr */ + 198, /* ss */ + 199, /* st */ + 201, /* sv */ + 202, /* sw */ + 203, /* syr */ + 204, /* ta */ + 205, /* te */ + 206, /* tg */ + 207, /* th */ + 208, /* ti_er */ + 209, /* ti_et */ + 210, /* tig */ + 211, /* tk */ + 212, /* tl */ + 213, /* tn */ + 214, /* to */ + 215, /* tr */ + 216, /* ts */ + 217, /* tt */ + 218, /* tw */ + 220, /* tyv */ + 221, /* ug */ + 222, /* uk */ + 223, /* ur */ + 224, /* uz */ + 225, /* ve */ + 226, /* vi */ + 227, /* vo */ + 228, /* vot */ + 229, /* wa */ + 231, /* wen */ + 232, /* wo */ + 233, /* xh */ + 234, /* yap */ + 235, /* yi */ + 236, /* yo */ + 238, /* zh_cn */ + 239, /* zh_hk */ + 240, /* zh_mo */ + 241, /* zh_sg */ + 242, /* zh_tw */ + 243, /* zu */ + 3, /* ak */ + 5, /* an */ + 15, /* ber_dz */ + 16, /* ber_ma */ + 29, /* byn */ + 36, /* crh */ + 38, /* csb */ + 45, /* dv */ + 47, /* ee */ + 55, /* fat */ + 58, /* fil */ + 75, /* hne */ + 78, /* hsb */ + 79, /* ht */ + 82, /* hz */ + 87, /* ii */ + 94, /* jv */ + 97, /* kab */ + 99, /* kj */ + 106, /* kr */ + 109, /* ku_iq */ + 111, /* ku_tr */ + 115, /* kwm */ + 121, /* lg */ + 122, /* li */ + 127, /* mai */ + 134, /* mn_mn */ + 138, /* ms */ + 141, /* na */ + 145, /* ng */ + 152, /* nv */ + 158, /* ota */ + 160, /* pa_pk */ + 161, /* pap_an */ + 162, /* pap_aw */ + 167, /* qu */ + 168, /* quz */ + 170, /* rn */ + 173, /* rw */ + 177, /* sc */ + 179, /* sd */ + 182, /* sg */ + 186, /* sid */ + 194, /* sn */ + 200, /* su */ + 219, /* ty */ + 230, /* wal */ + 237, /* za */ + 118, /* lah */ + 149, /* nqo */ + 26, /* brx */ + 176, /* sat */ + 44, /* doi */ + 135, /* mni */ +} +}; + +#define NUM_LANG_CHAR_SET 244 +#define NUM_LANG_SET_MAP 8 + +static const FcChar32 fcLangCountrySets[][NUM_LANG_SET_MAP] = { + { 0x00000600, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, /* az */ + { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, }, /* ber */ + { 0x00000000, 0x00000000, 0x00c00000, 0x00000000, 0x00000000, 0x00000000, 0x000c0000, 0x00000000, }, /* ku */ + { 0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00000000, 0x00000000, 0x01000000, 0x00000000, }, /* mn */ + { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x40000000, 0x00000000, }, /* pa */ + { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x80000000, 0x00000001, }, /* pap */ + { 0x00000000, 0x00000000, 0x00000000, 0x30000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, /* ps */ + { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x60000000, 0x00000000, 0x00000000, 0x00000000, }, /* ti */ + { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1f000000, 0x00000000, 0x00000000, }, /* zh */ +}; + +#define NUM_COUNTRY_SET 9 + +static const FcLangCharSetRange fcLangCharSetRanges[] = { + + { 0, 12 }, /* a */ + { 13, 29 }, /* b */ + { 30, 41 }, /* c */ + { 42, 46 }, /* d */ + { 47, 53 }, /* e */ + { 54, 63 }, /* f */ + { 64, 70 }, /* g */ + { 71, 82 }, /* h */ + { 83, 92 }, /* i */ + { 93, 94 }, /* j */ + { 95, 116 }, /* k */ + { 117, 126 }, /* l */ + { 127, 140 }, /* m */ + { 141, 153 }, /* n */ + { 154, 158 }, /* o */ + { 159, 166 }, /* p */ + { 167, 168 }, /* q */ + { 169, 173 }, /* r */ + { 174, 203 }, /* s */ + { 204, 220 }, /* t */ + { 221, 224 }, /* u */ + { 225, 228 }, /* v */ + { 229, 232 }, /* w */ + { 233, 233 }, /* x */ + { 234, 236 }, /* y */ + { 237, 243 }, /* z */ +}; + diff --git a/project/jni/fontconfig/include/fontconfig/fcfreetype.h b/project/jni/fontconfig/include/fontconfig/fcfreetype.h new file mode 100644 index 000000000..753fdf9da --- /dev/null +++ b/project/jni/fontconfig/include/fontconfig/fcfreetype.h @@ -0,0 +1,59 @@ +/* + * fontconfig/fontconfig/fcfreetype.h + * + * Copyright © 2001 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _FCFREETYPE_H_ +#define _FCFREETYPE_H_ +#include +#include FT_FREETYPE_H + +#ifndef FcPublic +#define FcPublic +#endif + +_FCFUNCPROTOBEGIN + +FcPublic FT_UInt +FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4); + +FcPublic FcCharSet * +FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing); + +FcPublic FcCharSet * +FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks); + +FcPublic FcResult +FcPatternGetFTFace (const FcPattern *p, const char *object, int n, FT_Face *f); + +FcPublic FcBool +FcPatternAddFTFace (FcPattern *p, const char *object, const FT_Face f); + +FcPublic FcPattern * +FcFreeTypeQueryFace (const FT_Face face, + const FcChar8 *file, + int id, + FcBlanks *blanks); + +_FCFUNCPROTOEND + +#endif diff --git a/project/jni/fontconfig/include/fontconfig/fcprivate.h b/project/jni/fontconfig/include/fontconfig/fcprivate.h new file mode 100644 index 000000000..210c1d8a3 --- /dev/null +++ b/project/jni/fontconfig/include/fontconfig/fcprivate.h @@ -0,0 +1,124 @@ +/* + * fontconfig/fontconfig/fcprivate.h + * + * Copyright © 2001 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _FCPRIVATE_H_ +#define _FCPRIVATE_H_ + +/* + * I tried this with functions that took va_list* arguments + * but portability concerns made me change these functions + * into macros (sigh). + */ + +#define FcPatternVapBuild(result, orig, va) \ +{ \ + FcPattern *__p__ = (orig); \ + const char *__o__; \ + FcValue __v__; \ + \ + if (!__p__) \ + { \ + __p__ = FcPatternCreate (); \ + if (!__p__) \ + goto _FcPatternVapBuild_bail0; \ + } \ + for (;;) \ + { \ + __o__ = va_arg (va, const char *); \ + if (!__o__) \ + break; \ + __v__.type = va_arg (va, int); \ + switch (__v__.type) { \ + case FcTypeUnknown: \ + case FcTypeVoid: \ + goto _FcPatternVapBuild_bail1; \ + case FcTypeInteger: \ + __v__.u.i = va_arg (va, int); \ + break; \ + case FcTypeDouble: \ + __v__.u.d = va_arg (va, double); \ + break; \ + case FcTypeString: \ + __v__.u.s = va_arg (va, const FcChar8 *); \ + break; \ + case FcTypeBool: \ + __v__.u.b = va_arg (va, FcBool); \ + break; \ + case FcTypeMatrix: \ + __v__.u.m = va_arg (va, const FcMatrix *); \ + break; \ + case FcTypeCharSet: \ + __v__.u.c = va_arg (va, const FcCharSet *); \ + break; \ + case FcTypeFTFace: \ + __v__.u.f = va_arg (va, FT_Face); \ + break; \ + case FcTypeLangSet: \ + __v__.u.l = va_arg (va, const FcLangSet *); \ + break; \ + } \ + if (!FcPatternAdd (__p__, __o__, __v__, FcTrue)) \ + goto _FcPatternVapBuild_bail1; \ + } \ + result = __p__; \ + goto _FcPatternVapBuild_return; \ + \ +_FcPatternVapBuild_bail1: \ + if (!orig) \ + FcPatternDestroy (__p__); \ +_FcPatternVapBuild_bail0: \ + result = (void*)0; \ + \ +_FcPatternVapBuild_return: \ + ; \ +} + + +#define FcObjectSetVapBuild(__ret__, __first__, __va__) \ +{ \ + FcObjectSet *__os__; \ + const char *__ob__; \ + \ + __ret__ = 0; \ + __os__ = FcObjectSetCreate (); \ + if (!__os__) \ + goto _FcObjectSetVapBuild_bail0; \ + __ob__ = __first__; \ + while (__ob__) \ + { \ + if (!FcObjectSetAdd (__os__, __ob__)) \ + goto _FcObjectSetVapBuild_bail1; \ + __ob__ = va_arg (__va__, const char *); \ + } \ + __ret__ = __os__; \ + \ +_FcObjectSetVapBuild_bail1: \ + if (!__ret__ && __os__) \ + FcObjectSetDestroy (__os__); \ +_FcObjectSetVapBuild_bail0: \ + ; \ +} + +#endif /* _FCPRIVATE_H_ */ + diff --git a/project/jni/fontconfig/include/fontconfig/fontconfig.h b/project/jni/fontconfig/include/fontconfig/fontconfig.h new file mode 100644 index 000000000..1a283a1ce --- /dev/null +++ b/project/jni/fontconfig/include/fontconfig/fontconfig.h @@ -0,0 +1,1010 @@ +/* + * fontconfig/fontconfig/fontconfig.h + * + * Copyright © 2001 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _FONTCONFIG_H_ +#define _FONTCONFIG_H_ + +#include +#include +#include + +#if defined(__GNUC__) && (__GNUC__ >= 4) +#define FC_ATTRIBUTE_SENTINEL(x) __attribute__((__sentinel__(0))) +#else +#define FC_ATTRIBUTE_SENTINEL(x) +#endif + +#ifndef FcPublic +#define FcPublic +#endif + +typedef unsigned char FcChar8; +typedef unsigned short FcChar16; +typedef unsigned int FcChar32; +typedef int FcBool; + +/* + * Current Fontconfig version number. This same number + * must appear in the fontconfig configure.in file. Yes, + * it'a a pain to synchronize version numbers like this. + */ + +#define FC_MAJOR 2 +#define FC_MINOR 11 +#define FC_REVISION 0 + +#define FC_VERSION ((FC_MAJOR * 10000) + (FC_MINOR * 100) + (FC_REVISION)) + +/* + * Current font cache file format version + * This is appended to the cache files so that multiple + * versions of the library will peacefully coexist + * + * Change this value whenever the disk format for the cache file + * changes in any non-compatible way. Try to avoid such changes as + * it means multiple copies of the font information. + */ + +#define FC_CACHE_VERSION "4" + +#define FcTrue 1 +#define FcFalse 0 + +#define FC_FAMILY "family" /* String */ +#define FC_STYLE "style" /* String */ +#define FC_SLANT "slant" /* Int */ +#define FC_WEIGHT "weight" /* Int */ +#define FC_SIZE "size" /* Double */ +#define FC_ASPECT "aspect" /* Double */ +#define FC_PIXEL_SIZE "pixelsize" /* Double */ +#define FC_SPACING "spacing" /* Int */ +#define FC_FOUNDRY "foundry" /* String */ +#define FC_ANTIALIAS "antialias" /* Bool (depends) */ +#define FC_HINTING "hinting" /* Bool (true) */ +#define FC_HINT_STYLE "hintstyle" /* Int */ +#define FC_VERTICAL_LAYOUT "verticallayout" /* Bool (false) */ +#define FC_AUTOHINT "autohint" /* Bool (false) */ +/* FC_GLOBAL_ADVANCE is deprecated. this is simply ignored on freetype 2.4.5 or later */ +#define FC_GLOBAL_ADVANCE "globaladvance" /* Bool (true) */ +#define FC_WIDTH "width" /* Int */ +#define FC_FILE "file" /* String */ +#define FC_INDEX "index" /* Int */ +#define FC_FT_FACE "ftface" /* FT_Face */ +#define FC_RASTERIZER "rasterizer" /* String (deprecated) */ +#define FC_OUTLINE "outline" /* Bool */ +#define FC_SCALABLE "scalable" /* Bool */ +#define FC_SCALE "scale" /* double */ +#define FC_DPI "dpi" /* double */ +#define FC_RGBA "rgba" /* Int */ +#define FC_MINSPACE "minspace" /* Bool use minimum line spacing */ +#define FC_SOURCE "source" /* String (deprecated) */ +#define FC_CHARSET "charset" /* CharSet */ +#define FC_LANG "lang" /* String RFC 3066 langs */ +#define FC_FONTVERSION "fontversion" /* Int from 'head' table */ +#define FC_FULLNAME "fullname" /* String */ +#define FC_FAMILYLANG "familylang" /* String RFC 3066 langs */ +#define FC_STYLELANG "stylelang" /* String RFC 3066 langs */ +#define FC_FULLNAMELANG "fullnamelang" /* String RFC 3066 langs */ +#define FC_CAPABILITY "capability" /* String */ +#define FC_FONTFORMAT "fontformat" /* String */ +#define FC_EMBOLDEN "embolden" /* Bool - true if emboldening needed*/ +#define FC_EMBEDDED_BITMAP "embeddedbitmap" /* Bool - true to enable embedded bitmaps */ +#define FC_DECORATIVE "decorative" /* Bool - true if style is a decorative variant */ +#define FC_LCD_FILTER "lcdfilter" /* Int */ +#define FC_FONT_FEATURES "fontfeatures" /* String */ +#define FC_NAMELANG "namelang" /* String RFC 3866 langs */ +#define FC_PRGNAME "prgname" /* String */ +#define FC_HASH "hash" /* String */ +#define FC_POSTSCRIPT_NAME "postscriptname" /* String */ + +#define FC_CACHE_SUFFIX ".cache-" FC_CACHE_VERSION +#define FC_DIR_CACHE_FILE "fonts.cache-" FC_CACHE_VERSION +#define FC_USER_CACHE_FILE ".fonts.cache-" FC_CACHE_VERSION + +/* Adjust outline rasterizer */ +#define FC_CHAR_WIDTH "charwidth" /* Int */ +#define FC_CHAR_HEIGHT "charheight"/* Int */ +#define FC_MATRIX "matrix" /* FcMatrix */ + +#define FC_WEIGHT_THIN 0 +#define FC_WEIGHT_EXTRALIGHT 40 +#define FC_WEIGHT_ULTRALIGHT FC_WEIGHT_EXTRALIGHT +#define FC_WEIGHT_LIGHT 50 +#define FC_WEIGHT_BOOK 75 +#define FC_WEIGHT_REGULAR 80 +#define FC_WEIGHT_NORMAL FC_WEIGHT_REGULAR +#define FC_WEIGHT_MEDIUM 100 +#define FC_WEIGHT_DEMIBOLD 180 +#define FC_WEIGHT_SEMIBOLD FC_WEIGHT_DEMIBOLD +#define FC_WEIGHT_BOLD 200 +#define FC_WEIGHT_EXTRABOLD 205 +#define FC_WEIGHT_ULTRABOLD FC_WEIGHT_EXTRABOLD +#define FC_WEIGHT_BLACK 210 +#define FC_WEIGHT_HEAVY FC_WEIGHT_BLACK +#define FC_WEIGHT_EXTRABLACK 215 +#define FC_WEIGHT_ULTRABLACK FC_WEIGHT_EXTRABLACK + +#define FC_SLANT_ROMAN 0 +#define FC_SLANT_ITALIC 100 +#define FC_SLANT_OBLIQUE 110 + +#define FC_WIDTH_ULTRACONDENSED 50 +#define FC_WIDTH_EXTRACONDENSED 63 +#define FC_WIDTH_CONDENSED 75 +#define FC_WIDTH_SEMICONDENSED 87 +#define FC_WIDTH_NORMAL 100 +#define FC_WIDTH_SEMIEXPANDED 113 +#define FC_WIDTH_EXPANDED 125 +#define FC_WIDTH_EXTRAEXPANDED 150 +#define FC_WIDTH_ULTRAEXPANDED 200 + +#define FC_PROPORTIONAL 0 +#define FC_DUAL 90 +#define FC_MONO 100 +#define FC_CHARCELL 110 + +/* sub-pixel order */ +#define FC_RGBA_UNKNOWN 0 +#define FC_RGBA_RGB 1 +#define FC_RGBA_BGR 2 +#define FC_RGBA_VRGB 3 +#define FC_RGBA_VBGR 4 +#define FC_RGBA_NONE 5 + +/* hinting style */ +#define FC_HINT_NONE 0 +#define FC_HINT_SLIGHT 1 +#define FC_HINT_MEDIUM 2 +#define FC_HINT_FULL 3 + +/* LCD filter */ +#define FC_LCD_NONE 0 +#define FC_LCD_DEFAULT 1 +#define FC_LCD_LIGHT 2 +#define FC_LCD_LEGACY 3 + +typedef enum _FcType { + FcTypeUnknown = -1, + FcTypeVoid, + FcTypeInteger, + FcTypeDouble, + FcTypeString, + FcTypeBool, + FcTypeMatrix, + FcTypeCharSet, + FcTypeFTFace, + FcTypeLangSet +} FcType; + +typedef struct _FcMatrix { + double xx, xy, yx, yy; +} FcMatrix; + +#define FcMatrixInit(m) ((m)->xx = (m)->yy = 1, \ + (m)->xy = (m)->yx = 0) + +/* + * A data structure to represent the available glyphs in a font. + * This is represented as a sparse boolean btree. + */ + +typedef struct _FcCharSet FcCharSet; + +typedef struct _FcObjectType { + const char *object; + FcType type; +} FcObjectType; + +typedef struct _FcConstant { + const FcChar8 *name; + const char *object; + int value; +} FcConstant; + +typedef enum _FcResult { + FcResultMatch, FcResultNoMatch, FcResultTypeMismatch, FcResultNoId, + FcResultOutOfMemory +} FcResult; + +typedef struct _FcPattern FcPattern; + +typedef struct _FcLangSet FcLangSet; + +typedef struct _FcValue { + FcType type; + union { + const FcChar8 *s; + int i; + FcBool b; + double d; + const FcMatrix *m; + const FcCharSet *c; + void *f; + const FcLangSet *l; + } u; +} FcValue; + +typedef struct _FcFontSet { + int nfont; + int sfont; + FcPattern **fonts; +} FcFontSet; + +typedef struct _FcObjectSet { + int nobject; + int sobject; + const char **objects; +} FcObjectSet; + +typedef enum _FcMatchKind { + FcMatchPattern, FcMatchFont, FcMatchScan +} FcMatchKind; + +typedef enum _FcLangResult { + FcLangEqual = 0, + FcLangDifferentCountry = 1, + FcLangDifferentTerritory = 1, + FcLangDifferentLang = 2 +} FcLangResult; + +typedef enum _FcSetName { + FcSetSystem = 0, + FcSetApplication = 1 +} FcSetName; + +typedef struct _FcAtomic FcAtomic; + +#if defined(__cplusplus) || defined(c_plusplus) /* for C++ V2.0 */ +#define _FCFUNCPROTOBEGIN extern "C" { /* do not leave open across includes */ +#define _FCFUNCPROTOEND } +#else +#define _FCFUNCPROTOBEGIN +#define _FCFUNCPROTOEND +#endif + +typedef enum { FcEndianBig, FcEndianLittle } FcEndian; + +typedef struct _FcConfig FcConfig; + +typedef struct _FcGlobalCache FcFileCache; + +typedef struct _FcBlanks FcBlanks; + +typedef struct _FcStrList FcStrList; + +typedef struct _FcStrSet FcStrSet; + +typedef struct _FcCache FcCache; + +_FCFUNCPROTOBEGIN + +/* fcblanks.c */ +FcPublic FcBlanks * +FcBlanksCreate (void); + +FcPublic void +FcBlanksDestroy (FcBlanks *b); + +FcPublic FcBool +FcBlanksAdd (FcBlanks *b, FcChar32 ucs4); + +FcPublic FcBool +FcBlanksIsMember (FcBlanks *b, FcChar32 ucs4); + +/* fccache.c */ + +FcPublic const FcChar8 * +FcCacheDir(const FcCache *c); + +FcPublic FcFontSet * +FcCacheCopySet(const FcCache *c); + +FcPublic const FcChar8 * +FcCacheSubdir (const FcCache *c, int i); + +FcPublic int +FcCacheNumSubdir (const FcCache *c); + +FcPublic int +FcCacheNumFont (const FcCache *c); + +FcPublic FcBool +FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config); + +FcPublic FcBool +FcDirCacheValid (const FcChar8 *cache_file); + +FcPublic FcBool +FcDirCacheClean (const FcChar8 *cache_dir, FcBool verbose); + +FcPublic void +FcCacheCreateTagFile (const FcConfig *config); + +/* fccfg.c */ +FcPublic FcChar8 * +FcConfigHome (void); + +FcPublic FcBool +FcConfigEnableHome (FcBool enable); + +FcPublic FcChar8 * +FcConfigFilename (const FcChar8 *url); + +FcPublic FcConfig * +FcConfigCreate (void); + +FcPublic FcConfig * +FcConfigReference (FcConfig *config); + +FcPublic void +FcConfigDestroy (FcConfig *config); + +FcPublic FcBool +FcConfigSetCurrent (FcConfig *config); + +FcPublic FcConfig * +FcConfigGetCurrent (void); + +FcPublic FcBool +FcConfigUptoDate (FcConfig *config); + +FcPublic FcBool +FcConfigBuildFonts (FcConfig *config); + +FcPublic FcStrList * +FcConfigGetFontDirs (FcConfig *config); + +FcPublic FcStrList * +FcConfigGetConfigDirs (FcConfig *config); + +FcPublic FcStrList * +FcConfigGetConfigFiles (FcConfig *config); + +FcPublic FcChar8 * +FcConfigGetCache (FcConfig *config); + +FcPublic FcBlanks * +FcConfigGetBlanks (FcConfig *config); + +FcPublic FcStrList * +FcConfigGetCacheDirs (const FcConfig *config); + +FcPublic int +FcConfigGetRescanInterval (FcConfig *config); + +FcPublic FcBool +FcConfigSetRescanInterval (FcConfig *config, int rescanInterval); + +FcPublic FcFontSet * +FcConfigGetFonts (FcConfig *config, + FcSetName set); + +FcPublic FcBool +FcConfigAppFontAddFile (FcConfig *config, + const FcChar8 *file); + +FcPublic FcBool +FcConfigAppFontAddDir (FcConfig *config, + const FcChar8 *dir); + +FcPublic void +FcConfigAppFontClear (FcConfig *config); + +FcPublic FcBool +FcConfigSubstituteWithPat (FcConfig *config, + FcPattern *p, + FcPattern *p_pat, + FcMatchKind kind); + +FcPublic FcBool +FcConfigSubstitute (FcConfig *config, + FcPattern *p, + FcMatchKind kind); + +FcPublic const FcChar8 * +FcConfigGetSysRoot (const FcConfig *config); + +FcPublic void +FcConfigSetSysRoot (FcConfig *config, + const FcChar8 *sysroot); + +/* fccharset.c */ +FcPublic FcCharSet* +FcCharSetCreate (void); + +/* deprecated alias for FcCharSetCreate */ +FcPublic FcCharSet * +FcCharSetNew (void); + +FcPublic void +FcCharSetDestroy (FcCharSet *fcs); + +FcPublic FcBool +FcCharSetAddChar (FcCharSet *fcs, FcChar32 ucs4); + +FcPublic FcBool +FcCharSetDelChar (FcCharSet *fcs, FcChar32 ucs4); + +FcPublic FcCharSet* +FcCharSetCopy (FcCharSet *src); + +FcPublic FcBool +FcCharSetEqual (const FcCharSet *a, const FcCharSet *b); + +FcPublic FcCharSet* +FcCharSetIntersect (const FcCharSet *a, const FcCharSet *b); + +FcPublic FcCharSet* +FcCharSetUnion (const FcCharSet *a, const FcCharSet *b); + +FcPublic FcCharSet* +FcCharSetSubtract (const FcCharSet *a, const FcCharSet *b); + +FcPublic FcBool +FcCharSetMerge (FcCharSet *a, const FcCharSet *b, FcBool *changed); + +FcPublic FcBool +FcCharSetHasChar (const FcCharSet *fcs, FcChar32 ucs4); + +FcPublic FcChar32 +FcCharSetCount (const FcCharSet *a); + +FcPublic FcChar32 +FcCharSetIntersectCount (const FcCharSet *a, const FcCharSet *b); + +FcPublic FcChar32 +FcCharSetSubtractCount (const FcCharSet *a, const FcCharSet *b); + +FcPublic FcBool +FcCharSetIsSubset (const FcCharSet *a, const FcCharSet *b); + +#define FC_CHARSET_MAP_SIZE (256/32) +#define FC_CHARSET_DONE ((FcChar32) -1) + +FcPublic FcChar32 +FcCharSetFirstPage (const FcCharSet *a, + FcChar32 map[FC_CHARSET_MAP_SIZE], + FcChar32 *next); + +FcPublic FcChar32 +FcCharSetNextPage (const FcCharSet *a, + FcChar32 map[FC_CHARSET_MAP_SIZE], + FcChar32 *next); + +/* + * old coverage API, rather hard to use correctly + */ + +FcPublic FcChar32 +FcCharSetCoverage (const FcCharSet *a, FcChar32 page, FcChar32 *result); + +/* fcdbg.c */ +FcPublic void +FcValuePrint (const FcValue v); + +FcPublic void +FcPatternPrint (const FcPattern *p); + +FcPublic void +FcFontSetPrint (const FcFontSet *s); + +/* fcdefault.c */ +FcPublic FcStrSet * +FcGetDefaultLangs (void); + +FcPublic void +FcDefaultSubstitute (FcPattern *pattern); + +/* fcdir.c */ +FcPublic FcBool +FcFileIsDir (const FcChar8 *file); + +FcPublic FcBool +FcFileScan (FcFontSet *set, + FcStrSet *dirs, + FcFileCache *cache, + FcBlanks *blanks, + const FcChar8 *file, + FcBool force); + +FcPublic FcBool +FcDirScan (FcFontSet *set, + FcStrSet *dirs, + FcFileCache *cache, + FcBlanks *blanks, + const FcChar8 *dir, + FcBool force); + +FcPublic FcBool +FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir); + +FcPublic FcCache * +FcDirCacheLoad (const FcChar8 *dir, FcConfig *config, FcChar8 **cache_file); + +FcPublic FcCache * +FcDirCacheRescan (const FcChar8 *dir, FcConfig *config); + +FcPublic FcCache * +FcDirCacheRead (const FcChar8 *dir, FcBool force, FcConfig *config); + +FcPublic FcCache * +FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat); + +FcPublic void +FcDirCacheUnload (FcCache *cache); + +/* fcfreetype.c */ +FcPublic FcPattern * +FcFreeTypeQuery (const FcChar8 *file, int id, FcBlanks *blanks, int *count); + +/* fcfs.c */ + +FcPublic FcFontSet * +FcFontSetCreate (void); + +FcPublic void +FcFontSetDestroy (FcFontSet *s); + +FcPublic FcBool +FcFontSetAdd (FcFontSet *s, FcPattern *font); + +/* fcinit.c */ +FcPublic FcConfig * +FcInitLoadConfig (void); + +FcPublic FcConfig * +FcInitLoadConfigAndFonts (void); + +FcPublic FcBool +FcInit (void); + +FcPublic void +FcFini (void); + +FcPublic int +FcGetVersion (void); + +FcPublic FcBool +FcInitReinitialize (void); + +FcPublic FcBool +FcInitBringUptoDate (void); + +/* fclang.c */ +FcPublic FcStrSet * +FcGetLangs (void); + +FcPublic FcChar8 * +FcLangNormalize (const FcChar8 *lang); + +FcPublic const FcCharSet * +FcLangGetCharSet (const FcChar8 *lang); + +FcPublic FcLangSet* +FcLangSetCreate (void); + +FcPublic void +FcLangSetDestroy (FcLangSet *ls); + +FcPublic FcLangSet* +FcLangSetCopy (const FcLangSet *ls); + +FcPublic FcBool +FcLangSetAdd (FcLangSet *ls, const FcChar8 *lang); + +FcPublic FcBool +FcLangSetDel (FcLangSet *ls, const FcChar8 *lang); + +FcPublic FcLangResult +FcLangSetHasLang (const FcLangSet *ls, const FcChar8 *lang); + +FcPublic FcLangResult +FcLangSetCompare (const FcLangSet *lsa, const FcLangSet *lsb); + +FcPublic FcBool +FcLangSetContains (const FcLangSet *lsa, const FcLangSet *lsb); + +FcPublic FcBool +FcLangSetEqual (const FcLangSet *lsa, const FcLangSet *lsb); + +FcPublic FcChar32 +FcLangSetHash (const FcLangSet *ls); + +FcPublic FcStrSet * +FcLangSetGetLangs (const FcLangSet *ls); + +FcPublic FcLangSet * +FcLangSetUnion (const FcLangSet *a, const FcLangSet *b); + +FcPublic FcLangSet * +FcLangSetSubtract (const FcLangSet *a, const FcLangSet *b); + +/* fclist.c */ +FcPublic FcObjectSet * +FcObjectSetCreate (void); + +FcPublic FcBool +FcObjectSetAdd (FcObjectSet *os, const char *object); + +FcPublic void +FcObjectSetDestroy (FcObjectSet *os); + +FcPublic FcObjectSet * +FcObjectSetVaBuild (const char *first, va_list va); + +FcPublic FcObjectSet * +FcObjectSetBuild (const char *first, ...) FC_ATTRIBUTE_SENTINEL(0); + +FcPublic FcFontSet * +FcFontSetList (FcConfig *config, + FcFontSet **sets, + int nsets, + FcPattern *p, + FcObjectSet *os); + +FcPublic FcFontSet * +FcFontList (FcConfig *config, + FcPattern *p, + FcObjectSet *os); + +/* fcatomic.c */ + +FcPublic FcAtomic * +FcAtomicCreate (const FcChar8 *file); + +FcPublic FcBool +FcAtomicLock (FcAtomic *atomic); + +FcPublic FcChar8 * +FcAtomicNewFile (FcAtomic *atomic); + +FcPublic FcChar8 * +FcAtomicOrigFile (FcAtomic *atomic); + +FcPublic FcBool +FcAtomicReplaceOrig (FcAtomic *atomic); + +FcPublic void +FcAtomicDeleteNew (FcAtomic *atomic); + +FcPublic void +FcAtomicUnlock (FcAtomic *atomic); + +FcPublic void +FcAtomicDestroy (FcAtomic *atomic); + +/* fcmatch.c */ +FcPublic FcPattern * +FcFontSetMatch (FcConfig *config, + FcFontSet **sets, + int nsets, + FcPattern *p, + FcResult *result); + +FcPublic FcPattern * +FcFontMatch (FcConfig *config, + FcPattern *p, + FcResult *result); + +FcPublic FcPattern * +FcFontRenderPrepare (FcConfig *config, + FcPattern *pat, + FcPattern *font); + +FcPublic FcFontSet * +FcFontSetSort (FcConfig *config, + FcFontSet **sets, + int nsets, + FcPattern *p, + FcBool trim, + FcCharSet **csp, + FcResult *result); + +FcPublic FcFontSet * +FcFontSort (FcConfig *config, + FcPattern *p, + FcBool trim, + FcCharSet **csp, + FcResult *result); + +FcPublic void +FcFontSetSortDestroy (FcFontSet *fs); + +/* fcmatrix.c */ +FcPublic FcMatrix * +FcMatrixCopy (const FcMatrix *mat); + +FcPublic FcBool +FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2); + +FcPublic void +FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b); + +FcPublic void +FcMatrixRotate (FcMatrix *m, double c, double s); + +FcPublic void +FcMatrixScale (FcMatrix *m, double sx, double sy); + +FcPublic void +FcMatrixShear (FcMatrix *m, double sh, double sv); + +/* fcname.c */ + +/* Deprecated. Does nothing. Returns FcFalse. */ +FcPublic FcBool +FcNameRegisterObjectTypes (const FcObjectType *types, int ntype); + +/* Deprecated. Does nothing. Returns FcFalse. */ +FcPublic FcBool +FcNameUnregisterObjectTypes (const FcObjectType *types, int ntype); + +FcPublic const FcObjectType * +FcNameGetObjectType (const char *object); + +/* Deprecated. Does nothing. Returns FcFalse. */ +FcPublic FcBool +FcNameRegisterConstants (const FcConstant *consts, int nconsts); + +/* Deprecated. Does nothing. Returns FcFalse. */ +FcPublic FcBool +FcNameUnregisterConstants (const FcConstant *consts, int nconsts); + +FcPublic const FcConstant * +FcNameGetConstant (const FcChar8 *string); + +FcPublic FcBool +FcNameConstant (const FcChar8 *string, int *result); + +FcPublic FcPattern * +FcNameParse (const FcChar8 *name); + +FcPublic FcChar8 * +FcNameUnparse (FcPattern *pat); + +/* fcpat.c */ +FcPublic FcPattern * +FcPatternCreate (void); + +FcPublic FcPattern * +FcPatternDuplicate (const FcPattern *p); + +FcPublic void +FcPatternReference (FcPattern *p); + +FcPublic FcPattern * +FcPatternFilter (FcPattern *p, const FcObjectSet *os); + +FcPublic void +FcValueDestroy (FcValue v); + +FcPublic FcBool +FcValueEqual (FcValue va, FcValue vb); + +FcPublic FcValue +FcValueSave (FcValue v); + +FcPublic void +FcPatternDestroy (FcPattern *p); + +FcPublic FcBool +FcPatternEqual (const FcPattern *pa, const FcPattern *pb); + +FcPublic FcBool +FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os); + +FcPublic FcChar32 +FcPatternHash (const FcPattern *p); + +FcPublic FcBool +FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append); + +FcPublic FcBool +FcPatternAddWeak (FcPattern *p, const char *object, FcValue value, FcBool append); + +FcPublic FcResult +FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v); + +FcPublic FcBool +FcPatternDel (FcPattern *p, const char *object); + +FcPublic FcBool +FcPatternRemove (FcPattern *p, const char *object, int id); + +FcPublic FcBool +FcPatternAddInteger (FcPattern *p, const char *object, int i); + +FcPublic FcBool +FcPatternAddDouble (FcPattern *p, const char *object, double d); + +FcPublic FcBool +FcPatternAddString (FcPattern *p, const char *object, const FcChar8 *s); + +FcPublic FcBool +FcPatternAddMatrix (FcPattern *p, const char *object, const FcMatrix *s); + +FcPublic FcBool +FcPatternAddCharSet (FcPattern *p, const char *object, const FcCharSet *c); + +FcPublic FcBool +FcPatternAddBool (FcPattern *p, const char *object, FcBool b); + +FcPublic FcBool +FcPatternAddLangSet (FcPattern *p, const char *object, const FcLangSet *ls); + +FcPublic FcResult +FcPatternGetInteger (const FcPattern *p, const char *object, int n, int *i); + +FcPublic FcResult +FcPatternGetDouble (const FcPattern *p, const char *object, int n, double *d); + +FcPublic FcResult +FcPatternGetString (const FcPattern *p, const char *object, int n, FcChar8 ** s); + +FcPublic FcResult +FcPatternGetMatrix (const FcPattern *p, const char *object, int n, FcMatrix **s); + +FcPublic FcResult +FcPatternGetCharSet (const FcPattern *p, const char *object, int n, FcCharSet **c); + +FcPublic FcResult +FcPatternGetBool (const FcPattern *p, const char *object, int n, FcBool *b); + +FcPublic FcResult +FcPatternGetLangSet (const FcPattern *p, const char *object, int n, FcLangSet **ls); + +FcPublic FcPattern * +FcPatternVaBuild (FcPattern *p, va_list va); + +FcPublic FcPattern * +FcPatternBuild (FcPattern *p, ...) FC_ATTRIBUTE_SENTINEL(0); + +FcPublic FcChar8 * +FcPatternFormat (FcPattern *pat, const FcChar8 *format); + +/* fcstr.c */ + +FcPublic FcChar8 * +FcStrCopy (const FcChar8 *s); + +FcPublic FcChar8 * +FcStrCopyFilename (const FcChar8 *s); + +FcPublic FcChar8 * +FcStrPlus (const FcChar8 *s1, const FcChar8 *s2); + +FcPublic void +FcStrFree (FcChar8 *s); + +/* These are ASCII only, suitable only for pattern element names */ +#define FcIsUpper(c) ((0101 <= (c) && (c) <= 0132)) +#define FcIsLower(c) ((0141 <= (c) && (c) <= 0172)) +#define FcToLower(c) (FcIsUpper(c) ? (c) - 0101 + 0141 : (c)) + +FcPublic FcChar8 * +FcStrDowncase (const FcChar8 *s); + +FcPublic int +FcStrCmpIgnoreCase (const FcChar8 *s1, const FcChar8 *s2); + +FcPublic int +FcStrCmp (const FcChar8 *s1, const FcChar8 *s2); + +FcPublic const FcChar8 * +FcStrStrIgnoreCase (const FcChar8 *s1, const FcChar8 *s2); + +FcPublic const FcChar8 * +FcStrStr (const FcChar8 *s1, const FcChar8 *s2); + +FcPublic int +FcUtf8ToUcs4 (const FcChar8 *src_orig, + FcChar32 *dst, + int len); + +FcPublic FcBool +FcUtf8Len (const FcChar8 *string, + int len, + int *nchar, + int *wchar); + +#define FC_UTF8_MAX_LEN 6 + +FcPublic int +FcUcs4ToUtf8 (FcChar32 ucs4, + FcChar8 dest[FC_UTF8_MAX_LEN]); + +FcPublic int +FcUtf16ToUcs4 (const FcChar8 *src_orig, + FcEndian endian, + FcChar32 *dst, + int len); /* in bytes */ + +FcPublic FcBool +FcUtf16Len (const FcChar8 *string, + FcEndian endian, + int len, /* in bytes */ + int *nchar, + int *wchar); + +FcPublic FcChar8 * +FcStrDirname (const FcChar8 *file); + +FcPublic FcChar8 * +FcStrBasename (const FcChar8 *file); + +FcPublic FcStrSet * +FcStrSetCreate (void); + +FcPublic FcBool +FcStrSetMember (FcStrSet *set, const FcChar8 *s); + +FcPublic FcBool +FcStrSetEqual (FcStrSet *sa, FcStrSet *sb); + +FcPublic FcBool +FcStrSetAdd (FcStrSet *set, const FcChar8 *s); + +FcPublic FcBool +FcStrSetAddFilename (FcStrSet *set, const FcChar8 *s); + +FcPublic FcBool +FcStrSetDel (FcStrSet *set, const FcChar8 *s); + +FcPublic void +FcStrSetDestroy (FcStrSet *set); + +FcPublic FcStrList * +FcStrListCreate (FcStrSet *set); + +FcPublic void +FcStrListFirst (FcStrList *list); + +FcPublic FcChar8 * +FcStrListNext (FcStrList *list); + +FcPublic void +FcStrListDone (FcStrList *list); + +/* fcxml.c */ +FcPublic FcBool +FcConfigParseAndLoad (FcConfig *config, const FcChar8 *file, FcBool complain); + +_FCFUNCPROTOEND + +#undef FC_ATTRIBUTE_SENTINEL + + +#ifndef _FCINT_H_ + +/* + * Deprecated functions are placed here to help users fix their code without + * digging through documentation + */ + +#define FcConfigGetRescanInverval FcConfigGetRescanInverval_REPLACE_BY_FcConfigGetRescanInterval +#define FcConfigSetRescanInverval FcConfigSetRescanInverval_REPLACE_BY_FcConfigSetRescanInterval + +#endif + +#endif /* _FONTCONFIG_H_ */ diff --git a/project/jni/fontconfig/src/fcalias.h b/project/jni/fontconfig/src/fcalias.h new file mode 100644 index 000000000..9b68b3ea3 --- /dev/null +++ b/project/jni/fontconfig/src/fcalias.h @@ -0,0 +1,392 @@ +extern __typeof (FcBlanksCreate) IA__FcBlanksCreate __attribute((visibility("hidden"))); +#define FcBlanksCreate IA__FcBlanksCreate +extern __typeof (FcBlanksDestroy) IA__FcBlanksDestroy __attribute((visibility("hidden"))); +#define FcBlanksDestroy IA__FcBlanksDestroy +extern __typeof (FcBlanksAdd) IA__FcBlanksAdd __attribute((visibility("hidden"))); +#define FcBlanksAdd IA__FcBlanksAdd +extern __typeof (FcBlanksIsMember) IA__FcBlanksIsMember __attribute((visibility("hidden"))); +#define FcBlanksIsMember IA__FcBlanksIsMember +extern __typeof (FcCacheCopySet) IA__FcCacheCopySet __attribute((visibility("hidden"))); +#define FcCacheCopySet IA__FcCacheCopySet +extern __typeof (FcCacheNumSubdir) IA__FcCacheNumSubdir __attribute((visibility("hidden"))); +#define FcCacheNumSubdir IA__FcCacheNumSubdir +extern __typeof (FcCacheNumFont) IA__FcCacheNumFont __attribute((visibility("hidden"))); +#define FcCacheNumFont IA__FcCacheNumFont +extern __typeof (FcDirCacheUnlink) IA__FcDirCacheUnlink __attribute((visibility("hidden"))); +#define FcDirCacheUnlink IA__FcDirCacheUnlink +extern __typeof (FcDirCacheValid) IA__FcDirCacheValid __attribute((visibility("hidden"))); +#define FcDirCacheValid IA__FcDirCacheValid +extern __typeof (FcDirCacheClean) IA__FcDirCacheClean __attribute((visibility("hidden"))); +#define FcDirCacheClean IA__FcDirCacheClean +extern __typeof (FcCacheCreateTagFile) IA__FcCacheCreateTagFile __attribute((visibility("hidden"))); +#define FcCacheCreateTagFile IA__FcCacheCreateTagFile +extern __typeof (FcConfigHome) IA__FcConfigHome __attribute((visibility("hidden"))); +#define FcConfigHome IA__FcConfigHome +extern __typeof (FcConfigEnableHome) IA__FcConfigEnableHome __attribute((visibility("hidden"))); +#define FcConfigEnableHome IA__FcConfigEnableHome +extern __typeof (FcConfigFilename) IA__FcConfigFilename __attribute((visibility("hidden"))); +#define FcConfigFilename IA__FcConfigFilename +extern __typeof (FcConfigCreate) IA__FcConfigCreate __attribute((visibility("hidden"))); +#define FcConfigCreate IA__FcConfigCreate +extern __typeof (FcConfigReference) IA__FcConfigReference __attribute((visibility("hidden"))); +#define FcConfigReference IA__FcConfigReference +extern __typeof (FcConfigDestroy) IA__FcConfigDestroy __attribute((visibility("hidden"))); +#define FcConfigDestroy IA__FcConfigDestroy +extern __typeof (FcConfigSetCurrent) IA__FcConfigSetCurrent __attribute((visibility("hidden"))); +#define FcConfigSetCurrent IA__FcConfigSetCurrent +extern __typeof (FcConfigGetCurrent) IA__FcConfigGetCurrent __attribute((visibility("hidden"))); +#define FcConfigGetCurrent IA__FcConfigGetCurrent +extern __typeof (FcConfigUptoDate) IA__FcConfigUptoDate __attribute((visibility("hidden"))); +#define FcConfigUptoDate IA__FcConfigUptoDate +extern __typeof (FcConfigBuildFonts) IA__FcConfigBuildFonts __attribute((visibility("hidden"))); +#define FcConfigBuildFonts IA__FcConfigBuildFonts +extern __typeof (FcConfigGetFontDirs) IA__FcConfigGetFontDirs __attribute((visibility("hidden"))); +#define FcConfigGetFontDirs IA__FcConfigGetFontDirs +extern __typeof (FcConfigGetConfigDirs) IA__FcConfigGetConfigDirs __attribute((visibility("hidden"))); +#define FcConfigGetConfigDirs IA__FcConfigGetConfigDirs +extern __typeof (FcConfigGetConfigFiles) IA__FcConfigGetConfigFiles __attribute((visibility("hidden"))); +#define FcConfigGetConfigFiles IA__FcConfigGetConfigFiles +extern __typeof (FcConfigGetCache) IA__FcConfigGetCache __attribute((visibility("hidden"))); +#define FcConfigGetCache IA__FcConfigGetCache +extern __typeof (FcConfigGetBlanks) IA__FcConfigGetBlanks __attribute((visibility("hidden"))); +#define FcConfigGetBlanks IA__FcConfigGetBlanks +extern __typeof (FcConfigGetCacheDirs) IA__FcConfigGetCacheDirs __attribute((visibility("hidden"))); +#define FcConfigGetCacheDirs IA__FcConfigGetCacheDirs +extern __typeof (FcConfigGetRescanInterval) IA__FcConfigGetRescanInterval __attribute((visibility("hidden"))); +#define FcConfigGetRescanInterval IA__FcConfigGetRescanInterval +extern __typeof (FcConfigSetRescanInterval) IA__FcConfigSetRescanInterval __attribute((visibility("hidden"))); +#define FcConfigSetRescanInterval IA__FcConfigSetRescanInterval +extern __typeof (FcConfigGetFonts) IA__FcConfigGetFonts __attribute((visibility("hidden"))); +#define FcConfigGetFonts IA__FcConfigGetFonts +extern __typeof (FcConfigAppFontAddFile) IA__FcConfigAppFontAddFile __attribute((visibility("hidden"))); +#define FcConfigAppFontAddFile IA__FcConfigAppFontAddFile +extern __typeof (FcConfigAppFontAddDir) IA__FcConfigAppFontAddDir __attribute((visibility("hidden"))); +#define FcConfigAppFontAddDir IA__FcConfigAppFontAddDir +extern __typeof (FcConfigAppFontClear) IA__FcConfigAppFontClear __attribute((visibility("hidden"))); +#define FcConfigAppFontClear IA__FcConfigAppFontClear +extern __typeof (FcConfigSubstituteWithPat) IA__FcConfigSubstituteWithPat __attribute((visibility("hidden"))); +#define FcConfigSubstituteWithPat IA__FcConfigSubstituteWithPat +extern __typeof (FcConfigSubstitute) IA__FcConfigSubstitute __attribute((visibility("hidden"))); +#define FcConfigSubstitute IA__FcConfigSubstitute +extern __typeof (FcConfigGetSysRoot) IA__FcConfigGetSysRoot __attribute((visibility("hidden"))); +#define FcConfigGetSysRoot IA__FcConfigGetSysRoot +extern __typeof (FcConfigSetSysRoot) IA__FcConfigSetSysRoot __attribute((visibility("hidden"))); +#define FcConfigSetSysRoot IA__FcConfigSetSysRoot +extern __typeof (FcCharSetCreate) IA__FcCharSetCreate __attribute((visibility("hidden"))); +#define FcCharSetCreate IA__FcCharSetCreate +extern __typeof (FcCharSetNew) IA__FcCharSetNew __attribute((visibility("hidden"))); +#define FcCharSetNew IA__FcCharSetNew +extern __typeof (FcCharSetDestroy) IA__FcCharSetDestroy __attribute((visibility("hidden"))); +#define FcCharSetDestroy IA__FcCharSetDestroy +extern __typeof (FcCharSetAddChar) IA__FcCharSetAddChar __attribute((visibility("hidden"))); +#define FcCharSetAddChar IA__FcCharSetAddChar +extern __typeof (FcCharSetDelChar) IA__FcCharSetDelChar __attribute((visibility("hidden"))); +#define FcCharSetDelChar IA__FcCharSetDelChar +extern __typeof (FcCharSetCopy) IA__FcCharSetCopy __attribute((visibility("hidden"))); +#define FcCharSetCopy IA__FcCharSetCopy +extern __typeof (FcCharSetEqual) IA__FcCharSetEqual __attribute((visibility("hidden"))); +#define FcCharSetEqual IA__FcCharSetEqual +extern __typeof (FcCharSetIntersect) IA__FcCharSetIntersect __attribute((visibility("hidden"))); +#define FcCharSetIntersect IA__FcCharSetIntersect +extern __typeof (FcCharSetUnion) IA__FcCharSetUnion __attribute((visibility("hidden"))); +#define FcCharSetUnion IA__FcCharSetUnion +extern __typeof (FcCharSetSubtract) IA__FcCharSetSubtract __attribute((visibility("hidden"))); +#define FcCharSetSubtract IA__FcCharSetSubtract +extern __typeof (FcCharSetMerge) IA__FcCharSetMerge __attribute((visibility("hidden"))); +#define FcCharSetMerge IA__FcCharSetMerge +extern __typeof (FcCharSetHasChar) IA__FcCharSetHasChar __attribute((visibility("hidden"))); +#define FcCharSetHasChar IA__FcCharSetHasChar +extern __typeof (FcCharSetCount) IA__FcCharSetCount __attribute((visibility("hidden"))); +#define FcCharSetCount IA__FcCharSetCount +extern __typeof (FcCharSetIntersectCount) IA__FcCharSetIntersectCount __attribute((visibility("hidden"))); +#define FcCharSetIntersectCount IA__FcCharSetIntersectCount +extern __typeof (FcCharSetSubtractCount) IA__FcCharSetSubtractCount __attribute((visibility("hidden"))); +#define FcCharSetSubtractCount IA__FcCharSetSubtractCount +extern __typeof (FcCharSetIsSubset) IA__FcCharSetIsSubset __attribute((visibility("hidden"))); +#define FcCharSetIsSubset IA__FcCharSetIsSubset +extern __typeof (FcCharSetFirstPage) IA__FcCharSetFirstPage __attribute((visibility("hidden"))); +#define FcCharSetFirstPage IA__FcCharSetFirstPage +extern __typeof (FcCharSetNextPage) IA__FcCharSetNextPage __attribute((visibility("hidden"))); +#define FcCharSetNextPage IA__FcCharSetNextPage +extern __typeof (FcCharSetCoverage) IA__FcCharSetCoverage __attribute((visibility("hidden"))); +#define FcCharSetCoverage IA__FcCharSetCoverage +extern __typeof (FcValuePrint) IA__FcValuePrint __attribute((visibility("hidden"))); +#define FcValuePrint IA__FcValuePrint +extern __typeof (FcPatternPrint) IA__FcPatternPrint __attribute((visibility("hidden"))); +#define FcPatternPrint IA__FcPatternPrint +extern __typeof (FcFontSetPrint) IA__FcFontSetPrint __attribute((visibility("hidden"))); +#define FcFontSetPrint IA__FcFontSetPrint +extern __typeof (FcGetDefaultLangs) IA__FcGetDefaultLangs __attribute((visibility("hidden"))); +#define FcGetDefaultLangs IA__FcGetDefaultLangs +extern __typeof (FcDefaultSubstitute) IA__FcDefaultSubstitute __attribute((visibility("hidden"))); +#define FcDefaultSubstitute IA__FcDefaultSubstitute +extern __typeof (FcFileIsDir) IA__FcFileIsDir __attribute((visibility("hidden"))); +#define FcFileIsDir IA__FcFileIsDir +extern __typeof (FcFileScan) IA__FcFileScan __attribute((visibility("hidden"))); +#define FcFileScan IA__FcFileScan +extern __typeof (FcDirScan) IA__FcDirScan __attribute((visibility("hidden"))); +#define FcDirScan IA__FcDirScan +extern __typeof (FcDirSave) IA__FcDirSave __attribute((visibility("hidden"))); +#define FcDirSave IA__FcDirSave +extern __typeof (FcDirCacheLoad) IA__FcDirCacheLoad __attribute((visibility("hidden"))); +#define FcDirCacheLoad IA__FcDirCacheLoad +extern __typeof (FcDirCacheRescan) IA__FcDirCacheRescan __attribute((visibility("hidden"))); +#define FcDirCacheRescan IA__FcDirCacheRescan +extern __typeof (FcDirCacheRead) IA__FcDirCacheRead __attribute((visibility("hidden"))); +#define FcDirCacheRead IA__FcDirCacheRead +extern __typeof (FcDirCacheLoadFile) IA__FcDirCacheLoadFile __attribute((visibility("hidden"))); +#define FcDirCacheLoadFile IA__FcDirCacheLoadFile +extern __typeof (FcDirCacheUnload) IA__FcDirCacheUnload __attribute((visibility("hidden"))); +#define FcDirCacheUnload IA__FcDirCacheUnload +extern __typeof (FcFreeTypeQuery) IA__FcFreeTypeQuery __attribute((visibility("hidden"))); +#define FcFreeTypeQuery IA__FcFreeTypeQuery +extern __typeof (FcFontSetCreate) IA__FcFontSetCreate __attribute((visibility("hidden"))); +#define FcFontSetCreate IA__FcFontSetCreate +extern __typeof (FcFontSetDestroy) IA__FcFontSetDestroy __attribute((visibility("hidden"))); +#define FcFontSetDestroy IA__FcFontSetDestroy +extern __typeof (FcFontSetAdd) IA__FcFontSetAdd __attribute((visibility("hidden"))); +#define FcFontSetAdd IA__FcFontSetAdd +extern __typeof (FcInitLoadConfig) IA__FcInitLoadConfig __attribute((visibility("hidden"))); +#define FcInitLoadConfig IA__FcInitLoadConfig +extern __typeof (FcInitLoadConfigAndFonts) IA__FcInitLoadConfigAndFonts __attribute((visibility("hidden"))); +#define FcInitLoadConfigAndFonts IA__FcInitLoadConfigAndFonts +extern __typeof (FcInit) IA__FcInit __attribute((visibility("hidden"))); +#define FcInit IA__FcInit +extern __typeof (FcFini) IA__FcFini __attribute((visibility("hidden"))); +#define FcFini IA__FcFini +extern __typeof (FcGetVersion) IA__FcGetVersion __attribute((visibility("hidden"))); +#define FcGetVersion IA__FcGetVersion +extern __typeof (FcInitReinitialize) IA__FcInitReinitialize __attribute((visibility("hidden"))); +#define FcInitReinitialize IA__FcInitReinitialize +extern __typeof (FcInitBringUptoDate) IA__FcInitBringUptoDate __attribute((visibility("hidden"))); +#define FcInitBringUptoDate IA__FcInitBringUptoDate +extern __typeof (FcGetLangs) IA__FcGetLangs __attribute((visibility("hidden"))); +#define FcGetLangs IA__FcGetLangs +extern __typeof (FcLangNormalize) IA__FcLangNormalize __attribute((visibility("hidden"))); +#define FcLangNormalize IA__FcLangNormalize +extern __typeof (FcLangGetCharSet) IA__FcLangGetCharSet __attribute((visibility("hidden"))); +#define FcLangGetCharSet IA__FcLangGetCharSet +extern __typeof (FcLangSetCreate) IA__FcLangSetCreate __attribute((visibility("hidden"))); +#define FcLangSetCreate IA__FcLangSetCreate +extern __typeof (FcLangSetDestroy) IA__FcLangSetDestroy __attribute((visibility("hidden"))); +#define FcLangSetDestroy IA__FcLangSetDestroy +extern __typeof (FcLangSetCopy) IA__FcLangSetCopy __attribute((visibility("hidden"))); +#define FcLangSetCopy IA__FcLangSetCopy +extern __typeof (FcLangSetAdd) IA__FcLangSetAdd __attribute((visibility("hidden"))); +#define FcLangSetAdd IA__FcLangSetAdd +extern __typeof (FcLangSetDel) IA__FcLangSetDel __attribute((visibility("hidden"))); +#define FcLangSetDel IA__FcLangSetDel +extern __typeof (FcLangSetHasLang) IA__FcLangSetHasLang __attribute((visibility("hidden"))); +#define FcLangSetHasLang IA__FcLangSetHasLang +extern __typeof (FcLangSetCompare) IA__FcLangSetCompare __attribute((visibility("hidden"))); +#define FcLangSetCompare IA__FcLangSetCompare +extern __typeof (FcLangSetContains) IA__FcLangSetContains __attribute((visibility("hidden"))); +#define FcLangSetContains IA__FcLangSetContains +extern __typeof (FcLangSetEqual) IA__FcLangSetEqual __attribute((visibility("hidden"))); +#define FcLangSetEqual IA__FcLangSetEqual +extern __typeof (FcLangSetHash) IA__FcLangSetHash __attribute((visibility("hidden"))); +#define FcLangSetHash IA__FcLangSetHash +extern __typeof (FcLangSetGetLangs) IA__FcLangSetGetLangs __attribute((visibility("hidden"))); +#define FcLangSetGetLangs IA__FcLangSetGetLangs +extern __typeof (FcLangSetUnion) IA__FcLangSetUnion __attribute((visibility("hidden"))); +#define FcLangSetUnion IA__FcLangSetUnion +extern __typeof (FcLangSetSubtract) IA__FcLangSetSubtract __attribute((visibility("hidden"))); +#define FcLangSetSubtract IA__FcLangSetSubtract +extern __typeof (FcObjectSetCreate) IA__FcObjectSetCreate __attribute((visibility("hidden"))); +#define FcObjectSetCreate IA__FcObjectSetCreate +extern __typeof (FcObjectSetAdd) IA__FcObjectSetAdd __attribute((visibility("hidden"))); +#define FcObjectSetAdd IA__FcObjectSetAdd +extern __typeof (FcObjectSetDestroy) IA__FcObjectSetDestroy __attribute((visibility("hidden"))); +#define FcObjectSetDestroy IA__FcObjectSetDestroy +extern __typeof (FcObjectSetVaBuild) IA__FcObjectSetVaBuild __attribute((visibility("hidden"))); +#define FcObjectSetVaBuild IA__FcObjectSetVaBuild +extern __typeof (FcObjectSetBuild) IA__FcObjectSetBuild __attribute((visibility("hidden"))); +#define FcObjectSetBuild IA__FcObjectSetBuild +extern __typeof (FcFontSetList) IA__FcFontSetList __attribute((visibility("hidden"))); +#define FcFontSetList IA__FcFontSetList +extern __typeof (FcFontList) IA__FcFontList __attribute((visibility("hidden"))); +#define FcFontList IA__FcFontList +extern __typeof (FcAtomicCreate) IA__FcAtomicCreate __attribute((visibility("hidden"))); +#define FcAtomicCreate IA__FcAtomicCreate +extern __typeof (FcAtomicLock) IA__FcAtomicLock __attribute((visibility("hidden"))); +#define FcAtomicLock IA__FcAtomicLock +extern __typeof (FcAtomicNewFile) IA__FcAtomicNewFile __attribute((visibility("hidden"))); +#define FcAtomicNewFile IA__FcAtomicNewFile +extern __typeof (FcAtomicOrigFile) IA__FcAtomicOrigFile __attribute((visibility("hidden"))); +#define FcAtomicOrigFile IA__FcAtomicOrigFile +extern __typeof (FcAtomicReplaceOrig) IA__FcAtomicReplaceOrig __attribute((visibility("hidden"))); +#define FcAtomicReplaceOrig IA__FcAtomicReplaceOrig +extern __typeof (FcAtomicDeleteNew) IA__FcAtomicDeleteNew __attribute((visibility("hidden"))); +#define FcAtomicDeleteNew IA__FcAtomicDeleteNew +extern __typeof (FcAtomicUnlock) IA__FcAtomicUnlock __attribute((visibility("hidden"))); +#define FcAtomicUnlock IA__FcAtomicUnlock +extern __typeof (FcAtomicDestroy) IA__FcAtomicDestroy __attribute((visibility("hidden"))); +#define FcAtomicDestroy IA__FcAtomicDestroy +extern __typeof (FcFontSetMatch) IA__FcFontSetMatch __attribute((visibility("hidden"))); +#define FcFontSetMatch IA__FcFontSetMatch +extern __typeof (FcFontMatch) IA__FcFontMatch __attribute((visibility("hidden"))); +#define FcFontMatch IA__FcFontMatch +extern __typeof (FcFontRenderPrepare) IA__FcFontRenderPrepare __attribute((visibility("hidden"))); +#define FcFontRenderPrepare IA__FcFontRenderPrepare +extern __typeof (FcFontSetSort) IA__FcFontSetSort __attribute((visibility("hidden"))); +#define FcFontSetSort IA__FcFontSetSort +extern __typeof (FcFontSort) IA__FcFontSort __attribute((visibility("hidden"))); +#define FcFontSort IA__FcFontSort +extern __typeof (FcFontSetSortDestroy) IA__FcFontSetSortDestroy __attribute((visibility("hidden"))); +#define FcFontSetSortDestroy IA__FcFontSetSortDestroy +extern __typeof (FcMatrixCopy) IA__FcMatrixCopy __attribute((visibility("hidden"))); +#define FcMatrixCopy IA__FcMatrixCopy +extern __typeof (FcMatrixEqual) IA__FcMatrixEqual __attribute((visibility("hidden"))); +#define FcMatrixEqual IA__FcMatrixEqual +extern __typeof (FcMatrixMultiply) IA__FcMatrixMultiply __attribute((visibility("hidden"))); +#define FcMatrixMultiply IA__FcMatrixMultiply +extern __typeof (FcMatrixRotate) IA__FcMatrixRotate __attribute((visibility("hidden"))); +#define FcMatrixRotate IA__FcMatrixRotate +extern __typeof (FcMatrixScale) IA__FcMatrixScale __attribute((visibility("hidden"))); +#define FcMatrixScale IA__FcMatrixScale +extern __typeof (FcMatrixShear) IA__FcMatrixShear __attribute((visibility("hidden"))); +#define FcMatrixShear IA__FcMatrixShear +extern __typeof (FcNameRegisterObjectTypes) IA__FcNameRegisterObjectTypes __attribute((visibility("hidden"))); +#define FcNameRegisterObjectTypes IA__FcNameRegisterObjectTypes +extern __typeof (FcNameUnregisterObjectTypes) IA__FcNameUnregisterObjectTypes __attribute((visibility("hidden"))); +#define FcNameUnregisterObjectTypes IA__FcNameUnregisterObjectTypes +extern __typeof (FcNameGetObjectType) IA__FcNameGetObjectType __attribute((visibility("hidden"))); +#define FcNameGetObjectType IA__FcNameGetObjectType +extern __typeof (FcNameRegisterConstants) IA__FcNameRegisterConstants __attribute((visibility("hidden"))); +#define FcNameRegisterConstants IA__FcNameRegisterConstants +extern __typeof (FcNameUnregisterConstants) IA__FcNameUnregisterConstants __attribute((visibility("hidden"))); +#define FcNameUnregisterConstants IA__FcNameUnregisterConstants +extern __typeof (FcNameGetConstant) IA__FcNameGetConstant __attribute((visibility("hidden"))); +#define FcNameGetConstant IA__FcNameGetConstant +extern __typeof (FcNameConstant) IA__FcNameConstant __attribute((visibility("hidden"))); +#define FcNameConstant IA__FcNameConstant +extern __typeof (FcNameParse) IA__FcNameParse __attribute((visibility("hidden"))); +#define FcNameParse IA__FcNameParse +extern __typeof (FcNameUnparse) IA__FcNameUnparse __attribute((visibility("hidden"))); +#define FcNameUnparse IA__FcNameUnparse +extern __typeof (FcPatternCreate) IA__FcPatternCreate __attribute((visibility("hidden"))); +#define FcPatternCreate IA__FcPatternCreate +extern __typeof (FcPatternDuplicate) IA__FcPatternDuplicate __attribute((visibility("hidden"))); +#define FcPatternDuplicate IA__FcPatternDuplicate +extern __typeof (FcPatternReference) IA__FcPatternReference __attribute((visibility("hidden"))); +#define FcPatternReference IA__FcPatternReference +extern __typeof (FcPatternFilter) IA__FcPatternFilter __attribute((visibility("hidden"))); +#define FcPatternFilter IA__FcPatternFilter +extern __typeof (FcValueDestroy) IA__FcValueDestroy __attribute((visibility("hidden"))); +#define FcValueDestroy IA__FcValueDestroy +extern __typeof (FcValueEqual) IA__FcValueEqual __attribute((visibility("hidden"))); +#define FcValueEqual IA__FcValueEqual +extern __typeof (FcValueSave) IA__FcValueSave __attribute((visibility("hidden"))); +#define FcValueSave IA__FcValueSave +extern __typeof (FcPatternDestroy) IA__FcPatternDestroy __attribute((visibility("hidden"))); +#define FcPatternDestroy IA__FcPatternDestroy +extern __typeof (FcPatternEqual) IA__FcPatternEqual __attribute((visibility("hidden"))); +#define FcPatternEqual IA__FcPatternEqual +extern __typeof (FcPatternEqualSubset) IA__FcPatternEqualSubset __attribute((visibility("hidden"))); +#define FcPatternEqualSubset IA__FcPatternEqualSubset +extern __typeof (FcPatternHash) IA__FcPatternHash __attribute((visibility("hidden"))); +#define FcPatternHash IA__FcPatternHash +extern __typeof (FcPatternAdd) IA__FcPatternAdd __attribute((visibility("hidden"))); +#define FcPatternAdd IA__FcPatternAdd +extern __typeof (FcPatternAddWeak) IA__FcPatternAddWeak __attribute((visibility("hidden"))); +#define FcPatternAddWeak IA__FcPatternAddWeak +extern __typeof (FcPatternGet) IA__FcPatternGet __attribute((visibility("hidden"))); +#define FcPatternGet IA__FcPatternGet +extern __typeof (FcPatternDel) IA__FcPatternDel __attribute((visibility("hidden"))); +#define FcPatternDel IA__FcPatternDel +extern __typeof (FcPatternRemove) IA__FcPatternRemove __attribute((visibility("hidden"))); +#define FcPatternRemove IA__FcPatternRemove +extern __typeof (FcPatternAddInteger) IA__FcPatternAddInteger __attribute((visibility("hidden"))); +#define FcPatternAddInteger IA__FcPatternAddInteger +extern __typeof (FcPatternAddDouble) IA__FcPatternAddDouble __attribute((visibility("hidden"))); +#define FcPatternAddDouble IA__FcPatternAddDouble +extern __typeof (FcPatternAddString) IA__FcPatternAddString __attribute((visibility("hidden"))); +#define FcPatternAddString IA__FcPatternAddString +extern __typeof (FcPatternAddMatrix) IA__FcPatternAddMatrix __attribute((visibility("hidden"))); +#define FcPatternAddMatrix IA__FcPatternAddMatrix +extern __typeof (FcPatternAddCharSet) IA__FcPatternAddCharSet __attribute((visibility("hidden"))); +#define FcPatternAddCharSet IA__FcPatternAddCharSet +extern __typeof (FcPatternAddBool) IA__FcPatternAddBool __attribute((visibility("hidden"))); +#define FcPatternAddBool IA__FcPatternAddBool +extern __typeof (FcPatternAddLangSet) IA__FcPatternAddLangSet __attribute((visibility("hidden"))); +#define FcPatternAddLangSet IA__FcPatternAddLangSet +extern __typeof (FcPatternGetInteger) IA__FcPatternGetInteger __attribute((visibility("hidden"))); +#define FcPatternGetInteger IA__FcPatternGetInteger +extern __typeof (FcPatternGetDouble) IA__FcPatternGetDouble __attribute((visibility("hidden"))); +#define FcPatternGetDouble IA__FcPatternGetDouble +extern __typeof (FcPatternGetString) IA__FcPatternGetString __attribute((visibility("hidden"))); +#define FcPatternGetString IA__FcPatternGetString +extern __typeof (FcPatternGetMatrix) IA__FcPatternGetMatrix __attribute((visibility("hidden"))); +#define FcPatternGetMatrix IA__FcPatternGetMatrix +extern __typeof (FcPatternGetCharSet) IA__FcPatternGetCharSet __attribute((visibility("hidden"))); +#define FcPatternGetCharSet IA__FcPatternGetCharSet +extern __typeof (FcPatternGetBool) IA__FcPatternGetBool __attribute((visibility("hidden"))); +#define FcPatternGetBool IA__FcPatternGetBool +extern __typeof (FcPatternGetLangSet) IA__FcPatternGetLangSet __attribute((visibility("hidden"))); +#define FcPatternGetLangSet IA__FcPatternGetLangSet +extern __typeof (FcPatternVaBuild) IA__FcPatternVaBuild __attribute((visibility("hidden"))); +#define FcPatternVaBuild IA__FcPatternVaBuild +extern __typeof (FcPatternBuild) IA__FcPatternBuild __attribute((visibility("hidden"))); +#define FcPatternBuild IA__FcPatternBuild +extern __typeof (FcPatternFormat) IA__FcPatternFormat __attribute((visibility("hidden"))); +#define FcPatternFormat IA__FcPatternFormat +extern __typeof (FcStrCopy) IA__FcStrCopy __attribute((visibility("hidden"))); +#define FcStrCopy IA__FcStrCopy +extern __typeof (FcStrCopyFilename) IA__FcStrCopyFilename __attribute((visibility("hidden"))); +#define FcStrCopyFilename IA__FcStrCopyFilename +extern __typeof (FcStrPlus) IA__FcStrPlus __attribute((visibility("hidden"))); +#define FcStrPlus IA__FcStrPlus +extern __typeof (FcStrFree) IA__FcStrFree __attribute((visibility("hidden"))); +#define FcStrFree IA__FcStrFree +extern __typeof (FcStrDowncase) IA__FcStrDowncase __attribute((visibility("hidden"))); +#define FcStrDowncase IA__FcStrDowncase +extern __typeof (FcStrCmpIgnoreCase) IA__FcStrCmpIgnoreCase __attribute((visibility("hidden"))); +#define FcStrCmpIgnoreCase IA__FcStrCmpIgnoreCase +extern __typeof (FcStrCmp) IA__FcStrCmp __attribute((visibility("hidden"))); +#define FcStrCmp IA__FcStrCmp +extern __typeof (FcStrStrIgnoreCase) IA__FcStrStrIgnoreCase __attribute((visibility("hidden"))); +#define FcStrStrIgnoreCase IA__FcStrStrIgnoreCase +extern __typeof (FcStrStr) IA__FcStrStr __attribute((visibility("hidden"))); +#define FcStrStr IA__FcStrStr +extern __typeof (FcUtf8ToUcs4) IA__FcUtf8ToUcs4 __attribute((visibility("hidden"))); +#define FcUtf8ToUcs4 IA__FcUtf8ToUcs4 +extern __typeof (FcUtf8Len) IA__FcUtf8Len __attribute((visibility("hidden"))); +#define FcUtf8Len IA__FcUtf8Len +extern __typeof (FcUcs4ToUtf8) IA__FcUcs4ToUtf8 __attribute((visibility("hidden"))); +#define FcUcs4ToUtf8 IA__FcUcs4ToUtf8 +extern __typeof (FcUtf16ToUcs4) IA__FcUtf16ToUcs4 __attribute((visibility("hidden"))); +#define FcUtf16ToUcs4 IA__FcUtf16ToUcs4 +extern __typeof (FcUtf16Len) IA__FcUtf16Len __attribute((visibility("hidden"))); +#define FcUtf16Len IA__FcUtf16Len +extern __typeof (FcStrDirname) IA__FcStrDirname __attribute((visibility("hidden"))); +#define FcStrDirname IA__FcStrDirname +extern __typeof (FcStrBasename) IA__FcStrBasename __attribute((visibility("hidden"))); +#define FcStrBasename IA__FcStrBasename +extern __typeof (FcStrSetCreate) IA__FcStrSetCreate __attribute((visibility("hidden"))); +#define FcStrSetCreate IA__FcStrSetCreate +extern __typeof (FcStrSetMember) IA__FcStrSetMember __attribute((visibility("hidden"))); +#define FcStrSetMember IA__FcStrSetMember +extern __typeof (FcStrSetEqual) IA__FcStrSetEqual __attribute((visibility("hidden"))); +#define FcStrSetEqual IA__FcStrSetEqual +extern __typeof (FcStrSetAdd) IA__FcStrSetAdd __attribute((visibility("hidden"))); +#define FcStrSetAdd IA__FcStrSetAdd +extern __typeof (FcStrSetAddFilename) IA__FcStrSetAddFilename __attribute((visibility("hidden"))); +#define FcStrSetAddFilename IA__FcStrSetAddFilename +extern __typeof (FcStrSetDel) IA__FcStrSetDel __attribute((visibility("hidden"))); +#define FcStrSetDel IA__FcStrSetDel +extern __typeof (FcStrSetDestroy) IA__FcStrSetDestroy __attribute((visibility("hidden"))); +#define FcStrSetDestroy IA__FcStrSetDestroy +extern __typeof (FcStrListCreate) IA__FcStrListCreate __attribute((visibility("hidden"))); +#define FcStrListCreate IA__FcStrListCreate +extern __typeof (FcStrListFirst) IA__FcStrListFirst __attribute((visibility("hidden"))); +#define FcStrListFirst IA__FcStrListFirst +extern __typeof (FcStrListNext) IA__FcStrListNext __attribute((visibility("hidden"))); +#define FcStrListNext IA__FcStrListNext +extern __typeof (FcStrListDone) IA__FcStrListDone __attribute((visibility("hidden"))); +#define FcStrListDone IA__FcStrListDone +extern __typeof (FcConfigParseAndLoad) IA__FcConfigParseAndLoad __attribute((visibility("hidden"))); +#define FcConfigParseAndLoad IA__FcConfigParseAndLoad +extern __typeof (FcConfigGetRescanInverval) IA__FcConfigGetRescanInverval __attribute((visibility("hidden"))); +#define FcConfigGetRescanInverval IA__FcConfigGetRescanInverval +extern __typeof (FcConfigSetRescanInverval) IA__FcConfigSetRescanInverval __attribute((visibility("hidden"))); +#define FcConfigSetRescanInverval IA__FcConfigSetRescanInverval diff --git a/project/jni/fontconfig/src/fcaliastail.h b/project/jni/fontconfig/src/fcaliastail.h new file mode 100644 index 000000000..8c06f7ee1 --- /dev/null +++ b/project/jni/fontconfig/src/fcaliastail.h @@ -0,0 +1,442 @@ +#if HAVE_GNUC_ATTRIBUTE +#ifdef __fcblanks__ +# undef FcBlanksCreate +extern __typeof (FcBlanksCreate) FcBlanksCreate __attribute((alias("IA__FcBlanksCreate"), visibility("default"))); +# undef FcBlanksDestroy +extern __typeof (FcBlanksDestroy) FcBlanksDestroy __attribute((alias("IA__FcBlanksDestroy"), visibility("default"))); +# undef FcBlanksAdd +extern __typeof (FcBlanksAdd) FcBlanksAdd __attribute((alias("IA__FcBlanksAdd"), visibility("default"))); +# undef FcBlanksIsMember +extern __typeof (FcBlanksIsMember) FcBlanksIsMember __attribute((alias("IA__FcBlanksIsMember"), visibility("default"))); +#endif /* __fcblanks__ */ +#ifdef __fccache__ +# undef FcCacheCopySet +extern __typeof (FcCacheCopySet) FcCacheCopySet __attribute((alias("IA__FcCacheCopySet"), visibility("default"))); +# undef FcCacheNumSubdir +extern __typeof (FcCacheNumSubdir) FcCacheNumSubdir __attribute((alias("IA__FcCacheNumSubdir"), visibility("default"))); +# undef FcCacheNumFont +extern __typeof (FcCacheNumFont) FcCacheNumFont __attribute((alias("IA__FcCacheNumFont"), visibility("default"))); +# undef FcDirCacheUnlink +extern __typeof (FcDirCacheUnlink) FcDirCacheUnlink __attribute((alias("IA__FcDirCacheUnlink"), visibility("default"))); +# undef FcDirCacheValid +extern __typeof (FcDirCacheValid) FcDirCacheValid __attribute((alias("IA__FcDirCacheValid"), visibility("default"))); +# undef FcDirCacheClean +extern __typeof (FcDirCacheClean) FcDirCacheClean __attribute((alias("IA__FcDirCacheClean"), visibility("default"))); +# undef FcCacheCreateTagFile +extern __typeof (FcCacheCreateTagFile) FcCacheCreateTagFile __attribute((alias("IA__FcCacheCreateTagFile"), visibility("default"))); +#endif /* __fccache__ */ +#ifdef __fccfg__ +# undef FcConfigHome +extern __typeof (FcConfigHome) FcConfigHome __attribute((alias("IA__FcConfigHome"), visibility("default"))); +# undef FcConfigEnableHome +extern __typeof (FcConfigEnableHome) FcConfigEnableHome __attribute((alias("IA__FcConfigEnableHome"), visibility("default"))); +# undef FcConfigFilename +extern __typeof (FcConfigFilename) FcConfigFilename __attribute((alias("IA__FcConfigFilename"), visibility("default"))); +# undef FcConfigCreate +extern __typeof (FcConfigCreate) FcConfigCreate __attribute((alias("IA__FcConfigCreate"), visibility("default"))); +# undef FcConfigReference +extern __typeof (FcConfigReference) FcConfigReference __attribute((alias("IA__FcConfigReference"), visibility("default"))); +# undef FcConfigDestroy +extern __typeof (FcConfigDestroy) FcConfigDestroy __attribute((alias("IA__FcConfigDestroy"), visibility("default"))); +# undef FcConfigSetCurrent +extern __typeof (FcConfigSetCurrent) FcConfigSetCurrent __attribute((alias("IA__FcConfigSetCurrent"), visibility("default"))); +# undef FcConfigGetCurrent +extern __typeof (FcConfigGetCurrent) FcConfigGetCurrent __attribute((alias("IA__FcConfigGetCurrent"), visibility("default"))); +# undef FcConfigUptoDate +extern __typeof (FcConfigUptoDate) FcConfigUptoDate __attribute((alias("IA__FcConfigUptoDate"), visibility("default"))); +# undef FcConfigBuildFonts +extern __typeof (FcConfigBuildFonts) FcConfigBuildFonts __attribute((alias("IA__FcConfigBuildFonts"), visibility("default"))); +# undef FcConfigGetFontDirs +extern __typeof (FcConfigGetFontDirs) FcConfigGetFontDirs __attribute((alias("IA__FcConfigGetFontDirs"), visibility("default"))); +# undef FcConfigGetConfigDirs +extern __typeof (FcConfigGetConfigDirs) FcConfigGetConfigDirs __attribute((alias("IA__FcConfigGetConfigDirs"), visibility("default"))); +# undef FcConfigGetConfigFiles +extern __typeof (FcConfigGetConfigFiles) FcConfigGetConfigFiles __attribute((alias("IA__FcConfigGetConfigFiles"), visibility("default"))); +# undef FcConfigGetCache +extern __typeof (FcConfigGetCache) FcConfigGetCache __attribute((alias("IA__FcConfigGetCache"), visibility("default"))); +# undef FcConfigGetBlanks +extern __typeof (FcConfigGetBlanks) FcConfigGetBlanks __attribute((alias("IA__FcConfigGetBlanks"), visibility("default"))); +# undef FcConfigGetCacheDirs +extern __typeof (FcConfigGetCacheDirs) FcConfigGetCacheDirs __attribute((alias("IA__FcConfigGetCacheDirs"), visibility("default"))); +# undef FcConfigGetRescanInterval +extern __typeof (FcConfigGetRescanInterval) FcConfigGetRescanInterval __attribute((alias("IA__FcConfigGetRescanInterval"), visibility("default"))); +# undef FcConfigSetRescanInterval +extern __typeof (FcConfigSetRescanInterval) FcConfigSetRescanInterval __attribute((alias("IA__FcConfigSetRescanInterval"), visibility("default"))); +# undef FcConfigGetFonts +extern __typeof (FcConfigGetFonts) FcConfigGetFonts __attribute((alias("IA__FcConfigGetFonts"), visibility("default"))); +# undef FcConfigAppFontAddFile +extern __typeof (FcConfigAppFontAddFile) FcConfigAppFontAddFile __attribute((alias("IA__FcConfigAppFontAddFile"), visibility("default"))); +# undef FcConfigAppFontAddDir +extern __typeof (FcConfigAppFontAddDir) FcConfigAppFontAddDir __attribute((alias("IA__FcConfigAppFontAddDir"), visibility("default"))); +# undef FcConfigAppFontClear +extern __typeof (FcConfigAppFontClear) FcConfigAppFontClear __attribute((alias("IA__FcConfigAppFontClear"), visibility("default"))); +# undef FcConfigSubstituteWithPat +extern __typeof (FcConfigSubstituteWithPat) FcConfigSubstituteWithPat __attribute((alias("IA__FcConfigSubstituteWithPat"), visibility("default"))); +# undef FcConfigSubstitute +extern __typeof (FcConfigSubstitute) FcConfigSubstitute __attribute((alias("IA__FcConfigSubstitute"), visibility("default"))); +# undef FcConfigGetSysRoot +extern __typeof (FcConfigGetSysRoot) FcConfigGetSysRoot __attribute((alias("IA__FcConfigGetSysRoot"), visibility("default"))); +# undef FcConfigSetSysRoot +extern __typeof (FcConfigSetSysRoot) FcConfigSetSysRoot __attribute((alias("IA__FcConfigSetSysRoot"), visibility("default"))); +#endif /* __fccfg__ */ +#ifdef __fccharset__ +# undef FcCharSetCreate +extern __typeof (FcCharSetCreate) FcCharSetCreate __attribute((alias("IA__FcCharSetCreate"), visibility("default"))); +# undef FcCharSetNew +extern __typeof (FcCharSetNew) FcCharSetNew __attribute((alias("IA__FcCharSetNew"), visibility("default"))); +# undef FcCharSetDestroy +extern __typeof (FcCharSetDestroy) FcCharSetDestroy __attribute((alias("IA__FcCharSetDestroy"), visibility("default"))); +# undef FcCharSetAddChar +extern __typeof (FcCharSetAddChar) FcCharSetAddChar __attribute((alias("IA__FcCharSetAddChar"), visibility("default"))); +# undef FcCharSetDelChar +extern __typeof (FcCharSetDelChar) FcCharSetDelChar __attribute((alias("IA__FcCharSetDelChar"), visibility("default"))); +# undef FcCharSetCopy +extern __typeof (FcCharSetCopy) FcCharSetCopy __attribute((alias("IA__FcCharSetCopy"), visibility("default"))); +# undef FcCharSetEqual +extern __typeof (FcCharSetEqual) FcCharSetEqual __attribute((alias("IA__FcCharSetEqual"), visibility("default"))); +# undef FcCharSetIntersect +extern __typeof (FcCharSetIntersect) FcCharSetIntersect __attribute((alias("IA__FcCharSetIntersect"), visibility("default"))); +# undef FcCharSetUnion +extern __typeof (FcCharSetUnion) FcCharSetUnion __attribute((alias("IA__FcCharSetUnion"), visibility("default"))); +# undef FcCharSetSubtract +extern __typeof (FcCharSetSubtract) FcCharSetSubtract __attribute((alias("IA__FcCharSetSubtract"), visibility("default"))); +# undef FcCharSetMerge +extern __typeof (FcCharSetMerge) FcCharSetMerge __attribute((alias("IA__FcCharSetMerge"), visibility("default"))); +# undef FcCharSetHasChar +extern __typeof (FcCharSetHasChar) FcCharSetHasChar __attribute((alias("IA__FcCharSetHasChar"), visibility("default"))); +# undef FcCharSetCount +extern __typeof (FcCharSetCount) FcCharSetCount __attribute((alias("IA__FcCharSetCount"), visibility("default"))); +# undef FcCharSetIntersectCount +extern __typeof (FcCharSetIntersectCount) FcCharSetIntersectCount __attribute((alias("IA__FcCharSetIntersectCount"), visibility("default"))); +# undef FcCharSetSubtractCount +extern __typeof (FcCharSetSubtractCount) FcCharSetSubtractCount __attribute((alias("IA__FcCharSetSubtractCount"), visibility("default"))); +# undef FcCharSetIsSubset +extern __typeof (FcCharSetIsSubset) FcCharSetIsSubset __attribute((alias("IA__FcCharSetIsSubset"), visibility("default"))); +# undef FcCharSetFirstPage +extern __typeof (FcCharSetFirstPage) FcCharSetFirstPage __attribute((alias("IA__FcCharSetFirstPage"), visibility("default"))); +# undef FcCharSetNextPage +extern __typeof (FcCharSetNextPage) FcCharSetNextPage __attribute((alias("IA__FcCharSetNextPage"), visibility("default"))); +# undef FcCharSetCoverage +extern __typeof (FcCharSetCoverage) FcCharSetCoverage __attribute((alias("IA__FcCharSetCoverage"), visibility("default"))); +#endif /* __fccharset__ */ +#ifdef __fcdbg__ +# undef FcValuePrint +extern __typeof (FcValuePrint) FcValuePrint __attribute((alias("IA__FcValuePrint"), visibility("default"))); +# undef FcPatternPrint +extern __typeof (FcPatternPrint) FcPatternPrint __attribute((alias("IA__FcPatternPrint"), visibility("default"))); +# undef FcFontSetPrint +extern __typeof (FcFontSetPrint) FcFontSetPrint __attribute((alias("IA__FcFontSetPrint"), visibility("default"))); +#endif /* __fcdbg__ */ +#ifdef __fcdefault__ +# undef FcGetDefaultLangs +extern __typeof (FcGetDefaultLangs) FcGetDefaultLangs __attribute((alias("IA__FcGetDefaultLangs"), visibility("default"))); +# undef FcDefaultSubstitute +extern __typeof (FcDefaultSubstitute) FcDefaultSubstitute __attribute((alias("IA__FcDefaultSubstitute"), visibility("default"))); +#endif /* __fcdefault__ */ +#ifdef __fcdir__ +# undef FcFileIsDir +extern __typeof (FcFileIsDir) FcFileIsDir __attribute((alias("IA__FcFileIsDir"), visibility("default"))); +# undef FcFileScan +extern __typeof (FcFileScan) FcFileScan __attribute((alias("IA__FcFileScan"), visibility("default"))); +# undef FcDirScan +extern __typeof (FcDirScan) FcDirScan __attribute((alias("IA__FcDirScan"), visibility("default"))); +# undef FcDirSave +extern __typeof (FcDirSave) FcDirSave __attribute((alias("IA__FcDirSave"), visibility("default"))); +#endif /* __fcdir__ */ +#ifdef __fccache__ +# undef FcDirCacheLoad +extern __typeof (FcDirCacheLoad) FcDirCacheLoad __attribute((alias("IA__FcDirCacheLoad"), visibility("default"))); +#endif /* __fccache__ */ +#ifdef __fcdir__ +# undef FcDirCacheRescan +extern __typeof (FcDirCacheRescan) FcDirCacheRescan __attribute((alias("IA__FcDirCacheRescan"), visibility("default"))); +# undef FcDirCacheRead +extern __typeof (FcDirCacheRead) FcDirCacheRead __attribute((alias("IA__FcDirCacheRead"), visibility("default"))); +#endif /* __fcdir__ */ +#ifdef __fccache__ +# undef FcDirCacheLoadFile +extern __typeof (FcDirCacheLoadFile) FcDirCacheLoadFile __attribute((alias("IA__FcDirCacheLoadFile"), visibility("default"))); +# undef FcDirCacheUnload +extern __typeof (FcDirCacheUnload) FcDirCacheUnload __attribute((alias("IA__FcDirCacheUnload"), visibility("default"))); +#endif /* __fccache__ */ +#ifdef __fcfreetype__ +# undef FcFreeTypeQuery +extern __typeof (FcFreeTypeQuery) FcFreeTypeQuery __attribute((alias("IA__FcFreeTypeQuery"), visibility("default"))); +#endif /* __fcfreetype__ */ +#ifdef __fcfs__ +# undef FcFontSetCreate +extern __typeof (FcFontSetCreate) FcFontSetCreate __attribute((alias("IA__FcFontSetCreate"), visibility("default"))); +# undef FcFontSetDestroy +extern __typeof (FcFontSetDestroy) FcFontSetDestroy __attribute((alias("IA__FcFontSetDestroy"), visibility("default"))); +# undef FcFontSetAdd +extern __typeof (FcFontSetAdd) FcFontSetAdd __attribute((alias("IA__FcFontSetAdd"), visibility("default"))); +#endif /* __fcfs__ */ +#ifdef __fcinit__ +# undef FcInitLoadConfig +extern __typeof (FcInitLoadConfig) FcInitLoadConfig __attribute((alias("IA__FcInitLoadConfig"), visibility("default"))); +# undef FcInitLoadConfigAndFonts +extern __typeof (FcInitLoadConfigAndFonts) FcInitLoadConfigAndFonts __attribute((alias("IA__FcInitLoadConfigAndFonts"), visibility("default"))); +# undef FcInit +extern __typeof (FcInit) FcInit __attribute((alias("IA__FcInit"), visibility("default"))); +# undef FcFini +extern __typeof (FcFini) FcFini __attribute((alias("IA__FcFini"), visibility("default"))); +# undef FcGetVersion +extern __typeof (FcGetVersion) FcGetVersion __attribute((alias("IA__FcGetVersion"), visibility("default"))); +# undef FcInitReinitialize +extern __typeof (FcInitReinitialize) FcInitReinitialize __attribute((alias("IA__FcInitReinitialize"), visibility("default"))); +# undef FcInitBringUptoDate +extern __typeof (FcInitBringUptoDate) FcInitBringUptoDate __attribute((alias("IA__FcInitBringUptoDate"), visibility("default"))); +#endif /* __fcinit__ */ +#ifdef __fclang__ +# undef FcGetLangs +extern __typeof (FcGetLangs) FcGetLangs __attribute((alias("IA__FcGetLangs"), visibility("default"))); +# undef FcLangNormalize +extern __typeof (FcLangNormalize) FcLangNormalize __attribute((alias("IA__FcLangNormalize"), visibility("default"))); +# undef FcLangGetCharSet +extern __typeof (FcLangGetCharSet) FcLangGetCharSet __attribute((alias("IA__FcLangGetCharSet"), visibility("default"))); +# undef FcLangSetCreate +extern __typeof (FcLangSetCreate) FcLangSetCreate __attribute((alias("IA__FcLangSetCreate"), visibility("default"))); +# undef FcLangSetDestroy +extern __typeof (FcLangSetDestroy) FcLangSetDestroy __attribute((alias("IA__FcLangSetDestroy"), visibility("default"))); +# undef FcLangSetCopy +extern __typeof (FcLangSetCopy) FcLangSetCopy __attribute((alias("IA__FcLangSetCopy"), visibility("default"))); +# undef FcLangSetAdd +extern __typeof (FcLangSetAdd) FcLangSetAdd __attribute((alias("IA__FcLangSetAdd"), visibility("default"))); +# undef FcLangSetDel +extern __typeof (FcLangSetDel) FcLangSetDel __attribute((alias("IA__FcLangSetDel"), visibility("default"))); +# undef FcLangSetHasLang +extern __typeof (FcLangSetHasLang) FcLangSetHasLang __attribute((alias("IA__FcLangSetHasLang"), visibility("default"))); +# undef FcLangSetCompare +extern __typeof (FcLangSetCompare) FcLangSetCompare __attribute((alias("IA__FcLangSetCompare"), visibility("default"))); +# undef FcLangSetContains +extern __typeof (FcLangSetContains) FcLangSetContains __attribute((alias("IA__FcLangSetContains"), visibility("default"))); +# undef FcLangSetEqual +extern __typeof (FcLangSetEqual) FcLangSetEqual __attribute((alias("IA__FcLangSetEqual"), visibility("default"))); +# undef FcLangSetHash +extern __typeof (FcLangSetHash) FcLangSetHash __attribute((alias("IA__FcLangSetHash"), visibility("default"))); +# undef FcLangSetGetLangs +extern __typeof (FcLangSetGetLangs) FcLangSetGetLangs __attribute((alias("IA__FcLangSetGetLangs"), visibility("default"))); +# undef FcLangSetUnion +extern __typeof (FcLangSetUnion) FcLangSetUnion __attribute((alias("IA__FcLangSetUnion"), visibility("default"))); +# undef FcLangSetSubtract +extern __typeof (FcLangSetSubtract) FcLangSetSubtract __attribute((alias("IA__FcLangSetSubtract"), visibility("default"))); +#endif /* __fclang__ */ +#ifdef __fclist__ +# undef FcObjectSetCreate +extern __typeof (FcObjectSetCreate) FcObjectSetCreate __attribute((alias("IA__FcObjectSetCreate"), visibility("default"))); +# undef FcObjectSetAdd +extern __typeof (FcObjectSetAdd) FcObjectSetAdd __attribute((alias("IA__FcObjectSetAdd"), visibility("default"))); +# undef FcObjectSetDestroy +extern __typeof (FcObjectSetDestroy) FcObjectSetDestroy __attribute((alias("IA__FcObjectSetDestroy"), visibility("default"))); +# undef FcObjectSetVaBuild +extern __typeof (FcObjectSetVaBuild) FcObjectSetVaBuild __attribute((alias("IA__FcObjectSetVaBuild"), visibility("default"))); +# undef FcObjectSetBuild +extern __typeof (FcObjectSetBuild) FcObjectSetBuild __attribute((alias("IA__FcObjectSetBuild"), visibility("default"))); +# undef FcFontSetList +extern __typeof (FcFontSetList) FcFontSetList __attribute((alias("IA__FcFontSetList"), visibility("default"))); +# undef FcFontList +extern __typeof (FcFontList) FcFontList __attribute((alias("IA__FcFontList"), visibility("default"))); +#endif /* __fclist__ */ +#ifdef __fcatomic__ +# undef FcAtomicCreate +extern __typeof (FcAtomicCreate) FcAtomicCreate __attribute((alias("IA__FcAtomicCreate"), visibility("default"))); +# undef FcAtomicLock +extern __typeof (FcAtomicLock) FcAtomicLock __attribute((alias("IA__FcAtomicLock"), visibility("default"))); +# undef FcAtomicNewFile +extern __typeof (FcAtomicNewFile) FcAtomicNewFile __attribute((alias("IA__FcAtomicNewFile"), visibility("default"))); +# undef FcAtomicOrigFile +extern __typeof (FcAtomicOrigFile) FcAtomicOrigFile __attribute((alias("IA__FcAtomicOrigFile"), visibility("default"))); +# undef FcAtomicReplaceOrig +extern __typeof (FcAtomicReplaceOrig) FcAtomicReplaceOrig __attribute((alias("IA__FcAtomicReplaceOrig"), visibility("default"))); +# undef FcAtomicDeleteNew +extern __typeof (FcAtomicDeleteNew) FcAtomicDeleteNew __attribute((alias("IA__FcAtomicDeleteNew"), visibility("default"))); +# undef FcAtomicUnlock +extern __typeof (FcAtomicUnlock) FcAtomicUnlock __attribute((alias("IA__FcAtomicUnlock"), visibility("default"))); +# undef FcAtomicDestroy +extern __typeof (FcAtomicDestroy) FcAtomicDestroy __attribute((alias("IA__FcAtomicDestroy"), visibility("default"))); +#endif /* __fcatomic__ */ +#ifdef __fcmatch__ +# undef FcFontSetMatch +extern __typeof (FcFontSetMatch) FcFontSetMatch __attribute((alias("IA__FcFontSetMatch"), visibility("default"))); +# undef FcFontMatch +extern __typeof (FcFontMatch) FcFontMatch __attribute((alias("IA__FcFontMatch"), visibility("default"))); +# undef FcFontRenderPrepare +extern __typeof (FcFontRenderPrepare) FcFontRenderPrepare __attribute((alias("IA__FcFontRenderPrepare"), visibility("default"))); +# undef FcFontSetSort +extern __typeof (FcFontSetSort) FcFontSetSort __attribute((alias("IA__FcFontSetSort"), visibility("default"))); +# undef FcFontSort +extern __typeof (FcFontSort) FcFontSort __attribute((alias("IA__FcFontSort"), visibility("default"))); +# undef FcFontSetSortDestroy +extern __typeof (FcFontSetSortDestroy) FcFontSetSortDestroy __attribute((alias("IA__FcFontSetSortDestroy"), visibility("default"))); +#endif /* __fcmatch__ */ +#ifdef __fcmatrix__ +# undef FcMatrixCopy +extern __typeof (FcMatrixCopy) FcMatrixCopy __attribute((alias("IA__FcMatrixCopy"), visibility("default"))); +# undef FcMatrixEqual +extern __typeof (FcMatrixEqual) FcMatrixEqual __attribute((alias("IA__FcMatrixEqual"), visibility("default"))); +# undef FcMatrixMultiply +extern __typeof (FcMatrixMultiply) FcMatrixMultiply __attribute((alias("IA__FcMatrixMultiply"), visibility("default"))); +# undef FcMatrixRotate +extern __typeof (FcMatrixRotate) FcMatrixRotate __attribute((alias("IA__FcMatrixRotate"), visibility("default"))); +# undef FcMatrixScale +extern __typeof (FcMatrixScale) FcMatrixScale __attribute((alias("IA__FcMatrixScale"), visibility("default"))); +# undef FcMatrixShear +extern __typeof (FcMatrixShear) FcMatrixShear __attribute((alias("IA__FcMatrixShear"), visibility("default"))); +#endif /* __fcmatrix__ */ +#ifdef __fcname__ +# undef FcNameRegisterObjectTypes +extern __typeof (FcNameRegisterObjectTypes) FcNameRegisterObjectTypes __attribute((alias("IA__FcNameRegisterObjectTypes"), visibility("default"))); +# undef FcNameUnregisterObjectTypes +extern __typeof (FcNameUnregisterObjectTypes) FcNameUnregisterObjectTypes __attribute((alias("IA__FcNameUnregisterObjectTypes"), visibility("default"))); +# undef FcNameGetObjectType +extern __typeof (FcNameGetObjectType) FcNameGetObjectType __attribute((alias("IA__FcNameGetObjectType"), visibility("default"))); +# undef FcNameRegisterConstants +extern __typeof (FcNameRegisterConstants) FcNameRegisterConstants __attribute((alias("IA__FcNameRegisterConstants"), visibility("default"))); +# undef FcNameUnregisterConstants +extern __typeof (FcNameUnregisterConstants) FcNameUnregisterConstants __attribute((alias("IA__FcNameUnregisterConstants"), visibility("default"))); +# undef FcNameGetConstant +extern __typeof (FcNameGetConstant) FcNameGetConstant __attribute((alias("IA__FcNameGetConstant"), visibility("default"))); +# undef FcNameConstant +extern __typeof (FcNameConstant) FcNameConstant __attribute((alias("IA__FcNameConstant"), visibility("default"))); +# undef FcNameParse +extern __typeof (FcNameParse) FcNameParse __attribute((alias("IA__FcNameParse"), visibility("default"))); +# undef FcNameUnparse +extern __typeof (FcNameUnparse) FcNameUnparse __attribute((alias("IA__FcNameUnparse"), visibility("default"))); +#endif /* __fcname__ */ +#ifdef __fcpat__ +# undef FcPatternCreate +extern __typeof (FcPatternCreate) FcPatternCreate __attribute((alias("IA__FcPatternCreate"), visibility("default"))); +# undef FcPatternDuplicate +extern __typeof (FcPatternDuplicate) FcPatternDuplicate __attribute((alias("IA__FcPatternDuplicate"), visibility("default"))); +# undef FcPatternReference +extern __typeof (FcPatternReference) FcPatternReference __attribute((alias("IA__FcPatternReference"), visibility("default"))); +# undef FcPatternFilter +extern __typeof (FcPatternFilter) FcPatternFilter __attribute((alias("IA__FcPatternFilter"), visibility("default"))); +# undef FcValueDestroy +extern __typeof (FcValueDestroy) FcValueDestroy __attribute((alias("IA__FcValueDestroy"), visibility("default"))); +# undef FcValueEqual +extern __typeof (FcValueEqual) FcValueEqual __attribute((alias("IA__FcValueEqual"), visibility("default"))); +# undef FcValueSave +extern __typeof (FcValueSave) FcValueSave __attribute((alias("IA__FcValueSave"), visibility("default"))); +# undef FcPatternDestroy +extern __typeof (FcPatternDestroy) FcPatternDestroy __attribute((alias("IA__FcPatternDestroy"), visibility("default"))); +# undef FcPatternEqual +extern __typeof (FcPatternEqual) FcPatternEqual __attribute((alias("IA__FcPatternEqual"), visibility("default"))); +# undef FcPatternEqualSubset +extern __typeof (FcPatternEqualSubset) FcPatternEqualSubset __attribute((alias("IA__FcPatternEqualSubset"), visibility("default"))); +# undef FcPatternHash +extern __typeof (FcPatternHash) FcPatternHash __attribute((alias("IA__FcPatternHash"), visibility("default"))); +# undef FcPatternAdd +extern __typeof (FcPatternAdd) FcPatternAdd __attribute((alias("IA__FcPatternAdd"), visibility("default"))); +# undef FcPatternAddWeak +extern __typeof (FcPatternAddWeak) FcPatternAddWeak __attribute((alias("IA__FcPatternAddWeak"), visibility("default"))); +# undef FcPatternGet +extern __typeof (FcPatternGet) FcPatternGet __attribute((alias("IA__FcPatternGet"), visibility("default"))); +# undef FcPatternDel +extern __typeof (FcPatternDel) FcPatternDel __attribute((alias("IA__FcPatternDel"), visibility("default"))); +# undef FcPatternRemove +extern __typeof (FcPatternRemove) FcPatternRemove __attribute((alias("IA__FcPatternRemove"), visibility("default"))); +# undef FcPatternAddInteger +extern __typeof (FcPatternAddInteger) FcPatternAddInteger __attribute((alias("IA__FcPatternAddInteger"), visibility("default"))); +# undef FcPatternAddDouble +extern __typeof (FcPatternAddDouble) FcPatternAddDouble __attribute((alias("IA__FcPatternAddDouble"), visibility("default"))); +# undef FcPatternAddString +extern __typeof (FcPatternAddString) FcPatternAddString __attribute((alias("IA__FcPatternAddString"), visibility("default"))); +# undef FcPatternAddMatrix +extern __typeof (FcPatternAddMatrix) FcPatternAddMatrix __attribute((alias("IA__FcPatternAddMatrix"), visibility("default"))); +# undef FcPatternAddCharSet +extern __typeof (FcPatternAddCharSet) FcPatternAddCharSet __attribute((alias("IA__FcPatternAddCharSet"), visibility("default"))); +# undef FcPatternAddBool +extern __typeof (FcPatternAddBool) FcPatternAddBool __attribute((alias("IA__FcPatternAddBool"), visibility("default"))); +# undef FcPatternAddLangSet +extern __typeof (FcPatternAddLangSet) FcPatternAddLangSet __attribute((alias("IA__FcPatternAddLangSet"), visibility("default"))); +# undef FcPatternGetInteger +extern __typeof (FcPatternGetInteger) FcPatternGetInteger __attribute((alias("IA__FcPatternGetInteger"), visibility("default"))); +# undef FcPatternGetDouble +extern __typeof (FcPatternGetDouble) FcPatternGetDouble __attribute((alias("IA__FcPatternGetDouble"), visibility("default"))); +# undef FcPatternGetString +extern __typeof (FcPatternGetString) FcPatternGetString __attribute((alias("IA__FcPatternGetString"), visibility("default"))); +# undef FcPatternGetMatrix +extern __typeof (FcPatternGetMatrix) FcPatternGetMatrix __attribute((alias("IA__FcPatternGetMatrix"), visibility("default"))); +# undef FcPatternGetCharSet +extern __typeof (FcPatternGetCharSet) FcPatternGetCharSet __attribute((alias("IA__FcPatternGetCharSet"), visibility("default"))); +# undef FcPatternGetBool +extern __typeof (FcPatternGetBool) FcPatternGetBool __attribute((alias("IA__FcPatternGetBool"), visibility("default"))); +# undef FcPatternGetLangSet +extern __typeof (FcPatternGetLangSet) FcPatternGetLangSet __attribute((alias("IA__FcPatternGetLangSet"), visibility("default"))); +# undef FcPatternVaBuild +extern __typeof (FcPatternVaBuild) FcPatternVaBuild __attribute((alias("IA__FcPatternVaBuild"), visibility("default"))); +# undef FcPatternBuild +extern __typeof (FcPatternBuild) FcPatternBuild __attribute((alias("IA__FcPatternBuild"), visibility("default"))); +#endif /* __fcpat__ */ +#ifdef __fcformat__ +# undef FcPatternFormat +extern __typeof (FcPatternFormat) FcPatternFormat __attribute((alias("IA__FcPatternFormat"), visibility("default"))); +#endif /* __fcformat__ */ +#ifdef __fcstr__ +# undef FcStrCopy +extern __typeof (FcStrCopy) FcStrCopy __attribute((alias("IA__FcStrCopy"), visibility("default"))); +# undef FcStrCopyFilename +extern __typeof (FcStrCopyFilename) FcStrCopyFilename __attribute((alias("IA__FcStrCopyFilename"), visibility("default"))); +# undef FcStrPlus +extern __typeof (FcStrPlus) FcStrPlus __attribute((alias("IA__FcStrPlus"), visibility("default"))); +# undef FcStrFree +extern __typeof (FcStrFree) FcStrFree __attribute((alias("IA__FcStrFree"), visibility("default"))); +# undef FcStrDowncase +extern __typeof (FcStrDowncase) FcStrDowncase __attribute((alias("IA__FcStrDowncase"), visibility("default"))); +# undef FcStrCmpIgnoreCase +extern __typeof (FcStrCmpIgnoreCase) FcStrCmpIgnoreCase __attribute((alias("IA__FcStrCmpIgnoreCase"), visibility("default"))); +# undef FcStrCmp +extern __typeof (FcStrCmp) FcStrCmp __attribute((alias("IA__FcStrCmp"), visibility("default"))); +# undef FcStrStrIgnoreCase +extern __typeof (FcStrStrIgnoreCase) FcStrStrIgnoreCase __attribute((alias("IA__FcStrStrIgnoreCase"), visibility("default"))); +# undef FcStrStr +extern __typeof (FcStrStr) FcStrStr __attribute((alias("IA__FcStrStr"), visibility("default"))); +# undef FcUtf8ToUcs4 +extern __typeof (FcUtf8ToUcs4) FcUtf8ToUcs4 __attribute((alias("IA__FcUtf8ToUcs4"), visibility("default"))); +# undef FcUtf8Len +extern __typeof (FcUtf8Len) FcUtf8Len __attribute((alias("IA__FcUtf8Len"), visibility("default"))); +# undef FcUcs4ToUtf8 +extern __typeof (FcUcs4ToUtf8) FcUcs4ToUtf8 __attribute((alias("IA__FcUcs4ToUtf8"), visibility("default"))); +# undef FcUtf16ToUcs4 +extern __typeof (FcUtf16ToUcs4) FcUtf16ToUcs4 __attribute((alias("IA__FcUtf16ToUcs4"), visibility("default"))); +# undef FcUtf16Len +extern __typeof (FcUtf16Len) FcUtf16Len __attribute((alias("IA__FcUtf16Len"), visibility("default"))); +# undef FcStrDirname +extern __typeof (FcStrDirname) FcStrDirname __attribute((alias("IA__FcStrDirname"), visibility("default"))); +# undef FcStrBasename +extern __typeof (FcStrBasename) FcStrBasename __attribute((alias("IA__FcStrBasename"), visibility("default"))); +# undef FcStrSetCreate +extern __typeof (FcStrSetCreate) FcStrSetCreate __attribute((alias("IA__FcStrSetCreate"), visibility("default"))); +# undef FcStrSetMember +extern __typeof (FcStrSetMember) FcStrSetMember __attribute((alias("IA__FcStrSetMember"), visibility("default"))); +# undef FcStrSetEqual +extern __typeof (FcStrSetEqual) FcStrSetEqual __attribute((alias("IA__FcStrSetEqual"), visibility("default"))); +# undef FcStrSetAdd +extern __typeof (FcStrSetAdd) FcStrSetAdd __attribute((alias("IA__FcStrSetAdd"), visibility("default"))); +# undef FcStrSetAddFilename +extern __typeof (FcStrSetAddFilename) FcStrSetAddFilename __attribute((alias("IA__FcStrSetAddFilename"), visibility("default"))); +# undef FcStrSetDel +extern __typeof (FcStrSetDel) FcStrSetDel __attribute((alias("IA__FcStrSetDel"), visibility("default"))); +# undef FcStrSetDestroy +extern __typeof (FcStrSetDestroy) FcStrSetDestroy __attribute((alias("IA__FcStrSetDestroy"), visibility("default"))); +# undef FcStrListCreate +extern __typeof (FcStrListCreate) FcStrListCreate __attribute((alias("IA__FcStrListCreate"), visibility("default"))); +# undef FcStrListFirst +extern __typeof (FcStrListFirst) FcStrListFirst __attribute((alias("IA__FcStrListFirst"), visibility("default"))); +# undef FcStrListNext +extern __typeof (FcStrListNext) FcStrListNext __attribute((alias("IA__FcStrListNext"), visibility("default"))); +# undef FcStrListDone +extern __typeof (FcStrListDone) FcStrListDone __attribute((alias("IA__FcStrListDone"), visibility("default"))); +#endif /* __fcstr__ */ +#ifdef __fcxml__ +# undef FcConfigParseAndLoad +extern __typeof (FcConfigParseAndLoad) FcConfigParseAndLoad __attribute((alias("IA__FcConfigParseAndLoad"), visibility("default"))); +#endif /* __fcxml__ */ +#ifdef __fccfg__ +# undef FcConfigGetRescanInverval +extern __typeof (FcConfigGetRescanInverval) FcConfigGetRescanInverval __attribute((alias("IA__FcConfigGetRescanInverval"), visibility("default"))); +# undef FcConfigSetRescanInverval +extern __typeof (FcConfigSetRescanInverval) FcConfigSetRescanInverval __attribute((alias("IA__FcConfigSetRescanInverval"), visibility("default"))); +#endif /* */ +#endif /* HAVE_GNUC_ATTRIBUTE */ diff --git a/project/jni/fontconfig/src/fcarch.c b/project/jni/fontconfig/src/fcarch.c new file mode 100644 index 000000000..398f4bbfc --- /dev/null +++ b/project/jni/fontconfig/src/fcarch.c @@ -0,0 +1,60 @@ +/* + * Copyright © 2002 Keith Packard + * Copyright © 2010 Behdad Esfahbod + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include "fcint.h" +#include "fcarch.h" + +FC_ASSERT_STATIC (1 == sizeof (char)); +FC_ASSERT_STATIC (2 == sizeof (FcChar16)); +FC_ASSERT_STATIC (4 == sizeof (int)); +FC_ASSERT_STATIC (4 == sizeof (FcChar32)); +FC_ASSERT_STATIC (4 == sizeof (FcObject)); +FC_ASSERT_STATIC (4 == sizeof (FcValueBinding)); +FC_ASSERT_STATIC (8 == sizeof (FcAlign)); +FC_ASSERT_STATIC (0x20 == sizeof (FcCharLeaf)); + +FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (intptr_t)); +FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcPatternEltPtr)); +FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcValueListPtr)); +FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (char *)); +FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (struct FcPatternElt *)); +FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcValueList *)); +FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcStrSet *)); +FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcCharLeaf **)); +FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcChar16 *)); + +FC_ASSERT_STATIC (0x08 + 1*FC_MAX(SIZEOF_VOID_P,ALIGNOF_DOUBLE) == sizeof (FcValue)); +FC_ASSERT_STATIC (0x00 + 2*SIZEOF_VOID_P == sizeof (FcPatternElt)); +FC_ASSERT_STATIC (0x08 + 2*SIZEOF_VOID_P == sizeof (FcPattern)); +FC_ASSERT_STATIC (0x08 + 2*SIZEOF_VOID_P == sizeof (FcCharSet)); +FC_ASSERT_STATIC (0x08 + 6*SIZEOF_VOID_P == sizeof (FcCache)); + + +int +main (int argc FC_UNUSED, char **argv FC_UNUSED) +{ + printf ("%s\n", FC_ARCHITECTURE); + return 0; +} diff --git a/project/jni/fontconfig/src/fcarch.h b/project/jni/fontconfig/src/fcarch.h new file mode 100644 index 000000000..049a5b02b --- /dev/null +++ b/project/jni/fontconfig/src/fcarch.h @@ -0,0 +1,76 @@ +/* + * Copyright © 2006 Keith Packard + * Copyright © 2010 Behdad Esfahbod + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef _FCARCH_H_ +#define _FCARCH_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/* + * Each unique machine architecture needs an entry in this file + * So far the differences boil down to: endianness, 32 vs 64 bit pointers, + * and on 32bit ones, whether double is aligned to one word or two words. + * Those result in the 6 formats listed below. + * + * If any of the assertion errors in fcarch.c fail, you need to add a new + * architecture. Contact the fontconfig mailing list in that case. + * + * name endianness pointer-size double-alignment + * + * le32d4 4321 4 4 + * le32d8 4321 4 8 + * le64 4321 8 8 + * be32d4 1234 4 4 + * be32d8 1234 4 8 + * be64 1234 8 8 + */ + +#if defined(__DARWIN_BYTE_ORDER) && __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN +# define FC_ARCH_ENDIAN "le" +#elif defined(__DARWIN_BYTE_ORDER) && __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN +# define FC_ARCH_ENDIAN "be" +#elif defined(__DARWIN_BYTE_ORDER) && __DARWIN_BYTE_ORDER == __DARWIN_PDP_ENDIAN +# define FC_ARCH_ENDIAN "pe" +#elif defined(WORDS_BIGENDIAN) && WORDS_BIGENDIAN +# define FC_ARCH_ENDIAN "be" +#else +# define FC_ARCH_ENDIAN "le" +#endif + +#if SIZEOF_VOID_P == 4 +# if ALIGNOF_DOUBLE == 4 +# define FC_ARCH_SIZE_ALIGN "32d4" +# else /* ALIGNOF_DOUBLE != 4 */ +# define FC_ARCH_SIZE_ALIGN "32d8" +# endif +#else /* SIZEOF_VOID_P != 4 */ +# define FC_ARCH_SIZE_ALIGN "64" +#endif + +/* config.h might override this */ +#ifndef FC_ARCHITECTURE +# define FC_ARCHITECTURE FC_ARCH_ENDIAN FC_ARCH_SIZE_ALIGN +#endif + +#endif /* _FCARCH_H_ */ diff --git a/project/jni/fontconfig/src/fcatomic.c b/project/jni/fontconfig/src/fcatomic.c new file mode 100644 index 000000000..c1daed938 --- /dev/null +++ b/project/jni/fontconfig/src/fcatomic.c @@ -0,0 +1,229 @@ +/* + * fontconfig/src/fcatomic.c + * + * Copyright © 2002 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * fcatomic.c + * + * Lock cache and configuration files for atomic update + * + * Uses only regular filesystem calls so it should + * work even in the absense of functioning file locking + * + * On Unix, four files are used: + * file - the data file accessed by other apps. + * new - a new version of the data file while it's being written + * lck - the lock file + * tmp - a temporary file made unique with mkstemp + * + * Here's how it works: + * Create 'tmp' and store our PID in it + * Attempt to link it to 'lck' + * Unlink 'tmp' + * If the link succeeded, the lock is held + * + * On Windows, where there are no links, no tmp file is used, and lck + * is a directory that's mkdir'ed. If the mkdir succeeds, the lock is + * held. + */ + +#include "fcint.h" +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#define mkdir(path,mode) _mkdir(path) +#endif + +#define NEW_NAME ".NEW" +#define LCK_NAME ".LCK" +#define TMP_NAME ".TMP-XXXXXX" + +FcAtomic * +FcAtomicCreate (const FcChar8 *file) +{ + int file_len = strlen ((char *) file); + int new_len = file_len + sizeof (NEW_NAME); + int lck_len = file_len + sizeof (LCK_NAME); + int tmp_len = file_len + sizeof (TMP_NAME); + int total_len = (sizeof (FcAtomic) + + file_len + 1 + + new_len + 1 + + lck_len + 1 + + tmp_len + 1); + FcAtomic *atomic = malloc (total_len); + if (!atomic) + return 0; + + atomic->file = (FcChar8 *) (atomic + 1); + strcpy ((char *) atomic->file, (char *) file); + + atomic->new = atomic->file + file_len + 1; + strcpy ((char *) atomic->new, (char *) file); + strcat ((char *) atomic->new, NEW_NAME); + + atomic->lck = atomic->new + new_len + 1; + strcpy ((char *) atomic->lck, (char *) file); + strcat ((char *) atomic->lck, LCK_NAME); + + atomic->tmp = atomic->lck + lck_len + 1; + + return atomic; +} + +FcBool +FcAtomicLock (FcAtomic *atomic) +{ + int ret; + struct stat lck_stat; + +#ifdef HAVE_LINK + int fd = -1; + FILE *f = 0; + FcBool no_link = FcFalse; + + strcpy ((char *) atomic->tmp, (char *) atomic->file); + strcat ((char *) atomic->tmp, TMP_NAME); + fd = FcMakeTempfile ((char *) atomic->tmp); + if (fd < 0) + return FcFalse; + f = fdopen (fd, "w"); + if (!f) + { + close (fd); + unlink ((char *) atomic->tmp); + return FcFalse; + } + ret = fprintf (f, "%ld\n", (long)getpid()); + if (ret <= 0) + { + fclose (f); + unlink ((char *) atomic->tmp); + return FcFalse; + } + if (fclose (f) == EOF) + { + unlink ((char *) atomic->tmp); + return FcFalse; + } + ret = link ((char *) atomic->tmp, (char *) atomic->lck); + if (ret < 0 && errno == EPERM) + { + /* the filesystem where atomic->lck points to may not supports + * the hard link. so better try to fallback + */ + ret = mkdir ((char *) atomic->lck, 0600); + no_link = FcTrue; + } + (void) unlink ((char *) atomic->tmp); +#else + ret = mkdir ((char *) atomic->lck, 0600); +#endif + if (ret < 0) + { + /* + * If the file is around and old (> 10 minutes), + * assume the lock is stale. This assumes that any + * machines sharing the same filesystem will have clocks + * reasonably close to each other. + */ + if (FcStat (atomic->lck, &lck_stat) >= 0) + { + time_t now = time (0); + if ((long int) (now - lck_stat.st_mtime) > 10 * 60) + { +#ifdef HAVE_LINK + if (no_link) + { + if (rmdir ((char *) atomic->lck) == 0) + return FcAtomicLock (atomic); + } + else + { + if (unlink ((char *) atomic->lck) == 0) + return FcAtomicLock (atomic); + } +#else + if (rmdir ((char *) atomic->lck) == 0) + return FcAtomicLock (atomic); +#endif + } + } + return FcFalse; + } + (void) unlink ((char *) atomic->new); + return FcTrue; +} + +FcChar8 * +FcAtomicNewFile (FcAtomic *atomic) +{ + return atomic->new; +} + +FcChar8 * +FcAtomicOrigFile (FcAtomic *atomic) +{ + return atomic->file; +} + +FcBool +FcAtomicReplaceOrig (FcAtomic *atomic) +{ +#ifdef _WIN32 + unlink ((const char *) atomic->file); +#endif + if (rename ((char *) atomic->new, (char *) atomic->file) < 0) + return FcFalse; + return FcTrue; +} + +void +FcAtomicDeleteNew (FcAtomic *atomic) +{ + unlink ((char *) atomic->new); +} + +void +FcAtomicUnlock (FcAtomic *atomic) +{ +#ifdef HAVE_LINK + if (unlink ((char *) atomic->lck) == -1) + rmdir ((char *) atomic->lck); +#else + rmdir ((char *) atomic->lck); +#endif +} + +void +FcAtomicDestroy (FcAtomic *atomic) +{ + free (atomic); +} +#define __fcatomic__ +#include "fcaliastail.h" +#undef __fcatomic__ diff --git a/project/jni/fontconfig/src/fcatomic.h b/project/jni/fontconfig/src/fcatomic.h new file mode 100644 index 000000000..362e52164 --- /dev/null +++ b/project/jni/fontconfig/src/fcatomic.h @@ -0,0 +1,145 @@ +/* + * Mutex operations. Originally copied from HarfBuzz. + * + * Copyright © 2007 Chris Wilson + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2011,2012,2013 Google, Inc. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Contributor(s): + * Chris Wilson + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef _FCATOMIC_H_ +#define _FCATOMIC_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + + +/* atomic_int */ + +/* We need external help for these */ + +#if 0 + + +#elif !defined(FC_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__) + +#include "fcwindows.h" + +/* mingw32 does not have MemoryBarrier. + * MemoryBarrier may be defined as a macro or a function. + * Just make a failsafe version for ourselves. */ +#ifdef MemoryBarrier +#define HBMemoryBarrier MemoryBarrier +#else +static inline void HBMemoryBarrier (void) { + long dummy = 0; + InterlockedExchange (&dummy, 1); +} +#endif + +typedef LONG fc_atomic_int_t; +#define fc_atomic_int_add(AI, V) InterlockedExchangeAdd (&(AI), (V)) + +#define fc_atomic_ptr_get(P) (HBMemoryBarrier (), (void *) *(P)) +#define fc_atomic_ptr_cmpexch(P,O,N) (InterlockedCompareExchangePointer ((void **) (P), (void *) (N), (void *) (O)) == (void *) (O)) + + +#elif !defined(FC_NO_MT) && defined(__APPLE__) + +#include +#ifdef __MAC_OS_X_MIN_REQUIRED +#include +#elif defined(__IPHONE_OS_MIN_REQUIRED) +#include +#endif + +typedef int fc_atomic_int_t; +#define fc_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V)) + +#define fc_atomic_ptr_get(P) (OSMemoryBarrier (), (void *) *(P)) +#if (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 || __IPHONE_VERSION_MIN_REQUIRED >= 20100) +#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P)) +#else +#if __ppc64__ || __x86_64__ +#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap64Barrier ((int64_t) (O), (int64_t) (N), (int64_t*) (P)) +#else +#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap32Barrier ((int32_t) (O), (int32_t) (N), (int32_t*) (P)) +#endif +#endif + +#elif !defined(FC_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) + +typedef int fc_atomic_int_t; +#define fc_atomic_int_add(AI, V) __sync_fetch_and_add (&(AI), (V)) + +#define fc_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P)) +#define fc_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N)) + + +#elif !defined(FC_NO_MT) && defined(HAVE_SOLARIS_ATOMIC_OPS) + +#include +#include + +typedef unsigned int fc_atomic_int_t; +#define fc_atomic_int_add(AI, V) ( ({__machine_rw_barrier ();}), atomic_add_int_nv (&(AI), (V)) - (V)) + +#define fc_atomic_ptr_get(P) ( ({__machine_rw_barrier ();}), (void *) *(P)) +#define fc_atomic_ptr_cmpexch(P,O,N) ( ({__machine_rw_barrier ();}), atomic_cas_ptr ((P), (O), (N)) == (void *) (O) ? FcTrue : FcFalse) + + +#elif !defined(FC_NO_MT) + +#define FC_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */ +typedef volatile int fc_atomic_int_t; +#define fc_atomic_int_add(AI, V) (((AI) += (V)) - (V)) + +#define fc_atomic_ptr_get(P) ((void *) *(P)) +#define fc_atomic_ptr_cmpexch(P,O,N) (* (void * volatile *) (P) == (void *) (O) ? (* (void * volatile *) (P) = (void *) (N), FcTrue) : FcFalse) + + +#else /* FC_NO_MT */ + +typedef int fc_atomic_int_t; +#define fc_atomic_int_add(AI, V) (((AI) += (V)) - (V)) + +#define fc_atomic_ptr_get(P) ((void *) *(P)) +#define fc_atomic_ptr_cmpexch(P,O,N) (* (void **) (P) == (void *) (O) ? (* (void **) (P) = (void *) (N), FcTrue) : FcFalse) + +#endif + +/* reference count */ +#define FC_REF_CONSTANT_VALUE ((fc_atomic_int_t) -1) +#define FC_REF_CONSTANT {FC_REF_CONSTANT_VALUE} +typedef struct _FcRef { fc_atomic_int_t count; } FcRef; +static inline void FcRefInit (FcRef *r, int v) { r->count = v; } +static inline int FcRefInc (FcRef *r) { return fc_atomic_int_add (r->count, +1); } +static inline int FcRefDec (FcRef *r) { return fc_atomic_int_add (r->count, -1); } +static inline int FcRefAdd (FcRef *r, int v) { return fc_atomic_int_add (r->count, v); } +static inline void FcRefSetConst (FcRef *r) { r->count = FC_REF_CONSTANT_VALUE; } +static inline FcBool FcRefIsConst (const FcRef *r) { return r->count == FC_REF_CONSTANT_VALUE; } + +#endif /* _FCATOMIC_H_ */ diff --git a/project/jni/fontconfig/src/fcblanks.c b/project/jni/fontconfig/src/fcblanks.c new file mode 100644 index 000000000..46698bcda --- /dev/null +++ b/project/jni/fontconfig/src/fcblanks.c @@ -0,0 +1,87 @@ +/* + * fontconfig/src/fcblanks.c + * + * Copyright © 2002 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" + +FcBlanks * +FcBlanksCreate (void) +{ + FcBlanks *b; + + b = malloc (sizeof (FcBlanks)); + if (!b) + return 0; + b->nblank = 0; + b->sblank = 0; + b->blanks = 0; + return b; +} + +void +FcBlanksDestroy (FcBlanks *b) +{ + if (b->blanks) + free (b->blanks); + free (b); +} + +FcBool +FcBlanksAdd (FcBlanks *b, FcChar32 ucs4) +{ + FcChar32 *c; + int sblank; + + for (sblank = 0; sblank < b->nblank; sblank++) + if (b->blanks[sblank] == ucs4) + return FcTrue; + + if (b->nblank == b->sblank) + { + sblank = b->sblank + 32; + if (b->blanks) + c = (FcChar32 *) realloc (b->blanks, sblank * sizeof (FcChar32)); + else + c = (FcChar32 *) malloc (sblank * sizeof (FcChar32)); + if (!c) + return FcFalse; + b->sblank = sblank; + b->blanks = c; + } + b->blanks[b->nblank++] = ucs4; + return FcTrue; +} + +FcBool +FcBlanksIsMember (FcBlanks *b, FcChar32 ucs4) +{ + int i; + + for (i = 0; i < b->nblank; i++) + if (b->blanks[i] == ucs4) + return FcTrue; + return FcFalse; +} +#define __fcblanks__ +#include "fcaliastail.h" +#undef __fcblanks__ diff --git a/project/jni/fontconfig/src/fccache.c b/project/jni/fontconfig/src/fccache.c new file mode 100644 index 000000000..5173e0be2 --- /dev/null +++ b/project/jni/fontconfig/src/fccache.c @@ -0,0 +1,1478 @@ +/* + * Copyright © 2000 Keith Packard + * Copyright © 2005 Patrick Lam + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ +#include "fcint.h" +#include "fcarch.h" +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(HAVE_MMAP) || defined(__CYGWIN__) +# include +# include +#endif + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + + +struct MD5Context { + FcChar32 buf[4]; + FcChar32 bits[2]; + unsigned char in[64]; +}; + +static void MD5Init(struct MD5Context *ctx); +static void MD5Update(struct MD5Context *ctx, const unsigned char *buf, unsigned len); +static void MD5Final(unsigned char digest[16], struct MD5Context *ctx); +static void MD5Transform(FcChar32 buf[4], FcChar32 in[16]); + +#define CACHEBASE_LEN (1 + 32 + 1 + sizeof (FC_ARCHITECTURE) + sizeof (FC_CACHE_SUFFIX)) + +static FcBool +FcCacheIsMmapSafe (int fd) +{ + enum { + MMAP_NOT_INITIALIZED = 0, + MMAP_USE, + MMAP_DONT_USE, + MMAP_CHECK_FS, + } status; + static void *static_status; + + status = (intptr_t) fc_atomic_ptr_get (&static_status); + + if (status == MMAP_NOT_INITIALIZED) + { + const char *env = getenv ("FONTCONFIG_USE_MMAP"); + FcBool use; + if (env && FcNameBool ((const FcChar8 *) env, &use)) + status = use ? MMAP_USE : MMAP_DONT_USE; + else + status = MMAP_CHECK_FS; + (void) fc_atomic_ptr_cmpexch (&static_status, NULL, (void *) status); + } + + if (status == MMAP_CHECK_FS) + return FcIsFsMmapSafe (fd); + else + return status == MMAP_USE; + +} + +static const char bin2hex[] = { '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'a', 'b', + 'c', 'd', 'e', 'f' }; + +static FcChar8 * +FcDirCacheBasename (const FcChar8 * dir, FcChar8 cache_base[CACHEBASE_LEN]) +{ + unsigned char hash[16]; + FcChar8 *hex_hash; + int cnt; + struct MD5Context ctx; + + MD5Init (&ctx); + MD5Update (&ctx, (const unsigned char *)dir, strlen ((const char *) dir)); + + MD5Final (hash, &ctx); + + cache_base[0] = '/'; + hex_hash = cache_base + 1; + for (cnt = 0; cnt < 16; ++cnt) + { + hex_hash[2*cnt ] = bin2hex[hash[cnt] >> 4]; + hex_hash[2*cnt+1] = bin2hex[hash[cnt] & 0xf]; + } + hex_hash[2*cnt] = 0; + strcat ((char *) cache_base, "-" FC_ARCHITECTURE FC_CACHE_SUFFIX); + + return cache_base; +} + +FcBool +FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config) +{ + FcChar8 *cache_hashed = NULL; + FcChar8 cache_base[CACHEBASE_LEN]; + FcStrList *list; + FcChar8 *cache_dir; + const FcChar8 *sysroot = FcConfigGetSysRoot (config); + + FcDirCacheBasename (dir, cache_base); + + list = FcStrListCreate (config->cacheDirs); + if (!list) + return FcFalse; + + while ((cache_dir = FcStrListNext (list))) + { + if (sysroot) + cache_hashed = FcStrBuildFilename (sysroot, cache_dir, cache_base, NULL); + else + cache_hashed = FcStrBuildFilename (cache_dir, cache_base, NULL); + if (!cache_hashed) + break; + (void) unlink ((char *) cache_hashed); + FcStrFree (cache_hashed); + } + FcStrListDone (list); + /* return FcFalse if something went wrong */ + if (cache_dir) + return FcFalse; + return FcTrue; +} + +static int +FcDirCacheOpenFile (const FcChar8 *cache_file, struct stat *file_stat) +{ + int fd; + +#ifdef _WIN32 + if (FcStat (cache_file, file_stat) < 0) + return -1; +#endif + fd = FcOpen((char *) cache_file, O_RDONLY | O_BINARY); + if (fd < 0) + return fd; +#ifndef _WIN32 + if (fstat (fd, file_stat) < 0) + { + close (fd); + return -1; + } +#endif + return fd; +} + +/* + * Look for a cache file for the specified dir. Attempt + * to use each one we find, stopping when the callback + * indicates success + */ +static FcBool +FcDirCacheProcess (FcConfig *config, const FcChar8 *dir, + FcBool (*callback) (int fd, struct stat *fd_stat, + struct stat *dir_stat, void *closure), + void *closure, FcChar8 **cache_file_ret) +{ + int fd = -1; + FcChar8 cache_base[CACHEBASE_LEN]; + FcStrList *list; + FcChar8 *cache_dir; + struct stat file_stat, dir_stat; + FcBool ret = FcFalse; + + if (FcStatChecksum (dir, &dir_stat) < 0) + return FcFalse; + + FcDirCacheBasename (dir, cache_base); + + list = FcStrListCreate (config->cacheDirs); + if (!list) + return FcFalse; + + while ((cache_dir = FcStrListNext (list))) + { + const FcChar8 *sysroot = FcConfigGetSysRoot (config); + FcChar8 *cache_hashed; + + if (sysroot) + cache_hashed = FcStrBuildFilename (sysroot, cache_dir, cache_base, NULL); + else + cache_hashed = FcStrBuildFilename (cache_dir, cache_base, NULL); + if (!cache_hashed) + break; + fd = FcDirCacheOpenFile (cache_hashed, &file_stat); + if (fd >= 0) { + ret = (*callback) (fd, &file_stat, &dir_stat, closure); + close (fd); + if (ret) + { + if (cache_file_ret) + *cache_file_ret = cache_hashed; + else + FcStrFree (cache_hashed); + break; + } + } + FcStrFree (cache_hashed); + } + FcStrListDone (list); + + return ret; +} + +#define FC_CACHE_MIN_MMAP 1024 + +/* + * Skip list element, make sure the 'next' pointer is the last thing + * in the structure, it will be allocated large enough to hold all + * of the necessary pointers + */ + +typedef struct _FcCacheSkip FcCacheSkip; + +struct _FcCacheSkip { + FcCache *cache; + FcRef ref; + intptr_t size; + dev_t cache_dev; + ino_t cache_ino; + time_t cache_mtime; + FcCacheSkip *next[1]; +}; + +/* + * The head of the skip list; pointers for every possible level + * in the skip list, plus the largest level in the list + */ + +#define FC_CACHE_MAX_LEVEL 16 + +/* Protected by cache_lock below */ +static FcCacheSkip *fcCacheChains[FC_CACHE_MAX_LEVEL]; +static int fcCacheMaxLevel; + + +static FcMutex *cache_lock; + +static void +lock_cache (void) +{ + FcMutex *lock; +retry: + lock = fc_atomic_ptr_get (&cache_lock); + if (!lock) { + lock = (FcMutex *) malloc (sizeof (FcMutex)); + FcMutexInit (lock); + if (!fc_atomic_ptr_cmpexch (&cache_lock, NULL, lock)) { + FcMutexFinish (lock); + goto retry; + } + + FcMutexLock (lock); + /* Initialize random state */ + FcRandom (); + return; + } + FcMutexLock (lock); +} + +static void +unlock_cache (void) +{ + FcMutexUnlock (cache_lock); +} + +static void +free_lock (void) +{ + FcMutex *lock; + lock = fc_atomic_ptr_get (&cache_lock); + if (lock && fc_atomic_ptr_cmpexch (&cache_lock, lock, NULL)) { + FcMutexFinish (lock); + free (lock); + } +} + + + +/* + * Generate a random level number, distributed + * so that each level is 1/4 as likely as the one before + * + * Note that level numbers run 1 <= level <= MAX_LEVEL + */ +static int +random_level (void) +{ + /* tricky bit -- each bit is '1' 75% of the time */ + long int bits = FcRandom () | FcRandom (); + int level = 0; + + while (++level < FC_CACHE_MAX_LEVEL) + { + if (bits & 1) + break; + bits >>= 1; + } + return level; +} + +/* + * Insert cache into the list + */ +static FcBool +FcCacheInsert (FcCache *cache, struct stat *cache_stat) +{ + FcCacheSkip **update[FC_CACHE_MAX_LEVEL]; + FcCacheSkip *s, **next; + int i, level; + + lock_cache (); + + /* + * Find links along each chain + */ + next = fcCacheChains; + for (i = fcCacheMaxLevel; --i >= 0; ) + { + for (; (s = next[i]); next = s->next) + if (s->cache > cache) + break; + update[i] = &next[i]; + } + + /* + * Create new list element + */ + level = random_level (); + if (level > fcCacheMaxLevel) + { + level = fcCacheMaxLevel + 1; + update[fcCacheMaxLevel] = &fcCacheChains[fcCacheMaxLevel]; + fcCacheMaxLevel = level; + } + + s = malloc (sizeof (FcCacheSkip) + (level - 1) * sizeof (FcCacheSkip *)); + if (!s) + return FcFalse; + + s->cache = cache; + s->size = cache->size; + FcRefInit (&s->ref, 1); + if (cache_stat) + { + s->cache_dev = cache_stat->st_dev; + s->cache_ino = cache_stat->st_ino; + s->cache_mtime = cache_stat->st_mtime; + } + else + { + s->cache_dev = 0; + s->cache_ino = 0; + s->cache_mtime = 0; + } + + /* + * Insert into all fcCacheChains + */ + for (i = 0; i < level; i++) + { + s->next[i] = *update[i]; + *update[i] = s; + } + + unlock_cache (); + return FcTrue; +} + +static FcCacheSkip * +FcCacheFindByAddrUnlocked (void *object) +{ + int i; + FcCacheSkip **next = fcCacheChains; + FcCacheSkip *s; + + if (!object) + return NULL; + + /* + * Walk chain pointers one level at a time + */ + for (i = fcCacheMaxLevel; --i >= 0;) + while (next[i] && (char *) object >= ((char *) next[i]->cache + next[i]->size)) + next = next[i]->next; + /* + * Here we are + */ + s = next[0]; + if (s && (char *) object < ((char *) s->cache + s->size)) + return s; + return NULL; +} + +static FcCacheSkip * +FcCacheFindByAddr (void *object) +{ + FcCacheSkip *ret; + lock_cache (); + ret = FcCacheFindByAddrUnlocked (object); + unlock_cache (); + return ret; +} + +static void +FcCacheRemoveUnlocked (FcCache *cache) +{ + FcCacheSkip **update[FC_CACHE_MAX_LEVEL]; + FcCacheSkip *s, **next; + int i; + + /* + * Find links along each chain + */ + next = fcCacheChains; + for (i = fcCacheMaxLevel; --i >= 0; ) + { + for (; (s = next[i]); next = s->next) + if (s->cache >= cache) + break; + update[i] = &next[i]; + } + s = next[0]; + for (i = 0; i < fcCacheMaxLevel && *update[i] == s; i++) + *update[i] = s->next[i]; + while (fcCacheMaxLevel > 0 && fcCacheChains[fcCacheMaxLevel - 1] == NULL) + fcCacheMaxLevel--; + free (s); +} + +static FcCache * +FcCacheFindByStat (struct stat *cache_stat) +{ + FcCacheSkip *s; + + lock_cache (); + for (s = fcCacheChains[0]; s; s = s->next[0]) + if (s->cache_dev == cache_stat->st_dev && + s->cache_ino == cache_stat->st_ino && + s->cache_mtime == cache_stat->st_mtime) + { + FcRefInc (&s->ref); + unlock_cache (); + return s->cache; + } + unlock_cache (); + return NULL; +} + +static void +FcDirCacheDisposeUnlocked (FcCache *cache) +{ + FcCacheRemoveUnlocked (cache); + + switch (cache->magic) { + case FC_CACHE_MAGIC_ALLOC: + free (cache); + break; + case FC_CACHE_MAGIC_MMAP: +#if defined(HAVE_MMAP) || defined(__CYGWIN__) + munmap (cache, cache->size); +#elif defined(_WIN32) + UnmapViewOfFile (cache); +#endif + break; + } +} + +void +FcCacheObjectReference (void *object) +{ + FcCacheSkip *skip = FcCacheFindByAddr (object); + + if (skip) + FcRefInc (&skip->ref); +} + +void +FcCacheObjectDereference (void *object) +{ + FcCacheSkip *skip; + + lock_cache (); + skip = FcCacheFindByAddrUnlocked (object); + if (skip) + { + if (FcRefDec (&skip->ref) == 1) + FcDirCacheDisposeUnlocked (skip->cache); + } + unlock_cache (); +} + +void +FcCacheFini (void) +{ + int i; + + for (i = 0; i < FC_CACHE_MAX_LEVEL; i++) + assert (fcCacheChains[i] == NULL); + assert (fcCacheMaxLevel == 0); + + free_lock (); +} + +static FcBool +FcCacheTimeValid (FcCache *cache, struct stat *dir_stat) +{ + struct stat dir_static; + + if (!dir_stat) + { + if (FcStatChecksum (FcCacheDir (cache), &dir_static) < 0) + return FcFalse; + dir_stat = &dir_static; + } + if (FcDebug () & FC_DBG_CACHE) + printf ("FcCacheTimeValid dir \"%s\" cache checksum %d dir checksum %d\n", + FcCacheDir (cache), cache->checksum, (int) dir_stat->st_mtime); + return cache->checksum == (int) dir_stat->st_mtime; +} + +/* + * Map a cache file into memory + */ +static FcCache * +FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat) +{ + FcCache *cache; + FcBool allocated = FcFalse; + + if (fd_stat->st_size < (int) sizeof (FcCache)) + return NULL; + cache = FcCacheFindByStat (fd_stat); + if (cache) + { + if (FcCacheTimeValid (cache, dir_stat)) + return cache; + FcDirCacheUnload (cache); + cache = NULL; + } + + /* + * Large cache files are mmap'ed, smaller cache files are read. This + * balances the system cost of mmap against per-process memory usage. + */ + if (FcCacheIsMmapSafe (fd) && fd_stat->st_size >= FC_CACHE_MIN_MMAP) + { +#if defined(HAVE_MMAP) || defined(__CYGWIN__) + cache = mmap (0, fd_stat->st_size, PROT_READ, MAP_SHARED, fd, 0); +#if (HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED) + posix_fadvise (fd, 0, fd_stat->st_size, POSIX_FADV_WILLNEED); +#endif + if (cache == MAP_FAILED) + cache = NULL; +#elif defined(_WIN32) + { + HANDLE hFileMap; + + cache = NULL; + hFileMap = CreateFileMapping((HANDLE) _get_osfhandle(fd), NULL, + PAGE_READONLY, 0, 0, NULL); + if (hFileMap != NULL) + { + cache = MapViewOfFile (hFileMap, FILE_MAP_READ, 0, 0, + fd_stat->st_size); + CloseHandle (hFileMap); + } + } +#endif + } + if (!cache) + { + cache = malloc (fd_stat->st_size); + if (!cache) + return NULL; + + if (read (fd, cache, fd_stat->st_size) != fd_stat->st_size) + { + free (cache); + return NULL; + } + allocated = FcTrue; + } + if (cache->magic != FC_CACHE_MAGIC_MMAP || + cache->version < FC_CACHE_CONTENT_VERSION || + cache->size != (intptr_t) fd_stat->st_size || + !FcCacheTimeValid (cache, dir_stat) || + !FcCacheInsert (cache, fd_stat)) + { + if (allocated) + free (cache); + else + { +#if defined(HAVE_MMAP) || defined(__CYGWIN__) + munmap (cache, fd_stat->st_size); +#elif defined(_WIN32) + UnmapViewOfFile (cache); +#endif + } + return NULL; + } + + /* Mark allocated caches so they're freed rather than unmapped */ + if (allocated) + cache->magic = FC_CACHE_MAGIC_ALLOC; + + return cache; +} + +void +FcDirCacheReference (FcCache *cache, int nref) +{ + FcCacheSkip *skip = FcCacheFindByAddr (cache); + + if (skip) + FcRefAdd (&skip->ref, nref); +} + +void +FcDirCacheUnload (FcCache *cache) +{ + FcCacheObjectDereference (cache); +} + +static FcBool +FcDirCacheMapHelper (int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure) +{ + FcCache *cache = FcDirCacheMapFd (fd, fd_stat, dir_stat); + + if (!cache) + return FcFalse; + *((FcCache **) closure) = cache; + return FcTrue; +} + +FcCache * +FcDirCacheLoad (const FcChar8 *dir, FcConfig *config, FcChar8 **cache_file) +{ + FcCache *cache = NULL; + + if (!FcDirCacheProcess (config, dir, + FcDirCacheMapHelper, + &cache, cache_file)) + return NULL; + return cache; +} + +FcCache * +FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat) +{ + int fd; + FcCache *cache; + struct stat my_file_stat; + + if (!file_stat) + file_stat = &my_file_stat; + fd = FcDirCacheOpenFile (cache_file, file_stat); + if (fd < 0) + return NULL; + cache = FcDirCacheMapFd (fd, file_stat, NULL); + close (fd); + return cache; +} + +/* + * Validate a cache file by reading the header and checking + * the magic number and the size field + */ +static FcBool +FcDirCacheValidateHelper (int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure FC_UNUSED) +{ + FcBool ret = FcTrue; + FcCache c; + + if (read (fd, &c, sizeof (FcCache)) != sizeof (FcCache)) + ret = FcFalse; + else if (c.magic != FC_CACHE_MAGIC_MMAP) + ret = FcFalse; + else if (c.version < FC_CACHE_CONTENT_VERSION) + ret = FcFalse; + else if (fd_stat->st_size != c.size) + ret = FcFalse; + else if (c.checksum != (int) dir_stat->st_mtime) + ret = FcFalse; + return ret; +} + +static FcBool +FcDirCacheValidConfig (const FcChar8 *dir, FcConfig *config) +{ + return FcDirCacheProcess (config, dir, + FcDirCacheValidateHelper, + NULL, NULL); +} + +FcBool +FcDirCacheValid (const FcChar8 *dir) +{ + FcConfig *config; + + config = FcConfigGetCurrent (); + if (!config) + return FcFalse; + + return FcDirCacheValidConfig (dir, config); +} + +/* + * Build a cache structure from the given contents + */ +FcCache * +FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, struct stat *dir_stat, FcStrSet *dirs) +{ + FcSerialize *serialize = FcSerializeCreate (); + FcCache *cache; + int i; + FcChar8 *dir_serialize; + intptr_t *dirs_serialize; + FcFontSet *set_serialize; + + if (!serialize) + return NULL; + /* + * Space for cache structure + */ + FcSerializeReserve (serialize, sizeof (FcCache)); + /* + * Directory name + */ + if (!FcStrSerializeAlloc (serialize, dir)) + goto bail1; + /* + * Subdirs + */ + FcSerializeAlloc (serialize, dirs, dirs->num * sizeof (FcChar8 *)); + for (i = 0; i < dirs->num; i++) + if (!FcStrSerializeAlloc (serialize, dirs->strs[i])) + goto bail1; + + /* + * Patterns + */ + if (!FcFontSetSerializeAlloc (serialize, set)) + goto bail1; + + /* Serialize layout complete. Now allocate space and fill it */ + cache = malloc (serialize->size); + if (!cache) + goto bail1; + /* shut up valgrind */ + memset (cache, 0, serialize->size); + + serialize->linear = cache; + + cache->magic = FC_CACHE_MAGIC_ALLOC; + cache->version = FC_CACHE_CONTENT_VERSION; + cache->size = serialize->size; + cache->checksum = (int) dir_stat->st_mtime; + + /* + * Serialize directory name + */ + dir_serialize = FcStrSerialize (serialize, dir); + if (!dir_serialize) + goto bail2; + cache->dir = FcPtrToOffset (cache, dir_serialize); + + /* + * Serialize sub dirs + */ + dirs_serialize = FcSerializePtr (serialize, dirs); + if (!dirs_serialize) + goto bail2; + cache->dirs = FcPtrToOffset (cache, dirs_serialize); + cache->dirs_count = dirs->num; + for (i = 0; i < dirs->num; i++) + { + FcChar8 *d_serialize = FcStrSerialize (serialize, dirs->strs[i]); + if (!d_serialize) + goto bail2; + dirs_serialize[i] = FcPtrToOffset (dirs_serialize, d_serialize); + } + + /* + * Serialize font set + */ + set_serialize = FcFontSetSerialize (serialize, set); + if (!set_serialize) + goto bail2; + cache->set = FcPtrToOffset (cache, set_serialize); + + FcSerializeDestroy (serialize); + + FcCacheInsert (cache, NULL); + + return cache; + +bail2: + free (cache); +bail1: + FcSerializeDestroy (serialize); + return NULL; +} + +FcCache * +FcDirCacheRebuild (FcCache *cache, struct stat *dir_stat, FcStrSet *dirs) +{ + FcCache *new; + FcFontSet *set = FcFontSetDeserialize (FcCacheSet (cache)); + const FcChar8 *dir = FcCacheDir (cache); + + new = FcDirCacheBuild (set, dir, dir_stat, dirs); + FcFontSetDestroy (set); + + return new; +} + +/* write serialized state to the cache file */ +FcBool +FcDirCacheWrite (FcCache *cache, FcConfig *config) +{ + FcChar8 *dir = FcCacheDir (cache); + FcChar8 cache_base[CACHEBASE_LEN]; + FcChar8 *cache_hashed; + int fd; + FcAtomic *atomic; + FcStrList *list; + FcChar8 *cache_dir = NULL; + FcChar8 *test_dir, *d = NULL; + FcCacheSkip *skip; + struct stat cache_stat; + unsigned int magic; + int written; + const FcChar8 *sysroot = FcConfigGetSysRoot (config); + + /* + * Write it to the first directory in the list which is writable + */ + + list = FcStrListCreate (config->cacheDirs); + if (!list) + return FcFalse; + while ((test_dir = FcStrListNext (list))) + { + if (d) + FcStrFree (d); + if (sysroot) + d = FcStrBuildFilename (sysroot, test_dir, NULL); + else + d = FcStrCopyFilename (test_dir); + + if (access ((char *) d, W_OK) == 0) + { + cache_dir = FcStrCopyFilename (d); + break; + } + else + { + /* + * If the directory doesn't exist, try to create it + */ + if (access ((char *) d, F_OK) == -1) { + if (FcMakeDirectory (d)) + { + cache_dir = FcStrCopyFilename (d); + /* Create CACHEDIR.TAG */ + FcDirCacheCreateTagFile (d); + break; + } + } + /* + * Otherwise, try making it writable + */ + else if (chmod ((char *) d, 0755) == 0) + { + cache_dir = FcStrCopyFilename (d); + /* Try to create CACHEDIR.TAG too */ + FcDirCacheCreateTagFile (d); + break; + } + } + } + if (d) + FcStrFree (d); + FcStrListDone (list); + if (!cache_dir) + return FcFalse; + + FcDirCacheBasename (dir, cache_base); + cache_hashed = FcStrBuildFilename (cache_dir, cache_base, NULL); + if (!cache_hashed) + return FcFalse; + FcStrFree (cache_dir); + + if (FcDebug () & FC_DBG_CACHE) + printf ("FcDirCacheWriteDir dir \"%s\" file \"%s\"\n", + dir, cache_hashed); + + atomic = FcAtomicCreate ((FcChar8 *)cache_hashed); + if (!atomic) + goto bail1; + + if (!FcAtomicLock (atomic)) + goto bail3; + + fd = FcOpen((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT | O_BINARY, 0666); + if (fd == -1) + goto bail4; + + /* Temporarily switch magic to MMAP while writing to file */ + magic = cache->magic; + if (magic != FC_CACHE_MAGIC_MMAP) + cache->magic = FC_CACHE_MAGIC_MMAP; + + /* + * Write cache contents to file + */ + written = write (fd, cache, cache->size); + + /* Switch magic back */ + if (magic != FC_CACHE_MAGIC_MMAP) + cache->magic = magic; + + if (written != cache->size) + { + perror ("write cache"); + goto bail5; + } + + close(fd); + if (!FcAtomicReplaceOrig(atomic)) + goto bail4; + + /* If the file is small, update the cache chain entry such that the + * new cache file is not read again. If it's large, we don't do that + * such that we reload it, using mmap, which is shared across processes. + */ + if (cache->size < FC_CACHE_MIN_MMAP && FcStat (cache_hashed, &cache_stat)) + { + lock_cache (); + if ((skip = FcCacheFindByAddrUnlocked (cache))) + { + skip->cache_dev = cache_stat.st_dev; + skip->cache_ino = cache_stat.st_ino; + skip->cache_mtime = cache_stat.st_mtime; + } + unlock_cache (); + } + + FcStrFree (cache_hashed); + FcAtomicUnlock (atomic); + FcAtomicDestroy (atomic); + return FcTrue; + + bail5: + close (fd); + bail4: + FcAtomicUnlock (atomic); + bail3: + FcAtomicDestroy (atomic); + bail1: + FcStrFree (cache_hashed); + return FcFalse; +} + +FcBool +FcDirCacheClean (const FcChar8 *cache_dir, FcBool verbose) +{ + DIR *d; + struct dirent *ent; + FcChar8 *dir; + FcBool ret = FcTrue; + FcBool remove; + FcCache *cache; + struct stat target_stat; + const FcChar8 *sysroot; + + /* FIXME: this API needs to support non-current FcConfig */ + sysroot = FcConfigGetSysRoot (NULL); + if (sysroot) + dir = FcStrBuildFilename (sysroot, cache_dir, NULL); + else + dir = FcStrCopyFilename (cache_dir); + if (!dir) + { + fprintf (stderr, "Fontconfig error: %s: out of memory\n", cache_dir); + return FcFalse; + } + if (access ((char *) dir, W_OK) != 0) + { + if (verbose || FcDebug () & FC_DBG_CACHE) + printf ("%s: not cleaning %s cache directory\n", dir, + access ((char *) dir, F_OK) == 0 ? "unwritable" : "non-existent"); + goto bail0; + } + if (verbose || FcDebug () & FC_DBG_CACHE) + printf ("%s: cleaning cache directory\n", dir); + d = opendir ((char *) dir); + if (!d) + { + perror ((char *) dir); + ret = FcFalse; + goto bail0; + } + while ((ent = readdir (d))) + { + FcChar8 *file_name; + const FcChar8 *target_dir; + + if (ent->d_name[0] == '.') + continue; + /* skip cache files for different architectures and */ + /* files which are not cache files at all */ + if (strlen(ent->d_name) != 32 + strlen ("-" FC_ARCHITECTURE FC_CACHE_SUFFIX) || + strcmp(ent->d_name + 32, "-" FC_ARCHITECTURE FC_CACHE_SUFFIX)) + continue; + + file_name = FcStrBuildFilename (dir, (FcChar8 *)ent->d_name, NULL); + if (!file_name) + { + fprintf (stderr, "Fontconfig error: %s: allocation failure\n", dir); + ret = FcFalse; + break; + } + remove = FcFalse; + cache = FcDirCacheLoadFile (file_name, NULL); + if (!cache) + { + if (verbose || FcDebug () & FC_DBG_CACHE) + printf ("%s: invalid cache file: %s\n", dir, ent->d_name); + remove = FcTrue; + } + else + { + target_dir = FcCacheDir (cache); + if (stat ((char *) target_dir, &target_stat) < 0) + { + if (verbose || FcDebug () & FC_DBG_CACHE) + printf ("%s: %s: missing directory: %s \n", + dir, ent->d_name, target_dir); + remove = FcTrue; + } + FcDirCacheUnload (cache); + } + if (remove) + { + if (unlink ((char *) file_name) < 0) + { + perror ((char *) file_name); + ret = FcFalse; + } + } + FcStrFree (file_name); + } + + closedir (d); + bail0: + FcStrFree (dir); + + return ret; +} + +/* + * Hokey little macro trick to permit the definitions of C functions + * with the same name as CPP macros + */ +#define args1(x) (x) +#define args2(x,y) (x,y) + +const FcChar8 * +FcCacheDir args1(const FcCache *c) +{ + return FcCacheDir (c); +} + +FcFontSet * +FcCacheCopySet args1(const FcCache *c) +{ + FcFontSet *old = FcCacheSet (c); + FcFontSet *new = FcFontSetCreate (); + int i; + + if (!new) + return NULL; + for (i = 0; i < old->nfont; i++) + { + FcPattern *font = FcFontSetFont (old, i); + + FcPatternReference (font); + if (!FcFontSetAdd (new, font)) + { + FcFontSetDestroy (new); + return NULL; + } + } + return new; +} + +const FcChar8 * +FcCacheSubdir args2(const FcCache *c, int i) +{ + return FcCacheSubdir (c, i); +} + +int +FcCacheNumSubdir args1(const FcCache *c) +{ + return c->dirs_count; +} + +int +FcCacheNumFont args1(const FcCache *c) +{ + return FcCacheSet(c)->nfont; +} + +/* + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * MD5Context structure, pass it to MD5Init, call MD5Update as + * needed on buffers full of bytes, and then call MD5Final, which + * will fill a supplied 16-byte array with the digest. + */ + +#ifndef HIGHFIRST +#define byteReverse(buf, len) /* Nothing */ +#else +/* + * Note: this code is harmless on little-endian machines. + */ +void byteReverse(unsigned char *buf, unsigned longs) +{ + FcChar32 t; + do { + t = (FcChar32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | + ((unsigned) buf[1] << 8 | buf[0]); + *(FcChar32 *) buf = t; + buf += 4; + } while (--longs); +} +#endif + +/* + * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious + * initialization constants. + */ +static void MD5Init(struct MD5Context *ctx) +{ + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; + + ctx->bits[0] = 0; + ctx->bits[1] = 0; +} + +/* + * Update context to reflect the concatenation of another buffer full + * of bytes. + */ +static void MD5Update(struct MD5Context *ctx, const unsigned char *buf, unsigned len) +{ + FcChar32 t; + + /* Update bitcount */ + + t = ctx->bits[0]; + if ((ctx->bits[0] = t + ((FcChar32) len << 3)) < t) + ctx->bits[1]++; /* Carry from low to high */ + ctx->bits[1] += len >> 29; + + t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ + + /* Handle any leading odd-sized chunks */ + + if (t) { + unsigned char *p = (unsigned char *) ctx->in + t; + + t = 64 - t; + if (len < t) { + memcpy(p, buf, len); + return; + } + memcpy(p, buf, t); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (FcChar32 *) ctx->in); + buf += t; + len -= t; + } + /* Process data in 64-byte chunks */ + + while (len >= 64) { + memcpy(ctx->in, buf, 64); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (FcChar32 *) ctx->in); + buf += 64; + len -= 64; + } + + /* Handle any remaining bytes of data. */ + + memcpy(ctx->in, buf, len); +} + +/* + * Final wrapup - pad to 64-byte boundary with the bit pattern + * 1 0* (64-bit count of bits processed, MSB-first) + */ +static void MD5Final(unsigned char digest[16], struct MD5Context *ctx) +{ + unsigned count; + unsigned char *p; + + /* Compute number of bytes mod 64 */ + count = (ctx->bits[0] >> 3) & 0x3F; + + /* Set the first char of padding to 0x80. This is safe since there is + always at least one byte free */ + p = ctx->in + count; + *p++ = 0x80; + + /* Bytes of padding needed to make 64 bytes */ + count = 64 - 1 - count; + + /* Pad out to 56 mod 64 */ + if (count < 8) { + /* Two lots of padding: Pad the first block to 64 bytes */ + memset(p, 0, count); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (FcChar32 *) ctx->in); + + /* Now fill the next block with 56 bytes */ + memset(ctx->in, 0, 56); + } else { + /* Pad block to 56 bytes */ + memset(p, 0, count - 8); + } + byteReverse(ctx->in, 14); + + /* Append length in bits and transform */ + ((FcChar32 *) ctx->in)[14] = ctx->bits[0]; + ((FcChar32 *) ctx->in)[15] = ctx->bits[1]; + + MD5Transform(ctx->buf, (FcChar32 *) ctx->in); + byteReverse((unsigned char *) ctx->buf, 4); + memcpy(digest, ctx->buf, 16); + memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ +} + + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. MD5Update blocks + * the data and converts bytes into longwords for this routine. + */ +static void MD5Transform(FcChar32 buf[4], FcChar32 in[16]) +{ + register FcChar32 a, b, c, d; + + a = buf[0]; + b = buf[1]; + c = buf[2]; + d = buf[3]; + + MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; +} + +FcBool +FcDirCacheCreateTagFile (const FcChar8 *cache_dir) +{ + FcChar8 *cache_tag; + int fd; + FILE *fp; + FcAtomic *atomic; + static const FcChar8 cache_tag_contents[] = + "Signature: 8a477f597d28d172789f06886806bc55\n" + "# This file is a cache directory tag created by fontconfig.\n" + "# For information about cache directory tags, see:\n" + "# http://www.brynosaurus.com/cachedir/\n"; + static size_t cache_tag_contents_size = sizeof (cache_tag_contents) - 1; + FcBool ret = FcFalse; + + if (!cache_dir) + return FcFalse; + + if (access ((char *) cache_dir, W_OK) == 0) + { + /* Create CACHEDIR.TAG */ + cache_tag = FcStrBuildFilename (cache_dir, "CACHEDIR.TAG", NULL); + if (!cache_tag) + return FcFalse; + atomic = FcAtomicCreate ((FcChar8 *)cache_tag); + if (!atomic) + goto bail1; + if (!FcAtomicLock (atomic)) + goto bail2; + fd = FcOpen((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT, 0644); + if (fd == -1) + goto bail3; + fp = fdopen(fd, "wb"); + if (fp == NULL) + goto bail3; + + fwrite(cache_tag_contents, cache_tag_contents_size, sizeof (FcChar8), fp); + fclose(fp); + + if (!FcAtomicReplaceOrig(atomic)) + goto bail3; + + ret = FcTrue; + bail3: + FcAtomicUnlock (atomic); + bail2: + FcAtomicDestroy (atomic); + bail1: + FcStrFree (cache_tag); + } + + if (FcDebug () & FC_DBG_CACHE) + { + if (ret) + printf ("Created CACHEDIR.TAG at %s\n", cache_dir); + else + printf ("Unable to create CACHEDIR.TAG at %s\n", cache_dir); + } + + return ret; +} + +void +FcCacheCreateTagFile (const FcConfig *config) +{ + FcChar8 *cache_dir = NULL, *d = NULL; + FcStrList *list; + const FcChar8 *sysroot = FcConfigGetSysRoot (config); + + list = FcConfigGetCacheDirs (config); + if (!list) + return; + + while ((cache_dir = FcStrListNext (list))) + { + if (d) + FcStrFree (d); + if (sysroot) + d = FcStrBuildFilename (sysroot, cache_dir, NULL); + else + d = FcStrCopyFilename (cache_dir); + if (FcDirCacheCreateTagFile (d)) + break; + } + if (d) + FcStrFree (d); + FcStrListDone (list); +} + +#define __fccache__ +#include "fcaliastail.h" +#undef __fccache__ diff --git a/project/jni/fontconfig/src/fccfg.c b/project/jni/fontconfig/src/fccfg.c new file mode 100644 index 000000000..6377fd7c6 --- /dev/null +++ b/project/jni/fontconfig/src/fccfg.c @@ -0,0 +1,2352 @@ +/* + * fontconfig/src/fccfg.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* Objects MT-safe for readonly access. */ + +#include "fcint.h" +#include +#include + +#if defined (_WIN32) && !defined (R_OK) +#define R_OK 4 +#endif + +static FcConfig *_fcConfig; /* MT-safe */ + +static FcConfig * +FcConfigEnsure (void) +{ + FcConfig *config; +retry: + config = fc_atomic_ptr_get (&_fcConfig); + if (!config) + { + config = FcInitLoadConfigAndFonts (); + + if (!fc_atomic_ptr_cmpexch (&_fcConfig, NULL, config)) { + FcConfigDestroy (config); + goto retry; + } + } + return config; +} + +FcBool +FcConfigInit (void) +{ + return FcConfigEnsure () ? FcTrue : FcFalse; +} + +void +FcConfigFini (void) +{ + FcConfig *cfg = fc_atomic_ptr_get (&_fcConfig); + if (cfg && fc_atomic_ptr_cmpexch (&_fcConfig, cfg, NULL)) + FcConfigDestroy (cfg); +} + + +FcConfig * +FcConfigCreate (void) +{ + FcSetName set; + FcConfig *config; + + config = malloc (sizeof (FcConfig)); + if (!config) + goto bail0; + + config->configDirs = FcStrSetCreate (); + if (!config->configDirs) + goto bail1; + + config->configFiles = FcStrSetCreate (); + if (!config->configFiles) + goto bail2; + + config->fontDirs = FcStrSetCreate (); + if (!config->fontDirs) + goto bail3; + + config->acceptGlobs = FcStrSetCreate (); + if (!config->acceptGlobs) + goto bail4; + + config->rejectGlobs = FcStrSetCreate (); + if (!config->rejectGlobs) + goto bail5; + + config->acceptPatterns = FcFontSetCreate (); + if (!config->acceptPatterns) + goto bail6; + + config->rejectPatterns = FcFontSetCreate (); + if (!config->rejectPatterns) + goto bail7; + + config->cacheDirs = FcStrSetCreate (); + if (!config->cacheDirs) + goto bail8; + + config->blanks = 0; + + config->substPattern = 0; + config->substFont = 0; + config->substScan = 0; + config->maxObjects = 0; + for (set = FcSetSystem; set <= FcSetApplication; set++) + config->fonts[set] = 0; + + config->rescanTime = time(0); + config->rescanInterval = 30; + + config->expr_pool = NULL; + + config->sysRoot = NULL; + + FcRefInit (&config->ref, 1); + + return config; + +bail8: + FcFontSetDestroy (config->rejectPatterns); +bail7: + FcFontSetDestroy (config->acceptPatterns); +bail6: + FcStrSetDestroy (config->rejectGlobs); +bail5: + FcStrSetDestroy (config->acceptGlobs); +bail4: + FcStrSetDestroy (config->fontDirs); +bail3: + FcStrSetDestroy (config->configFiles); +bail2: + FcStrSetDestroy (config->configDirs); +bail1: + free (config); +bail0: + return 0; +} + +static FcFileTime +FcConfigNewestFile (FcStrSet *files) +{ + FcStrList *list = FcStrListCreate (files); + FcFileTime newest = { 0, FcFalse }; + FcChar8 *file; + struct stat statb; + + if (list) + { + while ((file = FcStrListNext (list))) + if (FcStat (file, &statb) == 0) + if (!newest.set || statb.st_mtime - newest.time > 0) + { + newest.set = FcTrue; + newest.time = statb.st_mtime; + } + FcStrListDone (list); + } + return newest; +} + +FcBool +FcConfigUptoDate (FcConfig *config) +{ + FcFileTime config_time, config_dir_time, font_time; + time_t now = time(0); + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return FcFalse; + } + config_time = FcConfigNewestFile (config->configFiles); + config_dir_time = FcConfigNewestFile (config->configDirs); + font_time = FcConfigNewestFile (config->fontDirs); + if ((config_time.set && config_time.time - config->rescanTime > 0) || + (config_dir_time.set && (config_dir_time.time - config->rescanTime) > 0) || + (font_time.set && (font_time.time - config->rescanTime) > 0)) + { + /* We need to check for potential clock problems here (OLPC ticket #6046) */ + if ((config_time.set && (config_time.time - now) > 0) || + (config_dir_time.set && (config_dir_time.time - now) > 0) || + (font_time.set && (font_time.time - now) > 0)) + { + fprintf (stderr, + "Fontconfig warning: Directory/file mtime in the future. New fonts may not be detected.\n"); + config->rescanTime = now; + return FcTrue; + } + else + return FcFalse; + } + config->rescanTime = now; + return FcTrue; +} + +static void +FcSubstDestroy (FcSubst *s) +{ + FcSubst *n; + + while (s) + { + n = s->next; + if (s->rule) + FcRuleDestroy (s->rule); + free (s); + s = n; + } +} + +FcExpr * +FcConfigAllocExpr (FcConfig *config) +{ + if (!config->expr_pool || config->expr_pool->next == config->expr_pool->end) + { + FcExprPage *new_page; + + new_page = malloc (sizeof (FcExprPage)); + if (!new_page) + return 0; + + new_page->next_page = config->expr_pool; + new_page->next = new_page->exprs; + config->expr_pool = new_page; + } + + return config->expr_pool->next++; +} + +FcConfig * +FcConfigReference (FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + + FcRefInc (&config->ref); + + return config; +} + +void +FcConfigDestroy (FcConfig *config) +{ + FcSetName set; + FcExprPage *page; + + if (FcRefDec (&config->ref) != 1) + return; + + (void) fc_atomic_ptr_cmpexch (&_fcConfig, config, NULL); + + FcStrSetDestroy (config->configDirs); + FcStrSetDestroy (config->fontDirs); + FcStrSetDestroy (config->cacheDirs); + FcStrSetDestroy (config->configFiles); + FcStrSetDestroy (config->acceptGlobs); + FcStrSetDestroy (config->rejectGlobs); + FcFontSetDestroy (config->acceptPatterns); + FcFontSetDestroy (config->rejectPatterns); + + if (config->blanks) + FcBlanksDestroy (config->blanks); + + FcSubstDestroy (config->substPattern); + FcSubstDestroy (config->substFont); + FcSubstDestroy (config->substScan); + for (set = FcSetSystem; set <= FcSetApplication; set++) + if (config->fonts[set]) + FcFontSetDestroy (config->fonts[set]); + + page = config->expr_pool; + while (page) + { + FcExprPage *next = page->next_page; + free (page); + page = next; + } + if (config->sysRoot) + FcStrFree (config->sysRoot); + + free (config); +} + +/* + * Add cache to configuration, adding fonts and directories + */ + +FcBool +FcConfigAddCache (FcConfig *config, FcCache *cache, + FcSetName set, FcStrSet *dirSet) +{ + FcFontSet *fs; + intptr_t *dirs; + int i; + + /* + * Add fonts + */ + fs = FcCacheSet (cache); + if (fs) + { + int nref = 0; + + for (i = 0; i < fs->nfont; i++) + { + FcPattern *font = FcFontSetFont (fs, i); + FcChar8 *font_file; + + /* + * Check to see if font is banned by filename + */ + if (FcPatternObjectGetString (font, FC_FILE_OBJECT, + 0, &font_file) == FcResultMatch && + !FcConfigAcceptFilename (config, font_file)) + { + continue; + } + + /* + * Check to see if font is banned by pattern + */ + if (!FcConfigAcceptFont (config, font)) + continue; + + if (FcFontSetAdd (config->fonts[set], font)) + nref++; + } + FcDirCacheReference (cache, nref); + } + + /* + * Add directories + */ + dirs = FcCacheDirs (cache); + if (dirs) + { + for (i = 0; i < cache->dirs_count; i++) + { + FcChar8 *dir = FcOffsetToPtr (dirs, dirs[i], FcChar8); + if (FcConfigAcceptFilename (config, dir)) + FcStrSetAddFilename (dirSet, dir); + } + } + return FcTrue; +} + +static FcBool +FcConfigAddDirList (FcConfig *config, FcSetName set, FcStrSet *dirSet) +{ + FcStrList *dirlist; + FcChar8 *dir; + FcCache *cache; + + dirlist = FcStrListCreate (dirSet); + if (!dirlist) + return FcFalse; + + while ((dir = FcStrListNext (dirlist))) + { + if (FcDebug () & FC_DBG_FONTSET) + printf ("adding fonts from%s\n", dir); + cache = FcDirCacheRead (dir, FcFalse, config); + if (!cache) + continue; + FcConfigAddCache (config, cache, set, dirSet); + FcDirCacheUnload (cache); + } + FcStrListDone (dirlist); + return FcTrue; +} + +/* + * Scan the current list of directories in the configuration + * and build the set of available fonts. + */ + +FcBool +FcConfigBuildFonts (FcConfig *config) +{ + FcFontSet *fonts; + + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return FcFalse; + } + + fonts = FcFontSetCreate (); + if (!fonts) + return FcFalse; + + FcConfigSetFonts (config, fonts, FcSetSystem); + + if (!FcConfigAddDirList (config, FcSetSystem, config->fontDirs)) + return FcFalse; + if (FcDebug () & FC_DBG_FONTSET) + FcFontSetPrint (fonts); + return FcTrue; +} + +FcBool +FcConfigSetCurrent (FcConfig *config) +{ + FcConfig *cfg; + +retry: + cfg = fc_atomic_ptr_get (&_fcConfig); + + if (config == cfg) + return FcTrue; + + if (config && !config->fonts[FcSetSystem]) + if (!FcConfigBuildFonts (config)) + return FcFalse; + + if (!fc_atomic_ptr_cmpexch (&_fcConfig, cfg, config)) + goto retry; + + if (cfg) + FcConfigDestroy (cfg); + + return FcTrue; +} + +FcConfig * +FcConfigGetCurrent (void) +{ + return FcConfigEnsure (); +} + +FcBool +FcConfigAddConfigDir (FcConfig *config, + const FcChar8 *d) +{ + return FcStrSetAddFilename (config->configDirs, d); +} + +FcStrList * +FcConfigGetConfigDirs (FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + return FcStrListCreate (config->configDirs); +} + +FcBool +FcConfigAddFontDir (FcConfig *config, + const FcChar8 *d) +{ + return FcStrSetAddFilename (config->fontDirs, d); +} + +FcBool +FcConfigAddDir (FcConfig *config, + const FcChar8 *d) +{ + return (FcConfigAddConfigDir (config, d) && + FcConfigAddFontDir (config, d)); +} + +FcStrList * +FcConfigGetFontDirs (FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + return FcStrListCreate (config->fontDirs); +} + +FcBool +FcConfigAddCacheDir (FcConfig *config, + const FcChar8 *d) +{ + return FcStrSetAddFilename (config->cacheDirs, d); +} + +FcStrList * +FcConfigGetCacheDirs (const FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + return FcStrListCreate (config->cacheDirs); +} + +FcBool +FcConfigAddConfigFile (FcConfig *config, + const FcChar8 *f) +{ + FcBool ret; + FcChar8 *file = FcConfigFilename (f); + + if (!file) + return FcFalse; + + ret = FcStrSetAdd (config->configFiles, file); + FcStrFree (file); + return ret; +} + +FcStrList * +FcConfigGetConfigFiles (FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + return FcStrListCreate (config->configFiles); +} + +FcChar8 * +FcConfigGetCache (FcConfig *config FC_UNUSED) +{ + return NULL; +} + +FcFontSet * +FcConfigGetFonts (FcConfig *config, + FcSetName set) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + return config->fonts[set]; +} + +void +FcConfigSetFonts (FcConfig *config, + FcFontSet *fonts, + FcSetName set) +{ + if (config->fonts[set]) + FcFontSetDestroy (config->fonts[set]); + config->fonts[set] = fonts; +} + +FcBlanks * +FcConfigGetBlanks (FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + return config->blanks; +} + +FcBool +FcConfigAddBlank (FcConfig *config, + FcChar32 blank) +{ + FcBlanks *b, *freeme = 0; + + b = config->blanks; + if (!b) + { + freeme = b = FcBlanksCreate (); + if (!b) + return FcFalse; + } + if (!FcBlanksAdd (b, blank)) + { + if (freeme) + FcBlanksDestroy (freeme); + return FcFalse; + } + config->blanks = b; + return FcTrue; +} + +int +FcConfigGetRescanInterval (FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + return config->rescanInterval; +} + +FcBool +FcConfigSetRescanInterval (FcConfig *config, int rescanInterval) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return FcFalse; + } + config->rescanInterval = rescanInterval; + return FcTrue; +} + +/* + * A couple of typos escaped into the library + */ +int +FcConfigGetRescanInverval (FcConfig *config) +{ + return FcConfigGetRescanInterval (config); +} + +FcBool +FcConfigSetRescanInverval (FcConfig *config, int rescanInterval) +{ + return FcConfigSetRescanInterval (config, rescanInterval); +} + +FcBool +FcConfigAddRule (FcConfig *config, + FcRule *rule, + FcMatchKind kind) +{ + FcSubst *subst, **prev; + FcRule *r; + int n = 0; + + if (!rule) + return FcFalse; + switch (kind) { + case FcMatchPattern: + prev = &config->substPattern; + break; + case FcMatchFont: + prev = &config->substFont; + break; + case FcMatchScan: + prev = &config->substScan; + break; + default: + return FcFalse; + } + subst = (FcSubst *) malloc (sizeof (FcSubst)); + if (!subst) + return FcFalse; + for (; *prev; prev = &(*prev)->next); + *prev = subst; + subst->next = NULL; + subst->rule = rule; + for (r = rule; r; r = r->next) + { + switch (r->type) + { + case FcRuleTest: + if (r->u.test && + r->u.test->kind == FcMatchDefault) + r->u.test->kind = kind; + + if (n < r->u.test->object) + n = r->u.test->object; + break; + case FcRuleEdit: + if (n < r->u.edit->object) + n = r->u.edit->object; + break; + default: + break; + } + } + n = FC_OBJ_ID (n) - FC_MAX_BASE_OBJECT; + if (config->maxObjects < n) + config->maxObjects = n; + if (FcDebug () & FC_DBG_EDIT) + { + printf ("Add Subst "); + FcSubstPrint (subst); + } + return FcTrue; +} + +static FcValue +FcConfigPromote (FcValue v, FcValue u, FcValuePromotionBuffer *buf) +{ + if (v.type == FcTypeInteger) + { + v.type = FcTypeDouble; + v.u.d = (double) v.u.i; + } + else if (v.type == FcTypeVoid && u.type == FcTypeMatrix) + { + v.u.m = &FcIdentityMatrix; + v.type = FcTypeMatrix; + } + else if (buf && v.type == FcTypeString && u.type == FcTypeLangSet) + { + v.u.l = FcLangSetPromote (v.u.s, buf); + v.type = FcTypeLangSet; + } + return v; +} + +FcBool +FcConfigCompareValue (const FcValue *left_o, + unsigned int op_, + const FcValue *right_o) +{ + FcValue left = FcValueCanonicalize(left_o); + FcValue right = FcValueCanonicalize(right_o); + FcBool ret = FcFalse; + FcOp op = FC_OP_GET_OP (op_); + int flags = FC_OP_GET_FLAGS (op_); + FcValuePromotionBuffer buf1, buf2; + + left = FcConfigPromote (left, right, &buf1); + right = FcConfigPromote (right, left, &buf2); + if (left.type == right.type) + { + switch (left.type) { + case FcTypeUnknown: + break; /* No way to guess how to compare for this object */ + case FcTypeInteger: + break; /* FcConfigPromote prevents this from happening */ + case FcTypeDouble: + switch ((int) op) { + case FcOpEqual: + case FcOpContains: + case FcOpListing: + ret = left.u.d == right.u.d; + break; + case FcOpNotEqual: + case FcOpNotContains: + ret = left.u.d != right.u.d; + break; + case FcOpLess: + ret = left.u.d < right.u.d; + break; + case FcOpLessEqual: + ret = left.u.d <= right.u.d; + break; + case FcOpMore: + ret = left.u.d > right.u.d; + break; + case FcOpMoreEqual: + ret = left.u.d >= right.u.d; + break; + default: + break; + } + break; + case FcTypeBool: + switch ((int) op) { + case FcOpEqual: + case FcOpContains: + case FcOpListing: + ret = left.u.b == right.u.b; + break; + case FcOpNotEqual: + case FcOpNotContains: + ret = left.u.b != right.u.b; + break; + default: + break; + } + break; + case FcTypeString: + switch ((int) op) { + case FcOpEqual: + case FcOpListing: + if (flags & FcOpFlagIgnoreBlanks) + ret = FcStrCmpIgnoreBlanksAndCase (left.u.s, right.u.s) == 0; + else + ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) == 0; + break; + case FcOpContains: + ret = FcStrStrIgnoreCase (left.u.s, right.u.s) != 0; + break; + case FcOpNotEqual: + if (flags & FcOpFlagIgnoreBlanks) + ret = FcStrCmpIgnoreBlanksAndCase (left.u.s, right.u.s) != 0; + else + ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) != 0; + break; + case FcOpNotContains: + ret = FcStrStrIgnoreCase (left.u.s, right.u.s) == 0; + break; + default: + break; + } + break; + case FcTypeMatrix: + switch ((int) op) { + case FcOpEqual: + case FcOpContains: + case FcOpListing: + ret = FcMatrixEqual (left.u.m, right.u.m); + break; + case FcOpNotEqual: + case FcOpNotContains: + ret = !FcMatrixEqual (left.u.m, right.u.m); + break; + default: + break; + } + break; + case FcTypeCharSet: + switch ((int) op) { + case FcOpContains: + case FcOpListing: + /* left contains right if right is a subset of left */ + ret = FcCharSetIsSubset (right.u.c, left.u.c); + break; + case FcOpNotContains: + /* left contains right if right is a subset of left */ + ret = !FcCharSetIsSubset (right.u.c, left.u.c); + break; + case FcOpEqual: + ret = FcCharSetEqual (left.u.c, right.u.c); + break; + case FcOpNotEqual: + ret = !FcCharSetEqual (left.u.c, right.u.c); + break; + default: + break; + } + break; + case FcTypeLangSet: + switch ((int) op) { + case FcOpContains: + case FcOpListing: + ret = FcLangSetContains (left.u.l, right.u.l); + break; + case FcOpNotContains: + ret = !FcLangSetContains (left.u.l, right.u.l); + break; + case FcOpEqual: + ret = FcLangSetEqual (left.u.l, right.u.l); + break; + case FcOpNotEqual: + ret = !FcLangSetEqual (left.u.l, right.u.l); + break; + default: + break; + } + break; + case FcTypeVoid: + switch ((int) op) { + case FcOpEqual: + case FcOpContains: + case FcOpListing: + ret = FcTrue; + break; + default: + break; + } + break; + case FcTypeFTFace: + switch ((int) op) { + case FcOpEqual: + case FcOpContains: + case FcOpListing: + ret = left.u.f == right.u.f; + break; + case FcOpNotEqual: + case FcOpNotContains: + ret = left.u.f != right.u.f; + break; + default: + break; + } + break; + } + } + else + { + if (op == FcOpNotEqual || op == FcOpNotContains) + ret = FcTrue; + } + return ret; +} + + +#define _FcDoubleFloor(d) ((int) (d)) +#define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1)) +#define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d))) +#define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d))) +#define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5) +#define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d))) + +static FcValue +FcConfigEvaluate (FcPattern *p, FcPattern *p_pat, FcMatchKind kind, FcExpr *e) +{ + FcValue v, vl, vr; + FcMatrix *m; + FcChar8 *str; + FcOp op = FC_OP_GET_OP (e->op); + + switch ((int) op) { + case FcOpInteger: + v.type = FcTypeInteger; + v.u.i = e->u.ival; + break; + case FcOpDouble: + v.type = FcTypeDouble; + v.u.d = e->u.dval; + break; + case FcOpString: + v.type = FcTypeString; + v.u.s = e->u.sval; + v = FcValueSave (v); + break; + case FcOpMatrix: + { + FcMatrix m; + FcValue xx, xy, yx, yy; + v.type = FcTypeMatrix; + xx = FcConfigPromote (FcConfigEvaluate (p, p_pat, kind, e->u.mexpr->xx), v, NULL); + xy = FcConfigPromote (FcConfigEvaluate (p, p_pat, kind, e->u.mexpr->xy), v, NULL); + yx = FcConfigPromote (FcConfigEvaluate (p, p_pat, kind, e->u.mexpr->yx), v, NULL); + yy = FcConfigPromote (FcConfigEvaluate (p, p_pat, kind, e->u.mexpr->yy), v, NULL); + if (xx.type == FcTypeDouble && xy.type == FcTypeDouble && + yx.type == FcTypeDouble && yy.type == FcTypeDouble) + { + m.xx = xx.u.d; + m.xy = xy.u.d; + m.yx = yx.u.d; + m.yy = yy.u.d; + v.u.m = &m; + } + else + v.type = FcTypeVoid; + v = FcValueSave (v); + } + break; + case FcOpCharSet: + v.type = FcTypeCharSet; + v.u.c = e->u.cval; + v = FcValueSave (v); + break; + case FcOpLangSet: + v.type = FcTypeLangSet; + v.u.l = e->u.lval; + v = FcValueSave (v); + break; + case FcOpBool: + v.type = FcTypeBool; + v.u.b = e->u.bval; + break; + case FcOpField: + if (kind == FcMatchFont && e->u.name.kind == FcMatchPattern) + { + if (FcResultMatch != FcPatternObjectGet (p_pat, e->u.name.object, 0, &v)) + v.type = FcTypeVoid; + } + else if (kind == FcMatchPattern && e->u.name.kind == FcMatchFont) + { + fprintf (stderr, + "Fontconfig warning: tag has target=\"font\" in a .\n"); + v.type = FcTypeVoid; + } + else + { + if (FcResultMatch != FcPatternObjectGet (p, e->u.name.object, 0, &v)) + v.type = FcTypeVoid; + } + v = FcValueSave (v); + break; + case FcOpConst: + if (FcNameConstant (e->u.constant, &v.u.i)) + v.type = FcTypeInteger; + else + v.type = FcTypeVoid; + break; + case FcOpQuest: + vl = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + if (vl.type == FcTypeBool) + { + if (vl.u.b) + v = FcConfigEvaluate (p, p_pat, kind, e->u.tree.right->u.tree.left); + else + v = FcConfigEvaluate (p, p_pat, kind, e->u.tree.right->u.tree.right); + } + else + v.type = FcTypeVoid; + FcValueDestroy (vl); + break; + case FcOpEqual: + case FcOpNotEqual: + case FcOpLess: + case FcOpLessEqual: + case FcOpMore: + case FcOpMoreEqual: + case FcOpContains: + case FcOpNotContains: + case FcOpListing: + vl = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + vr = FcConfigEvaluate (p, p_pat, kind, e->u.tree.right); + v.type = FcTypeBool; + v.u.b = FcConfigCompareValue (&vl, e->op, &vr); + FcValueDestroy (vl); + FcValueDestroy (vr); + break; + case FcOpOr: + case FcOpAnd: + case FcOpPlus: + case FcOpMinus: + case FcOpTimes: + case FcOpDivide: + vl = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + vr = FcConfigEvaluate (p, p_pat, kind, e->u.tree.right); + vl = FcConfigPromote (vl, vr, NULL); + vr = FcConfigPromote (vr, vl, NULL); + if (vl.type == vr.type) + { + switch ((int) vl.type) { + case FcTypeDouble: + switch ((int) op) { + case FcOpPlus: + v.type = FcTypeDouble; + v.u.d = vl.u.d + vr.u.d; + break; + case FcOpMinus: + v.type = FcTypeDouble; + v.u.d = vl.u.d - vr.u.d; + break; + case FcOpTimes: + v.type = FcTypeDouble; + v.u.d = vl.u.d * vr.u.d; + break; + case FcOpDivide: + v.type = FcTypeDouble; + v.u.d = vl.u.d / vr.u.d; + break; + default: + v.type = FcTypeVoid; + break; + } + if (v.type == FcTypeDouble && + v.u.d == (double) (int) v.u.d) + { + v.type = FcTypeInteger; + v.u.i = (int) v.u.d; + } + break; + case FcTypeBool: + switch ((int) op) { + case FcOpOr: + v.type = FcTypeBool; + v.u.b = vl.u.b || vr.u.b; + break; + case FcOpAnd: + v.type = FcTypeBool; + v.u.b = vl.u.b && vr.u.b; + break; + default: + v.type = FcTypeVoid; + break; + } + break; + case FcTypeString: + switch ((int) op) { + case FcOpPlus: + v.type = FcTypeString; + str = FcStrPlus (vl.u.s, vr.u.s); + v.u.s = FcStrdup (str); + FcStrFree (str); + + if (!v.u.s) + v.type = FcTypeVoid; + break; + default: + v.type = FcTypeVoid; + break; + } + break; + case FcTypeMatrix: + switch ((int) op) { + case FcOpTimes: + v.type = FcTypeMatrix; + m = malloc (sizeof (FcMatrix)); + if (m) + { + FcMatrixMultiply (m, vl.u.m, vr.u.m); + v.u.m = m; + } + else + { + v.type = FcTypeVoid; + } + break; + default: + v.type = FcTypeVoid; + break; + } + break; + case FcTypeCharSet: + switch ((int) op) { + case FcOpPlus: + v.type = FcTypeCharSet; + v.u.c = FcCharSetUnion (vl.u.c, vr.u.c); + if (!v.u.c) + v.type = FcTypeVoid; + break; + case FcOpMinus: + v.type = FcTypeCharSet; + v.u.c = FcCharSetSubtract (vl.u.c, vr.u.c); + if (!v.u.c) + v.type = FcTypeVoid; + break; + default: + v.type = FcTypeVoid; + break; + } + break; + case FcTypeLangSet: + switch ((int) op) { + case FcOpPlus: + v.type = FcTypeLangSet; + v.u.l = FcLangSetUnion (vl.u.l, vr.u.l); + if (!v.u.l) + v.type = FcTypeVoid; + break; + case FcOpMinus: + v.type = FcTypeLangSet; + v.u.l = FcLangSetSubtract (vl.u.l, vr.u.l); + if (!v.u.l) + v.type = FcTypeVoid; + break; + default: + v.type = FcTypeVoid; + break; + } + break; + default: + v.type = FcTypeVoid; + break; + } + } + else + v.type = FcTypeVoid; + FcValueDestroy (vl); + FcValueDestroy (vr); + break; + case FcOpNot: + vl = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + switch ((int) vl.type) { + case FcTypeBool: + v.type = FcTypeBool; + v.u.b = !vl.u.b; + break; + default: + v.type = FcTypeVoid; + break; + } + FcValueDestroy (vl); + break; + case FcOpFloor: + vl = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + switch ((int) vl.type) { + case FcTypeInteger: + v = vl; + break; + case FcTypeDouble: + v.type = FcTypeInteger; + v.u.i = FcDoubleFloor (vl.u.d); + break; + default: + v.type = FcTypeVoid; + break; + } + FcValueDestroy (vl); + break; + case FcOpCeil: + vl = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + switch ((int) vl.type) { + case FcTypeInteger: + v = vl; + break; + case FcTypeDouble: + v.type = FcTypeInteger; + v.u.i = FcDoubleCeil (vl.u.d); + break; + default: + v.type = FcTypeVoid; + break; + } + FcValueDestroy (vl); + break; + case FcOpRound: + vl = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + switch ((int) vl.type) { + case FcTypeInteger: + v = vl; + break; + case FcTypeDouble: + v.type = FcTypeInteger; + v.u.i = FcDoubleRound (vl.u.d); + break; + default: + v.type = FcTypeVoid; + break; + } + FcValueDestroy (vl); + break; + case FcOpTrunc: + vl = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + switch ((int) vl.type) { + case FcTypeInteger: + v = vl; + break; + case FcTypeDouble: + v.type = FcTypeInteger; + v.u.i = FcDoubleTrunc (vl.u.d); + break; + default: + v.type = FcTypeVoid; + break; + } + FcValueDestroy (vl); + break; + default: + v.type = FcTypeVoid; + break; + } + return v; +} + +static FcValueList * +FcConfigMatchValueList (FcPattern *p, + FcPattern *p_pat, + FcMatchKind kind, + FcTest *t, + FcValueList *values) +{ + FcValueList *ret = 0; + FcExpr *e = t->expr; + FcValue value; + FcValueList *v; + + while (e) + { + /* Compute the value of the match expression */ + if (FC_OP_GET_OP (e->op) == FcOpComma) + { + value = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + e = e->u.tree.right; + } + else + { + value = FcConfigEvaluate (p, p_pat, kind, e); + e = 0; + } + + for (v = values; v; v = FcValueListNext(v)) + { + /* Compare the pattern value to the match expression value */ + if (FcConfigCompareValue (&v->value, t->op, &value)) + { + if (!ret) + ret = v; + } + else + { + if (t->qual == FcQualAll) + { + ret = 0; + break; + } + } + } + FcValueDestroy (value); + } + return ret; +} + +static FcValueList * +FcConfigValues (FcPattern *p, FcPattern *p_pat, FcMatchKind kind, FcExpr *e, FcValueBinding binding) +{ + FcValueList *l; + + if (!e) + return 0; + l = (FcValueList *) malloc (sizeof (FcValueList)); + if (!l) + return 0; + if (FC_OP_GET_OP (e->op) == FcOpComma) + { + l->value = FcConfigEvaluate (p, p_pat, kind, e->u.tree.left); + l->next = FcConfigValues (p, p_pat, kind, e->u.tree.right, binding); + } + else + { + l->value = FcConfigEvaluate (p, p_pat, kind, e); + l->next = NULL; + } + l->binding = binding; + if (l->value.type == FcTypeVoid) + { + FcValueList *next = FcValueListNext(l); + + free (l); + l = next; + } + + return l; +} + +static FcBool +FcConfigAdd (FcValueListPtr *head, + FcValueList *position, + FcBool append, + FcValueList *new, + FcObject object) +{ + FcValueListPtr *prev, l, last, v; + FcValueBinding sameBinding; + + /* + * Make sure the stored type is valid for built-in objects + */ + for (l = new; l != NULL; l = FcValueListNext (l)) + { + if (!FcObjectValidType (object, l->value.type)) + { + fprintf (stderr, + "Fontconfig warning: FcPattern object %s does not accept value", FcObjectName (object)); + FcValuePrintFile (stderr, l->value); + fprintf (stderr, "\n"); + + if (FcDebug () & FC_DBG_EDIT) + { + printf ("Not adding\n"); + } + + return FcFalse; + } + } + + if (position) + sameBinding = position->binding; + else + sameBinding = FcValueBindingWeak; + for (v = new; v != NULL; v = FcValueListNext(v)) + if (v->binding == FcValueBindingSame) + v->binding = sameBinding; + if (append) + { + if (position) + prev = &position->next; + else + for (prev = head; *prev != NULL; + prev = &(*prev)->next) + ; + } + else + { + if (position) + { + for (prev = head; *prev != NULL; + prev = &(*prev)->next) + { + if (*prev == position) + break; + } + } + else + prev = head; + + if (FcDebug () & FC_DBG_EDIT) + { + if (*prev == NULL) + printf ("position not on list\n"); + } + } + + if (FcDebug () & FC_DBG_EDIT) + { + printf ("%s list before ", append ? "Append" : "Prepend"); + FcValueListPrintWithPosition (*head, *prev); + printf ("\n"); + } + + if (new) + { + last = new; + while (last->next != NULL) + last = last->next; + + last->next = *prev; + *prev = new; + } + + if (FcDebug () & FC_DBG_EDIT) + { + printf ("%s list after ", append ? "Append" : "Prepend"); + FcValueListPrint (*head); + printf ("\n"); + } + + return FcTrue; +} + +static void +FcConfigDel (FcValueListPtr *head, + FcValueList *position) +{ + FcValueListPtr *prev; + + for (prev = head; *prev != NULL; prev = &(*prev)->next) + { + if (*prev == position) + { + *prev = position->next; + position->next = NULL; + FcValueListDestroy (position); + break; + } + } +} + +static void +FcConfigPatternAdd (FcPattern *p, + FcObject object, + FcValueList *list, + FcBool append) +{ + if (list) + { + FcPatternElt *e = FcPatternObjectInsertElt (p, object); + + if (!e) + return; + FcConfigAdd (&e->values, 0, append, list, object); + } +} + +/* + * Delete all values associated with a field + */ +static void +FcConfigPatternDel (FcPattern *p, + FcObject object) +{ + FcPatternElt *e = FcPatternObjectFindElt (p, object); + if (!e) + return; + while (e->values != NULL) + FcConfigDel (&e->values, e->values); +} + +static void +FcConfigPatternCanon (FcPattern *p, + FcObject object) +{ + FcPatternElt *e = FcPatternObjectFindElt (p, object); + if (!e) + return; + if (e->values == NULL) + FcPatternObjectDel (p, object); +} + +FcBool +FcConfigSubstituteWithPat (FcConfig *config, + FcPattern *p, + FcPattern *p_pat, + FcMatchKind kind) +{ + FcValue v; + FcSubst *s; + FcRule *r; + FcValueList *l, **value = NULL, *vl; + FcPattern *m; + FcStrSet *strs; + FcObject object = FC_INVALID_OBJECT; + FcPatternElt **elt = NULL, *e; + int i, nobjs; + FcBool retval = FcTrue; + FcTest **tst = NULL; + + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return FcFalse; + } + + switch (kind) { + case FcMatchPattern: + s = config->substPattern; + strs = FcGetDefaultLangs (); + if (strs) + { + FcStrList *l = FcStrListCreate (strs); + FcChar8 *lang; + FcValue v; + + FcStrSetDestroy (strs); + while (l && (lang = FcStrListNext (l))) + { + v.type = FcTypeString; + v.u.s = lang; + FcPatternObjectAddWithBinding (p, FC_LANG_OBJECT, v, FcValueBindingWeak, FcTrue); + } + FcStrListDone (l); + } + if (FcPatternObjectGet (p, FC_PRGNAME_OBJECT, 0, &v) == FcResultNoMatch) + { + FcChar8 *prgname = FcGetPrgname (); + if (prgname) + FcPatternObjectAddString (p, FC_PRGNAME_OBJECT, prgname); + } + break; + case FcMatchFont: + s = config->substFont; + break; + case FcMatchScan: + s = config->substScan; + break; + default: + return FcFalse; + } + + nobjs = FC_MAX_BASE_OBJECT + config->maxObjects + 2; + value = (FcValueList **) malloc (SIZEOF_VOID_P * nobjs); + if (!value) + { + retval = FcFalse; + goto bail1; + } + elt = (FcPatternElt **) malloc (SIZEOF_VOID_P * nobjs); + if (!elt) + { + retval = FcFalse; + goto bail1; + } + tst = (FcTest **) malloc (SIZEOF_VOID_P * nobjs); + if (!tst) + { + retval = FcFalse; + goto bail1; + } + + if (FcDebug () & FC_DBG_EDIT) + { + printf ("FcConfigSubstitute "); + FcPatternPrint (p); + } + for (; s; s = s->next) + { + r = s->rule; + for (i = 0; i < nobjs; i++) + { + elt[i] = NULL; + value[i] = NULL; + tst[i] = NULL; + } + for (; r; r = r->next) + { + switch (r->type) { + case FcRuleUnknown: + /* shouldn't be reached */ + break; + case FcRuleTest: + object = FC_OBJ_ID (r->u.test->object); + /* + * Check the tests to see if + * they all match the pattern + */ + if (FcDebug () & FC_DBG_EDIT) + { + printf ("FcConfigSubstitute test "); + FcTestPrint (r->u.test); + } + if (kind == FcMatchFont && r->u.test->kind == FcMatchPattern) + m = p_pat; + else + m = p; + if (m) + e = FcPatternObjectFindElt (m, r->u.test->object); + else + e = NULL; + /* different 'kind' won't be the target of edit */ + if (!elt[object] && kind == r->u.test->kind) + { + elt[object] = e; + tst[object] = r->u.test; + } + /* + * If there's no such field in the font, + * then FcQualAll matches while FcQualAny does not + */ + if (!e) + { + if (r->u.test->qual == FcQualAll) + { + value[object] = NULL; + continue; + } + else + { + if (FcDebug () & FC_DBG_EDIT) + printf ("No match\n"); + goto bail; + } + } + /* + * Check to see if there is a match, mark the location + * to apply match-relative edits + */ + vl = FcConfigMatchValueList (m, p_pat, kind, r->u.test, e->values); + /* different 'kind' won't be the target of edit */ + if (!value[object] && kind == r->u.test->kind) + value[object] = vl; + if (!vl || + (r->u.test->qual == FcQualFirst && vl != e->values) || + (r->u.test->qual == FcQualNotFirst && vl == e->values)) + { + if (FcDebug () & FC_DBG_EDIT) + printf ("No match\n"); + goto bail; + } + break; + case FcRuleEdit: + object = FC_OBJ_ID (r->u.edit->object); + if (FcDebug () & FC_DBG_EDIT) + { + printf ("Substitute "); + FcEditPrint (r->u.edit); + printf ("\n\n"); + } + /* + * Evaluate the list of expressions + */ + l = FcConfigValues (p, p_pat,kind, r->u.edit->expr, r->u.edit->binding); + if (tst[object] && (tst[object]->kind == FcMatchFont || kind == FcMatchPattern)) + elt[object] = FcPatternObjectFindElt (p, tst[object]->object); + + switch (FC_OP_GET_OP (r->u.edit->op)) { + case FcOpAssign: + /* + * If there was a test, then replace the matched + * value with the new list of values + */ + if (value[object]) + { + FcValueList *thisValue = value[object]; + FcValueList *nextValue = l; + + /* + * Append the new list of values after the current value + */ + FcConfigAdd (&elt[object]->values, thisValue, FcTrue, l, r->u.edit->object); + /* + * Delete the marked value + */ + if (thisValue) + FcConfigDel (&elt[object]->values, thisValue); + /* + * Adjust a pointer into the value list to ensure + * future edits occur at the same place + */ + value[object] = nextValue; + break; + } + /* fall through ... */ + case FcOpAssignReplace: + /* + * Delete all of the values and insert + * the new set + */ + FcConfigPatternDel (p, r->u.edit->object); + FcConfigPatternAdd (p, r->u.edit->object, l, FcTrue); + /* + * Adjust a pointer into the value list as they no + * longer point to anything valid + */ + value[object] = NULL; + break; + case FcOpPrepend: + if (value[object]) + { + FcConfigAdd (&elt[object]->values, value[object], FcFalse, l, r->u.edit->object); + break; + } + /* fall through ... */ + case FcOpPrependFirst: + FcConfigPatternAdd (p, r->u.edit->object, l, FcFalse); + break; + case FcOpAppend: + if (value[object]) + { + FcConfigAdd (&elt[object]->values, value[object], FcTrue, l, r->u.edit->object); + break; + } + /* fall through ... */ + case FcOpAppendLast: + FcConfigPatternAdd (p, r->u.edit->object, l, FcTrue); + break; + case FcOpDelete: + if (value[object]) + { + FcConfigDel (&elt[object]->values, value[object]); + break; + } + /* fall through ... */ + case FcOpDeleteAll: + FcConfigPatternDel (p, r->u.edit->object); + break; + default: + FcValueListDestroy (l); + break; + } + /* + * Now go through the pattern and eliminate + * any properties without data + */ + FcConfigPatternCanon (p, r->u.edit->object); + + if (FcDebug () & FC_DBG_EDIT) + { + printf ("FcConfigSubstitute edit"); + FcPatternPrint (p); + } + break; + } + } + bail:; + } + if (FcDebug () & FC_DBG_EDIT) + { + printf ("FcConfigSubstitute done"); + FcPatternPrint (p); + } +bail1: + if (elt) + free (elt); + if (value) + free (value); + if (tst) + free (tst); + + return retval; +} + +FcBool +FcConfigSubstitute (FcConfig *config, + FcPattern *p, + FcMatchKind kind) +{ + return FcConfigSubstituteWithPat (config, p, 0, kind); +} + +#if defined (_WIN32) + +static FcChar8 fontconfig_path[1000] = ""; /* MT-dontcare */ + +# if (defined (PIC) || defined (DLL_EXPORT)) + +BOOL WINAPI +DllMain (HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID lpvReserved); + +BOOL WINAPI +DllMain (HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID lpvReserved) +{ + FcChar8 *p; + + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + if (!GetModuleFileName ((HMODULE) hinstDLL, (LPCH) fontconfig_path, + sizeof (fontconfig_path))) + break; + + /* If the fontconfig DLL is in a "bin" or "lib" subfolder, + * assume it's a Unix-style installation tree, and use + * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the + * folder where the DLL is as FONTCONFIG_PATH. + */ + p = (FcChar8 *) strrchr ((const char *) fontconfig_path, '\\'); + if (p) + { + *p = '\0'; + p = (FcChar8 *) strrchr ((const char *) fontconfig_path, '\\'); + if (p && (FcStrCmpIgnoreCase (p + 1, (const FcChar8 *) "bin") == 0 || + FcStrCmpIgnoreCase (p + 1, (const FcChar8 *) "lib") == 0)) + *p = '\0'; + strcat ((char *) fontconfig_path, "\\etc\\fonts"); + } + else + fontconfig_path[0] = '\0'; + + break; + } + + return TRUE; +} + +# endif /* !PIC */ + +#undef FONTCONFIG_PATH +#define FONTCONFIG_PATH fontconfig_path + +#endif /* !_WIN32 */ + +#ifndef FONTCONFIG_FILE +#define FONTCONFIG_FILE "fonts.conf" +#endif + +static FcChar8 * +FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file) +{ + FcChar8 *path; + int size, osize; + + if (!dir) + dir = (FcChar8 *) ""; + + osize = strlen ((char *) dir) + 1 + strlen ((char *) file) + 1; + /* + * workaround valgrind warning because glibc takes advantage of how it knows memory is + * allocated to implement strlen by reading in groups of 4 + */ + size = (osize + 3) & ~3; + + path = malloc (size); + if (!path) + return 0; + + strcpy ((char *) path, (const char *) dir); + /* make sure there's a single separator */ +#ifdef _WIN32 + if ((!path[0] || (path[strlen((char *) path)-1] != '/' && + path[strlen((char *) path)-1] != '\\')) && + !(file[0] == '/' || + file[0] == '\\' || + (isalpha (file[0]) && file[1] == ':' && (file[2] == '/' || file[2] == '\\')))) + strcat ((char *) path, "\\"); +#else + if ((!path[0] || path[strlen((char *) path)-1] != '/') && file[0] != '/') + strcat ((char *) path, "/"); + else + osize--; +#endif + strcat ((char *) path, (char *) file); + + if (access ((char *) path, R_OK) == 0) + return path; + + FcStrFree (path); + + return 0; +} + +static FcChar8 ** +FcConfigGetPath (void) +{ + FcChar8 **path; + FcChar8 *env, *e, *colon; + FcChar8 *dir; + int npath; + int i; + + npath = 2; /* default dir + null */ + env = (FcChar8 *) getenv ("FONTCONFIG_PATH"); + if (env) + { + e = env; + npath++; + while (*e) + if (*e++ == FC_SEARCH_PATH_SEPARATOR) + npath++; + } + path = calloc (npath, sizeof (FcChar8 *)); + if (!path) + goto bail0; + i = 0; + + if (env) + { + e = env; + while (*e) + { + colon = (FcChar8 *) strchr ((char *) e, FC_SEARCH_PATH_SEPARATOR); + if (!colon) + colon = e + strlen ((char *) e); + path[i] = malloc (colon - e + 1); + if (!path[i]) + goto bail1; + strncpy ((char *) path[i], (const char *) e, colon - e); + path[i][colon - e] = '\0'; + if (*colon) + e = colon + 1; + else + e = colon; + i++; + } + } + +#ifdef _WIN32 + if (fontconfig_path[0] == '\0') + { + char *p; + if(!GetModuleFileName(NULL, (LPCH) fontconfig_path, sizeof(fontconfig_path))) + goto bail1; + p = strrchr ((const char *) fontconfig_path, '\\'); + if (p) *p = '\0'; + strcat ((char *) fontconfig_path, "\\fonts"); + } +#endif + dir = (FcChar8 *) FONTCONFIG_PATH; + path[i] = malloc (strlen ((char *) dir) + 1); + if (!path[i]) + goto bail1; + strcpy ((char *) path[i], (const char *) dir); + return path; + +bail1: + for (i = 0; path[i]; i++) + free (path[i]); + free (path); +bail0: + return 0; +} + +static void +FcConfigFreePath (FcChar8 **path) +{ + FcChar8 **p; + + for (p = path; *p; p++) + free (*p); + free (path); +} + +static FcBool _FcConfigHomeEnabled = FcTrue; /* MT-goodenough */ + +FcChar8 * +FcConfigHome (void) +{ + if (_FcConfigHomeEnabled) + { + char *home = getenv ("HOME"); + +#ifdef _WIN32 + if (home == NULL) + home = getenv ("USERPROFILE"); +#endif + + return (FcChar8 *) home; + } + return 0; +} + +FcChar8 * +FcConfigXdgCacheHome (void) +{ + const char *env = getenv ("XDG_CACHE_HOME"); + FcChar8 *ret = NULL; + + if (env) + ret = FcStrCopy ((const FcChar8 *)env); + else + { + const FcChar8 *home = FcConfigHome (); + size_t len = home ? strlen ((const char *)home) : 0; + + ret = malloc (len + 7 + 1); + if (ret) + { + memcpy (ret, home, len); + memcpy (&ret[len], FC_DIR_SEPARATOR_S ".cache", 7); + ret[len + 7] = 0; + } + } + + return ret; +} + +FcChar8 * +FcConfigXdgConfigHome (void) +{ + const char *env = getenv ("XDG_CONFIG_HOME"); + FcChar8 *ret = NULL; + + if (env) + ret = FcStrCopy ((const FcChar8 *)env); + else + { + const FcChar8 *home = FcConfigHome (); + size_t len = home ? strlen ((const char *)home) : 0; + + ret = malloc (len + 8 + 1); + if (ret) + { + memcpy (ret, home, len); + memcpy (&ret[len], FC_DIR_SEPARATOR_S ".config", 8); + ret[len + 8] = 0; + } + } + + return ret; +} + +FcChar8 * +FcConfigXdgDataHome (void) +{ + const char *env = getenv ("XDG_DATA_HOME"); + FcChar8 *ret = NULL; + + if (env) + ret = FcStrCopy ((const FcChar8 *)env); + else + { + const FcChar8 *home = FcConfigHome (); + size_t len = home ? strlen ((const char *)home) : 0; + + ret = malloc (len + 13 + 1); + if (ret) + { + memcpy (ret, home, len); + memcpy (&ret[len], FC_DIR_SEPARATOR_S ".local" FC_DIR_SEPARATOR_S "share", 13); + ret[len + 13] = 0; + } + } + + return ret; +} + +FcBool +FcConfigEnableHome (FcBool enable) +{ + FcBool prev = _FcConfigHomeEnabled; + _FcConfigHomeEnabled = enable; + return prev; +} + +FcChar8 * +FcConfigFilename (const FcChar8 *url) +{ + FcChar8 *file, *dir, **path, **p; + + if (!url || !*url) + { + url = (FcChar8 *) getenv ("FONTCONFIG_FILE"); + if (!url) + url = (FcChar8 *) FONTCONFIG_FILE; + } + file = 0; + +#ifdef _WIN32 + if (isalpha (*url) && + url[1] == ':' && + (url[2] == '/' || url[2] == '\\')) + goto absolute_path; +#endif + + switch (*url) { + case '~': + dir = FcConfigHome (); + if (dir) + file = FcConfigFileExists (dir, url + 1); + else + file = 0; + break; +#ifdef _WIN32 + case '\\': + absolute_path: +#endif + case '/': + file = FcConfigFileExists (0, url); + break; + default: + path = FcConfigGetPath (); + if (!path) + return NULL; + for (p = path; *p; p++) + { + file = FcConfigFileExists (*p, url); + if (file) + break; + } + FcConfigFreePath (path); + break; + } + + return file; +} + +/* + * Manage the application-specific fonts + */ + +FcBool +FcConfigAppFontAddFile (FcConfig *config, + const FcChar8 *file) +{ + FcFontSet *set; + FcStrSet *subdirs; + FcStrList *sublist; + FcChar8 *subdir; + + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return FcFalse; + } + + subdirs = FcStrSetCreate (); + if (!subdirs) + return FcFalse; + + set = FcConfigGetFonts (config, FcSetApplication); + if (!set) + { + set = FcFontSetCreate (); + if (!set) + { + FcStrSetDestroy (subdirs); + return FcFalse; + } + FcConfigSetFonts (config, set, FcSetApplication); + } + + if (!FcFileScanConfig (set, subdirs, config->blanks, file, config)) + { + FcStrSetDestroy (subdirs); + return FcFalse; + } + if ((sublist = FcStrListCreate (subdirs))) + { + while ((subdir = FcStrListNext (sublist))) + { + FcConfigAppFontAddDir (config, subdir); + } + FcStrListDone (sublist); + } + FcStrSetDestroy (subdirs); + return FcTrue; +} + +FcBool +FcConfigAppFontAddDir (FcConfig *config, + const FcChar8 *dir) +{ + FcFontSet *set; + FcStrSet *dirs; + + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return FcFalse; + } + + dirs = FcStrSetCreate (); + if (!dirs) + return FcFalse; + + set = FcConfigGetFonts (config, FcSetApplication); + if (!set) + { + set = FcFontSetCreate (); + if (!set) + { + FcStrSetDestroy (dirs); + return FcFalse; + } + FcConfigSetFonts (config, set, FcSetApplication); + } + + FcStrSetAddFilename (dirs, dir); + + if (!FcConfigAddDirList (config, FcSetApplication, dirs)) + { + FcStrSetDestroy (dirs); + return FcFalse; + } + FcStrSetDestroy (dirs); + return FcTrue; +} + +void +FcConfigAppFontClear (FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return; + } + + FcConfigSetFonts (config, 0, FcSetApplication); +} + +/* + * Manage filename-based font source selectors + */ + +FcBool +FcConfigGlobAdd (FcConfig *config, + const FcChar8 *glob, + FcBool accept) +{ + FcStrSet *set = accept ? config->acceptGlobs : config->rejectGlobs; + + return FcStrSetAdd (set, glob); +} + +static FcBool +FcConfigGlobsMatch (const FcStrSet *globs, + const FcChar8 *string) +{ + int i; + + for (i = 0; i < globs->num; i++) + if (FcStrGlobMatch (globs->strs[i], string)) + return FcTrue; + return FcFalse; +} + +FcBool +FcConfigAcceptFilename (FcConfig *config, + const FcChar8 *filename) +{ + if (FcConfigGlobsMatch (config->acceptGlobs, filename)) + return FcTrue; + if (FcConfigGlobsMatch (config->rejectGlobs, filename)) + return FcFalse; + return FcTrue; +} + +/* + * Manage font-pattern based font source selectors + */ + +FcBool +FcConfigPatternsAdd (FcConfig *config, + FcPattern *pattern, + FcBool accept) +{ + FcFontSet *set = accept ? config->acceptPatterns : config->rejectPatterns; + + return FcFontSetAdd (set, pattern); +} + +static FcBool +FcConfigPatternsMatch (const FcFontSet *patterns, + const FcPattern *font) +{ + int i; + + for (i = 0; i < patterns->nfont; i++) + if (FcListPatternMatchAny (patterns->fonts[i], font)) + return FcTrue; + return FcFalse; +} + +FcBool +FcConfigAcceptFont (FcConfig *config, + const FcPattern *font) +{ + if (FcConfigPatternsMatch (config->acceptPatterns, font)) + return FcTrue; + if (FcConfigPatternsMatch (config->rejectPatterns, font)) + return FcFalse; + return FcTrue; +} + +const FcChar8 * +FcConfigGetSysRoot (const FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return NULL; + } + + return config->sysRoot; +} + +void +FcConfigSetSysRoot (FcConfig *config, + const FcChar8 *sysroot) +{ + FcChar8 *s; + FcBool init = FcFalse; + + if (!config) + { + /* We can't use FcConfigGetCurrent() here to ensure + * the sysroot is set prior to initialize FcConfig, + * to avoid loading caches from non-sysroot dirs. + * So postpone the initialization later. + */ + config = fc_atomic_ptr_get (&_fcConfig); + if (!config) + { + config = FcConfigCreate (); + if (!config) + return; + init = FcTrue; + } + } + + s = FcStrCopyFilename (sysroot); + if (!s) + return; + + if (config->sysRoot) + FcStrFree (config->sysRoot); + + config->sysRoot = s; + if (init) + { + config = FcInitLoadOwnConfigAndFonts (config); + FcConfigSetCurrent (config); + } +} + +#define __fccfg__ +#include "fcaliastail.h" +#undef __fccfg__ diff --git a/project/jni/fontconfig/src/fccharset.c b/project/jni/fontconfig/src/fccharset.c new file mode 100644 index 000000000..c9f928cd4 --- /dev/null +++ b/project/jni/fontconfig/src/fccharset.c @@ -0,0 +1,1434 @@ +/* + * fontconfig/src/fccharset.c + * + * Copyright © 2001 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include + +/* #define CHECK */ + +FcCharSet * +FcCharSetCreate (void) +{ + FcCharSet *fcs; + + fcs = (FcCharSet *) malloc (sizeof (FcCharSet)); + if (!fcs) + return 0; + FcRefInit (&fcs->ref, 1); + fcs->num = 0; + fcs->leaves_offset = 0; + fcs->numbers_offset = 0; + return fcs; +} + +FcCharSet * +FcCharSetNew (void) +{ + return FcCharSetCreate (); +} + +void +FcCharSetDestroy (FcCharSet *fcs) +{ + int i; + + if (fcs) + { + if (FcRefIsConst (&fcs->ref)) + { + FcCacheObjectDereference (fcs); + return; + } + if (FcRefDec (&fcs->ref) != 1) + return; + for (i = 0; i < fcs->num; i++) + free (FcCharSetLeaf (fcs, i)); + if (fcs->num) + { + free (FcCharSetLeaves (fcs)); + free (FcCharSetNumbers (fcs)); + } + free (fcs); + } +} + +/* + * Search for the leaf containing with the specified num. + * Return its index if it exists, otherwise return negative of + * the (position + 1) where it should be inserted + */ + + +static int +FcCharSetFindLeafForward (const FcCharSet *fcs, int start, FcChar16 num) +{ + FcChar16 *numbers = FcCharSetNumbers(fcs); + FcChar16 page; + int low = start; + int high = fcs->num - 1; + + if (!numbers) + return -1; + while (low <= high) + { + int mid = (low + high) >> 1; + page = numbers[mid]; + if (page == num) + return mid; + if (page < num) + low = mid + 1; + else + high = mid - 1; + } + if (high < 0 || (high < fcs->num && numbers[high] < num)) + high++; + return -(high + 1); +} + +/* + * Locate the leaf containing the specified char, return + * its index if it exists, otherwise return negative of + * the (position + 1) where it should be inserted + */ + +static int +FcCharSetFindLeafPos (const FcCharSet *fcs, FcChar32 ucs4) +{ + return FcCharSetFindLeafForward (fcs, 0, ucs4 >> 8); +} + +static FcCharLeaf * +FcCharSetFindLeaf (const FcCharSet *fcs, FcChar32 ucs4) +{ + int pos = FcCharSetFindLeafPos (fcs, ucs4); + if (pos >= 0) + return FcCharSetLeaf(fcs, pos); + return 0; +} + +#define FC_IS_ZERO_OR_POWER_OF_TWO(x) (!((x) & ((x)-1))) + +static FcBool +FcCharSetPutLeaf (FcCharSet *fcs, + FcChar32 ucs4, + FcCharLeaf *leaf, + int pos) +{ + intptr_t *leaves = FcCharSetLeaves (fcs); + FcChar16 *numbers = FcCharSetNumbers (fcs); + + ucs4 >>= 8; + if (ucs4 >= 0x10000) + return FcFalse; + + if (FC_IS_ZERO_OR_POWER_OF_TWO (fcs->num)) + { + if (!fcs->num) + { + unsigned int alloced = 8; + leaves = malloc (alloced * sizeof (*leaves)); + numbers = malloc (alloced * sizeof (*numbers)); + } + else + { + unsigned int alloced = fcs->num; + intptr_t *new_leaves, distance; + + alloced *= 2; + new_leaves = realloc (leaves, alloced * sizeof (*leaves)); + numbers = realloc (numbers, alloced * sizeof (*numbers)); + + distance = (intptr_t) new_leaves - (intptr_t) leaves; + if (new_leaves && distance) + { + int i; + for (i = 0; i < fcs->num; i++) + new_leaves[i] -= distance; + } + leaves = new_leaves; + } + + if (!leaves || !numbers) + return FcFalse; + + fcs->leaves_offset = FcPtrToOffset (fcs, leaves); + fcs->numbers_offset = FcPtrToOffset (fcs, numbers); + } + + memmove (leaves + pos + 1, leaves + pos, + (fcs->num - pos) * sizeof (*leaves)); + memmove (numbers + pos + 1, numbers + pos, + (fcs->num - pos) * sizeof (*numbers)); + numbers[pos] = (FcChar16) ucs4; + leaves[pos] = FcPtrToOffset (leaves, leaf); + fcs->num++; + return FcTrue; +} + +/* + * Locate the leaf containing the specified char, creating it + * if desired + */ + +FcCharLeaf * +FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4) +{ + int pos; + FcCharLeaf *leaf; + + pos = FcCharSetFindLeafPos (fcs, ucs4); + if (pos >= 0) + return FcCharSetLeaf(fcs, pos); + + leaf = calloc (1, sizeof (FcCharLeaf)); + if (!leaf) + return 0; + + pos = -pos - 1; + if (!FcCharSetPutLeaf (fcs, ucs4, leaf, pos)) + { + free (leaf); + return 0; + } + return leaf; +} + +static FcBool +FcCharSetInsertLeaf (FcCharSet *fcs, FcChar32 ucs4, FcCharLeaf *leaf) +{ + int pos; + + pos = FcCharSetFindLeafPos (fcs, ucs4); + if (pos >= 0) + { + free (FcCharSetLeaf (fcs, pos)); + FcCharSetLeaves(fcs)[pos] = FcPtrToOffset (FcCharSetLeaves(fcs), + leaf); + return FcTrue; + } + pos = -pos - 1; + return FcCharSetPutLeaf (fcs, ucs4, leaf, pos); +} + +FcBool +FcCharSetAddChar (FcCharSet *fcs, FcChar32 ucs4) +{ + FcCharLeaf *leaf; + FcChar32 *b; + + if (fcs == NULL || FcRefIsConst (&fcs->ref)) + return FcFalse; + leaf = FcCharSetFindLeafCreate (fcs, ucs4); + if (!leaf) + return FcFalse; + b = &leaf->map[(ucs4 & 0xff) >> 5]; + *b |= (1 << (ucs4 & 0x1f)); + return FcTrue; +} + +FcBool +FcCharSetDelChar (FcCharSet *fcs, FcChar32 ucs4) +{ + FcCharLeaf *leaf; + FcChar32 *b; + + if (fcs == NULL || FcRefIsConst (&fcs->ref)) + return FcFalse; + leaf = FcCharSetFindLeaf (fcs, ucs4); + if (!leaf) + return FcTrue; + b = &leaf->map[(ucs4 & 0xff) >> 5]; + *b &= ~(1 << (ucs4 & 0x1f)); + /* We don't bother removing the leaf if it's empty */ + return FcTrue; +} + +/* + * An iterator for the leaves of a charset + */ + +typedef struct _fcCharSetIter { + FcCharLeaf *leaf; + FcChar32 ucs4; + int pos; +} FcCharSetIter; + +/* + * Set iter->leaf to the leaf containing iter->ucs4 or higher + */ + +static void +FcCharSetIterSet (const FcCharSet *fcs, FcCharSetIter *iter) +{ + int pos = FcCharSetFindLeafPos (fcs, iter->ucs4); + + if (pos < 0) + { + pos = -pos - 1; + if (pos == fcs->num) + { + iter->ucs4 = ~0; + iter->leaf = 0; + return; + } + iter->ucs4 = (FcChar32) FcCharSetNumbers(fcs)[pos] << 8; + } + iter->leaf = FcCharSetLeaf(fcs, pos); + iter->pos = pos; +} + +static void +FcCharSetIterNext (const FcCharSet *fcs, FcCharSetIter *iter) +{ + int pos = iter->pos + 1; + if (pos >= fcs->num) + { + iter->ucs4 = ~0; + iter->leaf = 0; + } + else + { + iter->ucs4 = (FcChar32) FcCharSetNumbers(fcs)[pos] << 8; + iter->leaf = FcCharSetLeaf(fcs, pos); + iter->pos = pos; + } +} + + +static void +FcCharSetIterStart (const FcCharSet *fcs, FcCharSetIter *iter) +{ + iter->ucs4 = 0; + iter->pos = 0; + FcCharSetIterSet (fcs, iter); +} + +FcCharSet * +FcCharSetCopy (FcCharSet *src) +{ + if (src) + { + if (!FcRefIsConst (&src->ref)) + FcRefInc (&src->ref); + else + FcCacheObjectReference (src); + } + return src; +} + +FcBool +FcCharSetEqual (const FcCharSet *a, const FcCharSet *b) +{ + FcCharSetIter ai, bi; + int i; + + if (a == b) + return FcTrue; + if (!a || !b) + return FcFalse; + for (FcCharSetIterStart (a, &ai), FcCharSetIterStart (b, &bi); + ai.leaf && bi.leaf; + FcCharSetIterNext (a, &ai), FcCharSetIterNext (b, &bi)) + { + if (ai.ucs4 != bi.ucs4) + return FcFalse; + for (i = 0; i < 256/32; i++) + if (ai.leaf->map[i] != bi.leaf->map[i]) + return FcFalse; + } + return ai.leaf == bi.leaf; +} + +static FcBool +FcCharSetAddLeaf (FcCharSet *fcs, + FcChar32 ucs4, + FcCharLeaf *leaf) +{ + FcCharLeaf *new = FcCharSetFindLeafCreate (fcs, ucs4); + if (!new) + return FcFalse; + *new = *leaf; + return FcTrue; +} + +static FcCharSet * +FcCharSetOperate (const FcCharSet *a, + const FcCharSet *b, + FcBool (*overlap) (FcCharLeaf *result, + const FcCharLeaf *al, + const FcCharLeaf *bl), + FcBool aonly, + FcBool bonly) +{ + FcCharSet *fcs; + FcCharSetIter ai, bi; + + if (!a || !b) + goto bail0; + fcs = FcCharSetCreate (); + if (!fcs) + goto bail0; + FcCharSetIterStart (a, &ai); + FcCharSetIterStart (b, &bi); + while ((ai.leaf || (bonly && bi.leaf)) && (bi.leaf || (aonly && ai.leaf))) + { + if (ai.ucs4 < bi.ucs4) + { + if (aonly) + { + if (!FcCharSetAddLeaf (fcs, ai.ucs4, ai.leaf)) + goto bail1; + FcCharSetIterNext (a, &ai); + } + else + { + ai.ucs4 = bi.ucs4; + FcCharSetIterSet (a, &ai); + } + } + else if (bi.ucs4 < ai.ucs4 ) + { + if (bonly) + { + if (!FcCharSetAddLeaf (fcs, bi.ucs4, bi.leaf)) + goto bail1; + FcCharSetIterNext (b, &bi); + } + else + { + bi.ucs4 = ai.ucs4; + FcCharSetIterSet (b, &bi); + } + } + else + { + FcCharLeaf leaf; + + if ((*overlap) (&leaf, ai.leaf, bi.leaf)) + { + if (!FcCharSetAddLeaf (fcs, ai.ucs4, &leaf)) + goto bail1; + } + FcCharSetIterNext (a, &ai); + FcCharSetIterNext (b, &bi); + } + } + return fcs; +bail1: + FcCharSetDestroy (fcs); +bail0: + return 0; +} + +static FcBool +FcCharSetIntersectLeaf (FcCharLeaf *result, + const FcCharLeaf *al, + const FcCharLeaf *bl) +{ + int i; + FcBool nonempty = FcFalse; + + for (i = 0; i < 256/32; i++) + if ((result->map[i] = al->map[i] & bl->map[i])) + nonempty = FcTrue; + return nonempty; +} + +FcCharSet * +FcCharSetIntersect (const FcCharSet *a, const FcCharSet *b) +{ + return FcCharSetOperate (a, b, FcCharSetIntersectLeaf, FcFalse, FcFalse); +} + +static FcBool +FcCharSetUnionLeaf (FcCharLeaf *result, + const FcCharLeaf *al, + const FcCharLeaf *bl) +{ + int i; + + for (i = 0; i < 256/32; i++) + result->map[i] = al->map[i] | bl->map[i]; + return FcTrue; +} + +FcCharSet * +FcCharSetUnion (const FcCharSet *a, const FcCharSet *b) +{ + return FcCharSetOperate (a, b, FcCharSetUnionLeaf, FcTrue, FcTrue); +} + +FcBool +FcCharSetMerge (FcCharSet *a, const FcCharSet *b, FcBool *changed) +{ + int ai = 0, bi = 0; + FcChar16 an, bn; + + if (!a || !b) + return FcFalse; + + if (FcRefIsConst (&a->ref)) { + if (changed) + *changed = FcFalse; + return FcFalse; + } + + if (changed) { + *changed = !FcCharSetIsSubset(b, a); + if (!*changed) + return FcTrue; + } + + while (bi < b->num) + { + an = ai < a->num ? FcCharSetNumbers(a)[ai] : ~0; + bn = FcCharSetNumbers(b)[bi]; + + if (an < bn) + { + ai = FcCharSetFindLeafForward (a, ai + 1, bn); + if (ai < 0) + ai = -ai - 1; + } + else + { + FcCharLeaf *bl = FcCharSetLeaf(b, bi); + if (bn < an) + { + if (!FcCharSetAddLeaf (a, bn << 8, bl)) + return FcFalse; + } + else + { + FcCharLeaf *al = FcCharSetLeaf(a, ai); + FcCharSetUnionLeaf (al, al, bl); + } + + ai++; + bi++; + } + } + + return FcTrue; +} + +static FcBool +FcCharSetSubtractLeaf (FcCharLeaf *result, + const FcCharLeaf *al, + const FcCharLeaf *bl) +{ + int i; + FcBool nonempty = FcFalse; + + for (i = 0; i < 256/32; i++) + if ((result->map[i] = al->map[i] & ~bl->map[i])) + nonempty = FcTrue; + return nonempty; +} + +FcCharSet * +FcCharSetSubtract (const FcCharSet *a, const FcCharSet *b) +{ + return FcCharSetOperate (a, b, FcCharSetSubtractLeaf, FcTrue, FcFalse); +} + +FcBool +FcCharSetHasChar (const FcCharSet *fcs, FcChar32 ucs4) +{ + FcCharLeaf *leaf; + + if (!fcs) + return FcFalse; + leaf = FcCharSetFindLeaf (fcs, ucs4); + if (!leaf) + return FcFalse; + return (leaf->map[(ucs4 & 0xff) >> 5] & (1 << (ucs4 & 0x1f))) != 0; +} + +static FcChar32 +FcCharSetPopCount (FcChar32 c1) +{ +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) + return __builtin_popcount (c1); +#else + /* hackmem 169 */ + FcChar32 c2 = (c1 >> 1) & 033333333333; + c2 = c1 - c2 - ((c2 >> 1) & 033333333333); + return (((c2 + (c2 >> 3)) & 030707070707) % 077); +#endif +} + +FcChar32 +FcCharSetIntersectCount (const FcCharSet *a, const FcCharSet *b) +{ + FcCharSetIter ai, bi; + FcChar32 count = 0; + + if (a && b) + { + FcCharSetIterStart (a, &ai); + FcCharSetIterStart (b, &bi); + while (ai.leaf && bi.leaf) + { + if (ai.ucs4 == bi.ucs4) + { + FcChar32 *am = ai.leaf->map; + FcChar32 *bm = bi.leaf->map; + int i = 256/32; + while (i--) + count += FcCharSetPopCount (*am++ & *bm++); + FcCharSetIterNext (a, &ai); + } + else if (ai.ucs4 < bi.ucs4) + { + ai.ucs4 = bi.ucs4; + FcCharSetIterSet (a, &ai); + } + if (bi.ucs4 < ai.ucs4) + { + bi.ucs4 = ai.ucs4; + FcCharSetIterSet (b, &bi); + } + } + } + return count; +} + +FcChar32 +FcCharSetCount (const FcCharSet *a) +{ + FcCharSetIter ai; + FcChar32 count = 0; + + if (a) + { + for (FcCharSetIterStart (a, &ai); ai.leaf; FcCharSetIterNext (a, &ai)) + { + int i = 256/32; + FcChar32 *am = ai.leaf->map; + + while (i--) + count += FcCharSetPopCount (*am++); + } + } + return count; +} + +FcChar32 +FcCharSetSubtractCount (const FcCharSet *a, const FcCharSet *b) +{ + FcCharSetIter ai, bi; + FcChar32 count = 0; + + if (a && b) + { + FcCharSetIterStart (a, &ai); + FcCharSetIterStart (b, &bi); + while (ai.leaf) + { + if (ai.ucs4 <= bi.ucs4) + { + FcChar32 *am = ai.leaf->map; + int i = 256/32; + if (ai.ucs4 == bi.ucs4) + { + FcChar32 *bm = bi.leaf->map; + while (i--) + count += FcCharSetPopCount (*am++ & ~*bm++); + } + else + { + while (i--) + count += FcCharSetPopCount (*am++); + } + FcCharSetIterNext (a, &ai); + } + else if (bi.leaf) + { + bi.ucs4 = ai.ucs4; + FcCharSetIterSet (b, &bi); + } + } + } + return count; +} + +/* + * return FcTrue iff a is a subset of b + */ +FcBool +FcCharSetIsSubset (const FcCharSet *a, const FcCharSet *b) +{ + int ai, bi; + FcChar16 an, bn; + + if (a == b) + return FcTrue; + if (!a || !b) + return FcFalse; + bi = 0; + ai = 0; + while (ai < a->num && bi < b->num) + { + an = FcCharSetNumbers(a)[ai]; + bn = FcCharSetNumbers(b)[bi]; + /* + * Check matching pages + */ + if (an == bn) + { + FcChar32 *am = FcCharSetLeaf(a, ai)->map; + FcChar32 *bm = FcCharSetLeaf(b, bi)->map; + + if (am != bm) + { + int i = 256/32; + /* + * Does am have any bits not in bm? + */ + while (i--) + if (*am++ & ~*bm++) + return FcFalse; + } + ai++; + bi++; + } + /* + * Does a have any pages not in b? + */ + else if (an < bn) + return FcFalse; + else + { + bi = FcCharSetFindLeafForward (b, bi + 1, an); + if (bi < 0) + bi = -bi - 1; + } + } + /* + * did we look at every page? + */ + return ai >= a->num; +} + +/* + * These two functions efficiently walk the entire charmap for + * other software (like pango) that want their own copy + */ + +FcChar32 +FcCharSetNextPage (const FcCharSet *a, + FcChar32 map[FC_CHARSET_MAP_SIZE], + FcChar32 *next) +{ + FcCharSetIter ai; + FcChar32 page; + + if (!a) + return FC_CHARSET_DONE; + ai.ucs4 = *next; + FcCharSetIterSet (a, &ai); + if (!ai.leaf) + return FC_CHARSET_DONE; + + /* + * Save current information + */ + page = ai.ucs4; + memcpy (map, ai.leaf->map, sizeof (ai.leaf->map)); + /* + * Step to next page + */ + FcCharSetIterNext (a, &ai); + *next = ai.ucs4; + + return page; +} + +FcChar32 +FcCharSetFirstPage (const FcCharSet *a, + FcChar32 map[FC_CHARSET_MAP_SIZE], + FcChar32 *next) +{ + *next = 0; + return FcCharSetNextPage (a, map, next); +} + +/* + * old coverage API, rather hard to use correctly + */ + +FcChar32 +FcCharSetCoverage (const FcCharSet *a, FcChar32 page, FcChar32 *result) +{ + FcCharSetIter ai; + + ai.ucs4 = page; + FcCharSetIterSet (a, &ai); + if (!ai.leaf) + { + memset (result, '\0', 256 / 8); + page = 0; + } + else + { + memcpy (result, ai.leaf->map, sizeof (ai.leaf->map)); + FcCharSetIterNext (a, &ai); + page = ai.ucs4; + } + return page; +} + +/* + * ASCII representation of charsets. + * + * Each leaf is represented as 9 32-bit values, the code of the first character followed + * by 8 32 bit values for the leaf itself. Each value is encoded as 5 ASCII characters, + * only 85 different values are used to avoid control characters as well as the other + * characters used to encode font names. 85**5 > 2^32 so things work out, but + * it's not exactly human readable output. As a special case, 0 is encoded as a space + */ + +static const unsigned char charToValue[256] = { + /* "" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\b" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\020" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\030" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* " " */ 0xff, 0x00, 0xff, 0x01, 0x02, 0x03, 0x04, 0xff, + /* "(" */ 0x05, 0x06, 0x07, 0x08, 0xff, 0xff, 0x09, 0x0a, + /* "0" */ 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, + /* "8" */ 0x13, 0x14, 0xff, 0x15, 0x16, 0xff, 0x17, 0x18, + /* "@" */ 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + /* "H" */ 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + /* "P" */ 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + /* "X" */ 0x31, 0x32, 0x33, 0x34, 0xff, 0x35, 0x36, 0xff, + /* "`" */ 0xff, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, + /* "h" */ 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + /* "p" */ 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, + /* "x" */ 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0xff, + /* "\200" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\210" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\220" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\230" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\240" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\250" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\260" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\270" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\300" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\310" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\320" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\330" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\340" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\350" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\360" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* "\370" */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +}; + +static const FcChar8 valueToChar[0x55] = { + /* 0x00 */ '!', '#', '$', '%', '&', '(', ')', '*', + /* 0x08 */ '+', '.', '/', '0', '1', '2', '3', '4', + /* 0x10 */ '5', '6', '7', '8', '9', ';', '<', '>', + /* 0x18 */ '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', + /* 0x20 */ 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + /* 0x28 */ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + /* 0x30 */ 'W', 'X', 'Y', 'Z', '[', ']', '^', 'a', + /* 0x38 */ 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + /* 0x40 */ 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', + /* 0x48 */ 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', + /* 0x50 */ 'z', '{', '|', '}', '~', +}; + +static FcChar8 * +FcCharSetParseValue (FcChar8 *string, FcChar32 *value) +{ + int i; + FcChar32 v; + FcChar32 c; + + if (*string == ' ') + { + v = 0; + string++; + } + else + { + v = 0; + for (i = 0; i < 5; i++) + { + if (!(c = (FcChar32) (unsigned char) *string++)) + return 0; + c = charToValue[c]; + if (c == 0xff) + return 0; + v = v * 85 + c; + } + } + *value = v; + return string; +} + +static FcBool +FcCharSetUnparseValue (FcStrBuf *buf, FcChar32 value) +{ + int i; + if (value == 0) + { + return FcStrBufChar (buf, ' '); + } + else + { + FcChar8 string[6]; + FcChar8 *s = string + 5; + string[5] = '\0'; + for (i = 0; i < 5; i++) + { + *--s = valueToChar[value % 85]; + value /= 85; + } + for (i = 0; i < 5; i++) + if (!FcStrBufChar (buf, *s++)) + return FcFalse; + } + return FcTrue; +} + +FcCharSet * +FcNameParseCharSet (FcChar8 *string) +{ + FcCharSet *c; + FcChar32 ucs4; + FcCharLeaf *leaf; + FcCharLeaf temp; + FcChar32 bits; + int i; + + c = FcCharSetCreate (); + if (!c) + goto bail0; + while (*string) + { + string = FcCharSetParseValue (string, &ucs4); + if (!string) + goto bail1; + bits = 0; + for (i = 0; i < 256/32; i++) + { + string = FcCharSetParseValue (string, &temp.map[i]); + if (!string) + goto bail1; + bits |= temp.map[i]; + } + if (bits) + { + leaf = malloc (sizeof (FcCharLeaf)); + if (!leaf) + goto bail1; + *leaf = temp; + if (!FcCharSetInsertLeaf (c, ucs4, leaf)) + goto bail1; + } + } + return c; +bail1: + if (c->num) + { + free (FcCharSetLeaves (c)); + } + if (c->num) + { + free (FcCharSetNumbers (c)); + } + free (c); +bail0: + return NULL; +} + +FcBool +FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c) +{ + FcCharSetIter ci; + int i; +#ifdef CHECK + int len = buf->len; +#endif + + for (FcCharSetIterStart (c, &ci); + ci.leaf; + FcCharSetIterNext (c, &ci)) + { + if (!FcCharSetUnparseValue (buf, ci.ucs4)) + return FcFalse; + for (i = 0; i < 256/32; i++) + if (!FcCharSetUnparseValue (buf, ci.leaf->map[i])) + return FcFalse; + } +#ifdef CHECK + { + FcCharSet *check; + FcChar32 missing; + FcCharSetIter ci, checki; + + /* null terminate for parser */ + FcStrBufChar (buf, '\0'); + /* step back over null for life after test */ + buf->len--; + check = FcNameParseCharSet (buf->buf + len); + FcCharSetIterStart (c, &ci); + FcCharSetIterStart (check, &checki); + while (ci.leaf || checki.leaf) + { + if (ci.ucs4 < checki.ucs4) + { + printf ("Missing leaf node at 0x%x\n", ci.ucs4); + FcCharSetIterNext (c, &ci); + } + else if (checki.ucs4 < ci.ucs4) + { + printf ("Extra leaf node at 0x%x\n", checki.ucs4); + FcCharSetIterNext (check, &checki); + } + else + { + int i = 256/32; + FcChar32 *cm = ci.leaf->map; + FcChar32 *checkm = checki.leaf->map; + + for (i = 0; i < 256; i += 32) + { + if (*cm != *checkm) + printf ("Mismatching sets at 0x%08x: 0x%08x != 0x%08x\n", + ci.ucs4 + i, *cm, *checkm); + cm++; + checkm++; + } + FcCharSetIterNext (c, &ci); + FcCharSetIterNext (check, &checki); + } + } + if ((missing = FcCharSetSubtractCount (c, check))) + printf ("%d missing in reparsed result\n", missing); + if ((missing = FcCharSetSubtractCount (check, c))) + printf ("%d extra in reparsed result\n", missing); + FcCharSetDestroy (check); + } +#endif + + return FcTrue; +} + +typedef struct _FcCharLeafEnt FcCharLeafEnt; + +struct _FcCharLeafEnt { + FcCharLeafEnt *next; + FcChar32 hash; + FcCharLeaf leaf; +}; + +#define FC_CHAR_LEAF_BLOCK (4096 / sizeof (FcCharLeafEnt)) +#define FC_CHAR_LEAF_HASH_SIZE 257 + +typedef struct _FcCharSetEnt FcCharSetEnt; + +struct _FcCharSetEnt { + FcCharSetEnt *next; + FcChar32 hash; + FcCharSet set; +}; + +typedef struct _FcCharSetOrigEnt FcCharSetOrigEnt; + +struct _FcCharSetOrigEnt { + FcCharSetOrigEnt *next; + const FcCharSet *orig; + const FcCharSet *frozen; +}; + +#define FC_CHAR_SET_HASH_SIZE 67 + +struct _FcCharSetFreezer { + FcCharLeafEnt *leaf_hash_table[FC_CHAR_LEAF_HASH_SIZE]; + FcCharLeafEnt **leaf_blocks; + int leaf_block_count; + FcCharSetEnt *set_hash_table[FC_CHAR_SET_HASH_SIZE]; + FcCharSetOrigEnt *orig_hash_table[FC_CHAR_SET_HASH_SIZE]; + FcCharLeafEnt *current_block; + int leaf_remain; + int leaves_seen; + int charsets_seen; + int leaves_allocated; + int charsets_allocated; +}; + +static FcCharLeafEnt * +FcCharLeafEntCreate (FcCharSetFreezer *freezer) +{ + if (!freezer->leaf_remain) + { + FcCharLeafEnt **newBlocks; + + freezer->leaf_block_count++; + newBlocks = realloc (freezer->leaf_blocks, freezer->leaf_block_count * sizeof (FcCharLeafEnt *)); + if (!newBlocks) + return 0; + freezer->leaf_blocks = newBlocks; + freezer->current_block = freezer->leaf_blocks[freezer->leaf_block_count-1] = malloc (FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt)); + if (!freezer->current_block) + return 0; + freezer->leaf_remain = FC_CHAR_LEAF_BLOCK; + } + freezer->leaf_remain--; + freezer->leaves_allocated++; + return freezer->current_block++; +} + +static FcChar32 +FcCharLeafHash (FcCharLeaf *leaf) +{ + FcChar32 hash = 0; + int i; + + for (i = 0; i < 256/32; i++) + hash = ((hash << 1) | (hash >> 31)) ^ leaf->map[i]; + return hash; +} + +static FcCharLeaf * +FcCharSetFreezeLeaf (FcCharSetFreezer *freezer, FcCharLeaf *leaf) +{ + FcChar32 hash = FcCharLeafHash (leaf); + FcCharLeafEnt **bucket = &freezer->leaf_hash_table[hash % FC_CHAR_LEAF_HASH_SIZE]; + FcCharLeafEnt *ent; + + for (ent = *bucket; ent; ent = ent->next) + { + if (ent->hash == hash && !memcmp (&ent->leaf, leaf, sizeof (FcCharLeaf))) + return &ent->leaf; + } + + ent = FcCharLeafEntCreate(freezer); + if (!ent) + return 0; + ent->leaf = *leaf; + ent->hash = hash; + ent->next = *bucket; + *bucket = ent; + return &ent->leaf; +} + +static FcChar32 +FcCharSetHash (FcCharSet *fcs) +{ + FcChar32 hash = 0; + int i; + + /* hash in leaves */ + for (i = 0; i < fcs->num; i++) + hash = ((hash << 1) | (hash >> 31)) ^ FcCharLeafHash (FcCharSetLeaf(fcs,i)); + /* hash in numbers */ + for (i = 0; i < fcs->num; i++) + hash = ((hash << 1) | (hash >> 31)) ^ *FcCharSetNumbers(fcs); + return hash; +} + +static FcBool +FcCharSetFreezeOrig (FcCharSetFreezer *freezer, const FcCharSet *orig, const FcCharSet *frozen) +{ + FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) & FC_CHAR_SET_HASH_SIZE]; + FcCharSetOrigEnt *ent; + + ent = malloc (sizeof (FcCharSetOrigEnt)); + if (!ent) + return FcFalse; + ent->orig = orig; + ent->frozen = frozen; + ent->next = *bucket; + *bucket = ent; + return FcTrue; +} + +static FcCharSet * +FcCharSetFreezeBase (FcCharSetFreezer *freezer, FcCharSet *fcs) +{ + FcChar32 hash = FcCharSetHash (fcs); + FcCharSetEnt **bucket = &freezer->set_hash_table[hash % FC_CHAR_SET_HASH_SIZE]; + FcCharSetEnt *ent; + int size; + int i; + + for (ent = *bucket; ent; ent = ent->next) + { + if (ent->hash == hash && + ent->set.num == fcs->num && + !memcmp (FcCharSetNumbers(&ent->set), + FcCharSetNumbers(fcs), + fcs->num * sizeof (FcChar16))) + { + FcBool ok = FcTrue; + int i; + + for (i = 0; i < fcs->num; i++) + if (FcCharSetLeaf(&ent->set, i) != FcCharSetLeaf(fcs, i)) + ok = FcFalse; + if (ok) + return &ent->set; + } + } + + size = (sizeof (FcCharSetEnt) + + fcs->num * sizeof (FcCharLeaf *) + + fcs->num * sizeof (FcChar16)); + ent = malloc (size); + if (!ent) + return 0; + + freezer->charsets_allocated++; + + FcRefSetConst (&ent->set.ref); + ent->set.num = fcs->num; + if (fcs->num) + { + intptr_t *ent_leaves; + + ent->set.leaves_offset = sizeof (ent->set); + ent->set.numbers_offset = (ent->set.leaves_offset + + fcs->num * sizeof (intptr_t)); + + ent_leaves = FcCharSetLeaves (&ent->set); + for (i = 0; i < fcs->num; i++) + ent_leaves[i] = FcPtrToOffset (ent_leaves, + FcCharSetLeaf (fcs, i)); + memcpy (FcCharSetNumbers (&ent->set), + FcCharSetNumbers (fcs), + fcs->num * sizeof (FcChar16)); + } + else + { + ent->set.leaves_offset = 0; + ent->set.numbers_offset = 0; + } + + ent->hash = hash; + ent->next = *bucket; + *bucket = ent; + + return &ent->set; +} + +static const FcCharSet * +FcCharSetFindFrozen (FcCharSetFreezer *freezer, const FcCharSet *orig) +{ + FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) & FC_CHAR_SET_HASH_SIZE]; + FcCharSetOrigEnt *ent; + + for (ent = *bucket; ent; ent = ent->next) + if (ent->orig == orig) + return ent->frozen; + return NULL; +} + +const FcCharSet * +FcCharSetFreeze (FcCharSetFreezer *freezer, const FcCharSet *fcs) +{ + FcCharSet *b; + const FcCharSet *n = 0; + FcCharLeaf *l; + int i; + + b = FcCharSetCreate (); + if (!b) + goto bail0; + for (i = 0; i < fcs->num; i++) + { + l = FcCharSetFreezeLeaf (freezer, FcCharSetLeaf(fcs, i)); + if (!l) + goto bail1; + if (!FcCharSetInsertLeaf (b, FcCharSetNumbers(fcs)[i] << 8, l)) + goto bail1; + } + n = FcCharSetFreezeBase (freezer, b); + if (!FcCharSetFreezeOrig (freezer, fcs, n)) + { + n = NULL; + goto bail1; + } + freezer->charsets_seen++; + freezer->leaves_seen += fcs->num; +bail1: + if (b->num) + free (FcCharSetLeaves (b)); + if (b->num) + free (FcCharSetNumbers (b)); + free (b); +bail0: + return n; +} + +FcCharSetFreezer * +FcCharSetFreezerCreate (void) +{ + FcCharSetFreezer *freezer; + + freezer = calloc (1, sizeof (FcCharSetFreezer)); + return freezer; +} + +void +FcCharSetFreezerDestroy (FcCharSetFreezer *freezer) +{ + int i; + + if (FcDebug() & FC_DBG_CACHE) + { + printf ("\ncharsets %d -> %d leaves %d -> %d\n", + freezer->charsets_seen, freezer->charsets_allocated, + freezer->leaves_seen, freezer->leaves_allocated); + } + for (i = 0; i < FC_CHAR_SET_HASH_SIZE; i++) + { + FcCharSetEnt *ent, *next; + for (ent = freezer->set_hash_table[i]; ent; ent = next) + { + next = ent->next; + free (ent); + } + } + + for (i = 0; i < FC_CHAR_SET_HASH_SIZE; i++) + { + FcCharSetOrigEnt *ent, *next; + for (ent = freezer->orig_hash_table[i]; ent; ent = next) + { + next = ent->next; + free (ent); + } + } + + for (i = 0; i < freezer->leaf_block_count; i++) + free (freezer->leaf_blocks[i]); + + free (freezer->leaf_blocks); + free (freezer); +} + +FcBool +FcCharSetSerializeAlloc (FcSerialize *serialize, const FcCharSet *cs) +{ + intptr_t *leaves; + FcChar16 *numbers; + int i; + + if (!FcRefIsConst (&cs->ref)) + { + if (!serialize->cs_freezer) + { + serialize->cs_freezer = FcCharSetFreezerCreate (); + if (!serialize->cs_freezer) + return FcFalse; + } + if (FcCharSetFindFrozen (serialize->cs_freezer, cs)) + return FcTrue; + + cs = FcCharSetFreeze (serialize->cs_freezer, cs); + } + + leaves = FcCharSetLeaves (cs); + numbers = FcCharSetNumbers (cs); + + if (!FcSerializeAlloc (serialize, cs, sizeof (FcCharSet))) + return FcFalse; + if (!FcSerializeAlloc (serialize, leaves, cs->num * sizeof (intptr_t))) + return FcFalse; + if (!FcSerializeAlloc (serialize, numbers, cs->num * sizeof (FcChar16))) + return FcFalse; + for (i = 0; i < cs->num; i++) + if (!FcSerializeAlloc (serialize, FcCharSetLeaf(cs, i), + sizeof (FcCharLeaf))) + return FcFalse; + return FcTrue; +} + +FcCharSet * +FcCharSetSerialize(FcSerialize *serialize, const FcCharSet *cs) +{ + FcCharSet *cs_serialized; + intptr_t *leaves, *leaves_serialized; + FcChar16 *numbers, *numbers_serialized; + FcCharLeaf *leaf, *leaf_serialized; + int i; + + if (!FcRefIsConst (&cs->ref) && serialize->cs_freezer) + { + cs = FcCharSetFindFrozen (serialize->cs_freezer, cs); + if (!cs) + return NULL; + } + + cs_serialized = FcSerializePtr (serialize, cs); + if (!cs_serialized) + return NULL; + + FcRefSetConst (&cs_serialized->ref); + cs_serialized->num = cs->num; + + if (cs->num) + { + leaves = FcCharSetLeaves (cs); + leaves_serialized = FcSerializePtr (serialize, leaves); + if (!leaves_serialized) + return NULL; + + cs_serialized->leaves_offset = FcPtrToOffset (cs_serialized, + leaves_serialized); + + numbers = FcCharSetNumbers (cs); + numbers_serialized = FcSerializePtr (serialize, numbers); + if (!numbers) + return NULL; + + cs_serialized->numbers_offset = FcPtrToOffset (cs_serialized, + numbers_serialized); + + for (i = 0; i < cs->num; i++) + { + leaf = FcCharSetLeaf (cs, i); + leaf_serialized = FcSerializePtr (serialize, leaf); + if (!leaf_serialized) + return NULL; + *leaf_serialized = *leaf; + leaves_serialized[i] = FcPtrToOffset (leaves_serialized, + leaf_serialized); + numbers_serialized[i] = numbers[i]; + } + } + else + { + cs_serialized->leaves_offset = 0; + cs_serialized->numbers_offset = 0; + } + + return cs_serialized; +} +#define __fccharset__ +#include "fcaliastail.h" +#undef __fccharset__ diff --git a/project/jni/fontconfig/src/fccompat.c b/project/jni/fontconfig/src/fccompat.c new file mode 100644 index 000000000..f4f3f5fdc --- /dev/null +++ b/project/jni/fontconfig/src/fccompat.c @@ -0,0 +1,257 @@ +/* + * fontconfig/src/fccompat.c + * + * Copyright © 2012 Red Hat, Inc. + * + * Author(s): + * Akira TAGOH + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" + +#include +#if HAVE_SYS_TYPES_H +#include +#endif +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_FCNTL_H +#include +#endif +#include +#include +#include +#include + +#ifdef O_CLOEXEC +#define FC_O_CLOEXEC O_CLOEXEC +#else +#define FC_O_CLOEXEC 0 +#endif +#ifdef O_LARGEFILE +#define FC_O_LARGEFILE O_LARGEFILE +#else +#define FC_O_LARGEFILE 0 +#endif +#ifdef O_BINARY +#define FC_O_BINARY O_BINARY +#else +#define FC_O_BINARY 0 +#endif +#ifdef O_TEMPORARY +#define FC_O_TEMPORARY O_TEMPORARY +#else +#define FC_O_TEMPORARY 0 +#endif +#ifdef O_NOINHERIT +#define FC_O_NOINHERIT O_NOINHERIT +#else +#define FC_O_NOINHERIT 0 +#endif + +#if !defined (HAVE_MKOSTEMP) && !defined(HAVE_MKSTEMP) && !defined(HAVE__MKTEMP_S) +static int +mkstemp (char *template) +{ + static const char s[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int fd, i; + size_t l; + + if (template == NULL) + { + errno = EINVAL; + return -1; + } + l = strlen (template); + if (l < 6 || strcmp (&template[l - 6], "XXXXXX") != 0) + { + errno = EINVAL; + return -1; + } + do + { + errno = 0; + for (i = l - 6; i < l; i++) + { + int r = FcRandom (); + template[i] = s[r % 62]; + } + fd = FcOpen (template, FC_O_BINARY | O_CREAT | O_EXCL | FC_O_TEMPORARY | FC_O_NOINHERIT | O_RDWR, 0600); + } while (fd < 0 && errno == EEXIST); + if (fd >= 0) + errno = 0; + + return fd; +} +#define HAVE_MKSTEMP 1 +#endif + +int +FcOpen(const char *pathname, int flags, ...) +{ + int fd = -1; + + if (flags & O_CREAT) + { + va_list ap; + mode_t mode; + + va_start(ap, flags); + mode = (mode_t) va_arg(ap, int); + va_end(ap); + + fd = open(pathname, flags | FC_O_CLOEXEC | FC_O_LARGEFILE, mode); + } + else + { + fd = open(pathname, flags | FC_O_CLOEXEC | FC_O_LARGEFILE); + } + + return fd; +} + +int +FcMakeTempfile (char *template) +{ + int fd = -1; + +#if HAVE_MKOSTEMP + fd = mkostemp (template, FC_O_CLOEXEC); +#elif HAVE_MKSTEMP + fd = mkstemp (template); +# ifdef F_DUPFD_CLOEXEC + if (fd != -1) + { + int newfd = fcntl(fd, F_DUPFD_CLOEXEC, STDIN_FILENO); + + close(fd); + fd = newfd; + } +# elif defined(FD_CLOEXEC) + if (fd != -1) + { + fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); + } +# endif +#elif HAVE__MKTEMP_S + if (_mktemp_s(template, strlen(template) + 1) != 0) + return -1; + fd = FcOpen(template, O_RDWR | O_EXCL | O_CREAT, 0600); +#endif + + return fd; +} + +int32_t +FcRandom(void) +{ + int32_t result; + +#if HAVE_RANDOM_R + static struct random_data fcrandbuf; + static char statebuf[256]; + static FcBool initialized = FcFalse; +#ifdef _AIX + static char *retval; + long res; +#endif + + if (initialized != FcTrue) + { +#ifdef _AIX + initstate_r (time (NULL), statebuf, 256, &retval, &fcrandbuf); +#else + initstate_r (time (NULL), statebuf, 256, &fcrandbuf); +#endif + initialized = FcTrue; + } + +#ifdef _AIX + random_r (&res, &fcrandbuf); + result = (int32_t)res; +#else + random_r (&fcrandbuf, &result); +#endif +#elif HAVE_RANDOM + static char statebuf[256]; + char *state; + static FcBool initialized = FcFalse; + + if (initialized != FcTrue) + { + state = initstate (time (NULL), statebuf, 256); + initialized = FcTrue; + } + else + state = setstate (statebuf); + + result = random (); + + setstate (state); +#elif HAVE_LRAND48 + result = lrand48 (); +#elif HAVE_RAND_R + static unsigned int seed = time (NULL); + + result = rand_r (&seed); +#elif HAVE_RAND + static FcBool initialized = FcFalse; + + if (initialized != FcTrue) + { + srand (time (NULL)); + initialized = FcTrue; + } + result = rand (); +#else +# error no random number generator function available. +#endif + + return result; +} + +#ifdef _WIN32 +#include +#define mkdir(path,mode) _mkdir(path) +#endif + +FcBool +FcMakeDirectory (const FcChar8 *dir) +{ + FcChar8 *parent; + FcBool ret; + + if (strlen ((char *) dir) == 0) + return FcFalse; + + parent = FcStrDirname (dir); + if (!parent) + return FcFalse; + if (access ((char *) parent, F_OK) == 0) + ret = mkdir ((char *) dir, 0755) == 0 && chmod ((char *) dir, 0755) == 0; + else if (access ((char *) parent, F_OK) == -1) + ret = FcMakeDirectory (parent) && (mkdir ((char *) dir, 0755) == 0) && chmod ((char *) dir, 0755) == 0; + else + ret = FcFalse; + FcStrFree (parent); + return ret; +} diff --git a/project/jni/fontconfig/src/fcdbg.c b/project/jni/fontconfig/src/fcdbg.c new file mode 100644 index 000000000..d74bc2769 --- /dev/null +++ b/project/jni/fontconfig/src/fcdbg.c @@ -0,0 +1,499 @@ +/* + * fontconfig/src/fcdbg.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include +#include + +static void +_FcValuePrintFile (FILE *f, const FcValue v) +{ + switch (v.type) { + case FcTypeUnknown: + fprintf (f, ""); + break; + case FcTypeVoid: + fprintf (f, ""); + break; + case FcTypeInteger: + fprintf (f, "%d(i)", v.u.i); + break; + case FcTypeDouble: + fprintf (f, "%g(f)", v.u.d); + break; + case FcTypeString: + fprintf (f, "\"%s\"", v.u.s); + break; + case FcTypeBool: + fprintf (f, "%s", v.u.b ? "True" : "False"); + break; + case FcTypeMatrix: + fprintf (f, "[%g %g; %g %g]", v.u.m->xx, v.u.m->xy, v.u.m->yx, v.u.m->yy); + break; + case FcTypeCharSet: /* XXX */ + if (f == stdout) + FcCharSetPrint (v.u.c); + break; + case FcTypeLangSet: + FcLangSetPrint (v.u.l); + break; + case FcTypeFTFace: + fprintf (f, "face"); + break; + } +} + +void +FcValuePrintFile (FILE *f, const FcValue v) +{ + fprintf (f, " "); + _FcValuePrintFile (f, v); +} + +void +FcValuePrint (const FcValue v) +{ + printf (" "); + _FcValuePrintFile (stdout, v); +} + +void +FcValuePrintWithPosition (const FcValue v, FcBool show_pos_mark) +{ + if (show_pos_mark) + printf (" [marker] "); + else + printf (" "); + _FcValuePrintFile (stdout, v); +} + +static void +FcValueBindingPrint (const FcValueListPtr l) +{ + switch (l->binding) { + case FcValueBindingWeak: + printf ("(w)"); + break; + case FcValueBindingStrong: + printf ("(s)"); + break; + case FcValueBindingSame: + printf ("(=)"); + break; + default: + /* shouldn't be reached */ + printf ("(?)"); + break; + } +} + +void +FcValueListPrintWithPosition (FcValueListPtr l, const FcValueListPtr pos) +{ + for (; l != NULL; l = FcValueListNext(l)) + { + FcValuePrintWithPosition (FcValueCanonicalize (&l->value), pos != NULL && l == pos); + FcValueBindingPrint (l); + } + if (!pos) + printf (" [marker]"); +} + +void +FcValueListPrint (FcValueListPtr l) +{ + for (; l != NULL; l = FcValueListNext(l)) + { + FcValuePrint (FcValueCanonicalize (&l->value)); + FcValueBindingPrint (l); + } +} + +void +FcLangSetPrint (const FcLangSet *ls) +{ + FcStrBuf buf; + FcChar8 init_buf[1024]; + + FcStrBufInit (&buf, init_buf, sizeof (init_buf)); + if (FcNameUnparseLangSet (&buf, ls) && FcStrBufChar (&buf,'\0')) + printf ("%s", buf.buf); + else + printf ("langset (alloc error)"); + FcStrBufDestroy (&buf); +} + +void +FcCharSetPrint (const FcCharSet *c) +{ + int i, j; + intptr_t *leaves = FcCharSetLeaves (c); + FcChar16 *numbers = FcCharSetNumbers (c); + +#if 0 + printf ("CharSet 0x%x\n", (intptr_t) c); + printf ("Leaves: +%d = 0x%x\n", c->leaves_offset, (intptr_t) leaves); + printf ("Numbers: +%d = 0x%x\n", c->numbers_offset, (intptr_t) numbers); + + for (i = 0; i < c->num; i++) + { + printf ("Page %d: %04x +%d = 0x%x\n", + i, numbers[i], leaves[i], + (intptr_t) FcOffsetToPtr (leaves, leaves[i], FcCharLeaf)); + } +#endif + + printf ("\n"); + for (i = 0; i < c->num; i++) + { + intptr_t leaf_offset = leaves[i]; + FcCharLeaf *leaf = FcOffsetToPtr (leaves, leaf_offset, FcCharLeaf); + + printf ("\t"); + printf ("%04x:", numbers[i]); + for (j = 0; j < 256/32; j++) + printf (" %08x", leaf->map[j]); + printf ("\n"); + } +} + +void +FcPatternPrint (const FcPattern *p) +{ + int i; + FcPatternElt *e; + + if (!p) + { + printf ("Null pattern\n"); + return; + } + printf ("Pattern has %d elts (size %d)\n", p->num, p->size); + for (i = 0; i < p->num; i++) + { + e = &FcPatternElts(p)[i]; + printf ("\t%s:", FcObjectName(e->object)); + FcValueListPrint (FcPatternEltValues(e)); + printf ("\n"); + } + printf ("\n"); +} + +#define FcOpFlagsPrint(_o_) \ + { \ + int f = FC_OP_GET_FLAGS (_o_); \ + if (f & FcOpFlagIgnoreBlanks) \ + printf ("(ignore blanks)"); \ + } + +void +FcOpPrint (FcOp op_) +{ + FcOp op = FC_OP_GET_OP (op_); + + switch (op) { + case FcOpInteger: printf ("Integer"); break; + case FcOpDouble: printf ("Double"); break; + case FcOpString: printf ("String"); break; + case FcOpMatrix: printf ("Matrix"); break; + case FcOpRange: printf ("Range"); break; + case FcOpBool: printf ("Bool"); break; + case FcOpCharSet: printf ("CharSet"); break; + case FcOpLangSet: printf ("LangSet"); break; + case FcOpField: printf ("Field"); break; + case FcOpConst: printf ("Const"); break; + case FcOpAssign: printf ("Assign"); break; + case FcOpAssignReplace: printf ("AssignReplace"); break; + case FcOpPrepend: printf ("Prepend"); break; + case FcOpPrependFirst: printf ("PrependFirst"); break; + case FcOpAppend: printf ("Append"); break; + case FcOpAppendLast: printf ("AppendLast"); break; + case FcOpDelete: printf ("Delete"); break; + case FcOpDeleteAll: printf ("DeleteAll"); break; + case FcOpQuest: printf ("Quest"); break; + case FcOpOr: printf ("Or"); break; + case FcOpAnd: printf ("And"); break; + case FcOpEqual: printf ("Equal"); FcOpFlagsPrint (op_); break; + case FcOpNotEqual: printf ("NotEqual"); FcOpFlagsPrint (op_); break; + case FcOpLess: printf ("Less"); break; + case FcOpLessEqual: printf ("LessEqual"); break; + case FcOpMore: printf ("More"); break; + case FcOpMoreEqual: printf ("MoreEqual"); break; + case FcOpContains: printf ("Contains"); break; + case FcOpNotContains: printf ("NotContains"); break; + case FcOpPlus: printf ("Plus"); break; + case FcOpMinus: printf ("Minus"); break; + case FcOpTimes: printf ("Times"); break; + case FcOpDivide: printf ("Divide"); break; + case FcOpNot: printf ("Not"); break; + case FcOpNil: printf ("Nil"); break; + case FcOpComma: printf ("Comma"); break; + case FcOpFloor: printf ("Floor"); break; + case FcOpCeil: printf ("Ceil"); break; + case FcOpRound: printf ("Round"); break; + case FcOpTrunc: printf ("Trunc"); break; + case FcOpListing: printf ("Listing"); FcOpFlagsPrint (op_); break; + case FcOpInvalid: printf ("Invalid"); break; + } +} + +void +FcExprPrint (const FcExpr *expr) +{ + if (!expr) printf ("none"); + else switch (FC_OP_GET_OP (expr->op)) { + case FcOpInteger: printf ("%d", expr->u.ival); break; + case FcOpDouble: printf ("%g", expr->u.dval); break; + case FcOpString: printf ("\"%s\"", expr->u.sval); break; + case FcOpMatrix: + printf ("["); + FcExprPrint (expr->u.mexpr->xx); + printf (" "); + FcExprPrint (expr->u.mexpr->xy); + printf ("; "); + FcExprPrint (expr->u.mexpr->yx); + printf (" "); + FcExprPrint (expr->u.mexpr->yy); + printf ("]"); + break; + case FcOpRange: break; + case FcOpBool: printf ("%s", expr->u.bval ? "true" : "false"); break; + case FcOpCharSet: printf ("charset\n"); break; + case FcOpLangSet: + printf ("langset:"); + FcLangSetPrint(expr->u.lval); + printf ("\n"); + break; + case FcOpNil: printf ("nil\n"); break; + case FcOpField: printf ("%s ", FcObjectName(expr->u.name.object)); + switch ((int) expr->u.name.kind) { + case FcMatchPattern: + printf ("(pattern) "); + break; + case FcMatchFont: + printf ("(font) "); + break; + } + break; + case FcOpConst: printf ("%s", expr->u.constant); break; + case FcOpQuest: + FcExprPrint (expr->u.tree.left); + printf (" quest "); + FcExprPrint (expr->u.tree.right->u.tree.left); + printf (" colon "); + FcExprPrint (expr->u.tree.right->u.tree.right); + break; + case FcOpAssign: + case FcOpAssignReplace: + case FcOpPrependFirst: + case FcOpPrepend: + case FcOpAppend: + case FcOpAppendLast: + case FcOpOr: + case FcOpAnd: + case FcOpEqual: + case FcOpNotEqual: + case FcOpLess: + case FcOpLessEqual: + case FcOpMore: + case FcOpMoreEqual: + case FcOpContains: + case FcOpListing: + case FcOpNotContains: + case FcOpPlus: + case FcOpMinus: + case FcOpTimes: + case FcOpDivide: + case FcOpComma: + FcExprPrint (expr->u.tree.left); + printf (" "); + switch (FC_OP_GET_OP (expr->op)) { + case FcOpAssign: printf ("Assign"); break; + case FcOpAssignReplace: printf ("AssignReplace"); break; + case FcOpPrependFirst: printf ("PrependFirst"); break; + case FcOpPrepend: printf ("Prepend"); break; + case FcOpAppend: printf ("Append"); break; + case FcOpAppendLast: printf ("AppendLast"); break; + case FcOpOr: printf ("Or"); break; + case FcOpAnd: printf ("And"); break; + case FcOpEqual: printf ("Equal"); FcOpFlagsPrint (expr->op); break; + case FcOpNotEqual: printf ("NotEqual"); FcOpFlagsPrint (expr->op); break; + case FcOpLess: printf ("Less"); break; + case FcOpLessEqual: printf ("LessEqual"); break; + case FcOpMore: printf ("More"); break; + case FcOpMoreEqual: printf ("MoreEqual"); break; + case FcOpContains: printf ("Contains"); break; + case FcOpListing: printf ("Listing"); FcOpFlagsPrint (expr->op); break; + case FcOpNotContains: printf ("NotContains"); break; + case FcOpPlus: printf ("Plus"); break; + case FcOpMinus: printf ("Minus"); break; + case FcOpTimes: printf ("Times"); break; + case FcOpDivide: printf ("Divide"); break; + case FcOpComma: printf ("Comma"); break; + default: break; + } + printf (" "); + FcExprPrint (expr->u.tree.right); + break; + case FcOpNot: + printf ("Not "); + FcExprPrint (expr->u.tree.left); + break; + case FcOpFloor: + printf ("Floor "); + FcExprPrint (expr->u.tree.left); + break; + case FcOpCeil: + printf ("Ceil "); + FcExprPrint (expr->u.tree.left); + break; + case FcOpRound: + printf ("Round "); + FcExprPrint (expr->u.tree.left); + break; + case FcOpTrunc: + printf ("Trunc "); + FcExprPrint (expr->u.tree.left); + break; + case FcOpInvalid: printf ("Invalid"); break; + } +} + +void +FcTestPrint (const FcTest *test) +{ + switch (test->kind) { + case FcMatchPattern: + printf ("pattern "); + break; + case FcMatchFont: + printf ("font "); + break; + case FcMatchScan: + printf ("scan "); + break; + } + switch (test->qual) { + case FcQualAny: + printf ("any "); + break; + case FcQualAll: + printf ("all "); + break; + case FcQualFirst: + printf ("first "); + break; + case FcQualNotFirst: + printf ("not_first "); + break; + } + printf ("%s ", FcObjectName (test->object)); + FcOpPrint (test->op); + printf (" "); + FcExprPrint (test->expr); + printf ("\n"); +} + +void +FcEditPrint (const FcEdit *edit) +{ + printf ("Edit %s ", FcObjectName (edit->object)); + FcOpPrint (edit->op); + printf (" "); + FcExprPrint (edit->expr); +} + +void +FcSubstPrint (const FcSubst *subst) +{ + FcRule *r; + FcRuleType last_type = FcRuleUnknown; + + printf ("match\n"); + for (r = subst->rule; r; r = r->next) + { + if (last_type != r->type) + { + switch (r->type) { + case FcRuleTest: + printf ("[test]\n"); + break; + case FcRuleEdit: + printf ("[edit]\n"); + break; + default: + break; + } + last_type = r->type; + } + printf ("\t"); + switch (r->type) { + case FcRuleTest: + FcTestPrint (r->u.test); + break; + case FcRuleEdit: + FcEditPrint (r->u.edit); + printf (";\n"); + break; + default: + break; + } + } + printf ("\n"); +} + +void +FcFontSetPrint (const FcFontSet *s) +{ + int i; + + printf ("FontSet %d of %d\n", s->nfont, s->sfont); + for (i = 0; i < s->nfont; i++) + { + printf ("Font %d ", i); + FcPatternPrint (s->fonts[i]); + } +} + +int FcDebugVal; + +void +FcInitDebug (void) +{ + if (!FcDebugVal) { + char *e; + + e = getenv ("FC_DEBUG"); + if (e) + { + printf ("FC_DEBUG=%s\n", e); + FcDebugVal = atoi (e); + if (FcDebugVal < 0) + FcDebugVal = 0; + } + } +} +#define __fcdbg__ +#include "fcaliastail.h" +#undef __fcdbg__ diff --git a/project/jni/fontconfig/src/fcdefault.c b/project/jni/fontconfig/src/fcdefault.c new file mode 100644 index 000000000..4beda7c00 --- /dev/null +++ b/project/jni/fontconfig/src/fcdefault.c @@ -0,0 +1,316 @@ +/* + * fontconfig/src/fcdefault.c + * + * Copyright © 2001 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include +#include + +/* MT-safe */ + +static const struct { + FcObject field; + FcBool value; +} FcBoolDefaults[] = { + { FC_HINTING_OBJECT, FcTrue }, /* !FT_LOAD_NO_HINTING */ + { FC_VERTICAL_LAYOUT_OBJECT, FcFalse }, /* FC_LOAD_VERTICAL_LAYOUT */ + { FC_AUTOHINT_OBJECT, FcFalse }, /* FC_LOAD_FORCE_AUTOHINT */ + { FC_GLOBAL_ADVANCE_OBJECT, FcTrue }, /* !FC_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH */ + { FC_EMBEDDED_BITMAP_OBJECT, FcTrue }, /* !FC_LOAD_NO_BITMAP */ + { FC_DECORATIVE_OBJECT, FcFalse }, +}; + +#define NUM_FC_BOOL_DEFAULTS (int) (sizeof FcBoolDefaults / sizeof FcBoolDefaults[0]) + +FcStrSet *default_langs; + +FcStrSet * +FcGetDefaultLangs (void) +{ + FcStrSet *result; +retry: + result = (FcStrSet *) fc_atomic_ptr_get (&default_langs); + if (!result) + { + char *langs; + + result = FcStrSetCreate (); + + langs = getenv ("FC_LANG"); + if (!langs || !langs[0]) + langs = getenv ("LC_ALL"); + if (!langs || !langs[0]) + langs = getenv ("LC_CTYPE"); + if (!langs || !langs[0]) + langs = getenv ("LANG"); + if (langs && langs[0]) + { + if (!FcStrSetAddLangs (result, langs)) + FcStrSetAdd (result, (const FcChar8 *) "en"); + } + else + FcStrSetAdd (result, (const FcChar8 *) "en"); + + FcRefSetConst (&result->ref); + if (!fc_atomic_ptr_cmpexch (&default_langs, NULL, result)) { + FcRefInit (&result->ref, 1); + FcStrSetDestroy (result); + goto retry; + } + } + + return result; +} + +static FcChar8 *default_lang; /* MT-safe */ + +FcChar8 * +FcGetDefaultLang (void) +{ + FcChar8 *lang; +retry: + lang = fc_atomic_ptr_get (&default_lang); + if (!lang) + { + FcStrSet *langs = FcGetDefaultLangs (); + lang = FcStrdup (langs->strs[0]); + FcStrSetDestroy (langs); + + if (!fc_atomic_ptr_cmpexch (&default_lang, NULL, lang)) { + free (lang); + goto retry; + } + } + + return lang; +} + +static FcChar8 *default_prgname; + +FcChar8 * +FcGetPrgname (void) +{ + FcChar8 *prgname; +retry: + prgname = fc_atomic_ptr_get (&default_prgname); + if (!prgname) + { +#ifdef _WIN32 + char buf[MAX_PATH+1]; + + /* TODO This is ASCII-only; fix it. */ + if (GetModuleFileNameA (GetModuleHandle (NULL), buf, sizeof (buf) / sizeof (buf[0])) > 0) + { + char *p; + unsigned int len; + + p = strrchr (buf, '\\'); + if (p) + p++; + else + p = buf; + + len = strlen (p); + + if (len > 4 && 0 == strcmp (p + len - 4, ".exe")) + { + len -= 4; + buf[len] = '\0'; + } + + prgname = FcStrdup (p); + } +#elif defined (HAVE_GETPROGNAME) + const char *q = getprogname (); + if (q) + prgname = FcStrdup (q); + else + prgname = FcStrdup (""); +#else +# if defined (HAVE_GETEXECNAME) + const char *p = getexecname (); +# elif defined (HAVE_READLINK) + char buf[PATH_MAX + 1]; + int len; + char *p = NULL; + + len = readlink ("/proc/self/exe", buf, sizeof (buf) - 1); + if (len != -1) + { + buf[len] = '\0'; + p = buf; + } +# else + char *p = NULL; +# endif + if (p) + { + char *r = strrchr (p, '/'); + if (r) + r++; + else + r = p; + + prgname = FcStrdup (r); + } + + if (!prgname) + prgname = FcStrdup (""); +#endif + + if (!fc_atomic_ptr_cmpexch (&default_prgname, NULL, prgname)) { + free (prgname); + goto retry; + } + } + + if (prgname && !prgname[0]) + return NULL; + + return prgname; +} + +void +FcDefaultFini (void) +{ + FcChar8 *lang; + FcStrSet *langs; + FcChar8 *prgname; + + lang = fc_atomic_ptr_get (&default_lang); + if (lang && fc_atomic_ptr_cmpexch (&default_lang, lang, NULL)) { + free (lang); + } + + langs = fc_atomic_ptr_get (&default_langs); + if (langs && fc_atomic_ptr_cmpexch (&default_langs, langs, NULL)) { + FcRefInit (&langs->ref, 1); + FcStrSetDestroy (langs); + } + + prgname = fc_atomic_ptr_get (&default_prgname); + if (prgname && fc_atomic_ptr_cmpexch (&default_prgname, prgname, NULL)) { + free (prgname); + } +} + +void +FcDefaultSubstitute (FcPattern *pattern) +{ + FcValue v, namelang, v2; + int i; + + if (FcPatternObjectGet (pattern, FC_WEIGHT_OBJECT, 0, &v) == FcResultNoMatch ) + FcPatternObjectAddInteger (pattern, FC_WEIGHT_OBJECT, FC_WEIGHT_NORMAL); + + if (FcPatternObjectGet (pattern, FC_SLANT_OBJECT, 0, &v) == FcResultNoMatch) + FcPatternObjectAddInteger (pattern, FC_SLANT_OBJECT, FC_SLANT_ROMAN); + + if (FcPatternObjectGet (pattern, FC_WIDTH_OBJECT, 0, &v) == FcResultNoMatch) + FcPatternObjectAddInteger (pattern, FC_WIDTH_OBJECT, FC_WIDTH_NORMAL); + + for (i = 0; i < NUM_FC_BOOL_DEFAULTS; i++) + if (FcPatternObjectGet (pattern, FcBoolDefaults[i].field, 0, &v) == FcResultNoMatch) + FcPatternObjectAddBool (pattern, FcBoolDefaults[i].field, FcBoolDefaults[i].value); + + if (FcPatternObjectGet (pattern, FC_PIXEL_SIZE_OBJECT, 0, &v) == FcResultNoMatch) + { + double dpi, size, scale; + + if (FcPatternObjectGetDouble (pattern, FC_SIZE_OBJECT, 0, &size) != FcResultMatch) + { + size = 12.0; + (void) FcPatternObjectDel (pattern, FC_SIZE_OBJECT); + FcPatternObjectAddDouble (pattern, FC_SIZE_OBJECT, size); + } + if (FcPatternObjectGetDouble (pattern, FC_SCALE_OBJECT, 0, &scale) != FcResultMatch) + { + scale = 1.0; + (void) FcPatternObjectDel (pattern, FC_SCALE_OBJECT); + FcPatternObjectAddDouble (pattern, FC_SCALE_OBJECT, scale); + } + size *= scale; + if (FcPatternObjectGetDouble (pattern, FC_DPI_OBJECT, 0, &dpi) != FcResultMatch) + { + dpi = 75.0; + (void) FcPatternObjectDel (pattern, FC_DPI_OBJECT); + FcPatternObjectAddDouble (pattern, FC_DPI_OBJECT, dpi); + } + size *= dpi / 72.0; + FcPatternObjectAddDouble (pattern, FC_PIXEL_SIZE_OBJECT, size); + } + + if (FcPatternObjectGet (pattern, FC_FONTVERSION_OBJECT, 0, &v) == FcResultNoMatch) + { + FcPatternObjectAddInteger (pattern, FC_FONTVERSION_OBJECT, 0x7fffffff); + } + + if (FcPatternObjectGet (pattern, FC_HINT_STYLE_OBJECT, 0, &v) == FcResultNoMatch) + { + FcPatternObjectAddInteger (pattern, FC_HINT_STYLE_OBJECT, FC_HINT_FULL); + } + if (FcPatternObjectGet (pattern, FC_NAMELANG_OBJECT, 0, &v) == FcResultNoMatch) + { + FcPatternObjectAddString (pattern, FC_NAMELANG_OBJECT, FcGetDefaultLang ()); + } + /* shouldn't be failed. */ + FcPatternObjectGet (pattern, FC_NAMELANG_OBJECT, 0, &namelang); + /* Add a fallback to ensure the english name when the requested language + * isn't available. this would helps for the fonts that have non-English + * name at the beginning. + */ + /* Set "en-us" instead of "en" to avoid giving higher score to "en". + * This is a hack for the case that the orth is not like ll-cc, because, + * if no namelang isn't explicitly set, it will has something like ll-cc + * according to current locale. which may causes FcLangDifferentTerritory + * at FcLangCompare(). thus, the English name is selected so that + * exact matched "en" has higher score than ll-cc. + */ + v2.type = FcTypeString; + v2.u.s = (FcChar8 *) "en-us"; + if (FcPatternObjectGet (pattern, FC_FAMILYLANG_OBJECT, 0, &v) == FcResultNoMatch) + { + FcPatternObjectAdd (pattern, FC_FAMILYLANG_OBJECT, namelang, FcTrue); + FcPatternObjectAddWithBinding (pattern, FC_FAMILYLANG_OBJECT, v2, FcValueBindingWeak, FcTrue); + } + if (FcPatternObjectGet (pattern, FC_STYLELANG_OBJECT, 0, &v) == FcResultNoMatch) + { + FcPatternObjectAdd (pattern, FC_STYLELANG_OBJECT, namelang, FcTrue); + FcPatternObjectAddWithBinding (pattern, FC_STYLELANG_OBJECT, v2, FcValueBindingWeak, FcTrue); + } + if (FcPatternObjectGet (pattern, FC_FULLNAMELANG_OBJECT, 0, &v) == FcResultNoMatch) + { + FcPatternObjectAdd (pattern, FC_FULLNAMELANG_OBJECT, namelang, FcTrue); + FcPatternObjectAddWithBinding (pattern, FC_FULLNAMELANG_OBJECT, v2, FcValueBindingWeak, FcTrue); + } + + if (FcPatternObjectGet (pattern, FC_PRGNAME_OBJECT, 0, &v) == FcResultNoMatch) + { + FcChar8 *prgname = FcGetPrgname (); + if (prgname) + FcPatternObjectAddString (pattern, FC_PRGNAME_OBJECT, prgname); + } +} +#define __fcdefault__ +#include "fcaliastail.h" +#undef __fcdefault__ diff --git a/project/jni/fontconfig/src/fcdeprecate.h b/project/jni/fontconfig/src/fcdeprecate.h new file mode 100644 index 000000000..214b684cf --- /dev/null +++ b/project/jni/fontconfig/src/fcdeprecate.h @@ -0,0 +1,36 @@ +/* + * Copyright © 2007 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * These APIs are deprecated; still exported by the library, but not + * declared in the public header file + */ +#ifndef _FCDEPRECATE_H_ +#define _FCDEPRECATE_H_ + +FcPublic int +FcConfigGetRescanInverval (FcConfig *config); + +FcPublic FcBool +FcConfigSetRescanInverval (FcConfig *config, int rescanInterval); + +#endif /* _FCDEPRECATE_H_ */ diff --git a/project/jni/fontconfig/src/fcdir.c b/project/jni/fontconfig/src/fcdir.c new file mode 100644 index 000000000..3bcd0b867 --- /dev/null +++ b/project/jni/fontconfig/src/fcdir.c @@ -0,0 +1,379 @@ +/* + * fontconfig/src/fcdir.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include + +FcBool +FcFileIsDir (const FcChar8 *file) +{ + struct stat statb; + + if (FcStat (file, &statb) != 0) + return FcFalse; + return S_ISDIR(statb.st_mode); +} + +FcBool +FcFileIsLink (const FcChar8 *file) +{ +#if HAVE_LSTAT + struct stat statb; + + if (lstat ((const char *)file, &statb) != 0) + return FcFalse; + return S_ISLNK (statb.st_mode); +#else + return FcFalse; +#endif +} + +FcBool +FcFileIsFile (const FcChar8 *file) +{ + struct stat statb; + + if (FcStat (file, &statb) != 0) + return FcFalse; + return S_ISREG (statb.st_mode); +} + +static FcBool +FcFileScanFontConfig (FcFontSet *set, + FcBlanks *blanks, + const FcChar8 *file, + FcConfig *config) +{ + FcPattern *font; + FcBool ret = FcTrue; + int id; + int count = 0; + + id = 0; + do + { + font = 0; + /* + * Nothing in the cache, scan the file + */ + if (FcDebug () & FC_DBG_SCAN) + { + printf ("\tScanning file %s...", file); + fflush (stdout); + } + font = FcFreeTypeQuery (file, id, blanks, &count); + if (FcDebug () & FC_DBG_SCAN) + printf ("done\n"); + + /* + * Edit pattern with user-defined rules + */ + if (font && config && !FcConfigSubstitute (config, font, FcMatchScan)) + { + FcPatternDestroy (font); + font = NULL; + ret = FcFalse; + } + + /* + * Add the font + */ + if (font) + { + if (FcDebug() & FC_DBG_SCANV) + { + printf ("Final font pattern:\n"); + FcPatternPrint (font); + } + if (!FcFontSetAdd (set, font)) + { + FcPatternDestroy (font); + font = NULL; + ret = FcFalse; + } + } + else if (font) + FcPatternDestroy (font); + id++; + } while (font && ret && id < count); + return ret; +} + +FcBool +FcFileScanConfig (FcFontSet *set, + FcStrSet *dirs, + FcBlanks *blanks, + const FcChar8 *file, + FcConfig *config) +{ + if (FcFileIsDir (file)) + return FcStrSetAdd (dirs, file); + else + { + if (set) + return FcFileScanFontConfig (set, blanks, file, config); + else + return FcTrue; + } +} + +FcBool +FcFileScan (FcFontSet *set, + FcStrSet *dirs, + FcFileCache *cache FC_UNUSED, + FcBlanks *blanks, + const FcChar8 *file, + FcBool force FC_UNUSED) +{ + return FcFileScanConfig (set, dirs, blanks, file, FcConfigGetCurrent ()); +} + +/* + * Strcmp helper that takes pointers to pointers, copied from qsort(3) manpage + */ +static int +cmpstringp(const void *p1, const void *p2) +{ + return strcmp(* (char **) p1, * (char **) p2); +} + +FcBool +FcDirScanConfig (FcFontSet *set, + FcStrSet *dirs, + FcBlanks *blanks, + const FcChar8 *dir, + FcBool force, /* XXX unused */ + FcConfig *config) +{ + DIR *d; + struct dirent *e; + FcStrSet *files; + FcChar8 *file; + FcChar8 *base; + FcBool ret = FcTrue; + int i; + + if (!force) + return FcFalse; + + if (!set && !dirs) + return FcTrue; + + if (!blanks) + blanks = FcConfigGetBlanks (config); + + /* freed below */ + file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1); + if (!file) { + ret = FcFalse; + goto bail; + } + + strcpy ((char *) file, (char *) dir); + strcat ((char *) file, "/"); + base = file + strlen ((char *) file); + + if (FcDebug () & FC_DBG_SCAN) + printf ("\tScanning dir %s\n", dir); + + d = opendir ((char *) dir); + if (!d) + { + /* Don't complain about missing directories */ + if (errno != ENOENT) + ret = FcFalse; + goto bail; + } + + files = FcStrSetCreate (); + if (!files) + { + ret = FcFalse; + goto bail1; + } + while ((e = readdir (d))) + { + if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN) + { + strcpy ((char *) base, (char *) e->d_name); + if (!FcStrSetAdd (files, file)) { + ret = FcFalse; + goto bail2; + } + } + } + + /* + * Sort files to make things prettier + */ + qsort(files->strs, files->num, sizeof(FcChar8 *), cmpstringp); + + /* + * Scan file files to build font patterns + */ + for (i = 0; i < files->num; i++) + FcFileScanConfig (set, dirs, blanks, files->strs[i], config); + +bail2: + FcStrSetDestroy (files); +bail1: + closedir (d); +bail: + if (file) + free (file); + + return ret; +} + +FcBool +FcDirScan (FcFontSet *set, + FcStrSet *dirs, + FcFileCache *cache, /* XXX unused */ + FcBlanks *blanks, + const FcChar8 *dir, + FcBool force /* XXX unused */) +{ + if (cache || !force) + return FcFalse; + + return FcDirScanConfig (set, dirs, blanks, dir, force, FcConfigGetCurrent ()); +} + +/* + * Scan the specified directory and construct a cache of its contents + */ +FcCache * +FcDirCacheScan (const FcChar8 *dir, FcConfig *config) +{ + FcStrSet *dirs; + FcFontSet *set; + FcCache *cache = NULL; + struct stat dir_stat; + + if (FcDebug () & FC_DBG_FONTSET) + printf ("cache scan dir %s\n", dir); + + if (FcStatChecksum (dir, &dir_stat) < 0) + goto bail; + + set = FcFontSetCreate(); + if (!set) + goto bail; + + dirs = FcStrSetCreate (); + if (!dirs) + goto bail1; + + /* + * Scan the dir + */ + if (!FcDirScanConfig (set, dirs, NULL, dir, FcTrue, config)) + goto bail2; + + /* + * Build the cache object + */ + cache = FcDirCacheBuild (set, dir, &dir_stat, dirs); + if (!cache) + goto bail2; + + /* + * Write out the cache file, ignoring any troubles + */ + FcDirCacheWrite (cache, config); + + bail2: + FcStrSetDestroy (dirs); + bail1: + FcFontSetDestroy (set); + bail: + return cache; +} + +FcCache * +FcDirCacheRescan (const FcChar8 *dir, FcConfig *config) +{ + FcCache *cache = FcDirCacheLoad (dir, config, NULL); + FcCache *new = NULL; + struct stat dir_stat; + FcStrSet *dirs; + + if (!cache) + return NULL; + if (FcStatChecksum (dir, &dir_stat) < 0) + goto bail; + dirs = FcStrSetCreate (); + if (!dirs) + goto bail; + + /* + * Scan the dir + */ + if (!FcDirScanConfig (NULL, dirs, NULL, dir, FcTrue, config)) + goto bail1; + /* + * Rebuild the cache object + */ + new = FcDirCacheRebuild (cache, &dir_stat, dirs); + if (!new) + goto bail1; + FcDirCacheUnload (cache); + /* + * Write out the cache file, ignoring any troubles + */ + FcDirCacheWrite (new, config); + +bail1: + FcStrSetDestroy (dirs); +bail: + return new; +} + +/* + * Read (or construct) the cache for a directory + */ +FcCache * +FcDirCacheRead (const FcChar8 *dir, FcBool force, FcConfig *config) +{ + FcCache *cache = NULL; + + /* Try to use existing cache file */ + if (!force) + cache = FcDirCacheLoad (dir, config, NULL); + + /* Not using existing cache file, construct new cache */ + if (!cache) + cache = FcDirCacheScan (dir, config); + + return cache; +} + +FcBool +FcDirSave (FcFontSet *set FC_UNUSED, FcStrSet * dirs FC_UNUSED, const FcChar8 *dir FC_UNUSED) +{ + return FcFalse; /* XXX deprecated */ +} +#define __fcdir__ +#include "fcaliastail.h" +#undef __fcdir__ diff --git a/project/jni/fontconfig/src/fcformat.c b/project/jni/fontconfig/src/fcformat.c new file mode 100644 index 000000000..59f8681df --- /dev/null +++ b/project/jni/fontconfig/src/fcformat.c @@ -0,0 +1,1220 @@ +/* + * Copyright © 2008,2009 Red Hat, Inc. + * + * Red Hat Author(s): Behdad Esfahbod + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include +#include +#include + + +/* The language is documented in doc/fcformat.fncs + * These are the features implemented: + * + * simple %{elt} + * width %width{elt} + * index %{elt[idx]} + * name= %{elt=} + * :name= %{:elt} + * default %{elt:-word} + * count %{#elt} + * subexpr %{{expr}} + * filter-out %{-elt1,elt2,elt3{expr}} + * filter-in %{+elt1,elt2,elt3{expr}} + * conditional %{?elt1,elt2,!elt3{}{}} + * enumerate %{[]elt1,elt2{expr}} + * langset langset enumeration using the same syntax + * builtin %{=blt} + * convert %{elt|conv1|conv2|conv3} + * + * converters: + * basename FcStrBasename + * dirname FcStrDirname + * downcase FcStrDowncase + * shescape + * cescape + * xmlescape + * delete delete chars + * escape escape chars + * translate translate chars + * + * builtins: + * unparse FcNameUnparse + * fcmatch fc-match default + * fclist fc-list default + * fccat fc-cat default + * pkgkit PackageKit package tag format + * + * + * Some ideas for future syntax extensions: + * + * - verbose builtin that is like FcPatternPrint + * - allow indexing subexprs using '%{[idx]elt1,elt2{subexpr}}' + * - allow indexing in +, -, ? filtering? + * - conditional/filtering/deletion on binding (using '(w)'/'(s)'/'(=)' notation) + */ + + +#define FCCAT_FORMAT "\"%{file|basename|cescape}\" %{index} \"%{-file{%{=unparse|cescape}}}\"" +#define FCMATCH_FORMAT "%{file:-|basename}: \"%{family[0]:-}\" \"%{style[0]:-}\"" +#define FCLIST_FORMAT "%{?file{%{file}: }}%{-file{%{=unparse}}}" +#define PKGKIT_FORMAT "%{[]family{font(%{family|downcase|delete( )})\n}}%{[]lang{font(:lang=%{lang|downcase|translate(_,-)})\n}}" + + +static void +message (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + fprintf (stderr, "Fontconfig: Pattern format error: "); + vfprintf (stderr, fmt, args); + fprintf (stderr, ".\n"); + va_end (args); +} + + +typedef struct _FcFormatContext +{ + const FcChar8 *format_orig; + const FcChar8 *format; + int format_len; + FcChar8 *word; + FcBool word_allocated; +} FcFormatContext; + +static FcBool +FcFormatContextInit (FcFormatContext *c, + const FcChar8 *format, + FcChar8 *scratch, + int scratch_len) +{ + c->format_orig = c->format = format; + c->format_len = strlen ((const char *) format); + + if (c->format_len < scratch_len) + { + c->word = scratch; + c->word_allocated = FcFalse; + } + else + { + c->word = malloc (c->format_len + 1); + c->word_allocated = FcTrue; + } + + return c->word != NULL; +} + +static void +FcFormatContextDone (FcFormatContext *c) +{ + if (c && c->word_allocated) + { + free (c->word); + } +} + +static FcBool +consume_char (FcFormatContext *c, + FcChar8 term) +{ + if (*c->format != term) + return FcFalse; + + c->format++; + return FcTrue; +} + +static FcBool +expect_char (FcFormatContext *c, + FcChar8 term) +{ + FcBool res = consume_char (c, term); + if (!res) + { + if (c->format == c->format_orig + c->format_len) + message ("format ended while expecting '%c'", + term); + else + message ("expected '%c' at %d", + term, c->format - c->format_orig + 1); + } + return res; +} + +static FcBool +FcCharIsPunct (const FcChar8 c) +{ + if (c < '0') + return FcTrue; + if (c <= '9') + return FcFalse; + if (c < 'A') + return FcTrue; + if (c <= 'Z') + return FcFalse; + if (c < 'a') + return FcTrue; + if (c <= 'z') + return FcFalse; + if (c <= '~') + return FcTrue; + return FcFalse; +} + +static char escaped_char(const char ch) +{ + switch (ch) { + case 'a': return '\a'; + case 'b': return '\b'; + case 'f': return '\f'; + case 'n': return '\n'; + case 'r': return '\r'; + case 't': return '\t'; + case 'v': return '\v'; + default: return ch; + } +} + +static FcBool +read_word (FcFormatContext *c) +{ + FcChar8 *p; + + p = c->word; + + while (*c->format) + { + if (*c->format == '\\') + { + c->format++; + if (*c->format) + *p++ = escaped_char (*c->format++); + continue; + } + else if (FcCharIsPunct (*c->format)) + break; + + *p++ = *c->format++; + } + *p = '\0'; + + if (p == c->word) + { + message ("expected identifier at %d", + c->format - c->format_orig + 1); + return FcFalse; + } + + return FcTrue; +} + +static FcBool +read_chars (FcFormatContext *c, + FcChar8 term) +{ + FcChar8 *p; + + p = c->word; + + while (*c->format && *c->format != '}' && *c->format != term) + { + if (*c->format == '\\') + { + c->format++; + if (*c->format) + *p++ = escaped_char (*c->format++); + continue; + } + + *p++ = *c->format++; + } + *p = '\0'; + + if (p == c->word) + { + message ("expected character data at %d", + c->format - c->format_orig + 1); + return FcFalse; + } + + return FcTrue; +} + +static FcBool +FcPatternFormatToBuf (FcPattern *pat, + const FcChar8 *format, + FcStrBuf *buf); + +static FcBool +interpret_builtin (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + FcChar8 *new_str; + FcBool ret; + + if (!expect_char (c, '=') || + !read_word (c)) + return FcFalse; + + /* try simple builtins first */ + if (0) { } +#define BUILTIN(name, func) \ + else if (0 == strcmp ((const char *) c->word, name))\ + do { new_str = func (pat); ret = FcTrue; } while (0) + BUILTIN ("unparse", FcNameUnparse); + /* BUILTIN ("verbose", FcPatternPrint); XXX */ +#undef BUILTIN + else + ret = FcFalse; + + if (ret) + { + if (new_str) + { + FcStrBufString (buf, new_str); + FcStrFree (new_str); + return FcTrue; + } + else + return FcFalse; + } + + /* now try our custom formats */ + if (0) { } +#define BUILTIN(name, format) \ + else if (0 == strcmp ((const char *) c->word, name))\ + ret = FcPatternFormatToBuf (pat, (const FcChar8 *) format, buf) + BUILTIN ("fccat", FCCAT_FORMAT); + BUILTIN ("fcmatch", FCMATCH_FORMAT); + BUILTIN ("fclist", FCLIST_FORMAT); + BUILTIN ("pkgkit", PKGKIT_FORMAT); +#undef BUILTIN + else + ret = FcFalse; + + if (!ret) + message ("unknown builtin \"%s\"", + c->word); + + return ret; +} + +static FcBool +interpret_expr (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf, + FcChar8 term); + +static FcBool +interpret_subexpr (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + return expect_char (c, '{') && + interpret_expr (c, pat, buf, '}') && + expect_char (c, '}'); +} + +static FcBool +maybe_interpret_subexpr (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + return (*c->format == '{') ? + interpret_subexpr (c, pat, buf) : + FcTrue; +} + +static FcBool +skip_subexpr (FcFormatContext *c); + +static FcBool +skip_percent (FcFormatContext *c) +{ + if (!expect_char (c, '%')) + return FcFalse; + + /* skip an optional width specifier */ + if (strtol ((const char *) c->format, (char **) &c->format, 10)) + {/* don't care */} + + if (!expect_char (c, '{')) + return FcFalse; + + while(*c->format && *c->format != '}') + { + switch (*c->format) + { + case '\\': + c->format++; /* skip over '\\' */ + if (*c->format) + c->format++; + continue; + case '{': + if (!skip_subexpr (c)) + return FcFalse; + continue; + } + c->format++; + } + + return expect_char (c, '}'); +} + +static FcBool +skip_expr (FcFormatContext *c) +{ + while(*c->format && *c->format != '}') + { + switch (*c->format) + { + case '\\': + c->format++; /* skip over '\\' */ + if (*c->format) + c->format++; + continue; + case '%': + if (!skip_percent (c)) + return FcFalse; + continue; + } + c->format++; + } + + return FcTrue; +} + +static FcBool +skip_subexpr (FcFormatContext *c) +{ + return expect_char (c, '{') && + skip_expr (c) && + expect_char (c, '}'); +} + +static FcBool +maybe_skip_subexpr (FcFormatContext *c) +{ + return (*c->format == '{') ? + skip_subexpr (c) : + FcTrue; +} + +static FcBool +interpret_filter_in (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + FcObjectSet *os; + FcPattern *subpat; + + if (!expect_char (c, '+')) + return FcFalse; + + os = FcObjectSetCreate (); + if (!os) + return FcFalse; + + do + { + /* XXX binding */ + if (!read_word (c) || + !FcObjectSetAdd (os, (const char *) c->word)) + { + FcObjectSetDestroy (os); + return FcFalse; + } + } + while (consume_char (c, ',')); + + subpat = FcPatternFilter (pat, os); + FcObjectSetDestroy (os); + + if (!subpat || + !interpret_subexpr (c, subpat, buf)) + return FcFalse; + + FcPatternDestroy (subpat); + return FcTrue; +} + +static FcBool +interpret_filter_out (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + FcPattern *subpat; + + if (!expect_char (c, '-')) + return FcFalse; + + subpat = FcPatternDuplicate (pat); + if (!subpat) + return FcFalse; + + do + { + if (!read_word (c)) + { + FcPatternDestroy (subpat); + return FcFalse; + } + + FcPatternDel (subpat, (const char *) c->word); + } + while (consume_char (c, ',')); + + if (!interpret_subexpr (c, subpat, buf)) + return FcFalse; + + FcPatternDestroy (subpat); + return FcTrue; +} + +static FcBool +interpret_cond (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + FcBool pass; + + if (!expect_char (c, '?')) + return FcFalse; + + pass = FcTrue; + + do + { + FcBool negate; + FcValue v; + + negate = consume_char (c, '!'); + + if (!read_word (c)) + return FcFalse; + + pass = pass && + (negate ^ + (FcResultMatch == + FcPatternGet (pat, (const char *) c->word, 0, &v))); + } + while (consume_char (c, ',')); + + if (pass) + { + if (!interpret_subexpr (c, pat, buf) || + !maybe_skip_subexpr (c)) + return FcFalse; + } + else + { + if (!skip_subexpr (c) || + !maybe_interpret_subexpr (c, pat, buf)) + return FcFalse; + } + + return FcTrue; +} + +static FcBool +interpret_count (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + int count; + FcPatternElt *e; + FcChar8 buf_static[64]; + + if (!expect_char (c, '#')) + return FcFalse; + + if (!read_word (c)) + return FcFalse; + + count = 0; + e = FcPatternObjectFindElt (pat, + FcObjectFromName ((const char *) c->word)); + if (e) + { + FcValueListPtr l; + count++; + for (l = FcPatternEltValues(e); + l->next; + l = l->next) + count++; + } + + snprintf ((char *) buf_static, sizeof (buf_static), "%d", count); + FcStrBufString (buf, buf_static); + + return FcTrue; +} + +static FcBool +interpret_enumerate (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + FcObjectSet *os; + FcPattern *subpat; + const FcChar8 *format_save; + int idx; + FcBool ret, done; + FcStrList *lang_strs; + + if (!expect_char (c, '[') || + !expect_char (c, ']')) + return FcFalse; + + os = FcObjectSetCreate (); + if (!os) + return FcFalse; + + ret = FcTrue; + + do + { + if (!read_word (c) || + !FcObjectSetAdd (os, (const char *) c->word)) + { + FcObjectSetDestroy (os); + return FcFalse; + } + } + while (consume_char (c, ',')); + + /* If we have one element and it's of type FcLangSet, we want + * to enumerate the languages in it. */ + lang_strs = NULL; + if (os->nobject == 1) + { + FcLangSet *langset; + if (FcResultMatch == + FcPatternGetLangSet (pat, os->objects[0], 0, &langset)) + { + FcStrSet *ss; + if (!(ss = FcLangSetGetLangs (langset)) || + !(lang_strs = FcStrListCreate (ss))) + goto bail0; + } + } + + subpat = FcPatternDuplicate (pat); + if (!subpat) + goto bail0; + + format_save = c->format; + idx = 0; + do + { + int i; + + done = FcTrue; + + if (lang_strs) + { + FcChar8 *lang; + + FcPatternDel (subpat, os->objects[0]); + if ((lang = FcStrListNext (lang_strs))) + { + /* XXX binding? */ + FcPatternAddString (subpat, os->objects[0], lang); + done = FcFalse; + } + } + else + { + for (i = 0; i < os->nobject; i++) + { + FcValue v; + + /* XXX this can be optimized by accessing valuelist linked lists + * directly and remembering where we were. Most (all) value lists + * in normal uses are pretty short though (language tags are + * stored as a LangSet, not separate values.). */ + FcPatternDel (subpat, os->objects[i]); + if (FcResultMatch == + FcPatternGet (pat, os->objects[i], idx, &v)) + { + /* XXX binding */ + FcPatternAdd (subpat, os->objects[i], v, FcFalse); + done = FcFalse; + } + } + } + + if (!done) + { + c->format = format_save; + ret = interpret_subexpr (c, subpat, buf); + if (!ret) + goto bail; + } + + idx++; + } while (!done); + + if (c->format == format_save) + skip_subexpr (c); + +bail: + FcPatternDestroy (subpat); +bail0: + if (lang_strs) + FcStrListDone (lang_strs); + FcObjectSetDestroy (os); + + return ret; +} + +static FcBool +interpret_simple (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + FcPatternElt *e; + FcBool add_colon = FcFalse; + FcBool add_elt_name = FcFalse; + int idx; + FcChar8 *else_string; + + if (consume_char (c, ':')) + add_colon = FcTrue; + + if (!read_word (c)) + return FcFalse; + + idx = -1; + if (consume_char (c, '[')) + { + idx = strtol ((const char *) c->format, (char **) &c->format, 10); + if (idx < 0) + { + message ("expected non-negative number at %d", + c->format-1 - c->format_orig + 1); + return FcFalse; + } + if (!expect_char (c, ']')) + return FcFalse; + } + + if (consume_char (c, '=')) + add_elt_name = FcTrue; + + /* modifiers */ + else_string = NULL; + if (consume_char (c, ':')) + { + FcChar8 *orig; + /* divert the c->word for now */ + orig = c->word; + c->word = c->word + strlen ((const char *) c->word) + 1; + /* for now we just support 'default value' */ + if (!expect_char (c, '-') || + !read_chars (c, '|')) + { + c->word = orig; + return FcFalse; + } + else_string = c->word; + c->word = orig; + } + + e = FcPatternObjectFindElt (pat, + FcObjectFromName ((const char *) c->word)); + if (e || else_string) + { + FcValueListPtr l = NULL; + + if (add_colon) + FcStrBufChar (buf, ':'); + if (add_elt_name) + { + FcStrBufString (buf, c->word); + FcStrBufChar (buf, '='); + } + + if (e) + l = FcPatternEltValues(e); + + if (idx != -1) + { + while (l && idx > 0) + { + l = FcValueListNext(l); + idx--; + } + if (l && idx == 0) + { + if (!FcNameUnparseValue (buf, &l->value, '\0')) + return FcFalse; + } + else goto notfound; + } + else if (l) + { + FcNameUnparseValueList (buf, l, '\0'); + } + else + { + notfound: + if (else_string) + FcStrBufString (buf, else_string); + } + } + + return FcTrue; +} + +static FcBool +cescape (FcFormatContext *c FC_UNUSED, + const FcChar8 *str, + FcStrBuf *buf) +{ + /* XXX escape \n etc? */ + + while(*str) + { + switch (*str) + { + case '\\': + case '"': + FcStrBufChar (buf, '\\'); + break; + } + FcStrBufChar (buf, *str++); + } + return FcTrue; +} + +static FcBool +shescape (FcFormatContext *c FC_UNUSED, + const FcChar8 *str, + FcStrBuf *buf) +{ + FcStrBufChar (buf, '\''); + while(*str) + { + if (*str == '\'') + FcStrBufString (buf, (const FcChar8 *) "'\\''"); + else + FcStrBufChar (buf, *str); + str++; + } + FcStrBufChar (buf, '\''); + return FcTrue; +} + +static FcBool +xmlescape (FcFormatContext *c FC_UNUSED, + const FcChar8 *str, + FcStrBuf *buf) +{ + /* XXX escape \n etc? */ + + while(*str) + { + switch (*str) + { + case '&': FcStrBufString (buf, (const FcChar8 *) "&"); break; + case '<': FcStrBufString (buf, (const FcChar8 *) "<"); break; + case '>': FcStrBufString (buf, (const FcChar8 *) ">"); break; + default: FcStrBufChar (buf, *str); break; + } + str++; + } + return FcTrue; +} + +static FcBool +delete_chars (FcFormatContext *c, + const FcChar8 *str, + FcStrBuf *buf) +{ + /* XXX not UTF-8 aware */ + + if (!expect_char (c, '(') || + !read_chars (c, ')') || + !expect_char (c, ')')) + return FcFalse; + + while(*str) + { + FcChar8 *p; + + p = (FcChar8 *) strpbrk ((const char *) str, (const char *) c->word); + if (p) + { + FcStrBufData (buf, str, p - str); + str = p + 1; + } + else + { + FcStrBufString (buf, str); + break; + } + + } + + return FcTrue; +} + +static FcBool +escape_chars (FcFormatContext *c, + const FcChar8 *str, + FcStrBuf *buf) +{ + /* XXX not UTF-8 aware */ + + if (!expect_char (c, '(') || + !read_chars (c, ')') || + !expect_char (c, ')')) + return FcFalse; + + while(*str) + { + FcChar8 *p; + + p = (FcChar8 *) strpbrk ((const char *) str, (const char *) c->word); + if (p) + { + FcStrBufData (buf, str, p - str); + FcStrBufChar (buf, c->word[0]); + FcStrBufChar (buf, *p); + str = p + 1; + } + else + { + FcStrBufString (buf, str); + break; + } + + } + + return FcTrue; +} + +static FcBool +translate_chars (FcFormatContext *c, + const FcChar8 *str, + FcStrBuf *buf) +{ + char *from, *to, repeat; + int from_len, to_len; + + /* XXX not UTF-8 aware */ + + if (!expect_char (c, '(') || + !read_chars (c, ',') || + !expect_char (c, ',')) + return FcFalse; + + from = (char *) c->word; + from_len = strlen (from); + to = from + from_len + 1; + + /* hack: we temporarily divert c->word */ + c->word = (FcChar8 *) to; + if (!read_chars (c, ')')) + { + c->word = (FcChar8 *) from; + return FcFalse; + } + c->word = (FcChar8 *) from; + + to_len = strlen (to); + repeat = to[to_len - 1]; + + if (!expect_char (c, ')')) + return FcFalse; + + while(*str) + { + FcChar8 *p; + + p = (FcChar8 *) strpbrk ((const char *) str, (const char *) from); + if (p) + { + int i; + FcStrBufData (buf, str, p - str); + i = strchr (from, *p) - from; + FcStrBufChar (buf, i < to_len ? to[i] : repeat); + str = p + 1; + } + else + { + FcStrBufString (buf, str); + break; + } + + } + + return FcTrue; +} + +static FcBool +interpret_convert (FcFormatContext *c, + FcStrBuf *buf, + int start) +{ + const FcChar8 *str; + FcChar8 *new_str; + FcStrBuf new_buf; + FcChar8 buf_static[8192]; + FcBool ret; + + if (!expect_char (c, '|') || + !read_word (c)) + return FcFalse; + + /* prepare the buffer */ + FcStrBufChar (buf, '\0'); + if (buf->failed) + return FcFalse; + str = buf->buf + start; + buf->len = start; + + /* try simple converters first */ + if (0) { } +#define CONVERTER(name, func) \ + else if (0 == strcmp ((const char *) c->word, name))\ + do { new_str = func (str); ret = FcTrue; } while (0) + CONVERTER ("downcase", FcStrDowncase); + CONVERTER ("basename", FcStrBasename); + CONVERTER ("dirname", FcStrDirname); +#undef CONVERTER + else + ret = FcFalse; + + if (ret) + { + if (new_str) + { + FcStrBufString (buf, new_str); + FcStrFree (new_str); + return FcTrue; + } + else + return FcFalse; + } + + FcStrBufInit (&new_buf, buf_static, sizeof (buf_static)); + + /* now try our custom converters */ + if (0) { } +#define CONVERTER(name, func) \ + else if (0 == strcmp ((const char *) c->word, name))\ + ret = func (c, str, &new_buf) + CONVERTER ("cescape", cescape); + CONVERTER ("shescape", shescape); + CONVERTER ("xmlescape", xmlescape); + CONVERTER ("delete", delete_chars); + CONVERTER ("escape", escape_chars); + CONVERTER ("translate", translate_chars); +#undef CONVERTER + else + ret = FcFalse; + + if (ret) + { + FcStrBufChar (&new_buf, '\0'); + FcStrBufString (buf, new_buf.buf); + } + else + message ("unknown converter \"%s\"", + c->word); + + FcStrBufDestroy (&new_buf); + + return ret; +} + +static FcBool +maybe_interpret_converts (FcFormatContext *c, + FcStrBuf *buf, + int start) +{ + while (*c->format == '|') + if (!interpret_convert (c, buf, start)) + return FcFalse; + + return FcTrue; +} + +static FcBool +align_to_width (FcStrBuf *buf, + int start, + int width) +{ + int len; + + if (buf->failed) + return FcFalse; + + len = buf->len - start; + if (len < -width) + { + /* left align */ + while (len++ < -width) + FcStrBufChar (buf, ' '); + } + else if (len < width) + { + int old_len; + old_len = len; + /* right align */ + while (len++ < width) + FcStrBufChar (buf, ' '); + if (buf->failed) + return FcFalse; + len = old_len; + memmove (buf->buf + buf->len - len, + buf->buf + buf->len - width, + len); + memset (buf->buf + buf->len - width, + ' ', + width - len); + } + + return !buf->failed; +} +static FcBool +interpret_percent (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + int width, start; + FcBool ret; + + if (!expect_char (c, '%')) + return FcFalse; + + if (consume_char (c, '%')) /* "%%" */ + { + FcStrBufChar (buf, '%'); + return FcTrue; + } + + /* parse an optional width specifier */ + width = strtol ((const char *) c->format, (char **) &c->format, 10); + + if (!expect_char (c, '{')) + return FcFalse; + + start = buf->len; + + switch (*c->format) { + case '=': ret = interpret_builtin (c, pat, buf); break; + case '{': ret = interpret_subexpr (c, pat, buf); break; + case '+': ret = interpret_filter_in (c, pat, buf); break; + case '-': ret = interpret_filter_out (c, pat, buf); break; + case '?': ret = interpret_cond (c, pat, buf); break; + case '#': ret = interpret_count (c, pat, buf); break; + case '[': ret = interpret_enumerate (c, pat, buf); break; + default: ret = interpret_simple (c, pat, buf); break; + } + + return ret && + maybe_interpret_converts (c, buf, start) && + align_to_width (buf, start, width) && + expect_char (c, '}'); +} + +static FcBool +interpret_expr (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf, + FcChar8 term) +{ + while (*c->format && *c->format != term) + { + switch (*c->format) + { + case '\\': + c->format++; /* skip over '\\' */ + if (*c->format) + FcStrBufChar (buf, escaped_char (*c->format++)); + continue; + case '%': + if (!interpret_percent (c, pat, buf)) + return FcFalse; + continue; + } + FcStrBufChar (buf, *c->format++); + } + return FcTrue; +} + +static FcBool +FcPatternFormatToBuf (FcPattern *pat, + const FcChar8 *format, + FcStrBuf *buf) +{ + FcFormatContext c; + FcChar8 word_static[1024]; + FcBool ret; + + if (!FcFormatContextInit (&c, format, word_static, sizeof (word_static))) + return FcFalse; + + ret = interpret_expr (&c, pat, buf, '\0'); + + FcFormatContextDone (&c); + + return ret; +} + +FcChar8 * +FcPatternFormat (FcPattern *pat, + const FcChar8 *format) +{ + FcStrBuf buf; + FcChar8 buf_static[8192 - 1024]; + FcPattern *alloced = NULL; + FcBool ret; + + if (!pat) + alloced = pat = FcPatternCreate (); + + FcStrBufInit (&buf, buf_static, sizeof (buf_static)); + + ret = FcPatternFormatToBuf (pat, format, &buf); + + if (alloced) + FcPatternDestroy (alloced); + + if (ret) + return FcStrBufDone (&buf); + else + { + FcStrBufDestroy (&buf); + return NULL; + } +} + +#define __fcformat__ +#include "fcaliastail.h" +#undef __fcformat__ diff --git a/project/jni/fontconfig/src/fcfreetype.c b/project/jni/fontconfig/src/fcfreetype.c new file mode 100644 index 000000000..8ab3617aa --- /dev/null +++ b/project/jni/fontconfig/src/fcfreetype.c @@ -0,0 +1,2822 @@ +/* + * fontconfig/src/fcfreetype.c + * + * Copyright © 2001 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + Copyright © 2002-2003 by Juliusz Chroboczek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "fcint.h" +#include "fcftint.h" +#include +#include +#include +#include +#include FT_FREETYPE_H +#include FT_TRUETYPE_TABLES_H +#include FT_SFNT_NAMES_H +#include FT_TRUETYPE_IDS_H +#include FT_TYPE1_TABLES_H +#if HAVE_FT_GET_X11_FONT_FORMAT +#include FT_XFREE86_H +#endif +#if HAVE_FT_GET_BDF_PROPERTY +#include FT_BDF_H +#include FT_MODULE_H +#endif + +#include "ftglue.h" + +#if HAVE_WARNING_CPP_DIRECTIVE +#if !HAVE_FT_GET_BDF_PROPERTY +#warning "No FT_Get_BDF_Property: Please install freetype 2.1.4 or later" +#endif + +#if !HAVE_FT_GET_PS_FONT_INFO +#warning "No FT_Get_PS_Font_Info: Please install freetype 2.1.1 or later" +#endif +#endif + +/* + * Keep Han languages separated by eliminating languages + * that the codePageRange bits says aren't supported + */ + +static const struct { + char bit; + const FcChar8 lang[6]; +} FcCodePageRange[] = { + { 17, "ja" }, + { 18, "zh-cn" }, + { 19, "ko" }, + { 20, "zh-tw" }, +}; + +#define NUM_CODE_PAGE_RANGE (int) (sizeof FcCodePageRange / sizeof FcCodePageRange[0]) + +FcBool +FcFreeTypeIsExclusiveLang (const FcChar8 *lang) +{ + int i; + + for (i = 0; i < NUM_CODE_PAGE_RANGE; i++) + { + if (FcLangCompare (lang, FcCodePageRange[i].lang) == FcLangEqual) + return FcTrue; + } + return FcFalse; +} + +typedef struct { + const FT_UShort platform_id; + const FT_UShort encoding_id; + const char fromcode[12]; +} FcFtEncoding; + +#define TT_ENCODING_DONT_CARE 0xffff +#define FC_ENCODING_MAC_ROMAN "MACINTOSH" + +static const FcFtEncoding fcFtEncoding[] = { + { TT_PLATFORM_APPLE_UNICODE, TT_ENCODING_DONT_CARE, "UTF-16BE" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, "MACINTOSH" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_ID_JAPANESE, "SJIS" }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, "UTF-16BE" }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, "UTF-16BE" }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_SJIS, "SJIS-WIN" }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_GB2312, "GB2312" }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_BIG_5, "BIG-5" }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_WANSUNG, "Wansung" }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_JOHAB, "Johab" }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_UCS_4, "UTF-16BE" }, + { TT_PLATFORM_ISO, TT_ISO_ID_7BIT_ASCII, "ASCII" }, + { TT_PLATFORM_ISO, TT_ISO_ID_10646, "UTF-16BE" }, + { TT_PLATFORM_ISO, TT_ISO_ID_8859_1, "ISO-8859-1" }, +}; + +#define NUM_FC_FT_ENCODING (int) (sizeof (fcFtEncoding) / sizeof (fcFtEncoding[0])) + +typedef struct { + const FT_UShort platform_id; + const FT_UShort language_id; + const char lang[8]; +} FcFtLanguage; + +#define TT_LANGUAGE_DONT_CARE 0xffff + +static const FcFtLanguage fcFtLanguage[] = { + { TT_PLATFORM_APPLE_UNICODE, TT_LANGUAGE_DONT_CARE, "" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ENGLISH, "en" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_FRENCH, "fr" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GERMAN, "de" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ITALIAN, "it" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_DUTCH, "nl" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SWEDISH, "sv" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SPANISH, "es" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_DANISH, "da" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_PORTUGUESE, "pt" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_NORWEGIAN, "no" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_HEBREW, "he" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_JAPANESE, "ja" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ARABIC, "ar" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_FINNISH, "fi" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GREEK, "el" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ICELANDIC, "is" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MALTESE, "mt" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TURKISH, "tr" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_CROATIAN, "hr" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_CHINESE_TRADITIONAL, "zh-tw" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_URDU, "ur" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_HINDI, "hi" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_THAI, "th" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_KOREAN, "ko" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_LITHUANIAN, "lt" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_POLISH, "pl" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_HUNGARIAN, "hu" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ESTONIAN, "et" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_LETTISH, "lv" }, +/* { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SAAMISK, ??? */ + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_FAEROESE, "fo" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_FARSI, "fa" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_RUSSIAN, "ru" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_CHINESE_SIMPLIFIED, "zh-cn" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_FLEMISH, "nl" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_IRISH, "ga" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ALBANIAN, "sq" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ROMANIAN, "ro" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_CZECH, "cs" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SLOVAK, "sk" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SLOVENIAN, "sl" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_YIDDISH, "yi" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SERBIAN, "sr" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MACEDONIAN, "mk" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_BULGARIAN, "bg" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_UKRAINIAN, "uk" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_BYELORUSSIAN, "be" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_UZBEK, "uz" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_KAZAKH, "kk" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_AZERBAIJANI, "az" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_AZERBAIJANI_CYRILLIC_SCRIPT, "az" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_AZERBAIJANI_ARABIC_SCRIPT, "ar" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ARMENIAN, "hy" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GEORGIAN, "ka" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MOLDAVIAN, "mo" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_KIRGHIZ, "ky" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TAJIKI, "tg" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TURKMEN, "tk" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MONGOLIAN, "mo" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MONGOLIAN_MONGOLIAN_SCRIPT,"mo" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MONGOLIAN_CYRILLIC_SCRIPT, "mo" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_PASHTO, "ps" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_KURDISH, "ku" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_KASHMIRI, "ks" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SINDHI, "sd" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TIBETAN, "bo" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_NEPALI, "ne" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SANSKRIT, "sa" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MARATHI, "mr" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_BENGALI, "bn" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ASSAMESE, "as" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GUJARATI, "gu" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_PUNJABI, "pa" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ORIYA, "or" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MALAYALAM, "ml" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_KANNADA, "kn" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TAMIL, "ta" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TELUGU, "te" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SINHALESE, "si" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_BURMESE, "my" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_KHMER, "km" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_LAO, "lo" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_VIETNAMESE, "vi" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_INDONESIAN, "id" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TAGALOG, "tl" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MALAY_ROMAN_SCRIPT, "ms" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MALAY_ARABIC_SCRIPT, "ms" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_AMHARIC, "am" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TIGRINYA, "ti" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GALLA, "om" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SOMALI, "so" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SWAHILI, "sw" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_RUANDA, "rw" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_RUNDI, "rn" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_CHEWA, "ny" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MALAGASY, "mg" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ESPERANTO, "eo" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_WELSH, "cy" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_BASQUE, "eu" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_CATALAN, "ca" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_LATIN, "la" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_QUECHUA, "qu" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GUARANI, "gn" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_AYMARA, "ay" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TATAR, "tt" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_UIGHUR, "ug" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_DZONGKHA, "dz" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_JAVANESE, "jw" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SUNDANESE, "su" }, + +#if 0 /* these seem to be errors that have been dropped */ + + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SCOTTISH_GAELIC }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_IRISH_GAELIC }, + +#endif + + /* The following codes are new as of 2000-03-10 */ + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GALICIAN, "gl" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_AFRIKAANS, "af" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_BRETON, "br" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_INUKTITUT, "iu" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_SCOTTISH_GAELIC, "gd" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_MANX_GAELIC, "gv" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_IRISH_GAELIC, "ga" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_TONGAN, "to" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GREEK_POLYTONIC, "el" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GREELANDIC, "ik" }, + { TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_AZERBAIJANI_ROMAN_SCRIPT,"az" }, + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_SAUDI_ARABIA, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_IRAQ, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_EGYPT, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_LIBYA, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_ALGERIA, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_MOROCCO, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_TUNISIA, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_OMAN, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_YEMEN, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_SYRIA, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_JORDAN, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_LEBANON, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_KUWAIT, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_UAE, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_BAHRAIN, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_QATAR, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_BULGARIAN_BULGARIA, "bg" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CATALAN_SPAIN, "ca" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CHINESE_TAIWAN, "zh-tw" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CHINESE_PRC, "zh-cn" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CHINESE_HONG_KONG, "zh-hk" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CHINESE_SINGAPORE, "zh-sg" }, + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CHINESE_MACAU, "zh-mo" }, + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CZECH_CZECH_REPUBLIC, "cs" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_DANISH_DENMARK, "da" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GERMAN_GERMANY, "de" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GERMAN_SWITZERLAND, "de" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GERMAN_AUSTRIA, "de" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GERMAN_LUXEMBOURG, "de" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GERMAN_LIECHTENSTEI, "de" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GREEK_GREECE, "el" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_UNITED_STATES, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_UNITED_KINGDOM, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_AUSTRALIA, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_CANADA, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_NEW_ZEALAND, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_IRELAND, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_SOUTH_AFRICA, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_JAMAICA, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_CARIBBEAN, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_BELIZE, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_TRINIDAD, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_ZIMBABWE, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_PHILIPPINES, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_SPAIN_TRADITIONAL_SORT,"es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_MEXICO, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_SPAIN_INTERNATIONAL_SORT,"es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_GUATEMALA, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_COSTA_RICA, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_PANAMA, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_DOMINICAN_REPUBLIC,"es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_VENEZUELA, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_COLOMBIA, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_PERU, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_ARGENTINA, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_ECUADOR, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_CHILE, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_URUGUAY, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_PARAGUAY, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_BOLIVIA, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_EL_SALVADOR, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_HONDURAS, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_NICARAGUA, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_PUERTO_RICO, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FINNISH_FINLAND, "fi" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_FRANCE, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_BELGIUM, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_CANADA, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_SWITZERLAND, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_LUXEMBOURG, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_MONACO, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_HEBREW_ISRAEL, "he" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_HUNGARIAN_HUNGARY, "hu" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ICELANDIC_ICELAND, "is" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ITALIAN_ITALY, "it" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ITALIAN_SWITZERLAND, "it" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_JAPANESE_JAPAN, "ja" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA,"ko" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KOREAN_JOHAB_KOREA, "ko" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_DUTCH_NETHERLANDS, "nl" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_DUTCH_BELGIUM, "nl" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_NORWEGIAN_NORWAY_BOKMAL, "no" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_NORWEGIAN_NORWAY_NYNORSK, "nn" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_POLISH_POLAND, "pl" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_PORTUGUESE_BRAZIL, "pt" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_PORTUGUESE_PORTUGAL, "pt" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_RHAETO_ROMANIC_SWITZERLAND,"rm" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ROMANIAN_ROMANIA, "ro" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MOLDAVIAN_MOLDAVIA, "mo" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_RUSSIAN_RUSSIA, "ru" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_RUSSIAN_MOLDAVIA, "ru" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CROATIAN_CROATIA, "hr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SERBIAN_SERBIA_LATIN, "sr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SERBIAN_SERBIA_CYRILLIC, "sr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SLOVAK_SLOVAKIA, "sk" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ALBANIAN_ALBANIA, "sq" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SWEDISH_SWEDEN, "sv" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SWEDISH_FINLAND, "sv" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_THAI_THAILAND, "th" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TURKISH_TURKEY, "tr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_URDU_PAKISTAN, "ur" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_INDONESIAN_INDONESIA, "id" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_UKRAINIAN_UKRAINE, "uk" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_BELARUSIAN_BELARUS, "be" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SLOVENE_SLOVENIA, "sl" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ESTONIAN_ESTONIA, "et" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_LATVIAN_LATVIA, "lv" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_LITHUANIAN_LITHUANIA, "lt" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CLASSIC_LITHUANIAN_LITHUANIA,"lt" }, + +#ifdef TT_MS_LANGID_MAORI_NEW_ZELAND + /* this seems to be an error that have been dropped */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MAORI_NEW_ZEALAND, "mi" }, +#endif + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FARSI_IRAN, "fa" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_VIETNAMESE_VIET_NAM, "vi" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARMENIAN_ARMENIA, "hy" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_AZERI_AZERBAIJAN_LATIN, "az" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_AZERI_AZERBAIJAN_CYRILLIC, "az" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_BASQUE_SPAIN, "eu" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SORBIAN_GERMANY, "wen" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MACEDONIAN_MACEDONIA, "mk" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SUTU_SOUTH_AFRICA, "st" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TSONGA_SOUTH_AFRICA, "ts" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TSWANA_SOUTH_AFRICA, "tn" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_VENDA_SOUTH_AFRICA, "ven" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_XHOSA_SOUTH_AFRICA, "xh" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ZULU_SOUTH_AFRICA, "zu" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_AFRIKAANS_SOUTH_AFRICA, "af" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GEORGIAN_GEORGIA, "ka" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FAEROESE_FAEROE_ISLANDS, "fo" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_HINDI_INDIA, "hi" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MALTESE_MALTA, "mt" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SAAMI_LAPONIA, "se" }, + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM,"gd" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_IRISH_GAELIC_IRELAND, "ga" }, + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MALAY_MALAYSIA, "ms" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MALAY_BRUNEI_DARUSSALAM, "ms" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KAZAK_KAZAKSTAN, "kk" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SWAHILI_KENYA, "sw" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_UZBEK_UZBEKISTAN_LATIN, "uz" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_UZBEK_UZBEKISTAN_CYRILLIC, "uz" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TATAR_TATARSTAN, "tt" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_BENGALI_INDIA, "bn" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_PUNJABI_INDIA, "pa" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GUJARATI_INDIA, "gu" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ORIYA_INDIA, "or" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TAMIL_INDIA, "ta" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TELUGU_INDIA, "te" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KANNADA_INDIA, "kn" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MALAYALAM_INDIA, "ml" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ASSAMESE_INDIA, "as" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MARATHI_INDIA, "mr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SANSKRIT_INDIA, "sa" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KONKANI_INDIA, "kok" }, + + /* new as of 2001-01-01 */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ARABIC_GENERAL, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CHINESE_GENERAL, "zh" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_GENERAL, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_WEST_INDIES, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_REUNION, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_CONGO, "fr" }, + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_SENEGAL, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_CAMEROON, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_COTE_D_IVOIRE, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_MALI, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_BOSNIAN_BOSNIA_HERZEGOVINA,"bs" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_URDU_INDIA, "ur" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TAJIK_TAJIKISTAN, "tg" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_YIDDISH_GERMANY, "yi" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KIRGHIZ_KIRGHIZSTAN, "ky" }, + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TURKMEN_TURKMENISTAN, "tk" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MONGOLIAN_MONGOLIA, "mn" }, + + /* the following seems to be inconsistent; + here is the current "official" way: */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TIBETAN_BHUTAN, "bo" }, + /* and here is what is used by Passport SDK */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TIBETAN_CHINA, "bo" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_DZONGHKA_BHUTAN, "dz" }, + /* end of inconsistency */ + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_WELSH_WALES, "cy" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KHMER_CAMBODIA, "km" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_LAO_LAOS, "lo" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_BURMESE_MYANMAR, "my" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GALICIAN_SPAIN, "gl" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MANIPURI_INDIA, "mni" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SINDHI_INDIA, "sd" }, + /* the following one is only encountered in Microsoft RTF specification */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KASHMIRI_PAKISTAN, "ks" }, + /* the following one is not in the Passport list, looks like an omission */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KASHMIRI_INDIA, "ks" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_NEPALI_NEPAL, "ne" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_NEPALI_INDIA, "ne" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRISIAN_NETHERLANDS, "fy" }, + + /* new as of 2001-03-01 (from Office Xp) */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_HONG_KONG, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_INDIA, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_MALAYSIA, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_ENGLISH_SINGAPORE, "en" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SYRIAC_SYRIA, "syr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SINHALESE_SRI_LANKA, "si" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_CHEROKEE_UNITED_STATES, "chr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_INUKTITUT_CANADA, "iu" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_AMHARIC_ETHIOPIA, "am" }, +#if 0 + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TAMAZIGHT_MOROCCO }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TAMAZIGHT_MOROCCO_LATIN }, +#endif + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_PASHTO_AFGHANISTAN, "ps" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FILIPINO_PHILIPPINES, "phi" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_DHIVEHI_MALDIVES, "div" }, + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_OROMO_ETHIOPIA, "om" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TIGRIGNA_ETHIOPIA, "ti" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_TIGRIGNA_ERYTHREA, "ti" }, + + /* New additions from Windows Xp/Passport SDK 2001-11-10. */ + + /* don't ask what this one means... It is commented out currently. */ +#if 0 + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GREEK_GREECE2 }, +#endif + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_UNITED_STATES, "es" }, + /* The following two IDs blatantly violate MS specs by using a */ + /* sublanguage >,. */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SPANISH_LATIN_AMERICA, "es" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_NORTH_AFRICA, "fr" }, + + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_MOROCCO, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FRENCH_HAITI, "fr" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_BENGALI_BANGLADESH, "bn" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_PUNJABI_ARABIC_PAKISTAN, "ar" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_MONGOLIAN_MONGOLIA_MONGOLIAN,"mn" }, +#if 0 + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_EDO_NIGERIA }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_FULFULDE_NIGERIA }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_IBIBIO_NIGERIA }, +#endif + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_HAUSA_NIGERIA, "ha" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_YORUBA_NIGERIA, "yo" }, + /* language codes from, to, are (still) unknown. */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_IGBO_NIGERIA, "ibo" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_KANURI_NIGERIA, "kau" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_GUARANI_PARAGUAY, "gn" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_HAWAIIAN_UNITED_STATES, "haw" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_LATIN, "la" }, + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_SOMALI_SOMALIA, "so" }, +#if 0 + /* Note: Yi does not have a (proper) ISO 639-2 code, since it is mostly */ + /* not written (but OTOH the peculiar writing system is worth */ + /* studying). */ + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_YI_CHINA }, +#endif + { TT_PLATFORM_MICROSOFT, TT_MS_LANGID_PAPIAMENTU_NETHERLANDS_ANTILLES,"pap" }, +}; + +#define NUM_FC_FT_LANGUAGE (int) (sizeof (fcFtLanguage) / sizeof (fcFtLanguage[0])) + +typedef struct { + FT_UShort language_id; + char fromcode[12]; +} FcMacRomanFake; + +static const FcMacRomanFake fcMacRomanFake[] = { + { TT_MS_LANGID_JAPANESE_JAPAN, "SJIS-WIN" }, + { TT_MS_LANGID_ENGLISH_UNITED_STATES, "ASCII" }, +}; + +static FcChar8 * +FcFontCapabilities(FT_Face face); + +#define NUM_FC_MAC_ROMAN_FAKE (int) (sizeof (fcMacRomanFake) / sizeof (fcMacRomanFake[0])) + +#if USE_ICONV +#include +#endif + +/* + * A shift-JIS will have many high bits turned on + */ +static FcBool +FcLooksLikeSJIS (FcChar8 *string, int len) +{ + int nhigh = 0, nlow = 0; + + while (len-- > 0) + { + if (*string++ & 0x80) nhigh++; + else nlow++; + } + /* + * Heuristic -- if more than 1/3 of the bytes have the high-bit set, + * this is likely to be SJIS and not ROMAN + */ + if (nhigh * 2 > nlow) + return FcTrue; + return FcFalse; +} + +static FcChar8 * +FcSfntNameTranscode (FT_SfntName *sname) +{ + int i; + const char *fromcode; +#if USE_ICONV + iconv_t cd; +#endif + FcChar8 *utf8; + + for (i = 0; i < NUM_FC_FT_ENCODING; i++) + if (fcFtEncoding[i].platform_id == sname->platform_id && + (fcFtEncoding[i].encoding_id == TT_ENCODING_DONT_CARE || + fcFtEncoding[i].encoding_id == sname->encoding_id)) + break; + if (i == NUM_FC_FT_ENCODING) + return 0; + fromcode = fcFtEncoding[i].fromcode; + + /* + * Many names encoded for TT_PLATFORM_MACINTOSH are broken + * in various ways. Kludge around them. + */ + if (!strcmp (fromcode, FC_ENCODING_MAC_ROMAN)) + { + if (sname->language_id == TT_MAC_LANGID_ENGLISH && + FcLooksLikeSJIS (sname->string, sname->string_len)) + { + fromcode = "SJIS"; + } + else if (sname->language_id >= 0x100) + { + /* + * "real" Mac language IDs are all less than 150. + * Names using one of the MS language IDs are assumed + * to use an associated encoding (Yes, this is a kludge) + */ + int f; + + fromcode = NULL; + for (f = 0; f < NUM_FC_MAC_ROMAN_FAKE; f++) + if (fcMacRomanFake[f].language_id == sname->language_id) + { + fromcode = fcMacRomanFake[f].fromcode; + break; + } + if (!fromcode) + return 0; + } + } + if (!strcmp (fromcode, "UCS-2BE") || !strcmp (fromcode, "UTF-16BE")) + { + FcChar8 *src = sname->string; + int src_len = sname->string_len; + int len; + int wchar; + int ilen, olen; + FcChar8 *u8; + FcChar32 ucs4; + + /* + * Convert Utf16 to Utf8 + */ + + if (!FcUtf16Len (src, FcEndianBig, src_len, &len, &wchar)) + return 0; + + /* + * Allocate plenty of space. Freed below + */ + utf8 = malloc (len * FC_UTF8_MAX_LEN + 1); + if (!utf8) + return 0; + + u8 = utf8; + + while ((ilen = FcUtf16ToUcs4 (src, FcEndianBig, &ucs4, src_len)) > 0) + { + src_len -= ilen; + src += ilen; + olen = FcUcs4ToUtf8 (ucs4, u8); + u8 += olen; + } + *u8 = '\0'; + goto done; + } + if (!strcmp (fromcode, "ASCII") || !strcmp (fromcode, "ISO-8859-1")) + { + FcChar8 *src = sname->string; + int src_len = sname->string_len; + int olen; + FcChar8 *u8; + FcChar32 ucs4; + + /* + * Convert Latin1 to Utf8. Freed below + */ + utf8 = malloc (src_len * 2 + 1); + if (!utf8) + return 0; + + u8 = utf8; + while (src_len > 0) + { + ucs4 = *src++; + src_len--; + olen = FcUcs4ToUtf8 (ucs4, u8); + u8 += olen; + } + *u8 = '\0'; + goto done; + } +#if USE_ICONV + cd = iconv_open ("UTF-8", fromcode); + if (cd && cd != (iconv_t) (-1)) + { + size_t in_bytes_left = sname->string_len; + size_t out_bytes_left = sname->string_len * FC_UTF8_MAX_LEN; + char *inbuf, *outbuf; + + utf8 = malloc (out_bytes_left + 1); + if (!utf8) + { + iconv_close (cd); + return 0; + } + + outbuf = (char *) utf8; + inbuf = (char *) sname->string; + + while (in_bytes_left) + { + size_t did = iconv (cd, + &inbuf, &in_bytes_left, + &outbuf, &out_bytes_left); + if (did == (size_t) (-1)) + { + iconv_close (cd); + free (utf8); + return 0; + } + } + iconv_close (cd); + *outbuf = '\0'; + goto done; + } +#endif + return 0; +done: + if (FcStrCmpIgnoreBlanksAndCase (utf8, (FcChar8 *) "") == 0) + { + free (utf8); + return 0; + } + return utf8; +} + +static const FcChar8 * +FcSfntNameLanguage (FT_SfntName *sname) +{ + int i; + FT_UShort platform_id = sname->platform_id; + FT_UShort language_id = sname->language_id; + + /* + * Many names encoded for TT_PLATFORM_MACINTOSH are broken + * in various ways. Kludge around them. + */ + if (platform_id == TT_PLATFORM_MACINTOSH && + sname->encoding_id == TT_MAC_ID_ROMAN && + FcLooksLikeSJIS (sname->string, sname->string_len)) + { + language_id = TT_MAC_LANGID_JAPANESE; + } + + for (i = 0; i < NUM_FC_FT_LANGUAGE; i++) + if (fcFtLanguage[i].platform_id == platform_id && + (fcFtLanguage[i].language_id == TT_LANGUAGE_DONT_CARE || + fcFtLanguage[i].language_id == language_id)) + { + if (fcFtLanguage[i].lang[0] == '\0') + return NULL; + else + return (FcChar8 *) fcFtLanguage[i].lang; + } + return 0; +} + +/* Order is significant. For example, some B&H fonts are hinted by + URW++, and both strings appear in the notice. */ + +static const char *FcNoticeFoundries[][2] = + { + {"Adobe", "adobe"}, + {"Bigelow", "b&h"}, + {"Bitstream", "bitstream"}, + {"Gnat", "culmus"}, + {"Iorsh", "culmus"}, + {"HanYang System", "hanyang"}, + {"Font21", "hwan"}, + {"IBM", "ibm"}, + {"International Typeface Corporation", "itc"}, + {"Linotype", "linotype"}, + {"LINOTYPE-HELL", "linotype"}, + {"Microsoft", "microsoft"}, + {"Monotype", "monotype"}, + {"Omega", "omega"}, + {"Tiro Typeworks", "tiro"}, + {"URW", "urw"}, + {"XFree86", "xfree86"}, + {"Xorg", "xorg"}, +}; + +#define NUM_NOTICE_FOUNDRIES (int) (sizeof (FcNoticeFoundries) / sizeof (FcNoticeFoundries[0])) + +static const FcChar8 * +FcNoticeFoundry(const FT_String *notice) +{ + int i; + + if (notice) + for(i = 0; i < NUM_NOTICE_FOUNDRIES; i++) + { + const char *n = FcNoticeFoundries[i][0]; + const char *f = FcNoticeFoundries[i][1]; + + if (strstr ((const char *) notice, n)) + return (const FcChar8 *) f; + } + return 0; +} + +static FcBool +FcVendorMatch(const FT_Char vendor[4], const FT_Char *vendor_string) +{ + /* vendor is not necessarily NUL-terminated. */ + int i, len; + + len = strlen((char *) vendor_string); + if (memcmp(vendor, vendor_string, len) != 0) + return FcFalse; + for (i = len; i < 4; i++) + if (vendor[i] != ' ' && vendor[i] != '\0') + return FcFalse; + return FcTrue; +} + +/* This table is partly taken from ttmkfdir by Joerg Pommnitz. */ + +/* It should not contain useless entries (such as UNKN) nor duplicate + entries for padding both with spaces and NULs. */ + +static const struct { + const FT_Char vendor[5]; + const FcChar8 foundry[13]; +} FcVendorFoundries[] = { + { "ADBE", "adobe"}, + { "AGFA", "agfa"}, + { "ALTS", "altsys"}, + { "APPL", "apple"}, + { "ARPH", "arphic"}, + { "ATEC", "alltype"}, + { "B&H", "b&h"}, + { "BITS", "bitstream"}, + { "CANO", "cannon"}, + { "CLM", "culmus"}, + { "DYNA", "dynalab"}, + { "EPSN", "epson"}, + { "FJ", "fujitsu"}, + { "IBM", "ibm"}, + { "ITC", "itc"}, + { "IMPR", "impress"}, + { "LARA", "larabiefonts"}, + { "LEAF", "interleaf"}, + { "LETR", "letraset"}, + { "LINO", "linotype"}, + { "MACR", "macromedia"}, + { "MONO", "monotype"}, + { "MS", "microsoft"}, + { "MT", "monotype"}, + { "NEC", "nec"}, + { "PARA", "paratype"}, + { "QMSI", "qms"}, + { "RICO", "ricoh"}, + { "URW", "urw"}, + { "Y&Y", "y&y"} +}; + +#define NUM_VENDOR_FOUNDRIES (int) (sizeof (FcVendorFoundries) / sizeof (FcVendorFoundries[0])) + +static const FcChar8 * +FcVendorFoundry(const FT_Char vendor[4]) +{ + int i; + + if (vendor) + for(i = 0; i < NUM_VENDOR_FOUNDRIES; i++) + if (FcVendorMatch (vendor, FcVendorFoundries[i].vendor)) + return FcVendorFoundries[i].foundry; + return 0; +} + +typedef struct _FcStringConst { + const FcChar8 *name; + int value; +} FcStringConst; + +static int +FcStringIsConst (const FcChar8 *string, + const FcStringConst *c, + int nc) +{ + int i; + + for (i = 0; i < nc; i++) + if (FcStrCmpIgnoreBlanksAndCase (string, c[i].name) == 0) + return c[i].value; + return -1; +} + +static int +FcStringContainsConst (const FcChar8 *string, + const FcStringConst *c, + int nc) +{ + int i; + + for (i = 0; i < nc; i++) + { + if (c[i].name[0] == '<') + { + if (FcStrContainsWord (string, c[i].name + 1)) + return c[i].value; + } + else + { + if (FcStrContainsIgnoreBlanksAndCase (string, c[i].name)) + return c[i].value; + } + } + return -1; +} + +typedef FcChar8 *FC8; + +static const FcStringConst weightConsts[] = { + { (FC8) "thin", FC_WEIGHT_THIN }, + { (FC8) "extralight", FC_WEIGHT_EXTRALIGHT }, + { (FC8) "ultralight", FC_WEIGHT_ULTRALIGHT }, + { (FC8) "light", FC_WEIGHT_LIGHT }, + { (FC8) "book", FC_WEIGHT_BOOK }, + { (FC8) "regular", FC_WEIGHT_REGULAR }, + { (FC8) "normal", FC_WEIGHT_NORMAL }, + { (FC8) "medium", FC_WEIGHT_MEDIUM }, + { (FC8) "demibold", FC_WEIGHT_DEMIBOLD }, + { (FC8) "demi", FC_WEIGHT_DEMIBOLD }, + { (FC8) "semibold", FC_WEIGHT_SEMIBOLD }, + { (FC8) "extrabold", FC_WEIGHT_EXTRABOLD }, + { (FC8) "superbold", FC_WEIGHT_EXTRABOLD }, + { (FC8) "ultrabold", FC_WEIGHT_ULTRABOLD }, + { (FC8) "bold", FC_WEIGHT_BOLD }, + { (FC8) "ultrablack", FC_WEIGHT_ULTRABLACK }, + { (FC8) "superblack", FC_WEIGHT_EXTRABLACK }, + { (FC8) "extrablack", FC_WEIGHT_EXTRABLACK }, + { (FC8) "num_fixed_sizes == 1) + { + BDF_PropertyRec prop; + int rc; + + rc = FT_Get_BDF_Property (face, "PIXEL_SIZE", &prop); + if (rc == 0 && prop.type == BDF_PROPERTY_TYPE_INTEGER) + return (double) prop.u.integer; + } +#endif +#if HAVE_FT_BITMAP_SIZE_Y_PPEM + return (double) face->available_sizes[i].y_ppem / 64.0; +#else + return (double) face->available_sizes[i].height; +#endif +} + +static FcBool +FcStringInPatternElement (FcPattern *pat, const char *elt, FcChar8 *string) +{ + int e; + FcChar8 *old; + for (e = 0; FcPatternGetString (pat, elt, e, &old) == FcResultMatch; e++) + if (!FcStrCmpIgnoreBlanksAndCase (old, string)) + { + return FcTrue; + } + return FcFalse; +} + +static const FT_UShort platform_order[] = { + TT_PLATFORM_MICROSOFT, + TT_PLATFORM_APPLE_UNICODE, + TT_PLATFORM_MACINTOSH, +}; +#define NUM_PLATFORM_ORDER (sizeof (platform_order) / sizeof (platform_order[0])) + +static const FT_UShort nameid_order[] = { +#ifdef TT_NAME_ID_WWS_FAMILY + TT_NAME_ID_WWS_FAMILY, +#endif + TT_NAME_ID_PREFERRED_FAMILY, + TT_NAME_ID_FONT_FAMILY, + TT_NAME_ID_MAC_FULL_NAME, + TT_NAME_ID_FULL_NAME, +#ifdef TT_NAME_ID_WWS_SUBFAMILY + TT_NAME_ID_WWS_SUBFAMILY, +#endif + TT_NAME_ID_PREFERRED_SUBFAMILY, + TT_NAME_ID_FONT_SUBFAMILY, + TT_NAME_ID_TRADEMARK, + TT_NAME_ID_MANUFACTURER, +}; + +#define NUM_NAMEID_ORDER (sizeof (nameid_order) / sizeof (nameid_order[0])) +FcPattern * +FcFreeTypeQueryFace (const FT_Face face, + const FcChar8 *file, + int id, + FcBlanks *blanks) +{ + FcPattern *pat; + int slant = -1; + int weight = -1; + int width = -1; + FcBool decorative = FcFalse; + int i; + FcCharSet *cs; + FcLangSet *ls; +#if 0 + FcChar8 *family = 0; +#endif + FcChar8 *complex_; + const FcChar8 *foundry = 0; + int spacing; + TT_OS2 *os2; +#if HAVE_FT_GET_PS_FONT_INFO + PS_FontInfoRec psfontinfo; +#endif +#if HAVE_FT_GET_BDF_PROPERTY + BDF_PropertyRec prop; +#endif + TT_Header *head; + const FcChar8 *exclusiveLang = 0; + FT_SfntName sname; + FT_UInt snamei, snamec; + + int nfamily = 0; + int nfamily_lang = 0; + int nstyle = 0; + int nstyle_lang = 0; + int nfullname = 0; + int nfullname_lang = 0; + unsigned int p, n; + int platform, nameid; + + FcChar8 *style = 0; + int st; + char psname[256]; + const char *tmp; + + FcChar8 *hashstr = NULL; + FT_Error err; + FT_ULong len = 0, alen; + + pat = FcPatternCreate (); + if (!pat) + goto bail0; + + if (!FcPatternAddBool (pat, FC_OUTLINE, + (face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)) + goto bail1; + + if (!FcPatternAddBool (pat, FC_SCALABLE, + (face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)) + goto bail1; + + + /* + * Get the OS/2 table + */ + os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2); + + /* + * Look first in the OS/2 table for the foundry, if + * not found here, the various notices will be searched for + * that information, either from the sfnt name tables or + * the Postscript FontInfo dictionary. Finally, the + * BDF properties will queried. + */ + + if (os2 && os2->version >= 0x0001 && os2->version != 0xffff) + foundry = FcVendorFoundry(os2->achVendID); + + if (FcDebug () & FC_DBG_SCANV) + printf ("\n"); + /* + * Grub through the name table looking for family + * and style names. FreeType makes quite a hash + * of them + */ + snamec = FT_Get_Sfnt_Name_Count (face); + for (p = 0; p <= NUM_PLATFORM_ORDER; p++) + { + if (p < NUM_PLATFORM_ORDER) + platform = platform_order[p]; + else + platform = 0xffff; + + /* + * Order nameids so preferred names appear first + * in the resulting list + */ + for (n = 0; n < NUM_NAMEID_ORDER; n++) + { + nameid = nameid_order[n]; + + for (snamei = 0; snamei < snamec; snamei++) + { + FcChar8 *utf8, *pp; + const FcChar8 *lang; + const char *elt = 0, *eltlang = 0; + int *np = 0, *nlangp = 0; + size_t len; + + if (FT_Get_Sfnt_Name (face, snamei, &sname) != 0) + continue; + if (sname.name_id != nameid) + continue; + + /* + * Sort platforms in preference order, accepting + * all other platforms last + */ + if (p < NUM_PLATFORM_ORDER) + { + if (sname.platform_id != platform) + continue; + } + else + { + unsigned int sp; + + for (sp = 0; sp < NUM_PLATFORM_ORDER; sp++) + if (sname.platform_id == platform_order[sp]) + break; + if (sp != NUM_PLATFORM_ORDER) + continue; + } + utf8 = FcSfntNameTranscode (&sname); + lang = FcSfntNameLanguage (&sname); + + if (!utf8) + continue; + + switch (sname.name_id) { +#ifdef TT_NAME_ID_WWS_FAMILY + case TT_NAME_ID_WWS_FAMILY: +#endif + case TT_NAME_ID_PREFERRED_FAMILY: + case TT_NAME_ID_FONT_FAMILY: +#if 0 + case TT_NAME_ID_UNIQUE_ID: +#endif + if (FcDebug () & FC_DBG_SCANV) + printf ("found family (n %2d p %d e %d l 0x%04x) %s\n", + sname.name_id, sname.platform_id, + sname.encoding_id, sname.language_id, + utf8); + + elt = FC_FAMILY; + eltlang = FC_FAMILYLANG; + np = &nfamily; + nlangp = &nfamily_lang; + break; + case TT_NAME_ID_MAC_FULL_NAME: + case TT_NAME_ID_FULL_NAME: + if (FcDebug () & FC_DBG_SCANV) + printf ("found full (n %2d p %d e %d l 0x%04x) %s\n", + sname.name_id, sname.platform_id, + sname.encoding_id, sname.language_id, + utf8); + + elt = FC_FULLNAME; + eltlang = FC_FULLNAMELANG; + np = &nfullname; + nlangp = &nfullname_lang; + break; +#ifdef TT_NAME_ID_WWS_SUBFAMILY + case TT_NAME_ID_WWS_SUBFAMILY: +#endif + case TT_NAME_ID_PREFERRED_SUBFAMILY: + case TT_NAME_ID_FONT_SUBFAMILY: + if (utf8) + { + pp = utf8; + while (*pp == ' ') + pp++; + len = strlen ((const char *) pp); + memmove (utf8, pp, len + 1); + pp = utf8 + len - 1; + while (*pp == ' ') + pp--; + *(pp + 1) = 0; + } + if (FcDebug () & FC_DBG_SCANV) + printf ("found style (n %2d p %d e %d l 0x%04x) %s\n", + sname.name_id, sname.platform_id, + sname.encoding_id, sname.language_id, + utf8); + + elt = FC_STYLE; + eltlang = FC_STYLELANG; + np = &nstyle; + nlangp = &nstyle_lang; + break; + case TT_NAME_ID_TRADEMARK: + case TT_NAME_ID_MANUFACTURER: + /* If the foundry wasn't found in the OS/2 table, look here */ + if(!foundry) + foundry = FcNoticeFoundry((FT_String *) utf8); + break; + } + if (elt) + { + if (FcStringInPatternElement (pat, elt, utf8)) + { + free (utf8); + continue; + } + + /* add new element */ + if (!FcPatternAddString (pat, elt, utf8)) + { + free (utf8); + goto bail1; + } + free (utf8); + if (lang) + { + /* pad lang list with 'xx' to line up with elt */ + while (*nlangp < *np) + { + if (!FcPatternAddString (pat, eltlang, (FcChar8 *) "xx")) + goto bail1; + ++*nlangp; + } + if (!FcPatternAddString (pat, eltlang, lang)) + goto bail1; + ++*nlangp; + } + ++*np; + } + else + free (utf8); + } + } + } + + if (!nfamily && face->family_name && + FcStrCmpIgnoreBlanksAndCase ((FcChar8 *) face->family_name, (FcChar8 *) "") != 0) + { + if (FcDebug () & FC_DBG_SCANV) + printf ("using FreeType family \"%s\"\n", face->family_name); + if (!FcPatternAddString (pat, FC_FAMILY, (FcChar8 *) face->family_name)) + goto bail1; + ++nfamily; + } + + if (!nstyle && face->style_name && + FcStrCmpIgnoreBlanksAndCase ((FcChar8 *) face->style_name, (FcChar8 *) "") != 0) + { + if (FcDebug () & FC_DBG_SCANV) + printf ("using FreeType style \"%s\"\n", face->style_name); + if (!FcPatternAddString (pat, FC_STYLE, (FcChar8 *) face->style_name)) + goto bail1; + ++nstyle; + } + + if (!nfamily) + { + FcChar8 *start, *end; + FcChar8 *family; + + start = (FcChar8 *) strrchr ((char *) file, '/'); + if (start) + start++; + else + start = (FcChar8 *) file; + end = (FcChar8 *) strrchr ((char *) start, '.'); + if (!end) + end = start + strlen ((char *) start); + /* freed below */ + family = malloc (end - start + 1); + strncpy ((char *) family, (char *) start, end - start); + family[end - start] = '\0'; + if (FcDebug () & FC_DBG_SCANV) + printf ("using filename for family %s\n", family); + if (!FcPatternAddString (pat, FC_FAMILY, family)) + { + free (family); + goto bail1; + } + free (family); + ++nfamily; + } + + /* Add the PostScript name into the cache */ + tmp = FT_Get_Postscript_Name (face); + if (!tmp) + { + FcChar8 *family, *familylang = NULL; + size_t len; + int n = 0; + + /* Workaround when FT_Get_Postscript_Name didn't give any name. + * try to find out the English family name and convert. + */ + while (FcPatternObjectGetString (pat, FC_FAMILYLANG_OBJECT, n, &familylang) == FcResultMatch) + { + if (FcStrCmp (familylang, (const FcChar8 *)"en") == 0) + break; + n++; + familylang = NULL; + } + if (!familylang) + n = 0; + + if (FcPatternObjectGetString (pat, FC_FAMILY_OBJECT, n, &family) != FcResultMatch) + goto bail1; + len = strlen ((const char *)family); + /* the literal name in PostScript Language is limited to 127 characters though, + * It is the architectural limit. so assuming 255 characters may works enough. + */ + for (i = 0; i < len && i < 255; i++) + { + /* those characters are not allowed to be the literal name in PostScript */ + static const char exclusive_chars[] = "\x04()/<>[]{}\t\f\r\n "; + + if (strchr(exclusive_chars, family[i]) != NULL) + psname[i] = '-'; + else + psname[i] = family[i]; + } + psname[i] = 0; + } + else + { + strcpy (psname, tmp); + } + if (!FcPatternAddString (pat, FC_POSTSCRIPT_NAME, (const FcChar8 *)psname)) + goto bail1; + + if (!FcPatternAddString (pat, FC_FILE, file)) + goto bail1; + + if (!FcPatternAddInteger (pat, FC_INDEX, id)) + goto bail1; + +#if 0 + /* + * don't even try this -- CJK 'monospace' fonts are really + * dual width, and most other fonts don't bother to set + * the attribute. Sigh. + */ + if ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0) + if (!FcPatternAddInteger (pat, FC_SPACING, FC_MONO)) + goto bail1; +#endif + + /* + * Find the font revision (if available) + */ + head = (TT_Header *) FT_Get_Sfnt_Table (face, ft_sfnt_head); + if (head) + { + if (!FcPatternAddInteger (pat, FC_FONTVERSION, head->Font_Revision)) + goto bail1; + } + else + { + if (!FcPatternAddInteger (pat, FC_FONTVERSION, 0)) + goto bail1; + } + + if (os2 && os2->version >= 0x0001 && os2->version != 0xffff) + { + for (i = 0; i < NUM_CODE_PAGE_RANGE; i++) + { + FT_ULong bits; + int bit; + if (FcCodePageRange[i].bit < 32) + { + bits = os2->ulCodePageRange1; + bit = FcCodePageRange[i].bit; + } + else + { + bits = os2->ulCodePageRange2; + bit = FcCodePageRange[i].bit - 32; + } + if (bits & (1 << bit)) + { + /* + * If the font advertises support for multiple + * "exclusive" languages, then include support + * for any language found to have coverage + */ + if (exclusiveLang) + { + exclusiveLang = 0; + break; + } + exclusiveLang = FcCodePageRange[i].lang; + } + } + } + + if (os2 && os2->version != 0xffff) + { + if (os2->usWeightClass == 0) + ; + else if (os2->usWeightClass < 150) + weight = FC_WEIGHT_THIN; + else if (os2->usWeightClass < 250) + weight = FC_WEIGHT_EXTRALIGHT; + else if (os2->usWeightClass < 350) + weight = FC_WEIGHT_LIGHT; + else if (os2->usWeightClass < 450) + weight = FC_WEIGHT_REGULAR; + else if (os2->usWeightClass < 550) + weight = FC_WEIGHT_MEDIUM; + else if (os2->usWeightClass < 650) + weight = FC_WEIGHT_SEMIBOLD; + else if (os2->usWeightClass < 750) + weight = FC_WEIGHT_BOLD; + else if (os2->usWeightClass < 850) + weight = FC_WEIGHT_EXTRABOLD; + else if (os2->usWeightClass < 925) + weight = FC_WEIGHT_BLACK; + else if (os2->usWeightClass < 1000) + weight = FC_WEIGHT_EXTRABLACK; + if ((FcDebug() & FC_DBG_SCANV) && weight != -1) + printf ("\tos2 weight class %d maps to weight %d\n", + os2->usWeightClass, weight); + + switch (os2->usWidthClass) { + case 1: width = FC_WIDTH_ULTRACONDENSED; break; + case 2: width = FC_WIDTH_EXTRACONDENSED; break; + case 3: width = FC_WIDTH_CONDENSED; break; + case 4: width = FC_WIDTH_SEMICONDENSED; break; + case 5: width = FC_WIDTH_NORMAL; break; + case 6: width = FC_WIDTH_SEMIEXPANDED; break; + case 7: width = FC_WIDTH_EXPANDED; break; + case 8: width = FC_WIDTH_EXTRAEXPANDED; break; + case 9: width = FC_WIDTH_ULTRAEXPANDED; break; + } + if ((FcDebug() & FC_DBG_SCANV) && width != -1) + printf ("\tos2 width class %d maps to width %d\n", + os2->usWidthClass, width); + } + if (os2 && (complex_ = FcFontCapabilities(face))) + { + if (!FcPatternAddString (pat, FC_CAPABILITY, complex_)) + { + free (complex_); + goto bail1; + } + free (complex_); + } + + /* + * Type 1: Check for FontInfo dictionary information + * Code from g2@magestudios.net (Gerard Escalante) + */ + +#if HAVE_FT_GET_PS_FONT_INFO + if (FT_Get_PS_Font_Info(face, &psfontinfo) == 0) + { + if (weight == -1 && psfontinfo.weight) + { + weight = FcIsWeight ((FcChar8 *) psfontinfo.weight); + if (FcDebug() & FC_DBG_SCANV) + printf ("\tType1 weight %s maps to %d\n", + psfontinfo.weight, weight); + } + +#if 0 + /* + * Don't bother with italic_angle; FreeType already extracts that + * information for us and sticks it into style_flags + */ + if (psfontinfo.italic_angle) + slant = FC_SLANT_ITALIC; + else + slant = FC_SLANT_ROMAN; +#endif + + if(!foundry) + foundry = FcNoticeFoundry(psfontinfo.notice); + } +#endif /* HAVE_FT_GET_PS_FONT_INFO */ + +#if HAVE_FT_GET_BDF_PROPERTY + /* + * Finally, look for a FOUNDRY BDF property if no other + * mechanism has managed to locate a foundry + */ + + if (!foundry) + { + int rc; + rc = FT_Get_BDF_Property(face, "FOUNDRY", &prop); + if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) + foundry = (FcChar8 *) prop.u.atom; + } + + if (width == -1) + { + if (FT_Get_BDF_Property(face, "RELATIVE_SETWIDTH", &prop) == 0 && + (prop.type == BDF_PROPERTY_TYPE_INTEGER || + prop.type == BDF_PROPERTY_TYPE_CARDINAL)) + { + FT_Int32 value; + + if (prop.type == BDF_PROPERTY_TYPE_INTEGER) + value = prop.u.integer; + else + value = (FT_Int32) prop.u.cardinal; + switch ((value + 5) / 10) { + case 1: width = FC_WIDTH_ULTRACONDENSED; break; + case 2: width = FC_WIDTH_EXTRACONDENSED; break; + case 3: width = FC_WIDTH_CONDENSED; break; + case 4: width = FC_WIDTH_SEMICONDENSED; break; + case 5: width = FC_WIDTH_NORMAL; break; + case 6: width = FC_WIDTH_SEMIEXPANDED; break; + case 7: width = FC_WIDTH_EXPANDED; break; + case 8: width = FC_WIDTH_EXTRAEXPANDED; break; + case 9: width = FC_WIDTH_ULTRAEXPANDED; break; + } + } + if (width == -1 && + FT_Get_BDF_Property (face, "SETWIDTH_NAME", &prop) == 0 && + prop.type == BDF_PROPERTY_TYPE_ATOM && prop.u.atom != NULL) + { + width = FcIsWidth ((FcChar8 *) prop.u.atom); + if (FcDebug () & FC_DBG_SCANV) + printf ("\tsetwidth %s maps to %d\n", prop.u.atom, width); + } + } +#endif + + /* + * Look for weight, width and slant names in the style value + */ + for (st = 0; FcPatternGetString (pat, FC_STYLE, st, &style) == FcResultMatch; st++) + { + if (weight == -1) + { + weight = FcContainsWeight (style); + if (FcDebug() & FC_DBG_SCANV) + printf ("\tStyle %s maps to weight %d\n", style, weight); + } + if (width == -1) + { + width = FcContainsWidth (style); + if (FcDebug() & FC_DBG_SCANV) + printf ("\tStyle %s maps to width %d\n", style, width); + } + if (slant == -1) + { + slant = FcContainsSlant (style); + if (FcDebug() & FC_DBG_SCANV) + printf ("\tStyle %s maps to slant %d\n", style, slant); + } + if (decorative == FcFalse) + { + decorative = FcContainsDecorative (style) > 0; + if (FcDebug() & FC_DBG_SCANV) + printf ("\tStyle %s maps to decorative %d\n", style, decorative); + } + } + /* + * Pull default values from the FreeType flags if more + * specific values not found above + */ + if (slant == -1) + { + slant = FC_SLANT_ROMAN; + if (face->style_flags & FT_STYLE_FLAG_ITALIC) + slant = FC_SLANT_ITALIC; + } + + if (weight == -1) + { + weight = FC_WEIGHT_MEDIUM; + if (face->style_flags & FT_STYLE_FLAG_BOLD) + weight = FC_WEIGHT_BOLD; + } + + if (width == -1) + width = FC_WIDTH_NORMAL; + + if (foundry == 0) + foundry = (FcChar8 *) "unknown"; + + if (!FcPatternAddInteger (pat, FC_SLANT, slant)) + goto bail1; + + if (!FcPatternAddInteger (pat, FC_WEIGHT, weight)) + goto bail1; + + if (!FcPatternAddInteger (pat, FC_WIDTH, width)) + goto bail1; + + if (!FcPatternAddString (pat, FC_FOUNDRY, foundry)) + goto bail1; + + if (!FcPatternAddBool (pat, FC_DECORATIVE, decorative)) + goto bail1; + + err = FT_Load_Sfnt_Table (face, 0, 0, NULL, &len); + if (err == FT_Err_Ok) + { + char *fontdata; + + alen = (len + 63) & ~63; + fontdata = malloc (alen); + if (!fontdata) + goto bail3; + err = FT_Load_Sfnt_Table (face, 0, 0, (FT_Byte *)fontdata, &len); + if (err != FT_Err_Ok) + { + free (fontdata); + goto bail3; + } + memset (&fontdata[len], 0, alen - len); + hashstr = FcHashGetSHA256DigestFromMemory (fontdata, len); + free (fontdata); + } + else if (err == FT_Err_Invalid_Face_Handle) + { + /* font may not support SFNT. falling back to + * read the font data from file directly + */ + hashstr = FcHashGetSHA256DigestFromFile (file); + } + else + { + goto bail3; + } + if (hashstr) + { + if (!FcPatternAddString (pat, FC_HASH, hashstr)) + { + free (hashstr); + goto bail1; + } + free (hashstr); + } +bail3: + + /* + * Compute the unicode coverage for the font + */ + cs = FcFreeTypeCharSetAndSpacing (face, blanks, &spacing); + if (!cs) + goto bail1; + +#if HAVE_FT_GET_BDF_PROPERTY + /* For PCF fonts, override the computed spacing with the one from + the property */ + if(FT_Get_BDF_Property(face, "SPACING", &prop) == 0 && + prop.type == BDF_PROPERTY_TYPE_ATOM && prop.u.atom != NULL) { + if(!strcmp(prop.u.atom, "c") || !strcmp(prop.u.atom, "C")) + spacing = FC_CHARCELL; + else if(!strcmp(prop.u.atom, "m") || !strcmp(prop.u.atom, "M")) + spacing = FC_MONO; + else if(!strcmp(prop.u.atom, "p") || !strcmp(prop.u.atom, "P")) + spacing = FC_PROPORTIONAL; + } +#endif + + /* + * Skip over PCF fonts that have no encoded characters; they're + * usually just Unicode fonts transcoded to some legacy encoding + * FT forces us to approximate whether a font is a PCF font + * or not by whether it has any BDF properties. Try PIXEL_SIZE; + * I don't know how to get a list of BDF properties on the font. -PL + */ + if (FcCharSetCount (cs) == 0) + { +#if HAVE_FT_GET_BDF_PROPERTY + if(FT_Get_BDF_Property(face, "PIXEL_SIZE", &prop) == 0) + goto bail2; +#endif + } + + if (!FcPatternAddCharSet (pat, FC_CHARSET, cs)) + goto bail2; + + ls = FcFreeTypeLangSet (cs, exclusiveLang); + if (!ls) + goto bail2; + + if (!FcPatternAddLangSet (pat, FC_LANG, ls)) + { + FcLangSetDestroy (ls); + goto bail2; + } + + FcLangSetDestroy (ls); + + if (spacing != FC_PROPORTIONAL) + if (!FcPatternAddInteger (pat, FC_SPACING, spacing)) + goto bail2; + + if (!(face->face_flags & FT_FACE_FLAG_SCALABLE)) + { + for (i = 0; i < face->num_fixed_sizes; i++) + if (!FcPatternAddDouble (pat, FC_PIXEL_SIZE, + FcGetPixelSize (face, i))) + goto bail2; + if (!FcPatternAddBool (pat, FC_ANTIALIAS, FcFalse)) + goto bail2; + } +#if HAVE_FT_GET_X11_FONT_FORMAT + /* + * Use the (not well documented or supported) X-specific function + * from FreeType to figure out the font format + */ + { + const char *font_format = FT_Get_X11_Font_Format (face); + if (font_format) + if (!FcPatternAddString (pat, FC_FONTFORMAT, (FcChar8 *) font_format)) + goto bail2; + } +#endif + + /* + * Drop our reference to the charset + */ + FcCharSetDestroy (cs); + + return pat; + +bail2: + FcCharSetDestroy (cs); +bail1: + FcPatternDestroy (pat); +bail0: + return NULL; +} + +FcPattern * +FcFreeTypeQuery(const FcChar8 *file, + int id, + FcBlanks *blanks, + int *count) +{ + FT_Face face; + FT_Library ftLibrary; + FcPattern *pat = NULL; + + if (FT_Init_FreeType (&ftLibrary)) + return NULL; + + if (FT_New_Face (ftLibrary, (char *) file, id, &face)) + goto bail; + + *count = face->num_faces; + + pat = FcFreeTypeQueryFace (face, file, id, blanks); + + FT_Done_Face (face); +bail: + FT_Done_FreeType (ftLibrary); + return pat; +} + +/* + * For our purposes, this approximation is sufficient + */ +/*#if !HAVE_FT_GET_NEXT_CHAR*/ +/*#define FT_Get_Next_Char(face, ucs4, gi) ((ucs4) >= 0xffffff ? \*/ + /*(*(gi) = 0), 0 : \*/ + /*(*(gi) = 1), (ucs4) + 1)*/ +/*#warning "No FT_Get_Next_Char: Please install freetype version 2.1.0 or newer"*/ +/*#endif*/ + +typedef struct _FcCharEnt { + FcChar16 bmp; + unsigned char encode; +} FcCharEnt; + +struct _FcCharMap { + const FcCharEnt *ent; + int nent; +}; + +typedef struct _FcFontDecode { + FT_Encoding encoding; + const FcCharMap *map; + FcChar32 max; +} FcFontDecode; + +static const FcCharEnt AdobeSymbolEnt[] = { + { 0x0020, 0x20 }, /* SPACE # space */ + { 0x0021, 0x21 }, /* EXCLAMATION MARK # exclam */ + { 0x0023, 0x23 }, /* NUMBER SIGN # numbersign */ + { 0x0025, 0x25 }, /* PERCENT SIGN # percent */ + { 0x0026, 0x26 }, /* AMPERSAND # ampersand */ + { 0x0028, 0x28 }, /* LEFT PARENTHESIS # parenleft */ + { 0x0029, 0x29 }, /* RIGHT PARENTHESIS # parenright */ + { 0x002B, 0x2B }, /* PLUS SIGN # plus */ + { 0x002C, 0x2C }, /* COMMA # comma */ + { 0x002E, 0x2E }, /* FULL STOP # period */ + { 0x002F, 0x2F }, /* SOLIDUS # slash */ + { 0x0030, 0x30 }, /* DIGIT ZERO # zero */ + { 0x0031, 0x31 }, /* DIGIT ONE # one */ + { 0x0032, 0x32 }, /* DIGIT TWO # two */ + { 0x0033, 0x33 }, /* DIGIT THREE # three */ + { 0x0034, 0x34 }, /* DIGIT FOUR # four */ + { 0x0035, 0x35 }, /* DIGIT FIVE # five */ + { 0x0036, 0x36 }, /* DIGIT SIX # six */ + { 0x0037, 0x37 }, /* DIGIT SEVEN # seven */ + { 0x0038, 0x38 }, /* DIGIT EIGHT # eight */ + { 0x0039, 0x39 }, /* DIGIT NINE # nine */ + { 0x003A, 0x3A }, /* COLON # colon */ + { 0x003B, 0x3B }, /* SEMICOLON # semicolon */ + { 0x003C, 0x3C }, /* LESS-THAN SIGN # less */ + { 0x003D, 0x3D }, /* EQUALS SIGN # equal */ + { 0x003E, 0x3E }, /* GREATER-THAN SIGN # greater */ + { 0x003F, 0x3F }, /* QUESTION MARK # question */ + { 0x005B, 0x5B }, /* LEFT SQUARE BRACKET # bracketleft */ + { 0x005D, 0x5D }, /* RIGHT SQUARE BRACKET # bracketright */ + { 0x005F, 0x5F }, /* LOW LINE # underscore */ + { 0x007B, 0x7B }, /* LEFT CURLY BRACKET # braceleft */ + { 0x007C, 0x7C }, /* VERTICAL LINE # bar */ + { 0x007D, 0x7D }, /* RIGHT CURLY BRACKET # braceright */ + { 0x00A0, 0x20 }, /* NO-BREAK SPACE # space */ + { 0x00AC, 0xD8 }, /* NOT SIGN # logicalnot */ + { 0x00B0, 0xB0 }, /* DEGREE SIGN # degree */ + { 0x00B1, 0xB1 }, /* PLUS-MINUS SIGN # plusminus */ + { 0x00B5, 0x6D }, /* MICRO SIGN # mu */ + { 0x00D7, 0xB4 }, /* MULTIPLICATION SIGN # multiply */ + { 0x00F7, 0xB8 }, /* DIVISION SIGN # divide */ + { 0x0192, 0xA6 }, /* LATIN SMALL LETTER F WITH HOOK # florin */ + { 0x0391, 0x41 }, /* GREEK CAPITAL LETTER ALPHA # Alpha */ + { 0x0392, 0x42 }, /* GREEK CAPITAL LETTER BETA # Beta */ + { 0x0393, 0x47 }, /* GREEK CAPITAL LETTER GAMMA # Gamma */ + { 0x0394, 0x44 }, /* GREEK CAPITAL LETTER DELTA # Delta */ + { 0x0395, 0x45 }, /* GREEK CAPITAL LETTER EPSILON # Epsilon */ + { 0x0396, 0x5A }, /* GREEK CAPITAL LETTER ZETA # Zeta */ + { 0x0397, 0x48 }, /* GREEK CAPITAL LETTER ETA # Eta */ + { 0x0398, 0x51 }, /* GREEK CAPITAL LETTER THETA # Theta */ + { 0x0399, 0x49 }, /* GREEK CAPITAL LETTER IOTA # Iota */ + { 0x039A, 0x4B }, /* GREEK CAPITAL LETTER KAPPA # Kappa */ + { 0x039B, 0x4C }, /* GREEK CAPITAL LETTER LAMDA # Lambda */ + { 0x039C, 0x4D }, /* GREEK CAPITAL LETTER MU # Mu */ + { 0x039D, 0x4E }, /* GREEK CAPITAL LETTER NU # Nu */ + { 0x039E, 0x58 }, /* GREEK CAPITAL LETTER XI # Xi */ + { 0x039F, 0x4F }, /* GREEK CAPITAL LETTER OMICRON # Omicron */ + { 0x03A0, 0x50 }, /* GREEK CAPITAL LETTER PI # Pi */ + { 0x03A1, 0x52 }, /* GREEK CAPITAL LETTER RHO # Rho */ + { 0x03A3, 0x53 }, /* GREEK CAPITAL LETTER SIGMA # Sigma */ + { 0x03A4, 0x54 }, /* GREEK CAPITAL LETTER TAU # Tau */ + { 0x03A5, 0x55 }, /* GREEK CAPITAL LETTER UPSILON # Upsilon */ + { 0x03A6, 0x46 }, /* GREEK CAPITAL LETTER PHI # Phi */ + { 0x03A7, 0x43 }, /* GREEK CAPITAL LETTER CHI # Chi */ + { 0x03A8, 0x59 }, /* GREEK CAPITAL LETTER PSI # Psi */ + { 0x03A9, 0x57 }, /* GREEK CAPITAL LETTER OMEGA # Omega */ + { 0x03B1, 0x61 }, /* GREEK SMALL LETTER ALPHA # alpha */ + { 0x03B2, 0x62 }, /* GREEK SMALL LETTER BETA # beta */ + { 0x03B3, 0x67 }, /* GREEK SMALL LETTER GAMMA # gamma */ + { 0x03B4, 0x64 }, /* GREEK SMALL LETTER DELTA # delta */ + { 0x03B5, 0x65 }, /* GREEK SMALL LETTER EPSILON # epsilon */ + { 0x03B6, 0x7A }, /* GREEK SMALL LETTER ZETA # zeta */ + { 0x03B7, 0x68 }, /* GREEK SMALL LETTER ETA # eta */ + { 0x03B8, 0x71 }, /* GREEK SMALL LETTER THETA # theta */ + { 0x03B9, 0x69 }, /* GREEK SMALL LETTER IOTA # iota */ + { 0x03BA, 0x6B }, /* GREEK SMALL LETTER KAPPA # kappa */ + { 0x03BB, 0x6C }, /* GREEK SMALL LETTER LAMDA # lambda */ + { 0x03BC, 0x6D }, /* GREEK SMALL LETTER MU # mu */ + { 0x03BD, 0x6E }, /* GREEK SMALL LETTER NU # nu */ + { 0x03BE, 0x78 }, /* GREEK SMALL LETTER XI # xi */ + { 0x03BF, 0x6F }, /* GREEK SMALL LETTER OMICRON # omicron */ + { 0x03C0, 0x70 }, /* GREEK SMALL LETTER PI # pi */ + { 0x03C1, 0x72 }, /* GREEK SMALL LETTER RHO # rho */ + { 0x03C2, 0x56 }, /* GREEK SMALL LETTER FINAL SIGMA # sigma1 */ + { 0x03C3, 0x73 }, /* GREEK SMALL LETTER SIGMA # sigma */ + { 0x03C4, 0x74 }, /* GREEK SMALL LETTER TAU # tau */ + { 0x03C5, 0x75 }, /* GREEK SMALL LETTER UPSILON # upsilon */ + { 0x03C6, 0x66 }, /* GREEK SMALL LETTER PHI # phi */ + { 0x03C7, 0x63 }, /* GREEK SMALL LETTER CHI # chi */ + { 0x03C8, 0x79 }, /* GREEK SMALL LETTER PSI # psi */ + { 0x03C9, 0x77 }, /* GREEK SMALL LETTER OMEGA # omega */ + { 0x03D1, 0x4A }, /* GREEK THETA SYMBOL # theta1 */ + { 0x03D2, 0xA1 }, /* GREEK UPSILON WITH HOOK SYMBOL # Upsilon1 */ + { 0x03D5, 0x6A }, /* GREEK PHI SYMBOL # phi1 */ + { 0x03D6, 0x76 }, /* GREEK PI SYMBOL # omega1 */ + { 0x2022, 0xB7 }, /* BULLET # bullet */ + { 0x2026, 0xBC }, /* HORIZONTAL ELLIPSIS # ellipsis */ + { 0x2032, 0xA2 }, /* PRIME # minute */ + { 0x2033, 0xB2 }, /* DOUBLE PRIME # second */ + { 0x2044, 0xA4 }, /* FRACTION SLASH # fraction */ + { 0x20AC, 0xA0 }, /* EURO SIGN # Euro */ + { 0x2111, 0xC1 }, /* BLACK-LETTER CAPITAL I # Ifraktur */ + { 0x2118, 0xC3 }, /* SCRIPT CAPITAL P # weierstrass */ + { 0x211C, 0xC2 }, /* BLACK-LETTER CAPITAL R # Rfraktur */ + { 0x2126, 0x57 }, /* OHM SIGN # Omega */ + { 0x2135, 0xC0 }, /* ALEF SYMBOL # aleph */ + { 0x2190, 0xAC }, /* LEFTWARDS ARROW # arrowleft */ + { 0x2191, 0xAD }, /* UPWARDS ARROW # arrowup */ + { 0x2192, 0xAE }, /* RIGHTWARDS ARROW # arrowright */ + { 0x2193, 0xAF }, /* DOWNWARDS ARROW # arrowdown */ + { 0x2194, 0xAB }, /* LEFT RIGHT ARROW # arrowboth */ + { 0x21B5, 0xBF }, /* DOWNWARDS ARROW WITH CORNER LEFTWARDS # carriagereturn */ + { 0x21D0, 0xDC }, /* LEFTWARDS DOUBLE ARROW # arrowdblleft */ + { 0x21D1, 0xDD }, /* UPWARDS DOUBLE ARROW # arrowdblup */ + { 0x21D2, 0xDE }, /* RIGHTWARDS DOUBLE ARROW # arrowdblright */ + { 0x21D3, 0xDF }, /* DOWNWARDS DOUBLE ARROW # arrowdbldown */ + { 0x21D4, 0xDB }, /* LEFT RIGHT DOUBLE ARROW # arrowdblboth */ + { 0x2200, 0x22 }, /* FOR ALL # universal */ + { 0x2202, 0xB6 }, /* PARTIAL DIFFERENTIAL # partialdiff */ + { 0x2203, 0x24 }, /* THERE EXISTS # existential */ + { 0x2205, 0xC6 }, /* EMPTY SET # emptyset */ + { 0x2206, 0x44 }, /* INCREMENT # Delta */ + { 0x2207, 0xD1 }, /* NABLA # gradient */ + { 0x2208, 0xCE }, /* ELEMENT OF # element */ + { 0x2209, 0xCF }, /* NOT AN ELEMENT OF # notelement */ + { 0x220B, 0x27 }, /* CONTAINS AS MEMBER # suchthat */ + { 0x220F, 0xD5 }, /* N-ARY PRODUCT # product */ + { 0x2211, 0xE5 }, /* N-ARY SUMMATION # summation */ + { 0x2212, 0x2D }, /* MINUS SIGN # minus */ + { 0x2215, 0xA4 }, /* DIVISION SLASH # fraction */ + { 0x2217, 0x2A }, /* ASTERISK OPERATOR # asteriskmath */ + { 0x221A, 0xD6 }, /* SQUARE ROOT # radical */ + { 0x221D, 0xB5 }, /* PROPORTIONAL TO # proportional */ + { 0x221E, 0xA5 }, /* INFINITY # infinity */ + { 0x2220, 0xD0 }, /* ANGLE # angle */ + { 0x2227, 0xD9 }, /* LOGICAL AND # logicaland */ + { 0x2228, 0xDA }, /* LOGICAL OR # logicalor */ + { 0x2229, 0xC7 }, /* INTERSECTION # intersection */ + { 0x222A, 0xC8 }, /* UNION # union */ + { 0x222B, 0xF2 }, /* INTEGRAL # integral */ + { 0x2234, 0x5C }, /* THEREFORE # therefore */ + { 0x223C, 0x7E }, /* TILDE OPERATOR # similar */ + { 0x2245, 0x40 }, /* APPROXIMATELY EQUAL TO # congruent */ + { 0x2248, 0xBB }, /* ALMOST EQUAL TO # approxequal */ + { 0x2260, 0xB9 }, /* NOT EQUAL TO # notequal */ + { 0x2261, 0xBA }, /* IDENTICAL TO # equivalence */ + { 0x2264, 0xA3 }, /* LESS-THAN OR EQUAL TO # lessequal */ + { 0x2265, 0xB3 }, /* GREATER-THAN OR EQUAL TO # greaterequal */ + { 0x2282, 0xCC }, /* SUBSET OF # propersubset */ + { 0x2283, 0xC9 }, /* SUPERSET OF # propersuperset */ + { 0x2284, 0xCB }, /* NOT A SUBSET OF # notsubset */ + { 0x2286, 0xCD }, /* SUBSET OF OR EQUAL TO # reflexsubset */ + { 0x2287, 0xCA }, /* SUPERSET OF OR EQUAL TO # reflexsuperset */ + { 0x2295, 0xC5 }, /* CIRCLED PLUS # circleplus */ + { 0x2297, 0xC4 }, /* CIRCLED TIMES # circlemultiply */ + { 0x22A5, 0x5E }, /* UP TACK # perpendicular */ + { 0x22C5, 0xD7 }, /* DOT OPERATOR # dotmath */ + { 0x2320, 0xF3 }, /* TOP HALF INTEGRAL # integraltp */ + { 0x2321, 0xF5 }, /* BOTTOM HALF INTEGRAL # integralbt */ + { 0x2329, 0xE1 }, /* LEFT-POINTING ANGLE BRACKET # angleleft */ + { 0x232A, 0xF1 }, /* RIGHT-POINTING ANGLE BRACKET # angleright */ + { 0x25CA, 0xE0 }, /* LOZENGE # lozenge */ + { 0x2660, 0xAA }, /* BLACK SPADE SUIT # spade */ + { 0x2663, 0xA7 }, /* BLACK CLUB SUIT # club */ + { 0x2665, 0xA9 }, /* BLACK HEART SUIT # heart */ + { 0x2666, 0xA8 }, /* BLACK DIAMOND SUIT # diamond */ + { 0xF6D9, 0xD3 }, /* COPYRIGHT SIGN SERIF # copyrightserif (CUS) */ + { 0xF6DA, 0xD2 }, /* REGISTERED SIGN SERIF # registerserif (CUS) */ + { 0xF6DB, 0xD4 }, /* TRADE MARK SIGN SERIF # trademarkserif (CUS) */ + { 0xF8E5, 0x60 }, /* RADICAL EXTENDER # radicalex (CUS) */ + { 0xF8E6, 0xBD }, /* VERTICAL ARROW EXTENDER # arrowvertex (CUS) */ + { 0xF8E7, 0xBE }, /* HORIZONTAL ARROW EXTENDER # arrowhorizex (CUS) */ + { 0xF8E8, 0xE2 }, /* REGISTERED SIGN SANS SERIF # registersans (CUS) */ + { 0xF8E9, 0xE3 }, /* COPYRIGHT SIGN SANS SERIF # copyrightsans (CUS) */ + { 0xF8EA, 0xE4 }, /* TRADE MARK SIGN SANS SERIF # trademarksans (CUS) */ + { 0xF8EB, 0xE6 }, /* LEFT PAREN TOP # parenlefttp (CUS) */ + { 0xF8EC, 0xE7 }, /* LEFT PAREN EXTENDER # parenleftex (CUS) */ + { 0xF8ED, 0xE8 }, /* LEFT PAREN BOTTOM # parenleftbt (CUS) */ + { 0xF8EE, 0xE9 }, /* LEFT SQUARE BRACKET TOP # bracketlefttp (CUS) */ + { 0xF8EF, 0xEA }, /* LEFT SQUARE BRACKET EXTENDER # bracketleftex (CUS) */ + { 0xF8F0, 0xEB }, /* LEFT SQUARE BRACKET BOTTOM # bracketleftbt (CUS) */ + { 0xF8F1, 0xEC }, /* LEFT CURLY BRACKET TOP # bracelefttp (CUS) */ + { 0xF8F2, 0xED }, /* LEFT CURLY BRACKET MID # braceleftmid (CUS) */ + { 0xF8F3, 0xEE }, /* LEFT CURLY BRACKET BOTTOM # braceleftbt (CUS) */ + { 0xF8F4, 0xEF }, /* CURLY BRACKET EXTENDER # braceex (CUS) */ + { 0xF8F5, 0xF4 }, /* INTEGRAL EXTENDER # integralex (CUS) */ + { 0xF8F6, 0xF6 }, /* RIGHT PAREN TOP # parenrighttp (CUS) */ + { 0xF8F7, 0xF7 }, /* RIGHT PAREN EXTENDER # parenrightex (CUS) */ + { 0xF8F8, 0xF8 }, /* RIGHT PAREN BOTTOM # parenrightbt (CUS) */ + { 0xF8F9, 0xF9 }, /* RIGHT SQUARE BRACKET TOP # bracketrighttp (CUS) */ + { 0xF8FA, 0xFA }, /* RIGHT SQUARE BRACKET EXTENDER # bracketrightex (CUS) */ + { 0xF8FB, 0xFB }, /* RIGHT SQUARE BRACKET BOTTOM # bracketrightbt (CUS) */ + { 0xF8FC, 0xFC }, /* RIGHT CURLY BRACKET TOP # bracerighttp (CUS) */ + { 0xF8FD, 0xFD }, /* RIGHT CURLY BRACKET MID # bracerightmid (CUS) */ + { 0xF8FE, 0xFE }, /* RIGHT CURLY BRACKET BOTTOM # bracerightbt (CUS) */ +}; + +static const FcCharMap AdobeSymbol = { + AdobeSymbolEnt, + sizeof (AdobeSymbolEnt) / sizeof (AdobeSymbolEnt[0]), +}; + +static const FcFontDecode fcFontDecoders[] = { + { ft_encoding_unicode, 0, (1 << 21) - 1 }, + { ft_encoding_symbol, &AdobeSymbol, (1 << 16) - 1 }, +}; + +#define NUM_DECODE (int) (sizeof (fcFontDecoders) / sizeof (fcFontDecoders[0])) + +static const FcChar32 prefer_unicode[] = { + 0x20ac, /* EURO SIGN */ +}; + +#define NUM_PREFER_UNICODE (int) (sizeof (prefer_unicode) / sizeof (prefer_unicode[0])) + +FcChar32 +FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map) +{ + int low, high, mid; + FcChar16 bmp; + + low = 0; + high = map->nent - 1; + if (ucs4 < map->ent[low].bmp || map->ent[high].bmp < ucs4) + return ~0; + while (low <= high) + { + mid = (high + low) >> 1; + bmp = map->ent[mid].bmp; + if (ucs4 == bmp) + return (FT_ULong) map->ent[mid].encode; + if (ucs4 < bmp) + high = mid - 1; + else + low = mid + 1; + } + return ~0; +} + +FcChar32 +FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map) +{ + int i; + + for (i = 0; i < map->nent; i++) + if (map->ent[i].encode == private) + return (FcChar32) map->ent[i].bmp; + return ~0; +} + +const FcCharMap * +FcFreeTypeGetPrivateMap (FT_Encoding encoding) +{ + int i; + + for (i = 0; i < NUM_DECODE; i++) + if (fcFontDecoders[i].encoding == encoding) + return fcFontDecoders[i].map; + return 0; +} + +#include "../fc-glyphname/fcglyphname.h" + +static FcChar32 +FcHashGlyphName (const FcChar8 *name) +{ + FcChar32 h = 0; + FcChar8 c; + + while ((c = *name++)) + { + h = ((h << 1) | (h >> 31)) ^ c; + } + return h; +} + +#if HAVE_FT_HAS_PS_GLYPH_NAMES +/* + * Use Type1 glyph names for fonts which have reliable names + * and which export an Adobe Custom mapping + */ +static FcBool +FcFreeTypeUseNames (FT_Face face) +{ + FT_Int map; + + if (!FT_Has_PS_Glyph_Names (face)) + return FcFalse; + for (map = 0; map < face->num_charmaps; map++) + if (face->charmaps[map]->encoding == ft_encoding_adobe_custom) + return FcTrue; + return FcFalse; +} + +static const FcChar8 * +FcUcs4ToGlyphName (FcChar32 ucs4) +{ + int i = (int) (ucs4 % FC_GLYPHNAME_HASH); + int r = 0; + FcGlyphId gn; + + while ((gn = _fc_ucs_to_name[i]) != -1) + { + if (_fc_glyph_names[gn].ucs == ucs4) + return _fc_glyph_names[gn].name; + if (!r) + { + r = (int) (ucs4 % FC_GLYPHNAME_REHASH); + if (!r) + r = 1; + } + i += r; + if (i >= FC_GLYPHNAME_HASH) + i -= FC_GLYPHNAME_HASH; + } + return 0; +} + +static FcChar32 +FcGlyphNameToUcs4 (FcChar8 *name) +{ + FcChar32 h = FcHashGlyphName (name); + int i = (int) (h % FC_GLYPHNAME_HASH); + int r = 0; + FcGlyphId gn; + + while ((gn = _fc_name_to_ucs[i]) != -1) + { + if (!strcmp ((char *) name, (char *) _fc_glyph_names[gn].name)) + return _fc_glyph_names[gn].ucs; + if (!r) + { + r = (int) (h % FC_GLYPHNAME_REHASH); + if (!r) + r = 1; + } + i += r; + if (i >= FC_GLYPHNAME_HASH) + i -= FC_GLYPHNAME_HASH; + } + return 0xffff; +} + +/* + * Work around a bug in some FreeType versions which fail + * to correctly bounds check glyph name buffers and overwrite + * the stack. As Postscript names have a limit of 127 characters, + * this should be sufficient. + */ + +#if FC_GLYPHNAME_MAXLEN < 127 +# define FC_GLYPHNAME_BUFLEN 127 +#else +# define FC_GLYPHNAME_BUFLEN FC_GLYPHNAME_MAXLEN +#endif + +/* + * Search through a font for a glyph by name. This is + * currently a linear search as there doesn't appear to be + * any defined order within the font + */ +static FT_UInt +FcFreeTypeGlyphNameIndex (FT_Face face, const FcChar8 *name) +{ + FT_UInt gindex; + FcChar8 name_buf[FC_GLYPHNAME_BUFLEN + 2]; + + for (gindex = 0; gindex < (FT_UInt) face->num_glyphs; gindex++) + { + if (FT_Get_Glyph_Name (face, gindex, name_buf, FC_GLYPHNAME_BUFLEN+1) == 0) + if (!strcmp ((char *) name, (char *) name_buf)) + return gindex; + } + return 0; +} +#endif + +/* + * Map a UCS4 glyph to a glyph index. Use all available encoding + * tables to try and find one that works. This information is expected + * to be cached by higher levels, so performance isn't critical + */ + +FT_UInt +FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4) +{ + int initial, offset, decode; + FT_UInt glyphindex; + FcChar32 charcode; + int p; + + initial = 0; + + if (!face) + return 0; + + /* + * Find the current encoding + */ + if (face->charmap) + { + for (; initial < NUM_DECODE; initial++) + if (fcFontDecoders[initial].encoding == face->charmap->encoding) + break; + if (initial == NUM_DECODE) + initial = 0; + } + for (p = 0; p < NUM_PREFER_UNICODE; p++) + if (ucs4 == prefer_unicode[p]) + { + initial = 0; + break; + } + /* + * Check each encoding for the glyph, starting with the current one + */ + for (offset = 0; offset < NUM_DECODE; offset++) + { + decode = (initial + offset) % NUM_DECODE; + if (!face->charmap || face->charmap->encoding != fcFontDecoders[decode].encoding) + if (FT_Select_Charmap (face, fcFontDecoders[decode].encoding) != 0) + continue; + if (fcFontDecoders[decode].map) + { + charcode = FcFreeTypeUcs4ToPrivate (ucs4, fcFontDecoders[decode].map); + if (charcode == ~0U) + continue; + } + else + charcode = ucs4; + glyphindex = FT_Get_Char_Index (face, (FT_ULong) charcode); + if (glyphindex) + return glyphindex; + } +#if HAVE_FT_HAS_PS_GLYPH_NAMES + /* + * Check postscript name table if present + */ + if (FcFreeTypeUseNames (face)) + { + const FcChar8 *name = FcUcs4ToGlyphName (ucs4); + if (name) + { + glyphindex = FcFreeTypeGlyphNameIndex (face, name); + if (glyphindex) + return glyphindex; + } + } +#endif + return 0; +} + +static FcBool +FcFreeTypeCheckGlyph (FT_Face face, FcChar32 ucs4, + FT_UInt glyph, FcBlanks *blanks, + FT_Pos *advance, + FcBool using_strike) +{ + FT_Int load_flags = FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH | FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; + FT_GlyphSlot slot; + + if (using_strike) + load_flags &= ~FT_LOAD_NO_SCALE; + + /* + * When using scalable fonts, only report those glyphs + * which can be scaled; otherwise those fonts will + * only be available at some sizes, and never when + * transformed. Avoid this by simply reporting bitmap-only + * glyphs as missing + */ + if (face->face_flags & FT_FACE_FLAG_SCALABLE) + load_flags |= FT_LOAD_NO_BITMAP; + + if (FT_Load_Glyph (face, glyph, load_flags)) + return FcFalse; + + slot = face->glyph; + if (!glyph) + return FcFalse; + + *advance = slot->metrics.horiAdvance; + + switch ((int) slot->format) { + case ft_glyph_format_bitmap: + /* + * Bitmaps are assumed to be reasonable; if + * this proves to be a rash assumption, this + * code can be easily modified + */ + return FcTrue; + case ft_glyph_format_outline: + /* + * Glyphs with contours are always OK + */ + if (slot->outline.n_contours != 0) + return FcTrue; + /* + * Glyphs with no contours are only OK if + * they're members of the Blanks set specified + * in the configuration. If blanks isn't set, + * then allow any glyph to be blank + */ + if (!blanks || FcBlanksIsMember (blanks, ucs4)) + return FcTrue; + /* fall through ... */ + default: + break; + } + return FcFalse; +} + +#define APPROXIMATELY_EQUAL(x,y) (FC_ABS ((x) - (y)) <= FC_MAX (FC_ABS (x), FC_ABS (y)) / 33) + +static FcCharSet * +FcFreeTypeCharSetAndSpacingForSize (FT_Face face, FcBlanks *blanks, int *spacing, FT_Int strike_index) +{ + FcChar32 page, off, ucs4; +#ifdef CHECK + FcChar32 font_max = 0; +#endif + FcCharSet *fcs; + FcCharLeaf *leaf; + const FcCharMap *map; + int o; + int i; + FT_UInt glyph; + FT_Pos advance, advance_one = 0, advance_two = 0; + FcBool has_advance = FcFalse, fixed_advance = FcTrue, dual_advance = FcFalse; + FcBool using_strike = FcFalse; + + fcs = FcCharSetCreate (); + if (!fcs) + goto bail0; + +#if HAVE_FT_SELECT_SIZE + if (strike_index >= 0) { + if (FT_Select_Size (face, strike_index) != FT_Err_Ok) + goto bail1; + using_strike = FcTrue; + } +#endif + +#ifdef CHECK + printf ("Family %s style %s\n", face->family_name, face->style_name); +#endif + for (o = 0; o < NUM_DECODE; o++) + { + if (FT_Select_Charmap (face, fcFontDecoders[o].encoding) != 0) + continue; + map = fcFontDecoders[o].map; + if (map) + { + /* + * Non-Unicode tables are easy; there's a list of all possible + * characters + */ + for (i = 0; i < map->nent; i++) + { + ucs4 = map->ent[i].bmp; + glyph = FT_Get_Char_Index (face, map->ent[i].encode); + if (glyph && + FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks, &advance, using_strike)) + { + /* + * ignore glyphs with zero advance. They’re + * combining characters, and while their behaviour + * isn’t well defined for monospaced applications in + * Unicode, there are many fonts which include + * zero-width combining characters in otherwise + * monospaced fonts. + */ + if (advance) + { + if (!has_advance) + { + has_advance = FcTrue; + advance_one = advance; + } + else if (!APPROXIMATELY_EQUAL (advance, advance_one)) + { + if (fixed_advance) + { + dual_advance = FcTrue; + fixed_advance = FcFalse; + advance_two = advance; + } + else if (!APPROXIMATELY_EQUAL (advance, advance_two)) + dual_advance = FcFalse; + } + } + + leaf = FcCharSetFindLeafCreate (fcs, ucs4); + if (!leaf) + goto bail1; + leaf->map[(ucs4 & 0xff) >> 5] |= (1 << (ucs4 & 0x1f)); +#ifdef CHECK + if (ucs4 > font_max) + font_max = ucs4; +#endif + } + } + } + else + { + page = ~0; + leaf = NULL; + ucs4 = FT_Get_First_Char (face, &glyph); + while (glyph != 0) + { + if (FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks, &advance, using_strike)) + { + if (advance) + { + if (!has_advance) + { + has_advance = FcTrue; + advance_one = advance; + } + else if (!APPROXIMATELY_EQUAL (advance, advance_one)) + { + if (fixed_advance) + { + dual_advance = FcTrue; + fixed_advance = FcFalse; + advance_two = advance; + } + else if (!APPROXIMATELY_EQUAL (advance, advance_two)) + dual_advance = FcFalse; + } + } + + if ((ucs4 >> 8) != page) + { + page = (ucs4 >> 8); + leaf = FcCharSetFindLeafCreate (fcs, ucs4); + if (!leaf) + goto bail1; + } + off = ucs4 & 0xff; + leaf->map[off >> 5] |= (1 << (off & 0x1f)); +#ifdef CHECK + if (ucs4 > font_max) + font_max = ucs4; +#endif + } + ucs4 = FT_Get_Next_Char (face, ucs4, &glyph); + } +#ifdef CHECK + for (ucs4 = 0; ucs4 < 0x10000; ucs4++) + { + FcBool FT_Has, FC_Has; + + FT_Has = FT_Get_Char_Index (face, ucs4) != 0; + FC_Has = FcCharSetHasChar (fcs, ucs4); + if (FT_Has != FC_Has) + { + printf ("0x%08x FT says %d FC says %d\n", ucs4, FT_Has, FC_Has); + } + } +#endif + } + } +#if HAVE_FT_HAS_PS_GLYPH_NAMES + /* + * Add mapping from PS glyph names if available + */ + if (FcFreeTypeUseNames (face)) + { + FcChar8 name_buf[FC_GLYPHNAME_BUFLEN + 2]; + + for (glyph = 0; glyph < (FT_UInt) face->num_glyphs; glyph++) + { + if (FT_Get_Glyph_Name (face, glyph, name_buf, FC_GLYPHNAME_BUFLEN+1) == 0) + { + ucs4 = FcGlyphNameToUcs4 (name_buf); + if (ucs4 != 0xffff && + FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks, &advance, using_strike)) + { + if (advance) + { + if (!has_advance) + { + has_advance = FcTrue; + advance_one = advance; + } + else if (!APPROXIMATELY_EQUAL (advance, advance_one)) + { + if (fixed_advance) + { + dual_advance = FcTrue; + fixed_advance = FcFalse; + advance_two = advance; + } + else if (!APPROXIMATELY_EQUAL (advance, advance_two)) + dual_advance = FcFalse; + } + } + leaf = FcCharSetFindLeafCreate (fcs, ucs4); + if (!leaf) + goto bail1; + leaf->map[(ucs4 & 0xff) >> 5] |= (1 << (ucs4 & 0x1f)); +#ifdef CHECK + if (ucs4 > font_max) + font_max = ucs4; +#endif + } + } + } + } +#endif +#ifdef CHECK + printf ("%d glyphs %d encoded\n", (int) face->num_glyphs, FcCharSetCount (fcs)); + for (ucs4 = 0; ucs4 <= font_max; ucs4++) + { + FcBool has_char = (glyph = FcFreeTypeCharIndex (face, ucs4)) != 0; + FcBool has_bit = FcCharSetHasChar (fcs, ucs4); + + if (has_char && !has_bit) + { + if (!FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks, &advance, using_strike)) + printf ("Bitmap missing broken char 0x%x\n", ucs4); + else + printf ("Bitmap missing char 0x%x\n", ucs4); + } + else if (!has_char && has_bit) + printf ("Bitmap extra char 0x%x\n", ucs4); + } +#endif + if (fixed_advance) + *spacing = FC_MONO; + else if (dual_advance && APPROXIMATELY_EQUAL (2 * FC_MIN (advance_one, advance_two), FC_MAX (advance_one, advance_two))) + *spacing = FC_DUAL; + else + *spacing = FC_PROPORTIONAL; + return fcs; +bail1: + FcCharSetDestroy (fcs); +bail0: + return 0; +} + +FcCharSet * +FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing) +{ + FcCharSet *cs; + + /* + * Check for bitmap-only ttf fonts that are missing the glyf table. + * In that case, pick a size and look for glyphs in that size instead + */ + if (!(face->face_flags & FT_FACE_FLAG_SCALABLE) && + face->num_fixed_sizes > 0 && + FT_Get_Sfnt_Table (face, ft_sfnt_head)) + { + FT_Int strike_index = 0; + int i; + + /* Select the face closest to 16 pixels tall */ + for (i = 1; i < face->num_fixed_sizes; i++) { + if (abs (face->available_sizes[i].height - 16) < + abs (face->available_sizes[strike_index].height - 16)) + strike_index = i; + } + cs = FcFreeTypeCharSetAndSpacingForSize (face, blanks, spacing, strike_index); + } + else + cs = FcFreeTypeCharSetAndSpacingForSize (face, blanks, spacing, -1); + return cs; +} + +FcCharSet * +FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks) +{ + int spacing; + + return FcFreeTypeCharSetAndSpacing (face, blanks, &spacing); +} + + +#define TTAG_GPOS FT_MAKE_TAG( 'G', 'P', 'O', 'S' ) +#define TTAG_GSUB FT_MAKE_TAG( 'G', 'S', 'U', 'B' ) +#define TTAG_SILF FT_MAKE_TAG( 'S', 'i', 'l', 'f') + +#define OTLAYOUT_HEAD "otlayout:" +#define OTLAYOUT_HEAD_LEN 9 +#define OTLAYOUT_ID_LEN 4 +/* space + head + id */ +#define OTLAYOUT_LEN (1 + OTLAYOUT_HEAD_LEN + OTLAYOUT_ID_LEN) + +/* + * This is a bit generous; the registry has only lower case and space + * except for 'DFLT'. + */ +#define FcIsSpace(x) (040 == (x)) +#define FcIsDigit(c) (('0' <= (c) && (c) <= '9')) +#define FcIsValidScript(x) (FcIsLower(x) || FcIsUpper (x) || FcIsDigit(x) || FcIsSpace(x)) + +static void +addtag(FcChar8 *complex_, FT_ULong tag) +{ + FcChar8 tagstring[OTLAYOUT_ID_LEN + 1]; + + tagstring[0] = (FcChar8)(tag >> 24), + tagstring[1] = (FcChar8)(tag >> 16), + tagstring[2] = (FcChar8)(tag >> 8), + tagstring[3] = (FcChar8)(tag); + tagstring[4] = '\0'; + + /* skip tags which aren't alphanumeric, under the assumption that + * they're probably broken + */ + if (!FcIsValidScript(tagstring[0]) || + !FcIsValidScript(tagstring[1]) || + !FcIsValidScript(tagstring[2]) || + !FcIsValidScript(tagstring[3])) + return; + + if (*complex_ != '\0') + strcat ((char *) complex_, " "); + strcat ((char *) complex_, OTLAYOUT_HEAD); + strcat ((char *) complex_, (char *) tagstring); +} + +static int +compareulong (const void *a, const void *b) +{ + const FT_ULong *ua = (const FT_ULong *) a; + const FT_ULong *ub = (const FT_ULong *) b; + return *ua - *ub; +} + + +static int +GetScriptTags(FT_Face face, FT_ULong tabletag, FT_ULong **stags) +{ + FT_ULong cur_offset, new_offset, base_offset; + FT_Stream stream = face->stream; + FT_Error error; + FT_UShort n, p; + int script_count; + + if (!stream) + return 0; + + if (( error = ftglue_face_goto_table( face, tabletag, stream ) )) + return 0; + + base_offset = ftglue_stream_pos ( stream ); + + /* skip version */ + + if ( ftglue_stream_seek ( stream, base_offset + 4L ) || ftglue_stream_frame_enter( stream, 2L ) ) + return 0; + + new_offset = GET_UShort() + base_offset; + + ftglue_stream_frame_exit( stream ); + + cur_offset = ftglue_stream_pos( stream ); + + if ( ftglue_stream_seek( stream, new_offset ) != FT_Err_Ok ) + return 0; + + base_offset = ftglue_stream_pos( stream ); + + if ( ftglue_stream_frame_enter( stream, 2L ) ) + return 0; + + script_count = GET_UShort (); + + ftglue_stream_frame_exit( stream ); + + *stags = malloc(script_count * sizeof (FT_ULong)); + if (!stags) + return 0; + + p = 0; + for ( n = 0; n < script_count; n++ ) + { + if ( ftglue_stream_frame_enter( stream, 6L ) ) + goto Fail; + + (*stags)[p] = GET_ULong (); + new_offset = GET_UShort () + base_offset; + + ftglue_stream_frame_exit( stream ); + + cur_offset = ftglue_stream_pos( stream ); + + error = ftglue_stream_seek( stream, new_offset ); + + if ( error == FT_Err_Ok ) + p++; + + (void)ftglue_stream_seek( stream, cur_offset ); + } + + if (!p) + goto Fail; + + /* sort the tag list before returning it */ + qsort(*stags, script_count, sizeof(FT_ULong), compareulong); + + return script_count; + +Fail: + free(*stags); + *stags = NULL; + return 0; +} + +static FcChar8 * +FcFontCapabilities(FT_Face face) +{ + FcBool issilgraphitefont = 0; + FT_Error err; + FT_ULong len = 0; + FT_ULong *gsubtags=NULL, *gpostags=NULL; + FT_UShort gsub_count=0, gpos_count=0; + FT_ULong maxsize; + FcChar8 *complex_ = NULL; + int indx1 = 0, indx2 = 0; + + err = FT_Load_Sfnt_Table(face, TTAG_SILF, 0, 0, &len); + issilgraphitefont = ( err == FT_Err_Ok); + + gpos_count = GetScriptTags(face, TTAG_GPOS, &gpostags); + gsub_count = GetScriptTags(face, TTAG_GSUB, &gsubtags); + + if (!issilgraphitefont && !gsub_count && !gpos_count) + goto bail; + + maxsize = (((FT_ULong) gpos_count + (FT_ULong) gsub_count) * OTLAYOUT_LEN + + (issilgraphitefont ? 13 : 0)); + complex_ = malloc (sizeof (FcChar8) * maxsize); + if (!complex_) + goto bail; + + complex_[0] = '\0'; + if (issilgraphitefont) + strcpy((char *) complex_, "ttable:Silf "); + + while ((indx1 < gsub_count) || (indx2 < gpos_count)) { + if (indx1 == gsub_count) { + addtag(complex_, gpostags[indx2]); + indx2++; + } else if ((indx2 == gpos_count) || (gsubtags[indx1] < gpostags[indx2])) { + addtag(complex_, gsubtags[indx1]); + indx1++; + } else if (gsubtags[indx1] == gpostags[indx2]) { + addtag(complex_, gsubtags[indx1]); + indx1++; + indx2++; + } else { + addtag(complex_, gpostags[indx2]); + indx2++; + } + } + if (FcDebug () & FC_DBG_SCANV) + printf("complex_ features in this font: %s\n", complex_); +bail: + free(gsubtags); + free(gpostags); + return complex_; +} + +#define __fcfreetype__ +#include "fcaliastail.h" +#include "fcftaliastail.h" +#undef __fcfreetype__ diff --git a/project/jni/fontconfig/src/fcfs.c b/project/jni/fontconfig/src/fcfs.c new file mode 100644 index 000000000..21c6c7cbb --- /dev/null +++ b/project/jni/fontconfig/src/fcfs.c @@ -0,0 +1,149 @@ +/* + * fontconfig/src/fcfs.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include + +FcFontSet * +FcFontSetCreate (void) +{ + FcFontSet *s; + + s = (FcFontSet *) malloc (sizeof (FcFontSet)); + if (!s) + return 0; + s->nfont = 0; + s->sfont = 0; + s->fonts = 0; + return s; +} + +void +FcFontSetDestroy (FcFontSet *s) +{ + int i; + + for (i = 0; i < s->nfont; i++) + FcPatternDestroy (s->fonts[i]); + if (s->fonts) + free (s->fonts); + free (s); +} + +FcBool +FcFontSetAdd (FcFontSet *s, FcPattern *font) +{ + FcPattern **f; + int sfont; + + if (s->nfont == s->sfont) + { + sfont = s->sfont + 32; + if (s->fonts) + f = (FcPattern **) realloc (s->fonts, sfont * sizeof (FcPattern *)); + else + f = (FcPattern **) malloc (sfont * sizeof (FcPattern *)); + if (!f) + return FcFalse; + s->sfont = sfont; + s->fonts = f; + } + s->fonts[s->nfont++] = font; + return FcTrue; +} + +FcBool +FcFontSetSerializeAlloc (FcSerialize *serialize, const FcFontSet *s) +{ + int i; + + if (!FcSerializeAlloc (serialize, s, sizeof (FcFontSet))) + return FcFalse; + if (!FcSerializeAlloc (serialize, s->fonts, s->nfont * sizeof (FcPattern *))) + return FcFalse; + for (i = 0; i < s->nfont; i++) + { + if (!FcPatternSerializeAlloc (serialize, s->fonts[i])) + return FcFalse; + } + return FcTrue; +} + +FcFontSet * +FcFontSetSerialize (FcSerialize *serialize, const FcFontSet * s) +{ + int i; + FcFontSet *s_serialize; + FcPattern **fonts_serialize; + FcPattern *p_serialize; + + s_serialize = FcSerializePtr (serialize, s); + if (!s_serialize) + return NULL; + *s_serialize = *s; + s_serialize->sfont = s_serialize->nfont; + + fonts_serialize = FcSerializePtr (serialize, s->fonts); + if (!fonts_serialize) + return NULL; + s_serialize->fonts = FcPtrToEncodedOffset (s_serialize, + fonts_serialize, FcPattern *); + + for (i = 0; i < s->nfont; i++) + { + p_serialize = FcPatternSerialize (serialize, s->fonts[i]); + if (!p_serialize) + return NULL; + fonts_serialize[i] = FcPtrToEncodedOffset (s_serialize, + p_serialize, + FcPattern); + } + + return s_serialize; +} + +FcFontSet * +FcFontSetDeserialize (const FcFontSet *set) +{ + int i; + FcFontSet *new = FcFontSetCreate (); + + if (!new) + return NULL; + for (i = 0; i < set->nfont; i++) + { + if (!FcFontSetAdd (new, FcPatternDuplicate (FcFontSetFont (set, i)))) + goto bail; + } + + return new; +bail: + FcFontSetDestroy (new); + + return NULL; +} + +#define __fcfs__ +#include "fcaliastail.h" +#undef __fcfs__ diff --git a/project/jni/fontconfig/src/fcftalias.h b/project/jni/fontconfig/src/fcftalias.h new file mode 100644 index 000000000..884eb4b2e --- /dev/null +++ b/project/jni/fontconfig/src/fcftalias.h @@ -0,0 +1,12 @@ +extern __typeof (FcFreeTypeCharIndex) IA__FcFreeTypeCharIndex __attribute((visibility("hidden"))); +#define FcFreeTypeCharIndex IA__FcFreeTypeCharIndex +extern __typeof (FcFreeTypeCharSetAndSpacing) IA__FcFreeTypeCharSetAndSpacing __attribute((visibility("hidden"))); +#define FcFreeTypeCharSetAndSpacing IA__FcFreeTypeCharSetAndSpacing +extern __typeof (FcFreeTypeCharSet) IA__FcFreeTypeCharSet __attribute((visibility("hidden"))); +#define FcFreeTypeCharSet IA__FcFreeTypeCharSet +extern __typeof (FcPatternGetFTFace) IA__FcPatternGetFTFace __attribute((visibility("hidden"))); +#define FcPatternGetFTFace IA__FcPatternGetFTFace +extern __typeof (FcPatternAddFTFace) IA__FcPatternAddFTFace __attribute((visibility("hidden"))); +#define FcPatternAddFTFace IA__FcPatternAddFTFace +extern __typeof (FcFreeTypeQueryFace) IA__FcFreeTypeQueryFace __attribute((visibility("hidden"))); +#define FcFreeTypeQueryFace IA__FcFreeTypeQueryFace diff --git a/project/jni/fontconfig/src/fcftaliastail.h b/project/jni/fontconfig/src/fcftaliastail.h new file mode 100644 index 000000000..f5a537d9c --- /dev/null +++ b/project/jni/fontconfig/src/fcftaliastail.h @@ -0,0 +1,20 @@ +#if HAVE_GNUC_ATTRIBUTE +#ifdef __fcfreetype__ +# undef FcFreeTypeCharIndex +extern __typeof (FcFreeTypeCharIndex) FcFreeTypeCharIndex __attribute((alias("IA__FcFreeTypeCharIndex"), visibility("default"))); +# undef FcFreeTypeCharSetAndSpacing +extern __typeof (FcFreeTypeCharSetAndSpacing) FcFreeTypeCharSetAndSpacing __attribute((alias("IA__FcFreeTypeCharSetAndSpacing"), visibility("default"))); +# undef FcFreeTypeCharSet +extern __typeof (FcFreeTypeCharSet) FcFreeTypeCharSet __attribute((alias("IA__FcFreeTypeCharSet"), visibility("default"))); +#endif /* __fcfreetype__ */ +#ifdef __fcpat__ +# undef FcPatternGetFTFace +extern __typeof (FcPatternGetFTFace) FcPatternGetFTFace __attribute((alias("IA__FcPatternGetFTFace"), visibility("default"))); +# undef FcPatternAddFTFace +extern __typeof (FcPatternAddFTFace) FcPatternAddFTFace __attribute((alias("IA__FcPatternAddFTFace"), visibility("default"))); +#endif /* __fcpat__ */ +#ifdef __fcfreetype__ +# undef FcFreeTypeQueryFace +extern __typeof (FcFreeTypeQueryFace) FcFreeTypeQueryFace __attribute((alias("IA__FcFreeTypeQueryFace"), visibility("default"))); +#endif /* */ +#endif /* HAVE_GNUC_ATTRIBUTE */ diff --git a/project/jni/fontconfig/src/fcftint.h b/project/jni/fontconfig/src/fcftint.h new file mode 100644 index 000000000..a317370e1 --- /dev/null +++ b/project/jni/fontconfig/src/fcftint.h @@ -0,0 +1,54 @@ +/* + * Copyright © 2007 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _FCFTINT_H_ +#define _FCFTINT_H_ + +#include + +#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun) +#define FcPrivate __attribute__((__visibility__("hidden"))) +#define HAVE_GNUC_ATTRIBUTE 1 +#include "fcftalias.h" +#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) +#define FcPrivate __hidden +#else /* not gcc >= 3.3 and not Sun Studio >= 8 */ +#define FcPrivate +#endif + +/* fcfreetype.c */ +FcPrivate FcBool +FcFreeTypeIsExclusiveLang (const FcChar8 *lang); + +FcPrivate FcBool +FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang); + +FcPrivate FcChar32 +FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map); + +FcPrivate FcChar32 +FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map); + +FcPrivate const FcCharMap * +FcFreeTypeGetPrivateMap (FT_Encoding encoding); + +#endif /* _FCFTINT_H_ */ diff --git a/project/jni/fontconfig/src/fchash.c b/project/jni/fontconfig/src/fchash.c new file mode 100644 index 000000000..38300028c --- /dev/null +++ b/project/jni/fontconfig/src/fchash.c @@ -0,0 +1,317 @@ +/* + * fontconfig/src/fchash.c + * + * Copyright © 2003 Keith Packard + * Copyright © 2013 Red Hat, Inc. + * Red Hat Author(s): Akira TAGOH + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ +#include "fcint.h" +#include +#include + +#define ROTRN(w, v, n) ((((FcChar32)v) >> n) | (((FcChar32)v) << (w - n))) +#define ROTR32(v, n) ROTRN(32, v, n) +#define SHR(v, n) (v >> n) +#define Ch(x, y, z) ((x & y) ^ (~x & z)) +#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) +#define SS0(x) (ROTR32(x, 2) ^ ROTR32(x, 13) ^ ROTR32(x, 22)) +#define SS1(x) (ROTR32(x, 6) ^ ROTR32(x, 11) ^ ROTR32(x, 25)) +#define ss0(x) (ROTR32(x, 7) ^ ROTR32(x, 18) ^ SHR(x, 3)) +#define ss1(x) (ROTR32(x, 17) ^ ROTR32(x, 19) ^ SHR(x, 10)) + + +static FcChar32 * +FcHashInitSHA256Digest (void) +{ + int i; + static const FcChar32 h[] = { + 0x6a09e667UL, 0xbb67ae85UL, 0x3c6ef372UL, 0xa54ff53aUL, + 0x510e527fUL, 0x9b05688cUL, 0x1f83d9abUL, 0x5be0cd19UL + }; + FcChar32 *ret = malloc (sizeof (FcChar32) * 8); + + if (!ret) + return NULL; + + for (i = 0; i < 8; i++) + ret[i] = h[i]; + + return ret; +} + +static void +FcHashComputeSHA256Digest (FcChar32 *hash, + const char *block) +{ + static const FcChar32 k[] = { + 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, + 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, + 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, + 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL, + 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, + 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, + 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, + 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL, + 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL, + 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, + 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, + 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, + 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL, + 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL, + 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, + 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL + }; + FcChar32 w[64], i, j, t1, t2; + FcChar32 a, b, c, d, e, f, g, h; + +#define H(n) (hash[n]) + + a = H(0); + b = H(1); + c = H(2); + d = H(3); + e = H(4); + f = H(5); + g = H(6); + h = H(7); + + for (i = 0; i < 16; i++) + { + j = (block[(i * 4) + 0] & 0xff) << (8 * 3); + j |= (block[(i * 4) + 1] & 0xff) << (8 * 2); + j |= (block[(i * 4) + 2] & 0xff) << (8 * 1); + j |= (block[(i * 4) + 3] & 0xff); + w[i] = j; + } + for (i = 16; i < 64; i++) + w[i] = ss1(w[i - 2]) + w[i - 7] + ss0(w[i - 15]) + w[i - 16]; + + for (i = 0; i < 64; i++) + { + t1 = h + SS1(e) + Ch(e, f, g) + k[i] + w[i]; + t2 = SS0(a) + Maj(a, b, c); + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + } + + H(0) += a; + H(1) += b; + H(2) += c; + H(3) += d; + H(4) += e; + H(5) += f; + H(6) += g; + H(7) += h; + +#undef H +} + +static FcChar8 * +FcHashSHA256ToString (FcChar32 *hash) +{ + FcChar8 *ret = NULL; + static const char hex[] = "0123456789abcdef"; + int i, j; + + if (hash) + { + ret = malloc (sizeof (FcChar8) * (8 * 8 + 7 + 1)); + if (!ret) + return NULL; + memcpy (ret, "sha256:", 7); +#define H(n) hash[n] + for (i = 0; i < 8; i++) + { + FcChar32 v = H(i); + + for (j = 0; j < 8; j++) + ret[7 + (i * 8) + j] = hex[(v >> (28 - j * 4)) & 0xf]; + } + ret[7 + i * 8] = 0; +#undef H + free (hash); + } + + return ret; +} + +FcChar8 * +FcHashGetSHA256Digest (const FcChar8 *input_strings, + size_t len) +{ + size_t i, round_len = len / 64; + char block[64]; + FcChar32 *ret = FcHashInitSHA256Digest (); + + if (!ret) + return NULL; + + for (i = 0; i < round_len; i++) + { + FcHashComputeSHA256Digest (ret, (const char *)&input_strings[i * 64]); + } + /* padding */ + if ((len % 64) != 0) + memcpy (block, &input_strings[len / 64], len % 64); + memset (&block[len % 64], 0, 64 - (len % 64)); + block[len % 64] = 0x80; + if ((64 - (len % 64)) < 9) + { + /* process a block once */ + FcHashComputeSHA256Digest (ret, block); + memset (block, 0, 64); + } + /* set input size at the end */ + len *= 8; + block[63 - 0] = (uint64_t)len & 0xff; + block[63 - 1] = ((uint64_t)len >> 8) & 0xff; + block[63 - 2] = ((uint64_t)len >> 16) & 0xff; + block[63 - 3] = ((uint64_t)len >> 24) & 0xff; + block[63 - 4] = ((uint64_t)len >> 32) & 0xff; + block[63 - 5] = ((uint64_t)len >> 40) & 0xff; + block[63 - 6] = ((uint64_t)len >> 48) & 0xff; + block[63 - 7] = ((uint64_t)len >> 56) & 0xff; + FcHashComputeSHA256Digest (ret, block); + + return FcHashSHA256ToString (ret); +} + +FcChar8 * +FcHashGetSHA256DigestFromFile (const FcChar8 *filename) +{ + FILE *fp = fopen ((const char *)filename, "rb"); + char ibuf[64]; + FcChar32 *ret; + size_t len; + struct stat st; + + if (!fp) + return NULL; + + if (FcStat (filename, &st)) + goto bail0; + + ret = FcHashInitSHA256Digest (); + if (!ret) + goto bail0; + + while (!feof (fp)) + { + if ((len = fread (ibuf, sizeof (char), 64, fp)) < 64) + { + uint64_t v; + + /* add a padding */ + memset (&ibuf[len], 0, 64 - len); + ibuf[len] = 0x80; + if ((64 - len) < 9) + { + /* process a block once */ + FcHashComputeSHA256Digest (ret, ibuf); + memset (ibuf, 0, 64); + } + /* set input size at the end */ + v = (long)st.st_size * 8; + ibuf[63 - 0] = v & 0xff; + ibuf[63 - 1] = (v >> 8) & 0xff; + ibuf[63 - 2] = (v >> 16) & 0xff; + ibuf[63 - 3] = (v >> 24) & 0xff; + ibuf[63 - 4] = (v >> 32) & 0xff; + ibuf[63 - 5] = (v >> 40) & 0xff; + ibuf[63 - 6] = (v >> 48) & 0xff; + ibuf[63 - 7] = (v >> 56) & 0xff; + FcHashComputeSHA256Digest (ret, ibuf); + break; + } + else + { + FcHashComputeSHA256Digest (ret, ibuf); + } + } + fclose (fp); + + return FcHashSHA256ToString (ret); + +bail0: + fclose (fp); + + return NULL; +} + +FcChar8 * +FcHashGetSHA256DigestFromMemory (const char *fontdata, + size_t length) +{ + char ibuf[64]; + FcChar32 *ret; + size_t i = 0; + + ret = FcHashInitSHA256Digest (); + if (!ret) + return NULL; + + while (i <= length) + { + if ((length - i) < 64) + { + uint64_t v; + size_t n; + + /* add a padding */ + n = length - i; + if (n > 0) + memcpy (ibuf, &fontdata[i], n); + memset (&ibuf[n], 0, 64 - n); + ibuf[n] = 0x80; + if ((64 - n) < 9) + { + /* process a block once */ + FcHashComputeSHA256Digest (ret, ibuf); + memset (ibuf, 0, 64); + } + /* set input size at the end */ + v = length * 8; + ibuf[63 - 0] = v & 0xff; + ibuf[63 - 1] = (v >> 8) & 0xff; + ibuf[63 - 2] = (v >> 16) & 0xff; + ibuf[63 - 3] = (v >> 24) & 0xff; + ibuf[63 - 4] = (v >> 32) & 0xff; + ibuf[63 - 5] = (v >> 40) & 0xff; + ibuf[63 - 6] = (v >> 48) & 0xff; + ibuf[63 - 7] = (v >> 56) & 0xff; + FcHashComputeSHA256Digest (ret, ibuf); + break; + } + else + { + FcHashComputeSHA256Digest (ret, &fontdata[i]); + } + i += 64; + } + + return FcHashSHA256ToString (ret); +} diff --git a/project/jni/fontconfig/src/fcinit.c b/project/jni/fontconfig/src/fcinit.c new file mode 100644 index 000000000..b8d5d060c --- /dev/null +++ b/project/jni/fontconfig/src/fcinit.c @@ -0,0 +1,215 @@ +/* + * fontconfig/src/fcinit.c + * + * Copyright © 2001 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include + +#if defined(FC_ATOMIC_INT_NIL) +#pragma message("Could not find any system to define atomic_int macros, library may NOT be thread-safe.") +#endif +#if defined(FC_MUTEX_IMPL_NIL) +#pragma message("Could not find any system to define mutex macros, library may NOT be thread-safe.") +#endif +#if defined(FC_ATOMIC_INT_NIL) || defined(FC_MUTEX_IMPL_NIL) +#pragma message("To suppress these warnings, define FC_NO_MT.") +#endif + +static FcConfig * +FcInitFallbackConfig (void) +{ + FcConfig *config; + + config = FcConfigCreate (); + if (!config) + goto bail0; + if (!FcConfigAddDir (config, (FcChar8 *) FC_DEFAULT_FONTS)) + goto bail1; + if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR)) + goto bail1; + return config; + +bail1: + FcConfigDestroy (config); +bail0: + return 0; +} + +int +FcGetVersion (void) +{ + return FC_VERSION; +} + +/* + * Load the configuration files + */ +FcConfig * +FcInitLoadOwnConfig (FcConfig *config) +{ + if (!config) + { + config = FcConfigCreate (); + if (!config) + return NULL; + } + + FcInitDebug (); + + if (!FcConfigParseAndLoad (config, 0, FcTrue)) + { + FcConfigDestroy (config); + return FcInitFallbackConfig (); + } + + if (config->cacheDirs && config->cacheDirs->num == 0) + { + FcChar8 *prefix, *p; + size_t plen; + + fprintf (stderr, + "Fontconfig warning: no elements found. Check configuration.\n"); + fprintf (stderr, + "Fontconfig warning: adding %s\n", + FC_CACHEDIR); + prefix = FcConfigXdgCacheHome (); + if (!prefix) + goto bail; + plen = strlen ((const char *)prefix); + p = realloc (prefix, plen + 12); + if (!p) + goto bail; + prefix = p; + memcpy (&prefix[plen], FC_DIR_SEPARATOR_S "fontconfig", 11); + prefix[plen + 11] = 0; + fprintf (stderr, + "Fontconfig warning: adding fontconfig\n"); + + if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR) || + !FcConfigAddCacheDir (config, (FcChar8 *) prefix)) + { + bail: + fprintf (stderr, + "Fontconfig error: out of memory"); + if (prefix) + FcStrFree (prefix); + FcConfigDestroy (config); + return FcInitFallbackConfig (); + } + FcStrFree (prefix); + } + + return config; +} + +FcConfig * +FcInitLoadConfig (void) +{ + return FcInitLoadOwnConfig (NULL); +} + +/* + * Load the configuration files and scan for available fonts + */ +FcConfig * +FcInitLoadOwnConfigAndFonts (FcConfig *config) +{ + config = FcInitLoadOwnConfig (config); + if (!config) + return 0; + if (!FcConfigBuildFonts (config)) + { + FcConfigDestroy (config); + return 0; + } + return config; +} + +FcConfig * +FcInitLoadConfigAndFonts (void) +{ + return FcInitLoadOwnConfigAndFonts (NULL); +} + +/* + * Initialize the default library configuration + */ +FcBool +FcInit (void) +{ + return FcConfigInit (); +} + +/* + * Free all library-allocated data structures. + */ +void +FcFini (void) +{ + FcConfigFini (); + FcCacheFini (); + FcDefaultFini (); +} + +/* + * Reread the configuration and available font lists + */ +FcBool +FcInitReinitialize (void) +{ + FcConfig *config; + + config = FcInitLoadConfigAndFonts (); + if (!config) + return FcFalse; + return FcConfigSetCurrent (config); +} + +FcBool +FcInitBringUptoDate (void) +{ + FcConfig *config = FcConfigGetCurrent (); + time_t now; + + /* + * rescanInterval == 0 disables automatic up to date + */ + if (config->rescanInterval == 0) + return FcTrue; + /* + * Check no more often than rescanInterval seconds + */ + now = time (0); + if (config->rescanTime + config->rescanInterval - now > 0) + return FcTrue; + /* + * If up to date, don't reload configuration + */ + if (FcConfigUptoDate (0)) + return FcTrue; + return FcInitReinitialize (); +} + +#define __fcinit__ +#include "fcaliastail.h" +#undef __fcinit__ diff --git a/project/jni/fontconfig/src/fcint.h b/project/jni/fontconfig/src/fcint.h new file mode 100644 index 000000000..cdf2daba0 --- /dev/null +++ b/project/jni/fontconfig/src/fcint.h @@ -0,0 +1,1168 @@ +/* + * fontconfig/src/fcint.h + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _FCINT_H_ +#define _FCINT_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "fcstdint.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "fcdeprecate.h" +#include "fcmutex.h" +#include "fcatomic.h" + +#ifndef FC_CONFIG_PATH +#define FC_CONFIG_PATH "fonts.conf" +#endif + +#ifdef _WIN32 +# include "fcwindows.h" +typedef UINT (WINAPI *pfnGetSystemWindowsDirectory)(LPSTR, UINT); +typedef HRESULT (WINAPI *pfnSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR); +extern pfnGetSystemWindowsDirectory pGetSystemWindowsDirectory; +extern pfnSHGetFolderPathA pSHGetFolderPathA; +# define FC_SEARCH_PATH_SEPARATOR ';' +# define FC_DIR_SEPARATOR '\\' +# define FC_DIR_SEPARATOR_S "\\" +#else +# define FC_SEARCH_PATH_SEPARATOR ':' +# define FC_DIR_SEPARATOR '/' +# define FC_DIR_SEPARATOR_S "/" +#endif + +#if __GNUC__ >= 4 +#define FC_UNUSED __attribute__((unused)) +#else +#define FC_UNUSED +#endif + +#define FC_DBG_MATCH 1 +#define FC_DBG_MATCHV 2 +#define FC_DBG_EDIT 4 +#define FC_DBG_FONTSET 8 +#define FC_DBG_CACHE 16 +#define FC_DBG_CACHEV 32 +#define FC_DBG_PARSE 64 +#define FC_DBG_SCAN 128 +#define FC_DBG_SCANV 256 +#define FC_DBG_CONFIG 1024 +#define FC_DBG_LANGSET 2048 + +#define _FC_ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] FC_UNUSED +#define _FC_ASSERT_STATIC0(_line, _cond) _FC_ASSERT_STATIC1 (_line, (_cond)) +#define FC_ASSERT_STATIC(_cond) _FC_ASSERT_STATIC0 (__LINE__, (_cond)) + +#define FC_MIN(a,b) ((a) < (b) ? (a) : (b)) +#define FC_MAX(a,b) ((a) > (b) ? (a) : (b)) +#define FC_ABS(a) ((a) < 0 ? -(a) : (a)) + +/* slim_internal.h */ +#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun) +#define FcPrivate __attribute__((__visibility__("hidden"))) +#define HAVE_GNUC_ATTRIBUTE 1 +#include "fcalias.h" +#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) +#define FcPrivate __hidden +#else /* not gcc >= 3.3 and not Sun Studio >= 8 */ +#define FcPrivate +#endif + +FC_ASSERT_STATIC (sizeof (FcRef) == sizeof (int)); + +typedef enum _FcValueBinding { + FcValueBindingWeak, FcValueBindingStrong, FcValueBindingSame, + /* to make sure sizeof (FcValueBinding) == 4 even with -fshort-enums */ + FcValueBindingEnd = INT_MAX +} FcValueBinding; + +#define FcStrdup(s) ((FcChar8 *) strdup ((const char *) (s))) +#define FcFree(s) (free ((FcChar8 *) (s))) + +/* + * Serialized data structures use only offsets instead of pointers + * A low bit of 1 indicates an offset. + */ + +/* Is the provided pointer actually an offset? */ +#define FcIsEncodedOffset(p) ((((intptr_t) (p)) & 1) != 0) + +/* Encode offset in a pointer of type t */ +#define FcOffsetEncode(o,t) ((t *) ((o) | 1)) + +/* Decode a pointer into an offset */ +#define FcOffsetDecode(p) (((intptr_t) (p)) & ~1) + +/* Compute pointer offset */ +#define FcPtrToOffset(b,p) ((intptr_t) (p) - (intptr_t) (b)) + +/* Given base address, offset and type, return a pointer */ +#define FcOffsetToPtr(b,o,t) ((t *) ((intptr_t) (b) + (o))) + +/* Given base address, encoded offset and type, return a pointer */ +#define FcEncodedOffsetToPtr(b,p,t) FcOffsetToPtr(b,FcOffsetDecode(p),t) + +/* Given base address, pointer and type, return an encoded offset */ +#define FcPtrToEncodedOffset(b,p,t) FcOffsetEncode(FcPtrToOffset(b,p),t) + +/* Given a structure, offset member and type, return pointer */ +#define FcOffsetMember(s,m,t) FcOffsetToPtr(s,(s)->m,t) + +/* Given a structure, encoded offset member and type, return pointer to member */ +#define FcEncodedOffsetMember(s,m,t) FcOffsetToPtr(s,FcOffsetDecode((s)->m), t) + +/* Given a structure, member and type, convert the member to a pointer */ +#define FcPointerMember(s,m,t) (FcIsEncodedOffset((s)->m) ? \ + FcEncodedOffsetMember (s,m,t) : \ + (s)->m) + +/* + * Serialized values may hold strings, charsets and langsets as pointers, + * unfortunately FcValue is an exposed type so we can't just always use + * offsets + */ +#define FcValueString(v) FcPointerMember(v,u.s,FcChar8) +#define FcValueCharSet(v) FcPointerMember(v,u.c,const FcCharSet) +#define FcValueLangSet(v) FcPointerMember(v,u.l,const FcLangSet) + +typedef struct _FcValueList *FcValueListPtr; + +typedef struct _FcValueList { + struct _FcValueList *next; + FcValue value; + FcValueBinding binding; +} FcValueList; + +#define FcValueListNext(vl) FcPointerMember(vl,next,FcValueList) + +typedef int FcObject; + +/* The 1024 is to leave some room for future added internal objects, such + * that caches from newer fontconfig can still be used with older fontconfig + * without getting confused. */ +#define FC_EXT_OBJ_INDEX 1024 +#define FC_OBJ_ID(_n_) ((_n_) & (~FC_EXT_OBJ_INDEX)) + +typedef struct _FcPatternElt *FcPatternEltPtr; + +/* + * Pattern elts are stuck in a structure connected to the pattern, + * so they get moved around when the pattern is resized. Hence, the + * values field must be a pointer/offset instead of just an offset + */ +typedef struct _FcPatternElt { + FcObject object; + FcValueList *values; +} FcPatternElt; + +#define FcPatternEltValues(pe) FcPointerMember(pe,values,FcValueList) + +struct _FcPattern { + int num; + int size; + intptr_t elts_offset; + FcRef ref; +}; + +#define FcPatternElts(p) FcOffsetMember(p,elts_offset,FcPatternElt) + +#define FcFontSetFonts(fs) FcPointerMember(fs,fonts,FcPattern *) + +#define FcFontSetFont(fs,i) (FcIsEncodedOffset((fs)->fonts) ? \ + FcEncodedOffsetToPtr(fs, \ + FcFontSetFonts(fs)[i], \ + FcPattern) : \ + fs->fonts[i]) + +typedef enum _FcOp { + FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpRange, FcOpBool, FcOpCharSet, FcOpLangSet, + FcOpNil, + FcOpField, FcOpConst, + FcOpAssign, FcOpAssignReplace, + FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast, + FcOpDelete, FcOpDeleteAll, + FcOpQuest, + FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual, + FcOpContains, FcOpListing, FcOpNotContains, + FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual, + FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide, + FcOpNot, FcOpComma, FcOpFloor, FcOpCeil, FcOpRound, FcOpTrunc, + FcOpInvalid +} FcOp; + +typedef enum _FcOpFlags { + FcOpFlagIgnoreBlanks = 1 << 0 +} FcOpFlags; + +#define FC_OP_GET_OP(_x_) ((_x_) & 0xffff) +#define FC_OP_GET_FLAGS(_x_) (((_x_) & 0xffff0000) >> 16) +#define FC_OP(_x_,_f_) (FC_OP_GET_OP (_x_) | ((_f_) << 16)) + +typedef struct _FcExprMatrix { + struct _FcExpr *xx, *xy, *yx, *yy; +} FcExprMatrix; + +typedef struct _FcExprName { + FcObject object; + FcMatchKind kind; +} FcExprName; + + +typedef struct _FcExpr { + FcOp op; + union { + int ival; + double dval; + const FcChar8 *sval; + FcExprMatrix *mexpr; + FcBool bval; + FcCharSet *cval; + FcLangSet *lval; + + FcExprName name; + const FcChar8 *constant; + struct { + struct _FcExpr *left, *right; + } tree; + } u; +} FcExpr; + +typedef struct _FcExprPage FcExprPage; + +struct _FcExprPage { + FcExprPage *next_page; + FcExpr *next; + FcExpr exprs[(1024 - 2/* two pointers */ - 2/* malloc overhead */) * sizeof (void *) / sizeof (FcExpr)]; + FcExpr end[FLEXIBLE_ARRAY_MEMBER]; +}; + +typedef enum _FcQual { + FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst +} FcQual; + +#define FcMatchDefault ((FcMatchKind) -1) + +typedef struct _FcTest { + FcMatchKind kind; + FcQual qual; + FcObject object; + FcOp op; + FcExpr *expr; +} FcTest; + +typedef struct _FcEdit { + FcObject object; + FcOp op; + FcExpr *expr; + FcValueBinding binding; +} FcEdit; + +typedef enum _FcRuleType { + FcRuleUnknown, FcRuleTest, FcRuleEdit +} FcRuleType; + +typedef struct _FcRule { + struct _FcRule *next; + FcRuleType type; + union { + FcTest *test; + FcEdit *edit; + } u; +} FcRule; + +typedef struct _FcSubst { + struct _FcSubst *next; + FcRule *rule; +} FcSubst; + +typedef struct _FcCharLeaf { + FcChar32 map[256/32]; +} FcCharLeaf; + +struct _FcCharSet { + FcRef ref; /* reference count */ + int num; /* size of leaves and numbers arrays */ + intptr_t leaves_offset; + intptr_t numbers_offset; +}; + +#define FcCharSetLeaves(c) FcOffsetMember(c,leaves_offset,intptr_t) +#define FcCharSetLeaf(c,i) (FcOffsetToPtr(FcCharSetLeaves(c), \ + FcCharSetLeaves(c)[i], \ + FcCharLeaf)) +#define FcCharSetNumbers(c) FcOffsetMember(c,numbers_offset,FcChar16) + +struct _FcStrSet { + FcRef ref; /* reference count */ + int num; + int size; + FcChar8 **strs; +}; + +struct _FcStrList { + FcStrSet *set; + int n; +}; + +typedef struct _FcStrBuf { + FcChar8 *buf; + FcBool allocated; + FcBool failed; + int len; + int size; + FcChar8 buf_static[16 * sizeof (void *)]; +} FcStrBuf; + +struct _FcCache { + unsigned int magic; /* FC_CACHE_MAGIC_MMAP or FC_CACHE_ALLOC */ + int version; /* FC_CACHE_CONTENT_VERSION */ + intptr_t size; /* size of file */ + intptr_t dir; /* offset to dir name */ + intptr_t dirs; /* offset to subdirs */ + int dirs_count; /* number of subdir strings */ + intptr_t set; /* offset to font set */ + int checksum; /* checksum of directory state */ +}; + +#undef FcCacheDir +#undef FcCacheSubdir +#define FcCacheDir(c) FcOffsetMember(c,dir,FcChar8) +#define FcCacheDirs(c) FcOffsetMember(c,dirs,intptr_t) +#define FcCacheSet(c) FcOffsetMember(c,set,FcFontSet) +#define FcCacheSubdir(c,i) FcOffsetToPtr (FcCacheDirs(c),\ + FcCacheDirs(c)[i], \ + FcChar8) + +/* + * Used while constructing a directory cache object + */ + +#define FC_SERIALIZE_HASH_SIZE 8191 + +typedef union _FcAlign { + double d; + int i; + intptr_t ip; + FcBool b; + void *p; +} FcAlign; + +typedef struct _FcSerializeBucket { + struct _FcSerializeBucket *next; + const void *object; + intptr_t offset; +} FcSerializeBucket; + +typedef struct _FcCharSetFreezer FcCharSetFreezer; + +typedef struct _FcSerialize { + intptr_t size; + FcCharSetFreezer *cs_freezer; + void *linear; + FcSerializeBucket *buckets[FC_SERIALIZE_HASH_SIZE]; +} FcSerialize; + +/* + * To map adobe glyph names to unicode values, a precomputed hash + * table is used + */ + +typedef struct _FcGlyphName { + FcChar32 ucs; /* unicode value */ + FcChar8 name[1]; /* name extends beyond struct */ +} FcGlyphName; + +/* + * To perform case-insensitive string comparisons, a table + * is used which holds three different kinds of folding data. + * + * The first is a range of upper case values mapping to a range + * of their lower case equivalents. Within each range, the offset + * between upper and lower case is constant. + * + * The second is a range of upper case values which are interleaved + * with their lower case equivalents. + * + * The third is a set of raw unicode values mapping to a list + * of unicode values for comparison purposes. This allows conversion + * of ß to "ss" so that SS, ss and ß all match. A separate array + * holds the list of unicode values for each entry. + * + * These are packed into a single table. Using a binary search, + * the appropriate entry can be located. + */ + +#define FC_CASE_FOLD_RANGE 0 +#define FC_CASE_FOLD_EVEN_ODD 1 +#define FC_CASE_FOLD_FULL 2 + +typedef struct _FcCaseFold { + FcChar32 upper; + FcChar16 method : 2; + FcChar16 count : 14; + short offset; /* lower - upper for RANGE, table id for FULL */ +} FcCaseFold; + +#define FC_MAX_FILE_LEN 4096 + +#define FC_CACHE_MAGIC_MMAP 0xFC02FC04 +#define FC_CACHE_MAGIC_ALLOC 0xFC02FC05 +#define FC_CACHE_CONTENT_VERSION 4 + +struct _FcAtomic { + FcChar8 *file; /* original file name */ + FcChar8 *new; /* temp file name -- write data here */ + FcChar8 *lck; /* lockfile name (used for locking) */ + FcChar8 *tmp; /* tmpfile name (used for locking) */ +}; + +struct _FcBlanks { + int nblank; + int sblank; + FcChar32 *blanks; +}; + +struct _FcConfig { + /* + * File names loaded from the configuration -- saved here as the + * cache file must be consulted before the directories are scanned, + * and those directives may occur in any order + */ + FcStrSet *configDirs; /* directories to scan for fonts */ + /* + * Set of allowed blank chars -- used to + * trim fonts of bogus glyphs + */ + FcBlanks *blanks; + /* + * List of directories containing fonts, + * built by recursively scanning the set + * of configured directories + */ + FcStrSet *fontDirs; + /* + * List of directories containing cache files. + */ + FcStrSet *cacheDirs; + /* + * Names of all of the configuration files used + * to create this configuration + */ + FcStrSet *configFiles; /* config files loaded */ + /* + * Substitution instructions for patterns and fonts; + * maxObjects is used to allocate appropriate intermediate storage + * while performing a whole set of substitutions + */ + FcSubst *substPattern; /* substitutions for patterns */ + FcSubst *substFont; /* substitutions for fonts */ + FcSubst *substScan; /* substitutions for scanned fonts */ + int maxObjects; /* maximum number of tests in all substs */ + /* + * List of patterns used to control font file selection + */ + FcStrSet *acceptGlobs; + FcStrSet *rejectGlobs; + FcFontSet *acceptPatterns; + FcFontSet *rejectPatterns; + /* + * The set of fonts loaded from the listed directories; the + * order within the set does not determine the font selection, + * except in the case of identical matches in which case earlier fonts + * match preferrentially + */ + FcFontSet *fonts[FcSetApplication + 1]; + /* + * Fontconfig can periodically rescan the system configuration + * and font directories. This rescanning occurs when font + * listing requests are made, but no more often than rescanInterval + * seconds apart. + */ + time_t rescanTime; /* last time information was scanned */ + int rescanInterval; /* interval between scans */ + + FcRef ref; /* reference count */ + + FcExprPage *expr_pool; /* pool of FcExpr's */ + + FcChar8 *sysRoot; /* override the system root directory */ +}; + +typedef struct _FcFileTime { + time_t time; + FcBool set; +} FcFileTime; + +typedef struct _FcCharMap FcCharMap; + +typedef struct _FcRange FcRange; + +struct _FcRange { + FcChar32 begin; + FcChar32 end; +}; + +typedef struct _FcStatFS FcStatFS; + +struct _FcStatFS { + FcBool is_remote_fs; + FcBool is_mtime_broken; +}; + +typedef struct _FcValuePromotionBuffer FcValuePromotionBuffer; + +struct _FcValuePromotionBuffer { + union { + double d; + int i; + long l; + char c[256]; /* Enlarge as needed */ + } u; +}; + +/* fcblanks.c */ + +/* fccache.c */ + +FcPrivate FcCache * +FcDirCacheScan (const FcChar8 *dir, FcConfig *config); + +FcPrivate FcCache * +FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, struct stat *dir_stat, FcStrSet *dirs); + +FcPrivate FcCache * +FcDirCacheRebuild (FcCache *cache, struct stat *dir_stat, FcStrSet *dirs); + +FcPrivate FcBool +FcDirCacheWrite (FcCache *cache, FcConfig *config); + +FcPrivate FcBool +FcDirCacheCreateTagFile (const FcChar8 *cache_dir); + +FcPrivate void +FcCacheObjectReference (void *object); + +FcPrivate void +FcCacheObjectDereference (void *object); + +FcPrivate void +FcCacheFini (void); + +FcPrivate void +FcDirCacheReference (FcCache *cache, int nref); + +/* fccfg.c */ + +FcPrivate FcBool +FcConfigInit (void); + +FcPrivate void +FcConfigFini (void); + +FcPrivate FcChar8 * +FcConfigXdgCacheHome (void); + +FcPrivate FcChar8 * +FcConfigXdgConfigHome (void); + +FcPrivate FcChar8 * +FcConfigXdgDataHome (void); + +FcPrivate FcExpr * +FcConfigAllocExpr (FcConfig *config); + +FcPrivate FcBool +FcConfigAddConfigDir (FcConfig *config, + const FcChar8 *d); + +FcPrivate FcBool +FcConfigAddFontDir (FcConfig *config, + const FcChar8 *d); + +FcPrivate FcBool +FcConfigAddDir (FcConfig *config, + const FcChar8 *d); + +FcPrivate FcBool +FcConfigAddCacheDir (FcConfig *config, + const FcChar8 *d); + +FcPrivate FcBool +FcConfigAddConfigFile (FcConfig *config, + const FcChar8 *f); + +FcPrivate FcBool +FcConfigAddBlank (FcConfig *config, + FcChar32 blank); + +FcBool +FcConfigAddRule (FcConfig *config, + FcRule *rule, + FcMatchKind kind); + +FcPrivate void +FcConfigSetFonts (FcConfig *config, + FcFontSet *fonts, + FcSetName set); + +FcPrivate FcBool +FcConfigCompareValue (const FcValue *m, + unsigned int op_, + const FcValue *v); + +FcPrivate FcBool +FcConfigGlobAdd (FcConfig *config, + const FcChar8 *glob, + FcBool accept); + +FcPrivate FcBool +FcConfigAcceptFilename (FcConfig *config, + const FcChar8 *filename); + +FcPrivate FcBool +FcConfigPatternsAdd (FcConfig *config, + FcPattern *pattern, + FcBool accept); + +FcPrivate FcBool +FcConfigAcceptFont (FcConfig *config, + const FcPattern *font); + +FcPrivate FcFileTime +FcConfigModifiedTime (FcConfig *config); + +FcPrivate FcBool +FcConfigAddCache (FcConfig *config, FcCache *cache, + FcSetName set, FcStrSet *dirSet); + +/* fcserialize.c */ +FcPrivate intptr_t +FcAlignSize (intptr_t size); + +FcPrivate FcSerialize * +FcSerializeCreate (void); + +FcPrivate void +FcSerializeDestroy (FcSerialize *serialize); + +FcPrivate FcBool +FcSerializeAlloc (FcSerialize *serialize, const void *object, int size); + +FcPrivate intptr_t +FcSerializeReserve (FcSerialize *serialize, int size); + +FcPrivate intptr_t +FcSerializeOffset (FcSerialize *serialize, const void *object); + +FcPrivate void * +FcSerializePtr (FcSerialize *serialize, const void *object); + +FcPrivate FcBool +FcLangSetSerializeAlloc (FcSerialize *serialize, const FcLangSet *l); + +FcPrivate FcLangSet * +FcLangSetSerialize(FcSerialize *serialize, const FcLangSet *l); + +/* fccharset.c */ +FcPrivate void +FcLangCharSetPopulate (void); + +FcPrivate FcCharSetFreezer * +FcCharSetFreezerCreate (void); + +FcPrivate const FcCharSet * +FcCharSetFreeze (FcCharSetFreezer *freezer, const FcCharSet *fcs); + +FcPrivate void +FcCharSetFreezerDestroy (FcCharSetFreezer *freezer); + +FcPrivate FcBool +FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c); + +FcPrivate FcCharSet * +FcNameParseCharSet (FcChar8 *string); + +FcPrivate FcBool +FcNameUnparseValue (FcStrBuf *buf, + FcValue *v0, + FcChar8 *escape); + +FcPrivate FcBool +FcNameUnparseValueList (FcStrBuf *buf, + FcValueListPtr v, + FcChar8 *escape); + +FcPrivate FcCharLeaf * +FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4); + +FcPrivate FcBool +FcCharSetSerializeAlloc(FcSerialize *serialize, const FcCharSet *cs); + +FcPrivate FcCharSet * +FcCharSetSerialize(FcSerialize *serialize, const FcCharSet *cs); + +FcPrivate FcChar16 * +FcCharSetGetNumbers(const FcCharSet *c); + +/* fccompat.c */ +FcPrivate int +FcOpen(const char *pathname, int flags, ...); + +FcPrivate int +FcMakeTempfile (char *template); + +FcPrivate int32_t +FcRandom (void); + +FcPrivate FcBool +FcMakeDirectory (const FcChar8 *dir); + +/* fcdbg.c */ + +FcPrivate void +FcValuePrintFile (FILE *f, const FcValue v); + +FcPrivate void +FcValuePrintWithPosition (const FcValue v, FcBool show_pos_mark); + +FcPrivate void +FcValueListPrintWithPosition (FcValueListPtr l, const FcValueListPtr pos); + +FcPrivate void +FcValueListPrint (FcValueListPtr l); + +FcPrivate void +FcLangSetPrint (const FcLangSet *ls); + +FcPrivate void +FcOpPrint (FcOp op); + +FcPrivate void +FcTestPrint (const FcTest *test); + +FcPrivate void +FcExprPrint (const FcExpr *expr); + +FcPrivate void +FcEditPrint (const FcEdit *edit); + +FcPrivate void +FcSubstPrint (const FcSubst *subst); + +FcPrivate void +FcCharSetPrint (const FcCharSet *c); + +extern FcPrivate int FcDebugVal; + +#define FcDebug() (FcDebugVal) + +FcPrivate void +FcInitDebug (void); + +/* fcdefault.c */ +FcPrivate FcChar8 * +FcGetDefaultLang (void); + +FcPrivate FcChar8 * +FcGetPrgname (void); + +FcPrivate void +FcDefaultFini (void); + +/* fcdir.c */ + +FcPrivate FcBool +FcFileIsLink (const FcChar8 *file); + +FcPrivate FcBool +FcFileIsFile (const FcChar8 *file); + +FcPrivate FcBool +FcFileScanConfig (FcFontSet *set, + FcStrSet *dirs, + FcBlanks *blanks, + const FcChar8 *file, + FcConfig *config); + +FcPrivate FcBool +FcDirScanConfig (FcFontSet *set, + FcStrSet *dirs, + FcBlanks *blanks, + const FcChar8 *dir, + FcBool force, + FcConfig *config); + +/* fcfont.c */ +FcPrivate int +FcFontDebug (void); + +/* fcfs.c */ + +FcPrivate FcBool +FcFontSetSerializeAlloc (FcSerialize *serialize, const FcFontSet *s); + +FcPrivate FcFontSet * +FcFontSetSerialize (FcSerialize *serialize, const FcFontSet * s); + +FcPrivate FcFontSet * +FcFontSetDeserialize (const FcFontSet *set); + +/* fchash.c */ +FcPrivate FcChar8 * +FcHashGetSHA256Digest (const FcChar8 *input_strings, + size_t len); + +FcPrivate FcChar8 * +FcHashGetSHA256DigestFromFile (const FcChar8 *filename); + +FcPrivate FcChar8 * +FcHashGetSHA256DigestFromMemory (const char *fontdata, + size_t length); + +/* fcinit.c */ +FcPrivate FcConfig * +FcInitLoadOwnConfig (FcConfig *config); + +FcPrivate FcConfig * +FcInitLoadOwnConfigAndFonts (FcConfig *config); + +/* fcxml.c */ +FcPrivate void +FcTestDestroy (FcTest *test); + +FcPrivate void +FcEditDestroy (FcEdit *e); + +void +FcRuleDestroy (FcRule *rule); + +/* fclang.c */ +FcPrivate FcLangSet * +FcFreeTypeLangSet (const FcCharSet *charset, + const FcChar8 *exclusiveLang); + +FcPrivate FcLangResult +FcLangCompare (const FcChar8 *s1, const FcChar8 *s2); + +FcPrivate FcLangSet * +FcLangSetPromote (const FcChar8 *lang, FcValuePromotionBuffer *buf); + +FcPrivate FcLangSet * +FcNameParseLangSet (const FcChar8 *string); + +FcPrivate FcBool +FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls); + +FcPrivate FcChar8 * +FcNameUnparseEscaped (FcPattern *pat, FcBool escape); + +/* fclist.c */ + +FcPrivate FcBool +FcListPatternMatchAny (const FcPattern *p, + const FcPattern *font); + +/* fcmatch.c */ + +/* fcname.c */ + +enum { + FC_INVALID_OBJECT = 0, +#define FC_OBJECT(NAME, Type, Cmp) FC_##NAME##_OBJECT, +#include "fcobjs.h" +#undef FC_OBJECT + FC_ONE_AFTER_MAX_BASE_OBJECT +#define FC_MAX_BASE_OBJECT (FC_ONE_AFTER_MAX_BASE_OBJECT - 1) +}; + +FcPrivate FcBool +FcNameBool (const FcChar8 *v, FcBool *result); + +FcPrivate FcBool +FcObjectValidType (FcObject object, FcType type); + +FcPrivate FcObject +FcObjectFromName (const char * name); + +FcPrivate const char * +FcObjectName (FcObject object); + +FcPrivate FcObjectSet * +FcObjectGetSet (void); + +#define FcObjectCompare(a, b) ((int) a - (int) b) + +/* fcpat.c */ + +FcPrivate FcValue +FcValueCanonicalize (const FcValue *v); + +FcPrivate FcValueListPtr +FcValueListCreate (void); + +FcPrivate void +FcValueListDestroy (FcValueListPtr l); + +FcPrivate FcValueListPtr +FcValueListPrepend (FcValueListPtr vallist, + FcValue value, + FcValueBinding binding); + +FcPrivate FcValueListPtr +FcValueListAppend (FcValueListPtr vallist, + FcValue value, + FcValueBinding binding); + +FcPrivate FcValueListPtr +FcValueListDuplicate(FcValueListPtr orig); + +FcPrivate FcPatternElt * +FcPatternObjectFindElt (const FcPattern *p, FcObject object); + +FcPrivate FcPatternElt * +FcPatternObjectInsertElt (FcPattern *p, FcObject object); + +FcPrivate FcBool +FcPatternObjectListAdd (FcPattern *p, + FcObject object, + FcValueListPtr list, + FcBool append); + +FcPrivate FcBool +FcPatternObjectAddWithBinding (FcPattern *p, + FcObject object, + FcValue value, + FcValueBinding binding, + FcBool append); + +FcPrivate FcBool +FcPatternObjectAdd (FcPattern *p, FcObject object, FcValue value, FcBool append); + +FcPrivate FcBool +FcPatternObjectAddWeak (FcPattern *p, FcObject object, FcValue value, FcBool append); + +FcPrivate FcResult +FcPatternObjectGet (const FcPattern *p, FcObject object, int id, FcValue *v); + +FcPrivate FcBool +FcPatternObjectDel (FcPattern *p, FcObject object); + +FcPrivate FcBool +FcPatternObjectRemove (FcPattern *p, FcObject object, int id); + +FcPrivate FcBool +FcPatternObjectAddInteger (FcPattern *p, FcObject object, int i); + +FcPrivate FcBool +FcPatternObjectAddDouble (FcPattern *p, FcObject object, double d); + +FcPrivate FcBool +FcPatternObjectAddString (FcPattern *p, FcObject object, const FcChar8 *s); + +FcPrivate FcBool +FcPatternObjectAddMatrix (FcPattern *p, FcObject object, const FcMatrix *s); + +FcPrivate FcBool +FcPatternObjectAddCharSet (FcPattern *p, FcObject object, const FcCharSet *c); + +FcPrivate FcBool +FcPatternObjectAddBool (FcPattern *p, FcObject object, FcBool b); + +FcPrivate FcBool +FcPatternObjectAddLangSet (FcPattern *p, FcObject object, const FcLangSet *ls); + +FcPrivate FcResult +FcPatternObjectGetInteger (const FcPattern *p, FcObject object, int n, int *i); + +FcPrivate FcResult +FcPatternObjectGetDouble (const FcPattern *p, FcObject object, int n, double *d); + +FcPrivate FcResult +FcPatternObjectGetString (const FcPattern *p, FcObject object, int n, FcChar8 ** s); + +FcPrivate FcResult +FcPatternObjectGetMatrix (const FcPattern *p, FcObject object, int n, FcMatrix **s); + +FcPrivate FcResult +FcPatternObjectGetCharSet (const FcPattern *p, FcObject object, int n, FcCharSet **c); + +FcPrivate FcResult +FcPatternObjectGetBool (const FcPattern *p, FcObject object, int n, FcBool *b); + +FcPrivate FcResult +FcPatternObjectGetLangSet (const FcPattern *p, FcObject object, int n, FcLangSet **ls); + +FcPrivate FcBool +FcPatternAppend (FcPattern *p, FcPattern *s); + +FcPrivate FcChar32 +FcStringHash (const FcChar8 *s); + +FcPrivate FcBool +FcPatternSerializeAlloc (FcSerialize *serialize, const FcPattern *pat); + +FcPrivate FcPattern * +FcPatternSerialize (FcSerialize *serialize, const FcPattern *pat); + +FcPrivate FcBool +FcValueListSerializeAlloc (FcSerialize *serialize, const FcValueList *pat); + +FcPrivate FcValueList * +FcValueListSerialize (FcSerialize *serialize, const FcValueList *pat); + +/* fcrender.c */ + +/* fcmatrix.c */ + +extern FcPrivate const FcMatrix FcIdentityMatrix; + +FcPrivate void +FcMatrixFree (FcMatrix *mat); + +/* fcstat.c */ + +FcPrivate int +FcStat (const FcChar8 *file, struct stat *statb); + +FcPrivate int +FcStatChecksum (const FcChar8 *file, struct stat *statb); + +FcPrivate FcBool +FcIsFsMmapSafe (int fd); + +FcPrivate FcBool +FcIsFsMtimeBroken (const FcChar8 *dir); + +/* fcstr.c */ +FcPrivate FcBool +FcStrSetAddLangs (FcStrSet *strs, const char *languages); + +FcPrivate void +FcStrSetSort (FcStrSet * set); + +FcPrivate void +FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size); + +FcPrivate void +FcStrBufDestroy (FcStrBuf *buf); + +FcPrivate FcChar8 * +FcStrBufDone (FcStrBuf *buf); + +FcPrivate FcChar8 * +FcStrBufDoneStatic (FcStrBuf *buf); + +FcPrivate FcBool +FcStrBufChar (FcStrBuf *buf, FcChar8 c); + +FcPrivate FcBool +FcStrBufString (FcStrBuf *buf, const FcChar8 *s); + +FcPrivate FcBool +FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len); + +FcPrivate int +FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2); + +FcPrivate int +FcStrCmpIgnoreCaseAndDelims (const FcChar8 *s1, const FcChar8 *s2, const FcChar8 *delims); + +FcPrivate FcBool +FcStrRegexCmp (const FcChar8 *s, const FcChar8 *regex); + +FcPrivate FcBool +FcStrRegexCmpIgnoreCase (const FcChar8 *s, const FcChar8 *regex); + +FcPrivate const FcChar8 * +FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2); + +FcPrivate const FcChar8 * +FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2); + +FcPrivate const FcChar8 * +FcStrContainsWord (const FcChar8 *s1, const FcChar8 *s2); + +FcPrivate int +FcStrMatchIgnoreCaseAndDelims (const FcChar8 *s1, const FcChar8 *s2, const FcChar8 *delims); + +FcPrivate FcBool +FcStrGlobMatch (const FcChar8 *glob, + const FcChar8 *string); + +FcPrivate FcBool +FcStrUsesHome (const FcChar8 *s); + +FcPrivate FcChar8 * +FcStrBuildFilename (const FcChar8 *path, + ...); + +FcPrivate FcChar8 * +FcStrLastSlash (const FcChar8 *path); + +FcPrivate FcChar32 +FcStrHashIgnoreCase (const FcChar8 *s); + +FcPrivate FcChar8 * +FcStrCanonFilename (const FcChar8 *s); + +FcPrivate FcBool +FcStrSerializeAlloc (FcSerialize *serialize, const FcChar8 *str); + +FcPrivate FcChar8 * +FcStrSerialize (FcSerialize *serialize, const FcChar8 *str); + +/* fcobjs.c */ + +FcPrivate FcObject +FcObjectLookupIdByName (const char *str); + +FcPrivate FcObject +FcObjectLookupBuiltinIdByName (const char *str); + +FcPrivate const char * +FcObjectLookupOtherNameById (FcObject id); + +FcPrivate const FcObjectType * +FcObjectLookupOtherTypeById (FcObject id); + +FcPrivate const FcObjectType * +FcObjectLookupOtherTypeByName (const char *str); + +#endif /* _FC_INT_H_ */ diff --git a/project/jni/fontconfig/src/fclang.c b/project/jni/fontconfig/src/fclang.c new file mode 100644 index 000000000..9f685f6fd --- /dev/null +++ b/project/jni/fontconfig/src/fclang.c @@ -0,0 +1,1059 @@ +/* + * fontconfig/src/fclang.c + * + * Copyright © 2002 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include "fcftint.h" + +/* Objects MT-safe for readonly access. */ + +typedef struct { + const FcChar8 lang[8]; + const FcCharSet charset; +} FcLangCharSet; + +typedef struct { + int begin; + int end; +} FcLangCharSetRange; + +#include "../fc-lang/fclang.h" + +struct _FcLangSet { + FcStrSet *extra; + FcChar32 map_size; + FcChar32 map[NUM_LANG_SET_MAP]; +}; + +static int FcLangSetIndex (const FcChar8 *lang); + + +static void +FcLangSetBitSet (FcLangSet *ls, + unsigned int id) +{ + unsigned int bucket; + + id = fcLangCharSetIndices[id]; + bucket = id >> 5; + if (bucket >= ls->map_size) + return; /* shouldn't happen really */ + + ls->map[bucket] |= ((FcChar32) 1 << (id & 0x1f)); +} + +static FcBool +FcLangSetBitGet (const FcLangSet *ls, + unsigned int id) +{ + unsigned int bucket; + + id = fcLangCharSetIndices[id]; + bucket = id >> 5; + if (bucket >= ls->map_size) + return FcFalse; + + return ((ls->map[bucket] >> (id & 0x1f)) & 1) ? FcTrue : FcFalse; +} + +static void +FcLangSetBitReset (FcLangSet *ls, + unsigned int id) +{ + unsigned int bucket; + + id = fcLangCharSetIndices[id]; + bucket = id >> 5; + if (bucket >= ls->map_size) + return; /* shouldn't happen really */ + + ls->map[bucket] &= ~((FcChar32) 1 << (id & 0x1f)); +} + +FcLangSet * +FcFreeTypeLangSet (const FcCharSet *charset, + const FcChar8 *exclusiveLang) +{ + int i, j; + FcChar32 missing; + const FcCharSet *exclusiveCharset = 0; + FcLangSet *ls; + + if (exclusiveLang) + exclusiveCharset = FcLangGetCharSet (exclusiveLang); + ls = FcLangSetCreate (); + if (!ls) + return 0; + if (FcDebug() & FC_DBG_LANGSET) + { + printf ("font charset"); + FcCharSetPrint (charset); + printf ("\n"); + } + for (i = 0; i < NUM_LANG_CHAR_SET; i++) + { + if (FcDebug() & FC_DBG_LANGSET) + { + printf ("%s charset", fcLangCharSets[i].lang); + FcCharSetPrint (&fcLangCharSets[i].charset); + printf ("\n"); + } + + /* + * Check for Han charsets to make fonts + * which advertise support for a single language + * not support other Han languages + */ + if (exclusiveCharset && + FcFreeTypeIsExclusiveLang (fcLangCharSets[i].lang)) + { + if (fcLangCharSets[i].charset.num != exclusiveCharset->num) + continue; + + for (j = 0; j < fcLangCharSets[i].charset.num; j++) + if (FcCharSetLeaf(&fcLangCharSets[i].charset, j) != + FcCharSetLeaf(exclusiveCharset, j)) + continue; + } + missing = FcCharSetSubtractCount (&fcLangCharSets[i].charset, charset); + if (FcDebug() & FC_DBG_SCANV) + { + if (missing && missing < 10) + { + FcCharSet *missed = FcCharSetSubtract (&fcLangCharSets[i].charset, + charset); + FcChar32 ucs4; + FcChar32 map[FC_CHARSET_MAP_SIZE]; + FcChar32 next; + + printf ("\n%s(%u) ", fcLangCharSets[i].lang, missing); + printf ("{"); + for (ucs4 = FcCharSetFirstPage (missed, map, &next); + ucs4 != FC_CHARSET_DONE; + ucs4 = FcCharSetNextPage (missed, map, &next)) + { + int i, j; + for (i = 0; i < FC_CHARSET_MAP_SIZE; i++) + if (map[i]) + { + for (j = 0; j < 32; j++) + if (map[i] & (1 << j)) + printf (" %04x", ucs4 + i * 32 + j); + } + } + printf (" }\n\t"); + FcCharSetDestroy (missed); + } + else + printf ("%s(%u) ", fcLangCharSets[i].lang, missing); + } + if (!missing) + FcLangSetBitSet (ls, i); + } + + if (FcDebug() & FC_DBG_SCANV) + printf ("\n"); + + + return ls; +} + +FcChar8 * +FcLangNormalize (const FcChar8 *lang) +{ + FcChar8 *result = NULL, *s, *orig; + char *territory, *encoding, *modifier; + size_t llen, tlen = 0, mlen = 0; + + if (!lang || !*lang) + return NULL; + + if (FcStrCmpIgnoreCase (lang, (const FcChar8 *)"C") == 0 || + FcStrCmpIgnoreCase (lang, (const FcChar8 *)"POSIX") == 0) + { + result = FcStrCopy ((const FcChar8 *)"en"); + goto bail; + } + + s = FcStrCopy (lang); + if (!s) + goto bail; + + /* from the comments in glibc: + * + * LOCALE can consist of up to four recognized parts for the XPG syntax: + * + * language[_territory[.codeset]][@modifier] + * + * Beside the first all of them are allowed to be missing. If the + * full specified locale is not found, the less specific one are + * looked for. The various part will be stripped off according to + * the following order: + * (1) codeset + * (2) normalized codeset + * (3) territory + * (4) modifier + * + * So since we don't take care of the codeset part here, what patterns + * we need to deal with is: + * + * 1. language_territory@modifier + * 2. language@modifier + * 3. language + * + * then. and maybe no need to try language_territory here. + */ + modifier = strchr ((const char *) s, '@'); + if (modifier) + { + *modifier = 0; + modifier++; + mlen = strlen (modifier); + } + encoding = strchr ((const char *) s, '.'); + if (encoding) + { + *encoding = 0; + encoding++; + if (modifier) + { + memmove (encoding, modifier, mlen + 1); + modifier = encoding; + } + } + territory = strchr ((const char *) s, '_'); + if (!territory) + territory = strchr ((const char *) s, '-'); + if (territory) + { + *territory = 0; + territory++; + tlen = strlen (territory); + } + llen = strlen ((const char *) s); + if (llen < 2 || llen > 3) + { + fprintf (stderr, "Fontconfig warning: ignoring %s: not a valid language tag\n", + lang); + goto bail0; + } + if (territory && (tlen < 2 || tlen > 3)) + { + fprintf (stderr, "Fontconfig warning: ignoring %s: not a valid region tag\n", + lang); + goto bail0; + } + if (territory) + territory[-1] = '-'; + if (modifier) + modifier[-1] = '@'; + orig = FcStrDowncase (s); + if (!orig) + goto bail0; + if (territory) + { + if (FcDebug () & FC_DBG_LANGSET) + printf("Checking the existence of %s.orth\n", s); + if (FcLangSetIndex (s) < 0) + { + memmove (territory - 1, territory + tlen, (mlen > 0 ? mlen + 1 : 0) + 1); + if (modifier) + modifier = territory; + } + else + { + result = s; + /* we'll miss the opportunity to reduce the correct size + * of the allocated memory for the string after that. + */ + s = NULL; + goto bail1; + } + } + if (modifier) + { + if (FcDebug () & FC_DBG_LANGSET) + printf("Checking the existence of %s.orth\n", s); + if (FcLangSetIndex (s) < 0) + modifier[-1] = 0; + else + { + result = s; + /* we'll miss the opportunity to reduce the correct size + * of the allocated memory for the string after that. + */ + s = NULL; + goto bail1; + } + } + if (FcDebug () & FC_DBG_LANGSET) + printf("Checking the existence of %s.orth\n", s); + if (FcLangSetIndex (s) < 0) + { + /* there seems no languages matched in orth. + * add the language as is for fallback. + */ + result = orig; + orig = NULL; + } + else + { + result = s; + /* we'll miss the opportunity to reduce the correct size + * of the allocated memory for the string after that. + */ + s = NULL; + } + bail1: + if (orig) + FcStrFree (orig); + bail0: + if (s) + free (s); + bail: + if (FcDebug () & FC_DBG_LANGSET) + { + if (result) + printf ("normalized: %s -> %s\n", lang, result); + else + printf ("Unable to normalize %s\n", lang); + } + + return result; +} + +#define FcLangEnd(c) ((c) == '-' || (c) == '\0') + +FcLangResult +FcLangCompare (const FcChar8 *s1, const FcChar8 *s2) +{ + FcChar8 c1, c2; + FcLangResult result = FcLangDifferentLang; + + for (;;) + { + c1 = *s1++; + c2 = *s2++; + + c1 = FcToLower (c1); + c2 = FcToLower (c2); + if (c1 != c2) + { + if (FcLangEnd (c1) && FcLangEnd (c2)) + result = FcLangDifferentTerritory; + return result; + } + else if (!c1) + return FcLangEqual; + else if (c1 == '-') + result = FcLangDifferentTerritory; + } +} + +/* + * Return FcTrue when super contains sub. + * + * super contains sub if super and sub have the same + * language and either the same country or one + * is missing the country + */ + +static FcBool +FcLangContains (const FcChar8 *super, const FcChar8 *sub) +{ + FcChar8 c1, c2; + + for (;;) + { + c1 = *super++; + c2 = *sub++; + + c1 = FcToLower (c1); + c2 = FcToLower (c2); + if (c1 != c2) + { + /* see if super has a country while sub is mising one */ + if (c1 == '-' && c2 == '\0') + return FcTrue; + /* see if sub has a country while super is mising one */ + if (c1 == '\0' && c2 == '-') + return FcTrue; + return FcFalse; + } + else if (!c1) + return FcTrue; + } +} + +const FcCharSet * +FcLangGetCharSet (const FcChar8 *lang) +{ + int i; + int country = -1; + + for (i = 0; i < NUM_LANG_CHAR_SET; i++) + { + switch (FcLangCompare (lang, fcLangCharSets[i].lang)) { + case FcLangEqual: + return &fcLangCharSets[i].charset; + case FcLangDifferentTerritory: + if (country == -1) + country = i; + case FcLangDifferentLang: + default: + break; + } + } + if (country == -1) + return 0; + return &fcLangCharSets[country].charset; +} + +FcStrSet * +FcGetLangs (void) +{ + FcStrSet *langs; + int i; + + langs = FcStrSetCreate(); + if (!langs) + return 0; + + for (i = 0; i < NUM_LANG_CHAR_SET; i++) + FcStrSetAdd (langs, fcLangCharSets[i].lang); + + return langs; +} + +FcLangSet * +FcLangSetCreate (void) +{ + FcLangSet *ls; + + ls = malloc (sizeof (FcLangSet)); + if (!ls) + return 0; + memset (ls->map, '\0', sizeof (ls->map)); + ls->map_size = NUM_LANG_SET_MAP; + ls->extra = 0; + return ls; +} + +void +FcLangSetDestroy (FcLangSet *ls) +{ + if (ls->extra) + FcStrSetDestroy (ls->extra); + free (ls); +} + +FcLangSet * +FcLangSetCopy (const FcLangSet *ls) +{ + FcLangSet *new; + + new = FcLangSetCreate (); + if (!new) + goto bail0; + memset (new->map, '\0', sizeof (new->map)); + memcpy (new->map, ls->map, FC_MIN (sizeof (new->map), ls->map_size * sizeof (ls->map[0]))); + if (ls->extra) + { + FcStrList *list; + FcChar8 *extra; + + new->extra = FcStrSetCreate (); + if (!new->extra) + goto bail1; + + list = FcStrListCreate (ls->extra); + if (!list) + goto bail1; + + while ((extra = FcStrListNext (list))) + if (!FcStrSetAdd (new->extra, extra)) + { + FcStrListDone (list); + goto bail1; + } + FcStrListDone (list); + } + return new; +bail1: + FcLangSetDestroy (new); +bail0: + return 0; +} + +static int +FcLangSetIndex (const FcChar8 *lang) +{ + int low, high, mid = 0; + int cmp = 0; + FcChar8 firstChar = FcToLower(lang[0]); + FcChar8 secondChar = firstChar ? FcToLower(lang[1]) : '\0'; + + if (firstChar < 'a') + { + low = 0; + high = fcLangCharSetRanges[0].begin; + } + else if(firstChar > 'z') + { + low = fcLangCharSetRanges[25].begin; + high = NUM_LANG_CHAR_SET - 1; + } + else + { + low = fcLangCharSetRanges[firstChar - 'a'].begin; + high = fcLangCharSetRanges[firstChar - 'a'].end; + /* no matches */ + if (low > high) + return -low; /* next entry after where it would be */ + } + + while (low <= high) + { + mid = (high + low) >> 1; + if(fcLangCharSets[mid].lang[0] != firstChar) + cmp = FcStrCmpIgnoreCase(fcLangCharSets[mid].lang, lang); + else + { /* fast path for resolving 2-letter languages (by far the most common) after + * finding the first char (probably already true because of the hash table) */ + cmp = fcLangCharSets[mid].lang[1] - secondChar; + if (cmp == 0 && + (fcLangCharSets[mid].lang[2] != '\0' || + lang[2] != '\0')) + { + cmp = FcStrCmpIgnoreCase(fcLangCharSets[mid].lang+2, + lang+2); + } + } + if (cmp == 0) + return mid; + if (cmp < 0) + low = mid + 1; + else + high = mid - 1; + } + if (cmp < 0) + mid++; + return -(mid + 1); +} + +FcBool +FcLangSetAdd (FcLangSet *ls, const FcChar8 *lang) +{ + int id; + + id = FcLangSetIndex (lang); + if (id >= 0) + { + FcLangSetBitSet (ls, id); + return FcTrue; + } + if (!ls->extra) + { + ls->extra = FcStrSetCreate (); + if (!ls->extra) + return FcFalse; + } + return FcStrSetAdd (ls->extra, lang); +} + +FcBool +FcLangSetDel (FcLangSet *ls, const FcChar8 *lang) +{ + int id; + + id = FcLangSetIndex (lang); + if (id >= 0) + { + FcLangSetBitReset (ls, id); + } + else if (ls->extra) + { + FcStrSetDel (ls->extra, lang); + } + return FcTrue; +} + +FcLangResult +FcLangSetHasLang (const FcLangSet *ls, const FcChar8 *lang) +{ + int id; + FcLangResult best, r; + int i; + + id = FcLangSetIndex (lang); + if (id < 0) + id = -id - 1; + else if (FcLangSetBitGet (ls, id)) + return FcLangEqual; + best = FcLangDifferentLang; + for (i = id - 1; i >= 0; i--) + { + r = FcLangCompare (lang, fcLangCharSets[i].lang); + if (r == FcLangDifferentLang) + break; + if (FcLangSetBitGet (ls, i) && r < best) + best = r; + } + for (i = id; i < NUM_LANG_CHAR_SET; i++) + { + r = FcLangCompare (lang, fcLangCharSets[i].lang); + if (r == FcLangDifferentLang) + break; + if (FcLangSetBitGet (ls, i) && r < best) + best = r; + } + if (ls->extra) + { + FcStrList *list = FcStrListCreate (ls->extra); + FcChar8 *extra; + + if (list) + { + while (best > FcLangEqual && (extra = FcStrListNext (list))) + { + r = FcLangCompare (lang, extra); + if (r < best) + best = r; + } + FcStrListDone (list); + } + } + return best; +} + +static FcLangResult +FcLangSetCompareStrSet (const FcLangSet *ls, FcStrSet *set) +{ + FcStrList *list = FcStrListCreate (set); + FcLangResult r, best = FcLangDifferentLang; + FcChar8 *extra; + + if (list) + { + while (best > FcLangEqual && (extra = FcStrListNext (list))) + { + r = FcLangSetHasLang (ls, extra); + if (r < best) + best = r; + } + FcStrListDone (list); + } + return best; +} + +FcLangResult +FcLangSetCompare (const FcLangSet *lsa, const FcLangSet *lsb) +{ + int i, j, count; + FcLangResult best, r; + + count = FC_MIN (lsa->map_size, lsb->map_size); + count = FC_MIN (NUM_LANG_SET_MAP, count); + for (i = 0; i < count; i++) + if (lsa->map[i] & lsb->map[i]) + return FcLangEqual; + best = FcLangDifferentLang; + for (j = 0; j < NUM_COUNTRY_SET; j++) + for (i = 0; i < count; i++) + if ((lsa->map[i] & fcLangCountrySets[j][i]) && + (lsb->map[i] & fcLangCountrySets[j][i])) + { + best = FcLangDifferentTerritory; + break; + } + if (lsa->extra) + { + r = FcLangSetCompareStrSet (lsb, lsa->extra); + if (r < best) + best = r; + } + if (best > FcLangEqual && lsb->extra) + { + r = FcLangSetCompareStrSet (lsa, lsb->extra); + if (r < best) + best = r; + } + return best; +} + +/* + * Used in computing values -- mustn't allocate any storage + */ +FcLangSet * +FcLangSetPromote (const FcChar8 *lang, FcValuePromotionBuffer *vbuf) +{ + int id; + typedef struct { + FcLangSet ls; + FcStrSet strs; + FcChar8 *str; + } FcLangSetPromotionBuffer; + FcLangSetPromotionBuffer *buf = (FcLangSetPromotionBuffer *) vbuf; + + FC_ASSERT_STATIC (sizeof (FcLangSetPromotionBuffer) <= sizeof (FcValuePromotionBuffer)); + + memset (buf->ls.map, '\0', sizeof (buf->ls.map)); + buf->ls.map_size = NUM_LANG_SET_MAP; + buf->ls.extra = 0; + id = FcLangSetIndex (lang); + if (id > 0) + { + FcLangSetBitSet (&buf->ls, id); + } + else + { + buf->ls.extra = &buf->strs; + buf->strs.num = 1; + buf->strs.size = 1; + buf->strs.strs = &buf->str; + FcRefInit (&buf->strs.ref, 1); + buf->str = (FcChar8 *) lang; + } + return &buf->ls; +} + +FcChar32 +FcLangSetHash (const FcLangSet *ls) +{ + FcChar32 h = 0; + int i, count; + + count = FC_MIN (ls->map_size, NUM_LANG_SET_MAP); + for (i = 0; i < count; i++) + h ^= ls->map[i]; + if (ls->extra) + h ^= ls->extra->num; + return h; +} + +FcLangSet * +FcNameParseLangSet (const FcChar8 *string) +{ + FcChar8 lang[32], c = 0; + int i; + FcLangSet *ls; + + ls = FcLangSetCreate (); + if (!ls) + goto bail0; + + for(;;) + { + for(i = 0; i < 31;i++) + { + c = *string++; + if(c == '\0' || c == '|') + break; /* end of this code */ + lang[i] = c; + } + lang[i] = '\0'; + if (!FcLangSetAdd (ls, lang)) + goto bail1; + if(c == '\0') + break; + } + return ls; +bail1: + FcLangSetDestroy (ls); +bail0: + return 0; +} + +FcBool +FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls) +{ + int i, bit, count; + FcChar32 bits; + FcBool first = FcTrue; + + count = FC_MIN (ls->map_size, NUM_LANG_SET_MAP); + for (i = 0; i < count; i++) + { + if ((bits = ls->map[i])) + { + for (bit = 0; bit <= 31; bit++) + if (bits & (1 << bit)) + { + int id = (i << 5) | bit; + if (!first) + if (!FcStrBufChar (buf, '|')) + return FcFalse; + if (!FcStrBufString (buf, fcLangCharSets[fcLangCharSetIndicesInv[id]].lang)) + return FcFalse; + first = FcFalse; + } + } + } + if (ls->extra) + { + FcStrList *list = FcStrListCreate (ls->extra); + FcChar8 *extra; + + if (!list) + return FcFalse; + while ((extra = FcStrListNext (list))) + { + if (!first) + if (!FcStrBufChar (buf, '|')) + { + FcStrListDone (list); + return FcFalse; + } + if (!FcStrBufString (buf, extra)) + { + FcStrListDone (list); + return FcFalse; + } + first = FcFalse; + } + FcStrListDone (list); + } + return FcTrue; +} + +FcBool +FcLangSetEqual (const FcLangSet *lsa, const FcLangSet *lsb) +{ + int i, count; + + count = FC_MIN (lsa->map_size, lsb->map_size); + count = FC_MIN (NUM_LANG_SET_MAP, count); + for (i = 0; i < count; i++) + { + if (lsa->map[i] != lsb->map[i]) + return FcFalse; + } + if (!lsa->extra && !lsb->extra) + return FcTrue; + if (lsa->extra && lsb->extra) + return FcStrSetEqual (lsa->extra, lsb->extra); + return FcFalse; +} + +static FcBool +FcLangSetContainsLang (const FcLangSet *ls, const FcChar8 *lang) +{ + int id; + int i; + + id = FcLangSetIndex (lang); + if (id < 0) + id = -id - 1; + else if (FcLangSetBitGet (ls, id)) + return FcTrue; + /* + * search up and down among equal languages for a match + */ + for (i = id - 1; i >= 0; i--) + { + if (FcLangCompare (fcLangCharSets[i].lang, lang) == FcLangDifferentLang) + break; + if (FcLangSetBitGet (ls, i) && + FcLangContains (fcLangCharSets[i].lang, lang)) + return FcTrue; + } + for (i = id; i < NUM_LANG_CHAR_SET; i++) + { + if (FcLangCompare (fcLangCharSets[i].lang, lang) == FcLangDifferentLang) + break; + if (FcLangSetBitGet (ls, i) && + FcLangContains (fcLangCharSets[i].lang, lang)) + return FcTrue; + } + if (ls->extra) + { + FcStrList *list = FcStrListCreate (ls->extra); + FcChar8 *extra; + + if (list) + { + while ((extra = FcStrListNext (list))) + { + if (FcLangContains (extra, lang)) + break; + } + FcStrListDone (list); + if (extra) + return FcTrue; + } + } + return FcFalse; +} + +/* + * return FcTrue if lsa contains every language in lsb + */ +FcBool +FcLangSetContains (const FcLangSet *lsa, const FcLangSet *lsb) +{ + int i, j, count; + FcChar32 missing; + + if (FcDebug() & FC_DBG_MATCHV) + { + printf ("FcLangSet "); FcLangSetPrint (lsa); + printf (" contains "); FcLangSetPrint (lsb); + printf ("\n"); + } + /* + * check bitmaps for missing language support + */ + count = FC_MIN (lsa->map_size, lsb->map_size); + count = FC_MIN (NUM_LANG_SET_MAP, count); + for (i = 0; i < count; i++) + { + missing = lsb->map[i] & ~lsa->map[i]; + if (missing) + { + for (j = 0; j < 32; j++) + if (missing & (1 << j)) + { + if (!FcLangSetContainsLang (lsa, + fcLangCharSets[fcLangCharSetIndicesInv[i*32 + j]].lang)) + { + if (FcDebug() & FC_DBG_MATCHV) + printf ("\tMissing bitmap %s\n", fcLangCharSets[fcLangCharSetIndicesInv[i*32+j]].lang); + return FcFalse; + } + } + } + } + if (lsb->extra) + { + FcStrList *list = FcStrListCreate (lsb->extra); + FcChar8 *extra; + + if (list) + { + while ((extra = FcStrListNext (list))) + { + if (!FcLangSetContainsLang (lsa, extra)) + { + if (FcDebug() & FC_DBG_MATCHV) + printf ("\tMissing string %s\n", extra); + break; + } + } + FcStrListDone (list); + if (extra) + return FcFalse; + } + } + return FcTrue; +} + +FcBool +FcLangSetSerializeAlloc (FcSerialize *serialize, const FcLangSet *l) +{ + if (!FcSerializeAlloc (serialize, l, sizeof (FcLangSet))) + return FcFalse; + return FcTrue; +} + +FcLangSet * +FcLangSetSerialize(FcSerialize *serialize, const FcLangSet *l) +{ + FcLangSet *l_serialize = FcSerializePtr (serialize, l); + + if (!l_serialize) + return NULL; + memset (l_serialize->map, '\0', sizeof (l_serialize->map)); + memcpy (l_serialize->map, l->map, FC_MIN (sizeof (l_serialize->map), l->map_size * sizeof (l->map[0]))); + l_serialize->map_size = NUM_LANG_SET_MAP; + l_serialize->extra = NULL; /* We don't serialize ls->extra */ + return l_serialize; +} + +FcStrSet * +FcLangSetGetLangs (const FcLangSet *ls) +{ + FcStrSet *langs; + int i; + + langs = FcStrSetCreate(); + if (!langs) + return 0; + + for (i = 0; i < NUM_LANG_CHAR_SET; i++) + if (FcLangSetBitGet (ls, i)) + FcStrSetAdd (langs, fcLangCharSets[i].lang); + + if (ls->extra) + { + FcStrList *list = FcStrListCreate (ls->extra); + FcChar8 *extra; + + if (list) + { + while ((extra = FcStrListNext (list))) + FcStrSetAdd (langs, extra); + + FcStrListDone (list); + } + } + + return langs; +} + +static FcLangSet * +FcLangSetOperate(const FcLangSet *a, + const FcLangSet *b, + FcBool (*func) (FcLangSet *ls, + const FcChar8 *s)) +{ + FcLangSet *langset = FcLangSetCopy (a); + FcStrSet *set = FcLangSetGetLangs (b); + FcStrList *sl = FcStrListCreate (set); + FcChar8 *str; + + FcStrSetDestroy (set); + while ((str = FcStrListNext (sl))) + { + func (langset, str); + } + FcStrListDone (sl); + + return langset; +} + +FcLangSet * +FcLangSetUnion (const FcLangSet *a, const FcLangSet *b) +{ + return FcLangSetOperate(a, b, FcLangSetAdd); +} + +FcLangSet * +FcLangSetSubtract (const FcLangSet *a, const FcLangSet *b) +{ + return FcLangSetOperate(a, b, FcLangSetDel); +} + +#define __fclang__ +#include "fcaliastail.h" +#include "fcftaliastail.h" +#undef __fclang__ diff --git a/project/jni/fontconfig/src/fclist.c b/project/jni/fontconfig/src/fclist.c new file mode 100644 index 000000000..a365098a4 --- /dev/null +++ b/project/jni/fontconfig/src/fclist.c @@ -0,0 +1,607 @@ +/* + * fontconfig/src/fclist.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include + +FcObjectSet * +FcObjectSetCreate (void) +{ + FcObjectSet *os; + + os = (FcObjectSet *) malloc (sizeof (FcObjectSet)); + if (!os) + return 0; + os->nobject = 0; + os->sobject = 0; + os->objects = 0; + return os; +} + +FcBool +FcObjectSetAdd (FcObjectSet *os, const char *object) +{ + int s; + const char **objects; + int high, low, mid, c; + + if (os->nobject == os->sobject) + { + s = os->sobject + 4; + if (os->objects) + objects = (const char **) realloc ((void *) os->objects, + s * sizeof (const char *)); + else + objects = (const char **) malloc (s * sizeof (const char *)); + if (!objects) + return FcFalse; + os->objects = objects; + os->sobject = s; + } + high = os->nobject - 1; + low = 0; + mid = 0; + c = 1; + object = strdup (object); + while (low <= high) + { + mid = (low + high) >> 1; + c = os->objects[mid] - object; + if (c == 0) + { + FcFree (object); + return FcTrue; + } + if (c < 0) + low = mid + 1; + else + high = mid - 1; + } + if (c < 0) + mid++; + memmove (os->objects + mid + 1, os->objects + mid, + (os->nobject - mid) * sizeof (const char *)); + os->objects[mid] = object; + os->nobject++; + return FcTrue; +} + +void +FcObjectSetDestroy (FcObjectSet *os) +{ + int i; + + if (os->objects) + { + for (i = 0; i < os->nobject; i++) + FcFree (os->objects[i]); + + free ((void *) os->objects); + } + free (os); +} + +FcObjectSet * +FcObjectSetVaBuild (const char *first, va_list va) +{ + FcObjectSet *ret; + + FcObjectSetVapBuild (ret, first, va); + return ret; +} + +FcObjectSet * +FcObjectSetBuild (const char *first, ...) +{ + va_list va; + FcObjectSet *os; + + va_start (va, first); + FcObjectSetVapBuild (os, first, va); + va_end (va); + return os; +} + +/* + * Font must have a containing value for every value in the pattern + */ +static FcBool +FcListValueListMatchAny (FcValueListPtr patOrig, /* pattern */ + FcValueListPtr fntOrig) /* font */ +{ + FcValueListPtr pat, fnt; + + for (pat = patOrig; pat != NULL; pat = FcValueListNext(pat)) + { + for (fnt = fntOrig; fnt != NULL; fnt = FcValueListNext(fnt)) + { + /* + * make sure the font 'contains' the pattern. + * (OpListing is OpContains except for strings + * where it requires an exact match) + */ + if (FcConfigCompareValue (&fnt->value, + FC_OP (FcOpListing, FcOpFlagIgnoreBlanks), + &pat->value)) + break; + } + if (fnt == NULL) + return FcFalse; + } + return FcTrue; +} + +static FcBool +FcListValueListEqual (FcValueListPtr v1orig, + FcValueListPtr v2orig) +{ + FcValueListPtr v1, v2; + + for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1)) + { + for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2)) + if (FcValueEqual (FcValueCanonicalize(&(v1)->value), + FcValueCanonicalize(&(v2)->value))) + break; + if (v2 == NULL) + return FcFalse; + } + for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2)) + { + for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1)) + if (FcValueEqual (FcValueCanonicalize(&v1->value), + FcValueCanonicalize(&v2->value))) + break; + if (v1 == NULL) + return FcFalse; + } + return FcTrue; +} + +static FcBool +FcListPatternEqual (FcPattern *p1, + FcPattern *p2, + FcObjectSet *os) +{ + int i; + FcPatternElt *e1, *e2; + + for (i = 0; i < os->nobject; i++) + { + e1 = FcPatternObjectFindElt (p1, FcObjectFromName (os->objects[i])); + e2 = FcPatternObjectFindElt (p2, FcObjectFromName (os->objects[i])); + if (!e1 && !e2) + continue; + if (!e1 || !e2) + return FcFalse; + if (!FcListValueListEqual (FcPatternEltValues(e1), + FcPatternEltValues(e2))) + return FcFalse; + } + return FcTrue; +} + +/* + * FcTrue iff all objects in "p" match "font" + */ + +FcBool +FcListPatternMatchAny (const FcPattern *p, + const FcPattern *font) +{ + int i; + + if (!p) + return FcFalse; + for (i = 0; i < p->num; i++) + { + FcPatternElt *pe = &FcPatternElts(p)[i]; + FcPatternElt *fe; + + if (pe->object == FC_NAMELANG_OBJECT) + { + /* "namelang" object is the alias object to change "familylang", + * "stylelang" and "fullnamelang" object alltogether. it won't be + * available on the font pattern. so checking its availability + * causes no results. we should ignore it here. + */ + continue; + } + fe = FcPatternObjectFindElt (font, pe->object); + if (!fe) + return FcFalse; + if (!FcListValueListMatchAny (FcPatternEltValues(pe), /* pat elts */ + FcPatternEltValues(fe))) /* font elts */ + return FcFalse; + } + return FcTrue; +} + +static FcChar32 +FcListMatrixHash (const FcMatrix *m) +{ + int xx = (int) (m->xx * 100), + xy = (int) (m->xy * 100), + yx = (int) (m->yx * 100), + yy = (int) (m->yy * 100); + + return ((FcChar32) xx) ^ ((FcChar32) xy) ^ ((FcChar32) yx) ^ ((FcChar32) yy); +} + +static FcChar32 +FcListValueHash (FcValue *value) +{ + FcValue v = FcValueCanonicalize(value); + switch (v.type) { + case FcTypeUnknown: + case FcTypeVoid: + return 0; + case FcTypeInteger: + return (FcChar32) v.u.i; + case FcTypeDouble: + return (FcChar32) (int) v.u.d; + case FcTypeString: + return FcStrHashIgnoreCase (v.u.s); + case FcTypeBool: + return (FcChar32) v.u.b; + case FcTypeMatrix: + return FcListMatrixHash (v.u.m); + case FcTypeCharSet: + return FcCharSetCount (v.u.c); + case FcTypeFTFace: + return (long) v.u.f; + case FcTypeLangSet: + return FcLangSetHash (v.u.l); + } + return 0; +} + +static FcChar32 +FcListValueListHash (FcValueListPtr list) +{ + FcChar32 h = 0; + + while (list != NULL) + { + h = h ^ FcListValueHash (&list->value); + list = FcValueListNext(list); + } + return h; +} + +static FcChar32 +FcListPatternHash (FcPattern *font, + FcObjectSet *os) +{ + int n; + FcPatternElt *e; + FcChar32 h = 0; + + for (n = 0; n < os->nobject; n++) + { + e = FcPatternObjectFindElt (font, FcObjectFromName (os->objects[n])); + if (e) + h = h ^ FcListValueListHash (FcPatternEltValues(e)); + } + return h; +} + +typedef struct _FcListBucket { + struct _FcListBucket *next; + FcChar32 hash; + FcPattern *pattern; +} FcListBucket; + +#define FC_LIST_HASH_SIZE 4099 + +typedef struct _FcListHashTable { + int entries; + FcListBucket *buckets[FC_LIST_HASH_SIZE]; +} FcListHashTable; + +static void +FcListHashTableInit (FcListHashTable *table) +{ + table->entries = 0; + memset (table->buckets, '\0', sizeof (table->buckets)); +} + +static void +FcListHashTableCleanup (FcListHashTable *table) +{ + int i; + FcListBucket *bucket, *next; + + for (i = 0; i < FC_LIST_HASH_SIZE; i++) + { + for (bucket = table->buckets[i]; bucket; bucket = next) + { + next = bucket->next; + FcPatternDestroy (bucket->pattern); + free (bucket); + } + table->buckets[i] = 0; + } + table->entries = 0; +} + +static int +FcGetDefaultObjectLangIndex (FcPattern *font, FcObject object, const FcChar8 *lang) +{ + FcPatternElt *e = FcPatternObjectFindElt (font, object); + FcValueListPtr v; + FcValue value; + int idx = -1; + int defidx = -1; + int i; + + if (e) + { + for (v = FcPatternEltValues(e), i = 0; v; v = FcValueListNext(v), ++i) + { + value = FcValueCanonicalize (&v->value); + + if (value.type == FcTypeString) + { + FcLangResult res = FcLangCompare (value.u.s, lang); + if (res == FcLangEqual) + return i; + + if (res == FcLangDifferentCountry && idx < 0) + idx = i; + if (defidx < 0) + { + /* workaround for fonts that has non-English value + * at the head of values. + */ + res = FcLangCompare (value.u.s, (FcChar8 *)"en"); + if (res == FcLangEqual) + defidx = i; + } + } + } + } + + return (idx > 0) ? idx : (defidx > 0) ? defidx : 0; +} + +static FcBool +FcListAppend (FcListHashTable *table, + FcPattern *font, + FcObjectSet *os, + const FcChar8 *lang) +{ + int o; + FcPatternElt *e; + FcValueListPtr v; + FcChar32 hash; + FcListBucket **prev, *bucket; + int familyidx = -1; + int fullnameidx = -1; + int styleidx = -1; + int defidx = 0; + int idx; + + hash = FcListPatternHash (font, os); + for (prev = &table->buckets[hash % FC_LIST_HASH_SIZE]; + (bucket = *prev); prev = &(bucket->next)) + { + if (bucket->hash == hash && + FcListPatternEqual (bucket->pattern, font, os)) + return FcTrue; + } + bucket = (FcListBucket *) malloc (sizeof (FcListBucket)); + if (!bucket) + goto bail0; + bucket->next = 0; + bucket->hash = hash; + bucket->pattern = FcPatternCreate (); + if (!bucket->pattern) + goto bail1; + + for (o = 0; o < os->nobject; o++) + { + if (!strcmp (os->objects[o], FC_FAMILY) || !strcmp (os->objects[o], FC_FAMILYLANG)) + { + if (familyidx < 0) + familyidx = FcGetDefaultObjectLangIndex (font, FC_FAMILYLANG_OBJECT, lang); + defidx = familyidx; + } + else if (!strcmp (os->objects[o], FC_FULLNAME) || !strcmp (os->objects[o], FC_FULLNAMELANG)) + { + if (fullnameidx < 0) + fullnameidx = FcGetDefaultObjectLangIndex (font, FC_FULLNAMELANG_OBJECT, lang); + defidx = fullnameidx; + } + else if (!strcmp (os->objects[o], FC_STYLE) || !strcmp (os->objects[o], FC_STYLELANG)) + { + if (styleidx < 0) + styleidx = FcGetDefaultObjectLangIndex (font, FC_STYLELANG_OBJECT, lang); + defidx = styleidx; + } + else + defidx = 0; + + e = FcPatternObjectFindElt (font, FcObjectFromName (os->objects[o])); + if (e) + { + for (v = FcPatternEltValues(e), idx = 0; v; + v = FcValueListNext(v), ++idx) + { + if (!FcPatternAdd (bucket->pattern, + os->objects[o], + FcValueCanonicalize(&v->value), defidx != idx)) + goto bail2; + } + } + } + *prev = bucket; + ++table->entries; + + return FcTrue; + +bail2: + FcPatternDestroy (bucket->pattern); +bail1: + free (bucket); +bail0: + return FcFalse; +} + +FcFontSet * +FcFontSetList (FcConfig *config, + FcFontSet **sets, + int nsets, + FcPattern *p, + FcObjectSet *os) +{ + FcFontSet *ret; + FcFontSet *s; + int f; + int set; + FcListHashTable table; + int i; + FcListBucket *bucket; + int destroy_os = 0; + + if (!config) + { + if (!FcInitBringUptoDate ()) + goto bail0; + + config = FcConfigGetCurrent (); + if (!config) + goto bail0; + } + FcListHashTableInit (&table); + + if (!os) + { + os = FcObjectGetSet (); + destroy_os = 1; + } + + /* + * Walk all available fonts adding those that + * match to the hash table + */ + for (set = 0; set < nsets; set++) + { + s = sets[set]; + if (!s) + continue; + for (f = 0; f < s->nfont; f++) + if (FcListPatternMatchAny (p, /* pattern */ + s->fonts[f])) /* font */ + { + FcChar8 *lang; + + if (FcPatternObjectGetString (p, FC_NAMELANG_OBJECT, 0, &lang) != FcResultMatch) + { + lang = FcGetDefaultLang (); + } + if (!FcListAppend (&table, s->fonts[f], os, lang)) + goto bail1; + } + } +#if 0 + { + int max = 0; + int full = 0; + int ents = 0; + int len; + for (i = 0; i < FC_LIST_HASH_SIZE; i++) + { + if ((bucket = table.buckets[i])) + { + len = 0; + for (; bucket; bucket = bucket->next) + { + ents++; + len++; + } + if (len > max) + max = len; + full++; + } + } + printf ("used: %d max: %d avg: %g\n", full, max, + (double) ents / FC_LIST_HASH_SIZE); + } +#endif + /* + * Walk the hash table and build + * a font set + */ + ret = FcFontSetCreate (); + if (!ret) + goto bail0; + for (i = 0; i < FC_LIST_HASH_SIZE; i++) + while ((bucket = table.buckets[i])) + { + if (!FcFontSetAdd (ret, bucket->pattern)) + goto bail2; + table.buckets[i] = bucket->next; + free (bucket); + } + + return ret; + +bail2: + FcFontSetDestroy (ret); +bail1: + FcListHashTableCleanup (&table); +bail0: + if (destroy_os) + FcObjectSetDestroy (os); + return 0; +} + +FcFontSet * +FcFontList (FcConfig *config, + FcPattern *p, + FcObjectSet *os) +{ + FcFontSet *sets[2]; + int nsets; + + if (!config) + { + if (!FcInitBringUptoDate ()) + return 0; + + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + nsets = 0; + if (config->fonts[FcSetSystem]) + sets[nsets++] = config->fonts[FcSetSystem]; + if (config->fonts[FcSetApplication]) + sets[nsets++] = config->fonts[FcSetApplication]; + return FcFontSetList (config, sets, nsets, p, os); +} +#define __fclist__ +#include "fcaliastail.h" +#undef __fclist__ diff --git a/project/jni/fontconfig/src/fcmatch.c b/project/jni/fontconfig/src/fcmatch.c new file mode 100644 index 000000000..93e013f9b --- /dev/null +++ b/project/jni/fontconfig/src/fcmatch.c @@ -0,0 +1,1026 @@ +/* + * fontconfig/src/fcmatch.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" + +static double +FcCompareNumber (FcValue *value1, FcValue *value2) +{ + double v1, v2, v; + + switch ((int) value1->type) { + case FcTypeInteger: + v1 = (double) value1->u.i; + break; + case FcTypeDouble: + v1 = value1->u.d; + break; + default: + return -1.0; + } + switch ((int) value2->type) { + case FcTypeInteger: + v2 = (double) value2->u.i; + break; + case FcTypeDouble: + v2 = value2->u.d; + break; + default: + return -1.0; + } + v = v2 - v1; + if (v < 0) + v = -v; + return v; +} + +static double +FcCompareString (FcValue *v1, FcValue *v2) +{ + return (double) FcStrCmpIgnoreCase (FcValueString(v1), FcValueString(v2)) != 0; +} + +static double +FcCompareFamily (FcValue *v1, FcValue *v2) +{ + /* rely on the guarantee in FcPatternObjectAddWithBinding that + * families are always FcTypeString. */ + const FcChar8* v1_string = FcValueString(v1); + const FcChar8* v2_string = FcValueString(v2); + + if (FcToLower(*v1_string) != FcToLower(*v2_string) && + *v1_string != ' ' && *v2_string != ' ') + return 1.0; + + return (double) FcStrCmpIgnoreBlanksAndCase (v1_string, v2_string) != 0; +} + +static double +FcComparePostScript (FcValue *v1, FcValue *v2) +{ + const FcChar8 *v1_string = FcValueString (v1); + const FcChar8 *v2_string = FcValueString (v2); + int n; + size_t len; + + if (FcToLower (*v1_string) != FcToLower (*v2_string) && + *v1_string != ' ' && *v2_string != ' ') + return 1.0; + + n = FcStrMatchIgnoreCaseAndDelims (v1_string, v2_string, (const FcChar8 *)" -"); + len = strlen ((const char *)v1_string); + + return (double)(len - n) / (double)len; +} + +static double +FcCompareLang (FcValue *v1, FcValue *v2) +{ + FcLangResult result; + FcValue value1 = FcValueCanonicalize(v1), value2 = FcValueCanonicalize(v2); + + switch ((int) value1.type) { + case FcTypeLangSet: + switch ((int) value2.type) { + case FcTypeLangSet: + result = FcLangSetCompare (value1.u.l, value2.u.l); + break; + case FcTypeString: + result = FcLangSetHasLang (value1.u.l, + value2.u.s); + break; + default: + return -1.0; + } + break; + case FcTypeString: + switch ((int) value2.type) { + case FcTypeLangSet: + result = FcLangSetHasLang (value2.u.l, value1.u.s); + break; + case FcTypeString: + result = FcLangCompare (value1.u.s, + value2.u.s); + break; + default: + return -1.0; + } + break; + default: + return -1.0; + } + switch (result) { + case FcLangEqual: + return 0; + case FcLangDifferentCountry: + return 1; + case FcLangDifferentLang: + default: + return 2; + } +} + +static double +FcCompareBool (FcValue *v1, FcValue *v2) +{ + if (v2->type != FcTypeBool || v1->type != FcTypeBool) + return -1.0; + return (double) v2->u.b != v1->u.b; +} + +static double +FcCompareCharSet (FcValue *v1, FcValue *v2) +{ + return (double) FcCharSetSubtractCount (FcValueCharSet(v1), FcValueCharSet(v2)); +} + +static double +FcCompareSize (FcValue *value1, FcValue *value2) +{ + double v1, v2, v; + + switch ((int) value1->type) { + case FcTypeInteger: + v1 = value1->u.i; + break; + case FcTypeDouble: + v1 = value1->u.d; + break; + default: + return -1; + } + switch ((int) value2->type) { + case FcTypeInteger: + v2 = value2->u.i; + break; + case FcTypeDouble: + v2 = value2->u.d; + break; + default: + return -1; + } + if (v2 == 0) + return 0; + v = v2 - v1; + if (v < 0) + v = -v; + return v; +} + +static double +FcCompareFilename (FcValue *v1, FcValue *v2) +{ + const FcChar8 *s1 = FcValueString (v1), *s2 = FcValueString (v2); + if (FcStrCmp (s1, s2) == 0) + return 0.0; + else if (FcStrCmpIgnoreCase (s1, s2) == 0) + return 1.0; + else if (FcStrGlobMatch (s1, s2)) + return 2.0; + else + return 3.0; +} + +static double +FcCompareHash (FcValue *v1, FcValue *v2) +{ + const FcChar8 *s1 = FcValueString (v1), *s2 = FcValueString (v2); + + /* Do not match an empty string */ + if (!s1 || !s2 || !s1[0] || !s2[0]) + return 1.0; + return FcCompareString (v1, v2); +} + +#define PRI_NULL(n) \ + PRI_ ## n ## _STRONG = -1, \ + PRI_ ## n ## _WEAK = -1, +#define PRI1(n) +#define PRI_FcCompareFamily(n) PRI1(n) +#define PRI_FcCompareString(n) PRI1(n) +#define PRI_FcCompareNumber(n) PRI1(n) +#define PRI_FcCompareSize(n) PRI1(n) +#define PRI_FcCompareBool(n) PRI1(n) +#define PRI_FcCompareFilename(n) PRI1(n) +#define PRI_FcCompareCharSet(n) PRI1(n) +#define PRI_FcCompareLang(n) PRI1(n) +#define PRI_FcComparePostScript(n) PRI1(n) +#define PRI_FcCompareHash(n) PRI1(n) + +#define FC_OBJECT(NAME, Type, Cmp) PRI_##Cmp(NAME) + +typedef enum _FcMatcherPriorityDummy { +#include "fcobjs.h" +} FcMatcherPriorityDummy; + +#undef FC_OBJECT + +#undef PRI1 +#define PRI1(n) \ + PRI_ ## n, \ + PRI_ ## n ## _STRONG = PRI_ ## n, \ + PRI_ ## n ## _WEAK = PRI_ ## n + +typedef enum _FcMatcherPriority { + PRI1(HASH), + PRI1(FILE), + PRI1(FONTFORMAT), + PRI1(SCALABLE), + PRI1(FOUNDRY), + PRI1(CHARSET), + PRI_FAMILY_STRONG, + PRI_POSTSCRIPT_NAME_STRONG, + PRI1(LANG), + PRI_FAMILY_WEAK, + PRI_POSTSCRIPT_NAME_WEAK, + PRI1(SPACING), + PRI1(PIXEL_SIZE), + PRI1(STYLE), + PRI1(SLANT), + PRI1(WEIGHT), + PRI1(WIDTH), + PRI1(DECORATIVE), + PRI1(ANTIALIAS), + PRI1(RASTERIZER), + PRI1(OUTLINE), + PRI1(FONTVERSION), + PRI_END +} FcMatcherPriority; + +#undef PRI1 + +typedef struct _FcMatcher { + FcObject object; + double (*compare) (FcValue *value1, FcValue *value2); + int strong, weak; +} FcMatcher; + +/* + * Order is significant, it defines the precedence of + * each value, earlier values are more significant than + * later values + */ +#define FC_OBJECT(NAME, Type, Cmp) { FC_##NAME##_OBJECT, Cmp, PRI_##NAME##_STRONG, PRI_##NAME##_WEAK }, +static const FcMatcher _FcMatchers [] = { + { FC_INVALID_OBJECT, NULL, -1, -1 }, +#include "fcobjs.h" +}; +#undef FC_OBJECT + +static const FcMatcher* +FcObjectToMatcher (FcObject object, + FcBool include_lang) +{ + if (include_lang) + { + switch (object) { + case FC_FAMILYLANG_OBJECT: + case FC_STYLELANG_OBJECT: + case FC_FULLNAMELANG_OBJECT: + object = FC_LANG_OBJECT; + break; + } + } + if (object > FC_MAX_BASE_OBJECT || + !_FcMatchers[object].compare || + _FcMatchers[object].strong == -1 || + _FcMatchers[object].weak == -1) + return NULL; + + return _FcMatchers + object; +} + +static FcBool +FcCompareValueList (FcObject object, + const FcMatcher *match, + FcValueListPtr v1orig, /* pattern */ + FcValueListPtr v2orig, /* target */ + FcValue *bestValue, + double *value, + int *n, + FcResult *result) +{ + FcValueListPtr v1, v2; + double v, best, bestStrong, bestWeak; + int j, k, pos = 0; + + if (!match) + { + if (bestValue) + *bestValue = FcValueCanonicalize(&v2orig->value); + if (n) + *n = 0; + return FcTrue; + } + + best = 1e99; + bestStrong = 1e99; + bestWeak = 1e99; + j = 1; + for (v1 = v1orig; v1; v1 = FcValueListNext(v1)) + { + for (v2 = v2orig, k = 0; v2; v2 = FcValueListNext(v2), k++) + { + v = (match->compare) (&v1->value, &v2->value); + if (v < 0) + { + *result = FcResultTypeMismatch; + return FcFalse; + } + v = v * 1000 + j; + if (v < best) + { + if (bestValue) + *bestValue = FcValueCanonicalize(&v2->value); + best = v; + pos = k; + } + if (v1->binding == FcValueBindingStrong) + { + if (v < bestStrong) + bestStrong = v; + } + else + { + if (v < bestWeak) + bestWeak = v; + } + } + j++; + } + if (FcDebug () & FC_DBG_MATCHV) + { + printf (" %s: %g ", FcObjectName (object), best); + FcValueListPrint (v1orig); + printf (", "); + FcValueListPrint (v2orig); + printf ("\n"); + } + if (value) + { + int weak = match->weak; + int strong = match->strong; + if (weak == strong) + value[strong] += best; + else + { + value[weak] += bestWeak; + value[strong] += bestStrong; + } + } + if (n) + *n = pos; + + return FcTrue; +} + +/* + * Return a value indicating the distance between the two lists of + * values + */ + +static FcBool +FcCompare (FcPattern *pat, + FcPattern *fnt, + double *value, + FcResult *result) +{ + int i, i1, i2; + + for (i = 0; i < PRI_END; i++) + value[i] = 0.0; + + i1 = 0; + i2 = 0; + while (i1 < pat->num && i2 < fnt->num) + { + FcPatternElt *elt_i1 = &FcPatternElts(pat)[i1]; + FcPatternElt *elt_i2 = &FcPatternElts(fnt)[i2]; + + i = FcObjectCompare(elt_i1->object, elt_i2->object); + if (i > 0) + i2++; + else if (i < 0) + i1++; + else + { + const FcMatcher *match = FcObjectToMatcher (elt_i1->object, FcFalse); + if (!FcCompareValueList (elt_i1->object, match, + FcPatternEltValues(elt_i1), + FcPatternEltValues(elt_i2), + NULL, value, NULL, result)) + return FcFalse; + i1++; + i2++; + } + } + return FcTrue; +} + +FcPattern * +FcFontRenderPrepare (FcConfig *config, + FcPattern *pat, + FcPattern *font) +{ + FcPattern *new; + int i; + FcPatternElt *fe, *pe, *fel, *pel; + FcValue v; + FcResult result; + + assert (pat != NULL); + assert (font != NULL); + + new = FcPatternCreate (); + if (!new) + return NULL; + for (i = 0; i < font->num; i++) + { + fe = &FcPatternElts(font)[i]; + if (fe->object == FC_FAMILYLANG_OBJECT || + fe->object == FC_STYLELANG_OBJECT || + fe->object == FC_FULLNAMELANG_OBJECT) + { + /* ignore those objects. we need to deal with them + * another way */ + continue; + } + if (fe->object == FC_FAMILY_OBJECT || + fe->object == FC_STYLE_OBJECT || + fe->object == FC_FULLNAME_OBJECT) + { + FC_ASSERT_STATIC ((FC_FAMILY_OBJECT + 1) == FC_FAMILYLANG_OBJECT); + FC_ASSERT_STATIC ((FC_STYLE_OBJECT + 1) == FC_STYLELANG_OBJECT); + FC_ASSERT_STATIC ((FC_FULLNAME_OBJECT + 1) == FC_FULLNAMELANG_OBJECT); + + fel = FcPatternObjectFindElt (font, fe->object + 1); + pel = FcPatternObjectFindElt (pat, fe->object + 1); + } + else + { + fel = NULL; + pel = NULL; + } + pe = FcPatternObjectFindElt (pat, fe->object); + if (pe) + { + const FcMatcher *match = FcObjectToMatcher (pe->object, FcFalse); + + if (!FcCompareValueList (pe->object, match, + FcPatternEltValues(pe), + FcPatternEltValues(fe), &v, NULL, NULL, &result)) + { + FcPatternDestroy (new); + return NULL; + } + if (fel && pel) + { + int n = 1, j; + FcValueListPtr l1, l2, ln = NULL, ll = NULL; + + match = FcObjectToMatcher (pel->object, FcTrue); + if (!FcCompareValueList (pel->object, match, + FcPatternEltValues (pel), + FcPatternEltValues (fel), NULL, NULL, &n, &result)) + { + FcPatternDestroy (new); + return NULL; + } + + for (j = 0, l1 = FcPatternEltValues (fe), l2 = FcPatternEltValues (fel); + l1 != NULL || l2 != NULL; + j++, l1 = l1 ? FcValueListNext (l1) : NULL, l2 = l2 ? FcValueListNext (l2) : NULL) + { + if (j == n) + { + if (l1) + ln = FcValueListPrepend (ln, + FcValueCanonicalize (&l1->value), + FcValueBindingStrong); + if (l2) + ll = FcValueListPrepend (ll, + FcValueCanonicalize (&l2->value), + FcValueBindingStrong); + } + else + { + if (l1) + ln = FcValueListAppend (ln, + FcValueCanonicalize (&l1->value), + FcValueBindingStrong); + if (l2) + ll = FcValueListAppend (ll, + FcValueCanonicalize (&l2->value), + FcValueBindingStrong); + } + } + FcPatternObjectListAdd (new, fe->object, ln, FcFalse); + FcPatternObjectListAdd (new, fel->object, ll, FcFalse); + + continue; + } + else if (fel) + { + FcValueListPtr l1, l2; + + copy_lang: + l1 = FcValueListDuplicate (FcPatternEltValues (fe)); + l2 = FcValueListDuplicate (FcPatternEltValues (fel)); + FcPatternObjectListAdd (new, fe->object, l1, FcFalse); + FcPatternObjectListAdd (new, fel->object, l2, FcFalse); + + continue; + } + FcPatternObjectAdd (new, fe->object, v, FcFalse); + } + else + { + if (fel) + goto copy_lang; + FcPatternObjectListAdd (new, fe->object, + FcValueListDuplicate (FcPatternEltValues (fe)), + FcTrue); + } + } + for (i = 0; i < pat->num; i++) + { + pe = &FcPatternElts(pat)[i]; + fe = FcPatternObjectFindElt (font, pe->object); + if (!fe && + pe->object != FC_FAMILYLANG_OBJECT && + pe->object != FC_STYLELANG_OBJECT && + pe->object != FC_FULLNAMELANG_OBJECT) + { + FcPatternObjectListAdd (new, pe->object, + FcValueListDuplicate (FcPatternEltValues(pe)), + FcFalse); + } + } + + FcConfigSubstituteWithPat (config, new, pat, FcMatchFont); + return new; +} + +static FcPattern * +FcFontSetMatchInternal (FcFontSet **sets, + int nsets, + FcPattern *p, + FcResult *result) +{ + double score[PRI_END], bestscore[PRI_END]; + int f; + FcFontSet *s; + FcPattern *best; + int i; + int set; + + for (i = 0; i < PRI_END; i++) + bestscore[i] = 0; + best = 0; + if (FcDebug () & FC_DBG_MATCH) + { + printf ("Match "); + FcPatternPrint (p); + } + for (set = 0; set < nsets; set++) + { + s = sets[set]; + if (!s) + continue; + for (f = 0; f < s->nfont; f++) + { + if (FcDebug () & FC_DBG_MATCHV) + { + printf ("Font %d ", f); + FcPatternPrint (s->fonts[f]); + } + if (!FcCompare (p, s->fonts[f], score, result)) + return 0; + if (FcDebug () & FC_DBG_MATCHV) + { + printf ("Score"); + for (i = 0; i < PRI_END; i++) + { + printf (" %g", score[i]); + } + printf ("\n"); + } + for (i = 0; i < PRI_END; i++) + { + if (best && bestscore[i] < score[i]) + break; + if (!best || score[i] < bestscore[i]) + { + for (i = 0; i < PRI_END; i++) + bestscore[i] = score[i]; + best = s->fonts[f]; + break; + } + } + } + } + if (FcDebug () & FC_DBG_MATCH) + { + printf ("Best score"); + for (i = 0; i < PRI_END; i++) + printf (" %g", bestscore[i]); + printf ("\n"); + FcPatternPrint (best); + } + /* assuming that 'result' is initialized with FcResultNoMatch + * outside this function */ + if (best) + *result = FcResultMatch; + + return best; +} + +FcPattern * +FcFontSetMatch (FcConfig *config, + FcFontSet **sets, + int nsets, + FcPattern *p, + FcResult *result) +{ + FcPattern *best; + + assert (sets != NULL); + assert (p != NULL); + assert (result != NULL); + + *result = FcResultNoMatch; + + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + best = FcFontSetMatchInternal (sets, nsets, p, result); + if (best) + return FcFontRenderPrepare (config, p, best); + else + return NULL; +} + +FcPattern * +FcFontMatch (FcConfig *config, + FcPattern *p, + FcResult *result) +{ + FcFontSet *sets[2]; + int nsets; + FcPattern *best; + + assert (p != NULL); + assert (result != NULL); + + *result = FcResultNoMatch; + + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + nsets = 0; + if (config->fonts[FcSetSystem]) + sets[nsets++] = config->fonts[FcSetSystem]; + if (config->fonts[FcSetApplication]) + sets[nsets++] = config->fonts[FcSetApplication]; + + best = FcFontSetMatchInternal (sets, nsets, p, result); + if (best) + return FcFontRenderPrepare (config, p, best); + else + return NULL; +} + +typedef struct _FcSortNode { + FcPattern *pattern; + double score[PRI_END]; +} FcSortNode; + +static int +FcSortCompare (const void *aa, const void *ab) +{ + FcSortNode *a = *(FcSortNode **) aa; + FcSortNode *b = *(FcSortNode **) ab; + double *as = &a->score[0]; + double *bs = &b->score[0]; + double ad = 0, bd = 0; + int i; + + i = PRI_END; + while (i-- && (ad = *as++) == (bd = *bs++)) + ; + return ad < bd ? -1 : ad > bd ? 1 : 0; +} + +static FcBool +FcSortWalk (FcSortNode **n, int nnode, FcFontSet *fs, FcCharSet **csp, FcBool trim) +{ + FcBool ret = FcFalse; + FcCharSet *cs; + int i; + + cs = 0; + if (trim || csp) + { + cs = FcCharSetCreate (); + if (cs == NULL) + goto bail; + } + + for (i = 0; i < nnode; i++) + { + FcSortNode *node = *n++; + FcBool adds_chars = FcFalse; + + /* + * Only fetch node charset if we'd need it + */ + if (cs) + { + FcCharSet *ncs; + + if (FcPatternGetCharSet (node->pattern, FC_CHARSET, 0, &ncs) != + FcResultMatch) + continue; + + if (!FcCharSetMerge (cs, ncs, &adds_chars)) + goto bail; + } + + /* + * If this font isn't a subset of the previous fonts, + * add it to the list + */ + if (!i || !trim || adds_chars) + { + FcPatternReference (node->pattern); + if (FcDebug () & FC_DBG_MATCHV) + { + printf ("Add "); + FcPatternPrint (node->pattern); + } + if (!FcFontSetAdd (fs, node->pattern)) + { + FcPatternDestroy (node->pattern); + goto bail; + } + } + } + if (csp) + { + *csp = cs; + cs = 0; + } + + ret = FcTrue; + +bail: + if (cs) + FcCharSetDestroy (cs); + + return ret; +} + +void +FcFontSetSortDestroy (FcFontSet *fs) +{ + FcFontSetDestroy (fs); +} + +FcFontSet * +FcFontSetSort (FcConfig *config FC_UNUSED, + FcFontSet **sets, + int nsets, + FcPattern *p, + FcBool trim, + FcCharSet **csp, + FcResult *result) +{ + FcFontSet *ret; + FcFontSet *s; + FcSortNode *nodes; + FcSortNode **nodeps, **nodep; + int nnodes; + FcSortNode *new; + int set; + int f; + int i; + int nPatternLang; + FcBool *patternLangSat; + FcValue patternLang; + + assert (sets != NULL); + assert (p != NULL); + assert (result != NULL); + + /* There are some implementation that relying on the result of + * "result" to check if the return value of FcFontSetSort + * is valid or not. + * So we should initialize it to the conservative way since + * this function doesn't return NULL anymore. + */ + if (result) + *result = FcResultNoMatch; + + if (FcDebug () & FC_DBG_MATCH) + { + printf ("Sort "); + FcPatternPrint (p); + } + nnodes = 0; + for (set = 0; set < nsets; set++) + { + s = sets[set]; + if (!s) + continue; + nnodes += s->nfont; + } + if (!nnodes) + return FcFontSetCreate (); + + for (nPatternLang = 0; + FcPatternGet (p, FC_LANG, nPatternLang, &patternLang) == FcResultMatch; + nPatternLang++) + ; + + /* freed below */ + nodes = malloc (nnodes * sizeof (FcSortNode) + + nnodes * sizeof (FcSortNode *) + + nPatternLang * sizeof (FcBool)); + if (!nodes) + goto bail0; + nodeps = (FcSortNode **) (nodes + nnodes); + patternLangSat = (FcBool *) (nodeps + nnodes); + + new = nodes; + nodep = nodeps; + for (set = 0; set < nsets; set++) + { + s = sets[set]; + if (!s) + continue; + for (f = 0; f < s->nfont; f++) + { + if (FcDebug () & FC_DBG_MATCHV) + { + printf ("Font %d ", f); + FcPatternPrint (s->fonts[f]); + } + new->pattern = s->fonts[f]; + if (!FcCompare (p, new->pattern, new->score, result)) + goto bail1; + if (FcDebug () & FC_DBG_MATCHV) + { + printf ("Score"); + for (i = 0; i < PRI_END; i++) + { + printf (" %g", new->score[i]); + } + printf ("\n"); + } + *nodep = new; + new++; + nodep++; + } + } + + nnodes = new - nodes; + + qsort (nodeps, nnodes, sizeof (FcSortNode *), + FcSortCompare); + + for (i = 0; i < nPatternLang; i++) + patternLangSat[i] = FcFalse; + + for (f = 0; f < nnodes; f++) + { + FcBool satisfies = FcFalse; + /* + * If this node matches any language, go check + * which ones and satisfy those entries + */ + if (nodeps[f]->score[PRI_LANG] < 2000) + { + for (i = 0; i < nPatternLang; i++) + { + FcValue nodeLang; + + if (!patternLangSat[i] && + FcPatternGet (p, FC_LANG, i, &patternLang) == FcResultMatch && + FcPatternGet (nodeps[f]->pattern, FC_LANG, 0, &nodeLang) == FcResultMatch) + { + double compare = FcCompareLang (&patternLang, &nodeLang); + if (compare >= 0 && compare < 2) + { + if (FcDebug () & FC_DBG_MATCHV) + { + FcChar8 *family; + FcChar8 *style; + + if (FcPatternGetString (nodeps[f]->pattern, FC_FAMILY, 0, &family) == FcResultMatch && + FcPatternGetString (nodeps[f]->pattern, FC_STYLE, 0, &style) == FcResultMatch) + printf ("Font %s:%s matches language %d\n", family, style, i); + } + patternLangSat[i] = FcTrue; + satisfies = FcTrue; + break; + } + } + } + } + if (!satisfies) + { + nodeps[f]->score[PRI_LANG] = 10000.0; + } + } + + /* + * Re-sort once the language issues have been settled + */ + qsort (nodeps, nnodes, sizeof (FcSortNode *), + FcSortCompare); + + ret = FcFontSetCreate (); + if (!ret) + goto bail1; + + if (!FcSortWalk (nodeps, nnodes, ret, csp, trim)) + goto bail2; + + free (nodes); + + if (FcDebug() & FC_DBG_MATCH) + { + printf ("First font "); + FcPatternPrint (ret->fonts[0]); + } + if (ret->nfont > 0) + *result = FcResultMatch; + + return ret; + +bail2: + FcFontSetDestroy (ret); +bail1: + free (nodes); +bail0: + return 0; +} + +FcFontSet * +FcFontSort (FcConfig *config, + FcPattern *p, + FcBool trim, + FcCharSet **csp, + FcResult *result) +{ + FcFontSet *sets[2]; + int nsets; + + assert (p != NULL); + assert (result != NULL); + + *result = FcResultNoMatch; + + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + nsets = 0; + if (config->fonts[FcSetSystem]) + sets[nsets++] = config->fonts[FcSetSystem]; + if (config->fonts[FcSetApplication]) + sets[nsets++] = config->fonts[FcSetApplication]; + return FcFontSetSort (config, sets, nsets, p, trim, csp, result); +} +#define __fcmatch__ +#include "fcaliastail.h" +#undef __fcmatch__ diff --git a/project/jni/fontconfig/src/fcmatrix.c b/project/jni/fontconfig/src/fcmatrix.c new file mode 100644 index 000000000..a6fbca2a0 --- /dev/null +++ b/project/jni/fontconfig/src/fcmatrix.c @@ -0,0 +1,116 @@ +/* + * fontconfig/src/fcmatrix.c + * + * Copyright © 2000 Tuomas J. Lukka + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Tuomas Lukka not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Tuomas Lukka makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * TUOMAS LUKKA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL TUOMAS LUKKA BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include +#include +#include + +const FcMatrix FcIdentityMatrix = { 1, 0, 0, 1 }; + +FcMatrix * +FcMatrixCopy (const FcMatrix *mat) +{ + FcMatrix *r; + if(!mat) + return 0; + r = (FcMatrix *) malloc (sizeof (*r) ); + if (!r) + return 0; + *r = *mat; + return r; +} + +void +FcMatrixFree (FcMatrix *mat) +{ + if (mat != &FcIdentityMatrix) + free (mat); +} + +FcBool +FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2) +{ + if(mat1 == mat2) return FcTrue; + if(mat1 == 0 || mat2 == 0) return FcFalse; + return mat1->xx == mat2->xx && + mat1->xy == mat2->xy && + mat1->yx == mat2->yx && + mat1->yy == mat2->yy; +} + +void +FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b) +{ + FcMatrix r; + + r.xx = a->xx * b->xx + a->xy * b->yx; + r.xy = a->xx * b->xy + a->xy * b->yy; + r.yx = a->yx * b->xx + a->yy * b->yx; + r.yy = a->yx * b->xy + a->yy * b->yy; + *result = r; +} + +void +FcMatrixRotate (FcMatrix *m, double c, double s) +{ + FcMatrix r; + + /* + * X Coordinate system is upside down, swap to make + * rotations counterclockwise + */ + r.xx = c; + r.xy = -s; + r.yx = s; + r.yy = c; + FcMatrixMultiply (m, &r, m); +} + +void +FcMatrixScale (FcMatrix *m, double sx, double sy) +{ + FcMatrix r; + + r.xx = sx; + r.xy = 0; + r.yx = 0; + r.yy = sy; + FcMatrixMultiply (m, &r, m); +} + +void +FcMatrixShear (FcMatrix *m, double sh, double sv) +{ + FcMatrix r; + + r.xx = 1; + r.xy = sh; + r.yx = sv; + r.yy = 1; + FcMatrixMultiply (m, &r, m); +} +#define __fcmatrix__ +#include "fcaliastail.h" +#undef __fcmatrix__ diff --git a/project/jni/fontconfig/src/fcmutex.h b/project/jni/fontconfig/src/fcmutex.h new file mode 100644 index 000000000..556a05efc --- /dev/null +++ b/project/jni/fontconfig/src/fcmutex.h @@ -0,0 +1,127 @@ +/* + * Atomic int and pointer operations. Originally copied from HarfBuzz. + * + * Copyright © 2007 Chris Wilson + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2011,2012,2013 Google, Inc. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Contributor(s): + * Chris Wilson + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef _FCMUTEX_H_ +#define _FCMUTEX_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#define FC_STMT_START do +#define FC_STMT_END while (0) + +/* mutex */ + +/* We need external help for these */ + +#if 0 + + +#elif !defined(FC_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__) + +#include "fcwindows.h" +typedef CRITICAL_SECTION fc_mutex_impl_t; +#define FC_MUTEX_IMPL_INIT { NULL, 0, 0, NULL, NULL, 0 } +#define fc_mutex_impl_init(M) InitializeCriticalSection (M) +#define fc_mutex_impl_lock(M) EnterCriticalSection (M) +#define fc_mutex_impl_unlock(M) LeaveCriticalSection (M) +#define fc_mutex_impl_finish(M) DeleteCriticalSection (M) + + +#elif !defined(FC_NO_MT) && (defined(HAVE_PTHREAD) || defined(__APPLE__)) + +#include +typedef pthread_mutex_t fc_mutex_impl_t; +#define FC_MUTEX_IMPL_INIT PTHREAD_MUTEX_INITIALIZER +#define fc_mutex_impl_init(M) pthread_mutex_init (M, NULL) +#define fc_mutex_impl_lock(M) pthread_mutex_lock (M) +#define fc_mutex_impl_unlock(M) pthread_mutex_unlock (M) +#define fc_mutex_impl_finish(M) pthread_mutex_destroy (M) + + +#elif !defined(FC_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) + +#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_YIELD) +# include +# define FC_SCHED_YIELD() sched_yield () +#else +# define FC_SCHED_YIELD() FC_STMT_START {} FC_STMT_END +#endif + +/* This actually is not a totally awful implementation. */ +typedef volatile int fc_mutex_impl_t; +#define FC_MUTEX_IMPL_INIT 0 +#define fc_mutex_impl_init(M) *(M) = 0 +#define fc_mutex_impl_lock(M) FC_STMT_START { while (__sync_lock_test_and_set((M), 1)) FC_SCHED_YIELD (); } FC_STMT_END +#define fc_mutex_impl_unlock(M) __sync_lock_release (M) +#define fc_mutex_impl_finish(M) FC_STMT_START {} FC_STMT_END + + +#elif !defined(FC_NO_MT) + +#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_YIELD) +# include +# define FC_SCHED_YIELD() sched_yield () +#else +# define FC_SCHED_YIELD() FC_STMT_START {} FC_STMT_END +#endif + +#define FC_MUTEX_INT_NIL 1 /* Warn that fallback implementation is in use. */ +typedef volatile int fc_mutex_impl_t; +#define FC_MUTEX_IMPL_INIT 0 +#define fc_mutex_impl_init(M) *(M) = 0 +#define fc_mutex_impl_lock(M) FC_STMT_START { while (*(M)) FC_SCHED_YIELD (); (*(M))++; } FC_STMT_END +#define fc_mutex_impl_unlock(M) (*(M))--; +#define fc_mutex_impl_finish(M) FC_STMT_START {} FC_STMT_END + + +#else /* FC_NO_MT */ + +typedef int fc_mutex_impl_t; +#define FC_MUTEX_IMPL_INIT 0 +#define fc_mutex_impl_init(M) FC_STMT_START {} FC_STMT_END +#define fc_mutex_impl_lock(M) FC_STMT_START {} FC_STMT_END +#define fc_mutex_impl_unlock(M) FC_STMT_START {} FC_STMT_END +#define fc_mutex_impl_finish(M) FC_STMT_START {} FC_STMT_END + +#endif + + +#define FC_MUTEX_INIT {FC_MUTEX_IMPL_INIT} +typedef fc_mutex_impl_t FcMutex; +static inline void FcMutexInit (FcMutex *m) { fc_mutex_impl_init (m); } +static inline void FcMutexLock (FcMutex *m) { fc_mutex_impl_lock (m); } +static inline void FcMutexUnlock (FcMutex *m) { fc_mutex_impl_unlock (m); } +static inline void FcMutexFinish (FcMutex *m) { fc_mutex_impl_finish (m); } + + +#endif /* _FCMUTEX_H_ */ diff --git a/project/jni/fontconfig/src/fcname.c b/project/jni/fontconfig/src/fcname.c new file mode 100644 index 000000000..f302948dd --- /dev/null +++ b/project/jni/fontconfig/src/fcname.c @@ -0,0 +1,586 @@ +/* + * fontconfig/src/fcname.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include +#include +#include +#include + +static const FcObjectType FcObjects[] = { +#define FC_OBJECT(NAME, Type, Cmp) { FC_##NAME, Type }, +#include "fcobjs.h" +#undef FC_OBJECT +}; + +#define NUM_OBJECT_TYPES ((int) (sizeof FcObjects / sizeof FcObjects[0])) + +static const FcObjectType * +FcObjectFindById (FcObject object) +{ + if (1 <= object && object <= NUM_OBJECT_TYPES) + return &FcObjects[object - 1]; + return FcObjectLookupOtherTypeById (object); +} + +FcBool +FcNameRegisterObjectTypes (const FcObjectType *types, int ntypes) +{ + /* Deprecated. */ + return FcFalse; +} + +FcBool +FcNameUnregisterObjectTypes (const FcObjectType *types, int ntypes) +{ + /* Deprecated. */ + return FcFalse; +} + +const FcObjectType * +FcNameGetObjectType (const char *object) +{ + int id = FcObjectLookupBuiltinIdByName (object); + + if (!id) + return FcObjectLookupOtherTypeByName (object); + + return &FcObjects[id - 1]; +} + +FcBool +FcObjectValidType (FcObject object, FcType type) +{ + const FcObjectType *t = FcObjectFindById (object); + + if (t) { + switch ((int) t->type) { + case FcTypeUnknown: + return FcTrue; + case FcTypeDouble: + case FcTypeInteger: + if (type == FcTypeDouble || type == FcTypeInteger) + return FcTrue; + break; + case FcTypeLangSet: + if (type == FcTypeLangSet || type == FcTypeString) + return FcTrue; + break; + default: + if (type == t->type) + return FcTrue; + break; + } + return FcFalse; + } + return FcTrue; +} + +FcObject +FcObjectFromName (const char * name) +{ + return FcObjectLookupIdByName (name); +} + +FcObjectSet * +FcObjectGetSet (void) +{ + int i; + FcObjectSet *os = NULL; + + + os = FcObjectSetCreate (); + for (i = 0; i < NUM_OBJECT_TYPES; i++) + FcObjectSetAdd (os, FcObjects[i].object); + + return os; +} + +const char * +FcObjectName (FcObject object) +{ + const FcObjectType *o = FcObjectFindById (object); + + if (o) + return o->object; + + return FcObjectLookupOtherNameById (object); +} + +static const FcConstant _FcBaseConstants[] = { + { (FcChar8 *) "thin", "weight", FC_WEIGHT_THIN, }, + { (FcChar8 *) "extralight", "weight", FC_WEIGHT_EXTRALIGHT, }, + { (FcChar8 *) "ultralight", "weight", FC_WEIGHT_EXTRALIGHT, }, + { (FcChar8 *) "light", "weight", FC_WEIGHT_LIGHT, }, + { (FcChar8 *) "book", "weight", FC_WEIGHT_BOOK, }, + { (FcChar8 *) "regular", "weight", FC_WEIGHT_REGULAR, }, + { (FcChar8 *) "medium", "weight", FC_WEIGHT_MEDIUM, }, + { (FcChar8 *) "demibold", "weight", FC_WEIGHT_DEMIBOLD, }, + { (FcChar8 *) "semibold", "weight", FC_WEIGHT_DEMIBOLD, }, + { (FcChar8 *) "bold", "weight", FC_WEIGHT_BOLD, }, + { (FcChar8 *) "extrabold", "weight", FC_WEIGHT_EXTRABOLD, }, + { (FcChar8 *) "ultrabold", "weight", FC_WEIGHT_EXTRABOLD, }, + { (FcChar8 *) "black", "weight", FC_WEIGHT_BLACK, }, + { (FcChar8 *) "heavy", "weight", FC_WEIGHT_HEAVY, }, + + { (FcChar8 *) "roman", "slant", FC_SLANT_ROMAN, }, + { (FcChar8 *) "italic", "slant", FC_SLANT_ITALIC, }, + { (FcChar8 *) "oblique", "slant", FC_SLANT_OBLIQUE, }, + + { (FcChar8 *) "ultracondensed", "width", FC_WIDTH_ULTRACONDENSED }, + { (FcChar8 *) "extracondensed", "width", FC_WIDTH_EXTRACONDENSED }, + { (FcChar8 *) "condensed", "width", FC_WIDTH_CONDENSED }, + { (FcChar8 *) "semicondensed", "width", FC_WIDTH_SEMICONDENSED }, + { (FcChar8 *) "normal", "width", FC_WIDTH_NORMAL }, + { (FcChar8 *) "semiexpanded", "width", FC_WIDTH_SEMIEXPANDED }, + { (FcChar8 *) "expanded", "width", FC_WIDTH_EXPANDED }, + { (FcChar8 *) "extraexpanded", "width", FC_WIDTH_EXTRAEXPANDED }, + { (FcChar8 *) "ultraexpanded", "width", FC_WIDTH_ULTRAEXPANDED }, + + { (FcChar8 *) "proportional", "spacing", FC_PROPORTIONAL, }, + { (FcChar8 *) "dual", "spacing", FC_DUAL, }, + { (FcChar8 *) "mono", "spacing", FC_MONO, }, + { (FcChar8 *) "charcell", "spacing", FC_CHARCELL, }, + + { (FcChar8 *) "unknown", "rgba", FC_RGBA_UNKNOWN }, + { (FcChar8 *) "rgb", "rgba", FC_RGBA_RGB, }, + { (FcChar8 *) "bgr", "rgba", FC_RGBA_BGR, }, + { (FcChar8 *) "vrgb", "rgba", FC_RGBA_VRGB }, + { (FcChar8 *) "vbgr", "rgba", FC_RGBA_VBGR }, + { (FcChar8 *) "none", "rgba", FC_RGBA_NONE }, + + { (FcChar8 *) "hintnone", "hintstyle", FC_HINT_NONE }, + { (FcChar8 *) "hintslight", "hintstyle", FC_HINT_SLIGHT }, + { (FcChar8 *) "hintmedium", "hintstyle", FC_HINT_MEDIUM }, + { (FcChar8 *) "hintfull", "hintstyle", FC_HINT_FULL }, + + { (FcChar8 *) "antialias", "antialias", FcTrue }, + { (FcChar8 *) "hinting", "hinting", FcTrue }, + { (FcChar8 *) "verticallayout", "verticallayout", FcTrue }, + { (FcChar8 *) "autohint", "autohint", FcTrue }, + { (FcChar8 *) "globaladvance", "globaladvance", FcTrue }, /* deprecated */ + { (FcChar8 *) "outline", "outline", FcTrue }, + { (FcChar8 *) "scalable", "scalable", FcTrue }, + { (FcChar8 *) "minspace", "minspace", FcTrue }, + { (FcChar8 *) "embolden", "embolden", FcTrue }, + { (FcChar8 *) "embeddedbitmap", "embeddedbitmap", FcTrue }, + { (FcChar8 *) "decorative", "decorative", FcTrue }, + { (FcChar8 *) "lcdnone", "lcdfilter", FC_LCD_NONE }, + { (FcChar8 *) "lcddefault", "lcdfilter", FC_LCD_DEFAULT }, + { (FcChar8 *) "lcdlight", "lcdfilter", FC_LCD_LIGHT }, + { (FcChar8 *) "lcdlegacy", "lcdfilter", FC_LCD_LEGACY }, +}; + +#define NUM_FC_CONSTANTS (sizeof _FcBaseConstants/sizeof _FcBaseConstants[0]) + +FcBool +FcNameRegisterConstants (const FcConstant *consts, int nconsts) +{ + /* Deprecated. */ + return FcFalse; +} + +FcBool +FcNameUnregisterConstants (const FcConstant *consts, int nconsts) +{ + /* Deprecated. */ + return FcFalse; +} + +const FcConstant * +FcNameGetConstant (const FcChar8 *string) +{ + unsigned int i; + + for (i = 0; i < NUM_FC_CONSTANTS; i++) + if (!FcStrCmpIgnoreCase (string, _FcBaseConstants[i].name)) + return &_FcBaseConstants[i]; + + return 0; +} + +FcBool +FcNameConstant (const FcChar8 *string, int *result) +{ + const FcConstant *c; + + if ((c = FcNameGetConstant(string))) + { + *result = c->value; + return FcTrue; + } + return FcFalse; +} + +FcBool +FcNameBool (const FcChar8 *v, FcBool *result) +{ + char c0, c1; + + c0 = *v; + c0 = FcToLower (c0); + if (c0 == 't' || c0 == 'y' || c0 == '1') + { + *result = FcTrue; + return FcTrue; + } + if (c0 == 'f' || c0 == 'n' || c0 == '0') + { + *result = FcFalse; + return FcTrue; + } + if (c0 == 'o') + { + c1 = v[1]; + c1 = FcToLower (c1); + if (c1 == 'n') + { + *result = FcTrue; + return FcTrue; + } + if (c1 == 'f') + { + *result = FcFalse; + return FcTrue; + } + } + return FcFalse; +} + +static FcValue +FcNameConvert (FcType type, FcChar8 *string) +{ + FcValue v; + FcMatrix m; + + v.type = type; + switch ((int) v.type) { + case FcTypeInteger: + if (!FcNameConstant (string, &v.u.i)) + v.u.i = atoi ((char *) string); + break; + case FcTypeString: + v.u.s = FcStrdup (string); + if (!v.u.s) + v.type = FcTypeVoid; + break; + case FcTypeBool: + if (!FcNameBool (string, &v.u.b)) + v.u.b = FcFalse; + break; + case FcTypeDouble: + v.u.d = strtod ((char *) string, 0); + break; + case FcTypeMatrix: + FcMatrixInit (&m); + sscanf ((char *) string, "%lg %lg %lg %lg", &m.xx, &m.xy, &m.yx, &m.yy); + v.u.m = FcMatrixCopy (&m); + break; + case FcTypeCharSet: + v.u.c = FcNameParseCharSet (string); + if (!v.u.c) + v.type = FcTypeVoid; + break; + case FcTypeLangSet: + v.u.l = FcNameParseLangSet (string); + if (!v.u.l) + v.type = FcTypeVoid; + break; + default: + break; + } + return v; +} + +static const FcChar8 * +FcNameFindNext (const FcChar8 *cur, const char *delim, FcChar8 *save, FcChar8 *last) +{ + FcChar8 c; + + while ((c = *cur)) + { + if (!isspace (c)) + break; + ++cur; + } + while ((c = *cur)) + { + if (c == '\\') + { + ++cur; + if (!(c = *cur)) + break; + } + else if (strchr (delim, c)) + break; + ++cur; + *save++ = c; + } + *save = 0; + *last = *cur; + if (*cur) + cur++; + return cur; +} + +FcPattern * +FcNameParse (const FcChar8 *name) +{ + FcChar8 *save; + FcPattern *pat; + double d; + FcChar8 *e; + FcChar8 delim; + FcValue v; + const FcObjectType *t; + const FcConstant *c; + + /* freed below */ + save = malloc (strlen ((char *) name) + 1); + if (!save) + goto bail0; + pat = FcPatternCreate (); + if (!pat) + goto bail1; + + for (;;) + { + name = FcNameFindNext (name, "-,:", save, &delim); + if (save[0]) + { + if (!FcPatternAddString (pat, FC_FAMILY, save)) + goto bail2; + } + if (delim != ',') + break; + } + if (delim == '-') + { + for (;;) + { + name = FcNameFindNext (name, "-,:", save, &delim); + d = strtod ((char *) save, (char **) &e); + if (e != save) + { + if (!FcPatternAddDouble (pat, FC_SIZE, d)) + goto bail2; + } + if (delim != ',') + break; + } + } + while (delim == ':') + { + name = FcNameFindNext (name, "=_:", save, &delim); + if (save[0]) + { + if (delim == '=' || delim == '_') + { + t = FcNameGetObjectType ((char *) save); + for (;;) + { + name = FcNameFindNext (name, ":,", save, &delim); + if (t) + { + v = FcNameConvert (t->type, save); + if (!FcPatternAdd (pat, t->object, v, FcTrue)) + { + FcValueDestroy (v); + goto bail2; + } + FcValueDestroy (v); + } + if (delim != ',') + break; + } + } + else + { + if ((c = FcNameGetConstant (save))) + { + t = FcNameGetObjectType ((char *) c->object); + if (t == NULL) + goto bail2; + switch ((int) t->type) { + case FcTypeInteger: + case FcTypeDouble: + if (!FcPatternAddInteger (pat, c->object, c->value)) + goto bail2; + break; + case FcTypeBool: + if (!FcPatternAddBool (pat, c->object, c->value)) + goto bail2; + break; + default: + break; + } + } + } + } + } + + free (save); + return pat; + +bail2: + FcPatternDestroy (pat); +bail1: + free (save); +bail0: + return 0; +} +static FcBool +FcNameUnparseString (FcStrBuf *buf, + const FcChar8 *string, + const FcChar8 *escape) +{ + FcChar8 c; + while ((c = *string++)) + { + if (escape && strchr ((char *) escape, (char) c)) + { + if (!FcStrBufChar (buf, escape[0])) + return FcFalse; + } + if (!FcStrBufChar (buf, c)) + return FcFalse; + } + return FcTrue; +} + +FcBool +FcNameUnparseValue (FcStrBuf *buf, + FcValue *v0, + FcChar8 *escape) +{ + FcChar8 temp[1024]; + FcValue v = FcValueCanonicalize(v0); + + switch (v.type) { + case FcTypeUnknown: + case FcTypeVoid: + return FcTrue; + case FcTypeInteger: + sprintf ((char *) temp, "%d", v.u.i); + return FcNameUnparseString (buf, temp, 0); + case FcTypeDouble: + sprintf ((char *) temp, "%g", v.u.d); + return FcNameUnparseString (buf, temp, 0); + case FcTypeString: + return FcNameUnparseString (buf, v.u.s, escape); + case FcTypeBool: + return FcNameUnparseString (buf, v.u.b ? (FcChar8 *) "True" : (FcChar8 *) "False", 0); + case FcTypeMatrix: + sprintf ((char *) temp, "%g %g %g %g", + v.u.m->xx, v.u.m->xy, v.u.m->yx, v.u.m->yy); + return FcNameUnparseString (buf, temp, 0); + case FcTypeCharSet: + return FcNameUnparseCharSet (buf, v.u.c); + case FcTypeLangSet: + return FcNameUnparseLangSet (buf, v.u.l); + case FcTypeFTFace: + return FcTrue; + } + return FcFalse; +} + +FcBool +FcNameUnparseValueList (FcStrBuf *buf, + FcValueListPtr v, + FcChar8 *escape) +{ + while (v) + { + if (!FcNameUnparseValue (buf, &v->value, escape)) + return FcFalse; + if ((v = FcValueListNext(v)) != NULL) + if (!FcNameUnparseString (buf, (FcChar8 *) ",", 0)) + return FcFalse; + } + return FcTrue; +} + +#define FC_ESCAPE_FIXED "\\-:," +#define FC_ESCAPE_VARIABLE "\\=_:," + +FcChar8 * +FcNameUnparse (FcPattern *pat) +{ + return FcNameUnparseEscaped (pat, FcTrue); +} + +FcChar8 * +FcNameUnparseEscaped (FcPattern *pat, FcBool escape) +{ + FcStrBuf buf; + FcChar8 buf_static[8192]; + int i; + FcPatternElt *e; + + FcStrBufInit (&buf, buf_static, sizeof (buf_static)); + e = FcPatternObjectFindElt (pat, FC_FAMILY_OBJECT); + if (e) + { + if (!FcNameUnparseValueList (&buf, FcPatternEltValues(e), escape ? (FcChar8 *) FC_ESCAPE_FIXED : 0)) + goto bail0; + } + e = FcPatternObjectFindElt (pat, FC_SIZE_OBJECT); + if (e) + { + if (!FcNameUnparseString (&buf, (FcChar8 *) "-", 0)) + goto bail0; + if (!FcNameUnparseValueList (&buf, FcPatternEltValues(e), escape ? (FcChar8 *) FC_ESCAPE_FIXED : 0)) + goto bail0; + } + for (i = 0; i < NUM_OBJECT_TYPES; i++) + { + FcObject id = i + 1; + const FcObjectType *o; + o = &FcObjects[i]; + if (!strcmp (o->object, FC_FAMILY) || + !strcmp (o->object, FC_SIZE)) + continue; + + e = FcPatternObjectFindElt (pat, id); + if (e) + { + if (!FcNameUnparseString (&buf, (FcChar8 *) ":", 0)) + goto bail0; + if (!FcNameUnparseString (&buf, (FcChar8 *) o->object, escape ? (FcChar8 *) FC_ESCAPE_VARIABLE : 0)) + goto bail0; + if (!FcNameUnparseString (&buf, (FcChar8 *) "=", 0)) + goto bail0; + if (!FcNameUnparseValueList (&buf, FcPatternEltValues(e), escape ? + (FcChar8 *) FC_ESCAPE_VARIABLE : 0)) + goto bail0; + } + } + return FcStrBufDone (&buf); +bail0: + FcStrBufDestroy (&buf); + return 0; +} +#define __fcname__ +#include "fcaliastail.h" +#undef __fcname__ diff --git a/project/jni/fontconfig/src/fcobjs.c b/project/jni/fontconfig/src/fcobjs.c new file mode 100644 index 000000000..bad9824d4 --- /dev/null +++ b/project/jni/fontconfig/src/fcobjs.c @@ -0,0 +1,139 @@ +/* + * fontconfig/src/fclist.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" + +static unsigned int +FcObjectTypeHash (register const char *str, register unsigned int len); + +static const struct FcObjectTypeInfo * +FcObjectTypeLookup (register const char *str, register unsigned int len); + +#include "fcobjshash.h" + +#include + +/* The 1000 is to leave some room for future added internal objects, such + * that caches from newer fontconfig can still be used with older fontconfig + * without getting confused. */ +static fc_atomic_int_t next_id = FC_MAX_BASE_OBJECT + FC_EXT_OBJ_INDEX; +struct FcObjectOtherTypeInfo { + struct FcObjectOtherTypeInfo *next; + FcObjectType object; + FcObject id; +} *other_types; + +static FcObjectType * +_FcObjectLookupOtherTypeByName (const char *str, FcObject *id) +{ + struct FcObjectOtherTypeInfo *ots, *ot; + +retry: + ots = fc_atomic_ptr_get (&other_types); + + for (ot = ots; ot; ot = ot->next) + if (0 == strcmp (ot->object.object, str)) + break; + + if (!ot) + { + ot = malloc (sizeof (*ot)); + if (!ot) + return NULL; + + ot->object.object = (const char *) FcStrdup (str); + ot->object.type = FcTypeUnknown; + ot->id = fc_atomic_int_add (next_id, +1); + ot->next = ots; + + if (!fc_atomic_ptr_cmpexch (&other_types, ots, ot)) { + free (ot); + goto retry; + } + } + + if (id) + *id = ot->id; + + return &ot->object; +} + +FcObject +FcObjectLookupBuiltinIdByName (const char *str) +{ + const struct FcObjectTypeInfo *o = FcObjectTypeLookup (str, strlen (str)); + + if (o) + return o->id; + + return 0; +} + +FcObject +FcObjectLookupIdByName (const char *str) +{ + const struct FcObjectTypeInfo *o = FcObjectTypeLookup (str, strlen (str)); + FcObject id; + if (o) + return o->id; + + if (_FcObjectLookupOtherTypeByName (str, &id)) + return id; + + return 0; +} + +const char * +FcObjectLookupOtherNameById (FcObject id) +{ + struct FcObjectOtherTypeInfo *ot; + + for (ot = fc_atomic_ptr_get (&other_types); ot; ot = ot->next) + if (ot->id == id) + return ot->object.object; + + return NULL; +} + +const FcObjectType * +FcObjectLookupOtherTypeByName (const char *str) +{ + return _FcObjectLookupOtherTypeByName (str, NULL); +} + +FcPrivate const FcObjectType * +FcObjectLookupOtherTypeById (FcObject id) +{ + struct FcObjectOtherTypeInfo *ot; + + for (ot = fc_atomic_ptr_get (&other_types); ot; ot = ot->next) + if (ot->id == id) + return &ot->object; + + return NULL; +} + + +#include "fcaliastail.h" +#undef __fcobjs__ diff --git a/project/jni/fontconfig/src/fcobjs.h b/project/jni/fontconfig/src/fcobjs.h new file mode 100644 index 000000000..a0ee0795b --- /dev/null +++ b/project/jni/fontconfig/src/fcobjs.h @@ -0,0 +1,71 @@ +/* + * fontconfig/src/fcobjs.h + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ +/* DON'T REORDER! The order is part of the cache signature. */ +FC_OBJECT (FAMILY, FcTypeString, FcCompareFamily) +FC_OBJECT (FAMILYLANG, FcTypeString, NULL) +FC_OBJECT (STYLE, FcTypeString, FcCompareString) +FC_OBJECT (STYLELANG, FcTypeString, NULL) +FC_OBJECT (FULLNAME, FcTypeString, NULL) +FC_OBJECT (FULLNAMELANG, FcTypeString, NULL) +FC_OBJECT (SLANT, FcTypeInteger, FcCompareNumber) +FC_OBJECT (WEIGHT, FcTypeInteger, FcCompareNumber) +FC_OBJECT (WIDTH, FcTypeInteger, FcCompareNumber) +FC_OBJECT (SIZE, FcTypeDouble, NULL) +FC_OBJECT (ASPECT, FcTypeDouble, NULL) +FC_OBJECT (PIXEL_SIZE, FcTypeDouble, FcCompareSize) +FC_OBJECT (SPACING, FcTypeInteger, FcCompareNumber) +FC_OBJECT (FOUNDRY, FcTypeString, FcCompareString) +FC_OBJECT (ANTIALIAS, FcTypeBool, FcCompareBool) +FC_OBJECT (HINT_STYLE, FcTypeInteger, NULL) +FC_OBJECT (HINTING, FcTypeBool, NULL) +FC_OBJECT (VERTICAL_LAYOUT, FcTypeBool, NULL) +FC_OBJECT (AUTOHINT, FcTypeBool, NULL) +FC_OBJECT (GLOBAL_ADVANCE, FcTypeBool, NULL) /* deprecated */ +FC_OBJECT (FILE, FcTypeString, FcCompareFilename) +FC_OBJECT (INDEX, FcTypeInteger, NULL) +FC_OBJECT (RASTERIZER, FcTypeString, FcCompareString) +FC_OBJECT (OUTLINE, FcTypeBool, FcCompareBool) +FC_OBJECT (SCALABLE, FcTypeBool, FcCompareBool) +FC_OBJECT (DPI, FcTypeDouble, NULL) +FC_OBJECT (RGBA, FcTypeInteger, NULL) +FC_OBJECT (SCALE, FcTypeDouble, NULL) +FC_OBJECT (MINSPACE, FcTypeBool, NULL) +FC_OBJECT (CHAR_WIDTH, FcTypeInteger, NULL) +FC_OBJECT (CHAR_HEIGHT, FcTypeInteger, NULL) +FC_OBJECT (MATRIX, FcTypeMatrix, NULL) +FC_OBJECT (CHARSET, FcTypeCharSet, FcCompareCharSet) +FC_OBJECT (LANG, FcTypeLangSet, FcCompareLang) +FC_OBJECT (FONTVERSION, FcTypeInteger, FcCompareNumber) +FC_OBJECT (CAPABILITY, FcTypeString, NULL) +FC_OBJECT (FONTFORMAT, FcTypeString, FcCompareString) +FC_OBJECT (EMBOLDEN, FcTypeBool, NULL) +FC_OBJECT (EMBEDDED_BITMAP, FcTypeBool, NULL) +FC_OBJECT (DECORATIVE, FcTypeBool, FcCompareBool) +FC_OBJECT (LCD_FILTER, FcTypeInteger, NULL) +FC_OBJECT (NAMELANG, FcTypeString, NULL) +FC_OBJECT (FONT_FEATURES, FcTypeString, NULL) +FC_OBJECT (PRGNAME, FcTypeString, NULL) +FC_OBJECT (HASH, FcTypeString, FcCompareHash) +FC_OBJECT (POSTSCRIPT_NAME, FcTypeString, FcComparePostScript) +/* ^-------------- Add new objects here. */ diff --git a/project/jni/fontconfig/src/fcobjshash.h b/project/jni/fontconfig/src/fcobjshash.h new file mode 100644 index 000000000..2081ce5a2 --- /dev/null +++ b/project/jni/fontconfig/src/fcobjshash.h @@ -0,0 +1,317 @@ +/* ANSI-C code produced by gperf version 3.0.3 */ +/* Command-line: gperf -m 100 fcobjshash.gperf */ +/* Computed positions: -k'2-3' */ + +#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) +/* The character set is not based on ISO-646. */ +#error "gperf generated tables don't work with this execution character set. Please report a bug to ." +#endif + +#line 1 "fcobjshash.gperf" + +#line 13 "fcobjshash.gperf" +struct FcObjectTypeInfo { +int name; +int id; +}; +#include +/* maximum key range = 52, duplicates = 0 */ + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static unsigned int +FcObjectTypeHash (register const char *str, register unsigned int len) +{ + static const unsigned char asso_values[] = + { + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 17, 12, 1, + 35, 0, 56, 27, 15, 0, 56, 56, 0, 7, + 7, 0, 22, 56, 21, 10, 13, 0, 56, 56, + 0, 26, 1, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56 + }; + return len + asso_values[(unsigned char)str[2]] + asso_values[(unsigned char)str[1]]; +} + +struct FcObjectTypeNamePool_t + { + char FcObjectTypeNamePool_str4[sizeof("file")]; + char FcObjectTypeNamePool_str5[sizeof("size")]; + char FcObjectTypeNamePool_str6[sizeof("weight")]; + char FcObjectTypeNamePool_str7[sizeof("foundry")]; + char FcObjectTypeNamePool_str8[sizeof("fullname")]; + char FcObjectTypeNamePool_str9[sizeof("pixelsize")]; + char FcObjectTypeNamePool_str11[sizeof("decorative")]; + char FcObjectTypeNamePool_str12[sizeof("fullnamelang")]; + char FcObjectTypeNamePool_str13[sizeof("globaladvance")]; + char FcObjectTypeNamePool_str14[sizeof("hinting")]; + char FcObjectTypeNamePool_str15[sizeof("minspace")]; + char FcObjectTypeNamePool_str16[sizeof("hintstyle")]; + char FcObjectTypeNamePool_str17[sizeof("fontformat")]; + char FcObjectTypeNamePool_str18[sizeof("fontversion")]; + char FcObjectTypeNamePool_str19[sizeof("fontfeatures")]; + char FcObjectTypeNamePool_str20[sizeof("outline")]; + char FcObjectTypeNamePool_str21[sizeof("autohint")]; + char FcObjectTypeNamePool_str22[sizeof("slant")]; + char FcObjectTypeNamePool_str23[sizeof("scale")]; + char FcObjectTypeNamePool_str24[sizeof("postscriptname")]; + char FcObjectTypeNamePool_str25[sizeof("dpi")]; + char FcObjectTypeNamePool_str26[sizeof("scalable")]; + char FcObjectTypeNamePool_str27[sizeof("embolden")]; + char FcObjectTypeNamePool_str28[sizeof("lang")]; + char FcObjectTypeNamePool_str29[sizeof("antialias")]; + char FcObjectTypeNamePool_str30[sizeof("family")]; + char FcObjectTypeNamePool_str31[sizeof("hash")]; + char FcObjectTypeNamePool_str32[sizeof("namelang")]; + char FcObjectTypeNamePool_str33[sizeof("embeddedbitmap")]; + char FcObjectTypeNamePool_str34[sizeof("familylang")]; + char FcObjectTypeNamePool_str35[sizeof("verticallayout")]; + char FcObjectTypeNamePool_str36[sizeof("matrix")]; + char FcObjectTypeNamePool_str37[sizeof("rasterizer")]; + char FcObjectTypeNamePool_str38[sizeof("aspect")]; + char FcObjectTypeNamePool_str39[sizeof("charset")]; + char FcObjectTypeNamePool_str40[sizeof("width")]; + char FcObjectTypeNamePool_str41[sizeof("charwidth")]; + char FcObjectTypeNamePool_str42[sizeof("charheight")]; + char FcObjectTypeNamePool_str43[sizeof("rgba")]; + char FcObjectTypeNamePool_str44[sizeof("style")]; + char FcObjectTypeNamePool_str45[sizeof("lcdfilter")]; + char FcObjectTypeNamePool_str46[sizeof("spacing")]; + char FcObjectTypeNamePool_str47[sizeof("index")]; + char FcObjectTypeNamePool_str48[sizeof("stylelang")]; + char FcObjectTypeNamePool_str49[sizeof("capability")]; + char FcObjectTypeNamePool_str55[sizeof("prgname")]; + }; +static const struct FcObjectTypeNamePool_t FcObjectTypeNamePool_contents = + { + "file", + "size", + "weight", + "foundry", + "fullname", + "pixelsize", + "decorative", + "fullnamelang", + "globaladvance", + "hinting", + "minspace", + "hintstyle", + "fontformat", + "fontversion", + "fontfeatures", + "outline", + "autohint", + "slant", + "scale", + "postscriptname", + "dpi", + "scalable", + "embolden", + "lang", + "antialias", + "family", + "hash", + "namelang", + "embeddedbitmap", + "familylang", + "verticallayout", + "matrix", + "rasterizer", + "aspect", + "charset", + "width", + "charwidth", + "charheight", + "rgba", + "style", + "lcdfilter", + "spacing", + "index", + "stylelang", + "capability", + "prgname" + }; +#define FcObjectTypeNamePool ((const char *) &FcObjectTypeNamePool_contents) +#ifdef __GNUC__ +__inline +#ifdef __GNUC_STDC_INLINE__ +__attribute__ ((__gnu_inline__)) +#endif +#endif +const struct FcObjectTypeInfo * +FcObjectTypeLookup (register const char *str, register unsigned int len) +{ + enum + { + TOTAL_KEYWORDS = 46, + MIN_WORD_LENGTH = 3, + MAX_WORD_LENGTH = 14, + MIN_HASH_VALUE = 4, + MAX_HASH_VALUE = 55 + }; + + static const struct FcObjectTypeInfo wordlist[] = + { + {-1}, {-1}, {-1}, {-1}, +#line 38 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str4,FC_FILE_OBJECT}, +#line 27 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str5,FC_SIZE_OBJECT}, +#line 25 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str6,FC_WEIGHT_OBJECT}, +#line 31 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str7,FC_FOUNDRY_OBJECT}, +#line 22 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str8,FC_FULLNAME_OBJECT}, +#line 29 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str9,FC_PIXEL_SIZE_OBJECT}, + {-1}, +#line 57 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str11,FC_DECORATIVE_OBJECT}, +#line 23 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str12,FC_FULLNAMELANG_OBJECT}, +#line 37 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str13,FC_GLOBAL_ADVANCE_OBJECT}, +#line 34 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str14,FC_HINTING_OBJECT}, +#line 46 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str15,FC_MINSPACE_OBJECT}, +#line 33 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str16,FC_HINT_STYLE_OBJECT}, +#line 54 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str17,FC_FONTFORMAT_OBJECT}, +#line 52 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str18,FC_FONTVERSION_OBJECT}, +#line 60 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str19,FC_FONT_FEATURES_OBJECT}, +#line 41 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str20,FC_OUTLINE_OBJECT}, +#line 36 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str21,FC_AUTOHINT_OBJECT}, +#line 24 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str22,FC_SLANT_OBJECT}, +#line 45 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str23,FC_SCALE_OBJECT}, +#line 63 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str24,FC_POSTSCRIPT_NAME_OBJECT}, +#line 43 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str25,FC_DPI_OBJECT}, +#line 42 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str26,FC_SCALABLE_OBJECT}, +#line 55 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str27,FC_EMBOLDEN_OBJECT}, +#line 51 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str28,FC_LANG_OBJECT}, +#line 32 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str29,FC_ANTIALIAS_OBJECT}, +#line 18 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str30,FC_FAMILY_OBJECT}, +#line 62 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str31,FC_HASH_OBJECT}, +#line 59 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str32,FC_NAMELANG_OBJECT}, +#line 56 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str33,FC_EMBEDDED_BITMAP_OBJECT}, +#line 19 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str34,FC_FAMILYLANG_OBJECT}, +#line 35 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str35,FC_VERTICAL_LAYOUT_OBJECT}, +#line 49 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str36,FC_MATRIX_OBJECT}, +#line 40 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str37,FC_RASTERIZER_OBJECT}, +#line 28 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str38,FC_ASPECT_OBJECT}, +#line 50 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str39,FC_CHARSET_OBJECT}, +#line 26 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str40,FC_WIDTH_OBJECT}, +#line 47 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str41,FC_CHAR_WIDTH_OBJECT}, +#line 48 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str42,FC_CHAR_HEIGHT_OBJECT}, +#line 44 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str43,FC_RGBA_OBJECT}, +#line 20 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str44,FC_STYLE_OBJECT}, +#line 58 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str45,FC_LCD_FILTER_OBJECT}, +#line 30 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str46,FC_SPACING_OBJECT}, +#line 39 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str47,FC_INDEX_OBJECT}, +#line 21 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str48,FC_STYLELANG_OBJECT}, +#line 53 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str49,FC_CAPABILITY_OBJECT}, + {-1}, {-1}, {-1}, {-1}, {-1}, +#line 61 "fcobjshash.gperf" + {(int)(long)&((struct FcObjectTypeNamePool_t *)0)->FcObjectTypeNamePool_str55,FC_PRGNAME_OBJECT} + }; + + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + register int key = FcObjectTypeHash (str, len); + + if (key <= MAX_HASH_VALUE && key >= 0) + { + register int o = wordlist[key].name; + if (o >= 0) + { + register const char *s = o + FcObjectTypeNamePool; + + if (*str == *s && !strcmp (str + 1, s + 1)) + return &wordlist[key]; + } + } + } + return 0; +} diff --git a/project/jni/fontconfig/src/fcpat.c b/project/jni/fontconfig/src/fcpat.c new file mode 100644 index 000000000..986cca391 --- /dev/null +++ b/project/jni/fontconfig/src/fcpat.c @@ -0,0 +1,1318 @@ +/* + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include "fcftint.h" + +/* Objects MT-safe for readonly access. */ + +FcPattern * +FcPatternCreate (void) +{ + FcPattern *p; + + p = (FcPattern *) malloc (sizeof (FcPattern)); + if (!p) + return 0; + memset (p, 0, sizeof (FcPattern)); + p->num = 0; + p->size = 0; + p->elts_offset = FcPtrToOffset (p, NULL); + FcRefInit (&p->ref, 1); + return p; +} + +void +FcValueDestroy (FcValue v) +{ + switch ((int) v.type) { + case FcTypeString: + FcFree (v.u.s); + break; + case FcTypeMatrix: + FcMatrixFree ((FcMatrix *) v.u.m); + break; + case FcTypeCharSet: + FcCharSetDestroy ((FcCharSet *) v.u.c); + break; + case FcTypeLangSet: + FcLangSetDestroy ((FcLangSet *) v.u.l); + break; + default: + break; + } +} + +FcValue +FcValueCanonicalize (const FcValue *v) +{ + FcValue new; + + switch ((int) v->type) + { + case FcTypeString: + new.u.s = FcValueString(v); + new.type = FcTypeString; + break; + case FcTypeCharSet: + new.u.c = FcValueCharSet(v); + new.type = FcTypeCharSet; + break; + case FcTypeLangSet: + new.u.l = FcValueLangSet(v); + new.type = FcTypeLangSet; + break; + default: + new = *v; + break; + } + return new; +} + +FcValue +FcValueSave (FcValue v) +{ + switch ((int) v.type) { + case FcTypeString: + v.u.s = FcStrdup (v.u.s); + if (!v.u.s) + v.type = FcTypeVoid; + break; + case FcTypeMatrix: + v.u.m = FcMatrixCopy (v.u.m); + if (!v.u.m) + v.type = FcTypeVoid; + break; + case FcTypeCharSet: + v.u.c = FcCharSetCopy ((FcCharSet *) v.u.c); + if (!v.u.c) + v.type = FcTypeVoid; + break; + case FcTypeLangSet: + v.u.l = FcLangSetCopy (v.u.l); + if (!v.u.l) + v.type = FcTypeVoid; + break; + default: + break; + } + return v; +} + +FcValueListPtr +FcValueListCreate (void) +{ + return calloc (1, sizeof (FcValueList)); +} + +void +FcValueListDestroy (FcValueListPtr l) +{ + FcValueListPtr next; + for (; l; l = next) + { + switch ((int) l->value.type) { + case FcTypeString: + FcFree (l->value.u.s); + break; + case FcTypeMatrix: + FcMatrixFree ((FcMatrix *)l->value.u.m); + break; + case FcTypeCharSet: + FcCharSetDestroy + ((FcCharSet *) (l->value.u.c)); + break; + case FcTypeLangSet: + FcLangSetDestroy + ((FcLangSet *) (l->value.u.l)); + break; + default: + break; + } + next = FcValueListNext(l); + free(l); + } +} + +FcValueListPtr +FcValueListPrepend (FcValueListPtr vallist, + FcValue value, + FcValueBinding binding) +{ + FcValueListPtr new; + + if (value.type == FcTypeVoid) + return vallist; + new = FcValueListCreate (); + if (!new) + return vallist; + + new->value = FcValueSave (value); + new->binding = binding; + new->next = vallist; + + return new; +} + +FcValueListPtr +FcValueListAppend (FcValueListPtr vallist, + FcValue value, + FcValueBinding binding) +{ + FcValueListPtr new, last; + + if (value.type == FcTypeVoid) + return vallist; + new = FcValueListCreate (); + if (!new) + return vallist; + + new->value = FcValueSave (value); + new->binding = binding; + new->next = NULL; + + if (vallist) + { + for (last = vallist; FcValueListNext (last); last = FcValueListNext (last)); + + last->next = new; + } + else + vallist = new; + + return vallist; +} + +FcValueListPtr +FcValueListDuplicate(FcValueListPtr orig) +{ + FcValueListPtr new = NULL, l, t = NULL; + FcValue v; + + for (l = orig; l != NULL; l = FcValueListNext (l)) + { + if (!new) + { + t = new = FcValueListCreate(); + } + else + { + t->next = FcValueListCreate(); + t = FcValueListNext (t); + } + v = FcValueCanonicalize (&l->value); + t->value = FcValueSave (v); + t->binding = l->binding; + t->next = NULL; + } + + return new; +} + +FcBool +FcValueEqual (FcValue va, FcValue vb) +{ + if (va.type != vb.type) + { + if (va.type == FcTypeInteger) + { + va.type = FcTypeDouble; + va.u.d = va.u.i; + } + if (vb.type == FcTypeInteger) + { + vb.type = FcTypeDouble; + vb.u.d = vb.u.i; + } + if (va.type != vb.type) + return FcFalse; + } + switch (va.type) { + case FcTypeUnknown: + return FcFalse; /* don't know how to compare this object */ + case FcTypeVoid: + return FcTrue; + case FcTypeInteger: + return va.u.i == vb.u.i; + case FcTypeDouble: + return va.u.d == vb.u.d; + case FcTypeString: + return FcStrCmpIgnoreCase (va.u.s, vb.u.s) == 0; + case FcTypeBool: + return va.u.b == vb.u.b; + case FcTypeMatrix: + return FcMatrixEqual (va.u.m, vb.u.m); + case FcTypeCharSet: + return FcCharSetEqual (va.u.c, vb.u.c); + case FcTypeFTFace: + return va.u.f == vb.u.f; + case FcTypeLangSet: + return FcLangSetEqual (va.u.l, vb.u.l); + } + return FcFalse; +} + +static FcChar32 +FcDoubleHash (double d) +{ + if (d < 0) + d = -d; + if (d > 0xffffffff) + d = 0xffffffff; + return (FcChar32) d; +} + +FcChar32 +FcStringHash (const FcChar8 *s) +{ + FcChar8 c; + FcChar32 h = 0; + + if (s) + while ((c = *s++)) + h = ((h << 1) | (h >> 31)) ^ c; + return h; +} + +static FcChar32 +FcValueHash (const FcValue *v) +{ + switch (v->type) { + case FcTypeUnknown: + case FcTypeVoid: + return 0; + case FcTypeInteger: + return (FcChar32) v->u.i; + case FcTypeDouble: + return FcDoubleHash (v->u.d); + case FcTypeString: + return FcStringHash (FcValueString(v)); + case FcTypeBool: + return (FcChar32) v->u.b; + case FcTypeMatrix: + return (FcDoubleHash (v->u.m->xx) ^ + FcDoubleHash (v->u.m->xy) ^ + FcDoubleHash (v->u.m->yx) ^ + FcDoubleHash (v->u.m->yy)); + case FcTypeCharSet: + return (FcChar32) FcValueCharSet(v)->num; + case FcTypeFTFace: + return FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->family_name) ^ + FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->style_name); + case FcTypeLangSet: + return FcLangSetHash (FcValueLangSet(v)); + } + return 0; +} + +static FcBool +FcValueListEqual (FcValueListPtr la, FcValueListPtr lb) +{ + if (la == lb) + return FcTrue; + + while (la && lb) + { + if (!FcValueEqual (la->value, lb->value)) + return FcFalse; + la = FcValueListNext(la); + lb = FcValueListNext(lb); + } + if (la || lb) + return FcFalse; + return FcTrue; +} + +static FcChar32 +FcValueListHash (FcValueListPtr l) +{ + FcChar32 hash = 0; + + for (; l; l = FcValueListNext(l)) + { + hash = ((hash << 1) | (hash >> 31)) ^ FcValueHash (&l->value); + } + return hash; +} + +void +FcPatternDestroy (FcPattern *p) +{ + int i; + FcPatternElt *elts; + + if (!p) + return; + + if (FcRefIsConst (&p->ref)) + { + FcCacheObjectDereference (p); + return; + } + + if (FcRefDec (&p->ref) != 1) + return; + + elts = FcPatternElts (p); + for (i = 0; i < p->num; i++) + FcValueListDestroy (FcPatternEltValues(&elts[i])); + + free (elts); + free (p); +} + +static int +FcPatternObjectPosition (const FcPattern *p, FcObject object) +{ + int low, high, mid, c; + FcPatternElt *elts = FcPatternElts(p); + + low = 0; + high = p->num - 1; + c = 1; + mid = 0; + while (low <= high) + { + mid = (low + high) >> 1; + c = elts[mid].object - object; + if (c == 0) + return mid; + if (c < 0) + low = mid + 1; + else + high = mid - 1; + } + if (c < 0) + mid++; + return -(mid + 1); +} + +FcPatternElt * +FcPatternObjectFindElt (const FcPattern *p, FcObject object) +{ + int i = FcPatternObjectPosition (p, object); + if (i < 0) + return 0; + return &FcPatternElts(p)[i]; +} + +FcPatternElt * +FcPatternObjectInsertElt (FcPattern *p, FcObject object) +{ + int i; + FcPatternElt *e; + + i = FcPatternObjectPosition (p, object); + if (i < 0) + { + i = -i - 1; + + /* reallocate array */ + if (p->num + 1 >= p->size) + { + int s = p->size + 16; + if (p->size) + { + FcPatternElt *e0 = FcPatternElts(p); + e = (FcPatternElt *) realloc (e0, s * sizeof (FcPatternElt)); + if (!e) /* maybe it was mmapped */ + { + e = malloc(s * sizeof (FcPatternElt)); + if (e) + memcpy(e, e0, p->num * sizeof (FcPatternElt)); + } + } + else + e = (FcPatternElt *) malloc (s * sizeof (FcPatternElt)); + if (!e) + return FcFalse; + p->elts_offset = FcPtrToOffset (p, e); + while (p->size < s) + { + e[p->size].object = 0; + e[p->size].values = NULL; + p->size++; + } + } + + e = FcPatternElts(p); + /* move elts up */ + memmove (e + i + 1, + e + i, + sizeof (FcPatternElt) * + (p->num - i)); + + /* bump count */ + p->num++; + + e[i].object = object; + e[i].values = NULL; + } + + return FcPatternElts(p) + i; +} + +FcBool +FcPatternEqual (const FcPattern *pa, const FcPattern *pb) +{ + int i; + FcPatternElt *pae, *pbe; + + if (pa == pb) + return FcTrue; + + if (pa->num != pb->num) + return FcFalse; + pae = FcPatternElts(pa); + pbe = FcPatternElts(pb); + for (i = 0; i < pa->num; i++) + { + if (pae[i].object != pbe[i].object) + return FcFalse; + if (!FcValueListEqual (FcPatternEltValues(&pae[i]), + FcPatternEltValues(&pbe[i]))) + return FcFalse; + } + return FcTrue; +} + +FcChar32 +FcPatternHash (const FcPattern *p) +{ + int i; + FcChar32 h = 0; + FcPatternElt *pe = FcPatternElts(p); + + for (i = 0; i < p->num; i++) + { + h = (((h << 1) | (h >> 31)) ^ + pe[i].object ^ + FcValueListHash (FcPatternEltValues(&pe[i]))); + } + return h; +} + +FcBool +FcPatternEqualSubset (const FcPattern *pai, const FcPattern *pbi, const FcObjectSet *os) +{ + FcPatternElt *ea, *eb; + int i; + + for (i = 0; i < os->nobject; i++) + { + FcObject object = FcObjectFromName (os->objects[i]); + ea = FcPatternObjectFindElt (pai, object); + eb = FcPatternObjectFindElt (pbi, object); + if (ea) + { + if (!eb) + return FcFalse; + if (!FcValueListEqual (FcPatternEltValues(ea), FcPatternEltValues(eb))) + return FcFalse; + } + else + { + if (eb) + return FcFalse; + } + } + return FcTrue; +} + +FcBool +FcPatternObjectListAdd (FcPattern *p, + FcObject object, + FcValueListPtr list, + FcBool append) +{ + FcPatternElt *e; + FcValueListPtr l, *prev; + + if (FcRefIsConst (&p->ref)) + goto bail0; + + /* + * Make sure the stored type is valid for built-in objects + */ + for (l = list; l != NULL; l = FcValueListNext (l)) + { + if (!FcObjectValidType (object, l->value.type)) + { + fprintf (stderr, + "Fontconfig warning: FcPattern object %s does not accept value", FcObjectName (object)); + FcValuePrintFile (stderr, l->value); + fprintf (stderr, "\n"); + goto bail0; + } + } + + e = FcPatternObjectInsertElt (p, object); + if (!e) + goto bail0; + + if (append) + { + for (prev = &e->values; *prev; prev = &(*prev)->next) + ; + *prev = list; + } + else + { + for (prev = &list; *prev; prev = &(*prev)->next) + ; + *prev = e->values; + e->values = list; + } + + return FcTrue; + +bail0: + return FcFalse; +} + +FcBool +FcPatternObjectAddWithBinding (FcPattern *p, + FcObject object, + FcValue value, + FcValueBinding binding, + FcBool append) +{ + FcPatternElt *e; + FcValueListPtr new, *prev; + + if (FcRefIsConst (&p->ref)) + goto bail0; + + new = FcValueListCreate (); + if (!new) + goto bail0; + + value = FcValueSave (value); + if (value.type == FcTypeVoid) + goto bail1; + + /* + * Make sure the stored type is valid for built-in objects + */ + if (!FcObjectValidType (object, value.type)) + { + fprintf (stderr, + "Fontconfig warning: FcPattern object %s does not accept value", + FcObjectName (object)); + FcValuePrintFile (stderr, value); + fprintf (stderr, "\n"); + goto bail1; + } + + new->value = value; + new->binding = binding; + new->next = NULL; + + e = FcPatternObjectInsertElt (p, object); + if (!e) + goto bail2; + + if (append) + { + for (prev = &e->values; *prev; prev = &(*prev)->next) + ; + *prev = new; + } + else + { + new->next = e->values; + e->values = new; + } + + return FcTrue; + +bail2: + FcValueDestroy (value); +bail1: + free (new); +bail0: + return FcFalse; +} + +FcBool +FcPatternObjectAdd (FcPattern *p, FcObject object, FcValue value, FcBool append) +{ + return FcPatternObjectAddWithBinding (p, object, + value, FcValueBindingStrong, append); +} + +FcBool +FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append) +{ + return FcPatternObjectAddWithBinding (p, FcObjectFromName (object), + value, FcValueBindingStrong, append); +} + +FcBool +FcPatternAddWeak (FcPattern *p, const char *object, FcValue value, FcBool append) +{ + return FcPatternObjectAddWithBinding (p, FcObjectFromName (object), + value, FcValueBindingWeak, append); +} + +FcBool +FcPatternObjectDel (FcPattern *p, FcObject object) +{ + FcPatternElt *e; + + e = FcPatternObjectFindElt (p, object); + if (!e) + return FcFalse; + + /* destroy value */ + FcValueListDestroy (e->values); + + /* shuffle existing ones down */ + memmove (e, e+1, + (FcPatternElts(p) + p->num - (e + 1)) * + sizeof (FcPatternElt)); + p->num--; + e = FcPatternElts(p) + p->num; + e->object = 0; + e->values = NULL; + return FcTrue; +} + +FcBool +FcPatternDel (FcPattern *p, const char *object) +{ + return FcPatternObjectDel (p, FcObjectFromName (object)); +} + +FcBool +FcPatternRemove (FcPattern *p, const char *object, int id) +{ + FcPatternElt *e; + FcValueListPtr *prev, l; + + e = FcPatternObjectFindElt (p, FcObjectFromName (object)); + if (!e) + return FcFalse; + for (prev = &e->values; (l = *prev); prev = &l->next) + { + if (!id) + { + *prev = l->next; + l->next = NULL; + FcValueListDestroy (l); + if (!e->values) + FcPatternDel (p, object); + return FcTrue; + } + id--; + } + return FcFalse; +} + +FcBool +FcPatternObjectAddInteger (FcPattern *p, FcObject object, int i) +{ + FcValue v; + + v.type = FcTypeInteger; + v.u.i = i; + return FcPatternObjectAdd (p, object, v, FcTrue); +} + +FcBool +FcPatternAddInteger (FcPattern *p, const char *object, int i) +{ + return FcPatternObjectAddInteger (p, FcObjectFromName (object), i); +} + +FcBool +FcPatternObjectAddDouble (FcPattern *p, FcObject object, double d) +{ + FcValue v; + + v.type = FcTypeDouble; + v.u.d = d; + return FcPatternObjectAdd (p, object, v, FcTrue); +} + + +FcBool +FcPatternAddDouble (FcPattern *p, const char *object, double d) +{ + return FcPatternObjectAddDouble (p, FcObjectFromName (object), d); +} + +FcBool +FcPatternObjectAddString (FcPattern *p, FcObject object, const FcChar8 *s) +{ + FcValue v; + + if (!s) + { + v.type = FcTypeVoid; + v.u.s = 0; + return FcPatternObjectAdd (p, object, v, FcTrue); + } + + v.type = FcTypeString; + v.u.s = s; + return FcPatternObjectAdd (p, object, v, FcTrue); +} + +FcBool +FcPatternAddString (FcPattern *p, const char *object, const FcChar8 *s) +{ + return FcPatternObjectAddString (p, FcObjectFromName (object), s); +} + +FcBool +FcPatternAddMatrix (FcPattern *p, const char *object, const FcMatrix *s) +{ + FcValue v; + + v.type = FcTypeMatrix; + v.u.m = s; + return FcPatternAdd (p, object, v, FcTrue); +} + + +FcBool +FcPatternObjectAddBool (FcPattern *p, FcObject object, FcBool b) +{ + FcValue v; + + v.type = FcTypeBool; + v.u.b = b; + return FcPatternObjectAdd (p, object, v, FcTrue); +} + +FcBool +FcPatternAddBool (FcPattern *p, const char *object, FcBool b) +{ + return FcPatternObjectAddBool (p, FcObjectFromName (object), b); +} + +FcBool +FcPatternAddCharSet (FcPattern *p, const char *object, const FcCharSet *c) +{ + FcValue v; + + v.type = FcTypeCharSet; + v.u.c = (FcCharSet *)c; + return FcPatternAdd (p, object, v, FcTrue); +} + +FcBool +FcPatternAddFTFace (FcPattern *p, const char *object, const FT_Face f) +{ + FcValue v; + + v.type = FcTypeFTFace; + v.u.f = (void *) f; + return FcPatternAdd (p, object, v, FcTrue); +} + +FcBool +FcPatternAddLangSet (FcPattern *p, const char *object, const FcLangSet *ls) +{ + FcValue v; + + v.type = FcTypeLangSet; + v.u.l = (FcLangSet *)ls; + return FcPatternAdd (p, object, v, FcTrue); +} + +FcResult +FcPatternObjectGet (const FcPattern *p, FcObject object, int id, FcValue *v) +{ + FcPatternElt *e; + FcValueListPtr l; + + if (!p) + return FcResultNoMatch; + e = FcPatternObjectFindElt (p, object); + if (!e) + return FcResultNoMatch; + for (l = FcPatternEltValues(e); l; l = FcValueListNext(l)) + { + if (!id) + { + *v = FcValueCanonicalize(&l->value); + return FcResultMatch; + } + id--; + } + return FcResultNoId; +} + +FcResult +FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v) +{ + return FcPatternObjectGet (p, FcObjectFromName (object), id, v); +} + +FcResult +FcPatternObjectGetInteger (const FcPattern *p, FcObject object, int id, int *i) +{ + FcValue v; + FcResult r; + + r = FcPatternObjectGet (p, object, id, &v); + if (r != FcResultMatch) + return r; + switch ((int) v.type) { + case FcTypeDouble: + *i = (int) v.u.d; + break; + case FcTypeInteger: + *i = v.u.i; + break; + default: + return FcResultTypeMismatch; + } + return FcResultMatch; +} + +FcResult +FcPatternGetInteger (const FcPattern *p, const char *object, int id, int *i) +{ + return FcPatternObjectGetInteger (p, FcObjectFromName (object), id, i); +} + + +FcResult +FcPatternObjectGetDouble (const FcPattern *p, FcObject object, int id, double *d) +{ + FcValue v; + FcResult r; + + r = FcPatternObjectGet (p, object, id, &v); + if (r != FcResultMatch) + return r; + switch ((int) v.type) { + case FcTypeDouble: + *d = v.u.d; + break; + case FcTypeInteger: + *d = (double) v.u.i; + break; + default: + return FcResultTypeMismatch; + } + return FcResultMatch; +} + +FcResult +FcPatternGetDouble (const FcPattern *p, const char *object, int id, double *d) +{ + return FcPatternObjectGetDouble (p, FcObjectFromName (object), id, d); +} + +FcResult +FcPatternObjectGetString (const FcPattern *p, FcObject object, int id, FcChar8 ** s) +{ + FcValue v; + FcResult r; + + r = FcPatternObjectGet (p, object, id, &v); + if (r != FcResultMatch) + return r; + if (v.type != FcTypeString) + return FcResultTypeMismatch; + + *s = (FcChar8 *) v.u.s; + return FcResultMatch; +} + +FcResult +FcPatternGetString (const FcPattern *p, const char *object, int id, FcChar8 ** s) +{ + return FcPatternObjectGetString (p, FcObjectFromName (object), id, s); +} + +FcResult +FcPatternGetMatrix(const FcPattern *p, const char *object, int id, FcMatrix **m) +{ + FcValue v; + FcResult r; + + r = FcPatternGet (p, object, id, &v); + if (r != FcResultMatch) + return r; + if (v.type != FcTypeMatrix) + return FcResultTypeMismatch; + *m = (FcMatrix *)v.u.m; + return FcResultMatch; +} + + +FcResult +FcPatternGetBool(const FcPattern *p, const char *object, int id, FcBool *b) +{ + FcValue v; + FcResult r; + + r = FcPatternGet (p, object, id, &v); + if (r != FcResultMatch) + return r; + if (v.type != FcTypeBool) + return FcResultTypeMismatch; + *b = v.u.b; + return FcResultMatch; +} + +FcResult +FcPatternGetCharSet(const FcPattern *p, const char *object, int id, FcCharSet **c) +{ + FcValue v; + FcResult r; + + r = FcPatternGet (p, object, id, &v); + if (r != FcResultMatch) + return r; + if (v.type != FcTypeCharSet) + return FcResultTypeMismatch; + *c = (FcCharSet *)v.u.c; + return FcResultMatch; +} + +FcResult +FcPatternGetFTFace(const FcPattern *p, const char *object, int id, FT_Face *f) +{ + FcValue v; + FcResult r; + + r = FcPatternGet (p, object, id, &v); + if (r != FcResultMatch) + return r; + if (v.type != FcTypeFTFace) + return FcResultTypeMismatch; + *f = (FT_Face) v.u.f; + return FcResultMatch; +} + +FcResult +FcPatternGetLangSet(const FcPattern *p, const char *object, int id, FcLangSet **ls) +{ + FcValue v; + FcResult r; + + r = FcPatternGet (p, object, id, &v); + if (r != FcResultMatch) + return r; + if (v.type != FcTypeLangSet) + return FcResultTypeMismatch; + *ls = (FcLangSet *)v.u.l; + return FcResultMatch; +} + +FcPattern * +FcPatternDuplicate (const FcPattern *orig) +{ + FcPattern *new; + FcPatternElt *e; + int i; + FcValueListPtr l; + + new = FcPatternCreate (); + if (!new) + goto bail0; + + e = FcPatternElts(orig); + + for (i = 0; i < orig->num; i++) + { + for (l = FcPatternEltValues(e + i); l; l = FcValueListNext(l)) + { + if (!FcPatternObjectAddWithBinding (new, e[i].object, + FcValueCanonicalize(&l->value), + l->binding, + FcTrue)) + goto bail1; + + } + } + + return new; + +bail1: + FcPatternDestroy (new); +bail0: + return 0; +} + +void +FcPatternReference (FcPattern *p) +{ + if (!FcRefIsConst (&p->ref)) + FcRefInc (&p->ref); + else + FcCacheObjectReference (p); +} + +FcPattern * +FcPatternVaBuild (FcPattern *p, va_list va) +{ + FcPattern *ret; + + FcPatternVapBuild (ret, p, va); + return ret; +} + +FcPattern * +FcPatternBuild (FcPattern *p, ...) +{ + va_list va; + + va_start (va, p); + FcPatternVapBuild (p, p, va); + va_end (va); + return p; +} + +/* + * Add all of the elements in 's' to 'p' + */ +FcBool +FcPatternAppend (FcPattern *p, FcPattern *s) +{ + int i; + FcPatternElt *e; + FcValueListPtr v; + + for (i = 0; i < s->num; i++) + { + e = FcPatternElts(s)+i; + for (v = FcPatternEltValues(e); v; v = FcValueListNext(v)) + { + if (!FcPatternObjectAddWithBinding (p, e->object, + FcValueCanonicalize(&v->value), + v->binding, FcTrue)) + return FcFalse; + } + } + return FcTrue; +} + +FcPattern * +FcPatternFilter (FcPattern *p, const FcObjectSet *os) +{ + int i; + FcPattern *ret; + FcPatternElt *e; + FcValueListPtr v; + + if (!os) + return FcPatternDuplicate (p); + + ret = FcPatternCreate (); + if (!ret) + return NULL; + + for (i = 0; i < os->nobject; i++) + { + FcObject object = FcObjectFromName (os->objects[i]); + e = FcPatternObjectFindElt (p, object); + if (e) + { + for (v = FcPatternEltValues(e); v; v = FcValueListNext(v)) + { + if (!FcPatternObjectAddWithBinding (ret, e->object, + FcValueCanonicalize(&v->value), + v->binding, FcTrue)) + goto bail0; + } + } + } + return ret; + +bail0: + FcPatternDestroy (ret); + return NULL; +} + + +FcBool +FcPatternSerializeAlloc (FcSerialize *serialize, const FcPattern *pat) +{ + int i; + FcPatternElt *elts = FcPatternElts(pat); + + if (!FcSerializeAlloc (serialize, pat, sizeof (FcPattern))) + return FcFalse; + if (!FcSerializeAlloc (serialize, elts, pat->num * sizeof (FcPatternElt))) + return FcFalse; + for (i = 0; i < pat->num; i++) + if (!FcValueListSerializeAlloc (serialize, FcPatternEltValues(elts+i))) + return FcFalse; + return FcTrue; +} + +FcPattern * +FcPatternSerialize (FcSerialize *serialize, const FcPattern *pat) +{ + FcPattern *pat_serialized; + FcPatternElt *elts = FcPatternElts (pat); + FcPatternElt *elts_serialized; + FcValueList *values_serialized; + int i; + + pat_serialized = FcSerializePtr (serialize, pat); + if (!pat_serialized) + return NULL; + *pat_serialized = *pat; + pat_serialized->size = pat->num; + FcRefSetConst (&pat_serialized->ref); + + elts_serialized = FcSerializePtr (serialize, elts); + if (!elts_serialized) + return NULL; + + pat_serialized->elts_offset = FcPtrToOffset (pat_serialized, + elts_serialized); + + for (i = 0; i < pat->num; i++) + { + values_serialized = FcValueListSerialize (serialize, FcPatternEltValues (elts+i)); + if (!values_serialized) + return NULL; + elts_serialized[i].object = elts[i].object; + elts_serialized[i].values = FcPtrToEncodedOffset (&elts_serialized[i], + values_serialized, + FcValueList); + } + if (FcDebug() & FC_DBG_CACHEV) { + printf ("Raw pattern:\n"); + FcPatternPrint (pat); + printf ("Serialized pattern:\n"); + FcPatternPrint (pat_serialized); + printf ("\n"); + } + return pat_serialized; +} + +FcBool +FcValueListSerializeAlloc (FcSerialize *serialize, const FcValueList *vl) +{ + while (vl) + { + if (!FcSerializeAlloc (serialize, vl, sizeof (FcValueList))) + return FcFalse; + switch ((int) vl->value.type) { + case FcTypeString: + if (!FcStrSerializeAlloc (serialize, vl->value.u.s)) + return FcFalse; + break; + case FcTypeCharSet: + if (!FcCharSetSerializeAlloc (serialize, vl->value.u.c)) + return FcFalse; + break; + case FcTypeLangSet: + if (!FcLangSetSerializeAlloc (serialize, vl->value.u.l)) + return FcFalse; + break; + default: + break; + } + vl = vl->next; + } + return FcTrue; +} + +FcValueList * +FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl) +{ + FcValueList *vl_serialized; + FcChar8 *s_serialized; + FcCharSet *c_serialized; + FcLangSet *l_serialized; + FcValueList *head_serialized = NULL; + FcValueList *prev_serialized = NULL; + + while (vl) + { + vl_serialized = FcSerializePtr (serialize, vl); + if (!vl_serialized) + return NULL; + + if (prev_serialized) + prev_serialized->next = FcPtrToEncodedOffset (prev_serialized, + vl_serialized, + FcValueList); + else + head_serialized = vl_serialized; + + vl_serialized->next = NULL; + vl_serialized->value.type = vl->value.type; + switch ((int) vl->value.type) { + case FcTypeInteger: + vl_serialized->value.u.i = vl->value.u.i; + break; + case FcTypeDouble: + vl_serialized->value.u.d = vl->value.u.d; + break; + case FcTypeString: + s_serialized = FcStrSerialize (serialize, vl->value.u.s); + if (!s_serialized) + return NULL; + vl_serialized->value.u.s = FcPtrToEncodedOffset (&vl_serialized->value, + s_serialized, + FcChar8); + break; + case FcTypeBool: + vl_serialized->value.u.b = vl->value.u.b; + break; + case FcTypeMatrix: + /* can't happen */ + break; + case FcTypeCharSet: + c_serialized = FcCharSetSerialize (serialize, vl->value.u.c); + if (!c_serialized) + return NULL; + vl_serialized->value.u.c = FcPtrToEncodedOffset (&vl_serialized->value, + c_serialized, + FcCharSet); + break; + case FcTypeFTFace: + /* can't happen */ + break; + case FcTypeLangSet: + l_serialized = FcLangSetSerialize (serialize, vl->value.u.l); + if (!l_serialized) + return NULL; + vl_serialized->value.u.l = FcPtrToEncodedOffset (&vl_serialized->value, + l_serialized, + FcLangSet); + break; + default: + break; + } + prev_serialized = vl_serialized; + vl = vl->next; + } + return head_serialized; +} + +#define __fcpat__ +#include "fcaliastail.h" +#include "fcftaliastail.h" +#undef __fcpat__ diff --git a/project/jni/fontconfig/src/fcserialize.c b/project/jni/fontconfig/src/fcserialize.c new file mode 100644 index 000000000..d2f221df8 --- /dev/null +++ b/project/jni/fontconfig/src/fcserialize.c @@ -0,0 +1,155 @@ +/* + * Copyright © 2006 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "fcint.h" + +intptr_t +FcAlignSize (intptr_t size) +{ + intptr_t rem = size % sizeof (FcAlign); + if (rem) + size += sizeof (FcAlign) - rem; + return size; +} + +/* + * Serialization helper object -- allocate space in the + * yet-to-be-created linear array for a serialized font set + */ + +FcSerialize * +FcSerializeCreate (void) +{ + FcSerialize *serialize; + + serialize = malloc (sizeof (FcSerialize)); + if (!serialize) + return NULL; + serialize->size = 0; + serialize->linear = NULL; + serialize->cs_freezer = NULL; + memset (serialize->buckets, '\0', sizeof (serialize->buckets)); + return serialize; +} + +void +FcSerializeDestroy (FcSerialize *serialize) +{ + uintptr_t bucket; + + for (bucket = 0; bucket < FC_SERIALIZE_HASH_SIZE; bucket++) + { + FcSerializeBucket *buck, *next; + + for (buck = serialize->buckets[bucket]; buck; buck = next) { + next = buck->next; + free (buck); + } + } + if (serialize->cs_freezer) + FcCharSetFreezerDestroy (serialize->cs_freezer); + free (serialize); +} + +/* + * Allocate space for an object in the serialized array. Keep track + * of where the object is placed and only allocate one copy of each object + */ + +FcBool +FcSerializeAlloc (FcSerialize *serialize, const void *object, int size) +{ + uintptr_t bucket = ((uintptr_t) object) % FC_SERIALIZE_HASH_SIZE; + FcSerializeBucket *buck; + + for (buck = serialize->buckets[bucket]; buck; buck = buck->next) + if (buck->object == object) + return FcTrue; + buck = malloc (sizeof (FcSerializeBucket)); + if (!buck) + return FcFalse; + buck->object = object; + buck->offset = serialize->size; + buck->next = serialize->buckets[bucket]; + serialize->buckets[bucket] = buck; + serialize->size += FcAlignSize (size); + return FcTrue; +} + +/* + * Reserve space in the serialization array + */ +intptr_t +FcSerializeReserve (FcSerialize *serialize, int size) +{ + intptr_t offset = serialize->size; + serialize->size += FcAlignSize (size); + return offset; +} + +/* + * Given an object, return the offset in the serialized array where + * the serialized copy of the object is stored + */ +intptr_t +FcSerializeOffset (FcSerialize *serialize, const void *object) +{ + uintptr_t bucket = ((uintptr_t) object) % FC_SERIALIZE_HASH_SIZE; + FcSerializeBucket *buck; + + for (buck = serialize->buckets[bucket]; buck; buck = buck->next) + if (buck->object == object) + return buck->offset; + return 0; +} + +/* + * Given a cache and an object, return a pointer to where + * the serialized copy of the object is stored + */ +void * +FcSerializePtr (FcSerialize *serialize, const void *object) +{ + intptr_t offset = FcSerializeOffset (serialize, object); + + if (!offset) + return NULL; + return (void *) ((char *) serialize->linear + offset); +} + +FcBool +FcStrSerializeAlloc (FcSerialize *serialize, const FcChar8 *str) +{ + return FcSerializeAlloc (serialize, str, strlen ((const char *) str) + 1); +} + +FcChar8 * +FcStrSerialize (FcSerialize *serialize, const FcChar8 *str) +{ + FcChar8 *str_serialize = FcSerializePtr (serialize, str); + if (!str_serialize) + return NULL; + strcpy ((char *) str_serialize, (const char *) str); + return str_serialize; +} +#include "fcaliastail.h" +#undef __fcserialize__ diff --git a/project/jni/fontconfig/src/fcstat.c b/project/jni/fontconfig/src/fcstat.c new file mode 100644 index 000000000..0a880975a --- /dev/null +++ b/project/jni/fontconfig/src/fcstat.c @@ -0,0 +1,362 @@ +/* + * Copyright © 2000 Keith Packard + * Copyright © 2005 Patrick Lam + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ +#include "fcint.h" +#include "fcarch.h" +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_VFS_H +#include +#endif +#ifdef HAVE_SYS_STATVFS_H +#include +#endif +#ifdef HAVE_SYS_STATFS_H +#include +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif + +#ifdef _WIN32 +#ifdef __GNUC__ +typedef long long INT64; +#define EPOCH_OFFSET 11644473600ll +#else +#define EPOCH_OFFSET 11644473600i64 +typedef __int64 INT64; +#endif + +/* Workaround for problems in the stat() in the Microsoft C library: + * + * 1) stat() uses FindFirstFile() to get the file + * attributes. Unfortunately this API doesn't return correct values + * for modification time of a directory until some time after a file + * or subdirectory has been added to the directory. (This causes + * run-test.sh to fail, for instance.) GetFileAttributesEx() is + * better, it returns the updated timestamp right away. + * + * 2) stat() does some strange things related to backward + * compatibility with the local time timestamps on FAT volumes and + * daylight saving time. This causes problems after the switches + * to/from daylight saving time. See + * http://bugzilla.gnome.org/show_bug.cgi?id=154968 , especially + * comment #30, and http://www.codeproject.com/datetime/dstbugs.asp . + * We don't need any of that, FAT and Win9x are as good as dead. So + * just use the UTC timestamps from NTFS, converted to the Unix epoch. + */ + +int +FcStat (const FcChar8 *file, struct stat *statb) +{ + WIN32_FILE_ATTRIBUTE_DATA wfad; + char full_path_name[MAX_PATH]; + char *basename; + DWORD rc; + + if (!GetFileAttributesEx ((LPCSTR) file, GetFileExInfoStandard, &wfad)) + return -1; + + statb->st_dev = 0; + + /* Calculate a pseudo inode number as a hash of the full path name. + * Call GetLongPathName() to get the spelling of the path name as it + * is on disk. + */ + rc = GetFullPathName ((LPCSTR) file, sizeof (full_path_name), full_path_name, &basename); + if (rc == 0 || rc > sizeof (full_path_name)) + return -1; + + rc = GetLongPathName (full_path_name, full_path_name, sizeof (full_path_name)); + statb->st_ino = FcStringHash ((const FcChar8 *) full_path_name); + + statb->st_mode = _S_IREAD | _S_IWRITE; + statb->st_mode |= (statb->st_mode >> 3) | (statb->st_mode >> 6); + + if (wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + statb->st_mode |= _S_IFDIR; + else + statb->st_mode |= _S_IFREG; + + statb->st_nlink = 1; + statb->st_uid = statb->st_gid = 0; + statb->st_rdev = 0; + + if (wfad.nFileSizeHigh > 0) + return -1; + statb->st_size = wfad.nFileSizeLow; + + statb->st_atime = (*(INT64 *)&wfad.ftLastAccessTime)/10000000 - EPOCH_OFFSET; + statb->st_mtime = (*(INT64 *)&wfad.ftLastWriteTime)/10000000 - EPOCH_OFFSET; + statb->st_ctime = statb->st_mtime; + + return 0; +} + +#else + +int +FcStat (const FcChar8 *file, struct stat *statb) +{ + return stat ((char *) file, statb); +} + +/* Adler-32 checksum implementation */ +struct Adler32 { + int a; + int b; +}; + +static void +Adler32Init (struct Adler32 *ctx) +{ + ctx->a = 1; + ctx->b = 0; +} + +static void +Adler32Update (struct Adler32 *ctx, const char *data, int data_len) +{ + while (data_len--) + { + ctx->a = (ctx->a + *data++) % 65521; + ctx->b = (ctx->b + ctx->a) % 65521; + } +} + +static int +Adler32Finish (struct Adler32 *ctx) +{ + return ctx->a + (ctx->b << 16); +} + +#ifdef HAVE_STRUCT_DIRENT_D_TYPE +/* dirent.d_type can be relied upon on FAT filesystem */ +static FcBool +FcDirChecksumScandirFilter(const struct dirent *entry) +{ + return entry->d_type != DT_DIR; +} +#endif + +#ifdef HAVE_SCANDIR +static int +FcDirChecksumScandirSorter(const struct dirent **lhs, const struct dirent **rhs) +{ + return strcmp((*lhs)->d_name, (*rhs)->d_name); +} +#elif HAVE_SCANDIR_VOID_P +static int +FcDirChecksumScandirSorter(const void *a, const void *b) +{ + const struct dirent *lhs = a, *rhs = b; + + return strcmp(lhs->d_name, rhs->d_name); +} +#endif + +static int +FcDirChecksum (const FcChar8 *dir, time_t *checksum) +{ + struct Adler32 ctx; + struct dirent **files; + int n; + int ret = 0; + size_t len = strlen ((const char *)dir); + + Adler32Init (&ctx); + + n = scandir ((const char *)dir, &files, +#ifdef HAVE_STRUCT_DIRENT_D_TYPE + &FcDirChecksumScandirFilter, +#else + NULL, +#endif + &FcDirChecksumScandirSorter); + if (n == -1) + return -1; + + while (n--) + { + size_t dlen = strlen (files[n]->d_name); + int dtype; + +#ifdef HAVE_STRUCT_DIRENT_D_TYPE + dtype = files[n]->d_type; + if (dtype == DT_UNKNOWN) + { +#endif + struct stat statb; + char f[PATH_MAX + 1]; + + memcpy (f, dir, len); + f[len] = FC_DIR_SEPARATOR; + memcpy (&f[len + 1], files[n]->d_name, dlen); + f[len + 1 + dlen] = 0; + if (lstat (f, &statb) < 0) + { + ret = -1; + goto bail; + } + if (S_ISDIR (statb.st_mode)) + goto bail; + + dtype = statb.st_mode; +#ifdef HAVE_STRUCT_DIRENT_D_TYPE + } +#endif + Adler32Update (&ctx, files[n]->d_name, dlen + 1); + Adler32Update (&ctx, (char *)&dtype, sizeof (int)); + + bail: + free (files[n]); + } + free (files); + if (ret == -1) + return -1; + + *checksum = Adler32Finish (&ctx); + + return 0; +} +#endif /* _WIN32 */ + +int +FcStatChecksum (const FcChar8 *file, struct stat *statb) +{ + if (FcStat (file, statb) == -1) + return -1; + +#ifndef _WIN32 + /* We have a workaround of the broken stat() in FcStat() for Win32. + * No need to do something further more. + */ + if (FcIsFsMtimeBroken (file)) + { + if (FcDirChecksum (file, &statb->st_mtime) == -1) + return -1; + } +#endif + + return 0; +} + +static int +FcFStatFs (int fd, FcStatFS *statb) +{ + const char *p = NULL; + int ret = -1; + FcBool flag = FcFalse; + +#if defined(HAVE_FSTATVFS) && (defined(HAVE_STRUCT_STATVFS_F_BASETYPE) || defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)) + struct statvfs buf; + + memset (statb, 0, sizeof (FcStatFS)); + + if ((ret = fstatvfs (fd, &buf)) == 0) + { +# if defined(HAVE_STRUCT_STATVFS_F_BASETYPE) + p = buf.f_basetype; +# elif defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME) + p = buf.f_fstypename; +# endif + } +#elif defined(HAVE_FSTATFS) && (defined(HAVE_STRUCT_STATFS_F_FLAGS) || defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || defined(__linux__)) + struct statfs buf; + + memset (statb, 0, sizeof (FcStatFS)); + + if ((ret = fstatfs (fd, &buf)) == 0) + { +# if defined(HAVE_STRUCT_STATFS_F_FLAGS) && defined(MNT_LOCAL) + statb->is_remote_fs = !(buf.f_flags & MNT_LOCAL); + flag = FcTrue; +# endif +# if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) + p = buf.f_fstypename; +# elif defined(__linux__) + switch (buf.f_type) + { + case 0x6969: /* nfs */ + statb->is_remote_fs = FcTrue; + break; + case 0x4d44: /* fat */ + statb->is_mtime_broken = FcTrue; + break; + default: + break; + } + + return ret; +# else +# error "BUG: No way to figure out with fstatfs()" +# endif + } +#endif + if (p) + { + if (!flag && strcmp (p, "nfs") == 0) + statb->is_remote_fs = FcTrue; + if (strcmp (p, "msdosfs") == 0 || + strcmp (p, "pcfs") == 0) + statb->is_mtime_broken = FcTrue; + } + + return ret; +} + +FcBool +FcIsFsMmapSafe (int fd) +{ + FcStatFS statb; + + if (FcFStatFs (fd, &statb) < 0) + return FcTrue; + + return !statb.is_remote_fs; +} + +FcBool +FcIsFsMtimeBroken (const FcChar8 *dir) +{ + int fd = FcOpen ((const char *) dir, O_RDONLY); + + if (fd != -1) + { + FcStatFS statb; + int ret = FcFStatFs (fd, &statb); + + close (fd); + if (ret < 0) + return FcFalse; + + return statb.is_mtime_broken; + } + + return FcFalse; +} diff --git a/project/jni/fontconfig/src/fcstdint.h b/project/jni/fontconfig/src/fcstdint.h new file mode 100644 index 000000000..6a3d265d0 --- /dev/null +++ b/project/jni/fontconfig/src/fcstdint.h @@ -0,0 +1,9 @@ +#ifndef _FONTCONFIG_SRC_FCSTDINT_H +#define _FONTCONFIG_SRC_FCSTDINT_H 1 +#ifndef _GENERATED_STDINT_H +#define _GENERATED_STDINT_H "fontconfig 2.11.0" +/* generated using gnu compiler gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3 */ +#define _STDINT_HAVE_STDINT_H 1 +#include +#endif +#endif diff --git a/project/jni/fontconfig/src/fcstr.c b/project/jni/fontconfig/src/fcstr.c new file mode 100644 index 000000000..024dae325 --- /dev/null +++ b/project/jni/fontconfig/src/fcstr.c @@ -0,0 +1,1404 @@ +/* + * fontconfig/src/fcstr.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include +#include +#include +#ifdef HAVE_REGEX_H +#include +#endif + + +/* Objects MT-safe for readonly access. */ + +FcChar8 * +FcStrCopy (const FcChar8 *s) +{ + return FcStrdup (s); +} + +FcChar8 * +FcStrPlus (const FcChar8 *s1, const FcChar8 *s2) +{ + int s1l = strlen ((char *) s1); + int s2l = strlen ((char *) s2); + int l = s1l + s2l + 1; + FcChar8 *s = malloc (l); + + if (!s) + return 0; + memcpy (s, s1, s1l); + memcpy (s + s1l, s2, s2l + 1); + return s; +} + +void +FcStrFree (FcChar8 *s) +{ + free (s); +} + + +#include "../fc-case/fccase.h" + +#define FcCaseFoldUpperCount(cf) \ + ((cf)->method == FC_CASE_FOLD_FULL ? 1 : (cf)->count) + +typedef struct _FcCaseWalker { + const FcChar8 *read; + const FcChar8 *src; + FcChar8 utf8[FC_MAX_CASE_FOLD_CHARS + 1]; +} FcCaseWalker; + +static void +FcStrCaseWalkerInit (const FcChar8 *src, FcCaseWalker *w) +{ + w->src = src; + w->read = 0; +} + +static FcChar8 +FcStrCaseWalkerLong (FcCaseWalker *w, FcChar8 r) +{ + FcChar32 ucs4; + int slen; + int len = strlen((char*)w->src); + + slen = FcUtf8ToUcs4 (w->src - 1, &ucs4, len + 1); + if (slen <= 0) + return r; + if (FC_MIN_FOLD_CHAR <= ucs4 && ucs4 <= FC_MAX_FOLD_CHAR) + { + int min = 0; + int max = FC_NUM_CASE_FOLD; + + while (min <= max) + { + int mid = (min + max) >> 1; + FcChar32 low = fcCaseFold[mid].upper; + FcChar32 high = low + FcCaseFoldUpperCount (&fcCaseFold[mid]); + + if (high <= ucs4) + min = mid + 1; + else if (ucs4 < low) + max = mid - 1; + else + { + const FcCaseFold *fold = &fcCaseFold[mid]; + int dlen; + + switch (fold->method) { + case FC_CASE_FOLD_EVEN_ODD: + if ((ucs4 & 1) != (fold->upper & 1)) + return r; + /* fall through ... */ + default: + dlen = FcUcs4ToUtf8 (ucs4 + fold->offset, w->utf8); + break; + case FC_CASE_FOLD_FULL: + dlen = fold->count; + memcpy (w->utf8, fcCaseFoldChars + fold->offset, dlen); + break; + } + + /* consume rest of src utf-8 bytes */ + w->src += slen - 1; + + /* read from temp buffer */ + w->utf8[dlen] = '\0'; + w->read = w->utf8; + return *w->read++; + } + } + } + return r; +} + +static FcChar8 +FcStrCaseWalkerNext (FcCaseWalker *w, const char *delims) +{ + FcChar8 r; + + if (w->read) + { + if ((r = *w->read++)) + return r; + w->read = 0; + } + do + { + r = *w->src++; + } while (r != 0 && delims && strchr (delims, r)); + + if ((r & 0xc0) == 0xc0) + return FcStrCaseWalkerLong (w, r); + if ('A' <= r && r <= 'Z') + r = r - 'A' + 'a'; + return r; +} + +FcChar8 * +FcStrDowncase (const FcChar8 *s) +{ + FcCaseWalker w; + int len = 0; + FcChar8 *dst, *d; + + FcStrCaseWalkerInit (s, &w); + while (FcStrCaseWalkerNext (&w, NULL)) + len++; + d = dst = malloc (len + 1); + if (!d) + return 0; + FcStrCaseWalkerInit (s, &w); + while ((*d++ = FcStrCaseWalkerNext (&w, NULL))); + return dst; +} + +int +FcStrCmpIgnoreCase (const FcChar8 *s1, const FcChar8 *s2) +{ + FcCaseWalker w1, w2; + FcChar8 c1, c2; + + if (s1 == s2) return 0; + + FcStrCaseWalkerInit (s1, &w1); + FcStrCaseWalkerInit (s2, &w2); + + for (;;) + { + c1 = FcStrCaseWalkerNext (&w1, NULL); + c2 = FcStrCaseWalkerNext (&w2, NULL); + if (!c1 || (c1 != c2)) + break; + } + return (int) c1 - (int) c2; +} + +int +FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2) +{ + return FcStrCmpIgnoreCaseAndDelims (s1, s2, (const FcChar8 *)" "); +} + +int +FcStrCmpIgnoreCaseAndDelims (const FcChar8 *s1, const FcChar8 *s2, const FcChar8 *delims) +{ + FcCaseWalker w1, w2; + FcChar8 c1, c2; + + if (s1 == s2) return 0; + + FcStrCaseWalkerInit (s1, &w1); + FcStrCaseWalkerInit (s2, &w2); + + for (;;) + { + c1 = FcStrCaseWalkerNext (&w1, (const char *)delims); + c2 = FcStrCaseWalkerNext (&w2, (const char *)delims); + if (!c1 || (c1 != c2)) + break; + } + return (int) c1 - (int) c2; +} + +int +FcStrCmp (const FcChar8 *s1, const FcChar8 *s2) +{ + FcChar8 c1, c2; + + if (s1 == s2) + return 0; + for (;;) + { + c1 = *s1++; + c2 = *s2++; + if (!c1 || c1 != c2) + break; + } + return (int) c1 - (int) c2; +} + +#ifdef USE_REGEX +static FcBool +_FcStrRegexCmp (const FcChar8 *s, const FcChar8 *regex, int cflags, int eflags) +{ + int ret = -1; + regex_t reg; + + if ((ret = regcomp (®, (const char *)regex, cflags)) != 0) + { + if (FcDebug () & FC_DBG_MATCHV) + { + char buf[512]; + + regerror (ret, ®, buf, 512); + printf("Regexp compile error: %s\n", buf); + } + return FcFalse; + } + ret = regexec (®, (const char *)s, 0, NULL, eflags); + if (ret != 0) + { + if (FcDebug () & FC_DBG_MATCHV) + { + char buf[512]; + + regerror (ret, ®, buf, 512); + printf("Regexp exec error: %s\n", buf); + } + } + regfree (®); + + return ret == 0 ? FcTrue : FcFalse; +} +#else +# define _FcStrRegexCmp(_s_, _regex_, _cflags_, _eflags_) (FcFalse) +#endif + +FcBool +FcStrRegexCmp (const FcChar8 *s, const FcChar8 *regex) +{ + return _FcStrRegexCmp (s, regex, REG_EXTENDED | REG_NOSUB, 0); +} + +FcBool +FcStrRegexCmpIgnoreCase (const FcChar8 *s, const FcChar8 *regex) +{ + return _FcStrRegexCmp (s, regex, REG_EXTENDED | REG_NOSUB | REG_ICASE, 0); +} + +/* + * Return a hash value for a string + */ + +FcChar32 +FcStrHashIgnoreCase (const FcChar8 *s) +{ + FcChar32 h = 0; + FcCaseWalker w; + FcChar8 c; + + FcStrCaseWalkerInit (s, &w); + while ((c = FcStrCaseWalkerNext (&w, NULL))) + h = ((h << 3) ^ (h >> 3)) ^ c; + return h; +} + +/* + * Is the head of s1 equal to s2? + */ + +static FcBool +FcStrIsAtIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2) +{ + FcCaseWalker w1, w2; + FcChar8 c1, c2; + + FcStrCaseWalkerInit (s1, &w1); + FcStrCaseWalkerInit (s2, &w2); + + for (;;) + { + c1 = FcStrCaseWalkerNext (&w1, " "); + c2 = FcStrCaseWalkerNext (&w2, " "); + if (!c1 || (c1 != c2)) + break; + } + return c1 == c2 || !c2; +} + +/* + * Does s1 contain an instance of s2 (ignoring blanks and case)? + */ + +const FcChar8 * +FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2) +{ + while (*s1) + { + if (FcStrIsAtIgnoreBlanksAndCase (s1, s2)) + return s1; + s1++; + } + return 0; +} + +static FcBool +FcCharIsPunct (const FcChar8 c) +{ + if (c < '0') + return FcTrue; + if (c <= '9') + return FcFalse; + if (c < 'A') + return FcTrue; + if (c <= 'Z') + return FcFalse; + if (c < 'a') + return FcTrue; + if (c <= 'z') + return FcFalse; + if (c <= '~') + return FcTrue; + return FcFalse; +} + +/* + * Is the head of s1 equal to s2? + */ + +static FcBool +FcStrIsAtIgnoreCase (const FcChar8 *s1, const FcChar8 *s2) +{ + FcCaseWalker w1, w2; + FcChar8 c1, c2; + + FcStrCaseWalkerInit (s1, &w1); + FcStrCaseWalkerInit (s2, &w2); + + for (;;) + { + c1 = FcStrCaseWalkerNext (&w1, NULL); + c2 = FcStrCaseWalkerNext (&w2, NULL); + if (!c1 || (c1 != c2)) + break; + } + return c1 == c2 || !c2; +} + +/* + * Does s1 contain an instance of s2 (ignoring blanks and case)? + */ + +const FcChar8 * +FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2) +{ + while (*s1) + { + if (FcStrIsAtIgnoreCase (s1, s2)) + return s1; + s1++; + } + return 0; +} + +/* + * Does s1 contain an instance of s2 on a word boundary (ignoring case)? + */ + +const FcChar8 * +FcStrContainsWord (const FcChar8 *s1, const FcChar8 *s2) +{ + FcBool wordStart = FcTrue; + int s1len = strlen ((char *) s1); + int s2len = strlen ((char *) s2); + + while (s1len >= s2len) + { + if (wordStart && + FcStrIsAtIgnoreCase (s1, s2) && + (s1len == s2len || FcCharIsPunct (s1[s2len]))) + { + return s1; + } + wordStart = FcFalse; + if (FcCharIsPunct (*s1)) + wordStart = FcTrue; + s1++; + s1len--; + } + return 0; +} + +/* + * returns the number of strings (ignoring delimitors and case) being matched + */ + +int +FcStrMatchIgnoreCaseAndDelims (const FcChar8 *s1, const FcChar8 *s2, const FcChar8 *delims) +{ + FcCaseWalker w1, w2; + FcChar8 c1, c2; + + if (s1 == s2) return 0; + + FcStrCaseWalkerInit (s1, &w1); + FcStrCaseWalkerInit (s2, &w2); + + for (;;) + { + c1 = FcStrCaseWalkerNext (&w1, (const char *)delims); + c2 = FcStrCaseWalkerNext (&w2, (const char *)delims); + if (!c1 || (c1 != c2)) + break; + } + return w1.src - s1 - 1; +} + +FcBool +FcStrGlobMatch (const FcChar8 *glob, + const FcChar8 *string) +{ + FcChar8 c; + + while ((c = *glob++)) + { + switch (c) { + case '*': + /* short circuit common case */ + if (!*glob) + return FcTrue; + /* short circuit another common case */ + if (strchr ((char *) glob, '*') == 0) + { + size_t l1, l2; + + l1 = strlen ((char *) string); + l2 = strlen ((char *) glob); + if (l1 < l2) + return FcFalse; + string += (l1 - l2); + } + while (*string) + { + if (FcStrGlobMatch (glob, string)) + return FcTrue; + string++; + } + return FcFalse; + case '?': + if (*string++ == '\0') + return FcFalse; + break; + default: + if (*string++ != c) + return FcFalse; + break; + } + } + return *string == '\0'; +} + +const FcChar8 * +FcStrStrIgnoreCase (const FcChar8 *s1, const FcChar8 *s2) +{ + FcCaseWalker w1, w2; + FcChar8 c1, c2; + const FcChar8 *cur; + + if (!s1 || !s2) + return 0; + + if (s1 == s2) + return s1; + + FcStrCaseWalkerInit (s1, &w1); + FcStrCaseWalkerInit (s2, &w2); + + c2 = FcStrCaseWalkerNext (&w2, NULL); + + for (;;) + { + cur = w1.src; + c1 = FcStrCaseWalkerNext (&w1, NULL); + if (!c1) + break; + if (c1 == c2) + { + FcCaseWalker w1t = w1; + FcCaseWalker w2t = w2; + FcChar8 c1t, c2t; + + for (;;) + { + c1t = FcStrCaseWalkerNext (&w1t, NULL); + c2t = FcStrCaseWalkerNext (&w2t, NULL); + + if (!c2t) + return cur; + if (c2t != c1t) + break; + } + } + } + return 0; +} + +const FcChar8 * +FcStrStr (const FcChar8 *s1, const FcChar8 *s2) +{ + FcChar8 c1, c2; + const FcChar8 * p = s1; + const FcChar8 * b = s2; + + if (!s1 || !s2) + return 0; + + if (s1 == s2) + return s1; + +again: + c2 = *s2++; + + if (!c2) + return 0; + + for (;;) + { + p = s1; + c1 = *s1++; + if (!c1 || c1 == c2) + break; + } + + if (c1 != c2) + return 0; + + for (;;) + { + c1 = *s1; + c2 = *s2; + if (c1 && c2 && c1 != c2) + { + s1 = p + 1; + s2 = b; + goto again; + } + if (!c2) + return p; + if (!c1) + return 0; + ++ s1; + ++ s2; + } + /* never reached. */ +} + +int +FcUtf8ToUcs4 (const FcChar8 *src_orig, + FcChar32 *dst, + int len) +{ + const FcChar8 *src = src_orig; + FcChar8 s; + int extra; + FcChar32 result; + + if (len == 0) + return 0; + + s = *src++; + len--; + + if (!(s & 0x80)) + { + result = s; + extra = 0; + } + else if (!(s & 0x40)) + { + return -1; + } + else if (!(s & 0x20)) + { + result = s & 0x1f; + extra = 1; + } + else if (!(s & 0x10)) + { + result = s & 0xf; + extra = 2; + } + else if (!(s & 0x08)) + { + result = s & 0x07; + extra = 3; + } + else if (!(s & 0x04)) + { + result = s & 0x03; + extra = 4; + } + else if ( ! (s & 0x02)) + { + result = s & 0x01; + extra = 5; + } + else + { + return -1; + } + if (extra > len) + return -1; + + while (extra--) + { + result <<= 6; + s = *src++; + + if ((s & 0xc0) != 0x80) + return -1; + + result |= s & 0x3f; + } + *dst = result; + return src - src_orig; +} + +FcBool +FcUtf8Len (const FcChar8 *string, + int len, + int *nchar, + int *wchar) +{ + int n; + int clen; + FcChar32 c; + FcChar32 max; + + n = 0; + max = 0; + while (len) + { + clen = FcUtf8ToUcs4 (string, &c, len); + if (clen <= 0) /* malformed UTF8 string */ + return FcFalse; + if (c > max) + max = c; + string += clen; + len -= clen; + n++; + } + *nchar = n; + if (max >= 0x10000) + *wchar = 4; + else if (max > 0x100) + *wchar = 2; + else + *wchar = 1; + return FcTrue; +} + +int +FcUcs4ToUtf8 (FcChar32 ucs4, + FcChar8 dest[FC_UTF8_MAX_LEN]) +{ + int bits; + FcChar8 *d = dest; + + if (ucs4 < 0x80) { *d++= ucs4; bits= -6; } + else if (ucs4 < 0x800) { *d++= ((ucs4 >> 6) & 0x1F) | 0xC0; bits= 0; } + else if (ucs4 < 0x10000) { *d++= ((ucs4 >> 12) & 0x0F) | 0xE0; bits= 6; } + else if (ucs4 < 0x200000) { *d++= ((ucs4 >> 18) & 0x07) | 0xF0; bits= 12; } + else if (ucs4 < 0x4000000) { *d++= ((ucs4 >> 24) & 0x03) | 0xF8; bits= 18; } + else if (ucs4 < 0x80000000) { *d++= ((ucs4 >> 30) & 0x01) | 0xFC; bits= 24; } + else return 0; + + for ( ; bits >= 0; bits-= 6) { + *d++= ((ucs4 >> bits) & 0x3F) | 0x80; + } + return d - dest; +} + +#define GetUtf16(src,endian) \ + ((FcChar16) ((src)[endian == FcEndianBig ? 0 : 1] << 8) | \ + (FcChar16) ((src)[endian == FcEndianBig ? 1 : 0])) + +int +FcUtf16ToUcs4 (const FcChar8 *src_orig, + FcEndian endian, + FcChar32 *dst, + int len) /* in bytes */ +{ + const FcChar8 *src = src_orig; + FcChar16 a, b; + FcChar32 result; + + if (len < 2) + return 0; + + a = GetUtf16 (src, endian); src += 2; len -= 2; + + /* + * Check for surrogate + */ + if ((a & 0xfc00) == 0xd800) + { + if (len < 2) + return 0; + b = GetUtf16 (src, endian); src += 2; len -= 2; + /* + * Check for invalid surrogate sequence + */ + if ((b & 0xfc00) != 0xdc00) + return 0; + result = ((((FcChar32) a & 0x3ff) << 10) | + ((FcChar32) b & 0x3ff)) + 0x10000; + } + else + result = a; + *dst = result; + return src - src_orig; +} + +FcBool +FcUtf16Len (const FcChar8 *string, + FcEndian endian, + int len, /* in bytes */ + int *nchar, + int *wchar) +{ + int n; + int clen; + FcChar32 c; + FcChar32 max; + + n = 0; + max = 0; + while (len) + { + clen = FcUtf16ToUcs4 (string, endian, &c, len); + if (clen <= 0) /* malformed UTF8 string */ + return FcFalse; + if (c > max) + max = c; + string += clen; + len -= clen; + n++; + } + *nchar = n; + if (max >= 0x10000) + *wchar = 4; + else if (max > 0x100) + *wchar = 2; + else + *wchar = 1; + return FcTrue; +} + +void +FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size) +{ + if (init) + { + buf->buf = init; + buf->size = size; + } else + { + buf->buf = buf->buf_static; + buf->size = sizeof (buf->buf_static); + } + buf->allocated = FcFalse; + buf->failed = FcFalse; + buf->len = 0; +} + +void +FcStrBufDestroy (FcStrBuf *buf) +{ + if (buf->allocated) + { + free (buf->buf); + FcStrBufInit (buf, 0, 0); + } +} + +FcChar8 * +FcStrBufDone (FcStrBuf *buf) +{ + FcChar8 *ret; + + if (buf->failed) + ret = NULL; + else + ret = malloc (buf->len + 1); + if (ret) + { + memcpy (ret, buf->buf, buf->len); + ret[buf->len] = '\0'; + } + FcStrBufDestroy (buf); + return ret; +} + +FcChar8 * +FcStrBufDoneStatic (FcStrBuf *buf) +{ + FcStrBufChar (buf, '\0'); + + if (buf->failed) + return NULL; + + return buf->buf; +} + +FcBool +FcStrBufChar (FcStrBuf *buf, FcChar8 c) +{ + if (buf->len == buf->size) + { + FcChar8 *new; + int size; + + if (buf->failed) + return FcFalse; + + if (buf->allocated) + { + size = buf->size * 2; + new = realloc (buf->buf, size); + } + else + { + size = buf->size + 64; + new = malloc (size); + if (new) + { + buf->allocated = FcTrue; + memcpy (new, buf->buf, buf->len); + } + } + if (!new) + { + buf->failed = FcTrue; + return FcFalse; + } + buf->size = size; + buf->buf = new; + } + buf->buf[buf->len++] = c; + return FcTrue; +} + +FcBool +FcStrBufString (FcStrBuf *buf, const FcChar8 *s) +{ + FcChar8 c; + while ((c = *s++)) + if (!FcStrBufChar (buf, c)) + return FcFalse; + return FcTrue; +} + +FcBool +FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len) +{ + while (len-- > 0) + if (!FcStrBufChar (buf, *s++)) + return FcFalse; + return FcTrue; +} + +FcBool +FcStrUsesHome (const FcChar8 *s) +{ + return *s == '~'; +} + +FcChar8 * +FcStrBuildFilename (const FcChar8 *path, + ...) +{ + va_list ap; + FcStrSet *sset; + FcStrList *list; + FcChar8 *s, *ret = NULL, *p; + size_t len = 0; + + if (!path) + return NULL; + + sset = FcStrSetCreate (); + if (!sset) + return NULL; + + if (!FcStrSetAdd (sset, path)) + goto bail0; + + va_start (ap, path); + while (1) + { + s = (FcChar8 *)va_arg (ap, FcChar8 *); + if (!s) + break; + if (!FcStrSetAdd (sset, s)) + goto bail1; + } + list = FcStrListCreate (sset); + while ((s = FcStrListNext (list))) + { + len += strlen ((const char *)s) + 1; + } + list->n = 0; + ret = malloc (sizeof (FcChar8) * (len + 1)); + if (!ret) + goto bail2; + p = ret; + while ((s = FcStrListNext (list))) + { + if (p != ret) + { + p[0] = FC_DIR_SEPARATOR; + p++; + } + len = strlen ((const char *)s); + memcpy (p, s, len); + p += len; + } + *p = 0; + +bail2: + FcStrListDone (list); +bail1: + va_end (ap); +bail0: + FcStrSetDestroy (sset); + + return ret; +} + +FcChar8 * +FcStrCopyFilename (const FcChar8 *s) +{ + FcChar8 *new; + + if (*s == '~') + { + FcChar8 *home = FcConfigHome (); + FcChar8 *full; + int size; + if (!home) + return NULL; + size = strlen ((char *) home) + strlen ((char *) s); + full = (FcChar8 *) malloc (size); + if (!full) + return NULL; + strcpy ((char *) full, (char *) home); + strcat ((char *) full, (char *) s + 1); + new = FcStrCanonFilename (full); + free (full); + } + else + new = FcStrCanonFilename (s); + + return new; +} + +FcChar8 * +FcStrLastSlash (const FcChar8 *path) +{ + FcChar8 *slash; + + slash = (FcChar8 *) strrchr ((const char *) path, '/'); +#ifdef _WIN32 + { + FcChar8 *backslash; + + backslash = (FcChar8 *) strrchr ((const char *) path, '\\'); + if (!slash || (backslash && backslash > slash)) + slash = backslash; + } +#endif + + return slash; +} + +FcChar8 * +FcStrDirname (const FcChar8 *file) +{ + FcChar8 *slash; + FcChar8 *dir; + + slash = FcStrLastSlash (file); + if (!slash) + return FcStrCopy ((FcChar8 *) "."); + dir = malloc ((slash - file) + 1); + if (!dir) + return 0; + strncpy ((char *) dir, (const char *) file, slash - file); + dir[slash - file] = '\0'; + return dir; +} + +FcChar8 * +FcStrBasename (const FcChar8 *file) +{ + FcChar8 *slash; + + slash = FcStrLastSlash (file); + if (!slash) + return FcStrCopy (file); + return FcStrCopy (slash + 1); +} + +static FcChar8 * +FcStrCanonAbsoluteFilename (const FcChar8 *s) +{ + FcChar8 *file; + FcChar8 *f; + const FcChar8 *slash; + int size; + + size = strlen ((char *) s) + 1; + file = malloc (size); + if (!file) + return NULL; + slash = NULL; + f = file; +#ifdef _WIN32 + if (*s == '/' && *(s+1) == '/') /* Network path, do not squash // */ + *f++ = *s++; +#endif + for (;;) { + if (*s == '/' || *s == '\0') + { + if (slash) + { + switch (s - slash) { + case 1: + f -= 1; /* squash // and trim final / from file */ + break; + case 2: + if (!strncmp ((char *) slash, "/.", 2)) + { + f -= 2; /* trim /. from file */ + } + break; + case 3: + if (!strncmp ((char *) slash, "/..", 3)) + { + f -= 3; /* trim /.. from file */ + while (f > file) { + if (*--f == '/') + break; + } + } + break; + } + } + slash = s; + } + if (!(*f++ = *s++)) + break; + } + return file; +} + +#ifdef _WIN32 +/* + * Convert '\\' to '/' , remove double '/' + */ +static void +FcConvertDosPath (char *str) +{ + size_t len = strlen (str); + char *p = str; + char *dest = str; + char *end = str + len; + char last = 0; + + if (*p == '\\') + { + *p = '/'; + p++; + dest++; + } + while (p < end) + { + if (*p == '\\') + *p = '/'; + + if (*p != '/' + || last != '/') + { + *dest++ = *p; + } + + last = *p; + p++; + } + + *dest = 0; +} +#endif + +FcChar8 * +FcStrCanonFilename (const FcChar8 *s) +{ +#ifdef _WIN32 + FcChar8 full[FC_MAX_FILE_LEN + 2]; + int size = GetFullPathName ((LPCSTR) s, sizeof (full) -1, + (LPSTR) full, NULL); + + if (size == 0) + perror ("GetFullPathName"); + + FcConvertDosPath ((char *) full); + return FcStrCanonAbsoluteFilename (full); +#else + if (s[0] == '/') + return FcStrCanonAbsoluteFilename (s); + else + { + FcChar8 *full; + FcChar8 *file; + + FcChar8 cwd[FC_MAX_FILE_LEN + 2]; + if (getcwd ((char *) cwd, FC_MAX_FILE_LEN) == NULL) + return NULL; + full = FcStrBuildFilename (cwd, s, NULL); + file = FcStrCanonAbsoluteFilename (full); + FcStrFree (full); + return file; + } +#endif +} + + +FcStrSet * +FcStrSetCreate (void) +{ + FcStrSet *set = malloc (sizeof (FcStrSet)); + if (!set) + return 0; + FcRefInit (&set->ref, 1); + set->num = 0; + set->size = 0; + set->strs = 0; + return set; +} + +static FcBool +_FcStrSetAppend (FcStrSet *set, FcChar8 *s) +{ + if (FcStrSetMember (set, s)) + { + FcStrFree (s); + return FcTrue; + } + if (set->num == set->size) + { + FcChar8 **strs = malloc ((set->size + 2) * sizeof (FcChar8 *)); + + if (!strs) + return FcFalse; + if (set->num) + memcpy (strs, set->strs, set->num * sizeof (FcChar8 *)); + if (set->strs) + free (set->strs); + set->size = set->size + 1; + set->strs = strs; + } + set->strs[set->num++] = s; + set->strs[set->num] = 0; + return FcTrue; +} + +FcBool +FcStrSetMember (FcStrSet *set, const FcChar8 *s) +{ + int i; + + for (i = 0; i < set->num; i++) + if (!FcStrCmp (set->strs[i], s)) + return FcTrue; + return FcFalse; +} + +FcBool +FcStrSetEqual (FcStrSet *sa, FcStrSet *sb) +{ + int i; + if (sa->num != sb->num) + return FcFalse; + for (i = 0; i < sa->num; i++) + if (!FcStrSetMember (sb, sa->strs[i])) + return FcFalse; + return FcTrue; +} + +FcBool +FcStrSetAdd (FcStrSet *set, const FcChar8 *s) +{ + FcChar8 *new = FcStrCopy (s); + if (!new) + return FcFalse; + if (!_FcStrSetAppend (set, new)) + { + FcStrFree (new); + return FcFalse; + } + return FcTrue; +} + +FcBool +FcStrSetAddFilename (FcStrSet *set, const FcChar8 *s) +{ + FcChar8 *new = FcStrCopyFilename (s); + if (!new) + return FcFalse; + if (!_FcStrSetAppend (set, new)) + { + FcStrFree (new); + return FcFalse; + } + return FcTrue; +} + +FcBool +FcStrSetAddLangs (FcStrSet *strs, const char *languages) +{ + const char *p = languages, *next; + FcChar8 lang[128] = {0}, *normalized_lang; + size_t len; + FcBool ret = FcFalse; + + if (!languages) + return FcFalse; + + while ((next = strchr (p, ':'))) + { + len = next - p; + len = FC_MIN (len, 127); + strncpy ((char *) lang, p, len); + lang[len] = 0; + /* ignore an empty item */ + if (*lang) + { + normalized_lang = FcLangNormalize ((const FcChar8 *) lang); + if (normalized_lang) + { + FcStrSetAdd (strs, normalized_lang); + FcStrFree (normalized_lang); + ret = FcTrue; + } + } + p = next + 1; + } + if (*p) + { + normalized_lang = FcLangNormalize ((const FcChar8 *) p); + if (normalized_lang) + { + FcStrSetAdd (strs, normalized_lang); + FcStrFree (normalized_lang); + ret = FcTrue; + } + } + + return ret; +} + +FcBool +FcStrSetDel (FcStrSet *set, const FcChar8 *s) +{ + int i; + + for (i = 0; i < set->num; i++) + if (!FcStrCmp (set->strs[i], s)) + { + FcStrFree (set->strs[i]); + /* + * copy remaining string pointers and trailing + * NULL + */ + memmove (&set->strs[i], &set->strs[i+1], + (set->num - i) * sizeof (FcChar8 *)); + set->num--; + return FcTrue; + } + return FcFalse; +} + +/* TODO Make public */ +static FcStrSet * +FcStrSetReference (FcStrSet *set) +{ + if (FcRefIsConst (&set->ref)) + return set; + + FcRefInc (&set->ref); + return set; +} + +void +FcStrSetDestroy (FcStrSet *set) +{ + int i; + + /* We rely on this in FcGetDefaultLangs for caching. */ + if (FcRefIsConst (&set->ref)) + return; + + if (FcRefDec (&set->ref) != 1) + return; + + for (i = 0; i < set->num; i++) + FcStrFree (set->strs[i]); + if (set->strs) + free (set->strs); + free (set); +} + +FcStrList * +FcStrListCreate (FcStrSet *set) +{ + FcStrList *list; + + list = malloc (sizeof (FcStrList)); + if (!list) + return 0; + list->set = set; + FcStrSetReference (set); + list->n = 0; + return list; +} + +void +FcStrListFirst (FcStrList *list) +{ + list->n = 0; +} + +FcChar8 * +FcStrListNext (FcStrList *list) +{ + if (list->n >= list->set->num) + return 0; + return list->set->strs[list->n++]; +} + +void +FcStrListDone (FcStrList *list) +{ + FcStrSetDestroy (list->set); + free (list); +} + +#define __fcstr__ +#include "fcaliastail.h" +#undef __fcstr__ diff --git a/project/jni/fontconfig/src/fcwindows.h b/project/jni/fontconfig/src/fcwindows.h new file mode 100644 index 000000000..02489d9dc --- /dev/null +++ b/project/jni/fontconfig/src/fcwindows.h @@ -0,0 +1,44 @@ +/* + * fontconfig/src/fcwindows.h + * + * Copyright © 2013 Google, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef _FCWINDOWS_H_ +#define _FCWINDOWS_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef _WIN32 +# ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0500 +# endif +# define WIN32_LEAN_AND_MEAN +# define WIN32_EXTRA_LEAN +# define STRICT +# include +#endif + +#endif /* _FCWINDOWS_H_ */ diff --git a/project/jni/fontconfig/src/fcxml.c b/project/jni/fontconfig/src/fcxml.c new file mode 100644 index 000000000..454900dba --- /dev/null +++ b/project/jni/fontconfig/src/fcxml.c @@ -0,0 +1,3212 @@ +/* + * fontconfig/src/fcxml.c + * + * Copyright © 2002 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the author(s) not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The authors make no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "fcint.h" +#include +#include +#include + +#ifdef ENABLE_LIBXML2 + +#include + +#define XML_Char xmlChar +#define XML_Parser xmlParserCtxtPtr +#define XML_ParserFree xmlFreeParserCtxt +#define XML_GetCurrentLineNumber xmlSAX2GetLineNumber +#define XML_GetErrorCode xmlCtxtGetLastError +#define XML_ErrorString(Error) (Error)->message + +#else /* ENABLE_LIBXML2 */ + +#ifndef HAVE_XMLPARSE_H +#define HAVE_XMLPARSE_H 0 +#endif + +#if HAVE_XMLPARSE_H +#include +#else +#include +#endif + +#endif /* ENABLE_LIBXML2 */ + +#ifdef _WIN32 +#include +#endif + +static void +FcExprDestroy (FcExpr *e); + +void +FcTestDestroy (FcTest *test) +{ + FcExprDestroy (test->expr); + free (test); +} + +void +FcRuleDestroy (FcRule *rule) +{ + FcRule *n = rule->next; + + switch (rule->type) { + case FcRuleTest: + FcTestDestroy (rule->u.test); + break; + case FcRuleEdit: + FcEditDestroy (rule->u.edit); + break; + default: + break; + } + free (rule); + if (n) + FcRuleDestroy (n); +} + +static FcExpr * +FcExprCreateInteger (FcConfig *config, int i) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = FcOpInteger; + e->u.ival = i; + } + return e; +} + +static FcExpr * +FcExprCreateDouble (FcConfig *config, double d) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = FcOpDouble; + e->u.dval = d; + } + return e; +} + +static FcExpr * +FcExprCreateString (FcConfig *config, const FcChar8 *s) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = FcOpString; + e->u.sval = FcStrdup (s); + } + return e; +} + +static FcExprMatrix * +FcExprMatrixCopyShallow (const FcExprMatrix *matrix) +{ + FcExprMatrix *m = malloc (sizeof (FcExprMatrix)); + if (m) + { + *m = *matrix; + } + return m; +} + +static void +FcExprMatrixFreeShallow (FcExprMatrix *m) +{ + if (!m) + return; + + free (m); +} + +static void +FcExprMatrixFree (FcExprMatrix *m) +{ + if (!m) + return; + + FcExprDestroy (m->xx); + FcExprDestroy (m->xy); + FcExprDestroy (m->yx); + FcExprDestroy (m->yy); + + free (m); +} + +static FcExpr * +FcExprCreateMatrix (FcConfig *config, const FcExprMatrix *matrix) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = FcOpMatrix; + e->u.mexpr = FcExprMatrixCopyShallow (matrix); + } + return e; +} + +static FcExpr * +FcExprCreateBool (FcConfig *config, FcBool b) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = FcOpBool; + e->u.bval = b; + } + return e; +} + +static FcExpr * +FcExprCreateCharSet (FcConfig *config, FcCharSet *charset) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = FcOpCharSet; + e->u.cval = FcCharSetCopy (charset); + } + return e; +} + +static FcExpr * +FcExprCreateLangSet (FcConfig *config, FcLangSet *langset) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = FcOpLangSet; + e->u.lval = FcLangSetCopy (langset); + } + return e; +} + +static FcExpr * +FcExprCreateName (FcConfig *config, FcExprName name) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = FcOpField; + e->u.name = name; + } + return e; +} + +static FcExpr * +FcExprCreateConst (FcConfig *config, const FcChar8 *constant) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = FcOpConst; + e->u.constant = FcStrdup (constant); + } + return e; +} + +static FcExpr * +FcExprCreateOp (FcConfig *config, FcExpr *left, FcOp op, FcExpr *right) +{ + FcExpr *e = FcConfigAllocExpr (config); + if (e) + { + e->op = op; + e->u.tree.left = left; + e->u.tree.right = right; + } + return e; +} + +static void +FcExprDestroy (FcExpr *e) +{ + if (!e) + return; + switch (FC_OP_GET_OP (e->op)) { + case FcOpInteger: + break; + case FcOpDouble: + break; + case FcOpString: + FcFree (e->u.sval); + break; + case FcOpMatrix: + FcExprMatrixFree (e->u.mexpr); + break; + case FcOpRange: + break; + case FcOpCharSet: + FcCharSetDestroy (e->u.cval); + break; + case FcOpLangSet: + FcLangSetDestroy (e->u.lval); + break; + case FcOpBool: + break; + case FcOpField: + break; + case FcOpConst: + FcFree (e->u.constant); + break; + case FcOpAssign: + case FcOpAssignReplace: + case FcOpPrepend: + case FcOpPrependFirst: + case FcOpAppend: + case FcOpAppendLast: + case FcOpDelete: + case FcOpDeleteAll: + break; + case FcOpOr: + case FcOpAnd: + case FcOpEqual: + case FcOpNotEqual: + case FcOpLess: + case FcOpLessEqual: + case FcOpMore: + case FcOpMoreEqual: + case FcOpContains: + case FcOpListing: + case FcOpNotContains: + case FcOpPlus: + case FcOpMinus: + case FcOpTimes: + case FcOpDivide: + case FcOpQuest: + case FcOpComma: + FcExprDestroy (e->u.tree.right); + /* fall through */ + case FcOpNot: + case FcOpFloor: + case FcOpCeil: + case FcOpRound: + case FcOpTrunc: + FcExprDestroy (e->u.tree.left); + break; + case FcOpNil: + case FcOpInvalid: + break; + } + + e->op = FcOpNil; +} + +void +FcEditDestroy (FcEdit *e) +{ + if (e->expr) + FcExprDestroy (e->expr); + free (e); +} + +typedef enum _FcElement { + FcElementNone, + FcElementFontconfig, + FcElementDir, + FcElementCacheDir, + FcElementCache, + FcElementInclude, + FcElementConfig, + FcElementMatch, + FcElementAlias, + + FcElementBlank, + FcElementRescan, + + FcElementPrefer, + FcElementAccept, + FcElementDefault, + FcElementFamily, + + FcElementSelectfont, + FcElementAcceptfont, + FcElementRejectfont, + FcElementGlob, + FcElementPattern, + FcElementPatelt, + + FcElementTest, + FcElementEdit, + FcElementInt, + FcElementDouble, + FcElementString, + FcElementMatrix, + FcElementRange, + FcElementBool, + FcElementCharSet, + FcElementLangSet, + FcElementName, + FcElementConst, + FcElementOr, + FcElementAnd, + FcElementEq, + FcElementNotEq, + FcElementLess, + FcElementLessEq, + FcElementMore, + FcElementMoreEq, + FcElementContains, + FcElementNotContains, + FcElementPlus, + FcElementMinus, + FcElementTimes, + FcElementDivide, + FcElementNot, + FcElementIf, + FcElementFloor, + FcElementCeil, + FcElementRound, + FcElementTrunc, + FcElementUnknown +} FcElement; + +static const struct { + const char name[16]; + FcElement element; +} fcElementMap[] = { + { "fontconfig", FcElementFontconfig }, + { "dir", FcElementDir }, + { "cachedir", FcElementCacheDir }, + { "cache", FcElementCache }, + { "include", FcElementInclude }, + { "config", FcElementConfig }, + { "match", FcElementMatch }, + { "alias", FcElementAlias }, + + { "blank", FcElementBlank }, + { "rescan", FcElementRescan }, + + { "prefer", FcElementPrefer }, + { "accept", FcElementAccept }, + { "default", FcElementDefault }, + { "family", FcElementFamily }, + + { "selectfont", FcElementSelectfont }, + { "acceptfont", FcElementAcceptfont }, + { "rejectfont", FcElementRejectfont }, + { "glob", FcElementGlob }, + { "pattern", FcElementPattern }, + { "patelt", FcElementPatelt }, + + { "test", FcElementTest }, + { "edit", FcElementEdit }, + { "int", FcElementInt }, + { "double", FcElementDouble }, + { "string", FcElementString }, + { "matrix", FcElementMatrix }, + { "range", FcElementRange }, + { "bool", FcElementBool }, + { "charset", FcElementCharSet }, + { "langset", FcElementLangSet }, + { "name", FcElementName }, + { "const", FcElementConst }, + { "or", FcElementOr }, + { "and", FcElementAnd }, + { "eq", FcElementEq }, + { "not_eq", FcElementNotEq }, + { "less", FcElementLess }, + { "less_eq", FcElementLessEq }, + { "more", FcElementMore }, + { "more_eq", FcElementMoreEq }, + { "contains", FcElementContains }, + { "not_contains", FcElementNotContains }, + { "plus", FcElementPlus }, + { "minus", FcElementMinus }, + { "times", FcElementTimes }, + { "divide", FcElementDivide }, + { "not", FcElementNot }, + { "if", FcElementIf }, + { "floor", FcElementFloor }, + { "ceil", FcElementCeil }, + { "round", FcElementRound }, + { "trunc", FcElementTrunc }, +}; +#define NUM_ELEMENT_MAPS (int) (sizeof fcElementMap / sizeof fcElementMap[0]) + +static FcElement +FcElementMap (const XML_Char *name) +{ + + int i; + for (i = 0; i < NUM_ELEMENT_MAPS; i++) + if (!strcmp ((char *) name, fcElementMap[i].name)) + return fcElementMap[i].element; + return FcElementUnknown; +} + +typedef struct _FcPStack { + struct _FcPStack *prev; + FcElement element; + FcChar8 **attr; + FcStrBuf str; + FcChar8 *attr_buf_static[16]; +} FcPStack; + +typedef enum _FcVStackTag { + FcVStackNone, + + FcVStackString, + FcVStackFamily, + FcVStackConstant, + FcVStackGlob, + FcVStackName, + FcVStackPattern, + + FcVStackPrefer, + FcVStackAccept, + FcVStackDefault, + + FcVStackInteger, + FcVStackDouble, + FcVStackMatrix, + FcVStackRange, + FcVStackBool, + FcVStackCharSet, + FcVStackLangSet, + + FcVStackTest, + FcVStackExpr, + FcVStackEdit +} FcVStackTag; + +typedef struct _FcVStack { + struct _FcVStack *prev; + FcPStack *pstack; /* related parse element */ + FcVStackTag tag; + union { + FcChar8 *string; + + int integer; + double _double; + FcExprMatrix *matrix; + FcRange range; + FcBool bool_; + FcCharSet *charset; + FcLangSet *langset; + FcExprName name; + + FcTest *test; + FcQual qual; + FcOp op; + FcExpr *expr; + FcEdit *edit; + + FcPattern *pattern; + } u; +} FcVStack; + +typedef struct _FcConfigParse { + FcPStack *pstack; + FcVStack *vstack; + FcBool error; + const FcChar8 *name; + FcConfig *config; + XML_Parser parser; + unsigned int pstack_static_used; + FcPStack pstack_static[8]; + unsigned int vstack_static_used; + FcVStack vstack_static[64]; +} FcConfigParse; + +typedef enum _FcConfigSeverity { + FcSevereInfo, FcSevereWarning, FcSevereError +} FcConfigSeverity; + +static void +FcConfigMessage (FcConfigParse *parse, FcConfigSeverity severe, const char *fmt, ...) +{ + const char *s = "unknown"; + va_list args; + + va_start (args, fmt); + + switch (severe) { + case FcSevereInfo: s = "info"; break; + case FcSevereWarning: s = "warning"; break; + case FcSevereError: s = "error"; break; + } + if (parse) + { + if (parse->name) + fprintf (stderr, "Fontconfig %s: \"%s\", line %d: ", s, + parse->name, (int)XML_GetCurrentLineNumber (parse->parser)); + else + fprintf (stderr, "Fontconfig %s: line %d: ", s, + (int)XML_GetCurrentLineNumber (parse->parser)); + if (severe >= FcSevereError) + parse->error = FcTrue; + } + else + fprintf (stderr, "Fontconfig %s: ", s); + vfprintf (stderr, fmt, args); + fprintf (stderr, "\n"); + va_end (args); +} + + +static FcExpr * +FcPopExpr (FcConfigParse *parse); + + +static const char * +FcTypeName (FcType type) +{ + switch (type) { + case FcTypeVoid: + return "void"; + case FcTypeInteger: + case FcTypeDouble: + return "number"; + case FcTypeString: + return "string"; + case FcTypeBool: + return "bool"; + case FcTypeMatrix: + return "matrix"; + case FcTypeCharSet: + return "charset"; + case FcTypeFTFace: + return "FT_Face"; + case FcTypeLangSet: + return "langset"; + default: + return "unknown"; + } +} + +static void +FcTypecheckValue (FcConfigParse *parse, FcType value, FcType type) +{ + if (value == FcTypeInteger) + value = FcTypeDouble; + if (type == FcTypeInteger) + type = FcTypeDouble; + if (value != type) + { + if ((value == FcTypeLangSet && type == FcTypeString) || + (value == FcTypeString && type == FcTypeLangSet)) + return; + if (type == FcTypeUnknown) + return; + /* It's perfectly fine to use user-define elements in expressions, + * so don't warn in that case. */ + if (value == FcTypeUnknown) + return; + FcConfigMessage (parse, FcSevereWarning, "saw %s, expected %s", + FcTypeName (value), FcTypeName (type)); + } +} + +static void +FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type) +{ + const FcObjectType *o; + const FcConstant *c; + + /* If parsing the expression failed, some nodes may be NULL */ + if (!expr) + return; + + switch (FC_OP_GET_OP (expr->op)) { + case FcOpInteger: + case FcOpDouble: + FcTypecheckValue (parse, FcTypeDouble, type); + break; + case FcOpString: + FcTypecheckValue (parse, FcTypeString, type); + break; + case FcOpMatrix: + FcTypecheckValue (parse, FcTypeMatrix, type); + break; + case FcOpBool: + FcTypecheckValue (parse, FcTypeBool, type); + break; + case FcOpCharSet: + FcTypecheckValue (parse, FcTypeCharSet, type); + break; + case FcOpLangSet: + FcTypecheckValue (parse, FcTypeLangSet, type); + break; + case FcOpNil: + break; + case FcOpField: + o = FcNameGetObjectType (FcObjectName (expr->u.name.object)); + if (o) + FcTypecheckValue (parse, o->type, type); + break; + case FcOpConst: + c = FcNameGetConstant (expr->u.constant); + if (c) + { + o = FcNameGetObjectType (c->object); + if (o) + FcTypecheckValue (parse, o->type, type); + } + else + FcConfigMessage (parse, FcSevereWarning, + "invalid constant used : %s", + expr->u.constant); + break; + case FcOpQuest: + FcTypecheckExpr (parse, expr->u.tree.left, FcTypeBool); + FcTypecheckExpr (parse, expr->u.tree.right->u.tree.left, type); + FcTypecheckExpr (parse, expr->u.tree.right->u.tree.right, type); + break; + case FcOpAssign: + case FcOpAssignReplace: + break; + case FcOpEqual: + case FcOpNotEqual: + case FcOpLess: + case FcOpLessEqual: + case FcOpMore: + case FcOpMoreEqual: + case FcOpContains: + case FcOpNotContains: + case FcOpListing: + FcTypecheckValue (parse, FcTypeBool, type); + break; + case FcOpComma: + case FcOpOr: + case FcOpAnd: + case FcOpPlus: + case FcOpMinus: + case FcOpTimes: + case FcOpDivide: + FcTypecheckExpr (parse, expr->u.tree.left, type); + FcTypecheckExpr (parse, expr->u.tree.right, type); + break; + case FcOpNot: + FcTypecheckValue (parse, FcTypeBool, type); + FcTypecheckExpr (parse, expr->u.tree.left, FcTypeBool); + break; + case FcOpFloor: + case FcOpCeil: + case FcOpRound: + case FcOpTrunc: + FcTypecheckValue (parse, FcTypeDouble, type); + FcTypecheckExpr (parse, expr->u.tree.left, FcTypeDouble); + break; + default: + break; + } +} + +static FcTest * +FcTestCreate (FcConfigParse *parse, + FcMatchKind kind, + FcQual qual, + const FcChar8 *field, + unsigned int compare, + FcExpr *expr) +{ + FcTest *test = (FcTest *) malloc (sizeof (FcTest)); + + if (test) + { + const FcObjectType *o; + + test->kind = kind; + test->qual = qual; + test->object = FcObjectFromName ((const char *) field); + test->op = compare; + test->expr = expr; + o = FcNameGetObjectType (FcObjectName (test->object)); + if (o) + FcTypecheckExpr (parse, expr, o->type); + } + return test; +} + +static FcEdit * +FcEditCreate (FcConfigParse *parse, + FcObject object, + FcOp op, + FcExpr *expr, + FcValueBinding binding) +{ + FcEdit *e = (FcEdit *) malloc (sizeof (FcEdit)); + + if (e) + { + const FcObjectType *o; + + e->object = object; + e->op = op; + e->expr = expr; + e->binding = binding; + o = FcNameGetObjectType (FcObjectName (e->object)); + if (o) + FcTypecheckExpr (parse, expr, o->type); + } + return e; +} + +static FcRule * +FcRuleCreate (FcRuleType type, + void *p) +{ + FcRule *r = (FcRule *) malloc (sizeof (FcRule)); + + if (!r) + return NULL; + + r->next = NULL; + r->type = type; + switch (type) + { + case FcRuleTest: + r->u.test = (FcTest *) p; + break; + case FcRuleEdit: + r->u.edit = (FcEdit *) p; + break; + default: + free (r); + r = NULL; + break; + } + + return r; +} + +static FcVStack * +FcVStackCreateAndPush (FcConfigParse *parse) +{ + FcVStack *new; + + if (parse->vstack_static_used < sizeof (parse->vstack_static) / sizeof (parse->vstack_static[0])) + new = &parse->vstack_static[parse->vstack_static_used++]; + else + { + new = malloc (sizeof (FcVStack)); + if (!new) + return 0; + } + new->tag = FcVStackNone; + new->prev = 0; + + new->prev = parse->vstack; + new->pstack = parse->pstack ? parse->pstack->prev : 0; + parse->vstack = new; + + return new; +} + +static FcBool +FcVStackPushString (FcConfigParse *parse, FcVStackTag tag, FcChar8 *string) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.string = string; + vstack->tag = tag; + return FcTrue; +} + +static FcBool +FcVStackPushInteger (FcConfigParse *parse, int integer) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.integer = integer; + vstack->tag = FcVStackInteger; + return FcTrue; +} + +static FcBool +FcVStackPushDouble (FcConfigParse *parse, double _double) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u._double = _double; + vstack->tag = FcVStackDouble; + return FcTrue; +} + +static FcBool +FcVStackPushMatrix (FcConfigParse *parse, FcExprMatrix *matrix) +{ + FcVStack *vstack; + vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.matrix = FcExprMatrixCopyShallow (matrix); + vstack->tag = FcVStackMatrix; + return FcTrue; +} + +static FcBool +FcVStackPushRange (FcConfigParse *parse, FcRange *range) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.range.begin = range->begin; + vstack->u.range.end = range->end; + vstack->tag = FcVStackRange; + return FcTrue; +} + +static FcBool +FcVStackPushBool (FcConfigParse *parse, FcBool bool_) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.bool_ = bool_; + vstack->tag = FcVStackBool; + return FcTrue; +} + +static FcBool +FcVStackPushCharSet (FcConfigParse *parse, FcCharSet *charset) +{ + FcVStack *vstack; + if (!charset) + return FcFalse; + vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.charset = charset; + vstack->tag = FcVStackCharSet; + return FcTrue; +} + +static FcBool +FcVStackPushLangSet (FcConfigParse *parse, FcLangSet *langset) +{ + FcVStack *vstack; + if (!langset) + return FcFalse; + vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.langset = langset; + vstack->tag = FcVStackLangSet; + return FcTrue; +} + +static FcBool +FcVStackPushName (FcConfigParse *parse, FcMatchKind kind, FcObject object) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.name.object = object; + vstack->u.name.kind = kind; + vstack->tag = FcVStackName; + return FcTrue; +} + +static FcBool +FcVStackPushTest (FcConfigParse *parse, FcTest *test) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.test = test; + vstack->tag = FcVStackTest; + return FcTrue; +} + +static FcBool +FcVStackPushExpr (FcConfigParse *parse, FcVStackTag tag, FcExpr *expr) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.expr = expr; + vstack->tag = tag; + return FcTrue; +} + +static FcBool +FcVStackPushEdit (FcConfigParse *parse, FcEdit *edit) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.edit = edit; + vstack->tag = FcVStackEdit; + return FcTrue; +} + +static FcBool +FcVStackPushPattern (FcConfigParse *parse, FcPattern *pattern) +{ + FcVStack *vstack = FcVStackCreateAndPush (parse); + if (!vstack) + return FcFalse; + vstack->u.pattern = pattern; + vstack->tag = FcVStackPattern; + return FcTrue; +} + +static FcVStack * +FcVStackFetch (FcConfigParse *parse, int off) +{ + FcVStack *vstack; + + for (vstack = parse->vstack; vstack && off-- > 0; vstack = vstack->prev); + return vstack; +} + +static FcVStack * +FcVStackPeek (FcConfigParse *parse) +{ + FcVStack *vstack = parse->vstack; + + return vstack && vstack->pstack == parse->pstack ? vstack : 0; +} + +static void +FcVStackPopAndDestroy (FcConfigParse *parse) +{ + FcVStack *vstack = parse->vstack; + + if (!vstack || vstack->pstack != parse->pstack) + return; + + parse->vstack = vstack->prev; + + switch (vstack->tag) { + case FcVStackNone: + break; + case FcVStackName: + break; + case FcVStackFamily: + break; + case FcVStackString: + case FcVStackConstant: + case FcVStackGlob: + FcStrFree (vstack->u.string); + break; + case FcVStackPattern: + FcPatternDestroy (vstack->u.pattern); + break; + case FcVStackInteger: + case FcVStackDouble: + break; + case FcVStackMatrix: + FcExprMatrixFreeShallow (vstack->u.matrix); + break; + case FcVStackRange: + case FcVStackBool: + break; + case FcVStackCharSet: + FcCharSetDestroy (vstack->u.charset); + break; + case FcVStackLangSet: + FcLangSetDestroy (vstack->u.langset); + break; + case FcVStackTest: + FcTestDestroy (vstack->u.test); + break; + case FcVStackExpr: + case FcVStackPrefer: + case FcVStackAccept: + case FcVStackDefault: + FcExprDestroy (vstack->u.expr); + break; + case FcVStackEdit: + FcEditDestroy (vstack->u.edit); + break; + } + + if (vstack == &parse->vstack_static[parse->vstack_static_used - 1]) + parse->vstack_static_used--; + else + free (vstack); +} + +static void +FcVStackClear (FcConfigParse *parse) +{ + while (FcVStackPeek (parse)) + FcVStackPopAndDestroy (parse); +} + +static int +FcVStackElements (FcConfigParse *parse) +{ + int h = 0; + FcVStack *vstack = parse->vstack; + while (vstack && vstack->pstack == parse->pstack) + { + h++; + vstack = vstack->prev; + } + return h; +} + +static FcChar8 ** +FcConfigSaveAttr (const XML_Char **attr, FcChar8 **buf, int size_bytes) +{ + int slen; + int i; + FcChar8 **new; + FcChar8 *s; + + if (!attr) + return 0; + slen = 0; + for (i = 0; attr[i]; i++) + slen += strlen ((char *) attr[i]) + 1; + if (i == 0) + return 0; + slen += (i + 1) * sizeof (FcChar8 *); + if (slen <= size_bytes) + new = buf; + else + { + new = malloc (slen); + if (!new) + { + FcConfigMessage (0, FcSevereError, "out of memory"); + return 0; + } + } + s = (FcChar8 *) (new + (i + 1)); + for (i = 0; attr[i]; i++) + { + new[i] = s; + strcpy ((char *) s, (char *) attr[i]); + s += strlen ((char *) s) + 1; + } + new[i] = 0; + return new; +} + +static FcBool +FcPStackPush (FcConfigParse *parse, FcElement element, const XML_Char **attr) +{ + FcPStack *new; + + if (parse->pstack_static_used < sizeof (parse->pstack_static) / sizeof (parse->pstack_static[0])) + new = &parse->pstack_static[parse->pstack_static_used++]; + else + { + new = malloc (sizeof (FcPStack)); + if (!new) + return FcFalse; + } + + new->prev = parse->pstack; + new->element = element; + new->attr = FcConfigSaveAttr (attr, new->attr_buf_static, sizeof (new->attr_buf_static)); + FcStrBufInit (&new->str, 0, 0); + parse->pstack = new; + return FcTrue; +} + +static FcBool +FcPStackPop (FcConfigParse *parse) +{ + FcPStack *old; + + if (!parse->pstack) + { + FcConfigMessage (parse, FcSevereError, "mismatching element"); + return FcFalse; + } + + if (parse->pstack->attr) + { + /* Warn about unused attrs. */ + FcChar8 **attrs = parse->pstack->attr; + while (*attrs) + { + if (attrs[0][0]) + { + FcConfigMessage (parse, FcSevereError, "invalid attribute '%s'", attrs[0]); + } + attrs += 2; + } + } + + FcVStackClear (parse); + old = parse->pstack; + parse->pstack = old->prev; + FcStrBufDestroy (&old->str); + + if (old->attr && old->attr != old->attr_buf_static) + free (old->attr); + + if (old == &parse->pstack_static[parse->pstack_static_used - 1]) + parse->pstack_static_used--; + else + free (old); + return FcTrue; +} + +static FcBool +FcConfigParseInit (FcConfigParse *parse, const FcChar8 *name, FcConfig *config, XML_Parser parser) +{ + parse->pstack = 0; + parse->pstack_static_used = 0; + parse->vstack = 0; + parse->vstack_static_used = 0; + parse->error = FcFalse; + parse->name = name; + parse->config = config; + parse->parser = parser; + return FcTrue; +} + +static void +FcConfigCleanup (FcConfigParse *parse) +{ + while (parse->pstack) + FcPStackPop (parse); +} + +static const FcChar8 * +FcConfigGetAttribute (FcConfigParse *parse, const char *attr) +{ + FcChar8 **attrs; + if (!parse->pstack) + return 0; + + attrs = parse->pstack->attr; + if (!attrs) + return 0; + + while (*attrs) + { + if (!strcmp ((char *) *attrs, attr)) + { + attrs[0][0] = '\0'; /* Mark as used. */ + return attrs[1]; + } + attrs += 2; + } + return 0; +} + +static void +FcStartElement(void *userData, const XML_Char *name, const XML_Char **attr) +{ + FcConfigParse *parse = userData; + FcElement element; + + element = FcElementMap (name); + if (element == FcElementUnknown) + FcConfigMessage (parse, FcSevereWarning, "unknown element \"%s\"", name); + + if (!FcPStackPush (parse, element, attr)) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + return; +} + +static void +FcParseBlank (FcConfigParse *parse) +{ + int n = FcVStackElements (parse); + FcChar32 i; + while (n-- > 0) + { + FcVStack *v = FcVStackFetch (parse, n); + if (!parse->config->blanks) + { + parse->config->blanks = FcBlanksCreate (); + if (!parse->config->blanks) + goto bail; + } + switch ((int) v->tag) { + case FcVStackInteger: + if (!FcBlanksAdd (parse->config->blanks, v->u.integer)) + goto bail; + break; + case FcVStackRange: + if (v->u.range.begin <= v->u.range.end) + { + for (i = v->u.range.begin; i <= v->u.range.end; i++) + { + if (!FcBlanksAdd (parse->config->blanks, i)) + goto bail; + } + } + break; + default: + FcConfigMessage (parse, FcSevereError, "invalid element in blank"); + break; + } + } + return; + bail: + FcConfigMessage (parse, FcSevereError, "out of memory"); +} + +static void +FcParseRescan (FcConfigParse *parse) +{ + int n = FcVStackElements (parse); + while (n-- > 0) + { + FcVStack *v = FcVStackFetch (parse, n); + if (v->tag != FcVStackInteger) + FcConfigMessage (parse, FcSevereWarning, "non-integer rescan"); + else + parse->config->rescanInterval = v->u.integer; + } +} + +static void +FcParseInt (FcConfigParse *parse) +{ + FcChar8 *s, *end; + int l; + + if (!parse->pstack) + return; + s = FcStrBufDoneStatic (&parse->pstack->str); + if (!s) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + end = 0; + l = (int) strtol ((char *) s, (char **)&end, 0); + if (end != s + strlen ((char *) s)) + FcConfigMessage (parse, FcSevereError, "\"%s\": not a valid integer", s); + else + FcVStackPushInteger (parse, l); + FcStrBufDestroy (&parse->pstack->str); +} + +/* + * idea copied from glib g_ascii_strtod with + * permission of the author (Alexander Larsson) + */ + +#include + +static double +FcStrtod (char *s, char **end) +{ + /*struct lconv *locale_data;*/ + /*char *dot;*/ + double v; + + /* + * Have to swap the decimal point to match the current locale + * if that locale doesn't use 0x2e + */ + /*if ((dot = strchr (s, 0x2e)) &&*/ + /*(locale_data = localeconv ()) &&*/ + /*(locale_data->decimal_point[0] != 0x2e ||*/ + /*locale_data->decimal_point[1] != 0))*/ + /*{*/ + /*char buf[128];*/ + /*int slen = strlen (s);*/ + /*int dlen = strlen (locale_data->decimal_point);*/ + + /*if (slen + dlen > (int) sizeof (buf))*/ + /*{*/ + /*if (end)*/ + /**end = s;*/ + /*v = 0;*/ + /*}*/ + /*else*/ + /*{*/ + /*char *buf_end;*/ + /*[> mantissa <]*/ + /*strncpy (buf, s, dot - s);*/ + /*[> decimal point <]*/ + /*strcpy (buf + (dot - s), locale_data->decimal_point);*/ + /*[> rest of number <]*/ + /*strcpy (buf + (dot - s) + dlen, dot + 1);*/ + /*buf_end = 0;*/ + /*v = strtod (buf, &buf_end);*/ + /*if (buf_end) {*/ + /*buf_end = s + (buf_end - buf);*/ + /*if (buf_end > dot)*/ + /*buf_end -= dlen - 1;*/ + /*}*/ + /*if (end)*/ + /**end = buf_end;*/ + /*}*/ + /*}*/ + /*else*/ + v = strtod (s, end); + return v; +} + +static void +FcParseDouble (FcConfigParse *parse) +{ + FcChar8 *s, *end; + double d; + + if (!parse->pstack) + return; + s = FcStrBufDoneStatic (&parse->pstack->str); + if (!s) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + end = 0; + d = FcStrtod ((char *) s, (char **)&end); + if (end != s + strlen ((char *) s)) + FcConfigMessage (parse, FcSevereError, "\"%s\": not a valid double", s); + else + FcVStackPushDouble (parse, d); + FcStrBufDestroy (&parse->pstack->str); +} + +static void +FcParseString (FcConfigParse *parse, FcVStackTag tag) +{ + FcChar8 *s; + + if (!parse->pstack) + return; + s = FcStrBufDone (&parse->pstack->str); + if (!s) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + if (!FcVStackPushString (parse, tag, s)) + FcStrFree (s); +} + +static void +FcParseName (FcConfigParse *parse) +{ + const FcChar8 *kind_string; + FcMatchKind kind; + FcChar8 *s; + FcObject object; + + kind_string = FcConfigGetAttribute (parse, "target"); + if (!kind_string) + kind = FcMatchDefault; + else + { + if (!strcmp ((char *) kind_string, "pattern")) + kind = FcMatchPattern; + else if (!strcmp ((char *) kind_string, "font")) + kind = FcMatchFont; + else if (!strcmp ((char *) kind_string, "default")) + kind = FcMatchDefault; + else + { + FcConfigMessage (parse, FcSevereWarning, "invalid name target \"%s\"", kind_string); + return; + } + } + + if (!parse->pstack) + return; + s = FcStrBufDone (&parse->pstack->str); + if (!s) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + object = FcObjectFromName ((const char *) s); + + FcVStackPushName (parse, kind, object); + + FcStrFree (s); +} + +static void +FcParseMatrix (FcConfigParse *parse) +{ + FcExprMatrix m; + + m.yy = FcPopExpr (parse); + m.yx = FcPopExpr (parse); + m.xy = FcPopExpr (parse); + m.xx = FcPopExpr (parse); + + if (FcPopExpr (parse)) + FcConfigMessage (parse, FcSevereError, "wrong number of matrix elements"); + else + FcVStackPushMatrix (parse, &m); +} + +static void +FcParseRange (FcConfigParse *parse) +{ + FcVStack *vstack; + FcRange r = {0, 0}; + FcChar32 n; + int count = 1; + + while ((vstack = FcVStackPeek (parse))) + { + if (count < 0) + { + FcConfigMessage (parse, FcSevereError, "too many elements in range"); + return; + } + switch ((int) vstack->tag) { + case FcVStackInteger: + n = vstack->u.integer; + break; + default: + FcConfigMessage (parse, FcSevereError, "invalid element in range"); + n = 0; + break; + } + if (count == 1) + r.end = n; + else + r.begin = n; + count--; + FcVStackPopAndDestroy (parse); + } + if (count < 0) + { + if (r.begin > r.end) + { + FcConfigMessage (parse, FcSevereError, "invalid range"); + return; + } + FcVStackPushRange (parse, &r); + } + else + FcConfigMessage (parse, FcSevereError, "invalid range"); +} + +static FcBool +FcConfigLexBool (FcConfigParse *parse, const FcChar8 *bool_) +{ + FcBool result = FcFalse; + + if (!FcNameBool (bool_, &result)) + FcConfigMessage (parse, FcSevereWarning, "\"%s\" is not known boolean", + bool_); + return result; +} + +static void +FcParseBool (FcConfigParse *parse) +{ + FcChar8 *s; + + if (!parse->pstack) + return; + s = FcStrBufDoneStatic (&parse->pstack->str); + if (!s) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + FcVStackPushBool (parse, FcConfigLexBool (parse, s)); + FcStrBufDestroy (&parse->pstack->str); +} + +static void +FcParseCharSet (FcConfigParse *parse) +{ + FcVStack *vstack; + FcCharSet *charset = FcCharSetCreate (); + FcChar32 i; + int n = 0; + + while ((vstack = FcVStackPeek (parse))) + { + switch ((int) vstack->tag) { + case FcVStackInteger: + if (!FcCharSetAddChar (charset, vstack->u.integer)) + { + FcConfigMessage (parse, FcSevereWarning, "invalid character: 0x%04x", vstack->u.integer); + } + else + n++; + break; + case FcVStackRange: + if (vstack->u.range.begin <= vstack->u.range.end) + { + for (i = vstack->u.range.begin; i <= vstack->u.range.end; i++) + { + if (!FcCharSetAddChar (charset, i)) + { + FcConfigMessage (parse, FcSevereWarning, "invalid character: 0x%04x", i); + } + else + n++; + } + } + break; + default: + FcConfigMessage (parse, FcSevereError, "invalid element in charset"); + break; + } + FcVStackPopAndDestroy (parse); + } + if (n > 0) + FcVStackPushCharSet (parse, charset); + else + FcCharSetDestroy (charset); +} + +static void +FcParseLangSet (FcConfigParse *parse) +{ + FcVStack *vstack; + FcLangSet *langset = FcLangSetCreate (); + int n = 0; + + while ((vstack = FcVStackPeek (parse))) + { + switch ((int) vstack->tag) { + case FcVStackString: + if (!FcLangSetAdd (langset, vstack->u.string)) + { + FcConfigMessage (parse, FcSevereWarning, "invalid langset: %s", vstack->u.string); + } + else + n++; + break; + default: + FcConfigMessage (parse, FcSevereError, "invalid element in langset"); + break; + } + FcVStackPopAndDestroy (parse); + } + if (n > 0) + FcVStackPushLangSet (parse, langset); + else + FcLangSetDestroy (langset); +} + +static FcBool +FcConfigLexBinding (FcConfigParse *parse, + const FcChar8 *binding_string, + FcValueBinding *binding_ret) +{ + FcValueBinding binding; + + if (!binding_string) + binding = FcValueBindingWeak; + else + { + if (!strcmp ((char *) binding_string, "weak")) + binding = FcValueBindingWeak; + else if (!strcmp ((char *) binding_string, "strong")) + binding = FcValueBindingStrong; + else if (!strcmp ((char *) binding_string, "same")) + binding = FcValueBindingSame; + else + { + FcConfigMessage (parse, FcSevereWarning, "invalid binding \"%s\"", binding_string); + return FcFalse; + } + } + *binding_ret = binding; + return FcTrue; +} + +static void +FcParseFamilies (FcConfigParse *parse, FcVStackTag tag) +{ + FcVStack *vstack; + FcExpr *left, *expr = 0, *new; + + while ((vstack = FcVStackPeek (parse))) + { + if (vstack->tag != FcVStackFamily) + { + FcConfigMessage (parse, FcSevereWarning, "non-family"); + FcVStackPopAndDestroy (parse); + continue; + } + left = vstack->u.expr; + vstack->tag = FcVStackNone; + FcVStackPopAndDestroy (parse); + if (expr) + { + new = FcExprCreateOp (parse->config, left, FcOpComma, expr); + if (!new) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + FcExprDestroy (left); + FcExprDestroy (expr); + break; + } + expr = new; + } + else + expr = left; + } + if (expr) + { + if (!FcVStackPushExpr (parse, tag, expr)) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + FcExprDestroy (expr); + } + } +} + +static void +FcParseFamily (FcConfigParse *parse) +{ + FcChar8 *s; + FcExpr *expr; + + if (!parse->pstack) + return; + s = FcStrBufDoneStatic (&parse->pstack->str); + if (!s) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + expr = FcExprCreateString (parse->config, s); + FcStrBufDestroy (&parse->pstack->str); + if (expr) + FcVStackPushExpr (parse, FcVStackFamily, expr); +} + +static void +FcParseAlias (FcConfigParse *parse) +{ + FcExpr *family = 0, *accept = 0, *prefer = 0, *def = 0, *new = 0; + FcEdit *edit = 0; + FcVStack *vstack; + FcRule *rule = NULL, *r; + FcValueBinding binding; + + if (!FcConfigLexBinding (parse, FcConfigGetAttribute (parse, "binding"), &binding)) + return; + while ((vstack = FcVStackPeek (parse))) + { + switch ((int) vstack->tag) { + case FcVStackFamily: + if (family) + { + FcConfigMessage (parse, FcSevereWarning, "Having multiple in isn't supported and may not work as expected"); + new = FcExprCreateOp (parse->config, vstack->u.expr, FcOpComma, family); + if (!new) + FcConfigMessage (parse, FcSevereError, "out of memory"); + else + family = new; + } + else + new = vstack->u.expr; + if (new) + { + family = new; + vstack->tag = FcVStackNone; + } + break; + case FcVStackPrefer: + if (prefer) + FcExprDestroy (prefer); + prefer = vstack->u.expr; + vstack->tag = FcVStackNone; + break; + case FcVStackAccept: + if (accept) + FcExprDestroy (accept); + accept = vstack->u.expr; + vstack->tag = FcVStackNone; + break; + case FcVStackDefault: + if (def) + FcExprDestroy (def); + def = vstack->u.expr; + vstack->tag = FcVStackNone; + break; + case FcVStackTest: + if (rule) + { + r = FcRuleCreate (FcRuleTest, vstack->u.test); + r->next = rule; + rule = r; + } + else + rule = FcRuleCreate (FcRuleTest, vstack->u.test); + vstack->tag = FcVStackNone; + break; + default: + FcConfigMessage (parse, FcSevereWarning, "bad alias"); + break; + } + FcVStackPopAndDestroy (parse); + } + if (!family) + { + FcConfigMessage (parse, FcSevereError, "missing family in alias"); + if (prefer) + FcExprDestroy (prefer); + if (accept) + FcExprDestroy (accept); + if (def) + FcExprDestroy (def); + if (rule) + FcRuleDestroy (rule); + return; + } + if (!prefer && + !accept && + !def) + { + FcExprDestroy (family); + return; + } + else + { + FcTest *t = FcTestCreate (parse, FcMatchPattern, + FcQualAny, + (FcChar8 *) FC_FAMILY, + FC_OP (FcOpEqual, FcOpFlagIgnoreBlanks), + family); + if (rule) + { + for (r = rule; r->next; r = r->next); + r->next = FcRuleCreate (FcRuleTest, t); + r = r->next; + } + else + { + r = rule = FcRuleCreate (FcRuleTest, t); + } + } + if (prefer) + { + edit = FcEditCreate (parse, + FC_FAMILY_OBJECT, + FcOpPrepend, + prefer, + binding); + if (!edit) + FcExprDestroy (prefer); + else + { + r->next = FcRuleCreate (FcRuleEdit, edit); + r = r->next; + } + } + if (accept) + { + edit = FcEditCreate (parse, + FC_FAMILY_OBJECT, + FcOpAppend, + accept, + binding); + if (!edit) + FcExprDestroy (accept); + else + { + r->next = FcRuleCreate (FcRuleEdit, edit); + r = r->next; + } + } + if (def) + { + edit = FcEditCreate (parse, + FC_FAMILY_OBJECT, + FcOpAppendLast, + def, + binding); + if (!edit) + FcExprDestroy (def); + else + { + r->next = FcRuleCreate (FcRuleEdit, edit); + r = r->next; + } + } + if (!FcConfigAddRule (parse->config, rule, FcMatchPattern)) + FcRuleDestroy (rule); +} + +static FcExpr * +FcPopExpr (FcConfigParse *parse) +{ + FcVStack *vstack = FcVStackPeek (parse); + FcExpr *expr = 0; + if (!vstack) + return 0; + switch ((int) vstack->tag) { + case FcVStackNone: + break; + case FcVStackString: + case FcVStackFamily: + expr = FcExprCreateString (parse->config, vstack->u.string); + break; + case FcVStackName: + expr = FcExprCreateName (parse->config, vstack->u.name); + break; + case FcVStackConstant: + expr = FcExprCreateConst (parse->config, vstack->u.string); + break; + case FcVStackGlob: + /* XXX: What's the correct action here? (CDW) */ + break; + case FcVStackPrefer: + case FcVStackAccept: + case FcVStackDefault: + expr = vstack->u.expr; + vstack->tag = FcVStackNone; + break; + case FcVStackInteger: + expr = FcExprCreateInteger (parse->config, vstack->u.integer); + break; + case FcVStackDouble: + expr = FcExprCreateDouble (parse->config, vstack->u._double); + break; + case FcVStackMatrix: + expr = FcExprCreateMatrix (parse->config, vstack->u.matrix); + break; + case FcVStackRange: + break; + case FcVStackBool: + expr = FcExprCreateBool (parse->config, vstack->u.bool_); + break; + case FcVStackCharSet: + expr = FcExprCreateCharSet (parse->config, vstack->u.charset); + break; + case FcVStackLangSet: + expr = FcExprCreateLangSet (parse->config, vstack->u.langset); + break; + case FcVStackTest: + break; + case FcVStackExpr: + expr = vstack->u.expr; + vstack->tag = FcVStackNone; + break; + case FcVStackEdit: + break; + default: + break; + } + FcVStackPopAndDestroy (parse); + return expr; +} + +/* + * This builds a tree of binary operations. Note + * that every operator is defined so that if only + * a single operand is contained, the value of the + * whole expression is the value of the operand. + * + * This code reduces in that case to returning that + * operand. + */ +static FcExpr * +FcPopBinary (FcConfigParse *parse, FcOp op) +{ + FcExpr *left, *expr = 0, *new; + + while ((left = FcPopExpr (parse))) + { + if (expr) + { + new = FcExprCreateOp (parse->config, left, op, expr); + if (!new) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + FcExprDestroy (left); + FcExprDestroy (expr); + return 0; + } + expr = new; + } + else + expr = left; + } + return expr; +} + +static void +FcParseBinary (FcConfigParse *parse, FcOp op) +{ + FcExpr *expr = FcPopBinary (parse, op); + if (expr) + FcVStackPushExpr (parse, FcVStackExpr, expr); +} + +/* + * This builds a a unary operator, it consumes only + * a single operand + */ + +static FcExpr * +FcPopUnary (FcConfigParse *parse, FcOp op) +{ + FcExpr *operand, *new = 0; + + if ((operand = FcPopExpr (parse))) + { + new = FcExprCreateOp (parse->config, operand, op, 0); + if (!new) + { + FcExprDestroy (operand); + FcConfigMessage (parse, FcSevereError, "out of memory"); + } + } + return new; +} + +static void +FcParseUnary (FcConfigParse *parse, FcOp op) +{ + FcExpr *expr = FcPopUnary (parse, op); + if (expr) + FcVStackPushExpr (parse, FcVStackExpr, expr); +} + +static void +FcParseDir (FcConfigParse *parse) +{ + const FcChar8 *attr, *data; + FcChar8 *prefix = NULL, *p; +#ifdef _WIN32 + FcChar8 buffer[1000]; +#endif + + attr = FcConfigGetAttribute (parse, "prefix"); + if (attr && FcStrCmp (attr, (const FcChar8 *)"xdg") == 0) + prefix = FcConfigXdgDataHome (); + data = FcStrBufDoneStatic (&parse->pstack->str); + if (!data) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + data = prefix; + goto bail; + } + if (prefix) + { + size_t plen = strlen ((const char *)prefix); + size_t dlen = strlen ((const char *)data); + + p = realloc (prefix, plen + 1 + dlen + 1); + if (!p) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + goto bail; + } + prefix = p; + prefix[plen] = FC_DIR_SEPARATOR; + memcpy (&prefix[plen + 1], data, dlen); + prefix[plen + 1 + dlen] = 0; + data = prefix; + } +#ifdef _WIN32 + if (strcmp ((const char *) data, "CUSTOMFONTDIR") == 0) + { + FcChar8 *p; + data = buffer; + if (!GetModuleFileName (NULL, (LPCH) buffer, sizeof (buffer) - 20)) + { + FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed"); + goto bail; + } + /* + * Must use the multi-byte aware function to search + * for backslash because East Asian double-byte code + * pages have characters with backslash as the second + * byte. + */ + p = _mbsrchr (data, '\\'); + if (p) *p = '\0'; + strcat ((char *) data, "\\fonts"); + } + else if (strcmp ((const char *) data, "APPSHAREFONTDIR") == 0) + { + FcChar8 *p; + data = buffer; + if (!GetModuleFileName (NULL, (LPCH) buffer, sizeof (buffer) - 20)) + { + FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed"); + goto bail; + } + p = _mbsrchr (data, '\\'); + if (p) *p = '\0'; + strcat ((char *) data, "\\..\\share\\fonts"); + } + else if (strcmp ((const char *) data, "WINDOWSFONTDIR") == 0) + { + int rc; + data = buffer; + rc = pGetSystemWindowsDirectory ((LPSTR) buffer, sizeof (buffer) - 20); + if (rc == 0 || rc > sizeof (buffer) - 20) + { + FcConfigMessage (parse, FcSevereError, "GetSystemWindowsDirectory failed"); + goto bail; + } + if (data [strlen ((const char *) data) - 1] != '\\') + strcat ((char *) data, "\\"); + strcat ((char *) data, "fonts"); + } +#endif + if (strlen ((char *) data) == 0) + FcConfigMessage (parse, FcSevereWarning, "empty font directory name ignored"); + else if (!FcStrUsesHome (data) || FcConfigHome ()) + { + if (!FcConfigAddDir (parse->config, data)) + FcConfigMessage (parse, FcSevereError, "out of memory; cannot add directory %s", data); + } + FcStrBufDestroy (&parse->pstack->str); + + bail: + if (prefix) + FcStrFree (prefix); +} + +static void +FcParseCacheDir (FcConfigParse *parse) +{ + const FcChar8 *attr; + FcChar8 *prefix = NULL, *p, *data; + + attr = FcConfigGetAttribute (parse, "prefix"); + if (attr && FcStrCmp (attr, (const FcChar8 *)"xdg") == 0) + prefix = FcConfigXdgCacheHome (); + data = FcStrBufDone (&parse->pstack->str); + if (!data) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + goto bail; + } + if (prefix) + { + size_t plen = strlen ((const char *)prefix); + size_t dlen = strlen ((const char *)data); + + p = realloc (prefix, plen + 1 + dlen + 1); + if (!p) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + data = prefix; + goto bail; + } + prefix = p; + prefix[plen] = FC_DIR_SEPARATOR; + memcpy (&prefix[plen + 1], data, dlen); + prefix[plen + 1 + dlen] = 0; + FcStrFree (data); + data = prefix; + } +#ifdef _WIN32 + if (strcmp ((const char *) data, "WINDOWSTEMPDIR_FONTCONFIG_CACHE") == 0) + { + int rc; + FcStrFree (data); + data = malloc (1000); + if (!data) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + goto bail; + } + rc = GetTempPath (800, (LPSTR) data); + if (rc == 0 || rc > 800) + { + FcConfigMessage (parse, FcSevereError, "GetTempPath failed"); + goto bail; + } + if (data [strlen ((const char *) data) - 1] != '\\') + strcat ((char *) data, "\\"); + strcat ((char *) data, "fontconfig\\cache"); + } + else if (strcmp ((const char *) data, "LOCAL_APPDATA_FONTCONFIG_CACHE") == 0) + { + char szFPath[MAX_PATH + 1]; + size_t len; + + if (!(pSHGetFolderPathA && SUCCEEDED(pSHGetFolderPathA(NULL, /* CSIDL_LOCAL_APPDATA */ 28, NULL, 0, szFPath)))) + { + FcConfigMessage (parse, FcSevereError, "SHGetFolderPathA failed"); + goto bail; + } + strncat(szFPath, "\\fontconfig\\cache", MAX_PATH - 1 - strlen(szFPath)); + len = strlen(szFPath) + 1; + FcStrFree (data); + data = malloc(len); + if (!data) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + goto bail; + } + strncpy((char *) data, szFPath, len); + } +#endif + if (strlen ((char *) data) == 0) + FcConfigMessage (parse, FcSevereWarning, "empty cache directory name ignored"); + else if (!FcStrUsesHome (data) || FcConfigHome ()) + { + if (!FcConfigAddCacheDir (parse->config, data)) + FcConfigMessage (parse, FcSevereError, "out of memory; cannot add cache directory %s", data); + } + FcStrBufDestroy (&parse->pstack->str); + + bail: + if (data) + FcStrFree (data); +} + +static void +FcParseInclude (FcConfigParse *parse) +{ + FcChar8 *s; + const FcChar8 *attr; + FcBool ignore_missing = FcFalse; + FcBool deprecated = FcFalse; + FcChar8 *prefix = NULL, *p; + static FcChar8 *userdir = NULL; + static FcChar8 *userconf = NULL; + + s = FcStrBufDoneStatic (&parse->pstack->str); + if (!s) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + goto bail; + } + attr = FcConfigGetAttribute (parse, "ignore_missing"); + if (attr && FcConfigLexBool (parse, (FcChar8 *) attr) == FcTrue) + ignore_missing = FcTrue; + attr = FcConfigGetAttribute (parse, "deprecated"); + if (attr && FcConfigLexBool (parse, (FcChar8 *) attr) == FcTrue) + deprecated = FcTrue; + attr = FcConfigGetAttribute (parse, "prefix"); + if (attr && FcStrCmp (attr, (const FcChar8 *)"xdg") == 0) + prefix = FcConfigXdgConfigHome (); + if (prefix) + { + size_t plen = strlen ((const char *)prefix); + size_t dlen = strlen ((const char *)s); + + p = realloc (prefix, plen + 1 + dlen + 1); + if (!p) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + goto bail; + } + prefix = p; + prefix[plen] = FC_DIR_SEPARATOR; + memcpy (&prefix[plen + 1], s, dlen); + prefix[plen + 1 + dlen] = 0; + s = prefix; + if (FcFileIsDir (s)) + { + userdir: + if (!userdir) + userdir = FcStrdup (s); + } + else if (FcFileIsFile (s)) + { + userconf: + if (!userconf) + userconf = FcStrdup (s); + } + else + { + /* No config dir nor file on the XDG directory spec compliant place + * so need to guess what it is supposed to be. + */ + if (FcStrStr (s, (const FcChar8 *)"conf.d") != NULL) + goto userdir; + else + goto userconf; + } + } + if (!FcConfigParseAndLoad (parse->config, s, !ignore_missing)) + parse->error = FcTrue; +#ifndef _WIN32 + else + { + FcChar8 *filename; + static FcBool warn_conf = FcFalse, warn_confd = FcFalse; + + filename = FcConfigFilename(s); + if (deprecated == FcTrue && + filename != NULL && + !FcFileIsLink (filename)) + { + if (FcFileIsDir (filename)) + { + FcChar8 *parent = FcStrDirname (userdir); + + if (!FcFileIsDir (parent)) + FcMakeDirectory (parent); + FcStrFree (parent); + if (FcFileIsDir (userdir) || + rename ((const char *)filename, (const char *)userdir) != 0 || + symlink ((const char *)userdir, (const char *)filename) != 0) + { + if (!warn_confd) + { + FcConfigMessage (parse, FcSevereWarning, "reading configurations from %s is deprecated. please move it to %s manually", s, userdir); + warn_confd = FcTrue; + } + } + } + else + { + FcChar8 *parent = FcStrDirname (userconf); + + if (!FcFileIsDir (parent)) + FcMakeDirectory (parent); + FcStrFree (parent); + if (FcFileIsFile (userconf) || + rename ((const char *)filename, (const char *)userconf) != 0 || + symlink ((const char *)userconf, (const char *)filename) != 0) + { + if (!warn_conf) + { + FcConfigMessage (parse, FcSevereWarning, "reading configurations from %s is deprecated. please move it to %s manually", s, userconf); + warn_conf = FcTrue; + } + } + } + } + if(filename) + FcStrFree(filename); + } +#endif + FcStrBufDestroy (&parse->pstack->str); + + bail: + if (prefix) + FcStrFree (prefix); +} + +typedef struct _FcOpMap { + char name[16]; + FcOp op; +} FcOpMap; + +static FcOp +FcConfigLexOp (const FcChar8 *op, const FcOpMap *map, int nmap) +{ + int i; + + for (i = 0; i < nmap; i++) + if (!strcmp ((char *) op, map[i].name)) + return map[i].op; + return FcOpInvalid; +} + +static const FcOpMap fcCompareOps[] = { + { "eq", FcOpEqual }, + { "not_eq", FcOpNotEqual }, + { "less", FcOpLess }, + { "less_eq", FcOpLessEqual }, + { "more", FcOpMore }, + { "more_eq", FcOpMoreEqual }, + { "contains", FcOpContains }, + { "not_contains", FcOpNotContains } +}; + +#define NUM_COMPARE_OPS (int) (sizeof fcCompareOps / sizeof fcCompareOps[0]) + +static FcOp +FcConfigLexCompare (const FcChar8 *compare) +{ + return FcConfigLexOp (compare, fcCompareOps, NUM_COMPARE_OPS); +} + +static void +FcParseTest (FcConfigParse *parse) +{ + const FcChar8 *kind_string; + FcMatchKind kind; + const FcChar8 *qual_string; + FcQual qual; + const FcChar8 *name; + const FcChar8 *compare_string; + FcOp compare; + FcExpr *expr; + FcTest *test; + const FcChar8 *iblanks_string; + int flags = 0; + + kind_string = FcConfigGetAttribute (parse, "target"); + if (!kind_string) + kind = FcMatchDefault; + else + { + if (!strcmp ((char *) kind_string, "pattern")) + kind = FcMatchPattern; + else if (!strcmp ((char *) kind_string, "font")) + kind = FcMatchFont; + else if (!strcmp ((char *) kind_string, "scan")) + kind = FcMatchScan; + else if (!strcmp ((char *) kind_string, "default")) + kind = FcMatchDefault; + else + { + FcConfigMessage (parse, FcSevereWarning, "invalid test target \"%s\"", kind_string); + return; + } + } + qual_string = FcConfigGetAttribute (parse, "qual"); + if (!qual_string) + qual = FcQualAny; + else + { + if (!strcmp ((char *) qual_string, "any")) + qual = FcQualAny; + else if (!strcmp ((char *) qual_string, "all")) + qual = FcQualAll; + else if (!strcmp ((char *) qual_string, "first")) + qual = FcQualFirst; + else if (!strcmp ((char *) qual_string, "not_first")) + qual = FcQualNotFirst; + else + { + FcConfigMessage (parse, FcSevereWarning, "invalid test qual \"%s\"", qual_string); + return; + } + } + name = FcConfigGetAttribute (parse, "name"); + if (!name) + { + FcConfigMessage (parse, FcSevereWarning, "missing test name"); + return; + } + compare_string = FcConfigGetAttribute (parse, "compare"); + if (!compare_string) + compare = FcOpEqual; + else + { + compare = FcConfigLexCompare (compare_string); + if (compare == FcOpInvalid) + { + FcConfigMessage (parse, FcSevereWarning, "invalid test compare \"%s\"", compare_string); + return; + } + } + iblanks_string = FcConfigGetAttribute (parse, "ignore-blanks"); + if (iblanks_string) + { + FcBool f = FcFalse; + + if (!FcNameBool (iblanks_string, &f)) + { + FcConfigMessage (parse, + FcSevereWarning, + "invalid test ignore-blanks \"%s\"", iblanks_string); + } + if (f) + flags |= FcOpFlagIgnoreBlanks; + } + expr = FcPopBinary (parse, FcOpComma); + if (!expr) + { + FcConfigMessage (parse, FcSevereWarning, "missing test expression"); + return; + } + if (expr->op == FcOpComma) + { + FcConfigMessage (parse, FcSevereWarning, "Having multiple values in isn't supported and may not work as expected"); + } + test = FcTestCreate (parse, kind, qual, name, FC_OP (compare, flags), expr); + if (!test) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + FcVStackPushTest (parse, test); +} + +static const FcOpMap fcModeOps[] = { + { "assign", FcOpAssign }, + { "assign_replace", FcOpAssignReplace }, + { "prepend", FcOpPrepend }, + { "prepend_first", FcOpPrependFirst }, + { "append", FcOpAppend }, + { "append_last", FcOpAppendLast }, + { "delete", FcOpDelete }, + { "delete_all", FcOpDeleteAll }, +}; + +#define NUM_MODE_OPS (int) (sizeof fcModeOps / sizeof fcModeOps[0]) + +static FcOp +FcConfigLexMode (const FcChar8 *mode) +{ + return FcConfigLexOp (mode, fcModeOps, NUM_MODE_OPS); +} + +static void +FcParseEdit (FcConfigParse *parse) +{ + const FcChar8 *name; + const FcChar8 *mode_string; + FcOp mode; + FcValueBinding binding; + FcExpr *expr; + FcEdit *edit; + + name = FcConfigGetAttribute (parse, "name"); + if (!name) + { + FcConfigMessage (parse, FcSevereWarning, "missing edit name"); + return; + } + mode_string = FcConfigGetAttribute (parse, "mode"); + if (!mode_string) + mode = FcOpAssign; + else + { + mode = FcConfigLexMode (mode_string); + if (mode == FcOpInvalid) + { + FcConfigMessage (parse, FcSevereWarning, "invalid edit mode \"%s\"", mode_string); + return; + } + } + if (!FcConfigLexBinding (parse, FcConfigGetAttribute (parse, "binding"), &binding)) + return; + + expr = FcPopBinary (parse, FcOpComma); + if ((mode == FcOpDelete || mode == FcOpDeleteAll) && + expr != NULL) + { + FcConfigMessage (parse, FcSevereWarning, "Expression doesn't take any effects for delete and delete_all"); + FcExprDestroy (expr); + expr = NULL; + } + edit = FcEditCreate (parse, FcObjectFromName ((char *) name), + mode, expr, binding); + if (!edit) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + FcExprDestroy (expr); + return; + } + if (!FcVStackPushEdit (parse, edit)) + FcEditDestroy (edit); +} + +static void +FcParseMatch (FcConfigParse *parse) +{ + const FcChar8 *kind_name; + FcMatchKind kind; + FcVStack *vstack; + FcRule *rule = NULL, *r; + + kind_name = FcConfigGetAttribute (parse, "target"); + if (!kind_name) + kind = FcMatchPattern; + else + { + if (!strcmp ((char *) kind_name, "pattern")) + kind = FcMatchPattern; + else if (!strcmp ((char *) kind_name, "font")) + kind = FcMatchFont; + else if (!strcmp ((char *) kind_name, "scan")) + kind = FcMatchScan; + else + { + FcConfigMessage (parse, FcSevereWarning, "invalid match target \"%s\"", kind_name); + return; + } + } + while ((vstack = FcVStackPeek (parse))) + { + switch ((int) vstack->tag) { + case FcVStackTest: + r = FcRuleCreate (FcRuleTest, vstack->u.test); + if (rule) + r->next = rule; + rule = r; + vstack->tag = FcVStackNone; + break; + case FcVStackEdit: + if (kind == FcMatchScan && vstack->u.edit->object > FC_MAX_BASE_OBJECT) + { + FcConfigMessage (parse, FcSevereError, + " cannot edit user-defined object \"%s\"", + FcObjectName(vstack->u.edit->object)); + if (rule) + FcRuleDestroy (rule); + return; + } + r = FcRuleCreate (FcRuleEdit, vstack->u.edit); + if (rule) + r->next = rule; + rule = r; + vstack->tag = FcVStackNone; + break; + default: + FcConfigMessage (parse, FcSevereWarning, "invalid match element"); + break; + } + FcVStackPopAndDestroy (parse); + } + if (!rule) + { + FcConfigMessage (parse, FcSevereWarning, "No nor elements in "); + return; + } + if (!FcConfigAddRule (parse->config, rule, kind)) + FcConfigMessage (parse, FcSevereError, "out of memory"); +} + +static void +FcParseAcceptRejectFont (FcConfigParse *parse, FcElement element) +{ + FcVStack *vstack; + + while ((vstack = FcVStackPeek (parse))) + { + switch ((int) vstack->tag) { + case FcVStackGlob: + if (!FcConfigGlobAdd (parse->config, + vstack->u.string, + element == FcElementAcceptfont)) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + } + break; + case FcVStackPattern: + if (!FcConfigPatternsAdd (parse->config, + vstack->u.pattern, + element == FcElementAcceptfont)) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + } + else + vstack->tag = FcVStackNone; + break; + default: + FcConfigMessage (parse, FcSevereWarning, "bad font selector"); + break; + } + FcVStackPopAndDestroy (parse); + } +} + + +static FcValue +FcPopValue (FcConfigParse *parse) +{ + FcVStack *vstack = FcVStackPeek (parse); + FcValue value; + + value.type = FcTypeVoid; + + if (!vstack) + return value; + + switch ((int) vstack->tag) { + case FcVStackString: + value.u.s = FcStrdup (vstack->u.string); + if (value.u.s) + value.type = FcTypeString; + break; + case FcVStackConstant: + if (FcNameConstant (vstack->u.string, &value.u.i)) + value.type = FcTypeInteger; + break; + case FcVStackInteger: + value.u.i = vstack->u.integer; + value.type = FcTypeInteger; + break; + case FcVStackDouble: + value.u.d = vstack->u._double; + value.type = FcTypeDouble; + break; + case FcVStackBool: + value.u.b = vstack->u.bool_; + value.type = FcTypeBool; + break; + case FcVStackCharSet: + value.u.c = FcCharSetCopy (vstack->u.charset); + if (value.u.c) + value.type = FcTypeCharSet; + break; + case FcVStackLangSet: + value.u.l = FcLangSetCopy (vstack->u.langset); + if (value.u.l) + value.type = FcTypeLangSet; + break; + default: + FcConfigMessage (parse, FcSevereWarning, "unknown pattern element %d", + vstack->tag); + break; + } + FcVStackPopAndDestroy (parse); + + return value; +} + +static void +FcParsePatelt (FcConfigParse *parse) +{ + FcValue value; + FcPattern *pattern = FcPatternCreate (); + const char *name; + + if (!pattern) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + + name = (char *) FcConfigGetAttribute (parse, "name"); + if (!name) + { + FcConfigMessage (parse, FcSevereWarning, "missing pattern element name"); + FcPatternDestroy (pattern); + return; + } + + for (;;) + { + value = FcPopValue (parse); + if (value.type == FcTypeVoid) + break; + if (!FcPatternAdd (pattern, name, value, FcTrue)) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + FcValueDestroy(value); + break; + } + FcValueDestroy(value); + } + + FcVStackPushPattern (parse, pattern); +} + +static void +FcParsePattern (FcConfigParse *parse) +{ + FcVStack *vstack; + FcPattern *pattern = FcPatternCreate (); + + if (!pattern) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + return; + } + + while ((vstack = FcVStackPeek (parse))) + { + switch ((int) vstack->tag) { + case FcVStackPattern: + if (!FcPatternAppend (pattern, vstack->u.pattern)) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + FcPatternDestroy (pattern); + return; + } + break; + default: + FcConfigMessage (parse, FcSevereWarning, "unknown pattern element"); + break; + } + FcVStackPopAndDestroy (parse); + } + + FcVStackPushPattern (parse, pattern); +} + +static void +FcEndElement(void *userData, const XML_Char *name FC_UNUSED) +{ + FcConfigParse *parse = userData; + FcChar8 *data; + + if (!parse->pstack) + return; + switch (parse->pstack->element) { + case FcElementNone: + break; + case FcElementFontconfig: + break; + case FcElementDir: + FcParseDir (parse); + break; + case FcElementCacheDir: + FcParseCacheDir (parse); + break; + case FcElementCache: + data = FcStrBufDoneStatic (&parse->pstack->str); + if (!data) + { + FcConfigMessage (parse, FcSevereError, "out of memory"); + break; + } + /* discard this data; no longer used */ + FcStrBufDestroy (&parse->pstack->str); + break; + case FcElementInclude: + FcParseInclude (parse); + break; + case FcElementConfig: + break; + case FcElementMatch: + FcParseMatch (parse); + break; + case FcElementAlias: + FcParseAlias (parse); + break; + + case FcElementBlank: + FcParseBlank (parse); + break; + case FcElementRescan: + FcParseRescan (parse); + break; + + case FcElementPrefer: + FcParseFamilies (parse, FcVStackPrefer); + break; + case FcElementAccept: + FcParseFamilies (parse, FcVStackAccept); + break; + case FcElementDefault: + FcParseFamilies (parse, FcVStackDefault); + break; + case FcElementFamily: + FcParseFamily (parse); + break; + + case FcElementTest: + FcParseTest (parse); + break; + case FcElementEdit: + FcParseEdit (parse); + break; + + case FcElementInt: + FcParseInt (parse); + break; + case FcElementDouble: + FcParseDouble (parse); + break; + case FcElementString: + FcParseString (parse, FcVStackString); + break; + case FcElementMatrix: + FcParseMatrix (parse); + break; + case FcElementRange: + FcParseRange (parse); + break; + case FcElementBool: + FcParseBool (parse); + break; + case FcElementCharSet: + FcParseCharSet (parse); + break; + case FcElementLangSet: + FcParseLangSet (parse); + break; + case FcElementSelectfont: + break; + case FcElementAcceptfont: + case FcElementRejectfont: + FcParseAcceptRejectFont (parse, parse->pstack->element); + break; + case FcElementGlob: + FcParseString (parse, FcVStackGlob); + break; + case FcElementPattern: + FcParsePattern (parse); + break; + case FcElementPatelt: + FcParsePatelt (parse); + break; + case FcElementName: + FcParseName (parse); + break; + case FcElementConst: + FcParseString (parse, FcVStackConstant); + break; + case FcElementOr: + FcParseBinary (parse, FcOpOr); + break; + case FcElementAnd: + FcParseBinary (parse, FcOpAnd); + break; + case FcElementEq: + FcParseBinary (parse, FcOpEqual); + break; + case FcElementNotEq: + FcParseBinary (parse, FcOpNotEqual); + break; + case FcElementLess: + FcParseBinary (parse, FcOpLess); + break; + case FcElementLessEq: + FcParseBinary (parse, FcOpLessEqual); + break; + case FcElementMore: + FcParseBinary (parse, FcOpMore); + break; + case FcElementMoreEq: + FcParseBinary (parse, FcOpMoreEqual); + break; + case FcElementContains: + FcParseBinary (parse, FcOpContains); + break; + case FcElementNotContains: + FcParseBinary (parse, FcOpNotContains); + break; + case FcElementPlus: + FcParseBinary (parse, FcOpPlus); + break; + case FcElementMinus: + FcParseBinary (parse, FcOpMinus); + break; + case FcElementTimes: + FcParseBinary (parse, FcOpTimes); + break; + case FcElementDivide: + FcParseBinary (parse, FcOpDivide); + break; + case FcElementNot: + FcParseUnary (parse, FcOpNot); + break; + case FcElementIf: + FcParseBinary (parse, FcOpQuest); + break; + case FcElementFloor: + FcParseUnary (parse, FcOpFloor); + break; + case FcElementCeil: + FcParseUnary (parse, FcOpCeil); + break; + case FcElementRound: + FcParseUnary (parse, FcOpRound); + break; + case FcElementTrunc: + FcParseUnary (parse, FcOpTrunc); + break; + case FcElementUnknown: + break; + } + (void) FcPStackPop (parse); +} + +static void +FcCharacterData (void *userData, const XML_Char *s, int len) +{ + FcConfigParse *parse = userData; + + if (!parse->pstack) + return; + if (!FcStrBufData (&parse->pstack->str, (FcChar8 *) s, len)) + FcConfigMessage (parse, FcSevereError, "out of memory"); +} + +static void +FcStartDoctypeDecl (void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid FC_UNUSED, + const XML_Char *pubid FC_UNUSED, + int has_internal_subset FC_UNUSED) +{ + FcConfigParse *parse = userData; + + if (strcmp ((char *) doctypeName, "fontconfig") != 0) + FcConfigMessage (parse, FcSevereError, "invalid doctype \"%s\"", doctypeName); +} + +#ifdef ENABLE_LIBXML2 + +static void +FcInternalSubsetDecl (void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid) +{ + FcStartDoctypeDecl (userData, doctypeName, sysid, pubid, 1); +} + +static void +FcExternalSubsetDecl (void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid) +{ + FcStartDoctypeDecl (userData, doctypeName, sysid, pubid, 0); +} + +#else /* ENABLE_LIBXML2 */ + +static void +FcEndDoctypeDecl (void *userData FC_UNUSED) +{ +} + +#endif /* ENABLE_LIBXML2 */ + +static int +FcSortCmpStr (const void *a, const void *b) +{ + const FcChar8 *as = *((FcChar8 **) a); + const FcChar8 *bs = *((FcChar8 **) b); + return FcStrCmp (as, bs); +} + +static FcBool +FcConfigParseAndLoadDir (FcConfig *config, + const FcChar8 *name, + const FcChar8 *dir, + FcBool complain) +{ + DIR *d; + struct dirent *e; + FcBool ret = FcTrue; + FcChar8 *file; + FcChar8 *base; + FcStrSet *files; + + d = opendir ((char *) dir); + if (!d) + { + if (complain) + FcConfigMessage (0, FcSevereError, "Cannot open config dir \"%s\"", + name); + ret = FcFalse; + goto bail0; + } + /* freed below */ + file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1); + if (!file) + { + ret = FcFalse; + goto bail1; + } + + strcpy ((char *) file, (char *) dir); + strcat ((char *) file, "/"); + base = file + strlen ((char *) file); + + files = FcStrSetCreate (); + if (!files) + { + ret = FcFalse; + goto bail2; + } + + if (FcDebug () & FC_DBG_CONFIG) + printf ("\tScanning config dir %s\n", dir); + + while (ret && (e = readdir (d))) + { + int d_len; +#define TAIL ".conf" +#define TAIL_LEN 5 + /* + * Add all files of the form [0-9]*.conf + */ + if ('0' <= e->d_name[0] && e->d_name[0] <= '9' && + (d_len = strlen (e->d_name)) < FC_MAX_FILE_LEN && + d_len > TAIL_LEN && + strcmp (e->d_name + d_len - TAIL_LEN, TAIL) == 0) + { + strcpy ((char *) base, (char *) e->d_name); + if (!FcStrSetAdd (files, file)) + { + ret = FcFalse; + goto bail3; + } + } + } + if (ret) + { + int i; + qsort (files->strs, files->num, sizeof (FcChar8 *), + (int (*)(const void *, const void *)) FcSortCmpStr); + for (i = 0; ret && i < files->num; i++) + ret = FcConfigParseAndLoad (config, files->strs[i], complain); + } +bail3: + FcStrSetDestroy (files); +bail2: + free (file); +bail1: + closedir (d); +bail0: + return ret || !complain; +} + +#ifdef _WIN32 +pfnGetSystemWindowsDirectory pGetSystemWindowsDirectory = NULL; +pfnSHGetFolderPathA pSHGetFolderPathA = NULL; +#endif + +FcBool +FcConfigParseAndLoad (FcConfig *config, + const FcChar8 *name, + FcBool complain) +{ + + XML_Parser p; + FcChar8 *filename; + int fd; + int len; + FcConfigParse parse; + FcBool error = FcTrue; + +#ifdef ENABLE_LIBXML2 + xmlSAXHandler sax; + char buf[BUFSIZ]; +#else + void *buf; +#endif + +#ifdef _WIN32 + if (!pGetSystemWindowsDirectory) + { + HMODULE hk32 = GetModuleHandleA("kernel32.dll"); + if (!(pGetSystemWindowsDirectory = (pfnGetSystemWindowsDirectory) GetProcAddress(hk32, "GetSystemWindowsDirectoryA"))) + pGetSystemWindowsDirectory = (pfnGetSystemWindowsDirectory) GetWindowsDirectory; + } + if (!pSHGetFolderPathA) + { + HMODULE hSh = LoadLibraryA("shfolder.dll"); + /* the check is done later, because there is no provided fallback */ + if (hSh) + pSHGetFolderPathA = (pfnSHGetFolderPathA) GetProcAddress(hSh, "SHGetFolderPathA"); + } +#endif + + filename = FcConfigFilename (name); + if (!filename) + goto bail0; + + if (FcStrSetMember (config->configFiles, filename)) + { + FcStrFree (filename); + return FcTrue; + } + + if (!FcStrSetAdd (config->configFiles, filename)) + { + FcStrFree (filename); + goto bail0; + } + + if (FcFileIsDir (filename)) + { + FcBool ret = FcConfigParseAndLoadDir (config, name, filename, complain); + FcStrFree (filename); + return ret; + } + + if (FcDebug () & FC_DBG_CONFIG) + printf ("\tLoading config file %s\n", filename); + + fd = FcOpen ((char *) filename, O_RDONLY); + if (fd == -1) { + FcStrFree (filename); + goto bail0; + } + +#ifdef ENABLE_LIBXML2 + memset(&sax, 0, sizeof(sax)); + + sax.internalSubset = FcInternalSubsetDecl; + sax.externalSubset = FcExternalSubsetDecl; + sax.startElement = FcStartElement; + sax.endElement = FcEndElement; + sax.characters = FcCharacterData; + + p = xmlCreatePushParserCtxt (&sax, &parse, NULL, 0, (const char *) filename); +#else + p = XML_ParserCreate ("UTF-8"); +#endif + FcStrFree (filename); + + if (!p) + goto bail1; + + if (!FcConfigParseInit (&parse, name, config, p)) + goto bail2; + +#ifndef ENABLE_LIBXML2 + + XML_SetUserData (p, &parse); + + XML_SetDoctypeDeclHandler (p, FcStartDoctypeDecl, FcEndDoctypeDecl); + XML_SetElementHandler (p, FcStartElement, FcEndElement); + XML_SetCharacterDataHandler (p, FcCharacterData); + +#endif /* ENABLE_LIBXML2 */ + + do { +#ifndef ENABLE_LIBXML2 + buf = XML_GetBuffer (p, BUFSIZ); + if (!buf) + { + FcConfigMessage (&parse, FcSevereError, "cannot get parse buffer"); + goto bail3; + } +#endif + len = read (fd, buf, BUFSIZ); + if (len < 0) + { + FcConfigMessage (&parse, FcSevereError, "failed reading config file"); + goto bail3; + } + +#ifdef ENABLE_LIBXML2 + if (xmlParseChunk (p, buf, len, len == 0)) +#else + if (!XML_ParseBuffer (p, len, len == 0)) +#endif + { + FcConfigMessage (&parse, FcSevereError, "%s", + XML_ErrorString (XML_GetErrorCode (p))); + goto bail3; + } + } while (len != 0); + error = parse.error; +bail3: + FcConfigCleanup (&parse); +bail2: + XML_ParserFree (p); +bail1: + close (fd); + fd = -1; +bail0: + if (error && complain) + { + if (name) + FcConfigMessage (0, FcSevereError, "Cannot load config file \"%s\"", name); + else + FcConfigMessage (0, FcSevereError, "Cannot load default config file"); + return FcFalse; + } + return FcTrue; +} +#define __fcxml__ +#include "fcaliastail.h" +#undef __fcxml__ diff --git a/project/jni/fontconfig/src/ftglue.c b/project/jni/fontconfig/src/ftglue.c new file mode 100644 index 000000000..0e02bd2df --- /dev/null +++ b/project/jni/fontconfig/src/ftglue.c @@ -0,0 +1,261 @@ +/* ftglue.c: Glue code for compiling the OpenType code from + * FreeType 1 using only the public API of FreeType 2 + * + * By David Turner, The FreeType Project (www.freetype.org) + * + * This code is explicitely put in the public domain + * + * See ftglue.h for more information. + */ + +#include "ftglue.h" + +#if 0 +#include +#define LOG(x) ftglue_log x + +static void +ftglue_log( const char* format, ... ) +{ + va_list ap; + + va_start( ap, format ); + vfprintf( stderr, format, ap ); + va_end( ap ); +} + +#else +#define LOG(x) do {} while (0) +#endif + +/* only used internally */ +static FT_Pointer +ftglue_qalloc( FT_Memory memory, + FT_ULong size, + FT_Error *perror ) +{ + FT_Error error = 0; + FT_Pointer block = NULL; + + if ( size > 0 ) + { + block = memory->alloc( memory, size ); + if ( !block ) + error = FT_Err_Out_Of_Memory; + } + + *perror = error; + return block; +} + +#undef QALLOC /* just in case */ +#define QALLOC(ptr,size) ( (ptr) = ftglue_qalloc( memory, (size), &error ), error != 0 ) +#define FREE(_ptr) \ + do { \ + if ( (_ptr) ) \ + { \ + ftglue_free( memory, _ptr ); \ + _ptr = NULL; \ + } \ + } while (0) + + +static void +ftglue_free( FT_Memory memory, + FT_Pointer block ) +{ + if ( block ) + memory->free( memory, block ); +} + +FTGLUE_APIDEF( FT_Long ) +ftglue_stream_pos( FT_Stream stream ) +{ + LOG(( "ftglue:stream:pos() -> %ld\n", stream->pos )); + return stream->pos; +} + + +FTGLUE_APIDEF( FT_Error ) +ftglue_stream_seek( FT_Stream stream, + FT_Long pos ) +{ + FT_Error error = 0; + + if ( stream->read ) + { + if ( stream->read( stream, pos, 0, 0 ) ) + error = FT_Err_Invalid_Stream_Operation; + } + else if ( pos < 0 || (FT_ULong) pos > stream->size ) + error = FT_Err_Invalid_Stream_Operation; + + if ( !error ) + stream->pos = pos; + LOG(( "ftglue:stream:seek(%ld) -> %d\n", pos, error )); + return error; +} + + +FTGLUE_APIDEF( FT_Error ) +ftglue_stream_frame_enter( FT_Stream stream, + FT_ULong count ) +{ + FT_Error error = FT_Err_Ok; + FT_ULong read_bytes; + + if ( stream->read ) + { + /* allocate the frame in memory */ + FT_Memory memory = stream->memory; + + + if ( QALLOC( stream->base, count ) ) + goto Exit; + + /* read it */ + read_bytes = stream->read( stream, stream->pos, + stream->base, count ); + if ( read_bytes < count ) + { + FREE( stream->base ); + error = FT_Err_Invalid_Stream_Operation; + } + stream->cursor = stream->base; + stream->limit = stream->cursor + count; + stream->pos += read_bytes; + } + else + { + /* check current and new position */ + if ( stream->pos >= stream->size || + stream->pos + count > stream->size ) + { + error = FT_Err_Invalid_Stream_Operation; + goto Exit; + } + + /* set cursor */ + stream->cursor = stream->base + stream->pos; + stream->limit = stream->cursor + count; + stream->pos += count; + } + +Exit: + LOG(( "ftglue:stream:frame_enter(%ld) -> %d\n", count, error )); + return error; +} + + +FTGLUE_APIDEF( void ) +ftglue_stream_frame_exit( FT_Stream stream ) +{ + if ( stream->read ) + { + FT_Memory memory = stream->memory; + + FREE( stream->base ); + } + stream->cursor = 0; + stream->limit = 0; + + LOG(( "ftglue:stream:frame_exit()\n" )); +} + + +FTGLUE_APIDEF( FT_Error ) +ftglue_face_goto_table( FT_Face face, + FT_ULong the_tag, + FT_Stream stream ) +{ + FT_Error error; + + LOG(( "ftglue_face_goto_table( %p, %c%c%c%c, %p )\n", + face, + (int)((the_tag >> 24) & 0xFF), + (int)((the_tag >> 16) & 0xFF), + (int)((the_tag >> 8) & 0xFF), + (int)(the_tag & 0xFF), + stream )); + + if ( !FT_IS_SFNT(face) ) + { + LOG(( "not a SFNT face !!\n" )); + error = FT_Err_Invalid_Face_Handle; + } + else + { + /* parse the directory table directly, without using + * FreeType's built-in data structures + */ + FT_ULong offset = 0, sig; + FT_UInt count, nn; + + if ( FILE_Seek( 0 ) || ACCESS_Frame( 4 ) ) + goto Exit; + + sig = GET_Tag4(); + + FORGET_Frame(); + + if ( sig == FT_MAKE_TAG( 't', 't', 'c', 'f' ) ) + { + /* deal with TrueType collections */ + + LOG(( ">> This is a TrueType Collection\n" )); + + if ( FILE_Seek( 12 + face->face_index*4 ) || + ACCESS_Frame( 4 ) ) + goto Exit; + + offset = GET_ULong(); + + FORGET_Frame(); + } + + LOG(( "TrueType offset = %ld\n", offset )); + + if ( FILE_Seek( offset+4 ) || + ACCESS_Frame( 2 ) ) + goto Exit; + + count = GET_UShort(); + + FORGET_Frame(); + + if ( FILE_Seek( offset+12 ) || + ACCESS_Frame( count*16 ) ) + goto Exit; + + for ( nn = 0; nn < count; nn++ ) + { + FT_ULong tag = GET_ULong(); + FT_ULong checksum = GET_ULong(); + FT_ULong start = GET_ULong(); + FT_ULong size = GET_ULong(); + + FT_UNUSED(checksum); + FT_UNUSED(size); + + if ( tag == the_tag ) + { + LOG(( "TrueType table (start: %ld) (size: %ld)\n", start, size )); + error = ftglue_stream_seek( stream, start ); + goto FoundIt; + } + } + error = FT_Err_Table_Missing; + + FoundIt: + FORGET_Frame(); + } + +Exit: + LOG(( "TrueType error=%d\n", error )); + + return error; +} + +#undef QALLOC +#include "fcaliastail.h" +#undef __ftglue__ diff --git a/project/jni/fontconfig/src/ftglue.h b/project/jni/fontconfig/src/ftglue.h new file mode 100644 index 000000000..e0fd1714e --- /dev/null +++ b/project/jni/fontconfig/src/ftglue.h @@ -0,0 +1,111 @@ +/* ftglue.c: Glue code for compiling the OpenType code from + * FreeType 1 using only the public API of FreeType 2 + * + * By David Turner, The FreeType Project (www.freetype.org) + * + * This code is explicitely put in the public domain + * + * ========================================================================== + * + * the OpenType parser codes was originally written as an extension to + * FreeType 1.x. As such, its source code was embedded within the library, + * and used many internal FreeType functions to deal with memory and + * stream i/o. + * + * When it was 'salvaged' for Pango and Qt, the code was "ported" to FreeType 2, + * which basically means that some macro tricks were performed in order to + * directly access FT2 _internal_ functions. + * + * these functions were never part of FT2 public API, and _did_ change between + * various releases. This created chaos for many users: when they upgraded the + * FreeType library on their system, they couldn't run Gnome anymore since + * Pango refused to link. + * + * Very fortunately, it's possible to completely avoid this problem because + * the FT_StreamRec and FT_MemoryRec structure types, which describe how + * memory and stream implementations interface with the rest of the font + * library, have always been part of the public API, and never changed. + * + * What we do thus is re-implement, within the OpenType parser, the few + * functions that depend on them. This only adds one or two kilobytes of + * code, and ensures that the parser can work with _any_ version + * of FreeType installed on your system. How sweet... ! + * + * Note that we assume that Pango doesn't use any other internal functions + * from FreeType. It used to in old versions, but this should no longer + * be the case. (crossing my fingers). + * + * - David Turner + * - The FreeType Project (www.freetype.org) + * + * PS: This "glue" code is explicitely put in the public domain + */ +#ifndef __OPENTYPE_FTGLUE_H__ +#define __OPENTYPE_FTGLUE_H__ + +#include "fcint.h" + +#include +#include FT_FREETYPE_H + +FT_BEGIN_HEADER + + +#define SET_ERR(c) ( (error = (c)) != 0 ) + +#ifndef FTGLUE_API +#define FTGLUE_API(x) extern FcPrivate x +#endif + +#ifndef FTGLUE_APIDEF +#define FTGLUE_APIDEF(x) x +#endif + +/* stream macros used by the OpenType parser */ +#define FILE_Pos() ftglue_stream_pos( stream ) +#define FILE_Seek(pos) SET_ERR( ftglue_stream_seek( stream, pos ) ) +#define ACCESS_Frame(size) SET_ERR( ftglue_stream_frame_enter( stream, size ) ) +#define FORGET_Frame() ftglue_stream_frame_exit( stream ) + +#define GET_Byte() (*stream->cursor++) +#define GET_Short() (stream->cursor += 2, (FT_Short)( \ + (*(((FT_Byte*)stream->cursor)-2) << 8) | \ + *(((FT_Byte*)stream->cursor)-1) \ + )) +#define GET_Long() (stream->cursor += 4, (FT_Long)( \ + (*(((FT_Byte*)stream->cursor)-4) << 24) | \ + (*(((FT_Byte*)stream->cursor)-3) << 16) | \ + (*(((FT_Byte*)stream->cursor)-2) << 8) | \ + *(((FT_Byte*)stream->cursor)-1) \ + )) + +#define GET_Char() ((FT_Char)GET_Byte()) +#define GET_UShort() ((FT_UShort)GET_Short()) +#define GET_ULong() ((FT_ULong)GET_Long()) +#define GET_Tag4() GET_ULong() + +#define FT_SET_ERROR( expression ) \ + ( ( error = (expression) ) != 0 ) + +FTGLUE_API( FT_Long ) +ftglue_stream_pos( FT_Stream stream ); + +FTGLUE_API( FT_Error ) +ftglue_stream_seek( FT_Stream stream, + FT_Long pos ); + +FTGLUE_API( FT_Error ) +ftglue_stream_frame_enter( FT_Stream stream, + FT_ULong size ); + +FTGLUE_API( void ) +ftglue_stream_frame_exit( FT_Stream stream ); + +FTGLUE_API( FT_Error ) +ftglue_face_goto_table( FT_Face face, + FT_ULong tag, + FT_Stream stream ); + +FT_END_HEADER + +#endif /* __OPENTYPE_FTGLUE_H__ */