Ejemplo n.º 1
0
  static FT_Error
  tt_size_request( FT_Size          size,
                   FT_Size_Request  req )
  {
    TT_Size   ttsize = (TT_Size)size;
    FT_Error  error  = TT_Err_Ok;


#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS

    if ( FT_HAS_FIXED_SIZES( size->face ) )
    {
      TT_Face       ttface = (TT_Face)size->face;
      SFNT_Service  sfnt   = (SFNT_Service) ttface->sfnt;
      FT_ULong      strike_index;


      error = sfnt->set_sbit_strike( ttface, req, &strike_index );

      if ( error )
        ttsize->strike_index = 0xFFFFFFFFUL;
      else
        return tt_size_select( size, strike_index );
    }

#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */

    FT_Request_Metrics( size->face, req );

    if ( FT_IS_SCALABLE( size->face ) )
      error = tt_size_reset( ttsize );

    return error;
  }
Ejemplo n.º 2
0
static FT_Error
tt_size_request( FT_Size          size,
                 FT_Size_Request  req )
{
    TT_Size   ttsize = (TT_Size)size;
    FT_Error  error  = FT_Err_Ok;


#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS

    if ( FT_HAS_FIXED_SIZES( size->face ) )
    {
        TT_Face       ttface = (TT_Face)size->face;
        SFNT_Service  sfnt   = (SFNT_Service)ttface->sfnt;
        FT_ULong      strike_index;


        error = sfnt->set_sbit_strike( ttface, req, &strike_index );

        if ( error )
            ttsize->strike_index = 0xFFFFFFFFUL;
        else
            return tt_size_select( size, strike_index );
    }

#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */

    FT_Request_Metrics( size->face, req );

    if ( FT_IS_SCALABLE( size->face ) )
    {
        error = tt_size_reset( ttsize );
        ttsize->root.metrics = ttsize->metrics;

#ifdef TT_USE_BYTECODE_INTERPRETER
        /* for the `MPS' bytecode instruction we need the point size */
        {
            FT_UInt  resolution = ttsize->metrics.x_ppem > ttsize->metrics.y_ppem
                                  ? req->horiResolution
                                  : req->vertResolution;


            /* if we don't have a resolution value, assume 72dpi */
            if ( req->type == FT_SIZE_REQUEST_TYPE_SCALES ||
                    !resolution                              )
                resolution = 72;

            ttsize->point_size = FT_MulDiv( ttsize->ttmetrics.ppem,
                                            64 * 72,
                                            resolution );
        }
#endif
    }

    return error;
}
Ejemplo n.º 3
0
Archivo: ftdump.c Proyecto: xahgo/tama
  void
  Print_Type( FT_Face  face )
  {
    FT_Module  module;


    printf( "font type entries\n" );

    module = &face->driver->root;
    printf( "   FreeType driver: %s\n", module->clazz->module_name );

    /* Is it better to dump all sfnt tag names? */
    printf( "   sfnt wrapped:    %s\n",
            FT_IS_SFNT( face ) ? (char *)"yes" : (char *)"no" );

    /* isScalable? */
    comma_flag = 0;
    printf( "   type:            " );
    if ( FT_IS_SCALABLE( face ) )
    {
      Print_Comma( "scalable" );
      if ( FT_HAS_MULTIPLE_MASTERS( face ) )
        Print_Comma( "multiple masters" );
    }
    if ( FT_HAS_FIXED_SIZES( face ) )
      Print_Comma( "fixed size" );
    printf( "\n" );

    /* Direction */
    comma_flag = 0;
    printf( "   direction:       " );
    if ( FT_HAS_HORIZONTAL( face ) )
      Print_Comma( "horizontal" );

    if ( FT_HAS_VERTICAL( face ) )
      Print_Comma( "vertical" );

    printf( "\n" );

    printf( "   fixed width:     %s\n",
            FT_IS_FIXED_WIDTH( face ) ? (char *)"yes" : (char *)"no" );

    printf( "   glyph names:     %s\n",
            FT_HAS_GLYPH_NAMES( face ) ? (char *)"yes" : (char *)"no" );

    if ( FT_IS_SCALABLE( face ) )
    {
      printf( "   EM size:         %d\n", face->units_per_EM );
      printf( "   global BBox:     (%ld,%ld):(%ld,%ld)\n",
              face->bbox.xMin, face->bbox.yMin,
              face->bbox.xMax, face->bbox.yMax );
      printf( "   ascent:          %d\n", face->ascender );
      printf( "   descent:         %d\n", face->descender );
      printf( "   text height:     %d\n", face->height );
    }
  }
