+ LONG lNumFonts = 0L;
+ LONG lTemp = 0L;
+ PFONTMETRICS pFM = NULL;
+ ERRORID vError;
+
+ if ( GetResourceHandle() )
+ {
+ // VZ: the old code returned FALSE in this case, but it doesn't seem
+ // to make sense because the font _was_ created
+ wxLogDebug(wxT("Calling wxFont::RealizeResource() twice"));
+
+ return TRUE;
+ }
+
+ LONG flId;
+ bool bInternalPS = FALSE; // if we have to create one
+
+ //
+ // Now cheking
+ //
+ flId = 1L;
+ if (!M_FONTDATA->m_hPS)
+ {
+ M_FONTDATA->m_hPS = ::WinGetPS(HWND_DESKTOP);
+ bInternalPS = TRUE;
+ }
+
+ if (M_FONTDATA->m_pFM)
+ {
+ delete [] M_FONTDATA->m_pFM;
+ M_FONTDATA->m_pFM = NULL;
+ }
+ //
+ // Determine the number of fonts.
+ //
+ lNumFonts = ::GpiQueryFonts( M_FONTDATA->m_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( M_FONTDATA->m_hPS
+ ,QF_PUBLIC
+ ,NULL
+ ,&lTemp
+ ,(LONG) sizeof(FONTMETRICS)
+ ,pFM
+ );
+ SetFM( pFM
+ ,(int)lNumFonts
+ );
+
+ wxString sVals;
+
+ for (int i = 0; i < lNumFonts; i++)
+ {
+ sVals << "Face: " <<M_FONTDATA->m_pFM[i].szFacename
+ << "Family: " <<M_FONTDATA->m_pFM[i].szFamilyname
+ << " PointSize: " << M_FONTDATA->m_pFM[i].lEmHeight
+ << " Height: " << M_FONTDATA->m_pFM[i].lXHeight
+ ;
+ sVals = "";
+ }
+ M_FONTDATA->m_vFattrs.usRecordLength = sizeof(FATTRS);
+ M_FONTDATA->m_vFattrs.fsFontUse = FATTR_FONTUSE_OUTLINE | // only outline fonts allowed
+ FATTR_FONTUSE_TRANSFORMABLE; // may be transformed
+ M_FONTDATA->m_vFattrs.fsType = 0;
+ M_FONTDATA->m_vFattrs.lMaxBaselineExt = M_FONTDATA->m_vFattrs.lAveCharWidth = 0;
+ M_FONTDATA->m_vFattrs.idRegistry = 0;
+ M_FONTDATA->m_vFattrs.lMatch = 0;
+
+ M_FONTDATA->m_vFname.usSize = sizeof(FACENAMEDESC);
+ M_FONTDATA->m_vFname.usWidthClass = FWIDTH_NORMAL;
+ M_FONTDATA->m_vFname.usReserved = 0;
+ M_FONTDATA->m_vFname.flOptions = 0;
+
+ OS2SelectMatchingFontByName();
+
+ long lNumLids = ::GpiQueryNumberSetIds(M_FONTDATA->m_hPS);
+ long lGpiError;
+
+ //
+ // First we should generate unique id
+ //
+ if(lNumLids )
+ {
+ long alTypes[255];
+ STR8 azNames[255];
+ long alIds[255];
+
+ if(!::GpiQuerySetIds( M_FONTDATA->m_hPS
+ ,lNumLids
+ ,alTypes
+ ,azNames
+ ,alIds
+ ))
+ {
+ if (bInternalPS)
+ ::WinReleasePS(M_FONTDATA->m_hPS);
+ return 0;
+ }
+
+ for(unsigned long LCNum = 0; LCNum < lNumLids; LCNum++)
+ if(alIds[LCNum] == flId)
+ ++flId;
+ if(flId > 254) // wow, no id available!
+ {
+ if (bInternalPS)
+ ::WinReleasePS(M_FONTDATA->m_hPS);
+ return 0;
+ }
+ }
+
+ //
+ // Release and delete the current font
+ //
+ ::GpiSetCharSet(M_FONTDATA->m_hPS, LCID_DEFAULT);/* release the font before deleting */
+ ::GpiDeleteSetId(M_FONTDATA->m_hPS, 1L); /* delete the logical font */
+
+ //
+ // Now build a facestring
+ //
+ char zFacename[128];
+ strcpy(zFacename, M_FONTDATA->m_vFattrs.szFacename);
+
+ if(::GpiQueryFaceString( M_FONTDATA->m_hPS
+ ,zFacename
+ ,&M_FONTDATA->m_vFname
+ ,FACESIZE
+ ,M_FONTDATA->m_vFattrs.szFacename
+ ) == GPI_ERROR)
+ {
+ vError = ::WinGetLastError(vHabmain);
+ }
+
+ strcpy(zFacename, M_FONTDATA->m_vFattrs.szFacename);
+
+ if(::GpiCreateLogFont( M_FONTDATA->m_hPS
+ ,NULL
+ ,flId
+ ,&M_FONTDATA->m_vFattrs
+ ) != GPI_ERROR)
+ M_FONTDATA->m_hFont = (WXHFONT)1;
+
+
+ if (bInternalPS)
+ {
+ if(M_FONTDATA->m_hFont)
+ ::GpiDeleteSetId( M_FONTDATA->m_hPS
+ ,flId
+ );
+
+ ::WinReleasePS(M_FONTDATA->m_hPS);
+ }
+ else
+ ::GpiSetCharSet(M_FONTDATA->m_hPS, flId); // sets font for presentation space
+ if (!M_FONTDATA->m_hFont)
+ {
+ wxLogLastError("CreateFont");
+ }
+ M_FONTDATA->m_nFontId = flId;
+ return(M_FONTDATA->m_hFont != 0);
+} // end of wxFont::RealizeResource
+
+bool wxFont::FreeResource(
+ bool bForce
+)
+{
+ if (GetResourceHandle())
+ {
+ M_FONTDATA->m_hFont = 0;
+ ::GpiDeleteSetId( M_FONTDATA->m_hPS
+ ,M_FONTDATA->m_nFontId
+ );
+ return TRUE;
+ }