コード例 #1
1
ファイル: scfonts.cpp プロジェクト: HOST-Oman/scribus
static QString getFamilyName(const FT_Face face)
{
	QString familyName(face->family_name);

	QVector<FT_SfntName> names;

	for (FT_UInt i = 0; i < FT_Get_Sfnt_Name_Count(face); i++)
	{
		FT_SfntName name;
		if (!FT_Get_Sfnt_Name(face, i, &name))
		{
			switch (name.name_id) {
			case TT_NAME_ID_FONT_FAMILY:
			case TT_NAME_ID_PREFERRED_FAMILY:
				if (name.platform_id != TT_PLATFORM_MACINTOSH)
					names.append(name);
				break;
			default:
				break;
			}
		}
	}

	if (!names.isEmpty())
	{
		std::sort(names.begin(), names.end(), nameComp);
		foreach (const FT_SfntName& name, names)
		{
			QString string(decodeNameRecord(name));
			if (!string.isEmpty())
			{
				familyName = string;
				break;
			}
		}
コード例 #2
0
Py::Object
FT2Font::get_sfnt(const Py::Tuple & args) {
  _VERBOSE("FT2Font::get_sfnt");
  args.verify_length(0);
  
  if (!(face->face_flags & FT_FACE_FLAG_SFNT)) 
    throw Py::RuntimeError("No SFNT name table");
  
  size_t count = FT_Get_Sfnt_Name_Count(face);
  
  Py::Dict names;
  for (size_t j = 0; j < count; j++) {
    FT_SfntName sfnt;
    FT_Error error = FT_Get_Sfnt_Name(face, j, &sfnt);
    
    if (error) 
      throw Py::RuntimeError("Could not get SFNT name");
    
    Py::Tuple key(4);
    key[0] = Py::Int(sfnt.platform_id);
    key[1] = Py::Int(sfnt.encoding_id);
    key[2] = Py::Int(sfnt.language_id);
    key[3] = Py::Int(sfnt.name_id);
    names[key] = Py::String((char *) sfnt.string, (int) sfnt.string_len);
  }
  return names;
}
コード例 #3
0
ファイル: find-font.c プロジェクト: AlexNe/obs-studio
void build_font_path_info(FT_Face face, FT_Long idx, const char *path)
{
	FT_UInt num_names = FT_Get_Sfnt_Name_Count(face);
	DARRAY(char*) family_names;

	da_init(family_names);
	da_push_back(family_names, &face->family_name);

	for (FT_UInt i = 0; i < num_names; i++) {
		FT_SfntName name;
		char        *family;
		FT_Error    ret = FT_Get_Sfnt_Name(face, i, &name);

		if (ret != 0 || name.name_id != TT_NAME_ID_FONT_FAMILY)
			continue;

		family = sfnt_name_to_utf8(&name);
		if (!family)
			continue;

		for (size_t i = 0; i < family_names.num; i++) {
			if (astrcmpi(family_names.array[i], family) == 0) {
				bfree(family);
				family = NULL;
				break;
			}
		}

		if (family)
			da_push_back(family_names, &family);
	}

	for (size_t i = 0; i < family_names.num; i++) {
		add_font_path(face, idx, family_names.array[i],
				face->style_name, path);

		/* first item isn't our allocation */
		if (i > 0)
			bfree(family_names.array[i]);
	}

	da_free(family_names);
}
コード例 #4
0
bool FreeTypeLibrary::getFace(const std::string &fontfile, unsigned int index, FT_Face &face)
{
    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getMutex());

    FT_Error error = FT_New_Face(_ftlibrary, fontfile.c_str(), index, &face);

    if (error == FT_Err_Unknown_File_Format)
    {
        OSG_WARN << " .... the font file could be opened and read, but it appears" << std::endl;
        OSG_WARN << " .... that its font format is unsupported" << std::endl;
        return false;
    }
    else if (error)
    {
        OSG_WARN << " .... another error code means that the font file could not" << std::endl;
        OSG_WARN << " .... be opened, read or simply that it is broken.." << std::endl;
        return false;
    }

#ifdef PRINT_OUT_FONT_DETAILS
    OSG_NOTICE << "Face" << face << std::endl;
    unsigned int count = FT_Get_Sfnt_Name_Count(face);

    for (unsigned int i = 0; i < count; ++i)
    {
        FT_SfntName names;
        FT_Error    error = FT_Get_Sfnt_Name(face, i, &names);

        std::string name((char*)names.string, (char*)names.string + names.string_len);

        OSG_NOTICE << "names " << name << std::endl;
    }

    OSG_NOTICE << std::endl;
#endif

    //
    // GT: Fix to handle symbol fonts in MS Windows
    //
    verifyCharacterMap(face);

    return true;
}
コード例 #5
0
static int
getNameHelper(FT_Face face, int nid, int pid, int eid,
              FT_SfntName *name_return)
{
    FT_SfntName name;
    int n, i;

    n = FT_Get_Sfnt_Name_Count(face);
    if(n <= 0)
        return 0;

    for(i = 0; i < n; i++) {
        if(FT_Get_Sfnt_Name(face, i, &name))
            continue;
        if(name.name_id == nid &&
           name.platform_id == pid &&
           (eid < 0 || name.encoding_id == eid)) {
            switch(name.platform_id) {
            case TT_PLATFORM_APPLE_UNICODE:
            case TT_PLATFORM_MACINTOSH:
                if(name.language_id != TT_MAC_LANGID_ENGLISH)
                    continue;
                break;
            case TT_PLATFORM_MICROSOFT:
                if(name.language_id != TT_MS_LANGID_ENGLISH_UNITED_STATES &&
                   name.language_id != TT_MS_LANGID_ENGLISH_UNITED_KINGDOM)
                    continue;
                break;
            default:
                continue;
            }
            if(name.string_len > 0) {
                *name_return = name;
                return 1;
            }
        }
    }
    return 0;
}
コード例 #6
0
ファイル: FontEngine.cpp プロジェクト: serghei/kde3-kdebase
static bool lookupName(FT_Face face, int nid, int pid, int eid, FT_SfntName *nameReturn)
{
    int n = FT_Get_Sfnt_Name_Count(face);

    if(n > 0)
    {
        int i;
        FT_SfntName name;

        for(i = 0; i < n; i++)
            if(0 == FT_Get_Sfnt_Name(face, i, &name) && name.name_id == nid && name.platform_id == pid && (eid < 0 || name.encoding_id == eid))
            {
                switch(name.platform_id)
                {
                    case TT_PLATFORM_APPLE_UNICODE:
                    case TT_PLATFORM_MACINTOSH:
                        if(name.language_id != TT_MAC_LANGID_ENGLISH)
                            continue;
                        break;
                    case TT_PLATFORM_MICROSOFT:
                        if(name.language_id != TT_MS_LANGID_ENGLISH_UNITED_STATES && name.language_id != TT_MS_LANGID_ENGLISH_UNITED_KINGDOM)
                            continue;
                        break;
                    default:
                        continue;
                }

                if(name.string_len > 0)
                {
                    *nameReturn = name;
                    return true;
                }
            }
    }

    return false;
}
コード例 #7
0
/* ------------------------------------------------------------------------- */
int main ( int argc, char *argv[] )
{
    FT_Library  library;
    FT_Face     face;
    FT_FaceRec  props;
    FT_Error    error = 0;
    FT_UInt     names;
    FT_CharMap  charmap;
    FX_Kern_0   *kstable;
    TT_OS2      *pOS2;
    TT_Postscript *ppost;
    ULONG       rc;
    BOOL        bDumpUCS = FALSE;
    BOOL        bShowKST = FALSE;
    BOOL        bShowOS2 = FALSE;
    BOOL        bShowPS  = FALSE;
    char        szPID[10];
    char        szEID[32];
    int         i;


    char     *buf;

    if ( argc < 2 ) {
        printf("FONTNAME - Show summary of OpenType font names and other optional information.\n");
        printf("Syntax: FONTNAME <filename> [ options ]\n\n");
        printf("  /D    Dump Unicode and DBCS strings as hex values\n");
        printf("  /K    Show kerning summary (KERN format 0 only)\n");
        printf("  /O    Show OS/2 table\n");
        printf("  /P    Show POST table\n\n");
        printf("NAME and CMAP table information is always shown.\n\n");
        printf("\nNo font file specified.\n");
        return 0;
    }
    for ( i = 2; i < argc; i++ ) {
        if ( strlen( argv[i] ) > 1 ) {
            CHAR cOption = 0;
            if ( argv[i][0] == '/' || argv[i][0] == '-') cOption = argv[i][1];
            switch ( cOption ) {
                case 'd':
                case 'D':
                    bDumpUCS = TRUE;
                    break;
                case 'k':
                case 'K':
                    bShowKST = TRUE;
                    break;
                case 'o':
                case 'O':
                    bShowOS2 = TRUE;
                    break;
                case 'p':
                case 'P':
                    bShowPS = TRUE;
                    break;
                default : break;
            }
        }
    }

    if (( rc = UniCreateUconvObject( L"@endian=big", &uconv )) != ULS_SUCCESS ) {
        printf("Failed to create Unicode conversion object (rc=0x%X).\n");
        printf("Unicode text values will not be shown.\n");
        uconv = NULL;
    }

    error = FT_Init_FreeType( &library );
    if ( error ) {
        printf("An error occurred during library initialization.\n");
        return (int) error;
    }
    printf("FreeType 2 library initialized successfully.\n");

    error = FT_New_Face( library, argv[1], 0, &face );
    if ( error ) {
        if ( error == FT_Err_Unknown_File_Format )
            printf("The file format is unsupported.\n");
        else
            printf("The file \"%s\" could not be loaded.\n", argv[1]);
        goto done;
    }
    printf("Font %s read successfully.\n", face->family_name );

    names = FT_Get_Sfnt_Name_Count( face );
    if ( names ) {

        printf("Names table contains %d entries:\n", names );
        for ( i = 0; i < names; i++ ) {
            FT_SfntName name;
            error = FT_Get_Sfnt_Name( face, i, &name );
            if ( error ) continue;
            printf("%2d: Plat %d, Enc %d, Lang 0x%X, ID %2d ",
                   i, name.platform_id, name.encoding_id, name.language_id, name.name_id );
            if ( name.platform_id == 1 && name.encoding_id == 0 && name.string_len < 100 ) {
                printf(" \"");
                PrintNameString( name.string, name.string_len );
                printf("\"\n");
            }
            else if ( name.platform_id == 3 && name.encoding_id == 1 && uconv && name.string_len < 200 ) {
                printf(" (U)\"");
                if (bDumpUCS)
                    DumpUnicodeString( name.string, name.string_len );
                else
                    PrintUnicodeString( name.string, name.string_len );
                printf("\"\n");
            }
            else if ( name.string_len < 200 && bDumpUCS ) {
                printf(" \"");
                DumpUnicodeString( name.string, name.string_len );
                printf("\"\n");
            }
            else
                printf(" [%d bytes]\n", name.string_len );
        }
    }

    printf("\nINCLUDED CMAPS");
    printf("\n--------------\n");
    for ( i = 0; i < face->num_charmaps; i++ ) {
        charmap = face->charmaps[i];
        switch ( charmap->platform_id ) {
            case 0:
                strcpy( szPID, "Unicode");
                switch ( charmap->encoding_id ) {
                    case 0:  strcpy( szEID, "default");     break;
                    case 1:  strcpy( szEID, "1.1");         break;
                    case 3:  strcpy( szEID, "2+");          break;
                    case 4:  strcpy( szEID, "3.1+ UTF-32"); break;
                    default: strcpy( szEID, "unknown");     break;
                }
                break;

            case 1:
                strcpy( szPID, "Macintosh");
                switch ( charmap->encoding_id ) {
                    case 0:  strcpy( szEID, "Roman");         break;
                    case 1:  strcpy( szEID, "Japanese");      break;
                    case 2:  strcpy( szEID, "Chinese-T");     break;
                    case 3:  strcpy( szEID, "Korean");        break;
                    case 8:  strcpy( szEID, "symbols");       break;
                    case 25: strcpy( szEID, "Chinese-S");     break;
                    default: strcpy( szEID, "other language");break;
                }
                break;

            case 3:
                strcpy( szPID, "Windows");
                switch ( charmap->encoding_id ) {
                    case 0:  strcpy( szEID, "symbols");           break;
                    case 1:  strcpy( szEID, "Unicode");           break;
                    case 2:  strcpy( szEID, "Shift-JIS (Japan)"); break;
                    case 3:  strcpy( szEID, "GB2312 (China)");    break;
                    case 4:  strcpy( szEID, "Big5 (Taiwan)");     break;
                    case 5:  strcpy( szEID, "Wansung (Korea)");   break;
                    case 6:  strcpy( szEID, "Johab (Korea)");     break;
                    case 10: strcpy( szEID, "UCS-4");             break;
                    default: strcpy( szEID, "unknown");           break;
                }
                break;

            default:
                strcpy( szPID, "unknown");
                strcpy( szEID, "unknown");
                break;
        }
        printf("Platform: %d (%s), Encoding: %d (%s)\n", charmap->platform_id, szPID,
                                                         charmap->encoding_id, szEID );
    }
#if 0
    error = FX_Flush_Stream( face );
    if ( error ) {
        printf("Failed to close stream: 0x%X\n", error );
        FT_Done_Face( face );
        goto done;
    }
    error = FX_Activate_Stream( face );
    if ( error ) {
        printf("Failed to reopen stream: 0x%X\n", error );
        FT_Done_Face( face );
        goto done;
    }
#endif

    if ( bShowKST ) {
        printf("\nKERNING INFORMATION");
        printf("\n-------------------\n");
        error = FX_Get_Kerning_Pairs( face, &kstable );
        switch ( error ) {
            case 0:
                printf("%u kerning pairs defined:\n", kstable->nPairs );
                if ( kstable->nPairs )
                {
                    for ( i = 0; i < kstable->nPairs; i++ ) {
                        printf("   %X / %X (%d)\n",
                               kstable->pairs[i].left,
                               kstable->pairs[i].right,
                               kstable->pairs[i].value );
                    }
                }
                safe_free( kstable );
                break;
            case FT_Err_Table_Missing:
                printf("No kerning table defined.\n");
                break;
            case FX_Err_Invalid_Kerning_Table:
                printf("The kerning table is invalid.\n");
                break;
            case FT_Err_Out_Of_Memory:
                printf("Memory allocation error.\n");
                break;
            case FX_Err_Invalid_Kerning_Table_Format:
                printf("No supported kerning table format found.\n");
                break;
            default: printf("An unknown error (0x%X) was encountered.\n", error );
                     break;
        }
    }

    if ( bShowOS2 ) {
        printf("\nOS/2 TABLE");
        printf("\n----------\n");

        pOS2 = (TT_OS2 *) FT_Get_Sfnt_Table( face, ft_sfnt_os2 );
        if ( pOS2 ) {
            printf("version:             %u\n", pOS2->version );
            printf("xAvgCharWidth:       %d\n", pOS2->xAvgCharWidth );
            printf("usWeightClass:       %u\n", pOS2->usWeightClass );
            printf("usWidthClass:        %u\n", pOS2->usWidthClass );
            printf("fsType:              0x%X\n", pOS2->fsType );
            printf("ySubscriptXSize:     %d\n", pOS2->ySubscriptXSize );
            printf("ySubscriptYSize:     %d\n", pOS2->ySubscriptYSize );
            printf("ySubscriptXOffset:   %d\n", pOS2->ySubscriptXOffset );
            printf("ySubscriptYOffset:   %d\n", pOS2->ySubscriptYOffset );
            printf("ySuperscriptXSize:   %d\n", pOS2->ySuperscriptXSize );
            printf("ySuperscriptYSize:   %d\n", pOS2->ySuperscriptYSize );
            printf("ySuperscriptXOffset: %d\n", pOS2->ySuperscriptXOffset );
            printf("ySuperscriptYOffset: %d\n", pOS2->ySuperscriptYOffset );
            printf("yStrikeoutSize:      %d\n", pOS2->yStrikeoutSize );
            printf("yStrikeoutPosition:  %d\n", pOS2->yStrikeoutPosition );
            printf("sFamilyClass:        %d\n", pOS2->sFamilyClass );
            printf("panose:              []\n");
            printf("ulUnicodeRange1:     0x%X\n", pOS2->ulUnicodeRange1 );
            printf("ulUnicodeRange2:     0x%X\n", pOS2->ulUnicodeRange2 );
            printf("ulUnicodeRange3:     0x%X\n", pOS2->ulUnicodeRange3 );
            printf("ulUnicodeRange4:     0x%X\n", pOS2->ulUnicodeRange4 );
            printf("achVendID:           %c%c%c%c\n", pOS2->achVendID[0], pOS2->achVendID[1], pOS2->achVendID[2], pOS2->achVendID[3] );
            printf("fsSelection:         0x%X\n", pOS2->fsSelection );
            printf("usFirstCharIndex:    %u\n", pOS2->usFirstCharIndex );
            printf("usLastCharIndex:     %u\n", pOS2->usLastCharIndex );
            printf("sTypoAscender:       %d\n", pOS2->sTypoAscender );
            printf("sTypoDescender:      %d\n", pOS2->sTypoDescender );
            printf("sTypoLineGap:        %d\n", pOS2->sTypoLineGap );
            printf("usWinAscent:         %u\n", pOS2->usWinAscent );
            printf("usWinDescent:        %u\n", pOS2->usWinDescent );
        }
        else printf("OS/2 table could not be located.\n");
    }

    if ( bShowPS) {
        printf("\nPOST TABLE");
        printf("\n----------\n");

        ppost = (TT_Postscript *) FT_Get_Sfnt_Table( face, ft_sfnt_post );
        if ( ppost ) {
            printf("FormatType:         0x%X\n", ppost->FormatType );
            printf("italicAngle:        %d\n", ppost->italicAngle );
            printf("underlinePosition:  %d\n", ppost->underlinePosition );
            printf("underlineThickness: %d\n", ppost->underlineThickness );
            printf("isFixedPitch:       %u\n", ppost->isFixedPitch );
            printf("minMemType42:       %u\n", ppost->minMemType42 );
            printf("maxMemType42:       %u\n", ppost->maxMemType42 );
            printf("minMemType1:        %u\n", ppost->minMemType1 );
            printf("maxMemType1:        %u\n", ppost->maxMemType1 );
        }
        else printf("POST table could not be loaded.\n");
    }

    error = FT_Done_Face( face );
done:
    FT_Done_FreeType( library );
    if ( uconv ) UniFreeUconvObject( uconv );
    return (int) error;
}
コード例 #8
0
ファイル: ass_fontselect.c プロジェクト: DiamondStudio/libass
/**
 * \brief Read basic metadata (names, weight, slant) from a FreeType face,
 * as required for the FontSelector for matching and sorting.
 * \param lib FreeType library
 * \param face FreeType face
 * \param info metadata, returned here
 * \return success
 */
static bool
get_font_info(FT_Library lib, FT_Face face, ASS_FontProviderMetaData *info)
{
    int i;
    int num_fullname = 0;
    int num_family   = 0;
    int num_names = FT_Get_Sfnt_Name_Count(face);
    int slant, weight;
    char *fullnames[MAX_FULLNAME];
    char *families[MAX_FULLNAME];

    // we're only interested in outlines
    if (!(face->face_flags & FT_FACE_FLAG_SCALABLE))
        return false;

    for (i = 0; i < num_names; i++) {
        FT_SfntName name;

        if (FT_Get_Sfnt_Name(face, i, &name))
            continue;

        if (name.platform_id == TT_PLATFORM_MICROSOFT &&
                (name.name_id == TT_NAME_ID_FULL_NAME ||
                 name.name_id == TT_NAME_ID_FONT_FAMILY)) {
            char buf[1024];
            ass_utf16be_to_utf8(buf, sizeof(buf), (uint8_t *)name.string,
                                name.string_len);

            if (name.name_id == TT_NAME_ID_FULL_NAME) {
                fullnames[num_fullname] = strdup(buf);
                if (fullnames[num_fullname] == NULL)
                    goto error;
                num_fullname++;
            }

            if (name.name_id == TT_NAME_ID_FONT_FAMILY) {
                families[num_family] = strdup(buf);
                if (families[num_family] == NULL)
                    goto error;
                num_family++;
            }
        }

    }

    // check if we got a valid family - if not use whatever FreeType gives us
    if (num_family == 0 && face->family_name) {
        families[0] = strdup(face->family_name);
        if (families[0] == NULL)
            goto error;
        num_family++;
    }

    // we absolutely need a name
    if (num_family == 0)
        goto error;

    // calculate sensible slant and weight from style attributes
    slant  = 110 * !!(face->style_flags & FT_STYLE_FLAG_ITALIC);
    weight = 300 * !!(face->style_flags & FT_STYLE_FLAG_BOLD) + 400;

    // fill our struct
    info->slant  = slant;
    info->weight = weight;
    info->width  = 100;     // FIXME, should probably query the OS/2 table

    info->postscript_name = (char *)FT_Get_Postscript_Name(face);

    info->families = calloc(sizeof(char *), num_family);
    if (info->families == NULL)
        goto error;
    memcpy(info->families, &families, sizeof(char *) * num_family);
    info->n_family = num_family;

    if (num_fullname) {
        info->fullnames = calloc(sizeof(char *), num_fullname);
        if (info->fullnames == NULL)
            goto error;
        memcpy(info->fullnames, &fullnames, sizeof(char *) * num_fullname);
        info->n_fullname = num_fullname;
    }

    return false;

error:
    for (i = 0; i < num_family; i++)
        free(families[i]);

    for (i = 0; i < num_fullname; i++)
        free(fullnames[i]);

    free(info->families);
    free(info->fullnames);

    return true;
}
コード例 #9
0
ファイル: XeTeXFontMgr_FC.cpp プロジェクト: luigiScarso/mflua
XeTeXFontMgr::NameCollection*
XeTeXFontMgr_FC::readNames(FcPattern* pat)
{
	NameCollection*	names = new NameCollection;

	char*	pathname;
	if (FcPatternGetString(pat, FC_FILE, 0, (FcChar8**)&pathname) != FcResultMatch)
		return names;
	int index;
	if (FcPatternGetInteger(pat, FC_INDEX, 0, &index) != FcResultMatch)
		return names;

	FT_Face face;
	if (FT_New_Face(gFreeTypeLibrary, pathname, index, &face) != 0)
		return names;

	const char* name = FT_Get_Postscript_Name(face);
	if (name == NULL)
		return names;
	names->psName = name;

	// for sfnt containers, we'll read the name table ourselves, not rely on Fontconfig
	if (FT_IS_SFNT(face)) {
		std::list<std::string>	familyNames;
		std::list<std::string>	subFamilyNames;
		FT_SfntName	nameRec;
		for (index = 0; index < FT_Get_Sfnt_Name_Count(face); ++index) {
			char*	utf8name = NULL;
			if (FT_Get_Sfnt_Name(face, index, &nameRec) != 0)
				continue;
			switch (nameRec.name_id) {
				case kFontFullName:
				case kFontFamilyName:
				case kFontStyleName:
				case kPreferredFamilyName:
				case kPreferredSubfamilyName:
					{
						bool	preferredName = false;
						if (nameRec.platform_id == TT_PLATFORM_MACINTOSH
								&& nameRec.encoding_id == TT_MAC_ID_ROMAN && nameRec.language_id == 0) {
							utf8name = convertToUtf8(macRomanConv, nameRec.string, nameRec.string_len);
							preferredName = true;
						}
						else if ((nameRec.platform_id == TT_PLATFORM_APPLE_UNICODE)
								|| (nameRec.platform_id == TT_PLATFORM_MICROSOFT))
							utf8name = convertToUtf8(utf16beConv, nameRec.string, nameRec.string_len);

						if (utf8name != NULL) {
							std::list<std::string>*	nameList = NULL;
							switch (nameRec.name_id) {
								case kFontFullName:
									nameList = &names->fullNames;
									break;
								case kFontFamilyName:
									nameList = &names->familyNames;
									break;
								case kFontStyleName:
									nameList = &names->styleNames;
									break;
								case kPreferredFamilyName:
									nameList = &familyNames;
									break;
								case kPreferredSubfamilyName:
									nameList = &subFamilyNames;
									break;
							}
							if (preferredName)
								prependToList(nameList, utf8name);
							else
								appendToList(nameList, utf8name);
						}
					}
					break;
			}
		}
		if (familyNames.size() > 0)
			names->familyNames = familyNames;
		if (subFamilyNames.size() > 0)
			names->styleNames = subFamilyNames;
	}
	else {
		index = 0;
		while (FcPatternGetString(pat, FC_FULLNAME, index++, (FcChar8**)&name) == FcResultMatch)
			appendToList(&names->fullNames, name);
		index = 0;
		while (FcPatternGetString(pat, FC_FAMILY, index++, (FcChar8**)&name) == FcResultMatch)
			appendToList(&names->familyNames, name);
		index = 0;
		while (FcPatternGetString(pat, FC_STYLE, index++, (FcChar8**)&name) == FcResultMatch)
			appendToList(&names->styleNames, name);

		if (names->fullNames.size() == 0) {
			std::string fullName(names->familyNames.front());
			if (names->styleNames.size() > 0) {
				fullName += " ";
				fullName += names->styleNames.front();
			}
			names->fullNames.push_back(fullName);
		}
	}

	FT_Done_Face(face);

	return names;
}
コード例 #10
0
static void
add_face_info(GtkWidget *table, gint *row_p, const gchar *uri, FT_Face face)
{
    gchar *s;
    GFile *file;
    GFileInfo *info;
    PS_FontInfoRec ps_info;

    add_row(table, row_p, _("Name:"), face->family_name, FALSE, FALSE);

    if (face->style_name)
	add_row(table, row_p, _("Style:"), face->style_name, FALSE, FALSE);

    file = g_file_new_for_uri (uri);

    info = g_file_query_info (file,
                              G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
                              G_FILE_ATTRIBUTE_STANDARD_SIZE,
                              G_FILE_QUERY_INFO_NONE,
                              NULL, NULL);
    g_object_unref (file);

    if (info) {
        s = g_content_type_get_description (g_file_info_get_content_type (info));
        add_row (table, row_p, _("Type:"), s, FALSE, FALSE);
        g_free (s);

        s = g_format_size (g_file_info_get_size (info));
        add_row (table, row_p, _("Size:"), s, FALSE, FALSE);
        g_free (s);

        g_object_unref (info);
    }

    if (FT_IS_SFNT(face)) {
	gint i, len;
	gchar *version = NULL, *copyright = NULL, *description = NULL;

	len = FT_Get_Sfnt_Name_Count(face);
	for (i = 0; i < len; i++) {
	    FT_SfntName sname;

	    if (FT_Get_Sfnt_Name(face, i, &sname) != 0)
		continue;

	    /* only handle the unicode names for US langid */
	    if (!(sname.platform_id == TT_PLATFORM_MICROSOFT &&
		  sname.encoding_id == TT_MS_ID_UNICODE_CS &&
		  sname.language_id == TT_MS_LANGID_ENGLISH_UNITED_STATES))
		continue;

	    switch (sname.name_id) {
	    case TT_NAME_ID_COPYRIGHT:
		g_free(copyright);
		copyright = g_convert((gchar *)sname.string, sname.string_len,
				      "UTF-8", "UTF-16BE", NULL, NULL, NULL);
		break;
	    case TT_NAME_ID_VERSION_STRING:
		g_free(version);
		version = g_convert((gchar *)sname.string, sname.string_len,
				    "UTF-8", "UTF-16BE", NULL, NULL, NULL);
		break;
	    case TT_NAME_ID_DESCRIPTION:
		g_free(description);
		description = g_convert((gchar *)sname.string, sname.string_len,
					"UTF-8", "UTF-16BE", NULL, NULL, NULL);
		break;
	    default:
		break;
	    }
	}
	if (version) {
	    add_row(table, row_p, _("Version:"), version, FALSE, FALSE);
	    g_free(version);
	}
	if (copyright) {
	    add_row(table, row_p, _("Copyright:"), copyright, TRUE, TRUE);
	    g_free(copyright);
	}
	if (description) {
	    add_row(table, row_p, _("Description:"), description, TRUE, TRUE);
	    g_free(description);
	}
    } else if (FT_Get_PS_Font_Info(face, &ps_info) == 0) {
	if (ps_info.version && g_utf8_validate(ps_info.version, -1, NULL))
	    add_row(table, row_p, _("Version:"), ps_info.version, FALSE, FALSE);
	if (ps_info.notice && g_utf8_validate(ps_info.notice, -1, NULL))
	    add_row(table, row_p, _("Copyright:"), ps_info.notice, TRUE, FALSE);
    }
}
コード例 #11
0
ファイル: FontFace.cpp プロジェクト: ChristTrekker/fontaine
//
// 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();
	
}
コード例 #12
0
ファイル: mblandroidfont.cpp プロジェクト: Bjoernke/livecode
static bool create_custom_font_from_path(const char *p_path, FT_Library p_library, MCAndroidCustomFont *&r_custom_font)
{
    bool t_success;
    t_success = true;
    
    char *t_buffer;
    t_buffer = nil;
    uint32_t t_file_size;
    t_file_size = 0;
    if (t_success)
        t_success = load_custom_font_file_into_buffer_from_path(p_path, t_buffer, t_file_size);
    
    FT_Face t_font_face;
    t_font_face = nil;
    if (t_success)
        t_success = FT_New_Memory_Face(p_library, (FT_Byte *)t_buffer, t_file_size, 0, &t_font_face) == 0;
    
    MCAndroidCustomFont *t_font;
    t_font = nil;
    if (t_success)
        t_success = MCMemoryNew(t_font);
    
    if (t_success)
        t_success = MCCStringClone(p_path, t_font->path);
    
    if (t_success)
        t_success = MCCStringClone(t_font_face->family_name, t_font->family);
    
    if (t_success)
    {
        if (MCCStringEqualCaseless(t_font_face->style_name, "bold"))
            t_font->style = kMCAndroidFontStyleBold;
        else if (MCCStringEqualCaseless(t_font_face->style_name, "italic"))
            t_font->style = kMCAndroidFontStyleItalic;
        else if (MCCStringEqualCaseless(t_font_face->style_name, "bold italic"))
            t_font->style = kMCAndroidFontStyleBoldItalic;
        else
            t_font->style = kMCAndroidFontStyleRegular;
    }
    
    if (t_success)
    {       
        FT_SfntName t_sft_name;
        for (uint32_t i = 0; i < FT_Get_Sfnt_Name_Count(t_font_face); i++)
        {
            // Attempt to fetch the name of the font.  The name is name id 4 as defined in https://developer.apple.com/fonts/TTRefMan/RM06/Chap6name.html
            // It appears that the platform to use here is 1 (Macintosh according to the spec).
            FT_Get_Sfnt_Name(t_font_face, i, &t_sft_name);
            if (t_sft_name.name_id == 4 && t_sft_name.platform_id == 1 && t_sft_name.encoding_id == 0 && t_sft_name.language_id == 0 && t_sft_name.string_len != 0)
            {
                t_success = MCCStringCloneSubstring((char *)t_sft_name.string, t_sft_name.string_len, t_font->name); 
                break;
            }
        }
    }
    
    if (t_success)
        t_success = t_font->name != nil;
    
    if (t_success)
        r_custom_font = t_font;
    else
        delete_custom_font(t_font);    
    
    if (t_font_face != nil)
        FT_Done_Face(t_font_face);
    
    /*UNCHECKED */ MCMemoryDelete(t_buffer);
    
    return t_success;
}
コード例 #13
0
QStringList familyNameFromPath(const QString &filePath)
{
	if(!QFile::exists(filePath)) {
		return QStringList();
	}

	FT_Library library;
	FT_Face face;

    /* Initialize library */
	if(FT_Init_FreeType(&library)) {
		return QStringList();
	}

    /* Load face */
	QByteArray pathBytes = filePath.toLocal8Bit();
	if(FT_New_Face(library,pathBytes.data(),0,&face)) {
		FT_Done_FreeType(library);
		return QStringList();
	}

	int numOfFaces = face->num_faces;
	int faceIndex = 0;
	QStringList faceNameList;

	do {
		// default
		QString fontName(face->family_name);

		int count = FT_Get_Sfnt_Name_Count(face);
		FT_SfntName fnm = { 0 };

		for(int i = 0;i < count;i++) {
			FT_Get_Sfnt_Name(face,i,&fnm);

			/*
			Platform-specific ID code	Meaning
			0 							Symbol
			1 							Unicode BMP-only (UCS-2)
			2 							Shift-JIS
			3 							PRC
			4 							BigFive
			5 							Johab
			10 							Unicode UCS-4
			*/
			if((fnm.platform_id == TT_PLATFORM_MICROSOFT) && \
				(fnm.name_id == TT_NAME_ID_FONT_FAMILY) && \
				((fnm.language_id == TT_MS_LANGID_CHINESE_GENERAL) || (fnm.language_id == TT_MS_LANGID_CHINESE_TAIWAN) || \
				(fnm.language_id == TT_MS_LANGID_CHINESE_PRC) || (fnm.language_id == TT_MS_LANGID_CHINESE_HONG_KONG) || \
				(fnm.language_id == TT_MS_LANGID_CHINESE_SINGAPORE) || (fnm.language_id == TT_MS_LANGID_CHINESE_MACAU))) {

					if(fnm.encoding_id == TT_MS_ID_UNICODE_CS) {
						QChar fmName[128];
						for(int j = 0;j < (fnm.string_len / 2);j++) {
							int index = j * 2;
							fmName[j] = QChar((fnm.string[index] << 8) | (fnm.string[index + 1]));
						}

						fmName[fnm.string_len / 2] = QChar('\0');
						fontName = QString(fmName);

						break;
					}

					else if(fnm.encoding_id == TT_MS_ID_GB2312) {
						QTextCodec *codec = QTextCodec::codecForLocale();
						if(codec) {
							fontName = codec->toUnicode(QByteArray((const char *)fnm.string,fnm.string_len));
							break;
						}
					}
			}
		} 

		FT_Done_Face(face);

		faceNameList << fontName;
		faceIndex++;

		if(faceIndex < numOfFaces) {
			if(FT_New_Face(library,pathBytes.data(),faceIndex,&face)) {
				break;
			}
		} else {
			break;
		}
	} while(1);

	FT_Done_FreeType(library);

	return faceNameList;
}
コード例 #14
0
ファイル: ftdump.c プロジェクト: xahgo/tama
  void
  Print_Sfnt_Names( FT_Face  face )
  {
    FT_SfntName  name;
    FT_UInt      num_names, i;


    printf( "font string entries\n" );

    num_names = FT_Get_Sfnt_Name_Count( face );
    for ( i = 0; i < num_names; i++ )
    {
      error = FT_Get_Sfnt_Name( face, i, &name );
      if ( error == FT_Err_Ok )
      {
        printf( "   %-15s [%s]", name_id( name.name_id ),
                                 platform_id( name.platform_id ) );

        switch ( name.platform_id )
        {
        case TT_PLATFORM_APPLE_UNICODE:
          switch ( name.encoding_id )
          {
          case TT_APPLE_ID_DEFAULT:
          case TT_APPLE_ID_UNICODE_1_1:
          case TT_APPLE_ID_ISO_10646:
          case TT_APPLE_ID_UNICODE_2_0:
            put_unicode_be16( name.string, name.string_len, 6 );
            break;

          default:
            printf( "{unsupported encoding %d}", name.encoding_id );
            break;
          }
          break;

        case TT_PLATFORM_MACINTOSH:
          if ( name.language_id != TT_MAC_LANGID_ENGLISH )
            printf( " (language=%d)", name.language_id );
          fputs( ":\n", stdout );

          switch ( name.encoding_id )
          {
          case TT_MAC_ID_ROMAN:
            /* FIXME: convert from MacRoman to ASCII/ISO8895-1/whatever */
            /* (MacRoman is mostly like ISO8895-1 but there are         */
            /* differences)                                             */
            put_ascii( name.string, name.string_len, 6 );
            break;

          default:
            printf( "{unsupported encoding %d}", name.encoding_id );
            break;
          }

          break;

        case TT_PLATFORM_ISO:
          switch ( name.encoding_id )
          {
          case TT_ISO_ID_7BIT_ASCII:
          case TT_ISO_ID_8859_1:
            put_ascii( name.string, name.string_len, 6 );
            break;

          case TT_ISO_ID_10646:
            put_unicode_be16( name.string, name.string_len, 6 );
            break;

          default:
            printf( "{unsupported encoding %d}", name.encoding_id );
            break;
          }
          break;

        case TT_PLATFORM_MICROSOFT:
          if ( name.language_id != TT_MS_LANGID_ENGLISH_UNITED_STATES )
            printf( " (language=0x%04x)", name.language_id );
          fputs( ":\n", stdout );

          switch ( name.encoding_id )
          {
          /* TT_MS_ID_SYMBOL_CS is supposed to be Unicode, according to */
          /* information from the MS font development team              */
          case TT_MS_ID_SYMBOL_CS:
          case TT_MS_ID_UNICODE_CS:
            put_unicode_be16( name.string, name.string_len, 6 );
            break;

          default:
            printf( "{unsupported encoding %d}", name.encoding_id );
            break;
          }

          break;

        default:
          printf( "{unsupported platform}" );
          break;
        }

        printf( "\n" );
      }
    }
  }