Ejemplo n.º 4
0
static void
openfont(
	char *fname,
	char *arg /* unused now */
)
{
	FT_Error error;

#ifdef XP_PSTEXT
    extern FT_Face    xp_pstext_ft_face;
    extern FT_Library ftypeLibrary; /* defined in xc/lib/font/FreeType/ftfuncs.c */

    face = xp_pstext_ft_face;
#else
	if( FT_Init_FreeType( &library ) ) {
		fprintf(stderr, "** FreeType initialization failed\n");
		exit(1);
	}

	if( error = FT_New_Face( library, fname, 0, &face ) ) {
		if ( error == FT_Err_Unknown_File_Format )
			fprintf(stderr, "**** %s has format unknown to FreeType\n", fname);
		else
			fprintf(stderr, "**** Cannot access %s ****\n", fname);
		exit(1);
	}
#endif /* XP_PSTEXT */

	if(FT_HAS_FIXED_SIZES(face)) {
		WARNING_1 fprintf(stderr, "Font contains bitmaps\n");
	}
	if(FT_HAS_MULTIPLE_MASTERS(face)) {
		WARNING_1 fprintf(stderr, "Font contains multiple masters, using default\n");
	}

	if(ISDBG(FT)) fprintf(stderr," %d units per EM\n", face->units_per_EM);

	enc_found = 0;
}
Ejemplo n.º 5
0
  cff_size_request( FT_Size          size,
                    FT_Size_Request  req )
  {
    CFF_Size           cffsize = (CFF_Size)size;
    PSH_Globals_Funcs  funcs;


#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS

    if ( FT_HAS_FIXED_SIZES( size->face ) )
    {
      CFF_Face      cffface = (CFF_Face)size->face;
      SFNT_Service  sfnt    = (SFNT_Service)cffface->sfnt;
      FT_ULong      strike_index;


      if ( sfnt->set_sbit_strike( cffface, req, &strike_index ) )
        cffsize->strike_index = 0xFFFFFFFFUL;
      else
        return cff_size_select( size, strike_index );
    }

#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */

    FT_Request_Metrics( size->face, req );

    funcs = cff_size_get_globals_funcs( cffsize );

    if ( funcs )
    {
      CFF_Face      cffface  = (CFF_Face)size->face;
      CFF_Font      font     = (CFF_Font)cffface->extra.data;
      CFF_Internal  internal = (CFF_Internal)size->internal;

      FT_ULong  top_upm  = font->top_font.font_dict.units_per_em;
      FT_UInt   i;


      funcs->set_scale( internal->topfont,
                        size->metrics.x_scale, size->metrics.y_scale,
                        0, 0 );

      for ( i = font->num_subfonts; i > 0; i-- )
      {
        CFF_SubFont  sub     = font->subfonts[i - 1];
        FT_ULong     sub_upm = sub->font_dict.units_per_em;
        FT_Pos       x_scale, y_scale;


        if ( top_upm != sub_upm )
        {
          x_scale = FT_MulDiv( size->metrics.x_scale, top_upm, sub_upm );
          y_scale = FT_MulDiv( size->metrics.y_scale, top_upm, sub_upm );
        }
        else
        {
          x_scale = size->metrics.x_scale;
          y_scale = size->metrics.y_scale;
        }

        funcs->set_scale( internal->subfonts[i - 1],
                          x_scale, y_scale, 0, 0 );
      }
    }

    return FT_Err_Ok;
  }
