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