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