/*-------------------------------------------------- * Sets a new font to be used by the window *--------------------------------------------------*/ PMWindow& PMWindow::set_font( const char* font ) { static int have_warpsans = -1; const char* used_font = font; if( strcmp( font, "9.WarpSans" ) == 0 ) { if( have_warpsans == -1 ) { LONG rc; LONG fonts = 0; HPS hps; hps = WinGetPS( HWND_DESKTOP ); rc = GpiQueryFonts( hps, QF_PUBLIC, "WarpSans", &fonts, 0, NULL ); WinReleasePS( hps ); have_warpsans = ( rc > 0 && rc != GPI_ALTERROR ); } if( !have_warpsans ) { used_font = "8.Helv"; } } if( !WinSetPresParam( win_handle, PP_FONTNAMESIZE, strlen(used_font)+1, (PVOID)used_font )) PM_THROW_GUIERROR(); return *this; }
void setTNGfont(HPS hps) { LONG cFonts; LONG lTemp = 0L; CHAR fontName[25]; FATTRS fattrs; SIZEF sizfCharBox; fattrs.usRecordLength = sizeof(FATTRS); fattrs.fsSelection = 0; fattrs.lMatch = 0L; fattrs.idRegistry = 0; fattrs.usCodePage = 850; fattrs.lMaxBaselineExt = 0L; fattrs.lAveCharWidth = 0L; fattrs.fsType = 0; fattrs.fsFontUse = FATTR_FONTUSE_OUTLINE; strcpy(fattrs.szFacename,TNG_FONT); cFonts = GpiQueryFonts(hps, QF_PUBLIC,fattrs.szFacename, &lTemp, (LONG) sizeof(FONTMETRICS), (PFONTMETRICS)NULL); if (cFonts==0) { strcpy(fattrs.szFacename,"Helvetica"); } GpiCreateLogFont(hps, (PSTR8)NULL, fontId, &fattrs); GpiSetCharSet(hps,fontId); sizfCharBox.cx=MAKEFIXED(14,0); sizfCharBox.cy=MAKEFIXED(20,0); GpiSetCharBox(hps,&sizfCharBox); GpiSetTextAlignment(hps,TA_CENTER,TA_TOP); }
LONG SelectScalableFont(HPS hPS, CHAR *pszFacename) { LONG cFonts; /* Fonts Count */ LONG lFontsTotal = 0L; /* Fonts Total Count */ LONG lMatch = 1L; /* Font Match Value */ PFONTMETRICS pfm; /* Font Metrics Pointer */ register INT i; /* Loop Counter */ /* Get the number of fonts for the face name */ /* provided */ DosAllocMem((PPVOID)(PVOID)&pfm, (ULONG)(sizeof(FONTMETRICS) * (cFonts = GpiQueryFonts(hPS, QF_PUBLIC, pszFacename, &lFontsTotal, sizeof(FONTMETRICS), (PFONTMETRICS)NULL))), PAG_READ | PAG_WRITE | PAG_COMMIT); /* Make a pointer for the memory allocated for */ /* the font metrics and get the font metrics for */ /* the number of fonts for the face name */ /* provided */ GpiQueryFonts(hPS, QF_PUBLIC, pszFacename, &cFonts, sizeof(FONTMETRICS), pfm); /* Loop through the font metrics returned to */ /* locate the desired font by matching the x and */ /* y device resolution of the font and the point */ /* size */ for ( i = 0; i < (INT)cFonts; i++ ) if ( (pfm[i].sXDeviceRes == 1000) && (pfm[i].sYDeviceRes == 1000) ) { /* Font found, get the match value to allow the */ /* exact font to be selected by the calling */ /* application */ lMatch = pfm[i].lMatch; break; } /* Release the memory allocated for the font */ /* metrics array */ DosFreeMem(pfm); /* Return the match value to the calling */ /* application */ return(lMatch); }
/**************************************************************** DefaultOutlineFont: Set an outline font which is sizeable. ****************************************************************/ void SetOutlineFont(HPS hps, short height) {FONTMETRICS fm[80]; static FATTRS fat; static LONG cFonts=0; LONG ltemp=0; SIZEF size; int i; if (height<=2) return; if (cFonts==0) { GpiLoadFonts(WinQueryAnchorBlock(HWND_DESKTOP),"helv"); cFonts= GpiQueryFonts(hps,QF_PUBLIC|QF_PRIVATE,"Helv",<emp, sizeof(FONTMETRICS),(PFONTMETRICS)0); if (cFonts>sizeof(fm)/sizeof(FONTMETRICS)) cFonts=sizeof(fm)/sizeof(FONTMETRICS); GpiQueryFonts(hps,QF_PUBLIC|QF_PRIVATE,"Helv",&cFonts, sizeof(FONTMETRICS),fm); for (i=0; (!(fm[i].fsDefn&FM_DEFN_OUTLINE)) && //find outline and (!(fm[i].fsType&FM_TYPE_KERNING)) && //kerned if can (i<cFonts); i++); if (i==cFonts) for (i=0; (!(fm[i].fsDefn&FM_DEFN_OUTLINE))&& // Find outline atleast (i<cFonts); i++); if (i==cFonts) i=0; fat.usRecordLength =sizeof(FATTRS); fat.lMatch =fm[i].lMatch; fat.lMatch =0; fat.fsFontUse = FATTR_FONTUSE_OUTLINE; strcpy(fat.szFacename,fm[i].szFacename); } GpiCreateLogFont(hps,(PSTR8)0,1,&fat); GpiSetBackMix(hps,(LONG)BM_LEAVEALONE); GpiSetCharSet(hps,1); size.cx = MAKEFIXED(height,0); size.cy = MAKEFIXED(height,0); GpiSetCharBox(hps,&size); GpiSetTextAlignment(hps,TA_NORMAL_HORIZ,TA_BOTTOM); }
/* Returns TRUE if WarpSans is supported by operating system. */ BOOL check_warpsans( void ) { static int have_warpsans = -1; if( have_warpsans == -1 ) { LONG fontcounter = 0; HPS hps; BOOL rc; hps = WinGetPS( HWND_DESKTOP ); rc = GpiQueryFonts( hps, QF_PUBLIC, "WarpSans", &fontcounter, 0, NULL ); WinReleasePS( hps ); have_warpsans = ( rc != 0 && rc != GPI_ALTERROR ); } return have_warpsans; }
/**************************************************************************** * InitFonts * * - Retrieves font metrics then creates logical fonts. * * - Recieves HPS for GpiQueryFonts call. * ****************************************************************************/ VOID InitFonts(HPS hps) { CHAR *cp; INT i; LONG cFonts; FATTRS fat; FONTMETRICS afm[2]; /* Get font metrics for both fonts. */ cFonts = 2; GpiQueryFonts(hps, QF_PRIVATE, NULL, &cFonts, (LONG) sizeof(FONTMETRICS), (PFONTMETRICS) afm); /* Create both logical fonts. */ for (i=0,cp=(CHAR *)&fat;i<sizeof(FATTRS);i++,cp++) *cp=0; fat.usRecordLength = sizeof(FATTRS); fat.fsFontUse = FATTR_FONTUSE_NOMIX; for (i=0;i<2;i++) { /* Set up FATTRS structure */ fat.fsSelection = afm[i].fsSelection; fat.lMatch = afm[i].lMatch; fat.idRegistry = afm[i].idRegistry; fat.usCodePage = afm[i].usCodePage; fat.fsType = afm[i].fsType; fat.lAveCharWidth = afm[i].lAveCharWidth; fat.lMaxBaselineExt = afm[i].lMaxBaselineExt; strcpy(fat.szFacename,afm[i].szFacename); if (fat.lMaxBaselineExt < afm[(i+1)%2].lMaxBaselineExt) { iSizeSmall = (INT) fat.lMaxBaselineExt; GpiCreateLogFont(hps, NULL, LCID_SMALL, &fat); } else { iSizeLarge = (INT) fat.lMaxBaselineExt; GpiCreateLogFont(hps, NULL, LCID_LARGE, &fat); } } }
void _CreateFont( LPWDATA w ) { //=============================== LONG cFonts = { 0 }; LONG num_fonts; FONTMETRICS * fonts; int i; unsigned font_size; unsigned font_selected; HPS ps; #ifdef _MBCS int fontChosenFlag = 0; #endif /*** Prepare to search for a suitable console font ***/ ps = WinGetPS( w->hwnd ); num_fonts = GpiQueryFonts( ps, QF_PUBLIC, NULL, &cFonts, sizeof( FONTMETRICS ), NULL ); fonts = _MemAlloc( num_fonts * sizeof( FONTMETRICS ) ); GpiQueryFonts( ps, QF_PUBLIC, NULL, &num_fonts, sizeof( FONTMETRICS ), fonts ); font_size = UINT_MAX; font_selected = 0; #ifdef _MBCS if( __IsDBCS ) { /*** Try to find a DBCS font ***/ for( i = 0; i < num_fonts; ++i ) { if( ! (fonts[i].fsType & (FM_TYPE_DBCS|FM_TYPE_FIXED)) ) continue; if( fonts[i].lEmHeight > 10 ) continue; font_size = fonts[i].lEmHeight; font_selected = i; fontChosenFlag = 1; break; } /*** Try to find a regular font if can't find DBCS ***/ if( fontChosenFlag == 0 ) { for( i = 0; i < num_fonts; ++i ) { if( ! (fonts[i].fsType & FM_TYPE_DBCS) ) continue; if( fonts[i].lEmHeight > 10 ) continue; font_size = fonts[i].lEmHeight; font_selected = i; fontChosenFlag = 1; break; } } } /*** If !__IsDBCS or if DBCS font not found, find a fixed font ***/ if( fontChosenFlag == 0 ) { for( i = 0; i < num_fonts; ++i ) { if( ! (fonts[i].fsType & FM_TYPE_FIXED) ) continue; if( fonts[i].lEmHeight > 10 ) continue; font_size = fonts[i].lEmHeight; font_selected = i; break; } } #else /*** Try to find a suitable font ***/ for( i = 0; i < num_fonts; ++i ) { if( ! (fonts[i].fsType & FM_TYPE_FIXED) ) continue; if( fonts[i].lEmHeight > 10 ) continue; font_size = fonts[i].lEmHeight; font_selected = i; break; } #endif /*** Set up the chosen font ***/ FontAttrs.usRecordLength = sizeof( FATTRS ); FontAttrs.fsSelection = 0; FontAttrs.lMatch = fonts[font_selected].lMatch; strcpy( FontAttrs.szFacename, fonts[font_selected].szFacename ); FontAttrs.idRegistry = fonts[font_selected].idRegistry; FontAttrs.usCodePage = 0; FontAttrs.lMaxBaselineExt = 0; FontAttrs.lAveCharWidth = 0; FontAttrs.fsType = 0; FontAttrs.fsFontUse = 0; w->xchar = fonts[font_selected].lAveCharWidth; w->ychar = fonts[font_selected].lMaxBaselineExt + SPACE_BETWEEN_LINES; w->base_offset = fonts[font_selected].lMaxDescender; _MemFree( fonts ); WinReleasePS( ps ); }
LONG SelectFont(HDC hDC, HPS hPS, CHAR *pszFacename, LONG lPoints) { LONG cFonts; /* Fonts Count */ LONG lFontsTotal = 0L; /* Fonts Total Count */ LONG lMatch = 1L; /* Font Match Value */ LONG lXDeviceRes; /* x Device Resolution */ LONG lYDeviceRes; /* y Device Resolution */ PFONTMETRICS pfm; /* Font Metrics Pointer */ register INT i; /* Loop Counter */ /* Get the height of the screen in pels */ DevQueryCaps(hDC, CAPS_HORIZONTAL_FONT_RES, 1L, &lXDeviceRes); DevQueryCaps(hDC, CAPS_VERTICAL_FONT_RES, 1L, &lYDeviceRes); /* Get the number of fonts for the face name */ /* provided */ cFonts = GpiQueryFonts(hPS, QF_PUBLIC, pszFacename, &lFontsTotal, sizeof(FONTMETRICS), (PFONTMETRICS)NULL); /* Allocate space for the font metrics for the */ /* different font sizes and devices of the font */ DosAllocMem((PPVOID)(PVOID)&pfm, (ULONG)(sizeof(FONTMETRICS) * cFonts), PAG_READ | PAG_WRITE | PAG_COMMIT); /* Make a pointer for the memory allocated for */ /* the font metrics and get the font metrics for */ /* the number of fonts for the face name */ /* provided */ GpiQueryFonts(hPS, QF_PUBLIC, pszFacename, &cFonts, sizeof(FONTMETRICS), pfm); /* Adjust the point size to correspond to the */ /* the nominal point size that is contained */ /* within the font metrics structure */ lPoints *= 10; /* Loop through the font metrics returned to */ /* locate the desired font by matching the x and */ /* y device resolution of the font and the point */ /* size */ for ( i = 0; i < (INT)cFonts; i++ ) if ( (pfm[i].sXDeviceRes == (SHORT)lXDeviceRes) && (pfm[i].sYDeviceRes == (SHORT)lYDeviceRes) && ((LONG)pfm[i].sNominalPointSize == lPoints) ) { /* Font found, get the match value to allow the */ /* exact font to be selected by the calling */ /* application */ lMatch = pfm[i].lMatch; break; } /* Release the memory allocated for the font */ /* metrics array */ DosFreeMem(pfm); /* Return the match value to the calling */ /* application */ return(lMatch); }
/*@ XFont :: XFont(XGraphicDevice * dev, const char *fontName, const SHORT size, const LONG options) @group constructors/destructors @remarks Construct a font @parameters <t 'ø' c=2> øXGraphicDevice * device øowner øchar * fontName øname of the font øSHORT size øsize øLONG options øoptions </t> */ XFont :: XFont(XGraphicDevice * dev, const char *fontName, const SHORT size, const LONG options) { // dev->fontId+=1; fontId = dev->fonts + 1; fontSize = size; LONG cFont; /* Fonts Count */ LONG lFontsTotal = 0L; /* Fonts Total Count */ LONG lXDeviceRes; /* x Device Resolution */ LONG lYDeviceRes; /* y Device Resolution */ PFONTMETRICS pfmSelect; /* Font Metrics Pointer */ FATTRS fat; /* Font Attributes */ register INT i; /* Loop Counter */ LONG lNominalPointSize = size * 10; DevQueryCaps(dev->hdc, CAPS_HORIZONTAL_FONT_RES, 1L, &lXDeviceRes); DevQueryCaps(dev->hdc, CAPS_VERTICAL_FONT_RES, 1L, &lYDeviceRes); realSize = size; if ((cFont = GpiQueryFonts(dev->hps, QF_PUBLIC, (PSZ) fontName, &lFontsTotal, sizeof(FONTMETRICS), (PFONTMETRICS) NULL)) != 0L) { DosAllocMem((PPVOID) (PVOID) & pfmSelect, (ULONG) (sizeof(FONTMETRICS) * cFont), PAG_READ | PAG_WRITE | PAG_COMMIT); GpiQueryFonts(dev->hps, QF_PUBLIC, (PSZ) fontName, &cFont, sizeof(FONTMETRICS), pfmSelect); for (i = 0; i < (INT) cFont; i++) if ((pfmSelect[i].sXDeviceRes == (SHORT) lXDeviceRes) && (pfmSelect[i].sYDeviceRes == (SHORT) lYDeviceRes) && ((LONG) pfmSelect[i].sNominalPointSize == lNominalPointSize)) { memset(&fat, 0, sizeof(FATTRS)); fat.usRecordLength = sizeof(FATTRS); strcpy(fat.szFacename, fontName); fat.lMatch = pfmSelect[i].lMatch; fat.fsSelection = (USHORT) options; DosFreeMem((PVOID) pfmSelect); fixed = TRUE; GpiCreateLogFont(dev->hps, (PSTR8) NULL, fontId, &fat); dev->RegisterFont(this); dev->SetFont(this); return; } for (i = 0; i < (INT) cFont; i++) if ((pfmSelect[i].sXDeviceRes == 1000) && (pfmSelect[i].sYDeviceRes == 1000)) { memset(&fat, 0, sizeof(FATTRS)); fat.usRecordLength = sizeof(FATTRS); strcpy(fat.szFacename, fontName); fat.lMatch = pfmSelect[i].lMatch; fat.usCodePage = 850; fat.fsFontUse = FATTR_FONTUSE_OUTLINE | FATTR_FONTUSE_TRANSFORMABLE; fat.fsSelection = (USHORT) options; DosFreeMem((PVOID) pfmSelect); GpiCreateLogFont(dev->hps, (PSTR8) NULL, fontId, &fat); fontSize = lNominalPointSize; fixed = FALSE; dev->RegisterFont(this); dev->SetFont(this); return; } DosFreeMem((PVOID) pfmSelect); } }
BOOL CreatePS(HWND hwnd) { HPS hps; int iIndex; LONG lWidth; LONG lBiggest; LONG lFontCount; PFONTMETRICS pfmFonts; int iBigFont; hdcPs = WinOpenWindowDC(hwnd); hps = WinGetPS(hwnd); lFontCount = 0; lFontCount = GpiQueryFonts(hps, QF_PUBLIC, "Helv", &lFontCount, sizeof(FONTMETRICS), NULL); if (lFontCount > 0) { DosAllocMem((PVOID)&pfmFonts,(lFontCount * sizeof(FONTMETRICS)),(PAG_COMMIT | PAG_READ| PAG_WRITE)); lBiggest = GpiQueryFonts(hps, QF_PUBLIC, "Helv", &lFontCount, sizeof(FONTMETRICS), pfmFonts); lBiggest = 0; for (iIndex = 0;iIndex < lFontCount;iIndex++) { lWidth = pfmFonts[iIndex].lAveCharWidth; if (lWidth > lBiggest) { lBiggest = lWidth; iBigFont = iIndex; } } fattBigFont.usRecordLength = sizeof(FATTRS); fattBigFont.fsSelection = 0; fattBigFont.lMatch = pfmFonts[iBigFont].lMatch; strcpy(fattBigFont.szFacename,pfmFonts[iBigFont].szFacename); fattBigFont.idRegistry = pfmFonts[iBigFont].idRegistry; fattBigFont.usCodePage = pfmFonts[iBigFont].usCodePage; fattBigFont.lMaxBaselineExt = pfmFonts[iBigFont].lMaxBaselineExt; fattBigFont.lAveCharWidth = pfmFonts[iBigFont].lAveCharWidth; fattBigFont.fsType = 0; fattBigFont.fsFontUse = FATTR_FONTUSE_NOMIX; stBigCell.cx = pfmFonts[iBigFont].lAveCharWidth; stBigCell.cy = pfmFonts[iBigFont].lXHeight; DosFreeMem(pfmFonts); } lFontCount = 0; lFontCount = GpiQueryFonts(hps, QF_PUBLIC, "System VIO", &lFontCount, sizeof(FONTMETRICS), NULL); if (lFontCount > 0) { DosAllocMem((PVOID)&pfmFonts,(lFontCount * sizeof(FONTMETRICS)),(PAG_COMMIT | PAG_READ| PAG_WRITE)); lBiggest = GpiQueryFonts(hps, QF_PUBLIC, "System VIO", &lFontCount, sizeof(FONTMETRICS), pfmFonts); for (iIndex = 0;iIndex < lFontCount;iIndex++) if (pfmFonts[iIndex].lAveCharWidth == 8) break; if (iIndex >= lFontCount) iIndex = 0; fattMsgFont.usRecordLength = sizeof(FATTRS); fattMsgFont.fsSelection = 0; fattMsgFont.lMatch = pfmFonts[iIndex].lMatch; strcpy(fattMsgFont.szFacename,pfmFonts[iIndex].szFacename); fattMsgFont.idRegistry = pfmFonts[iIndex].idRegistry; fattMsgFont.usCodePage = pfmFonts[iIndex].usCodePage; fattMsgFont.lMaxBaselineExt = pfmFonts[iIndex].lMaxBaselineExt; fattMsgFont.lAveCharWidth = pfmFonts[iIndex].lAveCharWidth; fattMsgFont.fsType = 0; fattMsgFont.fsFontUse = FATTR_FONTUSE_NOMIX; stMsgCell.cx = pfmFonts[iIndex].lAveCharWidth; stMsgCell.cy = pfmFonts[iIndex].lXHeight; DosFreeMem(pfmFonts); } else { // this stuff is here because OS/2 version 2.0 does not have System VIO fonts lFontCount = 0; lFontCount = GpiQueryFonts(hps, QF_PUBLIC, "System Monospaced", &lFontCount, sizeof(FONTMETRICS), NULL); if (lFontCount > 0) { DosAllocMem((PVOID)&pfmFonts,(lFontCount * sizeof(FONTMETRICS)),(PAG_COMMIT | PAG_READ| PAG_WRITE)); lBiggest = GpiQueryFonts(hps, QF_PUBLIC, "System Monospaced", &lFontCount, sizeof(FONTMETRICS), pfmFonts); for (iIndex = 0;iIndex < lFontCount;iIndex++) if (pfmFonts[iIndex].lAveCharWidth == 10) break; if (iIndex >= lFontCount) iIndex = 0; fattMsgFont.usRecordLength = sizeof(FATTRS); fattMsgFont.fsSelection = 0; fattMsgFont.lMatch = pfmFonts[iIndex].lMatch; strcpy(fattMsgFont.szFacename,pfmFonts[iIndex].szFacename); fattMsgFont.idRegistry = pfmFonts[iIndex].idRegistry; fattMsgFont.usCodePage = pfmFonts[iIndex].usCodePage; fattMsgFont.lMaxBaselineExt = pfmFonts[iIndex].lMaxBaselineExt; fattMsgFont.lAveCharWidth = pfmFonts[iIndex].lAveCharWidth; fattMsgFont.fsType = 0; fattMsgFont.fsFontUse = FATTR_FONTUSE_NOMIX; stMsgCell.cx = pfmFonts[iIndex].lAveCharWidth; stMsgCell.cy = pfmFonts[iIndex].lXHeight; DosFreeMem(pfmFonts); } } WinReleasePS(hps); return(TRUE); }