Commit 11187206791326f7e851b62e13107723ce2c6505

David Turner 2000-05-26T17:13:23

finalised the multiple masters support fixed some nasty little bugs too

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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
diff --git a/CHANGES b/CHANGES
index 4013727..8ec03ee 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,14 @@
 LATEST_CHANGES
 
+  - added support for Multiple Master fonts in "type1z". There is also
+    a new file named <freetype/ftmm.h> which defines functions to
+    manage them from client applications.
+    
+    The new file "src/base/ftmm.c" is also optional to the engine..
+
+  - various formatting changes (e.g. EXPORT_DEF -> FT_EXPORT_DEF) +
+    small bug fixes in FT_Load_Glyph, the "type1" driver, etc..
+
   - a minor fix to the Type 1 driver to let them apply the font matrix
     correctly (used for many oblique fonts..)
 
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 4a4174f..4700830 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -733,6 +733,17 @@
   /*                                                                       */
 #define FT_FACE_FLAG_FAST_GLYPHS  0x80
 
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Constant>                                                            */
+  /*    FT_FACE_FLAG_MULTIPLE_MASTERS                                      */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A bit-field constant, used to indicate that the font contains      */
+  /*    multiple masters and is capable of interpolating between them..    */
+  /*                                                                       */
+#define FT_FACE_FLAG_MULTIPLE_MASTERS  0x100
+
 
 #define FT_HAS_HORIZONTAL(face)  (face->face_flags & FT_FACE_FLAG_HORIZONTAL)
 #define FT_HAS_VERTICAL(face)    (face->face_flags & FT_FACE_FLAG_VERTICAL)
@@ -743,6 +754,8 @@
 #define FT_HAS_FIXED_SIZES(face) (face->face_flags & FT_FACE_FLAG_FIXED_SIZES)
 #define FT_HAS_FAST_GLYPHS(face) (face->face_flags & FT_FACE_FLAG_FAST_GLYPHS)
 
+#define FT_HAS_MULTIPLE_MASTERS(face) \
+          (face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS)
 
   /*************************************************************************/
   /*                                                                       */
@@ -1964,7 +1977,7 @@
   /*    application if you want something simpler.                         */
   /*                                                                       */
   FT_EXPORT_DEF(FT_Error)  FT_Outline_Done( FT_Library   library,
-                                         FT_Outline*  outline );
+                                            FT_Outline*  outline );
 
   /*************************************************************************/
   /*                                                                       */
