| [2] | 1 | /* handles setting fonts */ | 
|---|
|  | 2 |  | 
|---|
|  | 3 | #define INCL_DOS | 
|---|
|  | 4 | #define INCL_WIN | 
|---|
|  | 5 | #define INCL_GPI | 
|---|
|  | 6 |  | 
|---|
|  | 7 | #include <os2.h> | 
|---|
|  | 8 | #include <stdlib.h> | 
|---|
|  | 9 | #include <stdio.h> | 
|---|
|  | 10 | #include <string.h> | 
|---|
|  | 11 | #include "fm3dll.h" | 
|---|
|  | 12 | #include "fm3str.h" | 
|---|
|  | 13 |  | 
|---|
|  | 14 | #pragma data_seg(DATA1) | 
|---|
|  | 15 |  | 
|---|
| [793] | 16 | static INT counter = 0; | 
|---|
| [2] | 17 |  | 
|---|
|  | 18 | /* | 
|---|
|  | 19 | *   Convert vector font size using point size and fAttrs structure and | 
|---|
|  | 20 | *   return it in that structure. | 
|---|
|  | 21 | */ | 
|---|
|  | 22 |  | 
|---|
| [551] | 23 | VOID ConvertVectorFontSize(FIXED fxPointSize, PFATTRS pfattrs) | 
|---|
|  | 24 | { | 
|---|
| [2] | 25 |  | 
|---|
| [551] | 26 | HPS hps; | 
|---|
|  | 27 | HDC hDC; | 
|---|
|  | 28 | LONG lxFontResolution; | 
|---|
|  | 29 | LONG lyFontResolution; | 
|---|
| [2] | 30 | SIZEF sizef; | 
|---|
|  | 31 |  | 
|---|
| [551] | 32 | hps = WinGetScreenPS(HWND_DESKTOP);   /* Screen presentation space */ | 
|---|
| [2] | 33 |  | 
|---|
|  | 34 | /* | 
|---|
|  | 35 | *   Query device context for the screen and then query | 
|---|
|  | 36 | *   the resolution of the device for the device context. | 
|---|
|  | 37 | */ | 
|---|
|  | 38 |  | 
|---|
|  | 39 | hDC = GpiQueryDevice(hps); | 
|---|
| [551] | 40 | DevQueryCaps(hDC, CAPS_HORIZONTAL_FONT_RES, (LONG) 1, &lxFontResolution); | 
|---|
|  | 41 | DevQueryCaps(hDC, CAPS_VERTICAL_FONT_RES, (LONG) 1, &lyFontResolution); | 
|---|
| [2] | 42 |  | 
|---|
|  | 43 | /* | 
|---|
|  | 44 | *   Calculate the size of the character box, based on the | 
|---|
|  | 45 | *   point size selected and the resolution of the device. | 
|---|
|  | 46 | *   The size parameters are of type FIXED, NOT int. | 
|---|
|  | 47 | *   NOTE: 1 point == 1/72 of an inch. | 
|---|
|  | 48 | */ | 
|---|
|  | 49 |  | 
|---|
| [551] | 50 | sizef.cx = (FIXED) (((fxPointSize) / 72) * lxFontResolution); | 
|---|
|  | 51 | sizef.cy = (FIXED) (((fxPointSize) / 72) * lyFontResolution); | 
|---|
| [2] | 52 |  | 
|---|
| [551] | 53 | pfattrs->lMaxBaselineExt = MAKELONG(HIUSHORT(sizef.cy), 0); | 
|---|
|  | 54 | pfattrs->lAveCharWidth = MAKELONG(HIUSHORT(sizef.cx), 0); | 
|---|
| [2] | 55 | WinReleasePS(hps); | 
|---|
|  | 56 |  | 
|---|
| [551] | 57 | }                                       /* end ConvertVectorPointSize() */ | 
|---|
| [2] | 58 |  | 
|---|
| [551] | 59 | VOID SetPresParamFromFattrs(HWND hwnd, FATTRS * fattrs, | 
|---|
|  | 60 | SHORT sNominalPointSize, FIXED fxPointSize) | 
|---|
|  | 61 | { | 
|---|
| [2] | 62 |  | 
|---|
|  | 63 | CHAR s[CCHMAXPATH * 2]; | 
|---|
|  | 64 |  | 
|---|
| [551] | 65 | if (fattrs->fsFontUse != FATTR_FONTUSE_OUTLINE) | 
|---|
|  | 66 | sprintf(s, "%hd.", sNominalPointSize / 10); | 
|---|
| [2] | 67 | else { | 
|---|
| [551] | 68 | sprintf(s, "%hd.", FIXEDINT(fxPointSize)); | 
|---|
|  | 69 | if ((((USHORT) FIXEDFRAC(fxPointSize) * 100) / 65536) > 0) | 
|---|
|  | 70 | sprintf(&s[strlen(s)], "%hd.", | 
|---|
|  | 71 | ((USHORT) FIXEDFRAC(fxPointSize) * 100) / 65536); | 
|---|
| [2] | 72 | } | 
|---|
| [551] | 73 | strcat(s, fattrs->szFacename); | 
|---|
|  | 74 | if (fattrs->fsSelection & FATTR_SEL_ITALIC) { | 
|---|
|  | 75 | strcat(s, "."); | 
|---|
|  | 76 | strcat(s, GetPString(IDS_ITALICTEXT)); | 
|---|
| [2] | 77 | } | 
|---|
| [551] | 78 | if (fattrs->fsSelection & FATTR_SEL_OUTLINE) { | 
|---|
|  | 79 | strcat(s, "."); | 
|---|
|  | 80 | strcat(s, GetPString(IDS_OUTLINETEXT)); | 
|---|
| [2] | 81 | } | 
|---|
| [551] | 82 | if (fattrs->fsSelection & FATTR_SEL_BOLD) { | 
|---|
|  | 83 | strcat(s, "."); | 
|---|
|  | 84 | strcat(s, GetPString(IDS_BOLDTEXT)); | 
|---|
| [2] | 85 | } | 
|---|
| [551] | 86 | if (fattrs->fsSelection & FATTR_SEL_UNDERSCORE) { | 
|---|
|  | 87 | strcat(s, "."); | 
|---|
|  | 88 | strcat(s, GetPString(IDS_UNDERSCORETEXT)); | 
|---|
| [2] | 89 | } | 
|---|
| [551] | 90 | if (fattrs->fsSelection & FATTR_SEL_STRIKEOUT) { | 
|---|
|  | 91 | strcat(s, "."); | 
|---|
|  | 92 | strcat(s, GetPString(IDS_STRIKEOUTTEXT)); | 
|---|
| [2] | 93 | } | 
|---|
| [551] | 94 | WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(s) + 1, s); | 
|---|
| [2] | 95 | } | 
|---|
|  | 96 |  | 
|---|
| [551] | 97 | VOID SetFont(HWND hwnd) | 
|---|
|  | 98 | { | 
|---|
| [2] | 99 |  | 
|---|
| [551] | 100 | FONTDLG fontdlg; | 
|---|
|  | 101 | HPS hps; | 
|---|
|  | 102 | FONTMETRICS fm; | 
|---|
|  | 103 | CHAR szFamily[CCHMAXPATH], | 
|---|
|  | 104 | *szTitle = GetPString(IDS_SETFONTTITLETEXT), *szPreview; | 
|---|
| [2] | 105 |  | 
|---|
|  | 106 | DosEnterCritSec(); | 
|---|
| [551] | 107 | szPreview = GetPString(IDS_BLURB1TEXT + counter++); | 
|---|
|  | 108 | if (strcmp(szPreview, "0")) { | 
|---|
|  | 109 | counter = 0; | 
|---|
|  | 110 | szPreview = GetPString(IDS_BLURB1TEXT + counter++); | 
|---|
|  | 111 | } | 
|---|
| [2] | 112 | DosExitCritSec(); | 
|---|
| [551] | 113 | memset(&fontdlg, 0, sizeof(fontdlg)); /* initialize all fields */ | 
|---|
| [2] | 114 | hps = WinGetPS(hwnd); | 
|---|
| [551] | 115 | GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm); | 
|---|
| [2] | 116 | WinReleasePS(hps); | 
|---|
|  | 117 | fontdlg.cbSize = sizeof(FONTDLG); | 
|---|
|  | 118 | fontdlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP); | 
|---|
|  | 119 | fontdlg.hpsPrinter = NULLHANDLE; | 
|---|
|  | 120 | fontdlg.pszTitle = szTitle; | 
|---|
|  | 121 | fontdlg.pszPreview = szPreview; | 
|---|
|  | 122 | fontdlg.pfnDlgProc = NULL; | 
|---|
| [551] | 123 | strcpy(szFamily, fm.szFamilyname); | 
|---|
| [2] | 124 | fontdlg.pszFamilyname = szFamily; | 
|---|
|  | 125 | fontdlg.usFamilyBufLen = sizeof(szFamily); | 
|---|
| [551] | 126 | fontdlg.fxPointSize = MAKEFIXED(fm.sNominalPointSize / 10, 0); | 
|---|
| [2] | 127 | fontdlg.fl = FNTS_CENTER | FNTS_INITFROMFATTRS; | 
|---|
|  | 128 | fontdlg.sNominalPointSize = fm.sNominalPointSize; | 
|---|
| [551] | 129 | fontdlg.flType = (LONG) fm.fsType; | 
|---|
| [2] | 130 | fontdlg.clrFore = CLR_NEUTRAL; | 
|---|
|  | 131 | fontdlg.clrBack = CLR_BACKGROUND; | 
|---|
|  | 132 | fontdlg.usWeight = fm.usWeightClass; | 
|---|
|  | 133 | fontdlg.usWidth = fm.usWidthClass; | 
|---|
| [551] | 134 | if (!WinFontDlg(HWND_DESKTOP, hwnd, &fontdlg) || fontdlg.lReturn != DID_OK) { | 
|---|
| [2] | 135 | WinReleasePS(fontdlg.hpsScreen); | 
|---|
|  | 136 | return; | 
|---|
|  | 137 | } | 
|---|
| [551] | 138 | if (fontdlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE) | 
|---|
|  | 139 | ConvertVectorFontSize(fontdlg.fxPointSize, &fontdlg.fAttrs); | 
|---|
| [2] | 140 | WinReleasePS(fontdlg.hpsScreen); | 
|---|
| [551] | 141 | SetPresParamFromFattrs(hwnd, &fontdlg.fAttrs, fontdlg.sNominalPointSize, | 
|---|
|  | 142 | fontdlg.fxPointSize); | 
|---|
| [2] | 143 | } | 
|---|
|  | 144 |  | 
|---|
| [551] | 145 | FATTRS *SetMLEFont(HWND hwndMLE, FATTRS * fattrs, ULONG flags) | 
|---|
|  | 146 | { | 
|---|
| [2] | 147 |  | 
|---|
| [551] | 148 | /* Flags: | 
|---|
|  | 149 | * | 
|---|
|  | 150 | * 1 = Don't assume MLE (no MLM_* messages, use fattrs only | 
|---|
|  | 151 | * 2 = Fixed width fonts only | 
|---|
|  | 152 | * 4 = No synthesized fonts | 
|---|
|  | 153 | * 8 = No vector fonts | 
|---|
|  | 154 | * 16 = No bitmapped fonts | 
|---|
|  | 155 | * | 
|---|
|  | 156 | */ | 
|---|
| [2] | 157 |  | 
|---|
| [551] | 158 | FONTDLG fontDlg; | 
|---|
|  | 159 | HPS hps; | 
|---|
|  | 160 | FONTMETRICS fontMetrics; | 
|---|
|  | 161 | CHAR szFamily[CCHMAXPATH], *szPreview; | 
|---|
|  | 162 | static FIXED fxPointSize = 0; /* keep track of this for vector fonts */ | 
|---|
| [2] | 163 |  | 
|---|
| [551] | 164 | if ((flags & 1) && !fattrs) | 
|---|
|  | 165 | return fattrs; | 
|---|
|  | 166 | DosEnterCritSec(); | 
|---|
|  | 167 | szPreview = GetPString(IDS_BLURB1TEXT + counter++); | 
|---|
|  | 168 | if (strcmp(szPreview, "0")) { | 
|---|
|  | 169 | counter = 0; | 
|---|
| [2] | 170 | szPreview = GetPString(IDS_BLURB1TEXT + counter++); | 
|---|
| [551] | 171 | } | 
|---|
|  | 172 | DosExitCritSec(); | 
|---|
|  | 173 | memset(&fontDlg, 0, sizeof(fontDlg)); /* initialize all fields */ | 
|---|
|  | 174 | /* | 
|---|
|  | 175 | * Get the current font attributes | 
|---|
|  | 176 | */ | 
|---|
|  | 177 | hps = WinGetPS(hwndMLE); | 
|---|
|  | 178 | if (!(flags & 1)) | 
|---|
|  | 179 | WinSendMsg(hwndMLE, MLM_QUERYFONT, | 
|---|
|  | 180 | MPFROMP((PFATTRS) & (fontDlg.fAttrs)), NULL); | 
|---|
|  | 181 | else | 
|---|
|  | 182 | memcpy(&fontDlg.fAttrs, fattrs, sizeof(FATTRS)); | 
|---|
| [2] | 183 |  | 
|---|
| [551] | 184 | /* create system default font */ | 
|---|
| [2] | 185 |  | 
|---|
| [551] | 186 | GpiCreateLogFont(hps, (PSTR8) fontDlg.fAttrs.szFacename, 1, | 
|---|
|  | 187 | &(fontDlg.fAttrs)); | 
|---|
|  | 188 | GpiSetCharSet(hps, 1); | 
|---|
|  | 189 | GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fontMetrics); | 
|---|
|  | 190 | GpiSetCharSet(hps, LCID_DEFAULT); | 
|---|
|  | 191 | GpiDeleteSetId(hps, 1); | 
|---|
|  | 192 | WinReleasePS(hps); | 
|---|
| [2] | 193 |  | 
|---|
| [551] | 194 | /* | 
|---|
|  | 195 | * Initialize the FONTDLG structure with the current font | 
|---|
|  | 196 | */ | 
|---|
|  | 197 | fontDlg.cbSize = sizeof(FONTDLG);     /* sizeof(FONTDLG) */ | 
|---|
|  | 198 | fontDlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP);     /* Screen presentation space */ | 
|---|
|  | 199 | fontDlg.hpsPrinter = NULLHANDLE;      /* Printer presentation space */ | 
|---|
| [2] | 200 |  | 
|---|
| [551] | 201 | fontDlg.pszTitle = GetPString(IDS_SETVIEWERFONTTITLETEXT); | 
|---|
|  | 202 | fontDlg.pszPreview = szPreview; | 
|---|
|  | 203 | fontDlg.pszPtSizeList = NULL;         /* Application provided size list  */ | 
|---|
|  | 204 | fontDlg.pfnDlgProc = NULL;            /* Dialog subclass procedure       */ | 
|---|
|  | 205 | strcpy(szFamily, fontMetrics.szFamilyname);   /* Family name of font        */ | 
|---|
|  | 206 | fontDlg.pszFamilyname = szFamily;     /* point to Family name of font    */ | 
|---|
|  | 207 | fontDlg.fxPointSize = fxPointSize;    /* Point size the user selected    */ | 
|---|
|  | 208 | fontDlg.fl = FNTS_CENTER |            /* FNTS_* flags - dialog styles    */ | 
|---|
|  | 209 | FNTS_INITFROMFATTRS; | 
|---|
|  | 210 | if (flags & 2) | 
|---|
|  | 211 | fontDlg.fl |= FNTS_FIXEDWIDTHONLY; | 
|---|
|  | 212 | if (flags & 4) | 
|---|
|  | 213 | fontDlg.fl |= FNTS_NOSYNTHESIZEDFONTS; | 
|---|
|  | 214 | if (flags & 8) | 
|---|
|  | 215 | fontDlg.fl |= FNTS_BITMAPONLY; | 
|---|
|  | 216 | else if (flags & 16) | 
|---|
|  | 217 | fontDlg.fl |= FNTS_VECTORONLY; | 
|---|
|  | 218 | fontDlg.flFlags = 0;                  /* FNTF_* state flags              */ | 
|---|
|  | 219 | /* Font type option bits           */ | 
|---|
|  | 220 | fontDlg.flType = (LONG) fontMetrics.fsType; | 
|---|
|  | 221 | fontDlg.flTypeMask = 0;               /* Mask of which font types to use */ | 
|---|
|  | 222 | fontDlg.flStyle = 0;                  /* The selected style bits         */ | 
|---|
|  | 223 | fontDlg.flStyleMask = 0;              /* Mask of which style bits to use */ | 
|---|
|  | 224 | fontDlg.clrFore = CLR_NEUTRAL;        /* Selected foreground color       */ | 
|---|
|  | 225 | fontDlg.clrBack = CLR_BACKGROUND;     /* Selected background color       */ | 
|---|
|  | 226 | fontDlg.ulUser = 0;                   /* Blank field for application     */ | 
|---|
|  | 227 | fontDlg.lReturn = 0;                  /* Return Value of the Dialog      */ | 
|---|
|  | 228 | fontDlg.lEmHeight = 0;                /* Em height of the current font   */ | 
|---|
|  | 229 | fontDlg.lXHeight = 0;                 /* X height of the current font    */ | 
|---|
|  | 230 | fontDlg.lExternalLeading = 0;         /* External Leading of font        */ | 
|---|
|  | 231 | /* Nominal Point Size of font      */ | 
|---|
|  | 232 | fontDlg.sNominalPointSize = fontMetrics.sNominalPointSize; | 
|---|
|  | 233 | fontDlg.usWeight = fontMetrics.usWeightClass; /* The boldness of the font */ | 
|---|
|  | 234 | fontDlg.usWidth = fontMetrics.usWidthClass;   /* The width of the font     */ | 
|---|
|  | 235 | fontDlg.x = 0;                        /* X coordinate of the dialog      */ | 
|---|
|  | 236 | fontDlg.y = 0;                        /* Y coordinate of the dialog      */ | 
|---|
| [2] | 237 | //   fontDlg.usDlgId      = IDD_FONT;       /* ID of a custom dialog template  */ | 
|---|
| [551] | 238 | fontDlg.usFamilyBufLen = sizeof(szFamily);    /*Length of family name buffer */ | 
|---|
| [2] | 239 |  | 
|---|
| [551] | 240 | /* | 
|---|
|  | 241 | *   Bring up the standard Font Dialog | 
|---|
|  | 242 | */ | 
|---|
| [2] | 243 |  | 
|---|
| [551] | 244 | if (!WinFontDlg(HWND_DESKTOP, hwndMLE, &fontDlg) | 
|---|
|  | 245 | || fontDlg.lReturn != DID_OK) { | 
|---|
|  | 246 | WinReleasePS(fontDlg.hpsScreen); | 
|---|
|  | 247 | return NULL; | 
|---|
|  | 248 | } | 
|---|
|  | 249 | fxPointSize = fontDlg.fxPointSize;    /* save point size for next dialog */ | 
|---|
| [2] | 250 |  | 
|---|
| [551] | 251 | /* | 
|---|
|  | 252 | *   If outline font, calculate the maxbaselineext and | 
|---|
|  | 253 | *   avecharwidth for the point size selected | 
|---|
|  | 254 | */ | 
|---|
| [2] | 255 |  | 
|---|
| [551] | 256 | if (fontDlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE) | 
|---|
|  | 257 | ConvertVectorFontSize(fontDlg.fxPointSize, &fontDlg.fAttrs); | 
|---|
| [2] | 258 |  | 
|---|
| [551] | 259 | WinReleasePS(fontDlg.hpsScreen); | 
|---|
|  | 260 | if (!(flags & 1)) | 
|---|
|  | 261 | WinSendMsg(hwndMLE, MLM_SETFONT, MPFROMP(&(fontDlg.fAttrs)), MPVOID); | 
|---|
|  | 262 | if (fattrs) | 
|---|
|  | 263 | memcpy(fattrs, &fontDlg.fAttrs, sizeof(FATTRS)); | 
|---|
|  | 264 | return fattrs; | 
|---|
| [2] | 265 |  | 
|---|
| [551] | 266 | }                                       /* End of SetMLEFont() */ | 
|---|
| [793] | 267 |  | 
|---|
|  | 268 | #pragma alloc_text(FONTS,ConvertVectorFontSize,SetFont,SetMLEFont) | 
|---|
|  | 269 | #pragma alloc_text(FONTS,SetPresParamFromFattrs) | 
|---|