' ########################################################################################
' Microsoft Windows
' File: t2embapi.inc
' Contents: OpenType embedding services dll (T2EMBED.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_t2embapi_PBI)
#DEFINE PBX_t2embapi_PBI
%T2EMBAPI_INC = 1
'// Charset flags for ulCharSet field of TTEmbedFont
%CHARSET_UNICODE = 1
%CHARSET_DEFAULT = 1
%CHARSET_SYMBOL = 2
%CHARSET_GLYPHIDX = 3
'// Status returned by TTLoadEmbeddedFont
%EMBED_PREVIEWPRINT = 1
%EMBED_EDITABLE = 2
%EMBED_INSTALLABLE = 3
%EMBED_NOEMBEDDING = 4
'// Use restriction flags
%LICENSE_INSTALLABLE = &H0000
%LICENSE_DEFAULT = &H0000
%LICENSE_NOEMBEDDING = &H0002
%LICENSE_PREVIEWPRINT = &H0004
%LICENSE_EDITABLE = &H0008
'// Options given to TTEmbedFont in uFlags parameter
%TTEMBED_RAW = &H00000000
%TTEMBED_SUBSET = &H00000001
%TTEMBED_TTCOMPRESSED = &H00000004
%TTEMBED_FAILIFVARIATIONSIMULATED = &H00000010
'// Embed EUDC font. If there is typeface EUDC embed it otherwise embed system EUDC.
%TTEMBED_EMBEDEUDC = &H00000020
%TTEMBED_WEBOBJECT = &H00000080
%TTEMBED_XORENCRYPTDATA = &H10000000
'// Bits returned through pulStatus for TTEmbedFont
%TTEMBED_VARIATIONSIMULATED = &H00000001
'// Bit set if EUDC embed success.
%TTEMBED_EUDCEMBEDDED = &H00000002
'// Bit set if font embedding permissions indicate no subset and subset requested by client.
%TTEMBED_SUBSETCANCEL = &H00000004
'// Flag options for TTLoadEmbeddedFont
%TTLOAD_PRIVATE = &H00000001
'// If typeface already has EUDC, overwrite setting.
%TTLOAD_EUDC_OVERWRITE = &H00000002
'// Bits returned through pulStatus for TTLoadEmbeddedFont
%TTLOAD_FONT_SUBSETTED = &H00000001
%TTLOAD_FONT_IN_SYSSTARTUP = &H00000002
%TTLOAD_EUDC_SET = &H00000004
'// Flag options for TTDeleteEmbeddedFont
%TTDELETE_DONTREMOVEFONT = &H00000001
'// Error codes
%E_NONE = &H0000&
%E_API_NOTIMPL = &H0001&
'// Top level error codes
%E_CHARCODECOUNTINVALID = &H0002&
%E_CHARCODESETINVALID = &H0003&
%E_DEVICETRUETYPEFONT = &H0004&
%E_HDCINVALID = &H0006&
%E_NOFREEMEMORY = &H0007&
%E_FONTREFERENCEINVALID = &H0008&
%E_NOTATRUETYPEFONT = &H000A&
%E_ERRORACCESSINGFONTDATA = &H000C&
%E_ERRORACCESSINGFACENAME = &H000D&
%E_ERRORUNICODECONVERSION = &H0011&
%E_ERRORCONVERTINGCHARS = &H0012&
%E_EXCEPTION = &H0013&
%E_RESERVEDPARAMNOTNULL = &H0014&
%E_CHARSETINVALID = &H0015&
%E_FILE_NOT_FOUND = &H0017&
%E_TTC_INDEX_OUT_OF_RANGE = &H0018&
%E_INPUTPARAMINVALID = &H0019&
'// Indep level error codes
%E_ERRORCOMPRESSINGFONTDATA = &H0100&
%E_FONTDATAINVALID = &H0102&
%E_NAMECHANGEFAILED = &H0103&
%E_FONTNOTEMBEDDABLE = &H0104&
%E_PRIVSINVALID = &H0105&
%E_SUBSETTINGFAILED = &H0106&
%E_READFROMSTREAMFAILED = &H0107&
%E_SAVETOSTREAMFAILED = &H0108&
%E_NOOS2 = &H0109&
%E_T2NOFREEMEMORY = &H010A&
%E_ERRORREADINGFONTDATA = &H010B&
%E_FLAGSINVALID = &H010C&
%E_ERRORCREATINGFONTFILE = &H010D&
%E_FONTALREADYEXISTS = &H010E&
%E_FONTNAMEALREADYEXISTS = &H010F&
%E_FONTINSTALLFAILED = &H0110&
%E_ERRORDECOMPRESSINGFONTDATA = &H0111&
%E_ERRORACCESSINGEXCLUDELIST = &H0112&
%E_FACENAMEINVALID = &H0113&
%E_STREAMINVALID = &H0114&
%E_STATUSINVALID = &H0115&
%E_PRIVSTATUSINVALID = &H0116&
%E_PERMISSIONSINVALID = &H0117&
%E_PBENABLEDINVALID = &H0118&
%E_SUBSETTINGEXCEPTION = &H0119&
%E_SUBSTRING_TEST_FAIL = &H011A&
%E_FONTVARIATIONSIMULATED = &H011B&
%E_FONTFAMILYNAMENOTINFULL = &H011D&
'// Bottom level error codes
%E_ADDFONTFAILED = &H0200&
%E_COULDNTCREATETEMPFILE = &H0201&
%E_FONTFILECREATEFAILED = &H0203&
%E_WINDOWSAPI = &H0204&
%E_FONTFILENOTFOUND = &H0205&
%E_RESOURCEFILECREATEFAILED = &H0206&
%E_ERROREXPANDINGFONTDATA = &H0207&
%E_ERRORGETTINGDC = &H0208&
%E_EXCEPTIONINDECOMPRESSION = &H0209&
%E_EXCEPTIONINCOMPRESSION = &H020A&
'// 1st argument - Stream identifier (file handle or other) (dwStream) */
'// 2nd argument - Address of buffer with data to read or write */
'// 3rd argument - Number of bytes to read or write */
'typedef unsigned long( WINAPIV *READEMBEDPROC ) ( void*, void*, const unsigned long );
'FUNCTION READEMBEDPROC ( ' BYVAL lpvReadStream AS DWORD
' , BYVAL lpvBuffer AS DWORD
' , BYVAL cbBuffer AS DWORD
' ) AS DWORD ' unsigned long
'typedef unsigned long( WINAPIV *WRITEEMBEDPROC ) ( void*, const void*, const unsigned long );
'FUNCTION WRITEEMBEDPROC ( ' BYVAL lpvReadStream AS DWORD
' , BYVAL lpvBuffer AS DWORD
' , BYVAL cbBuffer AS DWORD
' ) AS DWORD ' unsigned long
' // Size = 8 bytes
TYPE TTLOADINFO DWORD FILL
 usStructSize AS WORD ' unsigned short // size in bytes of structure client should set to sizeof(TTLOADINFO)
 usRefStrSize AS WORD ' unsigned short // size in wide characters of pusRefStr including NULL terminator
 pusRefStr AS WSTRINGZ PTR ' unsigned short * // reference or actual string.
