Example #1
0
  FT_GetFile_From_Mac_Name( const char*  fontName,
                            FSSpec*      pathSpec,
                            FT_Long*     face_index )
  {
    OptionBits            options = kFMUseGlobalScopeOption;

    FMFontFamilyIterator  famIter;
    OSStatus              status = FMCreateFontFamilyIterator( NULL, NULL,
                                                               options,
                                                               &famIter );
    FMFont                the_font = 0;
    FMFontFamily          family   = 0;


    if ( !fontName || !face_index )
      return FT_THROW( Invalid_Argument );

    *face_index = 0;
    while ( status == 0 && !the_font )
    {
      status = FMGetNextFontFamily( &famIter, &family );
      if ( status == 0 )
      {
        int                           stat2;
        FMFontFamilyInstanceIterator  instIter;
        Str255                        famNameStr;
        char                          famName[256];


        /* get the family name */
        FMGetFontFamilyName( family, famNameStr );
        CopyPascalStringToC( famNameStr, famName );

        /* iterate through the styles */
        FMCreateFontFamilyInstanceIterator( family, &instIter );

        *face_index = 0;
        stat2       = 0;

        while ( stat2 == 0 && !the_font )
        {
          FMFontStyle  style;
          FMFontSize   size;
          FMFont       font;


          stat2 = FMGetNextFontFamilyInstance( &instIter, &font,
                                               &style, &size );
          if ( stat2 == 0 && size == 0 )
          {
            char  fullName[256];


            /* build up a complete face name */
            ft_strcpy( fullName, famName );
            if ( style & bold )
              ft_strcat( fullName, " Bold" );
            if ( style & italic )
              ft_strcat( fullName, " Italic" );

            /* compare with the name we are looking for */
            if ( ft_strcmp( fullName, fontName ) == 0 )
            {
              /* found it! */
              the_font = font;
            }
            else
              ++(*face_index);
          }
        }

        FMDisposeFontFamilyInstanceIterator( &instIter );
      }
    }

    FMDisposeFontFamilyIterator( &famIter );

    if ( the_font )
    {
      FMGetFontContainer( the_font, pathSpec );
      return FT_Err_Ok;
    }
    else
      return FT_THROW( Unknown_File_Format );
  }
Example #2
0
int gp_enumerate_fonts_next(void *enum_state, char **fontname, char **path)
{
    fontenum_t *state = (fontenum_t *)enum_state;
        FMFontIterator *Iterator = &state->Iterator;
        FMFont Font;
        FourCharCode Format;
        FMFontFamily FontFamily;
        FMFontStyle Style;
        FSSpec FontContainer;
        char type[5];
        char fontpath[256];
        char *psname;
        fond_table *table = NULL;
        OSStatus result;

        result = FMGetNextFont(Iterator, &Font);
    if (result != noErr) return 0; /* no more fonts */

        result = FMGetFontFormat(Font, &Format);
        type[0] = ((char*)&Format)[0];
        type[1] = ((char*)&Format)[1];
        type[2] = ((char*)&Format)[2];
        type[3] = ((char*)&Format)[3];
        type[4] = '\0';

        FMGetFontFamilyInstanceFromFont(Font, &FontFamily, &Style);
    if (state->name) free (state->name);

    psname = makePSFontName(FontFamily, Style);
    if (psname == NULL) {
                state->name = strdup("GSPlaceHolder");
        } else {
                state->name = psname;
        }

        result = FMGetFontContainer(Font, &FontContainer);
        if (!memcmp(&FontContainer, &state->last_container, sizeof(FSSpec))) {
                /* we have cached data on this file */
                strncpy(fontpath, state->last_container_path, 256);
                table = state->last_table;
        } else {
                convertSpecToPath(&FontContainer, fontpath, 256);
                if (!is_ttf_file(fontpath) && !is_otf_file(fontpath))
                table = parse_fond(&FontContainer);
            /* cache data on the new font file */
            memcpy(&state->last_container, &FontContainer, sizeof(FSSpec));
            if (state->last_container_path) free (state->last_container_path);
                state->last_container_path = strdup(fontpath);
                if (state->last_table) fond_table_free(state->last_table);
                state->last_table = table;
        }

        if (state->path) {
                free(state->path);
                state->path = NULL;
        }
    if (table != NULL) {
        int i;
        for (i = 0; i < table->entries; i++) {
            if (table->refs[i].size == 0) { /* ignore non-scalable fonts */
                if (table->refs[i].style == Style) {
                    int len = strlen(fontpath) + strlen("%macresource%#sfnt+") + 6;
                        state->path = malloc(len);
                    snprintf(state->path, len, "%%macresource%%%s#sfnt+%d",
                        fontpath, table->refs[i].id);
                    break;
                }
            }
        }
    } else {
        /* regular font file */
        state->path = strdup(fontpath);
    }
    if (state->path == NULL) {
        /* no matching font was found in the FOND resource table. this usually */
        /* means an LWFN file, which we don't handle yet. */
        /* we still specify these with a %macresource% path, but no res id */
        /* TODO: check file type */
        int len = strlen(fontpath) + strlen("%macresource%#POST") + 1;
        state->path = malloc(len);
        snprintf(state->path, len, "%%macresource%%%s#POST", fontpath);
    }
#ifdef DEBUG
    dlprintf2("fontenum: returning '%s' in '%s'\n", state->name, state->path);
#endif
    *fontname = state->name;
    *path = state->path;

        state->count += 1;
        return 1;
}