How can I display fonts correctly?
Foxit PDF SDK provides the interface of FSCRT_Library_AddFontFile or FSCRT_Library_SetFontMapperHandler to display fonts.
Following is a sample to show how to use FSCRT_Library_SetFontMapperHandler in C++.
static FSCRT_FONTMAPPERHANDLER ExternalFontMapper;
static string FallbackFontPath;
// MapExternalFont function will be triggered when an external font is needed.
static FS_RESULT MapExternalFont(FS_LPVOID clientData, FS_LPCSTR fontName, FS_DWORD
fontStyles, FS_INT32 weight, FS_INT32 charset, FSCRT_FILE *fontFile, FS_INT32 *faceIndex)
{
/* The values of fontName, fontStyles, weight, charset will be provided. The setting of
fontFile is depending on programmer. An simple example is to set it to randomFontName*/
if(fontName=="randomFontName") {//set font file randomFontName.ttf}.
/*Set the font file. Call FSCRT_File_Create with FSCRT_File_Write,
FSCRT_File_CreateCacheFile, FSCRT_File_CreateFromMemory, or FSCRT_File_CreateFromFileName
to create the handle for FSCRT_FILE. Please see fs_base_r.h or fs_codec_r.h for details.
//faceIndex can be set to 0 for default*/
Return 0;
}
//Apply the font mapper after unlocking the library.
ExternalFontMapper.MapFont = MapExternalFont;
ExternalFontMapper.clientData = 0;
//clientData is your own data that you want to pass to MapExternalFont when it is triggered
FSCRT_Library_SetFontMapperHandler (&ExternalFontMapper);
Note: This article refers to a deprecated version of a Foxit Product. If you are still using Foxit PDF SDK 5.3 or older, please refer to your download package documents for Developer Guide and API Reference.
Get a trial version of the new Foxit PDF SDK and see our latest generation SDK’s brand new features!
Updated on March 26, 2017