summaryrefslogtreecommitdiff
path: root/include/freetype/internal/pshints.h
blob: bf9814aef3bd23d626a89faffc28c07e56c7c950 (plain)
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
/***************************************************************************/
/*                                                                         */
/*  pshints.h                                                              */
/*                                                                         */
/*    Interface to Postscript-specific (Type 1 and Type 2) hints           */
/*    recorders. These are used to support native T1/T2 hints              */
/*    in the "type1", "cid" and "cff" font drivers                         */
/*                                                                         */
/*  Copyright 2001 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 __PSHINTS_H__
#define __PSHINTS_H__

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_POSTSCRIPT_GLOBALS_H

FT_BEGIN_HEADER

 /**********************************************************************/
 /**********************************************************************/
 /*****                                                            *****/
 /*****               EXTERNAL REPRESENTATION OF GLOBALS           *****/
 /*****                                                            *****/
 /**********************************************************************/
 /**********************************************************************/

 /****************************************************************
  *
  * @constant: PS_GLOBALS_MAX_BLUE_ZONES
  *
  * @description:
  *   the maximum number of blue zones in a font global hints
  *   structure. See @PS_Globals_BluesRec
  */                                             
#define  PS_GLOBALS_MAX_BLUE_ZONES  16

 /****************************************************************
  *
  * @constant: PS_GLOBALS_MAX_STD_WIDTHS
  *
  * @description:
  *   the maximum number of standard and snap widths in either the
  *   horizontal or vertical direction. See @PS_Globals_WidthsRec
  */                                             
