Back to Blog

    Developer Blog

    How to support non-standard fonts on Foxit PDF SDK?

    Foxit PDF SDK 5.3

    To support non-standard fonts on Foxit PDF SDK, follow the steps outlined below:

    1. Use the FSCRT_Library_AddFontFile or use FSCRT_Library_SetFontMapperHandler.
    2. Create the callback to handle the non-standard font.
    3. static FSCRT_FONTMAPPERHANDLER ExternalFontMapper; 
      
      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){
      
              if(fontName=="randomFontName") {
      
                  //set fontFile to use the non-Standard font file
      
              }
      
               return 0;
      
      }

      Note: MapExternalFont is a callback function that will provide the font details.  With the details, user can set the best matching font.

      Note: Here is how to 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

      Note: The return code is for error handling.  Error code 0 means success.

    4. Set the callback function to the Library FontMapper.
      ExternalFontMapper.MapFont = MapExternalFont;
      
      ExternalFontMapper.clientData = 0; 
      
      FSCRT_Library_SetFontMapperHandler(&ExternalFontMapper);

      Note: ClientData is your own data that you want to pass to MapExternalFont when it is triggered.

    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!