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]
cffobjs.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* cffobjs.c */
4 /* */
5 /* OpenType objects manager (body). */
6 /* */
7 /* Copyright 1996-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 
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_CALC_H
23 #include FT_INTERNAL_STREAM_H
24 #include FT_ERRORS_H
25 #include FT_TRUETYPE_IDS_H
26 #include FT_TRUETYPE_TAGS_H
27 #include FT_INTERNAL_SFNT_H
28 #include FT_CFF_DRIVER_H
29 
30 #include "cffobjs.h"
31 #include "cffload.h"
32 #include "cffcmap.h"
33 #include "cffpic.h"
34 
35 #include "cfferrs.h"
36 
37 
38  /*************************************************************************/
39  /* */
40  /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
41  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
42  /* messages during execution. */
43  /* */
44 #undef FT_COMPONENT
45 #define FT_COMPONENT trace_cffobjs
46 
47 
48  /*************************************************************************/
49  /* */
50  /* SIZE FUNCTIONS */
51  /* */
52  /* Note that we store the global hints in the size's `internal' root */
53  /* field. */
54  /* */
55  /*************************************************************************/
56 
57 
58  static PSH_Globals_Funcs
59  cff_size_get_globals_funcs( CFF_Size size )
60  {
61  CFF_Face face = (CFF_Face)size->root.face;
62  CFF_Font font = (CFF_Font)face->extra.data;
63  PSHinter_Service pshinter = font->pshinter;
64  FT_Module module;
65 
66 
67  module = FT_Get_Module( size->root.face->driver->root.library,
68  "pshinter" );
69  return ( module && pshinter && pshinter->get_globals_funcs )
70  ? pshinter->get_globals_funcs( module )
71  : 0;
72  }
73 
74 
75  FT_LOCAL_DEF( void )
76  cff_size_done( FT_Size cffsize ) /* CFF_Size */
77  {
78  CFF_Size size = (CFF_Size)cffsize;
79  CFF_Face face = (CFF_Face)size->root.face;
80  CFF_Font font = (CFF_Font)face->extra.data;
81  CFF_Internal internal = (CFF_Internal)cffsize->internal;
82 
83 
84  if ( internal )
85  {
86  PSH_Globals_Funcs funcs;
87 
88 
89  funcs = cff_size_get_globals_funcs( size );
90  if ( funcs )
91  {
92  FT_UInt i;
93 
94 
95  funcs->destroy( internal->topfont );
96 
97  for ( i = font->num_subfonts; i > 0; i-- )
98  funcs->destroy( internal->subfonts[i - 1] );
99  }
100 
101  /* `internal' is freed by destroy_size (in ftobjs.c) */
102  }
103  }
104 
105 
106  /* CFF and Type 1 private dictionaries have slightly different */
107  /* structures; we need to synthesize a Type 1 dictionary on the fly */
108 
109  static void
110  cff_make_private_dict( CFF_SubFont subfont,
111  PS_Private priv )
112  {
113  CFF_Private cpriv = &subfont->private_dict;
114  FT_UInt n, count;
115 
116 
117  FT_MEM_ZERO( priv, sizeof ( *priv ) );
118 
119  count = priv->num_blue_values = cpriv->num_blue_values;
120  for ( n = 0; n < count; n++ )
121  priv->blue_values[n] = (FT_Short)cpriv->blue_values[n];
122 
123  count = priv->num_other_blues = cpriv->num_other_blues;
124  for ( n = 0; n < count; n++ )
125  priv->other_blues[n] = (FT_Short)cpriv->other_blues[n];
126 
127  count = priv->num_family_blues = cpriv->num_family_blues;
128  for ( n = 0; n < count; n++ )
129  priv->family_blues[n] = (FT_Short)cpriv->family_blues[n];
130 
131  count = priv->num_family_other_blues = cpriv->num_family_other_blues;
132  for ( n = 0; n < count; n++ )
133  priv->family_other_blues[n] = (FT_Short)cpriv->family_other_blues[n];
134 
135  priv->blue_scale = cpriv->blue_scale;
136  priv->blue_shift = (FT_Int)cpriv->blue_shift;
137  priv->blue_fuzz = (FT_Int)cpriv->blue_fuzz;
138 
139  priv->standard_width[0] = (FT_UShort)cpriv->standard_width;
140  priv->standard_height[0] = (FT_UShort)cpriv->standard_height;
141 
142  count = priv->num_snap_widths = cpriv->num_snap_widths;
143  for ( n = 0; n < count; n++ )
144  priv->snap_widths[n] = (FT_Short)cpriv->snap_widths[n];
145 
146  count = priv->num_snap_heights = cpriv->num_snap_heights;
147  for ( n = 0; n < count; n++ )
148  priv->snap_heights[n] = (FT_Short)cpriv->snap_heights[n];
149 
150  priv->force_bold = cpriv->force_bold;
151  priv->language_group = cpriv->language_group;
152  priv->lenIV = cpriv->lenIV;
153  }
154 
155 
157  cff_size_init( FT_Size cffsize ) /* CFF_Size */
158  {
159  CFF_Size size = (CFF_Size)cffsize;
161  PSH_Globals_Funcs funcs = cff_size_get_globals_funcs( size );
162 
163 
164  if ( funcs )
165  {
166  CFF_Face face = (CFF_Face)cffsize->face;
167  CFF_Font font = (CFF_Font)face->extra.data;
168  CFF_Internal internal = NULL;
169 
170  PS_PrivateRec priv;
171  FT_Memory memory = cffsize->face->memory;
172 
173  FT_UInt i;
174 
175 
176  if ( FT_NEW( internal ) )
177  goto Exit;
178 
179  cff_make_private_dict( &font->top_font, &priv );
180  error = funcs->create( cffsize->face->memory, &priv,
181  &internal->topfont );
182  if ( error )
183  goto Exit;
184 
185  for ( i = font->num_subfonts; i > 0; i-- )
186  {
187  CFF_SubFont sub = font->subfonts[i - 1];
188 
189 
190  cff_make_private_dict( sub, &priv );
191  error = funcs->create( cffsize->face->memory, &priv,
192  &internal->subfonts[i - 1] );
193  if ( error )
194  goto Exit;
195  }
196 
197  cffsize->internal = (FT_Size_Internal)(void*)internal;
198  }
199 
200  size->strike_index = 0xFFFFFFFFUL;
201 
202  Exit:
203  return error;
204  }
205 
206 
207 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
208 
210  cff_size_select( FT_Size size,
211  FT_ULong strike_index )
212  {
213  CFF_Size cffsize = (CFF_Size)size;
214  PSH_Globals_Funcs funcs;
215 
216 
217  cffsize->strike_index = strike_index;
218 
219  FT_Select_Metrics( size->face, strike_index );
220 
221  funcs = cff_size_get_globals_funcs( cffsize );
222 
223  if ( funcs )
224  {
225  CFF_Face face = (CFF_Face)size->face;
226  CFF_Font font = (CFF_Font)face->extra.data;
227  CFF_Internal internal = (CFF_Internal)size->internal;
228 
229  FT_ULong top_upm = font->top_font.font_dict.units_per_em;
230  FT_UInt i;
231 
232 
233  funcs->set_scale( internal->topfont,
234  size->metrics.x_scale, size->metrics.y_scale,
235  0, 0 );
236 
237  for ( i = font->num_subfonts; i > 0; i-- )
238  {
239  CFF_SubFont sub = font->subfonts[i - 1];
240  FT_ULong sub_upm = sub->font_dict.units_per_em;
241  FT_Pos x_scale, y_scale;
242 
243 
244  if ( top_upm != sub_upm )
245  {
246  x_scale = FT_MulDiv( size->metrics.x_scale, top_upm, sub_upm );
247  y_scale = FT_MulDiv( size->metrics.y_scale, top_upm, sub_upm );
248  }
249  else
250  {
251  x_scale = size->metrics.x_scale;
252  y_scale = size->metrics.y_scale;
253  }
254 
255  funcs->set_scale( internal->subfonts[i - 1],
256  x_scale, y_scale, 0, 0 );
257  }
258  }
259 
260  return FT_Err_Ok;
261  }
262 
263 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
264 
265 
268  FT_Size_Request req )
269  {
270  CFF_Size cffsize = (CFF_Size)size;
271  PSH_Globals_Funcs funcs;
272 
273 
274 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
275 
276  if ( FT_HAS_FIXED_SIZES( size->face ) )
277  {
278  CFF_Face cffface = (CFF_Face)size->face;
279  SFNT_Service sfnt = (SFNT_Service)cffface->sfnt;
280  FT_ULong strike_index;
281 
282 
283  if ( sfnt->set_sbit_strike( cffface, req, &strike_index ) )
284  cffsize->strike_index = 0xFFFFFFFFUL;
285  else
286  return cff_size_select( size, strike_index );
287  }
288 
289 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
290 
291  FT_Request_Metrics( size->face, req );
292 
293  funcs = cff_size_get_globals_funcs( cffsize );
294 
295  if ( funcs )
296  {
297  CFF_Face cffface = (CFF_Face)size->face;
298  CFF_Font font = (CFF_Font)cffface->extra.data;
299  CFF_Internal internal = (CFF_Internal)size->internal;
300 
301  FT_ULong top_upm = font->top_font.font_dict.units_per_em;
302  FT_UInt i;
303 
304 
305  funcs->set_scale( internal->topfont,
306  size->metrics.x_scale, size->metrics.y_scale,
307  0, 0 );
308 
309  for ( i = font->num_subfonts; i > 0; i-- )
310  {
311  CFF_SubFont sub = font->subfonts[i - 1];
312  FT_ULong sub_upm = sub->font_dict.units_per_em;
313  FT_Pos x_scale, y_scale;
314 
315 
316  if ( top_upm != sub_upm )
317  {
318  x_scale = FT_MulDiv( size->metrics.x_scale, top_upm, sub_upm );
319  y_scale = FT_MulDiv( size->metrics.y_scale, top_upm, sub_upm );
320  }
321  else
322  {
323  x_scale = size->metrics.x_scale;
324  y_scale = size->metrics.y_scale;
325  }
326 
327  funcs->set_scale( internal->subfonts[i - 1],
328  x_scale, y_scale, 0, 0 );
329  }
330  }
331 
332  return FT_Err_Ok;
333  }
334 
335 
336  /*************************************************************************/
337  /* */
338  /* SLOT FUNCTIONS */
339  /* */
340  /*************************************************************************/
341 
342  FT_LOCAL_DEF( void )
344  {
345  slot->internal->glyph_hints = 0;
346  }
347 
348 
351  {
352  CFF_Face face = (CFF_Face)slot->face;
353  CFF_Font font = (CFF_Font)face->extra.data;
354  PSHinter_Service pshinter = font->pshinter;
355 
356 
357  if ( pshinter )
358  {
359  FT_Module module;
360 
361 
362  module = FT_Get_Module( slot->face->driver->root.library,
363  "pshinter" );
364  if ( module )
365  {
366  T2_Hints_Funcs funcs;
367 
368 
369  funcs = pshinter->get_t2_funcs( module );
370  slot->internal->glyph_hints = (void*)funcs;
371  }
372  }
373 
374  return FT_Err_Ok;
375  }
376 
377 
378  /*************************************************************************/
379  /* */
380  /* FACE FUNCTIONS */
381  /* */
382  /*************************************************************************/
383 
384  static FT_String*
385  cff_strcpy( FT_Memory memory,
386  const FT_String* source )
387  {
388  FT_Error error;
389  FT_String* result;
390 
391 
392  (void)FT_STRDUP( result, source );
393 
394  FT_UNUSED( error );
395 
396  return result;
397  }
398 
399 
400  /* Strip all subset prefixes of the form `ABCDEF+'. Usually, there */
401  /* is only one, but font names like `APCOOG+JFABTD+FuturaBQ-Bold' */
402  /* have been seen in the wild. */
403 
404  static void
405  remove_subset_prefix( FT_String* name )
406  {
407  FT_Int32 idx = 0;
408  FT_Int32 length = strlen( name ) + 1;
409  FT_Bool continue_search = 1;
410 
411 
412  while ( continue_search )
413  {
414  if ( length >= 7 && name[6] == '+' )
415  {
416  for ( idx = 0; idx < 6; idx++ )
417  {
418  /* ASCII uppercase letters */
419  if ( !( 'A' <= name[idx] && name[idx] <= 'Z' ) )
420  continue_search = 0;
421  }
422 
423  if ( continue_search )
424  {
425  for ( idx = 7; idx < length; idx++ )
426  name[idx - 7] = name[idx];
427  length -= 7;
428  }
429  }
430  else
431  continue_search = 0;
432  }
433  }
434 
435 
436  /* Remove the style part from the family name (if present). */
437 
438  static void
439  remove_style( FT_String* family_name,
440  const FT_String* style_name )
441  {
442  FT_Int32 family_name_length, style_name_length;
443 
444 
445  family_name_length = strlen( family_name );
446  style_name_length = strlen( style_name );
447 
448  if ( family_name_length > style_name_length )
449  {
450  FT_Int idx;
451 
452 
453  for ( idx = 1; idx <= style_name_length; ++idx )
454  {
455  if ( family_name[family_name_length - idx] !=
456  style_name[style_name_length - idx] )
457  break;
458  }
459 
460  if ( idx > style_name_length )
461  {
462  /* family_name ends with style_name; remove it */
463  idx = family_name_length - style_name_length - 1;
464 
465  /* also remove special characters */
466  /* between real family name and style */
467  while ( idx > 0 &&
468  ( family_name[idx] == '-' ||
469  family_name[idx] == ' ' ||
470  family_name[idx] == '_' ||
471  family_name[idx] == '+' ) )
472  --idx;
473 
474  if ( idx > 0 )
475  family_name[idx + 1] = '\0';
476  }
477  }
478  }
479 
480 
483  FT_Face cffface, /* CFF_Face */
484  FT_Int face_index,
485  FT_Int num_params,
487  {
488  CFF_Face face = (CFF_Face)cffface;
489  FT_Error error;
490  SFNT_Service sfnt;
491  FT_Service_PsCMaps psnames;
492  PSHinter_Service pshinter;
493  FT_Bool pure_cff = 1;
494  FT_Bool sfnt_format = 0;
495  FT_Library library = cffface->driver->root.library;
496 
497 
499  library, "sfnt" );
500  if ( !sfnt )
501  {
502  FT_ERROR(( "cff_face_init: cannot access `sfnt' module\n" ));
503  error = FT_THROW( Missing_Module );
504  goto Exit;
505  }
506 
507  FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
508 
510  library, "pshinter" );
511 
512  FT_TRACE2(( "CFF driver\n" ));
513 
514  /* create input stream from resource */
515  if ( FT_STREAM_SEEK( 0 ) )
516  goto Exit;
517 
518  /* check whether we have a valid OpenType file */
519  error = sfnt->init_face( stream, face, face_index, num_params, params );
520  if ( !error )
521  {
522  if ( face->format_tag != TTAG_OTTO ) /* `OTTO'; OpenType/CFF font */
523  {
524  FT_TRACE2(( " not an OpenType/CFF font\n" ));
525  error = FT_THROW( Unknown_File_Format );
526  goto Exit;
527  }
528 
529  /* if we are performing a simple font format check, exit immediately */
530  if ( face_index < 0 )
531  return FT_Err_Ok;
532 
533  sfnt_format = 1;
534 
535  /* now, the font can be either an OpenType/CFF font, or an SVG CEF */
536  /* font; in the latter case it doesn't have a `head' table */
537  error = face->goto_table( face, TTAG_head, stream, 0 );
538  if ( !error )
539  {
540  pure_cff = 0;
541 
542  /* load font directory */
543  error = sfnt->load_face( stream, face, face_index,
544  num_params, params );
545  if ( error )
546  goto Exit;
547  }
548  else
549  {
550  /* load the `cmap' table explicitly */
551  error = sfnt->load_cmap( face, stream );
552  if ( error )
553  goto Exit;
554  }
555 
556  /* now load the CFF part of the file */
557  error = face->goto_table( face, TTAG_CFF, stream, 0 );
558  if ( error )
559  goto Exit;
560  }
561  else
562  {
563  /* rewind to start of file; we are going to load a pure-CFF font */
564  if ( FT_STREAM_SEEK( 0 ) )
565  goto Exit;
566  error = FT_Err_Ok;
567  }
568 
569  /* now load and parse the CFF table in the file */
570  {
571  CFF_Font cff = NULL;
572  CFF_FontRecDict dict;
573  FT_Memory memory = cffface->memory;
574  FT_Int32 flags;
575  FT_UInt i;
576 
577 
578  if ( FT_NEW( cff ) )
579  goto Exit;
580 
581  face->extra.data = cff;
582  error = cff_font_load( library, stream, face_index, cff, pure_cff );
583  if ( error )
584  goto Exit;
585 
586  cff->pshinter = pshinter;
587  cff->psnames = psnames;
588 
589  cffface->face_index = face_index;
590 
591  /* Complement the root flags with some interesting information. */
592  /* Note that this is only necessary for pure CFF and CEF fonts; */
593  /* SFNT based fonts use the `name' table instead. */
594 
595  cffface->num_glyphs = cff->num_glyphs;
596 
597  dict = &cff->top_font.font_dict;
598 
599  /* we need the `PSNames' module for CFF and CEF formats */
600  /* which aren't CID-keyed */
601  if ( dict->cid_registry == 0xFFFFU && !psnames )
602  {
603  FT_ERROR(( "cff_face_init:"
604  " cannot open CFF & CEF fonts\n"
605  " "
606  " without the `PSNames' module\n" ));
607  error = FT_THROW( Missing_Module );
608  goto Exit;
609  }
610 
611 #ifdef FT_DEBUG_LEVEL_TRACE
612  {
613  FT_UInt idx;
614  FT_String* s;
615 
616 
617  FT_TRACE4(( "SIDs\n" ));
618 
619  /* dump string index, including default strings for convenience */
620  for ( idx = 0; idx < cff->num_strings + 390; idx++ )
621  {
622  s = cff_index_get_sid_string( cff, idx );
623  if ( s )
624  FT_TRACE4((" %5d %s\n", idx, s ));
625  }
626  }
627 #endif /* FT_DEBUG_LEVEL_TRACE */
628 
629  if ( !dict->has_font_matrix )
630  dict->units_per_em = pure_cff ? 1000 : face->root.units_per_EM;
631 
632  /* Normalize the font matrix so that `matrix->xx' is 1; the */
633  /* scaling is done with `units_per_em' then (at this point, */
634  /* it already contains the scaling factor, but without */
635  /* normalization of the matrix). */
636  /* */
637  /* Note that the offsets must be expressed in integer font */
638  /* units. */
639 
640  {
641  FT_Matrix* matrix = &dict->font_matrix;
642  FT_Vector* offset = &dict->font_offset;
643  FT_ULong* upm = &dict->units_per_em;
644  FT_Fixed temp = FT_ABS( matrix->yy );
645 
646 
647  if ( temp != 0x10000L )
648  {
649  *upm = FT_DivFix( *upm, temp );
650 
651  matrix->xx = FT_DivFix( matrix->xx, temp );
652  matrix->yx = FT_DivFix( matrix->yx, temp );
653  matrix->xy = FT_DivFix( matrix->xy, temp );
654  matrix->yy = FT_DivFix( matrix->yy, temp );
655  offset->x = FT_DivFix( offset->x, temp );
656  offset->y = FT_DivFix( offset->y, temp );
657  }
658 
659  offset->x >>= 16;
660  offset->y >>= 16;
661  }
662 
663  for ( i = cff->num_subfonts; i > 0; i-- )
664  {
665  CFF_FontRecDict sub = &cff->subfonts[i - 1]->font_dict;
667 
668  FT_Matrix* matrix;
669  FT_Vector* offset;
670  FT_ULong* upm;
671  FT_Fixed temp;
672 
673 
674  if ( sub->has_font_matrix )
675  {
676  FT_Long scaling;
677 
678 
679  /* if we have a top-level matrix, */
680  /* concatenate the subfont matrix */
681 
682  if ( top->has_font_matrix )
683  {
684  if ( top->units_per_em > 1 && sub->units_per_em > 1 )
685  scaling = FT_MIN( top->units_per_em, sub->units_per_em );
686  else
687  scaling = 1;
688 
690  &sub->font_matrix,
691  scaling );
693  &top->font_matrix,
694  scaling );
695 
696  sub->units_per_em = FT_MulDiv( sub->units_per_em,
697  top->units_per_em,
698  scaling );
699  }
700  }
701  else
702  {
703  sub->font_matrix = top->font_matrix;
704  sub->font_offset = top->font_offset;
705 
706  sub->units_per_em = top->units_per_em;
707  }
708 
709  matrix = &sub->font_matrix;
710  offset = &sub->font_offset;
711  upm = &sub->units_per_em;
712  temp = FT_ABS( matrix->yy );
713 
714  if ( temp != 0x10000L )
715  {
716  *upm = FT_DivFix( *upm, temp );
717 
718  matrix->xx = FT_DivFix( matrix->xx, temp );
719  matrix->yx = FT_DivFix( matrix->yx, temp );
720  matrix->xy = FT_DivFix( matrix->xy, temp );
721  matrix->yy = FT_DivFix( matrix->yy, temp );
722  offset->x = FT_DivFix( offset->x, temp );
723  offset->y = FT_DivFix( offset->y, temp );
724  }
725 
726  offset->x >>= 16;
727  offset->y >>= 16;
728  }
729 
730  if ( pure_cff )
731  {
732  char* style_name = NULL;
733 
734 
735  /* set up num_faces */
736  cffface->num_faces = cff->num_faces;
737 
738  /* compute number of glyphs */
739  if ( dict->cid_registry != 0xFFFFU )
740  cffface->num_glyphs = cff->charset.max_cid + 1;
741  else
742  cffface->num_glyphs = cff->charstrings_index.count;
743 
744  /* set global bbox, as well as EM size */
745  cffface->bbox.xMin = dict->font_bbox.xMin >> 16;
746  cffface->bbox.yMin = dict->font_bbox.yMin >> 16;
747  /* no `U' suffix here to 0xFFFF! */
748  cffface->bbox.xMax = ( dict->font_bbox.xMax + 0xFFFF ) >> 16;
749  cffface->bbox.yMax = ( dict->font_bbox.yMax + 0xFFFF ) >> 16;
750 
751  cffface->units_per_EM = (FT_UShort)( dict->units_per_em );
752 
753  cffface->ascender = (FT_Short)( cffface->bbox.yMax );
754  cffface->descender = (FT_Short)( cffface->bbox.yMin );
755 
756  cffface->height = (FT_Short)( ( cffface->units_per_EM * 12 ) / 10 );
757  if ( cffface->height < cffface->ascender - cffface->descender )
758  cffface->height = (FT_Short)( cffface->ascender - cffface->descender );
759 
760  cffface->underline_position =
761  (FT_Short)( dict->underline_position >> 16 );
762  cffface->underline_thickness =
763  (FT_Short)( dict->underline_thickness >> 16 );
764 
765  /* retrieve font family & style name */
766  cffface->family_name = cff_index_get_name( cff, face_index );
767  if ( cffface->family_name )
768  {
769  char* full = cff_index_get_sid_string( cff,
770  dict->full_name );
771  char* fullp = full;
772  char* family = cffface->family_name;
773  char* family_name = NULL;
774 
775 
776  remove_subset_prefix( cffface->family_name );
777 
778  if ( dict->family_name )
779  {
780  family_name = cff_index_get_sid_string( cff,
781  dict->family_name );
782  if ( family_name )
783  family = family_name;
784  }
785 
786  /* We try to extract the style name from the full name. */
787  /* We need to ignore spaces and dashes during the search. */
788  if ( full && family )
789  {
790  while ( *fullp )
791  {
792  /* skip common characters at the start of both strings */
793  if ( *fullp == *family )
794  {
795  family++;
796  fullp++;
797  continue;
798  }
799 
800  /* ignore spaces and dashes in full name during comparison */
801  if ( *fullp == ' ' || *fullp == '-' )
802  {
803  fullp++;
804  continue;
805  }
806 
807  /* ignore spaces and dashes in family name during comparison */
808  if ( *family == ' ' || *family == '-' )
809  {
810  family++;
811  continue;
812  }
813 
814  if ( !*family && *fullp )
815  {
816  /* The full name begins with the same characters as the */
817  /* family name, with spaces and dashes removed. In this */
818  /* case, the remaining string in `fullp' will be used as */
819  /* the style name. */
820  style_name = cff_strcpy( memory, fullp );
821 
822  /* remove the style part from the family name (if present) */
823  remove_style( cffface->family_name, style_name );
824  }
825  break;
826  }
827  }
828  }
829  else
830  {
831  char *cid_font_name =
833  dict->cid_font_name );
834 
835 
836  /* do we have a `/FontName' for a CID-keyed font? */
837  if ( cid_font_name )
838  cffface->family_name = cff_strcpy( memory, cid_font_name );
839  }
840 
841  if ( style_name )
842  cffface->style_name = style_name;
843  else
844  /* assume "Regular" style if we don't know better */
845  cffface->style_name = cff_strcpy( memory, (char *)"Regular" );
846 
847  /*******************************************************************/
848  /* */
849  /* Compute face flags. */
850  /* */
851  flags = FT_FACE_FLAG_SCALABLE | /* scalable outlines */
852  FT_FACE_FLAG_HORIZONTAL | /* horizontal data */
853  FT_FACE_FLAG_HINTER; /* has native hinter */
854 
855  if ( sfnt_format )
856  flags |= FT_FACE_FLAG_SFNT;
857 
858  /* fixed width font? */
859  if ( dict->is_fixed_pitch )
860  flags |= FT_FACE_FLAG_FIXED_WIDTH;
861 
862  /* XXX: WE DO NOT SUPPORT KERNING METRICS IN THE GPOS TABLE FOR NOW */
863 #if 0
864  /* kerning available? */
865  if ( face->kern_pairs )
866  flags |= FT_FACE_FLAG_KERNING;
867 #endif
868 
869  cffface->face_flags = flags;
870 
871  /*******************************************************************/
872  /* */
873  /* Compute style flags. */
874  /* */
875  flags = 0;
876 
877  if ( dict->italic_angle )
878  flags |= FT_STYLE_FLAG_ITALIC;
879 
880  {
881  char *weight = cff_index_get_sid_string( cff,
882  dict->weight );
883 
884 
885  if ( weight )
886  if ( !ft_strcmp( weight, "Bold" ) ||
887  !ft_strcmp( weight, "Black" ) )
888  flags |= FT_STYLE_FLAG_BOLD;
889  }
890 
891  /* double check */
892  if ( !(flags & FT_STYLE_FLAG_BOLD) && cffface->style_name )
893  if ( !ft_strncmp( cffface->style_name, "Bold", 4 ) ||
894  !ft_strncmp( cffface->style_name, "Black", 5 ) )
895  flags |= FT_STYLE_FLAG_BOLD;
896 
897  cffface->style_flags = flags;
898  }
899 
900 
901 #ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
902  /* CID-keyed CFF fonts don't have glyph names -- the SFNT loader */
903  /* has unset this flag because of the 3.0 `post' table. */
904  if ( dict->cid_registry == 0xFFFFU )
905  cffface->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
906 #endif
907 
908  if ( dict->cid_registry != 0xFFFFU && pure_cff )
909  cffface->face_flags |= FT_FACE_FLAG_CID_KEYED;
910 
911 
912  /*******************************************************************/
913  /* */
914  /* Compute char maps. */
915  /* */
916 
917  /* Try to synthesize a Unicode charmap if there is none available */
918  /* already. If an OpenType font contains a Unicode "cmap", we */
919  /* will use it, whatever be in the CFF part of the file. */
920  {
921  FT_CharMapRec cmaprec;
922  FT_CharMap cmap;
923  FT_UInt nn;
924  CFF_Encoding encoding = &cff->encoding;
925 
926 
927  for ( nn = 0; nn < (FT_UInt)cffface->num_charmaps; nn++ )
928  {
929  cmap = cffface->charmaps[nn];
930 
931  /* Windows Unicode? */
932  if ( cmap->platform_id == TT_PLATFORM_MICROSOFT &&
934  goto Skip_Unicode;
935 
936  /* Apple Unicode platform id? */
937  if ( cmap->platform_id == TT_PLATFORM_APPLE_UNICODE )
938  goto Skip_Unicode; /* Apple Unicode */
939  }
940 
941  /* since CID-keyed fonts don't contain glyph names, we can't */
942  /* construct a cmap */
943  if ( pure_cff && cff->top_font.font_dict.cid_registry != 0xFFFFU )
944  goto Exit;
945 
946 #ifdef FT_MAX_CHARMAP_CACHEABLE
947  if ( nn + 1 > FT_MAX_CHARMAP_CACHEABLE )
948  {
949  FT_ERROR(( "cff_face_init: no Unicode cmap is found, "
950  "and too many subtables (%d) to add synthesized cmap\n",
951  nn ));
952  goto Exit;
953  }
954 #endif
955 
956  /* we didn't find a Unicode charmap -- synthesize one */
957  cmaprec.face = cffface;
960  cmaprec.encoding = FT_ENCODING_UNICODE;
961 
962  nn = (FT_UInt)cffface->num_charmaps;
963 
965  &cmaprec, NULL );
966  if ( error &&
967  FT_ERR_NEQ( error, No_Unicode_Glyph_Name ) )
968  goto Exit;
969  error = FT_Err_Ok;
970 
971  /* if no Unicode charmap was previously selected, select this one */
972  if ( cffface->charmap == NULL && nn != (FT_UInt)cffface->num_charmaps )
973  cffface->charmap = cffface->charmaps[nn];
974 
975  Skip_Unicode:
976 #ifdef FT_MAX_CHARMAP_CACHEABLE
977  if ( nn > FT_MAX_CHARMAP_CACHEABLE )
978  {
979  FT_ERROR(( "cff_face_init: Unicode cmap is found, "
980  "but too many preceding subtables (%d) to access\n",
981  nn - 1 ));
982  goto Exit;
983  }
984 #endif
985  if ( encoding->count > 0 )
986  {
987  FT_CMap_Class clazz;
988 
989 
990  cmaprec.face = cffface;
991  cmaprec.platform_id = TT_PLATFORM_ADOBE; /* Adobe platform id */
992 
993  if ( encoding->offset == 0 )
994  {
996  cmaprec.encoding = FT_ENCODING_ADOBE_STANDARD;
998  }
999  else if ( encoding->offset == 1 )
1000  {
1001  cmaprec.encoding_id = TT_ADOBE_ID_EXPERT;
1002  cmaprec.encoding = FT_ENCODING_ADOBE_EXPERT;
1004  }
1005  else
1006  {
1007  cmaprec.encoding_id = TT_ADOBE_ID_CUSTOM;
1008  cmaprec.encoding = FT_ENCODING_ADOBE_CUSTOM;
1010  }
1011 
1012  error = FT_CMap_New( clazz, NULL, &cmaprec, NULL );
1013  }
1014  }
1015  }
1016 
1017  Exit:
1018  return error;
1019  }
1020 
1021 
1022  FT_LOCAL_DEF( void )
1023  cff_face_done( FT_Face cffface ) /* CFF_Face */
1024  {
1025  CFF_Face face = (CFF_Face)cffface;
1026  FT_Memory memory;
1027  SFNT_Service sfnt;
1028 
1029 
1030  if ( !face )
1031  return;
1032 
1033  memory = cffface->memory;
1034  sfnt = (SFNT_Service)face->sfnt;
1035 
1036  if ( sfnt )
1037  sfnt->done_face( face );
1038 
1039  {
1040  CFF_Font cff = (CFF_Font)face->extra.data;
1041 
1042 
1043  if ( cff )
1044  {
1045  cff_font_done( cff );
1046  FT_FREE( face->extra.data );
1047  }
1048  }
1049  }
1050 
1051 
1053  cff_driver_init( FT_Module module ) /* CFF_Driver */
1054  {
1055  CFF_Driver driver = (CFF_Driver)module;
1056 
1057 
1058  /* set default property values */
1059  driver->hinting_engine = FT_CFF_HINTING_FREETYPE;
1060  driver->no_stem_darkening = FALSE;
1061 
1062  return FT_Err_Ok;
1063  }
1064 
1065 
1066  FT_LOCAL_DEF( void )
1067  cff_driver_done( FT_Module module ) /* CFF_Driver */
1068  {
1069  FT_UNUSED( module );
1070  }
1071 
1072 
1073 /* END */
FT_UShort standard_width[1]
Definition: t1tables.h:138
FT_UShort units_per_EM
Definition: freetype.h:945
GLenum GLuint GLenum GLsizei length
PSH_Globals_SetScaleFunc set_scale
Definition: pshints.h:62
cff_font_done(CFF_Font font)
Definition: cffload.c:1652
FT_Byte num_blue_values
Definition: t1tables.h:123
FT_Face face
Definition: freetype.h:1404
cff_face_init(FT_Stream stream, FT_Face cffface, FT_Int face_index, FT_Int num_params, FT_Parameter *params)
Definition: cffobjs.c:482
TT_Init_Face_Func init_face
Definition: sfnt.h:653
int FT_Error
Definition: fttypes.h:296
FT_UInt num_faces
Definition: cfftypes.h:223
FT_DivFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:586
GLuint GLuint stream
void * sfnt
Definition: tttypes.h:1298
cff_index_get_name(CFF_Font font, FT_UInt element)
Definition: cffload.c:583
signed long FT_Long
Definition: fttypes.h:238
SFNT_Interface * SFNT_Service
Definition: sfnt.h:754
#define ft_strncmp
Definition: ftstdlib.h:88
#define CFF_CMAP_UNICODE_CLASS_REC_GET
Definition: cffpic.h:38
unsigned long FT_ULong
Definition: fttypes.h:249
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:59
FT_Select_Metrics(FT_Face face, FT_ULong strike_index)
Definition: ftobjs.c:2602
#define TT_ADOBE_ID_STANDARD
Definition: ttnameid.h:309
#define FT_MEM_ZERO(dest, count)
Definition: ftmemory.h:208
#define NULL
Definition: ftobjs.h:61
#define FT_FACE_FLAG_CID_KEYED
Definition: freetype.h:1088
FT_Fixed xy
Definition: fttypes.h:383
FT_ULong strike_index
Definition: cffobjs.h:58
signed int FT_Int
Definition: fttypes.h:216
PSHinter_Interface * PSHinter_Service
Definition: pshints.h:680
#define FT_ABS(a)
Definition: ftobjs.h:73
FT_Fixed blue_scale
Definition: cfftypes.h:163
FT_Pos blue_shift
Definition: cfftypes.h:164
FT_Fixed underline_position
Definition: cfftypes.h:115
cff_size_init(FT_Size cffsize)
Definition: cffobjs.c:157
#define FT_FACE_FLAG_SCALABLE
Definition: freetype.h:1076
FT_Pos family_blues[14]
Definition: cfftypes.h:160
return FT_THROW(Missing_Property)
TT_Face CFF_Face
Definition: cffobjs.h:44
#define TTAG_CFF
Definition: tttags.h:43
#define FT_UNUSED(arg)
Definition: ftconfig.h:76
#define FT_MIN(a, b)
Definition: ftobjs.h:70
FT_Library library
Definition: ftobjs.h:476
GLsizei GLsizei GLchar * source
struct CFF_FontRec_ * CFF_Font
CFF_SubFont subfonts[CFF_MAX_CID_FONTS]
Definition: cfftypes.h:256
FT_UShort platform_id
Definition: freetype.h:744
PSHinter_Service pshinter
Definition: cfftypes.h:261
FT_Short snap_widths[13]
Definition: t1tables.h:146
CFF_EncodingRec encoding
Definition: cfftypes.h:236
#define FT_FACE_FIND_GLOBAL_SERVICE(face, ptr, id)
Definition: ftserv.h:133
FT_Library library
Definition: cffdrivr.c:414
PSH_Globals_NewFunc create
Definition: pshints.h:61
FT_Fixed underline_thickness
Definition: cfftypes.h:116
return FT_Err_Ok
Definition: ftbbox.c:645
#define TTAG_OTTO
Definition: tttags.h:83
struct FT_Size_InternalRec_ * FT_Size_Internal
Definition: freetype.h:1309
FT_Byte num_snap_heights
Definition: cfftypes.h:170
FT_Byte num_snap_widths
Definition: cfftypes.h:169
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
#define TT_PLATFORM_MICROSOFT
Definition: ttnameid.h:89
FT_Byte num_family_other_blues
Definition: cfftypes.h:156
TT_Loader_GotoTableFunc goto_table
Definition: tttypes.h:1288
FT_UShort standard_height[1]
Definition: t1tables.h:139
FT_Pos family_other_blues[10]
Definition: cfftypes.h:161
FT_Byte num_family_blues
Definition: t1tables.h:125
PSH_Globals_DestroyFunc destroy
Definition: pshints.h:63
return cff_index_get_sid_string(cff, sid)
png_uint_32 i
Definition: png.h:2640
FT_UShort encoding_id
Definition: freetype.h:745
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:104
FT_Face face
Definition: freetype.h:742
FT_Service_PsCMaps psnames
Definition: cfftypes.h:264
FT_Bool force_bold
Definition: t1tables.h:143
FT_Vector font_offset
Definition: cfftypes.h:122
FT_Bool has_font_matrix
Definition: cfftypes.h:120
GLenum GLuint GLint GLenum face
TT_Done_Face_Func done_face
Definition: sfnt.h:655
#define FT_ERROR(varformat)
Definition: ftdebug.h:181
cff_driver_done(FT_Module module)
Definition: cffobjs.c:1067
#define FT_CFF_HINTING_FREETYPE
Definition: ftcffdrv.h:108
#define FT_STYLE_FLAG_BOLD
Definition: freetype.h:1297
struct CFF_InternalRec_ * CFF_Internal
FT_Size_Internal internal
Definition: freetype.h:1407
#define FT_TRACE4(varformat)
Definition: ftdebug.h:161
FT_UInt num_subfonts
Definition: cfftypes.h:255
#define TT_ADOBE_ID_CUSTOM
Definition: ttnameid.h:311
CFF_FontRecDictRec font_dict
Definition: cfftypes.h:207
FT_Pos blue_values[14]
Definition: cfftypes.h:158
CFF_Font cff
Definition: cffdrivr.c:454
FT_Pos snap_widths[13]
Definition: cfftypes.h:171
#define FT_FREE(ptr)
Definition: ftmemory.h:286
FT_Bool force_bold
Definition: cfftypes.h:173
FT_ULong format_tag
Definition: tttypes.h:1264
#define FT_FACE_FLAG_SFNT
Definition: freetype.h:1079
#define FT_FACE_FLAG_FIXED_WIDTH
Definition: freetype.h:1078
cff_driver_init(FT_Module module)
Definition: cffobjs.c:1053
FT_Pos yMax
Definition: ftimage.h:119
FT_Pos xMin
Definition: ftimage.h:118
FT_ModuleRec root
Definition: ftobjs.h:751
FT_Request_Metrics(FT_Face face, FT_Size_Request req)
Definition: ftobjs.c:2649
FT_ULong offset
Definition: cfftypes.h:81
FT_UInt idx
Definition: cffcmap.c:127
FT_SizeRec root
Definition: cffobjs.h:57
FT_UInt max_cid
Definition: cfftypes.h:99
FT_MulDiv(FT_Long a, FT_Long b, FT_Long c)
Definition: ftcalc.c:412
FT_Error error
Definition: cffdrivr.c:411
#define TT_ADOBE_ID_EXPERT
Definition: ttnameid.h:310
FT_Pos x
Definition: ftimage.h:77
FT_UInt num_strings
Definition: cfftypes.h:250
FT_Int language_group
Definition: cfftypes.h:176
char FT_String
Definition: fttypes.h:183
FT_UInt family_name
Definition: cfftypes.h:111
#define FT_HAS_FIXED_SIZES(face)
Definition: freetype.h:1197
GLbitfield flags
#define FT_FACE_FLAG_HORIZONTAL
Definition: freetype.h:1080
FT_Byte num_snap_heights
Definition: t1tables.h:142
FT_Pos y
Definition: ftimage.h:78
CFF_SubFontRec top_font
Definition: cfftypes.h:254
GLdouble n
#define FT_TRACE2(varformat)
Definition: ftdebug.h:159
FT_Int lenIV
Definition: t1tables.h:121
#define TT_PLATFORM_ADOBE
Definition: ttnameid.h:91
CFF_PrivateRec private_dict
Definition: cfftypes.h:208
FT_Pos standard_width
Definition: cfftypes.h:166
signed int FT_Int32
Definition: ftconfig.h:132
FT_Byte num_other_blues
Definition: t1tables.h:124
cff_slot_init(FT_GlyphSlot slot)
Definition: cffobjs.c:350
FT_Int blue_shift
Definition: t1tables.h:135
FT_Encoding encoding
Definition: freetype.h:743
GLintptr offset
#define FT_ERR_NEQ(x, e)
Definition: fttypes.h:589
FT_Fixed blue_scale
Definition: t1tables.h:134
#define FALSE
Definition: ftobjs.h:57
FT_Pos xMax
Definition: ftimage.h:119
struct CFF_SizeRec_ * CFF_Size
TT_Load_Face_Func load_face
Definition: sfnt.h:654
signed short FT_Short
Definition: fttypes.h:194
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
TT_Load_Table_Func load_cmap
Definition: sfnt.h:669
FT_Fixed xx
Definition: fttypes.h:383
FT_Pos snap_heights[13]
Definition: cfftypes.h:172
#define FT_FACE_FLAG_HINTER
Definition: freetype.h:1087
FT_FaceRec root
Definition: tttypes.h:1260
FT_Vector_Transform_Scaled(FT_Vector *vector, const FT_Matrix *matrix, FT_Long scaling)
Definition: ftcalc.c:830
#define FT_STREAM_SEEK(position)
Definition: ftstream.h:489
CFF_Driver driver
Definition: cffdrivr.c:585
GLuint const GLchar * name
void * data
Definition: fttypes.h:457
FT_Byte num_family_blues
Definition: cfftypes.h:155
if(!abbox) return FT_THROW(Invalid_Argument)
FT_Generic extra
Definition: tttypes.h:1382
FT_Int lenIV
Definition: cfftypes.h:175
FT_CMap_New(FT_CMap_Class clazz, FT_Pointer init_data, FT_CharMap charmap, FT_CMap *acmap)
Definition: ftobjs.c:3248
FT_UInt cid_font_name
Definition: cfftypes.h:146
#define CFF_CMAP_ENCODING_CLASS_REC_GET
Definition: cffpic.h:37
GLenum const GLfloat * params
FT_Fixed yx
Definition: fttypes.h:384
FT_Fixed italic_angle
Definition: cfftypes.h:114
FT_Fixed y_scale
Definition: freetype.h:1373
FT_Short family_blues[14]
Definition: t1tables.h:131
FT_Pos other_blues[10]
Definition: cfftypes.h:159
GLdouble GLdouble GLdouble GLdouble top
signed long FT_Fixed
Definition: fttypes.h:284
FT_Bool is_fixed_pitch
Definition: cfftypes.h:113
FT_Short other_blues[10]
Definition: t1tables.h:129
GLuint64EXT * result
typedefFT_BEGIN_HEADER struct CFF_DriverRec_ * CFF_Driver
Definition: cffobjs.h:42
unsigned int FT_UInt
Definition: fttypes.h:227
cff_slot_done(FT_GlyphSlot slot)
Definition: cffobjs.c:343
FT_ULong units_per_em
Definition: cfftypes.h:121
FT_Matrix font_matrix
Definition: cfftypes.h:119
FT_Matrix_Multiply_Scaled(const FT_Matrix *a, FT_Matrix *b, FT_Long scaling)
Definition: ftcalc.c:805
GLdouble s
#define FT_FACE_FLAG_KERNING
Definition: freetype.h:1082
FT_Short snap_heights[13]
Definition: t1tables.h:147
FT_Fixed x_scale
Definition: freetype.h:1372
FT_Long language_group
Definition: t1tables.h:151
FT_Byte num_blue_values
Definition: cfftypes.h:153
FT_Get_Module(FT_Library library, const char *module_name)
Definition: ftobjs.c:4309
cff_size_done(FT_Size cffsize)
Definition: cffobjs.c:76
FT_Pos blue_fuzz
Definition: cfftypes.h:165
#define TT_PLATFORM_APPLE_UNICODE
Definition: ttnameid.h:86
GLuint GLuint GLsizei count
#define TTAG_head
Definition: tttags.h:63
CFF_IndexRec charstrings_index
Definition: cfftypes.h:239
FT_Driver driver
Definition: freetype.h:962
FT_Get_Module_Interface(FT_Library library, const char *mod_name)
Definition: ftobjs.c:4337
PSH_Globals_Funcs(* get_globals_funcs)(FT_Module module)
Definition: pshints.h:674
#define TT_MS_ID_UNICODE_CS
Definition: ttnameid.h:280
FT_Byte num_family_other_blues
Definition: t1tables.h:126
FT_Fixed yy
Definition: fttypes.h:384
cff_size_request(FT_Size size, FT_Size_Request req)
Definition: cffobjs.c:267
#define FT_STRDUP(dst, str)
Definition: ftmemory.h:351
#define FT_NEW(ptr)
Definition: ftmemory.h:288
FT_Short blue_values[14]
Definition: t1tables.h:128
FT_UInt count
Definition: cfftypes.h:83
FT_UInt num_glyphs
Definition: cfftypes.h:224
FT_Short family_other_blues[10]
Definition: t1tables.h:132
FT_Byte num_other_blues
Definition: cfftypes.h:154
T1_FIELD_DICT_FONTDICT family_name
Definition: t1tokens.h:30
#define FT_STYLE_FLAG_ITALIC
Definition: freetype.h:1296
unsigned short FT_UShort
Definition: fttypes.h:205
cff_face_done(FT_Face cffface)
Definition: cffobjs.c:1023
FT_Pos yMin
Definition: ftimage.h:118
GLuint GLuint GLfloat weight
FT_Pos standard_height
Definition: cfftypes.h:167
#define FT_FACE_FLAG_GLYPH_NAMES
Definition: freetype.h:1085
GLsizeiptr size
GLuint GLenum matrix
FT_Byte num_snap_widths
Definition: t1tables.h:141
FT_UInt cid_registry
Definition: cfftypes.h:135
CFF_CharsetRec charset
Definition: cfftypes.h:237
FT_Size_Metrics metrics
Definition: freetype.h:1406
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:236
FT_Int blue_fuzz
Definition: t1tables.h:136
#define ft_strcmp
Definition: ftstdlib.h:85
cff_font_load(FT_Library library, FT_Stream stream, FT_Int face_index, CFF_Font font, FT_Bool pure_cff)
Definition: cffload.c:1419
T2_Hints_Funcs(* get_t2_funcs)(FT_Module module)
Definition: pshints.h:676