#define  PS_GLOBALS_MAX_STD_WIDTHS  16

 /****************************************************************
  *
  * @type: PS_Globals
  *
  * @description:
  *   a handle to a @PS_GlobalsRec structure used to
  *   describe the global hints of a given font
  */                                             
  typedef struct PS_GlobalsRec_*    PS_Globals;
                                             
 /****************************************************************
  *
  * @struct: PS_Globals_BluesRec
  *
  * @description:
  *   a structure used to model the global blue zones of a given
  *   font
  *
  * @fields:
  *   count        :: number of blue zones
  *   zones        :: an array of (count*2) coordinates describing the zones
  *
  *   count_family :: number of family blue zones
  *   zones_family :: an array of (count_family*2) coordinates describing
  *                   the family blue zones
  *
  *   scale  :: the blue scale to be used (fixed float)
  *   shift  :: the blue shift to be used
  *   fuzz   :: the blue fuzz to be used
  *
  * @note:
  *   each blue zone is modeled by a (reference,overshoot) coordinate pair
  *   in the table. zones can be placed in any order..
  */                                             
  typedef struct PS_Globals_BluesRec
  {                    
    FT_UInt    count;
    FT_Int16   zones[ 2*PS_GLOBALS_MAX_BLUE_ZONES ];
    
    FT_UInt    count_family;
    FT_Int16   zones_family[ 2*PS_GLOBALS_MAX_BLUE_ZONES ];

    FT_Fixed   scale;
    FT_Int16   shift;
    FT_Int16   fuzz;
  
  } PS_Globals_BluesRec, *PS_Globals_Blues;


 /****************************************************************
  *
  * @type: PS_Global_Widths;
  *
  * @description:
  *   a handle to a @PS_Globals_WidthsRec structure used to model
  *   the global standard and snap widths in a given direction
  */                                             
  typedef struct PS_Globals_WidthsRec_*  PS_Globals_Widths;
  

 /****************************************************************
  *
  * @struct: PS_Globals_WidthsRec
  *
  * @description:
  *   a structure used to model the global standard and snap widths
  *   in a given font
  *
  * @fields:
  *   count  :: number of widths
  *   widths :: an array of 'count' widths in font units.
  *
  * @note:
  *   'widths[0]' must be the standard width or height, while
  *   remaining elements of the array are snap widths or heights
  */                                             
  typedef struct PS_Globals_WidthsRec_
  {                     
    FT_UInt    count;
    FT_Int16   widths[ PS_GLOBALS_MAX_STD_WIDTHS ];
  
  } PS_Globals_WidthsRec;

  
 /****************************************************************
  *
  * @struct: PS_Globals_GlobalsRec
  *
  * @description:
  *   a structure used to model the global hints for a given font
  *
  * @fields:
  *   horizontal :: horizontal widths
  *   vertical   :: vertical heights
  *   blues      :: blue zones
  */                                             
  typedef struct PS_GlobalsRec_
  {
    PS_Globals_WidthsRec  horizontal;
    PS_Globals_WidthsRec  vertical;
    PS_Globals_BluesRec   blues;
  
  } PS_GlobalsRec;
 

 /**********************************************************************/
 /**********************************************************************/
 /*****                                                            *****/
 /*****               INTERNAL REPRESENTATION OF GLOBALS           *****/
 /*****                                                            *****/
 /**********************************************************************/
 /**********************************************************************/

  typedef struct PSH_GlobalsRec_*   PSH_Globals;
  
  typedef FT_Error  (*PSH_Globals_NewFunc)( FT_Memory     memory,
                                            PSH_Globals*  aglobals );

  typedef FT_Error  (*PSH_Globals_ResetFunc)( PSH_Globals   globals,
                                              PS_Globals    ps_globals );
  
  typedef FT_Error  (*PSH_Globals_SetScaleFunc)( PSH_Globals  globals,
                                                 FT_Fixed     x_scale,
                                                 FT_Fixed     y_scale,
                                                 FT_Fixed     x_delta,
                                                 FT_Fixed     y_delta );
                                              
  typedef void      (*PSH_Globals_DestroyFunc)( PSH_Globals  globals );                                          

  typedef struct
  {
    PSH_Globals_NewFunc       create;
    PSH_Globals_ResetFunc     reset;
    PSH_Globals_SetScaleFunc  set_scale;
    PSH_Globals_DestroyFunc   destroy;
    
  } PSH_Globals_FuncsRec, *PSH_Globals_Funcs;

 /**********************************************************************/
 /**********************************************************************/
 /*****                                                            *****/
 /*****                  PUBLIC TYPE 1 HINTS RECORDER              *****/
 /*****                                                            *****/
 /**********************************************************************/
 /**********************************************************************/

 /************************************************************************
  *
  * @type: T1_Hints
  *
  * @description:
  *   this is a handle to an opaque structure used to record glyph
  *   hints from a Type 1 character glyph character string.
  *
  *   the methods used to operate on this object are defined by the
  *   @T1_Hints_FuncsRec structure. Recording glyph hints is normally
  *   achieved through the following scheme:
  *
  *     - open a new hint recording session by calling the "open"
  *       method. This will rewind the recorder and prepare it for
  *       new input
  *
  *     - for each hint found in the glyph charstring, call the
  *       corresponding method ("stem", "stem3" or "reset").
  *       note that these functions do not return an error code
  *
  *     - close the recording session by calling the "close" method
  *       it will return an error code if the hints were invalid or
  *       something strange happened (e.g. memory shortage)
  *  
  *  the hints accumulated in the object can later be used by the
  *  Postscript hinter
  */
  typedef struct T1_HintsRec_*   T1_Hints;
  
 /************************************************************************
  *
  * @type: T1_Hints_Funcs
  *
  * @description:
  *   a pointer to the @T1_Hints_FuncsRec structure that defines the
  *   API of a given @T1_Hints object
  */
  typedef const struct T1_Hints_FuncsRec_*  T1_Hints_Funcs;
  

 /************************************************************************
  *
  * @functype: T1_Hints_OpenFunc
  *
  * @description:
  *   a method of the @T1_Hints class used to prepare it for a new
  *   Type 1 hints recording session
  *
  * @input:
  *   hints :: handle to Type 1 hints recorder
  *
  * @note:
  *  You should always call the @T1_Hints_CloseFunc method in order
  *  to close an opened recording session
  */
  typedef void      (*T1_Hints_OpenFunc)      ( T1_Hints  hints );

 /************************************************************************
  *
  * @functype: T1_Hints_SetStemFunc
  *
  * @description:
  *   a method of the @T1_Hints class used to record a new horizontal or
  *   vertical stem. This corresponds to the Type 1 "hstem" and "vstem"
  *   operators
  *
  * @input:
  *   hints     :: handle to Type 1 hints recorder
  *   dimension :: 0 for horizontal stems (hstem), 1 for vertical ones (vstem)
  *   coords    :: array of 2 integers, used as (position,length) stem descriptor
  *
  * @note:
  *   use vertical coordinates   (y) for horizontal stems (dim=0)
  *   use horizontal coordinates (x) for vertical   stems (dim=1)
  *
  *   "coords[0]" is the absolute stem position (lowest coordinate)
  *   "coords[1]" is the length.
  *
  *   the length can be negative, in which case it must be either
  *   -20 or -21 in order and will be interpreted as a "ghost" stem,
  *   according to the Type 1 specification.
  *
  *   if the length is -21 (corresponding to a bottom ghost stem), then
  *   the real stem position is "coords[0]+coords[1]"
  */
  typedef void      (*T1_Hints_SetStemFunc)   ( T1_Hints  hints,
                                                FT_UInt   dimension,
                                                FT_Long*  coords );

 /************************************************************************
  *
  * @functype: T1_Hints_SetStem3Func
  *
  * @description:
  *   a method of the @T1_Hints class used to record three counter-controlled
  *   horizontal or vertical stems at once
  *
  * @input:
  *   hints     :: handle to Type 1 hints recorder
  *   dimension :: 0 for horizontal stems, 1 for vertical ones
  *   coords    :: array of 6 integers, i.e. 3 (position,length) pairs
  *                for the counter-controlled stems
  *
  * @note:
  *   use vertical coordinates   (y) for horizontal stems (dim=0)
  *   use horizontal coordinates (x) for vertical   stems (dim=1)
  *
  *   the lengths cannot be negative (ghost stems are never counter-controlled)
  */
  typedef void      (*T1_Hints_SetStem3Func)  ( T1_Hints  hints,
                                                FT_UInt   dimension,
                                                FT_Long*  coords );

 /************************************************************************
  *
  * @functype: T1_Hints_ResetFunc
  *
  * @description:
  *   a method of the @T1_Hints class used to reset the stems hints
  *   in a recording session. This is equivalent to the Type 1 ...
  *
  * @input:
  *   hints     :: handle to Type 1 hints recorder
  *   end_point :: index of last point in the input glyph in which
  *                the previously defined hints apply
  */
  typedef void      (*T1_Hints_ResetFunc)( T1_Hints  hints,
                                           FT_UInt   end_point );

 /************************************************************************
  *
  * @functype: T1_Hints_CloseFunc
  *
  * @description:
  *   a method of the @T1_Hints class used to close a hint recording
  *   session.
  *
  * @input:
  *   hints     :: handle to Type 1 hints recorder
  *   end_point :: index of last point in the input glyph
  *
  * @return:
  *   error code. 0 means success
  *
  * @note:
  *   the error code will be set to indicate that an error occured
  *   during the recording session
  */
  typedef FT_Error  (*T1_Hints_CloseFunc)( T1_Hints  hints,
                                           FT_UInt   end_point );


 /************************************************************************
  *
  * @functype: T1_Hints_ApplyFunc
  *
  * @description:
  *   a method of the @T1_Hints class used to apply hints to the
  *   corresponding glyph outline. Must be called once all hints
  *   have been recorded.
  *
  * @input:
  *   hints     :: handle to Type 1 hints recorder
  *   outline   :: pointer to target outline descriptor
  *   globals   :: the hinter globals for this font
  *
  * @return:
  *   error code. 0 means success
  *
  * @note:
  *   on input, all points within the outline are in font coordinates.
  *   on output, they're in 1/64th of pixels.
  *
  *   the scaling transform is taken from the "globals" object, which
  *   must correspond to the same font than the glyph
  */
  typedef FT_Error  (*T1_Hints_ApplyFunc)( T1_Hints     hints,
                                           FT_Outline*  outline,
                                           PSH_Globals  globals );
  

 /************************************************************************
  *
  * @struct: T1_Hints_FuncsRec
  *
  * @description:
  *   the structure used to provide the API to @T1_Hints objects
  *
  * @fields:
  *   hints  :: handle to T1 Hints recorder
  *   open   :: open recording session
  *   close  :: close recording session
  *   stem   :: set simple stem
  *   stem3  :: set counter-controlled stems
  *   reset  :: reset stem hints
  *   apply  :: apply the hints to the corresponding glyph outline
  */
  typedef struct T1_Hints_FuncsRec_
  {
    T1_Hints                hints;
    T1_Hints_OpenFunc       open;
    T1_Hints_CloseFunc      close;
    T1_Hints_SetStemFunc    stem;
    T1_Hints_SetStem3Func   stem3;
    T1_Hints_ResetFunc      reset;
    T1_Hints_ApplyFunc      apply;
  
  } T1_Hints_FuncsRec;


 /**********************************************************************/
 /**********************************************************************/
 /*****                                                            *****/
 /*****                  PUBLIC TYPE 2 HINTS RECORDER              *****/
 /*****                                                            *****/
 /**********************************************************************/
 /**********************************************************************/


 /************************************************************************
  *
  * @type: T2_Hints
  *
  * @description:
  *   this is a handle to an opaque structure used to record glyph
  *   hints from a Type 2 character glyph character string.
  *
  *   the methods used to operate on this object are defined by the
  *   @T2_Hints_FuncsRec structure. Recording glyph hints is normally
  *   achieved through the following scheme:
  *
  *     - open a new hint recording session by calling the "open"
  *       method. This will rewind the recorder and prepare it for
  *       new input
  *
  *     - for each hint found in the glyph charstring, call the
  *       corresponding method ("stems", "hintmask", "counters").
  *       note that these functions do not return an error code
  *
  *     - close the recording session by calling the "close" method
  *       it will return an error code if the hints were invalid or
  *       something strange happened (e.g. memory shortage)
  *  
  *  the hints accumulated in the object can later be used by the
  *  Postscript hinter
  */
  typedef struct T2_HintsRec_*   T2_Hints;

 /************************************************************************
  *
  * @type: T2_Hints_Funcs
  *
  * @description:
  *   a pointer to the @T1_Hints_FuncsRec structure that defines the
  *   API of a given @T2_Hints object
  */
  typedef const struct T2_Hints_FuncsRec_*  T2_Hints_Funcs;

 /************************************************************************
  *
  * @functype: T2_Hints_OpenFunc
  *
  * @description:
  *   a method of the @T2_Hints class used to prepare it for a new
  *   Type 2 hints recording session
  *
  * @input:
  *   hints :: handle to Type 2 hints recorder
  *
  * @note:
  *  You should always call the @T2_Hints_CloseFunc method in order
  *  to close an opened recording session
  */
  typedef void      (*T2_Hints_OpenFunc)   ( T2_Hints  hints );  


 /************************************************************************
  *
  * @functype: T2_Hints_StemsFunc
  *
  * @description:
  *   a method of the @T2_Hints class used to set the table of stems
  *   in either the vertical or horizontal dimension. Equivalent to the
  *   "hstem", "vstem", "hstemhm" and "vstemhm" Type 2 operators
  *
  * @input:
  *   hints       :: handle to Type 2 hints recorder
  *   dimension   :: 0 for horizontal stems (hstem), 1 for vertical ones (vstem)
  *   count       :: number of stems
  *   coordinates :: an array of "count" (position,length) pairs
  *
  * @note:
  *   use vertical coordinates   (y) for horizontal stems (dim=0)
  *   use horizontal coordinates (x) for vertical   stems (dim=1)
  *
  *   there are "2*count" elements in the "coordinates" array. Each
  *   even element is an absolute position in font units, each odd
  *   element is a length in font units
  *
  *   a length can be negative, in which case it must be either
  *   -20 or -21 in order and will be interpreted as a "ghost" stem,
  *   according to the Type 1 specification.
  */
  typedef void      (*T2_Hints_StemsFunc)  ( T2_Hints   hints,
                                             FT_UInt    dimension,
                                             FT_UInt    count,
                                             FT_Fixed*  coordinates );
                                                
 /************************************************************************
  *
  * @functype: T2_Hints_MaskFunc
  *
  * @description:
  *   a method of the @T2_Hints class used to set a given hintmask
  *   (correspond to the "hintmask" Type 2 operator)
  *
  * @input:
  *   hints       :: handle to Type 2 hints recorder
  *   end_point   :: glyph index of the last point to which the previously
  *                  defined/active hints apply.
  *   bit_count   :: number of bits in the hint mask.
  *   bytes       :: an array of bytes modelling the hint mask
  *                  
  * @note:
  *   if the hintmask starts the charstring (before any glyph point
  *   definition), the value of "end_point" should be 0
  *
  *   "bit_count" is the number of meaningful bits in the "bytes" array,
  *   and must be equal to the total number of hints defined so far
  *   (i.e. horizontal+verticals)
  *
  *   the "bytes" array can come directly from the Type 2 charstring
  *   and respect the same format.
  */
  typedef void      (*T2_Hints_MaskFunc)   ( T2_Hints        hints,
                                             FT_UInt         end_point,
                                             FT_UInt         bit_count,
                                             const FT_Byte*  bytes );

 /************************************************************************
  *
  * @functype: T2_Hints_CounterFunc
  *
  * @description:
  *   a method of the @T2_Hints class used to set a given counter
  *   mask (correspond to the "hintmask" Type 2 operator)
  *
  * @input:
  *   hints       :: handle to Type 2 hints recorder
  *   end_point   :: glyph index of the last point to which the previously
  *                  defined/active hints apply.
  *   bit_count   :: number of bits in the hint mask.
  *   bytes       :: an array of bytes modelling the hint mask
  *                  
  * @note:
  *   if the hintmask starts the charstring (before any glyph point
  *   definition), the value of "end_point" should be 0
  *
  *   "bit_count" is the number of meaningful bits in the "bytes" array,
  *   and must be equal to the total number of hints defined so far
  *   (i.e. horizontal+verticals)
  *
  *   the "bytes" array can come directly from the Type 2 charstring
  *   and respect the same format.
  */
  typedef void      (*T2_Hints_CounterFunc)( T2_Hints        hints,
                                             FT_UInt         bit_count,
                                             const FT_Byte*  bytes );

 /************************************************************************
  *
  * @functype: T2_Hints_CloseFunc
  *
  * @description:
  *   a method of the @T2_Hints class used to close a hint recording
  *   session.
  *
  * @input:
  *   hints     :: handle to Type 2 hints recorder
  *   end_point :: index of last point in the input glyph
  *
  * @return:
  *   error code. 0 means success
  *
  * @note:
  *   the error code will be set to indicate that an error occured
  *   during the recording session
  */
  typedef FT_Error  (*T2_Hints_CloseFunc)  ( T2_Hints        hints,
                                             FT_UInt         end_point );


 /************************************************************************
  *
  * @functype: T2_Hints_ApplyFunc
  *
  * @description:
  *   a method of the @T2_Hints class used to apply hints to the
  *   corresponding glyph outline. Must be called after the "close" method
  *
  * @input:
  *   hints     :: handle to Type 2 hints recorder
  *   outline   :: pointer to target outline descriptor
  *   globals   :: the hinter globals for this font
  *
  * @return:
  *   error code. 0 means success
  *
  * @note:
  *   on input, all points within the outline are in font coordinates.
  *   on output, they're in 1/64th of pixels.
  *
  *   the scaling transform is taken from the "globals" object, which
  *   must correspond to the same font than the glyph
  */
  typedef FT_Error  (*T2_Hints_ApplyFunc)( T2_Hints     hints,
                                           FT_Outline*  outline,
                                           PSH_Globals  globals );
  

 /************************************************************************
  *
  * @struct: T2_Hints_FuncsRec
  *
  * @description:
  *   the structure used to provide the API to @T2_Hints objects
  *
  * @fields:
  *   hints    :: handle to T2 hints recorder object
  *   open     :: open recording session
  *   close    :: close recording session
  *   stems    :: set dimension's stems table
  *   hintmask :: set hint masks
  *   counter  :: set counter masks
  *   apply    :: apply the hints on the corresponding glyph outline
  */
  typedef struct T2_Hints_FuncsRec_
  {
    T2_Hints              hints;
    T2_Hints_OpenFunc     open;
    T2_Hints_CloseFunc    close;
    T2_Hints_StemsFunc    stems;
    T2_Hints_MaskFunc     hintmask;
    T2_Hints_CounterFunc  counter;
    T2_Hints_ApplyFunc    apply;
  
  } T2_Hints_FuncsRec;


  /* */
  
  typedef struct PSHinter_Interface_
  {
    PSH_Globals_Funcs  (*get_globals_funcs)( FT_Module  module );
    T1_Hints_Funcs     (*get_t1_funcs)     ( FT_Module  module );
    T2_Hints_Funcs     (*get_t2_funcs)     ( FT_Module  module );
    
  } PSHinter_Interface, *PSHinter_InterfacePtr;

FT_END_HEADER

#endif /* __PSHINTS_H__ */