[2] | 1 |
|
---|
[907] | 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: fonts.c 1394 2009-02-05 04:17:25Z stevenhl $
|
---|
| 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 |
|
---|
| 36 | /*
|
---|
| 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 |
|
---|
[1160] | 50 | hps = WinGetScreenPS(HWND_DESKTOP); /* Screen presentation space */
|
---|
[2] | 51 |
|
---|
| 52 | /*
|
---|
| 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 |
|
---|
| 61 | /*
|
---|
| 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 |
|
---|
[1160] | 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;
|
---|
| 122 | CHAR szFamily[CCHMAXPATH],
|
---|
| 123 | *szTitle = GetPString(IDS_SETFONTTITLETEXT), *szPreview;
|
---|
[2] | 124 |
|
---|
[1304] | 125 | //DosEnterCritSec(); //GKY 11-30-08
|
---|
| 126 | DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
|
---|
[1394] | 127 | szPreview = GetPString(IDS_BLURB1TEXT + counter++);
|
---|
| 128 | if (strcmp(szPreview, "0") == 0) {
|
---|
| 129 | counter = 0;
|
---|
| 130 | szPreview = GetPString(IDS_BLURB1TEXT + counter++);
|
---|
| 131 | }
|
---|
[1304] | 132 | DosReleaseMutexSem(hmtxFM2Globals);
|
---|
| 133 | //DosExitCritSec();
|
---|
[1160] | 134 | memset(&fontdlg, 0, sizeof(fontdlg)); /* initialize all fields */
|
---|
[2] | 135 | hps = WinGetPS(hwnd);
|
---|
[551] | 136 | GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm);
|
---|
[2] | 137 | WinReleasePS(hps);
|
---|
| 138 | fontdlg.cbSize = sizeof(FONTDLG);
|
---|
| 139 | fontdlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP);
|
---|
| 140 | fontdlg.hpsPrinter = NULLHANDLE;
|
---|
| 141 | fontdlg.pszTitle = szTitle;
|
---|
| 142 | fontdlg.pszPreview = szPreview;
|
---|
| 143 | fontdlg.pfnDlgProc = NULL;
|
---|
[551] | 144 | strcpy(szFamily, fm.szFamilyname);
|
---|
[2] | 145 | fontdlg.pszFamilyname = szFamily;
|
---|
| 146 | fontdlg.usFamilyBufLen = sizeof(szFamily);
|
---|
[551] | 147 | fontdlg.fxPointSize = MAKEFIXED(fm.sNominalPointSize / 10, 0);
|
---|
[2] | 148 | fontdlg.fl = FNTS_CENTER | FNTS_INITFROMFATTRS;
|
---|
| 149 | fontdlg.sNominalPointSize = fm.sNominalPointSize;
|
---|
[551] | 150 | fontdlg.flType = (LONG) fm.fsType;
|
---|
[2] | 151 | fontdlg.clrFore = CLR_NEUTRAL;
|
---|
| 152 | fontdlg.clrBack = CLR_BACKGROUND;
|
---|
| 153 | fontdlg.usWeight = fm.usWeightClass;
|
---|
| 154 | fontdlg.usWidth = fm.usWidthClass;
|
---|
[551] | 155 | if (!WinFontDlg(HWND_DESKTOP, hwnd, &fontdlg) || fontdlg.lReturn != DID_OK) {
|
---|
[2] | 156 | WinReleasePS(fontdlg.hpsScreen);
|
---|
| 157 | return;
|
---|
| 158 | }
|
---|
[551] | 159 | if (fontdlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE)
|
---|
| 160 | ConvertVectorFontSize(fontdlg.fxPointSize, &fontdlg.fAttrs);
|
---|
[2] | 161 | WinReleasePS(fontdlg.hpsScreen);
|
---|
[551] | 162 | SetPresParamFromFattrs(hwnd, &fontdlg.fAttrs, fontdlg.sNominalPointSize,
|
---|
[1394] | 163 | fontdlg.fxPointSize);
|
---|
[2] | 164 | }
|
---|
[1160] | 165 | #endif
|
---|
[2] | 166 |
|
---|
[551] | 167 | FATTRS *SetMLEFont(HWND hwndMLE, FATTRS * fattrs, ULONG flags)
|
---|
| 168 | {
|
---|
[2] | 169 |
|
---|
[551] | 170 | /* Flags:
|
---|
| 171 | *
|
---|
| 172 | * 1 = Don't assume MLE (no MLM_* messages, use fattrs only
|
---|
| 173 | * 2 = Fixed width fonts only
|
---|
| 174 | * 4 = No synthesized fonts
|
---|
| 175 | * 8 = No vector fonts
|
---|
| 176 | * 16 = No bitmapped fonts
|
---|
| 177 | *
|
---|
| 178 | */
|
---|
[2] | 179 |
|
---|
[551] | 180 | FONTDLG fontDlg;
|
---|
| 181 | HPS hps;
|
---|
| 182 | FONTMETRICS fontMetrics;
|
---|
[1394] | 183 | CHAR szFamily[CCHMAXPATH];
|
---|
| 184 | PCSZ pcszPreview;
|
---|
[1160] | 185 | static FIXED fxPointSize = 0; /* keep track of this for vector fonts */
|
---|
[2] | 186 |
|
---|
[551] | 187 | if ((flags & 1) && !fattrs)
|
---|
| 188 | return fattrs;
|
---|
[1304] | 189 | //DosEnterCritSec(); //GKY 11-30-08
|
---|
| 190 | DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
|
---|
[1394] | 191 | // 12 Jan 09 SHL fixme to do multiple previews or rename to IDS_BLURBTEXT
|
---|
| 192 | pcszPreview = GetPString(IDS_BLURB1TEXT);
|
---|
[1304] | 193 | DosReleaseMutexSem(hmtxFM2Globals);
|
---|
| 194 | //DosExitCritSec();
|
---|
[1160] | 195 | memset(&fontDlg, 0, sizeof(fontDlg)); /* initialize all fields */
|
---|
[551] | 196 | /*
|
---|
| 197 | * Get the current font attributes
|
---|
| 198 | */
|
---|
| 199 | hps = WinGetPS(hwndMLE);
|
---|
| 200 | if (!(flags & 1))
|
---|
| 201 | WinSendMsg(hwndMLE, MLM_QUERYFONT,
|
---|
[1394] | 202 | MPFROMP((PFATTRS) & (fontDlg.fAttrs)), NULL);
|
---|
[551] | 203 | else
|
---|
| 204 | memcpy(&fontDlg.fAttrs, fattrs, sizeof(FATTRS));
|
---|
[2] | 205 |
|
---|
[551] | 206 | /* create system default font */
|
---|
[2] | 207 |
|
---|
[551] | 208 | GpiCreateLogFont(hps, (PSTR8) fontDlg.fAttrs.szFacename, 1,
|
---|
[1394] | 209 | &(fontDlg.fAttrs));
|
---|
[551] | 210 | GpiSetCharSet(hps, 1);
|
---|
| 211 | GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fontMetrics);
|
---|
| 212 | GpiSetCharSet(hps, LCID_DEFAULT);
|
---|
| 213 | GpiDeleteSetId(hps, 1);
|
---|
| 214 | WinReleasePS(hps);
|
---|
[2] | 215 |
|
---|
[551] | 216 | /*
|
---|
| 217 | * Initialize the FONTDLG structure with the current font
|
---|
| 218 | */
|
---|
[1160] | 219 | fontDlg.cbSize = sizeof(FONTDLG); /* sizeof(FONTDLG) */
|
---|
| 220 | fontDlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP); /* Screen presentation space */
|
---|
| 221 | fontDlg.hpsPrinter = NULLHANDLE; /* Printer presentation space */
|
---|
[2] | 222 |
|
---|
[1394] | 223 | fontDlg.pszTitle = (PSZ)GetPString(IDS_SETVIEWERFONTTITLETEXT);
|
---|
| 224 | fontDlg.pszPreview = (PSZ)pcszPreview;
|
---|
[1160] | 225 | fontDlg.pszPtSizeList = NULL; /* Application provided size list */
|
---|
| 226 | fontDlg.pfnDlgProc = NULL; /* Dialog subclass procedure */
|
---|
| 227 | strcpy(szFamily, fontMetrics.szFamilyname); /* Family name of font */
|
---|
| 228 | fontDlg.pszFamilyname = szFamily; /* point to Family name of font */
|
---|
| 229 | fontDlg.fxPointSize = fxPointSize; /* Point size the user selected */
|
---|
| 230 | fontDlg.fl = FNTS_CENTER | /* FNTS_* flags - dialog styles */
|
---|
[551] | 231 | FNTS_INITFROMFATTRS;
|
---|
| 232 | if (flags & 2)
|
---|
| 233 | fontDlg.fl |= FNTS_FIXEDWIDTHONLY;
|
---|
| 234 | if (flags & 4)
|
---|
| 235 | fontDlg.fl |= FNTS_NOSYNTHESIZEDFONTS;
|
---|
| 236 | if (flags & 8)
|
---|
| 237 | fontDlg.fl |= FNTS_BITMAPONLY;
|
---|
| 238 | else if (flags & 16)
|
---|
| 239 | fontDlg.fl |= FNTS_VECTORONLY;
|
---|
[1160] | 240 | fontDlg.flFlags = 0; /* FNTF_* state flags */
|
---|
[551] | 241 | /* Font type option bits */
|
---|
| 242 | fontDlg.flType = (LONG) fontMetrics.fsType;
|
---|
[1160] | 243 | fontDlg.flTypeMask = 0; /* Mask of which font types to use */
|
---|
| 244 | fontDlg.flStyle = 0; /* The selected style bits */
|
---|
| 245 | fontDlg.flStyleMask = 0; /* Mask of which style bits to use */
|
---|
| 246 | fontDlg.clrFore = CLR_NEUTRAL; /* Selected foreground color */
|
---|
| 247 | fontDlg.clrBack = CLR_BACKGROUND; /* Selected background color */
|
---|
| 248 | fontDlg.ulUser = 0; /* Blank field for application */
|
---|
| 249 | fontDlg.lReturn = 0; /* Return Value of the Dialog */
|
---|
| 250 | fontDlg.lEmHeight = 0; /* Em height of the current font */
|
---|
| 251 | fontDlg.lXHeight = 0; /* X height of the current font */
|
---|
| 252 | fontDlg.lExternalLeading = 0; /* External Leading of font */
|
---|
[551] | 253 | /* Nominal Point Size of font */
|
---|
| 254 | fontDlg.sNominalPointSize = fontMetrics.sNominalPointSize;
|
---|
[1160] | 255 | fontDlg.usWeight = fontMetrics.usWeightClass; /* The boldness of the font */
|
---|
| 256 | fontDlg.usWidth = fontMetrics.usWidthClass; /* The width of the font */
|
---|
| 257 | fontDlg.x = 0; /* X coordinate of the dialog */
|
---|
| 258 | fontDlg.y = 0; /* Y coordinate of the dialog */
|
---|
[2] | 259 | // fontDlg.usDlgId = IDD_FONT; /* ID of a custom dialog template */
|
---|
[1160] | 260 | fontDlg.usFamilyBufLen = sizeof(szFamily); /*Length of family name buffer */
|
---|
[2] | 261 |
|
---|
[551] | 262 | /*
|
---|
| 263 | * Bring up the standard Font Dialog
|
---|
| 264 | */
|
---|
[2] | 265 |
|
---|
[551] | 266 | if (!WinFontDlg(HWND_DESKTOP, hwndMLE, &fontDlg)
|
---|
| 267 | || fontDlg.lReturn != DID_OK) {
|
---|
| 268 | WinReleasePS(fontDlg.hpsScreen);
|
---|
| 269 | return NULL;
|
---|
| 270 | }
|
---|
[1160] | 271 | fxPointSize = fontDlg.fxPointSize; /* save point size for next dialog */
|
---|
[2] | 272 |
|
---|
[551] | 273 | /*
|
---|
| 274 | * If outline font, calculate the maxbaselineext and
|
---|
| 275 | * avecharwidth for the point size selected
|
---|
| 276 | */
|
---|
[2] | 277 |
|
---|
[551] | 278 | if (fontDlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE)
|
---|
| 279 | ConvertVectorFontSize(fontDlg.fxPointSize, &fontDlg.fAttrs);
|
---|
[2] | 280 |
|
---|
[551] | 281 | WinReleasePS(fontDlg.hpsScreen);
|
---|
| 282 | if (!(flags & 1))
|
---|
| 283 | WinSendMsg(hwndMLE, MLM_SETFONT, MPFROMP(&(fontDlg.fAttrs)), MPVOID);
|
---|
| 284 | if (fattrs)
|
---|
| 285 | memcpy(fattrs, &fontDlg.fAttrs, sizeof(FATTRS));
|
---|
| 286 | return fattrs;
|
---|
[2] | 287 |
|
---|
[1160] | 288 | } /* End of SetMLEFont() */
|
---|
[793] | 289 |
|
---|
| 290 | #pragma alloc_text(FONTS,ConvertVectorFontSize,SetFont,SetMLEFont)
|
---|
| 291 | #pragma alloc_text(FONTS,SetPresParamFromFattrs)
|
---|