コード例 #15
0
/// @brief Destructor 
///
FreetypeFontFileLister::~FreetypeFontFileLister() {
}



/// @brief Get name from face 
/// @param face 
/// @param id   
/// @return 
///
wxArrayString GetName(FT_Face &face,int id) {
	// Get name
	wxArrayString final;
	int count = FT_Get_Sfnt_Name_Count(face);

	for (int i=0;i<count;i++) {
		FT_SfntName name;
		FT_Get_Sfnt_Name(face,i,&name);
		if (name.name_id == id) {
			char *str = new char[name.string_len+2];
			memcpy(str,name.string,name.string_len);
			str[name.string_len] = 0;
			str[name.string_len+1] = 0;
			if (name.encoding_id == 0) final.Add(wxString(str));
			else if (name.encoding_id == 1) {
				wxMBConvUTF16BE conv;
				wxString string(str,conv);
				final.Add(string);
			}
コード例 #16
0
ファイル: _Glue_.c プロジェクト: Heether/font-manager
/* Mostly lifted from fontilus by James Henstridge. Thanks. :-) */
static void
get_sfnt_info(FontManagerFontInfo * fileinfo, const FT_Face face)
{
    gint    index,
            namecount = FT_Get_Sfnt_Name_Count(face);
    gchar * vendor = NULL;

    for (index = 0; index < namecount; index++) {
        FT_SfntName sname;
        if (FT_Get_Sfnt_Name(face, index, &sname) != 0)
            continue;

        /* Only handle the unicode names for US langid */
        if (!(sname.platform_id == TT_PLATFORM_MICROSOFT
            && sname.encoding_id == TT_MS_ID_UNICODE_CS
            && sname.language_id == TT_MS_LANGID_ENGLISH_UNITED_STATES))
            continue;

        gchar * val = UTF16BE_2_UTF8(sname);
        switch (sname.name_id) {
            case TT_NAME_ID_COPYRIGHT:
                font_manager_font_info_set_copyright(fileinfo, val);
                break;
            case TT_NAME_ID_VERSION_STRING:
                font_manager_font_info_set_version(fileinfo, val);
                break;
            case TT_NAME_ID_DESCRIPTION:
                font_manager_font_info_set_description(fileinfo, val);
                break;
            case TT_NAME_ID_LICENSE:
                font_manager_font_info_set_license_data(fileinfo, val);
                break;
            case TT_NAME_ID_LICENSE_URL:
                font_manager_font_info_set_license_url(fileinfo, val);
                break;
            case TT_NAME_ID_TRADEMARK:
                if (!vendor)
                    vendor = UTF16BE_2_UTF8(sname);
                break;
            case TT_NAME_ID_MANUFACTURER:
                if (vendor)
                    g_free0(vendor);
                vendor = UTF16BE_2_UTF8(sname);
                break;
            default:
                break;
        }
        g_free0(val);
    }

    if (vendor) {
        if (!font_manager_font_info_get_vendor(fileinfo)) {
            gchar * _vendor = get_vendor_from_notice(vendor);
            if (_vendor) {
                font_manager_font_info_set_vendor(fileinfo, _vendor);
                g_free0(_vendor);
            }
        }
        g_free0(vendor);
    }
}
コード例 #17
0
ファイル: FontFace.cpp プロジェクト: ChristTrekker/fontaine
//
// _checkLicenses();
//
void FontFace::_checkLicenses(void){
	
	//
	// Assign the default:
	//
	_licenseData = UnknownLicense::pData;
	
	std::string licenseString;
	
	///////////////////////////////////////
	//
	// Handle both (1) TrueType/OpenType
	//         and (2) Type1 fonts
	//
	///////////////////////////////////////
	if(FT_IS_SFNT(_face)){
		
		///////////////////////////////
		//
		// TrueType / OpenType CASE:
		//
		///////////////////////////////
		
		FT_UInt count=FT_Get_Sfnt_Name_Count(_face);
		
		FT_SfntName fontName;
		
		//
		// Check both the COPYRIGHT (TTF) and LICENSE (OPENTYPE) fields:
		//
		for(unsigned j=0;j<count;j++){
			
			FT_Get_Sfnt_Name(_face,j,&fontName);
			if(fontName.name_id==NID_LICENSE || fontName.name_id==NID_COPYRIGHT){
				
				licenseString = _getStringFromTrueTypeFont(fontName);
				
				if(fontName.name_id==NID_COPYRIGHT){
					_storeCopyrightSummary(licenseString);
				}
				
				if(_checkAllKnownLicenses(licenseString)){
					
					return;
					
				}
			}
			
			if(fontName.name_id==NID_URL_LICENSE){
				
				_licenseURL = _getStringFromTrueTypeFont(fontName);
				
			}
		}
		
		//
		// Get here if not a known license string:
		//
		
	}else if(FT_IS_SCALABLE(_face)){
		
		///////////////////////////////
		//
		// Could be Type 1, Type 42, 
		// CID, or PFR CASES:
		//
		///////////////////////////////
		
		PS_FontInfoRec fi;
		FT_Get_PS_Font_Info(_face,&fi);
		
		if(fi.notice){
			licenseString = fi.notice;
			_checkAllKnownLicenses(licenseString);
			_storeCopyrightSummary(licenseString);
		}
		
	}
	
	
}