END TYPE
' // Size = 8 bytes
TYPE TTEMBEDINFO DWORD FILL
 usStructSize AS WORD ' unsigned short // size in bytes of structure client should set to sizeof(TTEMBEDINFO)
 usRootStrSize AS WORD ' unsigned short // size in wide chars of pusSubStr including NULL terminator(s)
 pusRootStr AS WSTRINGZ PTR ' unsigned short * // substring(s) of strings given at load time. can have multiple strings separated
 ' // by a NULL terminator.
END TYPE
' // Size = 24 bytes
TYPE TTVALIDATIONTESTSPARAMS DWORD FILL
 ulStructSize AS DWORD ' unsigned long
 lTestFromSize AS LONG ' long
 lTestToSize AS LONG ' long
 ulCharSet AS DWORD ' unsigned long // Same as ulCharSet param to TTEmbedFont.
 usReserved1 AS WORD ' unsigned short
 usCharCodeCount AS WORD ' unsigned short // If zero, we test over all glyphs.
 pusCharCodeSet AS WSTRINGZ PTR ' unsigned short * // Pointer to array of Unicode chars.
END TYPE
' // Size = 24 bytes
TYPE TTVALIDATIONTESTSPARAMSEX DWORD FILL
 ulStructSize AS DWORD ' unsigned loong
 lTestFromSize AS LONG ' long
 lTestToSize AS LONG ' long
 ulCharSet AS DWORD ' unsigned loong // Same as ulCharSet param to TTEmbedFont.
 usReserved1 AS WORD ' unsigned short
 usCharCodeCount AS WORD ' unsigned short // If zero, we test over all glyphs.
 pulCharCodeSet AS WSTRINGZ PTR ' unsigned short * // Pointer to array of Unicode chars.