Ejemplo n.º 6
0
sfnt_load_face(FT_Stream stream,
               TT_Face face,
               FT_Int face_index,
               FT_Int num_params,
               FT_Parameter * params)
{
    FT_Error error;

#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
    FT_Error psnames_error;
#endif
    FT_Bool has_outline;
    FT_Bool is_apple_sbit;
    FT_Bool ignore_preferred_family    = FALSE;
    FT_Bool ignore_preferred_subfamily = FALSE;

    SFNT_Service sfnt = (SFNT_Service)face->sfnt;

    FT_UNUSED(face_index);

    /* Check parameters */

    {
        FT_Int i;


        for (i = 0; i < num_params; i++)
        {
            if (params[i].tag == FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY)
                ignore_preferred_family = TRUE;
            else if (params[i].tag == FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY)
                ignore_preferred_subfamily = TRUE;
        }
    }

    /* Load tables */

    /* We now support two SFNT-based bitmapped font formats.  They */
    /* are recognized easily as they do not include a `glyf'       */
    /* table.                                                      */
    /*                                                             */
    /* The first format comes from Apple, and uses a table named   */
    /* `bhed' instead of `head' to store the font header (using    */
    /* the same format).  It also doesn't include horizontal and   */
    /* vertical metrics tables (i.e. `hhea' and `vhea' tables are  */
    /* missing).                                                   */
    /*                                                             */
    /* The other format comes from Microsoft, and is used with     */
    /* WinCE/PocketPC.  It looks like a standard TTF, except that  */
    /* it doesn't contain outlines.                                */
    /*                                                             */

    FT_TRACE2(("sfnt_load_face: %08p\n\n", face));

    /* do we have outlines in there? */
#ifdef FT_CONFIG_OPTION_INCREMENTAL
    has_outline = FT_BOOL(face->root.internal->incremental_interface != 0 ||
                          tt_face_lookup_table(face, TTAG_glyf) != 0 ||
                          tt_face_lookup_table(face, TTAG_CFF) != 0);
#else
    has_outline = FT_BOOL(tt_face_lookup_table(face, TTAG_glyf) != 0 ||
                          tt_face_lookup_table(face, TTAG_CFF) != 0);
#endif

    is_apple_sbit = 0;

    /* if this font doesn't contain outlines, we try to load */
    /* a `bhed' table                                        */
    if (!has_outline && sfnt->load_bhed)
    {
        LOAD_(bhed);
        is_apple_sbit = FT_BOOL(!error);
    }

    /* load the font header (`head' table) if this isn't an Apple */
    /* sbit font file                                             */
    if (!is_apple_sbit)
    {
        LOAD_(head);
        if (error)
            goto Exit;
    }

    if (face->header.Units_Per_EM == 0)
    {
        error = SFNT_Err_Invalid_Table;

        goto Exit;
    }

    /* the following tables are often not present in embedded TrueType */
    /* fonts within PDF documents, so don't check for them.            */
    LOAD_(maxp);
    LOAD_(cmap);

    /* the following tables are optional in PCL fonts -- */
    /* don't check for errors                            */
    LOAD_(name);
    LOAD_(post);

#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
    psnames_error = error;
#endif

    /* do not load the metrics headers and tables if this is an Apple */
    /* sbit font file                                                 */
    if (!is_apple_sbit)
    {
        /* load the `hhea' and `hmtx' tables */
        LOADM_(hhea, 0);
        if (!error)
        {
            LOADM_(hmtx, 0);
            if (error == SFNT_Err_Table_Missing)
            {
                error = SFNT_Err_Hmtx_Table_Missing;

#ifdef FT_CONFIG_OPTION_INCREMENTAL
                /* If this is an incrementally loaded font and there are */
                /* overriding metrics, tolerate a missing `hmtx' table.  */
                if (face->root.internal->incremental_interface &&
                    face->root.internal->incremental_interface->funcs->
                    get_glyph_metrics)
                {
                    face->horizontal.number_Of_HMetrics = 0;
                    error                               = SFNT_Err_Ok;
                }
#endif
            }
        }
        else if (error == SFNT_Err_Table_Missing)
        {
            /* No `hhea' table necessary for SFNT Mac fonts. */
            if (face->format_tag == TTAG_true)
            {
                FT_TRACE2(("This is an SFNT Mac font.\n"));
                has_outline = 0;
                error       = SFNT_Err_Ok;
            }
            else
            {
                error = SFNT_Err_Horiz_Header_Missing;

#ifdef FT_CONFIG_OPTION_INCREMENTAL
                /* If this is an incrementally loaded font and there are */
                /* overriding metrics, tolerate a missing `hhea' table.  */
                if (face->root.internal->incremental_interface &&
                    face->root.internal->incremental_interface->funcs->
                    get_glyph_metrics)
                {
                    face->horizontal.number_Of_HMetrics = 0;
                    error                               = SFNT_Err_Ok;
                }
#endif
            }
        }

        if (error)
            goto Exit;

        /* try to load the `vhea' and `vmtx' tables */
        LOADM_(hhea, 1);
        if (!error)
        {
            LOADM_(hmtx, 1);
            if (!error)
                face->vertical_info = 1;
        }

        if (error && error != SFNT_Err_Table_Missing)
            goto Exit;

        LOAD_(os2);
        if (error)
        {
            if (error != SFNT_Err_Table_Missing)
                goto Exit;

            face->os2.version = 0xFFFFU;
        }
    }

    /* the optional tables */

    /* embedded bitmap support */
    if (sfnt->load_eblc)
    {
        LOAD_(eblc);
        if (error)
        {
            /* a font which contains neither bitmaps nor outlines is */
            /* still valid (although rather useless in most cases);  */
            /* however, you can find such stripped fonts in PDFs     */
            if (error == SFNT_Err_Table_Missing)
                error = SFNT_Err_Ok;
            else
                goto Exit;
        }
    }

    LOAD_(pclt);
    if (error)
    {
        if (error != SFNT_Err_Table_Missing)
            goto Exit;

        face->pclt.Version = 0;
    }

    /* consider the kerning and gasp tables as optional */
    LOAD_(gasp);
    LOAD_(kern);

    face->root.num_glyphs = face->max_profile.numGlyphs;

    /* Bit 8 of the `fsSelection' field in the `OS/2' table denotes  */
    /* a WWS-only font face.  `WWS' stands for `weight', width', and */
    /* `slope', a term used by Microsoft's Windows Presentation      */
    /* Foundation (WPF).  This flag has been introduced in version   */
    /* 1.5 of the OpenType specification (May 2008).                 */

    face->root.family_name = NULL;
    face->root.style_name  = NULL;
    if (face->os2.version != 0xFFFFU && face->os2.fsSelection & 256)
    {
        if (!ignore_preferred_family)
            GET_NAME(PREFERRED_FAMILY, &face->root.family_name);

        if (!face->root.family_name)
            GET_NAME(FONT_FAMILY, &face->root.family_name);

        if (!ignore_preferred_subfamily)
            GET_NAME(PREFERRED_SUBFAMILY, &face->root.style_name);

        if (!face->root.style_name)
            GET_NAME(FONT_SUBFAMILY, &face->root.style_name);
    }
    else
    {
        GET_NAME(WWS_FAMILY, &face->root.family_name);
        if (!face->root.family_name && !ignore_preferred_family)
            GET_NAME(PREFERRED_FAMILY, &face->root.family_name);

        if (!face->root.family_name)
            GET_NAME(FONT_FAMILY, &face->root.family_name);

        GET_NAME(WWS_SUBFAMILY, &face->root.style_name);
        if (!face->root.style_name && !ignore_preferred_subfamily)
            GET_NAME(PREFERRED_SUBFAMILY, &face->root.style_name);

        if (!face->root.style_name)
            GET_NAME(FONT_SUBFAMILY, &face->root.style_name);
    }

    /* now set up root fields */
    {
        FT_Face root  = &face->root;
        FT_Long flags = root->face_flags;


        /*********************************************************************/
        /*                                                                   */
        /* Compute face flags.                                               */
        /*                                                                   */
        if (has_outline == TRUE)
            flags |= FT_FACE_FLAG_SCALABLE; /* scalable outlines */

        /* The sfnt driver only supports bitmap fonts natively, thus we */
        /* don't set FT_FACE_FLAG_HINTER.                               */
        flags |= FT_FACE_FLAG_SFNT |      /* SFNT file format  */
                 FT_FACE_FLAG_HORIZONTAL; /* horizontal data   */

#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
        if (psnames_error == SFNT_Err_Ok &&
            face->postscript.FormatType != 0x00030000L)
            flags |= FT_FACE_FLAG_GLYPH_NAMES;
#endif

        /* fixed width font? */
        if (face->postscript.isFixedPitch)
            flags |= FT_FACE_FLAG_FIXED_WIDTH;

        /* vertical information? */
        if (face->vertical_info)
            flags |= FT_FACE_FLAG_VERTICAL;

        /* kerning available ? */
        if (TT_FACE_HAS_KERNING(face))
            flags |= FT_FACE_FLAG_KERNING;

#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
        /* Don't bother to load the tables unless somebody asks for them. */
        /* No need to do work which will (probably) not be used.          */
        if (tt_face_lookup_table(face, TTAG_glyf) != 0 &&
            tt_face_lookup_table(face, TTAG_fvar) != 0 &&
            tt_face_lookup_table(face, TTAG_gvar) != 0)
            flags |= FT_FACE_FLAG_MULTIPLE_MASTERS;
#endif

        root->face_flags = flags;

        /*********************************************************************/
        /*                                                                   */
        /* Compute style flags.                                              */
        /*                                                                   */

        flags = 0;
        if (has_outline == TRUE && face->os2.version != 0xFFFFU)
        {
            /* We have an OS/2 table; use the `fsSelection' field.  Bit 9 */
            /* indicates an oblique font face.  This flag has been        */
            /* introduced in version 1.5 of the OpenType specification.   */

            if (face->os2.fsSelection & 512)     /* bit 9 */
                flags |= FT_STYLE_FLAG_ITALIC;
            else if (face->os2.fsSelection & 1)  /* bit 0 */
                flags |= FT_STYLE_FLAG_ITALIC;

            if (face->os2.fsSelection & 32)      /* bit 5 */
                flags |= FT_STYLE_FLAG_BOLD;
        }
        else
        {
            /* this is an old Mac font, use the header field */

            if (face->header.Mac_Style & 1)
                flags |= FT_STYLE_FLAG_BOLD;

            if (face->header.Mac_Style & 2)
                flags |= FT_STYLE_FLAG_ITALIC;
        }

        root->style_flags = flags;

        /*********************************************************************/
        /*                                                                   */
        /* Polish the charmaps.                                              */
        /*                                                                   */
        /*   Try to set the charmap encoding according to the platform &     */
        /*   encoding ID of each charmap.                                    */
        /*                                                                   */

        tt_face_build_cmaps(face);  /* ignore errors */


        /* set the encoding fields */
        {
            FT_Int m;


            for (m = 0; m < root->num_charmaps; m++)
            {
                FT_CharMap charmap = root->charmaps[m];


                charmap->encoding = sfnt_find_encoding(charmap->platform_id,
                                                       charmap->encoding_id);

#if 0
                if (root->charmap == NULL &&
                    charmap->encoding == FT_ENCODING_UNICODE)
                {
                    /* set 'root->charmap' to the first Unicode encoding we find */
                    root->charmap = charmap;
                }
#endif
            }
        }

#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
        /*
         *  Now allocate the root array of FT_Bitmap_Size records and
         *  populate them.  Unfortunately, it isn't possible to indicate bit
         *  depths in the FT_Bitmap_Size record.  This is a design error.
         */
        {
            FT_UInt i, count;


#ifndef FT_CONFIG_OPTION_OLD_INTERNALS
            count = face->sbit_num_strikes;
#else
            count = (FT_UInt)face->num_sbit_strikes;
#endif

            if (count > 0)
            {
                FT_Memory       memory   = face->root.stream->memory;
                FT_UShort       em_size  = face->header.Units_Per_EM;
                FT_Short        avgwidth = face->os2.xAvgCharWidth;
                FT_Size_Metrics metrics;


                if (em_size == 0 || face->os2.version == 0xFFFFU)
                {
                    avgwidth = 0;
                    em_size  = 1;
                }

                if (FT_NEW_ARRAY(root->available_sizes, count))
                    goto Exit;

                for (i = 0; i < count; i++)
                {
                    FT_Bitmap_Size *bsize = root->available_sizes + i;


                    error = sfnt->load_strike_metrics(face, i, &metrics);
                    if (error)
                        goto Exit;

                    bsize->height = (FT_Short)(metrics.height >> 6);
                    bsize->width  = (FT_Short)(
                        (avgwidth * metrics.x_ppem + em_size / 2) / em_size);

                    bsize->x_ppem = metrics.x_ppem << 6;
                    bsize->y_ppem = metrics.y_ppem << 6;

                    /* assume 72dpi */
                    bsize->size = metrics.y_ppem << 6;
                }

                root->face_flags     |= FT_FACE_FLAG_FIXED_SIZES;
                root->num_fixed_sizes = (FT_Int)count;
            }
        }
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */

        /* a font with no bitmaps and no outlines is scalable; */
        /* it has only empty glyphs then                       */
        if (!FT_HAS_FIXED_SIZES(root) && !FT_IS_SCALABLE(root))
            root->face_flags |= FT_FACE_FLAG_SCALABLE;


        /*********************************************************************/
        /*                                                                   */
        /*  Set up metrics.                                                  */
        /*                                                                   */
        if (FT_IS_SCALABLE(root))
        {
            /* XXX What about if outline header is missing */
            /*     (e.g. sfnt wrapped bitmap)?             */
            root->bbox.xMin    = face->header.xMin;
            root->bbox.yMin    = face->header.yMin;
            root->bbox.xMax    = face->header.xMax;
            root->bbox.yMax    = face->header.yMax;
            root->units_per_EM = face->header.Units_Per_EM;


            /* XXX: Computing the ascender/descender/height is very different */
            /*      from what the specification tells you.  Apparently, we    */
            /*      must be careful because                                   */
            /*                                                                */
            /*      - not all fonts have an OS/2 table; in this case, we take */
            /*        the values in the horizontal header.  However, these    */
            /*        values very often are not reliable.                     */
            /*                                                                */
            /*      - otherwise, the correct typographic values are in the    */
            /*        sTypoAscender, sTypoDescender & sTypoLineGap fields.    */
            /*                                                                */
            /*        However, certain fonts have these fields set to 0.      */
            /*        Rather, they have usWinAscent & usWinDescent correctly  */
            /*        set (but with different values).                        */
            /*                                                                */
            /*      As an example, Arial Narrow is implemented through four   */
            /*      files ARIALN.TTF, ARIALNI.TTF, ARIALNB.TTF & ARIALNBI.TTF */
            /*                                                                */
            /*      Strangely, all fonts have the same values in their        */
            /*      sTypoXXX fields, except ARIALNB which sets them to 0.     */
            /*                                                                */
            /*      On the other hand, they all have different                */
            /*      usWinAscent/Descent values -- as a conclusion, the OS/2   */
            /*      table cannot be used to compute the text height reliably! */
            /*                                                                */

            /* The ascender/descender/height are computed from the OS/2 table */
            /* when found.  Otherwise, they're taken from the horizontal      */
            /* header.                                                        */
            /*                                                                */

            root->ascender  = face->horizontal.Ascender;
            root->descender = face->horizontal.Descender;

            root->height = (FT_Short)(root->ascender - root->descender +
                                      face->horizontal.Line_Gap);

#if 0
            /* if the line_gap is 0, we add an extra 15% to the text height --  */
            /* this computation is based on various versions of Times New Roman */
            if (face->horizontal.Line_Gap == 0)
                root->height = (FT_Short)((root->height * 115 + 50) / 100);
#endif /* 0 */

#if 0
            /* some fonts have the OS/2 "sTypoAscender", "sTypoDescender" & */
            /* "sTypoLineGap" fields set to 0, like ARIALNB.TTF             */
            if (face->os2.version != 0xFFFFU && root->ascender)
            {
                FT_Int height;


                root->ascender  = face->os2.sTypoAscender;
                root->descender = -face->os2.sTypoDescender;

                height = root->ascender + root->descender + face->os2.sTypoLineGap;
                if (height > root->height)
                    root->height = height;
            }
#endif /* 0 */

            root->max_advance_width  = face->horizontal.advance_Width_Max;
            root->max_advance_height = (FT_Short)(face->vertical_info
                                                  ? face->vertical.advance_Height_Max
                                                  : root->height);

            /* See http://www.microsoft.com/OpenType/OTSpec/post.htm -- */
            /* Adjust underline position from top edge to centre of     */
            /* stroke to convert TrueType meaning to FreeType meaning.  */
            root->underline_position = face->postscript.underlinePosition -
                                       face->postscript.underlineThickness / 2;
            root->underline_thickness = face->postscript.underlineThickness;
        }
    }
Ejemplo n.º 7
0
//
// Constructor:
//
FontFace::FontFace( FontLibrary &library, const std::string &fileName ){
	
	_fileName=fileName;
	
	//
	// By default report on fragmentary and partial orthographic
	// support in addition to fully supported orthographies:
	//
	_reportMissing     = true;
	_reportFragmentary = true;
	_reportPartial     = true;
	_reportFull        = true;

	_reportConscript   = false;
	
	FT_Error err;
	
	err = FT_New_Face(library.get(),_fileName.c_str(),0, &_face ); 
	if(err==FT_Err_Unknown_File_Format) throw Exception("FontFace()","Unknown file format.");
	else if(err) throw Exception("FontFace()","Unable to open or process font file.");
	//
	//
	//
	_commonName = _face->family_name;
	_subFamily  = _face->style_name;
	_glyphCount = _face->num_glyphs;
	
	if(FT_IS_SFNT(_face)){
		
		FT_UInt count=FT_Get_Sfnt_Name_Count(_face);
		
		FT_SfntName fontName;
		
		for(unsigned j=0;j<count;j++){
			
			FT_Get_Sfnt_Name(_face,j,&fontName);
			
			if(fontName.platform_id==3 && fontName.encoding_id==1){
				//
				// Microsoft 3:1 Platform:
				//
				if( fontName.language_id==0x0409 ){
					//
					// This is the de-facto
					// default AMERICAN ENGLISH
					// entry:
					//
					switch(fontName.name_id){
					case NID_FONT_FAMILY:
						if(_commonName.empty()) _commonName = _getPlatform3Encoding1String(fontName.string_len,fontName.string);
						break;
					case NID_FONT_SUBFAM:
						if(_subFamily.empty()) _subFamily   = _getPlatform3Encoding1String(fontName.string_len,fontName.string);
						break;
					case NID_VERSION:
						if(_version.empty()) _version       = _getPlatform3Encoding1String(fontName.string_len,fontName.string);
						break;
					case NID_VENDOR:
						if(_vendor.empty()) _vendor         = _getPlatform3Encoding1String(fontName.string_len,fontName.string);
						break;
					case NID_DESIGNER:
						if(_designer.empty()) _designer     = _getPlatform3Encoding1String(fontName.string_len,fontName.string);
						break;
					case NID_URL_VENDOR:
						if(_vendorURL.empty()) _vendorURL   = _getPlatform3Encoding1String(fontName.string_len,fontName.string);
						break;
					case NID_URL_DESIGNER:
						if(_designerURL.empty()) _designerURL = _getPlatform3Encoding1String(fontName.string_len,fontName.string);
						break;
					default:
						break;
					}
				}else{
					//
					// Some other language:
					// We take whatever the very first
					// other language is to be
					// our "nativeName" string:
					//
					switch(fontName.name_id){
					case NID_FONT_FAMILY:
						if(_nativeName.empty()) _nativeName = _getPlatform3Encoding1String(fontName.string_len,fontName.string);
						break;
					default:
						break;
					}
				}
				
				//
				// DEBUG
				//
				//if(fontName.name_id==NID_COPYRIGHT){
				//	// DEBUG:
				//	std::cout << ">>> COPYRIGHT: " << _getPlatform3Encoding1String(fontName.string_len,fontName.string) << std::endl;
				//}
				//if(fontName.name_id==NID_VERSION){
				//	// DEBUG:
				//	std::cout << ">>> VERSION     : " << _getPlatform3Encoding1String(fontName.string_len,fontName.string) << std::endl;
				//}
				
			}else if(fontName.platform_id==1 && fontName.encoding_id==0){
				//
				// Macintosh 1:0 platform: This is going to 
				// be English in the MacRoman encoding:
				//
				// NOTA BENE: We currently do not deal with
				// non-English Mac strings.  They seem to be 
				// very rare in real fonts out there in the world.
				//
				switch(fontName.name_id){
				case NID_FONT_FAMILY:
					if(_commonName.empty()) _commonName = _getPlatform1Encoding0String(fontName.string_len,fontName.string);
					break;
				case NID_FONT_SUBFAM:
					if(_subFamily.empty()) _subFamily   = _getPlatform1Encoding0String(fontName.string_len,fontName.string);
					break;
				case NID_VERSION:
					if(_version.empty()) _version       = _getPlatform1Encoding0String(fontName.string_len,fontName.string);
					break;
				case NID_VENDOR:
					if(_vendor.empty()) _vendor         = _getPlatform1Encoding0String(fontName.string_len,fontName.string);
					break;
				case NID_DESIGNER:
					if(_designer.empty()) _designer     = _getPlatform1Encoding0String(fontName.string_len,fontName.string);
					break;
				case NID_URL_VENDOR:
					if(_vendorURL.empty()) _vendorURL   = _getPlatform1Encoding0String(fontName.string_len,fontName.string);
					break;
				case NID_URL_DESIGNER:
					if(_designerURL.empty()) _designerURL = _getPlatform1Encoding0String(fontName.string_len,fontName.string);
					break;
				default:
					break;
				}
			}
			
			
		}
	}
	
	//
	// If native name is missing, fill it in:
	//
	//if(_nativeName.empty()) _nativeName = _commonName;
	
	_style=NORMAL;
	if( _face->style_flags & FT_STYLE_FLAG_ITALIC ) _style  = ITALIC;
	_weight=NORMAL_WEIGHT;
	if( _face->style_flags & FT_STYLE_FLAG_BOLD   ) _weight = BOLD;
	_isFixedWidth=FT_IS_FIXED_WIDTH(_face);
	
	
	
	//
	// Vertical metrics for Japanese, Chinese, Mongolian:
	//
	_hasVerticalMetrics = FT_HAS_VERTICAL(_face);
	//
	// Check for embedded bitmaps:
	//
	_hasFixedSizes = FT_HAS_FIXED_SIZES(_face);
	
	//
	// Get the set of unicode values this font covers
	//
	_getUnicodeValues();
	
	//
	// Check orthographic coverage:
	//
	//_checkOrthographies();
	
	//
	// Check license:
	//
	_checkLicenses();
	
}