+ LONG lNumFonts = 0L; // For system font count
+ ERRORID vError; // For logging API errors
+ LONG lTemp;
+ bool bInternalPS = FALSE; // if we have to create one
+ PFONTMETRICS pFM = NULL;
+
+ //
+ // Initial house cleaning to free data buffers and ensure we have a
+ // functional PS to work with
+ //
+ if (!hPS)
+ {
+ hPS = ::WinGetPS(HWND_DESKTOP);
+ bInternalPS = TRUE;
+ }
+
+ //
+ // Determine the number of fonts.
+ //
+ lNumFonts = ::GpiQueryFonts( hPS
+ ,QF_PUBLIC
+ ,NULL
+ ,&lTemp
+ ,(LONG) sizeof(FONTMETRICS)
+ ,NULL
+ );
+
+ //
+ // Allocate space for the font metrics.
+ //
+ pFM = new FONTMETRICS[lNumFonts + 1];
+
+ //
+ // Retrieve the font metrics.
+ //
+ lTemp = lNumFonts;
+ lTemp = ::GpiQueryFonts( hPS
+ ,QF_PUBLIC
+ ,NULL
+ ,&lTemp
+ ,(LONG) sizeof(FONTMETRICS)
+ ,pFM
+ );
+ pFont->SetFM( pFM
+ ,(int)lNumFonts
+ );
+
+ wxString sVals;
+
+ for (int i = 0; i < lNumFonts; i++)
+ {
+ sVals << "Face: " << pFM[i].szFacename
+ << "Family: " << pFM[i].szFamilyname
+ << " PointSize: " << pFM[i].lEmHeight
+ << " Height: " << pFM[i].lXHeight
+ ;
+ sVals = "";
+ }
+
+ //
+ // Initialize FATTR and FACENAMEDESC
+ //
+ pFattrs->usRecordLength = sizeof(FATTRS);
+ pFattrs->fsFontUse = FATTR_FONTUSE_OUTLINE | // only outline fonts allowed
+ FATTR_FONTUSE_TRANSFORMABLE; // may be transformed
+ pFattrs->fsType = 0;
+ pFattrs->lMaxBaselineExt = pFattrs->lAveCharWidth = 0;
+ pFattrs->idRegistry = 0;
+ pFattrs->lMatch = 0;
+
+ pFaceName->usSize = sizeof(FACENAMEDESC);
+ pFaceName->usWidthClass = FWIDTH_NORMAL;
+ pFaceName->usReserved = 0;
+ pFaceName->flOptions = 0;
+
+ //
+ // This does the actual selection of fonts
+ //
+ wxOS2SelectMatchingFontByName( pFattrs
+ ,pFaceName
+ ,pFM
+ ,(int)lNumFonts
+ ,pFont
+ );
+ //
+ // We should now have the correct FATTRS set with the selected
+ // font, so now we need to generate an ID
+ //
+ long lNumLids = ::GpiQueryNumberSetIds(hPS);
+ long lGpiError;
+
+ if(lNumLids )
+ {
+ long alTypes[255];
+ STR8 azNames[255];
+ long alIds[255];
+
+ if(!::GpiQuerySetIds( hPS
+ ,lNumLids
+ ,alTypes
+ ,azNames
+ ,alIds
+ ))
+ {
+ if (bInternalPS)
+ ::WinReleasePS(hPS);
+ return;
+ }
+
+ for(unsigned long LCNum = 0; LCNum < lNumLids; LCNum++)
+ if(alIds[LCNum] == *pflId)
+ ++*pflId;
+ if(*pflId > 254) // wow, no id available!
+ {
+ if (bInternalPS)
+ ::WinReleasePS(hPS);
+ return;
+ }
+ }