/* WATCOM Interface Generator   Version 1.0 */
/* This file contains code generated by PowerBuilder.
 * Do not modify code delimited by comments of the form:
 * // $PB$ -- begin generated code for object <>.  Do not modify this code
 * // $PB$ -- end generated code for object <>.
 * This file contains the bodies the functions for your user object.
 */ 



#include <pbdll.h>

#include "u_cpp_LO.hpp"

HDC hdcGlobal;
PTRUETYPEFONTINFO pArrayOfTTFInfo;
int iFace;
int iNumOfFontFaces;

int APIENTRY MyEnumfontFacesProc(
	LPLOGFONT lpLogFont,LPTEXTMETRIC lpTEXTMETRICS,
	DWORD fFontType,LPINT lpData)
{
	if(fFontType & TRUETYPE_FONTTYPE)
	{
		pArrayOfTTFInfo[iFace].plf=(LPLOGFONT)LocalAlloc(LPTR,sizeof(LOGFONT));
		pArrayOfTTFInfo[iFace].ptm=(LPTEXTMETRIC)LocalAlloc(LPTR,sizeof(TEXTMETRIC));
		if((pArrayOfTTFInfo[iFace].plf==NULL) ||
		   (pArrayOfTTFInfo[iFace].ptm==NULL))
		{
			MessageBox(NULL,"ÄÚ´æ·ÖÅäÊ§°Ü",NULL,MB_OK);
			return(FALSE);
		}
		*(pArrayOfTTFInfo[iFace].plf)=*lpLogFont;
		*(pArrayOfTTFInfo[iFace].ptm)=*lpTEXTMETRICS;
		iFace++;
	}
	return(TRUE);
}

int APIENTRY MyEnumfontCountProc(
	LPLOGFONT lpLogFont,LPTEXTMETRIC lptEXTMETRICs,
	DWORD fFontType,LPINT lpData)
{
	if(fFontType&TRUETYPE_FONTTYPE)
		(*lpData)++;
	return(TRUE);
}

PTRUETYPEFONTINFO BuildFontList(HDC hDCFont,LPINT retnFaces)
{
	iNumOfFontFaces=0;
	hdcGlobal=hDCFont;
	
	EnumFontFamilies(hdcGlobal,NULL,(FONTENUMPROC)MyEnumfontCountProc,
				(LPARAM)&iNumOfFontFaces);
	pArrayOfTTFInfo=(PTRUETYPEFONTINFO)LocalAlloc(LPTR,
			sizeof(TRUETYPEFONTINFO)*(iNumOfFontFaces +1 ));
			
	iFace=0;
	EnumFontFamilies(hdcGlobal,NULL,(FONTENUMPROC)MyEnumfontFacesProc,(LPARAM)NULL);
	*retnFaces=iNumOfFontFaces;
	
	return(pArrayOfTTFInfo);
}


// $PB$ -- begin generated code for object <u_cpp_getfontinf>.  Do not modify this code
#if 1
short u_cpp_getfontinf::uf_getfontname( char *as_fontname, short ai_fontnum ) {
// $PB$ -- end generated code for object <u_cpp_getfontinf>.
//==================================

    /*
     * PUT YOUR CODE HERE
    */
	strcpy(as_fontname,pArrayOfTTFInfo[ai_fontnum].plf->lfFaceName);
//	MessageBox(NULL,pArrayOfTTFInfo[ai_fontnum].plf->lfFaceName,NULL,MB_OK);


    return( 0 );
}
#endif // PowerBuilder code, do not remove 


// $PB$ -- begin generated code for object <u_cpp_getfontinf>.  Do not modify this code
#if 1
short u_cpp_getfontinf::uf_init( long al_hwnd ) {
// $PB$ -- end generated code for object <u_cpp_getfontinf>.
//==================================
    HDC  hDC;
    
    hDC=GetDC((HWND)al_hwnd);
    
    pArrayOfTTFInfo=BuildFontList(hDC,&iNumOfFontFaces);
    ReleaseDC((HWND)al_hwnd,hDC);

    return( 0 );
}
#endif // PowerBuilder code, do not remove 


// $PB$ -- begin generated code for object <u_cpp_getfontinf>.  Do not modify this code
#if 1
unsigned short u_cpp_getfontinf::uf_getfontcount(  ) {
// $PB$ -- end generated code for object <u_cpp_getfontinf>.
//==================================

    /*
     * PUT YOUR CODE HERE
     */

    return( iNumOfFontFaces );
}
#endif // PowerBuilder code, do not remove 


