Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
pfrcmap.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* pfrcmap.c */
4 /* */
5 /* FreeType PFR cmap handling (body). */
6 /* */
7 /* Copyright 2002, 2007, 2009, 2013 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 
19 #include <ft2build.h>
20 #include FT_INTERNAL_DEBUG_H
21 #include "pfrcmap.h"
22 #include "pfrobjs.h"
23 
24 #include "pfrerror.h"
25 
26 
29  {
32 
33 
34  cmap->num_chars = face->phy_font.num_chars;
35  cmap->chars = face->phy_font.chars;
36 
37  /* just for safety, check that the character entries are correctly */
38  /* sorted in increasing character code order */
39  {
40  FT_UInt n;
41 
42 
43  for ( n = 1; n < cmap->num_chars; n++ )
44  {
45  if ( cmap->chars[n - 1].char_code >= cmap->chars[n].char_code )
46  {
47  error = FT_THROW( Invalid_Table );
48  goto Exit;
49  }
50  }
51  }
52 
53  Exit:
54  return error;
55  }
56 
57 
58  FT_CALLBACK_DEF( void )
60  {
61  cmap->chars = NULL;
62  cmap->num_chars = 0;
63  }
64 
65 
68  FT_UInt32 char_code )
69  {
70  FT_UInt min = 0;
71  FT_UInt max = cmap->num_chars;
72  FT_UInt mid;
73  PFR_Char gchar;
74 
75 
76  while ( min < max )
77  {
78  mid = min + ( max - min ) / 2;
79  gchar = cmap->chars + mid;
80 
81  if ( gchar->char_code == char_code )
82  return mid + 1;
83 
84  if ( gchar->char_code < char_code )
85  min = mid + 1;
86  else
87  max = mid;
88  }
89  return 0;
90  }
91 
92 
95  FT_UInt32 *pchar_code )
96  {
97  FT_UInt result = 0;
98  FT_UInt32 char_code = *pchar_code + 1;
99 
100 
101  Restart:
102  {
103  FT_UInt min = 0;
104  FT_UInt max = cmap->num_chars;
105  FT_UInt mid;
106  PFR_Char gchar;
107 
108 
109  while ( min < max )
110  {
111  mid = min + ( ( max - min ) >> 1 );
112  gchar = cmap->chars + mid;
113 
114  if ( gchar->char_code == char_code )
115  {
116  result = mid;
117  if ( result != 0 )
118  {
119  result++;
120  goto Exit;
121  }
122 
123  char_code++;
124  goto Restart;
125  }
126 
127  if ( gchar->char_code < char_code )
128  min = mid+1;
129  else
130  max = mid;
131  }
132 
133  /* we didn't find it, but we have a pair just above it */
134  char_code = 0;
135 
136  if ( min < cmap->num_chars )
137  {
138  gchar = cmap->chars + min;
139  result = min;
140  if ( result != 0 )
141  {
142  result++;
143  char_code = gchar->char_code;
144  }
145  }
146  }
147 
148  Exit:
149  *pchar_code = char_code;
150  return result;
151  }
152 
153 
156  {
157  sizeof ( PFR_CMapRec ),
158 
163 
164  NULL, NULL, NULL, NULL, NULL
165  };
166 
167 
168 /* END */
int FT_Error
Definition: fttypes.h:296
#define FT_CMAP_FACE(x)
Definition: ftobjs.h:145
FT_UInt(* FT_CMap_CharIndexFunc)(FT_CMap cmap, FT_UInt32 char_code)
Definition: ftobjs.h:157
#define NULL
Definition: ftobjs.h:61
return FT_THROW(Missing_Property)
void(* FT_CMap_DoneFunc)(FT_CMap cmap)
Definition: ftobjs.h:154
unsigned int FT_UInt32
Definition: ftconfig.h:133
return FT_Err_Ok
Definition: ftbbox.c:645
GLenum GLuint GLint GLenum face
FT_UInt char_code
Definition: pfrtypes.h:174
pfr_cmap_char_index(PFR_CMap cmap, FT_UInt32 char_code)
Definition: pfrcmap.c:67
pfr_cmap_char_next(PFR_CMap cmap, FT_UInt32 *pchar_code)
Definition: pfrcmap.c:94
FT_Error error
Definition: cffdrivr.c:411
pfr_cmap_done(PFR_CMap cmap)
Definition: pfrcmap.c:59
float min(float a, float b)
Definition: Vector2.hpp:307
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec pfr_cmap_class_rec
Definition: pfrcmap.c:155
GLdouble n
#define FT_CALLBACK_DEF(x)
Definition: ftconfig.h:323
local int max
Definition: enough.c:170
FT_BEGIN_HEADER struct PFR_CMapRec_ PFR_CMapRec
#define FT_CALLBACK_TABLE_DEF
Definition: ftconfig.h:333
GLuint64EXT * result
unsigned int FT_UInt
Definition: fttypes.h:227
FT_UInt(* FT_CMap_CharNextFunc)(FT_CMap cmap, FT_UInt32 *achar_code)
Definition: ftobjs.h:161
typedefFT_BEGIN_HEADER struct PFR_FaceRec_ * PFR_Face
Definition: pfrobjs.h:27
FT_BEGIN_HEADER struct PFR_CMapRec_ * PFR_CMap
FT_Error(* FT_CMap_InitFunc)(FT_CMap cmap, FT_Pointer init_data)
Definition: ftobjs.h:150
pfr_cmap_init(PFR_CMap cmap)
Definition: pfrcmap.c:28