Commit 91a67478ec4a8ef0a7363f4728dd6c06be1ca92f

Werner Lemberg 2003-12-17T14:28:22

Add new function FT_Get_CMap_Language_ID to extract the language ID for TrueType/sfnt fonts. * include/freetype/internal/services/svttcmap.h: New file. * include/freetype/internal/ftserv.h (FT_SERVICE_TT_CMAP_H): Add svttcmap.h. * src/sfnt/sfdriver.c: Include ttcmap0.h. (tt_service_get_cmap_info): New service. (sfnt_services): Updated. * src/sfnt/ttcmap0.c (tt_cmap*_get_info): New functions. (tt_cmap*_class_rec): Add tt_cmap*_get_info members. (tt_get_cmap_info): New function. * src/sfnt/ttcmap0.h: Include FT_SERVICE_TT_CMAP_H. (TT_CMap_ClassRec): New field `get_cmap_info'. (tt_get_cmap_info): New declaration. * src/base/ftobjs.c: Include FT_SERVICE_TT_CMAP_H. (FT_Get_CMap_Language_ID): New function implementation. * include/freetype/tttables.h (FT_Get_CMap_Language_ID): New function declaration.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
diff --git a/ChangeLog b/ChangeLog
index dbd0423..9028eae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2003-12-17  Masatake YAMATO  <jet@gyve.org>
+
+	Add new function FT_Get_CMap_Language_ID to extract the language ID
+	for TrueType/sfnt fonts.
+
+	* include/freetype/internal/services/svttcmap.h: New file.
+	* include/freetype/internal/ftserv.h (FT_SERVICE_TT_CMAP_H): Add
+	svttcmap.h.
+
+	* src/sfnt/sfdriver.c: Include ttcmap0.h.
+	(tt_service_get_cmap_info): New service.
+	(sfnt_services): Updated.
+
+	* src/sfnt/ttcmap0.c (tt_cmap*_get_info): New functions.
+	(tt_cmap*_class_rec): Add tt_cmap*_get_info members.
+	(tt_get_cmap_info): New function.
+	* src/sfnt/ttcmap0.h: Include FT_SERVICE_TT_CMAP_H.
+	(TT_CMap_ClassRec): New field `get_cmap_info'.
+	(tt_get_cmap_info): New declaration.
+
+	* src/base/ftobjs.c: Include FT_SERVICE_TT_CMAP_H.
+	(FT_Get_CMap_Language_ID): New function implementation.
+	* include/freetype/tttables.h (FT_Get_CMap_Language_ID): New
+	function declaration.
+
 2003-12-16  Werner Lemberg  <wl@gnu.org>
 
 	* src/sfnt/ttcmap.c, src/sfnt/ttcmap.h: Removed.  Obsolete.
@@ -15,7 +40,7 @@
 	TT_CMapDirRec, TT_CMapDirEntryRec, TT_CMap0, TT_CMap2SubHeaderRec,
 	TT_CMap2Rec, TT_CMap4Segment, TT_CMap4Rec, TT_CMap6,
 	TT_CMapGroupRec, TT_CMap8_12Rec, TT_CMap10Rec, TT_CharMap_Func,
-	TT_CharNext_Func, TT_CMapTableRec, TT_CharMapRec): Removed. 
+	TT_CharNext_Func, TT_CMapTableRec, TT_CharMapRec): Removed.
 	Obsolete.
 	* src/cff/cffobjs.h (CFF_CharMapRec): Removed.  Obsolete.
 
@@ -6038,7 +6063,7 @@
 	(html_format): Replaced with ...
 	(html_quote): New function.
 	(html_quote0): New function.
