Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3918 Serge 1
/*  pcfdrivr.c
2
 
3
    FreeType font driver for pcf files
4
 
5
    Copyright (C) 2000-2004, 2006-2011, 2013 by
6
    Francesco Zappa Nardelli
7
 
8
Permission is hereby granted, free of charge, to any person obtaining a copy
9
of this software and associated documentation files (the "Software"), to deal
10
in the Software without restriction, including without limitation the rights
11
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
copies of the Software, and to permit persons to whom the Software is
13
furnished to do so, subject to the following conditions:
14
 
15
The above copyright notice and this permission notice shall be included in
16
all copies or substantial portions of the Software.
17
 
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
21
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
THE SOFTWARE.
25
*/
26
 
27
 
28
#include 
29
 
30
#include FT_INTERNAL_DEBUG_H
31
#include FT_INTERNAL_STREAM_H
32
#include FT_INTERNAL_OBJECTS_H
33
#include FT_GZIP_H
34
#include FT_LZW_H
35
#include FT_BZIP2_H
36
#include FT_ERRORS_H
37
#include FT_BDF_H
38
#include FT_TRUETYPE_IDS_H
39
 
40
#include "pcf.h"
41
#include "pcfdrivr.h"
42
#include "pcfread.h"
43
 
44
#include "pcferror.h"
45
#include "pcfutil.h"
46
 
47
#undef  FT_COMPONENT
48
#define FT_COMPONENT  trace_pcfread
49
 
50
#include FT_SERVICE_BDF_H
51
#include FT_SERVICE_XFREE86_NAME_H
52
 
53
 
54
  /*************************************************************************/
55
  /*                                                                       */
56
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
57
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
58
  /* messages during execution.                                            */
59
  /*                                                                       */
60
#undef  FT_COMPONENT
61
#define FT_COMPONENT  trace_pcfdriver
62
 
63
 
64
  typedef struct  PCF_CMapRec_
65
  {
66
    FT_CMapRec    root;
67
    FT_UInt       num_encodings;
68
    PCF_Encoding  encodings;
69
 
70
  } PCF_CMapRec, *PCF_CMap;
71
 
72
 
73
  FT_CALLBACK_DEF( FT_Error )
74
  pcf_cmap_init( FT_CMap     pcfcmap,   /* PCF_CMap */
75
                 FT_Pointer  init_data )
76
  {
77
    PCF_CMap  cmap = (PCF_CMap)pcfcmap;
78
    PCF_Face  face = (PCF_Face)FT_CMAP_FACE( pcfcmap );
79
 
80
    FT_UNUSED( init_data );
81
 
82
 
83
    cmap->num_encodings = (FT_UInt)face->nencodings;
84
    cmap->encodings     = face->encodings;
85
 
86
    return FT_Err_Ok;
87
  }
88
 
89
 
90
  FT_CALLBACK_DEF( void )
91
  pcf_cmap_done( FT_CMap  pcfcmap )         /* PCF_CMap */
92
  {
93
    PCF_CMap  cmap = (PCF_CMap)pcfcmap;
94
 
95
 
96
    cmap->encodings     = NULL;
97
    cmap->num_encodings = 0;
98
  }
99
 
100
 
101
  FT_CALLBACK_DEF( FT_UInt )
102
  pcf_cmap_char_index( FT_CMap    pcfcmap,  /* PCF_CMap */
103
                       FT_UInt32  charcode )
104
  {
105
    PCF_CMap      cmap      = (PCF_CMap)pcfcmap;
106
    PCF_Encoding  encodings = cmap->encodings;
107
    FT_UInt       min, max, mid;
108
    FT_UInt       result    = 0;
109
 
110
 
111
    min = 0;
112
    max = cmap->num_encodings;
113
 
114
    while ( min < max )
115
    {
116
      FT_ULong  code;
117
 
118
 
119
      mid  = ( min + max ) >> 1;
120
      code = encodings[mid].enc;
121
 
122
      if ( charcode == code )
123
      {
124
        result = encodings[mid].glyph + 1;
125
        break;
126
      }
127
 
128
      if ( charcode < code )
129
        max = mid;
130
      else
131
        min = mid + 1;
132
    }
133
 
134
    return result;
135
  }
136
 
137
 
138
  FT_CALLBACK_DEF( FT_UInt )
