home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
MLEVIEW.ZIP
/
EZFONTS.C
next >
Wrap
Text File
|
1991-04-04
|
4KB
|
133 lines
/*--------------------------------------------
EZFONT.C -- Routines for Using Image Fonts
--------------------------------------------*/
/* Note: */
/* The EZFONT routines are a direct port of the EASYFONT routines */
/* from Charles Petzold's book "Programming the OS/2 Presentation */
/* Manager". They have been enhanced and updated for OS/2 1.2 and */
/* later to make them more generally useful. Thanks Charles. */
/* W. David Ashley */
#define INCL_GPI
#include <os2.h>
#include <stdlib.h>
#include <string.h>
#include "ezfonts.h"
static LONG alMatch[EZF_NUMFONTFACES][EZF_NUMSIZES] =
{0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L};
static SHORT sFontSize[EZF_NUMSIZES] = { 80, 100, 120, 140, 180, 240 };
static CHAR szFacename[EZF_NUMFONTFACES][FACESIZE] =
{"Courier", "Helv", "System Monospaced",
"System Proportional", "Tms Rmn" };
PCHAR EzfQueryFacename (SHORT sFaceIndex) {
if (sFaceIndex >= EZF_NUMFONTFACES || sFaceIndex < 0)
return NULL;
return szFacename[sFaceIndex];
}
LONG EzfQueryMatchNum (SHORT sFaceIndex, SHORT sSizeIndex) {
if (sSizeIndex >= EZF_NUMSIZES || sSizeIndex < 0 ||
sFaceIndex >= EZF_NUMFONTFACES || sFaceIndex < 0)
return 0;
return (alMatch[sFaceIndex][sSizeIndex]);
}
SHORT EzfQuerySize (SHORT sSizeIndex) {
if (sSizeIndex >= EZF_NUMSIZES || sSizeIndex < 0)
return 0;
return (sFontSize[sSizeIndex]);
}
SHORT EzfQuerySizeIndex (SHORT sSize) {
SHORT sCntr;
for (sCntr = 0; sCntr < EZF_NUMSIZES; sCntr++)
if (sSize == sFontSize[sCntr])
return sCntr;
return (0);
}
BOOL EzfQueryFonts (HPS hps) {
PFONTMETRICS pfm;
HDC hdc;
LONG lHorzRes, lVertRes, lRequestFonts, lNumberFonts;
SHORT sIndex, sFace, sSize;
SEL selTemp;
hdc = GpiQueryDevice (hps);
DevQueryCaps (hdc, CAPS_HORIZONTAL_FONT_RES, 1L, &lHorzRes);
DevQueryCaps (hdc, CAPS_VERTICAL_FONT_RES, 1L, &lVertRes);
for (sFace = 0; sFace < EZF_NUMFONTFACES; sFace++) {
lRequestFonts = 0;
lNumberFonts = GpiQueryFonts (hps, QF_PUBLIC, szFacename[sFace],
&lRequestFonts, 0L, NULL);
if (lNumberFonts == 0)
continue;
if (lNumberFonts * sizeof (FONTMETRICS) >= 65535L)
return FALSE;
DosAllocSeg ((SHORT) (lNumberFonts * sizeof (FONTMETRICS)),
&selTemp, SEG_NONSHARED);
pfm = MAKEP (selTemp, 0);
if (pfm == NULL)
return FALSE;
GpiQueryFonts (hps, QF_PUBLIC, szFacename[sFace],
&lNumberFonts, (LONG) sizeof (FONTMETRICS), pfm);
for (sIndex = 0; sIndex < (SHORT) lNumberFonts; sIndex++)
if (pfm[sIndex].sXDeviceRes == (SHORT) lHorzRes &&
pfm[sIndex].sYDeviceRes == (SHORT) lVertRes &&
(pfm[sIndex].fsDefn & 1) == 0) {
for (sSize = 0; sSize < EZF_NUMSIZES; sSize++)
if (pfm[sIndex].sNominalPointSize == sFontSize[sSize])
break;
if (sSize != EZF_NUMSIZES)
alMatch[sFace][sSize] = pfm[sIndex].lMatch;
}
DosFreeSeg (selTemp);
}
return TRUE;
}
LONG EzfCreateLogFont (HPS hps, LONG lcid, USHORT idFace, USHORT idSize,
USHORT fsSelection) {
static FATTRS fat;
if (idFace >= EZF_NUMFONTFACES || idSize >= EZF_NUMSIZES ||
alMatch[idFace][idSize] == 0)
return 0;
fat.usRecordLength = sizeof fat;
fat.fsSelection = fsSelection;
fat.lMatch = alMatch[idFace][idSize];
strcpy (fat.szFacename, szFacename[idFace]);
return GpiCreateLogFont (hps, NULL, lcid, &fat);
}