~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/freetype/src/sfnt/sfobjs.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
  /*                                                                       */
124
124
  /*    nameid :: The name id of the name record to return.                */
125
125
  /*                                                                       */
 
126
  /* <InOut>                                                               */
 
127
  /*    name   :: The address of a string pointer.  NULL if no name is     */
 
128
  /*              present.                                                 */
 
129
  /*                                                                       */
126
130
  /* <Return>                                                              */
127
 
  /*    Character string.  NULL if no name is present.                     */
 
131
  /*    FreeType error code.  0 means success.                             */
128
132
  /*                                                                       */
129
 
  static FT_String*
130
 
  tt_face_get_name( TT_Face    face,
131
 
                    FT_UShort  nameid )
 
133
  static FT_Error
 
134
  tt_face_get_name( TT_Face      face,
 
135
                    FT_UShort    nameid,
 
136
                    FT_String**  name )
132
137
  {
133
138
    FT_Memory         memory = face->root.memory;
 
139
    FT_Error          error  = SFNT_Err_Ok;
134
140
    FT_String*        result = NULL;
135
141
    FT_UShort         n;
136
142
    TT_NameEntryRec*  rec;
145
151
    TT_NameEntry_ConvertFunc  convert;
146
152
 
147
153
 
 
154
    FT_ASSERT( name );
 
155
 
148
156
    rec = face->name_table.names;
149
157
    for ( n = 0; n < face->num_names; n++, rec++ )
150
158
    {
256
264
    {
257
265
      if ( rec->string == NULL )
258
266
      {
259
 
        FT_Error   error  = SFNT_Err_Ok;
260
267
        FT_Stream  stream = face->name_table.stream;
261
268
 
262
 
        FT_UNUSED( error );
263
 
 
264
269
 
265
270
        if ( FT_QNEW_ARRAY ( rec->string, rec->stringLength ) ||
266
271
             FT_STREAM_SEEK( rec->stringOffset )              ||
277
282
    }
278
283
 
279
284
  Exit:
280
 
    return result;
 
285
    *name = result;
 
286
    return error;
281
287
  }
282
288
 
283
289
 
363
369
    if ( FT_READ_ULONG( tag ) )
364
370
      return error;
365
371
 
366
 
    if ( tag != 0x00010000UL                      &&
367
 
         tag != TTAG_ttcf                         &&
368
 
         tag != FT_MAKE_TAG( 'O', 'T', 'T', 'O' ) &&
369
 
         tag != TTAG_true                         &&
370
 
         tag != 0x00020000UL                      )
 
372
    if ( tag != 0x00010000UL &&
 
373
         tag != TTAG_ttcf    &&
 
374
         tag != TTAG_OTTO    &&
 
375
         tag != TTAG_true    &&
 
376
         tag != TTAG_typ1    &&
 
377
         tag != 0x00020000UL )
371
378
      return SFNT_Err_Unknown_File_Format;
372
379
 
373
380
    face->ttc_header.tag = TTAG_ttcf;
401
408
      face->ttc_header.version = 1 << 16;
402
409
      face->ttc_header.count   = 1;
403
410
 
404
 
      if ( FT_NEW( face->ttc_header.offsets) )
 
411
      if ( FT_NEW( face->ttc_header.offsets ) )
405
412
        return error;
406
413
 
407
414
      face->ttc_header.offsets[0] = offset;
451
458
      face_index = 0;
452
459
 
453
460
    if ( face_index >= face->ttc_header.count )
454
 
        return SFNT_Err_Bad_Argument;
 
461
      return SFNT_Err_Invalid_Argument;
455
462
 
456
463
    if ( FT_STREAM_SEEK( face->ttc_header.offsets[face_index] ) )
457
464
      return error;
461
468
    if ( error )
462
469
      return error;
463
470
 
464
 
    face->root.num_faces = face->ttc_header.count;
 
471
    face->root.num_faces  = face->ttc_header.count;
 
472
    face->root.face_index = face_index;
465
473
 
466
474
    return error;
467
475
  }
498
506
    FT_TRACE3(( "\n" ));                                      \
499
507
  } while ( 0 )
500
508
 
 
509
#define GET_NAME( id, field )                                 \
 
510
  do {                                                        \
 
511
    error = tt_face_get_name( face, TT_NAME_ID_##id, field ); \
 
512
    if ( error )                                              \
 
513
      goto Exit;                                              \
 
514
  } while ( 0 )
 
515
 
501
516
 
502
517
  FT_LOCAL_DEF( FT_Error )
503
518
  sfnt_load_face( FT_Stream      stream,
506
521
                  FT_Int         num_params,
507
522
                  FT_Parameter*  params )
508
523
  {
509
 
    FT_Error      error, psnames_error;
 
524
    FT_Error      error;
 
525
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
 
526
    FT_Error      psnames_error;
 
527
#endif
510
528
    FT_Bool       has_outline;
511
529
    FT_Bool       is_apple_sbit;
512
530
 
581
599
    /* don't check for errors                            */
582
600
    LOAD_( name );
583
601
    LOAD_( post );
 
602
 
 
603
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
584
604
    psnames_error = error;
 
605
#endif
585
606
 
586
607
    /* do not load the metrics headers and tables if this is an Apple */
587
608
    /* sbit font file                                                 */
660
681
 
661
682
        face->os2.version = 0xFFFFU;
662
683
      }
663
 
 
664
684
    }
665
685
 
666
686
    /* the optional tables */
667
687
 
668
 
    /* embedded bitmap support. */
 
688
    /* embedded bitmap support */
669
689
    if ( sfnt->load_eblc )
670
690
    {
671
691
      LOAD_( eblc );
672
692
      if ( error )
673
693
      {
674
 
        /* return an error if this font file has no outlines */
675
 
        if ( error == SFNT_Err_Table_Missing && has_outline )
 
694
        /* a font which contains neither bitmaps nor outlines is */
 
695
        /* still valid (although rather useless in most cases);  */
 
696
        /* however, you can find such stripped fonts in PDFs     */
 
697
        if ( error == SFNT_Err_Table_Missing )
676
698
          error = SFNT_Err_Ok;
677
699
        else
678
700
          goto Exit;
692
714
    LOAD_( gasp );
693
715
    LOAD_( kern );
694
716
 
695
 
    error = SFNT_Err_Ok;
696
 
 
697
717
    face->root.num_glyphs = face->max_profile.numGlyphs;
698
718
 
699
 
#if 0
700
719
    /* Bit 8 of the `fsSelection' field in the `OS/2' table denotes  */
701
720
    /* a WWS-only font face.  `WWS' stands for `weight', width', and */
702
721
    /* `slope', a term used by Microsoft's Windows Presentation      */
703
 
    /* Foundation (WPF).  This flag will be introduced in version    */
704
 
    /* 1.5 of the OpenType specification (but is already in use).    */
 
722
    /* Foundation (WPF).  This flag has been introduced in version   */
 
723
    /* 1.5 of the OpenType specification (May 2008).                 */
705
724
 
706
725
    if ( face->os2.version != 0xFFFFU && face->os2.fsSelection & 256 )
707
 
#endif
708
726
    {
709
 
      face->root.family_name =
710
 
        tt_face_get_name( face, TT_NAME_ID_PREFERRED_FAMILY );
 
727
      GET_NAME( PREFERRED_FAMILY, &face->root.family_name );
711
728
      if ( !face->root.family_name )
712
 
        face->root.family_name =
713
 
          tt_face_get_name( face, TT_NAME_ID_FONT_FAMILY );
 
729
        GET_NAME( FONT_FAMILY, &face->root.family_name );
714
730
 
715
 
      face->root.style_name =
716
 
        tt_face_get_name( face, TT_NAME_ID_PREFERRED_SUBFAMILY );
 
731
      GET_NAME( PREFERRED_SUBFAMILY, &face->root.style_name );
717
732
      if ( !face->root.style_name )
718
 
        face->root.style_name =
719
 
          tt_face_get_name( face, TT_NAME_ID_FONT_SUBFAMILY );
 
733
        GET_NAME( FONT_SUBFAMILY, &face->root.style_name );
720
734
    }
721
 
#if 0
722
735
    else
723
736
    {
724
 
      /* Support for `name' table ID 21 (WWS family) and 22 (WWS  */
725
 
      /* subfamily) is still under consideration by Microsoft and */
726
 
      /* not implemented in the current version of WPF.           */
727
 
 
728
 
      face->root.family_name =
729
 
        tt_face_get_name( face, TT_NAME_ID_WWS_FAMILY );
730
 
      if ( !face->root.family_name )
731
 
        face->root.family_name =
732
 
          tt_face_get_name( face, TT_NAME_ID_PREFERRED_FAMILY );
733
 
      if ( !face->root.family_name )
734
 
        face->root.family_name =
735
 
          tt_face_get_name( face, TT_NAME_ID_FONT_FAMILY );
736
 
 
737
 
      face->root.style_name =
738
 
        tt_face_get_name( face, TT_NAME_ID_WWS_SUBFAMILY );
739
 
      if ( !face->root.style_name )
740
 
        face->root.style_name =
741
 
          tt_face_get_name( face, TT_NAME_ID_PREFERRED_SUBFAMILY );
742
 
      if ( !face->root.style_name )
743
 
        face->root.style_name =
744
 
          tt_face_get_name( face, TT_NAME_ID_FONT_SUBFAMILY );
 
737
      GET_NAME( WWS_FAMILY, &face->root.family_name );
 
738
      if ( !face->root.family_name )
 
739
        GET_NAME( PREFERRED_FAMILY, &face->root.family_name );
 
740
      if ( !face->root.family_name )
 
741
        GET_NAME( FONT_FAMILY, &face->root.family_name );
 
742
 
 
743
      GET_NAME( WWS_SUBFAMILY, &face->root.style_name );
 
744
      if ( !face->root.style_name )
 
745
        GET_NAME( PREFERRED_SUBFAMILY, &face->root.style_name );
 
746
      if ( !face->root.style_name )
 
747
        GET_NAME( FONT_SUBFAMILY, &face->root.style_name );
745
748
    }
746
 
#endif
747
 
 
748
749
 
749
750
    /* now set up root fields */
750
751
    {
801
802
      flags = 0;
802
803
      if ( has_outline == TRUE && face->os2.version != 0xFFFFU )
803
804
      {
804
 
        /* We have an OS/2 table; use the `fsSelection' field.  Bit 9   */
805
 
        /* indicates an oblique font face.  This flag will be           */
806
 
        /* introduced in version 1.5 of the OpenType specification (but */
807
 
        /* is already in use).                                          */
 
805
        /* We have an OS/2 table; use the `fsSelection' field.  Bit 9 */
 
806
        /* indicates an oblique font face.  This flag has been        */
 
807
        /* introduced in version 1.5 of the OpenType specification.   */
808
808
 
809
809
        if ( face->os2.fsSelection & 512 )       /* bit 9 */
810
810
          flags |= FT_STYLE_FLAG_ITALIC;
817
817
      else
818
818
      {
819
819
        /* this is an old Mac font, use the header field */
 
820
 
820
821
        if ( face->header.Mac_Style & 1 )
821
822
          flags |= FT_STYLE_FLAG_BOLD;
822
823
 
861
862
        }
862
863
      }
863
864
 
 
865
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
 
866
 
 
867
      /*
 
868
       *  Now allocate the root array of FT_Bitmap_Size records and
 
869
       *  populate them.  Unfortunately, it isn't possible to indicate bit
 
870
       *  depths in the FT_Bitmap_Size record.  This is a design error.
 
871
       */
 
872
      {
 
873
        FT_UInt  i, count;
 
874
 
 
875
 
 
876
#ifndef FT_CONFIG_OPTION_OLD_INTERNALS
 
877
        count = face->sbit_num_strikes;
 
878
#else
 
879
        count = (FT_UInt)face->num_sbit_strikes;
 
880
#endif
 
881
 
 
882
        if ( count > 0 )
 
883
        {
 
884
          FT_Memory        memory   = face->root.stream->memory;
 
885
          FT_UShort        em_size  = face->header.Units_Per_EM;
 
886
          FT_Short         avgwidth = face->os2.xAvgCharWidth;
 
887
          FT_Size_Metrics  metrics;
 
888
 
 
889
 
 
890
          if ( em_size == 0 || face->os2.version == 0xFFFFU )
 
891
          {
 
892
            avgwidth = 0;
 
893
            em_size = 1;
 
894
          }
 
895
 
 
896
          if ( FT_NEW_ARRAY( root->available_sizes, count ) )
 
897
            goto Exit;
 
898
 
 
899
          for ( i = 0; i < count; i++ )
 
900
          {
 
901
            FT_Bitmap_Size*  bsize = root->available_sizes + i;
 
902
 
 
903
 
 
904
            error = sfnt->load_strike_metrics( face, i, &metrics );
 
905
            if ( error )
 
906
              goto Exit;
 
907
 
 
908
            bsize->height = (FT_Short)( metrics.height >> 6 );
 
909
            bsize->width = (FT_Short)(
 
910
                ( avgwidth * metrics.x_ppem + em_size / 2 ) / em_size );
 
911
 
 
912
            bsize->x_ppem = metrics.x_ppem << 6;
 
913
            bsize->y_ppem = metrics.y_ppem << 6;
 
914
 
 
915
            /* assume 72dpi */
 
916
            bsize->size   = metrics.y_ppem << 6;
 
917
          }
 
918
 
 
919
          root->face_flags     |= FT_FACE_FLAG_FIXED_SIZES;
 
920
          root->num_fixed_sizes = (FT_Int)count;
 
921
        }
 
922
      }
 
923
 
 
924
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
 
925
 
 
926
      /* a font with no bitmaps and no outlines is scalable; */
 
927
      /* it has only empty glyphs then                       */
 
928
      if ( !FT_HAS_FIXED_SIZES( root ) && !FT_IS_SCALABLE( root ) )
 
929
        root->face_flags |= FT_FACE_FLAG_SCALABLE;
 
930
 
864
931
 
865
932
      /*********************************************************************/
866
933
      /*                                                                   */
867
934
      /*  Set up metrics.                                                  */
868
935
      /*                                                                   */
869
 
      if ( has_outline == TRUE )
 
936
      if ( FT_IS_SCALABLE( root ) )
870
937
      {
871
938
        /* XXX What about if outline header is missing */
872
939
        /*     (e.g. sfnt wrapped bitmap)?             */
919
986
        /* this computation is based on various versions of Times New Roman */
920
987
        if ( face->horizontal.Line_Gap == 0 )
921
988
          root->height = (FT_Short)( ( root->height * 115 + 50 ) / 100 );
922
 
#endif
 
989
#endif /* 0 */
923
990
 
924
991
#if 0
925
 
 
926
992
        /* some fonts have the OS/2 "sTypoAscender", "sTypoDescender" & */
927
993
        /* "sTypoLineGap" fields set to 0, like ARIALNB.TTF             */
928
994
        if ( face->os2.version != 0xFFFFU && root->ascender )
937
1003
          if ( height > root->height )
938
1004
            root->height = height;
939
1005
        }
940
 
 
941
1006
#endif /* 0 */
942
1007
 
943
 
        root->max_advance_width   = face->horizontal.advance_Width_Max;
944
 
 
945
 
        root->max_advance_height  = (FT_Short)( face->vertical_info
946
 
                                      ? face->vertical.advance_Height_Max
947
 
                                      : root->height );
948
 
 
949
 
        root->underline_position  = face->postscript.underlinePosition;
 
1008
        root->max_advance_width  = face->horizontal.advance_Width_Max;
 
1009
        root->max_advance_height = (FT_Short)( face->vertical_info
 
1010
                                     ? face->vertical.advance_Height_Max
 
1011
                                     : root->height );
 
1012
 
 
1013
        /* See http://www.microsoft.com/OpenType/OTSpec/post.htm -- */
 
1014
        /* Adjust underline position from top edge to centre of     */
 
1015
        /* stroke to convert TrueType meaning to FreeType meaning.  */
 
1016
        root->underline_position  = face->postscript.underlinePosition -
 
1017
                                    face->postscript.underlineThickness / 2;
950
1018
        root->underline_thickness = face->postscript.underlineThickness;
951
1019
      }
952
1020
 
953
 
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
954
 
 
955
 
      /*
956
 
       *  Now allocate the root array of FT_Bitmap_Size records and
957
 
       *  populate them.  Unfortunately, it isn't possible to indicate bit
958
 
       *  depths in the FT_Bitmap_Size record.  This is a design error.
959
 
       */
960
 
      {
961
 
        FT_UInt  i, count;
962
 
 
963
 
 
964
 
#if !defined FT_CONFIG_OPTION_OLD_INTERNALS
965
 
        count = face->sbit_num_strikes;
966
 
#else
967
 
        count = (FT_UInt)face->num_sbit_strikes;
968
 
#endif
969
 
 
970
 
        if ( count > 0 )
971
 
        {
972
 
          FT_Memory        memory   = face->root.stream->memory;
973
 
          FT_UShort        em_size  = face->header.Units_Per_EM;
974
 
          FT_Short         avgwidth = face->os2.xAvgCharWidth;
975
 
          FT_Size_Metrics  metrics;
976
 
 
977
 
 
978
 
          if ( em_size == 0 || face->os2.version == 0xFFFFU )
979
 
          {
980
 
            avgwidth = 0;
981
 
            em_size = 1;
982
 
          }
983
 
 
984
 
          if ( FT_NEW_ARRAY( root->available_sizes, count ) )
985
 
            goto Exit;
986
 
 
987
 
          for ( i = 0; i < count; i++ )
988
 
          {
989
 
            FT_Bitmap_Size*  bsize = root->available_sizes + i;
990
 
 
991
 
 
992
 
            error = sfnt->load_strike_metrics( face, i, &metrics );
993
 
            if ( error )
994
 
              goto Exit;
995
 
 
996
 
            bsize->height = (FT_Short)( metrics.height >> 6 );
997
 
            bsize->width = (FT_Short)(
998
 
                ( avgwidth * metrics.x_ppem + em_size / 2 ) / em_size );
999
 
 
1000
 
            bsize->x_ppem = metrics.x_ppem << 6;
1001
 
            bsize->y_ppem = metrics.y_ppem << 6;
1002
 
 
1003
 
            /* assume 72dpi */
1004
 
            bsize->size   = metrics.y_ppem << 6;
1005
 
          }
1006
 
 
1007
 
          root->face_flags     |= FT_FACE_FLAG_FIXED_SIZES;
1008
 
          root->num_fixed_sizes = (FT_Int)count;
1009
 
        }
1010
 
      }
1011
 
 
1012
 
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
1013
 
 
1014
1021
    }
1015
1022
 
1016
1023
  Exit:
1022
1029
 
1023
1030
#undef LOAD_
1024
1031
#undef LOADM_
 
1032
#undef GET_NAME
1025
1033
 
1026
1034
 
1027
1035
  FT_LOCAL_DEF( void )
1028
1036
  sfnt_done_face( TT_Face  face )
1029
1037
  {
1030
 
    FT_Memory     memory = face->root.memory;
1031
 
    SFNT_Service  sfnt   = (SFNT_Service)face->sfnt;
1032
 
 
 
1038
    FT_Memory     memory;
 
1039
    SFNT_Service  sfnt;
 
1040
 
 
1041
 
 
1042
    if ( !face )
 
1043
      return;
 
1044
 
 
1045
    memory = face->root.memory;
 
1046
    sfnt   = (SFNT_Service)face->sfnt;
1033
1047
 
1034
1048
    if ( sfnt )
1035
1049
    {
1068
1082
    }
1069
1083
 
1070
1084
    /* freeing the horizontal metrics */
1071
 
#if !defined FT_CONFIG_OPTION_OLD_INTERNALS
 
1085
#ifndef FT_CONFIG_OPTION_OLD_INTERNALS
1072
1086
    {
1073
1087
      FT_Stream  stream = FT_FACE_STREAM( face );
1074
1088