diff --git a/include/freetype/ftmm.h b/include/freetype/ftmm.h
new file mode 100644
index 0000000..ae3d352
--- /dev/null
+++ b/include/freetype/ftmm.h
@@ -0,0 +1,163 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftmm.h                                                                 */
+/*                                                                         */
+/*    FreeType Multiple-Master interface.                                  */
+/*                                                                         */
+/*                                                                         */
+/*  Copyright 1996-2000 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.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+#ifndef FTMM_H
+#define FTMM_H
+
+#include <freetype/t1tables.h>
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+ /**********************************************************************
+  *
+  * <Struct>
+  *    FT_MM_Axis
+  *
+  * <Description>
+  *    A simple structure used to model a given axis in design space
+  *    for multiple masters fonts..
+  *
+  * <Fields>
+  *    name     :: axis' name
+  *    minimum  :: axis' minimum design coordinate
+  *    maximum  :: axis's maximum design coordinate
+  *
+  */
+  typedef struct FT_MM_Axis_
+  {
+    FT_String*  name;
+    FT_Long     minimum;
+    FT_Long     maximum;
+  
+  } FT_MM_Axis;
+
+ /**********************************************************************
+  *
+  * <Struct>
+  *    FT_Multi_Master
+  *
+  * <Description>
+  *    A structure used to model the axis and space of a multiple    
+  *    masters font.               
+  *
+  * <Fields>
+  *    num_axis    :: number of axis. cannot exceed 4
+  *
+  *    num_designs :: number of designs, should ne normally 2^num_axis
+  *                   even though the Type 1 specification strangely
+  *                   allows for intermediate designs to be present
+  *                   this number cannot exceed 16
+  *
+  *    axis        :: an table of axis descriptors..
+  *
+  */
+  typedef struct FT_Multi_Master_
+  {
+    FT_UInt     num_axis;
+    FT_UInt     num_designs;
+    FT_MM_Axis  axis[ T1_MAX_MM_AXIS ];
+  
+  } FT_Multi_Master;
+
+
+  typedef  FT_Error  (*FT_Get_MM_Func)( FT_Face  face, FT_Multi_Master* master );
+  
+  typedef  FT_Error  (*FT_Set_MM_Design_Func)( FT_Face   face,
+                                               FT_UInt   num_coords,
+                                               FT_Long*  coords );
+
+  typedef  FT_Error  (*FT_Set_MM_Blend_Func)( FT_Face   face,
+                                              FT_UInt   num_coords,
+                                              FT_Long*  coords );
+
+ /*************************************************************************
+  *
+  *  <Function>
+  *     FT_Get_Multi_Master
+  *
+  *  <Description>
+  *     Retrieves the multiple master descriptor of a given font
+  *
+  *  <Input>
+  *     face    :: handle to source face
+  *
+  *  <Output>
+  *     master  :: multiple masters descriptor
+  *
+  *  <Return>
+  *     Error code. 0 means success.
+  *
+  */
+  FT_EXPORT_DEF(FT_Error)   FT_Get_Multi_Master( FT_Face           face,
+                                                 FT_Multi_Master*  master );
+
+
+ /*************************************************************************
+  *
+  *  <Function>
+  *     FT_Set_MM_Design_Coordinates
+  *
+  *  <Description>
+  *     For multiple masters fonts, choose an interpolated font design
+  *     through design coordinates
+  *
+  *  <Input>
+  *     face       :: handle to source face
+  *     num_coords :: number of design coordinates (must be equal to the
+  *                   number of axis in the font).
+  *     coords     :: design coordinates
+  *
+  *  <Return>
+  *     Error code. 0 means success.
+  *
+  */
+  FT_EXPORT_DEF(FT_Error)   FT_Set_MM_Design_Coordinates( FT_Face  face,
+                                                          FT_UInt  num_coords,
+                                                          FT_Long* coords );
+
+ /*************************************************************************
+  *
+  *  <Function>
+  *     FT_Set_MM_Blend_Coordinates
+  *
+  *  <Description>
+  *     For multiple masters fonts, choose an interpolated font design
+  *     through normalized blend coordinates
+  *
+  *  <Input>
+  *     face       :: handle to source face
+  *     num_coords :: number of design coordinates (must be equal to the
+  *                   number of axis in the font).
+  *     coords     :: design coordinates (each one must be between 0 and 1.0)
+  *
+  *  <Return>
+  *     Error code. 0 means success.
+  *
+  */
+  FT_EXPORT_DEF(FT_Error)   FT_Set_MM_Blend_Coordinates( FT_Face   face,
+                                                         FT_UInt   num_coords,
+                                                         FT_Fixed* coords );
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif /* FTMM_H */
+/* END */
diff --git a/src/base/ftmm.c b/src/base/ftmm.c
new file mode 100644
index 0000000..f9943bf
--- /dev/null
+++ b/src/base/ftmm.c
@@ -0,0 +1,66 @@
+#include <freetype/ftmm.h>
+#include <freetype/internal/ftobjs.h>
+
+  FT_EXPORT_FUNC(FT_Error)   FT_Get_Multi_Master( FT_Face           face,
+                                                  FT_Multi_Master*  master )
+  {
+    FT_Error  error;
+    
+    error = FT_Err_Invalid_Argument;
+    if (face && FT_HAS_MULTIPLE_MASTERS(face))
+    {
+      FT_Driver       driver = face->driver;
+      FT_Get_MM_Func  func;
+
+      func   = (FT_Get_MM_Func)driver->interface.get_interface(
+                                                   driver, "get_mm" );
+      if (func)
+        error = func(face,master);
+    }
+      
+    return error;
+  }                                                  
+
+
+  FT_EXPORT_FUNC(FT_Error)   FT_Set_MM_Design_Coordinates( FT_Face  face,
+                                                           FT_UInt  num_coords,
+                                                           FT_Long* coords )
+  {
+    FT_Error  error;
+    
+    error = FT_Err_Invalid_Argument;
+    if (face && FT_HAS_MULTIPLE_MASTERS(face))
+    {
+      FT_Driver              driver = face->driver;
+      FT_Set_MM_Design_Func  func;
+
+      func = (FT_Set_MM_Design_Func)driver->interface.get_interface(
+                                             driver, "set_mm_design" );
+      if (func)
+        error = func(face,num_coords,coords);
+    }
+      
+    return error;
+  }                                                           
+
+  FT_EXPORT_FUNC(FT_Error)   FT_Set_MM_Blend_Coordinates( FT_Face   face,
+                                                          FT_UInt   num_coords,
+                                                          FT_Fixed* coords )
+  {                                                          
+    FT_Error  error;
+    
+    error = FT_Err_Invalid_Argument;
+    if (face && FT_HAS_MULTIPLE_MASTERS(face))
+    {
+      FT_Driver              driver = face->driver;
+      FT_Set_MM_Blend_Func  func;
+
+      func = (FT_Set_MM_Blend_Func)driver->interface.get_interface(
+                                             driver, "set_mm_blend" );
+      if (func)
+        error = func(face,num_coords,coords);
+    }
+      
+    return error;
+  }
+
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index dbaac4d..e515562 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1638,6 +1638,12 @@
     memory    = driver->memory;
 
     /* default processing - this can be overriden by the driver */
