ReactOS 0.4.16-dev-2358-g0df3463
pfrcmap.c
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * pfrcmap.c
4 *
5 * FreeType PFR cmap handling (body).
6 *
7 * Copyright (C) 2002-2020 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
15 *
16 */
17
18
20#include "pfrcmap.h"
21#include "pfrobjs.h"
22
23#include "pfrerror.h"
24
25
29 {
32
34
35
36 cmap->num_chars = face->phy_font.num_chars;
37 cmap->chars = face->phy_font.chars;
38
39 /* just for safety, check that the character entries are correctly */
40 /* sorted in increasing character code order */
41 {
42 FT_UInt n;
43
44
45 for ( n = 1; n < cmap->num_chars; n++ )
46 {
47 if ( cmap->chars[n - 1].char_code >= cmap->chars[n].char_code )
48 {
49 error = FT_THROW( Invalid_Table );
50 goto Exit;
51 }
52 }
53 }
54
55 Exit:
56 return error;
57 }
58
59
60 FT_CALLBACK_DEF( void )
62 {
63 cmap->chars = NULL;
64 cmap->num_chars = 0;
65 }
66
67
70 FT_UInt32 char_code )
71 {
72 FT_UInt min = 0;
73 FT_UInt max = cmap->num_chars;
74
75
76 while ( min < max )
77 {
78 PFR_Char gchar;
79 FT_UInt mid;
80
81
82 mid = min + ( max - min ) / 2;
83 gchar = cmap->chars + mid;
84
85 if ( gchar->char_code == char_code )
86 return mid + 1;
87
88 if ( gchar->char_code < char_code )
89 min = mid + 1;
90 else
91 max = mid;
92 }
93 return 0;
94 }
95
96
97 FT_CALLBACK_DEF( FT_UInt32 )
99 FT_UInt32 *pchar_code )
100 {
101 FT_UInt result = 0;
102 FT_UInt32 char_code = *pchar_code + 1;
103
104
105 Restart:
106 {
107 FT_UInt min = 0;
108 FT_UInt max = cmap->num_chars;
109 FT_UInt mid;
110 PFR_Char gchar;
111
112
113 while ( min < max )
114 {
115 mid = min + ( ( max - min ) >> 1 );
116 gchar = cmap->chars + mid;
117
118 if ( gchar->char_code == char_code )
119 {
120 result = mid;
121 if ( result != 0 )
122 {
123 result++;
124 goto Exit;
125 }
126
127 char_code++;
128 goto Restart;
129 }
130
131 if ( gchar->char_code < char_code )
132 min = mid + 1;
133 else
134 max = mid;
135 }
136
137 /* we didn't find it, but we have a pair just above it */
138 char_code = 0;
139
140 if ( min < cmap->num_chars )
141 {
142 gchar = cmap->chars + min;
143 result = min;
144 if ( result != 0 )
145 {
146 result++;
147 char_code = gchar->char_code;
148 }
149 }
150 }
151
152 Exit:
153 *pchar_code = char_code;
154 return result;
155 }
156
157
160 {
161 sizeof ( PFR_CMapRec ),
162
163 (FT_CMap_InitFunc) pfr_cmap_init, /* init */
164 (FT_CMap_DoneFunc) pfr_cmap_done, /* done */
167
168 (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */
169 (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */
170 (FT_CMap_VariantListFunc) NULL, /* variant_list */
171 (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */
172 (FT_CMap_VariantCharListFunc) NULL /* variantchar_list */
173 };
174
175
176/* END */
#define FT_CALLBACK_DEF(x)
#define FT_CALLBACK_TABLE_DEF
#define NULL
Definition: types.h:112
return FT_Err_Ok
Definition: ftbbox.c:526
#define FT_THROW(e)
Definition: ftdebug.h:243
FT_UInt(* FT_CMap_CharNextFunc)(FT_CMap cmap, FT_UInt32 *achar_code)
Definition: ftobjs.h:179
FT_UInt(* FT_CMap_CharVarIndexFunc)(FT_CMap cmap, FT_CMap unicode_cmap, FT_UInt32 char_code, FT_UInt32 variant_selector)
Definition: ftobjs.h:183
FT_UInt32 *(* FT_CMap_CharVariantListFunc)(FT_CMap cmap, FT_Memory mem, FT_UInt32 char_code)
Definition: ftobjs.h:198
FT_Int(* FT_CMap_CharVarIsDefaultFunc)(FT_CMap cmap, FT_UInt32 char_code, FT_UInt32 variant_selector)
Definition: ftobjs.h:189
FT_UInt32 *(* FT_CMap_VariantCharListFunc)(FT_CMap cmap, FT_Memory mem, FT_UInt32 variant_selector)
Definition: ftobjs.h:203
FT_UInt32 *(* FT_CMap_VariantListFunc)(FT_CMap cmap, FT_Memory mem)
Definition: ftobjs.h:194
FT_Error(* FT_CMap_InitFunc)(FT_CMap cmap, FT_Pointer init_data)
Definition: ftobjs.h:168
void(* FT_CMap_DoneFunc)(FT_CMap cmap)
Definition: ftobjs.h:172
FT_UInt(* FT_CMap_CharIndexFunc)(FT_CMap cmap, FT_UInt32 char_code)
Definition: ftobjs.h:175
#define FT_CMAP_FACE(x)
Definition: ftobjs.h:163
int FT_Error
Definition: fttypes.h:299
unsigned int FT_UInt
Definition: fttypes.h:231
GLdouble n
Definition: glext.h:7729
GLsizei const GLvoid * pointer
Definition: glext.h:5848
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
GLuint64EXT * result
Definition: glext.h:11304
#define error(str)
Definition: mkdosfs.c:1605
#define min(a, b)
Definition: monoChain.cc:55
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec pfr_cmap_class_rec
Definition: pfrcmap.c:159
pfr_cmap_init(PFR_CMap cmap, FT_Pointer pointer)
Definition: pfrcmap.c:27
pfr_cmap_done(PFR_CMap cmap)
Definition: pfrcmap.c:61
pfr_cmap_char_next(PFR_CMap cmap, FT_UInt32 *pchar_code)
Definition: pfrcmap.c:98
pfr_cmap_char_index(PFR_CMap cmap, FT_UInt32 char_code)
Definition: pfrcmap.c:69
FT_BEGIN_HEADER struct PFR_CMapRec_ * PFR_CMap
FT_BEGIN_HEADER struct PFR_CMapRec_ PFR_CMapRec
typedefFT_BEGIN_HEADER struct PFR_FaceRec_ * PFR_Face
Definition: pfrobjs.h:27
#define FT_UNUSED(arg)
@ Restart
Definition: sacdrv.h:269
static void Exit(void)
Definition: sock.c:1330
FT_UInt char_code
Definition: pfrtypes.h:156
#define max(a, b)
Definition: svc.c:63