1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "../../../include/fxge/fx_freetype.h"
8 #include "../../../../third_party/freetype/src/psnames/pstables.h"
10 static int xyq_search_node(char* glyph_name, int name_offset, int table_offset, wchar_t unicode)
\r
16 glyph_name[name_offset] = ft_adobe_glyph_list[table_offset] & 0x7f;
\r
19 if (!(ft_adobe_glyph_list[table_offset - 1] & 0x80)) break;
\r
21 glyph_name[name_offset] = 0;
\r
24 count = ft_adobe_glyph_list[table_offset] & 0x7f;
\r
26 // check if we have value for this node
\r
27 if (ft_adobe_glyph_list[table_offset] & 0x80) {
\r
28 unsigned short thiscode = ft_adobe_glyph_list[table_offset + 1] * 256 + ft_adobe_glyph_list[table_offset + 2];
\r
29 if (thiscode == (unsigned short)unicode) // found it!
\r
36 // now search in sub-nodes
\r
37 if (count == 0) return 0;
\r
38 for (i = 0; i < count; i++) {
\r
39 int child_offset = ft_adobe_glyph_list[table_offset + i * 2] * 256 + ft_adobe_glyph_list[table_offset + i * 2 + 1];
\r
40 if (xyq_search_node(glyph_name, name_offset, child_offset, unicode))
\r
47 #define VARIANT_BIT 0x80000000UL
49 int FXFT_unicode_from_adobe_name(const char* glyph_name)
\r
51 /* If the name begins with `uni', then the glyph name may be a */
\r
52 /* hard-coded unicode character code. */
\r
53 if (glyph_name[0] == 'u' &&
\r
54 glyph_name[1] == 'n' &&
\r
55 glyph_name[2] == 'i')
\r
57 /* determine whether the next four characters following are */
\r
60 /* XXX: Add code to deal with ligatures, i.e. glyph names like */
\r
61 /* `uniXXXXYYYYZZZZ'... */
\r
64 FT_UInt32 value = 0;
\r
65 const char* p = glyph_name + 3;
\r
68 for (count = 4; count > 0; count--, p++)
\r
74 d = (unsigned char)c - '0';
\r
77 d = (unsigned char)c - 'A';
\r
84 /* Exit if a non-uppercase hexadecimal character was found */
\r
85 /* -- this also catches character codes below `0' since such */
\r
86 /* negative numbers cast to `unsigned int' are far too big. */
\r
90 value = (value << 4) + d;
\r
93 /* there must be exactly four hex digits */
\r
99 return (FT_UInt32)(value | VARIANT_BIT);
\r
103 /* If the name begins with `u', followed by four to six uppercase */
\r
104 /* hexadecimal digits, it is a hard-coded unicode character code. */
\r
105 if (glyph_name[0] == 'u')
\r
108 FT_UInt32 value = 0;
\r
109 const char* p = glyph_name + 1;
\r
112 for (count = 6; count > 0; count--, p++)
\r
118 d = (unsigned char)c - '0';
\r
121 d = (unsigned char)c - 'A';
\r
131 value = (value << 4) + d;
\r
139 return (FT_UInt32)(value | VARIANT_BIT);
\r
143 /* Look for a non-initial dot in the glyph name in order to */
\r
144 /* find variants like `A.swash', `e.final', etc. */
\r
146 const char* p = glyph_name;
\r
147 const char* dot = NULL;
\r
152 if (*p == '.' && p > glyph_name)
\r
159 /* now look up the glyph in the Adobe Glyph List */
\r
161 return (FT_UInt32)ft_get_adobe_glyph_index(glyph_name, p);
\r
163 return (FT_UInt32)(ft_get_adobe_glyph_index(glyph_name, dot) |
\r
168 void FXFT_adobe_name_from_unicode(char* glyph_name, wchar_t unicode)
\r
172 // start from top level node
\r
173 count = ft_adobe_glyph_list[1];
\r
174 for (i = 0; i < count; i++) {
\r
175 int child_offset = ft_adobe_glyph_list[i * 2 + 2] * 256 + ft_adobe_glyph_list[i * 2 + 3];
\r
176 if (xyq_search_node(glyph_name, 0, child_offset, unicode))
\r
180 // failed, clear the buffer
\r