+ vError = ::WinGetLastError(wxGetInstance());
+ sError = wxPMErrorToStr(vError);
+ return;
+ }
+
+ //
+ // Allocate space for the font metrics.
+ //
+ pFM = new FONTMETRICS[lNumFonts + 1];
+
+ //
+ // Retrieve the font metrics.
+ //
+ lTemp = lNumFonts;
+ lTemp = ::GpiQueryFonts( *phPS
+ ,QF_PUBLIC
+ ,NULL
+ ,&lTemp
+ ,(LONG) sizeof(FONTMETRICS)
+ ,pFM
+ );
+ pFont->SetFM( pFM
+ ,(int)lNumFonts
+ );
+
+ wxString sVals;
+
+ //
+ // For debugging, delete later
+ //
+ 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(*phPS);
+ long lGpiError;
+
+ if(lNumLids )
+ {
+ long alTypes[255];
+ STR8 azNames[255];
+ long alIds[255];
+
+ if(!::GpiQuerySetIds( *phPS
+ ,lNumLids
+ ,alTypes
+ ,azNames
+ ,alIds
+ ))
+ {
+ if (bInternalPS)
+ ::WinReleasePS(*phPS);
+ return;
+ }
+
+ for(unsigned long LCNum = 0; LCNum < lNumLids; LCNum++)
+ if(alIds[LCNum] == *pflId)
+ ++*pflId;
+ if(*pflId > 254) // wow, no id available!
+ {
+ if (bInternalPS)
+ ::WinReleasePS(*phPS);
+ return;
+ }
+ }
+ else
+ *pflId = 1L;
+ //
+ // Release and delete the current font
+ //
+ ::GpiSetCharSet(*phPS, LCID_DEFAULT);/* release the font before deleting */
+ ::GpiDeleteSetId(*phPS, 1L); /* delete the logical font */
+
+ //
+ // Now build a facestring
+ //
+ char zFacename[128];
+
+ strcpy(zFacename, pFattrs->szFacename);
+
+ if(::GpiQueryFaceString( *phPS
+ ,zFacename
+ ,pFaceName
+ ,FACESIZE
+ ,pFattrs->szFacename
+ ) == GPI_ERROR)
+ {
+ vError = ::WinGetLastError(vHabmain);
+ }
+ sFaceName = zFacename;
+ *pbInternalPS = bInternalPS;
+
+ //
+ // That's it, we now have everything we need to actually create the font
+ //
+} // end of wxFillLogFont
+
+void wxOS2SelectMatchingFontByName(
+ PFATTRS pFattrs
+, PFACENAMEDESC pFaceName
+, PFONTMETRICS pFM
+, int nNumFonts
+, const wxFont* pFont
+)
+{
+ int i;
+ int nDiff0;
+ int nPointSize;
+ int nDiff;
+ int nIs;
+ int nMinDiff;
+ int nMinDiff0;
+ int nApirc;
+ int anDiff[16];
+ int anMinDiff[16];
+ int nIndex = 0;
+ STR8 zFn;
+ char zFontFaceName[FACESIZE];
+ wxString sFaceName;
+ USHORT usWeightClass;
+ int fsSelection = 0;
+
+ nMinDiff0 = 0xf000;
+ for(i = 0;i < 16; i++)
+ anMinDiff[i] = nMinDiff0;
+
+ switch (pFont->GetFamily())