-	(DocCode::dump_html: Small improvement.
+	(DocCode::dump_html): Small improvement.
 	(DocParagraph::dump, DocBlock::html): Use html_quote0 and html_quote.
 
 	* include/freetype/config/ftoption.h: Setting default options for
diff --git a/include/freetype/internal/ftserv.h b/include/freetype/internal/ftserv.h
index d77e1d5..e5ed889 100644
--- a/include/freetype/internal/ftserv.h
+++ b/include/freetype/internal/ftserv.h
@@ -248,6 +248,7 @@ FT_BEGIN_HEADER
 #define FT_SERVICE_SFNT_H              <freetype/internal/services/svsfnt.h>
 #define FT_SERVICE_PFR_H               <freetype/internal/services/svpfr.h>
 #define FT_SERVICE_WINFNT_H            <freetype/internal/services/svwinfnt.h>
+#define FT_SERVICE_TT_CMAP_H           <freetype/internal/services/svttcmap.h>
 
  /* */
 
diff --git a/include/freetype/internal/services/svttcmap.h b/include/freetype/internal/services/svttcmap.h
new file mode 100644
index 0000000..f92fcd0
--- /dev/null
+++ b/include/freetype/internal/services/svttcmap.h
@@ -0,0 +1,77 @@
+/***************************************************************************/
+/*                                                                         */
+/*  svsttcmap.h                                                            */
+/*                                                                         */
+/*    The FreeType TrueType/sfnt cmap extra information service.           */
+/*                                                                         */
+/*  Copyright 2003 by                                                      */
+/*  Masatake YAMATO, Redhat K.K.                                           */
+/*                                                                         */
+/*  Copyright 2003 by                                                      */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+/* Development of this service is support of 
+   Information-technology Promotion Agency, Japan. */
+
+#ifndef __SVTTCMAP_H__
+#define __SVTTCMAP_H__ 
+
+#include FT_INTERNAL_SERVICE_H
+#include FT_TRUETYPE_TABLES_H
+
+
+FT_BEGIN_HEADER
+
+
+#define FT_SERVICE_ID_TT_CMAP "tt-cmaps"
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Struct>                                                              */
+  /*    TT_CMapInfo                                                        */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A structure used to store TrueType/sfnt specific cmap information  */
+  /*    which is not covered by the generic @FT_CharMap structure.  This   */
+  /*    structure can be accessed with the @FT_Get_TT_CMap_Info function.  */
+  /*                                                                       */
+  /* <Fields>                                                              */
+  /*    language ::                                                        */
+  /*      The language ID used in Mac fonts.  Definitions of values are in */
+  /*      freetype/ttnameid.h.                                             */
+  /*                                                                       */
+  typedef struct  TT_CMapInfo_
+  {
+    FT_ULong language;
+
+  } TT_CMapInfo;
+
+
+  typedef FT_Error
+  (*TT_CMap_Info_GetFunc)( FT_CharMap    charmap,
+                           TT_CMapInfo  *cmap_info );
+
+
+  FT_DEFINE_SERVICE( TTCMaps )
+  {
+    TT_CMap_Info_GetFunc  get_cmap_info;
+  }; 
+  
+  /* */
+
+
+FT_END_HEADER
+
+#endif /* __SVTTCMAP_H__ */
+
+
+/* END */
diff --git a/include/freetype/tttables.h b/include/freetype/tttables.h
index 32f78be..2224791 100644
--- a/include/freetype/tttables.h
+++ b/include/freetype/tttables.h
@@ -663,6 +663,27 @@ FT_BEGIN_HEADER
                       FT_Byte*   buffer,
                       FT_ULong*  length );
 
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FT_Get_CMap_Language_ID                                            */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Return TrueType/sfnt specific cmap language ID.  Definitions of    */
+  /*    language ID values are in freetype/ttnameid.h.                     */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    charmap ::                                                         */
+  /*      The target charmap.                                              */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    The language ID of `charmap'.  If `charmap' doesn't belong to a    */
+  /*    TrueType/sfnt face, just return 0 as the default value.            */
+  /*                                                                       */
+  FT_EXPORT( FT_ULong )
+  FT_Get_CMap_Language_ID( FT_CharMap  charmap );
+
   /* */
 
 
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 70453c6..b84a371 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -30,6 +30,7 @@
 #include FT_SERVICE_SFNT_H
 #include FT_SERVICE_POSTSCRIPT_NAME_H
 #include FT_SERVICE_GLYPH_DICT_H
+#include FT_SERVICE_TT_CMAP_H
 
 
   FT_BASE_DEF( FT_Pointer )
@@ -2508,6 +2509,28 @@
   }
 
 