+    if (pixel_width == 0)
+      pixel_width = pixel_height;
+      
+    else if (pixel_height == 0)
+      pixel_height = pixel_width;
+      
     if ( pixel_width  < 1 ) pixel_width  = 1;
     if ( pixel_height < 1 ) pixel_height = 1;
 
diff --git a/src/base/rules.mk b/src/base/rules.mk
index dd0f1a6..367f34b 100644
--- a/src/base/rules.mk
+++ b/src/base/rules.mk
@@ -56,6 +56,7 @@ BASE_H := $(INTERNAL_)ftcalc.h    \
 #
 BASE_EXT_SRC := $(BASE_)ftraster.c \
                 $(BASE_)ftglyph.c  \
+                $(BASE_)ftmm.c     \
                 $(BASE_)ftgrays.c
 
 # Base layer extensions headers
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index dcc163b..3c6b889 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -1,4 +1,5 @@
 #include <freetype/internal/sfnt.h>
+#include <freetype/internal/ftobjs.h>
 #include <sfdriver.h>
 #include <ttload.h>
 #include <ttsbit.h>
diff --git a/src/type1z/t1driver.c b/src/type1z/t1driver.c
index c6dba1a..b086d53 100644
--- a/src/type1z/t1driver.c
+++ b/src/type1z/t1driver.c
@@ -26,7 +26,6 @@
 #undef  FT_COMPONENT
 #define FT_COMPONENT  trace_t1driver
 
-#ifndef T1_CONFIG_OPTION_NO_AFM
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
@@ -59,15 +58,28 @@
                                      const FT_String*  interface )
   {
     UNUSED(driver);
-
+    UNUSED(interface);
+    
+#ifndef T1_CONFIG_OPTION_NO_AFM
     if ( strcmp( (const char*)interface, "attach_file" ) == 0 )
       return (FTDriver_Interface)T1_Read_AFM;
+#endif
+
+#ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
+    if ( strcmp( (const char*)interface, "get_mm" ) == 0 )
+      return (FTDriver_Interface)T1_Get_Multi_Master;
+      
+    if ( strcmp( (const char*)interface, "set_mm_design") == 0 )
+      return (FTDriver_Interface)T1_Set_MM_Design;      
 
+    if ( strcmp( (const char*)interface, "set_mm_blend") == 0 )
+      return (FTDriver_Interface)T1_Set_MM_Blend;      
+#endif
     return 0;
   }
 
 
-
+#ifndef T1_CONFIG_OPTION_NO_AFM
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
@@ -375,11 +387,7 @@
     (FTDriver_initDriver)           T1_Init_Driver,
     (FTDriver_doneDriver)           T1_Done_Driver,
 
-#ifdef T1_CONFIG_OPTION_NO_AFM
-    (FTDriver_getInterface)         0,
-#else
     (FTDriver_getInterface)         Get_Interface,
-#endif
 
     (FTDriver_initFace)             T1_Init_Face,
     (FTDriver_doneFace)             T1_Done_Face,
diff --git a/src/type1z/t1load.c b/src/type1z/t1load.c
index b3beb3e..f1de8dc 100644
--- a/src/type1z/t1load.c
+++ b/src/type1z/t1load.c
@@ -61,6 +61,7 @@
 
 #include <freetype/internal/ftdebug.h>
 #include <freetype/config/ftconfig.h>
+#include <freetype/ftmm.h>
 
 #include <freetype/internal/t1types.h>
 #include <t1errors.h>
@@ -70,6 +71,7 @@
 #undef  FT_COMPONENT
 #define FT_COMPONENT  trace_t1load
 
+#ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
  /***************************************************************************/
  /***************************************************************************/
  /*****                                                                 *****/
@@ -146,7 +148,135 @@
    goto Exit;
  }                                  
 