139
  pcf_cmap_char_next( FT_CMap    pcfcmap,   /* PCF_CMap */
140
                      FT_UInt32  *acharcode )
141
  {
142
    PCF_CMap      cmap      = (PCF_CMap)pcfcmap;
143
    PCF_Encoding  encodings = cmap->encodings;
144
    FT_UInt       min, max, mid;
145
    FT_ULong      charcode  = *acharcode + 1;
146
    FT_UInt       result    = 0;
147
 
148
 
149
    min = 0;
150
    max = cmap->num_encodings;
151
 
152
    while ( min < max )
153
    {
154
      FT_ULong  code;
155
 
156
 
157
      mid  = ( min + max ) >> 1;
158
      code = encodings[mid].enc;
159
 
160
      if ( charcode == code )
161
      {
162
        result = encodings[mid].glyph + 1;
163
        goto Exit;
164
      }
165
 
166
      if ( charcode < code )
167
        max = mid;
168
      else
169
        min = mid + 1;
170
    }
171
 
172
    charcode = 0;
173
    if ( min < cmap->num_encodings )
174
    {
175
      charcode = encodings[min].enc;
176
      result   = encodings[min].glyph + 1;
177
    }
178
 
179
  Exit:
180
    if ( charcode > 0xFFFFFFFFUL )
181
    {
182
      FT_TRACE1(( "pcf_cmap_char_next: charcode 0x%x > 32bit API" ));
183
      *acharcode = 0;
184
      /* XXX: result should be changed to indicate an overflow error */
185
    }
186
    else
187
      *acharcode = (FT_UInt32)charcode;
188
    return result;
189
  }
190
 
191
 
192
  FT_CALLBACK_TABLE_DEF
193
  const FT_CMap_ClassRec  pcf_cmap_class =
194
  {
195
    sizeof ( PCF_CMapRec ),
196
    pcf_cmap_init,
197
    pcf_cmap_done,
198
    pcf_cmap_char_index,
199
    pcf_cmap_char_next,
200
 
201
    NULL, NULL, NULL, NULL, NULL
202
  };
203
 
204
 
205
  FT_CALLBACK_DEF( void )
206
  PCF_Face_Done( FT_Face  pcfface )         /* PCF_Face */
207
  {
208
    PCF_Face   face = (PCF_Face)pcfface;
209
    FT_Memory  memory;
210
 
211
 
212
    if ( !face )
213
      return;
214
 
215
    memory = FT_FACE_MEMORY( face );
216
 
217
    FT_FREE( face->encodings );
218
    FT_FREE( face->metrics );
219
 
220
    /* free properties */
221
    {
222
      PCF_Property  prop;
223
      FT_Int        i;
224
 
225
 
226
      if ( face->properties )
227
      {
228
        for ( i = 0; i < face->nprops; i++ )
229
        {
230
          prop = &face->properties[i];
231
 
232
          if ( prop )
233
          {
234
            FT_FREE( prop->name );
235
            if ( prop->isString )
236
              FT_FREE( prop->value.atom );
237
          }
238
        }
239
      }
240
      FT_FREE( face->properties );
241
    }
242
 
243
    FT_FREE( face->toc.tables );
244
    FT_FREE( pcfface->family_name );
245
    FT_FREE( pcfface->style_name );
246
    FT_FREE( pcfface->available_sizes );
247
    FT_FREE( face->charset_encoding );
248
    FT_FREE( face->charset_registry );
249
 
250
    /* close compressed stream if any */
251
    if ( pcfface->stream == &face->comp_stream )
252
    {
253
      FT_Stream_Close( &face->comp_stream );
254
      pcfface->stream = face->comp_source;
255
    }
256
  }
257
 
258
 
259
  FT_CALLBACK_DEF( FT_Error )
260
  PCF_Face_Init( FT_Stream      stream,
261
                 FT_Face        pcfface,        /* PCF_Face */
262
                 FT_Int         face_index,
263
                 FT_Int         num_params,
264
                 FT_Parameter*  params )
265
  {
266
    PCF_Face  face  = (PCF_Face)pcfface;
267
    FT_Error  error = FT_Err_Ok;
268
 
269
    FT_UNUSED( num_params );
270
    FT_UNUSED( params );
271
    FT_UNUSED( face_index );
272
 
273
 
274
    FT_TRACE2(( "PCF driver\n" ));
275
 
276