' ########################################################################################
' Microsoft Windows
' File: fontsub.inc
' Contents: Font subsetting services (fontsub.dll)
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_fontsub_PBI)
#DEFINE PBX_fontsub_PBI
%EQUATE `FONTSUB_INC = 1
'typedef void *(__cdecl *CFP_ALLOCPROC)(size_t);
'FUNCTION CFP_ALLOCPROC CDECL (BYVAL nSize AS DWORD) AS DWORD
'typedef void *(__cdecl *CFP_REALLOCPROC)(void *, size_t);
'FUNCTION CFP_REALLOCPROC CDECL (BYVAL pMemBlock AS DWORD, BYVAL nSize AS DWORD) AS DWORD
'typedef void (__cdecl *CFP_FREEPROC)(void *);
'SUB CFP_FREEPROC CDECL (BYVAL pMemBlock AS DWORD)
'unsigned long __cdecl CreateFontPackage(
' CONST unsigned char * puchSrcBuffer, ' /* input TTF or TTC buffer */
' CONST unsigned long ulSrcBufferSize, ' /* size of input TTF or TTC buffer data */
' unsigned char ** ppuchFontPackageBuffer, ' /* output package buffer */
' unsigned long * pulFontPackageBufferSize, ' /* output package buffer size */
' unsigned long * pulBytesWritten, ' /* output package buffer data length */
' CONST unsigned short usFlag, ' /* subset, compress, or both, TTF or TTC, Chars or Glyphs */
' CONST unsigned short usTTCIndex, ' /* TTC Index, only used if TTC bit set */
' CONST unsigned short usSubsetFormat, ' /* Old Subset, Subset or Delta */
' CONST unsigned short usSubsetLanguage, ' /* Language in Name table to keep */
' CONST unsigned short usSubsetPlatform, ' /* if ListType is Character, Platform of cmap to use for glyph list */
' CONST unsigned short usSubsetEncoding, ' /* if ListType is Character, Encoding of cmap to use for glyph list */
' CONST unsigned short *pusSubsetKeepList, ' /* List of Characters or Glyphs to keep */
' CONST unsigned short 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 */
' void * lpvReserved);
DECLARE FUNCTION CreateFontPackage CDECL LIB "fontsub.dll" ALIAS "CreateFontPackage" ( BYVAL puchSrcBuffer AS BYTE PTR ' CONST unsigned char * puchSrcBuffer /* input TTF or TTC buffer */ , BYVAL ulSrcBufferSize AS QUAD ' CONST unsigned long ulSrcBufferSize /* size of input TTF or TTC buffer data */ , BYREF ppuchFontPackageBuffer AS QUAD ' unsigned char ** ppuchFontPackageBuffer /* output package buffer */ , BYREF pulFontPackageBufferSize AS QUAD ' unsigned long * pulFontPackageBufferSize /* output package buffer size */ , BYREF pulBytesWritten AS QUAD ' unsigned long * pulBytesWritten /* output package buffer data length */ , BYVAL usFlag AS WORD ' CONST unsigned short usFlag /* subset, compress, or both, TTF or TTC, Chars or Glyphs */ , BYVAL usTTCIndex AS WORD ' CONST unsigned short usTTCIndex /* TTC Index, only used if TTC bit set */ , BYVAL usSubsetFormat AS WORD ' CONST unsigned short usSubsetFormat /* Old Subset, Subset or Delta */ , BYVAL usSubsetLanguage AS WORD ' CONST unsigned short usSubsetLanguage /* Language in Name table to keep */ , BYVAL usSubsetPlatform AS WORD ' CONST unsigned short usSubsetPlatform /* if ListType is Character, Platform of cmap to use for glyph list */ , BYVAL usSubsetEncoding AS WORD ' CONST unsigned short usSubsetEncoding /* if ListType is Character, Encoding of cmap to use for glyph list */ , BYREF pusSubsetKeepList AS WORD ' CONST unsigned short *pusSubsetKeepList /* List of Characters or Glyphs to keep */ , BYVAL usSubsetListCount AS WORD ' CONST unsigned short usSubsetListCount /* number of elements in list */ , BYVAL lpfnAllocate AS QUAD ' CFP_ALLOCPROC lpfnAllocate /* call back function to allocate temp buffers and output buffers */ , BYVAL lpfnReAllocate AS QUAD ' CFP_REALLOCPROC lpfnReAllocate /* call back function to reallocate temp and output buffers */ , BYVAL lpfnFree AS QUAD ' CFP_FREEPROC lpfnFree /* call back function to free buffer allocated with lpfnAllocate and lpfnReAllocate */ , BYVAL lpvReserved AS QUAD ' void * lpvReserved ) AS QUAD ' unsigned long
' /* for usSubsetFormat */
%EQUATE `TTFCFP_SUBSET = 0 ' /* Straight Subset Font - Backward compatibility */
%EQUATE `TTFCFP_SUBSET1 = 1 ' /* Subset font with full TTO and Kern tables. For later merge */
%EQUATE `TTFCFP_DELTA = 2 ' /* Delta font, for merge with a subset1 font */
' /* for usSubsetPlatform ID values */
%EQUATE `TTFCFP_UNICODE_PLATFORMID = 0
%EQUATE `TTFCFP_APPLE_PLATFORMID = 1
%EQUATE `TTFCFP_ISO_PLATFORMID = 2
%EQUATE `TTFCFP_MS_PLATFORMID = 3
' /* for usSubsetEncoding values */
%EQUATE `TTFCFP_STD_MAC_CHAR_SET = 0 ' /* goes with TTFSUB_APPLE_PLATFORMID */
%EQUATE `TTFCFP_SYMBOL_CHAR_SET = 0 ' /* goes with TTFSUB_MS_PLATFORMID */
%EQUATE `TTFCFP_UNICODE_CHAR_SET = 1 ' /* goes with TTFSUB_MS_PLATFORMID */
%EQUATE `TTFCFP_DONT_CARE = &HFFFF
' /* for usSubsetLanguage values */
%EQUATE `TTFCFP_LANG_KEEP_ALL = 0
'' /* for usFlags values */
%EQUATE `TTFCFP_FLAGS_SUBSET = &H0001 ' /* if bit off, don't subset */
%EQUATE `TTFCFP_FLAGS_COMPRESS = &H0002 ' /* if bit off, don't compress */
%EQUATE `TTFCFP_FLAGS_TTC = &H0004 ' /* if bit off, its a TTF */
%EQUATE `TTFCFP_FLAGS_GLYPHLIST = &H0008 ' /* if bit off, list is characters */
'unsigned long __cdecl MergeFontPackage(CONST unsigned char * puchMergeFontBuffer, ' /* buffer containing font to merge with */
' CONST unsigned long ulMergeFontBufferSize, ' /* size of buffer containing font to merge with */
' CONST unsigned char * puchFontPackageBuffer, ' /* buffer containing a font package to merge with the MergeFontBuffer */
' CONST unsigned long ulFontPackageBufferSize, ' /* length of FontPakageBuffer */
' unsigned char **ppuchDestBuffer, ' /* output: pointer to output buffer containing a TTF to install */
' unsigned long *pulDestBufferSize, ' /* output: length of output buffer containing TTF to install */
' unsigned long *pulBytesWritten, ' /* output: number of bytes in buffer used for TTF */
' CONST unsigned short usMode, ' /* kind of action to perform, see #defines below */
' CFP_ALLOCPROC lpfnAllocate, ' /* call back function to allocate output and intermediate buffers */
' CFP_REALLOCPROC lpfnReAllocate, ' /* call back function to allocate or reallocate output and intermediate buffers */
' CFP_FREEPROC lpfnFree, ' /* call back function to free buffer allocated with lpfnReAllocate */
' void *lpvReserved);
DECLARE FUNCTION MergeFontPackage CDECL LIB "fontsub.dll" ALIAS "MergeFontPackage" ( BYVAL puchMergeFontBuffer AS BYTE PTR ' CONST unsigned char * puchMergeFontBuffer /* buffer containing font to merge with */ , BYVAL ulMergeFontBufferSize AS QUAD ' CONST unsigned long ulMergeFontBufferSize /* size of buffer containing font to merge with */ , BYVAL puchFontPackageBuffer AS QUAD ' CONST unsigned char * puchFontPackageBuffer /* buffer containing a font package to merge with the MergeFontBuffer */ , BYVAL ulFontPackageBufferSize AS QUAD ' CONST unsigned long ulFontPackageBufferSize /* length of FontPakageBuffer */ , BYREF ppuchDestBuffer AS QUAD ' unsigned char **ppuchDestBuffer /* output: pointer to output buffer containing a TTF to install */ , BYREF pulDestBufferSize AS QUAD ' unsigned long *pulDestBufferSize /* output: length of output buffer containing TTF to install */ , BYREF pulBytesWritten AS QUAD ' unsigned long *pulBytesWritten /* output: number of bytes in buffer used for TTF */ , BYVAL usMode AS WORD ' CONST unsigned short usMode /* kind of action to perform, see #defines below */ , BYVAL lpfnAllocate AS QUAD ' CFP_ALLOCPROC lpfnAllocate /* call back function to allocate output and intermediate buffers */ , BYVAL lpfnReAllocate AS QUAD ' CFP_REALLOCPROC lpfnReAllocate /* call back function to allocate or reallocate output and intermediate buffers */ , BYVAL lpfnFree AS QUAD ' CFP_FREEPROC lpfnFree /* call back function to free buffer allocated with lpfnReAllocate */ , BYVAL lpvReserved AS QUAD ' void *lpvReserved ) AS QUAD ' unsigned long
' /* for usModes */
%EQUATE `TTFMFP_SUBSET = 0 ' /* copy a Straight Subset Font package to Dest buffer */
%EQUATE `TTFMFP_SUBSET1 = 1 ' /* Expand a format 1 font into a format 3 font */
%EQUATE `TTFMFP_DELTA = 2 ' /* Merge a format 2 with a format 3 font */
' /* Error codes */
#IF NOT %DEF(%NO_ERROR)
%EQUATE `NO_ERROR = 0
#ENDIF
#IF NOT %DEF(%ERR_GENERIC)
%EQUATE `ERR_GENERIC = 1000
%EQUATE `ERR_READOUTOFBOUNDS = 1001 ' /* trying to read from memory not allowed - data error? */
%EQUATE `ERR_WRITEOUTOFBOUNDS = 1002 ' /* trying to write to memory not allowed - data error? */
%EQUATE `ERR_READCONTROL = 1003 ' /* read control structure does not match data */
%EQUATE `ERR_WRITECONTROL = 1004 ' /* write control structure does not match data */
%EQUATE `ERR_MEM = 1005 ' /* error allocating memory */
%EQUATE `ERR_FORMAT = 1006 ' /* input data format error */
%EQUATE `ERR_WOULD_GROW = 1007 ' /* action would cause data to grow. use original data */
%EQUATE `ERR_VERSION = 1008 ' /* major dttf.version of the input data is greater than the version this program can read */
%EQUATE `ERR_NO_GLYPHS = 1009
%EQUATE `ERR_INVALID_MERGE_FORMATS = 1010 ' /* trying to merge fonts with the wrong dttf formats */
%EQUATE `ERR_INVALID_MERGE_CHECKSUMS = 1011 ' /* trying to merge 2 fonts from different mother font */
%EQUATE `ERR_INVALID_MERGE_NUMGLYPHS = 1012 ' /* trying to merge 2 fonts from different mother font */
%EQUATE `ERR_INVALID_DELTA_FORMAT = 1013 ' /* trying to subset a format 1 or 2 font */
%EQUATE `ERR_NOT_TTC = 1014
%EQUATE `ERR_INVALID_TTC_INDEX = 1015
%EQUATE `ERR_MISSING_CMAP = 1030
%EQUATE `ERR_MISSING_GLYF = 1031
%EQUATE `ERR_MISSING_HEAD = 1032
%EQUATE `ERR_MISSING_HHEA = 1033
%EQUATE `ERR_MISSING_HMTX = 1034
%EQUATE `ERR_MISSING_LOCA = 1035
%EQUATE `ERR_MISSING_MAXP = 1036
%EQUATE `ERR_MISSING_NAME = 1037
%EQUATE `ERR_MISSING_POST = 1038
%EQUATE `ERR_MISSING_OS2 = 1039
%EQUATE `ERR_MISSING_VHEA = 1040
%EQUATE `ERR_MISSING_VMTX = 1041
%EQUATE `ERR_MISSING_HHEA_OR_VHEA = 1042
%EQUATE `ERR_MISSING_HMTX_OR_VMTX = 1043
%EQUATE `ERR_MISSING_EBDT = 1044
%EQUATE `ERR_INVALID_CMAP = 1060
%EQUATE `ERR_INVALID_GLYF = 1061
%EQUATE `ERR_INVALID_HEAD = 1062
%EQUATE `ERR_INVALID_HHEA = 1063
%EQUATE `ERR_INVALID_HMTX = 1064
%EQUATE `ERR_INVALID_LOCA = 1065
%EQUATE `ERR_INVALID_MAXP = 1066
%EQUATE `ERR_INVALID_NAME = 1067
%EQUATE `ERR_INVALID_POST = 1068
%EQUATE `ERR_INVALID_OS2 = 1069
%EQUATE `ERR_INVALID_VHEA = 1070
%EQUATE `ERR_INVALID_VMTX = 1071
%EQUATE `ERR_INVALID_HHEA_OR_VHEA = 1072
%EQUATE `ERR_INVALID_HMTX_OR_VMTX = 1073
%EQUATE `ERR_INVALID_TTO = 1080
%EQUATE `ERR_INVALID_GSUB = 1081
%EQUATE `ERR_INVALID_GPOS = 1082
%EQUATE `ERR_INVALID_GDEF = 1083
%EQUATE `ERR_INVALID_JSTF = 1084
%EQUATE `ERR_INVALID_BASE = 1085
%EQUATE `ERR_INVALID_EBLC = 1086
%EQUATE `ERR_INVALID_LTSH = 1087
%EQUATE `ERR_INVALID_VDMX = 1088
%EQUATE `ERR_INVALID_HDMX = 1089
%EQUATE `ERR_PARAMETER0 = 1100 ' /* calling function argument 0 is invalid */
%EQUATE `ERR_PARAMETER1 = 1101 ' /* calling function argument 1 is invalid */
%EQUATE `ERR_PARAMETER2 = 1102 ' /* calling function argument 2 is invalid */
%EQUATE `ERR_PARAMETER3 = 1103 ' /* calling function argument 3 is invalid */
%EQUATE `ERR_PARAMETER4 = 1104 ' /* calling function argument 4 is invalid */
%EQUATE `ERR_PARAMETER5 = 1105 ' /* calling function argument 5 is invalid */
%EQUATE `ERR_PARAMETER6 = 1106 ' /* calling function argument 6 is invalid */
%EQUATE `ERR_PARAMETER7 = 1107 ' /* calling function argument 7 is invalid */
%EQUATE `ERR_PARAMETER8 = 1108 ' /* calling function argument 8 is invalid */
%EQUATE `ERR_PARAMETER9 = 1109 ' /* calling function argument 9 is invalid */
%EQUATE `ERR_PARAMETER10 = 1110 ' /* calling function argument 10 is invalid */
%EQUATE `ERR_PARAMETER11 = 1111 ' /* calling function argument 11 is invalid */
%EQUATE `ERR_PARAMETER12 = 1112 ' /* calling function argument 12 is invalid */
%EQUATE `ERR_PARAMETER13 = 1113 ' /* calling function argument 13 is invalid */
%EQUATE `ERR_PARAMETER14 = 1114 ' /* calling function argument 14 is invalid */
%EQUATE `ERR_PARAMETER15 = 1115 ' /* calling function argument 15 is invalid */
%EQUATE `ERR_PARAMETER16 = 1116 ' /* calling function argument 16 is invalid */
#ENDIF ' /* ERR_GENERIC */
#ENDIF