+ LOCAL_FUNC  FT_Error  T1_Get_Multi_Master( T1_Face          face,
+                                            FT_Multi_Master* master )
+ {
+   T1_Blend*  blend = face->blend;
+   T1_UInt    n;
+   FT_Error   error;
+   
+   error = FT_Err_Invalid_Argument;
+   if (blend)
+   {
+     master->num_axis    = blend->num_axis;
+     master->num_designs = blend->num_designs;
+     for ( n = 0; n < blend->num_axis; n++ )
+     {
+       FT_MM_Axis*    axis = master->axis + n;
+       T1_DesignMap*  map = blend->design_map + n;
+       
+       axis->name    = blend->axis_names[n];
+       axis->minimum = map->design_points[0];
+       axis->maximum = map->design_points[map->num_points-1];
+     }
+     error = 0;
+   }
+   return error;
+ }                                            
+
+
+ LOCAL_FUNC  FT_Error  T1_Set_MM_Blend( T1_Face    face,
+                                        T1_UInt    num_coords,
+                                        T1_Fixed*  coords )
+ {
+   T1_Blend*  blend = face->blend;
+   FT_Error   error;
+   T1_UInt    n, m;
+   
+   error = FT_Err_Invalid_Argument;
+   if (blend && blend->num_axis == num_coords)
+   {
+     /* recompute the weight vector from the blend coordinates */
+     error = 0;
+     for ( n = 0; n < blend->num_designs; n++ )
+     {
+       FT_Fixed  result = 0x10000L;  /* 1.0 fixed */
+       for ( m = 0; m < blend->num_axis; m++ )
+       {
+         FT_Fixed  factor;
 
+         /* get current blend axis position */
+         factor = coords[m];
+         if (factor < 0) factor = 0;
+         if (factor > 0x10000L) factor = 0x10000L;
+         
+         if ((n & (1 << m)) == 0)
+           factor = 0x10000L - factor;
+           
+         result = FT_MulFix( result, factor );
+       }
+       blend->weight_vector[n] = result;
+     }
+     error = 0;
+   }
+   return error;
+ }
+ 
+
+ LOCAL_FUNC  FT_Error  T1_Set_MM_Design( T1_Face   face,
+                                         T1_UInt   num_coords,
+                                         T1_Long*  coords )
+ {
+   T1_Blend*  blend = face->blend;
+   FT_Error   error;
+   T1_UInt    n, p;
+   
+   error = FT_Err_Invalid_Argument;
+   if (blend && blend->num_axis == num_coords)
+   {
+     /* compute the blend coordinates through the blend design map */
+     T1_Fixed  final_blends[ T1_MAX_MM_DESIGNS ];
+     
+     for ( n = 0; n < blend->num_axis; n++ )
+     {
+       T1_Long        design = coords[n];
+       T1_Fixed       the_blend;
+       T1_DesignMap*  map     = blend->design_map + n;
+       T1_Fixed*      designs = map->design_points;
+       T1_Fixed*      blends  = map->blend_points;
+       T1_Int         before = -1, after = -1;
+       
+       for ( p = 0; p < map->num_points; p++ )
+       {
+         T1_Fixed  p_design = designs[p];
+         
+         /* exact match ? */
+         if (design == p_design)
+         {
+           the_blend = blends[p];
+           goto Found;
+         }
+         
+         if (design < p_design)
+         {
+           after = p;
+           break;
+         }
+         
+         before = p;
+       }
+       
+       /* now, interpolate if needed */
+       if (before < 0)
+         the_blend = blends[0];
+         
+       else if (after < 0)
+         the_blend = blends[map->num_points-1];
+         
+       else
+         the_blend = FT_MulDiv( design         - designs[before],
+                                blends [after] - blends [before],
+                                designs[after] - designs[before] );
+     Found:
+       final_blends[n] = the_blend;
+     }
+
+     error = T1_Set_MM_Blend( face, num_coords, final_blends );     
+   }
+   return error;
+ }
+
+ 
  LOCAL_FUNC  void T1_Done_Blend( T1_Face  face )
  {
    FT_Memory  memory = face->root.memory;
@@ -193,6 +323,7 @@
  }
 
 
+
  static  void  parse_blend_axis_types( T1_Face  face, T1_Loader*  loader )
  {
    T1_Token_Rec  axis_tokens[ T1_MAX_MM_AXIS ];
@@ -446,6 +577,7 @@
    parser->cursor = parser->limit;
    parser->error  = 0;
  }
+#endif
  
  /***************************************************************************/
  /***************************************************************************/
diff --git a/src/type1z/t1load.h b/src/type1z/t1load.h
index 47ca78b..8535597 100644
--- a/src/type1z/t1load.h
+++ b/src/type1z/t1load.h
@@ -48,6 +48,18 @@
 
 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
   LOCAL_DEF
+  FT_Error  T1_Get_Multi_Master( T1_Face          face,
+                                 FT_Multi_Master* master );
+
+  LOCAL_DEF  FT_Error  T1_Set_MM_Blend( T1_Face    face,
+                                        T1_UInt    num_coords,
+                                        T1_Fixed*  coords );
+
+  LOCAL_DEF  FT_Error  T1_Set_MM_Design( T1_Face   face,
+                                         T1_UInt   num_coords,
+                                         T1_Long*  coords );
+
+  LOCAL_DEF
   void T1_Done_Blend( T1_Face  face );
 #endif