Hi,
This is regarding the CreateFontPackage API which is implemented in the FontSub.dll as part of Windows GDI which we would like to use for Font subsetting:
I got the details about this from the URL below:
1. I tried out using this API but the API is returning an error code of 1009 for which I was not able to get the error message string. The API documentation gives a list of error codes @ http://windowssdk.msdn.microsoft.com/library/default.asp url=/library/en-us/gdi/t2embed_FontPackageErrorMessages.asp such as ERR_NO_GLYPHS.
2. Where are the error codes defined The error code definitons could not be found in FontSub.h which is in the Windows SDK Nov CTP include folder.
3. I wrote the output buffer contents to a .ttf file, but the output TTF file from this API seems to be corrupt as it does not open as a valid font file.
4. Is there any other way through which I can implement Font subsetting
Below is the piece of code which I have tried out:
I am building this code through VS2005 in a Windows Forms Application:
FILE* Httf = fopen("C:\\Windows\\Fonts\\COUR.TTF","rb");
fseek(Httf,0,SEEK_END);
DWORD len = ftell(Httf);
fread(puchSrcBuffer,sizeof(puchSrcBuffer),len,Httf);
unsigned long ulSrcBufferSize; /* size of input TTF or TTC buffer data */
ulSrcBufferSize = sizeof(puchSrcBuffer);
unsigned char ** ppuchFontPackageBuffer; /* output package buffer */
unsigned long * pulFontPackageBufferSize; /* output package buffer size */
unsigned long * pulBytesWritten; /* output package buffer data length */
unsigned short usFlag = TTFCFP_FLAGS_SUBSET; /* subset, compress, or both, TTF or TTC, Chars or Glyphs */
unsigned short usTTCIndex = NULL; /* TTC Index, only used if TTC bit set */
unsigned short usSubsetFormat = TTFCFP_SUBSET; /* Old Subset, Subset or Delta */
unsigned short usSubsetLanguage = 0; /* Language in Name table to keep */
unsigned short usSubsetPlatform = TTFCFP_UNICODE_PLATFORMID; /* if ListType is Character, Platform of cmap to use for glyph list */
unsigned short usSubsetEncoding = TTFCFP_DONT_CARE; /* if ListType is Character, Encoding of cmap to use for glyph list */
unsigned short *pusSubsetKeepList; /* List of Characters or Glyphs to keep */
pusSubsetKeepList = new unsigned short [10];
pusSubsetKeepList[0] = 48;
pusSubsetKeepList[1] = 49;
pusSubsetKeepList[2] = 50;
pusSubsetKeepList[3] = 51;
pusSubsetKeepList[4] = 71;
pusSubsetKeepList[5] = NULL;
INT iListCount = 0,i=0;
while(pusSubsetKeepList[i++] != NULL)
{
iListCount++;
}
unsigned short usSubsetListCount = iListCount; /* number of elements in list */
CFP_ALLOCPROC lpfnAllocate = fnAllocate; /* call back function to allocate temp buffers and output buffers */
CFP_REALLOCPROC lpfnReAllocate = fnReAllocate; /* call back function to reallocate temp and output buffers */
CFP_FREEPROC lpfnFree = fnFree; /* call back function to free buffer allocated with lpfnAllocate and lpfnReAllocate */
void * lpvReserved = NULL;
//Load the Font subset dll
HMODULE hFS = NULL;
hFS = LoadLibrary(L"C:\\WINDOWS\\system32\\FontSub.dll");
typedef short (*CREATEFONTPACKAGE)(const unsigned char *,const unsigned long ,unsigned char ** ,
const unsigned long *,unsigned long *,const unsigned short ,const unsigned short,
const unsigned short,const unsigned short,const unsigned short,const unsigned short,
const unsigned short*,const unsigned short,CFP_ALLOCPROC,CFP_REALLOCPROC,CFP_FREEPROC,
LPVOID);
if
(hFS != NULL){
//Get the Address of the exported fn
CREATEFONTPACKAGE lpDllEntryPoint = (CREATEFONTPACKAGE)GetProcAddress(hFS,"CreateFontPackage");
//#ifdef a 0
//Invoke the fn
short sRet = 1;
sRet = (short)(*lpDllEntryPoint)(
puchSrcBuffer, /* input TTF or TTC buffer */
ulSrcBufferSize, /* size of input TTF or TTC buffer data */
ppuchFontPackageBuffer, /* output package buffer */
pulFontPackageBufferSize, /* output package buffer size */
pulBytesWritten, /* output package buffer data length */
usFlag, /* subset, compress, or both, TTF or TTC, Chars or Glyphs */
usTTCIndex, /* TTC Index, only used if TTC bit set */
usSubsetFormat, /* Old Subset, Subset or Delta */
usSubsetLanguage, /* Language in Name table to keep */
usSubsetPlatform, /* if ListType is Character, Platform of cmap to use for glyph list */
usSubsetEncoding, /* if ListType is Character, Encoding of cmap to use for glyph list */
pusSubsetKeepList, /* List of Characters or Glyphs to keep */
usSubsetListCount, /* number of elements in list */
(CFP_ALLOCPROC)lpfnAllocate, /* call back function to allocate temp buffers and output buffers */
(CFP_REALLOCPROC) lpfnReAllocate, /* call back function to reallocate temp and output buffers */
(CFP_FREEPROC) lpfnFree, /* call back function to free buffer allocated with lpfnAllocate and lpfnReAllocate */
NULL);
DWORD Errno = GetLastError();
//Write the buffer contents to a file
FILE *ttfFile = NULL;
ttfFile = fopen("E:\\VSSamples\\Metro-Print\\Containers\\Arialsub.ttf","w+");
fwrite((void*)&ppuchFontPackageBuffer,sizeof(ppuchFontPackageBuffer),500,ttfFile);
fclose(ttfFile);
Best Regards,
Madhukar KR