[Learning Notes] JavaScript Basic-Any Movement Framework Mrlan

2022-12-26   ES  

//由fontconfig项目分析提取出来的

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TRUETYPE_TABLES_H
#include FT_SFNT_NAMES_H
#include FT_TRUETYPE_IDS_H

static const FT_UShort platform_order[] = {
	TT_PLATFORM_MICROSOFT,
	TT_PLATFORM_APPLE_UNICODE,
	TT_PLATFORM_MACINTOSH,
};

#define NUM_PLATFORM_ORDER (sizeof (platform_order) / sizeof (platform_order[0]))

static const FT_UShort nameid_order[] = {
	TT_NAME_ID_PREFERRED_FAMILY,
	TT_NAME_ID_FONT_FAMILY,
	TT_NAME_ID_MAC_FULL_NAME,
	TT_NAME_ID_FULL_NAME,
	TT_NAME_ID_PREFERRED_SUBFAMILY,
	TT_NAME_ID_FONT_SUBFAMILY,
	TT_NAME_ID_TRADEMARK,
	TT_NAME_ID_MANUFACTURER,
};

#define NUM_NAMEID_ORDER  (sizeof (nameid_order) / sizeof (nameid_order[0]))


typedef struct {
	const FT_UShort	platform_id;
	const FT_UShort	encoding_id;
	const char	fromcode[12];
} FcFtEncoding;

#define TT_ENCODING_DONT_CARE	0xffff
#define FC_ENCODING_MAC_ROMAN	"MACINTOSH"

static const FcFtEncoding   fcFtEncoding[] = {
	{ TT_PLATFORM_APPLE_UNICODE,	TT_ENCODING_DONT_CARE,	"UCS-2BE" },
	{ TT_PLATFORM_MACINTOSH,	TT_MAC_ID_ROMAN,	"MACINTOSH" },
	{ TT_PLATFORM_MACINTOSH,	TT_MAC_ID_JAPANESE,	"SJIS" },
	{ TT_PLATFORM_MICROSOFT,	TT_MS_ID_UNICODE_CS,	"UTF-16BE" },
	{ TT_PLATFORM_MICROSOFT,	TT_MS_ID_SJIS,		"SJIS-WIN" },
	{ TT_PLATFORM_MICROSOFT,	TT_MS_ID_GB2312,	"GB3212" },
	{ TT_PLATFORM_MICROSOFT,	TT_MS_ID_BIG_5,		"BIG-5" },
	{ TT_PLATFORM_MICROSOFT,	TT_MS_ID_WANSUNG,	"Wansung" },
	{ TT_PLATFORM_MICROSOFT,	TT_MS_ID_JOHAB,		"Johab" },
	{ TT_PLATFORM_MICROSOFT,	TT_MS_ID_UCS_4,		"UCS4" },
	{ TT_PLATFORM_ISO,		TT_ISO_ID_7BIT_ASCII,	"ASCII" },
	{ TT_PLATFORM_ISO,		TT_ISO_ID_10646,	"UCS-2BE" },
	{ TT_PLATFORM_ISO,		TT_ISO_ID_8859_1,	"ISO-8859-1" },
};

#define NUM_FC_FT_ENCODING  (int) (sizeof (fcFtEncoding) / sizeof (fcFtEncoding[0]))

typedef unsigned char FcChar8;

static FcChar8 * FcSfntNameTranscode(FT_SfntName *sname)
{
	int	       i;
	const char *fromcode;
	FcChar8 *utf8;

	for (i = 0; i < NUM_FC_FT_ENCODING; i++)
		if (fcFtEncoding[i].platform_id == sname->platform_id &&
			(fcFtEncoding[i].encoding_id == TT_ENCODING_DONT_CARE ||
				fcFtEncoding[i].encoding_id == sname->encoding_id))
			break;
	if (i == NUM_FC_FT_ENCODING)
		return 0;
	fromcode = fcFtEncoding[i].fromcode;
	//......
	//完整函数请参考fongconfig项目的fcfreetype.c源码

	return 0;
}

void get_full_name(FT_Face face)
{
	TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2);


	int		    p, platform;
	int		    n, nameid;
	FT_SfntName	    sname;
	FT_UInt    	    snamei, snamec;

	nameid = TT_NAME_ID_FULL_NAME;

	snamec = FT_Get_Sfnt_Name_Count(face);
	for (p = 0; p <= NUM_PLATFORM_ORDER; p++)
	{
		if (p < NUM_PLATFORM_ORDER)
			platform = platform_order[p];
		else
			platform = 0xffff;

		for (n = 0; n < NUM_NAMEID_ORDER; n++)
		{
			

			for (snamei = 0; snamei < snamec; snamei++)
			{
				FcChar8		*utf8;
				const FcChar8	*lang;
				const char	*elt = 0, *eltlang = 0;
				int		*np = 0, *nlangp = 0;

				if (FT_Get_Sfnt_Name(face, snamei, &sname) != 0)
					continue;
				if (sname.name_id != nameid)
					continue;

				if (p < NUM_PLATFORM_ORDER)
				{
					if (sname.platform_id != platform)
						continue;
				}
				else
				{
					int	    sp;

					for (sp = 0; sp < NUM_PLATFORM_ORDER; sp++)
						if (sname.platform_id == platform_order[sp])
							break;
					if (sp != NUM_PLATFORM_ORDER)
						continue;
				}

				utf8 = FcSfntNameTranscode(&sname);

			}
		}
	}

}

source

Related Posts

junit -parameterized test

Solving the bug of IE6 IE7 onResize

3. Null field appears when the association table

[phpmyadmin] ERROR 1045 (28000): Access Denied for User ‘root‘@‘localhost‘ (USING PASSWORD: Yes) solve PHPMYADMIN error 1045W

[Learning Notes] JavaScript Basic-Any Movement Framework Mrlan

Random Posts

Front-end packaging tool-the difference between the difference between the difference between the difference

Unity download resources from the server and save to the local area

br a little change tangxiao

vim editor’s basic use (open file method)

pycharm cracking method