END TYPE
'/* Font Embedding APIs ----------------------------------------------------*/
DECLARE FUNCTION TTEmbedFont LIB "t2embed.dll" ALIAS "TTEmbedFont" ( BYVAL hDC AS QUAD , BYVAL ulFlags AS QUAD , BYVAL ulCharSet AS QUAD , BYREF pulPrivStatus AS QUAD , BYREF pulStatus AS QUAD , BYVAL lpfnWriteToStream AS QUAD , BYVAL lpvWriteStream AS QUAD , BYREF pusCharCodeSet AS WORD , BYVAL usCharCodeCount AS WORD , BYVAL usLanguage AS WORD , BYREF pTTEmbedInfo AS TTEMBEDINFO ) AS LONG
DECLARE FUNCTION TTEmbedFontFromFileA LIB "t2embed.dll" ALIAS "TTEmbedFontFromFileA" ( BYVAL hDC AS QUAD , BYREF szFontFileName AS ASCIIZ , BYVAL usTTCIndex AS WORD , BYVAL ulFlags AS DWORD , BYVAL ulCharSet AS DWORD , BYREF pulPrivStatus AS DWORD , BYREF pulStatus AS DWORD , BYVAL lpfnWriteToStream AS DWORD , BYVAL lpvWriteStream AS DWORD , BYREF pusCharCodeSet AS WORD , BYVAL usCharCodeCount AS WORD , BYVAL usLanguage AS WORD , BYREF pTTEmbedInfo AS TTEMBEDINFO ) AS LONG
DECLARE FUNCTION TTLoadEmbeddedFont LIB "t2embed.dll" ALIAS "TTLoadEmbeddedFont" ( BYREF phFontReference AS DWORD , BYVAL ulFlags AS DWORD , BYREF pulPrivStatus AS DWORD , BYVAL ulPrivs AS DWORD , BYREF pulStatus AS DWORD , BYVAL lpfnReadFromStream AS DWORD , BYVAL lpvReadStream AS DWORD , BYREF szWinFamilyName AS WSTRINGZ , BYREF szMacFamilyName AS ASCIIZ , BYREF pTTLoadInfo AS TTLOADINFO ) AS LONG
DECLARE FUNCTION TTGetEmbeddedFontInfo LIB "t2embed.dll" ALIAS "TTGetEmbeddedFontInfo" ( BYVAL ulFlags AS DWORD , BYREF pulPrivStatus AS DWORD , BYVAL ulPrivs AS DWORD , BYREF pulStatus AS DWORD , BYVAL lpfnReadFromStream AS DWORD , BYVAL lpvReadStream AS DWORD , BYREF pTTLoadInfo AS TTLOADINFO ) AS LONG
DECLARE FUNCTION TTDeleteEmbeddedFont LIB "t2embed.dll" ALIAS "TTDeleteEmbeddedFont" ( BYVAL hFontReference AS DWORD , BYVAL ulFlags AS DWORD , BYREF pulStatus AS DWORD ) AS LONG
DECLARE FUNCTION TTGetEmbeddingType LIB "t2embed.dll" ALIAS "TTGetEmbeddingType" ( BYVAL hDC AS DWORD , BYREF pulEmbedType AS DWORD ) AS LONG
DECLARE FUNCTION TTCharToUnicode LIB "t2embed.dll" ALIAS "TTCharToUnicode" ( BYVAL hDC AS DWORD , BYREF pucCharCodes AS BYTE , BYVAL ulCharCodeSize AS DWORD , BYREF pusShortCodes AS WORD , BYVAL ulShortCodeSize AS DWORD , BYVAL ulFlags AS DWORD ) AS LONG
DECLARE FUNCTION TTRunValidationTests LIB "t2embed.dll" ALIAS "TTRunValidationTests" ( BYVAL hDC AS DWORD , BYREF pTestParam AS TTVALIDATIONTESTSPARAMS ) AS LONG
'/* Font Enabling APIs -----------------------------------------------------*/
DECLARE FUNCTION TTIsEmbeddingEnabled LIB "t2embed.dll" ALIAS "TTIsEmbeddingEnabled" ( BYVAL hDC AS QUAD , BYREF pbEnabled AS LONG ) AS LONG
DECLARE FUNCTION TTIsEmbeddingEnabledForFacename LIB "t2embed.dll" ALIAS "TTIsEmbeddingEnabledForFacename" ( BYREF lpszFacename AS ASCIIZ , BYREF pbEnabled AS LONG ) AS LONG
' If fEnable != 0, it removes the indicated typeface name from the "embedding
' exclusion list". Else, it enters the indicated typeface name in the "embedding exclusion list".
DECLARE FUNCTION TTEnableEmbeddingForFacename LIB "t2embed.dll" ALIAS "TTEnableEmbeddingForFacename" ( BYREF lpszFacename AS ASCIIZ , BYVAL bEnable AS LONG ) AS LONG
DECLARE FUNCTION TTEmbedFontEx LIB "t2embed.dll" ALIAS "TTEmbedFontEx" ( BYVAL hDC AS QUAD , BYVAL ulFlags AS DWORD , BYVAL ulCharSet AS DWORD , BYREF pulPrivStatus AS DWORD , BYREF pulStatus AS DWORD , BYVAL lpfnWriteToStream AS DWORD , BYVAL lpvWriteStream AS DWORD , BYREF pulCharCodeSet AS DWORD , BYVAL usCharCodeCount AS WORD , BYVAL usLanguage AS WORD , BYREF pTTEmbedInfo AS TTEMBEDINFO ) AS LONG
DECLARE FUNCTION TTRunValidationTestsEx LIB "t2embed.dll" ALIAS "TTRunValidationTestsEx" ( BYVAL hDC AS DWORD , BYREF pTestParam AS TTVALIDATIONTESTSPARAMSEX ) AS LONG
DECLARE FUNCTION TTGetNewFontName LIB "t2embed.dll" ALIAS "TTGetNewFontName" ( BYVAL phFontReference AS DWORD , BYREF wzWinFamilyName AS WSTRINGZ , BYVAL cchMaxWinName AS LONG , BYREF szMacFamilyName AS ASCIIZ , BYVAL cchMaxMacName AS LONG ) AS LONG