+  FT_EXPORT_DEF( FT_ULong )
+  FT_Get_CMap_Language_ID( FT_CharMap  charmap )
+  {
+    FT_Service_TTCMaps  service;
+    FT_Face             face;
+    TT_CMapInfo         cmap_info;
+
+    
+    if ( !charmap || !charmap->face )
+      return 0;
+
+    face = charmap->face;
+    FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
+    if ( service == NULL )
+      return 0;
+    if ( service->get_cmap_info( charmap, &cmap_info ))
+      return 0;
+
+    return cmap_info.language;
+  }
+
+
   FT_EXPORT_DEF( FT_Error )
   FT_Activate_Size( FT_Size  size )
   {
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index 685a3c6..c2bf948 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -34,9 +34,12 @@
 #include "ttpost.h"
 #endif
 
+#include "ttcmap0.h"
+
 #include FT_SERVICE_GLYPH_DICT_H
 #include FT_SERVICE_POSTSCRIPT_NAME_H
 #include FT_SERVICE_SFNT_H
+#include FT_SERVICE_TT_CMAP_H
 
 
  /*
@@ -260,6 +263,15 @@
   };
 
 
+ /*
+  *  TT CMAP INFO
+  *
+  */
+  static const FT_Service_TTCMapsRec  tt_service_get_cmap_info =
+  {
+    (TT_CMap_Info_GetFunc)tt_get_cmap_info
+  };
+
 
  /*
   *  SERVICE LIST
@@ -273,6 +285,7 @@
 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
     { FT_SERVICE_ID_GLYPH_DICT,           &sfnt_service_glyph_dict },
 #endif
+    { FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info },
 
     { NULL, NULL }
   };
diff --git a/src/sfnt/ttcmap0.c b/src/sfnt/ttcmap0.c
index 4c9dadf..35f6532 100644
--- a/src/sfnt/ttcmap0.c
+++ b/src/sfnt/ttcmap0.c
@@ -144,6 +144,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap0_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 4;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap0_class_rec =
   {
@@ -156,7 +169,8 @@
       (FT_CMap_CharNextFunc) tt_cmap0_char_next
     },
     0,
-    (TT_CMap_ValidateFunc)   tt_cmap0_validate
+    (TT_CMap_ValidateFunc)   tt_cmap0_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap0_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_0 */
@@ -497,6 +511,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap2_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 4;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap2_class_rec =
   {
@@ -509,7 +536,8 @@
       (FT_CMap_CharNextFunc) tt_cmap2_char_next
     },
     2,
-    (TT_CMap_ValidateFunc)   tt_cmap2_validate
+    (TT_CMap_ValidateFunc)   tt_cmap2_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap2_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_2 */
@@ -1058,6 +1086,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap4_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 4;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap4_class_rec =
   {
@@ -1070,7 +1111,8 @@
       (FT_CMap_CharNextFunc) tt_cmap4_char_next
     },
     4,
-    (TT_CMap_ValidateFunc)   tt_cmap4_validate
+    (TT_CMap_ValidateFunc)   tt_cmap4_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap4_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_4 */
@@ -1202,6 +1244,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap6_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 4;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap6_class_rec =
   {
@@ -1214,7 +1269,8 @@
       (FT_CMap_CharNextFunc) tt_cmap6_char_next
     },
     6,
-    (TT_CMap_ValidateFunc)   tt_cmap6_validate
+    (TT_CMap_ValidateFunc)   tt_cmap6_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap6_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_6 */
@@ -1439,6 +1495,18 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap8_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 8;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap8_class_rec =
   {
@@ -1451,7 +1519,8 @@
       (FT_CMap_CharNextFunc) tt_cmap8_char_next
     },
     8,
-    (TT_CMap_ValidateFunc)   tt_cmap8_validate
+    (TT_CMap_ValidateFunc)   tt_cmap8_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap8_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_8 */
@@ -1571,6 +1640,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap10_get_info( TT_CMap       cmap,
+                      TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 8;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap10_class_rec =
   {
@@ -1583,7 +1665,8 @@
       (FT_CMap_CharNextFunc) tt_cmap10_char_next
     },
     10,
-    (TT_CMap_ValidateFunc)   tt_cmap10_validate
+    (TT_CMap_ValidateFunc)   tt_cmap10_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap10_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_10 */
@@ -1741,6 +1824,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap12_get_info( TT_CMap       cmap,
+                      TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 8;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap12_class_rec =
   {
@@ -1753,7 +1849,8 @@
       (FT_CMap_CharNextFunc) tt_cmap12_char_next
     },
     12,
-    (TT_CMap_ValidateFunc)   tt_cmap12_validate
+    (TT_CMap_ValidateFunc)   tt_cmap12_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap12_get_info
   };
 
 
@@ -1875,4 +1972,16 @@
   }
 
 
+  FT_LOCAL( FT_Error )
+  tt_get_cmap_info( FT_CharMap    charmap,
+                    TT_CMapInfo  *cmap_info )
+  {
+    FT_CMap        cmap  = (FT_CMap)charmap;
+    TT_CMap_Class  clazz = (TT_CMap_Class)cmap->clazz;
+
+
+    return clazz->get_cmap_info( charmap, cmap_info );
+  }
+
+
 /* END */
diff --git a/src/sfnt/ttcmap0.h b/src/sfnt/ttcmap0.h
index ff1276e..28f5bac 100644
--- a/src/sfnt/ttcmap0.h
+++ b/src/sfnt/ttcmap0.h
@@ -23,7 +23,7 @@
 #include <ft2build.h>
 #include FT_INTERNAL_TRUETYPE_TYPES_H
 #include FT_INTERNAL_OBJECTS_H
-
+#include FT_SERVICE_TT_CMAP_H
 
 FT_BEGIN_HEADER
 
@@ -46,6 +46,7 @@ FT_BEGIN_HEADER
     FT_CMap_ClassRec      clazz;
     FT_UInt               format;
     TT_CMap_ValidateFunc  validate;
+    TT_CMap_Info_GetFunc  get_cmap_info;
 
   } TT_CMap_ClassRec;
 
@@ -65,6 +66,11 @@ FT_BEGIN_HEADER
   FT_LOCAL( FT_Error )
   tt_face_build_cmaps( TT_Face  face );
 
+  /* used in tt-cmaps service */
+  FT_LOCAL( FT_Error )
+  tt_get_cmap_info( FT_CharMap    charmap,
+                    TT_CMapInfo  *cmap_info );
+
 
 FT_END_HEADER